xref: /titanic_44/usr/src/uts/common/sys/hook_impl.h (revision 62a1b812a0c45c0d4c10ef645dda42bf71080108)
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 2007 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 #include <sys/netstack.h>
38 
39 #ifdef	__cplusplus
40 extern "C" {
41 #endif
42 
43 /*
44  * The following diagram describes the linking together of data structures
45  * used in this implementation of callback hooks.  The start of it all is
46  * the "familylist" variable in hook.c.  The relationships between data
47  * structures is:
48  * - there is a list of hook families;
49  * - each hook family can have a list of hook events;
50  * - each hook_event_t must be uniquely associated with one family and event;
51  * - each hook event can have a list of registered hooks to call.
52  *
53  *   familylist                    +--------------+
54  *       |                         | hook_event_t |<--\
55  *       |                         +--------------+   |
56  *       V                                            |
57  * +-------------------+       ->+------------------+ |     ->+--------------+
58  * | hook_family_int_t |      /  | hook_event_int_t | |    /  | hook_int_t   |
59  * | +---------------+ |     /   |                  | /   /   | +----------+ |
60  * | | hook_family_t | |    /    | hei_event---------/   /    | | hook_t   | |
61  * | +---------------+ |   /     |                  |   /     | +----------+ |
62  * |                   |  /      |                  |  /      |              |
63  * | hfi_head------------/       | hei_head-----------/       | hi_entry--\  |
64  * | hfi_entry--\      |         | hei_entry--\     |         +-----------|--+
65  * +------------|------+         +------------|-----+                     |
66  *              |                             |                           |
67  *              V                             V                           V
68  * +-------------------+         +------------------+         +--------------+
69  * | hook_family_int_t |         | hook_event_int_t |         | hook_int_t   |
70  * ...
71  */
72 
73 /*
74  * hook_int: internal storage of hook
75  */
76 typedef struct hook_int {
77 	TAILQ_ENTRY(hook_int)	hi_entry;
78 	hook_t			hi_hook;
79 } hook_int_t;
80 
81 /*
82  * Hook_int_head: tail queue of hook_int
83  */
84 TAILQ_HEAD(hook_int_head, hook_int);
85 typedef struct hook_int_head hook_int_head_t;
86 
87 /*
88  * hook_event_int: internal storage of hook_event
89  */
90 typedef struct hook_event_int {
91 	cvwaitlock_t			hei_lock;
92 	SLIST_ENTRY(hook_event_int)	hei_entry;
93 	hook_event_t			*hei_event;
94 	hook_int_head_t			hei_head;
95 } hook_event_int_t;
96 
97 /*
98  * hook_event_int_head: singly-linked list of hook_event_int
99  */
100 SLIST_HEAD(hook_event_int_head, hook_event_int);
101 typedef struct hook_event_int_head hook_event_int_head_t;
102 
103 /*
104  * hook_family_int: internal storage of hook_family
105  */
106 typedef struct hook_family_int {
107 	SLIST_ENTRY(hook_family_int)	hfi_entry;
108 	hook_event_int_head_t		hfi_head;
109 	hook_family_t 			hfi_family;
110 	void				*hfi_ptr;
111 } hook_family_int_t;
112 
113 /*
114  * hook_family_int_head: singly-linked list of hook_family
115  */
116 SLIST_HEAD(hook_family_int_head, hook_family_int);
117 typedef struct hook_family_int_head hook_family_int_head_t;
118 
119 /*
120  * hook stack instances
121  */
122 struct hook_stack {
123 	cvwaitlock_t hks_familylock;		/* global lock */
124 	hook_family_int_head_t hks_familylist;	/* family list head */
125 	netstack_t *hk_netstack;
126 };
127 typedef struct hook_stack hook_stack_t;
128 
129 /*
130  * Names of hooks families currently defined by Solaris
131  */
132 #define	Hn_ARP	"arp"
133 #define	Hn_IPV4	"inet"
134 #define	Hn_IPV6	"inet6"
135 
136 extern hook_family_int_t *hook_family_add(hook_family_t *, hook_stack_t *);
137 extern int hook_family_remove(hook_family_int_t *);
138 extern hook_event_int_t *hook_event_add(hook_family_int_t *, hook_event_t *);
139 extern int hook_event_remove(hook_family_int_t *, hook_event_t *);
140 extern int hook_register(hook_family_int_t *, char *, hook_t *);
141 extern int hook_unregister(hook_family_int_t *, char *, hook_t *);
142 extern int hook_run(hook_event_token_t, hook_data_t, netstack_t *);
143 
144 #ifdef	__cplusplus
145 }
146 #endif
147 
148 #endif /* _SYS_HOOK_IMPL_H */
149