1 //==========================================================================
3 // include/netinet/ip_state.h
7 //==========================================================================
8 //####BSDCOPYRIGHTBEGIN####
10 // -------------------------------------------
12 // Portions of this software may have been derived from OpenBSD or other sources,
13 // and are covered by the appropriate copyright disclaimers included herein.
15 // -------------------------------------------
17 //####BSDCOPYRIGHTEND####
18 //==========================================================================
19 //#####DESCRIPTIONBEGIN####
22 // Contributors: gthomas
28 //####DESCRIPTIONEND####
30 //==========================================================================
33 /* $OpenBSD: ip_state.h,v 1.10 1999/12/15 05:20:23 kjell Exp $ */
35 * Copyright (C) 1995-1998 by Darren Reed.
37 * Redistribution and use in source and binary forms are permitted
38 * provided that this notice is preserved and due credit is given
39 * to the original author and the contributors.
41 * @(#)ip_state.h 1.3 1/12/96 (C) 1995 Darren Reed
44 #ifndef _NETINET_IP_STATE_H__
45 #define _NETINET_IP_STATE_H__
47 #define IPSTATE_SIZE 257
48 #define IPSTATE_MAX 2048 /* Maximum number of states held */
50 #define PAIRS(s1,d1,s2,d2) ((((s1) == (s2)) && ((d1) == (d2))) ||\
51 (((s1) == (d2)) && ((d1) == (s2))))
52 #define IPPAIR(s1,d1,s2,d2) PAIRS((s1).s_addr, (d1).s_addr, \
53 (s2).s_addr, (d2).s_addr)
56 typedef struct udpstate {
61 typedef struct icmpstate {
67 typedef struct tcpdata {
73 typedef struct tcpstate {
80 typedef struct ipstate {
81 struct ipstate *is_next;
89 struct in_addr is_src;
90 struct in_addr is_dst;
91 u_char is_p; /* Protocol */
92 u_char is_rout; /* Is rule in/out ? */
94 u_32_t is_opt; /* packet options set */
95 u_32_t is_optmsk; /* " " mask */
96 u_short is_sec; /* security options set */
97 u_short is_secmsk; /* " " mask */
98 u_short is_auth; /* authentication options set */
99 u_short is_authmsk; /* " " mask */
107 #define is_icmp is_ps.is_ics
108 #define is_type is_icmp.ics_type
109 #define is_code is_icmp.ics_code
110 #define is_tcp is_ps.is_ts
111 #define is_udp is_ps.is_us
112 #define is_send is_tcp.ts_data[0].td_end
113 #define is_dend is_tcp.ts_data[1].td_end
114 #define is_maxswin is_tcp.ts_data[0].td_maxwin
115 #define is_maxdwin is_tcp.ts_data[1].td_maxwin
116 #define is_maxsend is_tcp.ts_data[0].td_maxend
117 #define is_maxdend is_tcp.ts_data[1].td_maxend
118 #define is_sport is_tcp.ts_sport
119 #define is_dport is_tcp.ts_dport
120 #define is_state is_tcp.ts_state
122 #define TH_OPENING (TH_SYN|TH_ACK)
125 * Bits 0 - 3 are use as a mask with the current packet's bits to check for
126 * whether it is short, tcp/udp, a fragment or the presence of IP options.
127 * Bits 4 - 7 are set from the initial packet and contain what the packet
128 * anded with bits 0-3 must match.
129 * Bits 8,9 are used to indicate wildcard source/destination port matching.
133 typedef struct ipslog {
136 struct in_addr isl_src;
137 struct in_addr isl_dst;
143 u_short isl_filler[2];
144 u_short isl_ports[2];
149 #define isl_sport isl_ps.isl_ports[0]
150 #define isl_dport isl_ps.isl_ports[1]
151 #define isl_itype isl_ps.isl_icmp
154 #define ISL_EXPIRE 0xffff
155 #define ISL_FLUSH 0xfffe
158 typedef struct ips_stat {
172 ipstate_t **iss_table;
176 extern u_long fr_tcpidletimeout;
177 extern u_long fr_tcpclosewait;
178 extern u_long fr_tcplastack;
179 extern u_long fr_tcptimeout;
180 extern u_long fr_tcpclosed;
181 extern u_long fr_udptimeout;
182 extern u_long fr_icmptimeout;
183 extern int fr_stateinit __P((void));
184 extern int fr_tcpstate __P((ipstate_t *, fr_info_t *, ip_t *, tcphdr_t *));
185 extern ipstate_t *fr_addstate __P((ip_t *, fr_info_t *, u_int));
186 extern frentry_t *fr_checkstate __P((ip_t *, fr_info_t *));
187 extern void fr_timeoutstate __P((void));
188 extern void fr_tcp_age __P((u_long *, u_char *, ip_t *, fr_info_t *, int));
189 extern void fr_stateunload __P((void));
190 extern void ipstate_log __P((struct ipstate *, u_int));
191 #if defined(__NetBSD__) || defined(__OpenBSD__)
192 extern int fr_state_ioctl __P((caddr_t, u_long, int));
194 extern int fr_state_ioctl __P((caddr_t, int, int));
197 #endif /* _NETINET_IP_STATE_H__ */