1 /*
2 * include/linux/sunrpc/xdr.h
3 *
4 * Copyright (C) 1995-1997 Olaf Kirch <okir@monad.swb.de>
5 */
6
7 #ifndef _SUNRPC_XDR_H_
8 #define _SUNRPC_XDR_H_
9
10 #ifdef __KERNEL__
11
12 #include <linux/uio.h>
13
14 /*
15 * Buffer adjustment
16 */
17 #define XDR_QUADLEN(l) (((l) + 3) >> 2)
18
19 /*
20 * Generic opaque `network object.' At the kernel level, this type
21 * is used only by lockd.
22 */
23 #define XDR_MAX_NETOBJ 1024
24 struct xdr_netobj {
25 unsigned int len;
26 u8 * data;
27 };
28
29 /*
30 * This is the generic XDR function. rqstp is either a rpc_rqst (client
31 * side) or svc_rqst pointer (server side).
32 * Encode functions always assume there's enough room in the buffer.
33 */
34 typedef int (*kxdrproc_t)(void *rqstp, u32 *data, void *obj);
35
36 /*
37 * Basic structure for transmission/reception of a client XDR message.
38 * Features a header (for a linear buffer containing RPC headers
39 * and the data payload for short messages), and then an array of
40 * pages.
41 * The tail iovec allows you to append data after the page array. Its
42 * main interest is for appending padding to the pages in order to
43 * satisfy the int_32-alignment requirements in RFC1832.
44 *
45 * For the future, we might want to string several of these together
46 * in a list if anybody wants to make use of NFSv4 COMPOUND
47 * operations and/or has a need for scatter/gather involving pages.
48 */
49 struct xdr_buf {
50 struct iovec head[1], /* RPC header + non-page data */
51 tail[1]; /* Appended after page data */
52
53 struct page ** pages; /* Array of contiguous pages */
54 unsigned int page_base, /* Start of page data */
55 page_len; /* Length of page data */
56
57 unsigned int len; /* Total length of data */
58
59 };
60
61 /*
62 * pre-xdr'ed macros.
63 */
64
65 #define xdr_zero __constant_htonl(0)
66 #define xdr_one __constant_htonl(1)
67 #define xdr_two __constant_htonl(2)
68
69 #define rpc_success __constant_htonl(RPC_SUCCESS)
70 #define rpc_prog_unavail __constant_htonl(RPC_PROG_UNAVAIL)
71 #define rpc_prog_mismatch __constant_htonl(RPC_PROG_MISMATCH)
72 #define rpc_proc_unavail __constant_htonl(RPC_PROC_UNAVAIL)
73 #define rpc_garbage_args __constant_htonl(RPC_GARBAGE_ARGS)
74 #define rpc_system_err __constant_htonl(RPC_SYSTEM_ERR)
75
76 #define rpc_auth_ok __constant_htonl(RPC_AUTH_OK)
77 #define rpc_autherr_badcred __constant_htonl(RPC_AUTH_BADCRED)
78 #define rpc_autherr_rejectedcred __constant_htonl(RPC_AUTH_REJECTEDCRED)
79 #define rpc_autherr_badverf __constant_htonl(RPC_AUTH_BADVERF)
80 #define rpc_autherr_rejectedverf __constant_htonl(RPC_AUTH_REJECTEDVERF)
81 #define rpc_autherr_tooweak __constant_htonl(RPC_AUTH_TOOWEAK)
82
83
84 /*
85 * Miscellaneous XDR helper functions
86 */
87 u32 * xdr_encode_array(u32 *p, const char *s, unsigned int len);
88 u32 * xdr_encode_string(u32 *p, const char *s);
89 u32 * xdr_decode_string(u32 *p, char **sp, int *lenp, int maxlen);
90 u32 * xdr_decode_string_inplace(u32 *p, char **sp, int *lenp, int maxlen);
91 u32 * xdr_encode_netobj(u32 *p, const struct xdr_netobj *);
92 u32 * xdr_decode_netobj(u32 *p, struct xdr_netobj *);
93 u32 * xdr_decode_netobj_fixed(u32 *p, void *obj, unsigned int len);
94
95 void xdr_encode_pages(struct xdr_buf *, struct page **, unsigned int,
96 unsigned int);
97 void xdr_inline_pages(struct xdr_buf *, unsigned int,
98 struct page **, unsigned int, unsigned int);
99
100 /*
101 * Decode 64bit quantities (NFSv3 support)
102 */
103 static inline u32 *
xdr_encode_hyper(u32 * p,__u64 val)104 xdr_encode_hyper(u32 *p, __u64 val)
105 {
106 *p++ = htonl(val >> 32);
107 *p++ = htonl(val & 0xFFFFFFFF);
108 return p;
109 }
110
111 static inline u32 *
xdr_decode_hyper(u32 * p,__u64 * valp)112 xdr_decode_hyper(u32 *p, __u64 *valp)
113 {
114 *valp = ((__u64) ntohl(*p++)) << 32;
115 *valp |= ntohl(*p++);
116 return p;
117 }
118
119 /*
120 * Adjust iovec to reflect end of xdr'ed data (RPC client XDR)
121 */
122 static inline int
xdr_adjust_iovec(struct iovec * iov,u32 * p)123 xdr_adjust_iovec(struct iovec *iov, u32 *p)
124 {
125 return iov->iov_len = ((u8 *) p - (u8 *) iov->iov_base);
126 }
127
128 void xdr_shift_iovec(struct iovec *, int, size_t);
129 void xdr_zero_iovec(struct iovec *, int, size_t);
130
131 /*
132 * Maximum number of iov's we use.
133 */
134 #define MAX_IOVEC (12)
135
136 /*
137 * XDR buffer helper functions
138 */
139 extern int xdr_kmap(struct iovec *, struct xdr_buf *, unsigned int);
140 extern void xdr_kunmap(struct xdr_buf *, unsigned int, int);
141 extern void xdr_shift_buf(struct xdr_buf *, size_t);
142
143 /*
144 * Helper structure for copying from an sk_buff.
145 */
146 typedef struct {
147 struct sk_buff *skb;
148 unsigned int offset;
149 size_t count;
150 unsigned int csum;
151 } skb_reader_t;
152
153 typedef size_t (*skb_read_actor_t)(skb_reader_t *desc, void *to, size_t len);
154
155 extern void xdr_partial_copy_from_skb(struct xdr_buf *, unsigned int,
156 skb_reader_t *, skb_read_actor_t);
157
158 extern int xdr_copy_skb(struct xdr_buf *xdr, unsigned int base,
159 struct sk_buff *skb, unsigned int offset);
160
161 extern int xdr_copy_and_csum_skb(struct xdr_buf *xdr, unsigned int base,
162 struct sk_buff *skb, unsigned int offset, unsigned int csum);
163
164 #endif /* __KERNEL__ */
165
166 #endif /* _SUNRPC_XDR_H_ */
167