diff options
author | Marko Zec <zec@FreeBSD.org> | 2009-05-05 10:56:12 +0000 |
---|---|---|
committer | Marko Zec <zec@FreeBSD.org> | 2009-05-05 10:56:12 +0000 |
commit | 21ca7b57bd9be4aa0b7f4e8d2fb62075319086b6 (patch) | |
tree | 79a0bccccf2c92504cdf23ad15f7c1813bb3f926 /sys/netinet6/in6_rmx.c | |
parent | 49939083a0543593d9c2729c7d5a835cfb0ac2dd (diff) | |
download | src-21ca7b57bd9be4aa0b7f4e8d2fb62075319086b6.tar.gz src-21ca7b57bd9be4aa0b7f4e8d2fb62075319086b6.zip |
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)
Notes
Notes:
svn path=/head/; revision=191816
Diffstat (limited to 'sys/netinet6/in6_rmx.c')
-rw-r--r-- | sys/netinet6/in6_rmx.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/sys/netinet6/in6_rmx.c b/sys/netinet6/in6_rmx.c index 3cc446878c57..70909b1fb0d2 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; } |