Skip to contentSkip to conversation

NFS: Introduce "-4" and "-6" options to the mount.nfs command

PATCH New Chuck Lever 1 participant 1 message Feb 18, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 17/17 NFS: Introduce "-4" and "-6" options to the mount.nfs command

Add command line options to mount.nfs that allow it to prioritize DNS resolution results for a server with interfaces registered for both families.

Since this is a mount.nfs command line option and not something more visible at higher levels (like as a mount option), consider this feature useful mostly for testing.

---

 utils/mount/mount.c       |   15 ++++++++++++++-
 utils/mount/mount.nfs.man |    8 ++++++++
 utils/mount/stropts.c     |    3 ++-
 3 files changed, 24 insertions(+), 2 deletions(-)
utils/mount/mount.c +14 -1
index 33d8d30..eecf1ad 100644
@@ -54,6 +54,7 @@ int nomtab;
 int verbose;
 int sloppy;
 int string;
+int dnsfamily = AF_INET;
 
 #define FOREGROUND	(0)
 #define BACKGROUND	(1)
@@ -294,6 +295,10 @@ void mount_usage(void)
 	printf(_("\t-v\t\tVerbose\n"));
 	printf(_("\t-V\t\tPrint version\n"));
 	printf(_("\t-w\t\tMount file system read-write\n"));
+#if IPV6_SUPPORTED
+	printf(_("\t-4\t\tFavor IPv4 DNS resolution results\n"));
+	printf(_("\t-6\t\tFavor IPv6 DNS resolution results\n"));
+#endif
 	printf(_("\t-f\t\tFake mount, do not actually mount\n"));
 	printf(_("\t-n\t\tDo not update /etc/mtab\n"));
 	printf(_("\t-s\t\tTolerate sloppy mount options rather than fail\n"));
@@ -442,7 +447,7 @@ int main(int argc, char *argv[])
 	mount_point = argv[2];
 
 	argv[2] = argv[0]; /* so that getopt error messages are correct */
-	while ((c = getopt_long(argc - 2, argv + 2, "rvVwfno:hs",
+	while ((c = getopt_long(argc - 2, argv + 2, "rvVw46fno:hs",
 				longopts, NULL)) != -1) {
 		switch (c) {
 		case 'r':
@@ -457,6 +462,14 @@ int main(int argc, char *argv[])
 		case 'w':
 			flags &= ~MS_RDONLY;
 			break;
+#if IPV6_SUPPORTED
+		case '4':
+			dnsfamily = AF_INET;
+			break;
+		case '6':
+			dnsfamily = AF_INET6;
+			break;
+#endif
 		case 'f':
 			++fake;
 			break;
utils/mount/mount.nfs.man +8 -0
index 1a4561b..9526d9e 100644
@@ -39,6 +39,14 @@ Print version.
 .BI "\-w"
 Mount file system read-write.
 .TP
+.BI "\-4"
+If a server has both IPv4 and IPv6 interfaces,
+favor IPv4 results when resolving the server's hostname to an IP address.
+.TP
+.BI "\-6"
+If a server has both IPv4 and IPv6 interfaces,
+favor IPv6 results when resolving the server's hostname to an IP address.
+.TP
 .BI "\-f"
 Fake mount. Don't actually call the mount system call.
 .TP
utils/mount/stropts.c +2 -1
index caf13b1..eef9ebf 100644
@@ -71,6 +71,7 @@
 extern int nfs_mount_data_version;
 extern char *progname;
 extern int verbose;
+extern int dnsfamily;
 
 static int parse_devname(const char *spec, char **hostname)
 {
@@ -732,7 +733,7 @@ int nfsmount_string(const char *spec, const char *node, const char *type,
 
 	if (!parse_devname(spec, &hostname))
 		return retval;
-	if (nfs_name_to_address(hostname, AF_UNSPEC, saddr))
+	if (nfs_name_to_address(hostname, dnsfamily, saddr))
 		goto fail;
 
 	options = po_split(*extra_opts);