Linux NFS development
 help / color / mirror / Atom feed
* [PATCH] nfs4: fix referrals on mounts that use IPv6 addrs
@ 2012-04-24 14:57 Weston Andros Adamson
  2012-04-24 15:19 ` Jim Rees
  2012-04-24 15:33 ` Myklebust, Trond
  0 siblings, 2 replies; 9+ messages in thread
From: Weston Andros Adamson @ 2012-04-24 14:57 UTC (permalink / raw)
  To: Trond.Myklebust; +Cc: chuck.lever, linux-nfs, Weston Andros Adamson

All referrals (IPv4 addr, IPv6 addr, and DNS) are broken on mounts of
IPv6 addresses, because validation code uses a path that is parsed
from the dev_name ("<server>:<path>") by splitting on the first colon and
colons are used in IPv6 addrs.
This patch ignores colons within IPv6 addresses that are escaped by '[' and ']'.

Signed-off-by: Weston Andros Adamson <dros@netapp.com>
---

This depends on commit 2f8e4bd91488f286e83e8abb14683102efaafb05
"nfs: Enclose hostname in brackets when needed in nfs_do_root_mount".

 fs/nfs/nfs4namespace.c |   35 ++++++++++++++++++++++++++++++++---
 1 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/fs/nfs/nfs4namespace.c b/fs/nfs/nfs4namespace.c
index 9c8eca3..307743d 100644
--- a/fs/nfs/nfs4namespace.c
+++ b/fs/nfs/nfs4namespace.c
@@ -52,6 +52,35 @@ Elong:
 }
 
 /*
+ * parse the path component of an nfs path ("<server>:<path>").
+ *  nfspath - the "<server>:<path>" string
+ *  end - pointer to end of devname component of 'nfspath'
+ * returns NULL on failure
+ */
+static inline char *nfs_parse_path_component(char *nfspath, char *end)
+{
+	bool ipv6_esc = false;
+	char *p;
+
+	/* find first colon not in IPv6 addr */
+	for (p = nfspath; p < end && *p; p++) {
+		switch (*p) {
+		case '[':
+			ipv6_esc = true;
+			break;
+		case ']':
+			ipv6_esc = false;
+			break;
+		case ':':
+			if (!ipv6_esc)
+				return (p + 1);
+			break;
+		}
+	}
+	return NULL;
+}
+
+/*
  * Determine the mount path as a string
  */
 static char *nfs4_path(struct dentry *dentry, char *buffer, ssize_t buflen)
@@ -59,9 +88,9 @@ static char *nfs4_path(struct dentry *dentry, char *buffer, ssize_t buflen)
 	char *limit;
 	char *path = nfs_path(&limit, dentry, buffer, buflen);
 	if (!IS_ERR(path)) {
-		char *colon = strchr(path, ':');
-		if (colon && colon < limit)
-			path = colon + 1;
+		char *path_component = nfs_parse_path_component(path, limit);
+		if (path_component)
+			return path_component;
 	}
 	return path;
 }
-- 
1.7.4.4


^ permalink raw reply related	[flat|nested] 9+ messages in thread
* [PATCH] nfs4: fix referrals on mounts that use IPv6 addrs
@ 2012-04-24 15:07 Weston Andros Adamson
  0 siblings, 0 replies; 9+ messages in thread
From: Weston Andros Adamson @ 2012-04-24 15:07 UTC (permalink / raw)
  To: Trond.Myklebust; +Cc: chuck.lever, linux-nfs, Weston Andros Adamson

All referrals (IPv4 addr, IPv6 addr, and DNS) are broken on mounts of
IPv6 addresses, because validation code uses a path that is parsed
from the dev_name ("<server>:<path>") by splitting on the first colon and
colons are used in IPv6 addrs.
This patch ignores colons within IPv6 addresses that are escaped by '[' and ']'.

Signed-off-by: Weston Andros Adamson <dros@netapp.com>
---

Updated to pass checkpatch.pl - sorry for posting twice!

This depends on commit 2f8e4bd91488f286e83e8abb14683102efaafb05
"nfs: Enclose hostname in brackets when needed in nfs_do_root_mount".

 fs/nfs/nfs4namespace.c |   35 ++++++++++++++++++++++++++++++++---
 1 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/fs/nfs/nfs4namespace.c b/fs/nfs/nfs4namespace.c
