4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #ifndef _IPP_FLOWACCT_FLOWACCT_IMPL_H
28 #define _IPP_FLOWACCT_FLOWACCT_IMPL_H
30 #pragma ident "%Z%%M% %I% %E% SMI"
32 #include <sys/types.h>
33 #include <sys/cmn_err.h>
35 #include <inet/ipp_common.h>
36 #include <ipp/flowacct/flowacct.h>
42 /* Header file for implementation of flowacct */
46 #define _FLOWACCT_DEBUG
48 #ifdef _FLOWACCT_DEBUG
49 #include <sys/debug.h>
50 #define flowacct0dbg(a) printf a
51 #define flowacct1dbg(a) if (flowacct_debug > 2) printf a
52 #define flowacct2dbg(a) if (flowacct_debug > 3) printf a
54 #define flowacct0dbg(a) /* */
55 #define flowacct1dbg(a) /* */
56 #define flowacct2dbg(a) /* */
57 #endif /* _FLOWACCT_DEBUG */
59 #define FLOWACCT_PURGE_FLOW 0x01
60 #define FLOWACCT_FLOW_TIMER 0x02
61 #define FLOWACCT_JUST_ONE 0x03
64 #define FLOW_TBL_COUNT ((uint_t)256)
66 /* To identify objects in the list - could be a flow or an item */
67 #define FLOWACCT_FLOW 0x01
68 #define FLOWACCT_ITEM 0x02
70 /* Whether an object has to be physically removed from the table */
71 #define FLOWACCT_DEL_OBJ 0x01
73 /* Utility macros to convert from msec to usec/nsec */
74 #define FLOWACCT_MSEC_TO_USEC (1000)
75 #define FLOWACCT_MSEC_TO_NSEC (1000000)
78 * Default values for timer and timeout - taken from SBM
79 * timer 15 secs (15000 msec) and timeout 60 secs (60000 msec).
81 #define FLOWACCT_DEF_TIMER (15000)
82 #define FLOWACCT_DEF_TIMEOUT (60000)
84 /* List holding an obj - flow or item */
85 typedef struct list_hdr_s
{
86 struct list_hdr_s
*next
;
87 struct list_hdr_s
*prev
;
88 struct list_hdr_s
*timeout_next
;
89 struct list_hdr_s
*timeout_prev
;
94 /* List of list of flows */
95 typedef struct list_head_s
{
103 /* Global stats for flowacct */
104 typedef struct flowacct_stat_s
{
105 ipp_named_t npackets
; /* no. of pkts seen by this instance */
106 ipp_named_t nbytes
; /* no. of bytes seen by this instance */
107 ipp_named_t nflows
; /* no. of flow items in the table */
108 ipp_named_t tbytes
; /* no. of bytes in the flow table */
109 ipp_named_t usedmem
; /* memory used by the flow table */
110 ipp_named_t epackets
; /* no. of pkts. in error */
113 #define FLOWACCT_STATS_COUNT 6
114 #define FLOWACCT_STATS_STRING "Flowacct statistics"
116 /* Item common to a flow (identified by 5-tuple) */
117 typedef struct flow_item_s
{
120 timespec_t creation_time
;
128 /* Flow attributes */
129 typedef struct flow_s
{
138 list_head_t
*back_ptr
;
141 * to indicate to the flow timer not to delete this flow
146 /* From the IP header */
147 typedef struct header
{
164 typedef struct flowacct_data_s
{
165 ipp_action_id_t next_action
; /* action id of next action */
166 char *act_name
; /* action name of next action */
167 uint64_t timer
; /* flow timer */
168 uint64_t timeout
; /* flow timeout */
169 uint32_t max_limit
; /* max flow entries */
170 uint32_t nflows
; /* no. of flows */
171 kmutex_t lock
; /* for nflows */
173 /* TRhe flow table. We'll use the last bucket for timeout purposes */
174 list_head_t flows_tbl
[FLOW_TBL_COUNT
+1];
175 boolean_t global_stats
; /* global stats */
177 uint64_t tbytes
; /* no. of bytes in flow tbl. */
178 uint64_t nbytes
; /* no. of bytes seen */
179 uint64_t npackets
; /* no. of pkts seen */
180 uint64_t usedmem
; /* mem used by flow table */
181 uint64_t epackets
; /* packets in error */
183 timeout_id_t flow_tid
;
187 #define FLOWACCT_DATA_SZ sizeof (flowacct_data_t)
188 #define FLOWACCT_HDR_SZ sizeof (list_hdr_t)
189 #define FLOWACCT_HEAD_SZ sizeof (list_head_t)
190 #define FLOWACCT_FLOW_SZ sizeof (flow_t)
191 #define FLOWACCT_ITEM_SZ sizeof (flow_item_t)
192 #define FLOWACCT_HEADER_SZ sizeof (header_t)
193 #define FLOWACCT_FLOW_RECORD_SZ (FLOWACCT_HDR_SZ + FLOWACCT_FLOW_SZ)
194 #define FLOWACCT_ITEM_RECORD_SZ (FLOWACCT_HDR_SZ + FLOWACCT_ITEM_SZ)
196 extern int flowacct_process(mblk_t
**, flowacct_data_t
*);
197 extern void flowacct_timer(int, flowacct_data_t
*);
198 extern void flowacct_timeout_flows(void *);
206 #endif /* _IPP_FLOWACCT_FLOWACCT_IMPL_H */