summaryrefslogtreecommitdiff
path: root/usr/src/uts/common/sys/hook_impl.h
diff options
context:
space:
mode:
authorDarren Reed <Darren.Reed@Sun.COM>2008-09-08 14:46:50 -0700
committerDarren Reed <Darren.Reed@Sun.COM>2008-09-08 14:46:50 -0700
commit7ddc9b1afd18f260b9fb78ec7732facd91769131 (patch)
tree1a305ae7471e9362c1ba0ea3d32834448059eb00 /usr/src/uts/common/sys/hook_impl.h
parent7739299d04f7910358ca2ad79106f174022a9ab2 (diff)
downloadillumos-gate-7ddc9b1afd18f260b9fb78ec7732facd91769131.tar.gz
PSARC/2008/219 Committed API for packet interception
PSARC/2008/335 Corrections for Committed API for packet interception PSARC/2008/557 Revision to net instance notification API 4844507 Solaris needs stable interface for packet filtering software 6705155 ipf_stack_init() assumes kmem_alloc with KM_NOSLEEP never fails
Diffstat (limited to 'usr/src/uts/common/sys/hook_impl.h')
-rw-r--r--usr/src/uts/common/sys/hook_impl.h135
1 files changed, 111 insertions, 24 deletions
diff --git a/usr/src/uts/common/sys/hook_impl.h b/usr/src/uts/common/sys/hook_impl.h
index 08112e4144..2357a2d287 100644
--- a/usr/src/uts/common/sys/hook_impl.h
+++ b/usr/src/uts/common/sys/hook_impl.h
@@ -19,7 +19,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -30,8 +30,6 @@
#ifndef _SYS_HOOK_IMPL_H
#define _SYS_HOOK_IMPL_H
-#pragma ident "%Z%%M% %I% %E% SMI"
-
#include <sys/hook.h>
#include <sys/condvar_impl.h>
#include <sys/netstack.h>
@@ -40,6 +38,31 @@
extern "C" {
#endif
+typedef enum fwflag_e {
+ FWF_NONE = 0x00,
+ FWF_DESTROY_ACTIVE = 0x01,
+ FWF_ADD_ACTIVE = 0x04,
+ FWF_DEL_ACTIVE = 0x08,
+ FWF_DESTROY_WANTED = 0x10,
+ FWF_ADD_WANTED = 0x40,
+ FWF_DEL_WANTED = 0x80,
+ FWF_NOT_READY = 0x100
+} fwflag_t;
+
+#define FWF_WAIT_MASK (FWF_ADD_ACTIVE|FWF_DEL_ACTIVE|\
+ FWF_ADD_WANTED|FWF_DEL_WANTED)
+#define FWF_UNSAFE (FWF_DESTROY_ACTIVE|FWF_NOT_READY)
+#define FWF_DESTROY (FWF_DESTROY_ACTIVE|FWF_DESTROY_WANTED)
+#define FWF_DESTROY_OK(x) ((x)->fw_flags == FWF_DESTROY_WANTED)
+
+typedef struct flagwait_s {
+ kcondvar_t fw_cv;
+ kmutex_t fw_lock;
+ uint32_t fw_flags;
+ cvwaitlock_t *fw_owner;
+} flagwait_t;
+
+
/*
* The following diagram describes the linking together of data structures
* used in this implementation of callback hooks. The start of it all is
@@ -58,32 +81,66 @@ extern "C" {
* | hook_family_int_t | / | hook_event_int_t | | / | hook_int_t |
* | +---------------+ | / | | / / | +----------+ |
* | | hook_family_t | | / | hei_event---------/ / | | hook_t | |
- * | +---------------+ | / | | / | +----------+ |
- * | | / | | / | |
- * | hfi_head------------/ | hei_head-----------/ | hi_entry--\ |
- * | hfi_entry--\ | | hei_entry--\ | +-----------|--+
- * +------------|------+ +------------|-----+ |
- * | | |
- * V V V
- * +-------------------+ +------------------+ +--------------+
- * | hook_family_int_t | | hook_event_int_t | | hook_int_t |
+ * | +---------------+ | / | hei_nhead----------\ / | +----------+ |
+ * | | / | | X | |
+ * | hfi_head------------/ | hei_head-----------/ \ | hi_entry--\ |
+ * | hfi_entry--\ | | hei_entry--\ | | +-----------|--+
+ * +------------|------+ +------------|-----+ | |
+ * | | | |
+ * V V | V
+ * +-------------------+ +------------------+ | +--------------+
+ * | hook_family_int_t | | hook_event_int_t | | | hook_int_t |
+ * V
+ * +--------------+
+ * |
* ...
*/
+typedef struct hook_hook_kstat {
+ kstat_named_t hook_version;
+ kstat_named_t hook_flags;
+ kstat_named_t hook_hint;
+ kstat_named_t hook_hintvalue;
+ kstat_named_t hook_position;
+ kstat_named_t hook_hits;
+} hook_hook_kstat_t;
+
/*
* hook_int: internal storage of hook
*/
typedef struct hook_int {
- TAILQ_ENTRY(hook_int) hi_entry;
- hook_t hi_hook;
+ TAILQ_ENTRY(hook_int) hi_entry;
+ hook_t hi_hook;
+ hook_hook_kstat_t hi_kstats;
+ kstat_t *hi_kstatp;
+ char *hi_ksname;
+ cvwaitlock_t hi_notify_lock;
} hook_int_t;
/*
- * Hook_int_head: tail queue of hook_int
+ * hook_int_head: tail queue of hook_int
*/
TAILQ_HEAD(hook_int_head, hook_int);
typedef struct hook_int_head hook_int_head_t;
+
+typedef struct hook_notify {
+ TAILQ_ENTRY(hook_notify) hn_entry;
+ hook_notify_fn_t hn_func;
+ void *hn_arg;
+ uint32_t hn_flags;
+} hook_notify_t;
+
+TAILQ_HEAD(hook_notify_head, hook_notify);
+typedef struct hook_notify_head hook_notify_head_t;
+
+
+typedef struct hook_event_kstat {
+ kstat_named_t hooks_added;
+ kstat_named_t hooks_removed;
+ kstat_named_t events;
+} hook_event_kstat_t;
+
/*
* hook_event_int: internal storage of hook_event
*/
@@ -92,6 +149,11 @@ typedef struct hook_event_int {
SLIST_ENTRY(hook_event_int) hei_entry;
hook_event_t *hei_event;
hook_int_head_t hei_head;
+ kstat_t *hei_kstatp;
+ hook_event_kstat_t hei_kstats;
+ hook_notify_head_t hei_nhead;
+ flagwait_t hei_waiter;
+ boolean_t hei_condemned;
} hook_event_int_t;
/*
@@ -104,10 +166,15 @@ typedef struct hook_event_int_head hook_event_int_head_t;
* hook_family_int: internal storage of hook_family
*/
typedef struct hook_family_int {
+ cvwaitlock_t hfi_lock;
SLIST_ENTRY(hook_family_int) hfi_entry;
hook_event_int_head_t hfi_head;
hook_family_t hfi_family;
- void *hfi_ptr;
+ kstat_t *hfi_kstat;
+ struct hook_stack *hfi_stack;
+ hook_notify_head_t hfi_nhead;
+ flagwait_t hfi_waiter;
+ boolean_t hfi_condemned;
} hook_family_int_t;
/*
@@ -120,11 +187,18 @@ typedef struct hook_family_int_head hook_family_int_head_t;
* hook stack instances
*/
struct hook_stack {
- cvwaitlock_t hks_familylock; /* global lock */
- hook_family_int_head_t hks_familylist; /* family list head */
- netstack_t *hk_netstack;
+ cvwaitlock_t hks_lock;
+ SLIST_ENTRY(hook_stack) hks_entry;
+ hook_family_int_head_t hks_familylist; /* family list head */
+ netstack_t *hks_netstack;
+ netstackid_t hks_netstackid;
+ hook_notify_head_t hks_nhead;
+ int hks_shutdown;
+ flagwait_t hks_waiter;
};
typedef struct hook_stack hook_stack_t;
+SLIST_HEAD(hook_stack_head, hook_stack);
+typedef struct hook_stack_head hook_stack_head_t;
/*
* Names of hooks families currently defined by Solaris
@@ -133,13 +207,26 @@ typedef struct hook_stack hook_stack_t;
#define Hn_IPV4 "inet"
#define Hn_IPV6 "inet6"
-extern hook_family_int_t *hook_family_add(hook_family_t *, hook_stack_t *);
-extern int hook_family_remove(hook_family_int_t *);
-extern hook_event_int_t *hook_event_add(hook_family_int_t *, hook_event_t *);
-extern int hook_event_remove(hook_family_int_t *, hook_event_t *);
+extern int hook_run(hook_family_int_t *, hook_event_token_t, hook_data_t);
extern int hook_register(hook_family_int_t *, char *, hook_t *);
+
extern int hook_unregister(hook_family_int_t *, char *, hook_t *);
-extern int hook_run(hook_event_token_t, hook_data_t, netstack_t *);
+extern hook_event_int_t *hook_event_add(hook_family_int_t *, hook_event_t *);
+extern int hook_event_notify_register(hook_family_int_t *, char *,
+ hook_notify_fn_t, void *);
+extern int hook_event_notify_unregister(hook_family_int_t *, char *,
+ hook_notify_fn_t);
+extern int hook_event_remove(hook_family_int_t *, hook_event_t *);
+
+extern hook_family_int_t *hook_family_add(hook_family_t *, hook_stack_t *);
+extern int hook_family_notify_register(hook_family_int_t *, hook_notify_fn_t,
+ void *);
+extern int hook_family_notify_unregister(hook_family_int_t *, hook_notify_fn_t);
+extern int hook_family_remove(hook_family_int_t *);
+
+extern int hook_stack_notify_register(netstackid_t, hook_notify_fn_t, void *);
+extern int hook_stack_notify_unregister(netstackid_t, hook_notify_fn_t);
+
#ifdef __cplusplus
}