10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*8485SPeter.Memishian@Sun.COM * Common Development and Distribution License (the "License"). 6*8485SPeter.Memishian@Sun.COM * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*8485SPeter.Memishian@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #ifndef _IPP_IPGPC_CLASSIFIER_OBJECTS_H 270Sstevel@tonic-gate #define _IPP_IPGPC_CLASSIFIER_OBJECTS_H 280Sstevel@tonic-gate 290Sstevel@tonic-gate #include <sys/time.h> 300Sstevel@tonic-gate #include <ipp/ipp.h> 310Sstevel@tonic-gate #include <ipp/ipgpc/ipgpc.h> 320Sstevel@tonic-gate 330Sstevel@tonic-gate #ifdef __cplusplus 340Sstevel@tonic-gate extern "C" { 350Sstevel@tonic-gate #endif 360Sstevel@tonic-gate 370Sstevel@tonic-gate /* common objects and defines used by the ipgpc code base */ 380Sstevel@tonic-gate 390Sstevel@tonic-gate /* default wildcard and unspecified value for selectors */ 400Sstevel@tonic-gate #define IPGPC_WILDCARD -1 410Sstevel@tonic-gate #define IPGPC_UNSPECIFIED 0 420Sstevel@tonic-gate 430Sstevel@tonic-gate /* trie id's */ 440Sstevel@tonic-gate #define IPGPC_TRIE_SPORTID 0 450Sstevel@tonic-gate #define IPGPC_TRIE_DPORTID 1 460Sstevel@tonic-gate #define IPGPC_TRIE_SADDRID 2 470Sstevel@tonic-gate #define IPGPC_TRIE_DADDRID 3 480Sstevel@tonic-gate 490Sstevel@tonic-gate /* 500Sstevel@tonic-gate * IPv6 trie id's 510Sstevel@tonic-gate * note: tries for SPORT, DPORT are shared between IPv4 and IPv6 filters 520Sstevel@tonic-gate */ 530Sstevel@tonic-gate #define IPGPC_TRIE_SADDRID6 4 540Sstevel@tonic-gate #define IPGPC_TRIE_DADDRID6 5 550Sstevel@tonic-gate 560Sstevel@tonic-gate /* ba table id's */ 570Sstevel@tonic-gate #define IPGPC_BA_DSID 6 580Sstevel@tonic-gate 590Sstevel@tonic-gate /* table id's */ 600Sstevel@tonic-gate #define IPGPC_TABLE_PROTOID 7 610Sstevel@tonic-gate #define IPGPC_TABLE_UID 8 620Sstevel@tonic-gate #define IPGPC_TABLE_PROJID 9 630Sstevel@tonic-gate #define IPGPC_TABLE_IF 10 64*8485SPeter.Memishian@Sun.COM #define IPGPC_TABLE_DIR 11 650Sstevel@tonic-gate #define TABLE_ID_OFFSET IPGPC_TABLE_PROTOID 660Sstevel@tonic-gate #define PROTOID_IDX (IPGPC_TABLE_PROTOID - TABLE_ID_OFFSET) 670Sstevel@tonic-gate #define UID_IDX (IPGPC_TABLE_UID - TABLE_ID_OFFSET) 680Sstevel@tonic-gate #define PROJID_IDX (IPGPC_TABLE_PROJID - TABLE_ID_OFFSET) 690Sstevel@tonic-gate #define IF_IDX (IPGPC_TABLE_IF - TABLE_ID_OFFSET) 700Sstevel@tonic-gate #define DIR_IDX (IPGPC_TABLE_DIR - TABLE_ID_OFFSET) 710Sstevel@tonic-gate 720Sstevel@tonic-gate /* Match types for selector searching */ 730Sstevel@tonic-gate #define NORMAL_MATCH 0 740Sstevel@tonic-gate #define NO_MATCHES 1 750Sstevel@tonic-gate #define DONTCARE_ONLY_MATCH 2 760Sstevel@tonic-gate 770Sstevel@tonic-gate /* match masks */ 780Sstevel@tonic-gate #define PROTO_MASK 0x01 790Sstevel@tonic-gate #define DS_MASK 0x02 800Sstevel@tonic-gate #define SPORT_MASK 0x04 810Sstevel@tonic-gate #define DPORT_MASK 0x08 820Sstevel@tonic-gate #define SADDR_MASK 0x10 830Sstevel@tonic-gate #define DADDR_MASK 0x20 840Sstevel@tonic-gate #define SADDR6_MASK SADDR_MASK 850Sstevel@tonic-gate #define DADDR6_MASK DADDR_MASK 860Sstevel@tonic-gate #define UID_MASK 0x40 870Sstevel@tonic-gate #define PROJID_MASK 0x80 880Sstevel@tonic-gate #define IF_MASK 0x100 89*8485SPeter.Memishian@Sun.COM #define DIR_MASK 0x200 900Sstevel@tonic-gate #define ALL_MATCH_MASK (DS_MASK | PROTO_MASK | SADDR_MASK | DADDR_MASK | \ 910Sstevel@tonic-gate SPORT_MASK | DPORT_MASK | UID_MASK | PROJID_MASK | \ 92*8485SPeter.Memishian@Sun.COM IF_MASK | DIR_MASK) 930Sstevel@tonic-gate 940Sstevel@tonic-gate #define HASH_SIZE 11 /* default hash table size */ 950Sstevel@tonic-gate 960Sstevel@tonic-gate /* used when inserting values into selector structures */ 970Sstevel@tonic-gate #define NORMAL_VALUE 0 /* a valid value was insert */ 980Sstevel@tonic-gate #define DONTCARE_VALUE 1 /* a dontcare/wildcard value was inserted */ 990Sstevel@tonic-gate 1000Sstevel@tonic-gate /* filter definition structure */ 1010Sstevel@tonic-gate typedef struct ipgpc_filter_s { 1020Sstevel@tonic-gate char filter_name[MAXNAMELEN]; /* null terminated name of filter */ 1030Sstevel@tonic-gate 1040Sstevel@tonic-gate /* exact match selectors */ 1050Sstevel@tonic-gate uid_t uid; /* uid key, value = exact or IPGPC_WILDCARD */ 1060Sstevel@tonic-gate projid_t projid; /* project id, " " */ 1070Sstevel@tonic-gate uint_t if_index; /* interface index, " " or 0 for wildcard */ 1080Sstevel@tonic-gate /* 1090Sstevel@tonic-gate * packet direction 1100Sstevel@tonic-gate * value = IPP_LOCAL_IN | IPP_LOCAL_OUT | 1110Sstevel@tonic-gate * IPP_FWD_IN | IPP_FWD_OUT | 0 for wildcard 1120Sstevel@tonic-gate */ 1130Sstevel@tonic-gate uint32_t direction; 1140Sstevel@tonic-gate uint8_t proto; /* protocol key, exact or 0 for wildcard */ 1150Sstevel@tonic-gate 1160Sstevel@tonic-gate /* non-exact match selectors */ 1170Sstevel@tonic-gate uint8_t dsfield; /* diffserv field key */ 1180Sstevel@tonic-gate uint8_t dsfield_mask; /* mask for diffserv field key */ 1190Sstevel@tonic-gate /* IP Addresses are represented as IPV6 address structures */ 1200Sstevel@tonic-gate in6_addr_t saddr; /* source address key */ 1210Sstevel@tonic-gate in6_addr_t saddr_mask; /* mask for saddr key */ 1220Sstevel@tonic-gate char *saddr_hostname; /* hostname of source address, optional */ 1230Sstevel@tonic-gate in6_addr_t daddr; /* destination address key */ 1240Sstevel@tonic-gate in6_addr_t daddr_mask; /* mask for daddr key */ 1250Sstevel@tonic-gate char *daddr_hostname; /* hostname of destination address, optional */ 1260Sstevel@tonic-gate uint16_t sport; /* source port key */ 1270Sstevel@tonic-gate uint16_t sport_mask; /* mask for sport key */ 1280Sstevel@tonic-gate uint16_t dport; /* destination port key */ 1290Sstevel@tonic-gate uint16_t dport_mask; /* mask for dport key */ 1300Sstevel@tonic-gate 1310Sstevel@tonic-gate /* filter ranking variables */ 1320Sstevel@tonic-gate uint32_t precedence; /* precedence value for filter */ 1330Sstevel@tonic-gate uint32_t priority; /* filter priority */ 1340Sstevel@tonic-gate 1350Sstevel@tonic-gate /* 1360Sstevel@tonic-gate * filter_type accepted values = 1370Sstevel@tonic-gate * IPGPC_GENERIC_FLTR | IPGPC_V4_FLTR | 1380Sstevel@tonic-gate * IPGPC_V6_FLTR 1390Sstevel@tonic-gate */ 1400Sstevel@tonic-gate uint8_t filter_type; 1410Sstevel@tonic-gate int32_t filter_instance; /* filter instance number, -1 if unused */ 1420Sstevel@tonic-gate uint32_t originator; /* originator of this config item */ 1430Sstevel@tonic-gate char *filter_comment; /* optional and unused by ipgpc */ 1440Sstevel@tonic-gate } ipgpc_filter_t; 1450Sstevel@tonic-gate 1460Sstevel@tonic-gate typedef struct ipgpc_class_stats_s { 1470Sstevel@tonic-gate ipp_action_id_t next_action; /* next action id */ 1480Sstevel@tonic-gate hrtime_t last_match; /* hrtime value of last match to class */ 1490Sstevel@tonic-gate uint64_t nbytes; /* number of matching bytes */ 1500Sstevel@tonic-gate uint64_t npackets; /* number of matching packets */ 1510Sstevel@tonic-gate } ipgpc_class_stats_t; 1520Sstevel@tonic-gate 1530Sstevel@tonic-gate /* linked list Element node structure */ 1540Sstevel@tonic-gate typedef struct element_node_s *linked_list; 1550Sstevel@tonic-gate typedef struct element_node_s *plink; 1560Sstevel@tonic-gate typedef struct element_node_s { 1570Sstevel@tonic-gate plink next; 1580Sstevel@tonic-gate void (*element_ref)(struct element_node_s *); 1590Sstevel@tonic-gate void (*element_unref)(struct element_node_s *); 1600Sstevel@tonic-gate int id; 1610Sstevel@tonic-gate uint32_t element_refcnt; 1620Sstevel@tonic-gate } element_node_t; 1630Sstevel@tonic-gate 1640Sstevel@tonic-gate /* trie node structure */ 1650Sstevel@tonic-gate typedef struct node_s *node_p; 1660Sstevel@tonic-gate typedef struct node_s { 1670Sstevel@tonic-gate linked_list elements; /* pointer to element list */ 1680Sstevel@tonic-gate node_p zero; /* left link */ 1690Sstevel@tonic-gate node_p one; /* right link */ 1700Sstevel@tonic-gate uint32_t val; /* value of bits covered */ 1710Sstevel@tonic-gate uint32_t mask; /* mask of bits covered */ 1720Sstevel@tonic-gate uint8_t bits; /* number of bits covered by this node */ 1730Sstevel@tonic-gate uint8_t pos; /* starting position of bits covered */ 1740Sstevel@tonic-gate uint16_t isroot; /* 1 if is root node, 0 otherwise */ 1750Sstevel@tonic-gate } node_t; 1760Sstevel@tonic-gate typedef node_p trie; 1770Sstevel@tonic-gate 1780Sstevel@tonic-gate /* hashtable node structure */ 1790Sstevel@tonic-gate typedef struct ht_node_s *hash_table; 1800Sstevel@tonic-gate typedef struct ht_node_s *ht_node_p; 1810Sstevel@tonic-gate typedef struct ht_node_s { 1820Sstevel@tonic-gate ht_node_p next; /* link to next node in chain */ 1830Sstevel@tonic-gate linked_list elements; /* elements stored at this node */ 1840Sstevel@tonic-gate int key; /* key stored at this node */ 1850Sstevel@tonic-gate int info; 1860Sstevel@tonic-gate } ht_node_t; 1870Sstevel@tonic-gate 1880Sstevel@tonic-gate /* behavior aggregate table element structure */ 1890Sstevel@tonic-gate typedef struct ba_table_element_s { 1900Sstevel@tonic-gate linked_list filter_list; /* list of filters */ 1910Sstevel@tonic-gate uint32_t info; 1920Sstevel@tonic-gate } ba_table_element_t; 1930Sstevel@tonic-gate 1940Sstevel@tonic-gate /* behavior aggregate table structure */ 1950Sstevel@tonic-gate typedef struct ba_table_s { 1960Sstevel@tonic-gate linked_list masks; /* list of loaded masks */ 1970Sstevel@tonic-gate ba_table_element_t masked_values[256]; /* table of masked values */ 1980Sstevel@tonic-gate } ba_table_t; 1990Sstevel@tonic-gate 2000Sstevel@tonic-gate /* selector information structure */ 2010Sstevel@tonic-gate typedef struct sel_info_s { 2020Sstevel@tonic-gate uint16_t mask; /* mask for marking */ 2030Sstevel@tonic-gate boolean_t dontcareonly; /* true if only don't cares are loaded */ 2040Sstevel@tonic-gate } sel_info_t; 2050Sstevel@tonic-gate 2060Sstevel@tonic-gate /* selector statistics structure */ 2070Sstevel@tonic-gate typedef struct sel_stats_s { 2080Sstevel@tonic-gate uint32_t num_inserted; /* number of nodes that are not dontcares */ 2090Sstevel@tonic-gate uint32_t num_dontcare; /* number of nodes that are dontcares */ 2100Sstevel@tonic-gate } sel_stats_t; 2110Sstevel@tonic-gate 2120Sstevel@tonic-gate /* identification structure for a trie */ 2130Sstevel@tonic-gate typedef struct trie_id_s { 2140Sstevel@tonic-gate trie trie; /* pointer to the trie structure */ 2150Sstevel@tonic-gate krwlock_t rw_lock; /* lock protecting this trie */ 2160Sstevel@tonic-gate size_t key_len; /* length (bits) of the key for a lookup */ 2170Sstevel@tonic-gate sel_stats_t stats; /* selector statistics strucutre */ 2180Sstevel@tonic-gate sel_info_t info; /* selector info structure */ 2190Sstevel@tonic-gate } trie_id_t; 2200Sstevel@tonic-gate 2210Sstevel@tonic-gate /* identification structure for a table */ 2220Sstevel@tonic-gate typedef struct table_id_s { 2230Sstevel@tonic-gate hash_table table; /* pointer to the hash table structure */ 2240Sstevel@tonic-gate int wildcard; /* wildcard value for this selector */ 2250Sstevel@tonic-gate sel_stats_t stats; /* selector statistics strucutre */ 2260Sstevel@tonic-gate sel_info_t info; /* selector info structure */ 2270Sstevel@tonic-gate } table_id_t; 2280Sstevel@tonic-gate 2290Sstevel@tonic-gate /* identification structure for a ba_table */ 2300Sstevel@tonic-gate typedef struct ba_table_id_s { 2310Sstevel@tonic-gate ba_table_t table; 2320Sstevel@tonic-gate kmutex_t lock; /* ba table lock */ 2330Sstevel@tonic-gate sel_info_t info; /* selector info structure */ 2340Sstevel@tonic-gate sel_stats_t stats; /* selector statistics structure */ 2350Sstevel@tonic-gate } ba_table_id_t; 2360Sstevel@tonic-gate 2370Sstevel@tonic-gate /* class definition structure */ 2380Sstevel@tonic-gate typedef struct ipgpc_class_s { 2390Sstevel@tonic-gate ipp_action_id_t next_action; /* id of action at head of list */ 2400Sstevel@tonic-gate boolean_t gather_stats; /* are stats desired? B_TRUE or B_FALSE */ 2410Sstevel@tonic-gate uint32_t originator; /* originator of this config item */ 2420Sstevel@tonic-gate char class_name[MAXNAMELEN]; /* name of classification */ 2430Sstevel@tonic-gate } ipgpc_class_t; 2440Sstevel@tonic-gate 2450Sstevel@tonic-gate /* filter id association data structure */ 2460Sstevel@tonic-gate typedef struct fid_s { 2470Sstevel@tonic-gate int info; /* 0 if unused, -1 if dirty, 1 if used */ 2480Sstevel@tonic-gate int class_id; /* id of class associated with filter */ 2490Sstevel@tonic-gate uint16_t insert_map; /* selectors w/ values inserted for this fid */ 2500Sstevel@tonic-gate ipgpc_filter_t filter; /* filter structure that this fid describes */ 2510Sstevel@tonic-gate } fid_t; 2520Sstevel@tonic-gate 2530Sstevel@tonic-gate /* class_id structure */ 2540Sstevel@tonic-gate typedef struct cid_s { 2550Sstevel@tonic-gate linked_list filter_list; /* list of filters associated with class */ 2560Sstevel@tonic-gate int info; /* 0 if unused, -1 if dirty, 1 if used */ 2570Sstevel@tonic-gate ipgpc_class_t aclass; /* the class structure this cid describes */ 2580Sstevel@tonic-gate ipp_stat_t *cl_stats; /* kstats structure */ 2590Sstevel@tonic-gate ipgpc_class_stats_t stats; /* statistics structure for class */ 2600Sstevel@tonic-gate } cid_t; 2610Sstevel@tonic-gate 2620Sstevel@tonic-gate /* ipp_stat global stats structure */ 2630Sstevel@tonic-gate typedef struct globalstats_s { 2640Sstevel@tonic-gate ipp_named_t nfilters; 2650Sstevel@tonic-gate ipp_named_t nclasses; 2660Sstevel@tonic-gate ipp_named_t nbytes; 2670Sstevel@tonic-gate ipp_named_t npackets; 2680Sstevel@tonic-gate ipp_named_t epackets; 2690Sstevel@tonic-gate } globalstats_t; 2700Sstevel@tonic-gate 2710Sstevel@tonic-gate /* ipp_stat class stats structure */ 2720Sstevel@tonic-gate typedef struct classstats_s { 2730Sstevel@tonic-gate ipp_named_t nbytes; 2740Sstevel@tonic-gate ipp_named_t npackets; 2750Sstevel@tonic-gate ipp_named_t last_match; 2760Sstevel@tonic-gate } classstats_t; 2770Sstevel@tonic-gate 2780Sstevel@tonic-gate /* matching hash table element */ 2790Sstevel@tonic-gate typedef struct ht_match_s *ht_chain; 2800Sstevel@tonic-gate typedef struct ht_match_s { 2810Sstevel@tonic-gate ht_chain next; /* link to next node in chain */ 2820Sstevel@tonic-gate int key; /* key stored at this node in the table */ 2830Sstevel@tonic-gate uint16_t match_map; /* match map for this id */ 2840Sstevel@tonic-gate } ht_match_t; 2850Sstevel@tonic-gate 2860Sstevel@tonic-gate extern kmem_cache_t *ht_node_cache; 2870Sstevel@tonic-gate extern kmem_cache_t *element_node_cache; 2880Sstevel@tonic-gate extern kmem_cache_t *ht_match_cache; 2890Sstevel@tonic-gate extern kmem_cache_t *trie_node_cache; 2900Sstevel@tonic-gate 2910Sstevel@tonic-gate #ifdef __cplusplus 2920Sstevel@tonic-gate } 2930Sstevel@tonic-gate #endif 2940Sstevel@tonic-gate 2950Sstevel@tonic-gate #endif /* _IPP_IPGPC_CLASSIFIER_OBJECTS_H */ 296