Skip to contentSkip to conversation

nfsd: add support for NFSv4 callbacks over IPv6 (try #2)

PATCH In review Jeff Layton 3 participants 10 messages Jun 19, 2009 – Jun 22, 2009

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

cover nfsd: add support for NFSv4 callbacks over IPv6 (try #2)

Here's a second pass at adding support for NFSv4 callback channels over IPv6. The main changes since the last set are:

1) rebase to Bruce's master/for-2.6.31 branches. It applies cleanly to either.

2) cleaned up the IPv6-enablement patch: mostly this was done by removing conditional compilation from several places where it wasn't really required.

3) add patch that makes it set the sin6_scope_id for the callback address to the same value as the sin6_scope_id in the svc_rqst->rq_addr. This allows the server to call back clients that mounted the server via one of its link-local addresses.

Again, tested using opensolaris and linux clients and watching the traffic with wireshark. Everything seems to work. Delegations and recalls work fine to opensolaris.

I seem to be having some trouble getting the server to issue delegations to linux clients, but I can see the callback channel being correctly established.

I think the problem with delegations is unrelated to this set. It seems to still be a problem even with IPv4 on an unpatched kernel. I think it has something to do with how linux clients are generating open_owner ID's. I'll email the list separately about that...

Jeff Layton (5):
nfsd: convert nfs4_callback struct to hold address in
sockaddr_storage
nfsd: break out setclientid port parsing into separate routine
nfsd: make nfs4_client->cl_addr a struct sockaddr_storage
nfsd: add support for NFSv4 callbacks over IPv6
nfsd: populate sin6_scope_id on callback address with scopeid from
rq_addr on SETCLIENTID call

 fs/nfsd/nfs4callback.c     |   11 +--
 fs/nfsd/nfs4state.c        |  221 ++++++++++++++++++++++++++++++++++++--------
 include/linux/nfsd/state.h |    6 +-
 3 files changed, 189 insertions(+), 49 deletions(-)
#1 lore raw

PATCH 1/5 nfsd: convert nfs4_callback struct to hold address in sockaddr_storage

...rather than as a separate address and port fields. This will be necessary for implementing callbacks over IPv6.

---
 fs/nfsd/nfs4callback.c     |   11 ++---------
 fs/nfsd/nfs4state.c        |   13 +++++++++----
 include/linux/nfsd/state.h |    4 ++--
 3 files changed, 13 insertions(+), 15 deletions(-)
fs/nfsd/nfs4callback.c +2 -9
index 3fd23f7..81d1c52 100644
@@ -377,7 +377,6 @@ static int max_cb_time(void)
 
 int setup_callback_client(struct nfs4_client *clp)
 {
-	struct sockaddr_in	addr;
 	struct nfs4_cb_conn *cb = &clp->cl_cb_conn;
 	struct rpc_timeout	timeparms = {
 		.to_initval	= max_cb_time(),
@@ -385,8 +384,8 @@ int setup_callback_client(struct nfs4_client *clp)
 	};
 	struct rpc_create_args args = {
 		.protocol	= IPPROTO_TCP,
-		.address	= (struct sockaddr *)&addr,
-		.addrsize	= sizeof(addr),
+		.address	= (struct sockaddr *) &cb->cb_addr,
+		.addrsize	= cb->cb_addrlen,
 		.timeout	= &timeparms,
 		.program	= &cb_program,
 		.prognumber	= cb->cb_prog,
@@ -400,12 +399,6 @@ int setup_callback_client(struct nfs4_client *clp)
 	if (!clp->cl_principal && (clp->cl_flavor >= RPC_AUTH_GSS_KRB5))
 		return -EINVAL;
 
-	/* Initialize address */
-	memset(&addr, 0, sizeof(addr));
-	addr.sin_family = AF_INET;
-	addr.sin_port = htons(cb->cb_port);
-	addr.sin_addr.s_addr = htonl(cb->cb_addr);
-
 	/* Create RPC client */
 	client = rpc_create(&args);
 	if (IS_ERR(client)) {
fs/nfsd/nfs4state.c +9 -4
index 980a216..d9ef1ea 100644
@@ -937,7 +937,7 @@ parse_octet(unsigned int *lenp, char **addrp)
 
 /* parse and set the setclientid ipv4 callback address */
 static int
-parse_ipv4(unsigned int addr_len, char *addr_val, unsigned int *cbaddrp, unsigned short *cbportp)
+parse_ipv4(unsigned int addr_len, char *addr_val, struct sockaddr_in *s4)
 {
 	int temp = 0;
 	u32 cbaddr = 0;
@@ -946,6 +946,8 @@ parse_ipv4(unsigned int addr_len, char *addr_val, unsigned int *cbaddrp, unsigne
 	char *addr = addr_val;
 	int i, shift;
 
+	s4->sin_family = AF_INET;
+
 	/* ipaddress */
 	shift = 24;
 	for(i = 4; i > 0  ; i--) {
@@ -956,7 +958,7 @@ parse_ipv4(unsigned int addr_len, char *addr_val, unsigned int *cbaddrp, unsigne
 		if (shift > 0)
 		shift -= 8;
 	}
-	*cbaddrp = cbaddr;
+	s4->sin_addr.s_addr = htonl(cbaddr);
 
 	/* port */
 	shift = 8;
@@ -968,7 +970,7 @@ parse_ipv4(unsigned int addr_len, char *addr_val, unsigned int *cbaddrp, unsigne
 		if (shift > 0)
 			shift -= 8;
 	}
-	*cbportp = cbport;
+	s4->sin_port = htons(cbport);
 	return 1;
 }
 
@@ -982,13 +984,16 @@ gen_callback(struct nfs4_client *clp, struct nfsd4_setclientid *se)
 		goto out_err;
 
 	if ( !(parse_ipv4(se->se_callback_addr_len, se->se_callback_addr_val,
-	                 &cb->cb_addr, &cb->cb_port)))
+			  (struct sockaddr_in *) &cb->cb_addr)))
 		goto out_err;
+	cb->cb_addrlen = sizeof(struct sockaddr_in);
 	cb->cb_minorversion = 0;
 	cb->cb_prog = se->se_callback_prog;
 	cb->cb_ident = se->se_callback_ident;
 	return;
 out_err:
+	cb->cb_addr.ss_family = AF_UNSPEC;
+	cb->cb_addrlen = 0;
 	dprintk(KERN_INFO "NFSD: this client (clientid %08x/%08x) "
 		"will not receive delegations\n",
 		clp->cl_clientid.cl_boot, clp->cl_clientid.cl_id);
include/linux/nfsd/state.h +2 -2
index 57ab2ed..0669a1e 100644
@@ -81,8 +81,8 @@ struct nfs4_delegation {
 /* client delegation callback info */
 struct nfs4_cb_conn {
 	/* SETCLIENTID info */
-	u32                     cb_addr;
-	unsigned short          cb_port;
+	struct sockaddr_storage	cb_addr;
+	size_t			cb_addrlen;
 	u32                     cb_prog;
 	u32			cb_minorversion;
 	u32                     cb_ident;	/* minorversion 0 only */
Signature · 1 line
1.6.0.6
#2 lore raw

PATCH 2/5 nfsd: break out setclientid port parsing into separate routine

In reply to Jeff Layton

...and change the parse_ipv4 routine to be a little more efficient with the stack.

---
 fs/nfsd/nfs4state.c |   46 ++++++++++++++++++++++++++++++----------------
 1 files changed, 30 insertions(+), 16 deletions(-)
fs/nfsd/nfs4state.c +30 -16
index d9ef1ea..92512de 100644
@@ -935,15 +935,40 @@ parse_octet(unsigned int *lenp, char **addrp)
 	return n;
 }
 
+/*
+ * Parse port out of setclientid callback address
+ *
+ * @addrlen: remaining length of address string
+ * @addr: pointer to first port octet in address string
+ * @sa: pointer to port field in sockaddr
+ *
+ * Parse the port portion of a setclientid callback address. Returns true on
+ * success and false on failure.
+ */
+static bool
+parse_port(unsigned int addrlen, char *addr, __be16 *port)
+{
+	int temp = 0, i, shift = 8;
+	u16 cbport = 0;
+
+	for (i = 2; i > 0; i--) {
+		temp = parse_octet(&addrlen, &addr);
+		if (temp < 0)
+			return 0;
+		cbport |= (temp << shift);
+		if (shift > 0)
+			shift -= 8;
+	}
+	*port = htons(cbport);
+	return 1;
+}
+
 /* parse and set the setclientid ipv4 callback address */
 static int
-parse_ipv4(unsigned int addr_len, char *addr_val, struct sockaddr_in *s4)
+parse_ipv4(unsigned int addrlen, char *addr, struct sockaddr_in *s4)
 {
 	int temp = 0;
 	u32 cbaddr = 0;
-	u16 cbport = 0;
-	u32 addrlen = addr_len;
-	char *addr = addr_val;
 	int i, shift;
 
 	s4->sin_family = AF_INET;
@@ -960,18 +985,7 @@ parse_ipv4(unsigned int addr_len, char *addr_val, struct sockaddr_in *s4)
 	}
 	s4->sin_addr.s_addr = htonl(cbaddr);
 
-	/* port */
-	shift = 8;
-	for(i = 2; i > 0  ; i--) {
-		if ((temp = parse_octet(&addrlen, &addr)) < 0) {
-			return 0;
-		}
-		cbport |= (temp << shift);
-		if (shift > 0)
-			shift -= 8;
-	}
-	s4->sin_port = htons(cbport);
-	return 1;
+	return parse_port(addrlen, addr, &s4->sin_port);
 }
 
 static void
Signature · 1 line
1.6.0.6
#3 lore raw

PATCH 3/5 nfsd: make nfs4_client->cl_addr a struct sockaddr_storage

In reply to Jeff Layton

It's currently a __be32, which isn't big enough to hold an IPv6 address. While we're at it, add some new routines for comparing and copying cl_addr's, and a function for formatting a cl_addr into a string.

---
 fs/nfsd/nfs4state.c        |   88 +++++++++++++++++++++++++++++++++++++------
 include/linux/nfsd/state.h |    2 +-
 2 files changed, 76 insertions(+), 14 deletions(-)
fs/nfsd/nfs4state.c +75 -13
index 92512de..c50f020 100644
@@ -1204,6 +1204,62 @@ nfsd4_set_ex_flags(struct nfs4_client *new, struct nfsd4_exchange_id *clid)
 	clid->flags = new->cl_exchange_flags;
 }
 
+/* Returns true if addresses are equal (ignoring port, scope, etc) */
+static bool
+cl_addr_equal(struct sockaddr *a, struct sockaddr *b)
+{
+	struct sockaddr_in *a4, *b4;
+
+	if (a->sa_family != b->sa_family)
+		return false;
+
+	switch (a->sa_family) {
+	case AF_INET:
+		a4 = (struct sockaddr_in *) a;
+		b4 = (struct sockaddr_in *) b;
+		return (a4->sin_addr.s_addr == b4->sin_addr.s_addr);
+	}
+
+	/* not sure how to compare, so just return false */
+	return false;
+}
+
+/* Given a sockaddr, fill in the cl_addr -- ignore port, scope, etc */
+static void
+cl_addr_copy(struct sockaddr *dst, struct sockaddr *src)
+{
+	struct sockaddr_in *s4, *d4;
+
+	dst->sa_family = src->sa_family;
+
+	switch (dst->sa_family) {
+	case AF_INET:
+		s4 = (struct sockaddr_in *) src;
+		d4 = (struct sockaddr_in *) dst;
+		d4->sin_addr.s_addr = s4->sin_addr.s_addr;
+		return;
+	default:
+		dst->sa_family = AF_UNSPEC;
+	}
+}
+
+/* format the cl_addr as text and stuff it into buf. Don't go beyond size. */
+static void
+cl_addr_snprintf(char *buf, size_t size, struct sockaddr *sa)
+{
+	switch (sa->sa_family) {
+	case AF_INET:
+		snprintf(buf, size, "%pI4",
+			 &((struct sockaddr_in *) sa)->sin_addr.s_addr);
+		break;
+	default:
+		snprintf(buf, size, "(family=%hu)", sa->sa_family);
+	}
+
+	/* forcibly NULL terminate string, just in case */
+	buf[size - 1] = '\0';
+}
+
 __be32
 nfsd4_exchange_id(struct svc_rqst *rqstp,
 		  struct nfsd4_compound_state *cstate,
@@ -1213,13 +1269,15 @@ nfsd4_exchange_id(struct svc_rqst *rqstp,
 	int status;
 	unsigned int		strhashval;
 	char			dname[HEXDIR_LEN];
+	char			addr_str[INET_ADDRSTRLEN];
 	nfs4_verifier		verf = exid->verifier;
-	u32			ip_addr = svc_addr_in(rqstp)->sin_addr.s_addr;
+	struct sockaddr		*sa = svc_addr(rqstp);
 
+	cl_addr_snprintf(addr_str, INET_ADDRSTRLEN, sa);
 	dprintk("%s rqstp=%p exid=%p clname.len=%u clname.data=%p "
-		" ip_addr=%u flags %x, spa_how %d\n",
+		"ip_addr=%s flags %x, spa_how %d\n",
 		__func__, rqstp, exid, exid->clname.len, exid->clname.data,
-		ip_addr, exid->flags, exid->spa_how);
+		addr_str, exid->flags, exid->spa_how);
 
 	if (!check_name(exid->clname) || (exid->flags & ~EXCHGID4_FLAG_MASK_A))
 		return nfserr_inval;
@@ -1267,6 +1325,7 @@ nfsd4_exchange_id(struct svc_rqst *rqstp,
 			expire_client(conf);
 			goto out_new;
 		}
+
 		/*
 		 * Set bit when the owner id and verifier map to an already
 		 * confirmed client id (18.35.3).
@@ -1308,7 +1367,7 @@ out_new:
 
 	copy_verf(new, &verf);
 	copy_cred(&new->cl_cred, &rqstp->rq_cred);
-	new->cl_addr = ip_addr;
+	cl_addr_copy((struct sockaddr *) &new->cl_addr, sa);
 	gen_clid(new);
 	gen_confirm(new);
 	add_to_unconfirmed(new, strhashval);
@@ -1362,7 +1421,7 @@ nfsd4_create_session(struct svc_rqst *rqstp,
 		     struct nfsd4_compound_state *cstate,
 		     struct nfsd4_create_session *cr_ses)
 {
-	u32 ip_addr = svc_addr_in(rqstp)->sin_addr.s_addr;
+	struct sockaddr *sa = svc_addr(rqstp);
 	struct nfsd4_compoundres *resp = rqstp->rq_resp;
 	struct nfs4_client *conf, *unconf;
 	struct nfsd4_slot *slot = NULL;
@@ -1393,7 +1452,7 @@ nfsd4_create_session(struct svc_rqst *rqstp,
 		conf->cl_slot.sl_seqid++;
 	} else if (unconf) {
 		if (!same_creds(&unconf->cl_cred, &rqstp->rq_cred) ||
-		    (ip_addr != unconf->cl_addr)) {
+		    !cl_addr_equal(sa, (struct sockaddr *) &unconf->cl_addr)) {
 			status = nfserr_clid_inuse;
 			goto out;
 		}
@@ -1541,7 +1600,7 @@ __be32
 nfsd4_setclientid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
 		  struct nfsd4_setclientid *setclid)
 {
-	struct sockaddr_in	*sin = svc_addr_in(rqstp);
+	struct sockaddr		*sa = svc_addr(rqstp);
 	struct xdr_netobj 	clname = { 
 		.len = setclid->se_namelen,
 		.data = setclid->se_name,
@@ -1573,8 +1632,11 @@ nfsd4_setclientid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
 		/* RFC 3530 14.2.33 CASE 0: */
 		status = nfserr_clid_inuse;
 		if (!same_creds(&conf->cl_cred, &rqstp->rq_cred)) {
-			dprintk("NFSD: setclientid: string in use by client"
-				" at %pI4\n", &conf->cl_addr);
+			char addr_str[INET_ADDRSTRLEN];
+			cl_addr_snprintf(addr_str, INET_ADDRSTRLEN,
+					 (struct sockaddr *) &conf->cl_addr);
+			dprintk("NFSD: setclientid: string in use by client "
+				"at %s\n", addr_str);
 			goto out;
 		}
 	}
@@ -1636,7 +1698,7 @@ nfsd4_setclientid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
 		gen_clid(new);
 	}
 	copy_verf(new, &clverifier);
