xref: /freebsd/share/man/man9/VNET.9 (revision 22886d3af0657dae3b547b21e612642bb47e0321)
13049b2f5SQuentin Thébault.\"-
23049b2f5SQuentin Thébault.\" Copyright (c) 2010 The FreeBSD Foundation
33049b2f5SQuentin Thébault.\"
43049b2f5SQuentin Thébault.\" This documentation was written by CK Software GmbH under sponsorship from
53049b2f5SQuentin Thébault.\" the FreeBSD Foundation.
63049b2f5SQuentin Thébault.\"
73049b2f5SQuentin Thébault.\" Redistribution and use in source and binary forms, with or without
83049b2f5SQuentin Thébault.\" modification, are permitted provided that the following conditions
93049b2f5SQuentin Thébault.\" are met:
103049b2f5SQuentin Thébault.\" 1. Redistributions of source code must retain the above copyright
113049b2f5SQuentin Thébault.\"    notice, this list of conditions and the following disclaimer.
123049b2f5SQuentin Thébault.\" 2. Redistributions in binary form must reproduce the above copyright
133049b2f5SQuentin Thébault.\"    notice, this list of conditions and the following disclaimer in the
143049b2f5SQuentin Thébault.\"    documentation and/or other materials provided with the distribution.
153049b2f5SQuentin Thébault.\"
163049b2f5SQuentin Thébault.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
173049b2f5SQuentin Thébault.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
183049b2f5SQuentin Thébault.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
193049b2f5SQuentin Thébault.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
203049b2f5SQuentin Thébault.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
213049b2f5SQuentin Thébault.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
223049b2f5SQuentin Thébault.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
233049b2f5SQuentin Thébault.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
243049b2f5SQuentin Thébault.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
253049b2f5SQuentin Thébault.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
263049b2f5SQuentin Thébault.\" SUCH DAMAGE.
273049b2f5SQuentin Thébault.\"
28*22886d3aSBrad Davis.Dd September 19, 2025
293049b2f5SQuentin Thébault.Dt VNET 9
303049b2f5SQuentin Thébault.Os
313049b2f5SQuentin Thébault.Sh NAME
323049b2f5SQuentin Thébault.Nm VNET
333049b2f5SQuentin Thébault.Nd "network subsystem virtualization infrastructure"
343049b2f5SQuentin Thébault.Sh SYNOPSIS
353049b2f5SQuentin Thébault.Cd "options VIMAGE"
363049b2f5SQuentin Thébault.Cd "options VNET_DEBUG"
373049b2f5SQuentin Thébault.Pp
383049b2f5SQuentin Thébault.In net/vnet.h
393049b2f5SQuentin Thébault.\"------------------------------------------------------------
403049b2f5SQuentin Thébault.Ss "Constants and Global Variables"
413049b2f5SQuentin Thébault.\"
423049b2f5SQuentin Thébault.Dv VNET_SETNAME
433049b2f5SQuentin Thébault.\"	"set_vnet"
443049b2f5SQuentin Thébault.Dv VNET_SYMPREFIX
453049b2f5SQuentin Thébault.\"	"vnet_entry_"
463049b2f5SQuentin Thébault.Vt extern struct vnet *vnet0;
473049b2f5SQuentin Thébault.\"------------------------------------------------------------
483049b2f5SQuentin Thébault.Ss "Variable Declaration"
493049b2f5SQuentin Thébault.Fo VNET
503049b2f5SQuentin Thébault.Fa "name"
513049b2f5SQuentin Thébault.Fc
523049b2f5SQuentin Thébault.\"
533049b2f5SQuentin Thébault.Fo VNET_NAME
543049b2f5SQuentin Thébault.Fa "name"
553049b2f5SQuentin Thébault.Fc
563049b2f5SQuentin Thébault.\"
573049b2f5SQuentin Thébault.Fo VNET_DECLARE
583049b2f5SQuentin Thébault.Fa "type" "name"
593049b2f5SQuentin Thébault.Fc
603049b2f5SQuentin Thébault.\"
613049b2f5SQuentin Thébault.Fo VNET_DEFINE
623049b2f5SQuentin Thébault.Fa "type" "name"
633049b2f5SQuentin Thébault.Fc
643049b2f5SQuentin Thébault.\"
653049b2f5SQuentin Thébault.Fo VNET_DEFINE_STATIC
663049b2f5SQuentin Thébault.Fa "type" "name"
673049b2f5SQuentin Thébault.Fc
683049b2f5SQuentin Thébault.\"
693049b2f5SQuentin Thébault.Bd -literal
703049b2f5SQuentin Thébault#define	V_name	VNET(name)
713049b2f5SQuentin Thébault.Ed
723049b2f5SQuentin Thébault.\" ------------------------------------------------------------
733049b2f5SQuentin Thébault.Ss "Virtual Instance Selection"
743049b2f5SQuentin Thébault.\"
753049b2f5SQuentin Thébault.Fo CRED_TO_VNET
763049b2f5SQuentin Thébault.Fa "struct ucred *"
773049b2f5SQuentin Thébault.Fc
783049b2f5SQuentin Thébault.\"
793049b2f5SQuentin Thébault.Fo TD_TO_VNET
803049b2f5SQuentin Thébault.Fa "struct thread *"
813049b2f5SQuentin Thébault.Fc
823049b2f5SQuentin Thébault.\"
833049b2f5SQuentin Thébault.Fo P_TO_VNET
843049b2f5SQuentin Thébault.Fa "struct proc *"
853049b2f5SQuentin Thébault.Fc
863049b2f5SQuentin Thébault.\"
873049b2f5SQuentin Thébault.Fo IS_DEFAULT_VNET
883049b2f5SQuentin Thébault.Fa "struct vnet *"
893049b2f5SQuentin Thébault.Fc
903049b2f5SQuentin Thébault.\"
913049b2f5SQuentin Thébault.Fo VNET_ASSERT
923049b2f5SQuentin Thébault.Fa exp msg
933049b2f5SQuentin Thébault.Fc
943049b2f5SQuentin Thébault.\"
953049b2f5SQuentin Thébault.Fo CURVNET_SET
963049b2f5SQuentin Thébault.Fa "struct vnet *"
973049b2f5SQuentin Thébault.Fc
983049b2f5SQuentin Thébault.\"
993049b2f5SQuentin Thébault.Fo CURVNET_SET_QUIET
1003049b2f5SQuentin Thébault.Fa "struct vnet *"
1013049b2f5SQuentin Thébault.Fc
1023049b2f5SQuentin Thébault.\"
1033049b2f5SQuentin Thébault.Fn CURVNET_RESTORE
1043049b2f5SQuentin Thébault.\"
1053049b2f5SQuentin Thébault.Fo VNET_ITERATOR_DECL
1063049b2f5SQuentin Thébault.Fa "struct vnet *"
1073049b2f5SQuentin Thébault.Fc
1083049b2f5SQuentin Thébault.\"
1093049b2f5SQuentin Thébault.Fo VNET_FOREACH
1103049b2f5SQuentin Thébault.Fa "struct vnet *"
1113049b2f5SQuentin Thébault.Fc
1123049b2f5SQuentin Thébault.\" ------------------------------------------------------------
1133049b2f5SQuentin Thébault.Ss "Locking"
1143049b2f5SQuentin Thébault.\"
1153049b2f5SQuentin Thébault.Fn VNET_LIST_RLOCK
1163049b2f5SQuentin Thébault.Fn VNET_LIST_RUNLOCK
1173049b2f5SQuentin Thébault.Fn VNET_LIST_RLOCK_NOSLEEP
1183049b2f5SQuentin Thébault.Fn VNET_LIST_RUNLOCK_NOSLEEP
1193049b2f5SQuentin Thébault.\" ------------------------------------------------------------
1203049b2f5SQuentin Thébault.Ss "Startup and Teardown Functions"
1213049b2f5SQuentin Thébault.\"
1223049b2f5SQuentin Thébault.Ft "struct vnet *"
1233049b2f5SQuentin Thébault.Fo vnet_alloc
1243049b2f5SQuentin Thébault.Fa void
1253049b2f5SQuentin Thébault.Fc
1263049b2f5SQuentin Thébault.\"
1273049b2f5SQuentin Thébault.Ft void
1283049b2f5SQuentin Thébault.Fo vnet_destroy
1293049b2f5SQuentin Thébault.Fa "struct vnet *"
1303049b2f5SQuentin Thébault.Fc
1313049b2f5SQuentin Thébault.\"
1323049b2f5SQuentin Thébault.Fo VNET_SYSINIT
1333049b2f5SQuentin Thébault.Fa ident
1343049b2f5SQuentin Thébault.Fa "enum sysinit_sub_id subsystem"
1353049b2f5SQuentin Thébault.Fa "enum sysinit_elem_order order"
1363049b2f5SQuentin Thébault.Fa "sysinit_cfunc_t func"
1373049b2f5SQuentin Thébault.Fa "const void *arg"
1383049b2f5SQuentin Thébault.Fc
1393049b2f5SQuentin Thébault.\"
1403049b2f5SQuentin Thébault.Fo VNET_SYSUNINIT
1413049b2f5SQuentin Thébault.Fa ident
1423049b2f5SQuentin Thébault.Fa "enum sysinit_sub_id subsystem"
1433049b2f5SQuentin Thébault.Fa "enum sysinit_elem_order order"
1443049b2f5SQuentin Thébault.Fa "sysinit_cfunc_t func"
1453049b2f5SQuentin Thébault.Fa "const void *arg"
1463049b2f5SQuentin Thébault.Fc
1473049b2f5SQuentin Thébault.\" ------------------------------------------------------------
1483049b2f5SQuentin Thébault.Ss "Eventhandlers"
1493049b2f5SQuentin Thébault.\"
1503049b2f5SQuentin Thébault.Fo VNET_GLOBAL_EVENTHANDLER_REGISTER
1513049b2f5SQuentin Thébault.Fa "const char *name"
1523049b2f5SQuentin Thébault.Fa "void *func"
1533049b2f5SQuentin Thébault.Fa "void *arg"
1543049b2f5SQuentin Thébault.Fa "int priority"
1553049b2f5SQuentin Thébault.Fc
1563049b2f5SQuentin Thébault.\"
1573049b2f5SQuentin Thébault.Fo VNET_GLOBAL_EVENTHANDLER_REGISTER_TAG
1583049b2f5SQuentin Thébault.Fa "eventhandler_tag tag"
1593049b2f5SQuentin Thébault.Fa "const char *name"
1603049b2f5SQuentin Thébault.Fa "void *func"
1613049b2f5SQuentin Thébault.Fa "void *arg"
1623049b2f5SQuentin Thébault.Fa "int priority"
1633049b2f5SQuentin Thébault.Fc
1643049b2f5SQuentin Thébault.\" ------------------------------------------------------------
1653049b2f5SQuentin Thébault.Sh DESCRIPTION
1663049b2f5SQuentin Thébault.Nm
1673049b2f5SQuentin Thébaultis the name of a technique to virtualize the network stack.
1683049b2f5SQuentin ThébaultThe basic idea is to change global resources most notably variables into
1693049b2f5SQuentin Thébaultper network stack resources and have functions, sysctls, eventhandlers,
1703049b2f5SQuentin Thébaultetc. access and handle them in the context of the correct instance.
1713049b2f5SQuentin ThébaultEach (virtual) network stack is attached to a
1723049b2f5SQuentin Thébault.Em prison ,
1733049b2f5SQuentin Thébaultwith
1743049b2f5SQuentin Thébault.Vt vnet0
1753049b2f5SQuentin Thébaultbeing the unrestricted default network stack of the base system.
1763049b2f5SQuentin Thébault.Pp
1773049b2f5SQuentin ThébaultThe global defines for
1783049b2f5SQuentin Thébault.Dv VNET_SETNAME
1793049b2f5SQuentin Thébaultand
1803049b2f5SQuentin Thébault.Dv VNET_SYMPREFIX
1813049b2f5SQuentin Thébaultare shared with
1823049b2f5SQuentin Thébault.Xr kvm 3
1833049b2f5SQuentin Thébaultto access internals for debugging reasons.
1843049b2f5SQuentin Thébault.\" ------------------------------------------------------------
1853049b2f5SQuentin Thébault.Ss "Variable Declaration"
1863049b2f5SQuentin Thébault.\"
1873049b2f5SQuentin ThébaultVariables are virtualized by using the
1883049b2f5SQuentin Thébault.Fn VNET_DEFINE
1893049b2f5SQuentin Thébaultmacro rather than writing them out as
1903049b2f5SQuentin Thébault.Em type name .
1913049b2f5SQuentin ThébaultOne can still use static initialization, e.g.,
1923049b2f5SQuentin Thébault.Pp
1933049b2f5SQuentin Thébault.Dl Li VNET_DEFINE(int, foo) = 1;
1943049b2f5SQuentin Thébault.Pp
1953049b2f5SQuentin ThébaultVariables declared with the static keyword can use the
1963049b2f5SQuentin Thébault.Fn VNET_DEFINE_STATIC
1973049b2f5SQuentin Thébaultmacro, e.g.,
1983049b2f5SQuentin Thébault.Pp
1993049b2f5SQuentin Thébault.Dl Li VNET_DEFINE_STATIC(SLIST_HEAD(, bar), bars);
2003049b2f5SQuentin Thébault.Pp
2013049b2f5SQuentin ThébaultStatic initialization is not possible when the virtualized variable
2023049b2f5SQuentin Thébaultwould need to be referenced, e.g., with
2033049b2f5SQuentin Thébault.Dq TAILQ_HEAD_INITIALIZER() .
2043049b2f5SQuentin ThébaultIn that case a
2053049b2f5SQuentin Thébault.Fn VNET_SYSINIT
2063049b2f5SQuentin Thébaultbased initialization function must be used.
2073049b2f5SQuentin Thébault.Pp
2083049b2f5SQuentin ThébaultExternal variables have to be declared using the
2093049b2f5SQuentin Thébault.Fn VNET_DECLARE
2103049b2f5SQuentin Thébaultmacro.
2113049b2f5SQuentin ThébaultIn either case the convention is to define another macro,
2123049b2f5SQuentin Thébaultthat is then used throughout the implementation to access that variable.
2133049b2f5SQuentin ThébaultThe variable name is usually prefixed by
2143049b2f5SQuentin Thébault.Em V_
2153049b2f5SQuentin Thébaultto express that it is virtualized.
2163049b2f5SQuentin ThébaultThe
2173049b2f5SQuentin Thébault.Fn VNET
2183049b2f5SQuentin Thébaultmacro will then translate accesses to that variable to the copy of the
2193049b2f5SQuentin Thébaultcurrently selected instance (see the
2203049b2f5SQuentin Thébault.Sx "Virtual instance selection"
2213049b2f5SQuentin Thébaultsection):
2223049b2f5SQuentin Thébault.Pp
2233049b2f5SQuentin Thébault.Dl Li #define	V_name	VNET(name)
2243049b2f5SQuentin Thébault.Pp
2253049b2f5SQuentin Thébault.Em NOTE:
2263049b2f5SQuentin ThébaultDo not confuse this with the convention used by
2273049b2f5SQuentin Thébault.Xr VFS 9 .
2283049b2f5SQuentin Thébault.Pp
2293049b2f5SQuentin ThébaultThe
2303049b2f5SQuentin Thébault.Fn VNET_NAME
2313049b2f5SQuentin Thébaultmacro returns the offset within the memory region of the virtual network
2323049b2f5SQuentin Thébaultstack instance.
2333049b2f5SQuentin Thébault.\" ------------------------------------------------------------
2343049b2f5SQuentin Thébault.Ss "Virtual Instance Selection"
2353049b2f5SQuentin Thébault.\"
2363049b2f5SQuentin ThébaultThere are three different places where the current virtual
2373049b2f5SQuentin Thébaultnetwork stack pointer is stored and can be taken from:
2383049b2f5SQuentin Thébault.Bl -enum -offset indent
2393049b2f5SQuentin Thébault.It
2403049b2f5SQuentin Thébaulta
2413049b2f5SQuentin Thébault.Em prison :
2423049b2f5SQuentin Thébault.Dl "(struct prison *)->pr_vnet"
2433049b2f5SQuentin Thébault.Pp
2443049b2f5SQuentin ThébaultFor convenience the following macros are provided:
2453049b2f5SQuentin Thébault.Bd -literal -compact -offset indent
2463049b2f5SQuentin Thébault.Fn CRED_TO_VNET "struct ucred *"
2473049b2f5SQuentin Thébault.Fn TD_TO_VNET "struct thread *"
2483049b2f5SQuentin Thébault.Fn P_TO_VNET "struct proc *"
2493049b2f5SQuentin Thébault.Ed
2503049b2f5SQuentin Thébault.It
2513049b2f5SQuentin Thébaulta
2523049b2f5SQuentin Thébault.Em socket :
2533049b2f5SQuentin Thébault.Dl "(struct socket *)->so_vnet"
2543049b2f5SQuentin Thébault.It
2553049b2f5SQuentin Thébaultan
2563049b2f5SQuentin Thébault.Em interface :
2573049b2f5SQuentin Thébault.Dl "(struct ifnet *)->if_vnet"
2583049b2f5SQuentin Thébault.El
2593049b2f5SQuentin Thébault.Pp
2603049b2f5SQuentin Thébault.\"
2613049b2f5SQuentin ThébaultIn addition the currently active instance is cached in
2623049b2f5SQuentin Thébault.Dq "curthread->td_vnet"
2633049b2f5SQuentin Thébaultwhich is usually only accessed through the
2643049b2f5SQuentin Thébault.Dv curvnet
2653049b2f5SQuentin Thébaultmacro.
2663049b2f5SQuentin Thébault.Pp
2673049b2f5SQuentin Thébault.\"
2683049b2f5SQuentin ThébaultTo set the correct context of the current virtual network instance, use the
2693049b2f5SQuentin Thébault.Fn CURVNET_SET
2703049b2f5SQuentin Thébaultor
2713049b2f5SQuentin Thébault.Fn CURVNET_SET_QUIET
2723049b2f5SQuentin Thébaultmacros.
2733049b2f5SQuentin ThébaultThe
2743049b2f5SQuentin Thébault.Fn CURVNET_SET_QUIET
2753049b2f5SQuentin Thébaultversion will not record vnet recursions in case the kernel was compiled
2763049b2f5SQuentin Thébaultwith
2773049b2f5SQuentin Thébault.Cd "options VNET_DEBUG"
2783049b2f5SQuentin Thébaultand should thus only be used in well known cases, where recursion is
2793049b2f5SQuentin Thébaultunavoidable.
2803049b2f5SQuentin ThébaultBoth macros will save the previous state on the stack and it must be restored
2813049b2f5SQuentin Thébaultwith the
2823049b2f5SQuentin Thébault.Fn CURVNET_RESTORE
2833049b2f5SQuentin Thébaultmacro.
2843049b2f5SQuentin Thébault.Pp
2853049b2f5SQuentin Thébault.Em NOTE:
2863049b2f5SQuentin ThébaultAs the previous state is saved on the stack, you cannot have multiple
2873049b2f5SQuentin Thébault.Fn CURVNET_SET
2883049b2f5SQuentin Thébaultcalls in the same block.
2893049b2f5SQuentin Thébault.Pp
2903049b2f5SQuentin Thébault.Em NOTE:
2913049b2f5SQuentin ThébaultAs the previous state is saved on the stack, a
2923049b2f5SQuentin Thébault.Fn CURVNET_RESTORE
2933049b2f5SQuentin Thébaultcall has to be in the same block as the
2943049b2f5SQuentin Thébault.Fn CURVNET_SET
2953049b2f5SQuentin Thébaultcall or in a subblock with the same idea of the saved instances as the
2963049b2f5SQuentin Thébaultouter block.
2973049b2f5SQuentin Thébault.Pp
2983049b2f5SQuentin Thébault.Em NOTE:
2993049b2f5SQuentin ThébaultAs each macro is a set of operations and, as previously explained, cannot
3003049b2f5SQuentin Thébaultbe put into its own block when defined, one cannot conditionally set
3013049b2f5SQuentin Thébaultthe current vnet context.
3023049b2f5SQuentin ThébaultThe following will
3033049b2f5SQuentin Thébault.Em not
3043049b2f5SQuentin Thébaultwork:
3053049b2f5SQuentin Thébault.Bd -literal -offset indent
3063049b2f5SQuentin Thébaultif (condition)
3073049b2f5SQuentin Thébault	CURVNET_SET(vnet);
3083049b2f5SQuentin Thébault.Ed
3093049b2f5SQuentin Thébault.Pp
3103049b2f5SQuentin Thébaultnor would this work:
3113049b2f5SQuentin Thébault.Bd -literal -offset indent
3123049b2f5SQuentin Thébaultif (condition) {
3133049b2f5SQuentin Thébault	CURVNET_SET(vnet);
3143049b2f5SQuentin Thébault}
3153049b2f5SQuentin ThébaultCURVNET_RESTORE();
3163049b2f5SQuentin Thébault.Ed
3173049b2f5SQuentin Thébault.Pp
3183049b2f5SQuentin Thébault.\"
3193049b2f5SQuentin ThébaultSometimes one needs to loop over all virtual instances, for example to update
3203049b2f5SQuentin Thébaultvirtual from global state, to run a function from a
3213049b2f5SQuentin Thébault.Xr callout 9
3223049b2f5SQuentin Thébaultfor each instance, etc.
3233049b2f5SQuentin ThébaultFor those cases the
3243049b2f5SQuentin Thébault.Fn VNET_ITERATOR_DECL
3253049b2f5SQuentin Thébaultand
3263049b2f5SQuentin Thébault.Fn VNET_FOREACH
3273049b2f5SQuentin Thébaultmacros are provided.
3283049b2f5SQuentin ThébaultThe former macro defines the variable that iterates over the loop,
3293049b2f5SQuentin Thébaultand the latter loops over all of the virtual network stack instances.
3303049b2f5SQuentin ThébaultSee
3313049b2f5SQuentin Thébault.Sx "Locking"
3323049b2f5SQuentin Thébaultfor how to savely traverse the list of all virtual instances.
3333049b2f5SQuentin Thébault.Pp
3343049b2f5SQuentin Thébault.\"
3353049b2f5SQuentin ThébaultThe
3363049b2f5SQuentin Thébault.Fn IS_DEFAULT_VNET
3373049b2f5SQuentin Thébaultmacro provides a safe way to check whether the currently active instance is the
3383049b2f5SQuentin Thébaultunrestricted default network stack of the base system
3393049b2f5SQuentin Thébault.Pq Vt vnet0 .
3403049b2f5SQuentin Thébault.Pp
3413049b2f5SQuentin Thébault.\"
3423049b2f5SQuentin ThébaultThe
3433049b2f5SQuentin Thébault.Fn VNET_ASSERT
3443049b2f5SQuentin Thébaultmacro provides a way to conditionally add assertions that are only active with
3453049b2f5SQuentin Thébault.Cd "options VIMAGE"
3463049b2f5SQuentin Thébaultcompiled in and either
3473049b2f5SQuentin Thébault.Cd "options VNET_DEBUG"
3483049b2f5SQuentin Thébaultor
3493049b2f5SQuentin Thébault.Cd "options INVARIANTS"
3503049b2f5SQuentin Thébaultenabled as well.
3513049b2f5SQuentin ThébaultIt uses the same semantics as
3523049b2f5SQuentin Thébault.Xr KASSERT 9 .
3533049b2f5SQuentin Thébault.\" ------------------------------------------------------------
3543049b2f5SQuentin Thébault.Ss "Locking"
3553049b2f5SQuentin Thébault.\"
3563049b2f5SQuentin ThébaultFor public access to the list of virtual network stack instances
3573049b2f5SQuentin Thébaulte.g., by the
3583049b2f5SQuentin Thébault.Fn VNET_FOREACH
3593049b2f5SQuentin Thébaultmacro, read locks are provided.
3603049b2f5SQuentin ThébaultMacros are used to abstract from the actual type of the locks.
3613049b2f5SQuentin ThébaultIf a caller may sleep while traversing the list, it must use the
3623049b2f5SQuentin Thébault.Fn VNET_LIST_RLOCK
3633049b2f5SQuentin Thébaultand
3643049b2f5SQuentin Thébault.Fn VNET_LIST_RUNLOCK
3653049b2f5SQuentin Thébaultmacros.
3663049b2f5SQuentin ThébaultOtherwise, the caller can use
3673049b2f5SQuentin Thébault.Fn VNET_LIST_RLOCK_NOSLEEP
3683049b2f5SQuentin Thébaultand
3693049b2f5SQuentin Thébault.Fn VNET_LIST_RUNLOCK_NOSLEEP .
3703049b2f5SQuentin Thébault.\" ------------------------------------------------------------
3713049b2f5SQuentin Thébault.Ss "Startup and Teardown Functions"
3723049b2f5SQuentin Thébault.\"
3733049b2f5SQuentin ThébaultTo start or tear down a virtual network stack instance the internal
3743049b2f5SQuentin Thébaultfunctions
3753049b2f5SQuentin Thébault.Fn vnet_alloc
3763049b2f5SQuentin Thébaultand
3773049b2f5SQuentin Thébault.Fn vnet_destroy
3783049b2f5SQuentin Thébaultare provided and called from the jail framework.
3793049b2f5SQuentin ThébaultThey run the publicly provided methods to handle network stack
3803049b2f5SQuentin Thébaultstartup and teardown.
3813049b2f5SQuentin Thébault.Pp
3823049b2f5SQuentin ThébaultFor public control, the system startup interface has been enhanced
3833049b2f5SQuentin Thébaultto not only handle a system boot but to also handle a virtual
3843049b2f5SQuentin Thébaultnetwork stack startup and teardown.
3853049b2f5SQuentin ThébaultTo the base system the
3863049b2f5SQuentin Thébault.Fn VNET_SYSINIT
3873049b2f5SQuentin Thébaultand
3883049b2f5SQuentin Thébault.Fn VNET_SYSUNINIT
3893049b2f5SQuentin Thébaultmacros look exactly as if there were no virtual network stack.
3903049b2f5SQuentin ThébaultIn fact, if
3913049b2f5SQuentin Thébault.Cd "options VIMAGE"
3923049b2f5SQuentin Thébaultis not compiled in they are compiled to the standard
3933049b2f5SQuentin Thébault.Fn SYSINIT
3943049b2f5SQuentin Thébaultmacros.
3953049b2f5SQuentin ThébaultIn addition to that they are run for each virtual network stack
3963049b2f5SQuentin Thébaultwhen starting or, in reverse order, when shutting down.
3973049b2f5SQuentin Thébault.\" ------------------------------------------------------------
3983049b2f5SQuentin Thébault.Ss "Eventhandlers"
3993049b2f5SQuentin Thébault.\"
4003049b2f5SQuentin ThébaultEventhandlers can be handled in two ways:
4013049b2f5SQuentin Thébault.Pp
4023049b2f5SQuentin Thébault.Bl -enum -offset indent -compact
4033049b2f5SQuentin Thébault.It
4043049b2f5SQuentin Thébaultsave the
4053049b2f5SQuentin Thébault.Em tags
4063049b2f5SQuentin Thébaultreturned in each virtual instance and properly free the eventhandlers
4073049b2f5SQuentin Thébaulton teardown using those, or
4083049b2f5SQuentin Thébault.It
4093049b2f5SQuentin Thébaultuse one eventhandler that will iterate over all virtual network
4103049b2f5SQuentin Thébaultstack instances.
4113049b2f5SQuentin Thébault.El
4123049b2f5SQuentin Thébault.Pp
4133049b2f5SQuentin ThébaultFor the first case one can just use the normal
4143049b2f5SQuentin Thébault.Xr EVENTHANDLER 9
4153049b2f5SQuentin Thébaultfunctions, while for the second case the
4163049b2f5SQuentin Thébault.Fn VNET_GLOBAL_EVENTHANDLER_REGISTER
4173049b2f5SQuentin Thébaultand
4183049b2f5SQuentin Thébault.Fn VNET_GLOBAL_EVENTHANDLER_REGISTER_TAG
4193049b2f5SQuentin Thébaultmacros are provided.
4203049b2f5SQuentin ThébaultThese differ in that
4213049b2f5SQuentin Thébault.Fn VNET_GLOBAL_EVENTHANDLER_REGISTER_TAG
4223049b2f5SQuentin Thébaulttakes an extra first argument that will carry the
4233049b2f5SQuentin Thébault.Fa "tag"
4243049b2f5SQuentin Thébaultupon return.
4253049b2f5SQuentin ThébaultEventhandlers registered with either of these will not run
4263049b2f5SQuentin Thébault.Fa func
4273049b2f5SQuentin Thébaultdirectly but
4283049b2f5SQuentin Thébault.Fa func
4293049b2f5SQuentin Thébaultwill be called from an internal iterator function for each vnet.
4303049b2f5SQuentin ThébaultBoth macros can only be used for eventhandlers that do not take
4313049b2f5SQuentin Thébaultadditional arguments, as the variadic arguments from an
4323049b2f5SQuentin Thébault.Xr EVENTHANDLER_INVOKE 9
4333049b2f5SQuentin Thébaultcall will be ignored.
4343049b2f5SQuentin Thébault.\" ------------------------------------------------------------
4353049b2f5SQuentin Thébault.Ss "Sysctl Handling"
4363049b2f5SQuentin Thébault.\"
4373049b2f5SQuentin ThébaultA
4383049b2f5SQuentin Thébault.Xr sysctl 9
439*22886d3aSBrad Daviscan be virtualized by adding the
440*22886d3aSBrad Davis.Dv CTLFLAG_VNET
441*22886d3aSBrad Daviscontrol flag to the ctlflags bitmask of the macros.
4423049b2f5SQuentin Thébault.\" ------------------------------------------------------------
4433049b2f5SQuentin Thébault.Sh SEE ALSO
4443049b2f5SQuentin Thébault.Xr jail 2 ,
4453049b2f5SQuentin Thébault.Xr kvm 3 ,
4463049b2f5SQuentin Thébault.Xr EVENTHANDLER 9 ,
4473049b2f5SQuentin Thébault.\" .Xr pcpu 9 ,
4483049b2f5SQuentin Thébault.Xr KASSERT 9 ,
4493049b2f5SQuentin Thébault.Xr sysctl 9
4503049b2f5SQuentin Thébault.\" .Xr SYSINIT 9
4513049b2f5SQuentin Thébault.Pp
4523049b2f5SQuentin ThébaultMarko Zec, Implementing a Clonable Network Stack in the FreeBSD Kernel,
4533049b2f5SQuentin ThébaultUSENIX ATC'03, June 2003, Boston
4543049b2f5SQuentin Thébault.Sh HISTORY
4553049b2f5SQuentin ThébaultThe virtual network stack implementation first appeared in
4563049b2f5SQuentin Thébault.Fx 8.0 .
4573049b2f5SQuentin Thébault.Sh AUTHORS
4583049b2f5SQuentin Thébault.An -nosplit
4593049b2f5SQuentin ThébaultThe
4603049b2f5SQuentin Thébault.Nm
4613049b2f5SQuentin Thébaultframework was designed and implemented at the University of Zagreb by
4623049b2f5SQuentin Thébault.An Marko Zec
4633049b2f5SQuentin Thébaultunder sponsorship of the FreeBSD Foundation and NLnet Foundation,
4643049b2f5SQuentin Thébaultand later extended and refined by
4653049b2f5SQuentin Thébault.An Bjoern A. Zeeb
4663049b2f5SQuentin Thébault(also under FreeBSD Foundation sponsorship), and
4673049b2f5SQuentin Thébault.An Robert Watson .
4683049b2f5SQuentin Thébault.Pp
4693049b2f5SQuentin ThébaultThis manual page was written by
4703049b2f5SQuentin Thébault.An Bjoern A. Zeeb, CK Software GmbH,
4713049b2f5SQuentin Thébaultunder sponsorship from the FreeBSD Foundation.
472