1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 2002 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate #ifndef _IPP_IPGPC_CLASSIFIER_OBJECTS_H 28*0Sstevel@tonic-gate #define _IPP_IPGPC_CLASSIFIER_OBJECTS_H 29*0Sstevel@tonic-gate 30*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 31*0Sstevel@tonic-gate 32*0Sstevel@tonic-gate #include <sys/time.h> 33*0Sstevel@tonic-gate #include <ipp/ipp.h> 34*0Sstevel@tonic-gate #include <ipp/ipgpc/ipgpc.h> 35*0Sstevel@tonic-gate 36*0Sstevel@tonic-gate #ifdef __cplusplus 37*0Sstevel@tonic-gate extern "C" { 38*0Sstevel@tonic-gate #endif 39*0Sstevel@tonic-gate 40*0Sstevel@tonic-gate /* common objects and defines used by the ipgpc code base */ 41*0Sstevel@tonic-gate 42*0Sstevel@tonic-gate /* default wildcard and unspecified value for selectors */ 43*0Sstevel@tonic-gate #define IPGPC_WILDCARD -1 44*0Sstevel@tonic-gate #define IPGPC_UNSPECIFIED 0 45*0Sstevel@tonic-gate 46*0Sstevel@tonic-gate /* trie id's */ 47*0Sstevel@tonic-gate #define IPGPC_TRIE_SPORTID 0 48*0Sstevel@tonic-gate #define IPGPC_TRIE_DPORTID 1 49*0Sstevel@tonic-gate #define IPGPC_TRIE_SADDRID 2 50*0Sstevel@tonic-gate #define IPGPC_TRIE_DADDRID 3 51*0Sstevel@tonic-gate 52*0Sstevel@tonic-gate /* 53*0Sstevel@tonic-gate * IPv6 trie id's 54*0Sstevel@tonic-gate * note: tries for SPORT, DPORT are shared between IPv4 and IPv6 filters 55*0Sstevel@tonic-gate */ 56*0Sstevel@tonic-gate #define IPGPC_TRIE_SADDRID6 4 57*0Sstevel@tonic-gate #define IPGPC_TRIE_DADDRID6 5 58*0Sstevel@tonic-gate 59*0Sstevel@tonic-gate /* ba table id's */ 60*0Sstevel@tonic-gate #define IPGPC_BA_DSID 6 61*0Sstevel@tonic-gate 62*0Sstevel@tonic-gate /* table id's */ 63*0Sstevel@tonic-gate #define IPGPC_TABLE_PROTOID 7 64*0Sstevel@tonic-gate #define IPGPC_TABLE_UID 8 65*0Sstevel@tonic-gate #define IPGPC_TABLE_PROJID 9 66*0Sstevel@tonic-gate #define IPGPC_TABLE_IF 10 67*0Sstevel@tonic-gate #define IPGPC_TABLE_IF_GRPNM 11 68*0Sstevel@tonic-gate #define IPGPC_TABLE_DIR 12 69*0Sstevel@tonic-gate #define TABLE_ID_OFFSET IPGPC_TABLE_PROTOID 70*0Sstevel@tonic-gate #define PROTOID_IDX (IPGPC_TABLE_PROTOID - TABLE_ID_OFFSET) 71*0Sstevel@tonic-gate #define UID_IDX (IPGPC_TABLE_UID - TABLE_ID_OFFSET) 72*0Sstevel@tonic-gate #define PROJID_IDX (IPGPC_TABLE_PROJID - TABLE_ID_OFFSET) 73*0Sstevel@tonic-gate #define IF_IDX (IPGPC_TABLE_IF - TABLE_ID_OFFSET) 74*0Sstevel@tonic-gate #define IF_GRPNM_IDX (IPGPC_TABLE_IF_GRPNM - TABLE_ID_OFFSET) 75*0Sstevel@tonic-gate #define DIR_IDX (IPGPC_TABLE_DIR - TABLE_ID_OFFSET) 76*0Sstevel@tonic-gate 77*0Sstevel@tonic-gate /* Match types for selector searching */ 78*0Sstevel@tonic-gate #define NORMAL_MATCH 0 79*0Sstevel@tonic-gate #define NO_MATCHES 1 80*0Sstevel@tonic-gate #define DONTCARE_ONLY_MATCH 2 81*0Sstevel@tonic-gate 82*0Sstevel@tonic-gate /* match masks */ 83*0Sstevel@tonic-gate #define PROTO_MASK 0x01 84*0Sstevel@tonic-gate #define DS_MASK 0x02 85*0Sstevel@tonic-gate #define SPORT_MASK 0x04 86*0Sstevel@tonic-gate #define DPORT_MASK 0x08 87*0Sstevel@tonic-gate #define SADDR_MASK 0x10 88*0Sstevel@tonic-gate #define DADDR_MASK 0x20 89*0Sstevel@tonic-gate #define SADDR6_MASK SADDR_MASK 90*0Sstevel@tonic-gate #define DADDR6_MASK DADDR_MASK 91*0Sstevel@tonic-gate #define UID_MASK 0x40 92*0Sstevel@tonic-gate #define PROJID_MASK 0x80 93*0Sstevel@tonic-gate #define IF_MASK 0x100 94*0Sstevel@tonic-gate #define IF_GRPNM_MASK 0x200 95*0Sstevel@tonic-gate #define DIR_MASK 0x400 96*0Sstevel@tonic-gate #define ALL_MATCH_MASK (DS_MASK | PROTO_MASK | SADDR_MASK | DADDR_MASK | \ 97*0Sstevel@tonic-gate SPORT_MASK | DPORT_MASK | UID_MASK | PROJID_MASK | \ 98*0Sstevel@tonic-gate IF_MASK | IF_GRPNM_MASK | DIR_MASK) 99*0Sstevel@tonic-gate 100*0Sstevel@tonic-gate #define HASH_SIZE 11 /* default hash table size */ 101*0Sstevel@tonic-gate 102*0Sstevel@tonic-gate /* used when inserting values into selector structures */ 103*0Sstevel@tonic-gate #define NORMAL_VALUE 0 /* a valid value was insert */ 104*0Sstevel@tonic-gate #define DONTCARE_VALUE 1 /* a dontcare/wildcard value was inserted */ 105*0Sstevel@tonic-gate 106*0Sstevel@tonic-gate /* filter definition structure */ 107*0Sstevel@tonic-gate typedef struct ipgpc_filter_s { 108*0Sstevel@tonic-gate char filter_name[MAXNAMELEN]; /* null terminated name of filter */ 109*0Sstevel@tonic-gate 110*0Sstevel@tonic-gate /* exact match selectors */ 111*0Sstevel@tonic-gate char if_groupname[LIFNAMSIZ]; /* null terminated iface groupname */ 112*0Sstevel@tonic-gate uid_t uid; /* uid key, value = exact or IPGPC_WILDCARD */ 113*0Sstevel@tonic-gate projid_t projid; /* project id, " " */ 114*0Sstevel@tonic-gate uint_t if_index; /* interface index, " " or 0 for wildcard */ 115*0Sstevel@tonic-gate /* 116*0Sstevel@tonic-gate * packet direction 117*0Sstevel@tonic-gate * value = IPP_LOCAL_IN | IPP_LOCAL_OUT | 118*0Sstevel@tonic-gate * IPP_FWD_IN | IPP_FWD_OUT | 0 for wildcard 119*0Sstevel@tonic-gate */ 120*0Sstevel@tonic-gate uint32_t direction; 121*0Sstevel@tonic-gate uint8_t proto; /* protocol key, exact or 0 for wildcard */ 122*0Sstevel@tonic-gate 123*0Sstevel@tonic-gate /* non-exact match selectors */ 124*0Sstevel@tonic-gate uint8_t dsfield; /* diffserv field key */ 125*0Sstevel@tonic-gate uint8_t dsfield_mask; /* mask for diffserv field key */ 126*0Sstevel@tonic-gate /* IP Addresses are represented as IPV6 address structures */ 127*0Sstevel@tonic-gate in6_addr_t saddr; /* source address key */ 128*0Sstevel@tonic-gate in6_addr_t saddr_mask; /* mask for saddr key */ 129*0Sstevel@tonic-gate char *saddr_hostname; /* hostname of source address, optional */ 130*0Sstevel@tonic-gate in6_addr_t daddr; /* destination address key */ 131*0Sstevel@tonic-gate in6_addr_t daddr_mask; /* mask for daddr key */ 132*0Sstevel@tonic-gate char *daddr_hostname; /* hostname of destination address, optional */ 133*0Sstevel@tonic-gate uint16_t sport; /* source port key */ 134*0Sstevel@tonic-gate uint16_t sport_mask; /* mask for sport key */ 135*0Sstevel@tonic-gate uint16_t dport; /* destination port key */ 136*0Sstevel@tonic-gate uint16_t dport_mask; /* mask for dport key */ 137*0Sstevel@tonic-gate 138*0Sstevel@tonic-gate /* filter ranking variables */ 139*0Sstevel@tonic-gate uint32_t precedence; /* precedence value for filter */ 140*0Sstevel@tonic-gate uint32_t priority; /* filter priority */ 141*0Sstevel@tonic-gate 142*0Sstevel@tonic-gate /* 143*0Sstevel@tonic-gate * filter_type accepted values = 144*0Sstevel@tonic-gate * IPGPC_GENERIC_FLTR | IPGPC_V4_FLTR | 145*0Sstevel@tonic-gate * IPGPC_V6_FLTR 146*0Sstevel@tonic-gate */ 147*0Sstevel@tonic-gate uint8_t filter_type; 148*0Sstevel@tonic-gate int32_t filter_instance; /* filter instance number, -1 if unused */ 149*0Sstevel@tonic-gate uint32_t originator; /* originator of this config item */ 150*0Sstevel@tonic-gate char *filter_comment; /* optional and unused by ipgpc */ 151*0Sstevel@tonic-gate } ipgpc_filter_t; 152*0Sstevel@tonic-gate 153*0Sstevel@tonic-gate typedef struct ipgpc_class_stats_s { 154*0Sstevel@tonic-gate ipp_action_id_t next_action; /* next action id */ 155*0Sstevel@tonic-gate hrtime_t last_match; /* hrtime value of last match to class */ 156*0Sstevel@tonic-gate uint64_t nbytes; /* number of matching bytes */ 157*0Sstevel@tonic-gate uint64_t npackets; /* number of matching packets */ 158*0Sstevel@tonic-gate } ipgpc_class_stats_t; 159*0Sstevel@tonic-gate 160*0Sstevel@tonic-gate /* linked list Element node structure */ 161*0Sstevel@tonic-gate typedef struct element_node_s *linked_list; 162*0Sstevel@tonic-gate typedef struct element_node_s *plink; 163*0Sstevel@tonic-gate typedef struct element_node_s { 164*0Sstevel@tonic-gate plink next; 165*0Sstevel@tonic-gate void (*element_ref)(struct element_node_s *); 166*0Sstevel@tonic-gate void (*element_unref)(struct element_node_s *); 167*0Sstevel@tonic-gate int id; 168*0Sstevel@tonic-gate uint32_t element_refcnt; 169*0Sstevel@tonic-gate } element_node_t; 170*0Sstevel@tonic-gate 171*0Sstevel@tonic-gate /* trie node structure */ 172*0Sstevel@tonic-gate typedef struct node_s *node_p; 173*0Sstevel@tonic-gate typedef struct node_s { 174*0Sstevel@tonic-gate linked_list elements; /* pointer to element list */ 175*0Sstevel@tonic-gate node_p zero; /* left link */ 176*0Sstevel@tonic-gate node_p one; /* right link */ 177*0Sstevel@tonic-gate uint32_t val; /* value of bits covered */ 178*0Sstevel@tonic-gate uint32_t mask; /* mask of bits covered */ 179*0Sstevel@tonic-gate uint8_t bits; /* number of bits covered by this node */ 180*0Sstevel@tonic-gate uint8_t pos; /* starting position of bits covered */ 181*0Sstevel@tonic-gate uint16_t isroot; /* 1 if is root node, 0 otherwise */ 182*0Sstevel@tonic-gate } node_t; 183*0Sstevel@tonic-gate typedef node_p trie; 184*0Sstevel@tonic-gate 185*0Sstevel@tonic-gate /* hashtable node structure */ 186*0Sstevel@tonic-gate typedef struct ht_node_s *hash_table; 187*0Sstevel@tonic-gate typedef struct ht_node_s *ht_node_p; 188*0Sstevel@tonic-gate typedef struct ht_node_s { 189*0Sstevel@tonic-gate ht_node_p next; /* link to next node in chain */ 190*0Sstevel@tonic-gate linked_list elements; /* elements stored at this node */ 191*0Sstevel@tonic-gate int key; /* key stored at this node */ 192*0Sstevel@tonic-gate int info; 193*0Sstevel@tonic-gate } ht_node_t; 194*0Sstevel@tonic-gate 195*0Sstevel@tonic-gate /* behavior aggregate table element structure */ 196*0Sstevel@tonic-gate typedef struct ba_table_element_s { 197*0Sstevel@tonic-gate linked_list filter_list; /* list of filters */ 198*0Sstevel@tonic-gate uint32_t info; 199*0Sstevel@tonic-gate } ba_table_element_t; 200*0Sstevel@tonic-gate 201*0Sstevel@tonic-gate /* behavior aggregate table structure */ 202*0Sstevel@tonic-gate typedef struct ba_table_s { 203*0Sstevel@tonic-gate linked_list masks; /* list of loaded masks */ 204*0Sstevel@tonic-gate ba_table_element_t masked_values[256]; /* table of masked values */ 205*0Sstevel@tonic-gate } ba_table_t; 206*0Sstevel@tonic-gate 207*0Sstevel@tonic-gate /* selector information structure */ 208*0Sstevel@tonic-gate typedef struct sel_info_s { 209*0Sstevel@tonic-gate uint16_t mask; /* mask for marking */ 210*0Sstevel@tonic-gate boolean_t dontcareonly; /* true if only don't cares are loaded */ 211*0Sstevel@tonic-gate } sel_info_t; 212*0Sstevel@tonic-gate 213*0Sstevel@tonic-gate /* selector statistics structure */ 214*0Sstevel@tonic-gate typedef struct sel_stats_s { 215*0Sstevel@tonic-gate uint32_t num_inserted; /* number of nodes that are not dontcares */ 216*0Sstevel@tonic-gate uint32_t num_dontcare; /* number of nodes that are dontcares */ 217*0Sstevel@tonic-gate } sel_stats_t; 218*0Sstevel@tonic-gate 219*0Sstevel@tonic-gate /* identification structure for a trie */ 220*0Sstevel@tonic-gate typedef struct trie_id_s { 221*0Sstevel@tonic-gate trie trie; /* pointer to the trie structure */ 222*0Sstevel@tonic-gate krwlock_t rw_lock; /* lock protecting this trie */ 223*0Sstevel@tonic-gate size_t key_len; /* length (bits) of the key for a lookup */ 224*0Sstevel@tonic-gate sel_stats_t stats; /* selector statistics strucutre */ 225*0Sstevel@tonic-gate sel_info_t info; /* selector info structure */ 226*0Sstevel@tonic-gate } trie_id_t; 227*0Sstevel@tonic-gate 228*0Sstevel@tonic-gate /* identification structure for a table */ 229*0Sstevel@tonic-gate typedef struct table_id_s { 230*0Sstevel@tonic-gate hash_table table; /* pointer to the hash table structure */ 231*0Sstevel@tonic-gate int wildcard; /* wildcard value for this selector */ 232*0Sstevel@tonic-gate sel_stats_t stats; /* selector statistics strucutre */ 233*0Sstevel@tonic-gate sel_info_t info; /* selector info structure */ 234*0Sstevel@tonic-gate } table_id_t; 235*0Sstevel@tonic-gate 236*0Sstevel@tonic-gate /* identification structure for a ba_table */ 237*0Sstevel@tonic-gate typedef struct ba_table_id_s { 238*0Sstevel@tonic-gate ba_table_t table; 239*0Sstevel@tonic-gate kmutex_t lock; /* ba table lock */ 240*0Sstevel@tonic-gate sel_info_t info; /* selector info structure */ 241*0Sstevel@tonic-gate sel_stats_t stats; /* selector statistics structure */ 242*0Sstevel@tonic-gate } ba_table_id_t; 243*0Sstevel@tonic-gate 244*0Sstevel@tonic-gate /* class definition structure */ 245*0Sstevel@tonic-gate typedef struct ipgpc_class_s { 246*0Sstevel@tonic-gate ipp_action_id_t next_action; /* id of action at head of list */ 247*0Sstevel@tonic-gate boolean_t gather_stats; /* are stats desired? B_TRUE or B_FALSE */ 248*0Sstevel@tonic-gate uint32_t originator; /* originator of this config item */ 249*0Sstevel@tonic-gate char class_name[MAXNAMELEN]; /* name of classification */ 250*0Sstevel@tonic-gate } ipgpc_class_t; 251*0Sstevel@tonic-gate 252*0Sstevel@tonic-gate /* filter id association data structure */ 253*0Sstevel@tonic-gate typedef struct fid_s { 254*0Sstevel@tonic-gate int info; /* 0 if unused, -1 if dirty, 1 if used */ 255*0Sstevel@tonic-gate int class_id; /* id of class associated with filter */ 256*0Sstevel@tonic-gate uint16_t insert_map; /* selectors w/ values inserted for this fid */ 257*0Sstevel@tonic-gate ipgpc_filter_t filter; /* filter structure that this fid describes */ 258*0Sstevel@tonic-gate } fid_t; 259*0Sstevel@tonic-gate 260*0Sstevel@tonic-gate /* class_id structure */ 261*0Sstevel@tonic-gate typedef struct cid_s { 262*0Sstevel@tonic-gate linked_list filter_list; /* list of filters associated with class */ 263*0Sstevel@tonic-gate int info; /* 0 if unused, -1 if dirty, 1 if used */ 264*0Sstevel@tonic-gate ipgpc_class_t aclass; /* the class structure this cid describes */ 265*0Sstevel@tonic-gate ipp_stat_t *cl_stats; /* kstats structure */ 266*0Sstevel@tonic-gate ipgpc_class_stats_t stats; /* statistics structure for class */ 267*0Sstevel@tonic-gate } cid_t; 268*0Sstevel@tonic-gate 269*0Sstevel@tonic-gate /* ipp_stat global stats structure */ 270*0Sstevel@tonic-gate typedef struct globalstats_s { 271*0Sstevel@tonic-gate ipp_named_t nfilters; 272*0Sstevel@tonic-gate ipp_named_t nclasses; 273*0Sstevel@tonic-gate ipp_named_t nbytes; 274*0Sstevel@tonic-gate ipp_named_t npackets; 275*0Sstevel@tonic-gate ipp_named_t epackets; 276*0Sstevel@tonic-gate } globalstats_t; 277*0Sstevel@tonic-gate 278*0Sstevel@tonic-gate /* ipp_stat class stats structure */ 279*0Sstevel@tonic-gate typedef struct classstats_s { 280*0Sstevel@tonic-gate ipp_named_t nbytes; 281*0Sstevel@tonic-gate ipp_named_t npackets; 282*0Sstevel@tonic-gate ipp_named_t last_match; 283*0Sstevel@tonic-gate } classstats_t; 284*0Sstevel@tonic-gate 285*0Sstevel@tonic-gate /* matching hash table element */ 286*0Sstevel@tonic-gate typedef struct ht_match_s *ht_chain; 287*0Sstevel@tonic-gate typedef struct ht_match_s { 288*0Sstevel@tonic-gate ht_chain next; /* link to next node in chain */ 289*0Sstevel@tonic-gate int key; /* key stored at this node in the table */ 290*0Sstevel@tonic-gate uint16_t match_map; /* match map for this id */ 291*0Sstevel@tonic-gate } ht_match_t; 292*0Sstevel@tonic-gate 293*0Sstevel@tonic-gate extern kmem_cache_t *ht_node_cache; 294*0Sstevel@tonic-gate extern kmem_cache_t *element_node_cache; 295*0Sstevel@tonic-gate extern kmem_cache_t *ht_match_cache; 296*0Sstevel@tonic-gate extern kmem_cache_t *trie_node_cache; 297*0Sstevel@tonic-gate 298*0Sstevel@tonic-gate #ifdef __cplusplus 299*0Sstevel@tonic-gate } 300*0Sstevel@tonic-gate #endif 301*0Sstevel@tonic-gate 302*0Sstevel@tonic-gate #endif /* _IPP_IPGPC_CLASSIFIER_OBJECTS_H */ 303