public inbox for linux-nfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Jeff Layton <jlayton@redhat.com>
To: linux-nfs@vger.kernel.org
Cc: chuck.lever@oracle.com, steved@redhat.com, trond.myklebust@fys.uio.no
Subject: [PATCH] mount.nfs: prefer IPv4 addresses over IPv6 (try #2)
Date: Tue, 19 Jan 2010 08:27:42 -0500	[thread overview]
Message-ID: <1263907662-19107-1-git-send-email-jlayton@redhat.com> (raw)

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


             reply	other threads:[~2010-01-19 13:27 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-19 13:27 Jeff Layton [this message]
2010-01-19 15:43 ` [PATCH] mount.nfs: prefer IPv4 addresses over IPv6 (try #2) 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1263907662-19107-1-git-send-email-jlayton@redhat.com \
    --to=jlayton@redhat.com \
    --cc=chuck.lever@oracle.com \
    --cc=linux-nfs@vger.kernel.org \
    --cc=steved@redhat.com \
    --cc=trond.myklebust@fys.uio.no \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox