[PATCH 1/2] NFS: change the ip_map cache code to handle IPv6 addresses
Here is a patch for the ip_map caching code part in nfs server. I have updated the code to use Brian Haley's ipv6_addr_v4mapped function, and corrected pointed out mistakes. So the first patch in attachment must be applied on a vanilla kernel before to include IPv4 mapping functions that are used. In case of bad formatting due to my mailer, you can also find the patch in attachment. Tests: tested with only IPv4 network and basic nfs ops (mount, file creation and modification) Signed-off-by: Aurelien Charbon <[EMAIL PROTECTED]> --- fs/nfsd/export.c | 10 ++- fs/nfsd/nfsctl.c | 16 - include/linux/sunrpc/svcauth.h |4 - include/net/ipv6.h | 17 + net/sunrpc/svcauth_unix.c | 117 - 5 files changed, 118 insertions(+), 46 deletions(-) diff -p -u -r -N linux-2.6.23-haley/fs/nfsd/export.c linux-2.6.23-ipmap-cache/fs/nfsd/export.c --- linux-2.6.23-haley/fs/nfsd/export.c2007-10-11 15:15:03.0 +0200 +++ linux-2.6.23-ipmap-cache/fs/nfsd/export.c2007-10-11 15:23:07.0 +0200 @@ -35,6 +35,7 @@ #include #include #include +#include #define NFSDDBG_FACILITYNFSDDBG_EXPORT @@ -1559,6 +1560,7 @@ exp_addclient(struct nfsctl_client *ncp) { struct auth_domain*dom; inti, 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_v4map(ncp->cl_addrlist[i], addr6); +auth_unix_add_addr(addr6, dom); +} auth_unix_forget_old(dom); auth_domain_put(dom); diff -p -u -r -N linux-2.6.23-haley/fs/nfsd/nfsctl.c linux-2.6.23-ipmap-cache/fs/nfsd/nfsctl.c --- linux-2.6.23-haley/fs/nfsd/nfsctl.c2007-10-11 15:15:03.0 +0200 +++ linux-2.6.23-ipmap-cache/fs/nfsd/nfsctl.c2007-10-11 15:23:07.0 +0200 @@ -38,6 +38,7 @@ #include +#include /* *We have a single directory with 9 nodes in it. */ @@ -222,7 +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; data = (struct nfsctl_fsparm*)buf; @@ -236,7 +237,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_v4map(sin->sin_addr, in6); + +if (!(clp = auth_unix_lookup(in6))) err = -EPERM; else { err = exp_rootfh(clp, data->gd_path, res, data->gd_maxlen); @@ -253,6 +258,7 @@ static ssize_t write_getfd(struct file * { struct nfsctl_fdparm *data; struct sockaddr_in *sin; +struct in6_addr in6; struct auth_domain *clp; int err = 0; struct knfsd_fh fh; @@ -271,7 +277,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_v4map(sin->sin_addr, in6); + +if (!(clp = auth_unix_lookup(in6))) err = -EPERM; else { err = exp_rootfh(clp, data->gd_path, &fh, NFS_FHSIZE); diff -p -u -r -N linux-2.6.23-haley/include/linux/sunrpc/svcauth.h linux-2.6.23-ipmap-cache/include/linux/sunrpc/svcauth.h --- linux-2.6.23-haley/include/linux/sunrpc/svcauth.h2007-10-11 15:15:00.0 +0200 +++ linux-2.6.23-ipmap-cache/include/linux/sunrpc/svcauth.h 2007-10-11 15:23:07.0 +0200 @@ -120,10 +120,10 @@ extern voidsvc_auth_unregister(rpc_auth extern 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 *); diff -p -u -r -N linux-2.6.23-haley/include/net/ipv6.h linux-2.6.23-ipmap-cache/include/net/ipv6.h --- linux-2.6.23-haley/include/net/ipv6.h2007-10-11 15:21:23.0 +0200 +++ linux-2.6.23-ipmap-cache/include/net/ipv6.h2007-10-12 10:46:09.0 +0200 @@ -21,6 +21,7 @@ #include #include #include +#include #define SIN6_LEN_RFC213324 @@ -167,6 +168,12 @@ DECLARE_S
[PATCH 1/2] NFS: change the ip_map cache code to handle IPv6 addresses
Here is a patch for the ip_map caching code part in nfs server. I have updated the code to use Brian Haley's ipv6_addr_v4mapped function, and corrected pointed out mistakes. So the first patch in attachment must be applied on a vanilla kernel before. In case of bad formatting due to my mailer, you can also find the patch in attachment. Tests: tested with only IPv4 network and basic nfs ops (mount, file creation and modification) Signed-off-by: Aurelien Charbon <[EMAIL PROTECTED]> --- diff -p -u -r -N linux-2.6.23-haley/fs/nfsd/export.c linux-2.6.23-ipmap/fs/nfsd/export.c --- linux-2.6.23-haley/fs/nfsd/export.c2007-10-22 09:43:17.0 +0200 +++ linux-2.6.23-ipmap/fs/nfsd/export.c2007-10-22 13:04:50.0 +0200 @@ -35,6 +35,7 @@ #include #include #include +#include #define NFSDDBG_FACILITYNFSDDBG_EXPORT @@ -1559,6 +1560,7 @@ exp_addclient(struct nfsctl_client *ncp) { struct auth_domain*dom; inti, 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(0x), ncp->cl_addrlist[i].s_addr); +auth_unix_add_addr(&addr6, dom); +} auth_unix_forget_old(dom); auth_domain_put(dom); diff -p -u -r -N linux-2.6.23-haley/fs/nfsd/nfsctl.c linux-2.6.23-ipmap/fs/nfsd/nfsctl.c --- linux-2.6.23-haley/fs/nfsd/nfsctl.c2007-10-22 09:43:17.0 +0200 +++ linux-2.6.23-ipmap/fs/nfsd/nfsctl.c2007-10-22 10:32:51.0 +0200 @@ -37,6 +37,7 @@ #include #include +#include /* *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(0x), (((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(0x), (((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); diff -p -u -r -N linux-2.6.23-haley/include/linux/sunrpc/svcauth.h linux-2.6.23-ipmap/include/linux/sunrpc/svcauth.h --- linux-2.6.23-haley/include/linux/sunrpc/svcauth.h2007-10-22 09:43:04.0 +0200 +++ linux-2.6.23-ipmap/include/linux/sunrpc/svcauth.h2007-10-22 10:10:37.0 +0200 @@ -120,10 +120,10 @@ extern voidsvc_auth_unregister(rpc_auth extern 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 *); diff -p -u -r -N linux-2.6.23-haley/include/net/ipv6.h linux-2.6.23-ipmap/include/net/ipv6.h --- linux-2.6.23-haley/include/net/ipv6.h2007-10-22 09:42:58.0 +0200 +++ linux-2.6.23-ipmap/include/net/ipv6.h2007-10-22 10:10:59.0 +0200 @@ -21,6 +21,7 @@ #include #include #include +#include #define SIN6_LEN_RFC213324 @@ -167,6 +168,12 @@ DECLARE_SNMP_STAT(struct udp_mib, udplit if (is_udplite) SNMP_INC_STATS_USER(udplite_stats_in6, field); \ elseSNMP_INC_STATS_USER(udp_stats_in6, field);} while(0) +#define IS_ADDR_MAPPED(a) \ +(((uint32_t *) (a))[0] == 0\ +
[PATCH 1/2] NFS: change the ip_map cache code to handle IPv6 addresses
Hi, Here is the IPv6 support patch for the ip_map caching code part in nfs server. I have ported it on 2.6.24-rc1 (in which Brian Haley's ipv6_addr_v4mapped function is included) In case of bad formatting due to my mailer, you can also find the patch in attachment. Tests: tested with only IPv4 network and basic nfs ops (mount, file creation and modification) Signed-off-by: Aurelien Charbon <[EMAIL PROTECTED]> --- diff -p -u -r -N linux-2.6.24-rc1/fs/nfsd/export.c linux-2.6.24-rc1-ipmap/fs/nfsd/export.c --- linux-2.6.24-rc1/fs/nfsd/export.c2007-10-30 12:47:21.0 +0100 +++ linux-2.6.24-rc1-ipmap/fs/nfsd/export.c2007-10-30 17:18:21.0 +0100 @@ -35,6 +35,7 @@ #include #include #include +#include #define NFSDDBG_FACILITYNFSDDBG_EXPORT @@ -1556,6 +1557,7 @@ exp_addclient(struct nfsctl_client *ncp) { struct auth_domain*dom; inti, err; +struct in6_addr addr6; /* First, consistency check. */ err = -EINVAL; @@ -1574,9 +1576,12 @@ 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(0x), ncp->cl_addrlist[i].s_addr); +auth_unix_add_addr(&addr6, dom); +} auth_unix_forget_old(dom); auth_domain_put(dom); diff -p -u -r -N linux-2.6.24-rc1/fs/nfsd/nfsctl.c linux-2.6.24-rc1-ipmap/fs/nfsd/nfsctl.c --- linux-2.6.24-rc1/fs/nfsd/nfsctl.c2007-10-30 12:47:21.0 +0100 +++ linux-2.6.24-rc1-ipmap/fs/nfsd/nfsctl.c2007-10-30 17:15:45.0 +0100 @@ -37,6 +37,7 @@ #include #include +#include /* *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,12 @@ 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(0x), (((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 +264,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 +279,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(0x), (((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); diff -p -u -r -N linux-2.6.24-rc1/include/linux/sunrpc/svcauth.h linux-2.6.24-rc1-ipmap/include/linux/sunrpc/svcauth.h --- linux-2.6.24-rc1/include/linux/sunrpc/svcauth.h2007-10-30 12:47:04.0 +0100 +++ linux-2.6.24-rc1-ipmap/include/linux/sunrpc/svcauth.h2007-10-30 13:14:04.0 +0100 @@ -120,10 +120,10 @@ extern voidsvc_auth_unregister(rpc_auth extern 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 *); diff -p -u -r -N linux-2.6.24-rc1/net/sunrpc/svcauth_unix.c linux-2.6.24-rc1-ipmap/net/sunrpc/svcauth_unix.c --- linux-2.6.24-rc1/net/sunrpc/svcauth_unix.c2007-10-30 12:47:07.0 +0100 +++ linux-2.6.24-rc1-ipmap/net/sunrpc/svcauth_unix.c2007-10-30 17:17:00.0 +0100 @@ -11,7 +11,8 @@ #include #include #include - +#include +#include #define RPCDBG_FACILITYRPCDBG_AUTH @@ -84,7 +85,7 @@ static void svcauth_unix_domain_release( struct ip_map { struct cache_headh; charm_class[8]; /* e.g. "nfsd" */ -struct in_addrm_addr; +struct in6_addrm_addr; struct unix_domain*m_client; intm_add
Re: [PATCH 1/2] NFS: change the ip_map cache code to handle IPv6 addresses
Hi Aurelien, There were some of my comments you haven't addressed yet, comments in-line. Aurélien Charbon wrote: Here is a patch for the ip_map caching code part in nfs server. +for (i = 0; i < ncp->cl_naddr; i++) { +/* Mapping address */ +ipv6_addr_v4map(ncp->cl_addrlist[i], addr6); ipv6_addr_set(&addr6, 0, 0, htonl(0x), ncp->cl_addrlist[i]); +/* IPv6 address mapping */ +ipv6_addr_v4map(sin->sin_addr, in6); ipv6_addr_set(&in6, 0, 0, htonl(0x), sin->sin_addr); +/* IPv6 address mapping */ +ipv6_addr_v4map(sin->sin_addr, in6); ipv6_addr_set(&in6, 0, 0, htonl(0x), sin->sin_addr); +#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(0x))) This is unused, can go away. +static inline void ipv6_addr_v4map(const struct in_addr a1, struct in6_addr a2) +{ +a2.s6_addr32[0] = 0; +a2.s6_addr32[1] = 0; +a2.s6_addr32[2] = htonl(0x); +a2.s6_addr32[3] = (uint32_t)a1.s_addr; +} If you use ipv6_addr_set() everywhere you don't need this. static 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(0x)); +a->s6_addr32[2] == htonl(0x)); } Guessing you changed a tab to a space, unnecessary. -static struct ip_map *ip_map_lookup(char *class, struct in_addr addr); +static struct ip_map *ip_map_lookup(char *class, struct in6_addr addr); I still think you should pass a pointer here. -int auth_unix_add_addr(struct in_addr addr, struct auth_domain *dom) +int auth_unix_add_addr(struct in6_addr addr, struct auth_domain *dom) And here. -struct auth_domain *auth_unix_lookup(struct in_addr addr) +struct auth_domain *auth_unix_lookup(struct in6_addr addr) And here. -Brian - To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 1/2] NFS: change the ip_map cache code to handle IPv6 addresses
Hi Aurelien, I think you're almost there, at least with my comments :) linux-2.6.23-ipmap/include/net/ipv6.h --- linux-2.6.23-haley/include/net/ipv6.h2007-10-22 09:42:58.0 +0200 +++ linux-2.6.23-ipmap/include/net/ipv6.h2007-10-22 10:10:59.0 +0200 @@ -21,6 +21,7 @@ #include #include #include +#include #define SIN6_LEN_RFC213324 @@ -167,6 +168,12 @@ DECLARE_SNMP_STAT(struct udp_mib, udplit if (is_udplite) SNMP_INC_STATS_USER(udplite_stats_in6, field); \ elseSNMP_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(0x))) + struct ip6_ra_chain { struct ip6_ra_chain*next; @@ -380,7 +387,7 @@ static inline int ipv6_addr_any(const st static 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(0x)); +a->s6_addr32[2] == htonl(0x)); } You don't need to touch ipv6.h at all, IS_ADDR_MAPPED is unused and the other is removing a space. static void ip_map_init(struct cache_head *cnew, struct cache_head *citem) { @@ -125,7 +133,7 @@ static void ip_map_init(struct cache_hea struct ip_map *item = container_of(citem, struct ip_map, h); strcpy(new->m_class, item->m_class); -new->m_addr.s_addr = item->m_addr.s_addr; +ipv6_addr_copy(&(new->m_addr), &(item->m_addr)); Extra () here. @@ -651,7 +694,7 @@ svcauth_unix_set_client(struct svc_rqst ipm = ip_map_cached_get(rqstp); if (ipm == NULL) ipm = ip_map_lookup(rqstp->rq_server->sv_program->pg_class, -sin->sin_addr); +&(sin6->sin6_addr)); Extra () here. -Brian - To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 1/2] NFS: change the ip_map cache code to handle IPv6 addresses
Thanks for working on this. Could you run linux/scripts/checkpatch.pl on your patch and fix the problems it complains about? On Tue, Oct 30, 2007 at 06:05:42PM +0100, Aurélien Charbon wrote: > static void update(struct cache_head *cnew, struct cache_head *citem) > { > @@ -149,22 +157,24 @@ static void ip_map_request(struct cache_ > struct cache_head *h, > char **bpp, int *blen) > { > -char text_addr[20]; > +char text_addr[40]; > struct ip_map *im = container_of(h, struct ip_map, h); > -__be32 addr = im->m_addr.s_addr; > - > -snprintf(text_addr, 20, "%u.%u.%u.%u", > - ntohl(addr) >> 24 & 0xff, > - ntohl(addr) >> 16 & 0xff, > - ntohl(addr) >> 8 & 0xff, > - ntohl(addr) >> 0 & 0xff); > +if (ipv6_addr_v4mapped(&(im->m_addr))) { > +snprintf(text_addr, 20, NIPQUAD_FMT, > +ntohl(im->m_addr.s6_addr32[3]) >> 24 & 0xff, > +ntohl(im->m_addr.s6_addr32[3]) >> 16 & 0xff, > +ntohl(im->m_addr.s6_addr32[3]) >> 8 & 0xff, > +ntohl(im->m_addr.s6_addr32[3]) >> 0 & 0xff); > +} else { > +snprintf(text_addr, 40, NIP6_FMT, NIP6(im->m_addr)); > +} > qword_add(bpp, blen, im->m_class); > qword_add(bpp, blen, text_addr); > (*bpp)[-1] = '\n'; > } What happens when an unpatched mountd gets this request? Does it ignore it, or respond with a negative entry? --b. - To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html