Skip to contentSkip to conversation

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

PATCH In review Jeff Layton 2 participants 10 messages Aug 12, 2009 – Aug 13, 2009

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

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

Fourth attempt at a patchset to add support for NFSv4 callbacks over IPv6. Changes from last patchset include:

1) moved address copy and comparison routines to net/sunrpc/addr.c and wrapped them properly in #ifdef's. Also changed lockd to use the common routines instead of its own.

2) added back in support for handling scope-id's (for when a host mounts a link-local address.

Tested using opensolaris and linux and verifying that delegations could be properly recalled. I also tested mounts to the server's link-local address and verified that the callback channel connected correctly.

...the rest of the code is pretty much the same as the last set. This patchset should apply cleanly to Bruce's tree as of a pull this morning.

Jeff Layton (7):
sunrpc: add routine for comparing addresses
sunrpc: add common routine for copying address portion of a sockaddr
nfsd: convert nfs4_cb_conn struct to hold address in sockaddr_storage
nfsd: make nfs4_client->cl_addr a struct sockaddr_storage
nfsd: convert gen_callback to use rpc_uaddr2sockaddr
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/lockd/clntlock.c         |    2 +-
 fs/lockd/host.c             |    4 +-
 fs/lockd/mon.c              |    2 +-
 fs/lockd/svcsubs.c          |    2 +-
 fs/nfsd/nfs4callback.c      |   11 +---
 fs/nfsd/nfs4state.c         |  142 ++++++++++++++++---------------------------
 include/linux/lockd/lockd.h |   43 -------------
 include/linux/nfsd/state.h  |    6 +-
 include/linux/sunrpc/clnt.h |    3 +
 net/sunrpc/addr.c           |   98 +++++++++++++++++++++++++++++
 10 files changed, 163 insertions(+), 150 deletions(-)

_______________________________________________
NFSv4 mailing list
[email protected]
http://linux-nfs.org/cgi-bin/mailman/listinfo/nfsv4

#1 lore raw

PATCH 1/7 sunrpc: add routine for comparing addresses

lockd needs these sort of routines, as does the NFSv4 callback code.

Move lockd's routines into common code and rename them so that they can be used by others.

---
 fs/lockd/clntlock.c         |    2 +-
 fs/lockd/host.c             |    4 +-
 fs/lockd/mon.c              |    2 +-
 fs/lockd/svcsubs.c          |    2 +-
 include/linux/lockd/lockd.h |   43 ---------------------------------------
 include/linux/sunrpc/clnt.h |    2 +
 net/sunrpc/addr.c           |   47 +++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 54 insertions(+), 48 deletions(-)
fs/lockd/clntlock.c +1 -1
index 1f3b0fc..fc9032d 100644
@@ -166,7 +166,7 @@ __be32 nlmclnt_grant(const struct sockaddr *addr, const struct nlm_lock *lock)
 		 */
 		if (fl_blocked->fl_u.nfs_fl.owner->pid != lock->svid)
 			continue;
-		if (!nlm_cmp_addr(nlm_addr(block->b_host), addr))
+		if (!rpc_cmp_addr(nlm_addr(block->b_host), addr))
 			continue;
 		if (nfs_compare_fh(NFS_FH(fl_blocked->fl_file->f_path.dentry->d_inode) ,fh) != 0)
 			continue;
fs/lockd/host.c +2 -2
index 7cb076a..4600c20 100644
@@ -111,7 +111,7 @@ static struct nlm_host *nlm_lookup_host(struct nlm_lookup_host_info *ni)
 	 */
 	chain = &nlm_hosts[nlm_hash_address(ni->sap)];
 	hlist_for_each_entry(host, pos, chain, h_hash) {
-		if (!nlm_cmp_addr(nlm_addr(host), ni->sap))
+		if (!rpc_cmp_addr(nlm_addr(host), ni->sap))
 			continue;
 
 		/* See if we have an NSM handle for this client */
@@ -125,7 +125,7 @@ static struct nlm_host *nlm_lookup_host(struct nlm_lookup_host_info *ni)
 		if (host->h_server != ni->server)
 			continue;
 		if (ni->server &&
-		    !nlm_cmp_addr(nlm_srcaddr(host), ni->src_sap))
+		    !rpc_cmp_addr(nlm_srcaddr(host), ni->src_sap))
 			continue;
 
 		/* Move to head of hash chain. */
fs/lockd/mon.c +1 -1
index 30c9331..f956651 100644
@@ -209,7 +209,7 @@ static struct nsm_handle *nsm_lookup_addr(const struct sockaddr *sap)
 	struct nsm_handle *nsm;
 
 	list_for_each_entry(nsm, &nsm_handles, sm_link)
-		if (nlm_cmp_addr(nsm_addr(nsm), sap))
+		if (rpc_cmp_addr(nsm_addr(nsm), sap))
 			return nsm;
 	return NULL;
 }
fs/lockd/svcsubs.c +1 -1
index 9e4d6aa..ad478da 100644
@@ -417,7 +417,7 @@ EXPORT_SYMBOL_GPL(nlmsvc_unlock_all_by_sb);
 static int
 nlmsvc_match_ip(void *datap, struct nlm_host *host)
 {
-	return nlm_cmp_addr(nlm_srcaddr(host), datap);
+	return rpc_cmp_addr(nlm_srcaddr(host), datap);
 }
 
 /**
include/linux/lockd/lockd.h +0 -43

49 lines not on this page · raw message

include/linux/sunrpc/clnt.h +2 -0
index ab3f6e9..b9171f2 100644
@@ -160,6 +160,8 @@ size_t		rpc_pton(const char *, const size_t,
 char *		rpc_sockaddr2uaddr(const struct sockaddr *);
 size_t		rpc_uaddr2sockaddr(const char *, const size_t,
 				   struct sockaddr *, const size_t);
+bool		rpc_cmp_addr(const struct sockaddr *sa1,
+				const struct sockaddr *sa2);
 
 static inline unsigned short rpc_get_port(const struct sockaddr *sap)
 {
net/sunrpc/addr.c +47 -0

50 lines not on this page · raw message

Signature · 1 line
1.6.0.6
#2 lore raw

Re: [PATCH 1/7] sunrpc: add routine for comparing addresses

Quoted 4 lines · Jeff Layton

lockd needs these sort of routines, as does the NFSv4 callback code.

Move lockd's routines into common code and rename them so that they can be used by others.

Trond preferred these little helpers to be "static inline". I put the port helpers in include/linux/sunrpc/clnt.h, fwiw.

The get_scope_id() function added in a later patch might also be a candidate for this treatment.

Quoted 207 lines

---

fs/lockd/clntlock.c         |    2 +-
fs/lockd/host.c             |    4 +-
fs/lockd/mon.c              |    2 +-
fs/lockd/svcsubs.c          |    2 +-
include/linux/lockd/lockd.h |   43  

---------------------------------------
include/linux/sunrpc/clnt.h | 2 +
net/sunrpc/addr.c | 47 ++++++++++++++++++++++++++++++++++
+++++++++

7 files changed, 54 insertions(+), 48 deletions(-)
fs/lockd/clntlock.c +1 -1
index 1f3b0fc..fc9032d 100644
@@ -166,7 +166,7 @@ __be32 nlmclnt_grant(const struct sockaddr  
 *addr, const struct nlm_lock *lock)
 		 */
 		if (fl_blocked->fl_u.nfs_fl.owner->pid != lock->svid)
 			continue;
-		if (!nlm_cmp_addr(nlm_addr(block->b_host), addr))
+		if (!rpc_cmp_addr(nlm_addr(block->b_host), addr))
 			continue;
 		if (nfs_compare_fh(NFS_FH(fl_blocked->fl_file->f_path.dentry- 
Quoted 1 line

d_inode) ,fh) != 0)

			continue;
fs/lockd/host.c +1 -1
index 7cb076a..4600c20 100644
@@ -111,7 +111,7 @@ static struct nlm_host *nlm_lookup_host(struct  
 nlm_lookup_host_info *ni)
 	 */
 	chain = &nlm_hosts[nlm_hash_address(ni->sap)];
 	hlist_for_each_entry(host, pos, chain, h_hash) {
-		if (!nlm_cmp_addr(nlm_addr(host), ni->sap))
+		if (!rpc_cmp_addr(nlm_addr(host), ni->sap))
 			continue;
 
		/* See if we have an NSM handle for this client */
fs/lockd/host.c +1 -1
@@ -125,7 +125,7 @@ static struct nlm_host *nlm_lookup_host(struct  
 nlm_lookup_host_info *ni)
 		if (host->h_server != ni->server)
 			continue;
 		if (ni->server &&
-		    !nlm_cmp_addr(nlm_srcaddr(host), ni->src_sap))
+		    !rpc_cmp_addr(nlm_srcaddr(host), ni->src_sap))
 			continue;
 
		/* Move to head of hash chain. */
