2 * Copyright (C) 1995-2001 by Darren Reed.
4 * See the IPFILTER.LICENCE file for details on licencing.
6 * @(#)ip_state.h 1.3 1/12/96 (C) 1995 Darren Reed
7 * $Id: ip_state.h,v 2.13.2.13 2002/06/27 14:40:29 darrenr Exp $
8 * $FreeBSD: src/sys/contrib/ipfilter/netinet/ip_state.h,v 1.10.2.4 2002/08/31 16:24:52 darrenr Exp $
9 * $DragonFly: src/sys/contrib/ipfilter/netinet/ip_state.h,v 1.2 2003/06/17 04:28:20 dillon Exp $
11 #ifndef __IP_STATE_H__
12 #define __IP_STATE_H__
14 #if defined(__STDC__) || defined(__GNUC__)
15 # define SIOCDELST _IOW('r', 61, struct ipstate *)
17 # define SIOCDELST _IOW(r, 61, struct ipstate *)
21 # define IPSTATE_SIZE 5737
24 # define IPSTATE_MAX 4013 /* Maximum number of states held */
27 #define PAIRS(s1,d1,s2,d2) ((((s1) == (s2)) && ((d1) == (d2))) ||\
28 (((s1) == (d2)) && ((d1) == (s2))))
29 #define IPPAIR(s1,d1,s2,d2) PAIRS((s1).s_addr, (d1).s_addr, \
30 (s2).s_addr, (d2).s_addr)
33 typedef struct udpstate {
38 typedef struct icmpstate {
44 typedef struct tcpdata {
51 typedef struct tcpstate {
58 typedef struct ipstate {
59 struct ipstate *is_next;
60 struct ipstate **is_pnext;
61 struct ipstate *is_hnext;
62 struct ipstate **is_phnext;
63 struct ipstate **is_me;
71 u_int is_frage[2]; /* age from filter rule, forward & reverse */
73 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 */
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 */
92 char is_ifname[4][IFNAMSIZ];
93 #if SOLARIS || defined(__sgi)
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
101 #define is_type is_icmp.ics_type
102 #define is_code is_icmp.ics_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
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
113 #define is_sport is_tcp.ts_sport
114 #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]
119 #define TH_OPENING (TH_SYN|TH_ACK)
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.
129 typedef struct ipstate_save {
131 struct ipstate ips_is;
132 struct frentry ips_fr;
135 #define ips_rule ips_is.is_rule
138 typedef struct ipslog {
141 union i6addr isl_src;
142 union i6addr isl_dst;
145 u_short isl_filler[2];
146 u_short isl_ports[2];
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
162 #define ISL_EXPIRE 0xffff
163 #define ISL_FLUSH 0xfffe
164 #define ISL_REMOVE 0xfffd
167 typedef struct ips_stat {
181 ipstate_t **iss_table;
186 extern u_long fr_tcpidletimeout;
187 extern u_long fr_tcpclosewait;
188 extern u_long fr_tcplastack;
189 extern u_long fr_tcptimeout;
190 extern u_long fr_tcpclosed;
191 extern u_long fr_tcphalfclosed;
192 extern u_long fr_udptimeout;
193 extern u_long fr_udpacktimeout;
194 extern u_long fr_icmptimeout;
195 extern u_long fr_icmpacktimeout;
196 extern ipstate_t *ips_list;
197 extern int fr_state_lock;
198 extern int fr_stateinit __P((void));
199 extern int fr_tcpstate __P((ipstate_t *, fr_info_t *, ip_t *, tcphdr_t *));
200 extern ipstate_t *fr_addstate __P((ip_t *, fr_info_t *, ipstate_t **, u_int));
201 extern frentry_t *fr_checkstate __P((ip_t *, fr_info_t *));
202 extern void ip_statesync __P((void *));
203 extern void fr_timeoutstate __P((void));
204 extern int fr_tcp_age __P((u_long *, u_char *, fr_info_t *, int, int));
205 extern void fr_stateunload __P((void));
206 extern void ipstate_log __P((struct ipstate *, u_int));
207 #if defined(__NetBSD__) || defined(__OpenBSD__)
208 extern int fr_state_ioctl __P((caddr_t, u_long, int));
210 extern int fr_state_ioctl __P((caddr_t, int, int));
213 #endif /* __IP_STATE_H__ */