rpcb_clnt.c 17 KB

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