xref: /onnv-gate/usr/src/uts/common/sys/hook_impl.h (revision 2958:98aa41c076f5)
1*2958Sdr146992 /*
2*2958Sdr146992  * CDDL HEADER START
3*2958Sdr146992  *
4*2958Sdr146992  * The contents of this file are subject to the terms of the
5*2958Sdr146992  * Common Development and Distribution License (the "License").
6*2958Sdr146992  * You may not use this file except in compliance with the License.
7*2958Sdr146992  *
8*2958Sdr146992  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*2958Sdr146992  * or http://www.opensolaris.org/os/licensing.
10*2958Sdr146992  * See the License for the specific language governing permissions
11*2958Sdr146992  * and limitations under the License.
12*2958Sdr146992  *
13*2958Sdr146992  * When distributing Covered Code, include this CDDL HEADER in each
14*2958Sdr146992  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*2958Sdr146992  * If applicable, add the following below this CDDL HEADER, with the
16*2958Sdr146992  * fields enclosed by brackets "[]" replaced with your own identifying
17*2958Sdr146992  * information: Portions Copyright [yyyy] [name of copyright owner]
18*2958Sdr146992  *
19*2958Sdr146992  * CDDL HEADER END
20*2958Sdr146992  */
21*2958Sdr146992 /*
22*2958Sdr146992  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23*2958Sdr146992  * Use is subject to license terms.
24*2958Sdr146992  */
25*2958Sdr146992 
26*2958Sdr146992 /*
27*2958Sdr146992  * This file include internal used definition and data structure of hooks
28*2958Sdr146992  */
29*2958Sdr146992 
30*2958Sdr146992 #ifndef _SYS_HOOK_IMPL_H
31*2958Sdr146992 #define	_SYS_HOOK_IMPL_H
32*2958Sdr146992 
33*2958Sdr146992 #pragma ident	"%Z%%M%	%I%	%E% SMI"
34*2958Sdr146992 
35*2958Sdr146992 #include <sys/hook.h>
36*2958Sdr146992 #include <sys/condvar_impl.h>
37*2958Sdr146992 
38*2958Sdr146992 #ifdef	__cplusplus
39*2958Sdr146992 extern "C" {
40*2958Sdr146992 #endif
41*2958Sdr146992 
42*2958Sdr146992 /*
43*2958Sdr146992  * The following diagram describes the linking together of data structures
44*2958Sdr146992  * used in this implementation of callback hooks.  The start of it all is
45*2958Sdr146992  * the "familylist" variable in hook.c.  The relationships between data
46*2958Sdr146992  * structures is:
47*2958Sdr146992  * - there is a list of hook families;
48*2958Sdr146992  * - each hook family can have a list of hook events;
49*2958Sdr146992  * - each hook_event_t must be uniquely associated with one family and event;
50*2958Sdr146992  * - each hook event can have a list of registered hooks to call.
51*2958Sdr146992  *
52*2958Sdr146992  *   familylist                    +--------------+
53*2958Sdr146992  *       |                         | hook_event_t |<--\
54*2958Sdr146992  *       |                         +--------------+   |
55*2958Sdr146992  *       V                                            |
56*2958Sdr146992  * +-------------------+       ->+------------------+ |     ->+--------------+
57*2958Sdr146992  * | hook_family_int_t |      /  | hook_event_int_t | |    /  | hook_int_t   |
58*2958Sdr146992  * | +---------------+ |     /   |                  | /   /   | +----------+ |
59*2958Sdr146992  * | | hook_family_t | |    /    | hei_event---------/   /    | | hook_t   | |
60*2958Sdr146992  * | +---------------+ |   /     |                  |   /     | +----------+ |
61*2958Sdr146992  * |                   |  /      |                  |  /      |              |
62*2958Sdr146992  * | hfi_head------------/       | hei_head-----------/       | hi_entry--\  |
63*2958Sdr146992  * | hfi_entry--\      |         | hei_entry--\     |         +-----------|--+
64*2958Sdr146992  * +------------|------+         +------------|-----+                     |
65*2958Sdr146992  *              |                             |                           |
66*2958Sdr146992  *              V                             V                           V
67*2958Sdr146992  * +-------------------+         +------------------+         +--------------+
68*2958Sdr146992  * | hook_family_int_t |         | hook_event_int_t |         | hook_int_t   |
69*2958Sdr146992  * ...
70*2958Sdr146992  */
71*2958Sdr146992 
72*2958Sdr146992 /*
73*2958Sdr146992  * hook_int: internal storage of hook
74*2958Sdr146992  */
75*2958Sdr146992 typedef struct hook_int {
76*2958Sdr146992 	TAILQ_ENTRY(hook_int)	hi_entry;
77*2958Sdr146992 	hook_t			hi_hook;
78*2958Sdr146992 } hook_int_t;
79*2958Sdr146992 
80*2958Sdr146992 /*
81*2958Sdr146992  * Hook_int_head: tail queue of hook_int
82*2958Sdr146992  */
83*2958Sdr146992 TAILQ_HEAD(hook_int_head, hook_int);
84*2958Sdr146992 typedef struct hook_int_head hook_int_head_t;
85*2958Sdr146992 
86*2958Sdr146992 /*
87*2958Sdr146992  * hook_event_int: internal storage of hook_event
88*2958Sdr146992  */
89*2958Sdr146992 typedef struct hook_event_int {
90*2958Sdr146992 	cvwaitlock_t			hei_lock;
91*2958Sdr146992 	SLIST_ENTRY(hook_event_int)	hei_entry;
92*2958Sdr146992 	hook_event_t			*hei_event;
93*2958Sdr146992 	hook_int_head_t			hei_head;
94*2958Sdr146992 } hook_event_int_t;
95*2958Sdr146992 
96*2958Sdr146992 /*
97*2958Sdr146992  * hook_event_int_head: singly-linked list of hook_event_int
98*2958Sdr146992  */
99*2958Sdr146992 SLIST_HEAD(hook_event_int_head, hook_event_int);
100*2958Sdr146992 typedef struct hook_event_int_head hook_event_int_head_t;
101*2958Sdr146992 
102*2958Sdr146992 /*
103*2958Sdr146992  * hook_family_int: internal storage of hook_family
104*2958Sdr146992  */
105*2958Sdr146992 typedef struct hook_family_int {
106*2958Sdr146992 	SLIST_ENTRY(hook_family_int)	hfi_entry;
107*2958Sdr146992 	hook_event_int_head_t		hfi_head;
108*2958Sdr146992 	hook_family_t 			hfi_family;
109*2958Sdr146992 } hook_family_int_t;
110*2958Sdr146992 
111*2958Sdr146992 /*
112*2958Sdr146992  * hook_family_int_head: singly-linked list of hook_family
113*2958Sdr146992  */
114*2958Sdr146992 SLIST_HEAD(hook_family_int_head, hook_family_int);
115*2958Sdr146992 typedef struct hook_family_int_head hook_family_int_head_t;
116*2958Sdr146992 
117*2958Sdr146992 /*
118*2958Sdr146992  * Names of hooks families currently defined by Solaris
119*2958Sdr146992  */
120*2958Sdr146992 #define	Hn_ARP	"arp"
121*2958Sdr146992 #define	Hn_IPV4	"inet"
122*2958Sdr146992 #define	Hn_IPV6	"inet6"
123*2958Sdr146992 
124*2958Sdr146992 extern hook_family_int_t *hook_family_add(hook_family_t *);
125*2958Sdr146992 extern int hook_family_remove(hook_family_int_t *);
126*2958Sdr146992 extern hook_event_int_t *hook_event_add(hook_family_int_t *, hook_event_t *);
127*2958Sdr146992 extern int hook_event_remove(hook_family_int_t *, hook_event_t *);
128*2958Sdr146992 extern int hook_register(hook_family_int_t *, char *, hook_t *);
129*2958Sdr146992 extern int hook_unregister(hook_family_int_t *, char *, hook_t *);
130*2958Sdr146992 extern int hook_run(hook_event_token_t, hook_data_t);
131*2958Sdr146992 
132*2958Sdr146992 #ifdef	__cplusplus
133*2958Sdr146992 }
134*2958Sdr146992 #endif
135*2958Sdr146992 
136*2958Sdr146992 #endif /* _SYS_HOOK_IMPL_H */
137