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