-	new->cl_addr = sin->sin_addr.s_addr;
+	cl_addr_copy((struct sockaddr *) &new->cl_addr, sa);
 	new->cl_flavor = rqstp->rq_flavor;
 	princ = svc_gss_principal(rqstp);
 	if (princ) {
@@ -1670,7 +1732,7 @@ nfsd4_setclientid_confirm(struct svc_rqst *rqstp,
 			 struct nfsd4_compound_state *cstate,
 			 struct nfsd4_setclientid_confirm *setclientid_confirm)
 {
-	struct sockaddr_in *sin = svc_addr_in(rqstp);
+	struct sockaddr *sa = svc_addr(rqstp);
 	struct nfs4_client *conf, *unconf;
 	nfs4_verifier confirm = setclientid_confirm->sc_confirm; 
 	clientid_t * clid = &setclientid_confirm->sc_clientid;
@@ -1689,9 +1751,9 @@ nfsd4_setclientid_confirm(struct svc_rqst *rqstp,
 	unconf = find_unconfirmed_client(clid);
 
 	status = nfserr_clid_inuse;
-	if (conf && conf->cl_addr != sin->sin_addr.s_addr)
+	if (conf && !cl_addr_equal((struct sockaddr *) &conf->cl_addr, sa))
 		goto out;
-	if (unconf && unconf->cl_addr != sin->sin_addr.s_addr)
+	if (unconf && !cl_addr_equal((struct sockaddr *) &unconf->cl_addr, sa))
 		goto out;
 
 	/*
include/linux/nfsd/state.h +1 -1
index 0669a1e..d55a64f 100644
@@ -180,7 +180,7 @@ struct nfs4_client {
 	char                    cl_recdir[HEXDIR_LEN]; /* recovery dir */
 	nfs4_verifier		cl_verifier; 	/* generated by client */
 	time_t                  cl_time;        /* time of last lease renewal */
-	__be32			cl_addr; 	/* client ipaddress */
+	struct sockaddr_storage	cl_addr; 	/* client ipaddress */
 	u32			cl_flavor;	/* setclientid pseudoflavor */
 	char			*cl_principal;	/* setclientid principal name */
 	struct svc_cred		cl_cred; 	/* setclientid principal */
Signature · 1 line
1.6.0.6
#4 lore raw

PATCH 4/5 nfsd: add support for NFSv4 callbacks over IPv6

In reply to Jeff Layton

The framework to add this is all in place. Now, add the code to allow support for establishing a callback channel on an IPv6 socket.

---
 fs/nfsd/nfs4state.c |   76 ++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 66 insertions(+), 10 deletions(-)
fs/nfsd/nfs4state.c +66 -10
index c50f020..4e9d5d9 100644
@@ -55,6 +55,8 @@
 #include <linux/lockd/bind.h>
 #include <linux/module.h>
 #include <linux/sunrpc/svcauth_gss.h>
+#include <linux/inet.h>
+#include <net/ipv6.h>
 
 #define NFSDDBG_FACILITY                NFSDDBG_PROC
 
@@ -988,19 +990,58 @@ parse_ipv4(unsigned int addrlen, char *addr, struct sockaddr_in *s4)
 	return parse_port(addrlen, addr, &s4->sin_port);
 }
 
+#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
+static int
+parse_ipv6(unsigned int addrlen, char *addr, struct sockaddr_in6 *s6)
+{
+	char *dot;
+
+	s6->sin6_family = AF_INET6;
+
+	if (!in6_pton(addr, addrlen, (u8 *) &s6->sin6_addr.s6_addr, '.',
+		      (const char **) &dot))
+		return 0;
+
+	if ((addr + addrlen) <= dot)
+		return 0;
+
+	if (*dot++ != '.')
+		return 0;
+
+	return parse_port(addrlen - (dot - addr), dot, &s6->sin6_port);
+}
+#else /* defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) */
+static int
+parse_ipv6(unsigned int addrlen, char *addr, struct sockaddr_in6 *s6)
+{
+	return 0;
+}
+#endif /* defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) */
+
 static void
 gen_callback(struct nfs4_client *clp, struct nfsd4_setclientid *se)
 {
 	struct nfs4_cb_conn *cb = &clp->cl_cb_conn;
 
-	/* Currently, we only support tcp for the callback channel */
-	if ((se->se_callback_netid_len != 3) || memcmp((char *)se->se_callback_netid_val, "tcp", 3))
+	/* Currently, we only support tcp and tcp6 for the callback channel */
+	if (se->se_callback_netid_len == 3 &&
+	    !memcmp(se->se_callback_netid_val, "tcp", 3)) {
+		if (!parse_ipv4(se->se_callback_addr_len,
+				se->se_callback_addr_val,
+				(struct sockaddr_in *) &cb->cb_addr))
+			goto out_err;
+		cb->cb_addrlen = sizeof(struct sockaddr_in);
+	} else if (se->se_callback_netid_len == 4 &&
+		   !memcmp(se->se_callback_netid_val, "tcp6", 4)) {
+		if (!parse_ipv6(se->se_callback_addr_len,
+				se->se_callback_addr_val,
+				(struct sockaddr_in6 *) &cb->cb_addr))
+			goto out_err;
+		cb->cb_addrlen = sizeof(struct sockaddr_in6);
+	} else {
 		goto out_err;
+	}
 
-	if ( !(parse_ipv4(se->se_callback_addr_len, se->se_callback_addr_val,
-			  (struct sockaddr_in *) &cb->cb_addr)))
-		goto out_err;
-	cb->cb_addrlen = sizeof(struct sockaddr_in);
 	cb->cb_minorversion = 0;
 	cb->cb_prog = se->se_callback_prog;
 	cb->cb_ident = se->se_callback_ident;
@@ -1209,6 +1250,7 @@ static bool
 cl_addr_equal(struct sockaddr *a, struct sockaddr *b)
 {
 	struct sockaddr_in *a4, *b4;
+	struct sockaddr_in6 *a6, *b6;
 
 	if (a->sa_family != b->sa_family)
 		return false;
@@ -1218,6 +1260,10 @@ cl_addr_equal(struct sockaddr *a, struct sockaddr *b)
 		a4 = (struct sockaddr_in *) a;
 		b4 = (struct sockaddr_in *) b;
 		return (a4->sin_addr.s_addr == b4->sin_addr.s_addr);
+	case AF_INET6:
+		a6 = (struct sockaddr_in6 *) a;
+		b6 = (struct sockaddr_in6 *) b;
+		return ipv6_addr_equal(&a6->sin6_addr, &b6->sin6_addr);
 	}
 
 	/* not sure how to compare, so just return false */
@@ -1229,6 +1275,7 @@ static void
 cl_addr_copy(struct sockaddr *dst, struct sockaddr *src)
 {
 	struct sockaddr_in *s4, *d4;
+	struct sockaddr_in6 *s6, *d6;
 
 	dst->sa_family = src->sa_family;
 
@@ -1238,6 +1285,11 @@ cl_addr_copy(struct sockaddr *dst, struct sockaddr *src)
 		d4 = (struct sockaddr_in *) dst;
 		d4->sin_addr.s_addr = s4->sin_addr.s_addr;
 		return;
+	case AF_INET6:
+		s6 = (struct sockaddr_in6 *) src;
+		d6 = (struct sockaddr_in6 *) dst;
+		ipv6_addr_copy(&d6->sin6_addr, &s6->sin6_addr);
+		return;
 	default:
 		dst->sa_family = AF_UNSPEC;
 	}
@@ -1252,6 +1304,10 @@ cl_addr_snprintf(char *buf, size_t size, struct sockaddr *sa)
 		snprintf(buf, size, "%pI4",
 			 &((struct sockaddr_in *) sa)->sin_addr.s_addr);
 		break;
+	case AF_INET6:
+		snprintf(buf, size, "%pI6",
+			 &((struct sockaddr_in6 *) sa)->sin6_addr.s6_addr);
+		break;
 	default:
 		snprintf(buf, size, "(family=%hu)", sa->sa_family);
 	}
@@ -1269,11 +1325,11 @@ nfsd4_exchange_id(struct svc_rqst *rqstp,
 	int status;
 	unsigned int		strhashval;
 	char			dname[HEXDIR_LEN];
-	char			addr_str[INET_ADDRSTRLEN];
+	char			addr_str[INET6_ADDRSTRLEN];
 	nfs4_verifier		verf = exid->verifier;
 	struct sockaddr		*sa = svc_addr(rqstp);
 
-	cl_addr_snprintf(addr_str, INET_ADDRSTRLEN, sa);
+	cl_addr_snprintf(addr_str, INET6_ADDRSTRLEN, sa);
 	dprintk("%s rqstp=%p exid=%p clname.len=%u clname.data=%p "
 		"ip_addr=%s flags %x, spa_how %d\n",
 		__func__, rqstp, exid, exid->clname.len, exid->clname.data,
@@ -1632,8 +1688,8 @@ nfsd4_setclientid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
 		/* RFC 3530 14.2.33 CASE 0: */
 		status = nfserr_clid_inuse;
 		if (!same_creds(&conf->cl_cred, &rqstp->rq_cred)) {
-			char addr_str[INET_ADDRSTRLEN];
-			cl_addr_snprintf(addr_str, INET_ADDRSTRLEN,
+			char addr_str[INET6_ADDRSTRLEN];
+			cl_addr_snprintf(addr_str, INET6_ADDRSTRLEN,
 					 (struct sockaddr *) &conf->cl_addr);
 			dprintk("NFSD: setclientid: string in use by client "
 				"at %s\n", addr_str);
Signature · 1 line
1.6.0.6
#5 lore raw

PATCH 5/5 nfsd: populate sin6_scope_id on callback address with scopeid from rq_addr on SETCLIENTID call

In reply to Jeff Layton

When a SETCLIENTID call comes in, one of the args given is the svc_rqst. This struct contains an rq_addr field which holds the address that sent the call. If this is an IPv6 address, then we can use the sin6_scope_id field in this address to populate the sin6_scope_id field in the callback address.

AFAICT, the rq_addr.sin6_scope_id is non-zero if and only if the client mounted the server's link-local address.

---
 fs/nfsd/nfs4state.c |   14 ++++++++++++--
 1 files changed, 12 insertions(+), 2 deletions(-)
fs/nfsd/nfs4state.c +12 -2
index 4e9d5d9..d98d95c 100644
@@ -1019,7 +1019,7 @@ parse_ipv6(unsigned int addrlen, char *addr, struct sockaddr_in6 *s6)
 #endif /* defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) */
 
 static void
-gen_callback(struct nfs4_client *clp, struct nfsd4_setclientid *se)
+gen_callback(struct nfs4_client *clp, struct nfsd4_setclientid *se, u32 scopeid)
 {
 	struct nfs4_cb_conn *cb = &clp->cl_cb_conn;
 
@@ -1037,6 +1037,7 @@ gen_callback(struct nfs4_client *clp, struct nfsd4_setclientid *se)
 				se->se_callback_addr_val,
 				(struct sockaddr_in6 *) &cb->cb_addr))
 			goto out_err;
+		((struct sockaddr_in6 *) &cb->cb_addr)->sin6_scope_id = scopeid;
 		cb->cb_addrlen = sizeof(struct sockaddr_in6);
 	} else {
 		goto out_err;
@@ -1652,6 +1653,15 @@ out:
 	return status;
 }
 
+static u32
+get_scope_id(struct sockaddr *sa)
+{
+	if (sa->sa_family != AF_INET6)
+		return 0;
+
+	return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
+}
+
 __be32
 nfsd4_setclientid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
 		  struct nfsd4_setclientid *setclid)
@@ -1766,7 +1776,7 @@ nfsd4_setclientid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
 	}
 	copy_cred(&new->cl_cred, &rqstp->rq_cred);
 	gen_confirm(new);
-	gen_callback(new, setclid);
+	gen_callback(new, setclid, get_scope_id(sa));
 	add_to_unconfirmed(new, strhashval);
 	setclid->se_clientid.cl_boot = new->cl_clientid.cl_boot;
 	setclid->se_clientid.cl_id = new->cl_clientid.cl_id;
Signature · 1 line
1.6.0.6
#6 lore raw
In reply to Jeff Layton
Quoted 19 lines · Jeff Layton

Here's a second pass at adding support for NFSv4 callback channels over IPv6. The main changes since the last set are:

1) rebase to Bruce's master/for-2.6.31 branches. It applies cleanly to either.

2) cleaned up the IPv6-enablement patch: mostly this was done by removing conditional compilation from several places where it wasn't really required.