fs/lockd/mon.c +1 -1
index 30c9331..f956651 100644
@@ -209,7 +209,7 @@ static struct nsm_handle *nsm_lookup_addr(const  
 struct sockaddr *sap)
 	struct nsm_handle *nsm;
 
 	list_for_each_entry(nsm, &nsm_handles, sm_link)
-		if (nlm_cmp_addr(nsm_addr(nsm), sap))
+		if (rpc_cmp_addr(nsm_addr(nsm), sap))
 			return nsm;
 	return NULL;

}

fs/lockd/svcsubs.c +0 -0
index 9e4d6aa..ad478da 100644
@@ -417,7 +417,7 @@ EXPORT_SYMBOL_GPL(nlmsvc_unlock_all_by_sb);

static int
nlmsvc_match_ip(void *datap, struct nlm_host *host) {

fs/lockd/svcsubs.c +1 -1
-	return nlm_cmp_addr(nlm_srcaddr(host), datap);
+	return rpc_cmp_addr(nlm_srcaddr(host), datap);

}

/**

include/linux/lockd/lockd.h +0 -43
index c325b18..e7a251a 100644
@@ -338,49 +338,6 @@ static inline int  
 nlm_privileged_requester(const struct svc_rqst *rqstp)
 	}
 }
 
-static inline int __nlm_cmp_addr4(const struct sockaddr *sap1,
-				  const struct sockaddr *sap2)
-{
-	const struct sockaddr_in *sin1 = (const struct sockaddr_in *)sap1;
-	const struct sockaddr_in *sin2 = (const struct sockaddr_in *)sap2;
-	return sin1->sin_addr.s_addr == sin2->sin_addr.s_addr;
-}
-
-#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
-static inline int __nlm_cmp_addr6(const struct sockaddr *sap1,
-				  const struct sockaddr *sap2)
-{
-	const struct sockaddr_in6 *sin1 = (const struct sockaddr_in6 *)sap1;
-	const struct sockaddr_in6 *sin2 = (const struct sockaddr_in6 *)sap2;
-	return ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr);
-}
-#else	/* !(CONFIG_IPV6 || CONFIG_IPV6_MODULE) */
-static inline int __nlm_cmp_addr6(const struct sockaddr *sap1,
-				  const struct sockaddr *sap2)
-{
-	return 0;
-}
-#endif	/* !(CONFIG_IPV6 || CONFIG_IPV6_MODULE) */
-
-/*
- * Compare two host addresses
- *
- * Return TRUE if the addresses are the same; otherwise FALSE.
- */
-static inline int nlm_cmp_addr(const struct sockaddr *sap1,
-			       const struct sockaddr *sap2)
-{
-	if (sap1->sa_family == sap2->sa_family) {
-		switch (sap1->sa_family) {
-		case AF_INET:
-			return __nlm_cmp_addr4(sap1, sap2);
-		case AF_INET6:
-			return __nlm_cmp_addr6(sap1, sap2);
-		}
-	}
-	return 0;
-}
-
 /*
 * Compare two NLM locks.

* When the second lock is of type F_UNLCK, this acts like a wildcard.

include/linux/sunrpc/clnt.h +2 -0
index ab3f6e9..b9171f2 100644
@@ -160,6 +160,8 @@ size_t		rpc_pton(const char *, const size_t,
 char *		rpc_sockaddr2uaddr(const struct sockaddr *);
 size_t		rpc_uaddr2sockaddr(const char *, const size_t,
 				   struct sockaddr *, const size_t);
+bool		rpc_cmp_addr(const struct sockaddr *sa1,
+				const struct sockaddr *sa2);
 
 static inline unsigned short rpc_get_port(const struct sockaddr *sap)
 {
net/sunrpc/addr.c +0 -0
index 22e8fd8..dbf908e 100644
@@ -362,3 +362,50 @@ size_t rpc_uaddr2sockaddr(const char *uaddr,  
 const size_t uaddr_len,
 	return 0;
 }

EXPORT_SYMBOL_GPL(rpc_uaddr2sockaddr);

net/sunrpc/addr.c +32 -0
+
+static bool __rpc_cmp_addr4(const struct sockaddr *sap1,
+			    const struct sockaddr *sap2)
+{
+	const struct sockaddr_in *sin1 = (const struct sockaddr_in *)sap1;
+	const struct sockaddr_in *sin2 = (const struct sockaddr_in *)sap2;
+
+	return sin1->sin_addr.s_addr == sin2->sin_addr.s_addr;
+}
+
+#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
+static bool __rpc_cmp_addr6(const struct sockaddr *sap1,
+			    const struct sockaddr *sap2)
+{
+	const struct sockaddr_in6 *sin1 = (const struct sockaddr_in6 *)sap1;
+	const struct sockaddr_in6 *sin2 = (const struct sockaddr_in6 *)sap2;
+	return ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr);
+}
+#else	/* !(CONFIG_IPV6 || CONFIG_IPV6_MODULE) */
+static bool __rpc_cmp_addr6(const struct sockaddr *sap1,
+			    const struct sockaddr *sap2)
+{
+	return false;
+}
+#endif	/* !(CONFIG_IPV6 || CONFIG_IPV6_MODULE) */
+
+/**
+ * rpc_cmp_addr - compare the address portion of two sockaddrs.
+ * @sap1: first sockaddr
+ * @sap2: second sockaddr
+ *
+ * Just compares the family and address portion. Ignores port,  

scope, etc.
+ * Returns true if the addrs are equal, false if they aren't.
+ */
+bool rpc_cmp_addr(const struct sockaddr *sap1, const struct sockaddr *sap2)

net/sunrpc/addr.c +12 -0
+{
+	if (sap1->sa_family == sap2->sa_family) {
+		switch (sap1->sa_family) {
+		case AF_INET:
+			return __rpc_cmp_addr4(sap1, sap2);
+		case AF_INET6:
+			return __rpc_cmp_addr6(sap1, sap2);
+		}
+	}
+	return false;
+}
+EXPORT_SYMBOL_GPL(rpc_cmp_addr);
Signature · 1 line
1.6.0.6

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

#3 lore raw

PATCH 2/7 sunrpc: add common routine for copying address portion of a sockaddr

In reply to Jeff Layton
---
 include/linux/sunrpc/clnt.h |    1 +
 net/sunrpc/addr.c           |   51 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+), 0 deletions(-)
include/linux/sunrpc/clnt.h +1 -0
index b9171f2..9c0b0a6 100644
@@ -162,6 +162,7 @@ size_t		rpc_uaddr2sockaddr(const char *, const size_t,
 				   struct sockaddr *, const size_t);
 bool		rpc_cmp_addr(const struct sockaddr *sa1,
 				const struct sockaddr *sa2);
+bool		rpc_copy_addr(struct sockaddr *dst, const struct sockaddr *src);
 
 static inline unsigned short rpc_get_port(const struct sockaddr *sap)
 {
net/sunrpc/addr.c +51 -0

72 lines not on this page · raw message

Signature · 1 line
1.6.0.6
#4 lore raw

PATCH 3/7 nfsd: convert nfs4_cb_conn struct to hold address in sockaddr_storage

In reply to Jeff Layton

...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 9295c4b..95e2185 100644
@@ -931,7 +931,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;
@@ -940,6 +940,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--) {
@@ -950,7 +952,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;
@@ -962,7 +964,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;
 }
 
@@ -976,13 +978,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 58bb197..d866368 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
#5 lore raw

Re: [PATCH 3/7] nfsd: convert nfs4_cb_conn struct to hold address in sockaddr_storage

Quoted 54 lines · Jeff Layton

...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 +0 -0
index 9295c4b..95e2185 100644
@@ -931,7 +931,7 @@ parse_octet(unsigned int *lenp, char **addrp)
 
 /* parse and set the setclientid ipv4 callback address */
Quoted 5 lines

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)

I'm a little uncomfortable with dinking around with a function that is about to be replaced anyway. Would it be cleaner to handle the upgrades to sockaddr_storage and replacing this code with rpc_pton() in a single patch? That would be a more clear and direct change, better documentation, and easier to review and prove correct, perhaps.

Not a big deal, I just thought I'd mention it.

And, minor style nit: networking code usually prefers naming IPv4 socket address variables "sin" rather than "s4".

Quoted 70 lines
{
	int temp = 0;
	u32 cbaddr = 0;
fs/nfsd/nfs4state.c +2 -0
@@ -940,6 +940,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--) {
fs/nfsd/nfs4state.c +1 -1
@@ -950,7 +952,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;
fs/nfsd/nfs4state.c +3 -2
@@ -962,7 +964,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;
 }
