Skip to contentSkip to conversation

Support for mounting NFSv4 servers over IPv6

PATCH In review Chuck Lever 2 participants 16 messages Jul 11, 2008 – Jul 15, 2008 1 message not in the archive

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

PATCH 1/14 nfs-utils: Introduce new ./configure option: "--enable-ipv6"

In reply to a message not in the archive

We want to continue to support building nfs-utils on systems that do not have IPv6-enabled RPC libraries and headers installed, so add a ./configure switch that allows distros to disable IPv6 functionality.

This patch introduces the nfs-utils autotools configuration to the library and header dependencies that will be required in subsequent patches. Later patches can then be reordered more easily if these new dependencies are added in one heap.

For now, --enable-ipv6 defaults to "no", so this patch should not result in any behavioral changes to the nfs-utils build process, by default.

---

 configure.ac |   29 ++++++++++++++++++++++++++++-
 1 files changed, 28 insertions(+), 1 deletions(-)
configure.ac +28 -1
index d508c28..e6bcb62 100644
@@ -127,6 +127,18 @@ AC_ARG_ENABLE(mount,
 	enable_mount=$enableval,
 	enable_mount=yes)
 	AM_CONDITIONAL(CONFIG_MOUNT, [test "$enable_mount" = "yes"])
+AC_ARG_ENABLE(ipv6,
+	[AC_HELP_STRING([--enable-ipv6],
+                        [enable support for IPv6 @<:@default=no@:>@])],
+	enable_ipv6=$enableval,
+	enable_ipv6=no)
+	if test "$enable_ipv6" = yes; then
+		AC_DEFINE(IPV6_SUPPORTED, 1, [Define this if you want IPv6 support compiled in])
+	else
+		enable_ipv6=
+	fi
+	AC_SUBST(enable_ipv6)
+	AM_CONDITIONAL(CONFIG_IPV6, [test "$enable_ipv6" = "yes"])
 
 # Check whether user wants TCP wrappers support
 AC_TCP_WRAPPERS
@@ -237,6 +249,17 @@ if test "$enable_gss" = yes; then
 
 fi
 
+if test "$enable_ipv6" = yes; then
+  AC_CHECK_FUNC(inet_ntop, , ,
+               AC_MSG_ERROR(Function 'inet_ntop' not found.))
+  AC_CHECK_FUNC(getnameinfo, , ,
+               AC_MSG_ERROR(Function 'getnameinfo' not found.))
+  AC_CHECK_LIB(tirpc, clnt_tli_create, ,
+               AC_MSG_ERROR([libtirpc needed for IPv6 support]))
+  AC_CHECK_HEADERS(tirpc/netconfig.h, ,
+               AC_MSG_ERROR([libtirpc-devel needed for IPv6 support]))
+fi
+
 dnl *************************************************************
 dnl Check for headers
 dnl *************************************************************
@@ -245,7 +268,7 @@ AC_CHECK_HEADERS([arpa/inet.h fcntl.h libintl.h limits.h \
                  stdlib.h string.h sys/file.h sys/ioctl.h sys/mount.h \
                  sys/param.h sys/socket.h sys/time.h sys/vfs.h \
                  syslog.h unistd.h com_err.h et/com_err.h \
-                 ifaddrs.h])
+                 ifaddrs.h tirpc/netconfig.h])
 
 dnl *************************************************************
 dnl Checks for typedefs, structures, and compiler characteristics
@@ -281,6 +304,10 @@ AC_FUNC_STAT
 AC_FUNC_VPRINTF
 AC_CHECK_FUNCS([alarm atexit dup2 fdatasync ftruncate getcwd \
                gethostbyaddr gethostbyname gethostname getmntent \
+               inet_ntop getnameinfo getrpcbyname \
+               bindresvport_sa getnetconfig \
+               clnt_create clnt_create_timed \
+               clnt_tli_create clnt_vc_create clnt_dg_create xdr_rpcb \
                gettimeofday hasmntopt inet_ntoa innetgr memset mkdir pathconf \
                realpath rmdir select socket strcasecmp strchr strdup \
                strerror strrchr strtol strtoul sigprocmask])
#4 lore raw

PATCH 3/14 mount command: Add functions to manage addresses in string form

In reply to a message not in the archive

Introduce two new functions to convert a sockaddr to a presentation format string and back.

---

 utils/mount/network.c |   92 +++++++++++++++++++++++++++++++++++++++++++++++++
 utils/mount/network.h |    4 ++
 2 files changed, 96 insertions(+), 0 deletions(-)
utils/mount/network.c +92 -0
index c9fd548..3f2721b 100644
@@ -215,6 +215,98 @@ int nfs_gethostbyname(const char *hostname, struct sockaddr_in *sin)
 					(struct sockaddr *)sin, &len);
 }
 
