diff options
author | zec <zec@FreeBSD.org> | 2009-05-05 10:56:12 +0000 |
---|---|---|
committer | zec <zec@FreeBSD.org> | 2009-05-05 10:56:12 +0000 |
commit | d78a1b1a824c4f5eb8cb3583bb5265f73dcc24dd (patch) | |
tree | 79a0bccccf2c92504cdf23ad15f7c1813bb3f926 /sys/netinet6 | |
parent | 8e4ffe653f6c9ff6da3eed58566ef35e77d530d0 (diff) | |
download | FreeBSD-src-d78a1b1a824c4f5eb8cb3583bb5265f73dcc24dd.zip FreeBSD-src-d78a1b1a824c4f5eb8cb3583bb5265f73dcc24dd.tar.gz |
Change the curvnet variable from a global const struct vnet *,
previously always pointing to the default vnet context, to a
dynamically changing thread-local one. The currvnet context
should be set on entry to networking code via CURVNET_SET() macros,
and reverted to previous state via CURVNET_RESTORE(). Recursions
on curvnet are permitted, though strongly discuouraged.
This change should have no functional impact on nooptions VIMAGE
kernel builds, where CURVNET_* macros expand to whitespace.
The curthread->td_vnet (aka curvnet) variable's purpose is to be an
indicator of the vnet context in which the current network-related
operation takes place, in case we cannot deduce the current vnet
context from any other source, such as by looking at mbuf's
m->m_pkthdr.rcvif->if_vnet, sockets's so->so_vnet etc. Moreover, so
far curvnet has turned out to be an invaluable consistency checking
aid: it helps to catch cases when sockets, ifnets or any other
vnet-aware structures may have leaked from one vnet to another.
The exact placement of the CURVNET_SET() / CURVNET_RESTORE() macros
was a result of an empirical iterative process, whith an aim to
reduce recursions on CURVNET_SET() to a minimum, while still reducing
the scope of CURVNET_SET() to networking only operations - the
alternative would be calling CURVNET_SET() on each system call entry.
In general, curvnet has to be set in three typicall cases: when
processing socket-related requests from userspace or from within the
kernel; when processing inbound traffic flowing from device drivers
to upper layers of the networking stack, and when executing
timer-driven networking functions.
This change also introduces a DDB subcommand to show the list of all
vnet instances.
Approved by: julian (mentor)
Diffstat (limited to 'sys/netinet6')
-rw-r--r-- | sys/netinet6/in6_rmx.c | 16 | ||||
-rw-r--r-- | sys/netinet6/ip6_mroute.c | 6 | ||||
-rw-r--r-- | sys/netinet6/mld6.c | 8 | ||||
-rw-r--r-- | sys/netinet6/nd6.c | 10 | ||||
-rw-r--r-- | sys/netinet6/nd6_nbr.c | 20 |
5 files changed, 37 insertions, 23 deletions
diff --git a/sys/netinet6/in6_rmx.c b/sys/netinet6/in6_rmx.c index 3cc4468..70909b1 100644 --- a/sys/netinet6/in6_rmx.c +++ b/sys/netinet6/in6_rmx.c @@ -289,8 +289,9 @@ static void in6_rtqtimo(void *rock) { CURVNET_SET_QUIET((struct vnet *) rock); + INIT_VNET_NET(curvnet); INIT_VNET_INET6(curvnet); - struct radix_node_head *rnh = rock; + struct radix_node_head *rnh = V_rt_tables[0][AF_INET6]; struct rtqk_arg arg; struct timeval atv; static time_t last_adjusted_timeout = 0; @@ -376,8 +377,9 @@ static void in6_mtutimo(void *rock) { CURVNET_SET_QUIET((struct vnet *) rock); + INIT_VNET_NET(curvnet); INIT_VNET_INET6(curvnet); - struct radix_node_head *rnh = rock; + struct radix_node_head *rnh = V_rt_tables[0][AF_INET6]; struct mtuex_arg arg; struct timeval atv; @@ -403,7 +405,7 @@ void in6_rtqdrain(void) { INIT_VNET_NET(curvnet); - struct radix_node_head *rnh = V_rt_tables[AF_INET6]; + struct radix_node_head *rnh = V_rt_tables[0][AF_INET6]; struct rtqk_arg arg; arg.found = arg.killed = 0; @@ -427,6 +429,9 @@ in6_rtqdrain(void) int in6_inithead(void **head, int off) { +#ifdef INVARIANTS + INIT_VNET_NET(curvnet); +#endif INIT_VNET_INET6(curvnet); struct radix_node_head *rnh; @@ -442,11 +447,12 @@ in6_inithead(void **head, int off) V_rtq_timeout6 = RTQ_TIMEOUT; rnh = *head; + KASSERT(rnh == V_rt_tables[0][AF_INET6], ("rnh?")); rnh->rnh_addaddr = in6_addroute; rnh->rnh_matchaddr = in6_matroute; callout_init(&V_rtq_timer6, CALLOUT_MPSAFE); - in6_rtqtimo(rnh); /* kick off timeout first time */ callout_init(&V_rtq_mtutimer, CALLOUT_MPSAFE); - in6_mtutimo(rnh); /* kick off timeout first time */ + in6_rtqtimo(curvnet); /* kick off timeout first time */ + in6_mtutimo(curvnet); /* kick off timeout first time */ return 1; } diff --git a/sys/netinet6/ip6_mroute.c b/sys/netinet6/ip6_mroute.c index a88a9a1..5a76ef3 100644 --- a/sys/netinet6/ip6_mroute.c +++ b/sys/netinet6/ip6_mroute.c @@ -219,7 +219,7 @@ static struct mtx mif6_mtx; #ifdef MRT6DEBUG #ifdef VIMAGE_GLOBALS -static u_int mrt6debug = 0; /* debug level */ +static u_int mrt6debug; /* debug level */ #endif #define DEBUG_MFC 0x02 #define DEBUG_FORWARD 0x04 @@ -546,7 +546,11 @@ ip6_mrouter_init(struct socket *so, int v, int cmd) { INIT_VNET_INET6(curvnet); + V_ip6_mrouter_ver = 0; + #ifdef MRT6DEBUG + V_mrt6debug = 0; + if (V_mrt6debug) log(LOG_DEBUG, "ip6_mrouter_init: so_type = %d, pr_protocol = %d\n", diff --git a/sys/netinet6/mld6.c b/sys/netinet6/mld6.c index 4359322..149d351 100644 --- a/sys/netinet6/mld6.c +++ b/sys/netinet6/mld6.c @@ -2908,7 +2908,6 @@ mld_dispatch_packet(struct mbuf *m) * indexes to guard against interface detach, they are * unique to each VIMAGE and must be retrieved. */ - CURVNET_SET(m->m_pkthdr.header); INIT_VNET_NET(curvnet); INIT_VNET_INET6(curvnet); ifindex = mld_restore_context(m); @@ -2987,10 +2986,7 @@ mld_dispatch_packet(struct mbuf *m) } } out: - /* - * We must restore the existing vnet pointer before continuing. - */ - CURVNET_RESTORE(); + return; } /* @@ -3142,7 +3138,9 @@ vnet_mld_iattach(const void *unused __unused) static int vnet_mld_idetach(const void *unused __unused) { +#ifdef INVARIANTS INIT_VNET_INET6(curvnet); +#endif CTR1(KTR_MLD, "%s: tearing down", __func__); diff --git a/sys/netinet6/nd6.c b/sys/netinet6/nd6.c index e387a7f..a74ee7d 100644 --- a/sys/netinet6/nd6.c +++ b/sys/netinet6/nd6.c @@ -489,6 +489,14 @@ nd6_llinfo_timer(void *arg) if ((ifp = ((ln->lle_tbl != NULL) ? ln->lle_tbl->llt_ifp : NULL)) == NULL) panic("ln ifp == NULL"); +/* + * XXX XXX XXX XXX XXX + * + * Why the ^%(@)*&%^) is this #define MIN() needed for CURVNET_SET()?!? + * And #define MIN() is in sys/param.h already, which is #included first + * here?!? + */ +#define MIN(a,b) (((a)<(b))?(a):(b)) CURVNET_SET(ifp->if_vnet); INIT_VNET_INET6(curvnet); @@ -592,7 +600,7 @@ done: void nd6_timer(void *arg) { - CURVNET_SET_QUIET((struct vnet *) arg); + CURVNET_SET((struct vnet *) arg); INIT_VNET_INET6(curvnet); int s; struct nd_defrouter *dr; diff --git a/sys/netinet6/nd6_nbr.c b/sys/netinet6/nd6_nbr.c index c83a245..65c0c09 100644 --- a/sys/netinet6/nd6_nbr.c +++ b/sys/netinet6/nd6_nbr.c @@ -86,7 +86,7 @@ struct dadq; static struct dadq *nd6_dad_find(struct ifaddr *); static void nd6_dad_starttimer(struct dadq *, int); static void nd6_dad_stoptimer(struct dadq *); -static void nd6_dad_timer(struct ifaddr *); +static void nd6_dad_timer(struct dadq *); static void nd6_dad_ns_output(struct dadq *, struct ifaddr *); static void nd6_dad_ns_input(struct ifaddr *); static void nd6_dad_na_input(struct ifaddr *); @@ -1105,7 +1105,6 @@ nd6_ifptomac(struct ifnet *ifp) } } -TAILQ_HEAD(dadq_head, dadq); struct dadq { TAILQ_ENTRY(dadq) dad_list; struct ifaddr *dad_ifa; @@ -1115,10 +1114,11 @@ struct dadq { int dad_ns_icount; int dad_na_icount; struct callout dad_timer_ch; + struct vnet *dad_vnet; }; #ifdef VIMAGE_GLOBALS -static struct dadq_head dadq; +static TAILQ_HEAD(, dadq) dadq; int dad_init; #endif @@ -1140,7 +1140,7 @@ nd6_dad_starttimer(struct dadq *dp, int ticks) { callout_reset(&dp->dad_timer_ch, ticks, - (void (*)(void *))nd6_dad_timer, (void *)dp->dad_ifa); + (void (*)(void *))nd6_dad_timer, (void *)dp); } static void @@ -1208,6 +1208,9 @@ nd6_dad_start(struct ifaddr *ifa, int delay) } bzero(dp, sizeof(*dp)); callout_init(&dp->dad_timer_ch, 0); +#ifdef VIMAGE + dp->dad_vnet = curvnet; +#endif TAILQ_INSERT_TAIL(&V_dadq, (struct dadq *)dp, dad_list); nd6log((LOG_DEBUG, "%s: starting DAD for %s\n", if_name(ifa->ifa_ifp), @@ -1259,13 +1262,13 @@ nd6_dad_stop(struct ifaddr *ifa) } static void -nd6_dad_timer(struct ifaddr *ifa) +nd6_dad_timer(struct dadq *dp) { CURVNET_SET(dp->dad_vnet); INIT_VNET_INET6(curvnet); int s; + struct ifaddr *ifa = dp->dad_ifa; struct in6_ifaddr *ia = (struct in6_ifaddr *)ifa; - struct dadq *dp; char ip6buf[INET6_ADDRSTRLEN]; s = splnet(); /* XXX */ @@ -1275,11 +1278,6 @@ nd6_dad_timer(struct ifaddr *ifa) log(LOG_ERR, "nd6_dad_timer: called with null parameter\n"); goto done; } - dp = nd6_dad_find(ifa); - if (dp == NULL) { - log(LOG_ERR, "nd6_dad_timer: DAD structure not found\n"); - goto done; - } if (ia->ia6_flags & IN6_IFF_DUPLICATED) { log(LOG_ERR, "nd6_dad_timer: called with duplicated address " "%s(%s)\n", |