Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 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 | |
Chuck Lever | cce63cd | 2007-07-01 12:13:12 -0400 | [diff] [blame] | 15 | #include <linux/module.h> |
| 16 | |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 17 | #include <linux/types.h> |
| 18 | #include <linux/socket.h> |
Chuck Lever | d5b6443 | 2007-08-06 11:57:18 -0400 | [diff] [blame] | 19 | #include <linux/in.h> |
| 20 | #include <linux/in6.h> |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 21 | #include <linux/kernel.h> |
| 22 | #include <linux/errno.h> |
Chuck Lever | c526611 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 23 | #include <linux/mutex.h> |
Chuck Lever | 9d548b9 | 2008-09-15 16:27:30 -0500 | [diff] [blame] | 24 | #include <net/ipv6.h> |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 25 | |
| 26 | #include <linux/sunrpc/clnt.h> |
| 27 | #include <linux/sunrpc/sched.h> |
\"Talpey, Thomas\ | 0896a72 | 2007-09-10 13:48:23 -0400 | [diff] [blame] | 28 | #include <linux/sunrpc/xprtsock.h> |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 29 | |
| 30 | #ifdef RPC_DEBUG |
| 31 | # define RPCDBG_FACILITY RPCDBG_BIND |
| 32 | #endif |
| 33 | |
| 34 | #define RPCBIND_PROGRAM (100000u) |
| 35 | #define RPCBIND_PORT (111u) |
| 36 | |
Chuck Lever | fc200e7 | 2008-06-25 17:24:31 -0400 | [diff] [blame] | 37 | #define RPCBVERS_2 (2u) |
| 38 | #define RPCBVERS_3 (3u) |
| 39 | #define RPCBVERS_4 (4u) |
| 40 | |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 41 | enum { |
| 42 | RPCBPROC_NULL, |
| 43 | RPCBPROC_SET, |
| 44 | RPCBPROC_UNSET, |
| 45 | RPCBPROC_GETPORT, |
| 46 | RPCBPROC_GETADDR = 3, /* alias for GETPORT */ |
| 47 | RPCBPROC_DUMP, |
| 48 | RPCBPROC_CALLIT, |
| 49 | RPCBPROC_BCAST = 5, /* alias for CALLIT */ |
| 50 | RPCBPROC_GETTIME, |
| 51 | RPCBPROC_UADDR2TADDR, |
| 52 | RPCBPROC_TADDR2UADDR, |
| 53 | RPCBPROC_GETVERSADDR, |
| 54 | RPCBPROC_INDIRECT, |
| 55 | RPCBPROC_GETADDRLIST, |
| 56 | RPCBPROC_GETSTAT, |
| 57 | }; |
| 58 | |
| 59 | #define RPCB_HIGHPROC_2 RPCBPROC_CALLIT |
| 60 | #define RPCB_HIGHPROC_3 RPCBPROC_TADDR2UADDR |
| 61 | #define RPCB_HIGHPROC_4 RPCBPROC_GETSTAT |
| 62 | |
| 63 | /* |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 64 | * r_owner |
| 65 | * |
| 66 | * The "owner" is allowed to unset a service in the rpcbind database. |
Chuck Lever | 126e4bc | 2009-03-18 20:47:14 -0400 | [diff] [blame] | 67 | * |
| 68 | * For AF_LOCAL SET/UNSET requests, rpcbind treats this string as a |
| 69 | * UID which it maps to a local user name via a password lookup. |
| 70 | * In all other cases it is ignored. |
| 71 | * |
| 72 | * For SET/UNSET requests, user space provides a value, even for |
| 73 | * network requests, and GETADDR uses an empty string. We follow |
| 74 | * those precedents here. |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 75 | */ |
Chuck Lever | 126e4bc | 2009-03-18 20:47:14 -0400 | [diff] [blame] | 76 | #define RPCB_OWNER_STRING "0" |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 77 | #define RPCB_MAXOWNERLEN sizeof(RPCB_OWNER_STRING) |
| 78 | |
Chuck Lever | 0b10bf5 | 2009-08-09 15:09:33 -0400 | [diff] [blame] | 79 | /* |
| 80 | * XDR data type sizes |
| 81 | */ |
| 82 | #define RPCB_program_sz (1) |
| 83 | #define RPCB_version_sz (1) |
| 84 | #define RPCB_protocol_sz (1) |
| 85 | #define RPCB_port_sz (1) |
| 86 | #define RPCB_boolean_sz (1) |
| 87 | |
| 88 | #define RPCB_netid_sz (1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN)) |
| 89 | #define RPCB_addr_sz (1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN)) |
| 90 | #define RPCB_ownerstring_sz (1 + XDR_QUADLEN(RPCB_MAXOWNERLEN)) |
| 91 | |
| 92 | /* |
| 93 | * XDR argument and result sizes |
| 94 | */ |
| 95 | #define RPCB_mappingargs_sz (RPCB_program_sz + RPCB_version_sz + \ |
| 96 | RPCB_protocol_sz + RPCB_port_sz) |
| 97 | #define RPCB_getaddrargs_sz (RPCB_program_sz + RPCB_version_sz + \ |
| 98 | RPCB_netid_sz + RPCB_addr_sz + \ |
| 99 | RPCB_ownerstring_sz) |
| 100 | |
| 101 | #define RPCB_getportres_sz RPCB_port_sz |
| 102 | #define RPCB_setres_sz RPCB_boolean_sz |
| 103 | |
| 104 | /* |
| 105 | * Note that RFC 1833 does not put any size restrictions on the |
| 106 | * address string returned by the remote rpcbind database. |
| 107 | */ |
| 108 | #define RPCB_getaddrres_sz RPCB_addr_sz |
| 109 | |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 110 | static void rpcb_getport_done(struct rpc_task *, void *); |
Trond Myklebust | 381ba74 | 2008-07-07 12:18:53 -0400 | [diff] [blame] | 111 | static void rpcb_map_release(void *data); |
Adrian Bunk | 7f4adef | 2007-06-13 01:03:13 +0200 | [diff] [blame] | 112 | static struct rpc_program rpcb_program; |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 113 | |
Chuck Lever | c526611 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 114 | static struct rpc_clnt * rpcb_local_clnt; |
| 115 | static struct rpc_clnt * rpcb_local_clnt4; |
| 116 | |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 117 | struct rpcbind_args { |
| 118 | struct rpc_xprt * r_xprt; |
| 119 | |
| 120 | u32 r_prog; |
| 121 | u32 r_vers; |
| 122 | u32 r_prot; |
| 123 | unsigned short r_port; |
Trond Myklebust | 86d61d8 | 2008-01-07 21:16:56 -0500 | [diff] [blame] | 124 | const char * r_netid; |
| 125 | const char * r_addr; |
| 126 | const char * r_owner; |
Trond Myklebust | 381ba74 | 2008-07-07 12:18:53 -0400 | [diff] [blame] | 127 | |
| 128 | int r_status; |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 129 | }; |
| 130 | |
| 131 | static struct rpc_procinfo rpcb_procedures2[]; |
| 132 | static struct rpc_procinfo rpcb_procedures3[]; |
Chuck Lever | c2e1b09 | 2008-07-14 16:03:30 -0400 | [diff] [blame] | 133 | static struct rpc_procinfo rpcb_procedures4[]; |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 134 | |
Chuck Lever | d5b6443 | 2007-08-06 11:57:18 -0400 | [diff] [blame] | 135 | struct rpcb_info { |
Chuck Lever | fc200e7 | 2008-06-25 17:24:31 -0400 | [diff] [blame] | 136 | u32 rpc_vers; |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 137 | struct rpc_procinfo * rpc_proc; |
Chuck Lever | d5b6443 | 2007-08-06 11:57:18 -0400 | [diff] [blame] | 138 | }; |
| 139 | |
| 140 | static struct rpcb_info rpcb_next_version[]; |
| 141 | static struct rpcb_info rpcb_next_version6[]; |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 142 | |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 143 | static const struct rpc_call_ops rpcb_getport_ops = { |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 144 | .rpc_call_done = rpcb_getport_done, |
| 145 | .rpc_release = rpcb_map_release, |
| 146 | }; |
| 147 | |
| 148 | static void rpcb_wake_rpcbind_waiters(struct rpc_xprt *xprt, int status) |
| 149 | { |
| 150 | xprt_clear_binding(xprt); |
| 151 | rpc_wake_up_status(&xprt->binding, status); |
| 152 | } |
| 153 | |
Trond Myklebust | 381ba74 | 2008-07-07 12:18:53 -0400 | [diff] [blame] | 154 | static void rpcb_map_release(void *data) |
| 155 | { |
| 156 | struct rpcbind_args *map = data; |
| 157 | |
| 158 | rpcb_wake_rpcbind_waiters(map->r_xprt, map->r_status); |
| 159 | xprt_put(map->r_xprt); |
Chuck Lever | ba80913 | 2009-08-09 15:09:35 -0400 | [diff] [blame] | 160 | kfree(map->r_addr); |
Trond Myklebust | 381ba74 | 2008-07-07 12:18:53 -0400 | [diff] [blame] | 161 | kfree(map); |
| 162 | } |
| 163 | |
Chuck Lever | cc5598b | 2008-07-14 16:03:27 -0400 | [diff] [blame] | 164 | static const struct sockaddr_in rpcb_inaddr_loopback = { |
| 165 | .sin_family = AF_INET, |
| 166 | .sin_addr.s_addr = htonl(INADDR_LOOPBACK), |
| 167 | .sin_port = htons(RPCBIND_PORT), |
| 168 | }; |
| 169 | |
Chuck Lever | c526611 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 170 | static DEFINE_MUTEX(rpcb_create_local_mutex); |
| 171 | |
| 172 | /* |
| 173 | * Returns zero on success, otherwise a negative errno value |
| 174 | * is returned. |
| 175 | */ |
| 176 | static int rpcb_create_local(void) |
Chuck Lever | cc5598b | 2008-07-14 16:03:27 -0400 | [diff] [blame] | 177 | { |
| 178 | struct rpc_create_args args = { |
Chuck Lever | 2a76b3b | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 179 | .protocol = XPRT_TRANSPORT_TCP, |
Chuck Lever | 5a46211 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 180 | .address = (struct sockaddr *)&rpcb_inaddr_loopback, |
| 181 | .addrsize = sizeof(rpcb_inaddr_loopback), |
Chuck Lever | cc5598b | 2008-07-14 16:03:27 -0400 | [diff] [blame] | 182 | .servername = "localhost", |
| 183 | .program = &rpcb_program, |
Chuck Lever | c526611 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 184 | .version = RPCBVERS_2, |
Chuck Lever | cc5598b | 2008-07-14 16:03:27 -0400 | [diff] [blame] | 185 | .authflavor = RPC_AUTH_UNIX, |
| 186 | .flags = RPC_CLNT_CREATE_NOPING, |
| 187 | }; |
Chuck Lever | c526611 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 188 | struct rpc_clnt *clnt, *clnt4; |
| 189 | int result = 0; |
Chuck Lever | cc5598b | 2008-07-14 16:03:27 -0400 | [diff] [blame] | 190 | |
Chuck Lever | c526611 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 191 | if (rpcb_local_clnt) |
| 192 | return result; |
| 193 | |
| 194 | mutex_lock(&rpcb_create_local_mutex); |
| 195 | if (rpcb_local_clnt) |
| 196 | goto out; |
| 197 | |
| 198 | clnt = rpc_create(&args); |
| 199 | if (IS_ERR(clnt)) { |
| 200 | dprintk("RPC: failed to create local rpcbind " |
| 201 | "client (errno %ld).\n", PTR_ERR(clnt)); |
| 202 | result = -PTR_ERR(clnt); |
| 203 | goto out; |
| 204 | } |
| 205 | |
| 206 | /* |
| 207 | * This results in an RPC ping. On systems running portmapper, |
| 208 | * the v4 ping will fail. Proceed anyway, but disallow rpcb |
| 209 | * v4 upcalls. |
| 210 | */ |
| 211 | clnt4 = rpc_bind_new_program(clnt, &rpcb_program, RPCBVERS_4); |
| 212 | if (IS_ERR(clnt4)) { |
| 213 | dprintk("RPC: failed to create local rpcbind v4 " |
| 214 | "cleint (errno %ld).\n", PTR_ERR(clnt4)); |
| 215 | clnt4 = NULL; |
| 216 | } |
| 217 | |
| 218 | rpcb_local_clnt = clnt; |
| 219 | rpcb_local_clnt4 = clnt4; |
| 220 | |
| 221 | out: |
| 222 | mutex_unlock(&rpcb_create_local_mutex); |
| 223 | return result; |
Chuck Lever | cc5598b | 2008-07-14 16:03:27 -0400 | [diff] [blame] | 224 | } |
| 225 | |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 226 | static struct rpc_clnt *rpcb_create(char *hostname, struct sockaddr *srvaddr, |
Chuck Lever | 423d8b0 | 2008-07-14 16:03:28 -0400 | [diff] [blame] | 227 | size_t salen, int proto, u32 version) |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 228 | { |
| 229 | struct rpc_create_args args = { |
| 230 | .protocol = proto, |
| 231 | .address = srvaddr, |
Chuck Lever | 9f6ad26 | 2007-12-10 14:56:31 -0500 | [diff] [blame] | 232 | .addrsize = salen, |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 233 | .servername = hostname, |
| 234 | .program = &rpcb_program, |
| 235 | .version = version, |
| 236 | .authflavor = RPC_AUTH_UNIX, |
Chuck Lever | 423d8b0 | 2008-07-14 16:03:28 -0400 | [diff] [blame] | 237 | .flags = (RPC_CLNT_CREATE_NOPING | |
| 238 | RPC_CLNT_CREATE_NONPRIVPORT), |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 239 | }; |
| 240 | |
Chuck Lever | d5b6443 | 2007-08-06 11:57:18 -0400 | [diff] [blame] | 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: |
| 249 | return NULL; |
| 250 | } |
| 251 | |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 252 | return rpc_create(&args); |
| 253 | } |
| 254 | |
Chuck Lever | c526611 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 255 | static int rpcb_register_call(struct rpc_clnt *clnt, struct rpc_message *msg) |
Chuck Lever | babe80e | 2008-07-14 16:03:29 -0400 | [diff] [blame] | 256 | { |
Chuck Lever | 14aeb21 | 2008-08-18 19:34:00 -0400 | [diff] [blame] | 257 | int result, error = 0; |
Chuck Lever | babe80e | 2008-07-14 16:03:29 -0400 | [diff] [blame] | 258 | |
Chuck Lever | 14aeb21 | 2008-08-18 19:34:00 -0400 | [diff] [blame] | 259 | msg->rpc_resp = &result; |
Chuck Lever | babe80e | 2008-07-14 16:03:29 -0400 | [diff] [blame] | 260 | |
Chuck Lever | 2a76b3b | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 261 | error = rpc_call_sync(clnt, msg, RPC_TASK_SOFTCONN); |
Chuck Lever | 14aeb21 | 2008-08-18 19:34:00 -0400 | [diff] [blame] | 262 | if (error < 0) { |
Chuck Lever | 363f724 | 2009-03-18 20:47:44 -0400 | [diff] [blame] | 263 | dprintk("RPC: failed to contact local rpcbind " |
Chuck Lever | babe80e | 2008-07-14 16:03:29 -0400 | [diff] [blame] | 264 | "server (errno %d).\n", -error); |
Chuck Lever | 14aeb21 | 2008-08-18 19:34:00 -0400 | [diff] [blame] | 265 | return error; |
| 266 | } |
Chuck Lever | babe80e | 2008-07-14 16:03:29 -0400 | [diff] [blame] | 267 | |
Chuck Lever | db820d6 | 2008-09-25 11:57:05 -0400 | [diff] [blame] | 268 | if (!result) |
Chuck Lever | 14aeb21 | 2008-08-18 19:34:00 -0400 | [diff] [blame] | 269 | return -EACCES; |
Chuck Lever | 14aeb21 | 2008-08-18 19:34:00 -0400 | [diff] [blame] | 270 | return 0; |
Chuck Lever | babe80e | 2008-07-14 16:03:29 -0400 | [diff] [blame] | 271 | } |
| 272 | |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 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 |
Chuck Lever | c2e1b09 | 2008-07-14 16:03:30 -0400 | [diff] [blame] | 277 | * @prot: transport protocol to register |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 278 | * @port: port value to register |
Chuck Lever | 14aeb21 | 2008-08-18 19:34:00 -0400 | [diff] [blame] | 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). |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 284 | * |
Chuck Lever | c2e1b09 | 2008-07-14 16:03:30 -0400 | [diff] [blame] | 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. |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 289 | * |
Chuck Lever | c2e1b09 | 2008-07-14 16:03:30 -0400 | [diff] [blame] | 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 | * |
Chuck Lever | c2e1b09 | 2008-07-14 16:03:30 -0400 | [diff] [blame] | 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). |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 304 | */ |
Chuck Lever | 14aeb21 | 2008-08-18 19:34:00 -0400 | [diff] [blame] | 305 | int rpcb_register(u32 prog, u32 vers, int prot, unsigned short port) |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 306 | { |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 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 = { |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 314 | .rpc_argp = &map, |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 315 | }; |
Chuck Lever | c526611 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 316 | int error; |
| 317 | |
| 318 | error = rpcb_create_local(); |
| 319 | if (error) |
| 320 | return error; |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 321 | |
| 322 | dprintk("RPC: %sregistering (%u, %u, %d, %u) with local " |
| 323 | "rpcbind\n", (port ? "" : "un"), |
| 324 | prog, vers, prot, port); |
| 325 | |
Chuck Lever | babe80e | 2008-07-14 16:03:29 -0400 | [diff] [blame] | 326 | msg.rpc_proc = &rpcb_procedures2[RPCBPROC_UNSET]; |
| 327 | if (port) |
| 328 | msg.rpc_proc = &rpcb_procedures2[RPCBPROC_SET]; |
| 329 | |
Chuck Lever | c526611 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 330 | return rpcb_register_call(rpcb_local_clnt, &msg); |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 331 | } |
| 332 | |
Chuck Lever | c2e1b09 | 2008-07-14 16:03:30 -0400 | [diff] [blame] | 333 | /* |
| 334 | * Fill in AF_INET family-specific arguments to register |
| 335 | */ |
Chuck Lever | 1673d0d | 2009-03-18 20:47:21 -0400 | [diff] [blame] | 336 | static int rpcb_register_inet4(const struct sockaddr *sap, |
| 337 | struct rpc_message *msg) |
Chuck Lever | c2e1b09 | 2008-07-14 16:03:30 -0400 | [diff] [blame] | 338 | { |
Chuck Lever | 3aba455 | 2009-03-18 20:47:06 -0400 | [diff] [blame] | 339 | const struct sockaddr_in *sin = (const struct sockaddr_in *)sap; |
Chuck Lever | c2e1b09 | 2008-07-14 16:03:30 -0400 | [diff] [blame] | 340 | struct rpcbind_args *map = msg->rpc_argp; |
Chuck Lever | 3aba455 | 2009-03-18 20:47:06 -0400 | [diff] [blame] | 341 | unsigned short port = ntohs(sin->sin_port); |
Chuck Lever | ba80913 | 2009-08-09 15:09:35 -0400 | [diff] [blame] | 342 | int result; |
Chuck Lever | c2e1b09 | 2008-07-14 16:03:30 -0400 | [diff] [blame] | 343 | |
Chuck Lever | ba80913 | 2009-08-09 15:09:35 -0400 | [diff] [blame] | 344 | map->r_addr = rpc_sockaddr2uaddr(sap); |
Chuck Lever | c2e1b09 | 2008-07-14 16:03:30 -0400 | [diff] [blame] | 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 | |
Chuck Lever | c526611 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 355 | result = rpcb_register_call(rpcb_local_clnt4, msg); |
Chuck Lever | ba80913 | 2009-08-09 15:09:35 -0400 | [diff] [blame] | 356 | kfree(map->r_addr); |
| 357 | return result; |
Chuck Lever | c2e1b09 | 2008-07-14 16:03:30 -0400 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | /* |
| 361 | * Fill in AF_INET6 family-specific arguments to register |
| 362 | */ |
Chuck Lever | 1673d0d | 2009-03-18 20:47:21 -0400 | [diff] [blame] | 363 | static int rpcb_register_inet6(const struct sockaddr *sap, |
| 364 | struct rpc_message *msg) |
Chuck Lever | c2e1b09 | 2008-07-14 16:03:30 -0400 | [diff] [blame] | 365 | { |
Chuck Lever | 3aba455 | 2009-03-18 20:47:06 -0400 | [diff] [blame] | 366 | const struct sockaddr_in6 *sin6 = (const struct sockaddr_in6 *)sap; |
Chuck Lever | c2e1b09 | 2008-07-14 16:03:30 -0400 | [diff] [blame] | 367 | struct rpcbind_args *map = msg->rpc_argp; |
Chuck Lever | 3aba455 | 2009-03-18 20:47:06 -0400 | [diff] [blame] | 368 | unsigned short port = ntohs(sin6->sin6_port); |
Chuck Lever | ba80913 | 2009-08-09 15:09:35 -0400 | [diff] [blame] | 369 | int result; |
Chuck Lever | c2e1b09 | 2008-07-14 16:03:30 -0400 | [diff] [blame] | 370 | |
Chuck Lever | ba80913 | 2009-08-09 15:09:35 -0400 | [diff] [blame] | 371 | map->r_addr = rpc_sockaddr2uaddr(sap); |
Chuck Lever | c2e1b09 | 2008-07-14 16:03:30 -0400 | [diff] [blame] | 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 | |
Chuck Lever | c526611 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 382 | result = rpcb_register_call(rpcb_local_clnt4, msg); |
Chuck Lever | ba80913 | 2009-08-09 15:09:35 -0400 | [diff] [blame] | 383 | kfree(map->r_addr); |
| 384 | return result; |
Chuck Lever | c2e1b09 | 2008-07-14 16:03:30 -0400 | [diff] [blame] | 385 | } |
| 386 | |
Chuck Lever | 1673d0d | 2009-03-18 20:47:21 -0400 | [diff] [blame] | 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 | |
Chuck Lever | c526611 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 398 | return rpcb_register_call(rpcb_local_clnt4, msg); |
Chuck Lever | 1673d0d | 2009-03-18 20:47:21 -0400 | [diff] [blame] | 399 | } |
| 400 | |
Chuck Lever | c2e1b09 | 2008-07-14 16:03:30 -0400 | [diff] [blame] | 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 |
Chuck Lever | 14aeb21 | 2008-08-18 19:34:00 -0400 | [diff] [blame] | 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). |
Chuck Lever | c2e1b09 | 2008-07-14 16:03:30 -0400 | [diff] [blame] | 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 | * |
Chuck Lever | 1673d0d | 2009-03-18 20:47:21 -0400 | [diff] [blame] | 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. |
Chuck Lever | c2e1b09 | 2008-07-14 16:03:30 -0400 | [diff] [blame] | 423 | * |
Chuck Lever | c2e1b09 | 2008-07-14 16:03:30 -0400 | [diff] [blame] | 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, |
Chuck Lever | 14aeb21 | 2008-08-18 19:34:00 -0400 | [diff] [blame] | 445 | const struct sockaddr *address, const char *netid) |
Chuck Lever | c2e1b09 | 2008-07-14 16:03:30 -0400 | [diff] [blame] | 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, |
Chuck Lever | c2e1b09 | 2008-07-14 16:03:30 -0400 | [diff] [blame] | 455 | }; |
Chuck Lever | c526611 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 456 | int error; |
| 457 | |
| 458 | error = rpcb_create_local(); |
| 459 | if (error) |
| 460 | return error; |
| 461 | if (rpcb_local_clnt4 == NULL) |
| 462 | return -EPROTONOSUPPORT; |
Chuck Lever | c2e1b09 | 2008-07-14 16:03:30 -0400 | [diff] [blame] | 463 | |
Chuck Lever | 1673d0d | 2009-03-18 20:47:21 -0400 | [diff] [blame] | 464 | if (address == NULL) |
| 465 | return rpcb_unregister_all_protofamilies(&msg); |
| 466 | |
Chuck Lever | c2e1b09 | 2008-07-14 16:03:30 -0400 | [diff] [blame] | 467 | switch (address->sa_family) { |
| 468 | case AF_INET: |
Chuck Lever | 1673d0d | 2009-03-18 20:47:21 -0400 | [diff] [blame] | 469 | return rpcb_register_inet4(address, &msg); |
Chuck Lever | c2e1b09 | 2008-07-14 16:03:30 -0400 | [diff] [blame] | 470 | case AF_INET6: |
Chuck Lever | 1673d0d | 2009-03-18 20:47:21 -0400 | [diff] [blame] | 471 | return rpcb_register_inet6(address, &msg); |
Chuck Lever | c2e1b09 | 2008-07-14 16:03:30 -0400 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | return -EAFNOSUPPORT; |
| 475 | } |
| 476 | |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 477 | /** |
Chuck Lever | cce63cd | 2007-07-01 12:13:12 -0400 | [diff] [blame] | 478 | * rpcb_getport_sync - obtain the port for an RPC service on a given host |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 479 | * @sin: address of remote peer |
| 480 | * @prog: RPC program number to bind |
| 481 | * @vers: RPC version number to bind |
| 482 | * @prot: transport protocol to use to make this request |
| 483 | * |
Chuck Lever | 67d6021 | 2008-01-14 15:12:01 -0500 | [diff] [blame] | 484 | * Return value is the requested advertised port number, |
| 485 | * or a negative errno value. |
| 486 | * |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 487 | * Called from outside the RPC client in a synchronous task context. |
Chuck Lever | cce63cd | 2007-07-01 12:13:12 -0400 | [diff] [blame] | 488 | * Uses default timeout parameters specified by underlying transport. |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 489 | * |
Chuck Lever | 67d6021 | 2008-01-14 15:12:01 -0500 | [diff] [blame] | 490 | * XXX: Needs to support IPv6 |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 491 | */ |
Chuck Lever | f1ec08c | 2008-01-14 15:11:53 -0500 | [diff] [blame] | 492 | int rpcb_getport_sync(struct sockaddr_in *sin, u32 prog, u32 vers, int prot) |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 493 | { |
| 494 | struct rpcbind_args map = { |
| 495 | .r_prog = prog, |
| 496 | .r_vers = vers, |
| 497 | .r_prot = prot, |
| 498 | .r_port = 0, |
| 499 | }; |
| 500 | struct rpc_message msg = { |
| 501 | .rpc_proc = &rpcb_procedures2[RPCBPROC_GETPORT], |
| 502 | .rpc_argp = &map, |
Chuck Lever | c0c077d | 2009-08-09 15:09:43 -0400 | [diff] [blame] | 503 | .rpc_resp = &map, |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 504 | }; |
| 505 | struct rpc_clnt *rpcb_clnt; |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 506 | int status; |
| 507 | |
Harvey Harrison | 21454aa | 2008-10-31 00:54:56 -0700 | [diff] [blame] | 508 | dprintk("RPC: %s(%pI4, %u, %u, %d)\n", |
| 509 | __func__, &sin->sin_addr.s_addr, prog, vers, prot); |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 510 | |
Chuck Lever | b91e101 | 2008-01-14 15:11:46 -0500 | [diff] [blame] | 511 | rpcb_clnt = rpcb_create(NULL, (struct sockaddr *)sin, |
Chuck Lever | 423d8b0 | 2008-07-14 16:03:28 -0400 | [diff] [blame] | 512 | sizeof(*sin), prot, RPCBVERS_2); |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 513 | if (IS_ERR(rpcb_clnt)) |
| 514 | return PTR_ERR(rpcb_clnt); |
| 515 | |
| 516 | status = rpc_call_sync(rpcb_clnt, &msg, 0); |
Trond Myklebust | 90c5755 | 2007-06-09 19:49:36 -0400 | [diff] [blame] | 517 | rpc_shutdown_client(rpcb_clnt); |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 518 | |
| 519 | if (status >= 0) { |
| 520 | if (map.r_port != 0) |
| 521 | return map.r_port; |
| 522 | status = -EACCES; |
| 523 | } |
| 524 | return status; |
| 525 | } |
Chuck Lever | cce63cd | 2007-07-01 12:13:12 -0400 | [diff] [blame] | 526 | EXPORT_SYMBOL_GPL(rpcb_getport_sync); |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 527 | |
Trond Myklebust | 803a906 | 2008-07-01 15:20:55 -0400 | [diff] [blame] | 528 | static struct rpc_task *rpcb_call_async(struct rpc_clnt *rpcb_clnt, struct rpcbind_args *map, struct rpc_procinfo *proc) |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 529 | { |
| 530 | struct rpc_message msg = { |
Trond Myklebust | 803a906 | 2008-07-01 15:20:55 -0400 | [diff] [blame] | 531 | .rpc_proc = proc, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 532 | .rpc_argp = map, |
Chuck Lever | c0c077d | 2009-08-09 15:09:43 -0400 | [diff] [blame] | 533 | .rpc_resp = map, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 534 | }; |
| 535 | struct rpc_task_setup task_setup_data = { |
| 536 | .rpc_client = rpcb_clnt, |
| 537 | .rpc_message = &msg, |
| 538 | .callback_ops = &rpcb_getport_ops, |
| 539 | .callback_data = map, |
Chuck Lever | 012da15 | 2009-12-03 15:58:56 -0500 | [diff] [blame^] | 540 | .flags = RPC_TASK_ASYNC | RPC_TASK_SOFTCONN, |
Trond Myklebust | 5138fde | 2007-07-14 15:40:01 -0400 | [diff] [blame] | 541 | }; |
| 542 | |
| 543 | return rpc_run_task(&task_setup_data); |
| 544 | } |
| 545 | |
Trond Myklebust | 9a4bd29 | 2008-10-03 16:48:34 -0400 | [diff] [blame] | 546 | /* |
| 547 | * In the case where rpc clients have been cloned, we want to make |
| 548 | * sure that we use the program number/version etc of the actual |
| 549 | * owner of the xprt. To do so, we walk back up the tree of parents |
| 550 | * to find whoever created the transport and/or whoever has the |
| 551 | * autobind flag set. |
| 552 | */ |
| 553 | static struct rpc_clnt *rpcb_find_transport_owner(struct rpc_clnt *clnt) |
| 554 | { |
| 555 | struct rpc_clnt *parent = clnt->cl_parent; |
| 556 | |
| 557 | while (parent != clnt) { |
| 558 | if (parent->cl_xprt != clnt->cl_xprt) |
| 559 | break; |
| 560 | if (clnt->cl_autobind) |
| 561 | break; |
| 562 | clnt = parent; |
| 563 | parent = parent->cl_parent; |
| 564 | } |
| 565 | return clnt; |
| 566 | } |
| 567 | |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 568 | /** |
Chuck Lever | 45160d6 | 2007-07-01 12:13:17 -0400 | [diff] [blame] | 569 | * rpcb_getport_async - obtain the port for a given RPC service on a given host |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 570 | * @task: task that is waiting for portmapper request |
| 571 | * |
| 572 | * This one can be called for an ongoing RPC request, and can be used in |
| 573 | * an async (rpciod) context. |
| 574 | */ |
Chuck Lever | 45160d6 | 2007-07-01 12:13:17 -0400 | [diff] [blame] | 575 | void rpcb_getport_async(struct rpc_task *task) |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 576 | { |
Trond Myklebust | 9a4bd29 | 2008-10-03 16:48:34 -0400 | [diff] [blame] | 577 | struct rpc_clnt *clnt; |
Trond Myklebust | 803a906 | 2008-07-01 15:20:55 -0400 | [diff] [blame] | 578 | struct rpc_procinfo *proc; |
Chuck Lever | 0a48f5d | 2007-12-10 14:56:38 -0500 | [diff] [blame] | 579 | u32 bind_version; |
Trond Myklebust | 9a4bd29 | 2008-10-03 16:48:34 -0400 | [diff] [blame] | 580 | struct rpc_xprt *xprt; |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 581 | struct rpc_clnt *rpcb_clnt; |
| 582 | static struct rpcbind_args *map; |
| 583 | struct rpc_task *child; |
Chuck Lever | 9f6ad26 | 2007-12-10 14:56:31 -0500 | [diff] [blame] | 584 | struct sockaddr_storage addr; |
| 585 | struct sockaddr *sap = (struct sockaddr *)&addr; |
| 586 | size_t salen; |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 587 | int status; |
| 588 | |
Trond Myklebust | 9a4bd29 | 2008-10-03 16:48:34 -0400 | [diff] [blame] | 589 | clnt = rpcb_find_transport_owner(task->tk_client); |
| 590 | xprt = clnt->cl_xprt; |
| 591 | |
Chuck Lever | 45160d6 | 2007-07-01 12:13:17 -0400 | [diff] [blame] | 592 | dprintk("RPC: %5u %s(%s, %u, %u, %d)\n", |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 593 | task->tk_pid, __func__, |
Chuck Lever | 45160d6 | 2007-07-01 12:13:17 -0400 | [diff] [blame] | 594 | clnt->cl_server, clnt->cl_prog, clnt->cl_vers, xprt->prot); |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 595 | |
Trond Myklebust | 381ba74 | 2008-07-07 12:18:53 -0400 | [diff] [blame] | 596 | /* Put self on the wait queue to ensure we get notified if |
| 597 | * some other task is already attempting to bind the port */ |
| 598 | rpc_sleep_on(&xprt->binding, task, NULL); |
| 599 | |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 600 | if (xprt_test_and_set_binding(xprt)) { |
Chuck Lever | 45160d6 | 2007-07-01 12:13:17 -0400 | [diff] [blame] | 601 | dprintk("RPC: %5u %s: waiting for another binder\n", |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 602 | task->tk_pid, __func__); |
Trond Myklebust | 381ba74 | 2008-07-07 12:18:53 -0400 | [diff] [blame] | 603 | return; |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 604 | } |
| 605 | |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 606 | /* Someone else may have bound if we slept */ |
| 607 | if (xprt_bound(xprt)) { |
| 608 | status = 0; |
Chuck Lever | 45160d6 | 2007-07-01 12:13:17 -0400 | [diff] [blame] | 609 | dprintk("RPC: %5u %s: already bound\n", |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 610 | task->tk_pid, __func__); |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 611 | goto bailout_nofree; |
| 612 | } |
| 613 | |
Chuck Lever | ba80913 | 2009-08-09 15:09:35 -0400 | [diff] [blame] | 614 | /* Parent transport's destination address */ |
Chuck Lever | 9f6ad26 | 2007-12-10 14:56:31 -0500 | [diff] [blame] | 615 | salen = rpc_peeraddr(clnt, sap, sizeof(addr)); |
Chuck Lever | d5b6443 | 2007-08-06 11:57:18 -0400 | [diff] [blame] | 616 | |
| 617 | /* Don't ever use rpcbind v2 for AF_INET6 requests */ |
Chuck Lever | 9f6ad26 | 2007-12-10 14:56:31 -0500 | [diff] [blame] | 618 | switch (sap->sa_family) { |
Chuck Lever | d5b6443 | 2007-08-06 11:57:18 -0400 | [diff] [blame] | 619 | case AF_INET: |
Trond Myklebust | 803a906 | 2008-07-01 15:20:55 -0400 | [diff] [blame] | 620 | proc = rpcb_next_version[xprt->bind_index].rpc_proc; |
| 621 | bind_version = rpcb_next_version[xprt->bind_index].rpc_vers; |
Chuck Lever | d5b6443 | 2007-08-06 11:57:18 -0400 | [diff] [blame] | 622 | break; |
| 623 | case AF_INET6: |
Trond Myklebust | 803a906 | 2008-07-01 15:20:55 -0400 | [diff] [blame] | 624 | proc = rpcb_next_version6[xprt->bind_index].rpc_proc; |
| 625 | bind_version = rpcb_next_version6[xprt->bind_index].rpc_vers; |
Chuck Lever | d5b6443 | 2007-08-06 11:57:18 -0400 | [diff] [blame] | 626 | break; |
| 627 | default: |
| 628 | status = -EAFNOSUPPORT; |
| 629 | dprintk("RPC: %5u %s: bad address family\n", |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 630 | task->tk_pid, __func__); |
Chuck Lever | d5b6443 | 2007-08-06 11:57:18 -0400 | [diff] [blame] | 631 | goto bailout_nofree; |
| 632 | } |
Trond Myklebust | 803a906 | 2008-07-01 15:20:55 -0400 | [diff] [blame] | 633 | if (proc == NULL) { |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 634 | xprt->bind_index = 0; |
Chuck Lever | 906462a | 2007-09-11 18:00:47 -0400 | [diff] [blame] | 635 | status = -EPFNOSUPPORT; |
Chuck Lever | 45160d6 | 2007-07-01 12:13:17 -0400 | [diff] [blame] | 636 | dprintk("RPC: %5u %s: no more getport versions available\n", |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 637 | task->tk_pid, __func__); |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 638 | goto bailout_nofree; |
| 639 | } |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 640 | |
Chuck Lever | 45160d6 | 2007-07-01 12:13:17 -0400 | [diff] [blame] | 641 | dprintk("RPC: %5u %s: trying rpcbind version %u\n", |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 642 | task->tk_pid, __func__, bind_version); |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 643 | |
Chuck Lever | 9f6ad26 | 2007-12-10 14:56:31 -0500 | [diff] [blame] | 644 | rpcb_clnt = rpcb_create(clnt->cl_server, sap, salen, xprt->prot, |
Chuck Lever | 423d8b0 | 2008-07-14 16:03:28 -0400 | [diff] [blame] | 645 | bind_version); |
Chuck Lever | 143b6c4 | 2007-08-16 16:03:31 -0400 | [diff] [blame] | 646 | if (IS_ERR(rpcb_clnt)) { |
| 647 | status = PTR_ERR(rpcb_clnt); |
| 648 | dprintk("RPC: %5u %s: rpcb_create failed, error %ld\n", |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 649 | task->tk_pid, __func__, PTR_ERR(rpcb_clnt)); |
Chuck Lever | 143b6c4 | 2007-08-16 16:03:31 -0400 | [diff] [blame] | 650 | goto bailout_nofree; |
| 651 | } |
| 652 | |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 653 | map = kzalloc(sizeof(struct rpcbind_args), GFP_ATOMIC); |
| 654 | if (!map) { |
| 655 | status = -ENOMEM; |
Chuck Lever | 45160d6 | 2007-07-01 12:13:17 -0400 | [diff] [blame] | 656 | dprintk("RPC: %5u %s: no memory available\n", |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 657 | task->tk_pid, __func__); |
Trond Myklebust | 96165e2 | 2008-10-03 16:48:40 -0400 | [diff] [blame] | 658 | goto bailout_release_client; |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 659 | } |
| 660 | map->r_prog = clnt->cl_prog; |
| 661 | map->r_vers = clnt->cl_vers; |
| 662 | map->r_prot = xprt->prot; |
| 663 | map->r_port = 0; |
| 664 | map->r_xprt = xprt_get(xprt); |
Trond Myklebust | 381ba74 | 2008-07-07 12:18:53 -0400 | [diff] [blame] | 665 | map->r_status = -EIO; |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 666 | |
Chuck Lever | ba80913 | 2009-08-09 15:09:35 -0400 | [diff] [blame] | 667 | switch (bind_version) { |
| 668 | case RPCBVERS_4: |
| 669 | case RPCBVERS_3: |
| 670 | map->r_netid = rpc_peeraddr2str(clnt, RPC_DISPLAY_NETID); |
| 671 | map->r_addr = rpc_sockaddr2uaddr(sap); |
| 672 | map->r_owner = ""; |
| 673 | break; |
| 674 | case RPCBVERS_2: |
| 675 | map->r_addr = NULL; |
| 676 | break; |
| 677 | default: |
| 678 | BUG(); |
| 679 | } |
| 680 | |
Trond Myklebust | 803a906 | 2008-07-01 15:20:55 -0400 | [diff] [blame] | 681 | child = rpcb_call_async(rpcb_clnt, map, proc); |
Trond Myklebust | 4c402b4 | 2007-06-14 16:40:32 -0400 | [diff] [blame] | 682 | rpc_release_client(rpcb_clnt); |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 683 | if (IS_ERR(child)) { |
Trond Myklebust | 0d3a34b | 2008-07-07 12:18:52 -0400 | [diff] [blame] | 684 | /* rpcb_map_release() has freed the arguments */ |
Chuck Lever | 45160d6 | 2007-07-01 12:13:17 -0400 | [diff] [blame] | 685 | dprintk("RPC: %5u %s: rpc_run_task failed\n", |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 686 | task->tk_pid, __func__); |
Trond Myklebust | 381ba74 | 2008-07-07 12:18:53 -0400 | [diff] [blame] | 687 | return; |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 688 | } |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 689 | |
Trond Myklebust | 9a4bd29 | 2008-10-03 16:48:34 -0400 | [diff] [blame] | 690 | xprt->stat.bind_count++; |
| 691 | rpc_put_task(child); |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 692 | return; |
| 693 | |
Trond Myklebust | 96165e2 | 2008-10-03 16:48:40 -0400 | [diff] [blame] | 694 | bailout_release_client: |
| 695 | rpc_release_client(rpcb_clnt); |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 696 | bailout_nofree: |
| 697 | rpcb_wake_rpcbind_waiters(xprt, status); |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 698 | task->tk_status = status; |
| 699 | } |
\"Talpey, Thomas\ | 1244480 | 2007-09-10 13:45:36 -0400 | [diff] [blame] | 700 | EXPORT_SYMBOL_GPL(rpcb_getport_async); |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 701 | |
| 702 | /* |
| 703 | * Rpcbind child task calls this callback via tk_exit. |
| 704 | */ |
| 705 | static void rpcb_getport_done(struct rpc_task *child, void *data) |
| 706 | { |
| 707 | struct rpcbind_args *map = data; |
| 708 | struct rpc_xprt *xprt = map->r_xprt; |
| 709 | int status = child->tk_status; |
| 710 | |
Chuck Lever | 4784cb5 | 2007-09-11 18:00:36 -0400 | [diff] [blame] | 711 | /* Garbage reply: retry with a lesser rpcbind version */ |
| 712 | if (status == -EIO) |
| 713 | status = -EPROTONOSUPPORT; |
| 714 | |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 715 | /* rpcbind server doesn't support this rpcbind protocol version */ |
| 716 | if (status == -EPROTONOSUPPORT) |
| 717 | xprt->bind_index++; |
| 718 | |
| 719 | if (status < 0) { |
| 720 | /* rpcbind server not available on remote host? */ |
| 721 | xprt->ops->set_port(xprt, 0); |
| 722 | } else if (map->r_port == 0) { |
| 723 | /* Requested RPC service wasn't registered on remote host */ |
| 724 | xprt->ops->set_port(xprt, 0); |
| 725 | status = -EACCES; |
| 726 | } else { |
| 727 | /* Succeeded */ |
| 728 | xprt->ops->set_port(xprt, map->r_port); |
| 729 | xprt_set_bound(xprt); |
| 730 | status = 0; |
| 731 | } |
| 732 | |
| 733 | dprintk("RPC: %5u rpcb_getport_done(status %d, port %u)\n", |
| 734 | child->tk_pid, status, map->r_port); |
| 735 | |
Trond Myklebust | 381ba74 | 2008-07-07 12:18:53 -0400 | [diff] [blame] | 736 | map->r_status = status; |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 737 | } |
| 738 | |
Chuck Lever | 166b88d | 2008-07-14 16:03:26 -0400 | [diff] [blame] | 739 | /* |
| 740 | * XDR functions for rpcbind |
| 741 | */ |
| 742 | |
Chuck Lever | 6f2c2db | 2009-08-09 15:09:40 -0400 | [diff] [blame] | 743 | static int rpcb_enc_mapping(struct rpc_rqst *req, __be32 *p, |
| 744 | const struct rpcbind_args *rpcb) |
| 745 | { |
| 746 | struct rpc_task *task = req->rq_task; |
| 747 | struct xdr_stream xdr; |
| 748 | |
| 749 | dprintk("RPC: %5u encoding PMAP_%s call (%u, %u, %d, %u)\n", |
| 750 | task->tk_pid, task->tk_msg.rpc_proc->p_name, |
| 751 | rpcb->r_prog, rpcb->r_vers, rpcb->r_prot, rpcb->r_port); |
| 752 | |
| 753 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
| 754 | |
| 755 | p = xdr_reserve_space(&xdr, sizeof(__be32) * RPCB_mappingargs_sz); |
| 756 | if (unlikely(p == NULL)) |
| 757 | return -EIO; |
| 758 | |
| 759 | *p++ = htonl(rpcb->r_prog); |
| 760 | *p++ = htonl(rpcb->r_vers); |
| 761 | *p++ = htonl(rpcb->r_prot); |
| 762 | *p = htonl(rpcb->r_port); |
| 763 | |
| 764 | return 0; |
| 765 | } |
| 766 | |
Chuck Lever | c0c077d | 2009-08-09 15:09:43 -0400 | [diff] [blame] | 767 | static int rpcb_dec_getport(struct rpc_rqst *req, __be32 *p, |
| 768 | struct rpcbind_args *rpcb) |
| 769 | { |
| 770 | struct rpc_task *task = req->rq_task; |
| 771 | struct xdr_stream xdr; |
| 772 | unsigned long port; |
| 773 | |
| 774 | xdr_init_decode(&xdr, &req->rq_rcv_buf, p); |
| 775 | |
| 776 | rpcb->r_port = 0; |
| 777 | |
| 778 | p = xdr_inline_decode(&xdr, sizeof(__be32)); |
| 779 | if (unlikely(p == NULL)) |
| 780 | return -EIO; |
| 781 | |
| 782 | port = ntohl(*p); |
| 783 | dprintk("RPC: %5u PMAP_%s result: %lu\n", task->tk_pid, |
| 784 | task->tk_msg.rpc_proc->p_name, port); |
| 785 | if (unlikely(port > USHORT_MAX)) |
| 786 | return -EIO; |
| 787 | |
| 788 | rpcb->r_port = port; |
| 789 | return 0; |
| 790 | } |
| 791 | |
Chuck Lever | 7ed0ff9 | 2009-08-09 15:09:42 -0400 | [diff] [blame] | 792 | static int rpcb_dec_set(struct rpc_rqst *req, __be32 *p, |
| 793 | unsigned int *boolp) |
| 794 | { |
| 795 | struct rpc_task *task = req->rq_task; |
| 796 | struct xdr_stream xdr; |
| 797 | |
| 798 | xdr_init_decode(&xdr, &req->rq_rcv_buf, p); |
| 799 | |
| 800 | p = xdr_inline_decode(&xdr, sizeof(__be32)); |
| 801 | if (unlikely(p == NULL)) |
| 802 | return -EIO; |
| 803 | |
| 804 | *boolp = 0; |
| 805 | if (*p) |
| 806 | *boolp = 1; |
| 807 | |
| 808 | dprintk("RPC: %5u RPCB_%s call %s\n", |
| 809 | task->tk_pid, task->tk_msg.rpc_proc->p_name, |
| 810 | (*boolp ? "succeeded" : "failed")); |
| 811 | return 0; |
| 812 | } |
| 813 | |
Chuck Lever | 6f2c2db | 2009-08-09 15:09:40 -0400 | [diff] [blame] | 814 | static int encode_rpcb_string(struct xdr_stream *xdr, const char *string, |
| 815 | const u32 maxstrlen) |
| 816 | { |
| 817 | u32 len; |
| 818 | __be32 *p; |
| 819 | |
| 820 | if (unlikely(string == NULL)) |
| 821 | return -EIO; |
| 822 | len = strlen(string); |
| 823 | if (unlikely(len > maxstrlen)) |
| 824 | return -EIO; |
| 825 | |
| 826 | p = xdr_reserve_space(xdr, sizeof(__be32) + len); |
| 827 | if (unlikely(p == NULL)) |
| 828 | return -EIO; |
| 829 | xdr_encode_opaque(p, string, len); |
| 830 | |
| 831 | return 0; |
| 832 | } |
| 833 | |
| 834 | static int rpcb_enc_getaddr(struct rpc_rqst *req, __be32 *p, |
| 835 | const struct rpcbind_args *rpcb) |
| 836 | { |
| 837 | struct rpc_task *task = req->rq_task; |
| 838 | struct xdr_stream xdr; |
| 839 | |
| 840 | dprintk("RPC: %5u encoding RPCB_%s call (%u, %u, '%s', '%s')\n", |
| 841 | task->tk_pid, task->tk_msg.rpc_proc->p_name, |
| 842 | rpcb->r_prog, rpcb->r_vers, |
| 843 | rpcb->r_netid, rpcb->r_addr); |
| 844 | |
| 845 | xdr_init_encode(&xdr, &req->rq_snd_buf, p); |
| 846 | |
| 847 | p = xdr_reserve_space(&xdr, |
| 848 | sizeof(__be32) * (RPCB_program_sz + RPCB_version_sz)); |
| 849 | if (unlikely(p == NULL)) |
| 850 | return -EIO; |
| 851 | *p++ = htonl(rpcb->r_prog); |
| 852 | *p = htonl(rpcb->r_vers); |
| 853 | |
| 854 | if (encode_rpcb_string(&xdr, rpcb->r_netid, RPCBIND_MAXNETIDLEN)) |
| 855 | return -EIO; |
| 856 | if (encode_rpcb_string(&xdr, rpcb->r_addr, RPCBIND_MAXUADDRLEN)) |
| 857 | return -EIO; |
| 858 | if (encode_rpcb_string(&xdr, rpcb->r_owner, RPCB_MAXOWNERLEN)) |
| 859 | return -EIO; |
| 860 | |
| 861 | return 0; |
| 862 | } |
| 863 | |
Chuck Lever | c0c077d | 2009-08-09 15:09:43 -0400 | [diff] [blame] | 864 | static int rpcb_dec_getaddr(struct rpc_rqst *req, __be32 *p, |
| 865 | struct rpcbind_args *rpcb) |
| 866 | { |
| 867 | struct sockaddr_storage address; |
| 868 | struct sockaddr *sap = (struct sockaddr *)&address; |
| 869 | struct rpc_task *task = req->rq_task; |
| 870 | struct xdr_stream xdr; |
| 871 | u32 len; |
| 872 | |
| 873 | rpcb->r_port = 0; |
| 874 | |
| 875 | xdr_init_decode(&xdr, &req->rq_rcv_buf, p); |
| 876 | |
| 877 | p = xdr_inline_decode(&xdr, sizeof(__be32)); |
| 878 | if (unlikely(p == NULL)) |
| 879 | goto out_fail; |
| 880 | len = ntohl(*p); |
| 881 | |
| 882 | /* |
| 883 | * If the returned universal address is a null string, |
| 884 | * the requested RPC service was not registered. |
| 885 | */ |
| 886 | if (len == 0) { |
| 887 | dprintk("RPC: %5u RPCB reply: program not registered\n", |
| 888 | task->tk_pid); |
| 889 | return 0; |
| 890 | } |
| 891 | |
| 892 | if (unlikely(len > RPCBIND_MAXUADDRLEN)) |
| 893 | goto out_fail; |
| 894 | |
| 895 | p = xdr_inline_decode(&xdr, len); |
| 896 | if (unlikely(p == NULL)) |
| 897 | goto out_fail; |
| 898 | dprintk("RPC: %5u RPCB_%s reply: %s\n", task->tk_pid, |
| 899 | task->tk_msg.rpc_proc->p_name, (char *)p); |
| 900 | |
| 901 | if (rpc_uaddr2sockaddr((char *)p, len, sap, sizeof(address)) == 0) |
| 902 | goto out_fail; |
| 903 | rpcb->r_port = rpc_get_port(sap); |
| 904 | |
| 905 | return 0; |
| 906 | |
| 907 | out_fail: |
| 908 | dprintk("RPC: %5u malformed RPCB_%s reply\n", |
| 909 | task->tk_pid, task->tk_msg.rpc_proc->p_name); |
| 910 | return -EIO; |
| 911 | } |
| 912 | |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 913 | /* |
| 914 | * Not all rpcbind procedures described in RFC 1833 are implemented |
| 915 | * since the Linux kernel RPC code requires only these. |
| 916 | */ |
Chuck Lever | f8b761e | 2009-08-09 15:09:44 -0400 | [diff] [blame] | 917 | |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 918 | static struct rpc_procinfo rpcb_procedures2[] = { |
Chuck Lever | f8b761e | 2009-08-09 15:09:44 -0400 | [diff] [blame] | 919 | [RPCBPROC_SET] = { |
| 920 | .p_proc = RPCBPROC_SET, |
| 921 | .p_encode = (kxdrproc_t)rpcb_enc_mapping, |
| 922 | .p_decode = (kxdrproc_t)rpcb_dec_set, |
| 923 | .p_arglen = RPCB_mappingargs_sz, |
| 924 | .p_replen = RPCB_setres_sz, |
| 925 | .p_statidx = RPCBPROC_SET, |
| 926 | .p_timer = 0, |
| 927 | .p_name = "SET", |
| 928 | }, |
| 929 | [RPCBPROC_UNSET] = { |
| 930 | .p_proc = RPCBPROC_UNSET, |
| 931 | .p_encode = (kxdrproc_t)rpcb_enc_mapping, |
| 932 | .p_decode = (kxdrproc_t)rpcb_dec_set, |
| 933 | .p_arglen = RPCB_mappingargs_sz, |
| 934 | .p_replen = RPCB_setres_sz, |
| 935 | .p_statidx = RPCBPROC_UNSET, |
| 936 | .p_timer = 0, |
| 937 | .p_name = "UNSET", |
| 938 | }, |
| 939 | [RPCBPROC_GETPORT] = { |
| 940 | .p_proc = RPCBPROC_GETPORT, |
| 941 | .p_encode = (kxdrproc_t)rpcb_enc_mapping, |
| 942 | .p_decode = (kxdrproc_t)rpcb_dec_getport, |
| 943 | .p_arglen = RPCB_mappingargs_sz, |
| 944 | .p_replen = RPCB_getportres_sz, |
| 945 | .p_statidx = RPCBPROC_GETPORT, |
| 946 | .p_timer = 0, |
| 947 | .p_name = "GETPORT", |
| 948 | }, |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 949 | }; |
| 950 | |
| 951 | static struct rpc_procinfo rpcb_procedures3[] = { |
Chuck Lever | f8b761e | 2009-08-09 15:09:44 -0400 | [diff] [blame] | 952 | [RPCBPROC_SET] = { |
| 953 | .p_proc = RPCBPROC_SET, |
| 954 | .p_encode = (kxdrproc_t)rpcb_enc_getaddr, |
| 955 | .p_decode = (kxdrproc_t)rpcb_dec_set, |
| 956 | .p_arglen = RPCB_getaddrargs_sz, |
| 957 | .p_replen = RPCB_setres_sz, |
| 958 | .p_statidx = RPCBPROC_SET, |
| 959 | .p_timer = 0, |
| 960 | .p_name = "SET", |
| 961 | }, |
| 962 | [RPCBPROC_UNSET] = { |
| 963 | .p_proc = RPCBPROC_UNSET, |
| 964 | .p_encode = (kxdrproc_t)rpcb_enc_getaddr, |
| 965 | .p_decode = (kxdrproc_t)rpcb_dec_set, |
| 966 | .p_arglen = RPCB_getaddrargs_sz, |
| 967 | .p_replen = RPCB_setres_sz, |
| 968 | .p_statidx = RPCBPROC_UNSET, |
| 969 | .p_timer = 0, |
| 970 | .p_name = "UNSET", |
| 971 | }, |
| 972 | [RPCBPROC_GETADDR] = { |
| 973 | .p_proc = RPCBPROC_GETADDR, |
| 974 | .p_encode = (kxdrproc_t)rpcb_enc_getaddr, |
| 975 | .p_decode = (kxdrproc_t)rpcb_dec_getaddr, |
| 976 | .p_arglen = RPCB_getaddrargs_sz, |
| 977 | .p_replen = RPCB_getaddrres_sz, |
| 978 | .p_statidx = RPCBPROC_GETADDR, |
| 979 | .p_timer = 0, |
| 980 | .p_name = "GETADDR", |
| 981 | }, |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 982 | }; |
| 983 | |
| 984 | static struct rpc_procinfo rpcb_procedures4[] = { |
Chuck Lever | f8b761e | 2009-08-09 15:09:44 -0400 | [diff] [blame] | 985 | [RPCBPROC_SET] = { |
| 986 | .p_proc = RPCBPROC_SET, |
| 987 | .p_encode = (kxdrproc_t)rpcb_enc_getaddr, |
| 988 | .p_decode = (kxdrproc_t)rpcb_dec_set, |
| 989 | .p_arglen = RPCB_getaddrargs_sz, |
| 990 | .p_replen = RPCB_setres_sz, |
| 991 | .p_statidx = RPCBPROC_SET, |
| 992 | .p_timer = 0, |
| 993 | .p_name = "SET", |
| 994 | }, |
| 995 | [RPCBPROC_UNSET] = { |
| 996 | .p_proc = RPCBPROC_UNSET, |
| 997 | .p_encode = (kxdrproc_t)rpcb_enc_getaddr, |
| 998 | .p_decode = (kxdrproc_t)rpcb_dec_set, |
| 999 | .p_arglen = RPCB_getaddrargs_sz, |
| 1000 | .p_replen = RPCB_setres_sz, |
| 1001 | .p_statidx = RPCBPROC_UNSET, |
| 1002 | .p_timer = 0, |
| 1003 | .p_name = "UNSET", |
| 1004 | }, |
| 1005 | [RPCBPROC_GETADDR] = { |
| 1006 | .p_proc = RPCBPROC_GETADDR, |
| 1007 | .p_encode = (kxdrproc_t)rpcb_enc_getaddr, |
| 1008 | .p_decode = (kxdrproc_t)rpcb_dec_getaddr, |
| 1009 | .p_arglen = RPCB_getaddrargs_sz, |
| 1010 | .p_replen = RPCB_getaddrres_sz, |
| 1011 | .p_statidx = RPCBPROC_GETADDR, |
| 1012 | .p_timer = 0, |
| 1013 | .p_name = "GETADDR", |
| 1014 | }, |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 1015 | }; |
| 1016 | |
| 1017 | static struct rpcb_info rpcb_next_version[] = { |
Chuck Lever | fc200e7 | 2008-06-25 17:24:31 -0400 | [diff] [blame] | 1018 | { |
| 1019 | .rpc_vers = RPCBVERS_2, |
| 1020 | .rpc_proc = &rpcb_procedures2[RPCBPROC_GETPORT], |
| 1021 | }, |
| 1022 | { |
| 1023 | .rpc_proc = NULL, |
| 1024 | }, |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 1025 | }; |
| 1026 | |
Chuck Lever | d5b6443 | 2007-08-06 11:57:18 -0400 | [diff] [blame] | 1027 | static struct rpcb_info rpcb_next_version6[] = { |
Chuck Lever | fc200e7 | 2008-06-25 17:24:31 -0400 | [diff] [blame] | 1028 | { |
| 1029 | .rpc_vers = RPCBVERS_4, |
Chuck Lever | 8842413 | 2008-06-25 17:24:47 -0400 | [diff] [blame] | 1030 | .rpc_proc = &rpcb_procedures4[RPCBPROC_GETADDR], |
Chuck Lever | fc200e7 | 2008-06-25 17:24:31 -0400 | [diff] [blame] | 1031 | }, |
| 1032 | { |
| 1033 | .rpc_vers = RPCBVERS_3, |
| 1034 | .rpc_proc = &rpcb_procedures3[RPCBPROC_GETADDR], |
| 1035 | }, |
Chuck Lever | fc200e7 | 2008-06-25 17:24:31 -0400 | [diff] [blame] | 1036 | { |
| 1037 | .rpc_proc = NULL, |
| 1038 | }, |
Chuck Lever | d5b6443 | 2007-08-06 11:57:18 -0400 | [diff] [blame] | 1039 | }; |
| 1040 | |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 1041 | static struct rpc_version rpcb_version2 = { |
Chuck Lever | fc200e7 | 2008-06-25 17:24:31 -0400 | [diff] [blame] | 1042 | .number = RPCBVERS_2, |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 1043 | .nrprocs = RPCB_HIGHPROC_2, |
| 1044 | .procs = rpcb_procedures2 |
| 1045 | }; |
| 1046 | |
| 1047 | static struct rpc_version rpcb_version3 = { |
Chuck Lever | fc200e7 | 2008-06-25 17:24:31 -0400 | [diff] [blame] | 1048 | .number = RPCBVERS_3, |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 1049 | .nrprocs = RPCB_HIGHPROC_3, |
| 1050 | .procs = rpcb_procedures3 |
| 1051 | }; |
| 1052 | |
| 1053 | static struct rpc_version rpcb_version4 = { |
Chuck Lever | fc200e7 | 2008-06-25 17:24:31 -0400 | [diff] [blame] | 1054 | .number = RPCBVERS_4, |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 1055 | .nrprocs = RPCB_HIGHPROC_4, |
| 1056 | .procs = rpcb_procedures4 |
| 1057 | }; |
| 1058 | |
| 1059 | static struct rpc_version *rpcb_version[] = { |
| 1060 | NULL, |
| 1061 | NULL, |
| 1062 | &rpcb_version2, |
| 1063 | &rpcb_version3, |
| 1064 | &rpcb_version4 |
| 1065 | }; |
| 1066 | |
| 1067 | static struct rpc_stat rpcb_stats; |
| 1068 | |
Adrian Bunk | 7f4adef | 2007-06-13 01:03:13 +0200 | [diff] [blame] | 1069 | static struct rpc_program rpcb_program = { |
Chuck Lever | a509050 | 2007-03-29 16:48:04 -0400 | [diff] [blame] | 1070 | .name = "rpcbind", |
| 1071 | .number = RPCBIND_PROGRAM, |
| 1072 | .nrvers = ARRAY_SIZE(rpcb_version), |
| 1073 | .version = rpcb_version, |
| 1074 | .stats = &rpcb_stats, |
| 1075 | }; |
Chuck Lever | c526611 | 2009-12-03 15:58:56 -0500 | [diff] [blame] | 1076 | |
| 1077 | /** |
| 1078 | * cleanup_rpcb_clnt - remove xprtsock's sysctls, unregister |
| 1079 | * |
| 1080 | */ |
| 1081 | void cleanup_rpcb_clnt(void) |
| 1082 | { |
| 1083 | if (rpcb_local_clnt4) |
| 1084 | rpc_shutdown_client(rpcb_local_clnt4); |
| 1085 | if (rpcb_local_clnt) |
| 1086 | rpc_shutdown_client(rpcb_local_clnt); |
| 1087 | } |