linux-cifs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Elijah Conners <business@elijahpepe.com>
To: "linux-cifs" <linux-cifs@vger.kernel.org>,
	"samba-technical" <samba-technical@lists.samba.org>
Cc: "tom" <tom@talpey.com>, "pc" <pc@cjr.nz>,
	"sfrench" <sfrench@samba.org>, "lsahlber" <lsahlber@redhat.com>,
	"sprasad" <sprasad@microsoft.com>
Subject: [PATCH v4] cifs: add ipv6 parsing
Date: Tue, 06 Dec 2022 18:37:24 -0800	[thread overview]
Message-ID: <184ea71e92a.115993f353574592.7325889929528068981@elijahpepe.com> (raw)
In-Reply-To: 

CIFS currently lacks IPv6 parsing, presenting complications for CIFS
over IPv6.

To parse both IPv4 and IPv6 addresses, the parse_srvaddr() function
was altered; parse_srvaddr() now returns void. To retrieve the IP
address from parse_srvaddr(), the parameters *out6 and *out32, an
in6_addr and a __be32 respectively, are provided. The value of
root_server_addr is determined by if those parameters are set or not.

The parsing in parse_srvaddr() was updated slightly. The character addr
can hold up to 46 characters, the longest a possible IPv6 address can
be. In the while loop, isdigit() has been replaced with isxdigit() to
account for letters present in IPv6 addresses, and *start is also
checked for being a colon. Finally, the function uses inet_pton() to
determine if the address is an IPv6 address; if so, *out6 is equal to
in6, set by inet_pton, otherwise, *out32 is set to in_aton(addr).

Signed-off-by: Elijah Conners <business@elijahpepe.com>
---
 fs/cifs/cifsroot.c | 27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/fs/cifs/cifsroot.c b/fs/cifs/cifsroot.c
index 9e91a5a40aae..f776508d558b 100644
--- a/fs/cifs/cifsroot.c
+++ b/fs/cifs/cifsroot.c
@@ -14,6 +14,7 @@
 #include <linux/in.h>
 #include <linux/inet.h>
 #include <net/ipconfig.h>
+#include <arpa/inet.h>
 
 #define DEFAULT_MNT_OPTS \
 	"vers=1.0,cifsacl,mfsymlinks,rsize=1048576,wsize=65536,uid=0,gid=0," \
@@ -22,19 +23,24 @@
 static char root_dev[2048] __initdata = "";
 static char root_opts[1024] __initdata = DEFAULT_MNT_OPTS;
 
-static __be32 __init parse_srvaddr(char *start, char *end)
+static void __init parse_srvaddr(char *start, char *end, struct in6_addr *out6, __be32 *out32)
 {
-	/* TODO: ipv6 support */
-	char addr[sizeof("aaa.bbb.ccc.ddd")];
+	char addr[INET6_ADDRSTRLEN];
+	struct in6_addr in6;
 	int i = 0;
 
 	while (start < end && i < sizeof(addr) - 1) {
-		if (isdigit(*start) || *start == '.')
+		if (isxdigit(*start) || *start == '.' || *start == ':')
 			addr[i++] = *start;
 		start++;
 	}
 	addr[i] = '\0';
-	return in_aton(addr);
+
+	if (inet_pton(AF_INET6, addr, &in6) > 0) {
+		*out6 = in6;
+	} else {
+		*out32 = in_aton(addr);
+	}
 }
 
 /* cifsroot=//<server-ip>/<share>[,options] */
@@ -42,7 +48,8 @@ static int __init cifs_root_setup(char *line)
 {
 	char *s;
 	int len;
-	__be32 srvaddr = htonl(INADDR_NONE);
+	struct in6_addr addr6;
+	__be32 addr32;
 
 	ROOT_DEV = Root_CIFS;
 
@@ -60,7 +67,7 @@ static int __init cifs_root_setup(char *line)
 			return 1;
 		}
 		strlcpy(root_dev, line, len);
-		srvaddr = parse_srvaddr(&line[2], s);
+		parse_srvaddr(&line[2], s, &addr6, &addr32);
 		if (*s) {
 			int n = snprintf(root_opts,
 					 sizeof(root_opts), "%s,%s",
@@ -73,7 +80,11 @@ static int __init cifs_root_setup(char *line)
 		}
 	}
 
-	root_server_addr = srvaddr;
+	if (addr6.is_set) {
+		root_server_addr = addr6;
+	} else if (addr32.is_set) {
+		root_server_addr = addr32;
+	}
 
 	return 1;
 }
-- 
2.29.2.windows.2



             reply	other threads:[~2022-12-07  2:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-07  2:37 Elijah Conners [this message]
2022-12-07  2:40 ` [PATCH v4] cifs: add ipv6 parsing Elijah Conners
     [not found]   ` <CAH2r5mtagKhCc_TxJfjVkuO92A9Nk6x3K39WAarzoHhyD_ZZyw@mail.gmail.com>
2022-12-07  2:51     ` Elijah Conners
     [not found] ` <CAH2r5mtSWPg7gwa5L79jyAwas3k2eMjqp0YTJ-wJi+fshc-9tA@mail.gmail.com>
2022-12-08 14:37   ` Elijah Conners

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=184ea71e92a.115993f353574592.7325889929528068981@elijahpepe.com \
    --to=business@elijahpepe.com \
    --cc=linux-cifs@vger.kernel.org \
    --cc=lsahlber@redhat.com \
    --cc=pc@cjr.nz \
    --cc=samba-technical@lists.samba.org \
    --cc=sfrench@samba.org \
    --cc=sprasad@microsoft.com \
    --cc=tom@talpey.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).