Allow NFS to bind to local IP address.
Subsystems (3)
cover Allow NFS to bind to local IP address.
From: Ben Greear <[email protected]>
This patch series allows binding the nfs and rpc logic to a specific local IP address.
Features/Benefits:
* Allow multiple unique mounts to the same server using unique source IP addresses on client system.
Routing rules can then be created based on the source IP address for advanced routing of the NFS traffic.
This could allow someone to use two 1G interfaces to access a server with 10G connectivity and allow aggregate 2Gbps transfer, for instance.
This is also useful for load testing NFS servers as well as the client-side NFS logic (note the bugs & fixed found while testing this code!)
* Allow using a specific IP address on multi-homed system. This could increase security in some cases and in general gives the user more control over how the services are configured.
This code has been tested under load on 3.7.3 and similar versions have been tested for many years on previous kernels.
Full implementation of this feature requires patches to mount.nfs, which were previously agreed to be accepted if the kernel patches are accepted.
Ben Greear (13):
sunrpc: Don't attempt to bind to AF_UNSPEC address.
nfs: Two AF_UNSPEC addresses should always match each other.
nfs: Add srcaddr member to nfs_client.
nfs: Use request destination addr as callback source addr.
nfs: Pay attention to srcaddr in v4.1 callback logic.
nfs: Use srcaddr in nfs_match_client.
nfs: Pass srcaddr into mount request.
nfs: Propagate src-addr in client code.
nfs: Bind to srcaddr in rpcb_create.
nfs: Support srcaddr= to bind to specific IP address.
nfs: Add srcaddr to /proc/fs/nfsfs/servers
lockd: Support binding nlm client to specific address.
nfs: Allow up to 5000 NFSv4 connections (instead of 1024).
fs/lockd/clntlock.c | 3 +- fs/lockd/host.c | 17 +++++++++++++++- fs/nfs/callback.c | 2 +- fs/nfs/callback.h | 3 ++ fs/nfs/callback_proc.c | 3 +- fs/nfs/callback_xdr.c | 3 ++ fs/nfs/client.c | 35 ++++++++++++++++++++++++++++++- fs/nfs/internal.h | 14 +++++++++++- fs/nfs/mount_clnt.c | 1 + fs/nfs/nfs4client.c | 32 +++++++++++++++++++++++++++++- fs/nfs/super.c | 33 +++++++++++++++++++++++++++++- include/linux/lockd/bind.h | 1 + include/linux/lockd/lockd.h | 1 + include/linux/nfs_fs_sb.h | 4 +++ include/linux/sunrpc/clnt.h | 2 + include/linux/sunrpc/svc.h | 1 + net/sunrpc/rpcb_clnt.c | 31 ++++++++++++++++++++++++++-- net/sunrpc/sunrpc.h | 45 ++++++++++++++++++++++++++++++++++++++++++ net/sunrpc/xprtsock.c | 46 +----------------------------------------- 19 files changed, 220 insertions(+), 57 deletions(-)
Signature · 1 line
1.7.3.4
RFC 1/13 sunrpc: Don't attempt to bind to AF_UNSPEC address.
From: Ben Greear <[email protected]>
This lets calling code simply pass AF_UNSPEC addresses instead of adding lots of checks to conditionally pass NULL addresses.
--- net/sunrpc/xprtsock.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
net/sunrpc/xprtsock.c +2 -2
@@ -2561,9 +2561,9 @@ static struct rpc_xprt *xs_setup_xprt(struct xprt_create *args, new = container_of(xprt, struct sock_xprt, xprt);memcpy (&xprt->addr, args->dstaddr, args->addrlen); xprt->addrlen = args->addrlen; -if (args->srcaddr) +if (args->srcaddr && (args->srcaddr->sa_family !=AF_UNSPEC )) {memcpy (&new->srcaddr, args->srcaddr, args->addrlen); -else { + }else {int err; err =xs_init_anyaddr (args->dstaddr->sa_family, (struct sockaddr *)&new->srcaddr);
Signature · 1 line
1.7.3.4
RFC 2/13 nfs: Two AF_UNSPEC addresses should always match each other.
In reply to [email protected]From: Ben Greear <[email protected]>
--- fs/nfs/client.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
fs/nfs/client.c +2 -0
@@ -369,6 +369,8 @@ int nfs_sockaddr_match_ipaddr(const struct sockaddr *sa1,return nfs_sockaddr_match_ipaddr4 (sa1, sa2);case AF_INET6 :return nfs_sockaddr_match_ipaddr6 (sa1, sa2); +case AF_UNSPEC : +return 1 ;/* two UNSPEC addresses match */ }return 0 ; }
Signature · 1 line
1.7.3.4
RFC 3/13 nfs: Add srcaddr member to nfs_client.
In reply to [email protected]From: Ben Greear <[email protected]>
--- fs/nfs/internal.h | 5 +++++ fs/nfs/super.c | 2 ++ include/linux/nfs_fs_sb.h | 4 ++++ 3 files changed, 11 insertions(+), 0 deletions(-)
fs/nfs/internal.h +5 -0
@@ -119,6 +119,11 @@ struct nfs_parsed_mount_data {struct {struct sockaddr_storage address;size_t addrlen; + } srcaddr; + +struct { +struct sockaddr_storage address; +size_t addrlen;char *hostname;u32 version;int port;
fs/nfs/super.c +2 -0
@@ -968,6 +968,8 @@ static struct nfs_parsed_mount_data *nfs_alloc_parsed_mount_data(void) data->minorversion =0 ; data->need_mount = true; data->net = current->nsproxy->net_ns; + data->srcaddr.address.ss_family =AF_UNSPEC ; + data->srcaddr.addrlen =sizeof (data->srcaddr.address);security_init_mnt_opts (&data->lsm_opts); }return data;
include/linux/nfs_fs_sb.h +4 -0
@@ -88,6 +88,10 @@ struct nfs_client {struct nfs41_impl_id *cl_implid;#endif /* CONFIG_NFS_V4 */ +/* If we should bind to a local IP, it should be specified below. */ +struct sockaddr_storage srcaddr; +size_t srcaddrlen; +#ifdef CONFIG_NFS_FSCACHE struct fscache_cookie *fscache;/* client index cache cookie */ #endif
Signature · 1 line
1.7.3.4
RFC 4/13 nfs: Use request destination addr as callback source addr.
In reply to [email protected]From: Ben Greear <[email protected]>
This helps make sure that responses use the correct source address on multi-homed machines.
--- fs/nfs/callback.h | 3 +++ fs/nfs/callback_xdr.c | 3 +++ include/linux/sunrpc/svc.h | 1 + 3 files changed, 7 insertions(+), 0 deletions(-)
fs/nfs/callback.h +3 -0
@@ -59,6 +59,7 @@ struct cb_compound_hdr_res {struct cb_getattrargs {struct sockaddr *addr; +struct sockaddr *srcaddr;struct nfs_fh fh;uint32_t bitmap[2 ]; };
@@ -74,6 +75,7 @@ struct cb_getattrres {struct cb_recallargs {struct sockaddr *addr; +struct sockaddr *srcaddr;struct nfs_fh fh;nfs4_stateid stateid;uint32_t truncate;
@@ -94,6 +96,7 @@ struct referring_call_list {struct cb_sequenceargs {struct sockaddr *csa_addr; +struct sockaddr *csa_daddr;struct nfs4_sessionid csa_sessionid;uint32_t csa_sequenceid;uint32_t csa_slotid;
fs/nfs/callback_xdr.c +3 -0
@@ -198,6 +198,7 @@ static __be32 decode_getattr_args(struct svc_rqst *rqstp, struct xdr_stream *xdrif (unlikely (status !=0 )) goto out; args->addr =svc_addr (rqstp); + args->srcaddr =svc_daddr (rqstp); status =decode_bitmap (xdr, args->bitmap); out:dprintk ("%s: exit with status = %d\n" , __func__,ntohl (status));
@@ -210,6 +211,7 @@ static __be32 decode_recall_args(struct svc_rqst *rqstp, struct xdr_stream *xdr,__be32 status; args->addr =svc_addr (rqstp); + args->srcaddr =svc_daddr (rqstp); status =decode_stateid (xdr, &args->stateid);if (unlikely (status !=0 )) goto out;
@@ -448,6 +450,7 @@ static __be32 decode_cb_sequence_args(struct svc_rqst *rqstp, goto out; args->csa_addr =svc_addr (rqstp); + args->csa_daddr =svc_daddr (rqstp); args->csa_sequenceid =ntohl (*p++); args->csa_slotid =ntohl (*p++); args->csa_highestslotid =ntohl (*p++);
include/linux/sunrpc/svc.h +1 -0
@@ -313,6 +313,7 @@ static inline struct sockaddr *svc_daddr(const struct svc_rqst *rqst)return (struct sockaddr *) &rqst->rq_daddr; } +/* * Check buffer bounds after decoding arguments */
Signature · 1 line
1.7.3.4
RFC 5/13 nfs: Pay attention to srcaddr in v4.1 callback logic.
In reply to [email protected]From: Ben Greear <[email protected]>
--- fs/nfs/callback_proc.c | 3 ++- fs/nfs/internal.h | 6 ++++-- fs/nfs/nfs4client.c | 24 +++++++++++++++++++++++- 3 files changed, 29 insertions(+), 4 deletions(-)
fs/nfs/callback_proc.c +2 -1
@@ -451,7 +451,8 @@ __be32 nfs4_callback_sequence(struct cb_sequenceargs *args,int i;__be32 status =htonl (NFS4ERR_BADSESSION ); - clp =nfs4_find_client_sessionid (cps->net, args->csa_addr, &args->csa_sessionid); + clp =nfs4_find_client_sessionid (cps->net, args->csa_daddr, args->csa_addr, + &args->csa_sessionid);if (clp ==NULL ) goto out;
fs/nfs/internal.h +4 -2
@@ -190,8 +190,10 @@ extern void nfs_put_client(struct nfs_client *);extern void nfs_free_client (struct nfs_client *);extern struct nfs_client *nfs4_find_client_ident (struct net *,int );extern struct nfs_client * -nfs4_find_client_sessionid (struct net *,const struct sockaddr *, -struct nfs4_sessionid *); +nfs4_find_client_sessionid (struct net *, +const struct sockaddr *srcaddr, +const struct sockaddr *addr, +struct nfs4_sessionid *);extern struct nfs_server *nfs_create_server (struct nfs_mount_info *,struct nfs_subversion *); extern struct nfs_server *nfs4_create_server(
fs/nfs/nfs4client.c +23 -1
@@ -543,11 +543,13 @@ static bool nfs4_cb_match_client(const struct sockaddr *addr,* Returns NULL if no such client */ struct nfs_client * -nfs4_find_client_sessionid (struct net *net,const struct sockaddr *addr, +nfs4_find_client_sessionid (struct net *net,const struct sockaddr *srcaddr, +const struct sockaddr *addr,struct nfs4_sessionid *sid) {struct nfs_client *clp;struct nfs_net *nn =net_generic (net, nfs_net_id); +struct nfs_client *ok_fit =NULL ;spin_lock (&nn->nfs_client_lock);list_for_each_entry (clp, &nn->nfs_client_list, cl_share_link) {
@@ -562,10 +564,30 @@ nfs4_find_client_sessionid(struct net *net, const struct sockaddr *addr, sid->data, NFS4_MAX_SESSIONID_LEN) != 0)continue ; +if (srcaddr) { +const struct sockaddr *sa; + sa = (const struct sockaddr *)&clp->cl_addr; +if (!nfs_sockaddr_match_ipaddr (srcaddr, sa)) { +/* If clp doesn't bind to srcaddr, then +* it is a potential match if we don't find +* a better one. +*/ +if (sa->sa_family ==AF_UNSPEC && !ok_fit) + ok_fit = clp; +continue ; + } + } +found_one:atomic_inc (&clp->cl_count);spin_unlock (&nn->nfs_client_lock);return clp; } + +if (ok_fit) { + clp = ok_fit; + goto found_one; + } +spin_unlock (&nn->nfs_client_lock);return NULL ; }
Signature · 1 line
1.7.3.4
RFC 6/13 nfs: Use srcaddr in nfs_match_client.
In reply to [email protected]From: Ben Greear <[email protected]>
For bound clients, we have to make sure we do not re-use a client that is bound differently.
--- fs/nfs/client.c | 10 ++++++++++ fs/nfs/internal.h | 2 ++ 2 files changed, 12 insertions(+), 0 deletions(-)
fs/nfs/client.c +10 -0
@@ -408,6 +408,9 @@ static struct nfs_client *nfs_match_client(const struct nfs_client_initdata *datlist_for_each_entry (clp, &nn->nfs_client_list, cl_share_link) {const struct sockaddr *clap = (struct sockaddr *)&clp->cl_addr; +const struct sockaddr *sa; + sa = (const struct sockaddr *)&clp->srcaddr; +/* Don't match clients that failed to initialise properly */ if (clp->cl_cons_state <0 )continue ;
@@ -425,6 +428,13 @@ static struct nfs_client *nfs_match_client(const struct nfs_client_initdata *datif (!nfs_sockaddr_cmp (sap, clap))continue ; +/* Check to make sure local-IP bindings match, +* but just the IP-addr. +*/ +if (data->srcaddr && + !nfs_sockaddr_match_ipaddr (data->srcaddr, sa)) +continue ; +atomic_inc (&clp->cl_count);return clp; }
fs/nfs/internal.h +2 -0
@@ -89,7 +89,9 @@ struct nfs_client_initdata {unsigned long init_flags;const char *hostname;const struct sockaddr *addr; +const struct sockaddr *srcaddr;size_t addrlen; +size_t srcaddrlen;struct nfs_subversion *nfs_mod;int proto;u32 minorversion;
Signature · 1 line
1.7.3.4
RFC 7/13 nfs: Pass srcaddr into mount request.
In reply to [email protected]From: Ben Greear <[email protected]>
This starts tying the srcaddr logic together.
--- fs/nfs/internal.h | 1 + fs/nfs/mount_clnt.c | 1 + fs/nfs/super.c | 2 ++ 3 files changed, 4 insertions(+), 0 deletions(-)
fs/nfs/internal.h +1 -0
@@ -148,6 +148,7 @@ struct nfs_parsed_mount_data {/* mount_clnt.c */ struct nfs_mount_request {struct sockaddr *sap; +struct sockaddr *srcaddr;size_t salen;char *hostname;char *dirpath;
fs/nfs/mount_clnt.c +1 -0
@@ -155,6 +155,7 @@ int nfs_mount(struct nfs_mount_request *info)struct rpc_create_args args = { .net = info->net, .protocol = info->protocol, + .saddress = info->srcaddr, .address = info->sap, .addrsize = info->salen, .servername = info->hostname,
fs/nfs/super.c +2 -0
@@ -1710,6 +1710,8 @@ static int nfs_request_mount(struct nfs_parsed_mount_data *args,struct nfs_mount_request request = { .sap = (struct sockaddr *) &args->mount_server.address, + .salen = args->mount_server.addrlen, + .srcaddr = (struct sockaddr *)&args->srcaddr.address, .dirpath = args->nfs_server.export_path, .protocol = args->mount_server.protocol, .fh = root_fh,
Signature · 1 line
1.7.3.4
RFC 8/13 nfs: Propagate src-addr in client code.
In reply to [email protected]From: Ben Greear <[email protected]>
This ties the srcaddr supplied by mount to the
rpc code.
--- fs/nfs/client.c | 5 +++++ fs/nfs/nfs4client.c | 8 ++++++++ 2 files changed, 13 insertions(+), 0 deletions(-)
fs/nfs/client.c +5 -0
@@ -167,6 +167,8 @@ struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *cl_init)memcpy (&clp->cl_addr, cl_init->addr, cl_init->addrlen); clp->cl_addrlen = cl_init->addrlen; +memcpy (&clp->srcaddr, cl_init->srcaddr, cl_init->srcaddrlen); + clp->srcaddrlen = cl_init->srcaddrlen;if (cl_init->hostname) { err = -ENOMEM ;
@@ -594,6 +596,7 @@ int nfs_create_rpc_client(struct nfs_client *clp, .net = clp->cl_net, .protocol = clp->cl_proto, .address = (struct sockaddr *)&clp->cl_addr, + .saddress = (struct sockaddr *)&clp->srcaddr, .addrsize = clp->cl_addrlen, .timeout = timeparms, .servername = clp->cl_hostname,
@@ -751,6 +754,8 @@ static int nfs_init_server(struct nfs_server *server, .addr = (const struct sockaddr *)&data->nfs_server.address, .addrlen = data->nfs_server.addrlen, .nfs_mod = nfs_mod, + .srcaddr = (const struct sockaddr *)&data->srcaddr.address, + .srcaddrlen = data->srcaddr.addrlen, .proto = data->nfs_server.protocol, .net = data->net, };
fs/nfs/nfs4client.c +8 -0
@@ -610,6 +610,8 @@ static int nfs4_set_client(struct nfs_server *server,const struct sockaddr *addr, const size_t addrlen, const char *ip_addr, + const struct sockaddr *srcaddr, + const size_t srcaddrlen, rpc_authflavor_t authflavour, int proto, const struct rpc_timeout *timeparms, u32 minorversion, struct net *net)
@@ -622,6 +624,8 @@ static int nfs4_set_client(struct nfs_server *server, .proto = proto, .minorversion = minorversion, .net = net, + .srcaddr = srcaddr, + .srcaddrlen = srcaddrlen, };struct nfs_client *clp;int error;
@@ -796,6 +800,8 @@ static int nfs4_init_server(struct nfs_server *server, (const struct sockaddr *)&data->nfs_server.address, data->nfs_server.addrlen, data->client_address, + (const struct sockaddr *)&data->srcaddr.address, + data->srcaddr.addrlen, data->auth_flavors[0 ], data->nfs_server.protocol, &timeparms,
@@ -896,6 +902,8 @@ struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *data, data->addr, data->addrlen, parent_client->cl_ipaddr, + (const struct sockaddr *)&parent_client->srcaddr, + parent_client->srcaddrlen, data->authflavor,rpc_protocol (parent_server->client), parent_server->client->cl_timeout,
Signature · 1 line
1.7.3.4
RFC 9/13 nfs: Bind to srcaddr in rpcb_create.
In reply to [email protected]From: Ben Greear <[email protected]>
This more properly clones the existing client connection settings, allowing rpc calls to take advantage of routing rules based on source IP addresses.
--- net/sunrpc/rpcb_clnt.c | 31 ++++++++++++++++++++++++++++--- net/sunrpc/sunrpc.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ net/sunrpc/xprtsock.c | 42 ------------------------------------------ 3 files changed, 73 insertions(+), 45 deletions(-)
net/sunrpc/rpcb_clnt.c +28 -3
@@ -31,6 +31,7 @@#include <linux/sunrpc/xprtsock.h> #include "netns.h" +#include "sunrpc.h" #ifdef RPC_DEBUG # define RPCDBG_FACILITY RPCDBG_BIND
@@ -346,12 +347,14 @@ out: }static struct rpc_clnt *rpcb_create (struct net *net,const char *hostname, -struct sockaddr *srvaddr,size_t salen, -int proto,u32 version) +struct sockaddr *srvaddr, +size_t salen,int proto,u32 version, +struct sockaddr *srcaddr) {struct rpc_create_args args = { .net = net, .protocol = proto, + .saddress = srcaddr, .address = srvaddr, .addrsize = salen, .servername = hostname,
@@ -655,16 +658,38 @@ void rpcb_getport_async(struct rpc_task *task)struct rpc_task *child;struct sockaddr_storage addr;struct sockaddr *sap = (struct sockaddr *)&addr; +struct sockaddr_storage srcaddr; +struct sockaddr *srcaddra =NULL ;size_t salen;int status; +struct sock_xprt *sxprt;rcu_read_lock ();do { clnt =rpcb_find_transport_owner (task->tk_client); xprt =xprt_get (rcu_dereference (clnt->cl_xprt)); }while (xprt ==NULL ); + + sxprt = container_of(xprt, struct sock_xprt, xprt);rcu_read_unlock (); +/* We just want to bind to the IP, not the port */ +memset (&srcaddr,0 ,sizeof (srcaddr)); + srcaddr.ss_family = sxprt->srcaddr.ss_family; +if (sxprt->srcaddr.ss_family ==AF_INET ) { +struct sockaddr_in *si = (struct sockaddr_in *)(&srcaddr); +struct sockaddr_in *si2; + si2 = (struct sockaddr_in *)(&sxprt->srcaddr); + si->sin_addr.s_addr = si2->sin_addr.s_addr; + srcaddra = (struct sockaddr *)(&srcaddr); + }else if (sxprt->srcaddr.ss_family ==AF_INET6 ) { +struct sockaddr_in6 *si = (struct sockaddr_in6 *)(&srcaddr); +struct sockaddr_in6 *si2; + si2 = (struct sockaddr_in6 *)(&sxprt->srcaddr); +memcpy (&si->sin6_addr, &si2->sin6_addr,sizeof (si2->sin6_addr)); + srcaddra = (struct sockaddr *)(&srcaddr); + } +dprintk ("RPC: %5u %s(%s, %u, %u, %d)\n" , task->tk_pid, __func__, xprt->servername, clnt->cl_prog, clnt->cl_vers, xprt->prot);
@@ -719,7 +744,7 @@ void rpcb_getport_async(struct rpc_task *task) task->tk_pid, __func__, bind_version); rpcb_clnt =rpcb_create (xprt->xprt_net, xprt->servername, sap, salen, - xprt->prot, bind_version); + xprt->prot, bind_version, srcaddra);if (IS_ERR (rpcb_clnt)) { status =PTR_ERR (rpcb_clnt); dprintk("RPC: %5u %s: rpcb_create failed, error %ld\n",
net/sunrpc/sunrpc.h +45 -0
51 lines not on this page · raw message
net/sunrpc/xprtsock.c +0 -42
48 lines not on this page · raw message
Signature · 1 line
1.7.3.4
RFC 10/13 nfs: Support srcaddr= to bind to specific IP address.
In reply to [email protected]From: Ben Greear <[email protected]>
In order to have more control on multi-homed machines, it is nice to be able to bind to a specific IP address. This can aid with interface selection, policy based routing, multiple unique mounts to the same server, and similar things.
This patch allows srcaddr= option for NFS. The key 'srcaddr' was chosen to match the similar patch for cifs.
For NFSv4, if one is specifying clientaddr, it must be the same as srcaddr or things may not work properly.
NFSv3, NFSv4 over TCP/IPv4 and TCP/IPv6 has been successfully tested.
Usage:
mount -t nfs4 [2002::1]:/rpool/ben /mnt/foo/ben-1 -o srcaddr=2002::2,clientaddr=2002::2 mount -t nfs4 192.168.100.3:/foo /mnt/foo/ben-2 -o srcaddr=192.168.100.174
--- fs/nfs/super.c | 29 ++++++++++++++++++++++++++++- 1 files changed, 28 insertions(+), 1 deletions(-)
fs/nfs/super.c +28 -1
@@ -106,7 +106,7 @@ enum {/* Mount options that take string arguments */ Opt_nfsvers, Opt_sec, Opt_proto, Opt_mountproto, Opt_mounthost, - Opt_addr, Opt_mountaddr, Opt_clientaddr, + Opt_addr, Opt_mountaddr, Opt_clientaddr, Opt_srcaddr, Opt_lookupcache, Opt_fscache_uniq, Opt_local_lock,
@@ -176,6 +176,7 @@ static const match_table_t nfs_mount_option_tokens = { { Opt_mountproto, "mountproto=%s" }, { Opt_addr, "addr=%s" }, { Opt_clientaddr, "clientaddr=%s" }, + { Opt_srcaddr, "srcaddr=%s" }, { Opt_mounthost, "mounthost=%s" }, { Opt_mountaddr, "mountaddr=%s" },
@@ -725,6 +726,15 @@ static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,else nfs_show_nfsv4_options (m, nfss, showdefaults); +if (clp->srcaddr.ss_family ==AF_INET6 ) { +struct sockaddr_in6 *sin6; + sin6 = (struct sockaddr_in6 *)(&clp->srcaddr); +seq_printf (m,",srcaddr=%pI6c" , &sin6->sin6_addr); + }else if (clp->srcaddr.ss_family ==AF_INET ) { +struct sockaddr_in *sin = (struct sockaddr_in *)&clp->srcaddr; +seq_printf (m,",srcaddr=%pI4" , &sin->sin_addr.s_addr); + } +if (nfss->options &NFS_OPTION_FSCACHE )seq_printf (m,",fsc" );
@@ -1543,6 +1553,23 @@ static int nfs_parse_mount_options(char *raw, goto out_nomem; mnt->options |=NFS_OPTION_FSCACHE ;break ; +case Opt_srcaddr: + string =match_strdup (args); +if (string ==NULL ) + goto out_nomem; + mnt->srcaddr.addrlen = +rpc_pton (mnt->net, string,strlen (string), + (struct sockaddr *) + &mnt->srcaddr.address, +sizeof (mnt->srcaddr.address)); +kfree (string); +if (mnt->srcaddr.addrlen ==0 ) { +printk (KERN_WARNING +"nfs: Could not parse srcaddr: %s\n" , + string); + goto out_invalid_address; + } +break ;case Opt_local_lock: string =match_strdup (args);if (string ==NULL )
Signature · 1 line
1.7.3.4
RFC 11/13 nfs: Add srcaddr to /proc/fs/nfsfs/servers
In reply to [email protected]From: Ben Greear <[email protected]>
Helps users understand whether a server instance is bound to a local IP or not.
--- fs/nfs/client.c | 17 +++++++++++++++-- 1 files changed, 15 insertions(+), 2 deletions(-)
fs/nfs/client.c +15 -2
@@ -1311,7 +1311,7 @@ static int nfs_server_list_show(struct seq_file *m, void *v)/* display header on line 1 */ if (v == &nn->nfs_client_list) { -seq_puts (m,"NV SERVER PORT USE HOSTNAME\n" ); +seq_puts (m,"NV SERVER PORT USE HOSTNAME SRCADDR\n" );return 0 ; }
@@ -1323,7 +1323,7 @@ static int nfs_server_list_show(struct seq_file *m, void *v)return 0 ;rcu_read_lock (); - seq_printf(m, "v%u %s %s %3d %s\n", + seq_printf(m, "v%u %s %s %3d %s", clp->rpc_ops->version, rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_ADDR), rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_HEX_PORT),
@@ -1331,6 +1331,19 @@ static int nfs_server_list_show(struct seq_file *m, void *v) clp->cl_hostname);rcu_read_unlock (); +if (clp->srcaddr.ss_family ==AF_INET ) { +const struct sockaddr_in *sin; + sin = (const struct sockaddr_in *)&clp->srcaddr; +seq_printf (m," %pI4\n" , &sin->sin_addr.s_addr); + }else if (clp->srcaddr.ss_family ==AF_INET6 ) { +const struct sockaddr_in6 *sin6; + sin6 = (const struct sockaddr_in6 *)&clp->srcaddr; +seq_printf (m," %pI6c\n" , &sin6->sin6_addr); + }else if (clp->srcaddr.ss_family ==AF_UNSPEC ) +seq_printf (m," ANY\n" ); +else +seq_printf (m," UNKNOWN_%i\n" , (int )(clp->srcaddr.ss_family)); +return 0 ; }
Signature · 1 line
1.7.3.4
RFC 12/13 lockd: Support binding nlm client to specific address.
In reply to [email protected]From: Ben Greear <[email protected]>
This ensures that file locking messages use the proper source IP address if the file system has been mounted with a specified source IP address.
--- fs/lockd/clntlock.c | 3 ++- fs/lockd/host.c | 17 ++++++++++++++++- fs/nfs/client.c | 1 + include/linux/lockd/bind.h | 1 + include/linux/lockd/lockd.h | 1 + include/linux/sunrpc/clnt.h | 2 ++ 6 files changed, 23 insertions(+), 2 deletions(-)
fs/lockd/clntlock.c +2 -1
@@ -60,7 +60,8 @@ struct nlm_host *nlmclnt_init(const struct nlmclnt_initdata *nlm_init)if (status <0 )return ERR_PTR (status); - host =nlmclnt_lookup_host (nlm_init->address, nlm_init->addrlen, + host =nlmclnt_lookup_host (nlm_init->address, nlm_init->srcaddr, + nlm_init->addrlen, nlm_init->protocol, nlm_version, nlm_init->hostname, nlm_init->noresvport, nlm_init->net);
fs/lockd/host.c +16 -1
@@ -51,6 +51,7 @@ static void nlm_gc_hosts(struct net *net);struct nlm_lookup_host_info {const int server;/* search for server|client */ const struct sockaddr *sap;/* address to search for */ +const struct sockaddr *src_addr;/* source address */ const size_t salen;/* it's length */ const unsigned short protocol;/* transport to search for*/ const u32 version;/* NLM version to search for */
@@ -134,7 +135,12 @@ static struct nlm_host *nlm_alloc_host(struct nlm_lookup_host_info *ni,memcpy (nlm_addr (host), ni->sap, ni->salen); host->h_addrlen = ni->salen;rpc_set_port (nlm_addr (host),0 ); - host->h_srcaddrlen =0 ; +if (ni->src_addr && ni->src_addr->sa_family !=AF_UNSPEC ) { +memcpy (nlm_srcaddr (host), ni->src_addr, ni->salen); + host->h_srcaddrlen = ni->salen; + }else { + host->h_srcaddrlen =0 ; + } host->h_rpcclnt =NULL ; host->h_name = nsm->sm_name;
@@ -209,6 +215,7 @@ static void nlm_destroy_host_locked(struct nlm_host *host)* created and returned. */ struct nlm_host *nlmclnt_lookup_host(const struct sockaddr *sap, + const struct sockaddr *srcaddr, const size_t salen, const unsigned short protocol, const u32 version,
@@ -224,6 +231,7 @@ struct nlm_host *nlmclnt_lookup_host(const struct sockaddr *sap, .version = version, .hostname = hostname, .hostname_len = strlen(hostname), + .src_addr = srcaddr, .noresvport = noresvport, .net = net, };
@@ -246,6 +254,13 @@ struct nlm_host *nlmclnt_lookup_host(const struct sockaddr *sap,if (!rpc_cmp_addr (nlm_addr (host), sap))continue ; +/* Check for local binding match only if user +* has specified the source-address. +*/ +if (srcaddr && srcaddr->sa_family !=AF_UNSPEC && + !rpc_cmp_addr (nlm_srcaddr (host), srcaddr)) +continue ; +/* Same address. Share an NSM handle if we already have one */ if (nsm ==NULL ) nsm = host->h_nsmhandle;
fs/nfs/client.c +1 -0
@@ -644,6 +644,7 @@ static int nfs_start_lockd(struct nfs_server *server)struct nlmclnt_initdata nlm_init = { .hostname = clp->cl_hostname, .address = (struct sockaddr *)&clp->cl_addr, + .srcaddr = (struct sockaddr *)&clp->srcaddr, .addrlen = clp->cl_addrlen, .nfs_version = clp->rpc_ops->version, .noresvport = server->flags & NFS_MOUNT_NORESVPORT ?
include/linux/lockd/bind.h +1 -0
@@ -38,6 +38,7 @@ extern struct nlmsvc_binding * nlmsvc_ops;struct nlmclnt_initdata {const char *hostname;const struct sockaddr *address; +const struct sockaddr *srcaddr;size_t addrlen;unsigned short protocol;u32 nfs_version;
include/linux/lockd/lockd.h +1 -0
@@ -219,6 +219,7 @@ void nlmclnt_next_cookie(struct nlm_cookie *);* Host cache */ struct nlm_host *nlmclnt_lookup_host(const struct sockaddr *sap, + const struct sockaddr *bindaddr, const size_t salen, const unsigned short protocol, const u32 version,
include/linux/sunrpc/clnt.h +2 -0
@@ -275,6 +275,8 @@ static inline bool rpc_cmp_addr(const struct sockaddr *sap1,return __rpc_cmp_addr4 (sap1, sap2);case AF_INET6 :return __rpc_cmp_addr6 (sap1, sap2); +case AF_UNSPEC : +return true; } }return false;
Signature · 1 line
1.7.3.4
RFC 13/13 nfs: Allow up to 5000 NFSv4 connections (instead of 1024).
In reply to [email protected]From: Ben Greear <[email protected]>
--- fs/nfs/callback.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
fs/nfs/callback.c +1 -1
@@ -335,7 +335,7 @@ static struct svc_serv *nfs_callback_create_svc(int minorversion)/* As there is only one thread we need to over-ride the * default maximum of 80 connections */ - serv->sv_maxconn =1024 ; + serv->sv_maxconn =5000 ;dprintk ("nfs_callback_create_svc: service created\n" );return serv; }
Signature · 1 line
1.7.3.4