xref: /illumos-gate/usr/src/uts/common/inet/ipf/netinet/ipf_stack.h (revision c85864d8472aaccb47ceb468ebd9b3a85b66d161)
1 /*
2  * Copyright (C) 1993-2001, 2003 by Darren Reed.
3  *
4  * See the IPFILTER.LICENCE file for details on licencing.
5  *
6  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
7  * Use is subject to license terms.
8  */
9 
10 #ifndef	__IPF_STACK_H__
11 #define	__IPF_STACK_H__
12 
13 /* FIXME: appears needed for ip_proxy.h - tcpseq */
14 #include <net/route.h>
15 #include <netinet/in.h>
16 #include <netinet/in_systm.h>
17 #include <netinet/ip.h>
18 #include <netinet/ip_var.h>
19 #include <netinet/tcp.h>
20 #include <netinet/udp.h>
21 #include <netinet/ip_icmp.h>
22 #include <netinet/tcpip.h>
23 
24 #include "ip_compat.h"
25 #include "ip_fil.h"
26 #include "ip_nat.h"
27 #include "ip_frag.h"
28 #include "ip_state.h"
29 #include "ip_proxy.h"
30 #include "ip_auth.h"
31 #include "ip_lookup.h"
32 #include "ip_pool.h"
33 #include "ip_htable.h"
34 #include <net/radix.h>
35 #include <sys/neti.h>
36 #include <sys/hook.h>
37 
38 /*
39  * IPF stack instances
40  */
41 struct ipf_stack {
42 	struct ipf_stack	*ifs_next;
43 	struct ipf_stack	**ifs_pnext;
44 	netid_t			ifs_netid;
45 	zoneid_t		ifs_zone;
46 
47 	/* ipf module */
48 
49 	filterstats_t		ifs_frstats[2];
50 	frentry_t		*ifs_ipfilter[2][2];
51 	frentry_t		*ifs_ipfilter6[2][2];
52 	frentry_t		*ifs_ipacct6[2][2];
53 	frentry_t		*ifs_ipacct[2][2];
54 #if 0 /* not used */
55 	frentry_t		*ifs_ipnatrules[2][2];
56 #endif
57 	frgroup_t		*ifs_ipfgroups[IPL_LOGSIZE][2];
58 	int			ifs_fr_refcnt;
59 	/*
60 	 * For fr_running:
61 	 * 0 == loading, 1 = running, -1 = disabled, -2 = unloading
62 	 */
63 	int			ifs_fr_running;
64 	int			ifs_fr_flags;
65 	int			ifs_fr_active;
66 	int			ifs_fr_control_forwarding;
67 	int			ifs_fr_update_ipid;
68 #if 0
69 	ushort_t		ifs_fr_ip_id;
70 #endif
71 	int			ifs_fr_chksrc;
72 	int			ifs_fr_minttl;
73 	int			ifs_fr_icmpminfragmtu;
74 	int			ifs_fr_pass;
75 	ulong_t			ifs_fr_frouteok[2];
76 	ulong_t			ifs_fr_userifqs;
77 	ulong_t			ifs_fr_badcoalesces[2];
78 	uchar_t			ifs_ipf_iss_secret[32];
79 	timeout_id_t		ifs_fr_timer_id;
80 #if 0
81 	timeout_id_t		ifs_synctimeoutid;
82 #endif
83 	int			ifs_ipf_locks_done;
84 
85 	ipftoken_t 		*ifs_ipftokenhead;
86 	ipftoken_t 		**ifs_ipftokentail;
87 
88 	ipfmutex_t	ifs_ipl_mutex;
89 	ipfmutex_t	ifs_ipf_authmx;
90 	ipfmutex_t	ifs_ipf_rw;
91 	ipfmutex_t	ifs_ipf_timeoutlock;
92 	ipfrwlock_t	ifs_ipf_mutex;
93 	ipfrwlock_t	ifs_ipf_global;
94 	ipfrwlock_t	ifs_ip_poolrw;
95 	ipfrwlock_t	ifs_ipf_frag;
96 	ipfrwlock_t	ifs_ipf_state;
97 	ipfrwlock_t	ifs_ipf_nat;
98 	ipfrwlock_t	ifs_ipf_natfrag;
99 	ipfmutex_t	ifs_ipf_nat_new;
100 	ipfmutex_t	ifs_ipf_natio;
101 	ipfrwlock_t	ifs_ipf_auth;
102 	ipfmutex_t	ifs_ipf_stinsert;
103 	ipfrwlock_t	ifs_ipf_ipidfrag;
104 	ipfrwlock_t	ifs_ipf_tokens;
105 	kcondvar_t	ifs_iplwait;
106 	kcondvar_t	ifs_ipfauthwait;
107 
108 	ipftuneable_t	*ifs_ipf_tuneables;
109 	ipftuneable_t	*ifs_ipf_tunelist;
110 
111 	/* ip_fil_solaris.c */
112 	hook_t		*ifs_ipfhook4_in;
113 	hook_t		*ifs_ipfhook4_out;
114 	hook_t		*ifs_ipfhook4_loop_in;
115 	hook_t		*ifs_ipfhook4_loop_out;
116 	hook_t		*ifs_ipfhook4_nicevents;
117 	hook_t		*ifs_ipfhook6_in;
118 	hook_t		*ifs_ipfhook6_out;
119 	hook_t		*ifs_ipfhook6_loop_in;
120 	hook_t		*ifs_ipfhook6_loop_out;
121 	hook_t		*ifs_ipfhook6_nicevents;
122 
123 	/* flags to indicate whether hooks are registered. */
124 	boolean_t	ifs_hook4_physical_in;
125 	boolean_t	ifs_hook4_physical_out;
126 	boolean_t	ifs_hook4_nic_events;
127 	boolean_t	ifs_hook4_loopback_in;
128 	boolean_t	ifs_hook4_loopback_out;
129 	boolean_t	ifs_hook6_physical_in;
130 	boolean_t	ifs_hook6_physical_out;
131 	boolean_t	ifs_hook6_nic_events;
132 	boolean_t	ifs_hook6_loopback_in;
133 	boolean_t	ifs_hook6_loopback_out;
134 
135 	int		ifs_ipf_loopback;
136 	net_handle_t	ifs_ipf_ipv4;
137 	net_handle_t	ifs_ipf_ipv6;
138 
139 	/* ip_auth.c */
140 	int			ifs_fr_authsize;
141 	int			ifs_fr_authused;
142 	int			ifs_fr_defaultauthage;
143 	int			ifs_fr_auth_lock;
144 	int			ifs_fr_auth_init;
145 	fr_authstat_t		ifs_fr_authstats;
146 	frauth_t		*ifs_fr_auth;
147 	mb_t			**ifs_fr_authpkts;
148 	int			ifs_fr_authstart;
149 	int			ifs_fr_authend;
150 	int			ifs_fr_authnext;
151 	frauthent_t		*ifs_fae_list;
152 	frentry_t		*ifs_ipauth;
153 	frentry_t		*ifs_fr_authlist;
154 
155 	/* ip_frag.c */
156 	ipfr_t			*ifs_ipfr_list;
157 	ipfr_t			**ifs_ipfr_tail;
158 	ipfr_t			**ifs_ipfr_heads;
159 
160 	ipfr_t			*ifs_ipfr_natlist;
161 	ipfr_t			**ifs_ipfr_nattail;
162 	ipfr_t			**ifs_ipfr_nattab;
163 
164 	ipfr_t  		*ifs_ipfr_ipidlist;
165 	ipfr_t  		**ifs_ipfr_ipidtail;
166 	ipfr_t			**ifs_ipfr_ipidtab;
167 
168 	ipfrstat_t		ifs_ipfr_stats;
169 	int			ifs_ipfr_inuse;
170 	int			ifs_ipfr_size;
171 
172 	int			ifs_fr_ipfrttl;
173 	int			ifs_fr_frag_lock;
174 	int			ifs_fr_frag_init;
175 	ulong_t			ifs_fr_ticks;
176 
177 	frentry_t		ifs_frblock;
178 
179 	/* ip_htable.c */
180 	iphtable_t		*ifs_ipf_htables[IPL_LOGSIZE];
181 	ulong_t			ifs_ipht_nomem[IPL_LOGSIZE];
182 	ulong_t			ifs_ipf_nhtables[IPL_LOGSIZE];
183 	ulong_t			ifs_ipf_nhtnodes[IPL_LOGSIZE];
184 
185 	/* ip_log.c */
186 	iplog_t			**ifs_iplh[IPL_LOGSIZE];
187 	iplog_t			*ifs_iplt[IPL_LOGSIZE];
188 	iplog_t			*ifs_ipll[IPL_LOGSIZE];
189 	int			ifs_iplused[IPL_LOGSIZE];
190 	fr_info_t		ifs_iplcrc[IPL_LOGSIZE];
191 	int			ifs_ipl_suppress;
192 	int			ifs_ipl_buffer_sz;
193 	int			ifs_ipl_logmax;
194 	int			ifs_ipl_logall;
195 	int			ifs_ipl_log_init;
196 	int			ifs_ipl_logsize;
197 
198 	/* ip_lookup.c */
199 	ip_pool_stat_t		ifs_ippoolstat;
200 	int			ifs_ip_lookup_inited;
201 
202 	/* ip_nat.c */
203 	/* nat_table[0] -> hashed list sorted by inside (ip, port) */
204 	/* nat_table[1] -> hashed list sorted by outside (ip, port) */
205 	nat_t			**ifs_nat_table[2];
206 	nat_t			*ifs_nat_instances;
207 	ipnat_t			*ifs_nat_list;
208 	uint_t			ifs_ipf_nattable_sz;
209 	uint_t			ifs_ipf_nattable_max;
210 	uint_t			ifs_ipf_natrules_sz;
211 	uint_t			ifs_ipf_rdrrules_sz;
212 	uint_t			ifs_ipf_hostmap_sz;
213 	uint_t			ifs_fr_nat_maxbucket;
214 	uint_t			ifs_fr_nat_maxbucket_reset;
215 	uint32_t		ifs_nat_masks;
216 	uint32_t		ifs_rdr_masks;
217 	uint32_t		ifs_nat6_masks[4];
218 	uint32_t		ifs_rdr6_masks[4];
219 	ipnat_t			**ifs_nat_rules;
220 	ipnat_t			**ifs_rdr_rules;
221 	hostmap_t		**ifs_maptable;
222 	hostmap_t		*ifs_ipf_hm_maplist;
223 
224 	ipftq_t			ifs_nat_tqb[IPF_TCP_NSTATES];
225 	ipftq_t			ifs_nat_udptq;
226 	ipftq_t			ifs_nat_icmptq;
227 	ipftq_t			ifs_nat_iptq;
228 	ipftq_t			*ifs_nat_utqe;
229 	int			ifs_nat_logging;
230 	ulong_t			ifs_fr_defnatage;
231 	ulong_t			ifs_fr_defnatipage;
232 	ulong_t			ifs_fr_defnaticmpage;
233 	natstat_t		ifs_nat_stats;
234 	int			ifs_fr_nat_lock;
235 	int			ifs_fr_nat_init;
236 	uint_t			ifs_nat_flush_level_hi;
237 	uint_t			ifs_nat_flush_level_lo;
238 	ulong_t			ifs_nat_last_force_flush;
239 	int			ifs_nat_doflush;
240 
241 	/* ip_pool.c */
242 	ip_pool_stat_t		ifs_ipoolstat;
243 	ip_pool_t		*ifs_ip_pool_list[IPL_LOGSIZE];
244 
245 	/* ip_proxy.c */
246 	ap_session_t		*ifs_ap_sess_list;
247 	aproxy_t		*ifs_ap_proxylist;
248 	aproxy_t		*ifs_ap_proxies; /* copy of lcl_ap_proxies */
249 
250 	/* ip_state.c */
251 	ipstate_t		**ifs_ips_table;
252 	ulong_t			*ifs_ips_seed;
253 	int			ifs_ips_num;
254 	ulong_t			ifs_ips_last_force_flush;
255 	uint_t			ifs_state_flush_level_hi;
256 	uint_t			ifs_state_flush_level_lo;
257 	ips_stat_t		ifs_ips_stats;
258 
259 	ulong_t			ifs_fr_tcpidletimeout;
260 	ulong_t			ifs_fr_tcpclosewait;
261 	ulong_t			ifs_fr_tcplastack;
262 	ulong_t			ifs_fr_tcptimeout;
263 	ulong_t			ifs_fr_tcpclosed;
264 	ulong_t			ifs_fr_tcphalfclosed;
265 	ulong_t			ifs_fr_udptimeout;
266 	ulong_t			ifs_fr_udpacktimeout;
267 	ulong_t			ifs_fr_icmptimeout;
268 	ulong_t			ifs_fr_icmpacktimeout;
269 	int			ifs_fr_statemax;
270 	int			ifs_fr_statesize;
271 	int			ifs_fr_state_doflush;
272 	int			ifs_fr_state_lock;
273 	int			ifs_fr_state_maxbucket;
274 	int			ifs_fr_state_maxbucket_reset;
275 	int			ifs_fr_state_init;
276 	int			ifs_fr_enable_active;
277 	ipftq_t			ifs_ips_tqtqb[IPF_TCP_NSTATES];
278 	ipftq_t			ifs_ips_udptq;
279 	ipftq_t			ifs_ips_udpacktq;
280 	ipftq_t			ifs_ips_iptq;
281 	ipftq_t			ifs_ips_icmptq;
282 	ipftq_t			ifs_ips_icmpacktq;
283 	ipftq_t			ifs_ips_deletetq;
284 	ipftq_t			*ifs_ips_utqe;
285 	int			ifs_ipstate_logging;
286 	ipstate_t		*ifs_ips_list;
287 	ulong_t			ifs_fr_iptimeout;
288 
289 	/* radix.c */
290 	int			ifs_max_keylen;
291 	struct radix_mask	*ifs_rn_mkfreelist;
292 	struct radix_node_head	*ifs_mask_rnhead;
293 	char			*ifs_addmask_key;
294 	char			*ifs_rn_zeros;
295 	char			*ifs_rn_ones;
296 #ifdef KERNEL
297 	/* kstats for inbound and outbound */
298 	kstat_t			*ifs_kstatp[2];
299 #endif
300 };
301 
302 #endif	/* __IPF_STACK_H__ */
303