|
NAMEVNET —
network subsystem virtualization infrastructure
SYNOPSISoptions VIMAGE
options VNET_DEBUG
Constants and Global VariablesVNET_SETNAME VNET_SYMPREFIX
extern struct vnet *vnet0; Variable DeclarationVNET (name);
#define V_name VNET(name) Virtual Instance SelectionCRED_TO_VNET (struct ucred *);
LockingVNET_LIST_RLOCK ();
Startup and Teardown Functionsstruct vnet *vnet_alloc (void);
void
EventhandlersVNET_GLOBAL_EVENTHANDLER_REGISTER (const
char *name, void *func, void
*arg, int priority);
Sysctl HandlingSYSCTL_VNET_INT (parent,
nbr, name,
access, ptr,
val, descr);
DESCRIPTIONVNET is the name of a technique to virtualize the
network stack. The basic idea is to change global resources most notably
variables into per network stack resources and have functions, sysctls,
eventhandlers, etc. access and handle them in the context of the correct
instance. Each (virtual) network stack is attached to a
prison, with vnet0 being the
unrestricted default network stack of the base system.
The global defines for Variable DeclarationVariables are virtualized by using theVNET_DEFINE ()
macro rather than writing them out as type name. One can
still use static initialization, e.g.,
Variables declared with the static keyword can use the
Static initialization is not possible when the virtualized
variable would need to be referenced, e.g., with
“TAILQ_HEAD_INITIALIZER()”. In that case a
External variables have to be declared using the
NOTE: Do not confuse this with the convention used by VFS(9). The Virtual Instance SelectionThere are three different places where the current virtual network stack pointer is stored and can be taken from:
In addition the currently active instance is cached in
“curthread->td_vnet” which is usually only accessed through
the To set the correct context of the current virtual network
instance, use the NOTE: As the previous state is saved on the
stack, you cannot have multiple NOTE: As the previous state is saved on the
stack, a NOTE: As each macro is a set of operations and, as previously explained, cannot be put into its own block when defined, one cannot conditionally set the current vnet context. The following will not work: if (condition) CURVNET_SET(vnet); nor would this work: if (condition) { CURVNET_SET(vnet); } CURVNET_RESTORE(); Sometimes one needs to loop over all virtual instances, for
example to update virtual from global state, to run a function from a
callout(9)
for each instance, etc. For those cases the
The The LockingFor public access to the list of virtual network stack instances e.g., by theVNET_FOREACH () macro, read locks are provided. Macros
are used to abstract from the actual type of the locks. If a caller may sleep
while traversing the list, it must use the
VNET_LIST_RLOCK () and
VNET_LIST_RUNLOCK () macros. Otherwise, the caller can
use VNET_LIST_RLOCK_NOSLEEP () and
VNET_LIST_RUNLOCK_NOSLEEP ().
Startup and Teardown FunctionsTo start or tear down a virtual network stack instance the internal functionsvnet_alloc () and
vnet_destroy () are provided and called from the jail
framework. They run the publicly provided methods to handle network stack
startup and teardown.
For public control, the system startup interface has been enhanced
to not only handle a system boot but to also handle a virtual network stack
startup and teardown. To the base system the
EventhandlersEventhandlers can be handled in two ways:
For the first case one can just use the normal
EVENTHANDLER(9)
functions, while for the second case the
Sysctl HandlingA sysctl(9) can be virtualized by using one of theSYSCTL_VNET_* ()
macros.
They take the same arguments as the standard
sysctl(9)
functions, with the only difference, that the ptr
argument has to be passed as
‘ For the very rare case a sysctl handler function would want to
handle arg1 itself the
SEE ALSOjail(2), kvm(3), EVENTHANDLER(9), KASSERT(9), sysctl(9)Marko Zec, Implementing a Clonable Network Stack in the FreeBSD Kernel, USENIX ATC'03, June 2003, Boston HISTORYThe virtual network stack implementation first appeared in FreeBSD 8.0.AUTHORSTheVNET framework was designed and implemented at the
University of Zagreb by Marko Zec under sponsorship of
the FreeBSD Foundation and NLnet Foundation, and later extended and refined by
Bjoern A. Zeeb (also under FreeBSD Foundation
sponsorship), and Robert Watson.
This manual page was written by Bjoern A. Zeeb, CK Software GmbH, under sponsorship from the FreeBSD Foundation.
Visit the GSP FreeBSD Man Page Interface. |