index 9c8eca3..f90c7b3 100644
--- a/fs/nfs/nfs4namespace.c
+++ b/fs/nfs/nfs4namespace.c
@@ -52,6 +52,35 @@ Elong:
 }
 
 /*
+ * parse the path component of an nfs path ("<server>:<path>").
+ *  nfspath - the "<server>:<path>" string
+ *  end - pointer to end of devname component of 'nfspath'
+ * returns NULL on failure
+ */
+static inline char *nfs_parse_path_component(char *nfspath, char *end)
+{
+	bool ipv6_esc = false;
+	char *p;
+
+	/* find first colon not in IPv6 addr */
+	for (p = nfspath; p < end && *p; p++) {
+		switch (*p) {
+		case '[':
+			ipv6_esc = true;
+			break;
+		case ']':
+			ipv6_esc = false;
+			break;
+		case ':':
+			if (!ipv6_esc)
+				return p + 1;
+			break;
+		}
+	}
+	return NULL;
+}
+
+/*
  * Determine the mount path as a string
  */
 static char *nfs4_path(struct dentry *dentry, char *buffer, ssize_t buflen)
@@ -59,9 +88,9 @@ static char *nfs4_path(struct dentry *dentry, char *buffer, ssize_t buflen)
 	char *limit;
 	char *path = nfs_path(&limit, dentry, buffer, buflen);
 	if (!IS_ERR(path)) {
-		char *colon = strchr(path, ':');
-		if (colon && colon < limit)
-			path = colon + 1;
+		char *path_component = nfs_parse_path_component(path, limit);
+		if (path_component)
+			return path_component;
 	}
 	return path;
 }
-- 
1.7.4.4


^ permalink raw reply related	[flat|nested] 9+ messages in thread
* [PATCH] nfs4: fix referrals on mounts that use IPv6 addrs
@ 2012-04-24 20:35 Weston Andros Adamson
  2012-04-24 20:42 ` Myklebust, Trond
  0 siblings, 1 reply; 9+ messages in thread
From: Weston Andros Adamson @ 2012-04-24 20:35 UTC (permalink / raw)
  To: Trond.Myklebust; +Cc: chuck.lever, linux-nfs, Weston Andros Adamson

All referrals (IPv4 addr, IPv6 addr, and DNS) are broken on mounts of
IPv6 addresses, because validation code uses a path that is parsed
from the dev_name ("<server>:<path>") by splitting on the first colon and
colons are used in IPv6 addrs.
This patch ignores colons within IPv6 addresses that are escaped by '[' and ']'.

Signed-off-by: Weston Andros Adamson <dros@netapp.com>
---
Reposted to address comments from Trond and Jim

This depends on commit 2f8e4bd91488f286e83e8abb14683102efaafb05
"nfs: Enclose hostname in brackets when needed in nfs_do_root_mount".

 fs/nfs/nfs4namespace.c |   30 +++++++++++++++++++++++++++---
 1 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/fs/nfs/nfs4namespace.c b/fs/nfs/nfs4namespace.c
index 9c8eca3..8c84e73 100644
--- a/fs/nfs/nfs4namespace.c
+++ b/fs/nfs/nfs4namespace.c
@@ -52,6 +52,30 @@ Elong:
 }
 
 /*
+ * return the path component of "<server>:<path>"
+ *  nfspath - the "<server>:<path>" string
+ *  end - one past the last char that could contain "<server>:"
+ * returns NULL on failure
+ */
+static char *nfs_path_component(const char *nfspath, const char *end)
+{
+	char *p;
+
+	if (*nfspath == '[') {
+		/* parse [] escaped IPv6 addrs */
+		p = strchr(nfspath, ']');
+		if (p != NULL && (p + 1) < end && *(++p) == ':')
+			return p + 1;
+	} else {
+		/* otherwise split on first colon */
+		p = strchr(nfspath, ':');
+		if (p != NULL && p < end)
+			return p + 1;
+	}
+	return NULL;
+}
+
+/*
  * Determine the mount path as a string
  */
 static char *nfs4_path(struct dentry *dentry, char *buffer, ssize_t buflen)
@@ -59,9 +83,9 @@ static char *nfs4_path(struct dentry *dentry, char *buffer, ssize_t buflen)
 	char *limit;
 	char *path = nfs_path(&limit, dentry, buffer, buflen);
 	if (!IS_ERR(path)) {
-		char *colon = strchr(path, ':');
-		if (colon && colon < limit)
-			path = colon + 1;
+		char *path_component = nfs_path_component(path, limit);
+		if (path_component)
+			return path_component;
 	}
 	return path;
 }
-- 
1.7.4.4


^ permalink raw reply related	[flat|nested] 9+ messages in thread
* [PATCH] nfs4: fix referrals on mounts that use IPv6 addrs
@ 2012-04-24 20:50 Weston Andros Adamson
  0 siblings, 0 replies; 9+ messages in thread
From: Weston Andros Adamson @ 2012-04-24 20:50 UTC (permalink / raw)
  To: Trond.Myklebust; +Cc: chuck.lever, linux-nfs, Weston Andros Adamson

All referrals (IPv4 addr, IPv6 addr, and DNS) are broken on mounts of
IPv6 addresses, because validation code uses a path that is parsed
from the dev_name ("<server>:<path>") by splitting on the first colon and
colons are used in IPv6 addrs.
This patch ignores colons within IPv6 addresses that are escaped by '[' and ']'.

Signed-off-by: Weston Andros Adamson <dros@netapp.com>
---
Reposted again to address a comment from Trond

This depends on commit 2f8e4bd91488f286e83e8abb14683102efaafb05
"nfs: Enclose hostname in brackets when needed in nfs_do_root_mount".



 fs/nfs/nfs4namespace.c |   30 +++++++++++++++++++++++++++---
 1 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/fs/nfs/nfs4namespace.c b/fs/nfs/nfs4namespace.c
index 9c8eca3..7483a17 100644
--- a/fs/nfs/nfs4namespace.c
+++ b/fs/nfs/nfs4namespace.c
@@ -52,6 +52,30 @@ Elong:
 }
 
 /*
+ * return the path component of "<server>:<path>"
+ *  nfspath - the "<server>:<path>" string
+ *  end - one past the last char that could contain "<server>:"
+ * returns NULL on failure
+ */
+static char *nfs_path_component(const char *nfspath, const char *end)
+{
+	char *p;
+
+	if (*nfspath == '[') {
+		/* parse [] escaped IPv6 addrs */
+		p = strchr(nfspath, ']');
+		if (p != NULL && ++p < end && *p == ':')
+			return p + 1;
+	} else {
+		/* otherwise split on first colon */
+		p = strchr(nfspath, ':');
+		if (p != NULL && p < end)
+			return p + 1;
+	}
+	return NULL;
+}
+
+/*
  * Determine the mount path as a string
  */
 static char *nfs4_path(struct dentry *dentry, char *buffer, ssize_t buflen)
@@ -59,9 +83,9 @@ static char *nfs4_path(struct dentry *dentry, char *buffer, ssize_t buflen)
 	char *limit;
 	char *path = nfs_path(&limit, dentry, buffer, buflen);
 	if (!IS_ERR(path)) {
-		char *colon = strchr(path, ':');
-		if (colon && colon < limit)
-			path = colon + 1;
+		char *path_component = nfs_path_component(path, limit);
+		if (path_component)
+			return path_component;
 	}
 	return path;
 }
-- 
1.7.4.4


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2012-04-24 20:51 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-04-24 14:57 [PATCH] nfs4: fix referrals on mounts that use IPv6 addrs Weston Andros Adamson
2012-04-24 15:19 ` Jim Rees
2012-04-24 16:20   ` Adamson, Dros
2012-04-24 15:33 ` Myklebust, Trond
2012-04-24 16:17   ` Adamson, Dros
  -- strict thread matches above, loose matches on Subject: below --
2012-04-24 15:07 Weston Andros Adamson
2012-04-24 20:35 Weston Andros Adamson
2012-04-24 20:42 ` Myklebust, Trond
2012-04-24 20:50 Weston Andros Adamson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox