aboutsummaryrefslogtreecommitdiffstats
path: root/net/sunrpc/xprtsock.c
diff options
context:
space:
mode:
authorChuck Lever <chuck.lever@oracle.com>2009-08-09 15:09:46 -0400
committerTrond Myklebust <Trond.Myklebust@netapp.com>2009-08-09 15:09:46 -0400
commit9dc3b095b78347bfb02c324b5ee2e558f7267396 (patch)
tree8c9d43d43db5a130506d31293858cb65e73643d1 /net/sunrpc/xprtsock.c
parentc740eff84bcfd63c0497ef880e80171931cb8222 (diff)
SUNRPC: Update xprt address strings after an rpcbind completes
After a bind completes, update the transport instance's address strings so debugging messages display the current port the transport is connected to. Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Diffstat (limited to 'net/sunrpc/xprtsock.c')
-rw-r--r--net/sunrpc/xprtsock.c82
1 files changed, 41 insertions, 41 deletions
diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c
index eee5ac96e177..8aaf9003fe6e 100644
--- a/net/sunrpc/xprtsock.c
+++ b/net/sunrpc/xprtsock.c
@@ -299,11 +299,34 @@ static inline struct sockaddr_in6 *xs_addr_in6(struct rpc_xprt *xprt)
299static void xs_format_common_peer_addresses(struct rpc_xprt *xprt) 299static void xs_format_common_peer_addresses(struct rpc_xprt *xprt)
300{ 300{
301 struct sockaddr *sap = xs_addr(xprt); 301 struct sockaddr *sap = xs_addr(xprt);
302 struct sockaddr_in6 *sin6;
303 struct sockaddr_in *sin;
302 char buf[128]; 304 char buf[128];
303 305
304 (void)rpc_ntop(sap, buf, sizeof(buf)); 306 (void)rpc_ntop(sap, buf, sizeof(buf));
305 xprt->address_strings[RPC_DISPLAY_ADDR] = kstrdup(buf, GFP_KERNEL); 307 xprt->address_strings[RPC_DISPLAY_ADDR] = kstrdup(buf, GFP_KERNEL);
306 308
309 switch (sap->sa_family) {
310 case AF_INET:
311 sin = xs_addr_in(xprt);
312 (void)snprintf(buf, sizeof(buf), "%02x%02x%02x%02x",
313 NIPQUAD(sin->sin_addr.s_addr));
314 break;
315 case AF_INET6:
316 sin6 = xs_addr_in6(xprt);
317 (void)snprintf(buf, sizeof(buf), "%pi6", &sin6->sin6_addr);
318 break;
319 default:
320 BUG();
321 }
322 xprt->address_strings[RPC_DISPLAY_HEX_ADDR] = kstrdup(buf, GFP_KERNEL);
323}
324
325static void xs_format_common_peer_ports(struct rpc_xprt *xprt)
326{
327 struct sockaddr *sap = xs_addr(xprt);
328 char buf[128];
329
307 (void)snprintf(buf, sizeof(buf), "%u", rpc_get_port(sap)); 330 (void)snprintf(buf, sizeof(buf), "%u", rpc_get_port(sap));
308 xprt->address_strings[RPC_DISPLAY_PORT] = kstrdup(buf, GFP_KERNEL); 331 xprt->address_strings[RPC_DISPLAY_PORT] = kstrdup(buf, GFP_KERNEL);
309 332
@@ -311,37 +334,22 @@ static void xs_format_common_peer_addresses(struct rpc_xprt *xprt)
311 xprt->address_strings[RPC_DISPLAY_HEX_PORT] = kstrdup(buf, GFP_KERNEL); 334 xprt->address_strings[RPC_DISPLAY_HEX_PORT] = kstrdup(buf, GFP_KERNEL);
312} 335}
313 336
314static void xs_format_ipv4_peer_addresses(struct rpc_xprt *xprt, 337static void xs_format_peer_addresses(struct rpc_xprt *xprt,
315 const char *protocol, 338 const char *protocol,
316 const char *netid) 339 const char *netid)
317{ 340{
318 struct sockaddr_in *sin = xs_addr_in(xprt);
319 char buf[16];
320
321 xprt->address_strings[RPC_DISPLAY_PROTO] = protocol; 341 xprt->address_strings[RPC_DISPLAY_PROTO] = protocol;
322 xprt->address_strings[RPC_DISPLAY_NETID] = netid; 342 xprt->address_strings[RPC_DISPLAY_NETID] = netid;
323
324 (void)snprintf(buf, sizeof(buf), "%02x%02x%02x%02x",
325 NIPQUAD(sin->sin_addr.s_addr));
326 xprt->address_strings[RPC_DISPLAY_HEX_ADDR] = kstrdup(buf, GFP_KERNEL);
327
328 xs_format_common_peer_addresses(xprt); 343 xs_format_common_peer_addresses(xprt);
344 xs_format_common_peer_ports(xprt);
329} 345}
330 346
331static void xs_format_ipv6_peer_addresses(struct rpc_xprt *xprt, 347static void xs_update_peer_port(struct rpc_xprt *xprt)
332 const char *protocol,
333 const char *netid)
334{ 348{
335 struct sockaddr_in6 *sin6 = xs_addr_in6(xprt); 349 kfree(xprt->address_strings[RPC_DISPLAY_HEX_PORT]);
336 char buf[48]; 350 kfree(xprt->address_strings[RPC_DISPLAY_PORT]);
337 351
338 xprt->address_strings[RPC_DISPLAY_PROTO] = protocol; 352 xs_format_common_peer_ports(xprt);
339 xprt->address_strings[RPC_DISPLAY_NETID] = netid;
340
341 (void)snprintf(buf, sizeof(buf), "%pi6", &sin6->sin6_addr);
342 xprt->address_strings[RPC_DISPLAY_HEX_ADDR] = kstrdup(buf, GFP_KERNEL);
343
344 xs_format_common_peer_addresses(xprt);
345} 353}
346 354
347static void xs_free_peer_addresses(struct rpc_xprt *xprt) 355static void xs_free_peer_addresses(struct rpc_xprt *xprt)
@@ -1522,20 +1530,10 @@ static unsigned short xs_get_random_port(void)
1522 */ 1530 */
1523static void xs_set_port(struct rpc_xprt *xprt, unsigned short port) 1531static void xs_set_port(struct rpc_xprt *xprt, unsigned short port)
1524{ 1532{
1525 struct sockaddr *addr = xs_addr(xprt);
1526
1527 dprintk("RPC: setting port for xprt %p to %u\n", xprt, port); 1533 dprintk("RPC: setting port for xprt %p to %u\n", xprt, port);
1528 1534
1529 switch (addr->sa_family) { 1535 rpc_set_port(xs_addr(xprt), port);
1530 case AF_INET: 1536 xs_update_peer_port(xprt);
1531 ((struct sockaddr_in *)addr)->sin_port = htons(port);
1532 break;
1533 case AF_INET6:
1534 ((struct sockaddr_in6 *)addr)->sin6_port = htons(port);
1535 break;
1536 default:
1537 BUG();
1538 }
1539} 1537}
1540 1538
1541static unsigned short xs_get_srcport(struct sock_xprt *transport, struct socket *sock) 1539static unsigned short xs_get_srcport(struct sock_xprt *transport, struct socket *sock)
@@ -2216,7 +2214,7 @@ static struct rpc_xprt *xs_setup_udp(struct xprt_create *args)
2216 2214
2217 INIT_DELAYED_WORK(&transport->connect_worker, 2215 INIT_DELAYED_WORK(&transport->connect_worker,
2218 xs_udp_connect_worker4); 2216 xs_udp_connect_worker4);
2219 xs_format_ipv4_peer_addresses(xprt, "udp", RPCBIND_NETID_UDP); 2217 xs_format_peer_addresses(xprt, "udp", RPCBIND_NETID_UDP);
2220 break; 2218 break;
2221 case AF_INET6: 2219 case AF_INET6:
2222 if (((struct sockaddr_in6 *)addr)->sin6_port != htons(0)) 2220 if (((struct sockaddr_in6 *)addr)->sin6_port != htons(0))
@@ -2224,7 +2222,7 @@ static struct rpc_xprt *xs_setup_udp(struct xprt_create *args)
2224 2222
2225 INIT_DELAYED_WORK(&transport->connect_worker, 2223 INIT_DELAYED_WORK(&transport->connect_worker,
2226 xs_udp_connect_worker6); 2224 xs_udp_connect_worker6);
2227 xs_format_ipv6_peer_addresses(xprt, "udp", RPCBIND_NETID_UDP6); 2225 xs_format_peer_addresses(xprt, "udp", RPCBIND_NETID_UDP6);
2228 break; 2226 break;
2229 default: 2227 default:
2230 kfree(xprt); 2228 kfree(xprt);
@@ -2288,15 +2286,17 @@ static struct rpc_xprt *xs_setup_tcp(struct xprt_create *args)
2288 if (((struct sockaddr_in *)addr)->sin_port != htons(0)) 2286 if (((struct sockaddr_in *)addr)->sin_port != htons(0))
2289 xprt_set_bound(xprt); 2287 xprt_set_bound(xprt);
2290 2288
2291 INIT_DELAYED_WORK(&transport->connect_worker, xs_tcp_connect_worker4); 2289 INIT_DELAYED_WORK(&transport->connect_worker,
2292 xs_format_ipv4_peer_addresses(xprt, "tcp", RPCBIND_NETID_TCP); 2290 xs_tcp_connect_worker4);
2291 xs_format_peer_addresses(xprt, "tcp", RPCBIND_NETID_TCP);
2293 break; 2292 break;
2294 case AF_INET6: 2293 case AF_INET6:
2295 if (((struct sockaddr_in6 *)addr)->sin6_port != htons(0)) 2294 if (((struct sockaddr_in6 *)addr)->sin6_port != htons(0))
2296 xprt_set_bound(xprt); 2295 xprt_set_bound(xprt);
2297 2296
2298 INIT_DELAYED_WORK(&transport->connect_worker, xs_tcp_connect_worker6); 2297 INIT_DELAYED_WORK(&transport->connect_worker,
2299 xs_format_ipv6_peer_addresses(xprt, "tcp", RPCBIND_NETID_TCP6); 2298 xs_tcp_connect_worker6);
2299 xs_format_peer_addresses(xprt, "tcp", RPCBIND_NETID_TCP6);
2300 break; 2300 break;
2301 default: 2301 default:
2302 kfree(xprt); 2302 kfree(xprt);