This source file includes following definitions.
- xdr_skb_read_bits
- xdr_skb_read_and_csum_bits
- xdr_partial_copy_from_skb
- csum_partial_copy_to_xdr
1
2
3
4
5
6
7
8
9
10 #include <linux/compiler.h>
11 #include <linux/netdevice.h>
12 #include <linux/gfp.h>
13 #include <linux/skbuff.h>
14 #include <linux/types.h>
15 #include <linux/pagemap.h>
16 #include <linux/udp.h>
17 #include <linux/sunrpc/xdr.h>
18 #include <linux/export.h>
19
20
21
22
23
24
25
26
27
28
29
30 static size_t
31 xdr_skb_read_bits(struct xdr_skb_reader *desc, void *to, size_t len)
32 {
33 if (len > desc->count)
34 len = desc->count;
35 if (unlikely(skb_copy_bits(desc->skb, desc->offset, to, len)))
36 return 0;
37 desc->count -= len;
38 desc->offset += len;
39 return len;
40 }
41
42
43
44
45
46
47
48
49
50 static size_t xdr_skb_read_and_csum_bits(struct xdr_skb_reader *desc, void *to, size_t len)
51 {
52 unsigned int pos;
53 __wsum csum2;
54
55 if (len > desc->count)
56 len = desc->count;
57 pos = desc->offset;
58 csum2 = skb_copy_and_csum_bits(desc->skb, pos, to, len, 0);
59 desc->csum = csum_block_add(desc->csum, csum2, pos);
60 desc->count -= len;
61 desc->offset += len;
62 return len;
63 }
64
65
66
67
68
69
70
71
72
73 static ssize_t
74 xdr_partial_copy_from_skb(struct xdr_buf *xdr, unsigned int base, struct xdr_skb_reader *desc, xdr_skb_read_actor copy_actor)
75 {
76 struct page **ppage = xdr->pages;
77 unsigned int len, pglen = xdr->page_len;
78 ssize_t copied = 0;
79 size_t ret;
80
81 len = xdr->head[0].iov_len;
82 if (base < len) {
83 len -= base;
84 ret = copy_actor(desc, (char *)xdr->head[0].iov_base + base, len);
85 copied += ret;
86 if (ret != len || !desc->count)
87 goto out;
88 base = 0;
89 } else
90 base -= len;
91
92 if (unlikely(pglen == 0))
93 goto copy_tail;
94 if (unlikely(base >= pglen)) {
95 base -= pglen;
96 goto copy_tail;
97 }
98 if (base || xdr->page_base) {
99 pglen -= base;
100 base += xdr->page_base;
101 ppage += base >> PAGE_SHIFT;
102 base &= ~PAGE_MASK;
103 }
104 do {
105 char *kaddr;
106
107
108
109 if ((xdr->flags & XDRBUF_SPARSE_PAGES) && *ppage == NULL) {
110 *ppage = alloc_page(GFP_NOWAIT | __GFP_NOWARN);
111 if (unlikely(*ppage == NULL)) {
112 if (copied == 0)
113 copied = -ENOMEM;
114 goto out;
115 }
116 }
117
118 len = PAGE_SIZE;
119 kaddr = kmap_atomic(*ppage);
120 if (base) {
121 len -= base;
122 if (pglen < len)
123 len = pglen;
124 ret = copy_actor(desc, kaddr + base, len);
125 base = 0;
126 } else {
127 if (pglen < len)
128 len = pglen;
129 ret = copy_actor(desc, kaddr, len);
130 }
131 flush_dcache_page(*ppage);
132 kunmap_atomic(kaddr);
133 copied += ret;
134 if (ret != len || !desc->count)
135 goto out;
136 ppage++;
137 } while ((pglen -= len) != 0);
138 copy_tail:
139 len = xdr->tail[0].iov_len;
140 if (base < len)
141 copied += copy_actor(desc, (char *)xdr->tail[0].iov_base + base, len - base);
142 out:
143 return copied;
144 }
145
146
147
148
149
150
151
152
153
154 int csum_partial_copy_to_xdr(struct xdr_buf *xdr, struct sk_buff *skb)
155 {
156 struct xdr_skb_reader desc;
157
158 desc.skb = skb;
159 desc.offset = 0;
160 desc.count = skb->len - desc.offset;
161
162 if (skb_csum_unnecessary(skb))
163 goto no_checksum;
164
165 desc.csum = csum_partial(skb->data, desc.offset, skb->csum);
166 if (xdr_partial_copy_from_skb(xdr, 0, &desc, xdr_skb_read_and_csum_bits) < 0)
167 return -1;
168 if (desc.offset != skb->len) {
169 __wsum csum2;
170 csum2 = skb_checksum(skb, desc.offset, skb->len - desc.offset, 0);
171 desc.csum = csum_block_add(desc.csum, csum2, desc.offset);
172 }
173 if (desc.count)
174 return -1;
175 if (csum_fold(desc.csum))
176 return -1;
177 if (unlikely(skb->ip_summed == CHECKSUM_COMPLETE) &&
178 !skb->csum_complete_sw)
179 netdev_rx_csum_fault(skb->dev, skb);
180 return 0;
181 no_checksum:
182 if (xdr_partial_copy_from_skb(xdr, 0, &desc, xdr_skb_read_bits) < 0)
183 return -1;
184 if (desc.count)
185 return -1;
186 return 0;
187 }
188 EXPORT_SYMBOL_GPL(csum_partial_copy_to_xdr);