linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] nfsd: add IPv6 addr escaping to fs_location hosts
@ 2012-04-24 14:59 Weston Andros Adamson
  2012-04-27 11:25 ` J. Bruce Fields
  0 siblings, 1 reply; 7+ messages in thread
From: Weston Andros Adamson @ 2012-04-24 14:59 UTC (permalink / raw)
  To: bfields; +Cc: SteveD, linux-nfs, 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.

Signed-off-by: Weston Andros Adamson <dros@netapp.com>
---
 fs/nfsd/nfs4xdr.c |   35 +++++++++++++++++++++++++++++------
 1 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index 74c00bc..782be6c 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -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);
-- 
1.7.4.4


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

* [PATCH] nfsd: add IPv6 addr escaping to fs_location hosts
@ 2012-04-24 15:07 Weston Andros Adamson
  2012-04-27 12:48 ` J. Bruce Fields
  0 siblings, 1 reply; 7+ messages in thread
From: Weston Andros Adamson @ 2012-04-24 15:07 UTC (permalink / raw)
  To: bfields; +Cc: SteveD, linux-nfs, 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.

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

Sorry, I posted a slightly older version of this patch.  This is the one
we want!

 fs/nfsd/nfs4xdr.c |   40 +++++++++++++++++++++++++++++++++-------
 1 files changed, 33 insertions(+), 7 deletions(-)

diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index 74c00bc..eabd0d9 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -1744,15 +1744,16 @@ 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;
 	int strlen, count=0;
-	char *str, *end;
+	char *str, *end, *next;
 
 	dprintk("nfsd4_encode_components(%s)\n", components);
 	if ((*buflen -= 4) < 0)
@@ -1760,8 +1761,23 @@ 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++)
+				/* find esc_exit or end of string */;
+			next = end + 1;
+			if (*end && (!*next || *next == sep)) {
+				str++;
+				found_esc = true;
+			}
+		}
+
+		if (!found_esc)
+			for (; *end && (*end != sep); end++)
+				/* find sep or end of string */;
+
 		strlen = end - str;
 		if (strlen) {
 			if ((*buflen -= ((XDR_QUADLEN(strlen) << 2) + 4)) < 0)
@@ -1780,6 +1796,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 +1814,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);
-- 
1.7.4.4


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

* Re: [PATCH] nfsd: add IPv6 addr escaping to fs_location hosts
  2012-04-24 14:59 [PATCH] nfsd: add IPv6 addr escaping to fs_location hosts Weston Andros Adamson
@ 2012-04-27 11:25 ` J. Bruce Fields
  2012-04-27 11:42   ` Jim Rees
  2012-05-01 16:09   ` Adamson, Dros
  0 siblings, 2 replies; 7+ messages in thread
From: J. Bruce Fields @ 2012-04-27 11:25 UTC (permalink / raw)
  To: Weston Andros Adamson; +Cc: SteveD, linux-nfs

On Tue, Apr 24, 2012 at 10:59:37AM -0400, Weston Andros Adamson wrote:
> 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:

> -		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.

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

* Re: [PATCH] nfsd: add IPv6 addr escaping to fs_location hosts
  2012-04-27 11:25 ` J. Bruce Fields
@ 2012-04-27 11:42   ` Jim Rees
  2012-05-01 16:09   ` Adamson, Dros
  1 sibling, 0 replies; 7+ messages in thread
From: Jim Rees @ 2012-04-27 11:42 UTC (permalink / raw)
  To: J. Bruce Fields; +Cc: Weston Andros Adamson, SteveD, linux-nfs

J. Bruce Fields wrote:

  > +			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.

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

* Re: [PATCH] nfsd: add IPv6 addr escaping to fs_location hosts
  2012-04-24 15:07 Weston Andros Adamson
