Subject: Re: bin/10986: mount_nfs doesn't fallback to IPv4
To: None <netbsd-bugs@netbsd.org>
From: Benedikt Meurer <bmeurer@fwdn.de>
List: netbsd-bugs
Date: 09/30/2002 18:53:31
Hello,

I did a small change to mount_nfs to get -4/-6 options to explicitly
select IPv4/IPv6 connections.

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 16:44:59
@@ -170,6 +170,8 @@
 int nfsproto = IPPROTO_UDP;
 int force2 = 0;
 int force3 = 0;
+int force4 = 0;
+int force6 = 0;
 int mnttcp_ok = 1;
 
 #ifdef NFSKERB
@@ -230,8 +232,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;
 
@@ -240,7 +241,7 @@
 	nfsargs = nfsdefargs;
 	nfsargsp = &nfsargs;
 	while ((c = getopt(argc, argv,
-	    "23a:bcCdD:g:I:iKL:lm:o:PpqR:r:sTt:w:x:UX")) != -1)
+	    "2346a:bcCdD:g:I:iKL:lm:o:PpqR:r:sTt:w:x:UX")) != -1)
 		switch (c) {
 		case '3':
 			if (force2)
@@ -253,6 +254,18 @@
 			force2 = 1;
 			nfsargsp->flags &= ~NFSMNT_NFSV3;
 			break;
+		case '4':
+			if (force6)
+				errx(1, "-4 and -6 are mutually exclusive");
+			force4 = 1;
+			nfsargsp->proto = IPPROTO_IPV4;
+			break;
+		case '6':
+			if (force4)
+				errx(1, "-4 and -6 are mutually exclusive");
+			force6 = 1;
+			nfsargsp->proto = IPPROTO_IPV6;
+			break;
 		case 'a':
 			num = strtol(optarg, &p, 10);
 			if (*p || num < 0)
@@ -674,6 +687,7 @@
 	memset(&hints, 0, sizeof hints);
 	hints.ai_flags = AI_NUMERICHOST;
 	hints.ai_socktype = nfsargsp->sotype;
+	hints.ai_protocol = nfsargsp->proto;
 	if (getaddrinfo(hostp, "nfs", &hints, &ai_nfs) == 0) {
 		if ((nfsargsp->flags & NFSMNT_KERB)) {
 			hints.ai_flags = 0;
@@ -907,7 +921,7 @@
 usage()
 {
 	(void)fprintf(stderr, "usage: mount_nfs %s\n%s\n%s\n%s\n%s\n",
-"[-23bcCdiKlpPqsTUX] [-a maxreadahead] [-D deadthresh]",
+"[-2346bcCdiKlpPqsTUX] [-a maxreadahead] [-D deadthresh]",
 "\t[-g maxgroups] [-I readdirsize] [-L leaseterm] [-m realm]",
 "\t[-o options] [-R retrycnt] [-r readsize] [-t timeout]",
 "\t[-w writesize] [-x retrans]",