prevent autofs to try the wrong IP protocol
PATCH 1/1 prevent autofs to try the wrong IP protocol
[please CC me on replies, I'm not subscribed]
If the user configures an IPv6 protocol for nfs, autofs tries IPv4 too, and vice versa. The attached patch against autofs-5.1.1 prevents this.
The additional tries for the wrong IP protocol can be quite costly if e.g. an IPSec tunnel must be brought up.
Signature · 1 line
Andreas Steinmetz SPAMmers use [email protected]
include/replicated.h +1 -1
@@ -72,7 +72,7 @@ unsigned int, unsigned int, unsigned int);void free_host_list (struct host **);int parse_location (unsigned ,struct host **,const char *,unsigned int ); -int prune_host_list (unsigned ,struct host **,unsigned int ,int ); +int prune_host_list (unsigned ,struct host **,unsigned int ,int ,int );void dump_host_list (struct host *);#endif
modules/mount_nfs.c +15 -3
@@ -72,6 +72,7 @@int port =-1 ;int ro =0 ;/* Set if mount bind should be read-only */ int rdma =0 ; +int v4v6 =0 ;if (ap->flags &MOUNT_FLAG_REMOUNT )return 0 ;
@@ -164,12 +165,22 @@if (port <0 ) port =0 ; port_opt = cp; + }else if (_strncmp ("proto=udp6" , cp, o_len) ==0 || +_strncmp ("udp6" , cp, o_len) ==0 ) { + vers &= ~TCP_SUPPORTED ; + v4v6 =2 ; + }else if (_strncmp ("proto=tcp6" , cp, o_len) ==0 || +_strncmp ("tcp6" , cp, o_len) ==0 ) { + vers &= ~UDP_SUPPORTED ; + v4v6 =2 ; }else if (_strncmp ("proto=udp" , cp, o_len) ==0 ||_strncmp ("udp" , cp, o_len) ==0 ) { vers &= ~TCP_SUPPORTED ; + v4v6 =1 ; }else if (_strncmp ("proto=tcp" , cp, o_len) ==0 ||_strncmp ("tcp" , cp, o_len) ==0 ) { vers &= ~UDP_SUPPORTED ; + v4v6 =1 ; }/* Check for options that also make sense with bind mounts */
@@ -220,7 +231,8 @@if (tmp) { tmp->rr = hosts->rr;prune_host_list (ap->logopt, &tmp, -NFS4_VERS_MASK |TCP_SUPPORTED , port); +NFS4_VERS_MASK |TCP_SUPPORTED , port, + v4v6);/* If probe succeeds just try the mount with host in hosts */ if (tmp) { v4_probe_ok =1 ;
@@ -228,9 +240,9 @@ } }if (!v4_probe_ok) -prune_host_list (ap->logopt, &hosts, vers, port); +prune_host_list (ap->logopt, &hosts, vers, port, v4v6); }else { -prune_host_list (ap->logopt, &hosts, vers, port); +prune_host_list (ap->logopt, &hosts, vers, port, v4v6); } dont_probe:
modules/replicated.c +17 -4
@@ -653,7 +653,7 @@ }int prune_host_list (unsigned logopt,struct host **list, -unsigned int vers,int port) +unsigned int vers,int port,int v4v6) {struct host *this, *last, *first;struct host *new =NULL ;
@@ -710,7 +710,14 @@break ;if (this->name) { - status =get_vers_and_cost (logopt, this, vers, port); +if ((v4v6 ==2 && this->addr_len ==INET_ADDRSTRLEN ) || + (v4v6 ==1 && + this->addr_len ==INET6_ADDRSTRLEN )) { + status =0 ; + }else { + status =get_vers_and_cost (logopt, this, + vers, port); + }if (!status) {if (this == first) { first = next;
@@ -818,8 +825,14 @@remove_host (list, this);add_host (&new, this); }else { - status =get_supported_ver_and_cost (logopt, this, - selected_version, port); +if ((v4v6 ==2 && this->addr_len ==INET_ADDRSTRLEN ) || + (v4v6 ==1 && + this->addr_len ==INET6_ADDRSTRLEN )) { + status =0 ; + }else { + status =get_supported_ver_and_cost (logopt, + this, selected_version, port); + }if (status) { this->version = selected_version;remove_host (list, this);
Ian Kent
maintainerQuoted 9 lines · Andreas Steinmetz
[please CC me on replies, I'm not subscribed]
If the user configures an IPv6 protocol for nfs, autofs tries IPv4 too,
and vice versa. The attached patch against autofs-5.1.1 prevents this.The additional tries for the wrong IP protocol can be quite costly if e.g. an IPSec tunnel must be brought up.
I get what your trying to say and agree that it should be fixed but I wouldn't do it quite this way.
The method you have used is not in line with the way the code currently works so I'll need to have a look at it when I get some time.
For example, it would probably be better to define TCP6_SUPPORTED, and a corresponding define for UDP, and use that to determine which of UDP or TCP should be tried in the same way that TCP_SUPPORTED and UDP_SUPPORTED is used.
--
To unsubscribe from this list: send the line "unsubscribe autofs" in
Ian Kent
maintainerQuoted 9 lines · Andreas Steinmetz
[please CC me on replies, I'm not subscribed]
If the user configures an IPv6 protocol for nfs, autofs tries IPv4 too,
and vice versa. The attached patch against autofs-5.1.1 prevents this.The additional tries for the wrong IP protocol can be quite costly if e.g. an IPSec tunnel must be brought up.
Is this close to what your asking for (not even compile tested)?
I'm not certain this won't have any undesired side effects AFAICS it looks ok.
autofs-5.1.1 - fix ipv6 proto option handling
From: Ian Kent <[email protected]>
If the option proto=(tcp6|udp6) is given on the NFS mount command line autofs does not properly recognise it needs to probe only the given protocol for matching address type.
--- include/replicated.h | 2 ++ modules/mount_nfs.c | 15 ++++++++++++++- modules/replicated.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-)
include/replicated.h +2 -0
@@ -37,6 +37,8 @@#define UDP_SUPPORTED 0x0002#define TCP_REQUESTED TCP_SUPPORTED#define UDP_REQUESTED UDP_SUPPORTED +#define TCP6_REQUESTED 0x0100 +#define UDP6_REQUESTED 0x0200#define NFS_PROTO_MASK (TCP_SUPPORTED|UDP_SUPPORTED)#define NFS2_TCP_SUPPORTED NFS2_SUPPORTED
modules/mount_nfs.c +14 -1
@@ -172,9 +172,17 @@ int mount_mount(struct autofs_point *ap, const char *root, const char *name, int }else if (_strncmp ("proto=udp" , cp, o_len) ==0 ||_strncmp ("udp" , cp, o_len) ==0 ) { vers &= ~TCP_SUPPORTED ; + }else if (_strncmp ("proto=udp6" , cp, o_len) ==0 || +_strncmp ("udp6" , cp, o_len) ==0 ) { + vers &= ~TCP_SUPPORTED ; + vers |=UDP6_REQUESTED ; }else if (_strncmp ("proto=tcp" , cp, o_len) ==0 ||_strncmp ("tcp" , cp, o_len) ==0 ) { vers &= ~UDP_SUPPORTED ; + }else if (_strncmp ("proto=tcp6" , cp, o_len) ==0 || +_strncmp ("tcp6" , cp, o_len) ==0 ) { + vers &= ~UDP_SUPPORTED ; + vers |=TCP6_REQUESTED ; }/* Check for options that also make sense with bind mounts */
@@ -212,11 +220,16 @@ int mount_mount(struct autofs_point *ap, const char *root, const char *name, int* configuration only probe NFSv4 and let mount.nfs(8) do fallback * to NFSv3 (if it can). If the NFSv4 probe fails then probe as * normal. +* +* Note: some NFS servers consider it a protocol violation to use +* NFSv4 over UDP so if it has been requested in the mount options +* we can't use this at all. */ if ((hosts && !hosts->next) && mount_default_proto ==4 && (vers &NFS_VERS_MASK ) !=0 && - (vers &NFS4_VERS_MASK ) !=0 ) { + (vers &NFS4_VERS_MASK ) !=0 && + !(vers &UDP6_REQUESTED )) {unsigned int v4_probe_ok =0 ; struct host *tmp = new_host(hosts->name, hosts->addr, hosts->addr_len,
modules/replicated.c +29 -0
@@ -458,6 +458,29 @@ done_ver:return supported; } +static int check_address_proto (unsigned logopt, +struct host *host,unsigned int version) +{ +int ipv6_requested = version & (TCP6_REQUESTED |UDP6_REQUESTED ); +int ret =1 ; + +/* If a protocol has been explicitly requested then don't +* consider addresses that don't match the requested protocol. +*/ +if (version & ipv6_requested) { +if (host->addr_len ==INET_ADDRSTRLEN ) + ret =0 ; + }else { +if (host->addr_len ==INET6_ADDRSTRLEN ) + ret =0 ; + } + +if (!ret) +debug (logopt,"requested protocol does not match address" ); + +return ret; +} +static int get_vers_and_cost (unsigned logopt,struct host *host,unsigned int version,int port) {
@@ -466,6 +489,9 @@ static int get_vers_and_cost(unsigned logopt, struct host *host,unsigned int supported, vers = (NFS_VERS_MASK |NFS4_VERS_MASK );int ret =0 ; +if (check_address_proto (logopt, host, version)) +return 0 ; +memset (&pm_info,0 ,sizeof (struct conn_info ));memset (&rpc_info,0 ,sizeof (struct conn_info ));
@@ -535,6 +561,9 @@ static int get_supported_ver_and_cost(unsigned logopt, struct host *host,debug (logopt,"called with host %s version 0x%x" , host->name, version); +if (check_address_proto (logopt, host, version)) +return 0 ; +memset (&pm_info,0 ,sizeof (struct conn_info ));memset (&rpc_info,0 ,sizeof (struct conn_info ));
--
To unsubscribe from this list: send the line "unsubscribe autofs" in
Ian Kent
maintainerReview
Quoted 11 lines · Ian Kent
(quoted diff) +10
-0+static int check_address_proto(unsigned logopt, +> > > > struct host *host, unsigned int version) +{ +> > int ipv6_requested = version & (TCP6_REQUESTED | UDP6_REQUESTED); +> > int ret = 1; + +> > /* If a protocol has been explicitly requested then don't +> > * consider addresses that don't match the requested protocol. +> > */ +> > if (version & ipv6_requested) {
Umm .. I think this should just be:
if (ipv6_requested) {
Review
Quoted 13 lines
(quoted diff) +13
-0+ if (host->addr_len == INET_ADDRSTRLEN) +> > > > ret = 0; +> > } else { +> > > if (host->addr_len == INET6_ADDRSTRLEN) +> > > > ret = 0; +> > } + +> > if (!ret) +> > > debug(logopt, "requested protocol does not match address"); + +> > return ret; +} +
--
To unsubscribe from this list: send the line "unsubscribe autofs" in
Quoted 12 lines · Ian Kent
Quoted 10 lines · Andreas Steinmetz
[please CC me on replies, I'm not subscribed]
If the user configures an IPv6 protocol for nfs, autofs tries IPv4 too,
and vice versa. The attached patch against autofs-5.1.1 prevents this.The additional tries for the wrong IP protocol can be quite costly if
e.g. an IPSec tunnel must be brought up.
Quoted 7 lines
Is this close to what your asking for (not even compile tested)?
I'm not certain this won't have any undesired side effects AFAICS it looks ok.
autofs-5.1.1 - fix ipv6 proto option handling
Well, I had to fix up your patch slightly to work, at least for my IPv6 use cases. Except for the fact that there are now new version bits in use which do hopefully not cause any unwanted side effects it now seems ok to me. Modified patch of yours is attached.
Signature · 1 line
Andreas Steinmetz SPAMmers use [email protected]
include/replicated.h +3 -0
@@ -37,7 +37,10 @@#define UDP_SUPPORTED 0x0002#define TCP_REQUESTED TCP_SUPPORTED#define UDP_REQUESTED UDP_SUPPORTED +#define TCP6_REQUESTED 0x0100 +#define UDP6_REQUESTED 0x0200#define NFS_PROTO_MASK (TCP_SUPPORTED|UDP_SUPPORTED) +#define NFS_IPV6_MASK (TCP6_REQUESTED|UDP6_REQUESTED)#define NFS2_TCP_SUPPORTED NFS2_SUPPORTED#define NFS3_TCP_SUPPORTED NFS3_SUPPORTED
modules/mount_nfs.c +14 -1
@@ -167,9 +167,17 @@ int mount_mount(struct autofs_point *ap, }else if (_strncmp ("proto=udp" , cp, o_len) ==0 ||_strncmp ("udp" , cp, o_len) ==0 ) { vers &= ~TCP_SUPPORTED ; + }else if (_strncmp ("proto=udp6" , cp, o_len) ==0 || +_strncmp ("udp6" , cp, o_len) ==0 ) { + vers &= ~TCP_SUPPORTED ; + vers |=UDP6_REQUESTED ; }else if (_strncmp ("proto=tcp" , cp, o_len) ==0 ||_strncmp ("tcp" , cp, o_len) ==0 ) { vers &= ~UDP_SUPPORTED ; + }else if (_strncmp ("proto=tcp6" , cp, o_len) ==0 || +_strncmp ("tcp6" , cp, o_len) ==0 ) { + vers &= ~UDP_SUPPORTED ; + vers |=TCP6_REQUESTED ; }/* Check for options that also make sense with bind mounts */
@@ -207,11 +215,16 @@ int mount_mount(struct autofs_point *ap,* configuration only probe NFSv4 and let mount.nfs(8) do fallback * to NFSv3 (if it can). If the NFSv4 probe fails then probe as * normal. +* +* Note: some NFS servers consider it a protocol violation to use +* NFSv4 over UDP so if it has been requested in the mount options +* we can't use this at all. */ if ((hosts && !hosts->next) && mount_default_proto ==4 && (vers &NFS_VERS_MASK ) !=0 && - (vers &NFS4_VERS_MASK ) !=0 ) { + (vers &NFS4_VERS_MASK ) !=0 && + !(vers &UDP6_REQUESTED )) {unsigned int v4_probe_ok =0 ; struct host *tmp = new_host(hosts->name, hosts->addr, hosts->addr_len,
modules/replicated.c +36 -1
@@ -459,6 +459,32 @@ done_ver:return supported; } +static int check_address_proto (unsigned logopt, +struct host *host,unsigned int version) +{ +int ipv6_requested = version &NFS_IPV6_MASK ; +int ret =1 ; +socklen_t len =INET6_ADDRSTRLEN ; +char buf[len +1 ]; + +/* If a protocol has been explicitly requested then don't +* consider addresses that don't match the requested protocol. +*/ +if (ipv6_requested) { +if (host->addr_len ==INET_ADDRSTRLEN ) + ret =0 ; + }else { +if (host->addr_len ==INET6_ADDRSTRLEN ) + ret =0 ; + } + +if (!ret) +debug (logopt,"requested protocol does not match host %s(%s)" , + host->name,get_addr_string (host->addr, buf, len)); + +return ret; +} +static int get_vers_and_cost (unsigned logopt,struct host *host,unsigned int version,int port) {
@@ -467,6 +493,9 @@ static int get_vers_and_cost(unsigned lounsigned int supported, vers = (NFS_VERS_MASK |NFS4_VERS_MASK );int ret =0 ; +if (!check_address_proto (logopt, host, version)) +return 0 ; +memset (&pm_info,0 ,sizeof (struct conn_info ));memset (&rpc_info,0 ,sizeof (struct conn_info ));
@@ -529,6 +558,11 @@ static int get_supported_ver_and_cost(untime_t timeout =RPC_TIMEOUT ;int status =0 ; +if (!check_address_proto (logopt, host, version)) +return 0 ; + + version &= ~NFS_IPV6_MASK ; +if (host->addr) debug(logopt, "called with host %s(%s) version 0x%x", host->name, get_addr_string(host->addr, buf, len),
@@ -819,7 +853,8 @@ int prune_host_list(unsigned logopt, stradd_host (&new, this); }else { status =get_supported_ver_and_cost (logopt, this, - selected_version, port); + selected_version | (vers &NFS_IPV6_MASK ), + port);if (status) { this->version = selected_version;remove_host (list, this);
Ian Kent
maintainerQuoted 24 lines · Andreas Steinmetz
Quoted 14 lines · Ian Kent
Quoted 8 lines · Andreas Steinmetz
[please CC me on replies, I'm not subscribed]
If the user configures an IPv6 protocol for nfs, autofs tries IPv4
too,
and vice versa. The attached patch against autofs-5.1.1 prevents this.Quoted 4 lines
The additional tries for the wrong IP protocol can be quite costly
if
e.g. an IPSec tunnel must be brought up.Quoted 8 lines
Is this close to what your asking for (not even compile tested)?
I'm not certain this won't have any undesired side effects AFAICS it
looks ok.autofs-5.1.1 - fix ipv6 proto option handling
Quoted 6 lines
Well, I had to fix up your patch slightly to work, at least for my IPv6
use cases. Except for the fact that there are now new version bits in use which do hopefully not cause any unwanted side effects it now seems
ok to me. Modified patch of yours is attached.
OK, thanks, I'll have a look at the changes and integrate them.
I think all accesses to the bit fields are bitwise or should be anyway, I'll have a look around to see if I can see any that could be a problem.
Quoted 1 line
--
To unsubscribe from this list: send the line "unsubscribe autofs" in