@@ -976,13 +978,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:

fs/nfsd/nfs4state.c +2 -0
+	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 58bb197..d866368 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
Signature · 2 lines
Chuck Lever
chuck[dot]lever[at]oracle[dot]com
#6 lore raw

PATCH 4/7 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.

---
 fs/nfsd/nfs4state.c        |   32 +++++++++++++++++++-------------
 include/linux/nfsd/state.h |    2 +-
 2 files changed, 20 insertions(+), 14 deletions(-)
fs/nfsd/nfs4state.c +19 -13
index 95e2185..7658070 100644
@@ -55,6 +55,7 @@
 #include <linux/lockd/bind.h>
 #include <linux/module.h>
 #include <linux/sunrpc/svcauth_gss.h>
+#include <linux/sunrpc/clnt.h>
 
 #define NFSDDBG_FACILITY                NFSDDBG_PROC
 
@@ -1225,13 +1226,15 @@ nfsd4_exchange_id(struct svc_rqst *rqstp,
 	int status;
 	unsigned int		strhashval;
 	char			dname[HEXDIR_LEN];
+	char			addr_str[INET6_ADDRSTRLEN];
 	nfs4_verifier		verf = exid->verifier;
-	u32			ip_addr = svc_addr_in(rqstp)->sin_addr.s_addr;
+	struct sockaddr		*sa = svc_addr(rqstp);
 
+	rpc_ntop(sa, addr_str, sizeof(addr_str));
 	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;
@@ -1320,7 +1323,7 @@ out_new:
 
 	copy_verf(new, &verf);
 	copy_cred(&new->cl_cred, &rqstp->rq_cred);
-	new->cl_addr = ip_addr;
+	rpc_copy_addr((struct sockaddr *) &new->cl_addr, sa);
 	gen_clid(new);
 	gen_confirm(new);
 	add_to_unconfirmed(new, strhashval);
@@ -1394,7 +1397,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 nfs4_client *conf, *unconf;
 	struct nfsd4_clid_slot *cs_slot = NULL;
 	int status = 0;
@@ -1422,7 +1425,7 @@ nfsd4_create_session(struct svc_rqst *rqstp,
 		cs_slot->sl_seqid++;
 	} else if (unconf) {
 		if (!same_creds(&unconf->cl_cred, &rqstp->rq_cred) ||
-		    (ip_addr != unconf->cl_addr)) {
+		    !rpc_cmp_addr(sa, (struct sockaddr *) &unconf->cl_addr)) {
 			status = nfserr_clid_inuse;
 			goto out;
 		}
@@ -1569,7 +1572,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,
@@ -1601,8 +1604,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[INET6_ADDRSTRLEN];
+			rpc_ntop((struct sockaddr *) &conf->cl_addr, addr_str,
+				 sizeof(addr_str));
+			dprintk("NFSD: setclientid: string in use by client "
+				"at %s\n", addr_str);
 			goto out;
 		}
 	}
@@ -1664,7 +1670,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;
+	rpc_copy_addr((struct sockaddr *) &new->cl_addr, sa);
 	new->cl_flavor = rqstp->rq_flavor;
 	princ = svc_gss_principal(rqstp);
 	if (princ) {
@@ -1698,7 +1704,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;
@@ -1717,9 +1723,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 && !rpc_cmp_addr((struct sockaddr *) &conf->cl_addr, sa))
 		goto out;
