xref: /titanic_41/usr/src/uts/common/sys/hook.h (revision 3441f6a1af86b9b2f883f3323bf02c9dd0f7a94d)
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 includes definitions of kernel hook framework components
28  */
29 
30 #ifndef _SYS_HOOK_H
31 #define	_SYS_HOOK_H
32 
33 #pragma ident	"%Z%%M%	%I%	%E% SMI"
34 
35 #include <sys/queue.h>
36 #include <sys/netstack.h>
37 
38 #ifdef	__cplusplus
39 extern "C" {
40 #endif
41 
42 /*
43  * Definition exposed to hook provider and consumer
44  */
45 
46 #define	HOOK_VERSION	1
47 
48 typedef uintptr_t hook_data_t;
49 
50 struct hook_event_int;
51 typedef struct hook_event_int *hook_event_token_t;
52 
53 typedef int (* hook_func_t)(hook_event_token_t, hook_data_t, netstack_t *);
54 
55 /*
56  * Hook
57  */
58 typedef struct hook {
59 	int32_t		h_version;	/* version number */
60 	hook_func_t	h_func;		/* callback func */
61 	char		*h_name;	/* name of this hook */
62 	int		h_flags;	/* extra hook properties */
63 } hook_t;
64 
65 #define	HOOK_INIT(x, fn, r)			\
66 	do {					\
67 		(x)->h_version = HOOK_VERSION;	\
68 		(x)->h_func = (fn);		\
69 		(x)->h_name = (r);		\
70 		(x)->h_flags = 0;		\
71 		_NOTE(CONSTCOND)		\
72 	} while (0)
73 
74 /*
75  * Family
76  */
77 typedef struct hook_family {
78 	int32_t		hf_version;	/* version number */
79 	char		*hf_name;	/* family name */
80 } hook_family_t;
81 
82 #define	HOOK_FAMILY_INIT(x, y)			\
83 	do {					\
84 		(x)->hf_version = HOOK_VERSION;	\
85 		(x)->hf_name = (y);		\
86 		_NOTE(CONSTCOND)		\
87 	} while (0)
88 
89 /*
90  * Event
91  */
92 typedef struct hook_event {
93 	int32_t		he_version;	/* version number */
94 	char		*he_name;	/* name of this hook list */
95 	int		he_flags;	/* 1 = multiple entries allowed */
96 	boolean_t	he_interested;	/* true if callback exist */
97 } hook_event_t;
98 
99 #define	HOOK_RDONLY	0x1		/* Callbacks must not change data */
100 					/* Multiple callbacks are allowed */
101 
102 #define	HOOK_EVENT_INIT(x, y)			\
103 	do {					\
104 		(x)->he_version = HOOK_VERSION;	\
105 		(x)->he_name = (y);		\
106 		(x)->he_flags = 0;		\
107 		(x)->he_interested = B_FALSE;	\
108 		_NOTE(CONSTCOND)		\
109 	} while (0)
110 
111 #ifdef	__cplusplus
112 }
113 #endif
114 
115 #endif /* _SYS_HOOK_H */
116