+/**
+ * nfs_string_to_sockaddr - convert string address to sockaddr
+ * @address:	pointer to presentation format address to convert
+ * @addrlen:	length of presentation address
+ * @sap:	pointer to socket address buffer to fill in
+ * @salen:	IN: length of address buffer
+ *		OUT: length of converted socket address
+ *
+ * Convert a presentation format address string to a socket address.
+ * Similar to nfs_name_to_address(), but the DNS query is squelched,
+ * and won't make any noise if the getaddrinfo() call fails.
+ *
+ * Returns 1 and fills in @sap and @salen if successful; otherwise zero.
+ *
+ * See RFC 4038 section 5.1 or RFC 3513 section 2.2 for more details
+ * on presenting IPv6 addresses as text strings.
+ */
+int nfs_string_to_sockaddr(const char *address, const size_t addrlen,
+			   struct sockaddr *sap, socklen_t *salen)
+{
+	struct addrinfo *gai_results;
+	struct addrinfo gai_hint = {
+		.ai_flags	= AI_NUMERICHOST,
+	};
+	socklen_t len = *salen;
+	int ret = 0;
+
+	*salen = 0;
+
+	if (getaddrinfo(address, NULL, &gai_hint, &gai_results) == 0) {
+		switch (gai_results->ai_addr->sa_family) {
+		case AF_INET:
+		case AF_INET6:
+			if (len >= gai_results->ai_addrlen) {
+				*salen = gai_results->ai_addrlen;
+				memcpy(sap, gai_results->ai_addr, *salen);
+				ret = 1;
+			}
+			break;
+		}
+		freeaddrinfo(gai_results);
+	}
+
+	return ret;
+}
+
+/**
+ * nfs_present_sockaddr - convert sockaddr to string
+ * @sap: pointer to socket address to convert
+ * @salen: length of socket address
+ * @buf: pointer to buffer to fill in
+ * @buflen: length of buffer
+ *
+ * Convert the passed-in sockaddr-style address to presentation format.
+ * The presentation format address is placed in @buf and is
+ * '\0'-terminated.
+ *
+ * Returns 1 if successful; otherwise zero.
+ *
+ * See RFC 4038 section 5.1 or RFC 3513 section 2.2 for more details
+ * on presenting IPv6 addresses as text strings.
+ */
+int nfs_present_sockaddr(const struct sockaddr *sap, const socklen_t salen,
+			 char *buf, const size_t buflen)
+{
+#ifdef HAVE_GETNAMEINFO
+	int result;
+
+	result = getnameinfo(sap, salen, buf, buflen,
+					NULL, 0, NI_NUMERICHOST);
+	if (!result)
+		return 1;
+
+	nfs_error(_("%s: invalid server address: %s"), progname,
+			gai_strerror(result));
+	return 0;
+#else	/* HAVE_GETNAMEINFO */
+	char *addr;
+
+	if (sap->sa_family == AF_INET) {
+		addr = inet_ntoa(((struct sockaddr_in *)sap)->sin_addr);
+		if (addr && strlen(addr) < buflen) {
+			strcpy(buf, addr);
+			return 1;
+		}
+	}
+
+	nfs_error(_("%s: invalid server address"), progname);
+	return 0;
+#endif	/* HAVE_GETNAMEINFO */
+}
+
 /*
  * Attempt to connect a socket, but time out after "timeout" seconds.
  *
utils/mount/network.h +4 -0
index 9de13b5..8da7e20 100644
@@ -53,6 +53,10 @@ int probe_bothports(clnt_addr_t *, clnt_addr_t *);
 int nfs_gethostbyname(const char *, struct sockaddr_in *);
 int nfs_name_to_address(const char *, const sa_family_t,
 		struct sockaddr *, socklen_t *);
+int nfs_string_to_sockaddr(const char *, const size_t,
+			   struct sockaddr *, socklen_t *);
+int nfs_present_sockaddr(const struct sockaddr *,
+			 const socklen_t, char *, const size_t);
 int get_client_address(struct sockaddr_in *, struct sockaddr_in *);
 int nfs_call_umount(clnt_addr_t *, dirpath *);
 int clnt_ping(struct sockaddr_in *, const unsigned long,
#8 lore raw

PATCH 7/14 text-based mount command: "clientaddr=" option support for IPv6 addresses

In reply to a message not in the archive

Change the append_clientaddr_option() function to support sending either IPv4 or IPv6 addresses to the kernel via the "clientaddr=" option.

If the mount.nfs4 command can't determine an appropriate callback address, it used to fail the mount request. This new function simply sends an ANY address instead, so the mount request succeeds, but delegation is disabled.

---

 utils/mount/stropts.c |   26 ++++++++++++--------------
 1 files changed, 12 insertions(+), 14 deletions(-)
utils/mount/stropts.c +12 -14
index f856998..ff51652 100644
@@ -252,24 +252,21 @@ static int nfs_append_addr_option(const struct sockaddr *sap,
  * Returns 1 if 'clientaddr=' option created successfully or if
  * 'clientaddr=' option is already present; otherwise zero.
  */