3) add patch that makes it set the sin6_scope_id for the callback address to the same value as the sin6_scope_id in the svc_rqst->rq_addr. This allows the server to call back clients that mounted the server via one of its link-local addresses.

Again, tested using opensolaris and linux clients and watching the traffic with wireshark. Everything seems to work. Delegations and recalls work fine to opensolaris.

Quoted 8 lines

I seem to be having some trouble getting the server to issue delegations to linux clients, but I can see the callback channel being correctly established.

I think the problem with delegations is unrelated to this set. It seems to still be a problem even with IPv4 on an unpatched kernel. I think it has something to do with how linux clients are generating open_owner ID's. I'll email the list separately about that...

The usual problem here is just that delegations aren't given out on first use of an open_owner. You'll probably need to open the file twice.

--b.

Quoted 15 lines

Jeff Layton (5):
nfsd: convert nfs4_callback struct to hold address in
sockaddr_storage
nfsd: break out setclientid port parsing into separate routine
nfsd: make nfs4_client->cl_addr a struct sockaddr_storage
nfsd: add support for NFSv4 callbacks over IPv6
nfsd: populate sin6_scope_id on callback address with scopeid from
rq_addr on SETCLIENTID call

 fs/nfsd/nfs4callback.c     |   11 +--
 fs/nfsd/nfs4state.c        |  221 ++++++++++++++++++++++++++++++++++++--------
 include/linux/nfsd/state.h |    6 +-
 3 files changed, 189 insertions(+), 49 deletions(-)
#7 lore raw
Quoted 24 lines · On Fri, 19 Jun 2009 15:58:10 -0400 "J. Bruce Fields" <[email protected]>…
Quoted 23 lines · Jeff Layton

Here's a second pass at adding support for NFSv4 callback channels over IPv6. The main changes since the last set are:

1) rebase to Bruce's master/for-2.6.31 branches. It applies cleanly to either.

2) cleaned up the IPv6-enablement patch: mostly this was done by removing conditional compilation from several places where it wasn't really required.

3) add patch that makes it set the sin6_scope_id for the callback address to the same value as the sin6_scope_id in the svc_rqst->rq_addr. This allows the server to call back clients that mounted the server via one of its link-local addresses.

Again, tested using opensolaris and linux clients and watching the traffic with wireshark. Everything seems to work. Delegations and recalls work fine to opensolaris.

I seem to be having some trouble getting the server to issue delegations to linux clients, but I can see the callback channel being correctly established.

Quoted 9 lines
Quoted 4 lines

I think the problem with delegations is unrelated to this set. It seems to still be a problem even with IPv4 on an unpatched kernel. I think it has something to do with how linux clients are generating open_owner ID's. I'll email the list separately about that...

The usual problem here is just that delegations aren't given out on first use of an open_owner. You'll probably need to open the file twice.

