4 * Copyright (C) 1995-2001 by Darren Reed.
6 * See the IPFILTER.LICENCE file for details on licencing.
8 * @(#)ip_state.h 1.3 1/12/96 (C) 1995 Darren Reed
9 * Id: ip_state.h,v 2.68.2.12 2008/11/06 21:18:38 darrenr Exp
11 #ifndef _NETINET_IP_STATE_H_
12 #define _NETINET_IP_STATE_H_
14 #if defined(__STDC__) || defined(__GNUC__) || defined(_AIX51)
15 # define SIOCDELST _IOW('r', 61, struct ipfobj)
17 # define SIOCDELST _IOW(r, 61, struct ipfobj)
23 # define IPSTATE_SIZE 5737
26 # define IPSTATE_MAX 4013 /* Maximum number of states held */
29 #define SEQ_GE(a,b) ((int)((a) - (b)) >= 0)
30 #define SEQ_GT(a,b) ((int)((a) - (b)) > 0)
33 typedef struct ipstate
{
35 struct ipstate
*is_next
;
36 struct ipstate
**is_pnext
;
37 struct ipstate
*is_hnext
;
38 struct ipstate
**is_phnext
;
39 struct ipstate
**is_me
;
43 struct ipftq
*is_tqehead
[2];
44 struct ipscan
*is_isc
;
47 U_QUAD_T is_icmppkts
[4];
48 struct ipftqent is_sti
;
50 int is_ref
; /* reference count */
56 u_char is_p
; /* Protocol */
60 u_32_t is_opt
[2]; /* packet options set */
61 u_32_t is_optmsk
[2]; /* " " mask */
62 u_short is_sec
; /* security options set */
63 u_short is_secmsk
; /* " " mask */
64 u_short is_auth
; /* authentication options set */
65 u_short is_authmsk
; /* " " mask */
74 u_32_t is_rulen
; /* rule number when created */
77 char is_group
[FR_GROUPLEN
];
79 char is_ifname
[4][LIFNAMSIZ
];
82 #define is_die is_sti.tqe_die
83 #define is_state is_sti.tqe_state
84 #define is_touched is_sti.tqe_touched
85 #define is_saddr is_src.in4.s_addr
86 #define is_daddr is_dst.in4.s_addr
87 #define is_icmp is_ps.is_ics
88 #define is_type is_icmp.ici_type
89 #define is_code is_icmp.ici_code
90 #define is_tcp is_ps.is_ts
91 #define is_udp is_ps.is_us
92 #define is_send is_tcp.ts_data[0].td_end
93 #define is_dend is_tcp.ts_data[1].td_end
94 #define is_maxswin is_tcp.ts_data[0].td_maxwin
95 #define is_maxdwin is_tcp.ts_data[1].td_maxwin
96 #define is_maxsend is_tcp.ts_data[0].td_maxend
97 #define is_maxdend is_tcp.ts_data[1].td_maxend
98 #define is_swinscale is_tcp.ts_data[0].td_winscale
99 #define is_dwinscale is_tcp.ts_data[1].td_winscale
100 #define is_swinflags is_tcp.ts_data[0].td_winflags
101 #define is_dwinflags is_tcp.ts_data[1].td_winflags
102 #define is_sport is_tcp.ts_sport
103 #define is_dport is_tcp.ts_dport
104 #define is_ifpin is_ifp[0]
105 #define is_ifpout is_ifp[2]
106 #define is_gre is_ps.is_ug
107 #define is_call is_gre.gs_call
109 #define IS_WSPORT SI_W_SPORT /* 0x00100 */
110 #define IS_WDPORT SI_W_DPORT /* 0x00200 */
111 #define IS_WSADDR SI_W_SADDR /* 0x00400 */
112 #define IS_WDADDR SI_W_DADDR /* 0x00800 */
113 #define IS_NEWFR SI_NEWFR /* 0x01000 */
114 #define IS_CLONE SI_CLONE /* 0x02000 */
115 #define IS_CLONED SI_CLONED /* 0x04000 */
116 #define IS_TCPFSM 0x10000
117 #define IS_STRICT 0x20000
118 #define IS_ISNSYN 0x40000
119 #define IS_ISNACK 0x80000
120 #define IS_STATESYNC 0x100000
122 * IS_SC flags are for scan-operations that need to be recognised in state.
124 #define IS_SC_CLIENT 0x10000000
125 #define IS_SC_SERVER 0x20000000
126 #define IS_SC_MATCHC 0x40000000
127 #define IS_SC_MATCHS 0x80000000
128 #define IS_SC_MATCHALL (IS_SC_MATCHC|IS_SC_MATCHC)
129 #define IS_SC_ALL (IS_SC_MATCHC|IS_SC_MATCHC|IS_SC_CLIENT|IS_SC_SERVER)
132 * Flags that can be passed into fr_addstate
134 #define IS_INHERITED 0x0fffff00
136 #define TH_OPENING (TH_SYN|TH_ACK)
139 * Bits 0 - 3 are use as a mask with the current packet's bits to check for
140 * whether it is short, tcp/udp, a fragment or the presence of IP options.
141 * Bits 4 - 7 are set from the initial packet and contain what the packet
142 * anded with bits 0-3 must match.
143 * Bits 8,9 are used to indicate wildcard source/destination port matching.
144 * Bits 10,11 are reserved for other wildcard flag compatibility.
145 * Bits 12,13 are for scaning.
148 typedef struct ipstate_save
{
150 struct ipstate ips_is
;
151 struct frentry ips_fr
;
154 #define ips_rule ips_is.is_rule
157 typedef struct ipslog
{
158 U_QUAD_T isl_pkts
[4];
159 U_QUAD_T isl_bytes
[4];
165 u_short isl_filler
[2];
166 u_short isl_ports
[2];
174 char isl_group
[FR_GROUPLEN
];
177 #define isl_sport isl_ps.isl_ports[0]
178 #define isl_dport isl_ps.isl_ports[1]
179 #define isl_itype isl_ps.isl_icmp
183 #define ISL_EXPIRE 0xffff
184 #define ISL_FLUSH 0xfffe
185 #define ISL_REMOVE 0xfffd
186 #define ISL_INTERMEDIATE 0xfffc
187 #define ISL_KILLED 0xfffb
188 #define ISL_ORPHAN 0xfffa
189 #define ISL_UNLOAD 0xfff9
192 typedef struct ips_stat
{
210 u_long iss_bucketfull
;
213 ipstate_t
**iss_table
;
215 u_long
*iss_bucketlen
;
220 extern u_long fr_tcpidletimeout
;
221 extern u_long fr_tcpclosewait
;
222 extern u_long fr_tcplastack
;
223 extern u_long fr_tcptimeout
;
224 extern u_long fr_tcpclosed
;
225 extern u_long fr_tcptimewait
;
226 extern u_long fr_tcphalfclosed
;
227 extern u_long fr_udptimeout
;
228 extern u_long fr_udpacktimeout
;
229 extern u_long fr_icmptimeout
;
230 extern u_long fr_icmpacktimeout
;
231 extern u_long fr_iptimeout
;
232 extern int fr_statemax
;
233 extern int fr_statesize
;
234 extern int fr_state_lock
;
235 extern int fr_state_maxbucket
;
236 extern int fr_state_maxbucket_reset
;
237 extern ipstate_t
*ips_list
;
238 extern ipftq_t
*ips_utqe
;
239 extern ipftq_t ips_tqtqb
[IPF_TCP_NSTATES
];
241 extern int fr_stateinit
__P((void));
242 extern ipstate_t
*fr_addstate
__P((fr_info_t
*, ipstate_t
**, u_int
));
243 extern frentry_t
*fr_checkstate
__P((struct fr_info
*, u_32_t
*));
244 extern ipstate_t
*fr_stlookup
__P((fr_info_t
*, tcphdr_t
*, ipftq_t
**));
245 extern void fr_statesync
__P((void *));
246 extern void fr_timeoutstate
__P((void));
247 extern int fr_tcp_age
__P((struct ipftqent
*, struct fr_info
*,
248 struct ipftq
*, int));
249 extern int fr_tcpinwindow
__P((struct fr_info
*, struct tcpdata
*,
250 struct tcpdata
*, tcphdr_t
*, int));
251 extern void fr_stateunload
__P((void));
252 extern void ipstate_log
__P((struct ipstate
*, u_int
));
253 extern int fr_state_ioctl
__P((void *, ioctlcmd_t
, int, int, void *));
254 extern void fr_stinsert
__P((struct ipstate
*, int));
255 extern void fr_sttab_init
__P((struct ipftq
*));
256 extern void fr_sttab_destroy
__P((struct ipftq
*));
257 extern void fr_updatestate
__P((fr_info_t
*, ipstate_t
*, ipftq_t
*));
258 extern void fr_statederef
__P((ipstate_t
**));
259 extern void fr_setstatequeue
__P((ipstate_t
*, int));
260 extern int fr_state_flush
__P((int, int));
262 #endif /* _NETINET_IP_STATE_H_ */