diff options
author | Chuck Lever <chuck.lever@oracle.com> | 2009-08-09 15:09:36 -0400 |
---|---|---|
committer | Trond Myklebust <Trond.Myklebust@netapp.com> | 2009-08-09 15:09:36 -0400 |
commit | c877b849d302d1275452af80b7221a2555dc02e1 (patch) | |
tree | 7baf4099cbb235e9ee4d420f61208d10ecdc8c4d /net/sunrpc/xprtsock.c | |
parent | ba809130bc260fce04141aca01ef9e068d32af2a (diff) |
SUNRPC: Use rpc_ntop() for constructing transport address strings
Clean up: In addition to using the new generic rpc_ntop() and
rpc_get_port() functions, have the RPC client compute the presentation
address buffer sizes dynamically using kstrdup().
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 | 109 |
1 files changed, 34 insertions, 75 deletions
diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c index a42c2adda59f..302a40904923 100644 --- a/net/sunrpc/xprtsock.c +++ b/net/sunrpc/xprtsock.c | |||
@@ -296,99 +296,58 @@ static inline struct sockaddr_in6 *xs_addr_in6(struct rpc_xprt *xprt) | |||
296 | return (struct sockaddr_in6 *) &xprt->addr; | 296 | return (struct sockaddr_in6 *) &xprt->addr; |
297 | } | 297 | } |
298 | 298 | ||
299 | static void xs_format_ipv4_peer_addresses(struct rpc_xprt *xprt, | 299 | static void xs_format_common_peer_addresses(struct rpc_xprt *xprt) |
300 | const char *protocol, | ||
301 | const char *netid) | ||
302 | { | 300 | { |
303 | struct sockaddr_in *addr = xs_addr_in(xprt); | 301 | struct sockaddr *sap = xs_addr(xprt); |
304 | char *buf; | 302 | char buf[128]; |
305 | |||
306 | buf = kzalloc(20, GFP_KERNEL); | ||
307 | if (buf) { | ||
308 | snprintf(buf, 20, "%pI4", &addr->sin_addr.s_addr); | ||
309 | } | ||
310 | xprt->address_strings[RPC_DISPLAY_ADDR] = buf; | ||
311 | 303 | ||
312 | buf = kzalloc(8, GFP_KERNEL); | 304 | (void)rpc_ntop(sap, buf, sizeof(buf)); |
313 | if (buf) { | 305 | xprt->address_strings[RPC_DISPLAY_ADDR] = kstrdup(buf, GFP_KERNEL); |
314 | snprintf(buf, 8, "%u", | ||
315 | ntohs(addr->sin_port)); | ||
316 | } | ||
317 | xprt->address_strings[RPC_DISPLAY_PORT] = buf; | ||
318 | 306 | ||
319 | xprt->address_strings[RPC_DISPLAY_PROTO] = protocol; | 307 | (void)snprintf(buf, sizeof(buf), "%u", rpc_get_port(sap)); |
308 | xprt->address_strings[RPC_DISPLAY_PORT] = kstrdup(buf, GFP_KERNEL); | ||
320 | 309 | ||
321 | buf = kzalloc(48, GFP_KERNEL); | 310 | (void)snprintf(buf, sizeof(buf), "addr=%s port=%s proto=%s", |
322 | if (buf) { | 311 | xprt->address_strings[RPC_DISPLAY_ADDR], |
323 | snprintf(buf, 48, "addr=%pI4 port=%u proto=%s", | 312 | xprt->address_strings[RPC_DISPLAY_PORT], |
324 | &addr->sin_addr.s_addr, | 313 | xprt->address_strings[RPC_DISPLAY_PROTO]); |
325 | ntohs(addr->sin_port), | 314 | xprt->address_strings[RPC_DISPLAY_ALL] = kstrdup(buf, GFP_KERNEL); |
326 | protocol); | ||
327 | } | ||
328 | xprt->address_strings[RPC_DISPLAY_ALL] = buf; | ||
329 | 315 | ||
330 | buf = kzalloc(10, GFP_KERNEL); | 316 | (void)snprintf(buf, sizeof(buf), "%4hx", rpc_get_port(sap)); |
331 | if (buf) { | 317 | xprt->address_strings[RPC_DISPLAY_HEX_PORT] = kstrdup(buf, GFP_KERNEL); |
332 | snprintf(buf, 10, "%02x%02x%02x%02x", | 318 | } |
333 | NIPQUAD(addr->sin_addr.s_addr)); | ||
334 | } | ||
335 | xprt->address_strings[RPC_DISPLAY_HEX_ADDR] = buf; | ||
336 | 319 | ||
337 | buf = kzalloc(8, GFP_KERNEL); | 320 | static void xs_format_ipv4_peer_addresses(struct rpc_xprt *xprt, |
338 | if (buf) { | 321 | const char *protocol, |
339 | snprintf(buf, 8, "%4hx", | 322 | const char *netid) |
340 | ntohs(addr->sin_port)); | 323 | { |
341 | } | 324 | struct sockaddr_in *sin = xs_addr_in(xprt); |
342 | xprt->address_strings[RPC_DISPLAY_HEX_PORT] = buf; | 325 | char buf[16]; |
343 | 326 | ||
327 | xprt->address_strings[RPC_DISPLAY_PROTO] = protocol; | ||
344 | xprt->address_strings[RPC_DISPLAY_NETID] = netid; | 328 | xprt->address_strings[RPC_DISPLAY_NETID] = netid; |
329 | |||
330 | (void)snprintf(buf, sizeof(buf), "%02x%02x%02x%02x", | ||
331 | NIPQUAD(sin->sin_addr.s_addr)); | ||
332 | xprt->address_strings[RPC_DISPLAY_HEX_ADDR] = kstrdup(buf, GFP_KERNEL); | ||
333 | |||
334 | xs_format_common_peer_addresses(xprt); | ||
345 | } | 335 | } |
346 | 336 | ||
347 | static void xs_format_ipv6_peer_addresses(struct rpc_xprt *xprt, | 337 | static void xs_format_ipv6_peer_addresses(struct rpc_xprt *xprt, |
348 | const char *protocol, | 338 | const char *protocol, |
349 | const char *netid) | 339 | const char *netid) |
350 | { | 340 | { |
351 | struct sockaddr_in6 *addr = xs_addr_in6(xprt); | 341 | struct sockaddr_in6 *sin6 = xs_addr_in6(xprt); |
352 | char *buf; | 342 | char buf[48]; |
353 | |||
354 | buf = kzalloc(40, GFP_KERNEL); | ||
355 | if (buf) { | ||
356 | snprintf(buf, 40, "%pI6",&addr->sin6_addr); | ||
357 | } | ||
358 | xprt->address_strings[RPC_DISPLAY_ADDR] = buf; | ||
359 | |||
360 | buf = kzalloc(8, GFP_KERNEL); | ||
361 | if (buf) { | ||
362 | snprintf(buf, 8, "%u", | ||
363 | ntohs(addr->sin6_port)); | ||
364 | } | ||
365 | xprt->address_strings[RPC_DISPLAY_PORT] = buf; | ||
366 | 343 | ||
367 | xprt->address_strings[RPC_DISPLAY_PROTO] = protocol; | 344 | xprt->address_strings[RPC_DISPLAY_PROTO] = protocol; |
345 | xprt->address_strings[RPC_DISPLAY_NETID] = netid; | ||
368 | 346 | ||
369 | buf = kzalloc(64, GFP_KERNEL); | 347 | (void)snprintf(buf, sizeof(buf), "%pi6", &sin6->sin6_addr); |
370 | if (buf) { | 348 | xprt->address_strings[RPC_DISPLAY_HEX_ADDR] = kstrdup(buf, GFP_KERNEL); |
371 | snprintf(buf, 64, "addr=%pI6 port=%u proto=%s", | ||
372 | &addr->sin6_addr, | ||
373 | ntohs(addr->sin6_port), | ||
374 | protocol); | ||
375 | } | ||
376 | xprt->address_strings[RPC_DISPLAY_ALL] = buf; | ||
377 | |||
378 | buf = kzalloc(36, GFP_KERNEL); | ||
379 | if (buf) | ||
380 | snprintf(buf, 36, "%pi6", &addr->sin6_addr); | ||
381 | |||
382 | xprt->address_strings[RPC_DISPLAY_HEX_ADDR] = buf; | ||
383 | |||
384 | buf = kzalloc(8, GFP_KERNEL); | ||
385 | if (buf) { | ||
386 | snprintf(buf, 8, "%4hx", | ||
387 | ntohs(addr->sin6_port)); | ||
388 | } | ||
389 | xprt->address_strings[RPC_DISPLAY_HEX_PORT] = buf; | ||
390 | 349 | ||
391 | xprt->address_strings[RPC_DISPLAY_NETID] = netid; | 350 | xs_format_common_peer_addresses(xprt); |
392 | } | 351 | } |
393 | 352 | ||
394 | static void xs_free_peer_addresses(struct rpc_xprt *xprt) | 353 | static void xs_free_peer_addresses(struct rpc_xprt *xprt) |