Skip to contentSkip to conversation

mount.cifs: Add support for parsing IPv6 addresses enclosed in brackets.

PATCH In review [email protected] 3 participants 12 messages Apr 14, 2013 – Apr 23, 2013 7 messages not in the archive

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

PATCH 1/1 mount.cifs: Add support for parsing IPv6 addresses enclosed in brackets.

From: Scott Lovenberg <[email protected]>

The standard for formatting IPv6 addresses is to enclose them in brackets. This patch allows the mount helper to parse IPv6 addresses that are enclosed in brackets. There is a slight change of behavior in this patch; specifying the --ip option without supplying an address now exits the mount helper rather than just ignoring and continuing.

---
 AUTHORS      |    1 +
 mount.cifs.c |   63 ++++++++++++++++++++++++++++++++++++++++++----------------
 2 files changed, 47 insertions(+), 17 deletions(-)
AUTHORS +1 -0
index 2807079..081c2fe 100644
@@ -5,5 +5,6 @@ Shirish Pargaonkar <[email protected]>
 Suresh Jayaraman <[email protected]>
 Pavel Shilovsky <[email protected]>
 Igor Druzhinin <[email protected]>
+Scott Lovenberg <[email protected]>
 
 ...and others.
mount.cifs.c +46 -17

75 lines not on this page · raw message

Signature · 1 line
1.7.10.4

A message that is not in the archive (sent off-list or not yet received): 1365963558-20082-1-git-send-email-scott.lovenberg-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#2 lore raw
Quoted 8 lines · On Sun, Apr 14, 2013 at 2:19 PM, <scott.lovenberg-Re5JQEeQqe8AvxtiuMwx3w@publi…

From: Scott Lovenberg <[email protected]>

The standard for formatting IPv6 addresses is to enclose them in brackets. This patch allows the mount helper to parse IPv6 addresses that are enclosed in brackets. There is a slight change of behavior in this patch; specifying the --ip option without supplying an address now exits the mount helper rather than just ignoring and continuing.

I should mention, this hasn't actually been tested. Only compiled. A patch this small is usually fairly safe.. then again, I've messed up one-liners. A few eyes over this code would be appreciated.

--
Peace and Blessings,
-Scott.

#3 lore raw
In reply to a message not in the archive
Quoted 33 lines · On Sun, 14 Apr 2013 14:19:18 -0400 scott.lovenberg-Re5JQEeQqe8AvxtiuMwx3w@publi…

From: Scott Lovenberg <[email protected]>

The standard for formatting IPv6 addresses is to enclose them in brackets. This patch allows the mount helper to parse IPv6 addresses that are enclosed in brackets. There is a slight change of behavior in this patch; specifying the --ip option without supplying an address now exits the mount helper rather than just ignoring and continuing.

---
 AUTHORS      |    1 +
 mount.cifs.c |   63 ++++++++++++++++++++++++++++++++++++++++++----------------
 2 files changed, 47 insertions(+), 17 deletions(-)
AUTHORS +1 -0
index 2807079..081c2fe 100644
@@ -5,5 +5,6 @@ Shirish Pargaonkar <[email protected]>
 Suresh Jayaraman <[email protected]>
 Pavel Shilovsky <[email protected]>
 Igor Druzhinin <[email protected]>
+Scott Lovenberg <[email protected]>
 
 ...and others.
mount.cifs.c +1 -0
index 3b2b89e..276f50d 100644
@@ -751,6 +751,48 @@ static int parse_opt_token(const char *token)
 	return OPT_ERROR;
 }
 
+/* 

mount.cifs.c static int parse_opt_token(const char *token) · line 764

Quoted 10 lines
mount.cifs.c +10 -0
+  Extract an ipv4 or ipv6 address and put it into parsed_info. 
+  Returns 0 on success.
+*/
+static int parse_ip(char *value, struct parsed_mount_info *parsed_info)
+{
+	char *closingBracket = NULL;
+
+	if (!value || !*value) {
+		fprintf(stderr, "target ip address argument missing\n");
+		return OPT_ERROR;

I think you want something like EX_USAGE here.

Quoted 62 lines
mount.cifs.c +35 -17
+	}
+
+	/* check for ipv6 in brackets */
+	if (value[0] == '[') {
+		value++;
+		/* temporarily null the closing bracket */
+		closingBracket = strchr(value, ']');
+		if (closingBracket)
+			*closingBracket = '\0';
+	}
+
+	/* check length of address*/
+	if (strnlen(value, MAX_ADDRESS_LEN + 1) > MAX_ADDRESS_LEN) {
+		fprintf(stderr, "ip address too long\n");
+		if (closingBracket)
+			*closingBracket = ']';
+		return EX_USAGE;
+	}
+
+	/* all test pass, copy it */
+	strcpy(parsed_info->addrlist, value);
+	if (parsed_info->verboseflag)
+		fprintf(stderr, "ip address %s override specified\n", value);
+
+	/* put back closing bracket */
+	if (closingBracket)
+		*closingBracket = ']';
+
+	return 0;
+}
+
 static int
 parse_options(const char *data, struct parsed_mount_info *parsed_info)
 {
@@ -861,23 +903,10 @@ parse_options(const char *data, struct parsed_mount_info *parsed_info)
 			break;
 
 		case OPT_IP:
-			if (!value || !*value) {
-				fprintf(stderr,
-					"target ip address argument missing\n");
-			} else if (strnlen(value, MAX_ADDRESS_LEN) <=
-				MAX_ADDRESS_LEN) {
-				strcpy(parsed_info->addrlist, value);
-				if (parsed_info->verboseflag)
-					fprintf(stderr,
-						"ip address %s override specified\n",
-						value);
-				goto nocopy;
-			} else {
-				fprintf(stderr, "ip address too long\n");
-				return EX_USAGE;
-
-			}
-			break;
+			rc = parse_ip(value, parsed_info);
+			if (rc)
+				return rc;			
+			goto nocopy;
 
 		/* unc || target || path */
 		case OPT_UNC:
Signature · 1 line
Jeff Layton <[email protected]>
#4 lore raw

PATCH 1/1 mount.cifs: add support for IPv6 addresses in brackets V2

In reply to a message not in the archive

From: Scott Lovenberg <[email protected]>

This is a respin of the last patch that returns EX_USAGE rather than OPT_ERROR as per Jeff's suggestion.

---
 AUTHORS      |    1 +
 mount.cifs.c |   62 ++++++++++++++++++++++++++++++++++++++++++----------------
 2 files changed, 46 insertions(+), 17 deletions(-)
AUTHORS +1 -0
index 2807079..081c2fe 100644
@@ -5,5 +5,6 @@ Shirish Pargaonkar <[email protected]>
 Suresh Jayaraman <[email protected]>
 Pavel Shilovsky <[email protected]>
 Igor Druzhinin <[email protected]>
+Scott Lovenberg <[email protected]>
 
 ...and others.
mount.cifs.c +45 -17

74 lines not on this page · raw message

Signature · 1 line
1.7.10.4

A message that is not in the archive (sent off-list or not yet received): 1366075789-23137-1-git-send-email-scott.lovenberg-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#6 lore raw

Re: [PATCH] mount.cifs: add support for IPv6 addresses in brackets V2

Quoted 5 lines · On Mon, Apr 15, 2013 at 9:29 PM, <scott.lovenberg-Re5JQEeQqe8AvxtiuMwx3w@publi…

From: Scott Lovenberg <[email protected]>

This is a respin of the last patch that returns EX_USAGE rather than OPT_ERROR as per Jeff's suggestion.

For future reference, is there a way to get git send-email to attach
this to another email thread? I tried to use --in-reply-to=1365963558-20082-1-git-send-email-scott.lovenberg-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org, but that seems to not be correct and my Google-fu seems to be weak
today.

--
Peace and Blessings,
-Scott.

#7 lore raw

Re: [PATCH] mount.cifs: add support for IPv6 addresses in brackets V2

In reply to a message not in the archive
Quoted 103 lines · On Mon, Apr 15, 2013 at 9:29 PM, <scott.lovenberg-Re5JQEeQqe8AvxtiuMwx3w@public…

From: Scott Lovenberg <[email protected]>

This is a respin of the last patch that returns EX_USAGE rather than OPT_ERROR as per Jeff's suggestion.

---
 AUTHORS      |    1 +
 mount.cifs.c |   62 ++++++++++++++++++++++++++++++++++++++++++----------------
 2 files changed, 46 insertions(+), 17 deletions(-)
AUTHORS +1 -0
index 2807079..081c2fe 100644
@@ -5,5 +5,6 @@ Shirish Pargaonkar <[email protected]>
 Suresh Jayaraman <[email protected]>
 Pavel Shilovsky <[email protected]>
 Igor Druzhinin <[email protected]>
+Scott Lovenberg <[email protected]>
 
 ...and others.
mount.cifs.c +45 -18
index 3b2b89e..561517b 100644
@@ -751,6 +751,47 @@ static int parse_opt_token(const char *token)
        return OPT_ERROR;
 }
 
+/*
+  Extract an ipv4 or ipv6 address and put it into parsed_info.
+  Returns 0 on success.
+*/
+static int parse_ip(char *value, struct parsed_mount_info *parsed_info)
+{
+       char *closingBracket = NULL;
+
+       if (!value || !*value) {
+               fprintf(stderr, "target ip address argument missing\n");
+               return EX_USAGE;
+       }
+
+       /* check for ipv6 in brackets */
+       if (value[0] == '[') {
+               value++;
+               /* temporarily null the closing bracket */
+               closingBracket = strchr(value, ']');
+               if (closingBracket)
+                       *closingBracket = '\0';
+       }
+
+       /* check length of address */
+       if (strnlen(value, MAX_ADDRESS_LEN + 1) > MAX_ADDRESS_LEN) {
+               fprintf(stderr, "ip address too long\n");
+               if (closingBracket)
+                       *closingBracket = ']';
+               return EX_USAGE;
+       }
+
+       strcpy(parsed_info->addrlist, value);
+       if (parsed_info->verboseflag)
+               fprintf(stderr, "ip address %s override specified\n", value);
+
+       /* put back closing bracket */
+       if (closingBracket)
+               *closingBracket = ']';
+
+       return 0;
+}
+
 static int
 parse_options(const char *data, struct parsed_mount_info *parsed_info)
 {
@@ -861,23 +902,10 @@ parse_options(const char *data, struct parsed_mount_info *parsed_info)
                        break;
 
                case OPT_IP:
-                       if (!value || !*value) {
-                               fprintf(stderr,
-                                       "target ip address argument missing\n");
-                       } else if (strnlen(value, MAX_ADDRESS_LEN) <=
-                               MAX_ADDRESS_LEN) {
-                               strcpy(parsed_info->addrlist, value);
-                               if (parsed_info->verboseflag)
-                                       fprintf(stderr,
-                                               "ip address %s override specified\n",
-                                               value);
-                               goto nocopy;
-                       } else {
-                               fprintf(stderr, "ip address too long\n");
-                               return EX_USAGE;
-
-                       }
-                       break;
+                       rc = parse_ip(value, parsed_info);
+                       if (rc)
+                               return rc;
+                       goto nocopy;
 
                /* unc || target || path */
                case OPT_UNC:
--
Quoted 2 lines

1.7.10.4

Ping.
Any comments?

--
Peace and Blessings,
-Scott.

A message that is not in the archive (sent off-list or not yet received): CAFB9KM00JWSUSP28LrzJsgQ0po6ZtTpK9enbwv3-N5y2+E5G0A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#9 lore raw

Re: [PATCH] mount.cifs: add support for IPv6 addresses in brackets V2

Quoted 101 lines · On Mon, 22 Apr 2013 10:21:13 -0400 Scott Lovenberg…
Quoted 100 lines · On Mon, Apr 15, 2013 at 9:29 PM, <scott.lovenberg-Re5JQEeQqe8AvxtiuMwx3w@public…

From: Scott Lovenberg <[email protected]>

This is a respin of the last patch that returns EX_USAGE rather than OPT_ERROR as per Jeff's suggestion.

---
 AUTHORS      |    1 +
 mount.cifs.c |   62 ++++++++++++++++++++++++++++++++++++++++++----------------
 2 files changed, 46 insertions(+), 17 deletions(-)
AUTHORS +1 -0
index 2807079..081c2fe 100644
@@ -5,5 +5,6 @@ Shirish Pargaonkar <[email protected]>
 Suresh Jayaraman <[email protected]>
 Pavel Shilovsky <[email protected]>
 Igor Druzhinin <[email protected]>
+Scott Lovenberg <[email protected]>
 
 ...and others.
mount.cifs.c +45 -17
index 3b2b89e..561517b 100644
@@ -751,6 +751,47 @@ static int parse_opt_token(const char *token)
        return OPT_ERROR;
 }
 
+/*
+  Extract an ipv4 or ipv6 address and put it into parsed_info.
+  Returns 0 on success.
+*/
+static int parse_ip(char *value, struct parsed_mount_info *parsed_info)
+{
+       char *closingBracket = NULL;
+
+       if (!value || !*value) {
+               fprintf(stderr, "target ip address argument missing\n");
+               return EX_USAGE;
+       }
+
+       /* check for ipv6 in brackets */
+       if (value[0] == '[') {
+               value++;
+               /* temporarily null the closing bracket */
+               closingBracket = strchr(value, ']');
+               if (closingBracket)
+                       *closingBracket = '\0';
+       }
+
+       /* check length of address */
+       if (strnlen(value, MAX_ADDRESS_LEN + 1) > MAX_ADDRESS_LEN) {
+               fprintf(stderr, "ip address too long\n");
+               if (closingBracket)
+                       *closingBracket = ']';
+               return EX_USAGE;
+       }
+
+       strcpy(parsed_info->addrlist, value);
+       if (parsed_info->verboseflag)
+               fprintf(stderr, "ip address %s override specified\n", value);
+
+       /* put back closing bracket */
+       if (closingBracket)
+               *closingBracket = ']';
+
+       return 0;
+}
+
 static int
 parse_options(const char *data, struct parsed_mount_info *parsed_info)
 {
@@ -861,23 +902,10 @@ parse_options(const char *data, struct parsed_mount_info *parsed_info)
                        break;
 
                case OPT_IP:
-                       if (!value || !*value) {
-                               fprintf(stderr,
-                                       "target ip address argument missing\n");
-                       } else if (strnlen(value, MAX_ADDRESS_LEN) <=
-                               MAX_ADDRESS_LEN) {
-                               strcpy(parsed_info->addrlist, value);
-                               if (parsed_info->verboseflag)
-                                       fprintf(stderr,
-                                               "ip address %s override specified\n",
-                                               value);
-                               goto nocopy;
-                       } else {
-                               fprintf(stderr, "ip address too long\n");
-                               return EX_USAGE;
-
-                       }
-                       break;
+                       rc = parse_ip(value, parsed_info);
+                       if (rc)
+                               return rc;
+                       goto nocopy;
 
Quoted 10 lines
Quoted 5 lines
mount.cifs.c +0 -1
                /* unc || target || path */
                case OPT_UNC:
--

1.7.10.4

Ping.
Any comments?

I guess I don't quite understand why we need this patch. For NFS it's pretty clear that we would since ':' has always served as the delimiter between the hostname and the pathname.

For CIFS, not so much... IPv6 addresses typically don't have '/' or '\\' characters in them, so why do we need to wrap them in []?

Note that this syntax doesn't follow what Windows does either, AFAIK. There, you need something like this since UNC paths can't contain ':' characters (and maybe also '%'):

http://www.samba.org/~idra/code/nss-ipv6literal/README.html

...we have no such restriction under Linux though.

Signature · 1 line
Jeff Layton <[email protected]>

A message that is not in the archive (sent off-list or not yet received): 20130422110907.4e684579-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org

#11 lore raw

Re: [PATCH] mount.cifs: add support for IPv6 addresses in brackets V2

Quoted 11 lines · Jeff Layton
Quoted 3 lines

Ping.
Any comments?

I guess I don't quite understand why we need this patch. For NFS it's pretty clear that we would since ':' has always served as the delimiter between the hostname and the pathname.

For CIFS, not so much... IPv6 addresses typically don't have '/' or '\\' characters in them, so why do we need to wrap them in []?

Quoted 8 lines

Note that this syntax doesn't follow what Windows does either, AFAIK. There, you need something like this since UNC paths can't contain ':' characters (and maybe also '%'):

http://www.samba.org/~idra/code/nss-ipv6literal/README.html

...we have no such restriction under Linux though.

I liked this approach for two reasons. It handles a convention for IPv6 formatting that is used that we don't support and allows us to (in the future) parse an address from the path instead of having to use --ip=, which I feel is a bit cumbersome. Originally I was going to just put in support for something like "mount.cifs //IPv6Address/share /mnt/path" right away, but I wanted to get this part in first.

--
Peace and Blessings,
-Scott.

A message that is not in the archive (sent off-list or not yet received): CAFB9KM2QWUZrF-Bj5gkKqHiybYcFB5gskqGqRRsOQ8aGQC6WBw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#13 lore raw

Re: [PATCH] mount.cifs: add support for IPv6 addresses in brackets V2

Quoted 21 lines · On Tue, 23 Apr 2013 08:34:14 -0400 Scott Lovenberg…
Quoted 11 lines · Jeff Layton
Quoted 3 lines

Ping.
Any comments?

I guess I don't quite understand why we need this patch. For NFS it's pretty clear that we would since ':' has always served as the delimiter between the hostname and the pathname.

For CIFS, not so much... IPv6 addresses typically don't have '/' or '\\' characters in them, so why do we need to wrap them in []?

Quoted 8 lines

Note that this syntax doesn't follow what Windows does either, AFAIK. There, you need something like this since UNC paths can't contain ':' characters (and maybe also '%'):

http://www.samba.org/~idra/code/nss-ipv6literal/README.html

...we have no such restriction under Linux though.

Quoted 8 lines

I liked this approach for two reasons. It handles a convention for IPv6 formatting that is used that we don't support and allows us to (in the future) parse an address from the path instead of having to use --ip=, which I feel is a bit cumbersome. Originally I was going to just put in support for something like "mount.cifs //IPv6Address/share /mnt/path" right away, but I wanted to get this part in first.

Again, I'm confused...this sort of syntax seems to work just fine already:

    # mount -t cifs //fecd::1/share /mnt/cifs -o sec=none,multiuser

Also, --ip= is not a valid option in the longopts[] array in mount.cifs (maybe you mean -o ip=). I still don't see what benefit we receive from allowing someone specify addresses inside of square brackets.

Signature · 1 line
Jeff Layton <[email protected]>

A message that is not in the archive (sent off-list or not yet received): 20130423100114.2146f72a-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org

#15 lore raw

Re: [PATCH] mount.cifs: add support for IPv6 addresses in brackets V2

Quoted 33 lines · Jeff Layton
Quoted 21 lines · On Tue, 23 Apr 2013 08:34:14 -0400 Scott Lovenberg…
Quoted 11 lines · Jeff Layton
Quoted 3 lines

Ping.
Any comments?

I guess I don't quite understand why we need this patch. For NFS it's pretty clear that we would since ':' has always served as the delimiter between the hostname and the pathname.

For CIFS, not so much... IPv6 addresses typically don't have '/' or '\\' characters in them, so why do we need to wrap them in []?

Quoted 8 lines

Note that this syntax doesn't follow what Windows does either, AFAIK. There, you need something like this since UNC paths can't contain ':' characters (and maybe also '%'):

http://www.samba.org/~idra/code/nss-ipv6literal/README.html

...we have no such restriction under Linux though.

Quoted 8 lines

I liked this approach for two reasons. It handles a convention for IPv6 formatting that is used that we don't support and allows us to (in the future) parse an address from the path instead of having to use --ip=, which I feel is a bit cumbersome. Originally I was going to just put in support for something like "mount.cifs //IPv6Address/share /mnt/path" right away, but I wanted to get this part in first.

Quoted 4 lines

Again, I'm confused...this sort of syntax seems to work just fine already:

    # mount -t cifs //fecd::1/share /mnt/cifs -o sec=none,multiuser

Hrm, I thought that didn't work (or, more likely, my test environment had some other problem).

Quoted 5 lines

Also, --ip= is not a valid option in the longopts[] array in mount.cifs (maybe you mean -o ip=). I still don't see what benefit we receive from allowing someone specify addresses inside of square brackets.

Sorry, posted before my first cup of coffee; -o ip= is what I meant to say.

Since this already works, I'm inclined to agree that this patch brings nothing to the table.

--
Peace and Blessings,
-Scott.

#16 lore raw

Re: [PATCH] mount.cifs: add support for IPv6 addresses in brackets V2

In reply to a message not in the archive
Quoted 11 lines · Jeff Layton
Quoted 8 lines · On Tue, 23 Apr 2013 08:34:14 -0400 Scott Lovenberg…
Quoted 7 lines · Jeff Layton
Quoted 3 lines

Ping.
Any comments?

I guess I don't quite understand why we need this patch. For NFS it's pretty clear that we would since ':' has always served as the delimiter between the hostname and the pathname.

I am ok with the idea of adding additional support that looks more
like what an NFS user is comfortable with. Ideally a user should be
able to type very similar mount commands for cifs/smb3 and NFSv3/v4 etc.

Scott,
Can you give a list of an example of these - mounts with each of the IPv6 formats that work (and what doesn't work) along with the one you propose?

Quoted 33 lines
Quoted 12 lines
Quoted 11 lines

For CIFS, not so much... IPv6 addresses typically don't have '/' or '\\' characters in them, so why do we need to wrap them in []?

Note that this syntax doesn't follow what Windows does either, AFAIK. There, you need something like this since UNC paths can't contain ':' characters (and maybe also '%'):

http://www.samba.org/~idra/code/nss-ipv6literal/README.html

...we have no such restriction under Linux though.

Quoted 8 lines

I liked this approach for two reasons. It handles a convention for IPv6 formatting that is used that we don't support and allows us to (in the future) parse an address from the path instead of having to use --ip=, which I feel is a bit cumbersome. Originally I was going to just put in support for something like "mount.cifs //IPv6Address/share /mnt/path" right away, but I wanted to get this part in first.

Again, I'm confused...this sort of syntax seems to work just fine already:

    # mount -t cifs //fecd::1/share /mnt/cifs -o sec=none,multiuser

Also, --ip= is not a valid option in the longopts[] array in mount.cifs (maybe you mean -o ip=). I still don't see what benefit we receive from allowing someone specify addresses inside of square brackets.

--
Jeff Layton <[email protected]>

Signature · 3 lines
Thanks,

Steve

A message that is not in the archive (sent off-list or not yet received): CAH2r5ms4pcD--VzekvfoOL9WU-hS1KEFB2OZVmkb1z8aekhwGg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#18 lore raw

Re: [PATCH] mount.cifs: add support for IPv6 addresses in brackets V2

Quoted 10 lines · Steve French
Quoted 3 lines · Jeff Layton
Quoted 3 lines
Quoted 3 lines

I guess I don't quite understand why we need this patch. For NFS it's pretty clear that we would since ':' has always served as the delimiter between the hostname and the pathname.

I am ok with the idea of adding additional support that looks more
like what an NFS user is comfortable with. Ideally a user should be
able to type very similar mount commands for cifs/smb3 and NFSv3/v4 etc.

Quoted 4 lines

Scott,
Can you give a list of an example of these - mounts with each of the IPv6 formats that work (and what doesn't work) along with the one you propose?

I can get that together.

--
Peace and Blessings,
-Scott.