-static int append_clientaddr_option(struct sockaddr_in *saddr,
-				    struct mount_options *options)
+static int nfs_append_clientaddr_option(const struct sockaddr *sap,
+					socklen_t salen,
+					struct mount_options *options)
 {
-	struct sockaddr_in my_addr;
-	char new_option[32];
+	struct sockaddr_storage dummy;
+	struct sockaddr *my_addr = (struct sockaddr *)&dummy;
+	socklen_t my_len = sizeof(dummy);
 
-	if (po_contains(options, "clientaddr") == PO_SUCCEEDED)
+	if (po_contains(options, "clientaddr") == PO_FOUND)
 		return 1;
 
-	if (!get_client_address(saddr, &my_addr))
-		return 0;
-
-	snprintf(new_option, sizeof(new_option) - 1,
-			"clientaddr=%s", inet_ntoa(my_addr.sin_addr));
+	nfs_callback_address(sap, salen, my_addr, &my_len);
 
-	if (po_append(options, new_option) == PO_SUCCEEDED)
-		return 1;
-	return 0;
+	return nfs_append_generic_address_option(my_addr, my_len,
+							"clientaddr", options);
 }
 
 /*
@@ -339,7 +336,8 @@ static int nfs_validate_options(struct nfsmount_info *mi)
 		return 0;
 
 	if (strncmp(mi->type, "nfs4", 4) == 0) {
-		if (!append_clientaddr_option(&saddr, mi->options))
+		if (!nfs_append_clientaddr_option((struct sockaddr *)&saddr,
+						  sizeof(saddr), mi->options))
 			return 0;
 	} else {
 		if (!fix_mounthost_option(mi->options))
#5 lore raw

PATCH 4/14 text-based mount command: get_client_address support for IPv6

In reply to a message not in the archive

Introduce IPv6-enabled version of get_client_address. The legacy mount command could use this eventually as well.

If this new function fails to discover an appropriate callback address, it fills in an ANY address to indicate to the server that it should not call the client back (ie delegations are disabled in this case).

The user can specify a callback address via the clientaddr= mount option in this case to enable delegation.

---

 utils/mount/network.c |  118 +++++++++++++++++++++++++++++++++++++++++++++++++
 utils/mount/network.h |    2 +
 2 files changed, 120 insertions(+), 0 deletions(-)
utils/mount/network.c +118 -0
index 3f2721b..849ce1d 100644
@@ -918,3 +918,121 @@ int get_client_address(struct sockaddr_in *saddr, struct sockaddr_in *caddr)
 	}
 	return 1;
 }
+
+/*
+ * Try a getsockname() on a connected datagram socket.
+ *
+ * Returns 1 and fills in @buf if successful; otherwise, zero.
+ *
+ * A connected datagram socket prevents leaving a socket in TIME_WAIT.
+ * This conserves the ephemeral port number space, helping reduce failed
+ * socket binds during mount storms.
+ */
+static int nfs_ca_sockname(const struct sockaddr *sap, const socklen_t salen,
+			   struct sockaddr *buf, socklen_t *buflen)
+{
+	struct sockaddr_in sin = {
+		.sin_family		= AF_INET,
+		.sin_addr.s_addr	= htonl(INADDR_ANY),
+	};
+	struct sockaddr_in6 sin6 = {
+		.sin6_family		= AF_INET6,
+		.sin6_addr		= IN6ADDR_ANY_INIT,
+	};
+	int sock;
+
+	sock = socket(sap->sa_family, SOCK_DGRAM, IPPROTO_UDP);
+	if (sock < 0)
+		return 0;
+
+	switch (sap->sa_family) {
+	case AF_INET:
+		if (bind(sock, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
+			close(sock);
+			return 0;
+		}
+		break;
+	case AF_INET6:
+		if (bind(sock, (struct sockaddr *)&sin6, sizeof(sin6)) < 0) {
+			close(sock);
+			return 0;
+		}
+		break;
+	default:
+		errno = EAFNOSUPPORT;
+		return 0;
+	}
+
+	if (connect(sock, sap, salen) < 0) {
+		close(sock);
+		return 0;
+	}
+
+	return !getsockname(sock, buf, buflen);
+}
+
+/*
+ * Try to generate an address that prevents the server from calling us.
+ *
+ * Returns 1 and fills in @buf if successful; otherwise, zero.
+ */
+static int nfs_ca_gai(const struct sockaddr *sap, const socklen_t salen,
+		      struct sockaddr *buf, socklen_t *buflen)
+{
+	struct addrinfo *gai_results;
+	struct addrinfo gai_hint = {
+		.ai_family	= sap->sa_family,
+		.ai_flags	= AI_PASSIVE,	/* ANYADDR */
+	};
+
+	if (getaddrinfo(NULL, "", &gai_hint, &gai_results))
+		return 0;
+
+	*buflen = gai_results->ai_addrlen;
+	memcpy(buf, gai_results->ai_addr, *buflen);
+
+	freeaddrinfo(gai_results);
+
+	return 1;
+}
+
+/**
+ * nfs_callback_address - acquire our local network address
+ * @sap: pointer to address of remote
+ * @sap_len: length of address
+ * @buf: pointer to buffer to be filled in with local network address
+ * @buflen: IN: length of buffer to fill in; OUT: length of filled-in address
+ *
+ * Discover a network address that an NFSv4 server can use to call us back.
+ * On multi-homed clients, this address depends on which NIC we use to
+ * route requests to the server.
+ *
+ * Returns 1 and fills in @buf if an unambiguous local address is
+ * available; returns 1 and fills in an appropriate ANYADDR address
+ * if a local address isn't available; otherwise, returns zero.
+ */
+int nfs_callback_address(const struct sockaddr *sap, const socklen_t salen,
+			 struct sockaddr *buf, socklen_t *buflen)
+{
+	struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)buf;
+
+	if (nfs_ca_sockname(sap, salen, buf, buflen) == 0)
+		if (nfs_ca_gai(sap, salen, buf, buflen) == 0)
+			goto out_failed;
+
+	/*
+	 * The server can't use an interface ID that was generated
+	 * here on the client, so always clear sin6_scope_id.
+	 */
+	if (sin6->sin6_family == AF_INET6)
+		sin6->sin6_scope_id = 0;
+
+	return 1;
+
+out_failed:
+	*buflen = 0;
+	if (verbose)
+		nfs_error(_("%s: failed to construct callback address"));
+	return 0;
+
+}
utils/mount/network.h +2 -0
index 8da7e20..2f4ff3a 100644
@@ -58,6 +58,8 @@ int nfs_string_to_sockaddr(const char *, const size_t,
 int nfs_present_sockaddr(const struct sockaddr *,
 			 const socklen_t, char *, const size_t);
 int get_client_address(struct sockaddr_in *, struct sockaddr_in *);
+int nfs_callback_address(const struct sockaddr *, const socklen_t,
+		struct sockaddr *, socklen_t *);
 int nfs_call_umount(clnt_addr_t *, dirpath *);
 int clnt_ping(struct sockaddr_in *, const unsigned long,
 		const unsigned long, const unsigned int,
#11 lore raw

PATCH 10/14 text-based mount command: Support raw IPv6 address hostnames

In reply to a message not in the archive

Traditionally the mount command has looked for a ":" to separate the server's hostname from the export path in the mounted on device name, like this:

mount server:/export /mounted/on/dir

The server's hostname is "server" and the export path is "/export".

You can also substitute a specific IPv4 network address for the server hostname, like this:

	mount 192.168.0.55:/export /mounted/on/dir

Raw IPv6 addresses present a problem, however, because they look something like this:

	fe80::200:5aff:fe00:30b

Note the use of colons.

To get around the presence of colons, copy the Solaris convention used for raw NFS server IPv6 addresses, which is to wrap the raw IPv6 address with square brackets. This is also suggested in RFC 4038.

Introduce a new device name parser that can support traditional device names and square brackets. Place the parser in a separate source file so both the mount and umount paths can derive the server's hostname and export pathname the same way.

Bonus points: add a check for NFS URLs and display an appropriate error message in that case. This is cleaner than failing with "unknown host:
nfs".

---

 utils/mount/Makefile.am |    6 +
 utils/mount/nfsumount.c |   35 +++----
 utils/mount/parse_dev.c |  230 +++++++++++++++++++++++++++++++++++++++++++++++
 utils/mount/parse_dev.h |   28 ++++++
 utils/mount/stropts.c   |   59 +-----------
 5 files changed, 282 insertions(+), 76 deletions(-)
 create mode 100644 utils/mount/parse_dev.c
 create mode 100644 utils/mount/parse_dev.h
utils/mount/Makefile.am +4 -2
index 5a94631..459fa45 100644
@@ -9,10 +9,12 @@ man5_MANS	= nfs.man
 
 sbin_PROGRAMS	= mount.nfs
 EXTRA_DIST = nfsmount.x $(man8_MANS) $(man5_MANS)
-mount_nfs_SOURCES = mount.c error.c network.c fstab.c token.c parse_opt.c \
+mount_nfs_SOURCES = mount.c error.c network.c fstab.c token.c \
+		    parse_opt.c parse_dev.c \
 		    nfsmount.c nfs4mount.c stropts.c\
 		    nfsumount.c \
-		    mount_constants.h error.h network.h fstab.h token.h parse_opt.h \
+		    mount_constants.h error.h network.h fstab.h token.h \
+		    parse_opt.h parse_dev.h \
 		    nfs4_mount.h nfs_mount4.h stropts.h version.h
 
 mount_nfs_LDADD = ../../support/nfs/libnfs.a \
utils/mount/nfsumount.c +16 -19
index 285273b..67e9c4b 100644
@@ -34,6 +34,7 @@
 #include "mount.h"
 #include "error.h"
 #include "network.h"
+#include "parse_dev.h"
 
 #if !defined(MNT_FORCE)
 /* dare not try to include <linux/mount.h> -- lots of errors */
@@ -150,21 +151,11 @@ static int do_nfs_umount23(const char *spec, char *opts)
 	struct mntent mnt = { .mnt_opts = opts };
 	struct pmap *pmap = &mnt_server.pmap;
 	char *p;
+	int result = EX_USAGE;
+
+	if (!nfs_parse_devname(spec, &hostname, &dirname))
+		return result;
 
-	if (spec == NULL) {
-		nfs_error(_("%s: No NFS export name was provided"),
-				progname);
-		return EX_USAGE;
-	}
-	
-	p = strchr(spec, ':');
-	if (p == NULL) {
-		nfs_error(_("%s: '%s' is not a legal NFS export name"),
-				progname, spec);
-		return EX_USAGE;
-	}
-	hostname = xstrndup(spec, p - spec);
-	dirname = xstrdup(p + 1);
 #ifdef NFS_MOUNT_DEBUG
 	printf(_("host: %s, directory: %s\n"), hostname, dirname);
 #endif
@@ -209,18 +200,24 @@ static int do_nfs_umount23(const char *spec, char *opts)
 		pmap->pm_prot = IPPROTO_TCP;
 
 	if (!nfs_gethostbyname(hostname, &mnt_server.saddr)) {
-		nfs_error(_("%s: '%s' does not contain a recognized hostname"),
-				progname, spec);
-		return EX_USAGE;
+		nfs_error(_("%s: DNS resolution of '%s' failed"),
+				progname, hostname);
+		goto out;
 	}
 
 	if (!nfs_call_umount(&mnt_server, &dirname)) {
 		nfs_error(_("%s: Server failed to unmount '%s'"),
 				progname, spec);
-		return EX_USAGE;
+		result = EX_FAIL;
+		goto out;
 	}
 
-	return EX_SUCCESS;
+	result = EX_SUCCESS;
+
+out:
+	free(hostname);
+	free(dirname);
+	return result;
 }
 
 static struct option umount_longopts[] =
utils/mount/parse_dev.c new file +230 -0

230 lines not on this page · raw message

utils/mount/parse_dev.h new file +28 -0
new file mode 100644
index 0000000..a1288c2
@@ -0,0 +1,28 @@
+/*
+ * parse_dev.c -- parse device name into hostname and export path
+ *
+ * Copyright (C) 2008 Oracle.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 021110-1307, USA.
+ *
+ */
+
+#ifndef __NFS_UTILS_PARSE_DEV_HEADER
+#define __NFS_UTILS_PARSE_DEV_HEADER
+
+extern int	nfs_parse_devname(const char *, char **, char **);
+
+#endif	/* __NFS_UTILS_PARSE_DEV */
utils/mount/stropts.c +4 -55

83 lines not on this page · raw message

#7 lore raw

PATCH 6/14 text-based mount command: "addr=" option support for IPv6 addresses

In reply to a message not in the archive

Change the append_addr_option() function to support sending either IPv4 or IPv6 addresses to the kernel via the "addr=" option.

---

 utils/mount/stropts.c |   21 ++++++---------------
 1 files changed, 6 insertions(+), 15 deletions(-)
utils/mount/stropts.c +6 -15
index a1ffca2..f856998 100644
@@ -237,19 +237,12 @@ out_err:
  * Returns 1 if 'addr=' option appended successfully;
  * otherwise zero.
  */
-static int append_addr_option(struct sockaddr_in *saddr,
-			   struct mount_options *options)
+static int nfs_append_addr_option(const struct sockaddr *sap,
+				  socklen_t salen,
+				  struct mount_options *options)
 {
-	char new_option[24];
-
 	po_remove_all(options, "addr");
-
-	snprintf(new_option, sizeof(new_option) - 1,
-			"addr=%s", inet_ntoa(saddr->sin_addr));
-
-	if (po_append(options, new_option) == PO_SUCCEEDED)
-		return 1;
-	return 0;
+	return nfs_append_generic_address_option(sap, salen, "addr", options);
 }
 
 /*
@@ -358,10 +351,8 @@ static int nfs_validate_options(struct nfsmount_info *mi)
 	if (!nfs_append_sloppy_option(mi->options))
 		return 0;
 
-	if (!append_addr_option(&saddr, mi->options))
-		return 0;
-
-	return 1;
+	return nfs_append_addr_option((struct sockaddr *)&saddr,
+					sizeof(saddr), mi->options);
 }
 
 /*
#13 lore raw

PATCH 12/14 text-based mount options: rename functions in stropts.c

In reply to a message not in the archive

Clean up: rename a couple of functions in utils/mount/stropts.c to match the naming convention of the others.

---

 utils/mount/stropts.c |   18 +++++++++---------
 1 files changed, 9 insertions(+), 9 deletions(-)
utils/mount/stropts.c +9 -9
index a51cf0b..b54df40 100644
@@ -230,7 +230,7 @@ static int nfs_fix_mounthost_option(const sa_family_t family,
  * Returns zero if the "lock" option is in effect, but statd
  * can't be started.  Otherwise, returns 1.
  */
-static int verify_lock_option(struct mount_options *options)
+static int nfs_verify_lock_option(struct mount_options *options)
 {
 	if (po_rightmost(options, "nolock", "lock") == PO_KEY1_RIGHTMOST)
 		return 1;
@@ -279,7 +279,7 @@ static int nfs_validate_options(struct nfsmount_info *mi)
 	} else {
 		if (!nfs_fix_mounthost_option(mi->family, mi->options))
 			return 0;
-		if (!mi->fake && !verify_lock_option(mi->options))
+		if (!mi->fake && !nfs_verify_lock_option(mi->options))
 			return 0;
 	}
 
@@ -297,7 +297,7 @@ static int nfs_validate_options(struct nfsmount_info *mi)
  * passed-in error is permanent, thus the mount system call
  * should not be retried.
  */
-static int is_permanent_error(int error)
+static int nfs_is_permanent_error(int error)
 {
 	switch (error) {
 	case ESTALE:
@@ -316,13 +316,13 @@ static int is_permanent_error(int error)
  *
  * To handle version and transport protocol fallback properly, we
  * need to parse some of the mount options in order to set up a
- * portmap probe.  Mount options that rewrite_mount_options()
+ * portmap probe.  Mount options that nfs_rewrite_mount_options()
  * doesn't recognize are left alone.
  *
  * Returns a new group of mount options if successful; otherwise
  * NULL is returned if some failure occurred.
  */
-static struct mount_options *rewrite_mount_options(char *str)
+static struct mount_options *nfs_rewrite_mount_options(char *str)
 {
 	struct mount_options *options;
 	char *option, new_option[64];
@@ -475,7 +475,7 @@ static int nfs_retry_nfs23mount(struct nfsmount_info *mi)
 	char *retry_str = NULL;
 	char **extra_opts = mi->extra_opts;
 
-	retry_options = rewrite_mount_options(*extra_opts);
+	retry_options = nfs_rewrite_mount_options(*extra_opts);
 	if (!retry_options)
 		return 0;
 
@@ -604,7 +604,7 @@ static int nfsmount_fg(struct nfsmount_info *mi)
 		if (nfs_try_mount(mi))
 			return EX_SUCCESS;
 
-		if (is_permanent_error(errno))
+		if (nfs_is_permanent_error(errno))
 			break;
 
 		if (time(NULL) > timeout) {
@@ -637,7 +637,7 @@ static int nfsmount_parent(struct nfsmount_info *mi)
 	if (nfs_try_mount(mi))
 		return EX_SUCCESS;
 
-	if (is_permanent_error(errno)) {
+	if (nfs_is_permanent_error(errno)) {
 		mount_error(mi->spec, mi->node, errno);
 		return EX_FAIL;
 	}
@@ -672,7 +672,7 @@ static int nfsmount_child(struct nfsmount_info *mi)
 		if (nfs_try_mount(mi))
 			return EX_SUCCESS;
 
-		if (is_permanent_error(errno))
+		if (nfs_is_permanent_error(errno))
 			break;
 
 		if (time(NULL) > timeout)
#14 lore raw

PATCH 13/14 text-based mount command: remove unnecessary headers from stropts.c

In reply to a message not in the archive

Clean up: remove unneeded headers from utils/mount/stropts.c.

---

 utils/mount/stropts.c |   14 +++-----------
 1 files changed, 3 insertions(+), 11 deletions(-)
utils/mount/stropts.c +3 -11
index b54df40..e4a4408 100644
@@ -25,11 +25,7 @@
 #include <config.h>
 #endif
 
-#include <ctype.h>
 #include <unistd.h>
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
 #include <errno.h>
 #include <netdb.h>
 #include <time.h>
@@ -42,7 +38,6 @@
 #include "xcommon.h"
 #include "mount.h"
 #include "nls.h"
-#include "nfs_mount.h"
 #include "mount_constants.h"
 #include "stropts.h"
 #include "error.h"
@@ -51,15 +46,12 @@
 #include "version.h"
 #include "parse_dev.h"
 
-#ifdef HAVE_RPCSVC_NFS_PROT_H
-#include <rpcsvc/nfs_prot.h>
-#else
-#include <linux/nfs.h>
-#define nfsstat nfs_stat
+#ifndef NFS_PROGRAM
+#define NFS_PROGRAM	(100003)
 #endif
 
 #ifndef NFS_PORT
-#define NFS_PORT 2049
+#define NFS_PORT	(2049)
 #endif
 
 #ifndef NFS_MAXHOSTNAME
#15 lore raw

PATCH 14/14 mount command: Remove RPC headers from network.h

In reply to a message not in the archive

Clean up: Include the bare minimum of legacy RPC headers in utils/mount/network.h.

---

 utils/mount/error.c     |    2 --
 utils/mount/mount.c     |    1 -
 utils/mount/network.c   |   11 -----------
 utils/mount/network.h   |   10 ----------
 utils/mount/nfs4mount.c |    2 ++
 utils/mount/nfsmount.c  |    7 +++++++
 6 files changed, 9 insertions(+), 24 deletions(-)
utils/mount/error.c +0 -2
index 5fd5705..5c9d3f2 100644
@@ -35,8 +35,6 @@
 #include <fcntl.h>
 #include <syslog.h>
 #include <rpc/rpc.h>
-#include <rpc/pmap_prot.h>
-#include <rpc/pmap_clnt.h>
 
 #include "xcommon.h"
 #include "nls.h"
utils/mount/mount.c +0 -1
index a7d5733..a806c7a 100644
@@ -44,7 +44,6 @@
 #include "nfs4_mount.h"
 #include "mount.h"
 #include "error.h"
-#include "network.h"
 #include "stropts.h"
 #include "version.h"
 
utils/mount/network.c +0 -11
index d8e6e10..7d3d09a 100644
@@ -48,17 +48,6 @@
 #include "mount_constants.h"
 #include "network.h"
 
-#ifdef HAVE_RPCSVC_NFS_PROT_H
-#include <rpcsvc/nfs_prot.h>
-#else
-#include <linux/nfs.h>
-#define nfsstat nfs_stat
-#endif
-
-#ifndef NFS_PORT
-#define NFS_PORT 2049
-#endif
-
 #define PMAP_TIMEOUT	(10)
 #define CONNECT_TIMEOUT	(20)
 #define MOUNT_TIMEOUT	(30)
utils/mount/network.h +0 -10
index 544ac93..a4dba1b 100644
@@ -25,16 +25,6 @@
 #define _NFS_UTILS_MOUNT_NETWORK_H
 
 #include <rpc/pmap_prot.h>
-#include <rpc/clnt.h>
-
-#include "mount.h"
-
-#ifdef HAVE_RPCSVC_NFS_PROT_H
-#include <rpcsvc/nfs_prot.h>
-#else
-#include <linux/nfs.h>
-#define nfsstat nfs_stat
-#endif
 
 #define MNT_SENDBUFSIZE (2048U)
 #define MNT_RECVBUFSIZE (1024U)
utils/mount/nfs4mount.c +2 -0
index 2b0fe2e..a2f318f 100644
@@ -34,6 +34,7 @@
 #include <arpa/inet.h>
 #include <rpc/auth.h>
 #include <rpc/rpc.h>
+
 #ifdef HAVE_RPCSVC_NFS_PROT_H
 #include <rpcsvc/nfs_prot.h>
 #else
@@ -45,6 +46,7 @@
 #include "nls.h"
 #include "xcommon.h"
 
+#include "mount.h"
 #include "mount_constants.h"
 #include "nfs4_mount.h"
 #include "nfs_mount.h"
utils/mount/nfsmount.c +7 -0
index b343a1f..6355681 100644
@@ -69,6 +69,13 @@
 #include "network.h"
 #include "version.h"
 
+#ifdef HAVE_RPCSVC_NFS_PROT_H
+#include <rpcsvc/nfs_prot.h>
+#else
+#include <linux/nfs.h>
+#define nfsstat nfs_stat
+#endif
+
 #ifndef NFS_PORT
 #define NFS_PORT 2049
 #endif
#9 lore raw

PATCH 8/14 text-based mount command: "mounthost=" option support for IPv6 addresses

In reply to a message not in the archive

Change the fix_mounthost_option() function to support resolving IPv6 addresses.

---

 utils/mount/stropts.c |   33 +++++++++++++++++++++------------
 1 files changed, 21 insertions(+), 12 deletions(-)
utils/mount/stropts.c +21 -12
index ff51652..e2e72a7 100644
@@ -94,6 +94,8 @@ struct nfsmount_info {
 	int			flags,		/* MS_ flags */
 				fake,		/* actually do the mount? */
 				child;		/* forked bg child? */
+
+	sa_family_t		family;		/* supported address family */
 };
 
 static int nfs_parse_devname(struct nfsmount_info *mi)
@@ -271,26 +273,28 @@ static int nfs_append_clientaddr_option(const struct sockaddr *sap,
 
 /*
  * Resolve the 'mounthost=' hostname and append a new option using
- * the resulting IPv4 address.
+ * the resulting address.
  */
-static int fix_mounthost_option(struct mount_options *options)
+static int nfs_fix_mounthost_option(const sa_family_t family,
+				    struct mount_options *options)
 {
-	struct sockaddr_in maddr;
-	char *mounthost, new_option[32];
+	struct sockaddr_storage dummy;
+	struct sockaddr *sap = (struct sockaddr *)&dummy;
+	socklen_t salen = sizeof(dummy);
+	char *mounthost;
 
 	mounthost = po_get(options, "mounthost");
 	if (!mounthost)
 		return 1;
 
-	if (!fill_ipv4_sockaddr(mounthost, &maddr))
+	if (!nfs_name_to_address(mounthost, family, sap, &salen)) {
+		nfs_error(_("%s: unable to determine mount server's address"),
+				progname);
 		return 0;
+	}
 
-	snprintf(new_option, sizeof(new_option) - 1,
-			"mountaddr=%s", inet_ntoa(maddr.sin_addr));
-
-	if (po_append(options, new_option) == PO_SUCCEEDED)
-		return 1;
-	return 0;
+	return nfs_append_generic_address_option(sap, salen,
+							"mountaddr", options);
 }
 
 /*
@@ -340,7 +344,7 @@ static int nfs_validate_options(struct nfsmount_info *mi)
 						  sizeof(saddr), mi->options))
 			return 0;
 	} else {
-		if (!fix_mounthost_option(mi->options))
+		if (!nfs_fix_mounthost_option(mi->family, mi->options))
 			return 0;
 		if (!mi->fake && !verify_lock_option(mi->options))
 			return 0;
@@ -800,6 +804,11 @@ int nfsmount_string(const char *spec, const char *node, const char *type,
 		.flags		= flags,
 		.fake		= fake,
 		.child		= child,
+#ifdef IPV6_SUPPORTED
+		.family		= AF_UNSPEC,	/* either IPv4 or v6 */
+#else
+		.family		= AF_INET,	/* only IPv4 */
+#endif
 	};
 	int retval = EX_FAIL;
 
#6 lore raw

PATCH 5/14 text-based mount command: Add helper to construct network addresses

In reply to a message not in the archive

There are three helpers that convert sockaddr-style addresses to text addresses, then construct mount options to pass these addresses to the kernel. The tail of each of these helpers does exactly the same thing, so introduce a helper that handles the common code.

Magically, the new helper supports IPv6 as well as IPv4.

---

 utils/mount/stropts.c |   31 +++++++++++++++++++++++++++++++
 1 files changed, 31 insertions(+), 0 deletions(-)
utils/mount/stropts.c +31 -0
index a9c0b50..a1ffca2 100644
@@ -195,6 +195,37 @@ static time_t nfs_parse_retry_option(struct mount_options *options,
 }
 
 /*
+ * Convert the passed-in sockaddr-style address to presentation
+ * format, then append an option of the form "keyword=address".
+ *
+ * Returns 1 if the option was appended successfully; otherwise zero.
+ */
+static int nfs_append_generic_address_option(const struct sockaddr *sap,
+					     const socklen_t salen,
+					     const char *keyword,
+					     struct mount_options *options)
+{
+	char address[NI_MAXHOST];
+	char new_option[512];
+
+	if (!nfs_present_sockaddr(sap, salen, address, sizeof(address)))
+		goto out_err;
+
+	if (snprintf(new_option, sizeof(new_option), "%s=%s",
+					keyword, address) >= sizeof(new_option))
+		goto out_err;
+
+	if (po_append(options, new_option) != PO_SUCCEEDED)
+		goto out_err;
+
+	return 1;
+
+out_err:
+	nfs_error(_("%s: failed to construct %s option"), progname, keyword);
+	return 0;
+}
+
+/*
  * Append the 'addr=' option to the options string to pass a resolved
  * server address to the kernel.  After a successful mount, this address
  * is also added to /etc/mtab for use when unmounting.
#12 lore raw

PATCH 11/14 text-based mount command: Remove unused IPv4-only functions

In reply to a message not in the archive

Clean up: remove unused IPv4-only functions used by the text-based mount command.

---

 utils/mount/network.c |   33 ---------------------------------
 utils/mount/network.h |    1 -
 utils/mount/stropts.c |   20 --------------------
 3 files changed, 0 insertions(+), 54 deletions(-)
utils/mount/network.c +0 -33
index 849ce1d..d8e6e10 100644
@@ -886,39 +886,6 @@ int clnt_ping(struct sockaddr_in *saddr, const unsigned long prog,
 		return 0;
 }
 
-/**
- * get_client_address - acquire our local network address
- * @saddr: server's address
- * @caddr: filled in with our network address
- *
- * Discover a network address that the server will use to call us back.
- * On multi-homed clients, this address depends on which NIC we use to
- * route requests to the server.
- *
- * Use a connected datagram socket so as not to leave a socket in TIME_WAIT.
- *
- * Returns one if successful, otherwise zero.
- */
-int get_client_address(struct sockaddr_in *saddr, struct sockaddr_in *caddr)
-{
-	socklen_t len = sizeof(*caddr);
-	int socket, err;
-
-	socket = get_socket(saddr, IPPROTO_UDP, CONNECT_TIMEOUT, FALSE, TRUE);
-	if (socket == RPC_ANYSOCK)
-		return 0;
-
-	err = getsockname(socket, caddr, &len);
-	close(socket);
-
-	if (err && verbose) {
-		nfs_error(_("%s: getsockname failed: %s"),
-				progname, strerror(errno));
-		return 0;
-	}
-	return 1;
-}
-
 /*
  * Try a getsockname() on a connected datagram socket.
  *
utils/mount/network.h +0 -1
index 2f4ff3a..544ac93 100644
@@ -57,7 +57,6 @@ int nfs_string_to_sockaddr(const char *, const size_t,
 			   struct sockaddr *, socklen_t *);
 int nfs_present_sockaddr(const struct sockaddr *,
 			 const socklen_t, char *, const size_t);
-int get_client_address(struct sockaddr_in *, struct sockaddr_in *);
 int nfs_callback_address(const struct sockaddr *, const socklen_t,
 		struct sockaddr *, socklen_t *);
 int nfs_call_umount(clnt_addr_t *, dirpath *);
utils/mount/stropts.c +0 -20
index c4f2326..a51cf0b 100644
@@ -99,26 +99,6 @@ struct nfsmount_info {
 	sa_family_t		family;		/* supported address family */
 };
 
-static int fill_ipv4_sockaddr(const char *hostname, struct sockaddr_in *addr)
-{
-	struct hostent *hp;
-	addr->sin_family = AF_INET;
-
-	if (inet_aton(hostname, &addr->sin_addr))
-		return 1;
-	if ((hp = gethostbyname(hostname)) == NULL) {
-		nfs_error(_("%s: can't get address for %s\n"),
-				progname, hostname);
-		return 0;
-	}
-	if (hp->h_length > sizeof(struct in_addr)) {
-		nfs_error(_("%s: got bad hp->h_length"), progname);
-		hp->h_length = sizeof(struct in_addr);
-	}
-	memcpy(&addr->sin_addr, hp->h_addr, hp->h_length);
-	return 1;
-}
-
 /*
  * Obtain a retry timeout value based on the value of the "retry=" option.
  *
#10 lore raw

PATCH 9/14 text-based mount command: Add IPv6 support to set_mandatory_options

In reply to a message not in the archive

---

 utils/mount/stropts.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)
utils/mount/stropts.c +6 -6
index e2e72a7..caa2c25 100644
@@ -334,14 +334,15 @@ static int nfs_append_sloppy_option(struct mount_options *options)
  */
 static int nfs_validate_options(struct nfsmount_info *mi)
 {
-	struct sockaddr_in saddr;
+	struct sockaddr_storage dummy;
+	struct sockaddr *sap = (struct sockaddr *)&dummy;
+	socklen_t salen = sizeof(dummy);
 
-	if (!fill_ipv4_sockaddr(mi->hostname, &saddr))
+	if (!nfs_name_to_address(mi->hostname, mi->family, sap, &salen))
 		return 0;
 
 	if (strncmp(mi->type, "nfs4", 4) == 0) {
-		if (!nfs_append_clientaddr_option((struct sockaddr *)&saddr,
-						  sizeof(saddr), mi->options))
+		if (!nfs_append_clientaddr_option(sap, salen, mi->options))
 			return 0;
 	} else {
 		if (!nfs_fix_mounthost_option(mi->family, mi->options))
@@ -353,8 +354,7 @@ static int nfs_validate_options(struct nfsmount_info *mi)
 	if (!nfs_append_sloppy_option(mi->options))
 		return 0;
 
-	return nfs_append_addr_option((struct sockaddr *)&saddr,
-					sizeof(saddr), mi->options);
+	return nfs_append_addr_option(sap, salen, mi->options);
 }
 
 /*
#0 lore raw

cover Support for mounting NFSv4 servers over IPv6

Hi Steve-

Here is the latest version of the patches that add support to the text- based mount.nfs command for mounting NFSv4 servers over IPv6. This set replaces the set I sent a couple of days ago.

It was suggested that these be included in the next release of nfs-utils, 1.1.3. Kernel support for these features (such as handling raw IPv6 NFS server addresses properly when mounting) is planned for 2.6.27, so inclusion of these patches would allow wider testing during .27's rc period.

Mounting NFSv2/v3 servers over IPv6 is more complex. It requires support for a scalable rpcbind/portmap client built into nfs-utils, thus it is not included in the present patch series. Anyone interested in looking at my current prototype for this can check out:

http://git.linux-nfs.org/?p=cel/nfs-utils.git;a=summary

It includes all the patches in this series and the patches I posted last week for nfs-utils 1.1.3, client-side support for NFSv2/v3 mounting and unmounting over IPv6, a prototype IPv6-enabled sm-notify command, and updates to nfs(5) describing IPv6 support for the NFS client.

For what it's worth, I'll be on holiday next week, but I can field any questions or comments before this Saturday, or when I return.

---

Chuck Lever (14):
mount command: Remove RPC headers from network.h
text-based mount command: remove unnecessary headers from stropts.c text-based mount options: rename functions in stropts.c text-based mount command: Remove unused IPv4-only functions text-based mount command: Support raw IPv6 address hostnames text-based mount command: Add IPv6 support to set_mandatory_options text-based mount command: "mounthost=" option support for IPv6 addresses text-based mount command: "clientaddr=" option support for IPv6 addresses text-based mount command: "addr=" option support for IPv6 addresses text-based mount command: Add helper to construct network addresses text-based mount command: get_client_address support for IPv6 mount command: Add functions to manage addresses in string form text-based mount command: Add headers needed for IPv6 support
nfs-utils: Introduce new ./configure option: "--enable-ipv6"

 configure.ac            |   29 ++++++
 utils/mount/Makefile.am |    6 +
 utils/mount/error.c     |    2 
 utils/mount/mount.c     |    1 
 utils/mount/network.c   |  237 +++++++++++++++++++++++++++++++++++++++++------
 utils/mount/network.h   |   17 +--
 utils/mount/nfs4mount.c |    2 
 utils/mount/nfsmount.c  |    7 +
 utils/mount/nfsumount.c |   35 +++----
 utils/mount/parse_dev.c |  230 ++++++++++++++++++++++++++++++++++++++++++++++
 utils/mount/parse_dev.h |   28 ++++++
 utils/mount/stropts.c   |  229 ++++++++++++++++++---------------------------
 12 files changed, 617 insertions(+), 206 deletions(-)
 create mode 100644 utils/mount/parse_dev.c
 create mode 100644 utils/mount/parse_dev.h
Signature · 4 lines
Signature

-- 
corporate:    <chuck dot lever at oracle dot com>
#3 lore raw

PATCH 2/14 text-based mount command: Add headers needed for IPv6 support

In reply to a message not in the archive

Add #include directives for additional header files needed to support IPv6 networking. This is a separate patch so subsequent
patches can be reordered without collision.

---

 utils/mount/network.c |    5 ++++-
 utils/mount/stropts.c |    3 +++
 2 files changed, 7 insertions(+), 1 deletions(-)
utils/mount/network.c +4 -1
index 30a4d40..c9fd548 100644
@@ -33,10 +33,13 @@
 #include <errno.h>
 #include <netdb.h>
 #include <time.h>
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
 #include <rpc/rpc.h>
 #include <rpc/pmap_prot.h>
 #include <rpc/pmap_clnt.h>
-#include <sys/socket.h>
 
 #include "xcommon.h"
 #include "mount.h"
utils/mount/stropts.c +3 -0
index 34b4134..a9c0b50 100644
@@ -33,8 +33,11 @@
 #include <errno.h>
 #include <netdb.h>
 #include <time.h>
+
 #include <sys/socket.h>
 #include <sys/mount.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
 
 #include "xcommon.h"
 #include "mount.h"
#16 lore raw
In reply to a message not in the archive
Quoted 28 lines · Chuck Lever

Hi Steve-

Here is the latest version of the patches that add support to the text- based mount.nfs command for mounting NFSv4 servers over IPv6. This set replaces the set I sent a couple of days ago.

It was suggested that these be included in the next release of nfs-utils, 1.1.3. Kernel support for these features (such as handling raw IPv6 NFS server addresses properly when mounting) is planned for 2.6.27, so inclusion of these patches would allow wider testing during .27's rc period.

Mounting NFSv2/v3 servers over IPv6 is more complex. It requires support for a scalable rpcbind/portmap client built into nfs-utils, thus it is not included in the present patch series. Anyone interested in looking at my current prototype for this can check out:

http://git.linux-nfs.org/?p=cel/nfs-utils.git;a=summary

It includes all the patches in this series and the patches I posted last week for nfs-utils 1.1.3, client-side support for NFSv2/v3 mounting and unmounting over IPv6, a prototype IPv6-enabled sm-notify command, and updates to nfs(5) describing IPv6 support for the NFS client.

For what it's worth, I'll be on holiday next week, but I can field any questions or comments before this Saturday, or when I return.

---

Quoted 16 lines

Chuck Lever (14):
mount command: Remove RPC headers from network.h
text-based mount command: remove unnecessary headers from stropts.c text-based mount options: rename functions in stropts.c text-based mount command: Remove unused IPv4-only functions text-based mount command: Support raw IPv6 address hostnames text-based mount command: Add IPv6 support to set_mandatory_options text-based mount command: "mounthost=" option support for IPv6 addresses text-based mount command: "clientaddr=" option support for IPv6 addresses text-based mount command: "addr=" option support for IPv6 addresses text-based mount command: Add helper to construct network addresses text-based mount command: get_client_address support for IPv6 mount command: Add functions to manage addresses in string form text-based mount command: Add headers needed for IPv6 support
nfs-utils: Introduce new ./configure option: "--enable-ipv6"

All 14 patches have been committed...

steved.