17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*e11c3f44Smeem * Common Development and Distribution License (the "License"). 6*e11c3f44Smeem * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*e11c3f44Smeem * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #ifndef _IPP_IPGPC_CLASSIFIER_OBJECTS_H 277c478bd9Sstevel@tonic-gate #define _IPP_IPGPC_CLASSIFIER_OBJECTS_H 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #include <sys/time.h> 307c478bd9Sstevel@tonic-gate #include <ipp/ipp.h> 317c478bd9Sstevel@tonic-gate #include <ipp/ipgpc/ipgpc.h> 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate #ifdef __cplusplus 347c478bd9Sstevel@tonic-gate extern "C" { 357c478bd9Sstevel@tonic-gate #endif 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate /* common objects and defines used by the ipgpc code base */ 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate /* default wildcard and unspecified value for selectors */ 407c478bd9Sstevel@tonic-gate #define IPGPC_WILDCARD -1 417c478bd9Sstevel@tonic-gate #define IPGPC_UNSPECIFIED 0 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate /* trie id's */ 447c478bd9Sstevel@tonic-gate #define IPGPC_TRIE_SPORTID 0 457c478bd9Sstevel@tonic-gate #define IPGPC_TRIE_DPORTID 1 467c478bd9Sstevel@tonic-gate #define IPGPC_TRIE_SADDRID 2 477c478bd9Sstevel@tonic-gate #define IPGPC_TRIE_DADDRID 3 487c478bd9Sstevel@tonic-gate 497c478bd9Sstevel@tonic-gate /* 507c478bd9Sstevel@tonic-gate * IPv6 trie id's 517c478bd9Sstevel@tonic-gate * note: tries for SPORT, DPORT are shared between IPv4 and IPv6 filters 527c478bd9Sstevel@tonic-gate */ 537c478bd9Sstevel@tonic-gate #define IPGPC_TRIE_SADDRID6 4 547c478bd9Sstevel@tonic-gate #define IPGPC_TRIE_DADDRID6 5 557c478bd9Sstevel@tonic-gate 567c478bd9Sstevel@tonic-gate /* ba table id's */ 577c478bd9Sstevel@tonic-gate #define IPGPC_BA_DSID 6 587c478bd9Sstevel@tonic-gate 597c478bd9Sstevel@tonic-gate /* table id's */ 607c478bd9Sstevel@tonic-gate #define IPGPC_TABLE_PROTOID 7 617c478bd9Sstevel@tonic-gate #define IPGPC_TABLE_UID 8 627c478bd9Sstevel@tonic-gate #define IPGPC_TABLE_PROJID 9 637c478bd9Sstevel@tonic-gate #define IPGPC_TABLE_IF 10 64*e11c3f44Smeem #define IPGPC_TABLE_DIR 11 657c478bd9Sstevel@tonic-gate #define TABLE_ID_OFFSET IPGPC_TABLE_PROTOID 667c478bd9Sstevel@tonic-gate #define PROTOID_IDX (IPGPC_TABLE_PROTOID - TABLE_ID_OFFSET) 677c478bd9Sstevel@tonic-gate #define UID_IDX (IPGPC_TABLE_UID - TABLE_ID_OFFSET) 687c478bd9Sstevel@tonic-gate #define PROJID_IDX (IPGPC_TABLE_PROJID - TABLE_ID_OFFSET) 697c478bd9Sstevel@tonic-gate #define IF_IDX (IPGPC_TABLE_IF - TABLE_ID_OFFSET) 707c478bd9Sstevel@tonic-gate #define DIR_IDX (IPGPC_TABLE_DIR - TABLE_ID_OFFSET) 717c478bd9Sstevel@tonic-gate 727c478bd9Sstevel@tonic-gate /* Match types for selector searching */ 737c478bd9Sstevel@tonic-gate #define NORMAL_MATCH 0 747c478bd9Sstevel@tonic-gate #define NO_MATCHES 1 757c478bd9Sstevel@tonic-gate #define DONTCARE_ONLY_MATCH 2 767c478bd9Sstevel@tonic-gate 777c478bd9Sstevel@tonic-gate /* match masks */ 787c478bd9Sstevel@tonic-gate #define PROTO_MASK 0x01 797c478bd9Sstevel@tonic-gate #define DS_MASK 0x02 807c478bd9Sstevel@tonic-gate #define SPORT_MASK 0x04 817c478bd9Sstevel@tonic-gate #define DPORT_MASK 0x08 827c478bd9Sstevel@tonic-gate #define SADDR_MASK 0x10 837c478bd9Sstevel@tonic-gate #define DADDR_MASK 0x20 847c478bd9Sstevel@tonic-gate #define SADDR6_MASK SADDR_MASK 857c478bd9Sstevel@tonic-gate #define DADDR6_MASK DADDR_MASK 867c478bd9Sstevel@tonic-gate #define UID_MASK 0x40 877c478bd9Sstevel@tonic-gate #define PROJID_MASK 0x80 887c478bd9Sstevel@tonic-gate #define IF_MASK 0x100 89*e11c3f44Smeem #define DIR_MASK 0x200 907c478bd9Sstevel@tonic-gate #define ALL_MATCH_MASK (DS_MASK | PROTO_MASK | SADDR_MASK | DADDR_MASK | \ 917c478bd9Sstevel@tonic-gate SPORT_MASK | DPORT_MASK | UID_MASK | PROJID_MASK | \ 92*e11c3f44Smeem IF_MASK | DIR_MASK) 937c478bd9Sstevel@tonic-gate 947c478bd9Sstevel@tonic-gate #define HASH_SIZE 11 /* default hash table size */ 957c478bd9Sstevel@tonic-gate 967c478bd9Sstevel@tonic-gate /* used when inserting values into selector structures */ 977c478bd9Sstevel@tonic-gate #define NORMAL_VALUE 0 /* a valid value was insert */ 987c478bd9Sstevel@tonic-gate #define DONTCARE_VALUE 1 /* a dontcare/wildcard value was inserted */ 997c478bd9Sstevel@tonic-gate 1007c478bd9Sstevel@tonic-gate /* filter definition structure */ 1017c478bd9Sstevel@tonic-gate typedef struct ipgpc_filter_s { 1027c478bd9Sstevel@tonic-gate char filter_name[MAXNAMELEN]; /* null terminated name of filter */ 1037c478bd9Sstevel@tonic-gate 1047c478bd9Sstevel@tonic-gate /* exact match selectors */ 1057c478bd9Sstevel@tonic-gate uid_t uid; /* uid key, value = exact or IPGPC_WILDCARD */ 1067c478bd9Sstevel@tonic-gate projid_t projid; /* project id, " " */ 1077c478bd9Sstevel@tonic-gate uint_t if_index; /* interface index, " " or 0 for wildcard */ 1087c478bd9Sstevel@tonic-gate /* 1097c478bd9Sstevel@tonic-gate * packet direction 1107c478bd9Sstevel@tonic-gate * value = IPP_LOCAL_IN | IPP_LOCAL_OUT | 1117c478bd9Sstevel@tonic-gate * IPP_FWD_IN | IPP_FWD_OUT | 0 for wildcard 1127c478bd9Sstevel@tonic-gate */ 1137c478bd9Sstevel@tonic-gate uint32_t direction; 1147c478bd9Sstevel@tonic-gate uint8_t proto; /* protocol key, exact or 0 for wildcard */ 1157c478bd9Sstevel@tonic-gate 1167c478bd9Sstevel@tonic-gate /* non-exact match selectors */ 1177c478bd9Sstevel@tonic-gate uint8_t dsfield; /* diffserv field key */ 1187c478bd9Sstevel@tonic-gate uint8_t dsfield_mask; /* mask for diffserv field key */ 1197c478bd9Sstevel@tonic-gate /* IP Addresses are represented as IPV6 address structures */ 1207c478bd9Sstevel@tonic-gate in6_addr_t saddr; /* source address key */ 1217c478bd9Sstevel@tonic-gate in6_addr_t saddr_mask; /* mask for saddr key */ 1227c478bd9Sstevel@tonic-gate char *saddr_hostname; /* hostname of source address, optional */ 1237c478bd9Sstevel@tonic-gate in6_addr_t daddr; /* destination address key */ 1247c478bd9Sstevel@tonic-gate in6_addr_t daddr_mask; /* mask for daddr key */ 1257c478bd9Sstevel@tonic-gate char *daddr_hostname; /* hostname of destination address, optional */ 1267c478bd9Sstevel@tonic-gate uint16_t sport; /* source port key */ 1277c478bd9Sstevel@tonic-gate uint16_t sport_mask; /* mask for sport key */ 1287c478bd9Sstevel@tonic-gate uint16_t dport; /* destination port key */ 1297c478bd9Sstevel@tonic-gate uint16_t dport_mask; /* mask for dport key */ 1307c478bd9Sstevel@tonic-gate 1317c478bd9Sstevel@tonic-gate /* filter ranking variables */ 1327c478bd9Sstevel@tonic-gate uint32_t precedence; /* precedence value for filter */ 1337c478bd9Sstevel@tonic-gate uint32_t priority; /* filter priority */ 1347c478bd9Sstevel@tonic-gate 1357c478bd9Sstevel@tonic-gate /* 1367c478bd9Sstevel@tonic-gate * filter_type accepted values = 1377c478bd9Sstevel@tonic-gate * IPGPC_GENERIC_FLTR | IPGPC_V4_FLTR | 1387c478bd9Sstevel@tonic-gate * IPGPC_V6_FLTR 1397c478bd9Sstevel@tonic-gate */ 1407c478bd9Sstevel@tonic-gate uint8_t filter_type; 1417c478bd9Sstevel@tonic-gate int32_t filter_instance; /* filter instance number, -1 if unused */ 1427c478bd9Sstevel@tonic-gate uint32_t originator; /* originator of this config item */ 1437c478bd9Sstevel@tonic-gate char *filter_comment; /* optional and unused by ipgpc */ 1447c478bd9Sstevel@tonic-gate } ipgpc_filter_t; 1457c478bd9Sstevel@tonic-gate 1467c478bd9Sstevel@tonic-gate typedef struct ipgpc_class_stats_s { 1477c478bd9Sstevel@tonic-gate ipp_action_id_t next_action; /* next action id */ 1487c478bd9Sstevel@tonic-gate hrtime_t last_match; /* hrtime value of last match to class */ 1497c478bd9Sstevel@tonic-gate uint64_t nbytes; /* number of matching bytes */ 1507c478bd9Sstevel@tonic-gate uint64_t npackets; /* number of matching packets */ 1517c478bd9Sstevel@tonic-gate } ipgpc_class_stats_t; 1527c478bd9Sstevel@tonic-gate 1537c478bd9Sstevel@tonic-gate /* linked list Element node structure */ 1547c478bd9Sstevel@tonic-gate typedef struct element_node_s *linked_list; 1557c478bd9Sstevel@tonic-gate typedef struct element_node_s *plink; 1567c478bd9Sstevel@tonic-gate typedef struct element_node_s { 1577c478bd9Sstevel@tonic-gate plink next; 1587c478bd9Sstevel@tonic-gate void (*element_ref)(struct element_node_s *); 1597c478bd9Sstevel@tonic-gate void (*element_unref)(struct element_node_s *); 1607c478bd9Sstevel@tonic-gate int id; 1617c478bd9Sstevel@tonic-gate uint32_t element_refcnt; 1627c478bd9Sstevel@tonic-gate } element_node_t; 1637c478bd9Sstevel@tonic-gate 1647c478bd9Sstevel@tonic-gate /* trie node structure */ 1657c478bd9Sstevel@tonic-gate typedef struct node_s *node_p; 1667c478bd9Sstevel@tonic-gate typedef struct node_s { 1677c478bd9Sstevel@tonic-gate linked_list elements; /* pointer to element list */ 1687c478bd9Sstevel@tonic-gate node_p zero; /* left link */ 1697c478bd9Sstevel@tonic-gate node_p one; /* right link */ 1707c478bd9Sstevel@tonic-gate uint32_t val; /* value of bits covered */ 1717c478bd9Sstevel@tonic-gate uint32_t mask; /* mask of bits covered */ 1727c478bd9Sstevel@tonic-gate uint8_t bits; /* number of bits covered by this node */ 1737c478bd9Sstevel@tonic-gate uint8_t pos; /* starting position of bits covered */ 1747c478bd9Sstevel@tonic-gate uint16_t isroot; /* 1 if is root node, 0 otherwise */ 1757c478bd9Sstevel@tonic-gate } node_t; 1767c478bd9Sstevel@tonic-gate typedef node_p trie; 1777c478bd9Sstevel@tonic-gate 1787c478bd9Sstevel@tonic-gate /* hashtable node structure */ 1797c478bd9Sstevel@tonic-gate typedef struct ht_node_s *hash_table; 1807c478bd9Sstevel@tonic-gate typedef struct ht_node_s *ht_node_p; 1817c478bd9Sstevel@tonic-gate typedef struct ht_node_s { 1827c478bd9Sstevel@tonic-gate ht_node_p next; /* link to next node in chain */ 1837c478bd9Sstevel@tonic-gate linked_list elements; /* elements stored at this node */ 1847c478bd9Sstevel@tonic-gate int key; /* key stored at this node */ 1857c478bd9Sstevel@tonic-gate int info; 1867c478bd9Sstevel@tonic-gate } ht_node_t; 1877c478bd9Sstevel@tonic-gate 1887c478bd9Sstevel@tonic-gate /* behavior aggregate table element structure */ 1897c478bd9Sstevel@tonic-gate typedef struct ba_table_element_s { 1907c478bd9Sstevel@tonic-gate linked_list filter_list; /* list of filters */ 1917c478bd9Sstevel@tonic-gate uint32_t info; 1927c478bd9Sstevel@tonic-gate } ba_table_element_t; 1937c478bd9Sstevel@tonic-gate 1947c478bd9Sstevel@tonic-gate /* behavior aggregate table structure */ 1957c478bd9Sstevel@tonic-gate typedef struct ba_table_s { 1967c478bd9Sstevel@tonic-gate linked_list masks; /* list of loaded masks */ 1977c478bd9Sstevel@tonic-gate ba_table_element_t masked_values[256]; /* table of masked values */ 1987c478bd9Sstevel@tonic-gate } ba_table_t; 1997c478bd9Sstevel@tonic-gate 2007c478bd9Sstevel@tonic-gate /* selector information structure */ 2017c478bd9Sstevel@tonic-gate typedef struct sel_info_s { 2027c478bd9Sstevel@tonic-gate uint16_t mask; /* mask for marking */ 2037c478bd9Sstevel@tonic-gate boolean_t dontcareonly; /* true if only don't cares are loaded */ 2047c478bd9Sstevel@tonic-gate } sel_info_t; 2057c478bd9Sstevel@tonic-gate 2067c478bd9Sstevel@tonic-gate /* selector statistics structure */ 2077c478bd9Sstevel@tonic-gate typedef struct sel_stats_s { 2087c478bd9Sstevel@tonic-gate uint32_t num_inserted; /* number of nodes that are not dontcares */ 2097c478bd9Sstevel@tonic-gate uint32_t num_dontcare; /* number of nodes that are dontcares */ 2107c478bd9Sstevel@tonic-gate } sel_stats_t; 2117c478bd9Sstevel@tonic-gate 2127c478bd9Sstevel@tonic-gate /* identification structure for a trie */ 2137c478bd9Sstevel@tonic-gate typedef struct trie_id_s { 2147c478bd9Sstevel@tonic-gate trie trie; /* pointer to the trie structure */ 2157c478bd9Sstevel@tonic-gate krwlock_t rw_lock; /* lock protecting this trie */ 2167c478bd9Sstevel@tonic-gate size_t key_len; /* length (bits) of the key for a lookup */ 2177c478bd9Sstevel@tonic-gate sel_stats_t stats; /* selector statistics strucutre */ 2187c478bd9Sstevel@tonic-gate sel_info_t info; /* selector info structure */ 2197c478bd9Sstevel@tonic-gate } trie_id_t; 2207c478bd9Sstevel@tonic-gate 2217c478bd9Sstevel@tonic-gate /* identification structure for a table */ 2227c478bd9Sstevel@tonic-gate typedef struct table_id_s { 2237c478bd9Sstevel@tonic-gate hash_table table; /* pointer to the hash table structure */ 2247c478bd9Sstevel@tonic-gate int wildcard; /* wildcard value for this selector */ 2257c478bd9Sstevel@tonic-gate sel_stats_t stats; /* selector statistics strucutre */ 2267c478bd9Sstevel@tonic-gate sel_info_t info; /* selector info structure */ 2277c478bd9Sstevel@tonic-gate } table_id_t; 2287c478bd9Sstevel@tonic-gate 2297c478bd9Sstevel@tonic-gate /* identification structure for a ba_table */ 2307c478bd9Sstevel@tonic-gate typedef struct ba_table_id_s { 2317c478bd9Sstevel@tonic-gate ba_table_t table; 2327c478bd9Sstevel@tonic-gate kmutex_t lock; /* ba table lock */ 2337c478bd9Sstevel@tonic-gate sel_info_t info; /* selector info structure */ 2347c478bd9Sstevel@tonic-gate sel_stats_t stats; /* selector statistics structure */ 2357c478bd9Sstevel@tonic-gate } ba_table_id_t; 2367c478bd9Sstevel@tonic-gate 2377c478bd9Sstevel@tonic-gate /* class definition structure */ 2387c478bd9Sstevel@tonic-gate typedef struct ipgpc_class_s { 2397c478bd9Sstevel@tonic-gate ipp_action_id_t next_action; /* id of action at head of list */ 2407c478bd9Sstevel@tonic-gate boolean_t gather_stats; /* are stats desired? B_TRUE or B_FALSE */ 2417c478bd9Sstevel@tonic-gate uint32_t originator; /* originator of this config item */ 2427c478bd9Sstevel@tonic-gate char class_name[MAXNAMELEN]; /* name of classification */ 2437c478bd9Sstevel@tonic-gate } ipgpc_class_t; 2447c478bd9Sstevel@tonic-gate 2457c478bd9Sstevel@tonic-gate /* filter id association data structure */ 2467c478bd9Sstevel@tonic-gate typedef struct fid_s { 2477c478bd9Sstevel@tonic-gate int info; /* 0 if unused, -1 if dirty, 1 if used */ 2487c478bd9Sstevel@tonic-gate int class_id; /* id of class associated with filter */ 2497c478bd9Sstevel@tonic-gate uint16_t insert_map; /* selectors w/ values inserted for this fid */ 2507c478bd9Sstevel@tonic-gate ipgpc_filter_t filter; /* filter structure that this fid describes */ 2517c478bd9Sstevel@tonic-gate } fid_t; 2527c478bd9Sstevel@tonic-gate 2537c478bd9Sstevel@tonic-gate /* class_id structure */ 2547c478bd9Sstevel@tonic-gate typedef struct cid_s { 2557c478bd9Sstevel@tonic-gate linked_list filter_list; /* list of filters associated with class */ 2567c478bd9Sstevel@tonic-gate int info; /* 0 if unused, -1 if dirty, 1 if used */ 2577c478bd9Sstevel@tonic-gate ipgpc_class_t aclass; /* the class structure this cid describes */ 2587c478bd9Sstevel@tonic-gate ipp_stat_t *cl_stats; /* kstats structure */ 2597c478bd9Sstevel@tonic-gate ipgpc_class_stats_t stats; /* statistics structure for class */ 2607c478bd9Sstevel@tonic-gate } cid_t; 2617c478bd9Sstevel@tonic-gate 2627c478bd9Sstevel@tonic-gate /* ipp_stat global stats structure */ 2637c478bd9Sstevel@tonic-gate typedef struct globalstats_s { 2647c478bd9Sstevel@tonic-gate ipp_named_t nfilters; 2657c478bd9Sstevel@tonic-gate ipp_named_t nclasses; 2667c478bd9Sstevel@tonic-gate ipp_named_t nbytes; 2677c478bd9Sstevel@tonic-gate ipp_named_t npackets; 2687c478bd9Sstevel@tonic-gate ipp_named_t epackets; 2697c478bd9Sstevel@tonic-gate } globalstats_t; 2707c478bd9Sstevel@tonic-gate 2717c478bd9Sstevel@tonic-gate /* ipp_stat class stats structure */ 2727c478bd9Sstevel@tonic-gate typedef struct classstats_s { 2737c478bd9Sstevel@tonic-gate ipp_named_t nbytes; 2747c478bd9Sstevel@tonic-gate ipp_named_t npackets; 2757c478bd9Sstevel@tonic-gate ipp_named_t last_match; 2767c478bd9Sstevel@tonic-gate } classstats_t; 2777c478bd9Sstevel@tonic-gate 2787c478bd9Sstevel@tonic-gate /* matching hash table element */ 2797c478bd9Sstevel@tonic-gate typedef struct ht_match_s *ht_chain; 2807c478bd9Sstevel@tonic-gate typedef struct ht_match_s { 2817c478bd9Sstevel@tonic-gate ht_chain next; /* link to next node in chain */ 2827c478bd9Sstevel@tonic-gate int key; /* key stored at this node in the table */ 2837c478bd9Sstevel@tonic-gate uint16_t match_map; /* match map for this id */ 2847c478bd9Sstevel@tonic-gate } ht_match_t; 2857c478bd9Sstevel@tonic-gate 2867c478bd9Sstevel@tonic-gate extern kmem_cache_t *ht_node_cache; 2877c478bd9Sstevel@tonic-gate extern kmem_cache_t *element_node_cache; 2887c478bd9Sstevel@tonic-gate extern kmem_cache_t *ht_match_cache; 2897c478bd9Sstevel@tonic-gate extern kmem_cache_t *trie_node_cache; 2907c478bd9Sstevel@tonic-gate 2917c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2927c478bd9Sstevel@tonic-gate } 2937c478bd9Sstevel@tonic-gate #endif 2947c478bd9Sstevel@tonic-gate 2957c478bd9Sstevel@tonic-gate #endif /* _IPP_IPGPC_CLASSIFIER_OBJECTS_H */ 296