This source file includes following definitions.
- xdr_buf_init
- xdr_encode_array
- xdr_encode_hyper
- xdr_decode_hyper
- xdr_decode_opaque_fixed
- xdr_netobj_dup
- xdr_adjust_iovec
- xdr_stream_remaining
- xdr_align_size
- xdr_stream_encode_u32
- xdr_stream_encode_u64
- xdr_stream_encode_opaque_inline
- xdr_stream_encode_opaque_fixed
- xdr_stream_encode_opaque
- xdr_stream_encode_uint32_array
- xdr_stream_decode_u32
- xdr_stream_decode_opaque_fixed
- xdr_stream_decode_opaque_inline
- xdr_stream_decode_uint32_array
1
2
3
4
5
6
7
8
9
10
11 #ifndef _SUNRPC_XDR_H_
12 #define _SUNRPC_XDR_H_
13
14 #ifdef __KERNEL__
15
16 #include <linux/uio.h>
17 #include <asm/byteorder.h>
18 #include <asm/unaligned.h>
19 #include <linux/scatterlist.h>
20
21 struct bio_vec;
22 struct rpc_rqst;
23
24
25
26
27 #define XDR_QUADLEN(l) (((l) + 3) >> 2)
28
29
30
31
32
33 #define XDR_MAX_NETOBJ 1024
34 struct xdr_netobj {
35 unsigned int len;
36 u8 * data;
37 };
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52 struct xdr_buf {
53 struct kvec head[1],
54 tail[1];
55
56 struct bio_vec *bvec;
57 struct page ** pages;
58 unsigned int page_base,
59 page_len,
60 flags;
61 #define XDRBUF_READ 0x01
62 #define XDRBUF_WRITE 0x02
63 #define XDRBUF_SPARSE_PAGES 0x04
64
65 unsigned int buflen,
66 len;
67 };
68
69 static inline void
70 xdr_buf_init(struct xdr_buf *buf, void *start, size_t len)
71 {
72 buf->head[0].iov_base = start;
73 buf->head[0].iov_len = len;
74 buf->tail[0].iov_len = 0;
75 buf->pages = NULL;
76 buf->page_len = 0;
77 buf->flags = 0;
78 buf->len = 0;
79 buf->buflen = len;
80 }
81
82
83
84
85
86 #define xdr_zero cpu_to_be32(0)
87 #define xdr_one cpu_to_be32(1)
88 #define xdr_two cpu_to_be32(2)
89
90 #define rpc_auth_null cpu_to_be32(RPC_AUTH_NULL)
91 #define rpc_auth_unix cpu_to_be32(RPC_AUTH_UNIX)
92 #define rpc_auth_short cpu_to_be32(RPC_AUTH_SHORT)
93 #define rpc_auth_gss cpu_to_be32(RPC_AUTH_GSS)
94
95 #define rpc_call cpu_to_be32(RPC_CALL)
96 #define rpc_reply cpu_to_be32(RPC_REPLY)
97
98 #define rpc_msg_accepted cpu_to_be32(RPC_MSG_ACCEPTED)
99
100 #define rpc_success cpu_to_be32(RPC_SUCCESS)
101 #define rpc_prog_unavail cpu_to_be32(RPC_PROG_UNAVAIL)
102 #define rpc_prog_mismatch cpu_to_be32(RPC_PROG_MISMATCH)
103 #define rpc_proc_unavail cpu_to_be32(RPC_PROC_UNAVAIL)
104 #define rpc_garbage_args cpu_to_be32(RPC_GARBAGE_ARGS)
105 #define rpc_system_err cpu_to_be32(RPC_SYSTEM_ERR)
106 #define rpc_drop_reply cpu_to_be32(RPC_DROP_REPLY)
107
108 #define rpc_mismatch cpu_to_be32(RPC_MISMATCH)
109 #define rpc_auth_error cpu_to_be32(RPC_AUTH_ERROR)
110
111 #define rpc_auth_ok cpu_to_be32(RPC_AUTH_OK)
112 #define rpc_autherr_badcred cpu_to_be32(RPC_AUTH_BADCRED)
113 #define rpc_autherr_rejectedcred cpu_to_be32(RPC_AUTH_REJECTEDCRED)
114 #define rpc_autherr_badverf cpu_to_be32(RPC_AUTH_BADVERF)
115 #define rpc_autherr_rejectedverf cpu_to_be32(RPC_AUTH_REJECTEDVERF)
116 #define rpc_autherr_tooweak cpu_to_be32(RPC_AUTH_TOOWEAK)
117 #define rpcsec_gsserr_credproblem cpu_to_be32(RPCSEC_GSS_CREDPROBLEM)
118 #define rpcsec_gsserr_ctxproblem cpu_to_be32(RPCSEC_GSS_CTXPROBLEM)
119
120
121
122
123 __be32 *xdr_encode_opaque_fixed(__be32 *p, const void *ptr, unsigned int len);
124 __be32 *xdr_encode_opaque(__be32 *p, const void *ptr, unsigned int len);
125 __be32 *xdr_encode_string(__be32 *p, const char *s);
126 __be32 *xdr_decode_string_inplace(__be32 *p, char **sp, unsigned int *lenp,
127 unsigned int maxlen);
128 __be32 *xdr_encode_netobj(__be32 *p, const struct xdr_netobj *);
129 __be32 *xdr_decode_netobj(__be32 *p, struct xdr_netobj *);
130
131 void xdr_inline_pages(struct xdr_buf *, unsigned int,
132 struct page **, unsigned int, unsigned int);
133 void xdr_terminate_string(struct xdr_buf *, const u32);
134 size_t xdr_buf_pagecount(struct xdr_buf *buf);
135 int xdr_alloc_bvec(struct xdr_buf *buf, gfp_t gfp);
136 void xdr_free_bvec(struct xdr_buf *buf);
137
138 static inline __be32 *xdr_encode_array(__be32 *p, const void *s, unsigned int len)
139 {
140 return xdr_encode_opaque(p, s, len);
141 }
142
143
144
145
146 static inline __be32 *
147 xdr_encode_hyper(__be32 *p, __u64 val)
148 {
149 put_unaligned_be64(val, p);
150 return p + 2;
151 }
152
153 static inline __be32 *
154 xdr_decode_hyper(__be32 *p, __u64 *valp)
155 {
156 *valp = get_unaligned_be64(p);
157 return p + 2;
158 }
159
160 static inline __be32 *
161 xdr_decode_opaque_fixed(__be32 *p, void *ptr, unsigned int len)
162 {
163 memcpy(ptr, p, len);
164 return p + XDR_QUADLEN(len);
165 }
166
167 static inline void xdr_netobj_dup(struct xdr_netobj *dst,
168 struct xdr_netobj *src, gfp_t gfp_mask)
169 {
170 dst->data = kmemdup(src->data, src->len, gfp_mask);
171 dst->len = src->len;
172 }
173
174
175
176
177 static inline int
178 xdr_adjust_iovec(struct kvec *iov, __be32 *p)
179 {
180 return iov->iov_len = ((u8 *) p - (u8 *) iov->iov_base);
181 }
182
183
184
185
186 extern void xdr_shift_buf(struct xdr_buf *, size_t);
187 extern void xdr_buf_from_iov(struct kvec *, struct xdr_buf *);
188 extern int xdr_buf_subsegment(struct xdr_buf *, struct xdr_buf *, unsigned int, unsigned int);
189 extern void xdr_buf_trim(struct xdr_buf *, unsigned int);
190 extern int xdr_buf_read_mic(struct xdr_buf *, struct xdr_netobj *, unsigned int);
191 extern int read_bytes_from_xdr_buf(struct xdr_buf *, unsigned int, void *, unsigned int);
192 extern int write_bytes_to_xdr_buf(struct xdr_buf *, unsigned int, void *, unsigned int);
193
194
195
196
197 struct xdr_skb_reader {
198 struct sk_buff *skb;
199 unsigned int offset;
200 size_t count;
201 __wsum csum;
202 };
203
204 typedef size_t (*xdr_skb_read_actor)(struct xdr_skb_reader *desc, void *to, size_t len);
205
206 extern int csum_partial_copy_to_xdr(struct xdr_buf *, struct sk_buff *);
207
208 extern int xdr_encode_word(struct xdr_buf *, unsigned int, u32);
209 extern int xdr_decode_word(struct xdr_buf *, unsigned int, u32 *);
210
211 struct xdr_array2_desc;
212 typedef int (*xdr_xcode_elem_t)(struct xdr_array2_desc *desc, void *elem);
213 struct xdr_array2_desc {
214 unsigned int elem_size;
215 unsigned int array_len;
216 unsigned int array_maxlen;
217 xdr_xcode_elem_t xcode;
218 };
219
220 extern int xdr_decode_array2(struct xdr_buf *buf, unsigned int base,
221 struct xdr_array2_desc *desc);
222 extern int xdr_encode_array2(struct xdr_buf *buf, unsigned int base,
223 struct xdr_array2_desc *desc);
224 extern void _copy_from_pages(char *p, struct page **pages, size_t pgbase,
225 size_t len);
226
227
228
229
230 struct xdr_stream {
231 __be32 *p;
232 struct xdr_buf *buf;
233
234 __be32 *end;
235 struct kvec *iov;
236 struct kvec scratch;
237 struct page **page_ptr;
238 unsigned int nwords;
239
240 struct rpc_rqst *rqst;
241 };
242
243
244
245
246 typedef void (*kxdreproc_t)(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
247 const void *obj);
248 typedef int (*kxdrdproc_t)(struct rpc_rqst *rqstp, struct xdr_stream *xdr,
249 void *obj);
250
251 extern void xdr_init_encode(struct xdr_stream *xdr, struct xdr_buf *buf,
252 __be32 *p, struct rpc_rqst *rqst);
253 extern __be32 *xdr_reserve_space(struct xdr_stream *xdr, size_t nbytes);
254 extern void xdr_commit_encode(struct xdr_stream *xdr);
255 extern void xdr_truncate_encode(struct xdr_stream *xdr, size_t len);
256 extern int xdr_restrict_buflen(struct xdr_stream *xdr, int newbuflen);
257 extern void xdr_write_pages(struct xdr_stream *xdr, struct page **pages,
258 unsigned int base, unsigned int len);
259 extern unsigned int xdr_stream_pos(const struct xdr_stream *xdr);
260 extern void xdr_init_decode(struct xdr_stream *xdr, struct xdr_buf *buf,
261 __be32 *p, struct rpc_rqst *rqst);
262 extern void xdr_init_decode_pages(struct xdr_stream *xdr, struct xdr_buf *buf,
263 struct page **pages, unsigned int len);
264 extern void xdr_set_scratch_buffer(struct xdr_stream *xdr, void *buf, size_t buflen);
265 extern __be32 *xdr_inline_decode(struct xdr_stream *xdr, size_t nbytes);
266 extern unsigned int xdr_read_pages(struct xdr_stream *xdr, unsigned int len);
267 extern void xdr_enter_page(struct xdr_stream *xdr, unsigned int len);
268 extern int xdr_process_buf(struct xdr_buf *buf, unsigned int offset, unsigned int len, int (*actor)(struct scatterlist *, void *), void *data);
269
270
271
272
273
274
275
276
277 static inline size_t
278 xdr_stream_remaining(const struct xdr_stream *xdr)
279 {
280 return xdr->nwords << 2;
281 }
282
283 ssize_t xdr_stream_decode_opaque(struct xdr_stream *xdr, void *ptr,
284 size_t size);
285 ssize_t xdr_stream_decode_opaque_dup(struct xdr_stream *xdr, void **ptr,
286 size_t maxlen, gfp_t gfp_flags);
287 ssize_t xdr_stream_decode_string(struct xdr_stream *xdr, char *str,
288 size_t size);
289 ssize_t xdr_stream_decode_string_dup(struct xdr_stream *xdr, char **str,
290 size_t maxlen, gfp_t gfp_flags);
291
292
293
294
295
296
297
298 static inline size_t
299 xdr_align_size(size_t n)
300 {
301 const size_t mask = sizeof(__u32) - 1;
302
303 return (n + mask) & ~mask;
304 }
305
306
307
308
309
310
311
312
313
314
315 static inline ssize_t
316 xdr_stream_encode_u32(struct xdr_stream *xdr, __u32 n)
317 {
318 const size_t len = sizeof(n);
319 __be32 *p = xdr_reserve_space(xdr, len);
320
321 if (unlikely(!p))
322 return -EMSGSIZE;
323 *p = cpu_to_be32(n);
324 return len;
325 }
326
327
328
329
330
331
332
333
334
335
336 static inline ssize_t
337 xdr_stream_encode_u64(struct xdr_stream *xdr, __u64 n)
338 {
339 const size_t len = sizeof(n);
340 __be32 *p = xdr_reserve_space(xdr, len);
341
342 if (unlikely(!p))
343 return -EMSGSIZE;
344 xdr_encode_hyper(p, n);
345 return len;
346 }
347
348
349
350
351
352
353
354
355
356
357
358 static inline ssize_t
359 xdr_stream_encode_opaque_inline(struct xdr_stream *xdr, void **ptr, size_t len)
360 {
361 size_t count = sizeof(__u32) + xdr_align_size(len);
362 __be32 *p = xdr_reserve_space(xdr, count);
363
364 if (unlikely(!p)) {
365 *ptr = NULL;
366 return -EMSGSIZE;
367 }
368 xdr_encode_opaque(p, NULL, len);
369 *ptr = ++p;
370 return count;
371 }
372
373
374
375
376
377
378
379
380
381
382
383 static inline ssize_t
384 xdr_stream_encode_opaque_fixed(struct xdr_stream *xdr, const void *ptr, size_t len)
385 {
386 __be32 *p = xdr_reserve_space(xdr, len);
387
388 if (unlikely(!p))
389 return -EMSGSIZE;
390 xdr_encode_opaque_fixed(p, ptr, len);
391 return xdr_align_size(len);
392 }
393
394
395
396
397
398
399
400
401
402
403
404 static inline ssize_t
405 xdr_stream_encode_opaque(struct xdr_stream *xdr, const void *ptr, size_t len)
406 {
407 size_t count = sizeof(__u32) + xdr_align_size(len);
408 __be32 *p = xdr_reserve_space(xdr, count);
409
410 if (unlikely(!p))
411 return -EMSGSIZE;
412 xdr_encode_opaque(p, ptr, len);
413 return count;
414 }
415
416
417
418
419
420
421
422
423
424
425
426 static inline ssize_t
427 xdr_stream_encode_uint32_array(struct xdr_stream *xdr,
428 const __u32 *array, size_t array_size)
429 {
430 ssize_t ret = (array_size+1) * sizeof(__u32);
431 __be32 *p = xdr_reserve_space(xdr, ret);
432
433 if (unlikely(!p))
434 return -EMSGSIZE;
435 *p++ = cpu_to_be32(array_size);
436 for (; array_size > 0; p++, array++, array_size--)
437 *p = cpu_to_be32p(array);
438 return ret;
439 }
440
441
442
443
444
445
446
447
448
449
450 static inline ssize_t
451 xdr_stream_decode_u32(struct xdr_stream *xdr, __u32 *ptr)
452 {
453 const size_t count = sizeof(*ptr);
454 __be32 *p = xdr_inline_decode(xdr, count);
455
456 if (unlikely(!p))
457 return -EBADMSG;
458 *ptr = be32_to_cpup(p);
459 return 0;
460 }
461
462
463
464
465
466
467
468
469
470
471
472 static inline ssize_t
473 xdr_stream_decode_opaque_fixed(struct xdr_stream *xdr, void *ptr, size_t len)
474 {
475 __be32 *p = xdr_inline_decode(xdr, len);
476
477 if (unlikely(!p))
478 return -EBADMSG;
479 xdr_decode_opaque_fixed(p, ptr, len);
480 return len;
481 }
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499 static inline ssize_t
500 xdr_stream_decode_opaque_inline(struct xdr_stream *xdr, void **ptr, size_t maxlen)
501 {
502 __be32 *p;
503 __u32 len;
504
505 *ptr = NULL;
506 if (unlikely(xdr_stream_decode_u32(xdr, &len) < 0))
507 return -EBADMSG;
508 if (len != 0) {
509 p = xdr_inline_decode(xdr, len);
510 if (unlikely(!p))
511 return -EBADMSG;
512 if (unlikely(len > maxlen))
513 return -EMSGSIZE;
514 *ptr = p;
515 }
516 return len;
517 }
518
519
520
521
522
523
524
525
526
527
528
529
530 static inline ssize_t
531 xdr_stream_decode_uint32_array(struct xdr_stream *xdr,
532 __u32 *array, size_t array_size)
533 {
534 __be32 *p;
535 __u32 len;
536 ssize_t retval;
537
538 if (unlikely(xdr_stream_decode_u32(xdr, &len) < 0))
539 return -EBADMSG;
540 p = xdr_inline_decode(xdr, len * sizeof(*p));
541 if (unlikely(!p))
542 return -EBADMSG;
543 if (array == NULL)
544 return len;
545 if (len <= array_size) {
546 if (len < array_size)
547 memset(array+len, 0, (array_size-len)*sizeof(*array));
548 array_size = len;
549 retval = len;
550 } else
551 retval = -EMSGSIZE;
552 for (; array_size > 0; p++, array++, array_size--)
553 *array = be32_to_cpup(p);
554 return retval;
555 }
556 #endif
557
558 #endif