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*3902Svi117747 * Common Development and Distribution License (the "License"). 6*3902Svi117747 * 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 */ 21*3902Svi117747 220Sstevel@tonic-gate /* 23*3902Svi117747 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #ifndef _IPP_FLOWACCT_FLOWACCT_IMPL_H 280Sstevel@tonic-gate #define _IPP_FLOWACCT_FLOWACCT_IMPL_H 290Sstevel@tonic-gate 300Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 310Sstevel@tonic-gate 320Sstevel@tonic-gate #include <sys/types.h> 330Sstevel@tonic-gate #include <sys/cmn_err.h> 340Sstevel@tonic-gate #include <ipp/ipp.h> 350Sstevel@tonic-gate #include <inet/ipp_common.h> 360Sstevel@tonic-gate #include <ipp/flowacct/flowacct.h> 370Sstevel@tonic-gate 380Sstevel@tonic-gate #ifdef __cplusplus 390Sstevel@tonic-gate extern "C" { 400Sstevel@tonic-gate #endif 410Sstevel@tonic-gate 420Sstevel@tonic-gate /* Header file for implementation of flowacct */ 430Sstevel@tonic-gate 440Sstevel@tonic-gate #ifdef _KERNEL 450Sstevel@tonic-gate 460Sstevel@tonic-gate #define _FLOWACCT_DEBUG 470Sstevel@tonic-gate 480Sstevel@tonic-gate #ifdef _FLOWACCT_DEBUG 490Sstevel@tonic-gate #include <sys/debug.h> 500Sstevel@tonic-gate #define flowacct0dbg(a) printf a 510Sstevel@tonic-gate #define flowacct1dbg(a) if (flowacct_debug > 2) printf a 520Sstevel@tonic-gate #define flowacct2dbg(a) if (flowacct_debug > 3) printf a 530Sstevel@tonic-gate #else 540Sstevel@tonic-gate #define flowacct0dbg(a) /* */ 550Sstevel@tonic-gate #define flowacct1dbg(a) /* */ 560Sstevel@tonic-gate #define flowacct2dbg(a) /* */ 570Sstevel@tonic-gate #endif /* _FLOWACCT_DEBUG */ 580Sstevel@tonic-gate 590Sstevel@tonic-gate #define FLOWACCT_PURGE_FLOW 0x01 600Sstevel@tonic-gate #define FLOWACCT_FLOW_TIMER 0x02 610Sstevel@tonic-gate #define FLOWACCT_JUST_ONE 0x03 620Sstevel@tonic-gate 630Sstevel@tonic-gate /* Flow Table Size */ 640Sstevel@tonic-gate #define FLOW_TBL_COUNT ((uint_t)256) 650Sstevel@tonic-gate 660Sstevel@tonic-gate /* To identify objects in the list - could be a flow or an item */ 670Sstevel@tonic-gate #define FLOWACCT_FLOW 0x01 680Sstevel@tonic-gate #define FLOWACCT_ITEM 0x02 690Sstevel@tonic-gate 700Sstevel@tonic-gate /* Whether an object has to be physically removed from the table */ 710Sstevel@tonic-gate #define FLOWACCT_DEL_OBJ 0x01 720Sstevel@tonic-gate 730Sstevel@tonic-gate /* Utility macros to convert from msec to usec/nsec */ 740Sstevel@tonic-gate #define FLOWACCT_MSEC_TO_USEC (1000) 750Sstevel@tonic-gate #define FLOWACCT_MSEC_TO_NSEC (1000000) 760Sstevel@tonic-gate 770Sstevel@tonic-gate /* 780Sstevel@tonic-gate * Default values for timer and timeout - taken from SBM 790Sstevel@tonic-gate * timer 15 secs (15000 msec) and timeout 60 secs (60000 msec). 800Sstevel@tonic-gate */ 810Sstevel@tonic-gate #define FLOWACCT_DEF_TIMER (15000) 820Sstevel@tonic-gate #define FLOWACCT_DEF_TIMEOUT (60000) 830Sstevel@tonic-gate 840Sstevel@tonic-gate /* List holding an obj - flow or item */ 850Sstevel@tonic-gate typedef struct list_hdr_s { 860Sstevel@tonic-gate struct list_hdr_s *next; 870Sstevel@tonic-gate struct list_hdr_s *prev; 880Sstevel@tonic-gate struct list_hdr_s *timeout_next; 890Sstevel@tonic-gate struct list_hdr_s *timeout_prev; 900Sstevel@tonic-gate timespec_t last_seen; 910Sstevel@tonic-gate void *objp; 920Sstevel@tonic-gate } list_hdr_t; 930Sstevel@tonic-gate 940Sstevel@tonic-gate /* List of list of flows */ 950Sstevel@tonic-gate typedef struct list_head_s { 960Sstevel@tonic-gate list_hdr_t *head; 970Sstevel@tonic-gate list_hdr_t *tail; 980Sstevel@tonic-gate uint_t nbr_items; 990Sstevel@tonic-gate uint_t max_items; 1000Sstevel@tonic-gate kmutex_t lock; 1010Sstevel@tonic-gate } list_head_t; 1020Sstevel@tonic-gate 1030Sstevel@tonic-gate /* Global stats for flowacct */ 1040Sstevel@tonic-gate typedef struct flowacct_stat_s { 1050Sstevel@tonic-gate ipp_named_t npackets; /* no. of pkts seen by this instance */ 1060Sstevel@tonic-gate ipp_named_t nbytes; /* no. of bytes seen by this instance */ 1070Sstevel@tonic-gate ipp_named_t nflows; /* no. of flow items in the table */ 1080Sstevel@tonic-gate ipp_named_t tbytes; /* no. of bytes in the flow table */ 1090Sstevel@tonic-gate ipp_named_t usedmem; /* memory used by the flow table */ 1100Sstevel@tonic-gate ipp_named_t epackets; /* no. of pkts. in error */ 1110Sstevel@tonic-gate } flowacct_stat_t; 1120Sstevel@tonic-gate 1130Sstevel@tonic-gate #define FLOWACCT_STATS_COUNT 6 1140Sstevel@tonic-gate #define FLOWACCT_STATS_STRING "Flowacct statistics" 1150Sstevel@tonic-gate 1160Sstevel@tonic-gate /* Item common to a flow (identified by 5-tuple) */ 1170Sstevel@tonic-gate typedef struct flow_item_s { 1180Sstevel@tonic-gate uint_t type; 1190Sstevel@tonic-gate list_hdr_t *hdr; 1200Sstevel@tonic-gate timespec_t creation_time; 1210Sstevel@tonic-gate uint64_t npackets; 1220Sstevel@tonic-gate uint64_t nbytes; 1230Sstevel@tonic-gate uint8_t dsfield; 1240Sstevel@tonic-gate projid_t projid; 1250Sstevel@tonic-gate uid_t uid; 1260Sstevel@tonic-gate } flow_item_t; 1270Sstevel@tonic-gate 1280Sstevel@tonic-gate /* Flow attributes */ 1290Sstevel@tonic-gate typedef struct flow_s { 1300Sstevel@tonic-gate uint_t type; 1310Sstevel@tonic-gate list_hdr_t *hdr; 1320Sstevel@tonic-gate in6_addr_t saddr; 1330Sstevel@tonic-gate in6_addr_t daddr; 1340Sstevel@tonic-gate uint8_t proto; 1350Sstevel@tonic-gate uint16_t sport; 1360Sstevel@tonic-gate uint16_t dport; 1370Sstevel@tonic-gate list_head_t items; 1380Sstevel@tonic-gate list_head_t *back_ptr; 1390Sstevel@tonic-gate boolean_t isv4; 140*3902Svi117747 /* 141*3902Svi117747 * to indicate to the flow timer not to delete this flow 142*3902Svi117747 */ 143*3902Svi117747 boolean_t inuse; 1440Sstevel@tonic-gate } flow_t; 1450Sstevel@tonic-gate 1460Sstevel@tonic-gate /* From the IP header */ 1470Sstevel@tonic-gate typedef struct header { 1480Sstevel@tonic-gate uint_t dir; 1490Sstevel@tonic-gate uint_t len; 1500Sstevel@tonic-gate in6_addr_t saddr; 1510Sstevel@tonic-gate in6_addr_t daddr; 1520Sstevel@tonic-gate uint16_t sport; 1530Sstevel@tonic-gate uint16_t dport; 1540Sstevel@tonic-gate uint16_t ident; 1550Sstevel@tonic-gate uint8_t proto; 1560Sstevel@tonic-gate uint8_t dsfield; 1570Sstevel@tonic-gate projid_t projid; 1580Sstevel@tonic-gate uid_t uid; 1590Sstevel@tonic-gate boolean_t isv4; 1600Sstevel@tonic-gate uint32_t pktlen; 1610Sstevel@tonic-gate } header_t; 1620Sstevel@tonic-gate 1630Sstevel@tonic-gate 1640Sstevel@tonic-gate typedef struct flowacct_data_s { 1650Sstevel@tonic-gate ipp_action_id_t next_action; /* action id of next action */ 1660Sstevel@tonic-gate char *act_name; /* action name of next action */ 1670Sstevel@tonic-gate uint64_t timer; /* flow timer */ 1680Sstevel@tonic-gate uint64_t timeout; /* flow timeout */ 1690Sstevel@tonic-gate uint32_t max_limit; /* max flow entries */ 1700Sstevel@tonic-gate uint32_t nflows; /* no. of flows */ 1710Sstevel@tonic-gate kmutex_t lock; /* for nflows */ 1720Sstevel@tonic-gate 1730Sstevel@tonic-gate /* TRhe flow table. We'll use the last bucket for timeout purposes */ 1740Sstevel@tonic-gate list_head_t flows_tbl[FLOW_TBL_COUNT+1]; 1750Sstevel@tonic-gate boolean_t global_stats; /* global stats */ 1760Sstevel@tonic-gate 1770Sstevel@tonic-gate uint64_t tbytes; /* no. of bytes in flow tbl. */ 1780Sstevel@tonic-gate uint64_t nbytes; /* no. of bytes seen */ 1790Sstevel@tonic-gate uint64_t npackets; /* no. of pkts seen */ 1800Sstevel@tonic-gate uint64_t usedmem; /* mem used by flow table */ 1810Sstevel@tonic-gate uint64_t epackets; /* packets in error */ 1820Sstevel@tonic-gate ipp_stat_t *stats; 1830Sstevel@tonic-gate timeout_id_t flow_tid; 1840Sstevel@tonic-gate 1850Sstevel@tonic-gate } flowacct_data_t; 1860Sstevel@tonic-gate 1870Sstevel@tonic-gate #define FLOWACCT_DATA_SZ sizeof (flowacct_data_t) 1880Sstevel@tonic-gate #define FLOWACCT_HDR_SZ sizeof (list_hdr_t) 1890Sstevel@tonic-gate #define FLOWACCT_HEAD_SZ sizeof (list_head_t) 1900Sstevel@tonic-gate #define FLOWACCT_FLOW_SZ sizeof (flow_t) 1910Sstevel@tonic-gate #define FLOWACCT_ITEM_SZ sizeof (flow_item_t) 1920Sstevel@tonic-gate #define FLOWACCT_HEADER_SZ sizeof (header_t) 1930Sstevel@tonic-gate #define FLOWACCT_FLOW_RECORD_SZ (FLOWACCT_HDR_SZ + FLOWACCT_FLOW_SZ) 1940Sstevel@tonic-gate #define FLOWACCT_ITEM_RECORD_SZ (FLOWACCT_HDR_SZ + FLOWACCT_ITEM_SZ) 1950Sstevel@tonic-gate 1960Sstevel@tonic-gate extern int flowacct_process(mblk_t **, flowacct_data_t *); 1970Sstevel@tonic-gate extern void flowacct_timer(int, flowacct_data_t *); 1980Sstevel@tonic-gate extern void flowacct_timeout_flows(void *); 1990Sstevel@tonic-gate 2000Sstevel@tonic-gate #endif /* _KERNEL */ 2010Sstevel@tonic-gate 2020Sstevel@tonic-gate #ifdef __cplusplus 2030Sstevel@tonic-gate } 2040Sstevel@tonic-gate #endif 2050Sstevel@tonic-gate 2060Sstevel@tonic-gate #endif /* _IPP_FLOWACCT_FLOWACCT_IMPL_H */ 207