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)
This commit is contained in:
parent
49939083a0
commit
21ca7b57bd
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=191816
@ -1952,8 +1952,8 @@ kern/kern_time.c standard
|
||||
kern/kern_timeout.c standard
|
||||
kern/kern_umtx.c standard
|
||||
kern/kern_uuid.c standard
|
||||
kern/kern_xxx.c standard
|
||||
kern/kern_vimage.c standard
|
||||
kern/kern_xxx.c standard
|
||||
kern/link_elf.c standard
|
||||
kern/linker_if.m standard
|
||||
kern/md4c.c optional netsmb
|
||||
|
@ -1217,7 +1217,7 @@ install_offload_ops(struct socket *so)
|
||||
* receive window.
|
||||
*/
|
||||
static __inline int
|
||||
select_rcv_wscale(int space)
|
||||
select_rcv_wscale(int space, struct vnet *vnet)
|
||||
{
|
||||
INIT_VNET_INET(so->so_vnet);
|
||||
int wscale = 0;
|
||||
@ -1326,7 +1326,7 @@ static inline unsigned int
|
||||
calc_opt0h(struct socket *so, int mtu_idx)
|
||||
{
|
||||
struct tcpcb *tp = so_sototcpcb(so);
|
||||
int wscale = select_rcv_wscale(tp->rcv_wnd);
|
||||
int wscale = select_rcv_wscale(tp->rcv_wnd, so->so_vnet);
|
||||
|
||||
return V_NAGLE((tp->t_flags & TF_NODELAY) == 0) |
|
||||
V_KEEP_ALIVE((so_options_get(so) & SO_KEEPALIVE) != 0) | F_TCAM_BYPASS |
|
||||
|
@ -74,6 +74,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/conf.h>
|
||||
#include <sys/cpuset.h>
|
||||
#include <sys/vimage.h>
|
||||
|
||||
#include <machine/cpu.h>
|
||||
|
||||
@ -452,6 +453,9 @@ proc0_init(void *dummy __unused)
|
||||
p->p_ucred->cr_uidinfo = uifind(0);
|
||||
p->p_ucred->cr_ruidinfo = uifind(0);
|
||||
p->p_ucred->cr_prison = NULL; /* Don't jail it. */
|
||||
#ifdef VIMAGE
|
||||
p->p_ucred->cr_vnet = LIST_FIRST(&vnet_head);
|
||||
#endif
|
||||
#ifdef AUDIT
|
||||
audit_cred_kproc0(p->p_ucred);
|
||||
#endif
|
||||
|
@ -68,6 +68,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/sdt.h>
|
||||
#include <sys/sx.h>
|
||||
#include <sys/signalvar.h>
|
||||
#include <sys/vimage.h>
|
||||
|
||||
#include <security/audit/audit.h>
|
||||
#include <security/mac/mac_framework.h>
|
||||
@ -523,6 +524,11 @@ fork1(td, flags, pages, procp)
|
||||
td2->td_sigmask = td->td_sigmask;
|
||||
td2->td_flags = TDF_INMEM;
|
||||
|
||||
#ifdef VIMAGE
|
||||
td2->td_vnet = NULL;
|
||||
td2->td_vnet_lpush = NULL;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Duplicate sub-structures as needed.
|
||||
* Increase reference counts on shared objects.
|
||||
|
@ -992,6 +992,12 @@ kern_kldload(struct thread *td, const char *file, int *fileid)
|
||||
if ((error = priv_check(td, PRIV_KLD_LOAD)) != 0)
|
||||
return (error);
|
||||
|
||||
/*
|
||||
* It's possible that kldloaded module will attach a new ifnet,
|
||||
* so vnet context must be set when this ocurs.
|
||||
*/
|
||||
CURVNET_SET(TD_TO_VNET(td));
|
||||
|
||||
/*
|
||||
* If file does not contain a qualified name or any dot in it
|
||||
* (kldname.ko, or kldname.ver.ko) treat it as an interface
|
||||
@ -1019,6 +1025,7 @@ kern_kldload(struct thread *td, const char *file, int *fileid)
|
||||
*fileid = lf->id;
|
||||
unlock:
|
||||
KLD_UNLOCK();
|
||||
CURVNET_RESTORE();
|
||||
return (error);
|
||||
}
|
||||
|
||||
@ -1056,6 +1063,7 @@ kern_kldunload(struct thread *td, int fileid, int flags)
|
||||
if ((error = priv_check(td, PRIV_KLD_UNLOAD)) != 0)
|
||||
return (error);
|
||||
|
||||
CURVNET_SET(TD_TO_VNET(td));
|
||||
KLD_LOCK();
|
||||
lf = linker_find_file_by_id(fileid);
|
||||
if (lf) {
|
||||
@ -1092,6 +1100,7 @@ kern_kldunload(struct thread *td, int fileid, int flags)
|
||||
PMC_CALL_HOOK(td, PMC_FN_KLD_UNLOAD, (void *) &pkm);
|
||||
#endif
|
||||
KLD_UNLOCK();
|
||||
CURVNET_RESTORE();
|
||||
return (error);
|
||||
}
|
||||
|
||||
|
@ -31,6 +31,8 @@
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include "opt_ddb.h"
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/kernel.h>
|
||||
@ -38,6 +40,9 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/systm.h>
|
||||
#include <sys/vimage.h>
|
||||
#ifdef DDB
|
||||
#include <ddb/ddb.h>
|
||||
#endif
|
||||
|
||||
#ifndef VIMAGE_GLOBALS
|
||||
|
||||
@ -51,8 +56,6 @@ static int vnet_mod_constructor(struct vnet_modlink *);
|
||||
static int vnet_mod_destructor(struct vnet_modlink *);
|
||||
|
||||
#ifdef VIMAGE
|
||||
/* curvnet should be thread-local - this is only a temporary step. */
|
||||
struct vnet *curvnet;
|
||||
struct vnet_list_head vnet_head;
|
||||
#endif
|
||||
|
||||
@ -183,7 +186,8 @@ vnet_mod_deregister_multi(const struct vnet_modinfo *vmi, void *iarg,
|
||||
free(vml, M_VIMAGE);
|
||||
}
|
||||
|
||||
static int vnet_mod_constructor(struct vnet_modlink *vml)
|
||||
static int
|
||||
vnet_mod_constructor(struct vnet_modlink *vml)
|
||||
{
|
||||
const struct vnet_modinfo *vmi = vml->vml_modinfo;
|
||||
|
||||
@ -303,7 +307,9 @@ vi_init(void *unused)
|
||||
if (vnet == NULL)
|
||||
panic("vi_alloc: malloc failed");
|
||||
LIST_INSERT_HEAD(&vnet_head, vnet, vnet_le);
|
||||
vnet->vnet_magic_n = VNET_MAGIC_N;
|
||||
|
||||
/* We MUST clear curvnet in vi_init_done before going SMP. */
|
||||
curvnet = LIST_FIRST(&vnet_head);
|
||||
#endif
|
||||
}
|
||||
@ -313,6 +319,10 @@ vi_init_done(void *unused)
|
||||
{
|
||||
struct vnet_modlink *vml_iter;
|
||||
|
||||
#ifdef VIMAGE
|
||||
curvnet = NULL;
|
||||
#endif
|
||||
|
||||
if (TAILQ_EMPTY(&vnet_modpending_head))
|
||||
return;
|
||||
|
||||
@ -327,5 +337,45 @@ vi_init_done(void *unused)
|
||||
|
||||
SYSINIT(vimage, SI_SUB_VIMAGE, SI_ORDER_FIRST, vi_init, NULL);
|
||||
SYSINIT(vimage_done, SI_SUB_VIMAGE_DONE, SI_ORDER_FIRST, vi_init_done, NULL);
|
||||
|
||||
#endif /* !VIMAGE_GLOBALS */
|
||||
|
||||
#ifdef VIMAGE
|
||||
#ifdef DDB
|
||||
static void
|
||||
db_vnet_ptr(void *arg)
|
||||
{
|
||||
|
||||
if (arg)
|
||||
db_printf(" %p", arg);
|
||||
else
|
||||
#if SIZE_MAX == UINT32_MAX /* 32-bit arch */
|
||||
db_printf(" 0");
|
||||
#else /* 64-bit arch, most probaly... */
|
||||
db_printf(" 0");
|
||||
#endif
|
||||
}
|
||||
|
||||
DB_SHOW_COMMAND(vnets, db_show_vnets)
|
||||
{
|
||||
VNET_ITERATOR_DECL(vnet_iter);
|
||||
|
||||
#if SIZE_MAX == UINT32_MAX /* 32-bit arch */
|
||||
db_printf(" vnet ifs socks");
|
||||
db_printf(" net inet inet6 ipsec netgraph\n");
|
||||
#else /* 64-bit arch, most probaly... */
|
||||
db_printf(" vnet ifs socks");
|
||||
db_printf(" net inet inet6 ipsec netgraph\n");
|
||||
#endif
|
||||
VNET_FOREACH(vnet_iter) {
|
||||
db_printf("%p %3d %5d",
|
||||
vnet_iter, vnet_iter->ifccnt, vnet_iter->sockcnt);
|
||||
db_vnet_ptr(vnet_iter->mod_data[VNET_MOD_NET]);
|
||||
db_vnet_ptr(vnet_iter->mod_data[VNET_MOD_INET]);
|
||||
db_vnet_ptr(vnet_iter->mod_data[VNET_MOD_INET6]);
|
||||
db_vnet_ptr(vnet_iter->mod_data[VNET_MOD_IPSEC]);
|
||||
db_vnet_ptr(vnet_iter->mod_data[VNET_MOD_NETGRAPH]);
|
||||
db_printf("\n");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif /* VIMAGE */
|
||||
|
@ -135,6 +135,10 @@ show_pcpu(struct pcpu *pc)
|
||||
db_printf("none\n");
|
||||
db_show_mdpcpu(pc);
|
||||
|
||||
#ifdef VIMAGE
|
||||
db_printf("curvnet = %p\n", pc->pc_curthread->td_vnet);
|
||||
#endif
|
||||
|
||||
#ifdef WITNESS
|
||||
db_printf("spin locks held:\n");
|
||||
witness_list_locks(&pc->pc_spinlocks);
|
||||
|
@ -50,6 +50,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/stat.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/ucred.h>
|
||||
#include <sys/vimage.h>
|
||||
|
||||
#include <net/if.h>
|
||||
#include <net/route.h>
|
||||
@ -74,16 +75,19 @@ soo_read(struct file *fp, struct uio *uio, struct ucred *active_cred,
|
||||
int flags, struct thread *td)
|
||||
{
|
||||
struct socket *so = fp->f_data;
|
||||
#ifdef MAC
|
||||
int error;
|
||||
|
||||
#ifdef MAC
|
||||
SOCK_LOCK(so);
|
||||
error = mac_socket_check_receive(active_cred, so);
|
||||
SOCK_UNLOCK(so);
|
||||
if (error)
|
||||
return (error);
|
||||
#endif
|
||||
return (soreceive(so, 0, uio, 0, 0, 0));
|
||||
CURVNET_SET(so->so_vnet);
|
||||
error = soreceive(so, 0, uio, 0, 0, 0);
|
||||
CURVNET_RESTORE();
|
||||
return (error);
|
||||
}
|
||||
|
||||
/* ARGSUSED */
|
||||
@ -125,6 +129,7 @@ soo_ioctl(struct file *fp, u_long cmd, void *data, struct ucred *active_cred,
|
||||
struct socket *so = fp->f_data;
|
||||
int error = 0;
|
||||
|
||||
CURVNET_SET(so->so_vnet);
|
||||
switch (cmd) {
|
||||
case FIONBIO:
|
||||
SOCK_LOCK(so);
|
||||
@ -205,6 +210,7 @@ soo_ioctl(struct file *fp, u_long cmd, void *data, struct ucred *active_cred,
|
||||
(so, cmd, data, 0, td));
|
||||
break;
|
||||
}
|
||||
CURVNET_RESTORE();
|
||||
return (error);
|
||||
}
|
||||
|
||||
|
@ -264,7 +264,7 @@ SYSINIT(param, SI_SUB_TUNABLES, SI_ORDER_ANY, init_maxsockets, NULL);
|
||||
* soalloc() returns a socket with a ref count of 0.
|
||||
*/
|
||||
static struct socket *
|
||||
soalloc(void)
|
||||
soalloc(struct vnet *vnet)
|
||||
{
|
||||
struct socket *so;
|
||||
|
||||
@ -286,7 +286,8 @@ soalloc(void)
|
||||
so->so_gencnt = ++so_gencnt;
|
||||
++numopensockets;
|
||||
#ifdef VIMAGE
|
||||
so->so_vnet = curvnet;
|
||||
++vnet->sockcnt; /* locked with so_global_mtx */
|
||||
so->so_vnet = vnet;
|
||||
#endif
|
||||
mtx_unlock(&so_global_mtx);
|
||||
return (so);
|
||||
@ -307,6 +308,9 @@ sodealloc(struct socket *so)
|
||||
mtx_lock(&so_global_mtx);
|
||||
so->so_gencnt = ++so_gencnt;
|
||||
--numopensockets; /* Could be below, but faster here. */
|
||||
#ifdef VIMAGE
|
||||
--so->so_vnet->sockcnt;
|
||||
#endif
|
||||
mtx_unlock(&so_global_mtx);
|
||||
if (so->so_rcv.sb_hiwat)
|
||||
(void)chgsbsize(so->so_cred->cr_uidinfo,
|
||||
@ -356,7 +360,7 @@ socreate(int dom, struct socket **aso, int type, int proto,
|
||||
|
||||
if (prp->pr_type != type)
|
||||
return (EPROTOTYPE);
|
||||
so = soalloc();
|
||||
so = soalloc(TD_TO_VNET(td));
|
||||
if (so == NULL)
|
||||
return (ENOBUFS);
|
||||
|
||||
@ -382,7 +386,9 @@ socreate(int dom, struct socket **aso, int type, int proto,
|
||||
* Auto-sizing of socket buffers is managed by the protocols and
|
||||
* the appropriate flags must be set in the pru_attach function.
|
||||
*/
|
||||
CURVNET_SET(so->so_vnet);
|
||||
error = (*prp->pr_usrreqs->pru_attach)(so, proto, td);
|
||||
CURVNET_RESTORE();
|
||||
if (error) {
|
||||
KASSERT(so->so_count == 1, ("socreate: so_count %d",
|
||||
so->so_count));
|
||||
@ -424,7 +430,8 @@ sonewconn(struct socket *head, int connstatus)
|
||||
if (over)
|
||||
#endif
|
||||
return (NULL);
|
||||
so = soalloc();
|
||||
VNET_ASSERT(head->so_vnet);
|
||||
so = soalloc(head->so_vnet);
|
||||
if (so == NULL)
|
||||
return (NULL);
|
||||
if ((head->so_options & SO_ACCEPTFILTER) != 0)
|
||||
@ -496,8 +503,12 @@ sonewconn(struct socket *head, int connstatus)
|
||||
int
|
||||
sobind(struct socket *so, struct sockaddr *nam, struct thread *td)
|
||||
{
|
||||
int error;
|
||||
|
||||
return ((*so->so_proto->pr_usrreqs->pru_bind)(so, nam, td));
|
||||
CURVNET_SET(so->so_vnet);
|
||||
error = (*so->so_proto->pr_usrreqs->pru_bind)(so, nam, td);
|
||||
CURVNET_RESTORE();
|
||||
return error;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -645,6 +656,7 @@ soclose(struct socket *so)
|
||||
|
||||
KASSERT(!(so->so_state & SS_NOFDREF), ("soclose: SS_NOFDREF on enter"));
|
||||
|
||||
CURVNET_SET(so->so_vnet);
|
||||
funsetown(&so->so_sigio);
|
||||
if (so->so_state & SS_ISCONNECTED) {
|
||||
if ((so->so_state & SS_ISDISCONNECTING) == 0) {
|
||||
@ -696,6 +708,7 @@ soclose(struct socket *so)
|
||||
KASSERT((so->so_state & SS_NOFDREF) == 0, ("soclose: NOFDREF"));
|
||||
so->so_state |= SS_NOFDREF;
|
||||
sorele(so);
|
||||
CURVNET_RESTORE();
|
||||
return (error);
|
||||
}
|
||||
|
||||
@ -771,7 +784,9 @@ soconnect(struct socket *so, struct sockaddr *nam, struct thread *td)
|
||||
* biting us.
|
||||
*/
|
||||
so->so_error = 0;
|
||||
CURVNET_SET(so->so_vnet);
|
||||
error = (*so->so_proto->pr_usrreqs->pru_connect)(so, nam, td);
|
||||
CURVNET_RESTORE();
|
||||
}
|
||||
|
||||
return (error);
|
||||
@ -1287,9 +1302,13 @@ int
|
||||
sosend(struct socket *so, struct sockaddr *addr, struct uio *uio,
|
||||
struct mbuf *top, struct mbuf *control, int flags, struct thread *td)
|
||||
{
|
||||
int error;
|
||||
|
||||
return (so->so_proto->pr_usrreqs->pru_sosend(so, addr, uio, top,
|
||||
control, flags, td));
|
||||
CURVNET_SET(so->so_vnet);
|
||||
error = so->so_proto->pr_usrreqs->pru_sosend(so, addr, uio, top,
|
||||
control, flags, td);
|
||||
CURVNET_RESTORE();
|
||||
return (error);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -2037,6 +2056,7 @@ int
|
||||
soshutdown(struct socket *so, int how)
|
||||
{
|
||||
struct protosw *pr = so->so_proto;
|
||||
int error;
|
||||
|
||||
if (!(how == SHUT_RD || how == SHUT_WR || how == SHUT_RDWR))
|
||||
return (EINVAL);
|
||||
@ -2045,8 +2065,12 @@ soshutdown(struct socket *so, int how)
|
||||
}
|
||||
if (how != SHUT_WR)
|
||||
sorflush(so);
|
||||
if (how != SHUT_RD)
|
||||
return ((*pr->pr_usrreqs->pru_shutdown)(so));
|
||||
if (how != SHUT_RD) {
|
||||
CURVNET_SET(so->so_vnet);
|
||||
error = (*pr->pr_usrreqs->pru_shutdown)(so);
|
||||
CURVNET_RESTORE();
|
||||
return (error);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
@ -2070,6 +2094,7 @@ sorflush(struct socket *so)
|
||||
* socket buffer. Don't let our acquire be interrupted by a signal
|
||||
* despite any existing socket disposition on interruptable waiting.
|
||||
*/
|
||||
CURVNET_SET(so->so_vnet);
|
||||
socantrcvmore(so);
|
||||
(void) sblock(sb, SBL_WAIT | SBL_NOINTR);
|
||||
|
||||
@ -2093,6 +2118,7 @@ sorflush(struct socket *so)
|
||||
if (pr->pr_flags & PR_RIGHTS && pr->pr_domain->dom_dispose != NULL)
|
||||
(*pr->pr_domain->dom_dispose)(asb.sb_mb);
|
||||
sbrelease_internal(&asb, so);
|
||||
CURVNET_RESTORE();
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -64,6 +64,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/vnode.h>
|
||||
#include <sys/vimage.h>
|
||||
#ifdef KTRACE
|
||||
#include <sys/ktrace.h>
|
||||
#endif
|
||||
@ -264,7 +265,9 @@ listen(td, uap)
|
||||
if (error)
|
||||
goto done;
|
||||
#endif
|
||||
CURVNET_SET(so->so_vnet);
|
||||
error = solisten(so, uap->backlog, td);
|
||||
CURVNET_RESTORE();
|
||||
#ifdef MAC
|
||||
done:
|
||||
#endif
|
||||
@ -429,7 +432,9 @@ kern_accept(struct thread *td, int s, struct sockaddr **name,
|
||||
tmp = fflag & FASYNC;
|
||||
(void) fo_ioctl(nfp, FIOASYNC, &tmp, td->td_ucred, td);
|
||||
sa = 0;
|
||||
CURVNET_SET(so->so_vnet);
|
||||
error = soaccept(so, &sa);
|
||||
CURVNET_RESTORE();
|
||||
if (error) {
|
||||
/*
|
||||
* return a namelen of zero for older code which might
|
||||
@ -976,9 +981,11 @@ kern_recvit(td, s, mp, fromseg, controlp)
|
||||
ktruio = cloneuio(&auio);
|
||||
#endif
|
||||
len = auio.uio_resid;
|
||||
CURVNET_SET(so->so_vnet);
|
||||
error = soreceive(so, &fromsa, &auio, (struct mbuf **)0,
|
||||
(mp->msg_control || controlp) ? &control : (struct mbuf **)0,
|
||||
&mp->msg_flags);
|
||||
CURVNET_RESTORE();
|
||||
if (error) {
|
||||
if (auio.uio_resid != (int)len && (error == ERESTART ||
|
||||
error == EINTR || error == EWOULDBLOCK))
|
||||
@ -1322,7 +1329,9 @@ kern_setsockopt(td, s, level, name, val, valseg, valsize)
|
||||
error = getsock(td->td_proc->p_fd, s, &fp, NULL);
|
||||
if (error == 0) {
|
||||
so = fp->f_data;
|
||||
CURVNET_SET(so->so_vnet);
|
||||
error = sosetopt(so, &sopt);
|
||||
CURVNET_RESTORE();
|
||||
fdrop(fp, td);
|
||||
}
|
||||
return(error);
|
||||
@ -1400,7 +1409,9 @@ kern_getsockopt(td, s, level, name, val, valseg, valsize)
|
||||
error = getsock(td->td_proc->p_fd, s, &fp, NULL);
|
||||
if (error == 0) {
|
||||
so = fp->f_data;
|
||||
CURVNET_SET(so->so_vnet);
|
||||
error = sogetopt(so, &sopt);
|
||||
CURVNET_RESTORE();
|
||||
*valsize = sopt.sopt_valsize;
|
||||
fdrop(fp, td);
|
||||
}
|
||||
@ -1463,7 +1474,9 @@ kern_getsockname(struct thread *td, int fd, struct sockaddr **sa,
|
||||
return (error);
|
||||
so = fp->f_data;
|
||||
*sa = NULL;
|
||||
CURVNET_SET(so->so_vnet);
|
||||
error = (*so->so_proto->pr_usrreqs->pru_sockaddr)(so, sa);
|
||||
CURVNET_RESTORE();
|
||||
if (error)
|
||||
goto bad;
|
||||
if (*sa == NULL)
|
||||
@ -1564,7 +1577,9 @@ kern_getpeername(struct thread *td, int fd, struct sockaddr **sa,
|
||||
goto done;
|
||||
}
|
||||
*sa = NULL;
|
||||
CURVNET_SET(so->so_vnet);
|
||||
error = (*so->so_proto->pr_usrreqs->pru_peeraddr)(so, sa);
|
||||
CURVNET_RESTORE();
|
||||
if (error)
|
||||
goto bad;
|
||||
if (*sa == NULL)
|
||||
@ -2176,9 +2191,11 @@ kern_sendfile(struct thread *td, struct sendfile_args *uap,
|
||||
goto done;
|
||||
}
|
||||
SOCKBUF_UNLOCK(&so->so_snd);
|
||||
CURVNET_SET(so->so_vnet);
|
||||
/* Avoid error aliasing. */
|
||||
err = (*so->so_proto->pr_usrreqs->pru_send)
|
||||
(so, 0, m, NULL, NULL, td);
|
||||
CURVNET_RESTORE();
|
||||
if (err == 0) {
|
||||
/*
|
||||
* We need two counters to get the
|
||||
|
@ -90,6 +90,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/un.h>
|
||||
#include <sys/unpcb.h>
|
||||
#include <sys/vnode.h>
|
||||
#include <sys/vimage.h>
|
||||
|
||||
#ifdef DDB
|
||||
#include <ddb/ddb.h>
|
||||
@ -1647,6 +1648,10 @@ static void
|
||||
unp_init(void)
|
||||
{
|
||||
|
||||
#ifdef VIMAGE
|
||||
if (!IS_DEFAULT_VNET(curvnet))
|
||||
return;
|
||||
#endif
|
||||
unp_zone = uma_zcreate("unpcb", sizeof(struct unpcb), NULL, NULL,
|
||||
NULL, NULL, UMA_ALIGN_PTR, 0);
|
||||
if (unp_zone == NULL)
|
||||
|
@ -873,11 +873,10 @@ bpfwrite(struct cdev *dev, struct uio *uio, int ioflag)
|
||||
m->m_len -= hlen;
|
||||
m->m_data += hlen; /* XXX */
|
||||
|
||||
CURVNET_SET(ifp->if_vnet);
|
||||
#ifdef MAC
|
||||
BPFD_LOCK(d);
|
||||
CURVNET_SET(ifp->if_vnet);
|
||||
mac_bpfdesc_create_mbuf(d, m);
|
||||
CURVNET_RESTORE();
|
||||
if (mc != NULL)
|
||||
mac_bpfdesc_create_mbuf(d, mc);
|
||||
BPFD_UNLOCK(d);
|
||||
@ -893,6 +892,7 @@ bpfwrite(struct cdev *dev, struct uio *uio, int ioflag)
|
||||
else
|
||||
m_freem(mc);
|
||||
}
|
||||
CURVNET_RESTORE();
|
||||
|
||||
return (error);
|
||||
}
|
||||
|
42
sys/net/if.c
42
sys/net/if.c
@ -53,6 +53,7 @@
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/refcount.h>
|
||||
#include <sys/module.h>
|
||||
#include <sys/rwlock.h>
|
||||
#include <sys/sockio.h>
|
||||
#include <sys/syslog.h>
|
||||
@ -126,7 +127,6 @@ static void if_attachdomain(void *);
|
||||
static void if_attachdomain1(struct ifnet *);
|
||||
static int ifconf(u_long, caddr_t);
|
||||
static void if_freemulti(struct ifmultiaddr *);
|
||||
static void if_grow(void);
|
||||
static void if_init(void *);
|
||||
static void if_check(void *);
|
||||
static void if_route(struct ifnet *, int flag, int fam);
|
||||
@ -202,7 +202,7 @@ MALLOC_DEFINE(M_IFNET, "ifnet", "interface internals");
|
||||
MALLOC_DEFINE(M_IFADDR, "ifaddr", "interface address");
|
||||
MALLOC_DEFINE(M_IFMADDR, "ether_multi", "link-level multicast address");
|
||||
|
||||
static struct ifnet *
|
||||
struct ifnet *
|
||||
ifnet_byindex_locked(u_short idx)
|
||||
{
|
||||
INIT_VNET_NET(curvnet);
|
||||
@ -239,7 +239,7 @@ ifnet_byindex_ref(u_short idx)
|
||||
return (ifp);
|
||||
}
|
||||
|
||||
static void
|
||||
void
|
||||
ifnet_setbyindex(u_short idx, struct ifnet *ifp)
|
||||
{
|
||||
INIT_VNET_NET(curvnet);
|
||||
@ -445,7 +445,7 @@ vnet_net_iattach(const void *unused __unused)
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void
|
||||
void
|
||||
if_grow(void)
|
||||
{
|
||||
INIT_VNET_NET(curvnet);
|
||||
@ -696,11 +696,13 @@ if_attach(struct ifnet *ifp)
|
||||
mac_ifnet_create(ifp);
|
||||
#endif
|
||||
|
||||
ifdev_setbyindex(ifp->if_index, make_dev(&net_cdevsw,
|
||||
ifp->if_index, UID_ROOT, GID_WHEEL, 0600, "%s/%s",
|
||||
net_cdevsw.d_name, ifp->if_xname));
|
||||
make_dev_alias(ifdev_byindex(ifp->if_index), "%s%d",
|
||||
net_cdevsw.d_name, ifp->if_index);
|
||||
if (IS_DEFAULT_VNET(curvnet)) {
|
||||
ifdev_setbyindex(ifp->if_index, make_dev(&net_cdevsw,
|
||||
ifp->if_index, UID_ROOT, GID_WHEEL, 0600, "%s/%s",
|
||||
net_cdevsw.d_name, ifp->if_xname));
|
||||
make_dev_alias(ifdev_byindex(ifp->if_index), "%s%d",
|
||||
net_cdevsw.d_name, ifp->if_index);
|
||||
}
|
||||
|
||||
ifq_attach(&ifp->if_snd, ifp);
|
||||
|
||||
@ -742,13 +744,17 @@ if_attach(struct ifnet *ifp)
|
||||
|
||||
IFNET_WLOCK();
|
||||
TAILQ_INSERT_TAIL(&V_ifnet, ifp, if_link);
|
||||
#ifdef VIMAGE
|
||||
curvnet->ifccnt++;
|
||||
#endif
|
||||
IFNET_WUNLOCK();
|
||||
|
||||
if (domain_init_status >= 2)
|
||||
if_attachdomain1(ifp);
|
||||
|
||||
EVENTHANDLER_INVOKE(ifnet_arrival_event, ifp);
|
||||
devctl_notify("IFNET", ifp->if_xname, "ATTACH", NULL);
|
||||
if (IS_DEFAULT_VNET(curvnet))
|
||||
devctl_notify("IFNET", ifp->if_xname, "ATTACH", NULL);
|
||||
|
||||
/* Announce the interface. */
|
||||
rt_ifannouncemsg(ifp, IFAN_ARRIVAL);
|
||||
@ -895,6 +901,10 @@ if_detach(struct ifnet *ifp)
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
#ifdef VIMAGE
|
||||
if (found)
|
||||
curvnet->ifccnt--;
|
||||
#endif
|
||||
IFNET_WUNLOCK();
|
||||
if (!found)
|
||||
return;
|
||||
@ -943,7 +953,8 @@ if_detach(struct ifnet *ifp)
|
||||
* Clean up all addresses.
|
||||
*/
|
||||
ifp->if_addr = NULL;
|
||||
destroy_dev(ifdev_byindex(ifp->if_index));
|
||||
if (IS_DEFAULT_VNET(curvnet))
|
||||
destroy_dev(ifdev_byindex(ifp->if_index));
|
||||
ifdev_setbyindex(ifp->if_index, NULL);
|
||||
|
||||
/* We can now free link ifaddr. */
|
||||
@ -972,7 +983,8 @@ if_detach(struct ifnet *ifp)
|
||||
/* Announce that the interface is gone. */
|
||||
rt_ifannouncemsg(ifp, IFAN_DEPARTURE);
|
||||
EVENTHANDLER_INVOKE(ifnet_departure_event, ifp);
|
||||
devctl_notify("IFNET", ifp->if_xname, "DETACH", NULL);
|
||||
if (IS_DEFAULT_VNET(curvnet))
|
||||
devctl_notify("IFNET", ifp->if_xname, "DETACH", NULL);
|
||||
if_delgroups(ifp);
|
||||
|
||||
IF_AFDATA_LOCK(ifp);
|
||||
@ -1701,8 +1713,10 @@ do_link_state_change(void *arg, int pending)
|
||||
(*lagg_linkstate_p)(ifp, link_state);
|
||||
}
|
||||
|
||||
devctl_notify("IFNET", ifp->if_xname,
|
||||
(link_state == LINK_STATE_UP) ? "LINK_UP" : "LINK_DOWN", NULL);
|
||||
if (IS_DEFAULT_VNET(curvnet))
|
||||
devctl_notify("IFNET", ifp->if_xname,
|
||||
(link_state == LINK_STATE_UP) ? "LINK_UP" : "LINK_DOWN",
|
||||
NULL);
|
||||
if (pending > 1)
|
||||
if_printf(ifp, "%d link states coalesced\n", pending);
|
||||
if (log_link_state_change)
|
||||
|
@ -39,6 +39,7 @@
|
||||
#include <sys/systm.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/vimage.h>
|
||||
|
||||
#include <net/if.h>
|
||||
#include <net/if_clone.h>
|
||||
@ -49,6 +50,7 @@
|
||||
#include <net/if_var.h>
|
||||
#include <net/radix.h>
|
||||
#include <net/route.h>
|
||||
#include <net/vnet.h>
|
||||
|
||||
static void if_clone_free(struct if_clone *ifc);
|
||||
static int if_clone_createif(struct if_clone *ifc, char *name, size_t len,
|
||||
@ -203,15 +205,14 @@ if_clone_destroyif(struct if_clone *ifc, struct ifnet *ifp)
|
||||
{
|
||||
int err;
|
||||
|
||||
if (ifc->ifc_destroy == NULL) {
|
||||
err = EOPNOTSUPP;
|
||||
goto done;
|
||||
}
|
||||
if (ifc->ifc_destroy == NULL)
|
||||
return(EOPNOTSUPP);
|
||||
|
||||
IF_CLONE_LOCK(ifc);
|
||||
IFC_IFLIST_REMOVE(ifc, ifp);
|
||||
IF_CLONE_UNLOCK(ifc);
|
||||
|
||||
CURVNET_SET_QUIET(ifp->if_vnet);
|
||||
if_delgroup(ifp, ifc->ifc_name);
|
||||
|
||||
err = (*ifc->ifc_destroy)(ifc, ifp);
|
||||
@ -223,8 +224,7 @@ if_clone_destroyif(struct if_clone *ifc, struct ifnet *ifp)
|
||||
IFC_IFLIST_INSERT(ifc, ifp);
|
||||
IF_CLONE_UNLOCK(ifc);
|
||||
}
|
||||
|
||||
done:
|
||||
CURVNET_RESTORE();
|
||||
return (err);
|
||||
}
|
||||
|
||||
|
@ -602,6 +602,8 @@ ether_input(struct ifnet *ifp, struct mbuf *m)
|
||||
}
|
||||
#endif
|
||||
|
||||
CURVNET_SET_QUIET(ifp->if_vnet);
|
||||
|
||||
if (ETHER_IS_MULTICAST(eh->ether_dhost)) {
|
||||
if (ETHER_IS_BROADCAST(eh->ether_dhost))
|
||||
m->m_flags |= M_BCAST;
|
||||
@ -638,6 +640,7 @@ ether_input(struct ifnet *ifp, struct mbuf *m)
|
||||
/* Allow monitor mode to claim this frame, after stats are updated. */
|
||||
if (ifp->if_flags & IFF_MONITOR) {
|
||||
m_freem(m);
|
||||
CURVNET_RESTORE();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -686,8 +689,10 @@ ether_input(struct ifnet *ifp, struct mbuf *m)
|
||||
("%s: ng_ether_input_p is NULL", __func__));
|
||||
m->m_flags &= ~M_PROMISC;
|
||||
(*ng_ether_input_p)(ifp, &m);
|
||||
if (m == NULL)
|
||||
if (m == NULL) {
|
||||
CURVNET_RESTORE();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@ -698,8 +703,10 @@ ether_input(struct ifnet *ifp, struct mbuf *m)
|
||||
if (ifp->if_bridge != NULL) {
|
||||
m->m_flags &= ~M_PROMISC;
|
||||
BRIDGE_INPUT(ifp, m);
|
||||
if (m == NULL)
|
||||
if (m == NULL) {
|
||||
CURVNET_RESTORE();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEV_CARP
|
||||
@ -735,6 +742,7 @@ ether_input(struct ifnet *ifp, struct mbuf *m)
|
||||
random_harvest(m, 16, 3, 0, RANDOM_NET);
|
||||
|
||||
ether_demux(ifp, m);
|
||||
CURVNET_RESTORE();
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -731,7 +731,9 @@ struct ifindex_entry {
|
||||
* to call ifnet_byindex() instead if ifnet_byindex_ref().
|
||||
*/
|
||||
struct ifnet *ifnet_byindex(u_short idx);
|
||||
struct ifnet *ifnet_byindex_locked(u_short idx);
|
||||
struct ifnet *ifnet_byindex_ref(u_short idx);
|
||||
void ifnet_setbyindex(u_short idx, struct ifnet *ifp);
|
||||
|
||||
/*
|
||||
* Given the index, ifaddr_byindex() returns the one and only
|
||||
@ -755,6 +757,7 @@ int if_allmulti(struct ifnet *, int);
|
||||
struct ifnet* if_alloc(u_char);
|
||||
void if_attach(struct ifnet *);
|
||||
void if_dead(struct ifnet *);
|
||||
void if_grow(void);
|
||||
int if_delmulti(struct ifnet *, struct sockaddr *);
|
||||
void if_delmulti_ifma(struct ifmultiaddr *);
|
||||
void if_detach(struct ifnet *);
|
||||
|
@ -43,6 +43,7 @@
|
||||
#include <sys/resourcevar.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/unistd.h>
|
||||
#include <sys/vimage.h>
|
||||
#include <machine/atomic.h>
|
||||
#include <machine/cpu.h>
|
||||
#include <machine/stdarg.h>
|
||||
@ -142,7 +143,10 @@ netisr_processqueue(struct netisr *ni)
|
||||
IF_DEQUEUE(ni->ni_queue, m);
|
||||
if (m == NULL)
|
||||
break;
|
||||
VNET_ASSERT(m->m_pkthdr.rcvif != NULL);
|
||||
CURVNET_SET(m->m_pkthdr.rcvif->if_vnet);
|
||||
ni->ni_handler(m);
|
||||
CURVNET_RESTORE();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1206,6 +1206,7 @@ rt_ifannouncemsg(struct ifnet *ifp, int what)
|
||||
static void
|
||||
rt_dispatch(struct mbuf *m, const struct sockaddr *sa)
|
||||
{
|
||||
INIT_VNET_NET(curvnet);
|
||||
struct m_tag *tag;
|
||||
|
||||
/*
|
||||
@ -1223,6 +1224,14 @@ rt_dispatch(struct mbuf *m, const struct sockaddr *sa)
|
||||
*(unsigned short *)(tag + 1) = sa->sa_family;
|
||||
m_tag_prepend(m, tag);
|
||||
}
|
||||
#ifdef VIMAGE
|
||||
if (V_loif)
|
||||
m->m_pkthdr.rcvif = V_loif;
|
||||
else {
|
||||
m_freem(m);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
netisr_queue(NETISR_ROUTE, m); /* mbuf is free'd on failure. */
|
||||
}
|
||||
|
||||
|
@ -41,6 +41,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <sys/vimage.h>
|
||||
|
||||
#include <net/if.h>
|
||||
#include <net/if_dl.h>
|
||||
@ -498,9 +499,11 @@ notify_macaddr(struct ifnet *ifp, int op, const uint8_t mac[IEEE80211_ADDR_LEN])
|
||||
{
|
||||
struct ieee80211_join_event iev;
|
||||
|
||||
CURVNET_SET(ifp->if_vnet);
|
||||
memset(&iev, 0, sizeof(iev));
|
||||
IEEE80211_ADDR_COPY(iev.iev_addr, mac);
|
||||
rt_ieee80211msg(ifp, op, &iev, sizeof(iev));
|
||||
CURVNET_RESTORE();
|
||||
}
|
||||
|
||||
void
|
||||
@ -509,6 +512,7 @@ ieee80211_notify_node_join(struct ieee80211_node *ni, int newassoc)
|
||||
struct ieee80211vap *vap = ni->ni_vap;
|
||||
struct ifnet *ifp = vap->iv_ifp;
|
||||
|
||||
CURVNET_SET_QUIET(ifp->if_vnet);
|
||||
IEEE80211_NOTE(vap, IEEE80211_MSG_NODE, ni, "%snode join",
|
||||
(ni == vap->iv_bss) ? "bss " : "");
|
||||
|
||||
@ -520,6 +524,7 @@ ieee80211_notify_node_join(struct ieee80211_node *ni, int newassoc)
|
||||
notify_macaddr(ifp, newassoc ?
|
||||
RTM_IEEE80211_JOIN : RTM_IEEE80211_REJOIN, ni->ni_macaddr);
|
||||
}
|
||||
CURVNET_RESTORE();
|
||||
}
|
||||
|
||||
void
|
||||
@ -528,6 +533,7 @@ ieee80211_notify_node_leave(struct ieee80211_node *ni)
|
||||
struct ieee80211vap *vap = ni->ni_vap;
|
||||
struct ifnet *ifp = vap->iv_ifp;
|
||||
|
||||
CURVNET_SET_QUIET(ifp->if_vnet);
|
||||
IEEE80211_NOTE(vap, IEEE80211_MSG_NODE, ni, "%snode leave",
|
||||
(ni == vap->iv_bss) ? "bss " : "");
|
||||
|
||||
@ -538,6 +544,7 @@ ieee80211_notify_node_leave(struct ieee80211_node *ni)
|
||||
/* fire off wireless event station leaving */
|
||||
notify_macaddr(ifp, RTM_IEEE80211_LEAVE, ni->ni_macaddr);
|
||||
}
|
||||
CURVNET_RESTORE();
|
||||
}
|
||||
|
||||
void
|
||||
@ -548,7 +555,9 @@ ieee80211_notify_scan_done(struct ieee80211vap *vap)
|
||||
IEEE80211_DPRINTF(vap, IEEE80211_MSG_SCAN, "%s\n", "notify scan done");
|
||||
|
||||
/* dispatch wireless event indicating scan completed */
|
||||
CURVNET_SET(ifp->if_vnet);
|
||||
rt_ieee80211msg(ifp, RTM_IEEE80211_SCAN, NULL, 0);
|
||||
CURVNET_RESTORE();
|
||||
}
|
||||
|
||||
void
|
||||
@ -576,7 +585,9 @@ ieee80211_notify_replay_failure(struct ieee80211vap *vap,
|
||||
iev.iev_keyix = k->wk_keyix;
|
||||
iev.iev_keyrsc = k->wk_keyrsc[0]; /* XXX need tid */
|
||||
iev.iev_rsc = rsc;
|
||||
CURVNET_SET(ifp->if_vnet);
|
||||
rt_ieee80211msg(ifp, RTM_IEEE80211_REPLAY, &iev, sizeof(iev));
|
||||
CURVNET_RESTORE();
|
||||
}
|
||||
}
|
||||
|
||||
@ -597,7 +608,9 @@ ieee80211_notify_michael_failure(struct ieee80211vap *vap,
|
||||
IEEE80211_ADDR_COPY(iev.iev_src, wh->i_addr2);
|
||||
iev.iev_cipher = IEEE80211_CIPHER_TKIP;
|
||||
iev.iev_keyix = keyix;
|
||||
CURVNET_SET(ifp->if_vnet);
|
||||
rt_ieee80211msg(ifp, RTM_IEEE80211_MICHAEL, &iev, sizeof(iev));
|
||||
CURVNET_RESTORE();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -352,6 +352,7 @@ struct ng_node {
|
||||
LIST_ENTRY(ng_node) nd_idnodes; /* ID hash collision list */
|
||||
struct ng_queue nd_input_queue; /* input queue for locking */
|
||||
int nd_refs; /* # of references to this node */
|
||||
struct vnet *nd_vnet; /* network stack instance */
|
||||
#ifdef NETGRAPH_DEBUG /*----------------------------------------------*/
|
||||
#define ND_MAGIC 0x59264837
|
||||
int nd_magic;
|
||||
|
@ -143,10 +143,12 @@ arp_ifscrub(struct ifnet *ifp, uint32_t addr)
|
||||
addr4.sin_len = sizeof(addr4);
|
||||
addr4.sin_family = AF_INET;
|
||||
addr4.sin_addr.s_addr = addr;
|
||||
CURVNET_SET(ifp->if_vnet);
|
||||
IF_AFDATA_LOCK(ifp);
|
||||
lla_lookup(LLTABLE(ifp), (LLE_DELETE | LLE_IFADDR),
|
||||
(struct sockaddr *)&addr4);
|
||||
IF_AFDATA_UNLOCK(ifp);
|
||||
CURVNET_RESTORE();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -1117,6 +1117,9 @@ igmp_input_v3_group_query(struct in_multi *inm, struct igmp_ifinfo *igi,
|
||||
|
||||
nsrc = ntohs(igmpv3->igmp_numsrc);
|
||||
|
||||
if (!IS_DEFAULT_VNET(curvnet))
|
||||
return (retval);
|
||||
|
||||
/*
|
||||
* Deal with group-specific queries upfront.
|
||||
* If any group query is already pending, purge any recorded
|
||||
@ -3372,7 +3375,7 @@ igmp_intr(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);
|
||||
CURVNET_SET((struct vnet *)(m->m_pkthdr.header));
|
||||
INIT_VNET_NET(curvnet);
|
||||
INIT_VNET_INET(curvnet);
|
||||
ifindex = igmp_restore_context(m);
|
||||
@ -3654,9 +3657,7 @@ igmp_modevent(module_t mod, int type, void *unused __unused)
|
||||
break;
|
||||
case MOD_UNLOAD:
|
||||
#ifndef VIMAGE_GLOBALS
|
||||
#ifdef NOTYET
|
||||
vnet_mod_deregister(&vnet_igmp_modinfo);
|
||||
#endif
|
||||
#else
|
||||
vnet_igmp_idetach(NULL);
|
||||
#endif
|
||||
|
@ -250,14 +250,13 @@ static void in_rtqtimo_one(void *rock);
|
||||
static void
|
||||
in_rtqtimo(void *rock)
|
||||
{
|
||||
CURVNET_SET((struct vnet *) rock);
|
||||
INIT_VNET_NET(curvnet);
|
||||
INIT_VNET_INET(curvnet);
|
||||
int fibnum;
|
||||
void *newrock;
|
||||
struct timeval atv;
|
||||
|
||||
KASSERT((rock == (void *)V_rt_tables[0][AF_INET]),
|
||||
("in_rtqtimo: unexpected arg"));
|
||||
for (fibnum = 0; fibnum < rt_numfibs; fibnum++) {
|
||||
if ((newrock = V_rt_tables[fibnum][AF_INET]) != NULL)
|
||||
in_rtqtimo_one(newrock);
|
||||
@ -265,6 +264,7 @@ in_rtqtimo(void *rock)
|
||||
atv.tv_usec = 0;
|
||||
atv.tv_sec = V_rtq_timeout;
|
||||
callout_reset(&V_rtq_timer, tvtohz(&atv), in_rtqtimo, rock);
|
||||
CURVNET_RESTORE();
|
||||
}
|
||||
|
||||
static void
|
||||
@ -377,7 +377,7 @@ in_inithead(void **head, int off)
|
||||
rnh->rnh_close = in_clsroute;
|
||||
if (_in_rt_was_here == 0 ) {
|
||||
callout_init(&V_rtq_timer, CALLOUT_MPSAFE);
|
||||
in_rtqtimo(rnh); /* kick off timeout first time */
|
||||
callout_reset(&V_rtq_timer, 1, in_rtqtimo, curvnet);
|
||||
_in_rt_was_here = 1;
|
||||
}
|
||||
return 1;
|
||||
|
@ -339,7 +339,7 @@ ip_init(void)
|
||||
|
||||
/* Start ipport_tick. */
|
||||
callout_init(&ipport_tick_callout, CALLOUT_MPSAFE);
|
||||
ipport_tick(NULL);
|
||||
callout_reset(&ipport_tick_callout, 1, ipport_tick, NULL);
|
||||
EVENTHANDLER_REGISTER(shutdown_pre_sync, ip_fini, NULL,
|
||||
SHUTDOWN_PRI_DEFAULT);
|
||||
EVENTHANDLER_REGISTER(nmbclusters_change, ipq_zone_change,
|
||||
|
@ -227,7 +227,7 @@ tcp_hc_init(void)
|
||||
*/
|
||||
callout_init(&V_tcp_hc_callout, CALLOUT_MPSAFE);
|
||||
callout_reset(&V_tcp_hc_callout, V_tcp_hostcache.prune * hz,
|
||||
tcp_hc_purge, 0);
|
||||
tcp_hc_purge, curvnet);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -634,9 +634,10 @@ sysctl_tcp_hc_list(SYSCTL_HANDLER_ARGS)
|
||||
static void
|
||||
tcp_hc_purge(void *arg)
|
||||
{
|
||||
CURVNET_SET((struct vnet *) arg);
|
||||
INIT_VNET_INET(curvnet);
|
||||
struct hc_metrics *hc_entry, *hc_next;
|
||||
int all = (intptr_t)arg;
|
||||
int all = 0; /* XXX was: (intptr_t)arg - makes no sense? */
|
||||
int i;
|
||||
|
||||
if (V_tcp_hostcache.purgeall) {
|
||||
@ -662,4 +663,5 @@ tcp_hc_purge(void *arg)
|
||||
|
||||
callout_reset(&V_tcp_hc_callout, V_tcp_hostcache.prune * hz,
|
||||
tcp_hc_purge, arg);
|
||||
CURVNET_RESTORE();
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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",
|
||||
|
@ -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__);
|
||||
|
||||
|
@ -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 @@ nd6_llinfo_timer(void *arg)
|
||||
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;
|
||||
|
@ -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",
|
||||
|
@ -82,6 +82,7 @@
|
||||
static int
|
||||
tcpsignature_init(struct secasvar *sav, struct xformsw *xsp)
|
||||
{
|
||||
INIT_VNET_IPSEC(curvnet);
|
||||
int keylen;
|
||||
|
||||
if (sav->spi != htonl(TCP_SIG_SPI)) {
|
||||
|
@ -1522,7 +1522,6 @@ nfs_create(struct vop_create_args *ap)
|
||||
if (v3) {
|
||||
tl = nfsm_build(u_int32_t *, NFSX_UNSIGNED);
|
||||
if (fmode & O_EXCL) {
|
||||
CURVNET_SET(VFSTONFS(dvp->v_mount)->nm_so->so_vnet);
|
||||
*tl = txdr_unsigned(NFSV3CREATE_EXCLUSIVE);
|
||||
tl = nfsm_build(u_int32_t *, NFSX_V3CREATEVERF);
|
||||
#ifdef INET
|
||||
@ -1533,7 +1532,6 @@ nfs_create(struct vop_create_args *ap)
|
||||
#endif
|
||||
*tl++ = create_verf;
|
||||
*tl = ++create_verf;
|
||||
CURVNET_RESTORE();
|
||||
} else {
|
||||
*tl = txdr_unsigned(NFSV3CREATE_UNCHECKED);
|
||||
nfsm_v3attrbuild(vap, FALSE);
|
||||
|
@ -275,6 +275,8 @@ struct thread {
|
||||
struct lpohead td_lprof[2]; /* (a) lock profiling objects. */
|
||||
struct kdtrace_thread *td_dtrace; /* (*) DTrace-specific data. */
|
||||
int td_errno; /* Error returned by last syscall. */
|
||||
struct vnet *td_vnet; /* (*) Effective vnet */
|
||||
const char *td_vnet_lpush; /* (*) Debugging vnet push / pop */
|
||||
};
|
||||
|
||||
struct mtx *thread_lock_block(struct thread *);
|
||||
|
@ -55,7 +55,8 @@ struct ucred {
|
||||
struct uidinfo *cr_uidinfo; /* per euid resource consumption */
|
||||
struct uidinfo *cr_ruidinfo; /* per ruid resource consumption */
|
||||
struct prison *cr_prison; /* jail(2) */
|
||||
void *cr_pspare[3]; /* vimage 2; general use 1 */
|
||||
struct vnet *cr_vnet; /* vimage / vnet */
|
||||
void *cr_pspare[2]; /* general use 2 */
|
||||
#define cr_endcopy cr_label
|
||||
struct label *cr_label; /* MAC label */
|
||||
struct auditinfo_addr cr_audit; /* Audit properties. */
|
||||
|
@ -33,6 +33,7 @@
|
||||
#ifndef _SYS_VIMAGE_H_
|
||||
#define _SYS_VIMAGE_H_
|
||||
|
||||
#include <sys/proc.h>
|
||||
#include <sys/queue.h>
|
||||
|
||||
#if defined(VIMAGE) && defined(VIMAGE_GLOBALS)
|
||||
@ -161,15 +162,69 @@ struct vnet {
|
||||
void *mod_data[VNET_MOD_MAX];
|
||||
LIST_ENTRY(vnet) vnet_le; /* all vnets list */
|
||||
u_int vnet_magic_n;
|
||||
u_int ifccnt;
|
||||
u_int sockcnt;
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef VIMAGE
|
||||
extern struct vnet *curvnet; /* XXX will become thread-local soon */
|
||||
#define curvnet curthread->td_vnet
|
||||
#else
|
||||
#define curvnet NULL
|
||||
#endif
|
||||
|
||||
#define VNET_MAGIC_N 0x3e0d8f29
|
||||
|
||||
#ifdef VIMAGE
|
||||
#ifdef VNET_DEBUG
|
||||
#define VNET_ASSERT(condition) \
|
||||
if (!(condition)) { \
|
||||
printf("VNET_ASSERT @ %s:%d %s():\n", \
|
||||
__FILE__, __LINE__, __FUNCTION__); \
|
||||
panic(#condition); \
|
||||
}
|
||||
|
||||
#define CURVNET_SET_QUIET(arg) \
|
||||
VNET_ASSERT((arg)->vnet_magic_n == VNET_MAGIC_N); \
|
||||
struct vnet *saved_vnet = curvnet; \
|
||||
const char *saved_vnet_lpush = curthread->td_vnet_lpush; \
|
||||
curvnet = arg; \
|
||||
curthread->td_vnet_lpush = __FUNCTION__;
|
||||
|
||||
#define CURVNET_SET_VERBOSE(arg) \
|
||||
CURVNET_SET_QUIET(arg) \
|
||||
if (saved_vnet) \
|
||||
printf("curvnet_set(%p) in %s() on cpu %d, prev %p in %s()\n", curvnet, \
|
||||
curthread->td_vnet_lpush, curcpu, \
|
||||
saved_vnet, saved_vnet_lpush);
|
||||
|
||||
#define CURVNET_SET(arg) CURVNET_SET_VERBOSE(arg)
|
||||
|
||||
#define CURVNET_RESTORE() \
|
||||
VNET_ASSERT(saved_vnet == NULL || \
|
||||
saved_vnet->vnet_magic_n == VNET_MAGIC_N); \
|
||||
curvnet = saved_vnet; \
|
||||
curthread->td_vnet_lpush = saved_vnet_lpush;
|
||||
#else /* !VNET_DEBUG */
|
||||
#define VNET_ASSERT(condition)
|
||||
|
||||
#define CURVNET_SET(arg) \
|
||||
struct vnet *saved_vnet = curvnet; \
|
||||
curvnet = arg;
|
||||
|
||||
#define CURVNET_SET_VERBOSE(arg) CURVNET_SET(arg)
|
||||
#define CURVNET_SET_QUIET(arg) CURVNET_SET(arg)
|
||||
|
||||
#define CURVNET_RESTORE() \
|
||||
curvnet = saved_vnet;
|
||||
#endif /* !VNET_DEBUG */
|
||||
#else /* !VIMAGE */
|
||||
#define VNET_ASSERT(condition)
|
||||
#define CURVNET_SET(arg)
|
||||
#define CURVNET_SET_QUIET(arg)
|
||||
#define CURVNET_RESTORE()
|
||||
#endif /* !VIMAGE */
|
||||
|
||||
#ifdef VIMAGE
|
||||
#ifdef VNET_DEBUG
|
||||
#define INIT_FROM_VNET(vnet, modindex, modtype, sym) \
|
||||
@ -196,14 +251,10 @@ extern struct vnet_list_head vnet_head;
|
||||
#define VNET_FOREACH(arg)
|
||||
#endif
|
||||
|
||||
#define TD_TO_VNET(td) curvnet
|
||||
#define TD_TO_VNET(td) (td)->td_ucred->cr_vnet
|
||||
|
||||
/* Non-VIMAGE null-macros */
|
||||
#define IS_DEFAULT_VNET(arg) 1
|
||||
#define CURVNET_SET(arg)
|
||||
#define CURVNET_SET_QUIET(arg)
|
||||
#define CURVNET_RESTORE()
|
||||
#define VNET_ASSERT(condition)
|
||||
#define VNET_LIST_RLOCK()
|
||||
#define VNET_LIST_RUNLOCK()
|
||||
#define INIT_VPROCG(arg)
|
||||
|
Loading…
Reference in New Issue
Block a user