diff options
author | Chuck Lever <chuck.lever@oracle.com> | 2008-01-07 18:34:48 -0500 |
---|---|---|
committer | Trond Myklebust <Trond.Myklebust@netapp.com> | 2008-01-30 02:06:04 -0500 |
commit | b454ae906085cf7774fb4756746680c9b03b6f84 (patch) | |
tree | c5f84a9524dd7a9c7470ef0782e2d79df94d3f5e /net/sunrpc/xprtsock.c | |
parent | cab6fc1b77c3ec4471d7d54ff6db9ad2dd59c2f5 (diff) |
SUNRPC: fewer conditionals in the format_ip_address routines
Clean up: have the set up routines explicitly pass the strings to be used
for the transport name and NETID. This removes a number of conditionals
and dependencies on rpc_xprt.prot, which is overloaded.
Tighten up type checking on the address_strings array while we're at it.
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.c | 56 |
1 files changed, 22 insertions, 34 deletions
diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c index 6ba329d339a2..b9b94f49c620 100644 --- a/net/sunrpc/xprtsock.c +++ b/net/sunrpc/xprtsock.c | |||
@@ -280,7 +280,9 @@ static inline struct sockaddr_in6 *xs_addr_in6(struct rpc_xprt *xprt) | |||
280 | return (struct sockaddr_in6 *) &xprt->addr; | 280 | return (struct sockaddr_in6 *) &xprt->addr; |
281 | } | 281 | } |
282 | 282 | ||
283 | static void xs_format_ipv4_peer_addresses(struct rpc_xprt *xprt) | 283 | static void xs_format_ipv4_peer_addresses(struct rpc_xprt *xprt, |
284 | const char *protocol, | ||
285 | const char *netid) | ||
284 | { | 286 | { |
285 | struct sockaddr_in *addr = xs_addr_in(xprt); | 287 | struct sockaddr_in *addr = xs_addr_in(xprt); |
286 | char *buf; | 288 | char *buf; |
@@ -299,21 +301,14 @@ static void xs_format_ipv4_peer_addresses(struct rpc_xprt *xprt) | |||
299 | } | 301 | } |
300 | xprt->address_strings[RPC_DISPLAY_PORT] = buf; | 302 | xprt->address_strings[RPC_DISPLAY_PORT] = buf; |
301 | 303 | ||
302 | buf = kzalloc(8, GFP_KERNEL); | 304 | xprt->address_strings[RPC_DISPLAY_PROTO] = protocol; |
303 | if (buf) { | ||
304 | if (xprt->prot == IPPROTO_UDP) | ||
305 | snprintf(buf, 8, "udp"); | ||
306 | else | ||
307 | snprintf(buf, 8, "tcp"); | ||
308 | } | ||
309 | xprt->address_strings[RPC_DISPLAY_PROTO] = buf; | ||
310 | 305 | ||
311 | buf = kzalloc(48, GFP_KERNEL); | 306 | buf = kzalloc(48, GFP_KERNEL); |
312 | if (buf) { | 307 | if (buf) { |
313 | snprintf(buf, 48, "addr="NIPQUAD_FMT" port=%u proto=%s", | 308 | snprintf(buf, 48, "addr="NIPQUAD_FMT" port=%u proto=%s", |
314 | NIPQUAD(addr->sin_addr.s_addr), | 309 | NIPQUAD(addr->sin_addr.s_addr), |
315 | ntohs(addr->sin_port), | 310 | ntohs(addr->sin_port), |
316 | xprt->prot == IPPROTO_UDP ? "udp" : "tcp"); | 311 | protocol); |
317 | } | 312 | } |
318 | xprt->address_strings[RPC_DISPLAY_ALL] = buf; | 313 | xprt->address_strings[RPC_DISPLAY_ALL] = buf; |
319 | 314 | ||
@@ -340,12 +335,12 @@ static void xs_format_ipv4_peer_addresses(struct rpc_xprt *xprt) | |||
340 | } | 335 | } |
341 | xprt->address_strings[RPC_DISPLAY_UNIVERSAL_ADDR] = buf; | 336 | xprt->address_strings[RPC_DISPLAY_UNIVERSAL_ADDR] = buf; |
342 | 337 | ||
343 | xprt->address_strings[RPC_DISPLAY_NETID] = | 338 | xprt->address_strings[RPC_DISPLAY_NETID] = netid; |
344 | kstrdup(xprt->prot == IPPROTO_UDP ? | ||
345 | RPCBIND_NETID_UDP : RPCBIND_NETID_TCP, GFP_KERNEL); | ||
346 | } | 339 | } |
347 | 340 | ||
348 | static void xs_format_ipv6_peer_addresses(struct rpc_xprt *xprt) | 341 | static void xs_format_ipv6_peer_addresses(struct rpc_xprt *xprt, |
342 | const char *protocol, | ||
343 | const char *netid) | ||
349 | { | 344 | { |
350 | struct sockaddr_in6 *addr = xs_addr_in6(xprt); | 345 | struct sockaddr_in6 *addr = xs_addr_in6(xprt); |
351 | char *buf; | 346 | char *buf; |
@@ -364,21 +359,14 @@ static void xs_format_ipv6_peer_addresses(struct rpc_xprt *xprt) | |||
364 | } | 359 | } |
365 | xprt->address_strings[RPC_DISPLAY_PORT] = buf; | 360 | xprt->address_strings[RPC_DISPLAY_PORT] = buf; |
366 | 361 | ||
367 | buf = kzalloc(8, GFP_KERNEL); | 362 | xprt->address_strings[RPC_DISPLAY_PROTO] = protocol; |
368 | if (buf) { | ||
369 | if (xprt->prot == IPPROTO_UDP) | ||
370 | snprintf(buf, 8, "udp"); | ||
371 | else | ||
372 | snprintf(buf, 8, "tcp"); | ||
373 | } | ||
374 | xprt->address_strings[RPC_DISPLAY_PROTO] = buf; | ||
375 | 363 | ||
376 | buf = kzalloc(64, GFP_KERNEL); | 364 | buf = kzalloc(64, GFP_KERNEL); |
377 | if (buf) { | 365 | if (buf) { |
378 | snprintf(buf, 64, "addr="NIP6_FMT" port=%u proto=%s", | 366 | snprintf(buf, 64, "addr="NIP6_FMT" port=%u proto=%s", |
379 | NIP6(addr->sin6_addr), | 367 | NIP6(addr->sin6_addr), |
380 | ntohs(addr->sin6_port), | 368 | ntohs(addr->sin6_port), |
381 | xprt->prot == IPPROTO_UDP ? "udp" : "tcp"); | 369 | protocol); |
382 | } | 370 | } |
383 | xprt->address_strings[RPC_DISPLAY_ALL] = buf; | 371 | xprt->address_strings[RPC_DISPLAY_ALL] = buf; |
384 | 372 | ||
@@ -405,17 +393,17 @@ static void xs_format_ipv6_peer_addresses(struct rpc_xprt *xprt) | |||
405 | } | 393 | } |
406 | xprt->address_strings[RPC_DISPLAY_UNIVERSAL_ADDR] = buf; | 394 | xprt->address_strings[RPC_DISPLAY_UNIVERSAL_ADDR] = buf; |
407 | 395 | ||
408 | xprt->address_strings[RPC_DISPLAY_NETID] = | 396 | xprt->address_strings[RPC_DISPLAY_NETID] = netid; |
409 | kstrdup(xprt->prot == IPPROTO_UDP ? | ||
410 | RPCBIND_NETID_UDP6 : RPCBIND_NETID_TCP6, GFP_KERNEL); | ||
411 | } | 397 | } |
412 | 398 | ||
413 | static void xs_free_peer_addresses(struct rpc_xprt *xprt) | 399 | static void xs_free_peer_addresses(struct rpc_xprt *xprt) |
414 | { | 400 | { |
415 | int i; | 401 | kfree(xprt->address_strings[RPC_DISPLAY_ADDR]); |
416 | 402 | kfree(xprt->address_strings[RPC_DISPLAY_PORT]); | |
417 | for (i = 0; i < RPC_DISPLAY_MAX; i++) | 403 | kfree(xprt->address_strings[RPC_DISPLAY_ALL]); |
418 | kfree(xprt->address_strings[i]); | 404 | kfree(xprt->address_strings[RPC_DISPLAY_HEX_ADDR]); |
405 | kfree(xprt->address_strings[RPC_DISPLAY_HEX_PORT]); | ||
406 | kfree(xprt->address_strings[RPC_DISPLAY_UNIVERSAL_ADDR]); | ||
419 | } | 407 | } |
420 | 408 | ||
421 | #define XS_SENDMSG_FLAGS (MSG_DONTWAIT | MSG_NOSIGNAL) | 409 | #define XS_SENDMSG_FLAGS (MSG_DONTWAIT | MSG_NOSIGNAL) |
@@ -1939,7 +1927,7 @@ static struct rpc_xprt *xs_setup_udp(struct xprt_create *args) | |||
1939 | 1927 | ||
1940 | INIT_DELAYED_WORK(&transport->connect_worker, | 1928 | INIT_DELAYED_WORK(&transport->connect_worker, |
1941 | xs_udp_connect_worker4); | 1929 | xs_udp_connect_worker4); |
1942 | xs_format_ipv4_peer_addresses(xprt); | 1930 | xs_format_ipv4_peer_addresses(xprt, "udp", RPCBIND_NETID_UDP); |
1943 | break; | 1931 | break; |
1944 | case AF_INET6: | 1932 | case AF_INET6: |
1945 | if (((struct sockaddr_in6 *)addr)->sin6_port != htons(0)) | 1933 | if (((struct sockaddr_in6 *)addr)->sin6_port != htons(0)) |
@@ -1947,7 +1935,7 @@ static struct rpc_xprt *xs_setup_udp(struct xprt_create *args) | |||
1947 | 1935 | ||
1948 | INIT_DELAYED_WORK(&transport->connect_worker, | 1936 | INIT_DELAYED_WORK(&transport->connect_worker, |
1949 | xs_udp_connect_worker6); | 1937 | xs_udp_connect_worker6); |
1950 | xs_format_ipv6_peer_addresses(xprt); | 1938 | xs_format_ipv6_peer_addresses(xprt, "udp", RPCBIND_NETID_UDP6); |
1951 | break; | 1939 | break; |
1952 | default: | 1940 | default: |
1953 | kfree(xprt); | 1941 | kfree(xprt); |
@@ -2005,14 +1993,14 @@ static struct rpc_xprt *xs_setup_tcp(struct xprt_create *args) | |||
2005 | xprt_set_bound(xprt); | 1993 | xprt_set_bound(xprt); |
2006 | 1994 | ||
2007 | INIT_DELAYED_WORK(&transport->connect_worker, xs_tcp_connect_worker4); | 1995 | INIT_DELAYED_WORK(&transport->connect_worker, xs_tcp_connect_worker4); |
2008 | xs_format_ipv4_peer_addresses(xprt); | 1996 | xs_format_ipv4_peer_addresses(xprt, "tcp", RPCBIND_NETID_TCP); |
2009 | break; | 1997 | break; |
2010 | case AF_INET6: | 1998 | case AF_INET6: |
2011 | if (((struct sockaddr_in6 *)addr)->sin6_port != htons(0)) | 1999 | if (((struct sockaddr_in6 *)addr)->sin6_port != htons(0)) |
2012 | xprt_set_bound(xprt); | 2000 | xprt_set_bound(xprt); |
2013 | 2001 | ||
2014 | INIT_DELAYED_WORK(&transport->connect_worker, xs_tcp_connect_worker6); | 2002 | INIT_DELAYED_WORK(&transport->connect_worker, xs_tcp_connect_worker6); |
2015 | xs_format_ipv6_peer_addresses(xprt); | 2003 | xs_format_ipv6_peer_addresses(xprt, "tcp", RPCBIND_NETID_TCP6); |
2016 | break; | 2004 | break; |
2017 | default: | 2005 | default: |
2018 | kfree(xprt); | 2006 | kfree(xprt); |