Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * linux/include/linux/sunrpc/clnt.h | |
3 | * | |
4 | * Declarations for the high-level RPC client interface | |
5 | * | |
6 | * Copyright (C) 1995, 1996, Olaf Kirch <okir@monad.swb.de> | |
7 | */ | |
8 | ||
9 | #ifndef _LINUX_SUNRPC_CLNT_H | |
10 | #define _LINUX_SUNRPC_CLNT_H | |
11 | ||
a02d6926 CL |
12 | #include <linux/socket.h> |
13 | #include <linux/in.h> | |
14 | #include <linux/in6.h> | |
15 | ||
1da177e4 LT |
16 | #include <linux/sunrpc/msg_prot.h> |
17 | #include <linux/sunrpc/sched.h> | |
18 | #include <linux/sunrpc/xprt.h> | |
19 | #include <linux/sunrpc/auth.h> | |
20 | #include <linux/sunrpc/stats.h> | |
21 | #include <linux/sunrpc/xdr.h> | |
22 | #include <linux/sunrpc/timer.h> | |
23 | #include <asm/signal.h> | |
7d217cac | 24 | #include <linux/path.h> |
4516fc04 | 25 | #include <net/ipv6.h> |
1da177e4 | 26 | |
1da177e4 LT |
27 | struct rpc_inode; |
28 | ||
29 | /* | |
30 | * The high-level client handle | |
31 | */ | |
32 | struct rpc_clnt { | |
34f52e35 | 33 | struct kref cl_kref; /* Number of references */ |
6529eba0 TM |
34 | struct list_head cl_clients; /* Global list of clients */ |
35 | struct list_head cl_tasks; /* List of tasks */ | |
4bef61ff | 36 | spinlock_t cl_lock; /* spinlock */ |
1da177e4 LT |
37 | struct rpc_xprt * cl_xprt; /* transport */ |
38 | struct rpc_procinfo * cl_procinfo; /* procedure info */ | |
4a68179d CL |
39 | u32 cl_prog, /* RPC program number */ |
40 | cl_vers, /* RPC version number */ | |
41 | cl_maxproc; /* max procedure number */ | |
1da177e4 LT |
42 | |
43 | char * cl_server; /* server machine name */ | |
44 | char * cl_protname; /* protocol name */ | |
45 | struct rpc_auth * cl_auth; /* authenticator */ | |
11c556b3 CL |
46 | struct rpc_stat * cl_stats; /* per-program statistics */ |
47 | struct rpc_iostats * cl_metrics; /* per-client statistics */ | |
1da177e4 LT |
48 | |
49 | unsigned int cl_softrtry : 1,/* soft timeouts */ | |
43d78ef2 | 50 | cl_discrtry : 1,/* disconnect before retry */ |
b6b6152c OK |
51 | cl_autobind : 1,/* use getport() */ |
52 | cl_chatty : 1;/* be verbose */ | |
1da177e4 LT |
53 | |
54 | struct rpc_rtt * cl_rtt; /* RTO estimator data */ | |
ba7392bb | 55 | const struct rpc_timeout *cl_timeout; /* Timeout strategy */ |
1da177e4 LT |
56 | |
57 | int cl_nodelen; /* nodename length */ | |
58 | char cl_nodename[UNX_MAXNODENAME]; | |
7d217cac | 59 | struct path cl_path; |
1da177e4 LT |
60 | struct rpc_clnt * cl_parent; /* Points to parent of clones */ |
61 | struct rpc_rtt cl_rtt_default; | |
ba7392bb | 62 | struct rpc_timeout cl_timeout_default; |
3e32a5d9 | 63 | struct rpc_program * cl_program; |
1da177e4 | 64 | char cl_inline_name[32]; |
608207e8 | 65 | char *cl_principal; /* target to authenticate to */ |
1da177e4 | 66 | }; |
1da177e4 LT |
67 | |
68 | /* | |
69 | * General RPC program info | |
70 | */ | |
71 | #define RPC_MAXVERSION 4 | |
72 | struct rpc_program { | |
73 | char * name; /* protocol name */ | |
74 | u32 number; /* program number */ | |
75 | unsigned int nrvers; /* number of versions */ | |
76 | struct rpc_version ** version; /* version array */ | |
77 | struct rpc_stat * stats; /* statistics */ | |
78 | char * pipe_dir_name; /* path to rpc_pipefs dir */ | |
79 | }; | |
80 | ||
81 | struct rpc_version { | |
82 | u32 number; /* version number */ | |
83 | unsigned int nrprocs; /* number of procs */ | |
84 | struct rpc_procinfo * procs; /* procedure array */ | |
85 | }; | |
86 | ||
87 | /* | |
88 | * Procedure information | |
89 | */ | |
90 | struct rpc_procinfo { | |
91 | u32 p_proc; /* RPC procedure number */ | |
92 | kxdrproc_t p_encode; /* XDR encode function */ | |
93 | kxdrproc_t p_decode; /* XDR decode function */ | |
2bea90d4 CL |
94 | unsigned int p_arglen; /* argument hdr length (u32) */ |
95 | unsigned int p_replen; /* reply hdr length (u32) */ | |
1da177e4 LT |
96 | unsigned int p_count; /* call count */ |
97 | unsigned int p_timer; /* Which RTT timer to use */ | |
cc0175c1 CL |
98 | u32 p_statidx; /* Which procedure to account */ |
99 | char * p_name; /* name of procedure */ | |
1da177e4 LT |
100 | }; |
101 | ||
1da177e4 LT |
102 | #ifdef __KERNEL__ |
103 | ||
c2866763 CL |
104 | struct rpc_create_args { |
105 | int protocol; | |
106 | struct sockaddr *address; | |
107 | size_t addrsize; | |
d3bc9a1d | 108 | struct sockaddr *saddress; |
ba7392bb | 109 | const struct rpc_timeout *timeout; |
c2866763 CL |
110 | char *servername; |
111 | struct rpc_program *program; | |
d5b337b4 | 112 | u32 prognumber; /* overrides program->number */ |
c2866763 CL |
113 | u32 version; |
114 | rpc_authflavor_t authflavor; | |
115 | unsigned long flags; | |
608207e8 | 116 | char *client_name; |
c2866763 CL |
117 | }; |
118 | ||
119 | /* Values for "flags" field */ | |
120 | #define RPC_CLNT_CREATE_HARDRTRY (1UL << 0) | |
c2866763 | 121 | #define RPC_CLNT_CREATE_AUTOBIND (1UL << 2) |
90c5755f TM |
122 | #define RPC_CLNT_CREATE_NONPRIVPORT (1UL << 3) |
123 | #define RPC_CLNT_CREATE_NOPING (1UL << 4) | |
124 | #define RPC_CLNT_CREATE_DISCRTRY (1UL << 5) | |
b6b6152c | 125 | #define RPC_CLNT_CREATE_QUIET (1UL << 6) |
c2866763 CL |
126 | |
127 | struct rpc_clnt *rpc_create(struct rpc_create_args *args); | |
007e251f | 128 | struct rpc_clnt *rpc_bind_new_program(struct rpc_clnt *, |
89eb21c3 | 129 | struct rpc_program *, u32); |
1da177e4 | 130 | struct rpc_clnt *rpc_clone_client(struct rpc_clnt *); |
4c402b40 | 131 | void rpc_shutdown_client(struct rpc_clnt *); |
1da177e4 | 132 | void rpc_release_client(struct rpc_clnt *); |
cce63cd6 | 133 | |
14aeb211 | 134 | int rpcb_register(u32, u32, int, unsigned short); |
c2e1b09f CL |
135 | int rpcb_v4_register(const u32 program, const u32 version, |
136 | const struct sockaddr *address, | |
14aeb211 | 137 | const char *netid); |
f1ec08cb | 138 | int rpcb_getport_sync(struct sockaddr_in *, u32, u32, int); |
45160d62 | 139 | void rpcb_getport_async(struct rpc_task *); |
1da177e4 | 140 | |
77de2c59 | 141 | void rpc_call_start(struct rpc_task *); |
cbc20059 TM |
142 | int rpc_call_async(struct rpc_clnt *clnt, |
143 | const struct rpc_message *msg, int flags, | |
144 | const struct rpc_call_ops *tk_ops, | |
963d8fe5 | 145 | void *calldata); |
cbc20059 TM |
146 | int rpc_call_sync(struct rpc_clnt *clnt, |
147 | const struct rpc_message *msg, int flags); | |
5e1550d6 TM |
148 | struct rpc_task *rpc_call_null(struct rpc_clnt *clnt, struct rpc_cred *cred, |
149 | int flags); | |
aae2006e | 150 | void rpc_restart_call_prepare(struct rpc_task *); |
1da177e4 | 151 | void rpc_restart_call(struct rpc_task *); |
1da177e4 LT |
152 | void rpc_setbufsize(struct rpc_clnt *, unsigned int, unsigned int); |
153 | size_t rpc_max_payload(struct rpc_clnt *); | |
35f5a422 | 154 | void rpc_force_rebind(struct rpc_clnt *); |
ed39440a | 155 | size_t rpc_peeraddr(struct rpc_clnt *, struct sockaddr *, size_t); |
b454ae90 | 156 | const char *rpc_peeraddr2str(struct rpc_clnt *, enum rpc_display_format_t); |
1da177e4 | 157 | |
a02d6926 CL |
158 | size_t rpc_ntop(const struct sockaddr *, char *, const size_t); |
159 | size_t rpc_pton(const char *, const size_t, | |
160 | struct sockaddr *, const size_t); | |
161 | char * rpc_sockaddr2uaddr(const struct sockaddr *); | |
162 | size_t rpc_uaddr2sockaddr(const char *, const size_t, | |
163 | struct sockaddr *, const size_t); | |
164 | ||
165 | static inline unsigned short rpc_get_port(const struct sockaddr *sap) | |
166 | { | |
167 | switch (sap->sa_family) { | |
168 | case AF_INET: | |
169 | return ntohs(((struct sockaddr_in *)sap)->sin_port); | |
170 | case AF_INET6: | |
171 | return ntohs(((struct sockaddr_in6 *)sap)->sin6_port); | |
172 | } | |
173 | return 0; | |
174 | } | |
175 | ||
176 | static inline void rpc_set_port(struct sockaddr *sap, | |
177 | const unsigned short port) | |
178 | { | |
179 | switch (sap->sa_family) { | |
180 | case AF_INET: | |
181 | ((struct sockaddr_in *)sap)->sin_port = htons(port); | |
182 | break; | |
183 | case AF_INET6: | |
184 | ((struct sockaddr_in6 *)sap)->sin6_port = htons(port); | |
185 | break; | |
186 | } | |
187 | } | |
188 | ||
189 | #define IPV6_SCOPE_DELIMITER '%' | |
190 | #define IPV6_SCOPE_ID_LEN sizeof("%nnnnnnnnnn") | |
191 | ||
4516fc04 JL |
192 | static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1, |
193 | const struct sockaddr *sap2) | |
194 | { | |
195 | const struct sockaddr_in *sin1 = (const struct sockaddr_in *)sap1; | |
196 | const struct sockaddr_in *sin2 = (const struct sockaddr_in *)sap2; | |
197 | ||
198 | return sin1->sin_addr.s_addr == sin2->sin_addr.s_addr; | |
199 | } | |
200 | ||
be3ad6b0 JL |
201 | static inline bool __rpc_copy_addr4(struct sockaddr *dst, |
202 | const struct sockaddr *src) | |
203 | { | |
204 | const struct sockaddr_in *ssin = (struct sockaddr_in *) src; | |
205 | struct sockaddr_in *dsin = (struct sockaddr_in *) dst; | |
206 | ||
207 | dsin->sin_family = ssin->sin_family; | |
208 | dsin->sin_addr.s_addr = ssin->sin_addr.s_addr; | |
209 | return true; | |
210 | } | |
211 | ||
4516fc04 JL |
212 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) |
213 | static inline bool __rpc_cmp_addr6(const struct sockaddr *sap1, | |
214 | const struct sockaddr *sap2) | |
215 | { | |
216 | const struct sockaddr_in6 *sin1 = (const struct sockaddr_in6 *)sap1; | |
217 | const struct sockaddr_in6 *sin2 = (const struct sockaddr_in6 *)sap2; | |
218 | return ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr); | |
219 | } | |
be3ad6b0 JL |
220 | |
221 | static inline bool __rpc_copy_addr6(struct sockaddr *dst, | |
222 | const struct sockaddr *src) | |
223 | { | |
224 | const struct sockaddr_in6 *ssin6 = (const struct sockaddr_in6 *) src; | |
225 | struct sockaddr_in6 *dsin6 = (struct sockaddr_in6 *) dst; | |
226 | ||
227 | dsin6->sin6_family = ssin6->sin6_family; | |
228 | ipv6_addr_copy(&dsin6->sin6_addr, &ssin6->sin6_addr); | |
229 | return true; | |
230 | } | |
4516fc04 JL |
231 | #else /* !(CONFIG_IPV6 || CONFIG_IPV6_MODULE) */ |
232 | static inline bool __rpc_cmp_addr6(const struct sockaddr *sap1, | |
233 | const struct sockaddr *sap2) | |
234 | { | |
235 | return false; | |
236 | } | |
be3ad6b0 JL |
237 | |
238 | static inline bool __rpc_copy_addr6(struct sockaddr *dst, | |
239 | const struct sockaddr *src) | |
240 | { | |
241 | return false; | |
242 | } | |
4516fc04 JL |
243 | #endif /* !(CONFIG_IPV6 || CONFIG_IPV6_MODULE) */ |
244 | ||
245 | /** | |
246 | * rpc_cmp_addr - compare the address portion of two sockaddrs. | |
247 | * @sap1: first sockaddr | |
248 | * @sap2: second sockaddr | |
249 | * | |
250 | * Just compares the family and address portion. Ignores port, scope, etc. | |
251 | * Returns true if the addrs are equal, false if they aren't. | |
252 | */ | |
253 | static inline bool rpc_cmp_addr(const struct sockaddr *sap1, | |
254 | const struct sockaddr *sap2) | |
255 | { | |
256 | if (sap1->sa_family == sap2->sa_family) { | |
257 | switch (sap1->sa_family) { | |
258 | case AF_INET: | |
259 | return __rpc_cmp_addr4(sap1, sap2); | |
260 | case AF_INET6: | |
261 | return __rpc_cmp_addr6(sap1, sap2); | |
262 | } | |
263 | } | |
264 | return false; | |
265 | } | |
266 | ||
be3ad6b0 JL |
267 | /** |
268 | * rpc_copy_addr - copy the address portion of one sockaddr to another | |
269 | * @dst: destination sockaddr | |
270 | * @src: source sockaddr | |
271 | * | |
272 | * Just copies the address portion and family. Ignores port, scope, etc. | |
273 | * Caller is responsible for making certain that dst is large enough to hold | |
274 | * the address in src. Returns true if address family is supported. Returns | |
275 | * false otherwise. | |
276 | */ | |
277 | static inline bool rpc_copy_addr(struct sockaddr *dst, | |
278 | const struct sockaddr *src) | |
279 | { | |
280 | switch (src->sa_family) { | |
281 | case AF_INET: | |
282 | return __rpc_copy_addr4(dst, src); | |
283 | case AF_INET6: | |
284 | return __rpc_copy_addr6(dst, src); | |
285 | } | |
286 | return false; | |
287 | } | |
288 | ||
fbf4665f JL |
289 | /** |
290 | * rpc_get_scope_id - return scopeid for a given sockaddr | |
291 | * @sa: sockaddr to get scopeid from | |
292 | * | |
293 | * Returns the value of the sin6_scope_id for AF_INET6 addrs, or 0 if | |
294 | * not an AF_INET6 address. | |
295 | */ | |
296 | static inline u32 rpc_get_scope_id(const struct sockaddr *sa) | |
297 | { | |
298 | if (sa->sa_family != AF_INET6) | |
299 | return 0; | |
300 | ||
301 | return ((struct sockaddr_in6 *) sa)->sin6_scope_id; | |
302 | } | |
303 | ||
1da177e4 LT |
304 | #endif /* __KERNEL__ */ |
305 | #endif /* _LINUX_SUNRPC_CLNT_H */ |