aboutsummaryrefslogtreecommitdiffstats
path: root/net/sunrpc/rpcb_clnt.c
diff options
context:
space:
mode:
authorChuck Lever <chuck.lever@oracle.com>2009-08-09 15:09:35 -0400
committerTrond Myklebust <Trond.Myklebust@netapp.com>2009-08-09 15:09:35 -0400
commitba809130bc260fce04141aca01ef9e068d32af2a (patch)
tree8aa5fe3f46c679346120f2c28848bf4446133a4c /net/sunrpc/rpcb_clnt.c
parenta02d692611348f11ee1bc37431a883c3ff2de23e (diff)
SUNRPC: Remove duplicate universal address generation
RPC universal address generation is currently done in several places: rpcb_clnt.c, nfs4proc.c xprtsock.c, and xprtrdma.c. Remove the redundant cases that convert a socket address to a universal address. The nfs4proc.c case takes a pre-formatted presentation address string, not a socket address, so we'll leave that one. Because the new uaddr constructor uses the recently introduced rpc_ntop(), it now supports proper "::" shorthanding for IPv6 addresses. This allows the kernel to register properly formed universal addresses with the local rpcbind service, in _all_ cases. The kernel can now also send properly formed universal addresses in RPCB_GETADDR requests, and support link-local properly when encoding and decoding IPv6 addresses. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Diffstat (limited to 'net/sunrpc/rpcb_clnt.c')
-rw-r--r--net/sunrpc/rpcb_clnt.c48
1 files changed, 29 insertions, 19 deletions
diff --git a/net/sunrpc/rpcb_clnt.c b/net/sunrpc/rpcb_clnt.c
index ad1d7315c498..1fb1c070c19d 100644
--- a/net/sunrpc/rpcb_clnt.c
+++ b/net/sunrpc/rpcb_clnt.c
@@ -153,6 +153,7 @@ static void rpcb_map_release(void *data)
153 153
154 rpcb_wake_rpcbind_waiters(map->r_xprt, map->r_status); 154 rpcb_wake_rpcbind_waiters(map->r_xprt, map->r_status);
155 xprt_put(map->r_xprt); 155 xprt_put(map->r_xprt);
156 kfree(map->r_addr);
156 kfree(map); 157 kfree(map);
157} 158}
158 159
@@ -299,12 +300,9 @@ static int rpcb_register_inet4(const struct sockaddr *sap,
299 const struct sockaddr_in *sin = (const struct sockaddr_in *)sap; 300 const struct sockaddr_in *sin = (const struct sockaddr_in *)sap;
300 struct rpcbind_args *map = msg->rpc_argp; 301 struct rpcbind_args *map = msg->rpc_argp;
301 unsigned short port = ntohs(sin->sin_port); 302 unsigned short port = ntohs(sin->sin_port);
302 char buf[32]; 303 int result;
303 304
304 /* Construct AF_INET universal address */ 305 map->r_addr = rpc_sockaddr2uaddr(sap);
305 snprintf(buf, sizeof(buf), "%pI4.%u.%u",
306 &sin->sin_addr.s_addr, port >> 8, port & 0xff);
307 map->r_addr = buf;
308 306
309 dprintk("RPC: %sregistering [%u, %u, %s, '%s'] with " 307 dprintk("RPC: %sregistering [%u, %u, %s, '%s'] with "
310 "local rpcbind\n", (port ? "" : "un"), 308 "local rpcbind\n", (port ? "" : "un"),
@@ -315,7 +313,9 @@ static int rpcb_register_inet4(const struct sockaddr *sap,
315 if (port) 313 if (port)
316 msg->rpc_proc = &rpcb_procedures4[RPCBPROC_SET]; 314 msg->rpc_proc = &rpcb_procedures4[RPCBPROC_SET];
317 315
318 return rpcb_register_call(RPCBVERS_4, msg); 316 result = rpcb_register_call(RPCBVERS_4, msg);
317 kfree(map->r_addr);
318 return result;
319} 319}
320 320
321/* 321/*
@@ -327,16 +327,9 @@ static int rpcb_register_inet6(const struct sockaddr *sap,
327 const struct sockaddr_in6 *sin6 = (const struct sockaddr_in6 *)sap; 327 const struct sockaddr_in6 *sin6 = (const struct sockaddr_in6 *)sap;
328 struct rpcbind_args *map = msg->rpc_argp; 328 struct rpcbind_args *map = msg->rpc_argp;
329 unsigned short port = ntohs(sin6->sin6_port); 329 unsigned short port = ntohs(sin6->sin6_port);
330 char buf[64]; 330 int result;
331 331
332 /* Construct AF_INET6 universal address */ 332 map->r_addr = rpc_sockaddr2uaddr(sap);
333 if (ipv6_addr_any(&sin6->sin6_addr))
334 snprintf(buf, sizeof(buf), "::.%u.%u",
335 port >> 8, port & 0xff);
336 else
337 snprintf(buf, sizeof(buf), "%pI6.%u.%u",
338 &sin6->sin6_addr, port >> 8, port & 0xff);
339 map->r_addr = buf;
340 333
341 dprintk("RPC: %sregistering [%u, %u, %s, '%s'] with " 334 dprintk("RPC: %sregistering [%u, %u, %s, '%s'] with "
342 "local rpcbind\n", (port ? "" : "un"), 335 "local rpcbind\n", (port ? "" : "un"),
@@ -347,7 +340,9 @@ static int rpcb_register_inet6(const struct sockaddr *sap,
347 if (port) 340 if (port)
348 msg->rpc_proc = &rpcb_procedures4[RPCBPROC_SET]; 341 msg->rpc_proc = &rpcb_procedures4[RPCBPROC_SET];
349 342
350 return rpcb_register_call(RPCBVERS_4, msg); 343 result = rpcb_register_call(RPCBVERS_4, msg);
344 kfree(map->r_addr);
345 return result;
351} 346}
352 347
353static int rpcb_unregister_all_protofamilies(struct rpc_message *msg) 348static int rpcb_unregister_all_protofamilies(struct rpc_message *msg)
@@ -570,6 +565,7 @@ void rpcb_getport_async(struct rpc_task *task)
570 goto bailout_nofree; 565 goto bailout_nofree;
571 } 566 }
572 567
568 /* Parent transport's destination address */
573 salen = rpc_peeraddr(clnt, sap, sizeof(addr)); 569 salen = rpc_peeraddr(clnt, sap, sizeof(addr));
574 570
575 /* Don't ever use rpcbind v2 for AF_INET6 requests */ 571 /* Don't ever use rpcbind v2 for AF_INET6 requests */
@@ -620,11 +616,22 @@ void rpcb_getport_async(struct rpc_task *task)
620 map->r_prot = xprt->prot; 616 map->r_prot = xprt->prot;
621 map->r_port = 0; 617 map->r_port = 0;
622 map->r_xprt = xprt_get(xprt); 618 map->r_xprt = xprt_get(xprt);
623 map->r_netid = rpc_peeraddr2str(clnt, RPC_DISPLAY_NETID);
624 map->r_addr = rpc_peeraddr2str(rpcb_clnt, RPC_DISPLAY_UNIVERSAL_ADDR);
625 map->r_owner = "";
626 map->r_status = -EIO; 619 map->r_status = -EIO;
627 620
621 switch (bind_version) {
622 case RPCBVERS_4:
623 case RPCBVERS_3:
624 map->r_netid = rpc_peeraddr2str(clnt, RPC_DISPLAY_NETID);
625 map->r_addr = rpc_sockaddr2uaddr(sap);
626 map->r_owner = "";
627 break;
628 case RPCBVERS_2:
629 map->r_addr = NULL;
630 break;
631 default:
632 BUG();
633 }
634
628 child = rpcb_call_async(rpcb_clnt, map, proc); 635 child = rpcb_call_async(rpcb_clnt, map, proc);
629 rpc_release_client(rpcb_clnt); 636 rpc_release_client(rpcb_clnt);
630 if (IS_ERR(child)) { 637 if (IS_ERR(child)) {
@@ -722,6 +729,9 @@ static int rpcb_decode_set(struct rpc_rqst *req, __be32 *p,
722static int rpcb_encode_getaddr(struct rpc_rqst *req, __be32 *p, 729static int rpcb_encode_getaddr(struct rpc_rqst *req, __be32 *p,
723 struct rpcbind_args *rpcb) 730 struct rpcbind_args *rpcb)
724{ 731{
732 if (rpcb->r_addr == NULL)
733 return -EIO;
734
725 dprintk("RPC: encoding rpcb request (%u, %u, %s)\n", 735 dprintk("RPC: encoding rpcb request (%u, %u, %s)\n",
726 rpcb->r_prog, rpcb->r_vers, rpcb->r_addr); 736 rpcb->r_prog, rpcb->r_vers, rpcb->r_addr);
727 *p++ = htonl(rpcb->r_prog); 737 *p++ = htonl(rpcb->r_prog);