Add the support of IPv6 in the LOCKD server.

Signed-off-by: Gilles Quillard <gilles.quillard@bull.net>
---

diff -Nru linux-2.6.9-cel5-gq-04/fs/lockd/clntproc.c linux-2.6.9-cel5-gq-05/fs/lockd/clntproc.c
--- linux-2.6.9-cel5-gq-04/fs/lockd/clntproc.c	2005-01-13 09:12:03.000000000 +0100
+++ linux-2.6.9-cel5-gq-05/fs/lockd/clntproc.c	2005-01-21 17:09:59.000000000 +0100
@@ -191,7 +191,7 @@
 {
 	struct nfs_server	*nfssrv = NFS_SERVER(inode);
 	struct rpc_xprt		*xprt = nfssrv->client->cl_xprt;
-	struct sockaddr_in	addr;
+	struct sockaddr_in6	addr;
 	struct nlm_host		*host;
 	struct nlm_rqst		reqst, *call = &reqst;
 	sigset_t		oldset;
diff -Nru linux-2.6.9-cel5-gq-04/fs/lockd/host.c linux-2.6.9-cel5-gq-05/fs/lockd/host.c
--- linux-2.6.9-cel5-gq-04/fs/lockd/host.c	2004-12-13 14:36:38.000000000 +0100
+++ linux-2.6.9-cel5-gq-05/fs/lockd/host.c	2005-01-21 17:09:59.000000000 +0100
@@ -38,7 +38,7 @@
  * Find an NLM server handle in the cache. If there is none, create it.
  */
 struct nlm_host *
-nlmclnt_lookup_host(struct sockaddr_in *sin, int proto, int version)
+nlmclnt_lookup_host(struct sockaddr_in6 *sin, int proto, int version)
 {
 	return nlm_lookup_host(0, sin, proto, version);
 }
@@ -57,17 +57,17 @@
  * Common host lookup routine for server & client
  */
 struct nlm_host *
-nlm_lookup_host(int server, struct sockaddr_in *sin,
+nlm_lookup_host(int server, struct sockaddr_in6 *sin,
 					int proto, int version)
 {
 	struct nlm_host	*host, **hp;
-	u32		addr;
+	struct in6_addr	addr;
 	int		hash;
 
-	dprintk("lockd: nlm_lookup_host(%08x, p=%d, v=%d)\n",
-			(unsigned)(sin? ntohl(sin->sin_addr.s_addr) : 0), proto, version);
+	dprintk("lockd: nlm_lookup_host(%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x, p=%d, v=%d)\n",
+		NIP6(addr), proto, version);
 
-	hash = NLM_ADDRHASH(sin->sin_addr.s_addr);
+	hash = NLM_ADDRHASH(addr.s6_addr32[3]);
 
 	/* Lock hash table */
 	down(&nlm_host_sema);
@@ -102,15 +102,10 @@
 		goto nohost;
 	memset(host, 0, sizeof(*host));
 
-	addr = sin->sin_addr.s_addr;
-	sprintf(host->h_name, "%d.%d.%d.%d",
-			(unsigned char) (ntohl(addr) >> 24),
-			(unsigned char) (ntohl(addr) >> 16),
-			(unsigned char) (ntohl(addr) >>  8),
-			(unsigned char) (ntohl(addr) >>  0));
+	sprintf(host->h_name, "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x", NIP6(addr));
 
 	host->h_addr       = *sin;
-	host->h_addr.sin_port = 0;	/* ouch! */
+	host->h_addr.sin6_port = 0;	/* ouch! */
 	host->h_version    = version;
 	host->h_proto      = proto;
 	host->h_authflavor = RPC_AUTH_UNIX;
@@ -168,8 +163,8 @@
 {
 	struct rpc_clnt	*clnt;
 
-	dprintk("lockd: nlm_bind_host(%08x)\n",
-			(unsigned)ntohl(host->h_addr.sin_addr.s_addr));
+	dprintk("lockd: nlm_bind_host(%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x)\n",
+			NIP6(host->h_addr.sin6_addr));
 
 	/* Lock host handle */
 	down(&host->h_sema);
diff -Nru linux-2.6.9-cel5-gq-04/fs/lockd/mon.c linux-2.6.9-cel5-gq-05/fs/lockd/mon.c
--- linux-2.6.9-cel5-gq-04/fs/lockd/mon.c	2004-12-13 14:36:38.000000000 +0100
+++ linux-2.6.9-cel5-gq-05/fs/lockd/mon.c	2005-01-21 17:09:59.000000000 +0100
@@ -42,7 +42,7 @@
 		goto out;
 	}
 
-	args.addr = host->h_addr.sin_addr.s_addr;
+	memcpy(&args.addr, &host->h_addr.sin6_addr, sizeof(struct in6_addr));
 	args.proto= (host->h_proto<<1) | host->h_server;
 	args.prog = NLM_PROGRAM;
 	args.vers = host->h_version;
@@ -104,10 +104,9 @@
 static struct rpc_clnt *
 nsm_create(void)
 {
-	struct sockaddr_in	sin = {
-		.sin_family	= AF_INET,
-		.sin_addr.s_addr = htonl(INADDR_LOOPBACK),
-		.sin_port	= 0,
+	struct sockaddr_in6	sin = {
+		.sin6_family	= AF_INET6,
+		.sin6_port	= 0,
 	};
 	struct rpc_create_args args = {
 		.protocol	= IPPROTO_UDP,
@@ -121,6 +120,11 @@
 					RPC_CLNT_ONESHOT | RPC_CLNT_RESVPORT,
 	};
 
+	sin.sin6_addr.s6_addr32[0] = 0;
+	sin.sin6_addr.s6_addr32[1] = 0;
+	sin.sin6_addr.s6_addr32[2] = htonl(0xffff);
+	sin.sin6_addr.s6_addr32[3] = htonl(INADDR_LOOPBACK);
+
 	return rpc_create(&args);
 }
 
diff -Nru linux-2.6.9-cel5-gq-04/fs/lockd/svc4proc.c linux-2.6.9-cel5-gq-05/fs/lockd/svc4proc.c
--- linux-2.6.9-cel5-gq-04/fs/lockd/svc4proc.c	2004-12-13 14:36:38.000000000 +0100
+++ linux-2.6.9-cel5-gq-05/fs/lockd/svc4proc.c	2005-01-21 17:09:59.000000000 +0100
@@ -416,26 +416,29 @@
 nlm4svc_proc_sm_notify(struct svc_rqst *rqstp, struct nlm_reboot *argp,
 					      void	        *resp)
 {
-	struct sockaddr_in	saddr = rqstp->rq_addr;
+	struct sockaddr_in6	saddr = rqstp->rq_addr;
 	int			vers = argp->vers;
 	int			prot = argp->proto >> 1;
 
 	struct nlm_host		*host;
 
 	dprintk("lockd: SM_NOTIFY     called\n");
-	if (saddr.sin_addr.s_addr != htonl(INADDR_LOOPBACK)
-	 || ntohs(saddr.sin_port) >= 1024) {
+	if (saddr.sin6_addr.s6_addr32[0] != 0
+	 || saddr.sin6_addr.s6_addr32[1] != 0
+	 || saddr.sin6_addr.s6_addr32[2] != 0
+	 || saddr.sin6_addr.s6_addr32[3] != htonl(1)
+	 || ntohs(saddr.sin6_port) >= 1024) {
 		printk(KERN_WARNING
-			"lockd: rejected NSM callback from %08x:%d\n",
-			ntohl(rqstp->rq_addr.sin_addr.s_addr),
-			ntohs(rqstp->rq_addr.sin_port));
+			"lockd: rejected NSM callback from %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x:%d\n",
+			NIP6(rqstp->rq_addr.sin6_addr),
+			ntohs(rqstp->rq_addr.sin6_port));
 		return rpc_system_err;
 	}
 
 	/* Obtain the host pointer for this NFS server and try to
 	 * reclaim all locks we hold on this server.
 	 */
-	saddr.sin_addr.s_addr = argp->addr;
+	memcpy(&saddr.sin6_addr, &argp->addr, sizeof(struct in6_addr));
 
 	if ((argp->proto & 1)==0) {
 		if ((host = nlmclnt_lookup_host(&saddr, prot, vers)) != NULL) {
diff -Nru linux-2.6.9-cel5-gq-04/fs/lockd/svc.c linux-2.6.9-cel5-gq-05/fs/lockd/svc.c
--- linux-2.6.9-cel5-gq-04/fs/lockd/svc.c	2004-12-13 14:36:38.000000000 +0100
+++ linux-2.6.9-cel5-gq-05/fs/lockd/svc.c	2005-01-21 17:09:59.000000000 +0100
@@ -166,8 +166,8 @@
 			break;
 		}
 
-		dprintk("lockd: request from %08x\n",
-			(unsigned)ntohl(rqstp->rq_addr.sin_addr.s_addr));
+		dprintk("lockd: request from %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n",
+			NIP6(rqstp->rq_addr.sin6_addr));
 
 		svc_process(serv, rqstp);
 
diff -Nru linux-2.6.9-cel5-gq-04/fs/lockd/svclock.c linux-2.6.9-cel5-gq-05/fs/lockd/svclock.c
--- linux-2.6.9-cel5-gq-04/fs/lockd/svclock.c	2004-12-13 14:36:38.000000000 +0100
+++ linux-2.6.9-cel5-gq-05/fs/lockd/svclock.c	2005-01-21 17:09:59.000000000 +0100
@@ -142,7 +142,7 @@
  * Find a block with a given NLM cookie.
  */
 static inline struct nlm_block *
-nlmsvc_find_block(struct nlm_cookie *cookie,  struct sockaddr_in *sin)
+nlmsvc_find_block(struct nlm_cookie *cookie,  struct sockaddr_in6 *sin)
 {
 	struct nlm_block *block;
 
@@ -581,19 +581,20 @@
 	struct nlm_rqst		*call = (struct nlm_rqst *) task->tk_calldata;
 	struct nlm_block	*block;
 	unsigned long		timeout;
-	struct sockaddr_in	addr, *peer_addr = &addr;
+	struct sockaddr_in6	addr, *peer_addr = &addr;
+	char	str[64];
 
 	rpc_peeraddr(task->tk_client, &addr, sizeof(addr));
+
 	dprintk("lockd: GRANT_MSG RPC callback\n");
-	dprintk("callback: looking for cookie %x, host (%08x)\n", 
-		*(unsigned int *)(call->a_args.cookie.data),
-		ntohl(peer_addr->sin_addr.s_addr));
+	sprintf(str, "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x", NIP6(addr.sin6_addr));
+	dprintk("callback: looking for cookie %x, host (%s)\n", 
+		*(unsigned int *)(call->a_args.cookie.data), str);
 	lock_kernel();
 	if (!(block = nlmsvc_find_block(&call->a_args.cookie, peer_addr))) {
 		unlock_kernel();
-		dprintk("lockd: no block for cookie %x, host (%08x)\n",
-			*(u32 *)(call->a_args.cookie.data),
-			ntohl(peer_addr->sin_addr.s_addr));
+		dprintk("lockd: no block for cookie %x, host (%s)\n",
+			*(u32 *)(call->a_args.cookie.data), str);
 		return;
 	}
 
@@ -628,9 +629,8 @@
 	struct nlm_block	*block;
 	struct nlm_file		*file;
 
-	dprintk("grant_reply: looking for cookie %x, host (%08x), s=%d \n", 
-		*(unsigned int *)(cookie->data), 
-		ntohl(rqstp->rq_addr.sin_addr.s_addr), status);
+	dprintk("grant_reply: looking for cookie %x, host (%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x), s=%d \n", 
+		*(unsigned int *)(cookie->data), NIP6(rqstp->rq_addr.sin6_addr), status);
 	if (!(block = nlmsvc_find_block(cookie, &rqstp->rq_addr)))
 		return;
 	file = block->b_file;
diff -Nru linux-2.6.9-cel5-gq-04/fs/lockd/svcproc.c linux-2.6.9-cel5-gq-05/fs/lockd/svcproc.c
--- linux-2.6.9-cel5-gq-04/fs/lockd/svcproc.c	2004-12-13 14:36:38.000000000 +0100
+++ linux-2.6.9-cel5-gq-05/fs/lockd/svcproc.c	2005-01-21 17:09:59.000000000 +0100
@@ -22,6 +22,12 @@
 
 #define NLMDBG_FACILITY		NLMDBG_CLIENT
 
+#define IS_ADDR6_LOOPBACK(a) \
+    (((uint32_t *) (a))[0] == 0                       \
+     && ((uint32_t *) (a))[1] == 0                    \
+     && ((uint32_t *) (a))[2] == 0                    \
+     && ((uint32_t *) (a))[3] == htonl(1))
+
 static u32	nlmsvc_callback(struct svc_rqst *, u32, struct nlm_res *);
 static void	nlmsvc_callback_exit(struct rpc_task *);
 
@@ -444,25 +450,25 @@
 nlmsvc_proc_sm_notify(struct svc_rqst *rqstp, struct nlm_reboot *argp,
 					      void	        *resp)
 {
-	struct sockaddr_in	saddr = rqstp->rq_addr;
+	struct sockaddr_in6	saddr = rqstp->rq_addr;
 	int			vers = argp->vers;
 	int			prot = argp->proto >> 1;
 	struct nlm_host		*host;
 
 	dprintk("lockd: SM_NOTIFY     called\n");
-	if (saddr.sin_addr.s_addr != htonl(INADDR_LOOPBACK)
-	 || ntohs(saddr.sin_port) >= 1024) {
+	if (! IS_ADDR6_LOOPBACK(&saddr.sin6_addr)
+	 || ntohs(saddr.sin6_port) >= 1024) {
 		printk(KERN_WARNING
-			"lockd: rejected NSM callback from %08x:%d\n",
-			ntohl(rqstp->rq_addr.sin_addr.s_addr),
-			ntohs(rqstp->rq_addr.sin_port));
+			"lockd: rejected NSM callback from %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x:%d\n",
+			NIP6(rqstp->rq_addr.sin6_addr),
+			ntohs(rqstp->rq_addr.sin6_port));
 		return rpc_system_err;
 	}
 
 	/* Obtain the host pointer for this NFS server and try to
 	 * reclaim all locks we hold on this server.
 	 */
-	saddr.sin_addr.s_addr = argp->addr;
+	memcpy(&saddr.sin6_addr, &argp->addr, sizeof(struct in6_addr));
 	if ((argp->proto & 1)==0) {
 		if ((host = nlmclnt_lookup_host(&saddr, prot, vers)) != NULL) {
 			nlmclnt_recovery(host, argp->state);
diff -Nru linux-2.6.9-cel5-gq-04/fs/lockd/xdr4.c linux-2.6.9-cel5-gq-05/fs/lockd/xdr4.c
--- linux-2.6.9-cel5-gq-04/fs/lockd/xdr4.c	2004-10-18 23:53:06.000000000 +0200
+++ linux-2.6.9-cel5-gq-05/fs/lockd/xdr4.c	2005-01-21 17:09:59.000000000 +0100
@@ -354,7 +354,10 @@
 		return 0;
 	argp->state = ntohl(*p++);
 	/* Preserve the address in network byte order */
-	argp->addr = *p++;
+	argp->addr.s6_addr32[0] = *p++;
+	argp->addr.s6_addr32[1] = *p++;
+	argp->addr.s6_addr32[2] = *p++;
+	argp->addr.s6_addr32[3] = *p++;
 	return xdr_argsize_check(rqstp, p);
 }
 
diff -Nru linux-2.6.9-cel5-gq-04/fs/lockd/xdr.c linux-2.6.9-cel5-gq-05/fs/lockd/xdr.c
--- linux-2.6.9-cel5-gq-04/fs/lockd/xdr.c	2004-10-18 23:53:11.000000000 +0200
+++ linux-2.6.9-cel5-gq-05/fs/lockd/xdr.c	2005-01-21 17:09:59.000000000 +0100
@@ -349,7 +349,10 @@
 		return 0;
 	argp->state = ntohl(*p++);
 	/* Preserve the address in network byte order */
-	argp->addr = *p++;
+	argp->addr.s6_addr32[0] = *p++;
+	argp->addr.s6_addr32[1] = *p++;
+	argp->addr.s6_addr32[2] = *p++;
+	argp->addr.s6_addr32[3] = *p++;
 	argp->vers = *p++;
 	argp->proto = *p++;
 	return xdr_argsize_check(rqstp, p);
diff -Nru linux-2.6.9-cel5-gq-04/include/linux/lockd/lockd.h linux-2.6.9-cel5-gq-05/include/linux/lockd/lockd.h
--- linux-2.6.9-cel5-gq-04/include/linux/lockd/lockd.h	2004-12-13 14:36:38.000000000 +0100
+++ linux-2.6.9-cel5-gq-05/include/linux/lockd/lockd.h	2005-01-21 17:09:59.000000000 +0100
@@ -38,7 +38,7 @@
  */
 struct nlm_host {
 	struct nlm_host *	h_next;		/* linked list (hash table) */
-	struct sockaddr_in	h_addr;		/* peer address */
+	struct sockaddr_in6	h_addr;		/* peer address */
 	struct rpc_clnt	*	h_rpcclnt;	/* RPC client to talk to peer */
 	char			h_name[20];	/* remote hostname */
 	u32			h_version;	/* interface version */
@@ -156,9 +156,9 @@
 /*
  * Host cache
  */
-struct nlm_host * nlmclnt_lookup_host(struct sockaddr_in *, int, int);
+struct nlm_host * nlmclnt_lookup_host(struct sockaddr_in6 *, int, int);
 struct nlm_host * nlmsvc_lookup_host(struct svc_rqst *);
-struct nlm_host * nlm_lookup_host(int server, struct sockaddr_in *, int, int);
+struct nlm_host * nlm_lookup_host(int server, struct sockaddr_in6 *, int, int);
 struct rpc_clnt * nlm_bind_host(struct nlm_host *);
 void		  nlm_rebind_host(struct nlm_host *);
 struct nlm_host * nlm_get_host(struct nlm_host *);
@@ -202,9 +202,9 @@
  * Compare two host addresses (needs modifying for ipv6)
  */
 static __inline__ int
-nlm_cmp_addr(struct sockaddr_in *sin1, struct sockaddr_in *sin2)
+nlm_cmp_addr(struct sockaddr_in6 *sin1, struct sockaddr_in6 *sin2)
 {
-	return sin1->sin_addr.s_addr == sin2->sin_addr.s_addr;
+	return memcmp(&sin1->sin6_addr, &sin2->sin6_addr, sizeof(struct in6_addr));
 }
 
 /*
diff -Nru linux-2.6.9-cel5-gq-04/include/linux/lockd/xdr.h linux-2.6.9-cel5-gq-05/include/linux/lockd/xdr.h
--- linux-2.6.9-cel5-gq-04/include/linux/lockd/xdr.h	2004-10-18 23:53:06.000000000 +0200
+++ linux-2.6.9-cel5-gq-05/include/linux/lockd/xdr.h	2005-01-21 17:09:59.000000000 +0100
@@ -75,7 +75,7 @@
 	char *		mon;
 	int		len;
 	u32		state;
-	u32		addr;
+	struct in6_addr	addr;
 	u32		vers;
 	u32		proto;
 };
