]>
Commit | Line | Data |
---|---|---|
a509050b CL |
1 | /* |
2 | * In-kernel rpcbind client supporting versions 2, 3, and 4 of the rpcbind | |
3 | * protocol | |
4 | * | |
5 | * Based on RFC 1833: "Binding Protocols for ONC RPC Version 2" and | |
6 | * RFC 3530: "Network File System (NFS) version 4 Protocol" | |
7 | * | |
8 | * Original: Gilles Quillard, Bull Open Source, 2005 <gilles.quillard@bull.net> | |
9 | * Updated: Chuck Lever, Oracle Corporation, 2007 <chuck.lever@oracle.com> | |
10 | * | |
11 | * Descended from net/sunrpc/pmap_clnt.c, | |
12 | * Copyright (C) 1996, Olaf Kirch <okir@monad.swb.de> | |
13 | */ | |
14 | ||
cce63cd6 CL |
15 | #include <linux/module.h> |
16 | ||
a509050b CL |
17 | #include <linux/types.h> |
18 | #include <linux/socket.h> | |
d5b64430 CL |
19 | #include <linux/in.h> |
20 | #include <linux/in6.h> | |
a509050b CL |
21 | #include <linux/kernel.h> |
22 | #include <linux/errno.h> | |
c526611d | 23 | #include <linux/mutex.h> |
5a0e3ad6 | 24 | #include <linux/slab.h> |
9d548b9c | 25 | #include <net/ipv6.h> |
a509050b CL |
26 | |
27 | #include <linux/sunrpc/clnt.h> | |
28 | #include <linux/sunrpc/sched.h> | |
0896a725 | 29 | #include <linux/sunrpc/xprtsock.h> |
a509050b CL |
30 | |
31 | #ifdef RPC_DEBUG | |
32 | # define RPCDBG_FACILITY RPCDBG_BIND | |
33 | #endif | |
34 | ||
35 | #define RPCBIND_PROGRAM (100000u) | |
36 | #define RPCBIND_PORT (111u) | |
37 | ||
fc200e79 CL |
38 | #define RPCBVERS_2 (2u) |
39 | #define RPCBVERS_3 (3u) | |
40 | #define RPCBVERS_4 (4u) | |
41 | ||
a509050b CL |
42 | enum { |
43 | RPCBPROC_NULL, | |
44 | RPCBPROC_SET, | |
45 | RPCBPROC_UNSET, | |
46 | RPCBPROC_GETPORT, | |
47 | RPCBPROC_GETADDR = 3, /* alias for GETPORT */ | |
48 | RPCBPROC_DUMP, | |
49 | RPCBPROC_CALLIT, | |
50 | RPCBPROC_BCAST = 5, /* alias for CALLIT */ | |
51 | RPCBPROC_GETTIME, | |
52 | RPCBPROC_UADDR2TADDR, | |
53 | RPCBPROC_TADDR2UADDR, | |
54 | RPCBPROC_GETVERSADDR, | |
55 | RPCBPROC_INDIRECT, | |
56 | RPCBPROC_GETADDRLIST, | |
57 | RPCBPROC_GETSTAT, | |
58 | }; | |
59 | ||
a509050b CL |
60 | /* |
61 | * r_owner | |
62 | * | |
63 | * The "owner" is allowed to unset a service in the rpcbind database. | |
126e4bc3 CL |
64 | * |
65 | * For AF_LOCAL SET/UNSET requests, rpcbind treats this string as a | |
66 | * UID which it maps to a local user name via a password lookup. | |
67 | * In all other cases it is ignored. | |
68 | * | |
69 | * For SET/UNSET requests, user space provides a value, even for | |
70 | * network requests, and GETADDR uses an empty string. We follow | |
71 | * those precedents here. | |
a509050b | 72 | */ |
126e4bc3 | 73 | #define RPCB_OWNER_STRING "0" |
a509050b CL |
74 | #define RPCB_MAXOWNERLEN sizeof(RPCB_OWNER_STRING) |
75 | ||
0b10bf5e CL |
76 | /* |
77 | * XDR data type sizes | |
78 | */ | |
79 | #define RPCB_program_sz (1) | |
80 | #define RPCB_version_sz (1) | |
81 | #define RPCB_protocol_sz (1) | |
82 | #define RPCB_port_sz (1) | |
83 | #define RPCB_boolean_sz (1) | |
84 | ||
85 | #define RPCB_netid_sz (1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN)) | |
86 | #define RPCB_addr_sz (1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN)) | |
87 | #define RPCB_ownerstring_sz (1 + XDR_QUADLEN(RPCB_MAXOWNERLEN)) | |
88 | ||
89 | /* | |
90 | * XDR argument and result sizes | |
91 | */ | |
92 | #define RPCB_mappingargs_sz (RPCB_program_sz + RPCB_version_sz + \ | |
93 | RPCB_protocol_sz + RPCB_port_sz) | |
94 | #define RPCB_getaddrargs_sz (RPCB_program_sz + RPCB_version_sz + \ | |
95 | RPCB_netid_sz + RPCB_addr_sz + \ | |
96 | RPCB_ownerstring_sz) | |
97 | ||
98 | #define RPCB_getportres_sz RPCB_port_sz | |
99 | #define RPCB_setres_sz RPCB_boolean_sz | |
100 | ||
101 | /* | |
102 | * Note that RFC 1833 does not put any size restrictions on the | |
103 | * address string returned by the remote rpcbind database. | |
104 | */ | |
105 | #define RPCB_getaddrres_sz RPCB_addr_sz | |
106 | ||
a509050b | 107 | static void rpcb_getport_done(struct rpc_task *, void *); |
381ba74a | 108 | static void rpcb_map_release(void *data); |
7f4adeff | 109 | static struct rpc_program rpcb_program; |
a509050b | 110 | |
c526611d CL |
111 | static struct rpc_clnt * rpcb_local_clnt; |
112 | static struct rpc_clnt * rpcb_local_clnt4; | |
113 | ||
a509050b CL |
114 | struct rpcbind_args { |
115 | struct rpc_xprt * r_xprt; | |
116 | ||
117 | u32 r_prog; | |
118 | u32 r_vers; | |
119 | u32 r_prot; | |
120 | unsigned short r_port; | |
86d61d86 TM |
121 | const char * r_netid; |
122 | const char * r_addr; | |
123 | const char * r_owner; | |
381ba74a TM |
124 | |
125 | int r_status; | |
a509050b CL |
126 | }; |
127 | ||
128 | static struct rpc_procinfo rpcb_procedures2[]; | |
129 | static struct rpc_procinfo rpcb_procedures3[]; | |
c2e1b09f | 130 | static struct rpc_procinfo rpcb_procedures4[]; |
a509050b | 131 | |
d5b64430 | 132 | struct rpcb_info { |
fc200e79 | 133 | u32 rpc_vers; |
a509050b | 134 | struct rpc_procinfo * rpc_proc; |
d5b64430 CL |
135 | }; |
136 | ||
137 | static struct rpcb_info rpcb_next_version[]; | |
138 | static struct rpcb_info rpcb_next_version6[]; | |
a509050b | 139 | |
a509050b | 140 | static const struct rpc_call_ops rpcb_getport_ops = { |
a509050b CL |
141 | .rpc_call_done = rpcb_getport_done, |
142 | .rpc_release = rpcb_map_release, | |
143 | }; | |
144 | ||
145 | static void rpcb_wake_rpcbind_waiters(struct rpc_xprt *xprt, int status) | |
146 | { | |
147 | xprt_clear_binding(xprt); | |
148 | rpc_wake_up_status(&xprt->binding, status); | |
149 | } | |
150 | ||
381ba74a TM |
151 | static void rpcb_map_release(void *data) |
152 | { | |
153 | struct rpcbind_args *map = data; | |
154 | ||
155 | rpcb_wake_rpcbind_waiters(map->r_xprt, map->r_status); | |
156 | xprt_put(map->r_xprt); | |
ba809130 | 157 | kfree(map->r_addr); |
381ba74a TM |
158 | kfree(map); |
159 | } | |
160 | ||
cc5598b7 CL |
161 | static const struct sockaddr_in rpcb_inaddr_loopback = { |
162 | .sin_family = AF_INET, | |
163 | .sin_addr.s_addr = htonl(INADDR_LOOPBACK), | |
164 | .sin_port = htons(RPCBIND_PORT), | |
165 | }; | |
166 | ||
c526611d CL |
167 | static DEFINE_MUTEX(rpcb_create_local_mutex); |
168 | ||
169 | /* | |
170 | * Returns zero on success, otherwise a negative errno value | |
171 | * is returned. | |
172 | */ | |
173 | static int rpcb_create_local(void) | |
cc5598b7 CL |
174 | { |
175 | struct rpc_create_args args = { | |
c653ce3f | 176 | .net = &init_net, |
2a76b3bf | 177 | .protocol = XPRT_TRANSPORT_TCP, |
5a462115 CL |
178 | .address = (struct sockaddr *)&rpcb_inaddr_loopback, |
179 | .addrsize = sizeof(rpcb_inaddr_loopback), | |
cc5598b7 CL |
180 | .servername = "localhost", |
181 | .program = &rpcb_program, | |
c526611d | 182 | .version = RPCBVERS_2, |
cc5598b7 CL |
183 | .authflavor = RPC_AUTH_UNIX, |
184 | .flags = RPC_CLNT_CREATE_NOPING, | |
185 | }; | |
c526611d CL |
186 | struct rpc_clnt *clnt, *clnt4; |
187 | int result = 0; | |
188 | ||
189 | if (rpcb_local_clnt) | |
190 | return result; | |
191 | ||
192 | mutex_lock(&rpcb_create_local_mutex); | |
193 | if (rpcb_local_clnt) | |
194 | goto out; | |
195 | ||
196 | clnt = rpc_create(&args); | |
197 | if (IS_ERR(clnt)) { | |
198 | dprintk("RPC: failed to create local rpcbind " | |
199 | "client (errno %ld).\n", PTR_ERR(clnt)); | |
200 | result = -PTR_ERR(clnt); | |
201 | goto out; | |
202 | } | |
cc5598b7 | 203 | |
c526611d CL |
204 | /* |
205 | * This results in an RPC ping. On systems running portmapper, | |
206 | * the v4 ping will fail. Proceed anyway, but disallow rpcb | |
207 | * v4 upcalls. | |
208 | */ | |
209 | clnt4 = rpc_bind_new_program(clnt, &rpcb_program, RPCBVERS_4); | |
210 | if (IS_ERR(clnt4)) { | |
38359352 CL |
211 | dprintk("RPC: failed to bind second program to " |
212 | "rpcbind v4 client (errno %ld).\n", | |
213 | PTR_ERR(clnt4)); | |
c526611d CL |
214 | clnt4 = NULL; |
215 | } | |
216 | ||
217 | rpcb_local_clnt = clnt; | |
218 | rpcb_local_clnt4 = clnt4; | |
219 | ||
220 | out: | |
221 | mutex_unlock(&rpcb_create_local_mutex); | |
222 | return result; | |
cc5598b7 CL |
223 | } |
224 | ||
a509050b | 225 | static struct rpc_clnt *rpcb_create(char *hostname, struct sockaddr *srvaddr, |
423d8b06 | 226 | size_t salen, int proto, u32 version) |
a509050b CL |
227 | { |
228 | struct rpc_create_args args = { | |
c653ce3f | 229 | .net = &init_net, |
a509050b CL |
230 | .protocol = proto, |
231 | .address = srvaddr, | |
9f6ad26d | 232 | .addrsize = salen, |
a509050b CL |
233 | .servername = hostname, |
234 | .program = &rpcb_program, | |
235 | .version = version, | |
236 | .authflavor = RPC_AUTH_UNIX, | |
423d8b06 CL |
237 | .flags = (RPC_CLNT_CREATE_NOPING | |
238 | RPC_CLNT_CREATE_NONPRIVPORT), | |
a509050b CL |
239 | }; |
240 | ||
d5b64430 CL |
241 | switch (srvaddr->sa_family) { |
242 | case AF_INET: | |
243 | ((struct sockaddr_in *)srvaddr)->sin_port = htons(RPCBIND_PORT); | |
244 | break; | |
245 | case AF_INET6: | |
246 | ((struct sockaddr_in6 *)srvaddr)->sin6_port = htons(RPCBIND_PORT); | |
247 | break; | |
248 | default: | |
c636b572 | 249 | return ERR_PTR(-EAFNOSUPPORT); |
d5b64430 CL |
250 | } |
251 | ||
a509050b CL |
252 | return rpc_create(&args); |
253 | } | |
254 | ||
c526611d | 255 | static int rpcb_register_call(struct rpc_clnt *clnt, struct rpc_message *msg) |
babe80eb | 256 | { |
14aeb211 | 257 | int result, error = 0; |
babe80eb | 258 | |
14aeb211 | 259 | msg->rpc_resp = &result; |
babe80eb | 260 | |
2a76b3bf | 261 | error = rpc_call_sync(clnt, msg, RPC_TASK_SOFTCONN); |
14aeb211 | 262 | if (error < 0) { |
363f724c | 263 | dprintk("RPC: failed to contact local rpcbind " |
babe80eb | 264 | "server (errno %d).\n", -error); |
14aeb211 CL |
265 | return error; |
266 | } | |
267 | ||
db820d63 | 268 | if (!result) |
14aeb211 | 269 | return -EACCES; |
14aeb211 | 270 | return 0; |
babe80eb CL |
271 | } |
272 | ||
a509050b CL |
273 | /** |
274 | * rpcb_register - set or unset a port registration with the local rpcbind svc | |
275 | * @prog: RPC program number to bind | |
276 | * @vers: RPC version number to bind | |
c2e1b09f | 277 | * @prot: transport protocol to register |
a509050b | 278 | * @port: port value to register |
14aeb211 CL |
279 | * |
280 | * Returns zero if the registration request was dispatched successfully | |
281 | * and the rpcbind daemon returned success. Otherwise, returns an errno | |
282 | * value that reflects the nature of the error (request could not be | |
283 | * dispatched, timed out, or rpcbind returned an error). | |
c2e1b09f CL |
284 | * |
285 | * RPC services invoke this function to advertise their contact | |
286 | * information via the system's rpcbind daemon. RPC services | |
287 | * invoke this function once for each [program, version, transport] | |
288 | * tuple they wish to advertise. | |
289 | * | |
290 | * Callers may also unregister RPC services that are no longer | |
291 | * available by setting the passed-in port to zero. This removes | |
292 | * all registered transports for [program, version] from the local | |
293 | * rpcbind database. | |
294 | * | |
c2e1b09f CL |
295 | * This function uses rpcbind protocol version 2 to contact the |
296 | * local rpcbind daemon. | |
297 | * | |
298 | * Registration works over both AF_INET and AF_INET6, and services | |
299 | * registered via this function are advertised as available for any | |
300 | * address. If the local rpcbind daemon is listening on AF_INET6, | |
301 | * services registered via this function will be advertised on | |
302 | * IN6ADDR_ANY (ie available for all AF_INET and AF_INET6 | |
303 | * addresses). | |
a509050b | 304 | */ |
14aeb211 | 305 | int rpcb_register(u32 prog, u32 vers, int prot, unsigned short port) |
a509050b | 306 | { |
a509050b CL |
307 | struct rpcbind_args map = { |
308 | .r_prog = prog, | |
309 | .r_vers = vers, | |
310 | .r_prot = prot, | |
311 | .r_port = port, | |
312 | }; | |
313 | struct rpc_message msg = { | |
a509050b | 314 | .rpc_argp = &map, |
a509050b | 315 | }; |
c526611d CL |
316 | int error; |
317 | ||
318 | error = rpcb_create_local(); | |
319 | if (error) | |
320 | return error; | |
a509050b CL |
321 | |
322 | dprintk("RPC: %sregistering (%u, %u, %d, %u) with local " | |
323 | "rpcbind\n", (port ? "" : "un"), | |
324 | prog, vers, prot, port); | |
325 | ||
babe80eb CL |
326 | msg.rpc_proc = &rpcb_procedures2[RPCBPROC_UNSET]; |
327 | if (port) | |
328 | msg.rpc_proc = &rpcb_procedures2[RPCBPROC_SET]; | |
a509050b | 329 | |
c526611d | 330 | return rpcb_register_call(rpcb_local_clnt, &msg); |
a509050b CL |
331 | } |
332 | ||
c2e1b09f CL |
333 | /* |
334 | * Fill in AF_INET family-specific arguments to register | |
335 | */ | |
1673d0de CL |
336 | static int rpcb_register_inet4(const struct sockaddr *sap, |
337 | struct rpc_message *msg) | |
c2e1b09f | 338 | { |
3aba4553 | 339 | const struct sockaddr_in *sin = (const struct sockaddr_in *)sap; |
c2e1b09f | 340 | struct rpcbind_args *map = msg->rpc_argp; |
3aba4553 | 341 | unsigned short port = ntohs(sin->sin_port); |
ba809130 | 342 | int result; |
c2e1b09f | 343 | |
ba809130 | 344 | map->r_addr = rpc_sockaddr2uaddr(sap); |
c2e1b09f CL |
345 | |
346 | dprintk("RPC: %sregistering [%u, %u, %s, '%s'] with " | |
347 | "local rpcbind\n", (port ? "" : "un"), | |
348 | map->r_prog, map->r_vers, | |
349 | map->r_addr, map->r_netid); | |
350 | ||
351 | msg->rpc_proc = &rpcb_procedures4[RPCBPROC_UNSET]; | |
352 | if (port) | |
353 | msg->rpc_proc = &rpcb_procedures4[RPCBPROC_SET]; | |
354 | ||
c526611d | 355 | result = rpcb_register_call(rpcb_local_clnt4, msg); |
ba809130 CL |
356 | kfree(map->r_addr); |
357 | return result; | |
c2e1b09f CL |
358 | } |
359 | ||
360 | /* | |
361 | * Fill in AF_INET6 family-specific arguments to register | |
362 | */ | |
1673d0de CL |
363 | static int rpcb_register_inet6(const struct sockaddr *sap, |
364 | struct rpc_message *msg) | |
c2e1b09f | 365 | { |
3aba4553 | 366 | const struct sockaddr_in6 *sin6 = (const struct sockaddr_in6 *)sap; |
c2e1b09f | 367 | struct rpcbind_args *map = msg->rpc_argp; |
3aba4553 | 368 | unsigned short port = ntohs(sin6->sin6_port); |
ba809130 | 369 | int result; |
c2e1b09f | 370 | |
ba809130 | 371 | map->r_addr = rpc_sockaddr2uaddr(sap); |
c2e1b09f CL |
372 | |
373 | dprintk("RPC: %sregistering [%u, %u, %s, '%s'] with " | |
374 | "local rpcbind\n", (port ? "" : "un"), | |
375 | map->r_prog, map->r_vers, | |
376 | map->r_addr, map->r_netid); | |
377 | ||
378 | msg->rpc_proc = &rpcb_procedures4[RPCBPROC_UNSET]; | |
379 | if (port) | |
380 | msg->rpc_proc = &rpcb_procedures4[RPCBPROC_SET]; | |
381 | ||
c526611d | 382 | result = rpcb_register_call(rpcb_local_clnt4, msg); |
ba809130 CL |
383 | kfree(map->r_addr); |
384 | return result; | |
c2e1b09f CL |
385 | } |
386 | ||
1673d0de CL |
387 | static int rpcb_unregister_all_protofamilies(struct rpc_message *msg) |
388 | { | |
389 | struct rpcbind_args *map = msg->rpc_argp; | |
390 | ||
391 | dprintk("RPC: unregistering [%u, %u, '%s'] with " | |
392 | "local rpcbind\n", | |
393 | map->r_prog, map->r_vers, map->r_netid); | |
394 | ||
395 | map->r_addr = ""; | |
396 | msg->rpc_proc = &rpcb_procedures4[RPCBPROC_UNSET]; | |
397 | ||
c526611d | 398 | return rpcb_register_call(rpcb_local_clnt4, msg); |
1673d0de CL |
399 | } |
400 | ||
c2e1b09f CL |
401 | /** |
402 | * rpcb_v4_register - set or unset a port registration with the local rpcbind | |
403 | * @program: RPC program number of service to (un)register | |
404 | * @version: RPC version number of service to (un)register | |
405 | * @address: address family, IP address, and port to (un)register | |
406 | * @netid: netid of transport protocol to (un)register | |
14aeb211 CL |
407 | * |
408 | * Returns zero if the registration request was dispatched successfully | |
409 | * and the rpcbind daemon returned success. Otherwise, returns an errno | |
410 | * value that reflects the nature of the error (request could not be | |
411 | * dispatched, timed out, or rpcbind returned an error). | |
c2e1b09f CL |
412 | * |
413 | * RPC services invoke this function to advertise their contact | |
414 | * information via the system's rpcbind daemon. RPC services | |
415 | * invoke this function once for each [program, version, address, | |
416 | * netid] tuple they wish to advertise. | |
417 | * | |
1673d0de CL |
418 | * Callers may also unregister RPC services that are registered at a |
419 | * specific address by setting the port number in @address to zero. | |
420 | * They may unregister all registered protocol families at once for | |
421 | * a service by passing a NULL @address argument. If @netid is "" | |
422 | * then all netids for [program, version, address] are unregistered. | |
c2e1b09f | 423 | * |
c2e1b09f CL |
424 | * This function uses rpcbind protocol version 4 to contact the |
425 | * local rpcbind daemon. The local rpcbind daemon must support | |
426 | * version 4 of the rpcbind protocol in order for these functions | |
427 | * to register a service successfully. | |
428 | * | |
429 | * Supported netids include "udp" and "tcp" for UDP and TCP over | |
430 | * IPv4, and "udp6" and "tcp6" for UDP and TCP over IPv6, | |
431 | * respectively. | |
432 | * | |
433 | * The contents of @address determine the address family and the | |
434 | * port to be registered. The usual practice is to pass INADDR_ANY | |
435 | * as the raw address, but specifying a non-zero address is also | |
436 | * supported by this API if the caller wishes to advertise an RPC | |
437 | * service on a specific network interface. | |
438 | * | |
439 | * Note that passing in INADDR_ANY does not create the same service | |
440 | * registration as IN6ADDR_ANY. The former advertises an RPC | |
441 | * service on any IPv4 address, but not on IPv6. The latter | |
442 | * advertises the service on all IPv4 and IPv6 addresses. | |
443 | */ | |
444 | int rpcb_v4_register(const u32 program, const u32 version, | |
14aeb211 | 445 | const struct sockaddr *address, const char *netid) |
c2e1b09f CL |
446 | { |
447 | struct rpcbind_args map = { | |
448 | .r_prog = program, | |
449 | .r_vers = version, | |
450 | .r_netid = netid, | |
451 | .r_owner = RPCB_OWNER_STRING, | |
452 | }; | |
453 | struct rpc_message msg = { | |
454 | .rpc_argp = &map, | |
c2e1b09f | 455 | }; |
c526611d CL |
456 | int error; |
457 | ||
458 | error = rpcb_create_local(); | |
459 | if (error) | |
460 | return error; | |
461 | if (rpcb_local_clnt4 == NULL) | |
462 | return -EPROTONOSUPPORT; | |
c2e1b09f | 463 | |
1673d0de CL |
464 | if (address == NULL) |
465 | return rpcb_unregister_all_protofamilies(&msg); | |
466 | ||
c2e1b09f CL |
467 | switch (address->sa_family) { |
468 | case AF_INET: | |
1673d0de | 469 | return rpcb_register_inet4(address, &msg); |
c2e1b09f | 470 | case AF_INET6: |
1673d0de | 471 | return rpcb_register_inet6(address, &msg); |
c2e1b09f CL |
472 | } |
473 | ||
474 | return -EAFNOSUPPORT; | |
475 | } | |
476 | ||
803a9067 | 477 | static struct rpc_task *rpcb_call_async(struct rpc_clnt *rpcb_clnt, struct rpcbind_args *map, struct rpc_procinfo *proc) |
5138fde0 TM |
478 | { |
479 | struct rpc_message msg = { | |
803a9067 | 480 | .rpc_proc = proc, |
5138fde0 | 481 | .rpc_argp = map, |
c0c077df | 482 | .rpc_resp = map, |
5138fde0 TM |
483 | }; |
484 | struct rpc_task_setup task_setup_data = { | |
485 | .rpc_client = rpcb_clnt, | |
486 | .rpc_message = &msg, | |
487 | .callback_ops = &rpcb_getport_ops, | |
488 | .callback_data = map, | |
012da158 | 489 | .flags = RPC_TASK_ASYNC | RPC_TASK_SOFTCONN, |
5138fde0 TM |
490 | }; |
491 | ||
492 | return rpc_run_task(&task_setup_data); | |
493 | } | |
494 | ||
9a4bd29f TM |
495 | /* |
496 | * In the case where rpc clients have been cloned, we want to make | |
497 | * sure that we use the program number/version etc of the actual | |
498 | * owner of the xprt. To do so, we walk back up the tree of parents | |
499 | * to find whoever created the transport and/or whoever has the | |
500 | * autobind flag set. | |
501 | */ | |
502 | static struct rpc_clnt *rpcb_find_transport_owner(struct rpc_clnt *clnt) | |
503 | { | |
504 | struct rpc_clnt *parent = clnt->cl_parent; | |
505 | ||
506 | while (parent != clnt) { | |
507 | if (parent->cl_xprt != clnt->cl_xprt) | |
508 | break; | |
509 | if (clnt->cl_autobind) | |
510 | break; | |
511 | clnt = parent; | |
512 | parent = parent->cl_parent; | |
513 | } | |
514 | return clnt; | |
515 | } | |
516 | ||
a509050b | 517 | /** |
45160d62 | 518 | * rpcb_getport_async - obtain the port for a given RPC service on a given host |
a509050b CL |
519 | * @task: task that is waiting for portmapper request |
520 | * | |
521 | * This one can be called for an ongoing RPC request, and can be used in | |
522 | * an async (rpciod) context. | |
523 | */ | |
45160d62 | 524 | void rpcb_getport_async(struct rpc_task *task) |
a509050b | 525 | { |
9a4bd29f | 526 | struct rpc_clnt *clnt; |
803a9067 | 527 | struct rpc_procinfo *proc; |
0a48f5d7 | 528 | u32 bind_version; |
9a4bd29f | 529 | struct rpc_xprt *xprt; |
a509050b CL |
530 | struct rpc_clnt *rpcb_clnt; |
531 | static struct rpcbind_args *map; | |
532 | struct rpc_task *child; | |
9f6ad26d CL |
533 | struct sockaddr_storage addr; |
534 | struct sockaddr *sap = (struct sockaddr *)&addr; | |
535 | size_t salen; | |
a509050b CL |
536 | int status; |
537 | ||
9a4bd29f TM |
538 | clnt = rpcb_find_transport_owner(task->tk_client); |
539 | xprt = clnt->cl_xprt; | |
540 | ||
45160d62 | 541 | dprintk("RPC: %5u %s(%s, %u, %u, %d)\n", |
0dc47877 | 542 | task->tk_pid, __func__, |
45160d62 | 543 | clnt->cl_server, clnt->cl_prog, clnt->cl_vers, xprt->prot); |
a509050b | 544 | |
381ba74a TM |
545 | /* Put self on the wait queue to ensure we get notified if |
546 | * some other task is already attempting to bind the port */ | |
547 | rpc_sleep_on(&xprt->binding, task, NULL); | |
548 | ||
a509050b | 549 | if (xprt_test_and_set_binding(xprt)) { |
45160d62 | 550 | dprintk("RPC: %5u %s: waiting for another binder\n", |
0dc47877 | 551 | task->tk_pid, __func__); |
381ba74a | 552 | return; |
a509050b CL |
553 | } |
554 | ||
a509050b CL |
555 | /* Someone else may have bound if we slept */ |
556 | if (xprt_bound(xprt)) { | |
557 | status = 0; | |
45160d62 | 558 | dprintk("RPC: %5u %s: already bound\n", |
0dc47877 | 559 | task->tk_pid, __func__); |
a509050b CL |
560 | goto bailout_nofree; |
561 | } | |
562 | ||
ba809130 | 563 | /* Parent transport's destination address */ |
9f6ad26d | 564 | salen = rpc_peeraddr(clnt, sap, sizeof(addr)); |
d5b64430 CL |
565 | |
566 | /* Don't ever use rpcbind v2 for AF_INET6 requests */ | |
9f6ad26d | 567 | switch (sap->sa_family) { |
d5b64430 | 568 | case AF_INET: |
803a9067 TM |
569 | proc = rpcb_next_version[xprt->bind_index].rpc_proc; |
570 | bind_version = rpcb_next_version[xprt->bind_index].rpc_vers; | |
d5b64430 CL |
571 | break; |
572 | case AF_INET6: | |
803a9067 TM |
573 | proc = rpcb_next_version6[xprt->bind_index].rpc_proc; |
574 | bind_version = rpcb_next_version6[xprt->bind_index].rpc_vers; | |
d5b64430 CL |
575 | break; |
576 | default: | |
577 | status = -EAFNOSUPPORT; | |
578 | dprintk("RPC: %5u %s: bad address family\n", | |
0dc47877 | 579 | task->tk_pid, __func__); |
d5b64430 CL |
580 | goto bailout_nofree; |
581 | } | |
803a9067 | 582 | if (proc == NULL) { |
a509050b | 583 | xprt->bind_index = 0; |
906462af | 584 | status = -EPFNOSUPPORT; |
45160d62 | 585 | dprintk("RPC: %5u %s: no more getport versions available\n", |
0dc47877 | 586 | task->tk_pid, __func__); |
a509050b CL |
587 | goto bailout_nofree; |
588 | } | |
a509050b | 589 | |
45160d62 | 590 | dprintk("RPC: %5u %s: trying rpcbind version %u\n", |
0dc47877 | 591 | task->tk_pid, __func__, bind_version); |
a509050b | 592 | |
9f6ad26d | 593 | rpcb_clnt = rpcb_create(clnt->cl_server, sap, salen, xprt->prot, |
423d8b06 | 594 | bind_version); |
143b6c40 CL |
595 | if (IS_ERR(rpcb_clnt)) { |
596 | status = PTR_ERR(rpcb_clnt); | |
597 | dprintk("RPC: %5u %s: rpcb_create failed, error %ld\n", | |
0dc47877 | 598 | task->tk_pid, __func__, PTR_ERR(rpcb_clnt)); |
143b6c40 CL |
599 | goto bailout_nofree; |
600 | } | |
601 | ||
a509050b CL |
602 | map = kzalloc(sizeof(struct rpcbind_args), GFP_ATOMIC); |
603 | if (!map) { | |
604 | status = -ENOMEM; | |
45160d62 | 605 | dprintk("RPC: %5u %s: no memory available\n", |
0dc47877 | 606 | task->tk_pid, __func__); |
96165e2b | 607 | goto bailout_release_client; |
a509050b CL |
608 | } |
609 | map->r_prog = clnt->cl_prog; | |
610 | map->r_vers = clnt->cl_vers; | |
611 | map->r_prot = xprt->prot; | |
612 | map->r_port = 0; | |
613 | map->r_xprt = xprt_get(xprt); | |
381ba74a | 614 | map->r_status = -EIO; |
a509050b | 615 | |
ba809130 CL |
616 | switch (bind_version) { |
617 | case RPCBVERS_4: | |
618 | case RPCBVERS_3: | |
619 | map->r_netid = rpc_peeraddr2str(clnt, RPC_DISPLAY_NETID); | |
620 | map->r_addr = rpc_sockaddr2uaddr(sap); | |
621 | map->r_owner = ""; | |
622 | break; | |
623 | case RPCBVERS_2: | |
624 | map->r_addr = NULL; | |
625 | break; | |
626 | default: | |
627 | BUG(); | |
628 | } | |
629 | ||
803a9067 | 630 | child = rpcb_call_async(rpcb_clnt, map, proc); |
4c402b40 | 631 | rpc_release_client(rpcb_clnt); |
a509050b | 632 | if (IS_ERR(child)) { |
0d3a34b4 | 633 | /* rpcb_map_release() has freed the arguments */ |
45160d62 | 634 | dprintk("RPC: %5u %s: rpc_run_task failed\n", |
0dc47877 | 635 | task->tk_pid, __func__); |
381ba74a | 636 | return; |
a509050b | 637 | } |
a509050b | 638 | |
9a4bd29f TM |
639 | xprt->stat.bind_count++; |
640 | rpc_put_task(child); | |
a509050b CL |
641 | return; |
642 | ||
96165e2b TM |
643 | bailout_release_client: |
644 | rpc_release_client(rpcb_clnt); | |
a509050b CL |
645 | bailout_nofree: |
646 | rpcb_wake_rpcbind_waiters(xprt, status); | |
a509050b CL |
647 | task->tk_status = status; |
648 | } | |
12444809 | 649 | EXPORT_SYMBOL_GPL(rpcb_getport_async); |
a509050b CL |
650 | |
651 | /* | |
652 | * Rpcbind child task calls this callback via tk_exit. | |
653 | */ | |
654 | static void rpcb_getport_done(struct rpc_task *child, void *data) | |
655 | { | |
656 | struct rpcbind_args *map = data; | |
657 | struct rpc_xprt *xprt = map->r_xprt; | |
658 | int status = child->tk_status; | |
659 | ||
4784cb51 CL |
660 | /* Garbage reply: retry with a lesser rpcbind version */ |
661 | if (status == -EIO) | |
662 | status = -EPROTONOSUPPORT; | |
663 | ||
a509050b CL |
664 | /* rpcbind server doesn't support this rpcbind protocol version */ |
665 | if (status == -EPROTONOSUPPORT) | |
666 | xprt->bind_index++; | |
667 | ||
668 | if (status < 0) { | |
669 | /* rpcbind server not available on remote host? */ | |
670 | xprt->ops->set_port(xprt, 0); | |
671 | } else if (map->r_port == 0) { | |
672 | /* Requested RPC service wasn't registered on remote host */ | |
673 | xprt->ops->set_port(xprt, 0); | |
674 | status = -EACCES; | |
675 | } else { | |
676 | /* Succeeded */ | |
677 | xprt->ops->set_port(xprt, map->r_port); | |
678 | xprt_set_bound(xprt); | |
679 | status = 0; | |
680 | } | |
681 | ||
682 | dprintk("RPC: %5u rpcb_getport_done(status %d, port %u)\n", | |
683 | child->tk_pid, status, map->r_port); | |
684 | ||
381ba74a | 685 | map->r_status = status; |
a509050b CL |
686 | } |
687 | ||
166b88d7 CL |
688 | /* |
689 | * XDR functions for rpcbind | |
690 | */ | |
691 | ||
9f06c719 CL |
692 | static void rpcb_enc_mapping(struct rpc_rqst *req, struct xdr_stream *xdr, |
693 | const struct rpcbind_args *rpcb) | |
6f2c2db7 CL |
694 | { |
695 | struct rpc_task *task = req->rq_task; | |
9f06c719 | 696 | __be32 *p; |
6f2c2db7 CL |
697 | |
698 | dprintk("RPC: %5u encoding PMAP_%s call (%u, %u, %d, %u)\n", | |
699 | task->tk_pid, task->tk_msg.rpc_proc->p_name, | |
700 | rpcb->r_prog, rpcb->r_vers, rpcb->r_prot, rpcb->r_port); | |
701 | ||
9f06c719 | 702 | p = xdr_reserve_space(xdr, RPCB_mappingargs_sz << 2); |
4129ccf3 CL |
703 | *p++ = cpu_to_be32(rpcb->r_prog); |
704 | *p++ = cpu_to_be32(rpcb->r_vers); | |
705 | *p++ = cpu_to_be32(rpcb->r_prot); | |
706 | *p = cpu_to_be32(rpcb->r_port); | |
6f2c2db7 CL |
707 | } |
708 | ||
c0c077df CL |
709 | static int rpcb_dec_getport(struct rpc_rqst *req, __be32 *p, |
710 | struct rpcbind_args *rpcb) | |
711 | { | |
712 | struct rpc_task *task = req->rq_task; | |
713 | struct xdr_stream xdr; | |
714 | unsigned long port; | |
715 | ||
716 | xdr_init_decode(&xdr, &req->rq_rcv_buf, p); | |
717 | ||
718 | rpcb->r_port = 0; | |
719 | ||
4129ccf3 | 720 | p = xdr_inline_decode(&xdr, 4); |
c0c077df CL |
721 | if (unlikely(p == NULL)) |
722 | return -EIO; | |
723 | ||
4129ccf3 | 724 | port = be32_to_cpup(p); |
c0c077df CL |
725 | dprintk("RPC: %5u PMAP_%s result: %lu\n", task->tk_pid, |
726 | task->tk_msg.rpc_proc->p_name, port); | |
4be929be | 727 | if (unlikely(port > USHRT_MAX)) |
c0c077df CL |
728 | return -EIO; |
729 | ||
730 | rpcb->r_port = port; | |
731 | return 0; | |
732 | } | |
733 | ||
7ed0ff98 CL |
734 | static int rpcb_dec_set(struct rpc_rqst *req, __be32 *p, |
735 | unsigned int *boolp) | |
736 | { | |
737 | struct rpc_task *task = req->rq_task; | |
738 | struct xdr_stream xdr; | |
739 | ||
740 | xdr_init_decode(&xdr, &req->rq_rcv_buf, p); | |
741 | ||
4129ccf3 | 742 | p = xdr_inline_decode(&xdr, 4); |
7ed0ff98 CL |
743 | if (unlikely(p == NULL)) |
744 | return -EIO; | |
745 | ||
746 | *boolp = 0; | |
747 | if (*p) | |
748 | *boolp = 1; | |
749 | ||
750 | dprintk("RPC: %5u RPCB_%s call %s\n", | |
751 | task->tk_pid, task->tk_msg.rpc_proc->p_name, | |
752 | (*boolp ? "succeeded" : "failed")); | |
753 | return 0; | |
754 | } | |
755 | ||
4129ccf3 CL |
756 | static void encode_rpcb_string(struct xdr_stream *xdr, const char *string, |
757 | const u32 maxstrlen) | |
6f2c2db7 | 758 | { |
6f2c2db7 | 759 | __be32 *p; |
4129ccf3 | 760 | u32 len; |
6f2c2db7 | 761 | |
6f2c2db7 | 762 | len = strlen(string); |
4129ccf3 CL |
763 | BUG_ON(len > maxstrlen); |
764 | p = xdr_reserve_space(xdr, 4 + len); | |
6f2c2db7 | 765 | xdr_encode_opaque(p, string, len); |
6f2c2db7 CL |
766 | } |
767 | ||
9f06c719 CL |
768 | static void rpcb_enc_getaddr(struct rpc_rqst *req, struct xdr_stream *xdr, |
769 | const struct rpcbind_args *rpcb) | |
6f2c2db7 CL |
770 | { |
771 | struct rpc_task *task = req->rq_task; | |
9f06c719 | 772 | __be32 *p; |
6f2c2db7 CL |
773 | |
774 | dprintk("RPC: %5u encoding RPCB_%s call (%u, %u, '%s', '%s')\n", | |
775 | task->tk_pid, task->tk_msg.rpc_proc->p_name, | |
776 | rpcb->r_prog, rpcb->r_vers, | |
777 | rpcb->r_netid, rpcb->r_addr); | |
778 | ||
9f06c719 | 779 | p = xdr_reserve_space(xdr, (RPCB_program_sz + RPCB_version_sz) << 2); |
4129ccf3 CL |
780 | *p++ = cpu_to_be32(rpcb->r_prog); |
781 | *p = cpu_to_be32(rpcb->r_vers); | |
6f2c2db7 | 782 | |
9f06c719 CL |
783 | encode_rpcb_string(xdr, rpcb->r_netid, RPCBIND_MAXNETIDLEN); |
784 | encode_rpcb_string(xdr, rpcb->r_addr, RPCBIND_MAXUADDRLEN); | |
785 | encode_rpcb_string(xdr, rpcb->r_owner, RPCB_MAXOWNERLEN); | |
6f2c2db7 CL |
786 | } |
787 | ||
c0c077df CL |
788 | static int rpcb_dec_getaddr(struct rpc_rqst *req, __be32 *p, |
789 | struct rpcbind_args *rpcb) | |
790 | { | |
791 | struct sockaddr_storage address; | |
792 | struct sockaddr *sap = (struct sockaddr *)&address; | |
793 | struct rpc_task *task = req->rq_task; | |
794 | struct xdr_stream xdr; | |
795 | u32 len; | |
796 | ||
797 | rpcb->r_port = 0; | |
798 | ||
799 | xdr_init_decode(&xdr, &req->rq_rcv_buf, p); | |
800 | ||
4129ccf3 | 801 | p = xdr_inline_decode(&xdr, 4); |
c0c077df CL |
802 | if (unlikely(p == NULL)) |
803 | goto out_fail; | |
4129ccf3 | 804 | len = be32_to_cpup(p); |
c0c077df CL |
805 | |
806 | /* | |
807 | * If the returned universal address is a null string, | |
808 | * the requested RPC service was not registered. | |
809 | */ | |
810 | if (len == 0) { | |
811 | dprintk("RPC: %5u RPCB reply: program not registered\n", | |
812 | task->tk_pid); | |
813 | return 0; | |
814 | } | |
815 | ||
816 | if (unlikely(len > RPCBIND_MAXUADDRLEN)) | |
817 | goto out_fail; | |
818 | ||
819 | p = xdr_inline_decode(&xdr, len); | |
820 | if (unlikely(p == NULL)) | |
821 | goto out_fail; | |
822 | dprintk("RPC: %5u RPCB_%s reply: %s\n", task->tk_pid, | |
823 | task->tk_msg.rpc_proc->p_name, (char *)p); | |
824 | ||
825 | if (rpc_uaddr2sockaddr((char *)p, len, sap, sizeof(address)) == 0) | |
826 | goto out_fail; | |
827 | rpcb->r_port = rpc_get_port(sap); | |
828 | ||
829 | return 0; | |
830 | ||
831 | out_fail: | |
832 | dprintk("RPC: %5u malformed RPCB_%s reply\n", | |
833 | task->tk_pid, task->tk_msg.rpc_proc->p_name); | |
834 | return -EIO; | |
835 | } | |
836 | ||
a509050b CL |
837 | /* |
838 | * Not all rpcbind procedures described in RFC 1833 are implemented | |
839 | * since the Linux kernel RPC code requires only these. | |
840 | */ | |
f8b761ef | 841 | |
a509050b | 842 | static struct rpc_procinfo rpcb_procedures2[] = { |
f8b761ef CL |
843 | [RPCBPROC_SET] = { |
844 | .p_proc = RPCBPROC_SET, | |
9f06c719 | 845 | .p_encode = (kxdreproc_t)rpcb_enc_mapping, |
f8b761ef CL |
846 | .p_decode = (kxdrproc_t)rpcb_dec_set, |
847 | .p_arglen = RPCB_mappingargs_sz, | |
848 | .p_replen = RPCB_setres_sz, | |
849 | .p_statidx = RPCBPROC_SET, | |
850 | .p_timer = 0, | |
851 | .p_name = "SET", | |
852 | }, | |
853 | [RPCBPROC_UNSET] = { | |
854 | .p_proc = RPCBPROC_UNSET, | |
9f06c719 | 855 | .p_encode = (kxdreproc_t)rpcb_enc_mapping, |
f8b761ef CL |
856 | .p_decode = (kxdrproc_t)rpcb_dec_set, |
857 | .p_arglen = RPCB_mappingargs_sz, | |
858 | .p_replen = RPCB_setres_sz, | |
859 | .p_statidx = RPCBPROC_UNSET, | |
860 | .p_timer = 0, | |
861 | .p_name = "UNSET", | |
862 | }, | |
863 | [RPCBPROC_GETPORT] = { | |
864 | .p_proc = RPCBPROC_GETPORT, | |
9f06c719 | 865 | .p_encode = (kxdreproc_t)rpcb_enc_mapping, |
f8b761ef CL |
866 | .p_decode = (kxdrproc_t)rpcb_dec_getport, |
867 | .p_arglen = RPCB_mappingargs_sz, | |
868 | .p_replen = RPCB_getportres_sz, | |
869 | .p_statidx = RPCBPROC_GETPORT, | |
870 | .p_timer = 0, | |
871 | .p_name = "GETPORT", | |
872 | }, | |
a509050b CL |
873 | }; |
874 | ||
875 | static struct rpc_procinfo rpcb_procedures3[] = { | |
f8b761ef CL |
876 | [RPCBPROC_SET] = { |
877 | .p_proc = RPCBPROC_SET, | |
9f06c719 | 878 | .p_encode = (kxdreproc_t)rpcb_enc_getaddr, |
f8b761ef CL |
879 | .p_decode = (kxdrproc_t)rpcb_dec_set, |
880 | .p_arglen = RPCB_getaddrargs_sz, | |
881 | .p_replen = RPCB_setres_sz, | |
882 | .p_statidx = RPCBPROC_SET, | |
883 | .p_timer = 0, | |
884 | .p_name = "SET", | |
885 | }, | |
886 | [RPCBPROC_UNSET] = { | |
887 | .p_proc = RPCBPROC_UNSET, | |
9f06c719 | 888 | .p_encode = (kxdreproc_t)rpcb_enc_getaddr, |
f8b761ef CL |
889 | .p_decode = (kxdrproc_t)rpcb_dec_set, |
890 | .p_arglen = RPCB_getaddrargs_sz, | |
891 | .p_replen = RPCB_setres_sz, | |
892 | .p_statidx = RPCBPROC_UNSET, | |
893 | .p_timer = 0, | |
894 | .p_name = "UNSET", | |
895 | }, | |
896 | [RPCBPROC_GETADDR] = { | |
897 | .p_proc = RPCBPROC_GETADDR, | |
9f06c719 | 898 | .p_encode = (kxdreproc_t)rpcb_enc_getaddr, |
f8b761ef CL |
899 | .p_decode = (kxdrproc_t)rpcb_dec_getaddr, |
900 | .p_arglen = RPCB_getaddrargs_sz, | |
901 | .p_replen = RPCB_getaddrres_sz, | |
902 | .p_statidx = RPCBPROC_GETADDR, | |
903 | .p_timer = 0, | |
904 | .p_name = "GETADDR", | |
905 | }, | |
a509050b CL |
906 | }; |
907 | ||
908 | static struct rpc_procinfo rpcb_procedures4[] = { | |
f8b761ef CL |
909 | [RPCBPROC_SET] = { |
910 | .p_proc = RPCBPROC_SET, | |
9f06c719 | 911 | .p_encode = (kxdreproc_t)rpcb_enc_getaddr, |
f8b761ef CL |
912 | .p_decode = (kxdrproc_t)rpcb_dec_set, |
913 | .p_arglen = RPCB_getaddrargs_sz, | |
914 | .p_replen = RPCB_setres_sz, | |
915 | .p_statidx = RPCBPROC_SET, | |
916 | .p_timer = 0, | |
917 | .p_name = "SET", | |
918 | }, | |
919 | [RPCBPROC_UNSET] = { | |
920 | .p_proc = RPCBPROC_UNSET, | |
9f06c719 | 921 | .p_encode = (kxdreproc_t)rpcb_enc_getaddr, |
f8b761ef CL |
922 | .p_decode = (kxdrproc_t)rpcb_dec_set, |
923 | .p_arglen = RPCB_getaddrargs_sz, | |
924 | .p_replen = RPCB_setres_sz, | |
925 | .p_statidx = RPCBPROC_UNSET, | |
926 | .p_timer = 0, | |
927 | .p_name = "UNSET", | |
928 | }, | |
929 | [RPCBPROC_GETADDR] = { | |
930 | .p_proc = RPCBPROC_GETADDR, | |
9f06c719 | 931 | .p_encode = (kxdreproc_t)rpcb_enc_getaddr, |
f8b761ef CL |
932 | .p_decode = (kxdrproc_t)rpcb_dec_getaddr, |
933 | .p_arglen = RPCB_getaddrargs_sz, | |
934 | .p_replen = RPCB_getaddrres_sz, | |
935 | .p_statidx = RPCBPROC_GETADDR, | |
936 | .p_timer = 0, | |
937 | .p_name = "GETADDR", | |
938 | }, | |
a509050b CL |
939 | }; |
940 | ||
941 | static struct rpcb_info rpcb_next_version[] = { | |
fc200e79 CL |
942 | { |
943 | .rpc_vers = RPCBVERS_2, | |
944 | .rpc_proc = &rpcb_procedures2[RPCBPROC_GETPORT], | |
945 | }, | |
946 | { | |
947 | .rpc_proc = NULL, | |
948 | }, | |
a509050b CL |
949 | }; |
950 | ||
d5b64430 | 951 | static struct rpcb_info rpcb_next_version6[] = { |
fc200e79 CL |
952 | { |
953 | .rpc_vers = RPCBVERS_4, | |
8842413a | 954 | .rpc_proc = &rpcb_procedures4[RPCBPROC_GETADDR], |
fc200e79 CL |
955 | }, |
956 | { | |
957 | .rpc_vers = RPCBVERS_3, | |
958 | .rpc_proc = &rpcb_procedures3[RPCBPROC_GETADDR], | |
959 | }, | |
fc200e79 CL |
960 | { |
961 | .rpc_proc = NULL, | |
962 | }, | |
d5b64430 CL |
963 | }; |
964 | ||
a509050b | 965 | static struct rpc_version rpcb_version2 = { |
fc200e79 | 966 | .number = RPCBVERS_2, |
1ac7c23e | 967 | .nrprocs = ARRAY_SIZE(rpcb_procedures2), |
a509050b CL |
968 | .procs = rpcb_procedures2 |
969 | }; | |
970 | ||
971 | static struct rpc_version rpcb_version3 = { | |
fc200e79 | 972 | .number = RPCBVERS_3, |
1ac7c23e | 973 | .nrprocs = ARRAY_SIZE(rpcb_procedures3), |
a509050b CL |
974 | .procs = rpcb_procedures3 |
975 | }; | |
976 | ||
977 | static struct rpc_version rpcb_version4 = { | |
fc200e79 | 978 | .number = RPCBVERS_4, |
1ac7c23e | 979 | .nrprocs = ARRAY_SIZE(rpcb_procedures4), |
a509050b CL |
980 | .procs = rpcb_procedures4 |
981 | }; | |
982 | ||
983 | static struct rpc_version *rpcb_version[] = { | |
984 | NULL, | |
985 | NULL, | |
986 | &rpcb_version2, | |
987 | &rpcb_version3, | |
988 | &rpcb_version4 | |
989 | }; | |
990 | ||
991 | static struct rpc_stat rpcb_stats; | |
992 | ||
7f4adeff | 993 | static struct rpc_program rpcb_program = { |
a509050b CL |
994 | .name = "rpcbind", |
995 | .number = RPCBIND_PROGRAM, | |
996 | .nrvers = ARRAY_SIZE(rpcb_version), | |
997 | .version = rpcb_version, | |
998 | .stats = &rpcb_stats, | |
999 | }; | |
c526611d CL |
1000 | |
1001 | /** | |
1002 | * cleanup_rpcb_clnt - remove xprtsock's sysctls, unregister | |
1003 | * | |
1004 | */ | |
1005 | void cleanup_rpcb_clnt(void) | |
1006 | { | |
1007 | if (rpcb_local_clnt4) | |
1008 | rpc_shutdown_client(rpcb_local_clnt4); | |
1009 | if (rpcb_local_clnt) | |
1010 | rpc_shutdown_client(rpcb_local_clnt); | |
1011 | } |