summaryrefslogtreecommitdiff
path: root/sys/net/vnet.h
diff options
context:
space:
mode:
Diffstat (limited to 'sys/net/vnet.h')
-rw-r--r--sys/net/vnet.h161
1 files changed, 113 insertions, 48 deletions
diff --git a/sys/net/vnet.h b/sys/net/vnet.h
index b5d2fbdc4f3b..4b543e6317d3 100644
--- a/sys/net/vnet.h
+++ b/sys/net/vnet.h
@@ -1,10 +1,6 @@
/*-
- * Copyright (c) 2006-2008 University of Zagreb
- * Copyright (c) 2006-2008 FreeBSD Foundation
- *
- * This software was developed by the University of Zagreb and the
- * FreeBSD Foundation under sponsorship by the Stichting NLnet and the
- * FreeBSD Foundation.
+ * Copyright (c) 2009 Jeffrey Roberson <jeff@freebsd.org>
+ * Copyright (c) 2009 Robert N. M. Watson
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -30,62 +26,131 @@
* $FreeBSD$
*/
+/*
+ * This is the virtual network stack memory allocator, which provides support
+ * for virtualized global variables via a special linker set, set_vnet. When
+ * "options VIMAGE" isn't defined, virtualized global variables are compiled
+ * as normal globals.
+ */
+
#ifndef _NET_VNET_H_
#define _NET_VNET_H_
-#include <net/if_var.h>
+#ifdef _KERNEL
+#ifdef VIMAGE
+
+#if defined(__arm__)
+__asm__(".section set_vnet, \"aw\", %progbits");
+#else
+__asm__(".section set_vnet, \"aw\", @progbits");
+#endif
+__asm__(".previous");
+
+#define VNET_NAME(n) vnet_entry_##n
+#define VNET_DECLARE(t, n) extern t VNET_NAME(n)
+#define VNET_DEFINE(t, n) t VNET_NAME(n) __section("set_vnet") __used
+#define _VNET_PTR(b, n) (__typeof(VNET_NAME(n))*) \
+ ((b) + (uintptr_t)&VNET_NAME(n))
+
+#define _VNET_GET(b, n) (*_VNET_PTR(b, n))
+#define _VNET_SET(b, n, v) (*_VNET_PTR(b, n) = v)
-struct ifindex_entry;
+/*
+ * Virtualized global variable accessor macros.
+ */
+#define VNET_VNET_PTR(vnet, n) _VNET_PTR((vnet)->vnet_data_base, n)
+#define VNET_VNET_GET(vnet, n) (*VNET_VNET_PTR((vnet), n))
+#define VNET_VNET_SET(vnet, n, v) ((*VNET_VNET_PTR((vnet), n)) = v)
-struct vnet_net {
- int _if_index;
- struct ifindex_entry * _ifindex_table;
- struct ifnethead _ifnet;
- struct ifgrouphead _ifg_head;
+#define VNET_PTR(n) VNET_VNET_PTR(curvnet, n)
+#define VNET_GET(n) VNET_VNET_GET(curvnet, n)
+#define VNET_SET(n, v) VNET_VNET_SET(curvnet, n, v)
- int _if_indexlim;
+/*
+ * Sysctl variants for vnet-virtualized global variables. Include
+ * <sys/sysctl.h> to expose these definitions.
+ *
+ * Note: SYSCTL_PROC() handler functions will need to resolve pointer
+ * arguments themselves, if required.
+ */
+#ifdef SYSCTL_OID
+int vnet_sysctl_handle_int(SYSCTL_HANDLER_ARGS);
+int vnet_sysctl_handle_opaque(SYSCTL_HANDLER_ARGS);
+int vnet_sysctl_handle_string(SYSCTL_HANDLER_ARGS);
+int vnet_sysctl_handle_uint(SYSCTL_HANDLER_ARGS);
- struct ifnet * _loif;
- struct if_clone * _lo_cloner;
- struct ifc_simple_data *_lo_cloner_data;
+#define SYSCTL_VNET_INT(parent, nbr, name, access, ptr, val, descr) \
+ SYSCTL_OID(parent, nbr, name, CTLTYPE_INT|CTLFLAG_MPSAFE|(access), \
+ ptr, val, vnet_sysctl_handle_int, "I", descr)
+#define SYSCTL_VNET_PROC(parent, nbr, name, access, ptr, arg, handler, \
+ fmt, descr) \
+ SYSCTL_OID(parent, nbr, name, access, ptr, arg, handler, fmt, \
+ descr)
+#define SYSCTL_VNET_STRING(parent, nbr, name, access, arg, len, descr) \
+ SYSCTL_OID(parent, nbr, name, CTLTYPE_STRING|(access), arg, \
+ len, vnet_sysctl_handle_string, "A", descr)
+#define SYSCTL_VNET_STRUCT(parent, nbr, name, access, ptr, type, descr) \
+ SYSCTL_OID(parent, nbr, name, CTLTYPE_OPAQUE|(access), ptr, \
+ sizeof(struct type), vnet_sysctl_handle_opaque, "S," #type, \
+ descr)
+#define SYSCTL_VNET_UINT(parent, nbr, name, access, ptr, val, descr) \
+ SYSCTL_OID(parent, nbr, name, CTLTYPE_UINT|CTLFLAG_MPSAFE|(access), \
+ ptr, val, vnet_sysctl_handle_uint, "IU", descr)
+#endif /* SYSCTL_OID */
- LIST_HEAD(, rawcb) _rawcb_list;
+/*
+ * Interfaces from the kernel linker.
+ */
+void *vnet_data_alloc(int size);
+void vnet_data_copy(void *start, int size);
+void vnet_data_free(void *start_arg, int size);
- LIST_HEAD(, if_clone) _if_cloners;
- int _if_cloners_count;
+/*
+ * Interfaces for vnet setup/teardown.
+ */
+struct vnet;
+void vnet_data_init(struct vnet *vnet);
+void vnet_data_destroy(struct vnet *vnet);
- int _ether_ipfw;
-};
+#else /* !VIMAGE */
-/* Size guard. See sys/vimage.h. */
-VIMAGE_CTASSERT(SIZEOF_vnet_net, sizeof(struct vnet_net));
+/*
+ * Versions of the VNET macros that compile to normal global variables and
+ * standard sysctl definitions.
+ */
+#define VNET_NAME(n) n
+#define VNET_DECLARE(t, n) extern t n
+#define VNET_DEFINE(t, n) t n
+#define _VNET_PTR(b, n) &VNET_NAME(n)
-#ifndef VIMAGE
-#ifndef VIMAGE_GLOBALS
-extern struct vnet_net vnet_net_0;
-#endif
-#endif
+#ifdef SYSCTL_OID
+#define SYSCTL_VNET_INT(parent, nbr, name, access, ptr, val, descr) \
+ SYSCTL_INT(parent, nbr, name, access, ptr, val, descr)
+#define SYSCTL_VNET_PROC(parent, nbr, name, access, ptr, arg, handler, \
+ fmt, descr) \
+ SYSCTL_PROC(parent, nbr, name, access, ptr, arg, handler, fmt, \
+ descr)
+#define SYSCTL_VNET_STRING(parent, nbr, name, access, arg, len, descr) \
+ SYSCTL_STRING(parent, nbr, name, access, arg, len, descr)
+#define SYSCTL_VNET_STRUCT(parent, nbr, name, access, ptr, type, descr) \
+ SYSCTL_STRUCT(parent, nbr, name, access, ptr, type, descr)
+#define SYSCTL_VNET_UINT(parent, nbr, name, access, ptr, val, descr) \
+ SYSCTL_UINT(parent, nbr, name, access, ptr, val, descr)
+#endif /* SYSCTL_OID */
/*
- * Symbol translation macros
+ * Virtualized global variable accessor macros.
*/
-#define INIT_VNET_NET(vnet) \
- INIT_FROM_VNET(vnet, VNET_MOD_NET, struct vnet_net, vnet_net)
-
-#define VNET_NET(sym) VSYM(vnet_net, sym)
-
-#define V_ether_ipfw VNET_NET(ether_ipfw)
-#define V_if_index VNET_NET(if_index)
-#define V_if_indexlim VNET_NET(if_indexlim)
-#define V_if_cloners VNET_NET(if_cloners)
-#define V_if_cloners_count VNET_NET(if_cloners_count)
-#define V_ifg_head VNET_NET(ifg_head)
-#define V_ifindex_table VNET_NET(ifindex_table)
-#define V_ifklist VNET_NET(ifklist)
-#define V_ifnet VNET_NET(ifnet)
-#define V_lo_cloner VNET_NET(lo_cloner)
-#define V_lo_cloner_data VNET_NET(lo_cloner_data)
-#define V_loif VNET_NET(loif)
-#define V_rawcb_list VNET_NET(rawcb_list)
+#define VNET_VNET_PTR(vnet, n) (&(n))
+#define VNET_VNET_GET(vnet, n) (n)
+#define VNET_VNET_SET(vnet, n, v) ((n) = (v))
+
+#define VNET_PTR(n) (&(n))
+#define VNET_GET(n) (n)
+#define VNET_SET(n, v) ((n) = (v))
+
+#endif /* VIMAGE */
+
+#endif /* _KERNEL */
#endif /* !_NET_VNET_H_ */