xref: /freebsd/sys/net/vnet.c (revision 941e286383714ef25f1ffe9ba6ae5040afdd7060)
1 /*-
2  * Copyright (c) 2004-2009 University of Zagreb
3  * Copyright (c) 2006-2009 FreeBSD Foundation
4  * All rights reserved.
5  *
6  * This software was developed by the University of Zagreb and the
7  * FreeBSD Foundation under sponsorship by the Stichting NLnet and the
8  * FreeBSD Foundation.
9  *
10  * Copyright (c) 2009 Jeffrey Roberson <jeff@freebsd.org>
11  * Copyright (c) 2009 Robert N. M. Watson
12  * All rights reserved.
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions
16  * are met:
17  * 1. Redistributions of source code must retain the above copyright
18  *    notice, this list of conditions and the following disclaimer.
19  * 2. Redistributions in binary form must reproduce the above copyright
20  *    notice, this list of conditions and the following disclaimer in the
21  *    documentation and/or other materials provided with the distribution.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  */
35 
36 #include <sys/cdefs.h>
37 __FBSDID("$FreeBSD$");
38 
39 #include "opt_ddb.h"
40 
41 #include <sys/param.h>
42 #include <sys/kernel.h>
43 #include <sys/jail.h>
44 #include <sys/systm.h>
45 #include <sys/sysctl.h>
46 #include <sys/linker_set.h>
47 #include <sys/lock.h>
48 #include <sys/malloc.h>
49 #include <sys/proc.h>
50 #include <sys/socket.h>
51 #include <sys/sx.h>
52 #include <sys/sysctl.h>
53 
54 #ifdef DDB
55 #include <ddb/ddb.h>
56 #endif
57 
58 #include <net/if.h>
59 #include <net/if_var.h>
60 #include <net/vnet.h>
61 
62 /*-
63  * This file implements core functions for virtual network stacks:
64  *
65  * - Virtual network stack management functions.
66  *
67  * - Virtual network stack memory allocator, which virtualizes global
68  *   variables in the network stack
69  *
70  * - Virtualized SYSINIT's/SYSUNINIT's, which allow network stack subsystems
71  *   to register startup/shutdown events to be run for each virtual network
72  *   stack instance.
73  */
74 
75 MALLOC_DEFINE(M_VNET, "vnet", "network stack control block");
76 
77 /*
78  * The virtual network stack list has two read-write locks, one sleepable and
79  * the other not, so that the list can be stablized and walked in a variety
80  * of network stack contexts.  Both must be acquired exclusively to modify
81  * the list, but a read lock of either lock is sufficient to walk the list.
82  */
83 struct rwlock		vnet_rwlock;
84 struct sx		vnet_sxlock;
85 
86 #define	VNET_LIST_WLOCK() do {						\
87 	sx_xlock(&vnet_sxlock);						\
88 	rw_wlock(&vnet_rwlock);						\
89 } while (0)
90 
91 #define	VNET_LIST_WUNLOCK() do {					\
92 	rw_wunlock(&vnet_rwlock);					\
93 	sx_xunlock(&vnet_sxlock);					\
94 } while (0)
95 
96 struct vnet_list_head vnet_head;
97 struct vnet *vnet0;
98 
99 /*
100  * The virtual network stack allocator provides storage for virtualized
101  * global variables.  These variables are defined/declared using the
102  * VNET_DEFINE()/VNET_DECLARE() macros, which place them in the 'set_vnet'
103  * linker set.  The details of the implementation are somewhat subtle, but
104  * allow the majority of most network subsystems to maintain
105  * virtualization-agnostic.
106  *
107  * The virtual network stack allocator handles variables in the base kernel
108  * vs. modules in similar but different ways.  In both cases, virtualized
109  * global variables are marked as such by being declared to be part of the
110  * vnet linker set.  These "master" copies of global variables serve two
111  * functions:
112  *
113  * (1) They contain static initialization or "default" values for global
114  *     variables which will be propagated to each virtual network stack
115  *     instance when created.  As with normal global variables, they default
116  *     to zero-filled.
117  *
118  * (2) They act as unique global names by which the variable can be referred
119  *     to, regardless of network stack instance.  The single global symbol
120  *     will be used to calculate the location of a per-virtual instance
121  *     variable at run-time.
122  *
123  * Each virtual network stack instance has a complete copy of each
124  * virtualized global variable, stored in a malloc'd block of memory
125  * referred to by vnet->vnet_data_mem.  Critical to the design is that each
126  * per-instance memory block is laid out identically to the master block so
127  * that the offset of each global variable is the same across all blocks.  To
128  * optimize run-time access, a precalculated 'base' address,
129  * vnet->vnet_data_base, is stored in each vnet, and is the amount that can
130  * be added to the address of a 'master' instance of a variable to get to the
131  * per-vnet instance.
132  *
133  * Virtualized global variables are handled in a similar manner, but as each
134  * module has its own 'set_vnet' linker set, and we want to keep all
135  * virtualized globals togther, we reserve space in the kernel's linker set
136  * for potential module variables using a per-vnet character array,
137  * 'modspace'.  The virtual network stack allocator maintains a free list to
138  * track what space in the array is free (all, initially) and as modules are
139  * linked, allocates portions of the space to specific globals.  The kernel
140  * module linker queries the virtual network stack allocator and will
141  * bind references of the global to the location during linking.  It also
142  * calls into the virtual network stack allocator, once the memory is
143  * initialized, in order to propagate the new static initializations to all
144  * existing virtual network stack instances so that the soon-to-be executing
145  * module will find every network stack instance with proper default values.
146  */
147 
148 /*
149  * Location of the kernel's 'set_vnet' linker set.
150  */
151 extern uintptr_t	*__start_set_vnet;
152 extern uintptr_t	*__stop_set_vnet;
153 
154 #define	VNET_START	(uintptr_t)&__start_set_vnet
155 #define	VNET_STOP	(uintptr_t)&__stop_set_vnet
156 
157 /*
158  * Number of bytes of data in the 'set_vnet' linker set, and hence the total
159  * size of all kernel virtualized global variables, and the malloc(9) type
160  * that will be used to allocate it.
161  */
162 #define	VNET_BYTES	(VNET_STOP - VNET_START)
163 
164 MALLOC_DEFINE(M_VNET_DATA, "vnet_data", "VNET data");
165 
166 /*
167  * VNET_MODMIN is the minimum number of bytes we will reserve for the sum of
168  * global variables across all loaded modules.  As this actually sizes an
169  * array declared as a virtualized global variable in the kernel itself, and
170  * we want the virtualized global variable space to be page-sized, we may
171  * have more space than that in practice.
172  */
173 #define	VNET_MODMIN	8192
174 #define	VNET_SIZE	roundup2(VNET_BYTES, PAGE_SIZE)
175 #define	VNET_MODSIZE	(VNET_SIZE - (VNET_BYTES - VNET_MODMIN))
176 
177 /*
178  * Space to store virtualized global variables from loadable kernel modules,
179  * and the free list to manage it.
180  */
181 static VNET_DEFINE(char, modspace[VNET_MODMIN]);
182 
183 /*
184  * Global lists of subsystem constructor and destructors for vnets.  They are
185  * registered via VNET_SYSINIT() and VNET_SYSUNINIT().  Both lists are
186  * protected by the vnet_sysinit_sxlock global lock.
187  */
188 static TAILQ_HEAD(vnet_sysinit_head, vnet_sysinit) vnet_constructors =
189 	TAILQ_HEAD_INITIALIZER(vnet_constructors);
190 static TAILQ_HEAD(vnet_sysuninit_head, vnet_sysinit) vnet_destructors =
191 	TAILQ_HEAD_INITIALIZER(vnet_destructors);
192 
193 struct sx		vnet_sysinit_sxlock;
194 
195 #define	VNET_SYSINIT_WLOCK()	sx_xlock(&vnet_sysinit_sxlock);
196 #define	VNET_SYSINIT_WUNLOCK()	sx_xunlock(&vnet_sysinit_sxlock);
197 #define	VNET_SYSINIT_RLOCK()	sx_slock(&vnet_sysinit_sxlock);
198 #define	VNET_SYSINIT_RUNLOCK()	sx_sunlock(&vnet_sysinit_sxlock);
199 
200 struct vnet_data_free {
201 	uintptr_t	vnd_start;
202 	int		vnd_len;
203 	TAILQ_ENTRY(vnet_data_free) vnd_link;
204 };
205 
206 MALLOC_DEFINE(M_VNET_DATA_FREE, "vnet_data_free", "VNET resource accounting");
207 static TAILQ_HEAD(, vnet_data_free) vnet_data_free_head =
208 	    TAILQ_HEAD_INITIALIZER(vnet_data_free_head);
209 static struct sx vnet_data_free_lock;
210 
211 /*
212  * Allocate a virtual network stack.
213  */
214 struct vnet *
215 vnet_alloc(void)
216 {
217 	struct vnet *vnet;
218 
219 	vnet = malloc(sizeof(struct vnet), M_VNET, M_WAITOK | M_ZERO);
220 	vnet->vnet_magic_n = VNET_MAGIC_N;
221 
222 	/*
223 	 * Allocate storage for virtualized global variables and copy in
224 	 * initial values form our 'master' copy.
225 	 */
226 	vnet->vnet_data_mem = malloc(VNET_SIZE, M_VNET_DATA, M_WAITOK);
227 	memcpy(vnet->vnet_data_mem, (void *)VNET_START, VNET_BYTES);
228 
229 	/*
230 	 * All use of vnet-specific data will immediately subtract VNET_START
231 	 * from the base memory pointer, so pre-calculate that now to avoid
232 	 * it on each use.
233 	 */
234 	vnet->vnet_data_base = (uintptr_t)vnet->vnet_data_mem - VNET_START;
235 
236 	/* Initialize / attach vnet module instances. */
237 	CURVNET_SET_QUIET(vnet);
238 	vnet_sysinit();
239 	CURVNET_RESTORE();
240 
241 	VNET_LIST_WLOCK();
242 	LIST_INSERT_HEAD(&vnet_head, vnet, vnet_le);
243 	VNET_LIST_WUNLOCK();
244 
245 	return (vnet);
246 }
247 
248 /*
249  * Destroy a virtual network stack.
250  */
251 void
252 vnet_destroy(struct vnet *vnet)
253 {
254 	struct ifnet *ifp, *nifp;
255 
256 	KASSERT(vnet->vnet_sockcnt == 0,
257 	    ("%s: vnet still has sockets", __func__));
258 
259 	VNET_LIST_WLOCK();
260 	LIST_REMOVE(vnet, vnet_le);
261 	VNET_LIST_WUNLOCK();
262 
263 	CURVNET_SET_QUIET(vnet);
264 
265 	/* Return all inherited interfaces to their parent vnets. */
266 	TAILQ_FOREACH_SAFE(ifp, &V_ifnet, if_link, nifp) {
267 		if (ifp->if_home_vnet != ifp->if_vnet)
268 			if_vmove(ifp, ifp->if_home_vnet);
269 	}
270 
271 	vnet_sysuninit();
272 	CURVNET_RESTORE();
273 
274 	/*
275 	 * Release storage for the virtual network stack instance.
276 	 */
277 	free(vnet->vnet_data_mem, M_VNET_DATA);
278 	vnet->vnet_data_mem = NULL;
279 	vnet->vnet_data_base = 0;
280 	vnet->vnet_magic_n = 0xdeadbeef;
281 	free(vnet, M_VNET);
282 }
283 
284 /*
285  * Boot time initialization and allocation of virtual network stacks.
286  */
287 static void
288 vnet_init_prelink(void *arg)
289 {
290 
291 	rw_init(&vnet_rwlock, "vnet_rwlock");
292 	sx_init(&vnet_sxlock, "vnet_sxlock");
293 	sx_init(&vnet_sysinit_sxlock, "vnet_sysinit_sxlock");
294 	LIST_INIT(&vnet_head);
295 }
296 SYSINIT(vnet_init_prelink, SI_SUB_VNET_PRELINK, SI_ORDER_FIRST,
297     vnet_init_prelink, NULL);
298 
299 static void
300 vnet0_init(void *arg)
301 {
302 
303 	/* Warn people before take off - in case we crash early. */
304 	printf("WARNING: VIMAGE (virtualized network stack) is a highly "
305 	    "experimental feature.\n");
306 
307 	/*
308 	 * We MUST clear curvnet in vi_init_done() before going SMP,
309 	 * otherwise CURVNET_SET() macros would scream about unnecessary
310 	 * curvnet recursions.
311 	 */
312 	curvnet = prison0.pr_vnet = vnet0 = vnet_alloc();
313 }
314 SYSINIT(vnet0_init, SI_SUB_VNET, SI_ORDER_FIRST, vnet0_init, NULL);
315 
316 static void
317 vnet_init_done(void *unused)
318 {
319 
320 	curvnet = NULL;
321 }
322 
323 SYSINIT(vnet_init_done, SI_SUB_VNET_DONE, SI_ORDER_FIRST, vnet_init_done,
324     NULL);
325 
326 /*
327  * Once on boot, initialize the modspace freelist to entirely cover modspace.
328  */
329 static void
330 vnet_data_startup(void *dummy __unused)
331 {
332 	struct vnet_data_free *df;
333 
334 	df = malloc(sizeof(*df), M_VNET_DATA_FREE, M_WAITOK | M_ZERO);
335 	df->vnd_start = (uintptr_t)&VNET_NAME(modspace);
336 	df->vnd_len = VNET_MODSIZE;
337 	TAILQ_INSERT_HEAD(&vnet_data_free_head, df, vnd_link);
338 	sx_init(&vnet_data_free_lock, "vnet_data alloc lock");
339 }
340 SYSINIT(vnet_data, SI_SUB_KLD, SI_ORDER_FIRST, vnet_data_startup, 0);
341 
342 /*
343  * When a module is loaded and requires storage for a virtualized global
344  * variable, allocate space from the modspace free list.  This interface
345  * should be used only by the kernel linker.
346  */
347 void *
348 vnet_data_alloc(int size)
349 {
350 	struct vnet_data_free *df;
351 	void *s;
352 
353 	s = NULL;
354 	size = roundup2(size, sizeof(void *));
355 	sx_xlock(&vnet_data_free_lock);
356 	TAILQ_FOREACH(df, &vnet_data_free_head, vnd_link) {
357 		if (df->vnd_len < size)
358 			continue;
359 		if (df->vnd_len == size) {
360 			s = (void *)df->vnd_start;
361 			TAILQ_REMOVE(&vnet_data_free_head, df, vnd_link);
362 			free(df, M_VNET_DATA_FREE);
363 			break;
364 		}
365 		s = (void *)df->vnd_start;
366 		df->vnd_len -= size;
367 		df->vnd_start = df->vnd_start + size;
368 		break;
369 	}
370 	sx_xunlock(&vnet_data_free_lock);
371 
372 	return (s);
373 }
374 
375 /*
376  * Free space for a virtualized global variable on module unload.
377  */
378 void
379 vnet_data_free(void *start_arg, int size)
380 {
381 	struct vnet_data_free *df;
382 	struct vnet_data_free *dn;
383 	uintptr_t start;
384 	uintptr_t end;
385 
386 	size = roundup2(size, sizeof(void *));
387 	start = (uintptr_t)start_arg;
388 	end = start + size;
389 	/*
390 	 * Free a region of space and merge it with as many neighbors as
391 	 * possible.  Keeping the list sorted simplifies this operation.
392 	 */
393 	sx_xlock(&vnet_data_free_lock);
394 	TAILQ_FOREACH(df, &vnet_data_free_head, vnd_link) {
395 		if (df->vnd_start > end)
396 			break;
397 		/*
398 		 * If we expand at the end of an entry we may have to merge
399 		 * it with the one following it as well.
400 		 */
401 		if (df->vnd_start + df->vnd_len == start) {
402 			df->vnd_len += size;
403 			dn = TAILQ_NEXT(df, vnd_link);
404 			if (df->vnd_start + df->vnd_len == dn->vnd_start) {
405 				df->vnd_len += dn->vnd_len;
406 				TAILQ_REMOVE(&vnet_data_free_head, dn,
407 				    vnd_link);
408 				free(dn, M_VNET_DATA_FREE);
409 			}
410 			sx_xunlock(&vnet_data_free_lock);
411 			return;
412 		}
413 		if (df->vnd_start == end) {
414 			df->vnd_start = start;
415 			df->vnd_len += size;
416 			sx_xunlock(&vnet_data_free_lock);
417 			return;
418 		}
419 	}
420 	dn = malloc(sizeof(*df), M_VNET_DATA_FREE, M_WAITOK | M_ZERO);
421 	dn->vnd_start = start;
422 	dn->vnd_len = size;
423 	if (df)
424 		TAILQ_INSERT_BEFORE(df, dn, vnd_link);
425 	else
426 		TAILQ_INSERT_TAIL(&vnet_data_free_head, dn, vnd_link);
427 	sx_xunlock(&vnet_data_free_lock);
428 }
429 
430 /*
431  * When a new virtualized global variable has been allocated, propagate its
432  * initial value to each already-allocated virtual network stack instance.
433  */
434 void
435 vnet_data_copy(void *start, int size)
436 {
437 	struct vnet *vnet;
438 
439 	VNET_LIST_RLOCK();
440 	LIST_FOREACH(vnet, &vnet_head, vnet_le)
441 		memcpy((void *)((uintptr_t)vnet->vnet_data_base +
442 		    (uintptr_t)start), start, size);
443 	VNET_LIST_RUNLOCK();
444 }
445 
446 /*
447  * Variants on sysctl_handle_foo that know how to handle virtualized global
448  * variables: if 'arg1' is a pointer, then we transform it to the local vnet
449  * offset.
450  */
451 int
452 vnet_sysctl_handle_int(SYSCTL_HANDLER_ARGS)
453 {
454 
455 	if (arg1 != NULL)
456 		arg1 = (void *)(curvnet->vnet_data_base + (uintptr_t)arg1);
457 	return (sysctl_handle_int(oidp, arg1, arg2, req));
458 }
459 
460 int
461 vnet_sysctl_handle_opaque(SYSCTL_HANDLER_ARGS)
462 {
463 
464 	if (arg1 != NULL)
465 		arg1 = (void *)(curvnet->vnet_data_base + (uintptr_t)arg1);
466 	return (sysctl_handle_opaque(oidp, arg1, arg2, req));
467 }
468 
469 int
470 vnet_sysctl_handle_string(SYSCTL_HANDLER_ARGS)
471 {
472 
473 	if (arg1 != NULL)
474 		arg1 = (void *)(curvnet->vnet_data_base + (uintptr_t)arg1);
475 	return (sysctl_handle_string(oidp, arg1, arg2, req));
476 }
477 
478 int
479 vnet_sysctl_handle_uint(SYSCTL_HANDLER_ARGS)
480 {
481 
482 	if (arg1 != NULL)
483 		arg1 = (void *)(curvnet->vnet_data_base + (uintptr_t)arg1);
484 	return (sysctl_handle_int(oidp, arg1, arg2, req));
485 }
486 
487 /*
488  * Support for special SYSINIT handlers registered via VNET_SYSINIT()
489  * and VNET_SYSUNINIT().
490  */
491 void
492 vnet_register_sysinit(void *arg)
493 {
494 	struct vnet_sysinit *vs, *vs2;
495 	struct vnet *vnet;
496 
497 	vs = arg;
498 	KASSERT(vs->subsystem > SI_SUB_VNET, ("vnet sysinit too early"));
499 
500 	/* Add the constructor to the global list of vnet constructors. */
501 	VNET_SYSINIT_WLOCK();
502 	TAILQ_FOREACH(vs2, &vnet_constructors, link) {
503 		if (vs2->subsystem > vs->subsystem)
504 			break;
505 		if (vs2->subsystem == vs->subsystem && vs2->order > vs->order)
506 			break;
507 	}
508 	if (vs2 != NULL)
509 		TAILQ_INSERT_BEFORE(vs2, vs, link);
510 	else
511 		TAILQ_INSERT_TAIL(&vnet_constructors, vs, link);
512 
513 	/*
514 	 * Invoke the constructor on all the existing vnets when it is
515 	 * registered.
516 	 */
517 	VNET_FOREACH(vnet) {
518 		CURVNET_SET_QUIET(vnet);
519 		vs->func(vs->arg);
520 		CURVNET_RESTORE();
521 	}
522 	VNET_SYSINIT_WUNLOCK();
523 }
524 
525 void
526 vnet_deregister_sysinit(void *arg)
527 {
528 	struct vnet_sysinit *vs;
529 
530 	vs = arg;
531 
532 	/* Remove the constructor from the global list of vnet constructors. */
533 	VNET_SYSINIT_WLOCK();
534 	TAILQ_REMOVE(&vnet_constructors, vs, link);
535 	VNET_SYSINIT_WUNLOCK();
536 }
537 
538 void
539 vnet_register_sysuninit(void *arg)
540 {
541 	struct vnet_sysinit *vs, *vs2;
542 
543 	vs = arg;
544 
545 	/* Add the destructor to the global list of vnet destructors. */
546 	VNET_SYSINIT_WLOCK();
547 	TAILQ_FOREACH(vs2, &vnet_destructors, link) {
548 		if (vs2->subsystem > vs->subsystem)
549 			break;
550 		if (vs2->subsystem == vs->subsystem && vs2->order > vs->order)
551 			break;
552 	}
553 	if (vs2 != NULL)
554 		TAILQ_INSERT_BEFORE(vs2, vs, link);
555 	else
556 		TAILQ_INSERT_TAIL(&vnet_destructors, vs, link);
557 	VNET_SYSINIT_WUNLOCK();
558 }
559 
560 void
561 vnet_deregister_sysuninit(void *arg)
562 {
563 	struct vnet_sysinit *vs;
564 	struct vnet *vnet;
565 
566 	vs = arg;
567 
568 	/*
569 	 * Invoke the destructor on all the existing vnets when it is
570 	 * deregistered.
571 	 */
572 	VNET_SYSINIT_WLOCK();
573 	VNET_FOREACH(vnet) {
574 		CURVNET_SET_QUIET(vnet);
575 		vs->func(vs->arg);
576 		CURVNET_RESTORE();
577 	}
578 
579 	/* Remove the destructor from the global list of vnet destructors. */
580 	TAILQ_REMOVE(&vnet_destructors, vs, link);
581 	VNET_SYSINIT_WUNLOCK();
582 }
583 
584 /*
585  * Invoke all registered vnet constructors on the current vnet.  Used during
586  * vnet construction.  The caller is responsible for ensuring the new vnet is
587  * the current vnet and that the vnet_sysinit_sxlock lock is locked.
588  */
589 void
590 vnet_sysinit(void)
591 {
592 	struct vnet_sysinit *vs;
593 
594 	VNET_SYSINIT_RLOCK();
595 	TAILQ_FOREACH(vs, &vnet_constructors, link) {
596 		vs->func(vs->arg);
597 	}
598 	VNET_SYSINIT_RUNLOCK();
599 }
600 
601 /*
602  * Invoke all registered vnet destructors on the current vnet.  Used during
603  * vnet destruction.  The caller is responsible for ensuring the dying vnet
604  * the current vnet and that the vnet_sysinit_sxlock lock is locked.
605  */
606 void
607 vnet_sysuninit(void)
608 {
609 	struct vnet_sysinit *vs;
610 
611 	VNET_SYSINIT_RLOCK();
612 	TAILQ_FOREACH_REVERSE(vs, &vnet_destructors, vnet_sysuninit_head,
613 	    link) {
614 		vs->func(vs->arg);
615 	}
616 	VNET_SYSINIT_RUNLOCK();
617 }
618 
619 #ifdef DDB
620 DB_SHOW_COMMAND(vnets, db_show_vnets)
621 {
622 	VNET_ITERATOR_DECL(vnet_iter);
623 
624 	VNET_FOREACH(vnet_iter) {
625 		db_printf("vnet            = %p\n", vnet_iter);
626 		db_printf(" vnet_magic_n   = 0x%x (%s, orig 0x%x)\n",
627 		    vnet_iter->vnet_magic_n,
628 		    (vnet_iter->vnet_magic_n == VNET_MAGIC_N) ?
629 			"ok" : "mismatch", VNET_MAGIC_N);
630 		db_printf(" vnet_ifcnt     = %u\n", vnet_iter->vnet_ifcnt);
631 		db_printf(" vnet_sockcnt   = %u\n", vnet_iter->vnet_sockcnt);
632 		db_printf(" vnet_data_mem  = %p\n", vnet_iter->vnet_data_mem);
633 		db_printf(" vnet_data_base = 0x%jx\n",
634 		    (uintmax_t)vnet_iter->vnet_data_base);
635 		db_printf("\n");
636 		if (db_pager_quit)
637 			break;
638 	}
639 }
640 #endif
641