1 #include <linux/types.h>
2 #include <linux/sched.h>
3 #include <linux/module.h>
4 #include <linux/sunrpc/types.h>
5 #include <linux/sunrpc/xdr.h>
6 #include <linux/sunrpc/svcsock.h>
7 #include <linux/sunrpc/svcauth.h>
8 #include <linux/sunrpc/gss_api.h>
10 #include <linux/seq_file.h>
11 #include <linux/hash.h>
12 #include <linux/string.h>
13 #include <linux/slab.h>
16 #include <linux/kernel.h>
17 #define RPCDBG_FACILITY RPCDBG_AUTH
19 #include <linux/sunrpc/clnt.h>
24 * AUTHUNIX and AUTHNULL credentials are both handled here.
25 * AUTHNULL is treated just like AUTHUNIX except that the uid/gid
26 * are always nobody (-2). i.e. we do the same IP address checks for
27 * AUTHNULL as for AUTHUNIX, and that is done here.
33 #ifdef CONFIG_NFSD_DEPRECATED
35 #endif /* CONFIG_NFSD_DEPRECATED */
36 /* other stuff later */
39 extern struct auth_ops svcauth_unix;
41 static void svcauth_unix_domain_release(struct auth_domain *dom)
43 struct unix_domain *ud = container_of(dom, struct unix_domain, h);
49 struct auth_domain *unix_domain_find(char *name)
51 struct auth_domain *rv;
52 struct unix_domain *new = NULL;
54 rv = auth_domain_lookup(name, NULL);
57 if (new && rv != &new->h)
58 svcauth_unix_domain_release(new);
60 if (rv->flavour != &svcauth_unix) {
67 new = kmalloc(sizeof(*new), GFP_KERNEL);
70 kref_init(&new->h.ref);
71 new->h.name = kstrdup(name, GFP_KERNEL);
72 if (new->h.name == NULL) {
76 new->h.flavour = &svcauth_unix;
77 #ifdef CONFIG_NFSD_DEPRECATED
78 new->addr_changes = 0;
79 #endif /* CONFIG_NFSD_DEPRECATED */
80 rv = auth_domain_lookup(name, &new->h);
83 EXPORT_SYMBOL_GPL(unix_domain_find);
86 /**************************************************
87 * cache for IP address to unix_domain
88 * as needed by AUTH_UNIX
91 #define IP_HASHMAX (1<<IP_HASHBITS)
95 char m_class[8]; /* e.g. "nfsd" */
96 struct in6_addr m_addr;
97 struct unix_domain *m_client;
98 #ifdef CONFIG_NFSD_DEPRECATED
100 #endif /* CONFIG_NFSD_DEPRECATED */
103 static void ip_map_put(struct kref *kref)
105 struct cache_head *item = container_of(kref, struct cache_head, ref);
106 struct ip_map *im = container_of(item, struct ip_map,h);
108 if (test_bit(CACHE_VALID, &item->flags) &&
109 !test_bit(CACHE_NEGATIVE, &item->flags))
110 auth_domain_put(&im->m_client->h);
115 /* hash_long on a 64 bit machine is currently REALLY BAD for
116 * IP addresses in reverse-endian (i.e. on a little-endian machine).
117 * So use a trivial but reliable hash instead
119 static inline int hash_ip(__be32 ip)
121 int hash = (__force u32)ip ^ ((__force u32)ip>>16);
122 return (hash ^ (hash>>8)) & 0xff;
125 static inline int hash_ip6(struct in6_addr ip)
127 return (hash_ip(ip.s6_addr32[0]) ^
128 hash_ip(ip.s6_addr32[1]) ^
129 hash_ip(ip.s6_addr32[2]) ^
130 hash_ip(ip.s6_addr32[3]));
132 static int ip_map_match(struct cache_head *corig, struct cache_head *cnew)
134 struct ip_map *orig = container_of(corig, struct ip_map, h);
135 struct ip_map *new = container_of(cnew, struct ip_map, h);
136 return strcmp(orig->m_class, new->m_class) == 0 &&
137 ipv6_addr_equal(&orig->m_addr, &new->m_addr);
139 static void ip_map_init(struct cache_head *cnew, struct cache_head *citem)
141 struct ip_map *new = container_of(cnew, struct ip_map, h);
142 struct ip_map *item = container_of(citem, struct ip_map, h);
144 strcpy(new->m_class, item->m_class);
145 ipv6_addr_copy(&new->m_addr, &item->m_addr);
147 static void update(struct cache_head *cnew, struct cache_head *citem)
149 struct ip_map *new = container_of(cnew, struct ip_map, h);
150 struct ip_map *item = container_of(citem, struct ip_map, h);
152 kref_get(&item->m_client->h.ref);
153 new->m_client = item->m_client;
154 #ifdef CONFIG_NFSD_DEPRECATED
155 new->m_add_change = item->m_add_change;
156 #endif /* CONFIG_NFSD_DEPRECATED */
158 static struct cache_head *ip_map_alloc(void)
160 struct ip_map *i = kmalloc(sizeof(*i), GFP_KERNEL);
167 static void ip_map_request(struct cache_detail *cd,
168 struct cache_head *h,
169 char **bpp, int *blen)
172 struct ip_map *im = container_of(h, struct ip_map, h);
174 if (ipv6_addr_v4mapped(&(im->m_addr))) {
175 snprintf(text_addr, 20, "%pI4", &im->m_addr.s6_addr32[3]);
177 snprintf(text_addr, 40, "%pI6", &im->m_addr);
179 qword_add(bpp, blen, im->m_class);
180 qword_add(bpp, blen, text_addr);
184 static int ip_map_upcall(struct cache_detail *cd, struct cache_head *h)
186 return sunrpc_cache_pipe_upcall(cd, h, ip_map_request);
189 static struct ip_map *__ip_map_lookup(struct cache_detail *cd, char *class, struct in6_addr *addr);
190 static int __ip_map_update(struct cache_detail *cd, struct ip_map *ipm, struct unix_domain *udom, time_t expiry);
192 static int ip_map_parse(struct cache_detail *cd,
193 char *mesg, int mlen)
195 /* class ipaddress [domainname] */
196 /* should be safe just to use the start of the input buffer
203 struct sockaddr_in s4;
204 struct sockaddr_in6 s6;
206 struct sockaddr_in6 sin6;
210 struct auth_domain *dom;
213 if (mesg[mlen-1] != '\n')
218 len = qword_get(&mesg, class, sizeof(class));
219 if (len <= 0) return -EINVAL;
222 len = qword_get(&mesg, buf, mlen);
223 if (len <= 0) return -EINVAL;
225 if (rpc_pton(buf, len, &address.sa, sizeof(address)) == 0)
227 switch (address.sa.sa_family) {
229 /* Form a mapped IPv4 address in sin6 */
230 sin6.sin6_family = AF_INET6;
231 ipv6_addr_set_v4mapped(address.s4.sin_addr.s_addr,
234 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
236 memcpy(&sin6, &address.s6, sizeof(sin6));
243 expiry = get_expiry(&mesg);
247 /* domainname, or empty for NEGATIVE */
248 len = qword_get(&mesg, buf, mlen);
249 if (len < 0) return -EINVAL;
252 dom = unix_domain_find(buf);
258 /* IPv6 scope IDs are ignored for now */
259 ipmp = __ip_map_lookup(cd, class, &sin6.sin6_addr);
261 err = __ip_map_update(cd, ipmp,
262 container_of(dom, struct unix_domain, h),
268 auth_domain_put(dom);
274 static int ip_map_show(struct seq_file *m,
275 struct cache_detail *cd,
276 struct cache_head *h)
279 struct in6_addr addr;
280 char *dom = "-no-domain-";
283 seq_puts(m, "#class IP domain\n");
286 im = container_of(h, struct ip_map, h);
287 /* class addr domain */
288 ipv6_addr_copy(&addr, &im->m_addr);
290 if (test_bit(CACHE_VALID, &h->flags) &&
291 !test_bit(CACHE_NEGATIVE, &h->flags))
292 dom = im->m_client->h.name;
294 if (ipv6_addr_v4mapped(&addr)) {
295 seq_printf(m, "%s %pI4 %s\n",
296 im->m_class, &addr.s6_addr32[3], dom);
298 seq_printf(m, "%s %pI6 %s\n", im->m_class, &addr, dom);
304 static struct ip_map *__ip_map_lookup(struct cache_detail *cd, char *class,
305 struct in6_addr *addr)
308 struct cache_head *ch;
310 strcpy(ip.m_class, class);
311 ipv6_addr_copy(&ip.m_addr, addr);
312 ch = sunrpc_cache_lookup(cd, &ip.h,
313 hash_str(class, IP_HASHBITS) ^
317 return container_of(ch, struct ip_map, h);
322 static inline struct ip_map *ip_map_lookup(struct net *net, char *class,
323 struct in6_addr *addr)
325 struct sunrpc_net *sn;
327 sn = net_generic(net, sunrpc_net_id);
328 return __ip_map_lookup(sn->ip_map_cache, class, addr);
331 static int __ip_map_update(struct cache_detail *cd, struct ip_map *ipm,
332 struct unix_domain *udom, time_t expiry)
335 struct cache_head *ch;
340 set_bit(CACHE_NEGATIVE, &ip.h.flags);
341 #ifdef CONFIG_NFSD_DEPRECATED
343 ip.m_add_change = udom->addr_changes;
344 /* if this is from the legacy set_client system call,
345 * we need m_add_change to be one higher
350 #endif /* CONFIG_NFSD_DEPRECATED */
351 ip.h.expiry_time = expiry;
352 ch = sunrpc_cache_update(cd, &ip.h, &ipm->h,
353 hash_str(ipm->m_class, IP_HASHBITS) ^
354 hash_ip6(ipm->m_addr));
361 static inline int ip_map_update(struct net *net, struct ip_map *ipm,
362 struct unix_domain *udom, time_t expiry)
364 struct sunrpc_net *sn;
366 sn = net_generic(net, sunrpc_net_id);
367 return __ip_map_update(sn->ip_map_cache, ipm, udom, expiry);
370 #ifdef CONFIG_NFSD_DEPRECATED
371 int auth_unix_add_addr(struct net *net, struct in6_addr *addr, struct auth_domain *dom)
373 struct unix_domain *udom;
376 if (dom->flavour != &svcauth_unix)
378 udom = container_of(dom, struct unix_domain, h);
379 ipmp = ip_map_lookup(net, "nfsd", addr);
382 return ip_map_update(net, ipmp, udom, NEVER);
386 EXPORT_SYMBOL_GPL(auth_unix_add_addr);
388 int auth_unix_forget_old(struct auth_domain *dom)
390 struct unix_domain *udom;
392 if (dom->flavour != &svcauth_unix)
394 udom = container_of(dom, struct unix_domain, h);
395 udom->addr_changes++;
398 EXPORT_SYMBOL_GPL(auth_unix_forget_old);
400 struct auth_domain *auth_unix_lookup(struct net *net, struct in6_addr *addr)
403 struct auth_domain *rv;
404 struct sunrpc_net *sn;
406 sn = net_generic(net, sunrpc_net_id);
407 ipm = ip_map_lookup(net, "nfsd", addr);
411 if (cache_check(sn->ip_map_cache, &ipm->h, NULL))
414 if ((ipm->m_client->addr_changes - ipm->m_add_change) >0) {
415 sunrpc_invalidate(&ipm->h, sn->ip_map_cache);
418 rv = &ipm->m_client->h;
421 cache_put(&ipm->h, sn->ip_map_cache);
424 EXPORT_SYMBOL_GPL(auth_unix_lookup);
425 #endif /* CONFIG_NFSD_DEPRECATED */
427 void svcauth_unix_purge(void)
432 struct sunrpc_net *sn;
434 sn = net_generic(net, sunrpc_net_id);
435 cache_purge(sn->ip_map_cache);
438 EXPORT_SYMBOL_GPL(svcauth_unix_purge);
440 static inline struct ip_map *
441 ip_map_cached_get(struct svc_xprt *xprt)
443 struct ip_map *ipm = NULL;
444 struct sunrpc_net *sn;
446 if (test_bit(XPT_CACHE_AUTH, &xprt->xpt_flags)) {
447 spin_lock(&xprt->xpt_lock);
448 ipm = xprt->xpt_auth_cache;
450 if (!cache_valid(&ipm->h)) {
452 * The entry has been invalidated since it was
453 * remembered, e.g. by a second mount from the
456 sn = net_generic(xprt->xpt_net, sunrpc_net_id);
457 xprt->xpt_auth_cache = NULL;
458 spin_unlock(&xprt->xpt_lock);
459 cache_put(&ipm->h, sn->ip_map_cache);
464 spin_unlock(&xprt->xpt_lock);
470 ip_map_cached_put(struct svc_xprt *xprt, struct ip_map *ipm)
472 if (test_bit(XPT_CACHE_AUTH, &xprt->xpt_flags)) {
473 spin_lock(&xprt->xpt_lock);
474 if (xprt->xpt_auth_cache == NULL) {
475 /* newly cached, keep the reference */
476 xprt->xpt_auth_cache = ipm;
479 spin_unlock(&xprt->xpt_lock);
482 struct sunrpc_net *sn;
484 sn = net_generic(xprt->xpt_net, sunrpc_net_id);
485 cache_put(&ipm->h, sn->ip_map_cache);
490 svcauth_unix_info_release(struct svc_xprt *xpt)
494 ipm = xpt->xpt_auth_cache;
496 struct sunrpc_net *sn;
498 sn = net_generic(xpt->xpt_net, sunrpc_net_id);
499 cache_put(&ipm->h, sn->ip_map_cache);
503 /****************************************************************************
504 * auth.unix.gid cache
505 * simple cache to map a UID to a list of GIDs
506 * because AUTH_UNIX aka AUTH_SYS has a max of 16
508 #define GID_HASHBITS 8
509 #define GID_HASHMAX (1<<GID_HASHBITS)
514 struct group_info *gi;
516 static struct cache_head *gid_table[GID_HASHMAX];
518 static void unix_gid_put(struct kref *kref)
520 struct cache_head *item = container_of(kref, struct cache_head, ref);
521 struct unix_gid *ug = container_of(item, struct unix_gid, h);
522 if (test_bit(CACHE_VALID, &item->flags) &&
523 !test_bit(CACHE_NEGATIVE, &item->flags))
524 put_group_info(ug->gi);
528 static int unix_gid_match(struct cache_head *corig, struct cache_head *cnew)
530 struct unix_gid *orig = container_of(corig, struct unix_gid, h);
531 struct unix_gid *new = container_of(cnew, struct unix_gid, h);
532 return orig->uid == new->uid;
534 static void unix_gid_init(struct cache_head *cnew, struct cache_head *citem)
536 struct unix_gid *new = container_of(cnew, struct unix_gid, h);
537 struct unix_gid *item = container_of(citem, struct unix_gid, h);
538 new->uid = item->uid;
540 static void unix_gid_update(struct cache_head *cnew, struct cache_head *citem)
542 struct unix_gid *new = container_of(cnew, struct unix_gid, h);
543 struct unix_gid *item = container_of(citem, struct unix_gid, h);
545 get_group_info(item->gi);
548 static struct cache_head *unix_gid_alloc(void)
550 struct unix_gid *g = kmalloc(sizeof(*g), GFP_KERNEL);
557 static void unix_gid_request(struct cache_detail *cd,
558 struct cache_head *h,
559 char **bpp, int *blen)
562 struct unix_gid *ug = container_of(h, struct unix_gid, h);
564 snprintf(tuid, 20, "%u", ug->uid);
565 qword_add(bpp, blen, tuid);
569 static int unix_gid_upcall(struct cache_detail *cd, struct cache_head *h)
571 return sunrpc_cache_pipe_upcall(cd, h, unix_gid_request);
574 static struct unix_gid *unix_gid_lookup(uid_t uid);
575 extern struct cache_detail unix_gid_cache;
577 static int unix_gid_parse(struct cache_detail *cd,
578 char *mesg, int mlen)
580 /* uid expiry Ngid gid0 gid1 ... gidN-1 */
587 struct unix_gid ug, *ugp;
589 if (mlen <= 0 || mesg[mlen-1] != '\n')
593 rv = get_int(&mesg, &uid);
598 expiry = get_expiry(&mesg);
602 rv = get_int(&mesg, &gids);
603 if (rv || gids < 0 || gids > 8192)
606 ug.gi = groups_alloc(gids);
610 for (i = 0 ; i < gids ; i++) {
612 rv = get_int(&mesg, &gid);
616 GROUP_AT(ug.gi, i) = gid;
619 ugp = unix_gid_lookup(uid);
621 struct cache_head *ch;
623 ug.h.expiry_time = expiry;
624 ch = sunrpc_cache_update(&unix_gid_cache,
626 hash_long(uid, GID_HASHBITS));
631 cache_put(ch, &unix_gid_cache);
637 put_group_info(ug.gi);
641 static int unix_gid_show(struct seq_file *m,
642 struct cache_detail *cd,
643 struct cache_head *h)
650 seq_puts(m, "#uid cnt: gids...\n");
653 ug = container_of(h, struct unix_gid, h);
654 if (test_bit(CACHE_VALID, &h->flags) &&
655 !test_bit(CACHE_NEGATIVE, &h->flags))
656 glen = ug->gi->ngroups;
660 seq_printf(m, "%u %d:", ug->uid, glen);
661 for (i = 0; i < glen; i++)
662 seq_printf(m, " %d", GROUP_AT(ug->gi, i));
667 struct cache_detail unix_gid_cache = {
668 .owner = THIS_MODULE,
669 .hash_size = GID_HASHMAX,
670 .hash_table = gid_table,
671 .name = "auth.unix.gid",
672 .cache_put = unix_gid_put,
673 .cache_upcall = unix_gid_upcall,
674 .cache_parse = unix_gid_parse,
675 .cache_show = unix_gid_show,
676 .match = unix_gid_match,
677 .init = unix_gid_init,
678 .update = unix_gid_update,
679 .alloc = unix_gid_alloc,
682 static struct unix_gid *unix_gid_lookup(uid_t uid)
685 struct cache_head *ch;
688 ch = sunrpc_cache_lookup(&unix_gid_cache, &ug.h,
689 hash_long(uid, GID_HASHBITS));
691 return container_of(ch, struct unix_gid, h);
696 static struct group_info *unix_gid_find(uid_t uid, struct svc_rqst *rqstp)
699 struct group_info *gi;
702 ug = unix_gid_lookup(uid);
704 return ERR_PTR(-EAGAIN);
705 ret = cache_check(&unix_gid_cache, &ug->h, &rqstp->rq_chandle);
708 return ERR_PTR(-ENOENT);
710 return ERR_PTR(-ESHUTDOWN);
712 gi = get_group_info(ug->gi);
713 cache_put(&ug->h, &unix_gid_cache);
716 return ERR_PTR(-EAGAIN);
721 svcauth_unix_set_client(struct svc_rqst *rqstp)
723 struct sockaddr_in *sin;
724 struct sockaddr_in6 *sin6, sin6_storage;
726 struct group_info *gi;
727 struct svc_cred *cred = &rqstp->rq_cred;
728 struct svc_xprt *xprt = rqstp->rq_xprt;
729 struct net *net = xprt->xpt_net;
730 struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
732 switch (rqstp->rq_addr.ss_family) {
734 sin = svc_addr_in(rqstp);
735 sin6 = &sin6_storage;
736 ipv6_addr_set_v4mapped(sin->sin_addr.s_addr, &sin6->sin6_addr);
739 sin6 = svc_addr_in6(rqstp);
745 rqstp->rq_client = NULL;
746 if (rqstp->rq_proc == 0)
749 ipm = ip_map_cached_get(xprt);
751 ipm = __ip_map_lookup(sn->ip_map_cache, rqstp->rq_server->sv_program->pg_class,
757 switch (cache_check(sn->ip_map_cache, &ipm->h, &rqstp->rq_chandle)) {
767 rqstp->rq_client = &ipm->m_client->h;
768 kref_get(&rqstp->rq_client->ref);
769 ip_map_cached_put(xprt, ipm);
773 gi = unix_gid_find(cred->cr_uid, rqstp);
774 switch (PTR_ERR(gi)) {
782 put_group_info(cred->cr_group_info);
783 cred->cr_group_info = gi;
788 EXPORT_SYMBOL_GPL(svcauth_unix_set_client);
791 svcauth_null_accept(struct svc_rqst *rqstp, __be32 *authp)
793 struct kvec *argv = &rqstp->rq_arg.head[0];
794 struct kvec *resv = &rqstp->rq_res.head[0];
795 struct svc_cred *cred = &rqstp->rq_cred;
797 cred->cr_group_info = NULL;
798 rqstp->rq_client = NULL;
800 if (argv->iov_len < 3*4)
803 if (svc_getu32(argv) != 0) {
804 dprintk("svc: bad null cred\n");
805 *authp = rpc_autherr_badcred;
808 if (svc_getu32(argv) != htonl(RPC_AUTH_NULL) || svc_getu32(argv) != 0) {
809 dprintk("svc: bad null verf\n");
810 *authp = rpc_autherr_badverf;
814 /* Signal that mapping to nobody uid/gid is required */
815 cred->cr_uid = (uid_t) -1;
816 cred->cr_gid = (gid_t) -1;
817 cred->cr_group_info = groups_alloc(0);
818 if (cred->cr_group_info == NULL)
819 return SVC_CLOSE; /* kmalloc failure - client must retry */
821 /* Put NULL verifier */
822 svc_putnl(resv, RPC_AUTH_NULL);
825 rqstp->rq_flavor = RPC_AUTH_NULL;
830 svcauth_null_release(struct svc_rqst *rqstp)
832 if (rqstp->rq_client)
833 auth_domain_put(rqstp->rq_client);
834 rqstp->rq_client = NULL;
835 if (rqstp->rq_cred.cr_group_info)
836 put_group_info(rqstp->rq_cred.cr_group_info);
837 rqstp->rq_cred.cr_group_info = NULL;
839 return 0; /* don't drop */
843 struct auth_ops svcauth_null = {
845 .owner = THIS_MODULE,
846 .flavour = RPC_AUTH_NULL,
847 .accept = svcauth_null_accept,
848 .release = svcauth_null_release,
849 .set_client = svcauth_unix_set_client,
854 svcauth_unix_accept(struct svc_rqst *rqstp, __be32 *authp)
856 struct kvec *argv = &rqstp->rq_arg.head[0];
857 struct kvec *resv = &rqstp->rq_res.head[0];
858 struct svc_cred *cred = &rqstp->rq_cred;
860 int len = argv->iov_len;
862 cred->cr_group_info = NULL;
863 rqstp->rq_client = NULL;
865 if ((len -= 3*4) < 0)
868 svc_getu32(argv); /* length */
869 svc_getu32(argv); /* time stamp */
870 slen = XDR_QUADLEN(svc_getnl(argv)); /* machname length */
871 if (slen > 64 || (len -= (slen + 3)*4) < 0)
873 argv->iov_base = (void*)((__be32*)argv->iov_base + slen); /* skip machname */
874 argv->iov_len -= slen*4;
876 cred->cr_uid = svc_getnl(argv); /* uid */
877 cred->cr_gid = svc_getnl(argv); /* gid */
878 slen = svc_getnl(argv); /* gids length */
879 if (slen > 16 || (len -= (slen + 2)*4) < 0)
881 cred->cr_group_info = groups_alloc(slen);
882 if (cred->cr_group_info == NULL)
884 for (i = 0; i < slen; i++)
885 GROUP_AT(cred->cr_group_info, i) = svc_getnl(argv);
886 if (svc_getu32(argv) != htonl(RPC_AUTH_NULL) || svc_getu32(argv) != 0) {
887 *authp = rpc_autherr_badverf;
891 /* Put NULL verifier */
892 svc_putnl(resv, RPC_AUTH_NULL);
895 rqstp->rq_flavor = RPC_AUTH_UNIX;
899 *authp = rpc_autherr_badcred;
904 svcauth_unix_release(struct svc_rqst *rqstp)
906 /* Verifier (such as it is) is already in place.
908 if (rqstp->rq_client)
909 auth_domain_put(rqstp->rq_client);
910 rqstp->rq_client = NULL;
911 if (rqstp->rq_cred.cr_group_info)
912 put_group_info(rqstp->rq_cred.cr_group_info);
913 rqstp->rq_cred.cr_group_info = NULL;
919 struct auth_ops svcauth_unix = {
921 .owner = THIS_MODULE,
922 .flavour = RPC_AUTH_UNIX,
923 .accept = svcauth_unix_accept,
924 .release = svcauth_unix_release,
925 .domain_release = svcauth_unix_domain_release,
926 .set_client = svcauth_unix_set_client,
929 int ip_map_cache_create(struct net *net)
932 struct cache_detail *cd;
933 struct cache_head **tbl;
934 struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
936 cd = kzalloc(sizeof(struct cache_detail), GFP_KERNEL);
940 tbl = kzalloc(IP_HASHMAX * sizeof(struct cache_head *), GFP_KERNEL);
944 cd->owner = THIS_MODULE,
945 cd->hash_size = IP_HASHMAX,
946 cd->hash_table = tbl,
947 cd->name = "auth.unix.ip",
948 cd->cache_put = ip_map_put,
949 cd->cache_upcall = ip_map_upcall,
950 cd->cache_parse = ip_map_parse,
951 cd->cache_show = ip_map_show,
952 cd->match = ip_map_match,
953 cd->init = ip_map_init,
955 cd->alloc = ip_map_alloc,
957 err = cache_register_net(cd, net);
961 sn->ip_map_cache = cd;
972 void ip_map_cache_destroy(struct net *net)
974 struct sunrpc_net *sn;
976 sn = net_generic(net, sunrpc_net_id);
977 cache_purge(sn->ip_map_cache);
978 cache_unregister_net(sn->ip_map_cache, net);
979 kfree(sn->ip_map_cache->hash_table);
980 kfree(sn->ip_map_cache);