Yep I tried that and it still didn't work. Looks like the client is generating a different open_owner on each open call. I even tried having the same process open and close the file multiple times and it generated a different open_owner for each open call.

For the record, the client is running a Fedora 11 kernel:

2.6.29.4-167.fc11.x86_64

...I need to dig a little deeper when I get some time, but I'm pretty sure it's a client problem.

Signature · 1 line
Jeff Layton <[email protected]>
#8 lore raw
In reply to Jeff Layton
Quoted 10 lines · Jeff Layton

Here's a second pass at adding support for NFSv4 callback channels over IPv6. The main changes since the last set are:

1) rebase to Bruce's master/for-2.6.31 branches. It applies cleanly to either.

2) cleaned up the IPv6-enablement patch: mostly this was done by removing conditional compilation from several places where it wasn't really required.

Quoted 5 lines

3) add patch that makes it set the sin6_scope_id for the callback address to the same value as the sin6_scope_id in the svc_rqst-

Quoted 1 line

rq_addr.

This allows the server to call back clients that mounted the server via one of its link-local addresses.

The rpcbind XDR patches I'm working on provide a full universal address 2 sockaddr conversion capability in sunrpc.ko, since several unrelated features in NFS/NFSD/sunrpc appear to require it. I think the server-side callback client should use this common code instead of having its own version.

