Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Chuck Lever | c4a5692 | 2006-08-22 20:06:16 -0400 | [diff] [blame] | 2 | * linux/net/sunrpc/pmap_clnt.c |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
Chuck Lever | c4a5692 | 2006-08-22 20:06:16 -0400 | [diff] [blame] | 4 | * In-kernel RPC portmapper client. |
| 5 | * |
| 6 | * Portmapper supports version 2 of the rpcbind protocol (RFC 1833). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
| 8 | * Copyright (C) 1996, Olaf Kirch <okir@monad.swb.de> |
| 9 | */ |
| 10 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/types.h> |
| 12 | #include <linux/socket.h> |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/errno.h> |
| 15 | #include <linux/uio.h> |
| 16 | #include <linux/in.h> |
| 17 | #include <linux/sunrpc/clnt.h> |
| 18 | #include <linux/sunrpc/xprt.h> |
| 19 | #include <linux/sunrpc/sched.h> |
| 20 | |
| 21 | #ifdef RPC_DEBUG |
| 22 | # define RPCDBG_FACILITY RPCDBG_PMAP |
| 23 | #endif |
| 24 | |
| 25 | #define PMAP_SET 1 |
| 26 | #define PMAP_UNSET 2 |
| 27 | #define PMAP_GETPORT 3 |
| 28 | |
Chuck Lever | 4a68179 | 2006-08-22 20:06:15 -0400 | [diff] [blame] | 29 | struct portmap_args { |
| 30 | u32 pm_prog; |
| 31 | u32 pm_vers; |
| 32 | u32 pm_prot; |
| 33 | unsigned short pm_port; |
| 34 | struct rpc_task * pm_task; |
| 35 | }; |
| 36 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | static struct rpc_procinfo pmap_procedures[]; |
Chuck Lever | 6cd7525 | 2005-09-22 21:24:59 -0400 | [diff] [blame] | 38 | static struct rpc_clnt * pmap_create(char *, struct sockaddr_in *, int, int); |
Chuck Lever | 4a68179 | 2006-08-22 20:06:15 -0400 | [diff] [blame] | 39 | static void pmap_getport_done(struct rpc_task *, void *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | static struct rpc_program pmap_program; |
Chuck Lever | 4a68179 | 2006-08-22 20:06:15 -0400 | [diff] [blame] | 41 | |
| 42 | static void pmap_getport_prepare(struct rpc_task *task, void *calldata) |
| 43 | { |
| 44 | struct portmap_args *map = calldata; |
| 45 | struct rpc_message msg = { |
| 46 | .rpc_proc = &pmap_procedures[PMAP_GETPORT], |
| 47 | .rpc_argp = map, |
| 48 | .rpc_resp = &map->pm_port, |
| 49 | }; |
| 50 | |
| 51 | rpc_call_setup(task, &msg, 0); |
| 52 | } |
| 53 | |
| 54 | static inline struct portmap_args *pmap_map_alloc(void) |
| 55 | { |
| 56 | return kmalloc(sizeof(struct portmap_args), GFP_NOFS); |
| 57 | } |
| 58 | |
| 59 | static inline void pmap_map_free(struct portmap_args *map) |
| 60 | { |
| 61 | kfree(map); |
| 62 | } |
| 63 | |
| 64 | static void pmap_map_release(void *data) |
| 65 | { |
| 66 | pmap_map_free(data); |
| 67 | } |
| 68 | |
| 69 | static const struct rpc_call_ops pmap_getport_ops = { |
| 70 | .rpc_call_prepare = pmap_getport_prepare, |
| 71 | .rpc_call_done = pmap_getport_done, |
| 72 | .rpc_release = pmap_map_release, |
| 73 | }; |
| 74 | |
| 75 | static inline void pmap_wake_portmap_waiters(struct rpc_xprt *xprt) |
| 76 | { |
| 77 | xprt_clear_binding(xprt); |
| 78 | rpc_wake_up(&xprt->binding); |
| 79 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
Chuck Lever | c4a5692 | 2006-08-22 20:06:16 -0400 | [diff] [blame] | 81 | /** |
| 82 | * rpc_getport - obtain the port for a given RPC service on a given host |
| 83 | * @task: task that is waiting for portmapper request |
Chuck Lever | c4a5692 | 2006-08-22 20:06:16 -0400 | [diff] [blame] | 84 | * |
| 85 | * This one can be called for an ongoing RPC request, and can be used in |
| 86 | * an async (rpciod) context. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | */ |
Chuck Lever | bbf7c1d | 2006-08-22 20:06:16 -0400 | [diff] [blame^] | 88 | void rpc_getport(struct rpc_task *task) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | { |
Chuck Lever | bbf7c1d | 2006-08-22 20:06:16 -0400 | [diff] [blame^] | 90 | struct rpc_clnt *clnt = task->tk_client; |
Chuck Lever | 4a68179 | 2006-08-22 20:06:15 -0400 | [diff] [blame] | 91 | struct rpc_xprt *xprt = task->tk_xprt; |
| 92 | struct sockaddr_in *sap = &xprt->addr; |
| 93 | struct portmap_args *map; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | struct rpc_clnt *pmap_clnt; |
Chuck Lever | 4a68179 | 2006-08-22 20:06:15 -0400 | [diff] [blame] | 95 | struct rpc_task *child; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | |
Chuck Lever | 4a68179 | 2006-08-22 20:06:15 -0400 | [diff] [blame] | 97 | dprintk("RPC: %4d rpc_getport(%s, %u, %u, %d)\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | task->tk_pid, clnt->cl_server, |
Chuck Lever | 4a68179 | 2006-08-22 20:06:15 -0400 | [diff] [blame] | 99 | clnt->cl_prog, clnt->cl_vers, xprt->prot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | |
Andreas Gruenbacher | 007e251 | 2005-06-22 17:16:23 +0000 | [diff] [blame] | 101 | /* Autobind on cloned rpc clients is discouraged */ |
| 102 | BUG_ON(clnt->cl_parent != clnt); |
| 103 | |
Chuck Lever | 4a68179 | 2006-08-22 20:06:15 -0400 | [diff] [blame] | 104 | if (xprt_test_and_set_binding(xprt)) { |
| 105 | task->tk_status = -EACCES; /* tell caller to check again */ |
| 106 | rpc_sleep_on(&xprt->binding, task, NULL, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | return; |
| 108 | } |
Chuck Lever | 4a68179 | 2006-08-22 20:06:15 -0400 | [diff] [blame] | 109 | |
| 110 | /* Someone else may have bound if we slept */ |
| 111 | if (xprt_bound(xprt)) { |
| 112 | task->tk_status = 0; |
| 113 | goto bailout_nofree; |
| 114 | } |
| 115 | |
| 116 | map = pmap_map_alloc(); |
| 117 | if (!map) { |
| 118 | task->tk_status = -ENOMEM; |
| 119 | goto bailout_nofree; |
| 120 | } |
| 121 | map->pm_prog = clnt->cl_prog; |
| 122 | map->pm_vers = clnt->cl_vers; |
| 123 | map->pm_prot = xprt->prot; |
| 124 | map->pm_port = 0; |
| 125 | map->pm_task = task; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | |
Chuck Lever | 6cd7525 | 2005-09-22 21:24:59 -0400 | [diff] [blame] | 127 | pmap_clnt = pmap_create(clnt->cl_server, sap, map->pm_prot, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | if (IS_ERR(pmap_clnt)) { |
| 129 | task->tk_status = PTR_ERR(pmap_clnt); |
| 130 | goto bailout; |
| 131 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | |
Chuck Lever | 4a68179 | 2006-08-22 20:06:15 -0400 | [diff] [blame] | 133 | child = rpc_run_task(pmap_clnt, RPC_TASK_ASYNC, &pmap_getport_ops, map); |
| 134 | if (IS_ERR(child)) { |
| 135 | task->tk_status = -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | goto bailout; |
Chuck Lever | 4a68179 | 2006-08-22 20:06:15 -0400 | [diff] [blame] | 137 | } |
| 138 | rpc_release_task(child); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | |
Chuck Lever | 4a68179 | 2006-08-22 20:06:15 -0400 | [diff] [blame] | 140 | rpc_sleep_on(&xprt->binding, task, NULL, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | |
Chuck Lever | 262ca07 | 2006-03-20 13:44:16 -0500 | [diff] [blame] | 142 | task->tk_xprt->stat.bind_count++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | return; |
| 144 | |
| 145 | bailout: |
Chuck Lever | 4a68179 | 2006-08-22 20:06:15 -0400 | [diff] [blame] | 146 | pmap_map_free(map); |
| 147 | bailout_nofree: |
| 148 | pmap_wake_portmap_waiters(xprt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | #ifdef CONFIG_ROOT_NFS |
Chuck Lever | c4a5692 | 2006-08-22 20:06:16 -0400 | [diff] [blame] | 152 | /** |
| 153 | * rpc_getport_external - obtain the port for a given RPC service on a given host |
| 154 | * @sin: address of remote peer |
| 155 | * @prog: RPC program number to bind |
| 156 | * @vers: RPC version number to bind |
| 157 | * @prot: transport protocol to use to make this request |
| 158 | * |
| 159 | * This one is called from outside the RPC client in a synchronous task context. |
| 160 | */ |
| 161 | int rpc_getport_external(struct sockaddr_in *sin, __u32 prog, __u32 vers, int prot) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | { |
Chuck Lever | 4a68179 | 2006-08-22 20:06:15 -0400 | [diff] [blame] | 163 | struct portmap_args map = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | .pm_prog = prog, |
| 165 | .pm_vers = vers, |
| 166 | .pm_prot = prot, |
| 167 | .pm_port = 0 |
| 168 | }; |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 169 | struct rpc_message msg = { |
| 170 | .rpc_proc = &pmap_procedures[PMAP_GETPORT], |
| 171 | .rpc_argp = &map, |
| 172 | .rpc_resp = &map.pm_port, |
| 173 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | struct rpc_clnt *pmap_clnt; |
| 175 | char hostname[32]; |
| 176 | int status; |
| 177 | |
Chuck Lever | c4a5692 | 2006-08-22 20:06:16 -0400 | [diff] [blame] | 178 | dprintk("RPC: rpc_getport_external(%u.%u.%u.%u, %u, %u, %d)\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | NIPQUAD(sin->sin_addr.s_addr), prog, vers, prot); |
| 180 | |
| 181 | sprintf(hostname, "%u.%u.%u.%u", NIPQUAD(sin->sin_addr.s_addr)); |
Chuck Lever | 6cd7525 | 2005-09-22 21:24:59 -0400 | [diff] [blame] | 182 | pmap_clnt = pmap_create(hostname, sin, prot, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | if (IS_ERR(pmap_clnt)) |
| 184 | return PTR_ERR(pmap_clnt); |
| 185 | |
| 186 | /* Setup the call info struct */ |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 187 | status = rpc_call_sync(pmap_clnt, &msg, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | |
| 189 | if (status >= 0) { |
| 190 | if (map.pm_port != 0) |
| 191 | return map.pm_port; |
| 192 | status = -EACCES; |
| 193 | } |
| 194 | return status; |
| 195 | } |
| 196 | #endif |
| 197 | |
Chuck Lever | c4a5692 | 2006-08-22 20:06:16 -0400 | [diff] [blame] | 198 | /* |
| 199 | * Portmapper child task invokes this callback via tk_exit. |
| 200 | */ |
| 201 | static void pmap_getport_done(struct rpc_task *child, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | { |
Chuck Lever | 4a68179 | 2006-08-22 20:06:15 -0400 | [diff] [blame] | 203 | struct portmap_args *map = data; |
| 204 | struct rpc_task *task = map->pm_task; |
Chuck Lever | 9220041 | 2006-01-03 09:55:51 +0100 | [diff] [blame] | 205 | struct rpc_xprt *xprt = task->tk_xprt; |
Chuck Lever | 4a68179 | 2006-08-22 20:06:15 -0400 | [diff] [blame] | 206 | int status = child->tk_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | |
Chuck Lever | 4a68179 | 2006-08-22 20:06:15 -0400 | [diff] [blame] | 208 | if (status < 0) { |
| 209 | /* Portmapper not available */ |
Chuck Lever | ec739ef | 2006-08-22 20:06:15 -0400 | [diff] [blame] | 210 | xprt->ops->set_port(xprt, 0); |
Chuck Lever | 4a68179 | 2006-08-22 20:06:15 -0400 | [diff] [blame] | 211 | task->tk_status = status; |
| 212 | } else if (map->pm_port == 0) { |
| 213 | /* Requested RPC service wasn't registered */ |
Chuck Lever | ec739ef | 2006-08-22 20:06:15 -0400 | [diff] [blame] | 214 | xprt->ops->set_port(xprt, 0); |
Chuck Lever | 4a68179 | 2006-08-22 20:06:15 -0400 | [diff] [blame] | 215 | task->tk_status = -EACCES; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | } else { |
Chuck Lever | 4a68179 | 2006-08-22 20:06:15 -0400 | [diff] [blame] | 217 | /* Succeeded */ |
| 218 | xprt->ops->set_port(xprt, map->pm_port); |
Chuck Lever | ec739ef | 2006-08-22 20:06:15 -0400 | [diff] [blame] | 219 | xprt_set_bound(xprt); |
Chuck Lever | 4a68179 | 2006-08-22 20:06:15 -0400 | [diff] [blame] | 220 | task->tk_status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | } |
Chuck Lever | 4a68179 | 2006-08-22 20:06:15 -0400 | [diff] [blame] | 222 | |
| 223 | dprintk("RPC: %4d pmap_getport_done(status %d, port %u)\n", |
| 224 | child->tk_pid, child->tk_status, map->pm_port); |
| 225 | |
| 226 | pmap_wake_portmap_waiters(xprt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | } |
| 228 | |
Chuck Lever | c4a5692 | 2006-08-22 20:06:16 -0400 | [diff] [blame] | 229 | /** |
| 230 | * rpc_register - set or unset a port registration with the local portmapper |
| 231 | * @prog: RPC program number to bind |
| 232 | * @vers: RPC version number to bind |
| 233 | * @prot: transport protocol to use to make this request |
| 234 | * @port: port value to register |
| 235 | * @okay: result code |
| 236 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | * port == 0 means unregister, port != 0 means register. |
| 238 | */ |
Chuck Lever | c4a5692 | 2006-08-22 20:06:16 -0400 | [diff] [blame] | 239 | int rpc_register(u32 prog, u32 vers, int prot, unsigned short port, int *okay) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | { |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 241 | struct sockaddr_in sin = { |
| 242 | .sin_family = AF_INET, |
| 243 | .sin_addr.s_addr = htonl(INADDR_LOOPBACK), |
| 244 | }; |
Chuck Lever | 4a68179 | 2006-08-22 20:06:15 -0400 | [diff] [blame] | 245 | struct portmap_args map = { |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 246 | .pm_prog = prog, |
| 247 | .pm_vers = vers, |
| 248 | .pm_prot = prot, |
| 249 | .pm_port = port, |
| 250 | }; |
| 251 | struct rpc_message msg = { |
| 252 | .rpc_proc = &pmap_procedures[port ? PMAP_SET : PMAP_UNSET], |
| 253 | .rpc_argp = &map, |
| 254 | .rpc_resp = okay, |
| 255 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | struct rpc_clnt *pmap_clnt; |
| 257 | int error = 0; |
| 258 | |
Chuck Lever | c4a5692 | 2006-08-22 20:06:16 -0400 | [diff] [blame] | 259 | dprintk("RPC: registering (%u, %u, %d, %u) with portmapper.\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | prog, vers, prot, port); |
| 261 | |
Chuck Lever | 6cd7525 | 2005-09-22 21:24:59 -0400 | [diff] [blame] | 262 | pmap_clnt = pmap_create("localhost", &sin, IPPROTO_UDP, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | if (IS_ERR(pmap_clnt)) { |
| 264 | error = PTR_ERR(pmap_clnt); |
| 265 | dprintk("RPC: couldn't create pmap client. Error = %d\n", error); |
| 266 | return error; |
| 267 | } |
| 268 | |
Chuck Lever | dead28d | 2006-03-20 13:44:23 -0500 | [diff] [blame] | 269 | error = rpc_call_sync(pmap_clnt, &msg, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | |
| 271 | if (error < 0) { |
| 272 | printk(KERN_WARNING |
| 273 | "RPC: failed to contact portmap (errno %d).\n", |
| 274 | error); |
| 275 | } |
| 276 | dprintk("RPC: registration status %d/%d\n", error, *okay); |
| 277 | |
| 278 | /* Client deleted automatically because cl_oneshot == 1 */ |
| 279 | return error; |
| 280 | } |
| 281 | |
Chuck Lever | c4a5692 | 2006-08-22 20:06:16 -0400 | [diff] [blame] | 282 | static struct rpc_clnt *pmap_create(char *hostname, struct sockaddr_in *srvaddr, int proto, int privileged) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | { |
| 284 | struct rpc_xprt *xprt; |
| 285 | struct rpc_clnt *clnt; |
| 286 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | xprt = xprt_create_proto(proto, srvaddr, NULL); |
| 288 | if (IS_ERR(xprt)) |
| 289 | return (struct rpc_clnt *)xprt; |
Chuck Lever | 9220041 | 2006-01-03 09:55:51 +0100 | [diff] [blame] | 290 | xprt->ops->set_port(xprt, RPC_PMAP_PORT); |
Chuck Lever | ec739ef | 2006-08-22 20:06:15 -0400 | [diff] [blame] | 291 | xprt_set_bound(xprt); |
Chuck Lever | 6cd7525 | 2005-09-22 21:24:59 -0400 | [diff] [blame] | 292 | if (!privileged) |
| 293 | xprt->resvport = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | |
Trond Myklebust | 5ee0ed7 | 2005-06-22 17:16:20 +0000 | [diff] [blame] | 295 | clnt = rpc_new_client(xprt, hostname, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | &pmap_program, RPC_PMAP_VERSION, |
| 297 | RPC_AUTH_UNIX); |
Trond Myklebust | 5b616f5 | 2005-06-22 17:16:20 +0000 | [diff] [blame] | 298 | if (!IS_ERR(clnt)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | clnt->cl_softrtry = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | clnt->cl_oneshot = 1; |
| 301 | } |
| 302 | return clnt; |
| 303 | } |
| 304 | |
| 305 | /* |
| 306 | * XDR encode/decode functions for PMAP |
| 307 | */ |
Chuck Lever | c4a5692 | 2006-08-22 20:06:16 -0400 | [diff] [blame] | 308 | static int xdr_encode_mapping(struct rpc_rqst *req, u32 *p, struct portmap_args *map) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | { |
Chuck Lever | c4a5692 | 2006-08-22 20:06:16 -0400 | [diff] [blame] | 310 | dprintk("RPC: xdr_encode_mapping(%u, %u, %u, %u)\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | map->pm_prog, map->pm_vers, map->pm_prot, map->pm_port); |
| 312 | *p++ = htonl(map->pm_prog); |
| 313 | *p++ = htonl(map->pm_vers); |
| 314 | *p++ = htonl(map->pm_prot); |
| 315 | *p++ = htonl(map->pm_port); |
| 316 | |
| 317 | req->rq_slen = xdr_adjust_iovec(req->rq_svec, p); |
| 318 | return 0; |
| 319 | } |
| 320 | |
Chuck Lever | c4a5692 | 2006-08-22 20:06:16 -0400 | [diff] [blame] | 321 | static int xdr_decode_port(struct rpc_rqst *req, u32 *p, unsigned short *portp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | { |
| 323 | *portp = (unsigned short) ntohl(*p++); |
| 324 | return 0; |
| 325 | } |
| 326 | |
Chuck Lever | c4a5692 | 2006-08-22 20:06:16 -0400 | [diff] [blame] | 327 | static int xdr_decode_bool(struct rpc_rqst *req, u32 *p, unsigned int *boolp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | { |
| 329 | *boolp = (unsigned int) ntohl(*p++); |
| 330 | return 0; |
| 331 | } |
| 332 | |
| 333 | static struct rpc_procinfo pmap_procedures[] = { |
| 334 | [PMAP_SET] = { |
| 335 | .p_proc = PMAP_SET, |
| 336 | .p_encode = (kxdrproc_t) xdr_encode_mapping, |
| 337 | .p_decode = (kxdrproc_t) xdr_decode_bool, |
| 338 | .p_bufsiz = 4, |
| 339 | .p_count = 1, |
Chuck Lever | cc0175c | 2006-03-20 13:44:22 -0500 | [diff] [blame] | 340 | .p_statidx = PMAP_SET, |
| 341 | .p_name = "SET", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | }, |
| 343 | [PMAP_UNSET] = { |
| 344 | .p_proc = PMAP_UNSET, |
| 345 | .p_encode = (kxdrproc_t) xdr_encode_mapping, |
| 346 | .p_decode = (kxdrproc_t) xdr_decode_bool, |
| 347 | .p_bufsiz = 4, |
| 348 | .p_count = 1, |
Chuck Lever | cc0175c | 2006-03-20 13:44:22 -0500 | [diff] [blame] | 349 | .p_statidx = PMAP_UNSET, |
| 350 | .p_name = "UNSET", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | }, |
| 352 | [PMAP_GETPORT] = { |
| 353 | .p_proc = PMAP_GETPORT, |
| 354 | .p_encode = (kxdrproc_t) xdr_encode_mapping, |
| 355 | .p_decode = (kxdrproc_t) xdr_decode_port, |
| 356 | .p_bufsiz = 4, |
| 357 | .p_count = 1, |
Chuck Lever | cc0175c | 2006-03-20 13:44:22 -0500 | [diff] [blame] | 358 | .p_statidx = PMAP_GETPORT, |
| 359 | .p_name = "GETPORT", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | }, |
| 361 | }; |
| 362 | |
| 363 | static struct rpc_version pmap_version2 = { |
| 364 | .number = 2, |
| 365 | .nrprocs = 4, |
| 366 | .procs = pmap_procedures |
| 367 | }; |
| 368 | |
| 369 | static struct rpc_version * pmap_version[] = { |
| 370 | NULL, |
| 371 | NULL, |
| 372 | &pmap_version2 |
| 373 | }; |
| 374 | |
| 375 | static struct rpc_stat pmap_stats; |
| 376 | |
| 377 | static struct rpc_program pmap_program = { |
| 378 | .name = "portmap", |
| 379 | .number = RPC_PMAP_PROGRAM, |
| 380 | .nrvers = ARRAY_SIZE(pmap_version), |
| 381 | .version = pmap_version, |
| 382 | .stats = &pmap_stats, |
| 383 | }; |