xref: /onnv-gate/usr/src/uts/common/sys/hook_impl.h (revision 3448:aaf16568054b)
12958Sdr146992 /*
22958Sdr146992  * CDDL HEADER START
32958Sdr146992  *
42958Sdr146992  * The contents of this file are subject to the terms of the
52958Sdr146992  * Common Development and Distribution License (the "License").
62958Sdr146992  * You may not use this file except in compliance with the License.
72958Sdr146992  *
82958Sdr146992  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
92958Sdr146992  * or http://www.opensolaris.org/os/licensing.
102958Sdr146992  * See the License for the specific language governing permissions
112958Sdr146992  * and limitations under the License.
122958Sdr146992  *
132958Sdr146992  * When distributing Covered Code, include this CDDL HEADER in each
142958Sdr146992  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
152958Sdr146992  * If applicable, add the following below this CDDL HEADER, with the
162958Sdr146992  * fields enclosed by brackets "[]" replaced with your own identifying
172958Sdr146992  * information: Portions Copyright [yyyy] [name of copyright owner]
182958Sdr146992  *
192958Sdr146992  * CDDL HEADER END
202958Sdr146992  */
212958Sdr146992 /*
22*3448Sdh155122  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
232958Sdr146992  * Use is subject to license terms.
242958Sdr146992  */
252958Sdr146992 
262958Sdr146992 /*
272958Sdr146992  * This file include internal used definition and data structure of hooks
282958Sdr146992  */
292958Sdr146992 
302958Sdr146992 #ifndef _SYS_HOOK_IMPL_H
312958Sdr146992 #define	_SYS_HOOK_IMPL_H
322958Sdr146992 
332958Sdr146992 #pragma ident	"%Z%%M%	%I%	%E% SMI"
342958Sdr146992 
352958Sdr146992 #include <sys/hook.h>
362958Sdr146992 #include <sys/condvar_impl.h>
37*3448Sdh155122 #include <sys/netstack.h>
382958Sdr146992 
392958Sdr146992 #ifdef	__cplusplus
402958Sdr146992 extern "C" {
412958Sdr146992 #endif
422958Sdr146992 
432958Sdr146992 /*
442958Sdr146992  * The following diagram describes the linking together of data structures
452958Sdr146992  * used in this implementation of callback hooks.  The start of it all is
462958Sdr146992  * the "familylist" variable in hook.c.  The relationships between data
472958Sdr146992  * structures is:
482958Sdr146992  * - there is a list of hook families;
492958Sdr146992  * - each hook family can have a list of hook events;
502958Sdr146992  * - each hook_event_t must be uniquely associated with one family and event;
512958Sdr146992  * - each hook event can have a list of registered hooks to call.
522958Sdr146992  *
532958Sdr146992  *   familylist                    +--------------+
542958Sdr146992  *       |                         | hook_event_t |<--\
552958Sdr146992  *       |                         +--------------+   |
562958Sdr146992  *       V                                            |
572958Sdr146992  * +-------------------+       ->+------------------+ |     ->+--------------+
582958Sdr146992  * | hook_family_int_t |      /  | hook_event_int_t | |    /  | hook_int_t   |
592958Sdr146992  * | +---------------+ |     /   |                  | /   /   | +----------+ |
602958Sdr146992  * | | hook_family_t | |    /    | hei_event---------/   /    | | hook_t   | |
612958Sdr146992  * | +---------------+ |   /     |                  |   /     | +----------+ |
622958Sdr146992  * |                   |  /      |                  |  /      |              |
632958Sdr146992  * | hfi_head------------/       | hei_head-----------/       | hi_entry--\  |
642958Sdr146992  * | hfi_entry--\      |         | hei_entry--\     |         +-----------|--+
652958Sdr146992  * +------------|------+         +------------|-----+                     |
662958Sdr146992  *              |                             |                           |
672958Sdr146992  *              V                             V                           V
682958Sdr146992  * +-------------------+         +------------------+         +--------------+
692958Sdr146992  * | hook_family_int_t |         | hook_event_int_t |         | hook_int_t   |
702958Sdr146992  * ...
712958Sdr146992  */
722958Sdr146992 
732958Sdr146992 /*
742958Sdr146992  * hook_int: internal storage of hook
752958Sdr146992  */
762958Sdr146992 typedef struct hook_int {
772958Sdr146992 	TAILQ_ENTRY(hook_int)	hi_entry;
782958Sdr146992 	hook_t			hi_hook;
792958Sdr146992 } hook_int_t;
802958Sdr146992 
812958Sdr146992 /*
822958Sdr146992  * Hook_int_head: tail queue of hook_int
832958Sdr146992  */
842958Sdr146992 TAILQ_HEAD(hook_int_head, hook_int);
852958Sdr146992 typedef struct hook_int_head hook_int_head_t;
862958Sdr146992 
872958Sdr146992 /*
882958Sdr146992  * hook_event_int: internal storage of hook_event
892958Sdr146992  */
902958Sdr146992 typedef struct hook_event_int {
912958Sdr146992 	cvwaitlock_t			hei_lock;
922958Sdr146992 	SLIST_ENTRY(hook_event_int)	hei_entry;
932958Sdr146992 	hook_event_t			*hei_event;
942958Sdr146992 	hook_int_head_t			hei_head;
952958Sdr146992 } hook_event_int_t;
962958Sdr146992 
972958Sdr146992 /*
982958Sdr146992  * hook_event_int_head: singly-linked list of hook_event_int
992958Sdr146992  */
1002958Sdr146992 SLIST_HEAD(hook_event_int_head, hook_event_int);
1012958Sdr146992 typedef struct hook_event_int_head hook_event_int_head_t;
1022958Sdr146992 
1032958Sdr146992 /*
1042958Sdr146992  * hook_family_int: internal storage of hook_family
1052958Sdr146992  */
1062958Sdr146992 typedef struct hook_family_int {
1072958Sdr146992 	SLIST_ENTRY(hook_family_int)	hfi_entry;
1082958Sdr146992 	hook_event_int_head_t		hfi_head;
1092958Sdr146992 	hook_family_t 			hfi_family;
110*3448Sdh155122 	void				*hfi_ptr;
1112958Sdr146992 } hook_family_int_t;
1122958Sdr146992 
1132958Sdr146992 /*
1142958Sdr146992  * hook_family_int_head: singly-linked list of hook_family
1152958Sdr146992  */
1162958Sdr146992 SLIST_HEAD(hook_family_int_head, hook_family_int);
1172958Sdr146992 typedef struct hook_family_int_head hook_family_int_head_t;
1182958Sdr146992 
1192958Sdr146992 /*
120*3448Sdh155122  * hook stack instances
121*3448Sdh155122  */
122*3448Sdh155122 struct hook_stack {
123*3448Sdh155122 	cvwaitlock_t hks_familylock;		/* global lock */
124*3448Sdh155122 	hook_family_int_head_t hks_familylist;	/* family list head */
125*3448Sdh155122 	netstack_t *hk_netstack;
126*3448Sdh155122 };
127*3448Sdh155122 typedef struct hook_stack hook_stack_t;
128*3448Sdh155122 
129*3448Sdh155122 /*
1302958Sdr146992  * Names of hooks families currently defined by Solaris
1312958Sdr146992  */
1322958Sdr146992 #define	Hn_ARP	"arp"
1332958Sdr146992 #define	Hn_IPV4	"inet"
1342958Sdr146992 #define	Hn_IPV6	"inet6"
1352958Sdr146992 
136*3448Sdh155122 extern hook_family_int_t *hook_family_add(hook_family_t *, hook_stack_t *);
1372958Sdr146992 extern int hook_family_remove(hook_family_int_t *);
1382958Sdr146992 extern hook_event_int_t *hook_event_add(hook_family_int_t *, hook_event_t *);
1392958Sdr146992 extern int hook_event_remove(hook_family_int_t *, hook_event_t *);
1402958Sdr146992 extern int hook_register(hook_family_int_t *, char *, hook_t *);
1412958Sdr146992 extern int hook_unregister(hook_family_int_t *, char *, hook_t *);
142*3448Sdh155122 extern int hook_run(hook_event_token_t, hook_data_t, netstack_t *);
1432958Sdr146992 
1442958Sdr146992 #ifdef	__cplusplus
1452958Sdr146992 }
1462958Sdr146992 #endif
1472958Sdr146992 
1482958Sdr146992 #endif /* _SYS_HOOK_IMPL_H */
149