xref: /titanic_41/usr/src/uts/common/sys/hook.h (revision 7ddc9b1afd18f260b9fb78ec7732facd91769131)
1381a2a9aSdr146992 /*
2381a2a9aSdr146992  * CDDL HEADER START
3381a2a9aSdr146992  *
4381a2a9aSdr146992  * The contents of this file are subject to the terms of the
5381a2a9aSdr146992  * Common Development and Distribution License (the "License").
6381a2a9aSdr146992  * You may not use this file except in compliance with the License.
7381a2a9aSdr146992  *
8381a2a9aSdr146992  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9381a2a9aSdr146992  * or http://www.opensolaris.org/os/licensing.
10381a2a9aSdr146992  * See the License for the specific language governing permissions
11381a2a9aSdr146992  * and limitations under the License.
12381a2a9aSdr146992  *
13381a2a9aSdr146992  * When distributing Covered Code, include this CDDL HEADER in each
14381a2a9aSdr146992  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15381a2a9aSdr146992  * If applicable, add the following below this CDDL HEADER, with the
16381a2a9aSdr146992  * fields enclosed by brackets "[]" replaced with your own identifying
17381a2a9aSdr146992  * information: Portions Copyright [yyyy] [name of copyright owner]
18381a2a9aSdr146992  *
19381a2a9aSdr146992  * CDDL HEADER END
20381a2a9aSdr146992  */
21381a2a9aSdr146992 /*
22*7ddc9b1aSDarren Reed  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23381a2a9aSdr146992  * Use is subject to license terms.
24381a2a9aSdr146992  */
25381a2a9aSdr146992 
26381a2a9aSdr146992 /*
27381a2a9aSdr146992  * This file includes definitions of kernel hook framework components
28381a2a9aSdr146992  */
29381a2a9aSdr146992 
30381a2a9aSdr146992 #ifndef _SYS_HOOK_H
31381a2a9aSdr146992 #define	_SYS_HOOK_H
32381a2a9aSdr146992 
33381a2a9aSdr146992 #include <sys/queue.h>
34f4b3ec61Sdh155122 #include <sys/netstack.h>
35381a2a9aSdr146992 
36381a2a9aSdr146992 #ifdef	__cplusplus
37381a2a9aSdr146992 extern "C" {
38381a2a9aSdr146992 #endif
39381a2a9aSdr146992 
40381a2a9aSdr146992 /*
41381a2a9aSdr146992  * Definition exposed to hook provider and consumer
42381a2a9aSdr146992  */
43381a2a9aSdr146992 
44381a2a9aSdr146992 #define	HOOK_VERSION	1
45381a2a9aSdr146992 
46381a2a9aSdr146992 typedef uintptr_t hook_data_t;
47381a2a9aSdr146992 
48381a2a9aSdr146992 struct hook_event_int;
49381a2a9aSdr146992 typedef struct hook_event_int *hook_event_token_t;
50*7ddc9b1aSDarren Reed struct hook_int;
51*7ddc9b1aSDarren Reed typedef struct hook_int *hook_token_t;
52381a2a9aSdr146992 
53*7ddc9b1aSDarren Reed typedef int (* hook_func_t)(hook_event_token_t, hook_data_t, void *);
54*7ddc9b1aSDarren Reed 
55*7ddc9b1aSDarren Reed /*
56*7ddc9b1aSDarren Reed  * A hook_notify_cmd_t is given as an argument to functions called as part of
57*7ddc9b1aSDarren Reed  * the notify callbacks that have been registered firing.
58*7ddc9b1aSDarren Reed  */
59*7ddc9b1aSDarren Reed typedef enum hook_notify_cmd_e {
60*7ddc9b1aSDarren Reed 	HN_NONE = 0,
61*7ddc9b1aSDarren Reed 	HN_REGISTER = 1,
62*7ddc9b1aSDarren Reed 	HN_UNREGISTER = 2
63*7ddc9b1aSDarren Reed } hook_notify_cmd_t;
64*7ddc9b1aSDarren Reed 
65*7ddc9b1aSDarren Reed /*
66*7ddc9b1aSDarren Reed  *
67*7ddc9b1aSDarren Reed  */
68*7ddc9b1aSDarren Reed typedef enum hook_hint_e {
69*7ddc9b1aSDarren Reed 	HH_NONE = 0,
70*7ddc9b1aSDarren Reed 	HH_FIRST,
71*7ddc9b1aSDarren Reed 	HH_LAST,
72*7ddc9b1aSDarren Reed 	HH_BEFORE,
73*7ddc9b1aSDarren Reed 	HH_AFTER
74*7ddc9b1aSDarren Reed } hook_hint_t;
75381a2a9aSdr146992 
76381a2a9aSdr146992 /*
77381a2a9aSdr146992  * Hook
78381a2a9aSdr146992  */
79*7ddc9b1aSDarren Reed typedef struct hook_s {
80*7ddc9b1aSDarren Reed 	int		h_version;
81381a2a9aSdr146992 	hook_func_t	h_func;		/* callback func */
82381a2a9aSdr146992 	char		*h_name;	/* name of this hook */
83*7ddc9b1aSDarren Reed 	uint_t		h_flags;	/* extra hook properties */
84*7ddc9b1aSDarren Reed 	hook_hint_t	h_hint;		/* What type of hint is hintvalue */
85*7ddc9b1aSDarren Reed 	uintptr_t	h_hintvalue;
86*7ddc9b1aSDarren Reed 	void		*h_arg;		/* value to pass back into the hook */
87381a2a9aSdr146992 } hook_t;
88381a2a9aSdr146992 
89*7ddc9b1aSDarren Reed #define	HOOK_INIT(x, fn, r, a)		\
90381a2a9aSdr146992 	do {					\
91*7ddc9b1aSDarren Reed 		(x) = hook_alloc(HOOK_VERSION);	\
92381a2a9aSdr146992 		(x)->h_func = (fn);		\
93381a2a9aSdr146992 		(x)->h_name = (r);		\
94381a2a9aSdr146992 		(x)->h_flags = 0;		\
95*7ddc9b1aSDarren Reed 		(x)->h_hint = HH_NONE;		\
96*7ddc9b1aSDarren Reed 		(x)->h_hintvalue = 0;		\
97*7ddc9b1aSDarren Reed 		(x)->h_arg = (a);		\
98381a2a9aSdr146992 		_NOTE(CONSTCOND)		\
99381a2a9aSdr146992 	} while (0)
100381a2a9aSdr146992 
101381a2a9aSdr146992 /*
102381a2a9aSdr146992  * Family
103381a2a9aSdr146992  */
104*7ddc9b1aSDarren Reed typedef struct hook_family_s {
105*7ddc9b1aSDarren Reed 	int		hf_version;	/* version number */
106381a2a9aSdr146992 	char		*hf_name;	/* family name */
107381a2a9aSdr146992 } hook_family_t;
108381a2a9aSdr146992 
109381a2a9aSdr146992 #define	HOOK_FAMILY_INIT(x, y)			\
110381a2a9aSdr146992 	do {					\
111381a2a9aSdr146992 		(x)->hf_version = HOOK_VERSION;	\
112381a2a9aSdr146992 		(x)->hf_name = (y);		\
113381a2a9aSdr146992 		_NOTE(CONSTCOND)		\
114381a2a9aSdr146992 	} while (0)
115381a2a9aSdr146992 
116381a2a9aSdr146992 /*
117381a2a9aSdr146992  * Event
118381a2a9aSdr146992  */
119*7ddc9b1aSDarren Reed typedef struct hook_event_s {
120*7ddc9b1aSDarren Reed 	int		he_version;
121381a2a9aSdr146992 	char		*he_name;	/* name of this hook list */
122381a2a9aSdr146992 	int		he_flags;	/* 1 = multiple entries allowed */
123381a2a9aSdr146992 	boolean_t	he_interested;	/* true if callback exist */
124381a2a9aSdr146992 } hook_event_t;
125381a2a9aSdr146992 
126381a2a9aSdr146992 #define	HOOK_RDONLY	0x1		/* Callbacks must not change data */
127381a2a9aSdr146992 					/* Multiple callbacks are allowed */
128381a2a9aSdr146992 
129381a2a9aSdr146992 #define	HOOK_EVENT_INIT(x, y)			\
130381a2a9aSdr146992 	do {					\
131381a2a9aSdr146992 		(x)->he_version = HOOK_VERSION;	\
132381a2a9aSdr146992 		(x)->he_name = (y);		\
133381a2a9aSdr146992 		(x)->he_flags = 0;		\
134381a2a9aSdr146992 		(x)->he_interested = B_FALSE;	\
135381a2a9aSdr146992 		_NOTE(CONSTCOND)		\
136381a2a9aSdr146992 	} while (0)
137381a2a9aSdr146992 
138*7ddc9b1aSDarren Reed typedef int (* hook_notify_fn_t)(hook_notify_cmd_t, void *, const char *,
139*7ddc9b1aSDarren Reed     const char *, const char *);
140*7ddc9b1aSDarren Reed 
141*7ddc9b1aSDarren Reed extern	hook_t		*hook_alloc(const int version);
142*7ddc9b1aSDarren Reed extern	void		hook_free(hook_t *);
143*7ddc9b1aSDarren Reed 
144381a2a9aSdr146992 #ifdef	__cplusplus
145381a2a9aSdr146992 }
146381a2a9aSdr146992 #endif
147381a2a9aSdr146992 
148381a2a9aSdr146992 #endif /* _SYS_HOOK_H */
149