summaryrefslogtreecommitdiffstats
path: root/sys/net
diff options
context:
space:
mode:
authorbz <bz@FreeBSD.org>2010-03-19 19:51:03 +0000
committerbz <bz@FreeBSD.org>2010-03-19 19:51:03 +0000
commit102a1f8933fc21bc4d59fefc7cf937a79852efd3 (patch)
treef7449f42c29dbbbb2dfc5e32c28e23f633214e78 /sys/net
parent1d097a47c39ac0c2575579a65e78796174fba8d3 (diff)
downloadFreeBSD-src-102a1f8933fc21bc4d59fefc7cf937a79852efd3.zip
FreeBSD-src-102a1f8933fc21bc4d59fefc7cf937a79852efd3.tar.gz
Split eventhandler_register() into an internal part and a wrapper function
that provides the allocated and setup eventhandler entry. Add a new wrapper for VIMAGE that allocates extra space to hold the callback function and argument in addition to an extra wrapper function. While the wrapper function goes as normal callback function the argument points to the extra space allocated holding the original func and arg that the wrapper function can then call. Provide an iterator function for the virtual network stack (vnet) that will call the callback function for each network stack. Provide a new set of macros for VNET that in the non-VIMAGE case will just call eventhandler_register() while in the VIMAGE case it will use vimage_eventhandler_register() passing in the extra iterator function but will only register once rather than per-vnet. We need a special macro in case we are interested in the tag returned as we must check for curvnet and can neither simply assign the return value, nor not change it in the non-vnet0 case without that. Sponsored by: ISPsystem Discussed with: jhb Reviewed by: zec (earlier version), jhb MFC after: 1 month
Diffstat (limited to 'sys/net')
-rw-r--r--sys/net/vnet.c39
-rw-r--r--sys/net/vnet.h30
2 files changed, 69 insertions, 0 deletions
diff --git a/sys/net/vnet.c b/sys/net/vnet.c
index 323ed08..1dac03a 100644
--- a/sys/net/vnet.c
+++ b/sys/net/vnet.c
@@ -47,6 +47,7 @@ __FBSDID("$FreeBSD$");
#include <sys/sdt.h>
#include <sys/systm.h>
#include <sys/sysctl.h>
+#include <sys/eventhandler.h>
#include <sys/linker_set.h>
#include <sys/lock.h>
#include <sys/malloc.h>
@@ -55,6 +56,8 @@ __FBSDID("$FreeBSD$");
#include <sys/sx.h>
#include <sys/sysctl.h>
+#include <machine/stdarg.h>
+
#ifdef DDB
#include <ddb/ddb.h>
#include <ddb/db_sym.h>
@@ -637,6 +640,39 @@ vnet_sysuninit(void)
VNET_SYSINIT_RUNLOCK();
}
+/*
+ * EVENTHANDLER(9) extensions.
+ */
+/*
+ * Invoke the eventhandler function originally registered with the possibly
+ * registered argument for all virtual network stack instances.
+ *
+ * This iterator can only be used for eventhandlers that do not take any
+ * additional arguments, as we do ignore the variadic arguments from the
+ * EVENTHANDLER_INVOKE() call.
+ */
+void
+vnet_global_eventhandler_iterator_func(void *arg, ...)
+{
+ VNET_ITERATOR_DECL(vnet_iter);
+ struct eventhandler_entry_vimage *v_ee;
+
+ /*
+ * There is a bug here in that we should actually cast things to
+ * (struct eventhandler_entry_ ## name *) but that's not easily
+ * possible in here so just re-using the variadic version we
+ * defined for the generic vimage case.
+ */
+ v_ee = arg;
+ VNET_LIST_RLOCK();
+ VNET_FOREACH(vnet_iter) {
+ CURVNET_SET(vnet_iter);
+ ((vimage_iterator_func_t)v_ee->func)(v_ee->ee_arg);
+ CURVNET_RESTORE();
+ }
+ VNET_LIST_RUNLOCK();
+}
+
#ifdef VNET_DEBUG
struct vnet_recursion {
SLIST_ENTRY(vnet_recursion) vnr_le;
@@ -696,6 +732,9 @@ vnet_log_recursion(struct vnet *old_vnet, const char *old_fn, int line)
}
#endif /* VNET_DEBUG */
+/*
+ * DDB(4).
+ */
#ifdef DDB
DB_SHOW_COMMAND(vnets, db_show_vnets)
{
diff --git a/sys/net/vnet.h b/sys/net/vnet.h
index d9a1ee0..fb2cc39 100644
--- a/sys/net/vnet.h
+++ b/sys/net/vnet.h
@@ -313,6 +313,29 @@ void vnet_register_sysuninit(void *arg);
void vnet_deregister_sysinit(void *arg);
void vnet_deregister_sysuninit(void *arg);
+/*
+ * EVENTHANDLER(9) extensions.
+ */
+#include <sys/eventhandler.h>
+
+void vnet_global_eventhandler_iterator_func(void *, ...);
+#define VNET_GLOBAL_EVENTHANDLER_REGISTER_TAG(tag, name, func, arg, priority) \
+do { \
+ if (IS_DEFAULT_VNET(curvnet)) { \
+ (tag) = vimage_eventhandler_register(NULL, #name, func, \
+ arg, priority, \
+ vnet_global_eventhandler_iterator_func); \
+ } \
+} while(0)
+#define VNET_GLOBAL_EVENTHANDLER_REGISTER(name, func, arg, priority) \
+do { \
+ if (IS_DEFAULT_VNET(curvnet)) { \
+ vimage_eventhandler_register(NULL, #name, func, \
+ arg, priority, \
+ vnet_global_eventhandler_iterator_func); \
+ } \
+} while(0)
+
#else /* !VIMAGE */
/*
@@ -384,6 +407,13 @@ void vnet_deregister_sysuninit(void *arg);
#define VNET_SYSUNINIT(ident, subsystem, order, func, arg) \
SYSUNINIT(ident, subsystem, order, func, arg)
+/*
+ * Without VIMAGE revert to the default implementation.
+ */
+#define VNET_GLOBAL_EVENTHANDLER_REGISTER_TAG(tag, name, func, arg, priority) \
+ (tag) = eventhandler_register(NULL, #name, func, arg, priority)
+#define VNET_GLOBAL_EVENTHANDLER_REGISTER(name, func, arg, priority) \
+ eventhandler_register(NULL, #name, func, arg, priority)
#endif /* VIMAGE */
#endif /* _KERNEL */
OpenPOWER on IntegriCloud