public inbox for linux-nfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mount.nfs: prefer IPv4 addresses over IPv6 (try #2)
@ 2010-01-19 13:27 Jeff Layton
  2010-01-19 15:43 ` Chuck Lever
  2010-01-23 12:54 ` NFS/IPv6 servers on GNU/Linux? Ivan Shmakov
  0 siblings, 2 replies; 17+ messages in thread
From: Jeff Layton @ 2010-01-19 13:27 UTC (permalink / raw)
  To: linux-nfs; +Cc: chuck.lever, steved, trond.myklebust

We're poised to enable IPv6 in nfs-utils in distros. There is a
potential problem however. mount.nfs will prefer IPv6 addrs.

If someone has a working IPv4 server today that has an IPv6 address,
then clients may start trying to mount over that address. If the server
doesn't support NFS serving over IPv6 (and virtually no linux servers
currently do), then the mount will start failing.

Avoid this problem by making the mount code prefer IPv4 addresses
when they are available and an address family isn't specified.

This is the second attempt at this patch. This moves the changes
into nfs_validate_options. Chuck also mentioned parameterizing this
behavior too. This patch doesn't include that, as I wasn't exactly
clear on what he had in mind.

Signed-off-by: Jeff Layton <jlayton@redhat.com>
---
 utils/mount/stropts.c |   32 +++++++++++++++++++++++++-------
 1 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/utils/mount/stropts.c b/utils/mount/stropts.c
index 57a4b32..f0937a2 100644
--- a/utils/mount/stropts.c
+++ b/utils/mount/stropts.c
@@ -326,6 +326,29 @@ static int nfs_set_version(struct nfsmount_info *mi)
 	return 1;
 }
 
+static int nfs_addr_option_lookup(struct nfsmount_info *mi)
+{
+	struct sockaddr *sap = &mi->address.sa;
+	sa_family_t family;
+
+	if (!nfs_nfs_proto_family(mi->options, &family))
+		return 0;
+
+	mi->salen = sizeof(mi->address);
+
+#ifdef IPV6_SUPPORTED
+	/*
+	 * A lot of servers don't support NFS over IPv6 yet. For now,
+	 * IPv4 addresses are preferred.
+	 */
+	if (family == AF_UNSPEC &&
+	    nfs_lookup(mi->hostname, AF_INET, sap, &mi->salen))
+		return 1;
+#endif /* IPV6_SUPPORTED */
+
+	return nfs_lookup(mi->hostname, family, sap, &mi->salen);
+}
+
 /*
  * Set up mandatory non-version specific NFS mount options.
  *
@@ -333,16 +356,11 @@ static int nfs_set_version(struct nfsmount_info *mi)
  */
 static int nfs_validate_options(struct nfsmount_info *mi)
 {
-	struct sockaddr *sap = &mi->address.sa;
-	sa_family_t family;
 
 	if (!nfs_parse_devname(mi->spec, &mi->hostname, NULL))
 		return 0;
 
-	if (!nfs_nfs_proto_family(mi->options, &family))
-		return 0;
-	mi->salen = sizeof(mi->address);
-	if (!nfs_lookup(mi->hostname, family, sap, &mi->salen))
+	if (!nfs_addr_option_lookup(mi))
 		return 0;
 
 	if (!nfs_set_version(mi))
@@ -351,7 +369,7 @@ static int nfs_validate_options(struct nfsmount_info *mi)
 	if (!nfs_append_sloppy_option(mi->options))
 		return 0;
 
-	if (!nfs_append_addr_option(sap, mi->salen, mi->options))
+	if (!nfs_append_addr_option(&mi->address.sa, mi->salen, mi->options))
 		return 0;
 
 	return 1;
-- 
1.6.5.2


^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2010-01-23 14:30 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-01-19 13:27 [PATCH] mount.nfs: prefer IPv4 addresses over IPv6 (try #2) Jeff Layton
2010-01-19 15:43 ` Chuck Lever
2010-01-19 20:38   ` Jeff Layton
     [not found]     ` <20100119153826.67dd97a5-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org>
2010-01-19 20:51       ` Trond Myklebust
2010-01-19 21:06         ` Chuck Lever
2010-01-20 13:13         ` Jeff Layton
2010-01-20 13:29   ` Jeff Layton
2010-01-20 15:36     ` Chuck Lever
2010-01-20 16:34       ` Jeff Layton
     [not found]         ` <20100120113422.6071bfbd-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org>
2010-01-20 19:09           ` Chuck Lever
2010-01-21 19:15       ` J. Bruce Fields
2010-01-21 19:37         ` Chuck Lever
2010-01-21 19:57           ` J. Bruce Fields
2010-01-21 20:28             ` Chuck Lever
2010-01-21 21:52               ` J. Bruce Fields
2010-01-23 12:54 ` NFS/IPv6 servers on GNU/Linux? Ivan Shmakov
     [not found]   ` <87y6jp56cw.fsf-Hr8DDCuc/255On46OghOUKxOck334EZe@public.gmane.org>
2010-01-23 14:30     ` Jeff Layton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox