Skip to contentSkip to conversation

mountd: support IPv6 [] escaping with fsloc hosts

PATCH In review Weston Andros Adamson 3 participants 3 messages Apr 24, 2012 – May 1, 2012

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

PATCH 1/1 mountd: support IPv6 [] escaping with fsloc hosts

mountd uses colons to split fsloc hosts, but this doesn't work with IPv6 addresses (they contain ':').
To fix this, mountd is changed to expect all IPv6 addresses to be escaped by '[' and ']' so colons that are part of the address may be skipped. To fix IPv6 referrals, this patch must be used with the nfsd patch that properly parses escaped IPv6 addresses in fs_location->hosts.

---
 utils/mountd/fsloc.c |   20 +++++++++++++++++---
 1 files changed, 17 insertions(+), 3 deletions(-)
utils/mountd/fsloc.c +17 -3
index 704b7a0..bc737d1 100644
@@ -120,10 +120,11 @@ static struct servers *parse_list(char **list)
  */
 static struct servers *method_list(char *data)
 {
-	char *copy, *ptr=data;
+	char *copy, *ptr=data, *p;
 	char **list;
 	int i, listsize;
 	struct servers *rv=NULL;
+	bool v6esc = false;
 
 	xlog(L_NOTICE, "method_list(%s)", data);
 	for (ptr--, listsize=1; ptr; ptr=index(ptr, ':'), listsize++)
@@ -134,9 +135,22 @@ static struct servers *method_list(char *data)
 		xlog(L_NOTICE, "converted to %s", copy);
 	if (list && copy) {
 		ptr = copy;
-		for (i=0; i<listsize; i++) {
-			list[i] = strsep(&ptr, ":");
+		for (p = ptr, i = 0; *p && i < listsize; p++) {
+			if (*p == '[')
+				v6esc = true;
+			else if (*p == ']')
+				v6esc = false;
+
+			if (!v6esc && *p == ':') {
+				*p = '\0';
+				if (*ptr)
+					list[i++] = ptr;
+				ptr = p + 1;
+			}
 		}
+		if (*ptr)
+			list[i++] = ptr;
+		list[i] = NULL;
 		rv = parse_list(list);
 	}
 	free(copy);
Signature · 1 line
1.7.4.4
#1 lore raw
Quoted 6 lines · Weston Andros Adamson

mountd uses colons to split fsloc hosts, but this doesn't work with IPv6 addresses (they contain ':').
To fix this, mountd is changed to expect all IPv6 addresses to be escaped by '[' and ']' so colons that are part of the address may be skipped. To fix IPv6 referrals, this patch must be used with the nfsd patch that properly parses escaped IPv6 addresses in fs_location->hosts.

Looks OK to me.--b.

Quoted 51 lines
---
 utils/mountd/fsloc.c |   20 +++++++++++++++++---
 1 files changed, 17 insertions(+), 3 deletions(-)
utils/mountd/fsloc.c +17 -3
index 704b7a0..bc737d1 100644
@@ -120,10 +120,11 @@ static struct servers *parse_list(char **list)
  */
 static struct servers *method_list(char *data)
 {
-	char *copy, *ptr=data;
+	char *copy, *ptr=data, *p;
 	char **list;
 	int i, listsize;
 	struct servers *rv=NULL;
+	bool v6esc = false;
 
 	xlog(L_NOTICE, "method_list(%s)", data);
 	for (ptr--, listsize=1; ptr; ptr=index(ptr, ':'), listsize++)
@@ -134,9 +135,22 @@ static struct servers *method_list(char *data)
 		xlog(L_NOTICE, "converted to %s", copy);
 	if (list && copy) {
 		ptr = copy;
-		for (i=0; i<listsize; i++) {
-			list[i] = strsep(&ptr, ":");
+		for (p = ptr, i = 0; *p && i < listsize; p++) {
+			if (*p == '[')
+				v6esc = true;
+			else if (*p == ']')
+				v6esc = false;
+
+			if (!v6esc && *p == ':') {
+				*p = '\0';
+				if (*ptr)
+					list[i++] = ptr;
+				ptr = p + 1;
+			}
 		}
+		if (*ptr)
+			list[i++] = ptr;
+		list[i] = NULL;
 		rv = parse_list(list);
 	}
 	free(copy);
Signature · 1 line
1.7.4.4
#2 lore raw
In reply to Weston Andros Adamson
Quoted 8 lines · Weston Andros Adamson

mountd uses colons to split fsloc hosts, but this doesn't work with IPv6 addresses (they contain ':').
To fix this, mountd is changed to expect all IPv6 addresses to be escaped by '[' and ']' so colons that are part of the address may be skipped. To fix IPv6 referrals, this patch must be used with the nfsd patch that properly parses escaped IPv6 addresses in fs_location->hosts.

Committed...

steved.

Quoted 48 lines
---
 utils/mountd/fsloc.c |   20 +++++++++++++++++---
 1 files changed, 17 insertions(+), 3 deletions(-)
utils/mountd/fsloc.c +17 -4
index 704b7a0..bc737d1 100644
@@ -120,10 +120,11 @@ static struct servers *parse_list(char **list)
  */
 static struct servers *method_list(char *data)
 {
-	char *copy, *ptr=data;
+	char *copy, *ptr=data, *p;
 	char **list;
 	int i, listsize;
 	struct servers *rv=NULL;
+	bool v6esc = false;
 
 	xlog(L_NOTICE, "method_list(%s)", data);
 	for (ptr--, listsize=1; ptr; ptr=index(ptr, ':'), listsize++)
@@ -134,9 +135,22 @@ static struct servers *method_list(char *data)
 		xlog(L_NOTICE, "converted to %s", copy);
 	if (list && copy) {
 		ptr = copy;
-		for (i=0; i<listsize; i++) {
-			list[i] = strsep(&ptr, ":");
+		for (p = ptr, i = 0; *p && i < listsize; p++) {
+			if (*p == '[')
+				v6esc = true;
+			else if (*p == ']')
+				v6esc = false;
+
+			if (!v6esc && *p == ':') {
+				*p = '\0';
+				if (*ptr)
+					list[i++] = ptr;
+				ptr = p + 1;
+			}
 		}
+		if (*ptr)
+			list[i++] = ptr;
+		list[i] = NULL;
 		rv = parse_list(list);
 	}
 	free(copy);
-- 1.7.4.4