Deleted Added
full compact
ip_state.h (139255) ip_state.h (145522)
1/* $FreeBSD: head/sys/contrib/ipfilter/netinet/ip_state.h 145522 2005-04-25 18:43:14Z darrenr $ */
2
1/*
2 * Copyright (C) 1995-2001 by Darren Reed.
3 *
4 * See the IPFILTER.LICENCE file for details on licencing.
5 *
6 * @(#)ip_state.h 1.3 1/12/96 (C) 1995 Darren Reed
3/*
4 * Copyright (C) 1995-2001 by Darren Reed.
5 *
6 * See the IPFILTER.LICENCE file for details on licencing.
7 *
8 * @(#)ip_state.h 1.3 1/12/96 (C) 1995 Darren Reed
7 * $Id: ip_state.h,v 2.13.2.1 2000/07/08 02:15:35 darrenr Exp $
8 * $FreeBSD: head/sys/contrib/ipfilter/netinet/ip_state.h 139255 2004-12-24 09:14:26Z darrenr $
9 * $FreeBSD: head/sys/contrib/ipfilter/netinet/ip_state.h 145522 2005-04-25 18:43:14Z darrenr $
10 * Id: ip_state.h,v 2.68.2.3 2005/03/03 14:24:11 darrenr Exp
9 */
10#ifndef __IP_STATE_H__
11#define __IP_STATE_H__
12
13#if defined(__STDC__) || defined(__GNUC__)
11 */
12#ifndef __IP_STATE_H__
13#define __IP_STATE_H__
14
15#if defined(__STDC__) || defined(__GNUC__)
14# define SIOCDELST _IOW('r', 61, struct ipstate *)
16# define SIOCDELST _IOW('r', 61, struct ipfobj)
15#else
17#else
16# define SIOCDELST _IOW(r, 61, struct ipstate *)
18# define SIOCDELST _IOW(r, 61, struct ipfobj)
17#endif
18
19#endif
20
21struct ipscan;
22
19#ifndef IPSTATE_SIZE
20# define IPSTATE_SIZE 5737
21#endif
22#ifndef IPSTATE_MAX
23# define IPSTATE_MAX 4013 /* Maximum number of states held */
24#endif
25
26#define PAIRS(s1,d1,s2,d2) ((((s1) == (s2)) && ((d1) == (d2))) ||\
27 (((s1) == (d2)) && ((d1) == (s2))))
28#define IPPAIR(s1,d1,s2,d2) PAIRS((s1).s_addr, (d1).s_addr, \
29 (s2).s_addr, (d2).s_addr)
30
31
23#ifndef IPSTATE_SIZE
24# define IPSTATE_SIZE 5737
25#endif
26#ifndef IPSTATE_MAX
27# define IPSTATE_MAX 4013 /* Maximum number of states held */
28#endif
29
30#define PAIRS(s1,d1,s2,d2) ((((s1) == (s2)) && ((d1) == (d2))) ||\
31 (((s1) == (d2)) && ((d1) == (s2))))
32#define IPPAIR(s1,d1,s2,d2) PAIRS((s1).s_addr, (d1).s_addr, \
33 (s2).s_addr, (d2).s_addr)
34
35
32typedef struct udpstate {
33 u_short us_sport;
34 u_short us_dport;
35} udpstate_t;
36
37typedef struct icmpstate {
38 u_short ics_id;
39 u_short ics_seq;
40 u_char ics_type;
41} icmpstate_t;
42
43typedef struct tcpdata {
44 u_32_t td_end;
45 u_32_t td_maxend;
46 u_32_t td_maxwin;
47 u_char td_wscale;
48} tcpdata_t;
49
50typedef struct tcpstate {
51 u_short ts_sport;
52 u_short ts_dport;
53 tcpdata_t ts_data[2];
54 u_char ts_state[2];
55} tcpstate_t;
56
57typedef struct ipstate {
36typedef struct ipstate {
37 ipfmutex_t is_lock;
58 struct ipstate *is_next;
59 struct ipstate **is_pnext;
60 struct ipstate *is_hnext;
61 struct ipstate **is_phnext;
62 struct ipstate **is_me;
38 struct ipstate *is_next;
39 struct ipstate **is_pnext;
40 struct ipstate *is_hnext;
41 struct ipstate **is_phnext;
42 struct ipstate **is_me;
43 void *is_ifp[4];
44 void *is_sync;
45 struct nat *is_nat[2];
63 frentry_t *is_rule;
46 frentry_t *is_rule;
64 U_QUAD_T is_pkts;
65 U_QUAD_T is_bytes;
66 U_QUAD_T is_icmppkts;
67 union i6addr is_src;
68 union i6addr is_dst;
69 void *is_ifp[4];
70 u_long is_age;
71 u_int is_frage[2]; /* age from filter rule, forward & reverse */
47 struct ipftq *is_tqehead[2];
48 struct ipscan *is_isc;
49 U_QUAD_T is_pkts[4];
50 U_QUAD_T is_bytes[4];
51 U_QUAD_T is_icmppkts[4];
52 struct ipftqent is_sti;
53 u_int is_frage[2];
54 int is_ref; /* reference count */
55 int is_isninc[2];
56 u_short is_sumd[2];
57 i6addr_t is_src;
58 i6addr_t is_dst;
72 u_int is_pass;
73 u_char is_p; /* Protocol */
59 u_int is_pass;
60 u_char is_p; /* Protocol */
74 u_char is_v; /* IP version */
75 u_char is_fsm; /* 1 = following FSM, 0 = not */
76 u_char is_xxx; /* pad */
77 u_int is_hv; /* hash value for this in the table */
78 u_32_t is_rulen; /* rule number */
79 u_32_t is_flags; /* flags for this structure */
61 u_char is_v;
62 u_32_t is_hv;
63 u_32_t is_tag;
80 u_32_t is_opt; /* packet options set */
81 u_32_t is_optmsk; /* " " mask */
82 u_short is_sec; /* security options set */
83 u_short is_secmsk; /* " " mask */
84 u_short is_auth; /* authentication options set */
85 u_short is_authmsk; /* " " mask */
86 union {
64 u_32_t is_opt; /* packet options set */
65 u_32_t is_optmsk; /* " " mask */
66 u_short is_sec; /* security options set */
67 u_short is_secmsk; /* " " mask */
68 u_short is_auth; /* authentication options set */
69 u_short is_authmsk; /* " " mask */
70 union {
87 icmpstate_t is_ics;
88 tcpstate_t is_ts;
89 udpstate_t is_us;
71 icmpinfo_t is_ics;
72 tcpinfo_t is_ts;
73 udpinfo_t is_us;
74 greinfo_t is_ug;
90 } is_ps;
75 } is_ps;
91 u_32_t is_group;
92 char is_ifname[4][IFNAMSIZ];
93#if SOLARIS || defined(__sgi) || (__FreeBSD_version >= 500043)
94 kmutex_t is_lock;
95#endif
76 u_32_t is_flags;
77 int is_flx[2][2];
78 u_32_t is_rulen; /* rule number when created */
79 u_32_t is_s0[2];
80 u_short is_smsk[2];
81 char is_group[FR_GROUPLEN];
82 char is_sbuf[2][16];
83 char is_ifname[4][LIFNAMSIZ];
96} ipstate_t;
97
84} ipstate_t;
85
86#define is_die is_sti.tqe_die
87#define is_state is_sti.tqe_state
88#define is_touched is_sti.tqe_touched
98#define is_saddr is_src.in4.s_addr
99#define is_daddr is_dst.in4.s_addr
100#define is_icmp is_ps.is_ics
89#define is_saddr is_src.in4.s_addr
90#define is_daddr is_dst.in4.s_addr
91#define is_icmp is_ps.is_ics
101#define is_type is_icmp.ics_type
102#define is_code is_icmp.ics_code
92#define is_type is_icmp.ici_type
93#define is_code is_icmp.ici_code
103#define is_tcp is_ps.is_ts
104#define is_udp is_ps.is_us
105#define is_send is_tcp.ts_data[0].td_end
106#define is_dend is_tcp.ts_data[1].td_end
107#define is_maxswin is_tcp.ts_data[0].td_maxwin
108#define is_maxdwin is_tcp.ts_data[1].td_maxwin
94#define is_tcp is_ps.is_ts
95#define is_udp is_ps.is_us
96#define is_send is_tcp.ts_data[0].td_end
97#define is_dend is_tcp.ts_data[1].td_end
98#define is_maxswin is_tcp.ts_data[0].td_maxwin
99#define is_maxdwin is_tcp.ts_data[1].td_maxwin
109#define is_swscale is_tcp.ts_data[0].td_wscale
110#define is_dwscale is_tcp.ts_data[1].td_wscale
111#define is_maxsend is_tcp.ts_data[0].td_maxend
112#define is_maxdend is_tcp.ts_data[1].td_maxend
100#define is_maxsend is_tcp.ts_data[0].td_maxend
101#define is_maxdend is_tcp.ts_data[1].td_maxend
102#define is_swinscale is_tcp.ts_data[0].td_winscale
103#define is_dwinscale is_tcp.ts_data[1].td_winscale
104#define is_swinflags is_tcp.ts_data[0].td_winflags
105#define is_dwinflags is_tcp.ts_data[1].td_winflags
113#define is_sport is_tcp.ts_sport
114#define is_dport is_tcp.ts_dport
106#define is_sport is_tcp.ts_sport
107#define is_dport is_tcp.ts_dport
115#define is_state is_tcp.ts_state
116#define is_ifpin is_ifp[0]
117#define is_ifpout is_ifp[2]
108#define is_ifpin is_ifp[0]
109#define is_ifpout is_ifp[2]
110#define is_gre is_ps.is_ug
111#define is_call is_gre.gs_call
118
112
113#define IS_WSPORT SI_W_SPORT /* 0x00100 */
114#define IS_WDPORT SI_W_DPORT /* 0x00200 */
115#define IS_WSADDR SI_W_SADDR /* 0x00400 */
116#define IS_WDADDR SI_W_DADDR /* 0x00800 */
117#define IS_NEWFR SI_NEWFR /* 0x01000 */
118#define IS_CLONE SI_CLONE /* 0x02000 */
119#define IS_CLONED SI_CLONED /* 0x04000 */
120#define IS_TCPFSM 0x10000
121#define IS_STRICT 0x20000
122#define IS_ISNSYN 0x40000
123#define IS_ISNACK 0x80000
124#define IS_STATESYNC 0x100000
125/*
126 * IS_SC flags are for scan-operations that need to be recognised in state.
127 */
128#define IS_SC_CLIENT 0x10000000
129#define IS_SC_SERVER 0x20000000
130#define IS_SC_MATCHC 0x40000000
131#define IS_SC_MATCHS 0x80000000
132#define IS_SC_MATCHALL (IS_SC_MATCHC|IS_SC_MATCHC)
133#define IS_SC_ALL (IS_SC_MATCHC|IS_SC_MATCHC|IS_SC_CLIENT|IS_SC_SERVER)
134
135/*
136 * Flags that can be passed into fr_addstate
137 */
138#define IS_INHERITED 0x0fffff00
139
119#define TH_OPENING (TH_SYN|TH_ACK)
120/*
121 * is_flags:
122 * Bits 0 - 3 are use as a mask with the current packet's bits to check for
123 * whether it is short, tcp/udp, a fragment or the presence of IP options.
124 * Bits 4 - 7 are set from the initial packet and contain what the packet
125 * anded with bits 0-3 must match.
126 * Bits 8,9 are used to indicate wildcard source/destination port matching.
140#define TH_OPENING (TH_SYN|TH_ACK)
141/*
142 * is_flags:
143 * Bits 0 - 3 are use as a mask with the current packet's bits to check for
144 * whether it is short, tcp/udp, a fragment or the presence of IP options.
145 * Bits 4 - 7 are set from the initial packet and contain what the packet
146 * anded with bits 0-3 must match.
147 * Bits 8,9 are used to indicate wildcard source/destination port matching.
148 * Bits 10,11 are reserved for other wildcard flag compatibility.
149 * Bits 12,13 are for scaning.
127 */
128
129typedef struct ipstate_save {
130 void *ips_next;
131 struct ipstate ips_is;
132 struct frentry ips_fr;
133} ipstate_save_t;
134
135#define ips_rule ips_is.is_rule
136
137
138typedef struct ipslog {
150 */
151
152typedef struct ipstate_save {
153 void *ips_next;
154 struct ipstate ips_is;
155 struct frentry ips_fr;
156} ipstate_save_t;
157
158#define ips_rule ips_is.is_rule
159
160
161typedef struct ipslog {
139 U_QUAD_T isl_pkts;
140 U_QUAD_T isl_bytes;
141 union i6addr isl_src;
142 union i6addr isl_dst;
162 U_QUAD_T isl_pkts[4];
163 U_QUAD_T isl_bytes[4];
164 i6addr_t isl_src;
165 i6addr_t isl_dst;
166 u_32_t isl_tag;
143 u_short isl_type;
144 union {
145 u_short isl_filler[2];
146 u_short isl_ports[2];
147 u_short isl_icmp;
148 } isl_ps;
149 u_char isl_v;
150 u_char isl_p;
151 u_char isl_flags;
152 u_char isl_state[2];
153 u_32_t isl_rulen;
167 u_short isl_type;
168 union {
169 u_short isl_filler[2];
170 u_short isl_ports[2];
171 u_short isl_icmp;
172 } isl_ps;
173 u_char isl_v;
174 u_char isl_p;
175 u_char isl_flags;
176 u_char isl_state[2];
177 u_32_t isl_rulen;
154 u_32_t isl_group;
178 char isl_group[FR_GROUPLEN];
155} ipslog_t;
156
157#define isl_sport isl_ps.isl_ports[0]
158#define isl_dport isl_ps.isl_ports[1]
159#define isl_itype isl_ps.isl_icmp
160
179} ipslog_t;
180
181#define isl_sport isl_ps.isl_ports[0]
182#define isl_dport isl_ps.isl_ports[1]
183#define isl_itype isl_ps.isl_icmp
184
161#define ISL_NEW 0
162#define ISL_EXPIRE 0xffff
163#define ISL_FLUSH 0xfffe
164#define ISL_REMOVE 0xfffd
185#define ISL_NEW 0
186#define ISL_CLONE 1
187#define ISL_EXPIRE 0xffff
188#define ISL_FLUSH 0xfffe
189#define ISL_REMOVE 0xfffd
190#define ISL_INTERMEDIATE 0xfffc
191#define ISL_KILLED 0xfffb
192#define ISL_ORPHAN 0xfffa
165
166
167typedef struct ips_stat {
168 u_long iss_hits;
169 u_long iss_miss;
170 u_long iss_max;
193
194
195typedef struct ips_stat {
196 u_long iss_hits;
197 u_long iss_miss;
198 u_long iss_max;
199 u_long iss_maxref;
171 u_long iss_tcp;
172 u_long iss_udp;
173 u_long iss_icmp;
174 u_long iss_nomem;
175 u_long iss_expire;
176 u_long iss_fin;
177 u_long iss_active;
178 u_long iss_logged;
179 u_long iss_logfail;
180 u_long iss_inuse;
200 u_long iss_tcp;
201 u_long iss_udp;
202 u_long iss_icmp;
203 u_long iss_nomem;
204 u_long iss_expire;
205 u_long iss_fin;
206 u_long iss_active;
207 u_long iss_logged;
208 u_long iss_logfail;
209 u_long iss_inuse;
210 u_long iss_wild;
211 u_long iss_killed;
212 u_long iss_ticks;
213 u_long iss_bucketfull;
214 int iss_statesize;
215 int iss_statemax;
181 ipstate_t **iss_table;
182 ipstate_t *iss_list;
216 ipstate_t **iss_table;
217 ipstate_t *iss_list;
218 u_long *iss_bucketlen;
183} ips_stat_t;
184
185
186extern u_long fr_tcpidletimeout;
187extern u_long fr_tcpclosewait;
188extern u_long fr_tcplastack;
189extern u_long fr_tcptimeout;
190extern u_long fr_tcpclosed;
191extern u_long fr_tcphalfclosed;
192extern u_long fr_udptimeout;
193extern u_long fr_udpacktimeout;
194extern u_long fr_icmptimeout;
195extern u_long fr_icmpacktimeout;
219} ips_stat_t;
220
221
222extern u_long fr_tcpidletimeout;
223extern u_long fr_tcpclosewait;
224extern u_long fr_tcplastack;
225extern u_long fr_tcptimeout;
226extern u_long fr_tcpclosed;
227extern u_long fr_tcphalfclosed;
228extern u_long fr_udptimeout;
229extern u_long fr_udpacktimeout;
230extern u_long fr_icmptimeout;
231extern u_long fr_icmpacktimeout;
196extern ipstate_t *ips_list;
232extern u_long fr_iptimeout;
233extern int fr_statemax;
234extern int fr_statesize;
197extern int fr_state_lock;
235extern int fr_state_lock;
236extern int fr_state_maxbucket;
237extern int fr_state_maxbucket_reset;
238extern ipstate_t *ips_list;
239extern ipftq_t *ips_utqe;
240extern ipftq_t ips_tqtqb[IPF_TCP_NSTATES];
241
198extern int fr_stateinit __P((void));
242extern int fr_stateinit __P((void));
199extern int fr_tcpstate __P((ipstate_t *, fr_info_t *, ip_t *, tcphdr_t *));
200extern ipstate_t *fr_addstate __P((ip_t *, fr_info_t *, ipstate_t **, u_int));
201extern frentry_t *fr_checkstate __P((ip_t *, fr_info_t *));
202extern void ip_statesync __P((void *));
243extern ipstate_t *fr_addstate __P((fr_info_t *, ipstate_t **, u_int));
244extern frentry_t *fr_checkstate __P((struct fr_info *, u_32_t *));
245extern ipstate_t *fr_stlookup __P((fr_info_t *, tcphdr_t *, ipftq_t **));
246extern void fr_statesync __P((void *));
203extern void fr_timeoutstate __P((void));
247extern void fr_timeoutstate __P((void));
204extern int fr_tcp_age __P((u_long *, u_char *, fr_info_t *, int, int));
248extern int fr_tcp_age __P((struct ipftqent *, struct fr_info *,
249 struct ipftq *, int));
250extern int fr_tcpinwindow __P((struct fr_info *, struct tcpdata *,
251 struct tcpdata *, tcphdr_t *, int));
205extern void fr_stateunload __P((void));
206extern void ipstate_log __P((struct ipstate *, u_int));
252extern void fr_stateunload __P((void));
253extern void ipstate_log __P((struct ipstate *, u_int));
207#if defined(__NetBSD__) || defined(__OpenBSD__)
208extern int fr_state_ioctl __P((caddr_t, u_long, int));
209#else
210extern int fr_state_ioctl __P((caddr_t, int, int));
211#endif
254extern int fr_state_ioctl __P((caddr_t, ioctlcmd_t, int));
255extern void fr_stinsert __P((struct ipstate *, int));
256extern void fr_sttab_init __P((struct ipftq *));
257extern void fr_sttab_destroy __P((struct ipftq *));
258extern void fr_updatestate __P((fr_info_t *, ipstate_t *, ipftq_t *));
259extern void fr_statederef __P((fr_info_t *, ipstate_t **));
260extern void fr_setstatequeue __P((ipstate_t *, int));
212
213#endif /* __IP_STATE_H__ */
261
262#endif /* __IP_STATE_H__ */