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

SUNRPC: Use "sockaddr_storage" for storing RPC client's remote peer address

IPv6 addresses are big (128 bytes).  Now that no RPC client consumers treat
the addr field in rpc_xprt structs as an opaque, and access it only via the
API calls, we can safely widen the field in the rpc_xprt struct to
accomodate larger addresses.

Test plan:
Compile kernel with CONFIG_NFS enabled.
Signed-off-by: default avatarChuck Lever <chuck.lever@oracle.com>
Signed-off-by: default avatarTrond Myklebust <Trond.Myklebust@netapp.com>
parent e7f78657
...@@ -134,7 +134,8 @@ struct rpc_xprt { ...@@ -134,7 +134,8 @@ struct rpc_xprt {
struct sock * inet; /* INET layer */ struct sock * inet; /* INET layer */
struct rpc_timeout timeout; /* timeout parms */ struct rpc_timeout timeout; /* timeout parms */
struct sockaddr_in addr; /* server address */ struct sockaddr_storage addr; /* server address */
size_t addrlen; /* size of server address */
int prot; /* IP protocol */ int prot; /* IP protocol */
unsigned long cong; /* current congestion */ unsigned long cong; /* current congestion */
......
...@@ -550,7 +550,7 @@ size_t rpc_peeraddr(struct rpc_clnt *clnt, struct sockaddr *buf, size_t bufsize) ...@@ -550,7 +550,7 @@ size_t rpc_peeraddr(struct rpc_clnt *clnt, struct sockaddr *buf, size_t bufsize)
if (bytes > bufsize) if (bytes > bufsize)
bytes = bufsize; bytes = bufsize;
memcpy(buf, &clnt->cl_xprt->addr, bytes); memcpy(buf, &clnt->cl_xprt->addr, bytes);
return sizeof(xprt->addr); return xprt->addrlen;
} }
EXPORT_SYMBOL(rpc_peeraddr); EXPORT_SYMBOL(rpc_peeraddr);
......
...@@ -896,7 +896,8 @@ static struct rpc_xprt *xprt_setup(int proto, struct sockaddr_in *ap, struct rpc ...@@ -896,7 +896,8 @@ static struct rpc_xprt *xprt_setup(int proto, struct sockaddr_in *ap, struct rpc
if ((xprt = kzalloc(sizeof(struct rpc_xprt), GFP_KERNEL)) == NULL) if ((xprt = kzalloc(sizeof(struct rpc_xprt), GFP_KERNEL)) == NULL)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
xprt->addr = *ap; memcpy(&xprt->addr, ap, sizeof(*ap));
xprt->addrlen = sizeof(*ap);
switch (proto) { switch (proto) {
case IPPROTO_UDP: case IPPROTO_UDP:
......
...@@ -341,7 +341,7 @@ static int xs_udp_send_request(struct rpc_task *task) ...@@ -341,7 +341,7 @@ static int xs_udp_send_request(struct rpc_task *task)
req->rq_xtime = jiffies; req->rq_xtime = jiffies;
status = xs_sendpages(xprt->sock, (struct sockaddr *) &xprt->addr, status = xs_sendpages(xprt->sock, (struct sockaddr *) &xprt->addr,
sizeof(xprt->addr), xdr, req->rq_bytes_sent); xprt->addrlen, xdr, req->rq_bytes_sent);
dprintk("RPC: xs_udp_send_request(%u) = %d\n", dprintk("RPC: xs_udp_send_request(%u) = %d\n",
xdr->len - req->rq_bytes_sent, status); xdr->len - req->rq_bytes_sent, status);
...@@ -1027,8 +1027,11 @@ static char *xs_print_peer_address(struct rpc_xprt *xprt, enum rpc_display_forma ...@@ -1027,8 +1027,11 @@ static char *xs_print_peer_address(struct rpc_xprt *xprt, enum rpc_display_forma
*/ */
static void xs_set_port(struct rpc_xprt *xprt, unsigned short port) static void xs_set_port(struct rpc_xprt *xprt, unsigned short port)
{ {
struct sockaddr_in *sap = (struct sockaddr_in *) &xprt->addr;
dprintk("RPC: setting port for xprt %p to %u\n", xprt, port); dprintk("RPC: setting port for xprt %p to %u\n", xprt, port);
xprt->addr.sin_port = htons(port);
sap->sin_port = htons(port);
} }
static int xs_bindresvport(struct rpc_xprt *xprt, struct socket *sock) static int xs_bindresvport(struct rpc_xprt *xprt, struct socket *sock)
...@@ -1209,7 +1212,7 @@ static void xs_tcp_connect_worker(void *args) ...@@ -1209,7 +1212,7 @@ static void xs_tcp_connect_worker(void *args)
xprt->stat.connect_count++; xprt->stat.connect_count++;
xprt->stat.connect_start = jiffies; xprt->stat.connect_start = jiffies;
status = sock->ops->connect(sock, (struct sockaddr *) &xprt->addr, status = sock->ops->connect(sock, (struct sockaddr *) &xprt->addr,
sizeof(xprt->addr), O_NONBLOCK); xprt->addrlen, O_NONBLOCK);
dprintk("RPC: %p connect status %d connected %d sock state %d\n", dprintk("RPC: %p connect status %d connected %d sock state %d\n",
xprt, -status, xprt_connected(xprt), sock->sk->sk_state); xprt, -status, xprt_connected(xprt), sock->sk->sk_state);
if (status < 0) { if (status < 0) {
...@@ -1359,6 +1362,7 @@ static struct rpc_xprt_ops xs_tcp_ops = { ...@@ -1359,6 +1362,7 @@ static struct rpc_xprt_ops xs_tcp_ops = {
int xs_setup_udp(struct rpc_xprt *xprt, struct rpc_timeout *to) int xs_setup_udp(struct rpc_xprt *xprt, struct rpc_timeout *to)
{ {
size_t slot_table_size; size_t slot_table_size;
struct sockaddr_in *addr = (struct sockaddr_in *) &xprt->addr;
xprt->max_reqs = xprt_udp_slot_table_entries; xprt->max_reqs = xprt_udp_slot_table_entries;
slot_table_size = xprt->max_reqs * sizeof(xprt->slot[0]); slot_table_size = xprt->max_reqs * sizeof(xprt->slot[0]);
...@@ -1366,7 +1370,7 @@ int xs_setup_udp(struct rpc_xprt *xprt, struct rpc_timeout *to) ...@@ -1366,7 +1370,7 @@ int xs_setup_udp(struct rpc_xprt *xprt, struct rpc_timeout *to)
if (xprt->slot == NULL) if (xprt->slot == NULL)
return -ENOMEM; return -ENOMEM;
if (ntohs(xprt->addr.sin_port) != 0) if (ntohs(addr->sin_port != 0))
xprt_set_bound(xprt); xprt_set_bound(xprt);
xprt->port = xs_get_random_port(); xprt->port = xs_get_random_port();
...@@ -1405,6 +1409,7 @@ int xs_setup_udp(struct rpc_xprt *xprt, struct rpc_timeout *to) ...@@ -1405,6 +1409,7 @@ int xs_setup_udp(struct rpc_xprt *xprt, struct rpc_timeout *to)
int xs_setup_tcp(struct rpc_xprt *xprt, struct rpc_timeout *to) int xs_setup_tcp(struct rpc_xprt *xprt, struct rpc_timeout *to)
{ {
size_t slot_table_size; size_t slot_table_size;
struct sockaddr_in *addr = (struct sockaddr_in *) &xprt->addr;
xprt->max_reqs = xprt_tcp_slot_table_entries; xprt->max_reqs = xprt_tcp_slot_table_entries;
slot_table_size = xprt->max_reqs * sizeof(xprt->slot[0]); slot_table_size = xprt->max_reqs * sizeof(xprt->slot[0]);
...@@ -1412,7 +1417,7 @@ int xs_setup_tcp(struct rpc_xprt *xprt, struct rpc_timeout *to) ...@@ -1412,7 +1417,7 @@ int xs_setup_tcp(struct rpc_xprt *xprt, struct rpc_timeout *to)
if (xprt->slot == NULL) if (xprt->slot == NULL)
return -ENOMEM; return -ENOMEM;
if (ntohs(xprt->addr.sin_port) != 0) if (ntohs(addr->sin_port) != 0)
xprt_set_bound(xprt); xprt_set_bound(xprt);
xprt->port = xs_get_random_port(); xprt->port = xs_get_random_port();
......
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