SUNRPC client: add interface for binding to a local address
In addition to binding to a local privileged port the NFS client should allow binding to a specific local address. This is used by the server for callbacks. The patch adds the necessary interface. Signed-off-by: Frank van Maarseveen <frankvm@frankvm.com> Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
This commit is contained in:
parent
a97476926e
commit
d3bc9a1deb
4 changed files with 19 additions and 8 deletions
|
@ -98,6 +98,7 @@ struct rpc_create_args {
|
||||||
int protocol;
|
int protocol;
|
||||||
struct sockaddr *address;
|
struct sockaddr *address;
|
||||||
size_t addrsize;
|
size_t addrsize;
|
||||||
|
struct sockaddr *saddress;
|
||||||
struct rpc_timeout *timeout;
|
struct rpc_timeout *timeout;
|
||||||
char *servername;
|
char *servername;
|
||||||
struct rpc_program *program;
|
struct rpc_program *program;
|
||||||
|
|
|
@ -198,6 +198,7 @@ struct rpc_xprt {
|
||||||
|
|
||||||
struct rpc_xprtsock_create {
|
struct rpc_xprtsock_create {
|
||||||
int proto; /* IPPROTO_UDP or IPPROTO_TCP */
|
int proto; /* IPPROTO_UDP or IPPROTO_TCP */
|
||||||
|
struct sockaddr * srcaddr; /* optional local address */
|
||||||
struct sockaddr * dstaddr; /* remote peer address */
|
struct sockaddr * dstaddr; /* remote peer address */
|
||||||
size_t addrlen;
|
size_t addrlen;
|
||||||
struct rpc_timeout * timeout; /* optional timeout parameters */
|
struct rpc_timeout * timeout; /* optional timeout parameters */
|
||||||
|
|
|
@ -236,6 +236,7 @@ struct rpc_clnt *rpc_create(struct rpc_create_args *args)
|
||||||
struct rpc_clnt *clnt;
|
struct rpc_clnt *clnt;
|
||||||
struct rpc_xprtsock_create xprtargs = {
|
struct rpc_xprtsock_create xprtargs = {
|
||||||
.proto = args->protocol,
|
.proto = args->protocol,
|
||||||
|
.srcaddr = args->saddress,
|
||||||
.dstaddr = args->address,
|
.dstaddr = args->address,
|
||||||
.addrlen = args->addrsize,
|
.addrlen = args->addrsize,
|
||||||
.timeout = args->timeout
|
.timeout = args->timeout
|
||||||
|
|
|
@ -235,6 +235,7 @@ struct sock_xprt {
|
||||||
* Connection of transports
|
* Connection of transports
|
||||||
*/
|
*/
|
||||||
struct delayed_work connect_worker;
|
struct delayed_work connect_worker;
|
||||||
|
struct sockaddr_storage addr;
|
||||||
unsigned short port;
|
unsigned short port;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1145,31 +1146,36 @@ static void xs_set_port(struct rpc_xprt *xprt, unsigned short port)
|
||||||
sap->sin_port = htons(port);
|
sap->sin_port = htons(port);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int xs_bindresvport(struct sock_xprt *transport, struct socket *sock)
|
static int xs_bind(struct sock_xprt *transport, struct socket *sock)
|
||||||
{
|
{
|
||||||
struct sockaddr_in myaddr = {
|
struct sockaddr_in myaddr = {
|
||||||
.sin_family = AF_INET,
|
.sin_family = AF_INET,
|
||||||
};
|
};
|
||||||
|
struct sockaddr_in *sa;
|
||||||
int err;
|
int err;
|
||||||
unsigned short port = transport->port;
|
unsigned short port = transport->port;
|
||||||
|
|
||||||
|
if (!transport->xprt.resvport)
|
||||||
|
port = 0;
|
||||||
|
sa = (struct sockaddr_in *)&transport->addr;
|
||||||
|
myaddr.sin_addr = sa->sin_addr;
|
||||||
do {
|
do {
|
||||||
myaddr.sin_port = htons(port);
|
myaddr.sin_port = htons(port);
|
||||||
err = kernel_bind(sock, (struct sockaddr *) &myaddr,
|
err = kernel_bind(sock, (struct sockaddr *) &myaddr,
|
||||||
sizeof(myaddr));
|
sizeof(myaddr));
|
||||||
|
if (!transport->xprt.resvport)
|
||||||
|
break;
|
||||||
if (err == 0) {
|
if (err == 0) {
|
||||||
transport->port = port;
|
transport->port = port;
|
||||||
dprintk("RPC: xs_bindresvport bound to port %u\n",
|
break;
|
||||||
port);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
if (port <= xprt_min_resvport)
|
if (port <= xprt_min_resvport)
|
||||||
port = xprt_max_resvport;
|
port = xprt_max_resvport;
|
||||||
else
|
else
|
||||||
port--;
|
port--;
|
||||||
} while (err == -EADDRINUSE && port != transport->port);
|
} while (err == -EADDRINUSE && port != transport->port);
|
||||||
|
dprintk("RPC: xs_bind "NIPQUAD_FMT":%u: %s (%d)\n",
|
||||||
dprintk("RPC: can't bind to reserved port (%d).\n", -err);
|
NIPQUAD(myaddr.sin_addr), port, err ? "failed" : "ok", err);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1228,7 +1234,7 @@ static void xs_udp_connect_worker(struct work_struct *work)
|
||||||
}
|
}
|
||||||
xs_reclassify_socket(sock);
|
xs_reclassify_socket(sock);
|
||||||
|
|
||||||
if (xprt->resvport && xs_bindresvport(transport, sock) < 0) {
|
if (xs_bind(transport, sock)) {
|
||||||
sock_release(sock);
|
sock_release(sock);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
@ -1315,7 +1321,7 @@ static void xs_tcp_connect_worker(struct work_struct *work)
|
||||||
}
|
}
|
||||||
xs_reclassify_socket(sock);
|
xs_reclassify_socket(sock);
|
||||||
|
|
||||||
if (xprt->resvport && xs_bindresvport(transport, sock) < 0) {
|
if (xs_bind(transport, sock)) {
|
||||||
sock_release(sock);
|
sock_release(sock);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
@ -1531,6 +1537,8 @@ static struct rpc_xprt *xs_setup_xprt(struct rpc_xprtsock_create *args, unsigned
|
||||||
|
|
||||||
memcpy(&xprt->addr, args->dstaddr, args->addrlen);
|
memcpy(&xprt->addr, args->dstaddr, args->addrlen);
|
||||||
xprt->addrlen = args->addrlen;
|
xprt->addrlen = args->addrlen;
|
||||||
|
if (args->srcaddr)
|
||||||
|
memcpy(&new->addr, args->srcaddr, args->addrlen);
|
||||||
new->port = xs_get_random_port();
|
new->port = xs_get_random_port();
|
||||||
|
|
||||||
return xprt;
|
return xprt;
|
||||||
|
|
Loading…
Reference in a new issue