rpcb_clnt.c 18 KB

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