The new code is in my git repo; you should be able to pull HEAD to have a look.

Quoted 24 lines

Again, tested using opensolaris and linux clients and watching the traffic with wireshark. Everything seems to work. Delegations and recalls work fine to opensolaris.

I seem to be having some trouble getting the server to issue delegations to linux clients, but I can see the callback channel being correctly established.

I think the problem with delegations is unrelated to this set. It seems to still be a problem even with IPv4 on an unpatched kernel. I think it has something to do with how linux clients are generating open_owner ID's. I'll email the list separately about that...

Jeff Layton (5):
nfsd: convert nfs4_callback struct to hold address in
sockaddr_storage
nfsd: break out setclientid port parsing into separate routine
nfsd: make nfs4_client->cl_addr a struct sockaddr_storage
nfsd: add support for NFSv4 callbacks over IPv6
nfsd: populate sin6_scope_id on callback address with scopeid from
rq_addr on SETCLIENTID call

fs/nfsd/nfs4callback.c | 11 +--
fs/nfsd/nfs4state.c | 221 +++++++++++++++++++++++++++++++++++

Quoted 8 lines
+--------
include/linux/nfsd/state.h |    6 +-
3 files changed, 189 insertions(+), 49 deletions(-)

--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

--
Chuck Lever
chuck[dot]lever[at]oracle[dot]com

#9 lore raw
Quoted 7 lines · On Mon, 22 Jun 2009 11:47:37 -0400 Chuck Lever <[email protected]> wrote:
Quoted 6 lines

3) add patch that makes it set the sin6_scope_id for the callback address to the same value as the sin6_scope_id in the svc_rqst-

Quoted 1 line

rq_addr.

This allows the server to call back clients that mounted the server via
one of its link-local addresses.

Quoted 9 lines

The rpcbind XDR patches I'm working on provide a full universal address 2 sockaddr conversion capability in sunrpc.ko, since several unrelated features in NFS/NFSD/sunrpc appear to require it. I think the server-side callback client should use this common code instead of having its own version.

The new code is in my git repo; you should be able to pull HEAD to have a look.

That sounds good. I'd rather use common code if it's present. I'll have a look.

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