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*7513SDarren.Reed@Sun.COM * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 232958Sdr146992 * Use is subject to license terms. 242958Sdr146992 */ 252958Sdr146992 262958Sdr146992 /* 272958Sdr146992 * This file includes definitions of kernel hook framework components 282958Sdr146992 */ 292958Sdr146992 302958Sdr146992 #ifndef _SYS_HOOK_H 312958Sdr146992 #define _SYS_HOOK_H 322958Sdr146992 332958Sdr146992 #include <sys/queue.h> 343448Sdh155122 #include <sys/netstack.h> 352958Sdr146992 362958Sdr146992 #ifdef __cplusplus 372958Sdr146992 extern "C" { 382958Sdr146992 #endif 392958Sdr146992 402958Sdr146992 /* 412958Sdr146992 * Definition exposed to hook provider and consumer 422958Sdr146992 */ 432958Sdr146992 442958Sdr146992 #define HOOK_VERSION 1 452958Sdr146992 462958Sdr146992 typedef uintptr_t hook_data_t; 472958Sdr146992 482958Sdr146992 struct hook_event_int; 492958Sdr146992 typedef struct hook_event_int *hook_event_token_t; 50*7513SDarren.Reed@Sun.COM struct hook_int; 51*7513SDarren.Reed@Sun.COM typedef struct hook_int *hook_token_t; 522958Sdr146992 53*7513SDarren.Reed@Sun.COM typedef int (* hook_func_t)(hook_event_token_t, hook_data_t, void *); 54*7513SDarren.Reed@Sun.COM 55*7513SDarren.Reed@Sun.COM /* 56*7513SDarren.Reed@Sun.COM * A hook_notify_cmd_t is given as an argument to functions called as part of 57*7513SDarren.Reed@Sun.COM * the notify callbacks that have been registered firing. 58*7513SDarren.Reed@Sun.COM */ 59*7513SDarren.Reed@Sun.COM typedef enum hook_notify_cmd_e { 60*7513SDarren.Reed@Sun.COM HN_NONE = 0, 61*7513SDarren.Reed@Sun.COM HN_REGISTER = 1, 62*7513SDarren.Reed@Sun.COM HN_UNREGISTER = 2 63*7513SDarren.Reed@Sun.COM } hook_notify_cmd_t; 64*7513SDarren.Reed@Sun.COM 65*7513SDarren.Reed@Sun.COM /* 66*7513SDarren.Reed@Sun.COM * 67*7513SDarren.Reed@Sun.COM */ 68*7513SDarren.Reed@Sun.COM typedef enum hook_hint_e { 69*7513SDarren.Reed@Sun.COM HH_NONE = 0, 70*7513SDarren.Reed@Sun.COM HH_FIRST, 71*7513SDarren.Reed@Sun.COM HH_LAST, 72*7513SDarren.Reed@Sun.COM HH_BEFORE, 73*7513SDarren.Reed@Sun.COM HH_AFTER 74*7513SDarren.Reed@Sun.COM } hook_hint_t; 752958Sdr146992 762958Sdr146992 /* 772958Sdr146992 * Hook 782958Sdr146992 */ 79*7513SDarren.Reed@Sun.COM typedef struct hook_s { 80*7513SDarren.Reed@Sun.COM int h_version; 812958Sdr146992 hook_func_t h_func; /* callback func */ 822958Sdr146992 char *h_name; /* name of this hook */ 83*7513SDarren.Reed@Sun.COM uint_t h_flags; /* extra hook properties */ 84*7513SDarren.Reed@Sun.COM hook_hint_t h_hint; /* What type of hint is hintvalue */ 85*7513SDarren.Reed@Sun.COM uintptr_t h_hintvalue; 86*7513SDarren.Reed@Sun.COM void *h_arg; /* value to pass back into the hook */ 872958Sdr146992 } hook_t; 882958Sdr146992 89*7513SDarren.Reed@Sun.COM #define HOOK_INIT(x, fn, r, a) \ 902958Sdr146992 do { \ 91*7513SDarren.Reed@Sun.COM (x) = hook_alloc(HOOK_VERSION); \ 922958Sdr146992 (x)->h_func = (fn); \ 932958Sdr146992 (x)->h_name = (r); \ 942958Sdr146992 (x)->h_flags = 0; \ 95*7513SDarren.Reed@Sun.COM (x)->h_hint = HH_NONE; \ 96*7513SDarren.Reed@Sun.COM (x)->h_hintvalue = 0; \ 97*7513SDarren.Reed@Sun.COM (x)->h_arg = (a); \ 982958Sdr146992 _NOTE(CONSTCOND) \ 992958Sdr146992 } while (0) 1002958Sdr146992 1012958Sdr146992 /* 1022958Sdr146992 * Family 1032958Sdr146992 */ 104*7513SDarren.Reed@Sun.COM typedef struct hook_family_s { 105*7513SDarren.Reed@Sun.COM int hf_version; /* version number */ 1062958Sdr146992 char *hf_name; /* family name */ 1072958Sdr146992 } hook_family_t; 1082958Sdr146992 1092958Sdr146992 #define HOOK_FAMILY_INIT(x, y) \ 1102958Sdr146992 do { \ 1112958Sdr146992 (x)->hf_version = HOOK_VERSION; \ 1122958Sdr146992 (x)->hf_name = (y); \ 1132958Sdr146992 _NOTE(CONSTCOND) \ 1142958Sdr146992 } while (0) 1152958Sdr146992 1162958Sdr146992 /* 1172958Sdr146992 * Event 1182958Sdr146992 */ 119*7513SDarren.Reed@Sun.COM typedef struct hook_event_s { 120*7513SDarren.Reed@Sun.COM int he_version; 1212958Sdr146992 char *he_name; /* name of this hook list */ 1222958Sdr146992 int he_flags; /* 1 = multiple entries allowed */ 1232958Sdr146992 boolean_t he_interested; /* true if callback exist */ 1242958Sdr146992 } hook_event_t; 1252958Sdr146992 1262958Sdr146992 #define HOOK_RDONLY 0x1 /* Callbacks must not change data */ 1272958Sdr146992 /* Multiple callbacks are allowed */ 1282958Sdr146992 1292958Sdr146992 #define HOOK_EVENT_INIT(x, y) \ 1302958Sdr146992 do { \ 1312958Sdr146992 (x)->he_version = HOOK_VERSION; \ 1322958Sdr146992 (x)->he_name = (y); \ 1332958Sdr146992 (x)->he_flags = 0; \ 1342958Sdr146992 (x)->he_interested = B_FALSE; \ 1352958Sdr146992 _NOTE(CONSTCOND) \ 1362958Sdr146992 } while (0) 1372958Sdr146992 138*7513SDarren.Reed@Sun.COM typedef int (* hook_notify_fn_t)(hook_notify_cmd_t, void *, const char *, 139*7513SDarren.Reed@Sun.COM const char *, const char *); 140*7513SDarren.Reed@Sun.COM 141*7513SDarren.Reed@Sun.COM extern hook_t *hook_alloc(const int version); 142*7513SDarren.Reed@Sun.COM extern void hook_free(hook_t *); 143*7513SDarren.Reed@Sun.COM 1442958Sdr146992 #ifdef __cplusplus 1452958Sdr146992 } 1462958Sdr146992 #endif 1472958Sdr146992 1482958Sdr146992 #endif /* _SYS_HOOK_H */ 149