1 /* 2 * Copyright (C) 2012 by Darren Reed. 3 * 4 * See the IPFILTER.LICENCE file for details on licencing. 5 * 6 * @(#)ip_fil.h 1.35 6/5/96 7 * $FreeBSD$ 8 * Id: ip_fil.h,v 2.170.2.51 2007/10/10 09:48:03 darrenr Exp $ 9 */ 10 11 #ifndef __IP_FIL_H__ 12 #define __IP_FIL_H__ 13 14 #include <netinet/in.h> 15 16 #include "netinet/ip_compat.h" 17 #include "netinet/ipf_rb.h" 18 #if NETBSD_GE_REV(104040000) 19 # include <sys/callout.h> 20 #endif 21 #if defined(BSD) && defined(_KERNEL) 22 # include <sys/selinfo.h> 23 #endif 24 25 #ifndef SOLARIS 26 # if defined(sun) && defined(__SVR4) 27 # define SOLARIS 1 28 # else 29 # define SOLARIS 0 30 # endif 31 #endif 32 33 #ifndef __P 34 # define __P(x) x 35 #endif 36 37 #define SIOCADAFR _IOW('r', 60, struct ipfobj) 38 #define SIOCRMAFR _IOW('r', 61, struct ipfobj) 39 #define SIOCSETFF _IOW('r', 62, u_int) 40 #define SIOCGETFF _IOR('r', 63, u_int) 41 #define SIOCGETFS _IOWR('r', 64, struct ipfobj) 42 #define SIOCIPFFL _IOWR('r', 65, int) 43 #define SIOCIPFFB _IOR('r', 66, int) 44 #define SIOCADIFR _IOW('r', 67, struct ipfobj) 45 #define SIOCRMIFR _IOW('r', 68, struct ipfobj) 46 #define SIOCSWAPA _IOR('r', 69, u_int) 47 #define SIOCINAFR _IOW('r', 70, struct ipfobj) 48 #define SIOCINIFR _IOW('r', 71, struct ipfobj) 49 #define SIOCFRENB _IOW('r', 72, u_int) 50 #define SIOCFRSYN _IOW('r', 73, u_int) 51 #define SIOCFRZST _IOWR('r', 74, struct ipfobj) 52 #define SIOCZRLST _IOWR('r', 75, struct ipfobj) 53 #define SIOCAUTHW _IOWR('r', 76, struct ipfobj) 54 #define SIOCAUTHR _IOWR('r', 77, struct ipfobj) 55 #define SIOCSTAT1 _IOWR('r', 78, struct ipfobj) 56 #define SIOCSTLCK _IOWR('r', 79, u_int) 57 #define SIOCSTPUT _IOWR('r', 80, struct ipfobj) 58 #define SIOCSTGET _IOWR('r', 81, struct ipfobj) 59 #define SIOCSTGSZ _IOWR('r', 82, struct ipfobj) 60 #define SIOCSTAT2 _IOWR('r', 83, struct ipfobj) 61 #define SIOCSETLG _IOWR('r', 84, int) 62 #define SIOCGETLG _IOWR('r', 85, int) 63 #define SIOCFUNCL _IOWR('r', 86, struct ipfunc_resolve) 64 #define SIOCIPFGETNEXT _IOWR('r', 87, struct ipfobj) 65 #define SIOCIPFGET _IOWR('r', 88, struct ipfobj) 66 #define SIOCIPFSET _IOWR('r', 89, struct ipfobj) 67 #define SIOCIPFL6 _IOWR('r', 90, int) 68 #define SIOCIPFITER _IOWR('r', 91, struct ipfobj) 69 #define SIOCGENITER _IOWR('r', 92, struct ipfobj) 70 #define SIOCGTABL _IOWR('r', 93, struct ipfobj) 71 #define SIOCIPFDELTOK _IOWR('r', 94, int) 72 #define SIOCLOOKUPITER _IOWR('r', 95, struct ipfobj) 73 #define SIOCGTQTAB _IOWR('r', 96, struct ipfobj) 74 #define SIOCMATCHFLUSH _IOWR('r', 97, struct ipfobj) 75 #define SIOCIPFINTERROR _IOR('r', 98, int) 76 #define SIOCADDFR SIOCADAFR 77 #define SIOCDELFR SIOCRMAFR 78 #define SIOCINSFR SIOCINAFR 79 #define SIOCATHST SIOCSTAT1 80 #define SIOCGFRST SIOCSTAT2 81 82 83 struct ipscan; 84 struct ifnet; 85 struct ipf_main_softc_s; 86 87 typedef int (* lookupfunc_t)(struct ipf_main_softc_s *, void *, 88 int, void *, u_int); 89 90 /* 91 * i6addr is used as a container for both IPv4 and IPv6 addresses, as well 92 * as other types of objects, depending on its qualifier. 93 */ 94 typedef union i6addr { 95 u_32_t i6[4]; 96 struct in_addr in4; 97 #ifdef USE_INET6 98 struct in6_addr in6; 99 #endif 100 void *vptr[2]; 101 lookupfunc_t lptr[2]; 102 struct { 103 u_short type; 104 u_short subtype; 105 int name; 106 } i6un; 107 } i6addr_t; 108 109 #define in4_addr in4.s_addr 110 #define iplookupnum i6[1] 111 #define iplookupname i6un.name 112 #define iplookuptype i6un.type 113 #define iplookupsubtype i6un.subtype 114 /* 115 * NOTE: These DO overlap the above on 64bit systems and this IS recognised. 116 */ 117 #define iplookupptr vptr[0] 118 #define iplookupfunc lptr[1] 119 120 #define I60(x) (((u_32_t *)(x))[0]) 121 #define I61(x) (((u_32_t *)(x))[1]) 122 #define I62(x) (((u_32_t *)(x))[2]) 123 #define I63(x) (((u_32_t *)(x))[3]) 124 #define HI60(x) ntohl(((u_32_t *)(x))[0]) 125 #define HI61(x) ntohl(((u_32_t *)(x))[1]) 126 #define HI62(x) ntohl(((u_32_t *)(x))[2]) 127 #define HI63(x) ntohl(((u_32_t *)(x))[3]) 128 129 #define IP6_EQ(a,b) ((I63(a) == I63(b)) && (I62(a) == I62(b)) && \ 130 (I61(a) == I61(b)) && (I60(a) == I60(b))) 131 #define IP6_NEQ(a,b) ((I63(a) != I63(b)) || (I62(a) != I62(b)) || \ 132 (I61(a) != I61(b)) || (I60(a) != I60(b))) 133 #define IP6_ISZERO(a) ((I60(a) | I61(a) | I62(a) | I63(a)) == 0) 134 #define IP6_NOTZERO(a) ((I60(a) | I61(a) | I62(a) | I63(a)) != 0) 135 #define IP6_ISONES(a) ((I63(a) == 0xffffffff) && (I62(a) == 0xffffffff) && \ 136 (I61(a) == 0xffffffff) && (I60(a) == 0xffffffff)) 137 #define IP6_GT(a,b) (ntohl(HI60(a)) > ntohl(HI60(b)) || \ 138 (HI60(a) == HI60(b) && \ 139 (ntohl(HI61(a)) > ntohl(HI61(b)) || \ 140 (HI61(a) == HI61(b) && \ 141 (ntohl(HI62(a)) > ntohl(HI62(b)) || \ 142 (HI62(a) == HI62(b) && \ 143 ntohl(HI63(a)) > ntohl(HI63(b)))))))) 144 #define IP6_LT(a,b) (ntohl(HI60(a)) < ntohl(HI60(b)) || \ 145 (HI60(a) == HI60(b) && \ 146 (ntohl(HI61(a)) < ntohl(HI61(b)) || \ 147 (HI61(a) == HI61(b) && \ 148 (ntohl(HI62(a)) < ntohl(HI62(b)) || \ 149 (HI62(a) == HI62(b) && \ 150 ntohl(HI63(a)) < ntohl(HI63(b)))))))) 151 #define NLADD(n,x) htonl(ntohl(n) + (x)) 152 #define IP6_INC(a) \ 153 do { u_32_t *_i6 = (u_32_t *)(a); \ 154 _i6[3] = NLADD(_i6[3], 1); \ 155 if (_i6[3] == 0) { \ 156 _i6[2] = NLADD(_i6[2], 1); \ 157 if (_i6[2] == 0) { \ 158 _i6[1] = NLADD(_i6[1], 1); \ 159 if (_i6[1] == 0) { \ 160 _i6[0] = NLADD(_i6[0], 1); \ 161 } \ 162 } \ 163 } \ 164 } while (0) 165 #define IP6_ADD(a,x,d) \ 166 do { i6addr_t *_s = (i6addr_t *)(a); \ 167 i6addr_t *_d = (i6addr_t *)(d); \ 168 _d->i6[0] = NLADD(_s->i6[0], x); \ 169 if (ntohl(_d->i6[0]) < ntohl(_s->i6[0])) { \ 170 _d->i6[1] = NLADD(_d->i6[1], 1); \ 171 if (ntohl(_d->i6[1]) < ntohl(_s->i6[1])) { \ 172 _d->i6[2] = NLADD(_d->i6[2], 1); \ 173 if (ntohl(_d->i6[2]) < ntohl(_s->i6[2])) { \ 174 _d->i6[3] = NLADD(_d->i6[3], 1); \ 175 } \ 176 } \ 177 } \ 178 } while (0) 179 #define IP6_AND(a,b,d) do { i6addr_t *_s1 = (i6addr_t *)(a); \ 180 i6addr_t *_s2 = (i6addr_t *)(b); \ 181 i6addr_t *_d = (i6addr_t *)(d); \ 182 _d->i6[0] = _s1->i6[0] & _s2->i6[0]; \ 183 _d->i6[1] = _s1->i6[1] & _s2->i6[1]; \ 184 _d->i6[2] = _s1->i6[2] & _s2->i6[2]; \ 185 _d->i6[3] = _s1->i6[3] & _s2->i6[3]; \ 186 } while (0) 187 #define IP6_ANDASSIGN(a,m) \ 188 do { i6addr_t *_d = (i6addr_t *)(a); \ 189 i6addr_t *_m = (i6addr_t *)(m); \ 190 _d->i6[0] &= _m->i6[0]; \ 191 _d->i6[1] &= _m->i6[1]; \ 192 _d->i6[2] &= _m->i6[2]; \ 193 _d->i6[3] &= _m->i6[3]; \ 194 } while (0) 195 #define IP6_MASKEQ(a,m,b) \ 196 (((I60(a) & I60(m)) == I60(b)) && \ 197 ((I61(a) & I61(m)) == I61(b)) && \ 198 ((I62(a) & I62(m)) == I62(b)) && \ 199 ((I63(a) & I63(m)) == I63(b))) 200 #define IP6_MASKNEQ(a,m,b) \ 201 (((I60(a) & I60(m)) != I60(b)) || \ 202 ((I61(a) & I61(m)) != I61(b)) || \ 203 ((I62(a) & I62(m)) != I62(b)) || \ 204 ((I63(a) & I63(m)) != I63(b))) 205 #define IP6_MERGE(a,b,c) \ 206 do { i6addr_t *_d, *_s1, *_s2; \ 207 _d = (i6addr_t *)(a); \ 208 _s1 = (i6addr_t *)(b); \ 209 _s2 = (i6addr_t *)(c); \ 210 _d->i6[0] |= _s1->i6[0] & ~_s2->i6[0]; \ 211 _d->i6[1] |= _s1->i6[1] & ~_s2->i6[1]; \ 212 _d->i6[2] |= _s1->i6[2] & ~_s2->i6[2]; \ 213 _d->i6[3] |= _s1->i6[3] & ~_s2->i6[3]; \ 214 } while (0) 215 #define IP6_MASK(a,b,c) \ 216 do { i6addr_t *_d, *_s1, *_s2; \ 217 _d = (i6addr_t *)(a); \ 218 _s1 = (i6addr_t *)(b); \ 219 _s2 = (i6addr_t *)(c); \ 220 _d->i6[0] = _s1->i6[0] & ~_s2->i6[0]; \ 221 _d->i6[1] = _s1->i6[1] & ~_s2->i6[1]; \ 222 _d->i6[2] = _s1->i6[2] & ~_s2->i6[2]; \ 223 _d->i6[3] = _s1->i6[3] & ~_s2->i6[3]; \ 224 } while (0) 225 #define IP6_SETONES(a) \ 226 do { i6addr_t *_d = (i6addr_t *)(a); \ 227 _d->i6[0] = 0xffffffff; \ 228 _d->i6[1] = 0xffffffff; \ 229 _d->i6[2] = 0xffffffff; \ 230 _d->i6[3] = 0xffffffff; \ 231 } while (0) 232 233 typedef union ipso_u { 234 u_short ipso_ripso[2]; 235 u_32_t ipso_doi; 236 } ipso_t; 237 238 typedef struct fr_ip { 239 u_32_t fi_v:4; /* IP version */ 240 u_32_t fi_xx:4; /* spare */ 241 u_32_t fi_tos:8; /* IP packet TOS */ 242 u_32_t fi_ttl:8; /* IP packet TTL */ 243 u_32_t fi_p:8; /* IP packet protocol */ 244 u_32_t fi_optmsk; /* bitmask composed from IP options */ 245 i6addr_t fi_src; /* source address from packet */ 246 i6addr_t fi_dst; /* destination address from packet */ 247 ipso_t fi_ipso; /* IP security options */ 248 u_32_t fi_flx; /* packet flags */ 249 u_32_t fi_tcpmsk; /* TCP options set/reset */ 250 u_32_t fi_ports[2]; /* TCP ports */ 251 u_char fi_tcpf; /* TCP flags */ 252 u_char fi_sensitivity; 253 u_char fi_xxx[2]; /* pad */ 254 } fr_ip_t; 255 256 /* 257 * For use in fi_flx 258 */ 259 #define FI_TCPUDP 0x0001 /* TCP/UCP implied comparison*/ 260 #define FI_OPTIONS 0x0002 261 #define FI_FRAG 0x0004 262 #define FI_SHORT 0x0008 263 #define FI_NATED 0x0010 264 #define FI_MULTICAST 0x0020 265 #define FI_BROADCAST 0x0040 266 #define FI_MBCAST 0x0080 267 #define FI_STATE 0x0100 268 #define FI_BADNAT 0x0200 269 #define FI_BAD 0x0400 270 #define FI_OOW 0x0800 /* Out of state window, else match */ 271 #define FI_ICMPERR 0x1000 272 #define FI_FRAGBODY 0x2000 273 #define FI_BADSRC 0x4000 274 #define FI_LOWTTL 0x8000 275 #define FI_CMP 0x5cfe3 /* Not FI_FRAG,FI_NATED,FI_FRAGTAIL */ 276 #define FI_ICMPCMP 0x0003 /* Flags we can check for ICMP error packets */ 277 #define FI_WITH 0x5effe /* Not FI_TCPUDP */ 278 #define FI_V6EXTHDR 0x10000 279 #define FI_COALESCE 0x20000 280 #define FI_NEWNAT 0x40000 281 #define FI_ICMPQUERY 0x80000 282 #define FI_ENCAP 0x100000 /* encap/decap with NAT */ 283 #define FI_AH 0x200000 /* AH header present */ 284 #define FI_DOCKSUM 0x10000000 /* Proxy wants L4 recalculation */ 285 #define FI_NOCKSUM 0x20000000 /* don't do a L4 checksum validation */ 286 #define FI_NOWILD 0x40000000 /* Do not do wildcard searches */ 287 #define FI_IGNORE 0x80000000 288 289 #define fi_secmsk fi_ipso.ipso_ripso[0] 290 #define fi_auth fi_ipso.ipso_ripso[1] 291 #define fi_doi fi_ipso.ipso_doi 292 #define fi_saddr fi_src.in4.s_addr 293 #define fi_daddr fi_dst.in4.s_addr 294 #define fi_srcnum fi_src.iplookupnum 295 #define fi_dstnum fi_dst.iplookupnum 296 #define fi_srcname fi_src.iplookupname 297 #define fi_dstname fi_dst.iplookupname 298 #define fi_srctype fi_src.iplookuptype 299 #define fi_dsttype fi_dst.iplookuptype 300 #define fi_srcsubtype fi_src.iplookupsubtype 301 #define fi_dstsubtype fi_dst.iplookupsubtype 302 #define fi_srcptr fi_src.iplookupptr 303 #define fi_dstptr fi_dst.iplookupptr 304 #define fi_srcfunc fi_src.iplookupfunc 305 #define fi_dstfunc fi_dst.iplookupfunc 306 307 308 /* 309 * These are both used by the state and NAT code to indicate that one port or 310 * the other should be treated as a wildcard. 311 * NOTE: When updating, check bit masks in ip_state.h and update there too. 312 */ 313 #define SI_W_SPORT 0x00000100 314 #define SI_W_DPORT 0x00000200 315 #define SI_WILDP (SI_W_SPORT|SI_W_DPORT) 316 #define SI_W_SADDR 0x00000400 317 #define SI_W_DADDR 0x00000800 318 #define SI_WILDA (SI_W_SADDR|SI_W_DADDR) 319 #define SI_NEWFR 0x00001000 320 #define SI_CLONE 0x00002000 321 #define SI_CLONED 0x00004000 322 #define SI_NEWCLONE 0x00008000 323 324 typedef struct { 325 u_short fda_ports[2]; 326 u_char fda_tcpf; /* TCP header flags (SYN, ACK, etc) */ 327 } frdat_t; 328 329 typedef enum fr_breasons_e { 330 FRB_BLOCKED = 0, 331 FRB_LOGFAIL = 1, 332 FRB_PPSRATE = 2, 333 FRB_JUMBO = 3, 334 FRB_MAKEFRIP = 4, 335 FRB_STATEADD = 5, 336 FRB_UPDATEIPID = 6, 337 FRB_LOGFAIL2 = 7, 338 FRB_DECAPFRIP = 8, 339 FRB_AUTHNEW = 9, 340 FRB_AUTHCAPTURE = 10, 341 FRB_COALESCE = 11, 342 FRB_PULLUP = 12, 343 FRB_AUTHFEEDBACK = 13, 344 FRB_BADFRAG = 14, 345 FRB_NATV4 = 15, 346 FRB_NATV6 = 16, 347 } fr_breason_t; 348 349 #define FRB_MAX_VALUE 16 350 351 typedef enum ipf_cksum_e { 352 FI_CK_BAD = -1, 353 FI_CK_NEEDED = 0, 354 FI_CK_SUMOK = 1, 355 FI_CK_L4PART = 2, 356 FI_CK_L4FULL = 4 357 } ipf_cksum_t; 358 359 typedef struct fr_info { 360 void *fin_main_soft; 361 void *fin_ifp; /* interface packet is `on' */ 362 struct frentry *fin_fr; /* last matching rule */ 363 int fin_out; /* in or out ? 1 == out, 0 == in */ 364 fr_ip_t fin_fi; /* IP Packet summary */ 365 frdat_t fin_dat; /* TCP/UDP ports, ICMP code/type */ 366 int fin_dlen; /* length of data portion of packet */ 367 int fin_plen; 368 u_32_t fin_rule; /* rule # last matched */ 369 u_short fin_hlen; /* length of IP header in bytes */ 370 char fin_group[FR_GROUPLEN]; /* group number, -1 for none */ 371 void *fin_dp; /* start of data past IP header */ 372 /* 373 * Fields after fin_dp aren't used for compression of log records. 374 * fin_fi contains the IP version (fin_family) 375 * fin_rule isn't included because adding a new rule can change it but 376 * not change fin_fr. fin_rule is the rule number reported. 377 * It isn't necessary to include fin_crc because that is checked 378 * for explicitly, before calling bcmp. 379 */ 380 u_32_t fin_crc; /* Simple calculation for logging */ 381 int fin_family; /* AF_INET, etc. */ 382 int fin_icode; /* ICMP error to return */ 383 int fin_mtu; /* MTU input for ICMP need-frag */ 384 int fin_rev; /* state only: 1 = reverse */ 385 int fin_ipoff; /* # bytes from buffer start to hdr */ 386 u_32_t fin_id; /* IP packet id field */ 387 u_short fin_l4hlen; /* length of L4 header, if known */ 388 u_short fin_off; 389 int fin_depth; /* Group nesting depth */ 390 int fin_error; /* Error code to return */ 391 ipf_cksum_t fin_cksum; /* -1 = bad, 1 = good, 0 = not done */ 392 fr_breason_t fin_reason; /* why auto blocked */ 393 u_int fin_pktnum; 394 void *fin_nattag; 395 struct frdest *fin_dif; 396 struct frdest *fin_tif; 397 union { 398 ip_t *fip_ip; 399 #ifdef USE_INET6 400 ip6_t *fip_ip6; 401 #endif 402 } fin_ipu; 403 mb_t **fin_mp; /* pointer to pointer to mbuf */ 404 mb_t *fin_m; /* pointer to mbuf */ 405 #if SOLARIS 406 mb_t *fin_qfm; /* pointer to mblk where pkt starts */ 407 void *fin_qpi; 408 char fin_ifname[LIFNAMSIZ]; 409 #endif 410 void *fin_fraghdr; /* pointer to start of ipv6 frag hdr */ 411 } fr_info_t; 412 413 #define fin_ip fin_ipu.fip_ip 414 #define fin_ip6 fin_ipu.fip_ip6 415 #define fin_v fin_fi.fi_v 416 #define fin_p fin_fi.fi_p 417 #define fin_flx fin_fi.fi_flx 418 #define fin_optmsk fin_fi.fi_optmsk 419 #define fin_secmsk fin_fi.fi_secmsk 420 #define fin_doi fin_fi.fi_doi 421 #define fin_auth fin_fi.fi_auth 422 #define fin_src fin_fi.fi_src.in4 423 #define fin_saddr fin_fi.fi_saddr 424 #define fin_dst fin_fi.fi_dst.in4 425 #define fin_daddr fin_fi.fi_daddr 426 #define fin_data fin_fi.fi_ports 427 #define fin_sport fin_fi.fi_ports[0] 428 #define fin_dport fin_fi.fi_ports[1] 429 #define fin_tcpf fin_fi.fi_tcpf 430 #define fin_src6 fin_fi.fi_src 431 #define fin_dst6 fin_fi.fi_dst 432 #define fin_srcip6 fin_fi.fi_src.in6 433 #define fin_dstip6 fin_fi.fi_dst.in6 434 435 #define IPF_IN 0 436 #define IPF_OUT 1 437 438 typedef struct frentry *(*ipfunc_t)(fr_info_t *, u_32_t *); 439 typedef int (*ipfuncinit_t)(struct ipf_main_softc_s *, struct frentry *); 440 441 typedef struct ipfunc_resolve { 442 char ipfu_name[32]; 443 ipfunc_t ipfu_addr; 444 ipfuncinit_t ipfu_init; 445 ipfuncinit_t ipfu_fini; 446 } ipfunc_resolve_t; 447 448 /* 449 * Size for compares on fr_info structures 450 */ 451 #define FI_CSIZE offsetof(fr_info_t, fin_icode) 452 #define FI_LCSIZE offsetof(fr_info_t, fin_dp) 453 454 /* 455 * Size for copying cache fr_info structure 456 */ 457 #define FI_COPYSIZE offsetof(fr_info_t, fin_dp) 458 459 /* 460 * Structure for holding IPFilter's tag information 461 */ 462 #define IPFTAG_LEN 16 463 typedef struct { 464 union { 465 u_32_t iptu_num[4]; 466 char iptu_tag[IPFTAG_LEN]; 467 } ipt_un; 468 int ipt_not; 469 } ipftag_t; 470 471 #define ipt_tag ipt_un.iptu_tag 472 #define ipt_num ipt_un.iptu_num 473 474 /* 475 * Structure to define address for pool lookups. 476 */ 477 typedef struct { 478 u_char adf_len; 479 sa_family_t adf_family; 480 u_char adf_xxx[2]; 481 i6addr_t adf_addr; 482 } addrfamily_t; 483 484 485 RBI_LINK(ipf_rb, host_node_s); 486 487 typedef struct host_node_s { 488 RBI_FIELD(ipf_rb) hn_entry; 489 addrfamily_t hn_addr; 490 int hn_active; 491 } host_node_t; 492 493 typedef RBI_HEAD(ipf_rb, host_node_s) ipf_rb_head_t; 494 495 typedef struct host_track_s { 496 ipf_rb_head_t ht_root; 497 int ht_max_nodes; 498 int ht_max_per_node; 499 int ht_netmask; 500 int ht_cur_nodes; 501 } host_track_t; 502 503 504 typedef enum fr_dtypes_e { 505 FRD_NORMAL = 0, 506 FRD_DSTLIST 507 } fr_dtypes_t; 508 /* 509 * This structure is used to hold information about the next hop for where 510 * to forward a packet. 511 */ 512 typedef struct frdest { 513 void *fd_ptr; 514 addrfamily_t fd_addr; 515 fr_dtypes_t fd_type; 516 int fd_name; 517 } frdest_t; 518 519 #define fd_ip6 fd_addr.adf_addr 520 #define fd_ip fd_ip6.in4 521 522 523 typedef enum fr_ctypes_e { 524 FR_NONE = 0, 525 FR_EQUAL, 526 FR_NEQUAL, 527 FR_LESST, 528 FR_GREATERT, 529 FR_LESSTE, 530 FR_GREATERTE, 531 FR_OUTRANGE, 532 FR_INRANGE, 533 FR_INCRANGE 534 } fr_ctypes_t; 535 536 /* 537 * This structure holds information about a port comparison. 538 */ 539 typedef struct frpcmp { 540 fr_ctypes_t frp_cmp; /* data for port comparisons */ 541 u_32_t frp_port; /* low port for <> and >< */ 542 u_32_t frp_top; /* high port for <> and >< */ 543 } frpcmp_t; 544 545 546 /* 547 * Structure containing all the relevant TCP/UDP things that can be checked in 548 * a filter rule. 549 */ 550 typedef struct frtuc { 551 u_char ftu_tcpfm; /* tcp flags mask */ 552 u_char ftu_tcpf; /* tcp flags */ 553 frpcmp_t ftu_src; /* source port */ 554 frpcmp_t ftu_dst; /* destination port */ 555 } frtuc_t; 556 557 #define ftu_scmp ftu_src.frp_cmp 558 #define ftu_dcmp ftu_dst.frp_cmp 559 #define ftu_sport ftu_src.frp_port 560 #define ftu_dport ftu_dst.frp_port 561 #define ftu_stop ftu_src.frp_top 562 #define ftu_dtop ftu_dst.frp_top 563 564 #define FR_TCPFMAX 0x3f 565 566 typedef enum fr_atypes_e { 567 FRI_NONE = -1, /* For LHS of NAT */ 568 FRI_NORMAL = 0, /* Normal address */ 569 FRI_DYNAMIC, /* dynamic address */ 570 FRI_LOOKUP, /* address is a pool # */ 571 FRI_RANGE, /* address/mask is a range */ 572 FRI_NETWORK, /* network address from if */ 573 FRI_BROADCAST, /* broadcast address from if */ 574 FRI_PEERADDR, /* Peer address for P-to-P */ 575 FRI_NETMASKED, /* network address with netmask from if */ 576 FRI_SPLIT, /* For NAT compatibility */ 577 FRI_INTERFACE /* address is based on interface name */ 578 } fr_atypes_t; 579 580 /* 581 * This structure makes up what is considered to be the IPFilter specific 582 * matching components of a filter rule, as opposed to the data structures 583 * used to define the result which are in frentry_t and not here. 584 */ 585 typedef struct fripf { 586 fr_ip_t fri_ip; 587 fr_ip_t fri_mip; /* mask structure */ 588 589 u_short fri_icmpm; /* data for ICMP packets (mask) */ 590 u_short fri_icmp; 591 592 frtuc_t fri_tuc; 593 fr_atypes_t fri_satype; /* addres type */ 594 fr_atypes_t fri_datype; /* addres type */ 595 int fri_sifpidx; /* doing dynamic addressing */ 596 int fri_difpidx; /* index into fr_ifps[] to use when */ 597 } fripf_t; 598 599 #define fri_dlookup fri_mip.fi_dst 600 #define fri_slookup fri_mip.fi_src 601 #define fri_dstnum fri_mip.fi_dstnum 602 #define fri_srcnum fri_mip.fi_srcnum 603 #define fri_dstname fri_mip.fi_dstname 604 #define fri_srcname fri_mip.fi_srcname 605 #define fri_dstptr fri_mip.fi_dstptr 606 #define fri_srcptr fri_mip.fi_srcptr 607 608 609 typedef enum fr_rtypes_e { 610 FR_T_NONE = 0, 611 FR_T_IPF, /* IPF structures */ 612 FR_T_BPFOPC, /* BPF opcode */ 613 FR_T_CALLFUNC, /* callout to function in fr_func only */ 614 FR_T_COMPIPF, /* compiled C code */ 615 FR_T_IPFEXPR, /* IPF expression */ 616 FR_T_BUILTIN = 0x40000000, /* rule is in kernel space */ 617 FR_T_IPF_BUILTIN, 618 FR_T_BPFOPC_BUILTIN, 619 FR_T_CALLFUNC_BUILTIN, 620 FR_T_COMPIPF_BUILTIN, 621 FR_T_IPFEXPR_BUILTIN 622 } fr_rtypes_t; 623 624 typedef struct frentry * (* frentfunc_t)(fr_info_t *); 625 626 typedef struct frentry { 627 ipfmutex_t fr_lock; 628 struct frentry *fr_next; 629 struct frentry **fr_pnext; 630 struct frgroup *fr_grp; 631 struct frgroup *fr_grphead; 632 struct frgroup *fr_icmpgrp; 633 struct ipscan *fr_isc; 634 struct frentry *fr_dnext; /* 2 fr_die linked list pointers */ 635 struct frentry **fr_pdnext; 636 void *fr_ifas[4]; 637 void *fr_ptr; /* for use with fr_arg */ 638 int fr_comment; /* text comment for rule */ 639 int fr_size; /* size of this structure */ 640 int fr_ref; /* reference count */ 641 int fr_statecnt; /* state count - for limit rules */ 642 u_32_t fr_die; /* only used on loading the rule */ 643 u_int fr_cksum; /* checksum on filter rules for performance */ 644 /* 645 * The line number from a file is here because we need to be able to 646 * match the rule generated with ``grep rule ipf.conf | ipf -rf -'' 647 * with the rule loaded using ``ipf -f ipf.conf'' - thus it can't be 648 * on the other side of fr_func. 649 */ 650 int fr_flineno; /* line number from conf file */ 651 /* 652 * These are only incremented when a packet matches this rule and 653 * it is the last match 654 */ 655 U_QUAD_T fr_hits; 656 U_QUAD_T fr_bytes; 657 658 /* 659 * For PPS rate limiting 660 * fr_lpu is used to always have the same size for this field, 661 * allocating 64bits for seconds and 32bits for milliseconds. 662 */ 663 union { 664 struct timeval frp_lastpkt; 665 char frp_bytes[12]; 666 } fr_lpu; 667 int fr_curpps; 668 669 union { 670 void *fru_data; 671 char *fru_caddr; 672 fripf_t *fru_ipf; 673 frentfunc_t fru_func; 674 } fr_dun; 675 676 /* 677 * Fields after this may not change whilst in the kernel. 678 */ 679 ipfunc_t fr_func; /* call this function */ 680 int fr_dsize; 681 int fr_pps; 682 fr_rtypes_t fr_type; 683 u_32_t fr_flags; /* per-rule flags && options (see below) */ 684 u_32_t fr_logtag; /* user defined log tag # */ 685 u_32_t fr_collect; /* collection number */ 686 u_int fr_arg; /* misc. numeric arg for rule */ 687 u_int fr_loglevel; /* syslog log facility + priority */ 688 u_char fr_family; 689 u_char fr_icode; /* return ICMP code */ 690 int fr_group; /* group to which this rule belongs */ 691 int fr_grhead; /* group # which this rule starts */ 692 int fr_isctag; 693 int fr_rpc; /* XID Filtering */ 694 ipftag_t fr_nattag; 695 /* 696 * These are all options related to stateful filtering 697 */ 698 host_track_t fr_srctrack; 699 int fr_nostatelog; 700 int fr_statemax; /* max reference count */ 701 int fr_icmphead; /* ICMP group for state options */ 702 u_int fr_age[2]; /* non-TCP state timeouts */ 703 /* 704 * These are compared separately. 705 */ 706 int fr_ifnames[4]; 707 frdest_t fr_tifs[2]; /* "to"/"reply-to" interface */ 708 frdest_t fr_dif; /* duplicate packet interface */ 709 /* 710 * How big is the name buffer at the end? 711 */ 712 int fr_namelen; 713 char fr_names[1]; 714 } frentry_t; 715 716 #define fr_lastpkt fr_lpu.frp_lastpkt 717 #define fr_caddr fr_dun.fru_caddr 718 #define fr_data fr_dun.fru_data 719 #define fr_dfunc fr_dun.fru_func 720 #define fr_ipf fr_dun.fru_ipf 721 #define fr_ip fr_ipf->fri_ip 722 #define fr_mip fr_ipf->fri_mip 723 #define fr_icmpm fr_ipf->fri_icmpm 724 #define fr_icmp fr_ipf->fri_icmp 725 #define fr_tuc fr_ipf->fri_tuc 726 #define fr_satype fr_ipf->fri_satype 727 #define fr_datype fr_ipf->fri_datype 728 #define fr_sifpidx fr_ipf->fri_sifpidx 729 #define fr_difpidx fr_ipf->fri_difpidx 730 #define fr_proto fr_ip.fi_p 731 #define fr_mproto fr_mip.fi_p 732 #define fr_ttl fr_ip.fi_ttl 733 #define fr_mttl fr_mip.fi_ttl 734 #define fr_tos fr_ip.fi_tos 735 #define fr_mtos fr_mip.fi_tos 736 #define fr_tcpfm fr_tuc.ftu_tcpfm 737 #define fr_tcpf fr_tuc.ftu_tcpf 738 #define fr_scmp fr_tuc.ftu_scmp 739 #define fr_dcmp fr_tuc.ftu_dcmp 740 #define fr_dport fr_tuc.ftu_dport 741 #define fr_sport fr_tuc.ftu_sport 742 #define fr_stop fr_tuc.ftu_stop 743 #define fr_dtop fr_tuc.ftu_dtop 744 #define fr_dst fr_ip.fi_dst.in4 745 #define fr_dst6 fr_ip.fi_dst 746 #define fr_daddr fr_ip.fi_dst.in4.s_addr 747 #define fr_src fr_ip.fi_src.in4 748 #define fr_src6 fr_ip.fi_src 749 #define fr_saddr fr_ip.fi_src.in4.s_addr 750 #define fr_dmsk fr_mip.fi_dst.in4 751 #define fr_dmsk6 fr_mip.fi_dst 752 #define fr_dmask fr_mip.fi_dst.in4.s_addr 753 #define fr_smsk fr_mip.fi_src.in4 754 #define fr_smsk6 fr_mip.fi_src 755 #define fr_smask fr_mip.fi_src.in4.s_addr 756 #define fr_dstnum fr_ip.fi_dstnum 757 #define fr_srcnum fr_ip.fi_srcnum 758 #define fr_dlookup fr_ip.fi_dst 759 #define fr_slookup fr_ip.fi_src 760 #define fr_dstname fr_ip.fi_dstname 761 #define fr_srcname fr_ip.fi_srcname 762 #define fr_dsttype fr_ip.fi_dsttype 763 #define fr_srctype fr_ip.fi_srctype 764 #define fr_dstsubtype fr_ip.fi_dstsubtype 765 #define fr_srcsubtype fr_ip.fi_srcsubtype 766 #define fr_dstptr fr_mip.fi_dstptr 767 #define fr_srcptr fr_mip.fi_srcptr 768 #define fr_dstfunc fr_mip.fi_dstfunc 769 #define fr_srcfunc fr_mip.fi_srcfunc 770 #define fr_optbits fr_ip.fi_optmsk 771 #define fr_optmask fr_mip.fi_optmsk 772 #define fr_secbits fr_ip.fi_secmsk 773 #define fr_secmask fr_mip.fi_secmsk 774 #define fr_authbits fr_ip.fi_auth 775 #define fr_authmask fr_mip.fi_auth 776 #define fr_doi fr_ip.fi_doi 777 #define fr_doimask fr_mip.fi_doi 778 #define fr_flx fr_ip.fi_flx 779 #define fr_mflx fr_mip.fi_flx 780 #define fr_ifa fr_ifas[0] 781 #define fr_oifa fr_ifas[2] 782 #define fr_tif fr_tifs[0] 783 #define fr_rif fr_tifs[1] 784 785 #define FR_NOLOGTAG 0 786 787 #define FR_CMPSIZ (offsetof(struct frentry, fr_ifnames) - \ 788 offsetof(struct frentry, fr_func)) 789 #define FR_NAME(_f, _n) (_f)->fr_names + (_f)->_n 790 #define FR_NUM(_a) (sizeof(_a) / sizeof(*_a)) 791 792 793 /* 794 * fr_flags 795 */ 796 #define FR_BLOCK 0x00001 /* do not allow packet to pass */ 797 #define FR_PASS 0x00002 /* allow packet to pass */ 798 #define FR_AUTH 0x00003 /* use authentication */ 799 #define FR_PREAUTH 0x00004 /* require preauthentication */ 800 #define FR_ACCOUNT 0x00005 /* Accounting rule */ 801 #define FR_SKIP 0x00006 /* skip rule */ 802 #define FR_DECAPSULATE 0x00008 /* decapsulate rule */ 803 #define FR_CALL 0x00009 /* call rule */ 804 #define FR_CMDMASK 0x0000f 805 #define FR_LOG 0x00010 /* Log */ 806 #define FR_LOGB 0x00011 /* Log-fail */ 807 #define FR_LOGP 0x00012 /* Log-pass */ 808 #define FR_LOGMASK (FR_LOG|FR_CMDMASK) 809 #define FR_CALLNOW 0x00020 /* call another function (fr_func) if matches */ 810 #define FR_NOTSRCIP 0x00040 811 #define FR_NOTDSTIP 0x00080 812 #define FR_QUICK 0x00100 /* match & stop processing list */ 813 #define FR_KEEPFRAG 0x00200 /* keep fragment information */ 814 #define FR_KEEPSTATE 0x00400 /* keep `connection' state information */ 815 #define FR_FASTROUTE 0x00800 /* bypass normal routing */ 816 #define FR_RETRST 0x01000 /* Return TCP RST packet - reset connection */ 817 #define FR_RETICMP 0x02000 /* Return ICMP unreachable packet */ 818 #define FR_FAKEICMP 0x03000 /* Return ICMP unreachable with fake source */ 819 #define FR_OUTQUE 0x04000 /* outgoing packets */ 820 #define FR_INQUE 0x08000 /* ingoing packets */ 821 #define FR_LOGBODY 0x10000 /* Log the body */ 822 #define FR_LOGFIRST 0x20000 /* Log the first byte if state held */ 823 #define FR_LOGORBLOCK 0x40000 /* block the packet if it can't be logged */ 824 #define FR_STLOOSE 0x80000 /* loose state checking */ 825 #define FR_FRSTRICT 0x100000 /* strict frag. cache */ 826 #define FR_STSTRICT 0x200000 /* strict keep state */ 827 #define FR_NEWISN 0x400000 /* new ISN for outgoing TCP */ 828 #define FR_NOICMPERR 0x800000 /* do not match ICMP errors in state */ 829 #define FR_STATESYNC 0x1000000 /* synchronize state to slave */ 830 #define FR_COPIED 0x2000000 /* copied from user space */ 831 #define FR_INACTIVE 0x4000000 /* only used when flush'ing rules */ 832 #define FR_NOMATCH 0x8000000 /* no match occured */ 833 /* 0x10000000 FF_LOGPASS */ 834 /* 0x20000000 FF_LOGBLOCK */ 835 /* 0x40000000 FF_LOGNOMATCH */ 836 /* 0x80000000 FF_BLOCKNONIP */ 837 838 #define FR_RETMASK (FR_RETICMP|FR_RETRST|FR_FAKEICMP) 839 #define FR_ISBLOCK(x) (((x) & FR_CMDMASK) == FR_BLOCK) 840 #define FR_ISPASS(x) (((x) & FR_CMDMASK) == FR_PASS) 841 #define FR_ISAUTH(x) (((x) & FR_CMDMASK) == FR_AUTH) 842 #define FR_ISPREAUTH(x) (((x) & FR_CMDMASK) == FR_PREAUTH) 843 #define FR_ISACCOUNT(x) (((x) & FR_CMDMASK) == FR_ACCOUNT) 844 #define FR_ISSKIP(x) (((x) & FR_CMDMASK) == FR_SKIP) 845 #define FR_ISDECAPS(x) (((x) & FR_CMDMASK) == FR_DECAPSULATE) 846 #define FR_ISNOMATCH(x) ((x) & FR_NOMATCH) 847 #define FR_INOUT (FR_INQUE|FR_OUTQUE) 848 849 /* 850 * recognized flags for SIOCGETFF and SIOCSETFF, and get put in fr_flags 851 */ 852 #define FF_LOGPASS 0x10000000 853 #define FF_LOGBLOCK 0x20000000 854 #define FF_LOGNOMATCH 0x40000000 855 #define FF_LOGGING (FF_LOGPASS|FF_LOGBLOCK|FF_LOGNOMATCH) 856 #define FF_BLOCKNONIP 0x80000000 /* Solaris2 Only */ 857 858 859 /* 860 * Structure that passes information on what/how to flush to the kernel. 861 */ 862 typedef struct ipfflush { 863 int ipflu_how; 864 int ipflu_arg; 865 } ipfflush_t; 866 867 868 /* 869 * 870 */ 871 typedef struct ipfgetctl { 872 u_int ipfg_min; /* min value */ 873 u_int ipfg_current; /* current value */ 874 u_int ipfg_max; /* max value */ 875 u_int ipfg_default; /* default value */ 876 u_int ipfg_steps; /* value increments */ 877 char ipfg_name[40]; /* tag name for this control */ 878 } ipfgetctl_t; 879 880 typedef struct ipfsetctl { 881 int ipfs_which; /* 0 = min 1 = current 2 = max 3 = default */ 882 u_int ipfs_value; /* min value */ 883 char ipfs_name[40]; /* tag name for this control */ 884 } ipfsetctl_t; 885 886 887 /* 888 * Some of the statistics below are in their own counters, but most are kept 889 * in this single structure so that they can all easily be collected and 890 * copied back as required. 891 */ 892 typedef struct ipf_statistics { 893 u_long fr_icmp_coalesce; 894 u_long fr_tcp_frag; 895 u_long fr_tcp_pullup; 896 u_long fr_tcp_short; 897 u_long fr_tcp_small; 898 u_long fr_tcp_bad_flags; 899 u_long fr_udp_pullup; 900 u_long fr_ip_freed; 901 u_long fr_v6_ah_bad; 902 u_long fr_v6_bad; 903 u_long fr_v6_badfrag; 904 u_long fr_v6_dst_bad; 905 u_long fr_v6_esp_pullup; 906 u_long fr_v6_ext_short; 907 u_long fr_v6_ext_pullup; 908 u_long fr_v6_ext_hlen; 909 u_long fr_v6_frag_bad; 910 u_long fr_v6_frag_pullup; 911 u_long fr_v6_frag_size; 912 u_long fr_v6_gre_pullup; 913 u_long fr_v6_icmp6_pullup; 914 u_long fr_v6_rh_bad; 915 u_long fr_v6_badttl; /* TTL in packet doesn't reach minimum */ 916 u_long fr_v4_ah_bad; 917 u_long fr_v4_ah_pullup; 918 u_long fr_v4_esp_pullup; 919 u_long fr_v4_cipso_bad; 920 u_long fr_v4_cipso_tlen; 921 u_long fr_v4_gre_frag; 922 u_long fr_v4_gre_pullup; 923 u_long fr_v4_icmp_frag; 924 u_long fr_v4_icmp_pullup; 925 u_long fr_v4_badttl; /* TTL in packet doesn't reach minimum */ 926 u_long fr_v4_badsrc; /* source received doesn't match route */ 927 u_long fr_l4_badcksum; /* layer 4 header checksum failure */ 928 u_long fr_badcoalesces; 929 u_long fr_pass; /* packets allowed */ 930 u_long fr_block; /* packets denied */ 931 u_long fr_nom; /* packets which don't match any rule */ 932 u_long fr_short; /* packets which are short */ 933 u_long fr_ppkl; /* packets allowed and logged */ 934 u_long fr_bpkl; /* packets denied and logged */ 935 u_long fr_npkl; /* packets unmatched and logged */ 936 u_long fr_ret; /* packets for which a return is sent */ 937 u_long fr_acct; /* packets for which counting was performed */ 938 u_long fr_bnfr; /* bad attempts to allocate fragment state */ 939 u_long fr_nfr; /* new fragment state kept */ 940 u_long fr_cfr; /* add new fragment state but complete pkt */ 941 u_long fr_bads; /* bad attempts to allocate packet state */ 942 u_long fr_ads; /* new packet state kept */ 943 u_long fr_chit; /* cached hit */ 944 u_long fr_cmiss; /* cached miss */ 945 u_long fr_tcpbad; /* TCP checksum check failures */ 946 u_long fr_pull[2]; /* good and bad pullup attempts */ 947 u_long fr_bad; /* bad IP packets to the filter */ 948 u_long fr_ipv6; /* IPv6 packets in/out */ 949 u_long fr_ppshit; /* dropped because of pps ceiling */ 950 u_long fr_ipud; /* IP id update failures */ 951 u_long fr_blocked[FRB_MAX_VALUE + 1]; 952 } ipf_statistics_t; 953 954 /* 955 * Log structure. Each packet header logged is prepended by one of these. 956 * Following this in the log records read from the device will be an ipflog 957 * structure which is then followed by any packet data. 958 */ 959 typedef struct iplog { 960 u_32_t ipl_magic; 961 u_int ipl_count; 962 u_32_t ipl_seqnum; 963 struct timeval ipl_time; 964 size_t ipl_dsize; 965 struct iplog *ipl_next; 966 } iplog_t; 967 968 #define ipl_sec ipl_time.tv_sec 969 #define ipl_usec ipl_time.tv_usec 970 971 #define IPL_MAGIC 0x49504c4d /* 'IPLM' */ 972 #define IPL_MAGIC_NAT 0x49504c4e /* 'IPLN' */ 973 #define IPL_MAGIC_STATE 0x49504c53 /* 'IPLS' */ 974 #define IPLOG_SIZE sizeof(iplog_t) 975 976 typedef struct ipflog { 977 u_int fl_unit; 978 u_32_t fl_rule; 979 u_32_t fl_flags; 980 u_32_t fl_lflags; 981 u_32_t fl_logtag; 982 ipftag_t fl_nattag; 983 u_short fl_plen; /* extra data after hlen */ 984 u_short fl_loglevel; /* syslog log level */ 985 char fl_group[FR_GROUPLEN]; 986 u_char fl_hlen; /* length of IP headers saved */ 987 u_char fl_dir; 988 u_char fl_breason; /* from fin_reason */ 989 u_char fl_family; /* address family of packet logged */ 990 char fl_ifname[LIFNAMSIZ]; 991 } ipflog_t; 992 993 #ifndef IPF_LOGGING 994 # define IPF_LOGGING 0 995 #endif 996 #ifndef IPF_DEFAULT_PASS 997 # define IPF_DEFAULT_PASS FR_PASS 998 #endif 999 1000 #define DEFAULT_IPFLOGSIZE 32768 1001 #ifndef IPFILTER_LOGSIZE 1002 # define IPFILTER_LOGSIZE DEFAULT_IPFLOGSIZE 1003 #else 1004 # if IPFILTER_LOGSIZE < 8192 1005 # error IPFILTER_LOGSIZE too small. Must be >= 8192 1006 # endif 1007 #endif 1008 1009 #define IPF_OPTCOPY 0x07ff00 /* bit mask of copied options */ 1010 1011 /* 1012 * Device filenames for reading log information. Use ipf on Solaris2 because 1013 * ipl is already a name used by something else. 1014 */ 1015 #ifndef IPL_NAME 1016 # if SOLARIS 1017 # define IPL_NAME "/dev/ipf" 1018 # else 1019 # define IPL_NAME "/dev/ipl" 1020 # endif 1021 #endif 1022 /* 1023 * Pathnames for various IP Filter control devices. Used by LKM 1024 * and userland, so defined here. 1025 */ 1026 #define IPNAT_NAME "/dev/ipnat" 1027 #define IPSTATE_NAME "/dev/ipstate" 1028 #define IPAUTH_NAME "/dev/ipauth" 1029 #define IPSYNC_NAME "/dev/ipsync" 1030 #define IPSCAN_NAME "/dev/ipscan" 1031 #define IPLOOKUP_NAME "/dev/iplookup" 1032 1033 #define IPL_LOGIPF 0 /* Minor device #'s for accessing logs */ 1034 #define IPL_LOGNAT 1 1035 #define IPL_LOGSTATE 2 1036 #define IPL_LOGAUTH 3 1037 #define IPL_LOGSYNC 4 1038 #define IPL_LOGSCAN 5 1039 #define IPL_LOGLOOKUP 6 1040 #define IPL_LOGCOUNT 7 1041 #define IPL_LOGMAX 7 1042 #define IPL_LOGSIZE IPL_LOGMAX + 1 1043 #define IPL_LOGALL -1 1044 #define IPL_LOGNONE -2 1045 1046 /* 1047 * For SIOCGETFS 1048 */ 1049 typedef struct friostat { 1050 ipf_statistics_t f_st[2]; 1051 frentry_t *f_ipf[2][2]; 1052 frentry_t *f_acct[2][2]; 1053 frentry_t *f_auth; 1054 struct frgroup *f_groups[IPL_LOGSIZE][2]; 1055 u_long f_froute[2]; 1056 u_long f_log_ok; 1057 u_long f_log_fail; 1058 u_long f_rb_no_mem; 1059 u_long f_rb_node_max; 1060 u_32_t f_ticks; 1061 int f_locks[IPL_LOGSIZE]; 1062 int f_defpass; /* default pass - from fr_pass */ 1063 int f_active; /* 1 or 0 - active rule set */ 1064 int f_running; /* 1 if running, else 0 */ 1065 int f_logging; /* 1 if enabled, else 0 */ 1066 int f_features; 1067 char f_version[32]; /* version string */ 1068 } friostat_t; 1069 1070 #define f_fin f_ipf[0] 1071 #define f_fout f_ipf[1] 1072 #define f_acctin f_acct[0] 1073 #define f_acctout f_acct[1] 1074 1075 #define IPF_FEAT_LKM 0x001 1076 #define IPF_FEAT_LOG 0x002 1077 #define IPF_FEAT_LOOKUP 0x004 1078 #define IPF_FEAT_BPF 0x008 1079 #define IPF_FEAT_COMPILED 0x010 1080 #define IPF_FEAT_CKSUM 0x020 1081 #define IPF_FEAT_SYNC 0x040 1082 #define IPF_FEAT_SCAN 0x080 1083 #define IPF_FEAT_IPV6 0x100 1084 1085 typedef struct optlist { 1086 u_short ol_val; 1087 int ol_bit; 1088 } optlist_t; 1089 1090 1091 /* 1092 * Group list structure. 1093 */ 1094 typedef struct frgroup { 1095 struct frgroup *fg_next; 1096 struct frentry *fg_head; 1097 struct frentry *fg_start; 1098 struct frgroup **fg_set; 1099 u_32_t fg_flags; 1100 int fg_ref; 1101 char fg_name[FR_GROUPLEN]; 1102 } frgroup_t; 1103 1104 #define FG_NAME(g) (*(g)->fg_name == '\0' ? "" : (g)->fg_name) 1105 1106 1107 /* 1108 * Used by state and NAT tables 1109 */ 1110 typedef struct icmpinfo { 1111 u_short ici_id; 1112 u_short ici_seq; 1113 u_char ici_type; 1114 } icmpinfo_t; 1115 1116 typedef struct udpinfo { 1117 u_short us_sport; 1118 u_short us_dport; 1119 } udpinfo_t; 1120 1121 1122 typedef struct tcpdata { 1123 u_32_t td_end; 1124 u_32_t td_maxend; 1125 u_32_t td_maxwin; 1126 u_32_t td_winscale; 1127 u_32_t td_maxseg; 1128 int td_winflags; 1129 } tcpdata_t; 1130 1131 #define TCP_WSCALE_MAX 14 1132 1133 #define TCP_WSCALE_SEEN 0x00000001 1134 #define TCP_WSCALE_FIRST 0x00000002 1135 #define TCP_SACK_PERMIT 0x00000004 1136 1137 1138 typedef struct tcpinfo { 1139 u_32_t ts_sport; 1140 u_32_t ts_dport; 1141 tcpdata_t ts_data[2]; 1142 } tcpinfo_t; 1143 1144 1145 /* 1146 * Structures to define a GRE header as seen in a packet. 1147 */ 1148 struct grebits { 1149 #if defined(sparc) 1150 u_32_t grb_ver:3; 1151 u_32_t grb_flags:3; 1152 u_32_t grb_A:1; 1153 u_32_t grb_recur:1; 1154 u_32_t grb_s:1; 1155 u_32_t grb_S:1; 1156 u_32_t grb_K:1; 1157 u_32_t grb_R:1; 1158 u_32_t grb_C:1; 1159 #else 1160 u_32_t grb_C:1; 1161 u_32_t grb_R:1; 1162 u_32_t grb_K:1; 1163 u_32_t grb_S:1; 1164 u_32_t grb_s:1; 1165 u_32_t grb_recur:1; 1166 u_32_t grb_A:1; 1167 u_32_t grb_flags:3; 1168 u_32_t grb_ver:3; 1169 #endif 1170 u_short grb_ptype; 1171 }; 1172 1173 typedef struct grehdr { 1174 union { 1175 struct grebits gru_bits; 1176 u_short gru_flags; 1177 } gr_un; 1178 u_short gr_len; 1179 u_short gr_call; 1180 } grehdr_t; 1181 1182 #define gr_flags gr_un.gru_flags 1183 #define gr_bits gr_un.gru_bits 1184 #define gr_ptype gr_bits.grb_ptype 1185 #define gr_C gr_bits.grb_C 1186 #define gr_R gr_bits.grb_R 1187 #define gr_K gr_bits.grb_K 1188 #define gr_S gr_bits.grb_S 1189 #define gr_s gr_bits.grb_s 1190 #define gr_recur gr_bits.grb_recur 1191 #define gr_A gr_bits.grb_A 1192 #define gr_ver gr_bits.grb_ver 1193 1194 /* 1195 * GRE information tracked by "keep state" 1196 */ 1197 typedef struct greinfo { 1198 u_short gs_call[2]; 1199 u_short gs_flags; 1200 u_short gs_ptype; 1201 } greinfo_t; 1202 1203 #define GRE_REV(x) ((ntohs(x) >> 13) & 7) 1204 1205 1206 /* 1207 * Format of an Authentication header 1208 */ 1209 typedef struct authhdr { 1210 u_char ah_next; 1211 u_char ah_plen; 1212 u_short ah_reserved; 1213 u_32_t ah_spi; 1214 u_32_t ah_seq; 1215 /* Following the sequence number field is 0 or more bytes of */ 1216 /* authentication data, as specified by ah_plen - RFC 2402. */ 1217 } authhdr_t; 1218 1219 1220 /* 1221 * Timeout tail queue list member 1222 */ 1223 typedef struct ipftqent { 1224 struct ipftqent **tqe_pnext; 1225 struct ipftqent *tqe_next; 1226 struct ipftq *tqe_ifq; 1227 void *tqe_parent; /* pointer back to NAT/state struct */ 1228 u_32_t tqe_die; /* when this entriy is to die */ 1229 u_32_t tqe_touched; 1230 int tqe_flags; 1231 int tqe_state[2]; /* current state of this entry */ 1232 } ipftqent_t; 1233 1234 #define TQE_RULEBASED 0x00000001 1235 #define TQE_DELETE 0x00000002 1236 1237 1238 /* 1239 * Timeout tail queue head for IPFilter 1240 */ 1241 typedef struct ipftq { 1242 ipfmutex_t ifq_lock; 1243 u_int ifq_ttl; 1244 ipftqent_t *ifq_head; 1245 ipftqent_t **ifq_tail; 1246 struct ipftq *ifq_next; 1247 struct ipftq **ifq_pnext; 1248 int ifq_ref; 1249 u_int ifq_flags; 1250 } ipftq_t; 1251 1252 #define IFQF_USER 0x01 /* User defined aging */ 1253 #define IFQF_DELETE 0x02 /* Marked for deletion */ 1254 #define IFQF_PROXY 0x04 /* Timeout queue in use by a proxy */ 1255 1256 #define IPFTQ_INIT(x,y,z) do { \ 1257 (x)->ifq_ttl = (y); \ 1258 (x)->ifq_head = NULL; \ 1259 (x)->ifq_ref = 1; \ 1260 (x)->ifq_tail = &(x)->ifq_head; \ 1261 MUTEX_INIT(&(x)->ifq_lock, (z)); \ 1262 } while (0) 1263 1264 #define IPF_HZ_MULT 1 1265 #define IPF_HZ_DIVIDE 2 /* How many times a second ipfilter */ 1266 /* checks its timeout queues. */ 1267 #define IPF_TTLVAL(x) (((x) / IPF_HZ_MULT) * IPF_HZ_DIVIDE) 1268 1269 typedef int (*ipftq_delete_fn_t)(struct ipf_main_softc_s *, void *); 1270 1271 1272 /* 1273 * Object structure description. For passing through in ioctls. 1274 */ 1275 typedef struct ipfobj { 1276 u_32_t ipfo_rev; /* IPFilter version number */ 1277 u_32_t ipfo_size; /* size of object at ipfo_ptr */ 1278 void *ipfo_ptr; /* pointer to object */ 1279 int ipfo_type; /* type of object being pointed to */ 1280 int ipfo_offset; /* bytes from ipfo_ptr where to start */ 1281 int ipfo_retval; /* return value */ 1282 u_char ipfo_xxxpad[28]; /* reserved for future use */ 1283 } ipfobj_t; 1284 1285 #define IPFOBJ_FRENTRY 0 /* struct frentry */ 1286 #define IPFOBJ_IPFSTAT 1 /* struct friostat */ 1287 #define IPFOBJ_IPFINFO 2 /* struct fr_info */ 1288 #define IPFOBJ_AUTHSTAT 3 /* struct fr_authstat */ 1289 #define IPFOBJ_FRAGSTAT 4 /* struct ipfrstat */ 1290 #define IPFOBJ_IPNAT 5 /* struct ipnat */ 1291 #define IPFOBJ_NATSTAT 6 /* struct natstat */ 1292 #define IPFOBJ_STATESAVE 7 /* struct ipstate_save */ 1293 #define IPFOBJ_NATSAVE 8 /* struct nat_save */ 1294 #define IPFOBJ_NATLOOKUP 9 /* struct natlookup */ 1295 #define IPFOBJ_IPSTATE 10 /* struct ipstate */ 1296 #define IPFOBJ_STATESTAT 11 /* struct ips_stat */ 1297 #define IPFOBJ_FRAUTH 12 /* struct frauth */ 1298 #define IPFOBJ_TUNEABLE 13 /* struct ipftune */ 1299 #define IPFOBJ_NAT 14 /* struct nat */ 1300 #define IPFOBJ_IPFITER 15 /* struct ipfruleiter */ 1301 #define IPFOBJ_GENITER 16 /* struct ipfgeniter */ 1302 #define IPFOBJ_GTABLE 17 /* struct ipftable */ 1303 #define IPFOBJ_LOOKUPITER 18 /* struct ipflookupiter */ 1304 #define IPFOBJ_STATETQTAB 19 /* struct ipftq * NSTATES */ 1305 #define IPFOBJ_IPFEXPR 20 1306 #define IPFOBJ_PROXYCTL 21 /* strct ap_ctl */ 1307 #define IPFOBJ_FRIPF 22 /* structfripf */ 1308 #define IPFOBJ_COUNT 23 /* How many #defines are above this? */ 1309 1310 1311 typedef union ipftunevalptr { 1312 void *ipftp_void; 1313 u_long *ipftp_long; 1314 u_int *ipftp_int; 1315 u_short *ipftp_short; 1316 u_char *ipftp_char; 1317 u_long ipftp_offset; 1318 } ipftunevalptr_t; 1319 1320 typedef union ipftuneval { 1321 u_long ipftu_long; 1322 u_int ipftu_int; 1323 u_short ipftu_short; 1324 u_char ipftu_char; 1325 } ipftuneval_t; 1326 1327 struct ipftuneable; 1328 typedef int (* ipftunefunc_t)(struct ipf_main_softc_s *, struct ipftuneable *, ipftuneval_t *); 1329 1330 typedef struct ipftuneable { 1331 ipftunevalptr_t ipft_una; 1332 const char *ipft_name; 1333 u_long ipft_min; 1334 u_long ipft_max; 1335 int ipft_sz; 1336 int ipft_flags; 1337 struct ipftuneable *ipft_next; 1338 ipftunefunc_t ipft_func; 1339 } ipftuneable_t; 1340 1341 #define ipft_addr ipft_una.ipftp_void 1342 #define ipft_plong ipft_una.ipftp_long 1343 #define ipft_pint ipft_una.ipftp_int 1344 #define ipft_pshort ipft_una.ipftp_short 1345 #define ipft_pchar ipft_una.ipftp_char 1346 1347 #define IPFT_RDONLY 1 /* read-only */ 1348 #define IPFT_WRDISABLED 2 /* write when disabled only */ 1349 1350 typedef struct ipftune { 1351 void *ipft_cookie; 1352 ipftuneval_t ipft_un; 1353 u_long ipft_min; 1354 u_long ipft_max; 1355 int ipft_sz; 1356 int ipft_flags; 1357 char ipft_name[80]; 1358 } ipftune_t; 1359 1360 #define ipft_vlong ipft_un.ipftu_long 1361 #define ipft_vint ipft_un.ipftu_int 1362 #define ipft_vshort ipft_un.ipftu_short 1363 #define ipft_vchar ipft_un.ipftu_char 1364 1365 /* 1366 * Hash table header 1367 */ 1368 #define IPFHASH(x,y) typedef struct { \ 1369 ipfrwlock_t ipfh_lock; \ 1370 struct x *ipfh_head; \ 1371 } y 1372 1373 /* 1374 ** HPUX Port 1375 */ 1376 1377 #if !defined(CDEV_MAJOR) && defined (__FreeBSD__) 1378 # define CDEV_MAJOR 79 1379 #endif 1380 1381 #ifdef _KERNEL 1382 # define FR_VERBOSE(verb_pr) 1383 # define FR_DEBUG(verb_pr) 1384 #else 1385 extern void ipfkdebug(char *, ...); 1386 extern void ipfkverbose(char *, ...); 1387 # define FR_VERBOSE(verb_pr) ipfkverbose verb_pr 1388 # define FR_DEBUG(verb_pr) ipfkdebug verb_pr 1389 #endif 1390 1391 /* 1392 * 1393 */ 1394 typedef struct ipfruleiter { 1395 int iri_inout; 1396 char iri_group[FR_GROUPLEN]; 1397 int iri_active; 1398 int iri_nrules; 1399 int iri_v; /* No longer used (compatibility) */ 1400 frentry_t *iri_rule; 1401 } ipfruleiter_t; 1402 1403 /* 1404 * Values for iri_inout 1405 */ 1406 #define F_IN 0 1407 #define F_OUT 1 1408 #define F_ACIN 2 1409 #define F_ACOUT 3 1410 1411 1412 typedef struct ipfgeniter { 1413 int igi_type; 1414 int igi_nitems; 1415 void *igi_data; 1416 } ipfgeniter_t; 1417 1418 #define IPFGENITER_IPF 0 1419 #define IPFGENITER_NAT 1 1420 #define IPFGENITER_IPNAT 2 1421 #define IPFGENITER_FRAG 3 1422 #define IPFGENITER_AUTH 4 1423 #define IPFGENITER_STATE 5 1424 #define IPFGENITER_NATFRAG 6 1425 #define IPFGENITER_HOSTMAP 7 1426 #define IPFGENITER_LOOKUP 8 1427 1428 typedef struct ipftable { 1429 int ita_type; 1430 void *ita_table; 1431 } ipftable_t; 1432 1433 #define IPFTABLE_BUCKETS 1 1434 #define IPFTABLE_BUCKETS_NATIN 2 1435 #define IPFTABLE_BUCKETS_NATOUT 3 1436 1437 1438 typedef struct ipf_v4_masktab_s { 1439 u_32_t imt4_active[33]; 1440 int imt4_masks[33]; 1441 int imt4_max; 1442 } ipf_v4_masktab_t; 1443 1444 typedef struct ipf_v6_masktab_s { 1445 i6addr_t imt6_active[129]; 1446 int imt6_masks[129]; 1447 int imt6_max; 1448 } ipf_v6_masktab_t; 1449 1450 1451 /* 1452 * 1453 */ 1454 typedef struct ipftoken { 1455 struct ipftoken *ipt_next; 1456 struct ipftoken **ipt_pnext; 1457 void *ipt_ctx; 1458 void *ipt_data; 1459 u_long ipt_die; 1460 int ipt_type; 1461 int ipt_uid; 1462 int ipt_subtype; 1463 int ipt_ref; 1464 int ipt_complete; 1465 } ipftoken_t; 1466 1467 1468 /* 1469 * 1470 */ 1471 typedef struct ipfexp { 1472 int ipfe_cmd; 1473 int ipfe_not; 1474 int ipfe_narg; 1475 int ipfe_size; 1476 int ipfe_arg0[1]; 1477 } ipfexp_t; 1478 1479 /* 1480 * Currently support commands (ipfe_cmd) 1481 * 32bits is split up follows: 1482 * aabbcccc 1483 * aa = 0 = packet matching, 1 = meta data matching 1484 * bb = IP protocol number 1485 * cccc = command 1486 */ 1487 #define IPF_EXP_IP_PR 0x00000001 1488 #define IPF_EXP_IP_ADDR 0x00000002 1489 #define IPF_EXP_IP_SRCADDR 0x00000003 1490 #define IPF_EXP_IP_DSTADDR 0x00000004 1491 #define IPF_EXP_IP6_ADDR 0x00000005 1492 #define IPF_EXP_IP6_SRCADDR 0x00000006 1493 #define IPF_EXP_IP6_DSTADDR 0x00000007 1494 #define IPF_EXP_TCP_FLAGS 0x00060001 1495 #define IPF_EXP_TCP_PORT 0x00060002 1496 #define IPF_EXP_TCP_SPORT 0x00060003 1497 #define IPF_EXP_TCP_DPORT 0x00060004 1498 #define IPF_EXP_UDP_PORT 0x00110002 1499 #define IPF_EXP_UDP_SPORT 0x00110003 1500 #define IPF_EXP_UDP_DPORT 0x00110004 1501 #define IPF_EXP_IDLE_GT 0x01000001 1502 #define IPF_EXP_TCP_STATE 0x01060002 1503 #define IPF_EXP_END 0xffffffff 1504 1505 #define ONE_DAY IPF_TTLVAL(1 * 86400) /* 1 day */ 1506 #define FIVE_DAYS (5 * ONE_DAY) 1507 1508 typedef struct ipf_main_softc_s { 1509 struct ipf_main_softc_s *ipf_next; 1510 ipfmutex_t ipf_rw; 1511 ipfmutex_t ipf_timeoutlock; 1512 ipfrwlock_t ipf_mutex; 1513 ipfrwlock_t ipf_frag; 1514 ipfrwlock_t ipf_global; 1515 ipfrwlock_t ipf_tokens; 1516 ipfrwlock_t ipf_state; 1517 ipfrwlock_t ipf_nat; 1518 ipfrwlock_t ipf_natfrag; 1519 ipfrwlock_t ipf_poolrw; 1520 int ipf_dynamic_softc; 1521 int ipf_refcnt; 1522 int ipf_running; 1523 int ipf_flags; 1524 int ipf_active; 1525 int ipf_control_forwarding; 1526 int ipf_update_ipid; 1527 int ipf_chksrc; /* causes a system crash if enabled */ 1528 int ipf_pass; 1529 int ipf_minttl; 1530 int ipf_icmpminfragmtu; 1531 int ipf_interror; /* Should be in a struct that is per */ 1532 /* thread or process. Does not belong */ 1533 /* here but there's a lot more work */ 1534 /* in doing that properly. For now, */ 1535 /* it is squatting. */ 1536 u_int ipf_tcpidletimeout; 1537 u_int ipf_tcpclosewait; 1538 u_int ipf_tcplastack; 1539 u_int ipf_tcptimewait; 1540 u_int ipf_tcptimeout; 1541 u_int ipf_tcpsynsent; 1542 u_int ipf_tcpsynrecv; 1543 u_int ipf_tcpclosed; 1544 u_int ipf_tcphalfclosed; 1545 u_int ipf_udptimeout; 1546 u_int ipf_udpacktimeout; 1547 u_int ipf_icmptimeout; 1548 u_int ipf_icmpacktimeout; 1549 u_int ipf_iptimeout; 1550 u_long ipf_ticks; 1551 u_long ipf_userifqs; 1552 u_long ipf_rb_no_mem; 1553 u_long ipf_rb_node_max; 1554 u_long ipf_frouteok[2]; 1555 ipftuneable_t *ipf_tuners; 1556 void *ipf_frag_soft; 1557 void *ipf_nat_soft; 1558 void *ipf_state_soft; 1559 void *ipf_auth_soft; 1560 void *ipf_proxy_soft; 1561 void *ipf_sync_soft; 1562 void *ipf_lookup_soft; 1563 void *ipf_log_soft; 1564 struct frgroup *ipf_groups[IPL_LOGSIZE][2]; 1565 frentry_t *ipf_rules[2][2]; 1566 frentry_t *ipf_acct[2][2]; 1567 frentry_t *ipf_rule_explist[2]; 1568 ipftoken_t *ipf_token_head; 1569 ipftoken_t **ipf_token_tail; 1570 #if defined(__FreeBSD__) && defined(_KERNEL) 1571 struct callout ipf_slow_ch; 1572 #endif 1573 #if NETBSD_GE_REV(104040000) 1574 struct callout ipf_slow_ch; 1575 #endif 1576 #if SOLARIS 1577 timeout_id_t ipf_slow_ch; 1578 #endif 1579 #if defined(_KERNEL) 1580 # if SOLARIS 1581 struct pollhead ipf_poll_head[IPL_LOGSIZE]; 1582 void *ipf_dip; 1583 # if defined(INSTANCES) 1584 int ipf_get_loopback; 1585 u_long ipf_idnum; 1586 net_handle_t ipf_nd_v4; 1587 net_handle_t ipf_nd_v6; 1588 hook_t *ipf_hk_v4_in; 1589 hook_t *ipf_hk_v4_out; 1590 hook_t *ipf_hk_v4_nic; 1591 hook_t *ipf_hk_v6_in; 1592 hook_t *ipf_hk_v6_out; 1593 hook_t *ipf_hk_v6_nic; 1594 hook_t *ipf_hk_loop_v4_in; 1595 hook_t *ipf_hk_loop_v4_out; 1596 hook_t *ipf_hk_loop_v6_in; 1597 hook_t *ipf_hk_loop_v6_out; 1598 # endif 1599 # else 1600 struct selinfo ipf_selwait[IPL_LOGSIZE]; 1601 # endif 1602 #endif 1603 void *ipf_slow; 1604 ipf_statistics_t ipf_stats[2]; 1605 u_char ipf_iss_secret[32]; 1606 u_short ipf_ip_id; 1607 } ipf_main_softc_t; 1608 1609 #define IPFERROR(_e) do { softc->ipf_interror = (_e); \ 1610 DT1(user_error, int, _e); \ 1611 } while (0) 1612 1613 #ifndef _KERNEL 1614 extern int ipf_check(void *, struct ip *, int, struct ifnet *, int, mb_t **); 1615 extern struct ifnet *get_unit(char *, int); 1616 extern char *get_ifname(struct ifnet *); 1617 extern int ipfioctl(ipf_main_softc_t *, int, ioctlcmd_t, 1618 caddr_t, int); 1619 extern void m_freem(mb_t *); 1620 extern size_t msgdsize(mb_t *); 1621 extern int bcopywrap(void *, void *, size_t); 1622 extern void ip_fillid(struct ip *); 1623 #else /* #ifndef _KERNEL */ 1624 # if defined(__NetBSD__) && defined(PFIL_HOOKS) 1625 extern void ipfilterattach(int); 1626 # endif 1627 extern int ipl_enable(void); 1628 extern int ipl_disable(void); 1629 # if SOLARIS 1630 extern int ipf_check(void *, struct ip *, int, struct ifnet *, int, void *, 1631 mblk_t **); 1632 # if SOLARIS 1633 extern void ipf_prependmbt(fr_info_t *, mblk_t *); 1634 extern int ipfioctl(dev_t, int, intptr_t, int, cred_t *, int *); 1635 # endif 1636 extern int ipf_qout(queue_t *, mblk_t *); 1637 # else /* SOLARIS */ 1638 extern int ipf_check(void *, struct ip *, int, struct ifnet *, int, mb_t **); 1639 extern int (*fr_checkp)(ip_t *, int, void *, int, mb_t **); 1640 extern size_t mbufchainlen(mb_t *); 1641 # ifdef IPFILTER_LKM 1642 extern int ipf_identify(char *); 1643 # endif 1644 # if defined(__FreeBSD__) 1645 extern int ipfioctl(struct cdev*, u_long, caddr_t, int, struct thread *); 1646 # elif defined(__NetBSD__) 1647 extern int ipfioctl(dev_t, u_long, void *, int, struct lwp *); 1648 # endif 1649 # endif /* SOLARIS */ 1650 1651 # if defined(__FreeBSD__) 1652 extern int ipf_pfil_hook(void); 1653 extern int ipf_pfil_unhook(void); 1654 extern void ipf_event_reg(void); 1655 extern void ipf_event_dereg(void); 1656 # endif 1657 1658 # if defined(INSTANCES) 1659 extern ipf_main_softc_t *ipf_find_softc(u_long); 1660 extern int ipf_set_loopback(ipf_main_softc_t *, ipftuneable_t *, 1661 ipftuneval_t *); 1662 # endif 1663 1664 #endif /* #ifndef _KERNEL */ 1665 1666 extern char *memstr(const char *, char *, size_t, size_t); 1667 extern int count4bits(u_32_t); 1668 #ifdef USE_INET6 1669 extern int count6bits(u_32_t *); 1670 #endif 1671 extern int frrequest(ipf_main_softc_t *, int, ioctlcmd_t, caddr_t, 1672 int, int); 1673 extern char *getifname(struct ifnet *); 1674 extern int ipfattach(ipf_main_softc_t *); 1675 extern int ipfdetach(ipf_main_softc_t *); 1676 extern u_short ipf_cksum(u_short *, int); 1677 extern int copyinptr(ipf_main_softc_t *, void *, void *, size_t); 1678 extern int copyoutptr(ipf_main_softc_t *, void *, void *, size_t); 1679 extern int ipf_fastroute(mb_t *, mb_t **, fr_info_t *, frdest_t *); 1680 extern int ipf_inject(fr_info_t *, mb_t *); 1681 extern int ipf_inobj(ipf_main_softc_t *, void *, ipfobj_t *, 1682 void *, int); 1683 extern int ipf_inobjsz(ipf_main_softc_t *, void *, void *, 1684 int , int); 1685 extern int ipf_ioctlswitch(ipf_main_softc_t *, int, void *, 1686 ioctlcmd_t, int, int, void *); 1687 extern int ipf_ipf_ioctl(ipf_main_softc_t *, caddr_t, ioctlcmd_t, 1688 int, int, void *); 1689 extern int ipf_ipftune(ipf_main_softc_t *, ioctlcmd_t, void *); 1690 extern int ipf_matcharray_load(ipf_main_softc_t *, caddr_t, 1691 ipfobj_t *, int **); 1692 extern int ipf_matcharray_verify(int *, int); 1693 extern int ipf_outobj(ipf_main_softc_t *, void *, void *, int); 1694 extern int ipf_outobjk(ipf_main_softc_t *, ipfobj_t *, void *); 1695 extern int ipf_outobjsz(ipf_main_softc_t *, void *, void *, 1696 int, int); 1697 extern void *ipf_pullup(mb_t *, fr_info_t *, int); 1698 extern int ipf_resolvedest(ipf_main_softc_t *, char *, 1699 struct frdest *, int); 1700 extern int ipf_resolvefunc(ipf_main_softc_t *, void *); 1701 extern void *ipf_resolvenic(ipf_main_softc_t *, char *, int); 1702 extern int ipf_send_icmp_err(int, fr_info_t *, int); 1703 extern int ipf_send_reset(fr_info_t *); 1704 extern void ipf_apply_timeout(ipftq_t *, u_int); 1705 extern ipftq_t *ipf_addtimeoutqueue(ipf_main_softc_t *, ipftq_t **, 1706 u_int); 1707 extern void ipf_deletequeueentry(ipftqent_t *); 1708 extern int ipf_deletetimeoutqueue(ipftq_t *); 1709 extern void ipf_freetimeoutqueue(ipf_main_softc_t *, ipftq_t *); 1710 extern void ipf_movequeue(u_long, ipftqent_t *, ipftq_t *, 1711 ipftq_t *); 1712 extern void ipf_queueappend(u_long, ipftqent_t *, ipftq_t *, void *); 1713 extern void ipf_queueback(u_long, ipftqent_t *); 1714 extern int ipf_queueflush(ipf_main_softc_t *, ipftq_delete_fn_t, 1715 ipftq_t *, ipftq_t *, u_int *, int, int); 1716 extern void ipf_queuefront(ipftqent_t *); 1717 extern int ipf_settimeout_tcp(ipftuneable_t *, ipftuneval_t *, 1718 ipftq_t *); 1719 extern int ipf_checkv4sum(fr_info_t *); 1720 extern int ipf_checkl4sum(fr_info_t *); 1721 extern int ipf_ifpfillv4addr(int, struct sockaddr_in *, 1722 struct sockaddr_in *, struct in_addr *, 1723 struct in_addr *); 1724 extern int ipf_coalesce(fr_info_t *); 1725 #ifdef USE_INET6 1726 extern int ipf_checkv6sum(fr_info_t *); 1727 extern int ipf_ifpfillv6addr(int, struct sockaddr_in6 *, 1728 struct sockaddr_in6 *, i6addr_t *, 1729 i6addr_t *); 1730 #endif 1731 1732 extern int ipf_tune_add(ipf_main_softc_t *, ipftuneable_t *); 1733 extern int ipf_tune_add_array(ipf_main_softc_t *, ipftuneable_t *); 1734 extern int ipf_tune_del(ipf_main_softc_t *, ipftuneable_t *); 1735 extern int ipf_tune_del_array(ipf_main_softc_t *, ipftuneable_t *); 1736 extern int ipf_tune_array_link(ipf_main_softc_t *, ipftuneable_t *); 1737 extern int ipf_tune_array_unlink(ipf_main_softc_t *, 1738 ipftuneable_t *); 1739 extern ipftuneable_t *ipf_tune_array_copy(void *, size_t, 1740 ipftuneable_t *); 1741 1742 extern int ipf_pr_pullup(fr_info_t *, int); 1743 1744 extern int ipf_flush(ipf_main_softc_t *, minor_t, int); 1745 extern frgroup_t *ipf_group_add(ipf_main_softc_t *, char *, void *, 1746 u_32_t, minor_t, int); 1747 extern void ipf_group_del(ipf_main_softc_t *, frgroup_t *, 1748 frentry_t *); 1749 extern int ipf_derefrule(ipf_main_softc_t *, frentry_t **); 1750 extern frgroup_t *ipf_findgroup(ipf_main_softc_t *, char *, minor_t, 1751 int, frgroup_t ***); 1752 1753 extern int ipf_log_init(void); 1754 extern int ipf_log_bytesused(ipf_main_softc_t *, int); 1755 extern int ipf_log_canread(ipf_main_softc_t *, int); 1756 extern int ipf_log_clear(ipf_main_softc_t *, minor_t); 1757 extern u_long ipf_log_failures(ipf_main_softc_t *, int); 1758 extern int ipf_log_read(ipf_main_softc_t *, minor_t, uio_t *); 1759 extern int ipf_log_items(ipf_main_softc_t *, int, fr_info_t *, 1760 void **, size_t *, int *, int); 1761 extern u_long ipf_log_logok(ipf_main_softc_t *, int); 1762 extern void ipf_log_unload(ipf_main_softc_t *); 1763 extern int ipf_log_pkt(fr_info_t *, u_int); 1764 1765 extern frentry_t *ipf_acctpkt(fr_info_t *, u_32_t *); 1766 extern u_short fr_cksum(fr_info_t *, ip_t *, int, void *); 1767 extern void ipf_deinitialise(ipf_main_softc_t *); 1768 extern int ipf_deliverlocal(ipf_main_softc_t *, int, void *, 1769 i6addr_t *); 1770 extern frentry_t *ipf_dstgrpmap(fr_info_t *, u_32_t *); 1771 extern void ipf_fixskip(frentry_t **, frentry_t *, int); 1772 extern void ipf_forgetifp(ipf_main_softc_t *, void *); 1773 extern frentry_t *ipf_getrulen(ipf_main_softc_t *, int, char *, 1774 u_32_t); 1775 extern int ipf_ifpaddr(ipf_main_softc_t *, int, int, void *, 1776 i6addr_t *, i6addr_t *); 1777 extern void ipf_inet_mask_add(int, ipf_v4_masktab_t *); 1778 extern void ipf_inet_mask_del(int, ipf_v4_masktab_t *); 1779 #ifdef USE_INET6 1780 extern void ipf_inet6_mask_add(int, i6addr_t *, 1781 ipf_v6_masktab_t *); 1782 extern void ipf_inet6_mask_del(int, i6addr_t *, 1783 ipf_v6_masktab_t *); 1784 #endif 1785 extern int ipf_initialise(void); 1786 extern int ipf_lock(caddr_t, int *); 1787 extern int ipf_makefrip(int, ip_t *, fr_info_t *); 1788 extern int ipf_matchtag(ipftag_t *, ipftag_t *); 1789 extern int ipf_matchicmpqueryreply(int, icmpinfo_t *, 1790 struct icmp *, int); 1791 extern u_32_t ipf_newisn(fr_info_t *); 1792 extern u_int ipf_pcksum(fr_info_t *, int, u_int); 1793 #ifdef USE_INET6 1794 extern u_int ipf_pcksum6(struct mbuf *, ip6_t *, 1795 u_int32_t, u_int32_t); 1796 #endif 1797 extern void ipf_rule_expire(ipf_main_softc_t *); 1798 extern int ipf_scanlist(fr_info_t *, u_32_t); 1799 extern frentry_t *ipf_srcgrpmap(fr_info_t *, u_32_t *); 1800 extern int ipf_tcpudpchk(fr_ip_t *, frtuc_t *); 1801 extern int ipf_verifysrc(fr_info_t *fin); 1802 extern int ipf_zerostats(ipf_main_softc_t *, char *); 1803 extern int ipf_getnextrule(ipf_main_softc_t *, ipftoken_t *, 1804 void *); 1805 extern int ipf_sync(ipf_main_softc_t *, void *); 1806 extern int ipf_token_deref(ipf_main_softc_t *, ipftoken_t *); 1807 extern void ipf_token_expire(ipf_main_softc_t *); 1808 extern ipftoken_t *ipf_token_find(ipf_main_softc_t *, int, int, 1809 void *); 1810 extern int ipf_token_del(ipf_main_softc_t *, int, int, 1811 void *); 1812 extern void ipf_token_mark_complete(ipftoken_t *); 1813 extern int ipf_genericiter(ipf_main_softc_t *, void *, 1814 int, void *); 1815 #ifdef IPFILTER_LOOKUP 1816 extern void *ipf_resolvelookup(int, u_int, u_int, 1817 lookupfunc_t *); 1818 #endif 1819 extern u_32_t ipf_random(void); 1820 1821 extern int ipf_main_load(void); 1822 extern void *ipf_main_soft_create(void *); 1823 extern void ipf_main_soft_destroy(ipf_main_softc_t *); 1824 extern int ipf_main_soft_init(ipf_main_softc_t *); 1825 extern int ipf_main_soft_fini(ipf_main_softc_t *); 1826 extern int ipf_main_unload(void); 1827 extern int ipf_load_all(void); 1828 extern int ipf_unload_all(void); 1829 extern void ipf_destroy_all(ipf_main_softc_t *); 1830 extern ipf_main_softc_t *ipf_create_all(void *); 1831 extern int ipf_init_all(ipf_main_softc_t *); 1832 extern int ipf_fini_all(ipf_main_softc_t *); 1833 extern void ipf_log_soft_destroy(ipf_main_softc_t *, void *); 1834 extern void *ipf_log_soft_create(ipf_main_softc_t *); 1835 extern int ipf_log_soft_init(ipf_main_softc_t *, void *); 1836 extern int ipf_log_soft_fini(ipf_main_softc_t *, void *); 1837 extern int ipf_log_main_load(void); 1838 extern int ipf_log_main_unload(void); 1839 1840 1841 extern char ipfilter_version[]; 1842 #ifdef USE_INET6 1843 extern int icmptoicmp6types[ICMP_MAXTYPE+1]; 1844 extern int icmptoicmp6unreach[ICMP_MAX_UNREACH]; 1845 extern int icmpreplytype6[ICMP6_MAXTYPE + 1]; 1846 #endif 1847 #ifdef IPFILTER_COMPAT 1848 extern int ipf_in_compat(ipf_main_softc_t *, ipfobj_t *, void *,int); 1849 extern int ipf_out_compat(ipf_main_softc_t *, ipfobj_t *, void *); 1850 #endif 1851 extern int icmpreplytype4[ICMP_MAXTYPE + 1]; 1852 1853 extern int ipf_ht_node_add(ipf_main_softc_t *, host_track_t *, 1854 int, i6addr_t *); 1855 extern int ipf_ht_node_del(host_track_t *, int, i6addr_t *); 1856 extern void ipf_rb_ht_flush(host_track_t *); 1857 extern void ipf_rb_ht_freenode(host_node_t *, void *); 1858 extern void ipf_rb_ht_init(host_track_t *); 1859 1860 #endif /* __IP_FIL_H__ */ 1861