Skip to contentSkip to conversation

nfsd: add IPv6 addr escaping to fs_location hosts

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

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

PATCH 1/1 nfsd: add IPv6 addr escaping to fs_location hosts

The fs_location->hosts list is split on colons, but this doesn't work when IPv6 addresses are used (they contain colons).
This patch adds the function nfsd4_encode_components_esc() to allow the caller to specify escape characters when splitting on 'sep'. In order to fix referrals, this patch must be used with the mountd patch that similarly fixes IPv6 [] escaping.

---
 fs/nfsd/nfs4xdr.c |   35 +++++++++++++++++++++++++++++------
 1 files changed, 29 insertions(+), 6 deletions(-)
fs/nfsd/nfs4xdr.c +29 -6
index 74c00bc..782be6c 100644
@@ -1744,10 +1744,11 @@ static void encode_seqid_op_tail(struct nfsd4_compoundres *resp, __be32 *save, _
 }
 
 /* Encode as an array of strings the string given with components
- * separated @sep.
+ * separated @sep, escaped with esc_enter and esc_exit.
  */
-static __be32 nfsd4_encode_components(char sep, char *components,
-				   __be32 **pp, int *buflen)
+static __be32 nfsd4_encode_components_esc(char sep, char *components,
+				   __be32 **pp, int *buflen,
+				   char esc_enter, char esc_exit)
 {
 	__be32 *p = *pp;
 	__be32 *countp = p;
@@ -1760,8 +1761,20 @@ static __be32 nfsd4_encode_components(char sep, char *components,
 	WRITE32(0); /* We will fill this in with @count later */
 	end = str = components;
 	while (*end) {
-		for (; *end && (*end != sep); end++)
-			; /* Point to end of component */
+		bool found_esc = false;
+
+		/* try to parse as esc_start, ..., esc_end, sep */
+		if (*str == esc_enter) {
+			for (; *end && (*end != esc_exit); end++);
+			if (*end && !*(end + 1) || (end + 1) == sep) {
+				str++;
+				found_esc = true;
+			}
+		}
+
+		if (!found_esc)
+			for (; *end && (*end != sep); end++);
+
 		strlen = end - str;
 		if (strlen) {
 			if ((*buflen -= ((XDR_QUADLEN(strlen) << 2) + 4)) < 0)
@@ -1780,6 +1793,15 @@ static __be32 nfsd4_encode_components(char sep, char *components,
 	return 0;
 }
 
+/* Encode as an array of strings the string given with components
+ * separated @sep.
+ */
+static __be32 nfsd4_encode_components(char sep, char *components,
+				   __be32 **pp, int *buflen)
+{
+	return nfsd4_encode_components_esc(sep, components, pp, buflen, 0, 0);
+}
+
 /*
  * encode a location element of a fs_locations structure
  */
@@ -1789,7 +1811,8 @@ static __be32 nfsd4_encode_fs_location4(struct nfsd4_fs_location *location,
 	__be32 status;
 	__be32 *p = *pp;
 
-	status = nfsd4_encode_components(':', location->hosts, &p, buflen);
+	status = nfsd4_encode_components_esc(':', location->hosts, &p, buflen,
+						'[', ']');
 	if (status)
 		return status;
 	status = nfsd4_encode_components('/', location->path, &p, buflen);
Signature · 1 line
1.7.4.4
#1 lore raw
Quoted 6 lines · Weston Andros Adamson

The fs_location->hosts list is split on colons, but this doesn't work when IPv6 addresses are used (they contain colons).
This patch adds the function nfsd4_encode_components_esc() to allow the caller to specify escape characters when splitting on 'sep'. In order to fix referrals, this patch must be used with the mountd patch that similarly fixes IPv6 [] escaping.

Thanks, looks fine, applying with one trivial change:

fs/nfsd/nfs4xdr.c static __be32 nfsd4_encode_components(char sep, char *components, · line 1768

Quoted 7 lines
fs/nfsd/nfs4xdr.c +5 -2
-		for (; *end && (*end != sep); end++)
-			; /* Point to end of component */
+		bool found_esc = false;
+
+		/* try to parse as esc_start, ..., esc_end, sep */
+		if (*str == esc_enter) {
+			for (; *end && (*end != esc_exit); end++);

I kinda like keeping the semicolon on its own line here. Tastes may differ.

(Also: how did you test this?)

--b.

#2 lore raw

fs/nfsd/nfs4xdr.c static __be32 nfsd4_encode_components(char sep, char *components, · line 1768

Quoted 1 line · J. Bruce Fields
fs/nfsd/nfs4xdr.c +1 -0
+			for (; *end && (*end != esc_exit); end++);

I kinda like keeping the semicolon on its own line here. Tastes may differ.

Tastes may differ, but the official kernel style requires putting the semicolon on a separate line.

#3 lore raw
In reply to J. Bruce Fields
Quoted 10 lines · J. Bruce Fields
Quoted 6 lines · Weston Andros Adamson

The fs_location->hosts list is split on colons, but this doesn't work when IPv6 addresses are used (they contain colons).
This patch adds the function nfsd4_encode_components_esc() to allow the caller to specify escape characters when splitting on 'sep'. In order to fix referrals, this patch must be used with the mountd patch that similarly fixes IPv6 [] escaping.

Thanks, looks fine, applying with one trivial change:

Quoted 10 lines

fs/nfsd/nfs4xdr.c static __be32 nfsd4_encode_components(char sep, char *components, · line 1768

Quoted 7 lines
fs/nfsd/nfs4xdr.c +5 -2
-		for (; *end && (*end != sep); end++)
-			; /* Point to end of component */
+		bool found_esc = false;
+
+		/* try to parse as esc_start, ..., esc_end, sep */
+		if (*str == esc_enter) {
+			for (; *end && (*end != esc_exit); end++);

I kinda like keeping the semicolon on its own line here. Tastes may differ.

Yeah, as Jim pointed out checkpatch will complain if it's not -- you already found my updated diff.

Quoted 1 line

(Also: how did you test this?)

I testsed this patch along with the corresponding mountd patch using two servers:

[fc00::10] - exporting /export, /export/refer @ [fc00:41]:/export [fc00::41] - exporting /export

On a client machine (with recently posted client-side fix), I mount [fc00::10]:/export on /mnt, then cd to /mnt/refer.

Without these patches, wireshark sees a list of referral locations: "[fc00", "", "10]", which is obviously wrong. With these patches the cd to /mnt/refer works as [fc00::41]:/export is mounted at /mnt/refer.

-dros

#4 lore raw
Quoted 30 lines · Dros
Quoted 10 lines · J. Bruce Fields
Quoted 6 lines · Weston Andros Adamson

The fs_location->hosts list is split on colons, but this doesn't work when IPv6 addresses are used (they contain colons).
This patch adds the function nfsd4_encode_components_esc() to allow the caller to specify escape characters when splitting on 'sep'. In order to fix referrals, this patch must be used with the mountd patch that similarly fixes IPv6 [] escaping.

Thanks, looks fine, applying with one trivial change:

Quoted 10 lines

fs/nfsd/nfs4xdr.c static __be32 nfsd4_encode_components(char sep, char *components, · line 1768

Quoted 7 lines
fs/nfsd/nfs4xdr.c +5 -2
-		for (; *end && (*end != sep); end++)
-			; /* Point to end of component */
+		bool found_esc = false;
+
+		/* try to parse as esc_start, ..., esc_end, sep */
+		if (*str == esc_enter) {
+			for (; *end && (*end != esc_exit); end++);

I kinda like keeping the semicolon on its own line here. Tastes may differ.

Yeah, as Jim pointed out checkpatch will complain if it's not -- you already found my updated diff.

Quoted 1 line

(Also: how did you test this?)

I testsed this patch along with the corresponding mountd patch using two servers:

Quoted 7 lines

[fc00::10] - exporting /export, /export/refer @ [fc00:41]:/export [fc00::41] - exporting /export

On a client machine (with recently posted client-side fix), I mount [fc00::10]:/export on /mnt, then cd to /mnt/refer.

Without these patches, wireshark sees a list of referral locations: "[fc00", "", "10]", which is obviously wrong. With these patches the cd to /mnt/refer works as [fc00::41]:/export is mounted at /mnt/refer.

Sounds good. Thanks!

--b.