rpcb_clnt.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  1. /*
  2. * In-kernel rpcbind client supporting versions 2, 3, and 4 of the rpcbind
  3. * protocol
  4. *
  5. * Based on RFC 1833: "Binding Protocols for ONC RPC Version 2" and
  6. * RFC 3530: "Network File System (NFS) version 4 Protocol"
  7. *
  8. * Original: Gilles Quillard, Bull Open Source, 2005 <gilles.quillard@bull.net>
  9. * Updated: Chuck Lever, Oracle Corporation, 2007 <chuck.lever@oracle.com>
  10. *
  11. * Descended from net/sunrpc/pmap_clnt.c,
  12. * Copyright (C) 1996, Olaf Kirch <okir@monad.swb.de>
  13. */
  14. #include <linux/module.h>
  15. #include <linux/types.h>
  16. #include <linux/socket.h>
  17. #include <linux/in.h>
  18. #include <linux/in6.h>
  19. #include <linux/kernel.h>
  20. #include <linux/errno.h>
  21. #include <linux/sunrpc/clnt.h>
  22. #include <linux/sunrpc/sched.h>
  23. #ifdef RPC_DEBUG
  24. # define RPCDBG_FACILITY RPCDBG_BIND
  25. #endif
  26. #define RPCBIND_PROGRAM (100000u)
  27. #define RPCBIND_PORT (111u)
  28. enum {
  29. RPCBPROC_NULL,
  30. RPCBPROC_SET,
  31. RPCBPROC_UNSET,
  32. RPCBPROC_GETPORT,
  33. RPCBPROC_GETADDR = 3, /* alias for GETPORT */
  34. RPCBPROC_DUMP,
  35. RPCBPROC_CALLIT,
  36. RPCBPROC_BCAST = 5, /* alias for CALLIT */
  37. RPCBPROC_GETTIME,
  38. RPCBPROC_UADDR2TADDR,
  39. RPCBPROC_TADDR2UADDR,
  40. RPCBPROC_GETVERSADDR,
  41. RPCBPROC_INDIRECT,
  42. RPCBPROC_GETADDRLIST,
  43. RPCBPROC_GETSTAT,
  44. };
  45. #define RPCB_HIGHPROC_2 RPCBPROC_CALLIT
  46. #define RPCB_HIGHPROC_3 RPCBPROC_TADDR2UADDR
  47. #define RPCB_HIGHPROC_4 RPCBPROC_GETSTAT
  48. /*
  49. * r_addr
  50. *
  51. * Quoting RFC 3530, section 2.2:
  52. *
  53. * For TCP over IPv4 and for UDP over IPv4, the format of r_addr is the
  54. * US-ASCII string:
  55. *
  56. * h1.h2.h3.h4.p1.p2
  57. *
  58. * The prefix, "h1.h2.h3.h4", is the standard textual form for
  59. * representing an IPv4 address, which is always four octets long.
  60. * Assuming big-endian ordering, h1, h2, h3, and h4, are respectively,
  61. * the first through fourth octets each converted to ASCII-decimal.
  62. * Assuming big-endian ordering, p1 and p2 are, respectively, the first
  63. * and second octets each converted to ASCII-decimal. For example, if a
  64. * host, in big-endian order, has an address of 0x0A010307 and there is
  65. * a service listening on, in big endian order, port 0x020F (decimal
  66. * 527), then the complete universal address is "10.1.3.7.2.15".
  67. *
  68. * ...
  69. *
  70. * For TCP over IPv6 and for UDP over IPv6, the format of r_addr is the
  71. * US-ASCII string:
  72. *
  73. * x1:x2:x3:x4:x5:x6:x7:x8.p1.p2
  74. *
  75. * The suffix "p1.p2" is the service port, and is computed the same way
  76. * as with universal addresses for TCP and UDP over IPv4. The prefix,
  77. * "x1:x2:x3:x4:x5:x6:x7:x8", is the standard textual form for
  78. * representing an IPv6 address as defined in Section 2.2 of [RFC2373].
  79. * Additionally, the two alternative forms specified in Section 2.2 of
  80. * [RFC2373] are also acceptable.
  81. *
  82. * XXX: Currently this implementation does not explicitly convert the
  83. * stored address to US-ASCII on non-ASCII systems.
  84. */
  85. #define RPCB_MAXADDRLEN (128u)
  86. /*
  87. * r_netid
  88. *
  89. * Quoting RFC 3530, section 2.2:
  90. *
  91. * For TCP over IPv4 the value of r_netid is the string "tcp". For UDP
  92. * over IPv4 the value of r_netid is the string "udp".
  93. *
  94. * ...
  95. *
  96. * For TCP over IPv6 the value of r_netid is the string "tcp6". For UDP
  97. * over IPv6 the value of r_netid is the string "udp6".
  98. */
  99. #define RPCB_NETID_UDP "\165\144\160" /* "udp" */
  100. #define RPCB_NETID_TCP "\164\143\160" /* "tcp" */
  101. #define RPCB_NETID_UDP6 "\165\144\160\066" /* "udp6" */
  102. #define RPCB_NETID_TCP6 "\164\143\160\066" /* "tcp6" */
  103. #define RPCB_MAXNETIDLEN (4u)
  104. /*
  105. * r_owner
  106. *
  107. * The "owner" is allowed to unset a service in the rpcbind database.
  108. * We always use the following (arbitrary) fixed string.
  109. */
  110. #define RPCB_OWNER_STRING "rpcb"
  111. #define RPCB_MAXOWNERLEN sizeof(RPCB_OWNER_STRING)
  112. static void rpcb_getport_done(struct rpc_task *, void *);
  113. extern struct rpc_program rpcb_program;
  114. struct rpcbind_args {
  115. struct rpc_xprt * r_xprt;
  116. u32 r_prog;
  117. u32 r_vers;
  118. u32 r_prot;
  119. unsigned short r_port;
  120. char * r_netid;
  121. char r_addr[RPCB_MAXADDRLEN];
  122. char * r_owner;
  123. };
  124. static struct rpc_procinfo rpcb_procedures2[];
  125. static struct rpc_procinfo rpcb_procedures3[];
  126. struct rpcb_info {
  127. int rpc_vers;
  128. struct rpc_procinfo * rpc_proc;
  129. };
  130. static struct rpcb_info rpcb_next_version[];
  131. static struct rpcb_info rpcb_next_version6[];
  132. static void rpcb_getport_prepare(struct rpc_task *task, void *calldata)
  133. {
  134. struct rpcbind_args *map = calldata;
  135. struct rpc_xprt *xprt = map->r_xprt;
  136. struct rpc_message msg = {
  137. .rpc_proc = rpcb_next_version[xprt->bind_index].rpc_proc,
  138. .rpc_argp = map,
  139. .rpc_resp = &map->r_port,
  140. };
  141. rpc_call_setup(task, &msg, 0);
  142. }
  143. static void rpcb_map_release(void *data)
  144. {
  145. struct rpcbind_args *map = data;
  146. xprt_put(map->r_xprt);
  147. kfree(map);
  148. }
  149. static const struct rpc_call_ops rpcb_getport_ops = {
  150. .rpc_call_prepare = rpcb_getport_prepare,
  151. .rpc_call_done = rpcb_getport_done,
  152. .rpc_release = rpcb_map_release,
  153. };
  154. static void rpcb_wake_rpcbind_waiters(struct rpc_xprt *xprt, int status)
  155. {
  156. xprt_clear_binding(xprt);
  157. rpc_wake_up_status(&xprt->binding, status);
  158. }
  159. static struct rpc_clnt *rpcb_create(char *hostname, struct sockaddr *srvaddr,
  160. int proto, int version, int privileged)
  161. {
  162. struct rpc_create_args args = {
  163. .protocol = proto,
  164. .address = srvaddr,
  165. .addrsize = sizeof(struct sockaddr_in),
  166. .servername = hostname,
  167. .program = &rpcb_program,
  168. .version = version,
  169. .authflavor = RPC_AUTH_UNIX,
  170. .flags = (RPC_CLNT_CREATE_NOPING |
  171. RPC_CLNT_CREATE_INTR),
  172. };
  173. switch (srvaddr->sa_family) {
  174. case AF_INET:
  175. ((struct sockaddr_in *)srvaddr)->sin_port = htons(RPCBIND_PORT);
  176. break;
  177. case AF_INET6:
  178. ((struct sockaddr_in6 *)srvaddr)->sin6_port = htons(RPCBIND_PORT);
  179. break;
  180. default:
  181. return NULL;
  182. }
  183. if (!privileged)
  184. args.flags |= RPC_CLNT_CREATE_NONPRIVPORT;
  185. return rpc_create(&args);
  186. }
  187. /**
  188. * rpcb_register - set or unset a port registration with the local rpcbind svc
  189. * @prog: RPC program number to bind
  190. * @vers: RPC version number to bind
  191. * @prot: transport protocol to use to make this request
  192. * @port: port value to register
  193. * @okay: result code
  194. *
  195. * port == 0 means unregister, port != 0 means register.
  196. *
  197. * This routine supports only rpcbind version 2.
  198. */
  199. int rpcb_register(u32 prog, u32 vers, int prot, unsigned short port, int *okay)
  200. {
  201. struct sockaddr_in sin = {
  202. .sin_family = AF_INET,
  203. .sin_addr.s_addr = htonl(INADDR_LOOPBACK),
  204. };
  205. struct rpcbind_args map = {
  206. .r_prog = prog,
  207. .r_vers = vers,
  208. .r_prot = prot,
  209. .r_port = port,
  210. };
  211. struct rpc_message msg = {
  212. .rpc_proc = &rpcb_procedures2[port ?
  213. RPCBPROC_SET : RPCBPROC_UNSET],
  214. .rpc_argp = &map,
  215. .rpc_resp = okay,
  216. };
  217. struct rpc_clnt *rpcb_clnt;
  218. int error = 0;
  219. dprintk("RPC: %sregistering (%u, %u, %d, %u) with local "
  220. "rpcbind\n", (port ? "" : "un"),
  221. prog, vers, prot, port);
  222. rpcb_clnt = rpcb_create("localhost", (struct sockaddr *) &sin,
  223. IPPROTO_UDP, 2, 1);
  224. if (IS_ERR(rpcb_clnt))
  225. return PTR_ERR(rpcb_clnt);
  226. error = rpc_call_sync(rpcb_clnt, &msg, 0);
  227. rpc_shutdown_client(rpcb_clnt);
  228. if (error < 0)
  229. printk(KERN_WARNING "RPC: failed to contact local rpcbind "
  230. "server (errno %d).\n", -error);
  231. dprintk("RPC: registration status %d/%d\n", error, *okay);
  232. return error;
  233. }
  234. /**
  235. * rpcb_getport_sync - obtain the port for an RPC service on a given host
  236. * @sin: address of remote peer
  237. * @prog: RPC program number to bind
  238. * @vers: RPC version number to bind
  239. * @prot: transport protocol to use to make this request
  240. *
  241. * Called from outside the RPC client in a synchronous task context.
  242. * Uses default timeout parameters specified by underlying transport.
  243. *
  244. * XXX: Needs to support IPv6, and rpcbind versions 3 and 4
  245. */
  246. int rpcb_getport_sync(struct sockaddr_in *sin, __u32 prog,
  247. __u32 vers, int prot)
  248. {
  249. struct rpcbind_args map = {
  250. .r_prog = prog,
  251. .r_vers = vers,
  252. .r_prot = prot,
  253. .r_port = 0,
  254. };
  255. struct rpc_message msg = {
  256. .rpc_proc = &rpcb_procedures2[RPCBPROC_GETPORT],
  257. .rpc_argp = &map,
  258. .rpc_resp = &map.r_port,
  259. };
  260. struct rpc_clnt *rpcb_clnt;
  261. char hostname[40];
  262. int status;
  263. dprintk("RPC: %s(" NIPQUAD_FMT ", %u, %u, %d)\n",
  264. __FUNCTION__, NIPQUAD(sin->sin_addr.s_addr), prog, vers, prot);
  265. sprintf(hostname, NIPQUAD_FMT, NIPQUAD(sin->sin_addr.s_addr));
  266. rpcb_clnt = rpcb_create(hostname, (struct sockaddr *)sin, prot, 2, 0);
  267. if (IS_ERR(rpcb_clnt))
  268. return PTR_ERR(rpcb_clnt);
  269. status = rpc_call_sync(rpcb_clnt, &msg, 0);
  270. rpc_shutdown_client(rpcb_clnt);
  271. if (status >= 0) {
  272. if (map.r_port != 0)
  273. return map.r_port;
  274. status = -EACCES;
  275. }
  276. return status;
  277. }
  278. EXPORT_SYMBOL_GPL(rpcb_getport_sync);
  279. /**
  280. * rpcb_getport_async - obtain the port for a given RPC service on a given host
  281. * @task: task that is waiting for portmapper request
  282. *
  283. * This one can be called for an ongoing RPC request, and can be used in
  284. * an async (rpciod) context.
  285. */
  286. void rpcb_getport_async(struct rpc_task *task)
  287. {
  288. struct rpc_clnt *clnt = task->tk_client;
  289. int bind_version;
  290. struct rpc_xprt *xprt = task->tk_xprt;
  291. struct rpc_clnt *rpcb_clnt;
  292. static struct rpcbind_args *map;
  293. struct rpc_task *child;
  294. struct sockaddr addr;
  295. int status;
  296. struct rpcb_info *info;
  297. dprintk("RPC: %5u %s(%s, %u, %u, %d)\n",
  298. task->tk_pid, __FUNCTION__,
  299. clnt->cl_server, clnt->cl_prog, clnt->cl_vers, xprt->prot);
  300. /* Autobind on cloned rpc clients is discouraged */
  301. BUG_ON(clnt->cl_parent != clnt);
  302. if (xprt_test_and_set_binding(xprt)) {
  303. status = -EACCES; /* tell caller to check again */
  304. dprintk("RPC: %5u %s: waiting for another binder\n",
  305. task->tk_pid, __FUNCTION__);
  306. goto bailout_nowake;
  307. }
  308. /* Put self on queue before sending rpcbind request, in case
  309. * rpcb_getport_done completes before we return from rpc_run_task */
  310. rpc_sleep_on(&xprt->binding, task, NULL, NULL);
  311. /* Someone else may have bound if we slept */
  312. if (xprt_bound(xprt)) {
  313. status = 0;
  314. dprintk("RPC: %5u %s: already bound\n",
  315. task->tk_pid, __FUNCTION__);
  316. goto bailout_nofree;
  317. }
  318. rpc_peeraddr(clnt, (void *)&addr, sizeof(addr));
  319. /* Don't ever use rpcbind v2 for AF_INET6 requests */
  320. switch (addr.sa_family) {
  321. case AF_INET:
  322. info = rpcb_next_version;
  323. break;
  324. case AF_INET6:
  325. info = rpcb_next_version6;
  326. break;
  327. default:
  328. status = -EAFNOSUPPORT;
  329. dprintk("RPC: %5u %s: bad address family\n",
  330. task->tk_pid, __FUNCTION__);
  331. goto bailout_nofree;
  332. }
  333. if (info[xprt->bind_index].rpc_proc == NULL) {
  334. xprt->bind_index = 0;
  335. status = -EACCES; /* tell caller to try again later */
  336. dprintk("RPC: %5u %s: no more getport versions available\n",
  337. task->tk_pid, __FUNCTION__);
  338. goto bailout_nofree;
  339. }
  340. bind_version = info[xprt->bind_index].rpc_vers;
  341. dprintk("RPC: %5u %s: trying rpcbind version %u\n",
  342. task->tk_pid, __FUNCTION__, bind_version);
  343. map = kzalloc(sizeof(struct rpcbind_args), GFP_ATOMIC);
  344. if (!map) {
  345. status = -ENOMEM;
  346. dprintk("RPC: %5u %s: no memory available\n",
  347. task->tk_pid, __FUNCTION__);
  348. goto bailout_nofree;
  349. }
  350. map->r_prog = clnt->cl_prog;
  351. map->r_vers = clnt->cl_vers;
  352. map->r_prot = xprt->prot;
  353. map->r_port = 0;
  354. map->r_xprt = xprt_get(xprt);
  355. map->r_netid = (xprt->prot == IPPROTO_TCP) ? RPCB_NETID_TCP :
  356. RPCB_NETID_UDP;
  357. memcpy(&map->r_addr, rpc_peeraddr2str(clnt, RPC_DISPLAY_ADDR),
  358. sizeof(map->r_addr));
  359. map->r_owner = RPCB_OWNER_STRING; /* ignored for GETADDR */
  360. rpcb_clnt = rpcb_create(clnt->cl_server, &addr, xprt->prot, bind_version, 0);
  361. if (IS_ERR(rpcb_clnt)) {
  362. status = PTR_ERR(rpcb_clnt);
  363. dprintk("RPC: %5u %s: rpcb_create failed, error %ld\n",
  364. task->tk_pid, __FUNCTION__, PTR_ERR(rpcb_clnt));
  365. goto bailout;
  366. }
  367. child = rpc_run_task(rpcb_clnt, RPC_TASK_ASYNC, &rpcb_getport_ops, map);
  368. rpc_release_client(rpcb_clnt);
  369. if (IS_ERR(child)) {
  370. status = -EIO;
  371. dprintk("RPC: %5u %s: rpc_run_task failed\n",
  372. task->tk_pid, __FUNCTION__);
  373. goto bailout_nofree;
  374. }
  375. rpc_put_task(child);
  376. task->tk_xprt->stat.bind_count++;
  377. return;
  378. bailout:
  379. kfree(map);
  380. xprt_put(xprt);
  381. bailout_nofree:
  382. rpcb_wake_rpcbind_waiters(xprt, status);
  383. bailout_nowake:
  384. task->tk_status = status;
  385. }
  386. /*
  387. * Rpcbind child task calls this callback via tk_exit.
  388. */
  389. static void rpcb_getport_done(struct rpc_task *child, void *data)
  390. {
  391. struct rpcbind_args *map = data;
  392. struct rpc_xprt *xprt = map->r_xprt;
  393. int status = child->tk_status;
  394. /* rpcbind server doesn't support this rpcbind protocol version */
  395. if (status == -EPROTONOSUPPORT)
  396. xprt->bind_index++;
  397. if (status < 0) {
  398. /* rpcbind server not available on remote host? */
  399. xprt->ops->set_port(xprt, 0);
  400. } else if (map->r_port == 0) {
  401. /* Requested RPC service wasn't registered on remote host */
  402. xprt->ops->set_port(xprt, 0);
  403. status = -EACCES;
  404. } else {
  405. /* Succeeded */
  406. xprt->ops->set_port(xprt, map->r_port);
  407. xprt_set_bound(xprt);
  408. status = 0;
  409. }
  410. dprintk("RPC: %5u rpcb_getport_done(status %d, port %u)\n",
  411. child->tk_pid, status, map->r_port);
  412. rpcb_wake_rpcbind_waiters(xprt, status);
  413. }
  414. static int rpcb_encode_mapping(struct rpc_rqst *req, __be32 *p,
  415. struct rpcbind_args *rpcb)
  416. {
  417. dprintk("RPC: rpcb_encode_mapping(%u, %u, %d, %u)\n",
  418. rpcb->r_prog, rpcb->r_vers, rpcb->r_prot, rpcb->r_port);
  419. *p++ = htonl(rpcb->r_prog);
  420. *p++ = htonl(rpcb->r_vers);
  421. *p++ = htonl(rpcb->r_prot);
  422. *p++ = htonl(rpcb->r_port);
  423. req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
  424. return 0;
  425. }
  426. static int rpcb_decode_getport(struct rpc_rqst *req, __be32 *p,
  427. unsigned short *portp)
  428. {
  429. *portp = (unsigned short) ntohl(*p++);
  430. dprintk("RPC: rpcb_decode_getport result %u\n",
  431. *portp);
  432. return 0;
  433. }
  434. static int rpcb_decode_set(struct rpc_rqst *req, __be32 *p,
  435. unsigned int *boolp)
  436. {
  437. *boolp = (unsigned int) ntohl(*p++);
  438. dprintk("RPC: rpcb_decode_set result %u\n",
  439. *boolp);
  440. return 0;
  441. }
  442. static int rpcb_encode_getaddr(struct rpc_rqst *req, __be32 *p,
  443. struct rpcbind_args *rpcb)
  444. {
  445. dprintk("RPC: rpcb_encode_getaddr(%u, %u, %s)\n",
  446. rpcb->r_prog, rpcb->r_vers, rpcb->r_addr);
  447. *p++ = htonl(rpcb->r_prog);
  448. *p++ = htonl(rpcb->r_vers);
  449. p = xdr_encode_string(p, rpcb->r_netid);
  450. p = xdr_encode_string(p, rpcb->r_addr);
  451. p = xdr_encode_string(p, rpcb->r_owner);
  452. req->rq_slen = xdr_adjust_iovec(req->rq_svec, p);
  453. return 0;
  454. }
  455. static int rpcb_decode_getaddr(struct rpc_rqst *req, __be32 *p,
  456. unsigned short *portp)
  457. {
  458. char *addr;
  459. u32 addr_len;
  460. int c, i, f, first, val;
  461. *portp = 0;
  462. addr_len = ntohl(*p++);
  463. if (addr_len > RPCB_MAXADDRLEN) /* sanity */
  464. return -EINVAL;
  465. dprintk("RPC: rpcb_decode_getaddr returned string: '%s'\n",
  466. (char *) p);
  467. addr = (char *)p;
  468. val = 0;
  469. first = 1;
  470. f = 1;
  471. for (i = addr_len - 1; i > 0; i--) {
  472. c = addr[i];
  473. if (c >= '0' && c <= '9') {
  474. val += (c - '0') * f;
  475. f *= 10;
  476. } else if (c == '.') {
  477. if (first) {
  478. *portp = val;
  479. val = first = 0;
  480. f = 1;
  481. } else {
  482. *portp |= (val << 8);
  483. break;
  484. }
  485. }
  486. }
  487. dprintk("RPC: rpcb_decode_getaddr port=%u\n", *portp);
  488. return 0;
  489. }
  490. #define RPCB_program_sz (1u)
  491. #define RPCB_version_sz (1u)
  492. #define RPCB_protocol_sz (1u)
  493. #define RPCB_port_sz (1u)
  494. #define RPCB_boolean_sz (1u)
  495. #define RPCB_netid_sz (1+XDR_QUADLEN(RPCB_MAXNETIDLEN))
  496. #define RPCB_addr_sz (1+XDR_QUADLEN(RPCB_MAXADDRLEN))
  497. #define RPCB_ownerstring_sz (1+XDR_QUADLEN(RPCB_MAXOWNERLEN))
  498. #define RPCB_mappingargs_sz RPCB_program_sz+RPCB_version_sz+ \
  499. RPCB_protocol_sz+RPCB_port_sz
  500. #define RPCB_getaddrargs_sz RPCB_program_sz+RPCB_version_sz+ \
  501. RPCB_netid_sz+RPCB_addr_sz+ \
  502. RPCB_ownerstring_sz
  503. #define RPCB_setres_sz RPCB_boolean_sz
  504. #define RPCB_getportres_sz RPCB_port_sz
  505. /*
  506. * Note that RFC 1833 does not put any size restrictions on the
  507. * address string returned by the remote rpcbind database.
  508. */
  509. #define RPCB_getaddrres_sz RPCB_addr_sz
  510. #define PROC(proc, argtype, restype) \
  511. [RPCBPROC_##proc] = { \
  512. .p_proc = RPCBPROC_##proc, \
  513. .p_encode = (kxdrproc_t) rpcb_encode_##argtype, \
  514. .p_decode = (kxdrproc_t) rpcb_decode_##restype, \
  515. .p_arglen = RPCB_##argtype##args_sz, \
  516. .p_replen = RPCB_##restype##res_sz, \
  517. .p_statidx = RPCBPROC_##proc, \
  518. .p_timer = 0, \
  519. .p_name = #proc, \
  520. }
  521. /*
  522. * Not all rpcbind procedures described in RFC 1833 are implemented
  523. * since the Linux kernel RPC code requires only these.
  524. */
  525. static struct rpc_procinfo rpcb_procedures2[] = {
  526. PROC(SET, mapping, set),
  527. PROC(UNSET, mapping, set),
  528. PROC(GETADDR, mapping, getport),
  529. };
  530. static struct rpc_procinfo rpcb_procedures3[] = {
  531. PROC(SET, mapping, set),
  532. PROC(UNSET, mapping, set),
  533. PROC(GETADDR, getaddr, getaddr),
  534. };
  535. static struct rpc_procinfo rpcb_procedures4[] = {
  536. PROC(SET, mapping, set),
  537. PROC(UNSET, mapping, set),
  538. PROC(GETVERSADDR, getaddr, getaddr),
  539. };
  540. static struct rpcb_info rpcb_next_version[] = {
  541. #ifdef CONFIG_SUNRPC_BIND34
  542. { 4, &rpcb_procedures4[RPCBPROC_GETVERSADDR] },
  543. { 3, &rpcb_procedures3[RPCBPROC_GETADDR] },
  544. #endif
  545. { 2, &rpcb_procedures2[RPCBPROC_GETPORT] },
  546. { 0, NULL },
  547. };
  548. static struct rpcb_info rpcb_next_version6[] = {
  549. #ifdef CONFIG_SUNRPC_BIND34
  550. { 4, &rpcb_procedures4[RPCBPROC_GETVERSADDR] },
  551. { 3, &rpcb_procedures3[RPCBPROC_GETADDR] },
  552. #endif
  553. { 0, NULL },
  554. };
  555. static struct rpc_version rpcb_version2 = {
  556. .number = 2,
  557. .nrprocs = RPCB_HIGHPROC_2,
  558. .procs = rpcb_procedures2
  559. };
  560. static struct rpc_version rpcb_version3 = {
  561. .number = 3,
  562. .nrprocs = RPCB_HIGHPROC_3,
  563. .procs = rpcb_procedures3
  564. };
  565. static struct rpc_version rpcb_version4 = {
  566. .number = 4,
  567. .nrprocs = RPCB_HIGHPROC_4,
  568. .procs = rpcb_procedures4
  569. };
  570. static struct rpc_version *rpcb_version[] = {
  571. NULL,
  572. NULL,
  573. &rpcb_version2,
  574. &rpcb_version3,
  575. &rpcb_version4
  576. };
  577. static struct rpc_stat rpcb_stats;
  578. struct rpc_program rpcb_program = {
  579. .name = "rpcbind",
  580. .number = RPCBIND_PROGRAM,
  581. .nrvers = ARRAY_SIZE(rpcb_version),
  582. .version = rpcb_version,
  583. .stats = &rpcb_stats,
  584. };