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