@ 2012-04-27 12:48 ` J. Bruce Fields
  0 siblings, 0 replies; 7+ messages in thread
From: J. Bruce Fields @ 2012-04-27 12:48 UTC (permalink / raw)
  To: Weston Andros Adamson; +Cc: SteveD, linux-nfs

On Tue, Apr 24, 2012 at 11:07:59AM -0400, Weston Andros Adamson wrote:
> 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.
> 
> Signed-off-by: Weston Andros Adamson <dros@netapp.com>
> ---
> 
> Sorry, I posted a slightly older version of this patch.  This is the one
> we want!

Whoops, right, applying this version....--b.

> 
>  fs/nfsd/nfs4xdr.c |   40 +++++++++++++++++++++++++++++++++-------
>  1 files changed, 33 insertions(+), 7 deletions(-)
> 
> diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
> index 74c00bc..eabd0d9 100644
> --- a/fs/nfsd/nfs4xdr.c
> +++ b/fs/nfsd/nfs4xdr.c
> @@ -1744,15 +1744,16 @@ 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;
>  	int strlen, count=0;
> -	char *str, *end;
> +	char *str, *end, *next;
>  
>  	dprintk("nfsd4_encode_components(%s)\n", components);
>  	if ((*buflen -= 4) < 0)
> @@ -1760,8 +1761,23 @@ 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++)
> +				/* find esc_exit or end of string */;
> +			next = end + 1;
> +			if (*end && (!*next || *next == sep)) {
> +				str++;
> +				found_esc = true;
> +			}
> +		}
> +
> +		if (!found_esc)
> +			for (; *end && (*end != sep); end++)
> +				/* find sep or end of string */;
> +
>  		strlen = end - str;
>  		if (strlen) {
>  			if ((*buflen -= ((XDR_QUADLEN(strlen) << 2) + 4)) < 0)
> @@ -1780,6 +1796,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 +1814,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);
> -- 
> 1.7.4.4
> 

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

* Re: [PATCH] nfsd: add IPv6 addr escaping to fs_location hosts
  2012-04-27 11:25 ` J. Bruce Fields
  2012-04-27 11:42   ` Jim Rees
@ 2012-05-01 16:09   ` Adamson, Dros
  2012-05-01 17:01     ` J. Bruce Fields
  1 sibling, 1 reply; 7+ messages in thread
From: Adamson, Dros @ 2012-05-01 16:09 UTC (permalink / raw)
  To: J. Bruce Fields
  Cc: <SteveD@redhat.com>, <linux-nfs@vger.kernel.org>

[-- Attachment #1: Type: text/plain, Size: 1604 bytes --]


On Apr 27, 2012, at 7:25 AM, J. Bruce Fields wrote:

> On Tue, Apr 24, 2012 at 10:59:37AM -0400, Weston Andros Adamson wrote:
>> 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:
> 
>> -		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.

> (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

[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 1374 bytes --]

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

* Re: [PATCH] nfsd: add IPv6 addr escaping to fs_location hosts
  2012-05-01 16:09   ` Adamson, Dros
@ 2012-05-01 17:01     ` J. Bruce Fields
  0 siblings, 0 replies; 7+ messages in thread
From: J. Bruce Fields @ 2012-05-01 17:01 UTC (permalink / raw)
  To: Adamson, Dros
  Cc: <SteveD@redhat.com>, <linux-nfs@vger.kernel.org>

On Tue, May 01, 2012 at 04:09:55PM +0000, Adamson, Dros wrote:
> 
> On Apr 27, 2012, at 7:25 AM, J. Bruce Fields wrote:
> 
> > On Tue, Apr 24, 2012 at 10:59:37AM -0400, Weston Andros Adamson wrote:
> >> 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:
> > 
> >> -		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.
> 
> > (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.

Sounds good.  Thanks!

--b.

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

end of thread, other threads:[~2012-05-01 17:01 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-04-24 14:59 [PATCH] nfsd: add IPv6 addr escaping to fs_location hosts Weston Andros Adamson
2012-04-27 11:25 ` J. Bruce Fields
2012-04-27 11:42   ` Jim Rees
2012-05-01 16:09   ` Adamson, Dros
2012-05-01 17:01     ` J. Bruce Fields
  -- strict thread matches above, loose matches on Subject: below --
2012-04-24 15:07 Weston Andros Adamson
2012-04-27 12:48 ` J. Bruce Fields

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).