Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Hide the radix-trie implementation of the forwarding tab...
details: https://anonhg.NetBSD.org/src/rev/e775d5e6f26e
branches: trunk
changeset: 763718:e775d5e6f26e
user: dyoung <dyoung%NetBSD.org@localhost>
date: Thu Mar 31 19:40:51 2011 +0000
description:
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. :-)
diffstat:
sys/conf/files | 3 +-
sys/net/route.c | 83 ++--------
sys/net/route.h | 27 ++-
sys/net/rtbl.c | 230 ++++++++++++++++++++++++++++++
sys/net/rtsock.c | 29 +---
sys/netatalk/at_proto.c | 6 +-
sys/netinet/in_proto.c | 6 +-
sys/netinet6/in6_proto.c | 6 +-
sys/netiso/iso_proto.c | 8 +-
sys/netmpls/mpls_proto.c | 6 +-
sys/nfs/nfs_export.c | 6 +-
sys/rump/librump/rumpnet/Makefile.rumpnet | 3 +-
sys/rump/librump/rumpnet/opt/opt_route.h | 3 +
sys/rump/net/lib/libnet/Makefile | 4 +-
sys/rump/net/lib/libsockin/sockin.c | 6 +-
sys/sys/domain.h | 6 +-
16 files changed, 307 insertions(+), 125 deletions(-)
diffs (truncated from 857 to 300 lines):
diff -r 6aa02b7d0841 -r e775d5e6f26e sys/conf/files
--- a/sys/conf/files Thu Mar 31 17:00:57 2011 +0000
+++ b/sys/conf/files Thu Mar 31 19:40:51 2011 +0000
@@ -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
diff -r 6aa02b7d0841 -r e775d5e6f26e sys/net/route.c
--- a/sys/net/route.c Thu Mar 31 17:00:57 2011 +0000
+++ b/sys/net/route.c Thu Mar 31 19:40:51 2011 +0000
@@ -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)
{
diff -r 6aa02b7d0841 -r e775d5e6f26e sys/net/route.h
--- a/sys/net/route.h Thu Mar 31 17:00:57 2011 +0000
+++ b/sys/net/route.h Thu Mar 31 19:40:51 2011 +0000
@@ -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_ */
diff -r 6aa02b7d0841 -r e775d5e6f26e sys/net/rtbl.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/net/rtbl.c Thu Mar 31 19:40:51 2011 +0000
@@ -0,0 +1,230 @@
+/* $NetBSD: rtbl.c,v 1.1 2011/03/31 19:40:52 dyoung Exp $ */
Home |
Main Index |
Thread Index |
Old Index