Module Name: src Committed By: dyoung Date: Thu Mar 31 19:40:54 UTC 2011
Modified Files: src/sys/conf: files src/sys/net: route.c route.h rtsock.c src/sys/netatalk: at_proto.c src/sys/netinet: in_proto.c src/sys/netinet6: in6_proto.c src/sys/netiso: iso_proto.c src/sys/netmpls: mpls_proto.c src/sys/nfs: nfs_export.c src/sys/rump/librump/rumpnet: Makefile.rumpnet src/sys/rump/net/lib/libnet: Makefile src/sys/rump/net/lib/libsockin: sockin.c src/sys/sys: domain.h Added Files: src/sys/net: rtbl.c src/sys/rump/librump/rumpnet/opt: opt_route.h Log Message: Hide the radix-trie implementation of the forwarding table so that we will have an easier time replacing it with something different, even if it is a second radix-trie implementation. sys/net/route.c and sys/net/rtsock.c no longer operate directly on radix_nodes or radix_node_heads. Hopefully this will reduce the temptation to implement multipath or source-based routing using grotty hacks to the grotty old radix-trie code, too. :-) To generate a diff of this commit: cvs rdiff -u -r1.1005 -r1.1006 src/sys/conf/files cvs rdiff -u -r1.124 -r1.125 src/sys/net/route.c cvs rdiff -u -r1.78 -r1.79 src/sys/net/route.h cvs rdiff -u -r0 -r1.1 src/sys/net/rtbl.c cvs rdiff -u -r1.134 -r1.135 src/sys/net/rtsock.c cvs rdiff -u -r1.16 -r1.17 src/sys/netatalk/at_proto.c cvs rdiff -u -r1.99 -r1.100 src/sys/netinet/in_proto.c cvs rdiff -u -r1.89 -r1.90 src/sys/netinet6/in6_proto.c cvs rdiff -u -r1.28 -r1.29 src/sys/netiso/iso_proto.c cvs rdiff -u -r1.1 -r1.2 src/sys/netmpls/mpls_proto.c cvs rdiff -u -r1.49 -r1.50 src/sys/nfs/nfs_export.c cvs rdiff -u -r1.11 -r1.12 src/sys/rump/librump/rumpnet/Makefile.rumpnet cvs rdiff -u -r0 -r1.1 src/sys/rump/librump/rumpnet/opt/opt_route.h cvs rdiff -u -r1.11 -r1.12 src/sys/rump/net/lib/libnet/Makefile cvs rdiff -u -r1.25 -r1.26 src/sys/rump/net/lib/libsockin/sockin.c cvs rdiff -u -r1.29 -r1.30 src/sys/sys/domain.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/conf/files diff -u src/sys/conf/files:1.1005 src/sys/conf/files:1.1006 --- src/sys/conf/files:1.1005 Sun Mar 20 17:54:02 2011 +++ src/sys/conf/files Thu Mar 31 19:40:51 2011 @@ -1,4 +1,4 @@ -# $NetBSD: files,v 1.1005 2011/03/20 17:54:02 tsutsui Exp $ +# $NetBSD: files,v 1.1006 2011/03/31 19:40:51 dyoung Exp $ # @(#)files.newconf 7.5 (Berkeley) 5/10/93 version 20100430 @@ -1654,6 +1654,7 @@ file net/raw_cb.c file net/raw_usrreq.c file net/route.c +file net/rtbl.c file net/rtsock.c file net/slcompress.c sl | ppp | strip | (irip & irip_vj) file net/zlib.c (ppp & ppp_deflate) | ipsec | opencrypto | vnd_compression Index: src/sys/net/route.c diff -u src/sys/net/route.c:1.124 src/sys/net/route.c:1.125 --- src/sys/net/route.c:1.124 Tue Feb 1 01:39:20 2011 +++ src/sys/net/route.c Thu Mar 31 19:40:52 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: route.c,v 1.124 2011/02/01 01:39:20 matt Exp $ */ +/* $NetBSD: route.c,v 1.125 2011/03/31 19:40:52 dyoung Exp $ */ /*- * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc. @@ -93,9 +93,10 @@ #include "opt_route.h" #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.124 2011/02/01 01:39:20 matt Exp $"); +__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.125 2011/03/31 19:40:52 dyoung Exp $"); #include <sys/param.h> +#include <sys/kmem.h> #include <sys/sysctl.h> #include <sys/systm.h> #include <sys/callout.h> @@ -125,7 +126,6 @@ #endif /* RTFLUSH_DEBUG */ struct rtstat rtstat; -struct radix_node_head *rt_tables[AF_MAX+1]; int rttrash; /* routes not in table but not freed */ @@ -252,16 +252,6 @@ rt_set_ifa1(rt, ifa); } -void -rtable_init(void **table) -{ - struct domain *dom; - DOMAIN_FOREACH(dom) - if (dom->dom_rtattach) - dom->dom_rtattach(&table[dom->dom_family], - dom->dom_rtoffset); -} - static int route_listener_cb(kauth_cred_t cred, kauth_action_t action, void *cookie, void *arg0, void *arg1, void *arg2, void *arg3) @@ -295,7 +285,7 @@ NULL, IPL_SOFTNET); rn_init(); /* initialize all zeroes, all ones, mask table */ - rtable_init((void **)rt_tables); + rtbl_init(); route_listener = kauth_listen_scope(KAUTH_SCOPE_NETWORK, route_listener_cb, NULL); @@ -338,16 +328,14 @@ struct rtentry * rtalloc1(const struct sockaddr *dst, int report) { - struct radix_node_head *rnh = rt_tables[dst->sa_family]; + rtbl_t *rtbl = rt_gettable(dst->sa_family); struct rtentry *rt; - struct radix_node *rn; struct rtentry *newrt = NULL; struct rt_addrinfo info; int s = splsoftnet(), err = 0, msgtype = RTM_MISS; - if (rnh && (rn = rnh->rnh_matchaddr(dst, rnh)) && - ((rn->rn_flags & RNF_ROOT) == 0)) { - newrt = rt = (struct rtentry *)rn; + if (rtbl != NULL && (rt = rt_matchaddr(rtbl, dst)) != NULL) { + newrt = rt; if (report && (rt->rt_flags & RTF_CLONING)) { err = rtrequest(RTM_RESOLVE, dst, NULL, NULL, 0, &newrt); @@ -395,8 +383,7 @@ panic("rtfree"); rt->rt_refcnt--; if (rt->rt_refcnt <= 0 && (rt->rt_flags & RTF_UP) == 0) { - if (rt->rt_nodes->rn_flags & (RNF_ACTIVE | RNF_ROOT)) - panic ("rtfree 2"); + rt_assert_inactive(rt); rttrash--; if (rt->rt_refcnt < 0) { printf("rtfree: %p not freed (neg refs)\n", rt); @@ -697,10 +684,9 @@ rtrequest1(int req, struct rt_addrinfo *info, struct rtentry **ret_nrt) { int s = splsoftnet(); - int error = 0; + int error = 0, rc; struct rtentry *rt, *crt; - struct radix_node *rn; - struct radix_node_head *rnh; + rtbl_t *rtbl; struct ifaddr *ifa, *ifa2; struct sockaddr_storage maskeddst; const struct sockaddr *dst = info->rti_info[RTAX_DST]; @@ -709,7 +695,7 @@ int flags = info->rti_flags; #define senderr(x) { error = x ; goto bad; } - if ((rnh = rt_tables[dst->sa_family]) == NULL) + if ((rtbl = rt_gettable(dst->sa_family)) == NULL) senderr(ESRCH); if (flags & RTF_HOST) netmask = NULL; @@ -720,18 +706,14 @@ netmask); dst = (struct sockaddr *)&maskeddst; } - if ((rn = rnh->rnh_lookup(dst, netmask, rnh)) == NULL) + if ((rt = rt_lookup(rtbl, dst, netmask)) == NULL) senderr(ESRCH); - rt = (struct rtentry *)rn; if ((rt->rt_flags & RTF_CLONING) != 0) { /* clean up any cloned children */ rtflushclone(dst->sa_family, rt); } - if ((rn = rnh->rnh_deladdr(dst, netmask, rnh)) == NULL) + if ((rt = rt_deladdr(rtbl, dst, netmask)) == NULL) senderr(ESRCH); - if (rn->rn_flags & (RNF_ACTIVE | RNF_ROOT)) - panic ("rtrequest delete"); - rt = (struct rtentry *)rn; if (rt->rt_gwroute) { RTFREE(rt->rt_gwroute); rt->rt_gwroute = NULL; @@ -817,21 +799,19 @@ rt->rt_parent->rt_refcnt++; } RT_DPRINTF("rt->_rt_key = %p\n", (void *)rt->_rt_key); - rn = rnh->rnh_addaddr(rt_getkey(rt), netmask, rnh, - rt->rt_nodes); + rc = rt_addaddr(rtbl, rt, netmask); RT_DPRINTF("rt->_rt_key = %p\n", (void *)rt->_rt_key); - if (rn == NULL && (crt = rtalloc1(rt_getkey(rt), 0)) != NULL) { + if (rc != 0 && (crt = rtalloc1(rt_getkey(rt), 0)) != NULL) { /* overwrite cloned route */ if ((crt->rt_flags & RTF_CLONED) != 0) { rtdeletemsg(crt); - rn = rnh->rnh_addaddr(rt_getkey(rt), - netmask, rnh, rt->rt_nodes); + rc = rt_addaddr(rtbl, rt, netmask); } RTFREE(crt); RT_DPRINTF("rt->_rt_key = %p\n", (void *)rt->_rt_key); } RT_DPRINTF("rt->_rt_key = %p\n", (void *)rt->_rt_key); - if (rn == NULL) { + if (rc != 0) { IFAFREE(ifa); if ((rt->rt_flags & RTF_CLONED) != 0 && rt->rt_parent) rtfree(rt->rt_parent); @@ -839,7 +819,7 @@ rtfree(rt->rt_gwroute); rt_destroy(rt); pool_put(&rtentry_pool, rt); - senderr(EEXIST); + senderr(rc); } RT_DPRINTF("rt->_rt_key = %p\n", (void *)rt->_rt_key); if (ifa->ifa_rtrequest) @@ -861,11 +841,9 @@ netmask); dst = (struct sockaddr *)&maskeddst; } - rn = rnh->rnh_lookup(dst, netmask, rnh); - if (rn == NULL || (rn->rn_flags & RNF_ROOT) != 0) + if ((rt = rt_lookup(rtbl, dst, netmask)) == NULL) senderr(ESRCH); if (ret_nrt != NULL) { - rt = (struct rtentry *)rn; *ret_nrt = rt; rt->rt_refcnt++; } @@ -1391,29 +1369,6 @@ return 0; } -static int -rt_walktree_visitor(struct radix_node *rn, void *v) -{ - struct rtwalk *rw = (struct rtwalk *)v; - - return (*rw->rw_f)((struct rtentry *)rn, rw->rw_v); -} - -int -rt_walktree(sa_family_t family, int (*f)(struct rtentry *, void *), void *v) -{ - struct radix_node_head *rnh = rt_tables[family]; - struct rtwalk rw; - - if (rnh == NULL) - return 0; - - rw.rw_f = f; - rw.rw_v = v; - - return rn_walktree(rnh, rt_walktree_visitor, &rw); -} - const struct sockaddr * rt_settag(struct rtentry *rt, const struct sockaddr *tag) { Index: src/sys/net/route.h diff -u src/sys/net/route.h:1.78 src/sys/net/route.h:1.79 --- src/sys/net/route.h:1.78 Tue Feb 1 01:39:20 2011 +++ src/sys/net/route.h Thu Mar 31 19:40:52 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: route.h,v 1.78 2011/02/01 01:39:20 matt Exp $ */ +/* $NetBSD: route.h,v 1.79 2011/03/31 19:40:52 dyoung Exp $ */ /* * Copyright (c) 1980, 1986, 1993 @@ -309,8 +309,15 @@ }; +struct rtbl; +typedef struct rtbl rtbl_t; + #ifdef _KERNEL +struct rtbl { + struct radix_node_head t_rnh; +}; + struct rt_walkarg { int w_op; int w_arg; @@ -347,7 +354,6 @@ extern struct route_info route_info; extern struct rtstat rtstat; -extern struct radix_node_head *rt_tables[AF_MAX+1]; struct socket; struct dom_rtlist; @@ -375,7 +381,6 @@ void rt_timer_remove_all(struct rtentry *, int); unsigned long rt_timer_count(struct rttimer_queue *); void rt_timer_timer(void *); -void rtable_init(void **); void rtcache(struct route *); void rtflushall(int); struct rtentry * @@ -425,8 +430,6 @@ return rt->_rt_key; } -struct rtentry *rtfindparent(struct radix_node_head *, struct route *); - struct rtentry *rtcache_init(struct route *); struct rtentry *rtcache_init_noclone(struct route *); void rtcache_copy(struct route *, const struct route *); @@ -502,9 +505,19 @@ rt->rt_refcnt--; } -int -rt_walktree(sa_family_t, int (*)(struct rtentry *, void *), void *); +int rt_walktree(sa_family_t, int (*)(struct rtentry *, void *), void *); void route_enqueue(struct mbuf *, int); +int rt_inithead(rtbl_t **, int); +struct rtentry *rt_matchaddr(rtbl_t *, const struct sockaddr *); +int rt_addaddr(rtbl_t *, struct rtentry *, const struct sockaddr *); +struct rtentry *rt_lookup(rtbl_t *, const struct sockaddr *, + const struct sockaddr *); +struct rtentry *rt_deladdr(rtbl_t *, const struct sockaddr *, + const struct sockaddr *); +void rtbl_init(void); +rtbl_t *rt_gettable(sa_family_t); +void rt_assert_inactive(const struct rtentry *); #endif /* _KERNEL */ + #endif /* !_NET_ROUTE_H_ */ Index: src/sys/net/rtsock.c diff -u src/sys/net/rtsock.c:1.134 src/sys/net/rtsock.c:1.135 --- src/sys/net/rtsock.c:1.134 Thu Feb 10 07:42:18 2011 +++ src/sys/net/rtsock.c Thu Mar 31 19:40:52 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: rtsock.c,v 1.134 2011/02/10 07:42:18 kefren Exp $ */ +/* $NetBSD: rtsock.c,v 1.135 2011/03/31 19:40:52 dyoung Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -61,7 +61,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.134 2011/02/10 07:42:18 kefren Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.135 2011/03/31 19:40:52 dyoung Exp $"); #ifdef _KERNEL_OPT #include "opt_inet.h" @@ -231,19 +231,6 @@ return error; } -static const struct sockaddr * -intern_netmask(const struct sockaddr *mask) -{ - struct radix_node *rn; - extern struct radix_node_head *mask_rnhead; - - if (mask != NULL && - (rn = rn_search(mask, mask_rnhead->rnh_treetop))) - mask = (const struct sockaddr *)rn->rn_key; - - return mask; -} - /*ARGSUSED*/ int COMPATNAME(route_output)(struct mbuf *m, ...) @@ -351,20 +338,12 @@ if (error != 0) senderr(error); if (rtm->rtm_type != RTM_GET) {/* XXX: too grotty */ - struct radix_node *rn; - if (memcmp(info.rti_info[RTAX_DST], rt_getkey(rt), info.rti_info[RTAX_DST]->sa_len) != 0) senderr(ESRCH); - info.rti_info[RTAX_NETMASK] = intern_netmask( - info.rti_info[RTAX_NETMASK]); - for (rn = rt->rt_nodes; rn; rn = rn->rn_dupedkey) - if (info.rti_info[RTAX_NETMASK] == - (const struct sockaddr *)rn->rn_mask) - break; - if (rn == NULL) + if (info.rti_info[RTAX_NETMASK] == NULL && + rt_mask(rt) != NULL) senderr(ETOOMANYREFS); - rt = (struct rtentry *)rn; } switch (rtm->rtm_type) { Index: src/sys/netatalk/at_proto.c diff -u src/sys/netatalk/at_proto.c:1.16 src/sys/netatalk/at_proto.c:1.17 --- src/sys/netatalk/at_proto.c:1.16 Thu Apr 24 11:38:37 2008 +++ src/sys/netatalk/at_proto.c Thu Mar 31 19:40:52 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: at_proto.c,v 1.16 2008/04/24 11:38:37 ad Exp $ */ +/* $NetBSD: at_proto.c,v 1.17 2011/03/31 19:40:52 dyoung Exp $ */ /* * Copyright (c) 1990,1991 Regents of The University of Michigan. @@ -27,7 +27,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: at_proto.c,v 1.16 2008/04/24 11:38:37 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: at_proto.c,v 1.17 2011/03/31 19:40:52 dyoung Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -73,7 +73,7 @@ .dom_dispose = NULL, .dom_protosw = atalksw, .dom_protoswNPROTOSW = &atalksw[__arraycount(atalksw)], - .dom_rtattach = rn_inithead, + .dom_rtattach = rt_inithead, .dom_rtoffset = 32, .dom_maxrtkey = sizeof(struct sockaddr_at), .dom_ifattach = NULL, Index: src/sys/netinet/in_proto.c diff -u src/sys/netinet/in_proto.c:1.99 src/sys/netinet/in_proto.c:1.100 --- src/sys/netinet/in_proto.c:1.99 Wed Sep 16 15:23:05 2009 +++ src/sys/netinet/in_proto.c Thu Mar 31 19:40:52 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: in_proto.c,v 1.99 2009/09/16 15:23:05 pooka Exp $ */ +/* $NetBSD: in_proto.c,v 1.100 2011/03/31 19:40:52 dyoung Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -61,7 +61,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: in_proto.c,v 1.99 2009/09/16 15:23:05 pooka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: in_proto.c,v 1.100 2011/03/31 19:40:52 dyoung Exp $"); #include "opt_mrouting.h" #include "opt_eon.h" /* ISO CLNL over IP */ @@ -467,7 +467,7 @@ .dom_externalize = NULL, .dom_dispose = NULL, .dom_protosw = inetsw, .dom_protoswNPROTOSW = &inetsw[__arraycount(inetsw)], - .dom_rtattach = rn_inithead, + .dom_rtattach = rt_inithead, .dom_rtoffset = 32, .dom_maxrtkey = sizeof(struct ip_pack4), #ifdef IPSELSRC Index: src/sys/netinet6/in6_proto.c diff -u src/sys/netinet6/in6_proto.c:1.89 src/sys/netinet6/in6_proto.c:1.90 --- src/sys/netinet6/in6_proto.c:1.89 Tue Aug 24 00:07:00 2010 +++ src/sys/netinet6/in6_proto.c Thu Mar 31 19:40:52 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: in6_proto.c,v 1.89 2010/08/24 00:07:00 jakllsch Exp $ */ +/* $NetBSD: in6_proto.c,v 1.90 2011/03/31 19:40:52 dyoung Exp $ */ /* $KAME: in6_proto.c,v 1.66 2000/10/10 15:35:47 itojun Exp $ */ /* @@ -62,7 +62,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: in6_proto.c,v 1.89 2010/08/24 00:07:00 jakllsch Exp $"); +__KERNEL_RCSID(0, "$NetBSD: in6_proto.c,v 1.90 2011/03/31 19:40:52 dyoung Exp $"); #include "opt_gateway.h" #include "opt_inet.h" @@ -412,7 +412,7 @@ .dom_init = NULL, .dom_externalize = NULL, .dom_dispose = NULL, .dom_protosw = (const struct protosw *)inet6sw, .dom_protoswNPROTOSW = (const struct protosw *)&inet6sw[sizeof(inet6sw)/sizeof(inet6sw[0])], - .dom_rtattach = rn_inithead, + .dom_rtattach = rt_inithead, .dom_rtoffset = offsetof(struct sockaddr_in6, sin6_addr) << 3, .dom_maxrtkey = sizeof(struct ip_pack6), .dom_ifattach = in6_domifattach, .dom_ifdetach = in6_domifdetach, Index: src/sys/netiso/iso_proto.c diff -u src/sys/netiso/iso_proto.c:1.28 src/sys/netiso/iso_proto.c:1.29 --- src/sys/netiso/iso_proto.c:1.28 Thu Apr 24 11:38:38 2008 +++ src/sys/netiso/iso_proto.c Thu Mar 31 19:40:53 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: iso_proto.c,v 1.28 2008/04/24 11:38:38 ad Exp $ */ +/* $NetBSD: iso_proto.c,v 1.29 2011/03/31 19:40:53 dyoung Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -65,7 +65,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: iso_proto.c,v 1.28 2008/04/24 11:38:38 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: iso_proto.c,v 1.29 2011/03/31 19:40:53 dyoung Exp $"); #include <sys/param.h> @@ -261,8 +261,8 @@ .dom_dispose = NULL, .dom_protosw = isosw, .dom_protoswNPROTOSW = &isosw[sizeof(isosw) / sizeof(isosw[0])], - .dom_rtattach = rn_inithead, /* rtattach */ - .dom_rtoffset = 48, /* rtoffset */ + .dom_rtattach = rt_inithead, + .dom_rtoffset = 48, .dom_maxrtkey = sizeof(struct sockaddr_iso), /* maxkeylen */ .dom_ifattach = NULL, .dom_ifdetach = NULL, Index: src/sys/netmpls/mpls_proto.c diff -u src/sys/netmpls/mpls_proto.c:1.1 src/sys/netmpls/mpls_proto.c:1.2 --- src/sys/netmpls/mpls_proto.c:1.1 Sat Jun 26 14:24:29 2010 +++ src/sys/netmpls/mpls_proto.c Thu Mar 31 19:40:53 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: mpls_proto.c,v 1.1 2010/06/26 14:24:29 kefren Exp $ */ +/* $NetBSD: mpls_proto.c,v 1.2 2011/03/31 19:40:53 dyoung Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: mpls_proto.c,v 1.1 2010/06/26 14:24:29 kefren Exp $"); +__KERNEL_RCSID(0, "$NetBSD: mpls_proto.c,v 1.2 2011/03/31 19:40:53 dyoung Exp $"); #include "opt_inet.h" #include "opt_mbuftrace.h" @@ -102,7 +102,7 @@ .dom_dispose = NULL, .dom_protosw = mplssw, .dom_protoswNPROTOSW = &mplssw[__arraycount(mplssw)], - .dom_rtattach = rn_inithead, + .dom_rtattach = rt_inithead, .dom_rtoffset = offsetof(struct sockaddr_mpls, smpls_addr) << 3, .dom_maxrtkey = sizeof(union mpls_shim), .dom_ifattach = NULL, Index: src/sys/nfs/nfs_export.c diff -u src/sys/nfs/nfs_export.c:1.49 src/sys/nfs/nfs_export.c:1.50 --- src/sys/nfs/nfs_export.c:1.49 Fri Nov 19 06:44:46 2010 +++ src/sys/nfs/nfs_export.c Thu Mar 31 19:40:53 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: nfs_export.c,v 1.49 2010/11/19 06:44:46 dholland Exp $ */ +/* $NetBSD: nfs_export.c,v 1.50 2011/03/31 19:40:53 dyoung Exp $ */ /*- * Copyright (c) 1997, 1998, 2004, 2005, 2008 The NetBSD Foundation, Inc. @@ -77,7 +77,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: nfs_export.c,v 1.49 2010/11/19 06:44:46 dholland Exp $"); +__KERNEL_RCSID(0, "$NetBSD: nfs_export.c,v 1.50 2011/03/31 19:40:53 dyoung Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -561,7 +561,7 @@ */ DOMAIN_FOREACH(dom) { if (dom->dom_family == i && dom->dom_rtattach) { - dom->dom_rtattach((void **)&nep->ne_rtable[i], + rn_inithead((void **)&nep->ne_rtable[i], dom->dom_rtoffset); break; } Index: src/sys/rump/librump/rumpnet/Makefile.rumpnet diff -u src/sys/rump/librump/rumpnet/Makefile.rumpnet:1.11 src/sys/rump/librump/rumpnet/Makefile.rumpnet:1.12 --- src/sys/rump/librump/rumpnet/Makefile.rumpnet:1.11 Tue Feb 1 01:39:21 2011 +++ src/sys/rump/librump/rumpnet/Makefile.rumpnet Thu Mar 31 19:40:53 2011 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile.rumpnet,v 1.11 2011/02/01 01:39:21 matt Exp $ +# $NetBSD: Makefile.rumpnet,v 1.12 2011/03/31 19:40:53 dyoung Exp $ # .include "${RUMPTOP}/Makefile.rump" @@ -20,6 +20,7 @@ # radix trie support SRCS+= radix.c +SRCS+= rtbl.c # compat (nothing for now) SRCS+= Index: src/sys/rump/net/lib/libnet/Makefile diff -u src/sys/rump/net/lib/libnet/Makefile:1.11 src/sys/rump/net/lib/libnet/Makefile:1.12 --- src/sys/rump/net/lib/libnet/Makefile:1.11 Tue Feb 1 01:39:21 2011 +++ src/sys/rump/net/lib/libnet/Makefile Thu Mar 31 19:40:54 2011 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.11 2011/02/01 01:39:21 matt Exp $ +# $NetBSD: Makefile,v 1.12 2011/03/31 19:40:54 dyoung Exp $ # .PATH: ${.CURDIR}/../../../../net ${.CURDIR}/../../../../compat/common @@ -6,7 +6,7 @@ LIB= rumpnet_net # iffy stuff -SRCS= if.c if_loop.c route.c rtsock.c rtsock_50.c raw_usrreq.c \ +SRCS= if.c if_loop.c route.c rtbl.c rtsock.c rtsock_50.c raw_usrreq.c \ raw_cb.c if_media.c link_proto.c net_stats.c if_ethersubr.c SRCS+= if_43.c uipc_syscalls_50.c SRCS+= component.c Index: src/sys/rump/net/lib/libsockin/sockin.c diff -u src/sys/rump/net/lib/libsockin/sockin.c:1.25 src/sys/rump/net/lib/libsockin/sockin.c:1.26 --- src/sys/rump/net/lib/libsockin/sockin.c:1.25 Sun Dec 5 18:01:46 2010 +++ src/sys/rump/net/lib/libsockin/sockin.c Thu Mar 31 19:40:54 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: sockin.c,v 1.25 2010/12/05 18:01:46 pooka Exp $ */ +/* $NetBSD: sockin.c,v 1.26 2011/03/31 19:40:54 dyoung Exp $ */ /* * Copyright (c) 2008, 2009 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: sockin.c,v 1.25 2010/12/05 18:01:46 pooka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sockin.c,v 1.26 2011/03/31 19:40:54 dyoung Exp $"); #include <sys/param.h> #include <sys/condvar.h> @@ -93,7 +93,7 @@ .dom_dispose = NULL, .dom_protosw = sockinsw, .dom_protoswNPROTOSW = &sockinsw[__arraycount(sockinsw)], - .dom_rtattach = rn_inithead, + .dom_rtattach = rt_inithead, .dom_rtoffset = 32, .dom_maxrtkey = sizeof(struct sockaddr_in), .dom_ifattach = NULL, Index: src/sys/sys/domain.h diff -u src/sys/sys/domain.h:1.29 src/sys/sys/domain.h:1.30 --- src/sys/sys/domain.h:1.29 Fri Sep 11 22:06:29 2009 +++ src/sys/sys/domain.h Thu Mar 31 19:40:54 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: domain.h,v 1.29 2009/09/11 22:06:29 dyoung Exp $ */ +/* $NetBSD: domain.h,v 1.30 2011/03/31 19:40:54 dyoung Exp $ */ /* * Copyright (c) 1982, 1986, 1993 @@ -39,6 +39,7 @@ */ #include <sys/mbuf.h> #include <sys/socket.h> +#include <net/route.h> /* * Forward structure declarations for function prototypes [sic]. @@ -47,7 +48,6 @@ struct mbuf; struct ifnet; struct ifqueue; -struct route; struct sockaddr; LIST_HEAD(dom_rtlist, route); @@ -63,7 +63,7 @@ (struct mbuf *); const struct protosw *dom_protosw, *dom_protoswNPROTOSW; int (*dom_rtattach) /* initialize routing table */ - (void **, int); + (rtbl_t **, int); int dom_rtoffset; /* an arg to rtattach, in bits */ int dom_maxrtkey; /* for routing layer */ void *(*dom_ifattach) /* attach af-dependent data on ifnet */ Added files: Index: src/sys/net/rtbl.c diff -u /dev/null src/sys/net/rtbl.c:1.1 --- /dev/null Thu Mar 31 19:40:55 2011 +++ src/sys/net/rtbl.c Thu Mar 31 19:40:52 2011 @@ -0,0 +1,230 @@ +/* $NetBSD: rtbl.c,v 1.1 2011/03/31 19:40:52 dyoung Exp $ */ + +/*- + * Copyright (c) 1998, 2008, 2011 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Kevin M. Lahey of the Numerical Aerospace Simulation Facility, + * NASA Ames Research Center. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the project nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * Copyright (c) 1980, 1986, 1991, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)route.c 8.3 (Berkeley) 1/9/95 + */ + +#ifdef _KERNEL +#include "opt_route.h" +#endif /* _KERNEL */ + +#include <sys/cdefs.h> +__KERNEL_RCSID(0, "$NetBSD: rtbl.c,v 1.1 2011/03/31 19:40:52 dyoung Exp $"); + +#include <sys/param.h> +#include <sys/kmem.h> +#include <sys/sysctl.h> +#include <sys/systm.h> +#include <sys/callout.h> +#include <sys/proc.h> +#include <sys/mbuf.h> +#include <sys/socket.h> +#include <sys/socketvar.h> +#include <sys/domain.h> +#include <sys/protosw.h> +#include <sys/kernel.h> +#include <sys/ioctl.h> +#include <sys/pool.h> +#include <sys/kauth.h> + +#include <net/if.h> +#include <net/if_dl.h> +#include <net/route.h> +#include <net/raw_cb.h> + +static rtbl_t *rt_tables[AF_MAX+1]; + +int +rt_inithead(rtbl_t **tp, int off) +{ + rtbl_t *t; + if (*tp != NULL) + return 1; + if ((t = kmem_alloc(sizeof(*t), KM_SLEEP)) == NULL) + return 0; + *tp = t; + return rn_inithead0(&t->t_rnh, off); +} + +struct rtentry * +rt_matchaddr(rtbl_t *t, const struct sockaddr *dst) +{ + struct radix_node_head *rnh = &t->t_rnh; + struct radix_node *rn; + + rn = rnh->rnh_matchaddr(dst, rnh); + if (rn == NULL || (rn->rn_flags & RNF_ROOT) != 0) + return NULL; + return (struct rtentry *)rn; +} + +int +rt_addaddr(rtbl_t *t, struct rtentry *rt, const struct sockaddr *netmask) +{ + struct radix_node_head *rnh = &t->t_rnh; + struct radix_node *rn; + + rn = rnh->rnh_addaddr(rt_getkey(rt), netmask, rnh, rt->rt_nodes); + + return (rn == NULL) ? EEXIST : 0; +} + +struct rtentry * +rt_lookup(rtbl_t *t, const struct sockaddr *dst, const struct sockaddr *netmask) +{ + struct radix_node_head *rnh = &t->t_rnh; + struct radix_node *rn; + + rn = rnh->rnh_lookup(dst, netmask, rnh); + if (rn == NULL || (rn->rn_flags & RNF_ROOT) != 0) + return NULL; + return (struct rtentry *)rn; +} + +struct rtentry * +rt_deladdr(rtbl_t *t, const struct sockaddr *dst, + const struct sockaddr *netmask) +{ + struct radix_node_head *rnh = &t->t_rnh; + struct radix_node *rn; + + if ((rn = rnh->rnh_deladdr(dst, netmask, rnh)) == NULL) + return NULL; + if (rn->rn_flags & (RNF_ACTIVE | RNF_ROOT)) + panic("%s", __func__); + return (struct rtentry *)rn; +} + +static int +rt_walktree_visitor(struct radix_node *rn, void *v) +{ + struct rtwalk *rw = (struct rtwalk *)v; + + return (*rw->rw_f)((struct rtentry *)rn, rw->rw_v); +} + +int +rt_walktree(sa_family_t family, int (*f)(struct rtentry *, void *), void *v) +{ + rtbl_t *t = rt_tables[family]; + struct rtwalk rw; + + if (t == NULL) + return 0; + + rw.rw_f = f; + rw.rw_v = v; + + return rn_walktree(&t->t_rnh, rt_walktree_visitor, &rw); +} + +rtbl_t * +rt_gettable(sa_family_t af) +{ + if (af >= __arraycount(rt_tables)) + return NULL; + return rt_tables[af]; +} + +void +rtbl_init(void) +{ + struct domain *dom; + DOMAIN_FOREACH(dom) + if (dom->dom_rtattach) + dom->dom_rtattach(&rt_tables[dom->dom_family], + dom->dom_rtoffset); +} + +void +rt_assert_inactive(const struct rtentry *rt) +{ + if (rt->rt_nodes->rn_flags & (RNF_ACTIVE | RNF_ROOT)) + panic ("rtfree 2"); +} Index: src/sys/rump/librump/rumpnet/opt/opt_route.h diff -u /dev/null src/sys/rump/librump/rumpnet/opt/opt_route.h:1.1 --- /dev/null Thu Mar 31 19:40:55 2011 +++ src/sys/rump/librump/rumpnet/opt/opt_route.h Thu Mar 31 19:40:53 2011 @@ -0,0 +1,3 @@ +/* $NetBSD: opt_route.h,v 1.1 2011/03/31 19:40:53 dyoung Exp $ */ + +/* dummy */