Subject: Re: bin/10986: mount_nfs doesn't fallback to IPv4
To: Andrew Brown <atatat@atatdot.net>
From: Benedikt Meurer <bmeurer@fwdn.de>
List: netbsd-bugs
Date: 10/01/2002 00:40:37
The following patch should work fine, also with NFSv4 (-4 ;-). I had
mixed up protocol family with protocol in my first patch :-(. I have
setup a FreeBSD nfsd for testing now, and as I can say, it works, when
using -o ipv4 to force the mount to use IPv4, even if there's an AAAA
record for the host. Maybe someone with a better knowledge of IPv4/IPv6
could have a look at the patch now.

HTH, Benedikt

Index: mount_nfs.c
===================================================================
RCS file: /cvsroot/basesrc/sbin/mount_nfs/mount_nfs.c,v
retrieving revision 1.34
diff -u -r1.34 mount_nfs.c
--- mount_nfs.c	2002/09/21 18:43:36	1.34
+++ mount_nfs.c	2002/09/30 22:31:57
@@ -107,6 +107,8 @@
 #define ALTF_SOFT	0x800
 #define ALTF_TCP	0x1000
 #define ALTF_NFSV2	0x2000
+#define ALTF_IPV4	0x4000
+#define ALTF_IPV6	0x8000
 
 static const struct mntopt mopts[] = {
 	MOPT_STDOPTS,
@@ -131,6 +133,8 @@
 	{ "soft", 0, ALTF_SOFT, 1 },
 	{ "tcp", 0, ALTF_TCP, 1 },
 	{ "nfsv2", 0, ALTF_NFSV2, 1 },
+	{ "ipv4", 0, ALTF_IPV4, 1 },
+	{ "ipv6", 0, ALTF_IPV6, 1 },
 	{ NULL }
 };
 
@@ -170,6 +174,7 @@
 int nfsproto = IPPROTO_UDP;
 int force2 = 0;
 int force3 = 0;
+int forcefamily = -1;
 int mnttcp_ok = 1;
 
 #ifdef NFSKERB
@@ -230,8 +235,7 @@
 	    sizeof (struct nfsrpc_fullblock) != RPCX_FULLBLOCK ||
 	    ((char *)&ktick.kt) - ((char *)&ktick) != NFSX_UNSIGNED ||
 	    ((char *)ktick.kt.dat) - ((char *)&ktick) != 2 * NFSX_UNSIGNED)
-		fprintf(stderr, "Yikes! NFSKERB structs not packed!!\n");
-
+		warnx ("Yikes! NFSKERB structs not packed!!");
 #endif
 	retrycnt = DEF_RETRY;
 
@@ -345,6 +349,16 @@
 				force2 = 1;
 				nfsargsp->flags &= ~NFSMNT_NFSV3;
 			}
+			if((altflags & ALTF_IPV4) &&
+			    (altflags & ALTF_IPV6)) {
+				errx(1,"ipv4 and ipv6 are mutually exclusive");
+			}
+			else if (altflags & ALTF_IPV4) {
+				forcefamily = PF_INET;
+			}
+			else if(altflags & ALTF_IPV6) {
+				forcefamily = PF_INET6;
+			}
 			if(altflags & ALTF_RDIRPLUS)
 				nfsargsp->flags |= NFSMNT_RDIRPLUS;
 			if(altflags & ALTF_MNTUDP)
@@ -674,6 +688,8 @@
 	memset(&hints, 0, sizeof hints);
 	hints.ai_flags = AI_NUMERICHOST;
 	hints.ai_socktype = nfsargsp->sotype;
+	if (forcefamily > 0)
+		hints.ai_family = forcefamily;
 	if (getaddrinfo(hostp, "nfs", &hints, &ai_nfs) == 0) {
 		if ((nfsargsp->flags & NFSMNT_KERB)) {
 			hints.ai_flags = 0;