RFC: support srcaddr= option to bind to local IPs.
Subsystems (2)
This patch lets one bind the local side of NFS sockets to a particular IP address. This can be useful for users on multi-homed systems.
This patch must be on top of the previous patch to fix the IPv6 address comparison or it will not work.
Comments and suggestions welcome...I'll incorporate those and post an official signed-off patch after that.
Thanks,
Ben
Signature · 2 lines
Ben Greear <[email protected]> Candela Technologies Inc http://www.candelatech.com
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);if (host ==NULL ) {
fs/lockd/host.c +3 -5
@@ -232,15 +232,13 @@ nlm_destroy_host(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,const char *hostname,int noresvport) { -const struct sockaddr source = { - .sa_family =AF_UNSPEC , - };struct nlm_lookup_host_info ni = { .server =0 , .sap = sap,
@@ -249,8 +247,8 @@ struct nlm_host *nlmclnt_lookup_host(const struct sockaddr *sap, .version = version, .hostname = hostname, .hostname_len = strlen(hostname), - .src_sap = &source, - .src_len = sizeof(source), + .src_sap = srcaddr, + .src_len = salen, .noresvport = noresvport, };
fs/nfs/callback.c +1 -1
@@ -353,7 +353,7 @@ static int nfs_callback_authenticate(struct svc_rqst *rqstp)int ret =SVC_OK ;/* Don't talk to strangers */ - clp =nfs_find_client (svc_addr (rqstp),4 ); + clp =nfs_find_client (svc_daddr (rqstp), true,svc_addr (rqstp),4 );if (clp ==NULL )return SVC_DROP ;
fs/nfs/callback.h +2 -0
@@ -50,6 +50,7 @@ struct cb_compound_hdr_res {struct cb_getattrargs {struct sockaddr *addr; +struct sockaddr *srcaddr;struct nfs_fh fh;uint32_t bitmap[2 ]; };
@@ -65,6 +66,7 @@ struct cb_getattrres {struct cb_recallargs {struct sockaddr *addr; +struct sockaddr *srcaddr;struct nfs_fh fh;nfs4_stateid stateid;uint32_t truncate;
fs/nfs/callback_proc.c +10 -3
@@ -26,7 +26,7 @@ __be32 nfs4_callback_getattr(struct cb_getattrargs *args, struct cb_getattrres * res->bitmap[0 ] = res->bitmap[1 ] =0 ; res->status =htonl (NFS4ERR_BADHANDLE ); - clp =nfs_find_client (args->addr,4 ); + clp =nfs_find_client (args->srcaddr, true, args->addr,4 );if (clp ==NULL ) goto out;
@@ -69,7 +69,7 @@ __be32 nfs4_callback_recall(struct cb_recallargs *args, void *dummy)__be32 res; res =htonl (NFS4ERR_BADHANDLE ); - clp =nfs_find_client (args->addr,4 ); + clp =nfs_find_client (args->srcaddr, true, args->addr,4 );if (clp ==NULL ) goto out;
@@ -197,8 +197,15 @@ validate_seqid(struct nfs4_slot_table *tbl, struct cb_sequenceargs * args) struct nfs4_sessionid *sessionid) {struct nfs_client *clp; +/* This would be the IP (if any) that we are bound +* to locally. Since session-id appears to be unique, +* we'll just ignore the bind-addr and match directly on +* session-id. +*/ +struct sockaddr_storage srcaddr; +memset (&srcaddr,0 ,sizeof (srcaddr)); - clp =nfs_find_client (addr,4 ); + clp =nfs_find_client ((struct sockaddr *)&srcaddr, false, addr,4 );if (clp ==NULL )return NULL ;
fs/nfs/callback_xdr.c +2 -0
@@ -191,6 +191,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));
@@ -203,6 +204,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;
fs/nfs/client.c +56 -5
188 lines not on this page · raw message
fs/nfs/internal.h +9 -1
@@ -84,6 +84,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;
@@ -105,6 +110,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;
@@ -123,7 +129,9 @@ extern void nfs_umount(const struct nfs_mount_request *info);extern struct rpc_program nfs_program;extern void nfs_put_client (struct nfs_client *); -extern struct nfs_client *nfs_find_client (const struct sockaddr *,u32 ); +extern struct nfs_client *nfs_find_client (const struct sockaddr *srcaddr, +bool compare_srcaddr, +const struct sockaddr *,u32 );extern struct nfs_client *nfs_find_client_next (struct nfs_client *); extern struct nfs_server *nfs_create_server( const struct nfs_parsed_mount_data *,
fs/nfs/mount_clnt.c +1 -0
@@ -154,6 +154,7 @@ int nfs_mount(struct nfs_mount_request *info) };struct rpc_create_args args = { .protocol = info->protocol, + .saddress = info->srcaddr, .address = info->sap, .addrsize = info->salen, .servername = info->hostname,
fs/nfs/super.c +30 -1
@@ -97,7 +97,7 @@ enum {/* Mount options that take string arguments */ 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,
@@ -166,6 +166,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" },
@@ -653,6 +654,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" );
@@ -1360,6 +1370,23 @@ static int nfs_parse_mount_options(char *raw,kfree (mnt->client_address); mnt->client_address = string;break ; +case Opt_srcaddr: + string =match_strdup (args); +if (string ==NULL ) + goto out_nomem; + mnt->srcaddr.addrlen = +rpc_pton (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_mounthost: string =match_strdup (args);if (string ==NULL )
@@ -1536,6 +1563,8 @@ static int nfs_try_mount(struct nfs_parsed_mount_data *args,struct nfs_mount_request request = { .sap = (struct sockaddr *) &args->mount_server.address, + .srcaddr = (struct sockaddr *)&args->srcaddr.address, + .salen = args->mount_server.addrlen, .dirpath = args->nfs_server.export_path, .protocol = args->mount_server.protocol, .fh = root_fh,
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
@@ -217,6 +217,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/nfs_fs_sb.h +3 -0
@@ -84,6 +84,9 @@ struct nfs_client {struct nfs4_session *cl_session;/* sharred session */ #endif /* CONFIG_NFS_V4_1 */ +/* If we should bind to a local IP, it should be specified below. */ +struct sockaddr_storage srcaddr; +#ifdef CONFIG_NFS_FSCACHE struct fscache_cookie *fscache;/* client index cache cookie */ #endif
include/linux/sunrpc/svc.h +5 -0
@@ -298,6 +298,11 @@ static inline struct sockaddr *svc_addr(const struct svc_rqst *rqst)return (struct sockaddr *) &rqst->rq_addr; } +static inline struct sockaddr *svc_daddr (struct svc_rqst *rqst) +{ +return (struct sockaddr *) &rqst->rq_daddr; +} +/* * Check buffer bounds after decoding arguments */
Quoted 12 lines · Ben Greear
This patch lets one bind the local side of NFS sockets to a particular IP address. This can be useful for users on multi-homed systems.
This patch must be on top of the previous patch to fix the IPv6 address comparison or it will not work.
Comments and suggestions welcome...I'll incorporate those and post an official signed-off patch after that.
Thanks,
Ben
The code in nfs_callback_authenticate is going to break NFSv4 callbacks. Callbacks are sent to the -oclientaddr address, not srcaddr (btw, I really dislike that new boolean argument to nfs_find_client(). If you don't want to compare the source address, then have the caller pass a NULL pointer).
As has been pointed out to you before, all this is very intrusive, and you have yet to give a description of why it is useful, and better than using private socket namespaces (which is what container virtualised systems will be wanting). The latter can even ensure that it all works for userspace applications (such as rpc.statd) too.
IOW: I'd be quite happy to take patches to support private namespaces
properly: afaics, we do need to make nfs_find_client aware of them, and ditto for lockd and the NFSv4 callback channel.
I remain less than convinced that we need to be able to specify per-mountpoint source addresses...
Trond
Quoted 14 lines · Trond Myklebust
Quoted 12 lines · Ben Greear
This patch lets one bind the local side of NFS sockets to a particular IP address. This can be useful for users on multi-homed systems.
This patch must be on top of the previous patch to fix the IPv6 address comparison or it will not work.
Comments and suggestions welcome...I'll incorporate those and post an official signed-off patch after that.
Thanks,
Ben
Quoted 5 lines
The code in
nfs_callback_authenticateis going to break NFSv4 callbacks. Callbacks are sent to the -oclientaddr address, not srcaddr (btw, I really dislike that new boolean argument tonfs_find_client(). If you don't want to compare the source address, then have the caller pass a NULL pointer).
It would break things to have clientaddr different than srcaddr, but as long as they are the same (or either is not specified), I think my patch will be fine. I have tested NFS without specifying srcaddr and it seems to work fine, for instance.
I think if one were to pass a flag that said 'bind-to-clientaddr' that would also solve my needs, but I don't think it would make the patch much less intrusive.
I'm fine with getting rid of the boolean.
Quoted 5 lines
As has been pointed out to you before, all this is very intrusive, and you have yet to give a description of why it is useful, and better than using private socket namespaces (which is what container virtualised systems will be wanting). The latter can even ensure that it all works for userspace applications (such as rpc.statd) too.
Namespaces can be difficult to manage and relatively heavy weight, so they are no good for my use. This srcaddr patch is useful because it allows multiple mounts on different network adapters or IP addresses, (virtual or otherwise). My particular use for this is to do load testing on NFS servers, but I'm sure other folks with have other uses.
I really don't see how it's so intrusive. It does add some arguments to some methods, but the overall logic change is quite small.
It should be simple enough to fix rpc.statd to bind to IPs properly, but I haven't looked at that code.
Quoted 5 lines
IOW: I'd be quite happy to take patches to support private namespaces
properly: afaics, we do need to makenfs_find_clientaware of them, and ditto for lockd and the NFSv4 callback channel.
I remain less than convinced that we need to be able to specify per-mountpoint source addresses...
I got my hopes up because the cifs guys were interested in supporting srcaddr, so I thought maybe NFS folks were now of similar mind. If you still see no use in it, I'll wait a few more years and try again.
In the meantime, I'll fix the boolean issue and work to fix any other technical issues that come up.
Thanks,
Ben
Signature · 2 lines
Ben Greear <[email protected]> Candela Technologies Inc http://www.candelatech.com
Quoted 14 lines · Trond Myklebust
Quoted 12 lines · Ben Greear
This patch lets one bind the local side of NFS sockets to a particular IP address. This can be useful for users on multi-homed systems.
This patch must be on top of the previous patch to fix the IPv6 address comparison or it will not work.
Comments and suggestions welcome...I'll incorporate those and post an official signed-off patch after that.
Thanks,
Ben
Quoted 5 lines
The code in
nfs_callback_authenticateis going to break NFSv4 callbacks. Callbacks are sent to the -oclientaddr address, not srcaddr (btw, I really dislike that new boolean argument tonfs_find_client(). If you don't want to compare the source address, then have the caller pass a NULL pointer).
Would this fix the callback issue you speak of? The idea is to use source and dest to match if it exists, but if we find one where server address matches and srcaddr isn't specified, then we will use that.
@@ -384,10 +390,30 @@ struct nfs_client *nfs_find_client(const struct sockaddr *addr, u32 nfsversion)
if (!nfs_sockaddr_match_ipaddr(addr, clap))
continue;
+ if (srcaddr) {
+ const struct sockaddr *sa;
+ sa = (const struct sockaddr *)&clp->srcaddr;
+ 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(&nfs_client_lock);
return clp;
}+
+ if (ok_fit) {
+ clp = ok_fit;
+ goto found_one;
+ }
+
spin_unlock(&nfs_client_lock);
return NULL;}
Thanks,
Ben
Signature · 2 lines
Ben Greear <[email protected]> Candela Technologies Inc http://www.candelatech.com
Quoted 22 lines · Ben Greear
Quoted 14 lines · Trond Myklebust
Quoted 12 lines · Ben Greear
This patch lets one bind the local side of NFS sockets to a particular IP address. This can be useful for users on multi-homed systems.
This patch must be on top of the previous patch to fix the IPv6 address comparison or it will not work.
Comments and suggestions welcome...I'll incorporate those and post an official signed-off patch after that.
Thanks,
BenQuoted 5 lines
The code in
nfs_callback_authenticateis going to break NFSv4 callbacks. Callbacks are sent to the -oclientaddr address, not srcaddr (btw, I really dislike that new boolean argument tonfs_find_client(). If you don't want to compare the source address, then have the caller pass a NULL pointer).
Quoted 4 lines
Would this fix the callback issue you speak of? The idea is to use source and dest to match if it exists, but if we find one where server address matches and srcaddr isn't specified, then we will use that.
No. As I said, it needs to match the clientaddr argument, not the srcaddr.
The problem is that you are now potentially introducing cases where the server may have multiple combinations of clientaddr and srcaddr.
Quoted 36 lines
(quoted diff) +20
-0@@ -384,10 +390,30 @@ struct nfs_client *nfs_find_client(const struct sockaddr *addr, u32 nfsversion) if (!nfs_sockaddr_match_ipaddr(addr, clap)) continue; + if (srcaddr) { + const struct sockaddr *sa; + sa = (const struct sockaddr *)&clp->srcaddr; + 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(&nfs_client_lock); return clp; } + + if (ok_fit) { + clp = ok_fit; + goto found_one; + } + spin_unlock(&nfs_client_lock); return NULL; }Thanks,
Ben
Quoted 28 lines · Trond Myklebust
Quoted 22 lines · Ben Greear
Quoted 14 lines · Trond Myklebust
Quoted 12 lines · Ben Greear
This patch lets one bind the local side of NFS sockets to a particular IP address. This can be useful for users on multi-homed systems.
This patch must be on top of the previous patch to fix the IPv6 address comparison or it will not work.
Comments and suggestions welcome...I'll incorporate those and post an official signed-off patch after that.
Thanks,
BenQuoted 5 lines
The code in
nfs_callback_authenticateis going to break NFSv4 callbacks. Callbacks are sent to the -oclientaddr address, not srcaddr (btw, I really dislike that new boolean argument tonfs_find_client(). If you don't want to compare the source address, then have the caller pass a NULL pointer).Quoted 4 lines
Would this fix the callback issue you speak of? The idea is to use source and dest to match if it exists, but if we find one where server address matches and srcaddr isn't specified, then we will use that.
Quoted 5 lines
No. As I said, it needs to match the clientaddr argument, not the srcaddr.
The problem is that you are now potentially introducing cases where the server may have multiple combinations of clientaddr and srcaddr.
Ok, so what do you think about allowing a flag to bind() to clientaddr instead of having the separate srcaddr option?
Thanks,
Ben
Signature · 2 lines
Ben Greear <[email protected]> Candela Technologies Inc http://www.candelatech.com
Quoted 29 lines · Ben Greear
Quoted 28 lines · Trond Myklebust
Quoted 26 lines · Ben Greear
Quoted 14 lines · Trond Myklebust
Quoted 12 lines · Ben Greear
This patch lets one bind the local side of NFS sockets to a particular IP address. This can be useful for users on multi-homed systems.
This patch must be on top of the previous patch to fix the IPv6 address comparison or it will not work.
Comments and suggestions welcome...I'll incorporate those and post an official signed-off patch after that.
Thanks,
BenQuoted 5 lines
The code in
nfs_callback_authenticateis going to break NFSv4 callbacks. Callbacks are sent to the -oclientaddr address, not srcaddr (btw, I really dislike that new boolean argument tonfs_find_client(). If you don't want to compare the source address, then have the caller pass a NULL pointer).Would this fix the callback issue you speak of? The idea is to use source and dest to match if it exists, but if we find one where server address matches and srcaddr isn't specified, then we will use that.
Quoted 8 lines
Quoted 5 lines
No. As I said, it needs to match the clientaddr argument, not the srcaddr.
The problem is that you are now potentially introducing cases where the server may have multiple combinations of clientaddr and srcaddr.
Ok, so what do you think about allowing a flag to
bind()to clientaddr instead of having the separate srcaddr option?
That might be slightly less intrusive, but I'm still unconvinced it is something we need to support in the upstream kernels.
Cheers
Trond
Quoted 6 lines · Trond Myklebust
Quoted 5 lines · Ben Greear
Quoted 3 lines · Trond Myklebust
No. As I said, it needs to match the clientaddr argument, not the srcaddr.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
The problem is that you are now potentially introducing cases where the server may have multiple combinations of clientaddr and srcaddr.
Ok, so what do you think about allowing a flag to
bind()to clientaddr instead of having the separate srcaddr option?That might be slightly less intrusive, but I'm still unconvinced it is something we need to support in the upstream kernels.
It seems clientaddr is saved as a string instead of a struct sockaddr_storage, which means doing conversion in lots of places. So, using a bindclient flag and clientaddr would be even trickier than my srcaddr= approach.
I can still try to get that working if that's the only hurdle to upstream inclusion, but if it's all for my own use, I'm just going to use the same api as for cifs, and ensure the caller always uses same thing for srcaddr and clientaddr.
Thanks,
Ben
Signature · 2 lines
Ben Greear <[email protected]> Candela Technologies Inc http://www.candelatech.com