-	if (unconf && unconf->cl_addr != sin->sin_addr.s_addr)
+	if (unconf && !rpc_cmp_addr((struct sockaddr *) &unconf->cl_addr, sa))
 		goto out;
 
 	/*
include/linux/nfsd/state.h +1 -1
index d866368..fb0c404 100644
@@ -200,7 +200,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
#7 lore raw

PATCH 5/7 nfsd: convert gen_callback to use rpc_uaddr2sockaddr

In reply to Jeff Layton

No need for a separate routine here. Use the standard one provided in sunrpc module.

---
 fs/nfsd/nfs4state.c |   82 ++++----------------------------------------------
 1 files changed, 7 insertions(+), 75 deletions(-)
fs/nfsd/nfs4state.c +7 -75
index 7658070..96a7423 100644
@@ -897,78 +897,6 @@ find_unconfirmed_client_by_str(const char *dname, unsigned int hashval,
 	return NULL;
 }
 
-/* a helper function for parse_callback */
-static int
-parse_octet(unsigned int *lenp, char **addrp)
-{
-	unsigned int len = *lenp;
-	char *p = *addrp;
-	int n = -1;
-	char c;
-
-	for (;;) {
-		if (!len)
-			break;
-		len--;
-		c = *p++;
-		if (c == '.')
-			break;
-		if ((c < '0') || (c > '9')) {
-			n = -1;
-			break;
-		}
-		if (n < 0)
-			n = 0;
-		n = (n * 10) + (c - '0');
-		if (n > 255) {
-			n = -1;
-			break;
-		}
-	}
-	*lenp = len;
-	*addrp = p;
-	return n;
-}
-
-/* parse and set the setclientid ipv4 callback address */
-static int
-parse_ipv4(unsigned int addr_len, char *addr_val, 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;
-
-	/* ipaddress */
-	shift = 24;
-	for(i = 4; i > 0  ; i--) {
-		if ((temp = parse_octet(&addrlen, &addr)) < 0) {
-			return 0;
-		}
-		cbaddr |= (temp << shift);
-		if (shift > 0)
-		shift -= 8;
-	}
-	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;
-}
-
 static void
 gen_callback(struct nfs4_client *clp, struct nfsd4_setclientid *se)
 {
@@ -978,10 +906,14 @@ gen_callback(struct nfs4_client *clp, struct nfsd4_setclientid *se)
 	if ((se->se_callback_netid_len != 3) || memcmp((char *)se->se_callback_netid_val, "tcp", 3))
 		goto out_err;
 
-	if ( !(parse_ipv4(se->se_callback_addr_len, se->se_callback_addr_val,
-			  (struct sockaddr_in *) &cb->cb_addr)))
+	cb->cb_addrlen = rpc_uaddr2sockaddr(se->se_callback_addr_val,
+					    se->se_callback_addr_len,
+					    (struct sockaddr *) &cb->cb_addr,
+					    sizeof(cb->cb_addr));
+
+	if (!cb->cb_addrlen || cb->cb_addr.ss_family != AF_INET)
 		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;
Signature · 1 line
1.6.0.6
#8 lore raw

PATCH 6/7 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 |   15 +++++++++++----
 1 files changed, 11 insertions(+), 4 deletions(-)
fs/nfsd/nfs4state.c +11 -4
index 96a7423..9ec0ca1 100644
@@ -901,9 +901,16 @@ 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))
+	unsigned short expected_family;
+
+	/* 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))
+		expected_family = AF_INET;
+	else if (se->se_callback_netid_len == 4 &&
+		 !memcmp(se->se_callback_netid_val, "tcp6", 4))
+		expected_family = AF_INET6;
+	else
 		goto out_err;
 
 	cb->cb_addrlen = rpc_uaddr2sockaddr(se->se_callback_addr_val,
@@ -911,7 +918,7 @@ gen_callback(struct nfs4_client *clp, struct nfsd4_setclientid *se)
 					    (struct sockaddr *) &cb->cb_addr,
 					    sizeof(cb->cb_addr));
 
-	if (!cb->cb_addrlen || cb->cb_addr.ss_family != AF_INET)
+	if (!cb->cb_addrlen || cb->cb_addr.ss_family != expected_family)
 		goto out_err;
 
 	cb->cb_minorversion = 0;
Signature · 1 line
1.6.0.6
#9 lore raw

PATCH 7/7 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 |   16 ++++++++++++++--
 1 files changed, 14 insertions(+), 2 deletions(-)
fs/nfsd/nfs4state.c +14 -2
index 9ec0ca1..3e8478b 100644
@@ -898,7 +898,7 @@ find_unconfirmed_client_by_str(const char *dname, unsigned int hashval,
 }
 
 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;
 	unsigned short expected_family;
@@ -921,6 +921,9 @@ gen_callback(struct nfs4_client *clp, struct nfsd4_setclientid *se)
 	if (!cb->cb_addrlen || cb->cb_addr.ss_family != expected_family)
 		goto out_err;
 
+	if (cb->cb_addr.ss_family == AF_INET6)
+		((struct sockaddr_in6 *) &cb->cb_addr)->sin6_scope_id = scopeid;
+
 	cb->cb_minorversion = 0;
 	cb->cb_prog = se->se_callback_prog;
 	cb->cb_ident = se->se_callback_ident;
@@ -1507,6 +1510,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)
@@ -1621,7 +1633,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