Blame SOURCES/nfs-utils-1.3.0-mount-restore-econn.patch

64c563
diff --git a/utils/mount/network.c b/utils/mount/network.c
64c563
index 751f9b8..b2e4374 100644
64c563
--- a/utils/mount/network.c
64c563
+++ b/utils/mount/network.c
64c563
@@ -33,11 +33,13 @@
64c563
 #include <errno.h>
64c563
 #include <netdb.h>
64c563
 #include <time.h>
64c563
+#include <grp.h>
64c563
 
64c563
 #include <sys/types.h>
64c563
 #include <sys/socket.h>
64c563
 #include <sys/wait.h>
64c563
 #include <sys/stat.h>
64c563
+#include <linux/in6.h>
64c563
 #include <netinet/in.h>
64c563
 #include <rpc/rpc.h>
64c563
 #include <rpc/pmap_prot.h>
64c563
@@ -802,6 +804,7 @@ int start_statd(void)
64c563
 			pid_t pid = fork();
64c563
 			switch (pid) {
64c563
 			case 0: /* child */
64c563
+				setgroups(0, NULL);
64c563
 				setgid(0);
64c563
 				setuid(0);
64c563
 				execle(START_STATD, START_STATD, NULL, envp);
64c563
@@ -1112,6 +1115,7 @@ static int nfs_ca_sockname(const struct sockaddr *sap, const socklen_t salen,
64c563
 		.sin6_addr		= IN6ADDR_ANY_INIT,
64c563
 	};
64c563
 	int sock, result = 0;
64c563
+	int val;
64c563
 
64c563
 	sock = socket(sap->sa_family, SOCK_DGRAM, IPPROTO_UDP);
64c563
 	if (sock < 0)
64c563
@@ -1123,6 +1127,9 @@ static int nfs_ca_sockname(const struct sockaddr *sap, const socklen_t salen,
64c563
 			goto out;
64c563
 		break;
64c563
 	case AF_INET6:
64c563
+		/* Make sure the call-back address is public/permanent */
64c563
+		val = IPV6_PREFER_SRC_PUBLIC;
64c563
+		setsockopt(sock, SOL_IPV6, IPV6_ADDR_PREFERENCES, &val, sizeof(val));
64c563
 		if (bind(sock, SAFE_SOCKADDR(&sin6), sizeof(sin6)) < 0)
64c563
 			goto out;
64c563
 		break;
64c563
diff --git a/utils/mount/stropts.c b/utils/mount/stropts.c
64c563
index fc68d41..57e932f 100644
64c563
--- a/utils/mount/stropts.c
64c563
+++ b/utils/mount/stropts.c
64c563
@@ -91,6 +91,7 @@ struct nfsmount_info {
64c563
 				*type;		/* "nfs" or "nfs4" */
64c563
 	char			*hostname;	/* server's hostname */
64c563
 	struct addrinfo		*address;	/* server's addresses */
64c563
+	sa_family_t		family;		/* Address family */
64c563
 
64c563
 	struct mount_options	*options;	/* parsed mount options */
64c563
 	char			**extra_opts;	/* string for /etc/mtab */
64c563
@@ -388,39 +389,19 @@ static int nfs_set_version(struct nfsmount_info *mi)
64c563
  */
64c563
 static int nfs_validate_options(struct nfsmount_info *mi)
64c563
 {
64c563
-	struct addrinfo hint = {
64c563
-		.ai_protocol	= (int)IPPROTO_UDP,
64c563
-	};
64c563
-	sa_family_t family;
64c563
-	int error;
64c563
-
64c563
 	if (!nfs_parse_devname(mi->spec, &mi->hostname, NULL))
64c563
 		return 0;
64c563
 
64c563
-	if (!nfs_nfs_proto_family(mi->options, &family))
64c563
+	if (!nfs_nfs_proto_family(mi->options, &mi->family))
64c563
 		return 0;
64c563
 
64c563
 	/*
64c563
 	 * A remount is not going to be able to change the server's address,
64c563
 	 * nor should we try to resolve another address for the server as we
64c563
 	 * may end up with a different address.
64c563
+	 * A non-remount will set 'addr' from ->hostname
64c563
 	 */
64c563
-	if (mi->flags & MS_REMOUNT) {
64c563
-		po_remove_all(mi->options, "addr");
64c563
-	} else {
64c563
-		hint.ai_family = (int)family;
64c563
-		error = getaddrinfo(mi->hostname, NULL, &hint, &mi->address);
64c563
-		if (error != 0) {
64c563
-			nfs_error(_("%s: Failed to resolve server %s: %s"),
64c563
-				progname, mi->hostname, gai_strerror(error));
64c563
-			mi->address = NULL;
64c563
-			return 0;
64c563
-		}
64c563
-
64c563
-		if (!nfs_append_addr_option(mi->address->ai_addr,
64c563
-						mi->address->ai_addrlen, mi->options))
64c563
-			return 0;
64c563
-	}
64c563
+	po_remove_all(mi->options, "addr");
64c563
 
64c563
 	if (!nfs_set_version(mi))
64c563
 		return 0;
64c563
@@ -900,7 +881,10 @@ check_result:
64c563
 			result = nfs_try_mount_v4(mi);
64c563
 			if (result == 0 && errno != ECONNREFUSED)
64c563
 				goto check_result;
64c563
-		}
64c563
+		} else if (result == 0)
64c563
+			/* Restore original errno with v3 failures */
64c563
+			errno = ECONNREFUSED;
64c563
+
64c563
 		return result;
64c563
 	default:
64c563
 		return result;
64c563
@@ -923,6 +907,32 @@ static int nfs_try_mount(struct nfsmount_info *mi)
64c563
 {
64c563
 	int result = 0;
64c563
 
64c563
+	if (mi->address == NULL) {
64c563
+		struct addrinfo hint = {
64c563
+			.ai_protocol	= (int)IPPROTO_UDP,
64c563
+		};
64c563
+		int error;
64c563
+		struct addrinfo *address;
64c563
+
64c563
+		hint.ai_family = (int)mi->family;
64c563
+		error = getaddrinfo(mi->hostname, NULL, &hint, &address);
64c563
+		if (error != 0) {
64c563
+			if (error == EAI_AGAIN)
64c563
+				errno = EAGAIN;
64c563
+			else {
64c563
+				nfs_error(_("%s: Failed to resolve server %s: %s"),
64c563
+					  progname, mi->hostname, gai_strerror(error));
64c563
+				errno = EALREADY;
64c563
+			}
64c563
+			return 0;
64c563
+		}
64c563
+
64c563
+		if (!nfs_append_addr_option(address->ai_addr,
64c563
+					    address->ai_addrlen, mi->options))
64c563
+			return 0;
64c563
+		mi->address = address;
64c563
+	}
64c563
+
64c563
 	switch (mi->version.major) {
64c563
 		case 2:
64c563
 		case 3:
64c563
@@ -1018,10 +1028,8 @@ static int nfsmount_fg(struct nfsmount_info *mi)
64c563
 		if (nfs_is_permanent_error(errno))
64c563
 			break;
64c563
 
64c563
-		if (time(NULL) > timeout) {
64c563
-			errno = ETIMEDOUT;
64c563
+		if (time(NULL) > timeout)
64c563
 			break;
64c563
-		}
64c563
 
64c563
 		if (errno != ETIMEDOUT) {
64c563
 			if (sleep(secs))