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