NFS: handle IPv6 addresses in nfs ctl
Subsystems (4)
PATCH 2/2 NFS: handle IPv6 addresses in nfs ctl
Here is a second missing part of the IPv6 support in NFS server code concerning knfd syscall interface. It updates write_getfd and write_getfd to accept IPv6 addresses.
I've updated it according to Brian's comments, and removed some unused code.
Applies on a kernel including ip_map cache modifications
Tests: tested with only IPv4 network and basic nfs ops (mount, file creation and modification)
---
fs/nfsd/nfsctl.c 2007-10-22 11:06:13.000000000 +0200 renamed from fs/nfsd/nfsctl.c 2007-10-22 10:32:51.000000000 +0200 +0 -0
@@ -219,7 +219,7 @@ static ssize_t write_unexport(struct fil
static ssize_t write_getfs(struct file *file, char *buf, size_t size) {
struct nfsctl_fsparm *data;
- struct sockaddr_in *sin;
+ struct sockaddr_in6 *sin6, sin6_storage;
struct auth_domain *clp;
int err = 0;
struct knfsd_fh *res;
@@ -229,9 +229,20 @@ static ssize_t write_getfs(struct file *
return -EINVAL;
data = (struct nfsctl_fsparm*)buf;
err = -EPROTONOSUPPORT;
- if (data->gd_addr.sa_family != AF_INET)
+ switch (data->gd_addr.sa_family) {
+ case AF_INET6:
+ sin6 = &sin6_storage;
+ sin6 = (struct sockaddr_in6 *)&data->gd_addr;
+ ipv6_addr_copy(&in6, &(sin6->sin6_addr));
+ break;
+ case AF_INET:
+ /* Map v4 address into v6 structure */
+ ipv6_addr_set(&in6, 0, 0, htonl(0x0000FFFF), (((struct sockaddr_in *)&data->gd_addr)->sin_addr.s_addr));
+ break;
+ default:
goto out;- sin = (struct sockaddr_in *)&data->gd_addr;
+ }
+
if (data->gd_maxlen > NFS3_FHSIZE)
data->gd_maxlen = NFS3_FHSIZE;
@@ -239,10 +250,7 @@ static ssize_t write_getfs(struct file *
exp_readlock();
- /* IPv6 address mapping */
- ipv6_addr_set(&in6, 0, 0, htonl(0x0000FFFF), (((struct sockaddr_in *)&data->gd_addr)->sin_addr.s_addr));
-
- if (!(clp = auth_unix_lookup(in6)))
+ if (!(clp = auth_unix_lookup(&in6)))
err = -EPERM;
else {
err = exp_rootfh(clp, data->gd_path, res, data->gd_maxlen);@@ -258,7 +266,7 @@ static ssize_t write_getfs(struct file * static ssize_t write_getfd(struct file *file, char *buf, size_t size) {
struct nfsctl_fdparm *data;
- struct sockaddr_in *sin;
+ struct sockaddr_in6 *sin6, sin6_storage;
struct auth_domain *clp;
int err = 0;
struct knfsd_fh fh;
@@ -269,20 +277,30 @@ static ssize_t write_getfd(struct file *
return -EINVAL;
data = (struct nfsctl_fdparm*)buf;
err = -EPROTONOSUPPORT;
- if (data->gd_addr.sa_family != AF_INET)
+ if (data->gd_addr.sa_family != AF_INET && data->gd_addr.sa_family != AF_INET6)
goto out;
err = -EINVAL;
if (data->gd_version < 2 || data->gd_version > NFSSVC_MAXVERS)
goto out; res = buf;
- sin = (struct sockaddr_in *)&data->gd_addr;
exp_readlock();
- - /* IPv6 address mapping */
- ipv6_addr_set(&in6, 0, 0, htonl(0x0000FFFF), (((struct sockaddr_in *)&data->gd_addr)->sin_addr.s_addr));
- if (!(clp = auth_unix_lookup(in6)))
+ switch (data->gd_addr.sa_family) {
+ case AF_INET:
+ /* IPv6 address mapping */ + ipv6_addr_set(&in6, 0, 0, htonl(0x0000FFFF), ((struct sockaddr_in *)&data->gd_addr)->sin_addr.s_addr); + break; + case AF_INET6: + sin6 = &sin6_storage; + sin6 = (struct sockaddr_in6 *)&data->gd_addr; + ipv6_addr_copy(&in6, &(sin6->sin6_addr)); + break;
+ default:
+ BUG();
+ }
+
+ if (!(clp = auth_unix_lookup(&in6)))
err = -EPERM;
else {
err = exp_rootfh(clp, data->gd_path, &fh, NFS_FHSIZE);Signature · 7 lines
********************************
Aurelien Charbon
Linux NFSv4 team
Bull SAS
Echirolles - France
http://nfsv4.bullopensource.org/
********************************fs/nfsd/export.c +7 -3
@@ -35,6 +35,7 @@#include <linux/lockd/bind.h> #include <linux/sunrpc/msg_prot.h> #include <linux/sunrpc/gss_api.h> +#include <net/ipv6.h> #define NFSDDBG_FACILITY NFSDDBG_EXPORT
@@ -1559,6 +1560,7 @@ exp_addclient(struct nfsctl_client *ncp) {struct auth_domain *dom;int i, err; +struct in6_addr addr6;/* First, consistency check. */ err = -EINVAL ;
@@ -1577,9 +1579,11 @@ exp_addclient(struct nfsctl_client *ncp) goto out_unlock;/* Insert client into hashtable. */ -for (i =0 ; i < ncp->cl_naddr; i++) -auth_unix_add_addr (ncp->cl_addrlist[i], dom); - +for (i =0 ; i < ncp->cl_naddr; i++) { +/* Mapping address */ +ipv6_addr_set (&addr6,0 ,0 ,htonl (0x0000FFFF ), ncp->cl_addrlist[i].s_addr); +auth_unix_add_addr (&addr6, dom); + }auth_unix_forget_old (dom);auth_domain_put (dom);
fs/nfsd/nfsctl.c +13 -2
@@ -37,6 +37,7 @@#include <linux/nfsd/syscall.h> #include <asm/uaccess.h> +#include <net/ipv6.h> /* * We have a single directory with 9 nodes in it.
@@ -222,6 +223,7 @@ static ssize_t write_getfs(struct file *struct auth_domain *clp;int err =0 ;struct knfsd_fh *res; +struct in6_addr in6;if (size <sizeof (*data))return -EINVAL ;
@@ -236,7 +238,11 @@ static ssize_t write_getfs(struct file * res = (struct knfsd_fh *)buf;exp_readlock (); -if (!(clp =auth_unix_lookup (sin->sin_addr))) + +/* IPv6 address mapping */ +ipv6_addr_set (&in6,0 ,0 ,htonl (0x0000FFFF ), (((struct sockaddr_in *)&data->gd_addr)->sin_addr.s_addr)); + +if (!(clp =auth_unix_lookup (in6))) err = -EPERM ;else { err =exp_rootfh (clp, data->gd_path, res, data->gd_maxlen);
@@ -257,6 +263,7 @@ static ssize_t write_getfd(struct file *int err =0 ;struct knfsd_fh fh;char *res; +struct in6_addr in6;if (size <sizeof (*data))return -EINVAL ;
@@ -271,7 +278,11 @@ static ssize_t write_getfd(struct file * res = buf; sin = (struct sockaddr_in *)&data->gd_addr;exp_readlock (); -if (!(clp =auth_unix_lookup (sin->sin_addr))) + +/* IPv6 address mapping */ +ipv6_addr_set (&in6,0 ,0 ,htonl (0x0000FFFF ), (((struct sockaddr_in *)&data->gd_addr)->sin_addr.s_addr)); + +if (!(clp =auth_unix_lookup (in6))) err = -EPERM ;else { err =exp_rootfh (clp, data->gd_path, &fh,NFS_FHSIZE );
include/linux/sunrpc/svcauth.h +2 -2
@@ -120,10 +120,10 @@ extern void svc_auth_unregister(rpc_authextern struct auth_domain *unix_domain_find (char *name);extern void auth_domain_put (struct auth_domain *item); -extern int auth_unix_add_addr (struct in_addr addr,struct auth_domain *dom); +extern int auth_unix_add_addr (struct in6_addr *addr,struct auth_domain *dom);extern struct auth_domain *auth_domain_lookup (char *name,struct auth_domain *new);extern struct auth_domain *auth_domain_find (char *name); -extern struct auth_domain *auth_unix_lookup (struct in_addr addr); +extern struct auth_domain *auth_unix_lookup (struct in6_addr *addr);extern int auth_unix_forget_old (struct auth_domain *dom);extern void svcauth_unix_purge (void );extern void svcauth_unix_info_release (void *);
include/net/ipv6.h +8 -1
@@ -21,6 +21,7 @@#include <net/ndisc.h> #include <net/flow.h> #include <net/snmp.h> +#include <linux/in.h> #define SIN6_LEN_RFC2133 24
@@ -167,6 +168,12 @@ DECLARE_SNMP_STAT(struct udp_mib, udplitif (is_udplite)SNMP_INC_STATS_USER (udplite_stats_in6, field); \ else SNMP_INC_STATS_USER(udp_stats_in6, field); } while(0) +#define IS_ADDR_MAPPED (a) \ + (((uint32_t *) (a))[0] == 0 \ + && ((uint32_t *) (a))[1] == 0 \ + && (((uint32_t *) (a))[2] == 0 \ + || ((uint32_t *) (a))[2] == htonl(0xffff))) +struct ip6_ra_chain {struct ip6_ra_chain *next;
@@ -380,7 +387,7 @@ static inline int ipv6_addr_any(const ststatic inline int ipv6_addr_v4mapped (const struct in6_addr *a) {return ((a->s6_addr32[0 ] | a->s6_addr32[1 ]) ==0 && - a->s6_addr32[2 ] ==htonl (0x0000ffff )); + a->s6_addr32[2 ] ==htonl (0x0000ffff )); }/*
net/sunrpc/svcauth_unix.c +81 -38
245 lines not on this page · raw message
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs