blob: 2277b7cdad27ff14cabf3ecdc7dfe2b6ffb757f8 [file] [log] [blame]
Chuck Levera5090502007-03-29 16:48:04 -04001/*
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 Levercce63cd2007-07-01 12:13:12 -040015#include <linux/module.h>
16
Chuck Levera5090502007-03-29 16:48:04 -040017#include <linux/types.h>
18#include <linux/socket.h>
Chuck Lever7402ab192011-05-09 15:22:55 -040019#include <linux/un.h>
Chuck Leverd5b64432007-08-06 11:57:18 -040020#include <linux/in.h>
21#include <linux/in6.h>
Chuck Levera5090502007-03-29 16:48:04 -040022#include <linux/kernel.h>
23#include <linux/errno.h>
Chuck Leverc5266112009-12-03 15:58:56 -050024#include <linux/mutex.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090025#include <linux/slab.h>
Chuck Lever9d548b92008-09-15 16:27:30 -050026#include <net/ipv6.h>
Chuck Levera5090502007-03-29 16:48:04 -040027
28#include <linux/sunrpc/clnt.h>
Jeff Layton59766872013-02-04 12:50:00 -050029#include <linux/sunrpc/addr.h>
Chuck Levera5090502007-03-29 16:48:04 -040030#include <linux/sunrpc/sched.h>
\"Talpey, Thomas\0896a722007-09-10 13:48:23 -040031#include <linux/sunrpc/xprtsock.h>
Chuck Levera5090502007-03-29 16:48:04 -040032
Stanislav Kinsburskydff02d42012-01-13 12:52:10 +040033#include "netns.h"
34
Jeff Laytonf895b252014-11-17 16:58:04 -050035#if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
Chuck Levera5090502007-03-29 16:48:04 -040036# define RPCDBG_FACILITY RPCDBG_BIND
37#endif
38
Chuck Lever7402ab192011-05-09 15:22:55 -040039#define RPCBIND_SOCK_PATHNAME "/var/run/rpcbind.sock"
40
Chuck Levera5090502007-03-29 16:48:04 -040041#define RPCBIND_PROGRAM (100000u)
42#define RPCBIND_PORT (111u)
43
Chuck Leverfc200e72008-06-25 17:24:31 -040044#define RPCBVERS_2 (2u)
45#define RPCBVERS_3 (3u)
46#define RPCBVERS_4 (4u)
47
Chuck Levera5090502007-03-29 16:48:04 -040048enum {
49 RPCBPROC_NULL,
50 RPCBPROC_SET,
51 RPCBPROC_UNSET,
52 RPCBPROC_GETPORT,
53 RPCBPROC_GETADDR = 3, /* alias for GETPORT */
54 RPCBPROC_DUMP,
55 RPCBPROC_CALLIT,
56 RPCBPROC_BCAST = 5, /* alias for CALLIT */
57 RPCBPROC_GETTIME,
58 RPCBPROC_UADDR2TADDR,
59 RPCBPROC_TADDR2UADDR,
60 RPCBPROC_GETVERSADDR,
61 RPCBPROC_INDIRECT,
62 RPCBPROC_GETADDRLIST,
63 RPCBPROC_GETSTAT,
64};
65
Chuck Levera5090502007-03-29 16:48:04 -040066/*
Chuck Levera5090502007-03-29 16:48:04 -040067 * r_owner
68 *
69 * The "owner" is allowed to unset a service in the rpcbind database.
Chuck Lever126e4bc2009-03-18 20:47:14 -040070 *
71 * For AF_LOCAL SET/UNSET requests, rpcbind treats this string as a
72 * UID which it maps to a local user name via a password lookup.
73 * In all other cases it is ignored.
74 *
75 * For SET/UNSET requests, user space provides a value, even for
76 * network requests, and GETADDR uses an empty string. We follow
77 * those precedents here.
Chuck Levera5090502007-03-29 16:48:04 -040078 */
Chuck Lever126e4bc2009-03-18 20:47:14 -040079#define RPCB_OWNER_STRING "0"
Chuck Levera5090502007-03-29 16:48:04 -040080#define RPCB_MAXOWNERLEN sizeof(RPCB_OWNER_STRING)
81
Chuck Lever0b10bf52009-08-09 15:09:33 -040082/*
83 * XDR data type sizes
84 */
85#define RPCB_program_sz (1)
86#define RPCB_version_sz (1)
87#define RPCB_protocol_sz (1)
88#define RPCB_port_sz (1)
89#define RPCB_boolean_sz (1)
90
91#define RPCB_netid_sz (1 + XDR_QUADLEN(RPCBIND_MAXNETIDLEN))
92#define RPCB_addr_sz (1 + XDR_QUADLEN(RPCBIND_MAXUADDRLEN))
93#define RPCB_ownerstring_sz (1 + XDR_QUADLEN(RPCB_MAXOWNERLEN))
94
95/*
96 * XDR argument and result sizes
97 */
98#define RPCB_mappingargs_sz (RPCB_program_sz + RPCB_version_sz + \
99 RPCB_protocol_sz + RPCB_port_sz)
100#define RPCB_getaddrargs_sz (RPCB_program_sz + RPCB_version_sz + \
101 RPCB_netid_sz + RPCB_addr_sz + \
102 RPCB_ownerstring_sz)
103
104#define RPCB_getportres_sz RPCB_port_sz
105#define RPCB_setres_sz RPCB_boolean_sz
106
107/*
108 * Note that RFC 1833 does not put any size restrictions on the
109 * address string returned by the remote rpcbind database.
110 */
111#define RPCB_getaddrres_sz RPCB_addr_sz
112
Chuck Levera5090502007-03-29 16:48:04 -0400113static void rpcb_getport_done(struct rpc_task *, void *);
Trond Myklebust381ba742008-07-07 12:18:53 -0400114static void rpcb_map_release(void *data);
Trond Myklebusta613fa12012-01-20 13:53:56 -0500115static const struct rpc_program rpcb_program;
Chuck Levera5090502007-03-29 16:48:04 -0400116
117struct 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 Myklebust86d61d82008-01-07 21:16:56 -0500124 const char * r_netid;
125 const char * r_addr;
126 const char * r_owner;
Trond Myklebust381ba742008-07-07 12:18:53 -0400127
128 int r_status;
Chuck Levera5090502007-03-29 16:48:04 -0400129};
130
Christoph Hellwig499b4982017-05-12 15:36:49 +0200131static const struct rpc_procinfo rpcb_procedures2[];
132static const struct rpc_procinfo rpcb_procedures3[];
133static const struct rpc_procinfo rpcb_procedures4[];
Chuck Levera5090502007-03-29 16:48:04 -0400134
Chuck Leverd5b64432007-08-06 11:57:18 -0400135struct rpcb_info {
Chuck Leverfc200e72008-06-25 17:24:31 -0400136 u32 rpc_vers;
Christoph Hellwig499b4982017-05-12 15:36:49 +0200137 const struct rpc_procinfo *rpc_proc;
Chuck Leverd5b64432007-08-06 11:57:18 -0400138};
139
Trond Myklebusta613fa12012-01-20 13:53:56 -0500140static const struct rpcb_info rpcb_next_version[];
141static const struct rpcb_info rpcb_next_version6[];
Chuck Levera5090502007-03-29 16:48:04 -0400142
Chuck Levera5090502007-03-29 16:48:04 -0400143static const struct rpc_call_ops rpcb_getport_ops = {
Chuck Levera5090502007-03-29 16:48:04 -0400144 .rpc_call_done = rpcb_getport_done,
145 .rpc_release = rpcb_map_release,
146};
147
148static 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 Myklebust381ba742008-07-07 12:18:53 -0400154static 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 Leverba809132009-08-09 15:09:35 -0400160 kfree(map->r_addr);
Trond Myklebust381ba742008-07-07 12:18:53 -0400161 kfree(map);
162}
163
Stanislav Kinsbursky2ea75a12012-01-13 12:52:18 +0400164static int rpcb_get_local(struct net *net)
Stanislav Kinsbursky914edb12011-10-25 14:16:36 +0300165{
166 int cnt;
Stanislav Kinsbursky2ea75a12012-01-13 12:52:18 +0400167 struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
Stanislav Kinsbursky914edb12011-10-25 14:16:36 +0300168
Stanislav Kinsburskydff02d42012-01-13 12:52:10 +0400169 spin_lock(&sn->rpcb_clnt_lock);
170 if (sn->rpcb_users)
171 sn->rpcb_users++;
172 cnt = sn->rpcb_users;
173 spin_unlock(&sn->rpcb_clnt_lock);
Stanislav Kinsbursky914edb12011-10-25 14:16:36 +0300174
175 return cnt;
176}
177
Stanislav Kinsburskyf7a30c12012-01-13 12:52:51 +0400178void rpcb_put_local(struct net *net)
Stanislav Kinsbursky914edb12011-10-25 14:16:36 +0300179{
Stanislav Kinsburskyf7a30c12012-01-13 12:52:51 +0400180 struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
Stanislav Kinsburskydff02d42012-01-13 12:52:10 +0400181 struct rpc_clnt *clnt = sn->rpcb_local_clnt;
182 struct rpc_clnt *clnt4 = sn->rpcb_local_clnt4;
Stanislav Kinsbursky9793f7c2012-05-02 16:08:38 +0400183 int shutdown = 0;
Stanislav Kinsbursky914edb12011-10-25 14:16:36 +0300184
Stanislav Kinsburskydff02d42012-01-13 12:52:10 +0400185 spin_lock(&sn->rpcb_clnt_lock);
Stanislav Kinsbursky9793f7c2012-05-02 16:08:38 +0400186 if (sn->rpcb_users) {
187 if (--sn->rpcb_users == 0) {
188 sn->rpcb_local_clnt = NULL;
189 sn->rpcb_local_clnt4 = NULL;
190 }
191 shutdown = !sn->rpcb_users;
Stanislav Kinsbursky914edb12011-10-25 14:16:36 +0300192 }
Stanislav Kinsburskydff02d42012-01-13 12:52:10 +0400193 spin_unlock(&sn->rpcb_clnt_lock);
Stanislav Kinsbursky914edb12011-10-25 14:16:36 +0300194
195 if (shutdown) {
196 /*
197 * cleanup_rpcb_clnt - remove xprtsock's sysctls, unregister
198 */
199 if (clnt4)
200 rpc_shutdown_client(clnt4);
201 if (clnt)
202 rpc_shutdown_client(clnt);
203 }
204}
205
Stanislav Kinsbursky2ea75a12012-01-13 12:52:18 +0400206static void rpcb_set_local(struct net *net, struct rpc_clnt *clnt,
Trond Myklebust786615b2013-08-05 16:04:47 -0400207 struct rpc_clnt *clnt4,
208 bool is_af_local)
Stanislav Kinsbursky914edb12011-10-25 14:16:36 +0300209{
Stanislav Kinsbursky2ea75a12012-01-13 12:52:18 +0400210 struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
Stanislav Kinsburskydff02d42012-01-13 12:52:10 +0400211
Stanislav Kinsbursky914edb12011-10-25 14:16:36 +0300212 /* Protected by rpcb_create_local_mutex */
Stanislav Kinsburskydff02d42012-01-13 12:52:10 +0400213 sn->rpcb_local_clnt = clnt;
214 sn->rpcb_local_clnt4 = clnt4;
Trond Myklebust786615b2013-08-05 16:04:47 -0400215 sn->rpcb_is_af_local = is_af_local ? 1 : 0;
Stephen Hemminger8fdee4c2018-07-24 12:29:15 -0700216 smp_wmb();
Stanislav Kinsburskydff02d42012-01-13 12:52:10 +0400217 sn->rpcb_users = 1;
Stanislav Kinsbursky914edb12011-10-25 14:16:36 +0300218 dprintk("RPC: created new rpcb local clients (rpcb_local_clnt: "
Vasily Averin6c67a3e4a2017-11-08 08:57:32 +0300219 "%p, rpcb_local_clnt4: %p) for net %x%s\n",
220 sn->rpcb_local_clnt, sn->rpcb_local_clnt4,
221 net->ns.inum, (net == &init_net) ? " (init_net)" : "");
Stanislav Kinsbursky914edb12011-10-25 14:16:36 +0300222}
223
Chuck Lever7402ab192011-05-09 15:22:55 -0400224/*
225 * Returns zero on success, otherwise a negative errno value
226 * is returned.
227 */
Stanislav Kinsbursky2ea75a12012-01-13 12:52:18 +0400228static int rpcb_create_local_unix(struct net *net)
Chuck Lever7402ab192011-05-09 15:22:55 -0400229{
230 static const struct sockaddr_un rpcb_localaddr_rpcbind = {
231 .sun_family = AF_LOCAL,
232 .sun_path = RPCBIND_SOCK_PATHNAME,
233 };
234 struct rpc_create_args args = {
Stanislav Kinsbursky2ea75a12012-01-13 12:52:18 +0400235 .net = net,
Chuck Lever7402ab192011-05-09 15:22:55 -0400236 .protocol = XPRT_TRANSPORT_LOCAL,
237 .address = (struct sockaddr *)&rpcb_localaddr_rpcbind,
238 .addrsize = sizeof(rpcb_localaddr_rpcbind),
239 .servername = "localhost",
240 .program = &rpcb_program,
241 .version = RPCBVERS_2,
242 .authflavor = RPC_AUTH_NULL,
Trond Myklebust79caa5f2019-04-24 17:46:42 -0400243 .cred = current_cred(),
Trond Myklebust00326ed2013-08-05 14:10:43 -0400244 /*
245 * We turn off the idle timeout to prevent the kernel
246 * from automatically disconnecting the socket.
247 * Otherwise, we'd have to cache the mount namespace
248 * of the caller and somehow pass that to the socket
249 * reconnect code.
250 */
251 .flags = RPC_CLNT_CREATE_NO_IDLE_TIMEOUT,
Chuck Lever7402ab192011-05-09 15:22:55 -0400252 };
253 struct rpc_clnt *clnt, *clnt4;
254 int result = 0;
Chuck Levercc5598b2008-07-14 16:03:27 -0400255
Chuck Lever7402ab192011-05-09 15:22:55 -0400256 /*
257 * Because we requested an RPC PING at transport creation time,
258 * this works only if the user space portmapper is rpcbind, and
259 * it's listening on AF_LOCAL on the named socket.
260 */
261 clnt = rpc_create(&args);
262 if (IS_ERR(clnt)) {
263 dprintk("RPC: failed to create AF_LOCAL rpcbind "
264 "client (errno %ld).\n", PTR_ERR(clnt));
Stanislav Kinsburskycaea33d2012-07-20 15:57:48 +0400265 result = PTR_ERR(clnt);
Chuck Lever7402ab192011-05-09 15:22:55 -0400266 goto out;
267 }
268
269 clnt4 = rpc_bind_new_program(clnt, &rpcb_program, RPCBVERS_4);
270 if (IS_ERR(clnt4)) {
271 dprintk("RPC: failed to bind second program to "
272 "rpcbind v4 client (errno %ld).\n",
273 PTR_ERR(clnt4));
274 clnt4 = NULL;
275 }
276
Trond Myklebust786615b2013-08-05 16:04:47 -0400277 rpcb_set_local(net, clnt, clnt4, true);
Chuck Lever7402ab192011-05-09 15:22:55 -0400278
279out:
280 return result;
281}
Chuck Leverc5266112009-12-03 15:58:56 -0500282
283/*
284 * Returns zero on success, otherwise a negative errno value
285 * is returned.
286 */
Stanislav Kinsbursky2ea75a12012-01-13 12:52:18 +0400287static int rpcb_create_local_net(struct net *net)
Chuck Levercc5598b2008-07-14 16:03:27 -0400288{
Chuck Lever7402ab192011-05-09 15:22:55 -0400289 static const struct sockaddr_in rpcb_inaddr_loopback = {
290 .sin_family = AF_INET,
291 .sin_addr.s_addr = htonl(INADDR_LOOPBACK),
292 .sin_port = htons(RPCBIND_PORT),
293 };
Chuck Levercc5598b2008-07-14 16:03:27 -0400294 struct rpc_create_args args = {
Stanislav Kinsbursky2ea75a12012-01-13 12:52:18 +0400295 .net = net,
Chuck Lever2a76b3b2009-12-03 15:58:56 -0500296 .protocol = XPRT_TRANSPORT_TCP,
Chuck Lever5a462112009-12-03 15:58:56 -0500297 .address = (struct sockaddr *)&rpcb_inaddr_loopback,
298 .addrsize = sizeof(rpcb_inaddr_loopback),
Chuck Levercc5598b2008-07-14 16:03:27 -0400299 .servername = "localhost",
300 .program = &rpcb_program,
Chuck Leverc5266112009-12-03 15:58:56 -0500301 .version = RPCBVERS_2,
Chuck Levercc5598b2008-07-14 16:03:27 -0400302 .authflavor = RPC_AUTH_UNIX,
Trond Myklebust79caa5f2019-04-24 17:46:42 -0400303 .cred = current_cred(),
Chuck Levercc5598b2008-07-14 16:03:27 -0400304 .flags = RPC_CLNT_CREATE_NOPING,
305 };
Chuck Leverc5266112009-12-03 15:58:56 -0500306 struct rpc_clnt *clnt, *clnt4;
307 int result = 0;
Chuck Levercc5598b2008-07-14 16:03:27 -0400308
Chuck Leverc5266112009-12-03 15:58:56 -0500309 clnt = rpc_create(&args);
310 if (IS_ERR(clnt)) {
311 dprintk("RPC: failed to create local rpcbind "
312 "client (errno %ld).\n", PTR_ERR(clnt));
Stanislav Kinsburskycaea33d2012-07-20 15:57:48 +0400313 result = PTR_ERR(clnt);
Chuck Leverc5266112009-12-03 15:58:56 -0500314 goto out;
315 }
316
317 /*
318 * This results in an RPC ping. On systems running portmapper,
319 * the v4 ping will fail. Proceed anyway, but disallow rpcb
320 * v4 upcalls.
321 */
322 clnt4 = rpc_bind_new_program(clnt, &rpcb_program, RPCBVERS_4);
323 if (IS_ERR(clnt4)) {
Chuck Lever38359352010-09-21 16:55:48 -0400324 dprintk("RPC: failed to bind second program to "
325 "rpcbind v4 client (errno %ld).\n",
326 PTR_ERR(clnt4));
Chuck Leverc5266112009-12-03 15:58:56 -0500327 clnt4 = NULL;
328 }
329
Trond Myklebust786615b2013-08-05 16:04:47 -0400330 rpcb_set_local(net, clnt, clnt4, false);
Chuck Leverc5266112009-12-03 15:58:56 -0500331
332out:
Chuck Lever7402ab192011-05-09 15:22:55 -0400333 return result;
334}
335
336/*
337 * Returns zero on success, otherwise a negative errno value
338 * is returned.
339 */
Stanislav Kinsburskyf7a30c12012-01-13 12:52:51 +0400340int rpcb_create_local(struct net *net)
Chuck Lever7402ab192011-05-09 15:22:55 -0400341{
342 static DEFINE_MUTEX(rpcb_create_local_mutex);
343 int result = 0;
344
Stanislav Kinsbursky2ea75a12012-01-13 12:52:18 +0400345 if (rpcb_get_local(net))
Chuck Lever7402ab192011-05-09 15:22:55 -0400346 return result;
347
348 mutex_lock(&rpcb_create_local_mutex);
Stanislav Kinsbursky2ea75a12012-01-13 12:52:18 +0400349 if (rpcb_get_local(net))
Chuck Lever7402ab192011-05-09 15:22:55 -0400350 goto out;
351
Stanislav Kinsbursky2ea75a12012-01-13 12:52:18 +0400352 if (rpcb_create_local_unix(net) != 0)
353 result = rpcb_create_local_net(net);
Chuck Lever7402ab192011-05-09 15:22:55 -0400354
355out:
Chuck Leverc5266112009-12-03 15:58:56 -0500356 mutex_unlock(&rpcb_create_local_mutex);
357 return result;
Chuck Levercc5598b2008-07-14 16:03:27 -0400358}
359
Trond Myklebust03a9a422015-01-30 18:12:28 -0500360static struct rpc_clnt *rpcb_create(struct net *net, const char *nodename,
361 const char *hostname,
Stanislav Kinsburskyc2550e02012-01-13 12:52:35 +0400362 struct sockaddr *srvaddr, size_t salen,
Trond Myklebust79caa5f2019-04-24 17:46:42 -0400363 int proto, u32 version,
364 const struct cred *cred)
Chuck Levera5090502007-03-29 16:48:04 -0400365{
366 struct rpc_create_args args = {
Stanislav Kinsburskyc2550e02012-01-13 12:52:35 +0400367 .net = net,
Chuck Levera5090502007-03-29 16:48:04 -0400368 .protocol = proto,
369 .address = srvaddr,
Chuck Lever9f6ad262007-12-10 14:56:31 -0500370 .addrsize = salen,
Chuck Levera5090502007-03-29 16:48:04 -0400371 .servername = hostname,
Trond Myklebust03a9a422015-01-30 18:12:28 -0500372 .nodename = nodename,
Chuck Levera5090502007-03-29 16:48:04 -0400373 .program = &rpcb_program,
374 .version = version,
375 .authflavor = RPC_AUTH_UNIX,
Trond Myklebust79caa5f2019-04-24 17:46:42 -0400376 .cred = cred,
Chuck Lever423d8b02008-07-14 16:03:28 -0400377 .flags = (RPC_CLNT_CREATE_NOPING |
378 RPC_CLNT_CREATE_NONPRIVPORT),
Chuck Levera5090502007-03-29 16:48:04 -0400379 };
380
Chuck Leverd5b64432007-08-06 11:57:18 -0400381 switch (srvaddr->sa_family) {
382 case AF_INET:
383 ((struct sockaddr_in *)srvaddr)->sin_port = htons(RPCBIND_PORT);
384 break;
385 case AF_INET6:
386 ((struct sockaddr_in6 *)srvaddr)->sin6_port = htons(RPCBIND_PORT);
387 break;
388 default:
Pavel Emelyanovc636b572010-10-06 13:45:56 +0400389 return ERR_PTR(-EAFNOSUPPORT);
Chuck Leverd5b64432007-08-06 11:57:18 -0400390 }
391
Chuck Levera5090502007-03-29 16:48:04 -0400392 return rpc_create(&args);
393}
394
Trond Myklebust786615b2013-08-05 16:04:47 -0400395static int rpcb_register_call(struct sunrpc_net *sn, struct rpc_clnt *clnt, struct rpc_message *msg, bool is_set)
Chuck Leverbabe80e2008-07-14 16:03:29 -0400396{
Trond Myklebust786615b2013-08-05 16:04:47 -0400397 int flags = RPC_TASK_NOCONNECT;
398 int error, result = 0;
Chuck Leverbabe80e2008-07-14 16:03:29 -0400399
Trond Myklebust786615b2013-08-05 16:04:47 -0400400 if (is_set || !sn->rpcb_is_af_local)
401 flags = RPC_TASK_SOFTCONN;
Chuck Lever14aeb212008-08-18 19:34:00 -0400402 msg->rpc_resp = &result;
Chuck Leverbabe80e2008-07-14 16:03:29 -0400403
Trond Myklebust786615b2013-08-05 16:04:47 -0400404 error = rpc_call_sync(clnt, msg, flags);
Chuck Lever14aeb212008-08-18 19:34:00 -0400405 if (error < 0) {
Chuck Lever363f7242009-03-18 20:47:44 -0400406 dprintk("RPC: failed to contact local rpcbind "
Chuck Leverbabe80e2008-07-14 16:03:29 -0400407 "server (errno %d).\n", -error);
Chuck Lever14aeb212008-08-18 19:34:00 -0400408 return error;
409 }
Chuck Leverbabe80e2008-07-14 16:03:29 -0400410
Chuck Leverdb820d62008-09-25 11:57:05 -0400411 if (!result)
Chuck Lever14aeb212008-08-18 19:34:00 -0400412 return -EACCES;
Chuck Lever14aeb212008-08-18 19:34:00 -0400413 return 0;
Chuck Leverbabe80e2008-07-14 16:03:29 -0400414}
415
Chuck Levera5090502007-03-29 16:48:04 -0400416/**
417 * rpcb_register - set or unset a port registration with the local rpcbind svc
Randy Dunlapbda14602012-05-13 10:35:40 -0700418 * @net: target network namespace
Chuck Levera5090502007-03-29 16:48:04 -0400419 * @prog: RPC program number to bind
420 * @vers: RPC version number to bind
Chuck Leverc2e1b092008-07-14 16:03:30 -0400421 * @prot: transport protocol to register
Chuck Levera5090502007-03-29 16:48:04 -0400422 * @port: port value to register
Chuck Lever14aeb212008-08-18 19:34:00 -0400423 *
424 * Returns zero if the registration request was dispatched successfully
425 * and the rpcbind daemon returned success. Otherwise, returns an errno
426 * value that reflects the nature of the error (request could not be
427 * dispatched, timed out, or rpcbind returned an error).
Chuck Levera5090502007-03-29 16:48:04 -0400428 *
Chuck Leverc2e1b092008-07-14 16:03:30 -0400429 * RPC services invoke this function to advertise their contact
430 * information via the system's rpcbind daemon. RPC services
431 * invoke this function once for each [program, version, transport]
432 * tuple they wish to advertise.
Chuck Levera5090502007-03-29 16:48:04 -0400433 *
Chuck Leverc2e1b092008-07-14 16:03:30 -0400434 * Callers may also unregister RPC services that are no longer
435 * available by setting the passed-in port to zero. This removes
436 * all registered transports for [program, version] from the local
437 * rpcbind database.
438 *
Chuck Leverc2e1b092008-07-14 16:03:30 -0400439 * This function uses rpcbind protocol version 2 to contact the
440 * local rpcbind daemon.
441 *
442 * Registration works over both AF_INET and AF_INET6, and services
443 * registered via this function are advertised as available for any
444 * address. If the local rpcbind daemon is listening on AF_INET6,
445 * services registered via this function will be advertised on
446 * IN6ADDR_ANY (ie available for all AF_INET and AF_INET6
447 * addresses).
Chuck Levera5090502007-03-29 16:48:04 -0400448 */
Stanislav Kinsbursky977ac312012-01-13 12:52:43 +0400449int rpcb_register(struct net *net, u32 prog, u32 vers, int prot, unsigned short port)
Chuck Levera5090502007-03-29 16:48:04 -0400450{
Chuck Levera5090502007-03-29 16:48:04 -0400451 struct rpcbind_args map = {
452 .r_prog = prog,
453 .r_vers = vers,
454 .r_prot = prot,
455 .r_port = port,
456 };
457 struct rpc_message msg = {
Chuck Levera5090502007-03-29 16:48:04 -0400458 .rpc_argp = &map,
Chuck Levera5090502007-03-29 16:48:04 -0400459 };
Stanislav Kinsbursky977ac312012-01-13 12:52:43 +0400460 struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
Trond Myklebust786615b2013-08-05 16:04:47 -0400461 bool is_set = false;
Chuck Levera5090502007-03-29 16:48:04 -0400462
463 dprintk("RPC: %sregistering (%u, %u, %d, %u) with local "
464 "rpcbind\n", (port ? "" : "un"),
465 prog, vers, prot, port);
466
Chuck Leverbabe80e2008-07-14 16:03:29 -0400467 msg.rpc_proc = &rpcb_procedures2[RPCBPROC_UNSET];
Trond Myklebust786615b2013-08-05 16:04:47 -0400468 if (port != 0) {
Chuck Leverbabe80e2008-07-14 16:03:29 -0400469 msg.rpc_proc = &rpcb_procedures2[RPCBPROC_SET];
Trond Myklebust786615b2013-08-05 16:04:47 -0400470 is_set = true;
471 }
Chuck Leverbabe80e2008-07-14 16:03:29 -0400472
Trond Myklebust786615b2013-08-05 16:04:47 -0400473 return rpcb_register_call(sn, sn->rpcb_local_clnt, &msg, is_set);
Chuck Levera5090502007-03-29 16:48:04 -0400474}
475
Chuck Leverc2e1b092008-07-14 16:03:30 -0400476/*
477 * Fill in AF_INET family-specific arguments to register
478 */
Stanislav Kinsbursky1a114a62012-01-13 12:52:26 +0400479static int rpcb_register_inet4(struct sunrpc_net *sn,
480 const struct sockaddr *sap,
Chuck Lever1673d0d2009-03-18 20:47:21 -0400481 struct rpc_message *msg)
Chuck Leverc2e1b092008-07-14 16:03:30 -0400482{
Chuck Lever3aba4552009-03-18 20:47:06 -0400483 const struct sockaddr_in *sin = (const struct sockaddr_in *)sap;
Chuck Leverc2e1b092008-07-14 16:03:30 -0400484 struct rpcbind_args *map = msg->rpc_argp;
Chuck Lever3aba4552009-03-18 20:47:06 -0400485 unsigned short port = ntohs(sin->sin_port);
Trond Myklebust786615b2013-08-05 16:04:47 -0400486 bool is_set = false;
Chuck Leverba809132009-08-09 15:09:35 -0400487 int result;
Chuck Leverc2e1b092008-07-14 16:03:30 -0400488
Trond Myklebustd77385f2011-10-17 16:08:10 -0700489 map->r_addr = rpc_sockaddr2uaddr(sap, GFP_KERNEL);
Chuck Leverc2e1b092008-07-14 16:03:30 -0400490
491 dprintk("RPC: %sregistering [%u, %u, %s, '%s'] with "
492 "local rpcbind\n", (port ? "" : "un"),
493 map->r_prog, map->r_vers,
494 map->r_addr, map->r_netid);
495
496 msg->rpc_proc = &rpcb_procedures4[RPCBPROC_UNSET];
Trond Myklebust786615b2013-08-05 16:04:47 -0400497 if (port != 0) {
Chuck Leverc2e1b092008-07-14 16:03:30 -0400498 msg->rpc_proc = &rpcb_procedures4[RPCBPROC_SET];
Trond Myklebust786615b2013-08-05 16:04:47 -0400499 is_set = true;
500 }
Chuck Leverc2e1b092008-07-14 16:03:30 -0400501
Trond Myklebust786615b2013-08-05 16:04:47 -0400502 result = rpcb_register_call(sn, sn->rpcb_local_clnt4, msg, is_set);
Chuck Leverba809132009-08-09 15:09:35 -0400503 kfree(map->r_addr);
504 return result;
Chuck Leverc2e1b092008-07-14 16:03:30 -0400505}
506
507/*
508 * Fill in AF_INET6 family-specific arguments to register
509 */
Stanislav Kinsbursky1a114a62012-01-13 12:52:26 +0400510static int rpcb_register_inet6(struct sunrpc_net *sn,
511 const struct sockaddr *sap,
Chuck Lever1673d0d2009-03-18 20:47:21 -0400512 struct rpc_message *msg)
Chuck Leverc2e1b092008-07-14 16:03:30 -0400513{
Chuck Lever3aba4552009-03-18 20:47:06 -0400514 const struct sockaddr_in6 *sin6 = (const struct sockaddr_in6 *)sap;
Chuck Leverc2e1b092008-07-14 16:03:30 -0400515 struct rpcbind_args *map = msg->rpc_argp;
Chuck Lever3aba4552009-03-18 20:47:06 -0400516 unsigned short port = ntohs(sin6->sin6_port);
Trond Myklebust786615b2013-08-05 16:04:47 -0400517 bool is_set = false;
Chuck Leverba809132009-08-09 15:09:35 -0400518 int result;
Chuck Leverc2e1b092008-07-14 16:03:30 -0400519
Trond Myklebustd77385f2011-10-17 16:08:10 -0700520 map->r_addr = rpc_sockaddr2uaddr(sap, GFP_KERNEL);
Chuck Leverc2e1b092008-07-14 16:03:30 -0400521
522 dprintk("RPC: %sregistering [%u, %u, %s, '%s'] with "
523 "local rpcbind\n", (port ? "" : "un"),
524 map->r_prog, map->r_vers,
525 map->r_addr, map->r_netid);
526
527 msg->rpc_proc = &rpcb_procedures4[RPCBPROC_UNSET];
Trond Myklebust786615b2013-08-05 16:04:47 -0400528 if (port != 0) {
Chuck Leverc2e1b092008-07-14 16:03:30 -0400529 msg->rpc_proc = &rpcb_procedures4[RPCBPROC_SET];
Trond Myklebust786615b2013-08-05 16:04:47 -0400530 is_set = true;
531 }
Chuck Leverc2e1b092008-07-14 16:03:30 -0400532
Trond Myklebust786615b2013-08-05 16:04:47 -0400533 result = rpcb_register_call(sn, sn->rpcb_local_clnt4, msg, is_set);
Chuck Leverba809132009-08-09 15:09:35 -0400534 kfree(map->r_addr);
535 return result;
Chuck Leverc2e1b092008-07-14 16:03:30 -0400536}
537
Stanislav Kinsbursky1a114a62012-01-13 12:52:26 +0400538static int rpcb_unregister_all_protofamilies(struct sunrpc_net *sn,
539 struct rpc_message *msg)
Chuck Lever1673d0d2009-03-18 20:47:21 -0400540{
541 struct rpcbind_args *map = msg->rpc_argp;
542
543 dprintk("RPC: unregistering [%u, %u, '%s'] with "
544 "local rpcbind\n",
545 map->r_prog, map->r_vers, map->r_netid);
546
547 map->r_addr = "";
548 msg->rpc_proc = &rpcb_procedures4[RPCBPROC_UNSET];
549
Trond Myklebust786615b2013-08-05 16:04:47 -0400550 return rpcb_register_call(sn, sn->rpcb_local_clnt4, msg, false);
Chuck Lever1673d0d2009-03-18 20:47:21 -0400551}
552
Chuck Leverc2e1b092008-07-14 16:03:30 -0400553/**
554 * rpcb_v4_register - set or unset a port registration with the local rpcbind
Randy Dunlapbda14602012-05-13 10:35:40 -0700555 * @net: target network namespace
Chuck Leverc2e1b092008-07-14 16:03:30 -0400556 * @program: RPC program number of service to (un)register
557 * @version: RPC version number of service to (un)register
558 * @address: address family, IP address, and port to (un)register
559 * @netid: netid of transport protocol to (un)register
Chuck Lever14aeb212008-08-18 19:34:00 -0400560 *
561 * Returns zero if the registration request was dispatched successfully
562 * and the rpcbind daemon returned success. Otherwise, returns an errno
563 * value that reflects the nature of the error (request could not be
564 * dispatched, timed out, or rpcbind returned an error).
Chuck Leverc2e1b092008-07-14 16:03:30 -0400565 *
566 * RPC services invoke this function to advertise their contact
567 * information via the system's rpcbind daemon. RPC services
568 * invoke this function once for each [program, version, address,
569 * netid] tuple they wish to advertise.
570 *
Chuck Lever1673d0d2009-03-18 20:47:21 -0400571 * Callers may also unregister RPC services that are registered at a
572 * specific address by setting the port number in @address to zero.
573 * They may unregister all registered protocol families at once for
574 * a service by passing a NULL @address argument. If @netid is ""
575 * then all netids for [program, version, address] are unregistered.
Chuck Leverc2e1b092008-07-14 16:03:30 -0400576 *
Chuck Leverc2e1b092008-07-14 16:03:30 -0400577 * This function uses rpcbind protocol version 4 to contact the
578 * local rpcbind daemon. The local rpcbind daemon must support
579 * version 4 of the rpcbind protocol in order for these functions
580 * to register a service successfully.
581 *
582 * Supported netids include "udp" and "tcp" for UDP and TCP over
583 * IPv4, and "udp6" and "tcp6" for UDP and TCP over IPv6,
584 * respectively.
585 *
586 * The contents of @address determine the address family and the
587 * port to be registered. The usual practice is to pass INADDR_ANY
588 * as the raw address, but specifying a non-zero address is also
589 * supported by this API if the caller wishes to advertise an RPC
590 * service on a specific network interface.
591 *
592 * Note that passing in INADDR_ANY does not create the same service
593 * registration as IN6ADDR_ANY. The former advertises an RPC
594 * service on any IPv4 address, but not on IPv6. The latter
595 * advertises the service on all IPv4 and IPv6 addresses.
596 */
Stanislav Kinsbursky977ac312012-01-13 12:52:43 +0400597int rpcb_v4_register(struct net *net, const u32 program, const u32 version,
Chuck Lever14aeb212008-08-18 19:34:00 -0400598 const struct sockaddr *address, const char *netid)
Chuck Leverc2e1b092008-07-14 16:03:30 -0400599{
600 struct rpcbind_args map = {
601 .r_prog = program,
602 .r_vers = version,
603 .r_netid = netid,
604 .r_owner = RPCB_OWNER_STRING,
605 };
606 struct rpc_message msg = {
607 .rpc_argp = &map,
Chuck Leverc2e1b092008-07-14 16:03:30 -0400608 };
Stanislav Kinsbursky977ac312012-01-13 12:52:43 +0400609 struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
Chuck Leverc5266112009-12-03 15:58:56 -0500610
Stanislav Kinsburskydff02d42012-01-13 12:52:10 +0400611 if (sn->rpcb_local_clnt4 == NULL)
Chuck Leverc5266112009-12-03 15:58:56 -0500612 return -EPROTONOSUPPORT;
Chuck Leverc2e1b092008-07-14 16:03:30 -0400613
Chuck Lever1673d0d2009-03-18 20:47:21 -0400614 if (address == NULL)
Stanislav Kinsbursky1a114a62012-01-13 12:52:26 +0400615 return rpcb_unregister_all_protofamilies(sn, &msg);
Chuck Lever1673d0d2009-03-18 20:47:21 -0400616
Chuck Leverc2e1b092008-07-14 16:03:30 -0400617 switch (address->sa_family) {
618 case AF_INET:
Stanislav Kinsbursky1a114a62012-01-13 12:52:26 +0400619 return rpcb_register_inet4(sn, address, &msg);
Chuck Leverc2e1b092008-07-14 16:03:30 -0400620 case AF_INET6:
Stanislav Kinsbursky1a114a62012-01-13 12:52:26 +0400621 return rpcb_register_inet6(sn, address, &msg);
Chuck Leverc2e1b092008-07-14 16:03:30 -0400622 }
623
624 return -EAFNOSUPPORT;
625}
626
Christoph Hellwig499b4982017-05-12 15:36:49 +0200627static struct rpc_task *rpcb_call_async(struct rpc_clnt *rpcb_clnt,
628 struct rpcbind_args *map, const struct rpc_procinfo *proc)
Trond Myklebust5138fde2007-07-14 15:40:01 -0400629{
630 struct rpc_message msg = {
Trond Myklebust803a9062008-07-01 15:20:55 -0400631 .rpc_proc = proc,
Trond Myklebust5138fde2007-07-14 15:40:01 -0400632 .rpc_argp = map,
Chuck Leverc0c077d2009-08-09 15:09:43 -0400633 .rpc_resp = map,
Trond Myklebust5138fde2007-07-14 15:40:01 -0400634 };
635 struct rpc_task_setup task_setup_data = {
636 .rpc_client = rpcb_clnt,
637 .rpc_message = &msg,
638 .callback_ops = &rpcb_getport_ops,
639 .callback_data = map,
Chuck Lever012da152009-12-03 15:58:56 -0500640 .flags = RPC_TASK_ASYNC | RPC_TASK_SOFTCONN,
Trond Myklebust5138fde2007-07-14 15:40:01 -0400641 };
642
643 return rpc_run_task(&task_setup_data);
644}
645
Trond Myklebust9a4bd292008-10-03 16:48:34 -0400646/*
647 * In the case where rpc clients have been cloned, we want to make
648 * sure that we use the program number/version etc of the actual
649 * owner of the xprt. To do so, we walk back up the tree of parents
650 * to find whoever created the transport and/or whoever has the
651 * autobind flag set.
652 */
653static struct rpc_clnt *rpcb_find_transport_owner(struct rpc_clnt *clnt)
654{
655 struct rpc_clnt *parent = clnt->cl_parent;
Trond Myklebustad01b2c2016-01-30 14:17:26 -0500656 struct rpc_xprt_switch *xps = rcu_access_pointer(clnt->cl_xpi.xpi_xpswitch);
Trond Myklebust9a4bd292008-10-03 16:48:34 -0400657
658 while (parent != clnt) {
Trond Myklebustad01b2c2016-01-30 14:17:26 -0500659 if (rcu_access_pointer(parent->cl_xpi.xpi_xpswitch) != xps)
Trond Myklebust9a4bd292008-10-03 16:48:34 -0400660 break;
661 if (clnt->cl_autobind)
662 break;
663 clnt = parent;
664 parent = parent->cl_parent;
665 }
666 return clnt;
667}
668
Chuck Levera5090502007-03-29 16:48:04 -0400669/**
Chuck Lever45160d62007-07-01 12:13:17 -0400670 * rpcb_getport_async - obtain the port for a given RPC service on a given host
Chuck Levera5090502007-03-29 16:48:04 -0400671 * @task: task that is waiting for portmapper request
672 *
673 * This one can be called for an ongoing RPC request, and can be used in
674 * an async (rpciod) context.
675 */
Chuck Lever45160d62007-07-01 12:13:17 -0400676void rpcb_getport_async(struct rpc_task *task)
Chuck Levera5090502007-03-29 16:48:04 -0400677{
Trond Myklebust9a4bd292008-10-03 16:48:34 -0400678 struct rpc_clnt *clnt;
Christoph Hellwig499b4982017-05-12 15:36:49 +0200679 const struct rpc_procinfo *proc;
Chuck Lever0a48f5d2007-12-10 14:56:38 -0500680 u32 bind_version;
Trond Myklebust9a4bd292008-10-03 16:48:34 -0400681 struct rpc_xprt *xprt;
Chuck Levera5090502007-03-29 16:48:04 -0400682 struct rpc_clnt *rpcb_clnt;
Ben Greearec0dd262011-07-12 10:27:55 -0700683 struct rpcbind_args *map;
Chuck Levera5090502007-03-29 16:48:04 -0400684 struct rpc_task *child;
Chuck Lever9f6ad262007-12-10 14:56:31 -0500685 struct sockaddr_storage addr;
686 struct sockaddr *sap = (struct sockaddr *)&addr;
687 size_t salen;
Chuck Levera5090502007-03-29 16:48:04 -0400688 int status;
689
Trond Myklebust2446ab62012-03-01 17:00:56 -0500690 rcu_read_lock();
Trond Myklebustfb43d172016-01-30 16:39:26 -0500691 clnt = rpcb_find_transport_owner(task->tk_client);
Trond Myklebust2446ab62012-03-01 17:00:56 -0500692 rcu_read_unlock();
Trond Myklebustfb43d172016-01-30 16:39:26 -0500693 xprt = xprt_get(task->tk_xprt);
Trond Myklebust9a4bd292008-10-03 16:48:34 -0400694
Chuck Lever45160d62007-07-01 12:13:17 -0400695 dprintk("RPC: %5u %s(%s, %u, %u, %d)\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -0800696 task->tk_pid, __func__,
Trond Myklebust4e0038b2012-03-01 17:01:05 -0500697 xprt->servername, clnt->cl_prog, clnt->cl_vers, xprt->prot);
Chuck Levera5090502007-03-29 16:48:04 -0400698
Trond Myklebust381ba742008-07-07 12:18:53 -0400699 /* Put self on the wait queue to ensure we get notified if
700 * some other task is already attempting to bind the port */
Trond Myklebust6b2e6852019-04-07 13:58:49 -0400701 rpc_sleep_on_timeout(&xprt->binding, task,
702 NULL, jiffies + xprt->bind_timeout);
Trond Myklebust381ba742008-07-07 12:18:53 -0400703
Chuck Levera5090502007-03-29 16:48:04 -0400704 if (xprt_test_and_set_binding(xprt)) {
Chuck Lever45160d62007-07-01 12:13:17 -0400705 dprintk("RPC: %5u %s: waiting for another binder\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -0800706 task->tk_pid, __func__);
Trond Myklebust2446ab62012-03-01 17:00:56 -0500707 xprt_put(xprt);
Trond Myklebust381ba742008-07-07 12:18:53 -0400708 return;
Chuck Levera5090502007-03-29 16:48:04 -0400709 }
710
Chuck Levera5090502007-03-29 16:48:04 -0400711 /* Someone else may have bound if we slept */
712 if (xprt_bound(xprt)) {
713 status = 0;
Chuck Lever45160d62007-07-01 12:13:17 -0400714 dprintk("RPC: %5u %s: already bound\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -0800715 task->tk_pid, __func__);
Chuck Levera5090502007-03-29 16:48:04 -0400716 goto bailout_nofree;
717 }
718
Chuck Leverba809132009-08-09 15:09:35 -0400719 /* Parent transport's destination address */
Chuck Lever9f6ad262007-12-10 14:56:31 -0500720 salen = rpc_peeraddr(clnt, sap, sizeof(addr));
Chuck Leverd5b64432007-08-06 11:57:18 -0400721
722 /* Don't ever use rpcbind v2 for AF_INET6 requests */
Chuck Lever9f6ad262007-12-10 14:56:31 -0500723 switch (sap->sa_family) {
Chuck Leverd5b64432007-08-06 11:57:18 -0400724 case AF_INET:
Trond Myklebust803a9062008-07-01 15:20:55 -0400725 proc = rpcb_next_version[xprt->bind_index].rpc_proc;
726 bind_version = rpcb_next_version[xprt->bind_index].rpc_vers;
Chuck Leverd5b64432007-08-06 11:57:18 -0400727 break;
728 case AF_INET6:
Trond Myklebust803a9062008-07-01 15:20:55 -0400729 proc = rpcb_next_version6[xprt->bind_index].rpc_proc;
730 bind_version = rpcb_next_version6[xprt->bind_index].rpc_vers;
Chuck Leverd5b64432007-08-06 11:57:18 -0400731 break;
732 default:
733 status = -EAFNOSUPPORT;
734 dprintk("RPC: %5u %s: bad address family\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -0800735 task->tk_pid, __func__);
Chuck Leverd5b64432007-08-06 11:57:18 -0400736 goto bailout_nofree;
737 }
Trond Myklebust803a9062008-07-01 15:20:55 -0400738 if (proc == NULL) {
Chuck Levera5090502007-03-29 16:48:04 -0400739 xprt->bind_index = 0;
Chuck Lever906462a2007-09-11 18:00:47 -0400740 status = -EPFNOSUPPORT;
Chuck Lever45160d62007-07-01 12:13:17 -0400741 dprintk("RPC: %5u %s: no more getport versions available\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -0800742 task->tk_pid, __func__);
Chuck Levera5090502007-03-29 16:48:04 -0400743 goto bailout_nofree;
744 }
Chuck Levera5090502007-03-29 16:48:04 -0400745
Chuck Lever45160d62007-07-01 12:13:17 -0400746 dprintk("RPC: %5u %s: trying rpcbind version %u\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -0800747 task->tk_pid, __func__, bind_version);
Chuck Levera5090502007-03-29 16:48:04 -0400748
Trond Myklebust03a9a422015-01-30 18:12:28 -0500749 rpcb_clnt = rpcb_create(xprt->xprt_net,
750 clnt->cl_nodename,
751 xprt->servername, sap, salen,
Trond Myklebust79caa5f2019-04-24 17:46:42 -0400752 xprt->prot, bind_version,
753 clnt->cl_cred);
Chuck Lever143b6c42007-08-16 16:03:31 -0400754 if (IS_ERR(rpcb_clnt)) {
755 status = PTR_ERR(rpcb_clnt);
756 dprintk("RPC: %5u %s: rpcb_create failed, error %ld\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -0800757 task->tk_pid, __func__, PTR_ERR(rpcb_clnt));
Chuck Lever143b6c42007-08-16 16:03:31 -0400758 goto bailout_nofree;
759 }
760
J. Bruce Fieldscb24e352018-12-20 10:42:36 -0500761 map = kzalloc(sizeof(struct rpcbind_args), GFP_NOFS);
Chuck Levera5090502007-03-29 16:48:04 -0400762 if (!map) {
763 status = -ENOMEM;
Chuck Lever45160d62007-07-01 12:13:17 -0400764 dprintk("RPC: %5u %s: no memory available\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -0800765 task->tk_pid, __func__);
Trond Myklebust96165e22008-10-03 16:48:40 -0400766 goto bailout_release_client;
Chuck Levera5090502007-03-29 16:48:04 -0400767 }
768 map->r_prog = clnt->cl_prog;
769 map->r_vers = clnt->cl_vers;
770 map->r_prot = xprt->prot;
771 map->r_port = 0;
Bryan Schumaker864cf9b2012-03-27 13:46:32 -0400772 map->r_xprt = xprt;
Trond Myklebust381ba742008-07-07 12:18:53 -0400773 map->r_status = -EIO;
Chuck Levera5090502007-03-29 16:48:04 -0400774
Chuck Leverba809132009-08-09 15:09:35 -0400775 switch (bind_version) {
776 case RPCBVERS_4:
777 case RPCBVERS_3:
Trond Myklebust2446ab62012-03-01 17:00:56 -0500778 map->r_netid = xprt->address_strings[RPC_DISPLAY_NETID];
J. Bruce Fieldscb24e352018-12-20 10:42:36 -0500779 map->r_addr = rpc_sockaddr2uaddr(sap, GFP_NOFS);
J. Bruce Fields81c88b12018-12-20 10:35:11 -0500780 if (!map->r_addr) {
781 status = -ENOMEM;
782 dprintk("RPC: %5u %s: no memory available\n",
783 task->tk_pid, __func__);
784 goto bailout_free_args;
785 }
Chuck Leverba809132009-08-09 15:09:35 -0400786 map->r_owner = "";
787 break;
788 case RPCBVERS_2:
789 map->r_addr = NULL;
790 break;
791 default:
792 BUG();
793 }
794
Trond Myklebust803a9062008-07-01 15:20:55 -0400795 child = rpcb_call_async(rpcb_clnt, map, proc);
Trond Myklebust4c402b42007-06-14 16:40:32 -0400796 rpc_release_client(rpcb_clnt);
Chuck Levera5090502007-03-29 16:48:04 -0400797 if (IS_ERR(child)) {
Trond Myklebust0d3a34b2008-07-07 12:18:52 -0400798 /* rpcb_map_release() has freed the arguments */
Chuck Lever45160d62007-07-01 12:13:17 -0400799 dprintk("RPC: %5u %s: rpc_run_task failed\n",
Harvey Harrison0dc47872008-03-05 20:47:47 -0800800 task->tk_pid, __func__);
Trond Myklebust381ba742008-07-07 12:18:53 -0400801 return;
Chuck Levera5090502007-03-29 16:48:04 -0400802 }
Chuck Levera5090502007-03-29 16:48:04 -0400803
Trond Myklebust9a4bd292008-10-03 16:48:34 -0400804 xprt->stat.bind_count++;
805 rpc_put_task(child);
Chuck Levera5090502007-03-29 16:48:04 -0400806 return;
807
J. Bruce Fields81c88b12018-12-20 10:35:11 -0500808bailout_free_args:
809 kfree(map);
Trond Myklebust96165e22008-10-03 16:48:40 -0400810bailout_release_client:
811 rpc_release_client(rpcb_clnt);
Chuck Levera5090502007-03-29 16:48:04 -0400812bailout_nofree:
813 rpcb_wake_rpcbind_waiters(xprt, status);
Chuck Levera5090502007-03-29 16:48:04 -0400814 task->tk_status = status;
Trond Myklebust2446ab62012-03-01 17:00:56 -0500815 xprt_put(xprt);
Chuck Levera5090502007-03-29 16:48:04 -0400816}
\"Talpey, Thomas\12444802007-09-10 13:45:36 -0400817EXPORT_SYMBOL_GPL(rpcb_getport_async);
Chuck Levera5090502007-03-29 16:48:04 -0400818
819/*
820 * Rpcbind child task calls this callback via tk_exit.
821 */
822static void rpcb_getport_done(struct rpc_task *child, void *data)
823{
824 struct rpcbind_args *map = data;
825 struct rpc_xprt *xprt = map->r_xprt;
826 int status = child->tk_status;
827
Chuck Lever4784cb52007-09-11 18:00:36 -0400828 /* Garbage reply: retry with a lesser rpcbind version */
829 if (status == -EIO)
830 status = -EPROTONOSUPPORT;
831
Chuck Levera5090502007-03-29 16:48:04 -0400832 /* rpcbind server doesn't support this rpcbind protocol version */
833 if (status == -EPROTONOSUPPORT)
834 xprt->bind_index++;
835
836 if (status < 0) {
837 /* rpcbind server not available on remote host? */
838 xprt->ops->set_port(xprt, 0);
839 } else if (map->r_port == 0) {
840 /* Requested RPC service wasn't registered on remote host */
841 xprt->ops->set_port(xprt, 0);
842 status = -EACCES;
843 } else {
844 /* Succeeded */
845 xprt->ops->set_port(xprt, map->r_port);
846 xprt_set_bound(xprt);
847 status = 0;
848 }
849
850 dprintk("RPC: %5u rpcb_getport_done(status %d, port %u)\n",
851 child->tk_pid, status, map->r_port);
852
Trond Myklebust381ba742008-07-07 12:18:53 -0400853 map->r_status = status;
Chuck Levera5090502007-03-29 16:48:04 -0400854}
855
Chuck Lever166b88d2008-07-14 16:03:26 -0400856/*
857 * XDR functions for rpcbind
858 */
859
Chuck Lever9f06c712010-12-14 14:59:18 +0000860static void rpcb_enc_mapping(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwig7d55f7f2017-05-08 09:59:45 +0200861 const void *data)
Chuck Lever6f2c2db2009-08-09 15:09:40 -0400862{
Christoph Hellwig7d55f7f2017-05-08 09:59:45 +0200863 const struct rpcbind_args *rpcb = data;
Chuck Lever9f06c712010-12-14 14:59:18 +0000864 __be32 *p;
Chuck Lever6f2c2db2009-08-09 15:09:40 -0400865
866 dprintk("RPC: %5u encoding PMAP_%s call (%u, %u, %d, %u)\n",
Trond Myklebustffa94db2012-03-20 09:22:00 -0400867 req->rq_task->tk_pid,
868 req->rq_task->tk_msg.rpc_proc->p_name,
Chuck Lever6f2c2db2009-08-09 15:09:40 -0400869 rpcb->r_prog, rpcb->r_vers, rpcb->r_prot, rpcb->r_port);
870
Chuck Lever9f06c712010-12-14 14:59:18 +0000871 p = xdr_reserve_space(xdr, RPCB_mappingargs_sz << 2);
Chuck Lever4129ccf2010-12-14 14:58:59 +0000872 *p++ = cpu_to_be32(rpcb->r_prog);
873 *p++ = cpu_to_be32(rpcb->r_vers);
874 *p++ = cpu_to_be32(rpcb->r_prot);
875 *p = cpu_to_be32(rpcb->r_port);
Chuck Lever6f2c2db2009-08-09 15:09:40 -0400876}
877
Chuck Leverbf269552010-12-14 14:59:29 +0000878static int rpcb_dec_getport(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwig605d7122017-05-08 15:00:29 +0200879 void *data)
Chuck Leverc0c077d2009-08-09 15:09:43 -0400880{
Christoph Hellwig605d7122017-05-08 15:00:29 +0200881 struct rpcbind_args *rpcb = data;
Chuck Leverc0c077d2009-08-09 15:09:43 -0400882 unsigned long port;
Chuck Leverbf269552010-12-14 14:59:29 +0000883 __be32 *p;
Chuck Leverc0c077d2009-08-09 15:09:43 -0400884
885 rpcb->r_port = 0;
886
Chuck Leverbf269552010-12-14 14:59:29 +0000887 p = xdr_inline_decode(xdr, 4);
Chuck Leverc0c077d2009-08-09 15:09:43 -0400888 if (unlikely(p == NULL))
889 return -EIO;
890
Chuck Lever4129ccf2010-12-14 14:58:59 +0000891 port = be32_to_cpup(p);
Trond Myklebustffa94db2012-03-20 09:22:00 -0400892 dprintk("RPC: %5u PMAP_%s result: %lu\n", req->rq_task->tk_pid,
893 req->rq_task->tk_msg.rpc_proc->p_name, port);
Alexey Dobriyan4be929b2010-05-24 14:33:03 -0700894 if (unlikely(port > USHRT_MAX))
Chuck Leverc0c077d2009-08-09 15:09:43 -0400895 return -EIO;
896
897 rpcb->r_port = port;
898 return 0;
899}
900
Chuck Leverbf269552010-12-14 14:59:29 +0000901static int rpcb_dec_set(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwig605d7122017-05-08 15:00:29 +0200902 void *data)
Chuck Lever7ed0ff92009-08-09 15:09:42 -0400903{
Christoph Hellwig605d7122017-05-08 15:00:29 +0200904 unsigned int *boolp = data;
Chuck Leverbf269552010-12-14 14:59:29 +0000905 __be32 *p;
Chuck Lever7ed0ff92009-08-09 15:09:42 -0400906
Chuck Leverbf269552010-12-14 14:59:29 +0000907 p = xdr_inline_decode(xdr, 4);
Chuck Lever7ed0ff92009-08-09 15:09:42 -0400908 if (unlikely(p == NULL))
909 return -EIO;
910
911 *boolp = 0;
Chuck Leverbf269552010-12-14 14:59:29 +0000912 if (*p != xdr_zero)
Chuck Lever7ed0ff92009-08-09 15:09:42 -0400913 *boolp = 1;
914
915 dprintk("RPC: %5u RPCB_%s call %s\n",
Trond Myklebustffa94db2012-03-20 09:22:00 -0400916 req->rq_task->tk_pid,
917 req->rq_task->tk_msg.rpc_proc->p_name,
Chuck Lever7ed0ff92009-08-09 15:09:42 -0400918 (*boolp ? "succeeded" : "failed"));
919 return 0;
920}
921
Chuck Lever4129ccf2010-12-14 14:58:59 +0000922static void encode_rpcb_string(struct xdr_stream *xdr, const char *string,
923 const u32 maxstrlen)
Chuck Lever6f2c2db2009-08-09 15:09:40 -0400924{
Chuck Lever6f2c2db2009-08-09 15:09:40 -0400925 __be32 *p;
Chuck Lever4129ccf2010-12-14 14:58:59 +0000926 u32 len;
Chuck Lever6f2c2db2009-08-09 15:09:40 -0400927
Chuck Lever6f2c2db2009-08-09 15:09:40 -0400928 len = strlen(string);
Weston Andros Adamson332e0082012-10-23 10:43:44 -0400929 WARN_ON_ONCE(len > maxstrlen);
930 if (len > maxstrlen)
931 /* truncate and hope for the best */
932 len = maxstrlen;
Chuck Lever4129ccf2010-12-14 14:58:59 +0000933 p = xdr_reserve_space(xdr, 4 + len);
Chuck Lever6f2c2db2009-08-09 15:09:40 -0400934 xdr_encode_opaque(p, string, len);
Chuck Lever6f2c2db2009-08-09 15:09:40 -0400935}
936
Chuck Lever9f06c712010-12-14 14:59:18 +0000937static void rpcb_enc_getaddr(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwig7d55f7f2017-05-08 09:59:45 +0200938 const void *data)
Chuck Lever6f2c2db2009-08-09 15:09:40 -0400939{
Christoph Hellwig7d55f7f2017-05-08 09:59:45 +0200940 const struct rpcbind_args *rpcb = data;
Chuck Lever9f06c712010-12-14 14:59:18 +0000941 __be32 *p;
Chuck Lever6f2c2db2009-08-09 15:09:40 -0400942
943 dprintk("RPC: %5u encoding RPCB_%s call (%u, %u, '%s', '%s')\n",
Trond Myklebustffa94db2012-03-20 09:22:00 -0400944 req->rq_task->tk_pid,
945 req->rq_task->tk_msg.rpc_proc->p_name,
Chuck Lever6f2c2db2009-08-09 15:09:40 -0400946 rpcb->r_prog, rpcb->r_vers,
947 rpcb->r_netid, rpcb->r_addr);
948
Chuck Lever9f06c712010-12-14 14:59:18 +0000949 p = xdr_reserve_space(xdr, (RPCB_program_sz + RPCB_version_sz) << 2);
Chuck Lever4129ccf2010-12-14 14:58:59 +0000950 *p++ = cpu_to_be32(rpcb->r_prog);
951 *p = cpu_to_be32(rpcb->r_vers);
Chuck Lever6f2c2db2009-08-09 15:09:40 -0400952
Chuck Lever9f06c712010-12-14 14:59:18 +0000953 encode_rpcb_string(xdr, rpcb->r_netid, RPCBIND_MAXNETIDLEN);
954 encode_rpcb_string(xdr, rpcb->r_addr, RPCBIND_MAXUADDRLEN);
955 encode_rpcb_string(xdr, rpcb->r_owner, RPCB_MAXOWNERLEN);
Chuck Lever6f2c2db2009-08-09 15:09:40 -0400956}
957
Chuck Leverbf269552010-12-14 14:59:29 +0000958static int rpcb_dec_getaddr(struct rpc_rqst *req, struct xdr_stream *xdr,
Christoph Hellwig605d7122017-05-08 15:00:29 +0200959 void *data)
Chuck Leverc0c077d2009-08-09 15:09:43 -0400960{
Christoph Hellwig605d7122017-05-08 15:00:29 +0200961 struct rpcbind_args *rpcb = data;
Chuck Leverc0c077d2009-08-09 15:09:43 -0400962 struct sockaddr_storage address;
963 struct sockaddr *sap = (struct sockaddr *)&address;
Chuck Leverbf269552010-12-14 14:59:29 +0000964 __be32 *p;
Chuck Leverc0c077d2009-08-09 15:09:43 -0400965 u32 len;
966
967 rpcb->r_port = 0;
968
Chuck Leverbf269552010-12-14 14:59:29 +0000969 p = xdr_inline_decode(xdr, 4);
Chuck Leverc0c077d2009-08-09 15:09:43 -0400970 if (unlikely(p == NULL))
971 goto out_fail;
Chuck Lever4129ccf2010-12-14 14:58:59 +0000972 len = be32_to_cpup(p);
Chuck Leverc0c077d2009-08-09 15:09:43 -0400973
974 /*
975 * If the returned universal address is a null string,
976 * the requested RPC service was not registered.
977 */
978 if (len == 0) {
979 dprintk("RPC: %5u RPCB reply: program not registered\n",
Trond Myklebustffa94db2012-03-20 09:22:00 -0400980 req->rq_task->tk_pid);
Chuck Leverc0c077d2009-08-09 15:09:43 -0400981 return 0;
982 }
983
984 if (unlikely(len > RPCBIND_MAXUADDRLEN))
985 goto out_fail;
986
Chuck Leverbf269552010-12-14 14:59:29 +0000987 p = xdr_inline_decode(xdr, len);
Chuck Leverc0c077d2009-08-09 15:09:43 -0400988 if (unlikely(p == NULL))
989 goto out_fail;
Trond Myklebustffa94db2012-03-20 09:22:00 -0400990 dprintk("RPC: %5u RPCB_%s reply: %s\n", req->rq_task->tk_pid,
991 req->rq_task->tk_msg.rpc_proc->p_name, (char *)p);
Chuck Leverc0c077d2009-08-09 15:09:43 -0400992
Stanislav Kinsburskyb030fb02012-01-13 14:02:40 +0400993 if (rpc_uaddr2sockaddr(req->rq_xprt->xprt_net, (char *)p, len,
994 sap, sizeof(address)) == 0)
Chuck Leverc0c077d2009-08-09 15:09:43 -0400995 goto out_fail;
996 rpcb->r_port = rpc_get_port(sap);
997
998 return 0;
999
1000out_fail:
1001 dprintk("RPC: %5u malformed RPCB_%s reply\n",
Trond Myklebustffa94db2012-03-20 09:22:00 -04001002 req->rq_task->tk_pid,
1003 req->rq_task->tk_msg.rpc_proc->p_name);
Chuck Leverc0c077d2009-08-09 15:09:43 -04001004 return -EIO;
1005}
1006
Chuck Levera5090502007-03-29 16:48:04 -04001007/*
1008 * Not all rpcbind procedures described in RFC 1833 are implemented
1009 * since the Linux kernel RPC code requires only these.
1010 */
Chuck Leverf8b761e2009-08-09 15:09:44 -04001011
Christoph Hellwig499b4982017-05-12 15:36:49 +02001012static const struct rpc_procinfo rpcb_procedures2[] = {
Chuck Leverf8b761e2009-08-09 15:09:44 -04001013 [RPCBPROC_SET] = {
1014 .p_proc = RPCBPROC_SET,
Christoph Hellwig7d55f7f2017-05-08 09:59:45 +02001015 .p_encode = rpcb_enc_mapping,
Christoph Hellwig605d7122017-05-08 15:00:29 +02001016 .p_decode = rpcb_dec_set,
Chuck Leverf8b761e2009-08-09 15:09:44 -04001017 .p_arglen = RPCB_mappingargs_sz,
1018 .p_replen = RPCB_setres_sz,
1019 .p_statidx = RPCBPROC_SET,
1020 .p_timer = 0,
1021 .p_name = "SET",
1022 },
1023 [RPCBPROC_UNSET] = {
1024 .p_proc = RPCBPROC_UNSET,
Christoph Hellwig7d55f7f2017-05-08 09:59:45 +02001025 .p_encode = rpcb_enc_mapping,
Christoph Hellwig605d7122017-05-08 15:00:29 +02001026 .p_decode = rpcb_dec_set,
Chuck Leverf8b761e2009-08-09 15:09:44 -04001027 .p_arglen = RPCB_mappingargs_sz,
1028 .p_replen = RPCB_setres_sz,
1029 .p_statidx = RPCBPROC_UNSET,
1030 .p_timer = 0,
1031 .p_name = "UNSET",
1032 },
1033 [RPCBPROC_GETPORT] = {
1034 .p_proc = RPCBPROC_GETPORT,
Christoph Hellwig7d55f7f2017-05-08 09:59:45 +02001035 .p_encode = rpcb_enc_mapping,
Christoph Hellwig605d7122017-05-08 15:00:29 +02001036 .p_decode = rpcb_dec_getport,
Chuck Leverf8b761e2009-08-09 15:09:44 -04001037 .p_arglen = RPCB_mappingargs_sz,
1038 .p_replen = RPCB_getportres_sz,
1039 .p_statidx = RPCBPROC_GETPORT,
1040 .p_timer = 0,
1041 .p_name = "GETPORT",
1042 },
Chuck Levera5090502007-03-29 16:48:04 -04001043};
1044
Christoph Hellwig499b4982017-05-12 15:36:49 +02001045static const struct rpc_procinfo rpcb_procedures3[] = {
Chuck Leverf8b761e2009-08-09 15:09:44 -04001046 [RPCBPROC_SET] = {
1047 .p_proc = RPCBPROC_SET,
Christoph Hellwig7d55f7f2017-05-08 09:59:45 +02001048 .p_encode = rpcb_enc_getaddr,
Christoph Hellwig605d7122017-05-08 15:00:29 +02001049 .p_decode = rpcb_dec_set,
Chuck Leverf8b761e2009-08-09 15:09:44 -04001050 .p_arglen = RPCB_getaddrargs_sz,
1051 .p_replen = RPCB_setres_sz,
1052 .p_statidx = RPCBPROC_SET,
1053 .p_timer = 0,
1054 .p_name = "SET",
1055 },
1056 [RPCBPROC_UNSET] = {
1057 .p_proc = RPCBPROC_UNSET,
Christoph Hellwig7d55f7f2017-05-08 09:59:45 +02001058 .p_encode = rpcb_enc_getaddr,
Christoph Hellwig605d7122017-05-08 15:00:29 +02001059 .p_decode = rpcb_dec_set,
Chuck Leverf8b761e2009-08-09 15:09:44 -04001060 .p_arglen = RPCB_getaddrargs_sz,
1061 .p_replen = RPCB_setres_sz,
1062 .p_statidx = RPCBPROC_UNSET,
1063 .p_timer = 0,
1064 .p_name = "UNSET",
1065 },
1066 [RPCBPROC_GETADDR] = {
1067 .p_proc = RPCBPROC_GETADDR,
Christoph Hellwig7d55f7f2017-05-08 09:59:45 +02001068 .p_encode = rpcb_enc_getaddr,
Christoph Hellwig605d7122017-05-08 15:00:29 +02001069 .p_decode = rpcb_dec_getaddr,
Chuck Leverf8b761e2009-08-09 15:09:44 -04001070 .p_arglen = RPCB_getaddrargs_sz,
1071 .p_replen = RPCB_getaddrres_sz,
1072 .p_statidx = RPCBPROC_GETADDR,
1073 .p_timer = 0,
1074 .p_name = "GETADDR",
1075 },
Chuck Levera5090502007-03-29 16:48:04 -04001076};
1077
Christoph Hellwig499b4982017-05-12 15:36:49 +02001078static const struct rpc_procinfo rpcb_procedures4[] = {
Chuck Leverf8b761e2009-08-09 15:09:44 -04001079 [RPCBPROC_SET] = {
1080 .p_proc = RPCBPROC_SET,
Christoph Hellwig7d55f7f2017-05-08 09:59:45 +02001081 .p_encode = rpcb_enc_getaddr,
Christoph Hellwig605d7122017-05-08 15:00:29 +02001082 .p_decode = rpcb_dec_set,
Chuck Leverf8b761e2009-08-09 15:09:44 -04001083 .p_arglen = RPCB_getaddrargs_sz,
1084 .p_replen = RPCB_setres_sz,
1085 .p_statidx = RPCBPROC_SET,
1086 .p_timer = 0,
1087 .p_name = "SET",
1088 },
1089 [RPCBPROC_UNSET] = {
1090 .p_proc = RPCBPROC_UNSET,
Christoph Hellwig7d55f7f2017-05-08 09:59:45 +02001091 .p_encode = rpcb_enc_getaddr,
Christoph Hellwig605d7122017-05-08 15:00:29 +02001092 .p_decode = rpcb_dec_set,
Chuck Leverf8b761e2009-08-09 15:09:44 -04001093 .p_arglen = RPCB_getaddrargs_sz,
1094 .p_replen = RPCB_setres_sz,
1095 .p_statidx = RPCBPROC_UNSET,
1096 .p_timer = 0,
1097 .p_name = "UNSET",
1098 },
1099 [RPCBPROC_GETADDR] = {
1100 .p_proc = RPCBPROC_GETADDR,
Christoph Hellwig7d55f7f2017-05-08 09:59:45 +02001101 .p_encode = rpcb_enc_getaddr,
Christoph Hellwig605d7122017-05-08 15:00:29 +02001102 .p_decode = rpcb_dec_getaddr,
Chuck Leverf8b761e2009-08-09 15:09:44 -04001103 .p_arglen = RPCB_getaddrargs_sz,
1104 .p_replen = RPCB_getaddrres_sz,
1105 .p_statidx = RPCBPROC_GETADDR,
1106 .p_timer = 0,
1107 .p_name = "GETADDR",
1108 },
Chuck Levera5090502007-03-29 16:48:04 -04001109};
1110
Trond Myklebusta613fa12012-01-20 13:53:56 -05001111static const struct rpcb_info rpcb_next_version[] = {
Chuck Leverfc200e72008-06-25 17:24:31 -04001112 {
1113 .rpc_vers = RPCBVERS_2,
1114 .rpc_proc = &rpcb_procedures2[RPCBPROC_GETPORT],
1115 },
1116 {
1117 .rpc_proc = NULL,
1118 },
Chuck Levera5090502007-03-29 16:48:04 -04001119};
1120
Trond Myklebusta613fa12012-01-20 13:53:56 -05001121static const struct rpcb_info rpcb_next_version6[] = {
Chuck Leverfc200e72008-06-25 17:24:31 -04001122 {
1123 .rpc_vers = RPCBVERS_4,
Chuck Lever88424132008-06-25 17:24:47 -04001124 .rpc_proc = &rpcb_procedures4[RPCBPROC_GETADDR],
Chuck Leverfc200e72008-06-25 17:24:31 -04001125 },
1126 {
1127 .rpc_vers = RPCBVERS_3,
1128 .rpc_proc = &rpcb_procedures3[RPCBPROC_GETADDR],
1129 },
Chuck Leverfc200e72008-06-25 17:24:31 -04001130 {
1131 .rpc_proc = NULL,
1132 },
Chuck Leverd5b64432007-08-06 11:57:18 -04001133};
1134
Christoph Hellwig1c5876d2017-05-08 23:27:10 +02001135static unsigned int rpcb_version2_counts[ARRAY_SIZE(rpcb_procedures2)];
Trond Myklebusta613fa12012-01-20 13:53:56 -05001136static const struct rpc_version rpcb_version2 = {
Chuck Leverfc200e72008-06-25 17:24:31 -04001137 .number = RPCBVERS_2,
Chuck Lever1ac7c232010-12-14 14:59:09 +00001138 .nrprocs = ARRAY_SIZE(rpcb_procedures2),
Christoph Hellwig1c5876d2017-05-08 23:27:10 +02001139 .procs = rpcb_procedures2,
1140 .counts = rpcb_version2_counts,
Chuck Levera5090502007-03-29 16:48:04 -04001141};
1142
Christoph Hellwig1c5876d2017-05-08 23:27:10 +02001143static unsigned int rpcb_version3_counts[ARRAY_SIZE(rpcb_procedures3)];
Trond Myklebusta613fa12012-01-20 13:53:56 -05001144static const struct rpc_version rpcb_version3 = {
Chuck Leverfc200e72008-06-25 17:24:31 -04001145 .number = RPCBVERS_3,
Chuck Lever1ac7c232010-12-14 14:59:09 +00001146 .nrprocs = ARRAY_SIZE(rpcb_procedures3),
Christoph Hellwig1c5876d2017-05-08 23:27:10 +02001147 .procs = rpcb_procedures3,
1148 .counts = rpcb_version3_counts,
Chuck Levera5090502007-03-29 16:48:04 -04001149};
1150
Christoph Hellwig1c5876d2017-05-08 23:27:10 +02001151static unsigned int rpcb_version4_counts[ARRAY_SIZE(rpcb_procedures4)];
Trond Myklebusta613fa12012-01-20 13:53:56 -05001152static const struct rpc_version rpcb_version4 = {
Chuck Leverfc200e72008-06-25 17:24:31 -04001153 .number = RPCBVERS_4,
Chuck Lever1ac7c232010-12-14 14:59:09 +00001154 .nrprocs = ARRAY_SIZE(rpcb_procedures4),
Christoph Hellwig1c5876d2017-05-08 23:27:10 +02001155 .procs = rpcb_procedures4,
1156 .counts = rpcb_version4_counts,
Chuck Levera5090502007-03-29 16:48:04 -04001157};
1158
Trond Myklebusta613fa12012-01-20 13:53:56 -05001159static const struct rpc_version *rpcb_version[] = {
Chuck Levera5090502007-03-29 16:48:04 -04001160 NULL,
1161 NULL,
1162 &rpcb_version2,
1163 &rpcb_version3,
1164 &rpcb_version4
1165};
1166
1167static struct rpc_stat rpcb_stats;
1168
Trond Myklebusta613fa12012-01-20 13:53:56 -05001169static const struct rpc_program rpcb_program = {
Chuck Levera5090502007-03-29 16:48:04 -04001170 .name = "rpcbind",
1171 .number = RPCBIND_PROGRAM,
1172 .nrvers = ARRAY_SIZE(rpcb_version),
1173 .version = rpcb_version,
1174 .stats = &rpcb_stats,
1175};