Commit c877b849 authored by Chuck Lever's avatar Chuck Lever Committed by Trond Myklebust

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: default avatarChuck Lever <chuck.lever@oracle.com>
Signed-off-by: default avatarTrond Myklebust <Trond.Myklebust@netapp.com>
parent ba809130
...@@ -168,39 +168,30 @@ static struct rpc_xprt_ops xprt_rdma_procs; /* forward reference */ ...@@ -168,39 +168,30 @@ static struct rpc_xprt_ops xprt_rdma_procs; /* forward reference */
static void static void
xprt_rdma_format_addresses(struct rpc_xprt *xprt) xprt_rdma_format_addresses(struct rpc_xprt *xprt)
{ {
struct sockaddr_in *addr = (struct sockaddr_in *) struct sockaddr *sap = (struct sockaddr *)
&rpcx_to_rdmad(xprt).addr; &rpcx_to_rdmad(xprt).addr;
char *buf; struct sockaddr_in *sin = (struct sockaddr_in *)sap;
char buf[64];
buf = kzalloc(20, GFP_KERNEL); (void)rpc_ntop(sap, buf, sizeof(buf));
if (buf) xprt->address_strings[RPC_DISPLAY_ADDR] = kstrdup(buf, GFP_KERNEL);
snprintf(buf, 20, "%pI4", &addr->sin_addr.s_addr);
xprt->address_strings[RPC_DISPLAY_ADDR] = buf;
buf = kzalloc(8, GFP_KERNEL); (void)snprintf(buf, sizeof(buf), "%u", rpc_get_port(sap));
if (buf) xprt->address_strings[RPC_DISPLAY_PORT] = kstrdup(buf, GFP_KERNEL);
snprintf(buf, 8, "%u", ntohs(addr->sin_port));
xprt->address_strings[RPC_DISPLAY_PORT] = buf;
xprt->address_strings[RPC_DISPLAY_PROTO] = "rdma"; xprt->address_strings[RPC_DISPLAY_PROTO] = "rdma";
buf = kzalloc(48, GFP_KERNEL); (void)snprintf(buf, sizeof(buf), "addr=%s port=%s proto=rdma",
if (buf) xprt->address_strings[RPC_DISPLAY_ADDR],
snprintf(buf, 48, "addr=%pI4 port=%u proto=%s", xprt->address_strings[RPC_DISPLAY_PORT]);
&addr->sin_addr.s_addr, xprt->address_strings[RPC_DISPLAY_ALL] = kstrdup(buf, GFP_KERNEL);
ntohs(addr->sin_port), "rdma");
xprt->address_strings[RPC_DISPLAY_ALL] = buf; (void)snprintf(buf, sizeof(buf), "%02x%02x%02x%02x",
NIPQUAD(sin->sin_addr.s_addr));
buf = kzalloc(10, GFP_KERNEL); xprt->address_strings[RPC_DISPLAY_HEX_ADDR] = kstrdup(buf, GFP_KERNEL);
if (buf)
snprintf(buf, 10, "%02x%02x%02x%02x", (void)snprintf(buf, sizeof(buf), "%4hx", rpc_get_port(sap));
NIPQUAD(addr->sin_addr.s_addr)); xprt->address_strings[RPC_DISPLAY_HEX_PORT] = kstrdup(buf, GFP_KERNEL);
xprt->address_strings[RPC_DISPLAY_HEX_ADDR] = buf;
buf = kzalloc(8, GFP_KERNEL);
if (buf)
snprintf(buf, 8, "%4hx", ntohs(addr->sin_port));
xprt->address_strings[RPC_DISPLAY_HEX_PORT] = buf;
/* netid */ /* netid */
xprt->address_strings[RPC_DISPLAY_NETID] = "rdma"; xprt->address_strings[RPC_DISPLAY_NETID] = "rdma";
......
...@@ -296,99 +296,58 @@ static inline struct sockaddr_in6 *xs_addr_in6(struct rpc_xprt *xprt) ...@@ -296,99 +296,58 @@ static inline struct sockaddr_in6 *xs_addr_in6(struct rpc_xprt *xprt)
return (struct sockaddr_in6 *) &xprt->addr; return (struct sockaddr_in6 *) &xprt->addr;
} }
static void xs_format_ipv4_peer_addresses(struct rpc_xprt *xprt, static void xs_format_common_peer_addresses(struct rpc_xprt *xprt)
const char *protocol,
const char *netid)
{ {
struct sockaddr_in *addr = xs_addr_in(xprt); struct sockaddr *sap = xs_addr(xprt);
char *buf; char buf[128];
buf = kzalloc(20, GFP_KERNEL);
if (buf) {
snprintf(buf, 20, "%pI4", &addr->sin_addr.s_addr);
}
xprt->address_strings[RPC_DISPLAY_ADDR] = buf;
buf = kzalloc(8, GFP_KERNEL); (void)rpc_ntop(sap, buf, sizeof(buf));
if (buf) { xprt->address_strings[RPC_DISPLAY_ADDR] = kstrdup(buf, GFP_KERNEL);
snprintf(buf, 8, "%u",
ntohs(addr->sin_port));
}
xprt->address_strings[RPC_DISPLAY_PORT] = buf;
xprt->address_strings[RPC_DISPLAY_PROTO] = protocol; (void)snprintf(buf, sizeof(buf), "%u", rpc_get_port(sap));
xprt->address_strings[RPC_DISPLAY_PORT] = kstrdup(buf, GFP_KERNEL);
buf = kzalloc(48, GFP_KERNEL); (void)snprintf(buf, sizeof(buf), "addr=%s port=%s proto=%s",
if (buf) { xprt->address_strings[RPC_DISPLAY_ADDR],
snprintf(buf, 48, "addr=%pI4 port=%u proto=%s", xprt->address_strings[RPC_DISPLAY_PORT],
&addr->sin_addr.s_addr, xprt->address_strings[RPC_DISPLAY_PROTO]);
ntohs(addr->sin_port), xprt->address_strings[RPC_DISPLAY_ALL] = kstrdup(buf, GFP_KERNEL);
protocol);
}
xprt->address_strings[RPC_DISPLAY_ALL] = buf;
buf = kzalloc(10, GFP_KERNEL); (void)snprintf(buf, sizeof(buf), "%4hx", rpc_get_port(sap));
if (buf) { xprt->address_strings[RPC_DISPLAY_HEX_PORT] = kstrdup(buf, GFP_KERNEL);
snprintf(buf, 10, "%02x%02x%02x%02x", }
NIPQUAD(addr->sin_addr.s_addr));
}
xprt->address_strings[RPC_DISPLAY_HEX_ADDR] = buf;
buf = kzalloc(8, GFP_KERNEL); static void xs_format_ipv4_peer_addresses(struct rpc_xprt *xprt,
if (buf) { const char *protocol,
snprintf(buf, 8, "%4hx", const char *netid)
ntohs(addr->sin_port)); {
} struct sockaddr_in *sin = xs_addr_in(xprt);
xprt->address_strings[RPC_DISPLAY_HEX_PORT] = buf; char buf[16];
xprt->address_strings[RPC_DISPLAY_PROTO] = protocol;
xprt->address_strings[RPC_DISPLAY_NETID] = netid; xprt->address_strings[RPC_DISPLAY_NETID] = netid;
(void)snprintf(buf, sizeof(buf), "%02x%02x%02x%02x",
NIPQUAD(sin->sin_addr.s_addr));
xprt->address_strings[RPC_DISPLAY_HEX_ADDR] = kstrdup(buf, GFP_KERNEL);
xs_format_common_peer_addresses(xprt);
} }
static void xs_format_ipv6_peer_addresses(struct rpc_xprt *xprt, static void xs_format_ipv6_peer_addresses(struct rpc_xprt *xprt,
const char *protocol, const char *protocol,
const char *netid) const char *netid)
{ {
struct sockaddr_in6 *addr = xs_addr_in6(xprt); struct sockaddr_in6 *sin6 = xs_addr_in6(xprt);
char *buf; char buf[48];
buf = kzalloc(40, GFP_KERNEL);
if (buf) {
snprintf(buf, 40, "%pI6",&addr->sin6_addr);
}
xprt->address_strings[RPC_DISPLAY_ADDR] = buf;
buf = kzalloc(8, GFP_KERNEL);
if (buf) {
snprintf(buf, 8, "%u",
ntohs(addr->sin6_port));
}
xprt->address_strings[RPC_DISPLAY_PORT] = buf;
xprt->address_strings[RPC_DISPLAY_PROTO] = protocol; xprt->address_strings[RPC_DISPLAY_PROTO] = protocol;
xprt->address_strings[RPC_DISPLAY_NETID] = netid;
buf = kzalloc(64, GFP_KERNEL); (void)snprintf(buf, sizeof(buf), "%pi6", &sin6->sin6_addr);
if (buf) { xprt->address_strings[RPC_DISPLAY_HEX_ADDR] = kstrdup(buf, GFP_KERNEL);
snprintf(buf, 64, "addr=%pI6 port=%u proto=%s",
&addr->sin6_addr,
ntohs(addr->sin6_port),
protocol);
}
xprt->address_strings[RPC_DISPLAY_ALL] = buf;
buf = kzalloc(36, GFP_KERNEL);
if (buf)
snprintf(buf, 36, "%pi6", &addr->sin6_addr);
xprt->address_strings[RPC_DISPLAY_HEX_ADDR] = buf;
buf = kzalloc(8, GFP_KERNEL);
if (buf) {
snprintf(buf, 8, "%4hx",
ntohs(addr->sin6_port));
}
xprt->address_strings[RPC_DISPLAY_HEX_PORT] = buf;
xprt->address_strings[RPC_DISPLAY_NETID] = netid; xs_format_common_peer_addresses(xprt);
} }
static void xs_free_peer_addresses(struct rpc_xprt *xprt) static void xs_free_peer_addresses(struct rpc_xprt *xprt)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment