summaryrefslogtreecommitdiff
path: root/fs/cifs/netmisc.c
diff options
context:
space:
mode:
authorJeff Layton <jlayton@redhat.com>2009-06-11 18:27:31 +0400
committerSteve French <sfrench@us.ibm.com>2009-06-25 05:14:36 +0400
commit681bf72e4893a187cf6b6b62c08fc193f81c8c2f (patch)
tree5c580474a21edf38140407bd42f28853e9354e25 /fs/cifs/netmisc.c
parent268875b9d1dd1bf0b523c59e736da9bc20c8ce1f (diff)
downloadlinux-681bf72e4893a187cf6b6b62c08fc193f81c8c2f.tar.xz
cifs: have cifs parse scope_id out of IPv6 addresses and use it
This patch has CIFS look for a '%' in an IPv6 address. If one is present then it will try to treat that value as a numeric interface index suitable for stuffing into the sin6_scope_id field. This should allow people to mount servers on IPv6 link-local addresses. Signed-off-by: Jeff Layton <jlayton@redhat.com> Acked-by: David Holder <david@erion.co.uk> Signed-off-by: Steve French <sfrench@us.ibm.com>
Diffstat (limited to 'fs/cifs/netmisc.c')
-rw-r--r--fs/cifs/netmisc.c32
1 files changed, 27 insertions, 5 deletions
diff --git a/fs/cifs/netmisc.c b/fs/cifs/netmisc.c
index f9a54da97d34..bd6d6895730d 100644
--- a/fs/cifs/netmisc.c
+++ b/fs/cifs/netmisc.c
@@ -158,25 +158,47 @@ cifs_inet_pton(const int address_family, const char *cp, void *dst)
/*
* Try to convert a string to an IPv4 address and then attempt to convert
* it to an IPv6 address if that fails. Set the family field if either
- * succeeds.
+ * succeeds. If it's an IPv6 address and it has a '%' sign in it, try to
+ * treat the part following it as a numeric sin6_scope_id.
*
* Returns 0 on failure.
*/
int
cifs_convert_address(char *src, void *dst)
{
+ int rc;
+ char *pct, *endp;
struct sockaddr_in *s4 = (struct sockaddr_in *) dst;
struct sockaddr_in6 *s6 = (struct sockaddr_in6 *) dst;
+ /* IPv4 address */
if (cifs_inet_pton(AF_INET, src, &s4->sin_addr.s_addr)) {
s4->sin_family = AF_INET;
return 1;
- } else if (cifs_inet_pton(AF_INET6, src, &s6->sin6_addr.s6_addr)) {
- s6->sin6_family = AF_INET6;
- return 1;
}
- return 0;
+ /* temporarily terminate string */
+ pct = strchr(src, '%');
+ if (pct)
+ *pct = '\0';
+
+ rc = cifs_inet_pton(AF_INET6, src, &s6->sin6_addr.s6_addr);
+
+ /* repair temp termination (if any) and make pct point to scopeid */
+ if (pct)
+ *pct++ = '%';
+
+ if (!rc)
+ return rc;
+
+ s6->sin6_family = AF_INET6;
+ if (pct) {
+ s6->sin6_scope_id = (u32) simple_strtoul(pct, &endp, 0);
+ if (!*pct || *endp)
+ return 0;
+ }
+
+ return rc;
}
/*****************************************************************************