1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2002-2003 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #ifndef _IPP_IPP_IMPL_H 28*7c478bd9Sstevel@tonic-gate #define _IPP_IPP_IMPL_H 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate /* 31*7c478bd9Sstevel@tonic-gate * IP Policy Framework (IPPF) implementation detail. 32*7c478bd9Sstevel@tonic-gate * 33*7c478bd9Sstevel@tonic-gate * WARNING: Everything in this file is private, belonging to the IPPF 34*7c478bd9Sstevel@tonic-gate * subsystem. The interfaces and declarations made here are subject 35*7c478bd9Sstevel@tonic-gate * to change. 36*7c478bd9Sstevel@tonic-gate */ 37*7c478bd9Sstevel@tonic-gate 38*7c478bd9Sstevel@tonic-gate #include <sys/stream.h> 39*7c478bd9Sstevel@tonic-gate #include <sys/thread.h> 40*7c478bd9Sstevel@tonic-gate #include <ipp/ipp.h> 41*7c478bd9Sstevel@tonic-gate 42*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 43*7c478bd9Sstevel@tonic-gate extern "C" { 44*7c478bd9Sstevel@tonic-gate #endif 45*7c478bd9Sstevel@tonic-gate 46*7c478bd9Sstevel@tonic-gate #ifdef _KERNEL 47*7c478bd9Sstevel@tonic-gate 48*7c478bd9Sstevel@tonic-gate #define IPP_ALIGN 64 49*7c478bd9Sstevel@tonic-gate 50*7c478bd9Sstevel@tonic-gate #define IPP_NBUCKET 23 51*7c478bd9Sstevel@tonic-gate 52*7c478bd9Sstevel@tonic-gate #define IPP_LOG2NACTION 16 53*7c478bd9Sstevel@tonic-gate #define IPP_NACTION (1 << IPP_LOG2NACTION) 54*7c478bd9Sstevel@tonic-gate 55*7c478bd9Sstevel@tonic-gate #define IPP_LOG2NMOD 6 56*7c478bd9Sstevel@tonic-gate #define IPP_NMOD (1 << IPP_LOG2NMOD) 57*7c478bd9Sstevel@tonic-gate 58*7c478bd9Sstevel@tonic-gate #define IPP_NCLASS 5 59*7c478bd9Sstevel@tonic-gate #define IPP_NLOG IPP_NMOD 60*7c478bd9Sstevel@tonic-gate 61*7c478bd9Sstevel@tonic-gate typedef struct ipp_ref ipp_ref_t; 62*7c478bd9Sstevel@tonic-gate 63*7c478bd9Sstevel@tonic-gate struct ipp_ref { 64*7c478bd9Sstevel@tonic-gate ipp_ref_t *ippr_nextp; 65*7c478bd9Sstevel@tonic-gate uint_t ippr_count; 66*7c478bd9Sstevel@tonic-gate union { 67*7c478bd9Sstevel@tonic-gate ipp_mod_t *u_mod; 68*7c478bd9Sstevel@tonic-gate ipp_action_t *u_action; 69*7c478bd9Sstevel@tonic-gate void *u_ptr; 70*7c478bd9Sstevel@tonic-gate } ippr_u; 71*7c478bd9Sstevel@tonic-gate }; 72*7c478bd9Sstevel@tonic-gate 73*7c478bd9Sstevel@tonic-gate #define ippr_action ippr_u.u_action 74*7c478bd9Sstevel@tonic-gate #define ippr_mod ippr_u.u_mod 75*7c478bd9Sstevel@tonic-gate #define ippr_ptr ippr_u.u_ptr 76*7c478bd9Sstevel@tonic-gate 77*7c478bd9Sstevel@tonic-gate typedef enum { 78*7c478bd9Sstevel@tonic-gate IPP_MODSTATE_PROTO = 0x10, 79*7c478bd9Sstevel@tonic-gate IPP_MODSTATE_AVAILABLE 80*7c478bd9Sstevel@tonic-gate } ipp_modstate_t; 81*7c478bd9Sstevel@tonic-gate 82*7c478bd9Sstevel@tonic-gate struct ipp_mod { 83*7c478bd9Sstevel@tonic-gate ipp_mod_id_t ippm_id; 84*7c478bd9Sstevel@tonic-gate ipp_ops_t *ippm_ops; 85*7c478bd9Sstevel@tonic-gate ipp_ref_t *ippm_action; 86*7c478bd9Sstevel@tonic-gate ipp_modstate_t ippm_state; 87*7c478bd9Sstevel@tonic-gate krwlock_t ippm_lock[1]; 88*7c478bd9Sstevel@tonic-gate uint32_t ippm_hold_count; 89*7c478bd9Sstevel@tonic-gate boolean_t ippm_destruct_pending; 90*7c478bd9Sstevel@tonic-gate char ippm_name[MAXNAMELEN]; 91*7c478bd9Sstevel@tonic-gate }; 92*7c478bd9Sstevel@tonic-gate 93*7c478bd9Sstevel@tonic-gate typedef enum { 94*7c478bd9Sstevel@tonic-gate IPP_ASTATE_PROTO = 0x20, 95*7c478bd9Sstevel@tonic-gate IPP_ASTATE_CONFIG_PENDING, 96*7c478bd9Sstevel@tonic-gate IPP_ASTATE_AVAILABLE 97*7c478bd9Sstevel@tonic-gate } ipp_astate_t; 98*7c478bd9Sstevel@tonic-gate 99*7c478bd9Sstevel@tonic-gate typedef struct cfglock { 100*7c478bd9Sstevel@tonic-gate kmutex_t cl_mutex[1]; 101*7c478bd9Sstevel@tonic-gate kcondvar_t cl_cv[1]; 102*7c478bd9Sstevel@tonic-gate uint_t cl_writers; 103*7c478bd9Sstevel@tonic-gate boolean_t cl_reader; 104*7c478bd9Sstevel@tonic-gate kthread_id_t cl_owner; 105*7c478bd9Sstevel@tonic-gate } cfglock_t; 106*7c478bd9Sstevel@tonic-gate 107*7c478bd9Sstevel@tonic-gate #ifndef __lint 108*7c478bd9Sstevel@tonic-gate 109*7c478bd9Sstevel@tonic-gate #define CL_READ 0 110*7c478bd9Sstevel@tonic-gate #define CL_WRITE 1 111*7c478bd9Sstevel@tonic-gate 112*7c478bd9Sstevel@tonic-gate #define CONFIG_LOCK_INIT(_clp) \ 113*7c478bd9Sstevel@tonic-gate { \ 114*7c478bd9Sstevel@tonic-gate mutex_init((_clp)->cl_mutex, NULL, MUTEX_DEFAULT, \ 115*7c478bd9Sstevel@tonic-gate (void *)ipltospl(LOCK_LEVEL)); \ 116*7c478bd9Sstevel@tonic-gate cv_init((_clp)->cl_cv, NULL, CV_DEFAULT, NULL); \ 117*7c478bd9Sstevel@tonic-gate } 118*7c478bd9Sstevel@tonic-gate 119*7c478bd9Sstevel@tonic-gate #define CONFIG_LOCK_FINI(_clp) \ 120*7c478bd9Sstevel@tonic-gate { \ 121*7c478bd9Sstevel@tonic-gate mutex_destroy((_clp)->cl_mutex); \ 122*7c478bd9Sstevel@tonic-gate cv_destroy((_clp)->cl_cv); \ 123*7c478bd9Sstevel@tonic-gate } 124*7c478bd9Sstevel@tonic-gate 125*7c478bd9Sstevel@tonic-gate #define CONFIG_LOCK_ENTER(_clp, _rw) \ 126*7c478bd9Sstevel@tonic-gate { \ 127*7c478bd9Sstevel@tonic-gate mutex_enter((_clp)->cl_mutex); \ 128*7c478bd9Sstevel@tonic-gate if ((_rw) == CL_WRITE) { \ 129*7c478bd9Sstevel@tonic-gate while ((_clp)->cl_reader || \ 130*7c478bd9Sstevel@tonic-gate ((_clp)->cl_owner != NULL && \ 131*7c478bd9Sstevel@tonic-gate (_clp)->cl_owner != curthread)) \ 132*7c478bd9Sstevel@tonic-gate cv_wait((_clp)->cl_cv, \ 133*7c478bd9Sstevel@tonic-gate (_clp)->cl_mutex); \ 134*7c478bd9Sstevel@tonic-gate (_clp)->cl_owner = curthread; \ 135*7c478bd9Sstevel@tonic-gate (_clp)->cl_writers++; \ 136*7c478bd9Sstevel@tonic-gate } \ 137*7c478bd9Sstevel@tonic-gate else if ((_rw) == CL_READ) { \ 138*7c478bd9Sstevel@tonic-gate while ((_clp)->cl_reader || \ 139*7c478bd9Sstevel@tonic-gate (_clp)->cl_writers > 0) { \ 140*7c478bd9Sstevel@tonic-gate ASSERT((_clp)->cl_owner != curthread); \ 141*7c478bd9Sstevel@tonic-gate cv_wait((_clp)->cl_cv, \ 142*7c478bd9Sstevel@tonic-gate (_clp)->cl_mutex); \ 143*7c478bd9Sstevel@tonic-gate } \ 144*7c478bd9Sstevel@tonic-gate (_clp)->cl_owner = curthread; \ 145*7c478bd9Sstevel@tonic-gate (_clp)->cl_reader = B_TRUE; \ 146*7c478bd9Sstevel@tonic-gate } \ 147*7c478bd9Sstevel@tonic-gate mutex_exit((_clp)->cl_mutex); \ 148*7c478bd9Sstevel@tonic-gate } 149*7c478bd9Sstevel@tonic-gate 150*7c478bd9Sstevel@tonic-gate #define CONFIG_LOCK_EXIT(_clp) \ 151*7c478bd9Sstevel@tonic-gate { \ 152*7c478bd9Sstevel@tonic-gate mutex_enter((_clp)->cl_mutex); \ 153*7c478bd9Sstevel@tonic-gate if ((_clp)->cl_reader) { \ 154*7c478bd9Sstevel@tonic-gate (_clp)->cl_reader = B_FALSE; \ 155*7c478bd9Sstevel@tonic-gate (_clp)->cl_owner = NULL; \ 156*7c478bd9Sstevel@tonic-gate cv_broadcast((_clp)->cl_cv); \ 157*7c478bd9Sstevel@tonic-gate } else { \ 158*7c478bd9Sstevel@tonic-gate ASSERT((_clp)->cl_writers != 0); \ 159*7c478bd9Sstevel@tonic-gate (_clp)->cl_writers--; \ 160*7c478bd9Sstevel@tonic-gate if ((_clp)->cl_writers == 0) { \ 161*7c478bd9Sstevel@tonic-gate (_clp)->cl_owner = NULL; \ 162*7c478bd9Sstevel@tonic-gate cv_broadcast((_clp)->cl_cv); \ 163*7c478bd9Sstevel@tonic-gate } \ 164*7c478bd9Sstevel@tonic-gate } \ 165*7c478bd9Sstevel@tonic-gate mutex_exit((_clp)->cl_mutex); \ 166*7c478bd9Sstevel@tonic-gate } 167*7c478bd9Sstevel@tonic-gate 168*7c478bd9Sstevel@tonic-gate #else /* __lint */ 169*7c478bd9Sstevel@tonic-gate 170*7c478bd9Sstevel@tonic-gate #define CONFIG_LOCK_INIT(_clp) 171*7c478bd9Sstevel@tonic-gate #define CONFIG_LOCK_FINI(_clp) 172*7c478bd9Sstevel@tonic-gate #define CONFIG_LOCK_ENTER(_clp, _rw) 173*7c478bd9Sstevel@tonic-gate #define CONFIG_LOCK_EXIT(_clp) 174*7c478bd9Sstevel@tonic-gate 175*7c478bd9Sstevel@tonic-gate #endif /* __lint */ 176*7c478bd9Sstevel@tonic-gate 177*7c478bd9Sstevel@tonic-gate struct ipp_action { 178*7c478bd9Sstevel@tonic-gate ipp_action_id_t ippa_id; 179*7c478bd9Sstevel@tonic-gate ipp_mod_t *ippa_mod; 180*7c478bd9Sstevel@tonic-gate ipp_ref_t *ippa_ref; 181*7c478bd9Sstevel@tonic-gate ipp_ref_t *ippa_refby; 182*7c478bd9Sstevel@tonic-gate void *ippa_ptr; 183*7c478bd9Sstevel@tonic-gate uint32_t ippa_packets; 184*7c478bd9Sstevel@tonic-gate ipp_astate_t ippa_state; 185*7c478bd9Sstevel@tonic-gate krwlock_t ippa_lock[1]; 186*7c478bd9Sstevel@tonic-gate uint32_t ippa_hold_count; 187*7c478bd9Sstevel@tonic-gate boolean_t ippa_destruct_pending; 188*7c478bd9Sstevel@tonic-gate cfglock_t ippa_config_lock[1]; 189*7c478bd9Sstevel@tonic-gate boolean_t ippa_nameless; 190*7c478bd9Sstevel@tonic-gate char ippa_name[MAXNAMELEN]; 191*7c478bd9Sstevel@tonic-gate ipp_ref_t **ippa_condemned; 192*7c478bd9Sstevel@tonic-gate }; 193*7c478bd9Sstevel@tonic-gate 194*7c478bd9Sstevel@tonic-gate struct ipp_class { 195*7c478bd9Sstevel@tonic-gate ipp_action_id_t ippc_aid; 196*7c478bd9Sstevel@tonic-gate char ippc_name[MAXNAMELEN]; 197*7c478bd9Sstevel@tonic-gate }; 198*7c478bd9Sstevel@tonic-gate 199*7c478bd9Sstevel@tonic-gate struct ipp_log { 200*7c478bd9Sstevel@tonic-gate ipp_action_id_t ippl_aid; 201*7c478bd9Sstevel@tonic-gate timespec_t ippl_begin; 202*7c478bd9Sstevel@tonic-gate timespec_t ippl_end; 203*7c478bd9Sstevel@tonic-gate char ippl_name[MAXNAMELEN]; 204*7c478bd9Sstevel@tonic-gate }; 205*7c478bd9Sstevel@tonic-gate 206*7c478bd9Sstevel@tonic-gate typedef struct ipp_stat_impl ipp_stat_impl_t; 207*7c478bd9Sstevel@tonic-gate 208*7c478bd9Sstevel@tonic-gate struct ipp_stat_impl { 209*7c478bd9Sstevel@tonic-gate void *ippsi_data; 210*7c478bd9Sstevel@tonic-gate kstat_t *ippsi_ksp; 211*7c478bd9Sstevel@tonic-gate int ippsi_limit; 212*7c478bd9Sstevel@tonic-gate int ippsi_count; 213*7c478bd9Sstevel@tonic-gate int (*ippsi_update)(ipp_stat_t *, void *, int); 214*7c478bd9Sstevel@tonic-gate void *ippsi_arg; 215*7c478bd9Sstevel@tonic-gate kmutex_t ippsi_lock[1]; 216*7c478bd9Sstevel@tonic-gate char ippsi_name[MAXNAMELEN]; 217*7c478bd9Sstevel@tonic-gate }; 218*7c478bd9Sstevel@tonic-gate 219*7c478bd9Sstevel@tonic-gate struct ipp_packet { 220*7c478bd9Sstevel@tonic-gate mblk_t *ippp_data; 221*7c478bd9Sstevel@tonic-gate ipp_class_t *ippp_class_array; 222*7c478bd9Sstevel@tonic-gate uint_t ippp_class_limit; 223*7c478bd9Sstevel@tonic-gate uint_t ippp_class_rindex; 224*7c478bd9Sstevel@tonic-gate uint_t ippp_class_windex; 225*7c478bd9Sstevel@tonic-gate ipp_log_t *ippp_log; 226*7c478bd9Sstevel@tonic-gate uint_t ippp_log_limit; 227*7c478bd9Sstevel@tonic-gate uint_t ippp_log_windex; 228*7c478bd9Sstevel@tonic-gate void *ippp_private; 229*7c478bd9Sstevel@tonic-gate void (*ippp_private_free)(void *); 230*7c478bd9Sstevel@tonic-gate }; 231*7c478bd9Sstevel@tonic-gate 232*7c478bd9Sstevel@tonic-gate extern void ipp_init(void); 233*7c478bd9Sstevel@tonic-gate 234*7c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 235*7c478bd9Sstevel@tonic-gate 236*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 237*7c478bd9Sstevel@tonic-gate } 238*7c478bd9Sstevel@tonic-gate #endif 239*7c478bd9Sstevel@tonic-gate 240*7c478bd9Sstevel@tonic-gate #endif /* _IPP_IPP_IMPL_H */ 241