1 /* 2 * Copyright (C) 1993-2001, 2003 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 * $Id: ip_fil.h,v 2.170.2.22 2005/07/16 05:55:35 darrenr Exp $ 8 * 9 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 10 * Use is subject to license terms. 11 */ 12 13 #pragma ident "%Z%%M% %I% %E% SMI" 14 15 #ifndef __IP_FIL_H__ 16 #define __IP_FIL_H__ 17 18 #include "netinet/ip_compat.h" 19 20 #ifndef SOLARIS 21 # define SOLARIS (defined(sun) && (defined(__svr4__) || defined(__SVR4))) 22 #endif 23 24 #ifndef __P 25 # ifdef __STDC__ 26 # define __P(x) x 27 # else 28 # define __P(x) () 29 # endif 30 #endif 31 32 #if defined(__STDC__) || defined(__GNUC__) || defined(_AIX51) 33 # define SIOCADAFR _IOW('r', 60, struct ipfobj) 34 # define SIOCRMAFR _IOW('r', 61, struct ipfobj) 35 # define SIOCSETFF _IOW('r', 62, u_int) 36 # define SIOCGETFF _IOR('r', 63, u_int) 37 # define SIOCGETFS _IOWR('r', 64, struct ipfobj) 38 # define SIOCIPFFL _IOWR('r', 65, int) 39 # define SIOCIPFFB _IOR('r', 66, int) 40 # define SIOCADIFR _IOW('r', 67, struct ipfobj) 41 # define SIOCRMIFR _IOW('r', 68, struct ipfobj) 42 # define SIOCSWAPA _IOR('r', 69, u_int) 43 # define SIOCINAFR _IOW('r', 70, struct ipfobj) 44 # define SIOCINIFR _IOW('r', 71, struct ipfobj) 45 # define SIOCFRENB _IOW('r', 72, u_int) 46 # define SIOCFRSYN _IOW('r', 73, u_int) 47 # define SIOCFRZST _IOWR('r', 74, struct ipfobj) 48 # define SIOCZRLST _IOWR('r', 75, struct ipfobj) 49 # define SIOCAUTHW _IOWR('r', 76, struct ipfobj) 50 # define SIOCAUTHR _IOWR('r', 77, struct ipfobj) 51 # define SIOCATHST _IOWR('r', 78, struct ipfobj) 52 # define SIOCSTLCK _IOWR('r', 79, u_int) 53 # define SIOCSTPUT _IOWR('r', 80, struct ipfobj) 54 # define SIOCSTGET _IOWR('r', 81, struct ipfobj) 55 # define SIOCSTGSZ _IOWR('r', 82, struct ipfobj) 56 # define SIOCGFRST _IOWR('r', 83, struct ipfobj) 57 # define SIOCSETLG _IOWR('r', 84, int) 58 # define SIOCGETLG _IOWR('r', 85, int) 59 # define SIOCFUNCL _IOWR('r', 86, struct ipfunc_resolve) 60 # define SIOCIPFGETNEXT _IOWR('r', 87, struct ipfobj) 61 # define SIOCIPFGET _IOWR('r', 88, struct ipfobj) 62 # define SIOCIPFSET _IOWR('r', 89, struct ipfobj) 63 # define SIOCIPFL6 _IOWR('r', 90, int) 64 #else 65 # define SIOCADAFR _IOW(r, 60, struct ipfobj) 66 # define SIOCRMAFR _IOW(r, 61, struct ipfobj) 67 # define SIOCSETFF _IOW(r, 62, u_int) 68 # define SIOCGETFF _IOR(r, 63, u_int) 69 # define SIOCGETFS _IOWR(r, 64, struct ipfobj) 70 # define SIOCIPFFL _IOWR(r, 65, int) 71 # define SIOCIPFFB _IOR(r, 66, int) 72 # define SIOCADIFR _IOW(r, 67, struct ipfobj) 73 # define SIOCRMIFR _IOW(r, 68, struct ipfobj) 74 # define SIOCSWAPA _IOR(r, 69, u_int) 75 # define SIOCINAFR _IOW(r, 70, struct ipfobj) 76 # define SIOCINIFR _IOW(r, 71, struct ipfobj) 77 # define SIOCFRENB _IOW(r, 72, u_int) 78 # define SIOCFRSYN _IOW(r, 73, u_int) 79 # define SIOCFRZST _IOWR(r, 74, struct ipfobj) 80 # define SIOCZRLST _IOWR(r, 75, struct ipfobj) 81 # define SIOCAUTHW _IOWR(r, 76, struct ipfobj) 82 # define SIOCAUTHR _IOWR(r, 77, struct ipfobj) 83 # define SIOCATHST _IOWR(r, 78, struct ipfobj) 84 # define SIOCSTLCK _IOWR(r, 79, u_int) 85 # define SIOCSTPUT _IOWR(r, 80, struct ipfobj) 86 # define SIOCSTGET _IOWR(r, 81, struct ipfobj) 87 # define SIOCSTGSZ _IOWR(r, 82, struct ipfobj) 88 # define SIOCGFRST _IOWR(r, 83, struct ipfobj) 89 # define SIOCSETLG _IOWR(r, 84, int) 90 # define SIOCGETLG _IOWR(r, 85, int) 91 # define SIOCFUNCL _IOWR(r, 86, struct ipfunc_resolve) 92 # define SIOCIPFGETNEXT _IOWR(r, 87, struct ipfobj) 93 # define SIOCIPFGET _IOWR(r, 88, struct ipfobj) 94 # define SIOCIPFSET _IOWR(r, 89, struct ipfobj) 95 # define SIOCIPFL6 _IOWR(r, 90, int) 96 #endif 97 #define SIOCADDFR SIOCADAFR 98 #define SIOCDELFR SIOCRMAFR 99 #define SIOCINSFR SIOCINAFR 100 101 102 struct ipscan; 103 struct ifnet; 104 105 106 typedef int (* lookupfunc_t) __P((void *, int, void *)); 107 108 /* 109 * i6addr is used as a container for both IPv4 and IPv6 addresses, as well 110 * as other types of objects, depending on its qualifier. 111 */ 112 #ifdef USE_INET6 113 typedef union i6addr { 114 u_32_t i6[4]; 115 struct in_addr in4; 116 struct in6_addr in6; 117 void *vptr[2]; 118 lookupfunc_t lptr[2]; 119 } i6addr_t; 120 #define in6_addr8 in6.s6_addr 121 #else 122 typedef union i6addr { 123 u_32_t i6[4]; 124 struct in_addr in4; 125 void *vptr[2]; 126 lookupfunc_t lptr[2]; 127 } i6addr_t; 128 #endif 129 130 #define in4_addr in4.s_addr 131 #define iplookupnum i6[0] 132 #define iplookuptype i6[1] 133 /* 134 * NOTE: These DO overlap the above on 64bit systems and this IS recognised. 135 */ 136 #define iplookupptr vptr[0] 137 #define iplookupfunc lptr[1] 138 139 #define I60(x) (((i6addr_t *)(x))->i6[0]) 140 #define I61(x) (((i6addr_t *)(x))->i6[1]) 141 #define I62(x) (((i6addr_t *)(x))->i6[2]) 142 #define I63(x) (((i6addr_t *)(x))->i6[3]) 143 #define HI60(x) ntohl(((i6addr_t *)(x))->i6[0]) 144 #define HI61(x) ntohl(((i6addr_t *)(x))->i6[1]) 145 #define HI62(x) ntohl(((i6addr_t *)(x))->i6[2]) 146 #define HI63(x) ntohl(((i6addr_t *)(x))->i6[3]) 147 148 #define IP6_EQ(a,b) ((I63(a) == I63(b)) && (I62(a) == I62(b)) && \ 149 (I61(a) == I61(b)) && (I60(a) == I60(b))) 150 #define IP6_NEQ(a,b) ((I63(a) != I63(b)) || (I62(a) != I62(b)) || \ 151 (I61(a) != I61(b)) || (I60(a) != I60(b))) 152 #define IP6_ISZERO(a) ((I60(a) | I61(a) | I62(a) | I63(a)) == 0) 153 #define IP6_NOTZERO(a) ((I60(a) | I61(a) | I62(a) | I63(a)) != 0) 154 #define IP6_GT(a,b) (HI60(a) > HI60(b) || (HI60(a) == HI60(b) && \ 155 (HI61(a) > HI61(b) || (HI61(a) == HI61(b) && \ 156 (HI62(a) > HI62(b) || (HI62(a) == HI62(b) && \ 157 HI63(a) > HI63(b))))))) 158 #define IP6_LT(a,b) (HI60(a) < HI60(b) || (HI60(a) == HI60(b) && \ 159 (HI61(a) < HI61(b) || (HI61(a) == HI61(b) && \ 160 (HI62(a) < HI62(b) || (HI62(a) == HI62(b) && \ 161 HI63(a) < HI63(b))))))) 162 #define NLADD(n,x) htonl(ntohl(n) + (x)) 163 #define IP6_INC(a) \ 164 { i6addr_t *_i6 = (i6addr_t *)(a); \ 165 _i6->i6[0] = NLADD(_i6->i6[0], 1); \ 166 if (_i6->i6[0] == 0) { \ 167 _i6->i6[0] = NLADD(_i6->i6[1], 1); \ 168 if (_i6->i6[1] == 0) { \ 169 _i6->i6[0] = NLADD(_i6->i6[2], 1); \ 170 if (_i6->i6[2] == 0) { \ 171 _i6->i6[0] = NLADD(_i6->i6[3], 1); \ 172 } \ 173 } \ 174 } \ 175 } 176 #define IP6_ADD(a,x,d) \ 177 { i6addr_t *_s = (i6addr_t *)(a); \ 178 i6addr_t *_d = (i6addr_t *)(d); \ 179 _d->i6[0] = NLADD(_s->i6[0], x); \ 180 if (ntohl(_d->i6[0]) < ntohl(_s->i6[0])) { \ 181 _d->i6[1] = NLADD(_d->i6[1], 1); \ 182 if (ntohl(_d->i6[1]) < ntohl(_s->i6[1])) { \ 183 _d->i6[2] = NLADD(_d->i6[2], 1); \ 184 if (ntohl(_d->i6[2]) < ntohl(_s->i6[2])) { \ 185 _d->i6[3] = NLADD(_d->i6[3], 1); \ 186 } \ 187 } \ 188 } \ 189 } 190 #define IP6_AND(a,b,d) { i6addr_t *_s1 = (i6addr_t *)(a); \ 191 i6addr_t *_s2 = (i6addr_t *)(d); \ 192 i6addr_t *_d = (i6addr_t *)(d); \ 193 _d->i6[0] = _s1->i6[0] & _s2->i6[0]; \ 194 _d->i6[1] = _s1->i6[1] & _s2->i6[1]; \ 195 _d->i6[2] = _s1->i6[2] & _s2->i6[2]; \ 196 _d->i6[3] = _s1->i6[3] & _s2->i6[3]; \ 197 } 198 #define IP6_MERGE(a,b,c) \ 199 { i6addr_t *_d, *_s1, *_s2; \ 200 _d = (i6addr_t *)(a); \ 201 _s1 = (i6addr_t *)(b); \ 202 _s2 = (i6addr_t *)(c); \ 203 _d->i6[0] |= _s1->i6[0] & ~_s2->i6[0]; \ 204 _d->i6[1] |= _s1->i6[1] & ~_s2->i6[1]; \ 205 _d->i6[2] |= _s1->i6[2] & ~_s2->i6[2]; \ 206 _d->i6[2] |= _s1->i6[3] & ~_s2->i6[3]; \ 207 } 208 209 210 typedef struct fr_ip { 211 u_32_t fi_v:4; /* IP version */ 212 u_32_t fi_xx:4; /* spare */ 213 u_32_t fi_tos:8; /* IP packet TOS */ 214 u_32_t fi_ttl:8; /* IP packet TTL */ 215 u_32_t fi_p:8; /* IP packet protocol */ 216 u_32_t fi_optmsk; /* bitmask composed from IP options */ 217 i6addr_t fi_src; /* source address from packet */ 218 i6addr_t fi_dst; /* destination address from packet */ 219 u_short fi_secmsk; /* bitmask composed from IP security options */ 220 u_short fi_auth; /* authentication code from IP sec. options */ 221 u_32_t fi_flx; /* packet flags */ 222 u_32_t fi_tcpmsk; /* TCP options set/reset */ 223 u_32_t fi_res1; /* RESERVED */ 224 } fr_ip_t; 225 226 /* 227 * For use in fi_flx 228 */ 229 #define FI_TCPUDP 0x0001 /* TCP/UCP implied comparison*/ 230 #define FI_OPTIONS 0x0002 231 #define FI_FRAG 0x0004 232 #define FI_SHORT 0x0008 233 #define FI_NATED 0x0010 234 #define FI_MULTICAST 0x0020 235 #define FI_BROADCAST 0x0040 236 #define FI_MBCAST 0x0080 237 #define FI_STATE 0x0100 238 #define FI_BADNAT 0x0200 239 #define FI_BAD 0x0400 240 #define FI_OOW 0x0800 /* Out of state window, else match */ 241 #define FI_ICMPERR 0x1000 242 #define FI_FRAGBODY 0x2000 243 #define FI_BADSRC 0x4000 244 #define FI_LOWTTL 0x8000 245 #define FI_CMP 0xcfe3 /* Not FI_FRAG,FI_NATED,FI_FRAGTAIL */ 246 #define FI_ICMPCMP 0x0003 /* Flags we can check for ICMP error packets */ 247 #define FI_WITH 0xeffe /* Not FI_TCPUDP */ 248 #define FI_V6EXTHDR 0x10000 249 #define FI_COALESCE 0x20000 250 #define FI_NOCKSUM 0x20000000 /* don't do a L4 checksum validation */ 251 #define FI_DONTCACHE 0x40000000 /* don't cache the result */ 252 #define FI_IGNORE 0x80000000 253 254 #define fi_saddr fi_src.in4.s_addr 255 #define fi_daddr fi_dst.in4.s_addr 256 #define fi_srcnum fi_src.iplookupnum 257 #define fi_dstnum fi_dst.iplookupnum 258 #define fi_srctype fi_src.iplookuptype 259 #define fi_dsttype fi_dst.iplookuptype 260 #define fi_srcptr fi_src.iplookupptr 261 #define fi_dstptr fi_dst.iplookupptr 262 #define fi_srcfunc fi_src.iplookupfunc 263 #define fi_dstfunc fi_dst.iplookupfunc 264 265 266 /* 267 * These are both used by the state and NAT code to indicate that one port or 268 * the other should be treated as a wildcard. 269 * NOTE: When updating, check bit masks in ip_state.h and update there too. 270 */ 271 #define SI_W_SPORT 0x00000100 272 #define SI_W_DPORT 0x00000200 273 #define SI_WILDP (SI_W_SPORT|SI_W_DPORT) 274 #define SI_W_SADDR 0x00000400 275 #define SI_W_DADDR 0x00000800 276 #define SI_WILDA (SI_W_SADDR|SI_W_DADDR) 277 #define SI_NEWFR 0x00001000 278 #define SI_CLONE 0x00002000 279 #define SI_CLONED 0x00004000 280 281 282 typedef struct fr_info { 283 void *fin_ifp; /* interface packet is `on' */ 284 fr_ip_t fin_fi; /* IP Packet summary */ 285 union { 286 u_short fid_16[2]; /* TCP/UDP ports, ICMP code/type */ 287 u_32_t fid_32; 288 } fin_dat; 289 int fin_out; /* in or out ? 1 == out, 0 == in */ 290 int fin_rev; /* state only: 1 = reverse */ 291 u_short fin_hlen; /* length of IP header in bytes */ 292 u_char fin_tcpf; /* TCP header flags (SYN, ACK, etc) */ 293 u_char fin_icode; /* ICMP error to return */ 294 u_32_t fin_rule; /* rule # last matched */ 295 char fin_group[FR_GROUPLEN]; /* group number, -1 for none */ 296 struct frentry *fin_fr; /* last matching rule */ 297 void *fin_dp; /* start of data past IP header */ 298 int fin_dlen; /* length of data portion of packet */ 299 int fin_plen; 300 int fin_flen; /* length of layer 4 hdr and 301 ipv6 ext hdr after fragment hdr */ 302 int fin_ipoff; /* # bytes from buffer start to hdr */ 303 u_32_t fin_id; /* IP packet id field */ 304 u_short fin_off; 305 int fin_depth; /* Group nesting depth */ 306 int fin_error; /* Error code to return */ 307 void *fin_nat; 308 void *fin_state; 309 void *fin_nattag; 310 ip_t *fin_ip; 311 mb_t **fin_mp; /* pointer to pointer to mbuf */ 312 mb_t *fin_m; /* pointer to mbuf */ 313 #ifdef MENTAT 314 mb_t *fin_qfm; /* pointer to mblk where pkt starts */ 315 void *fin_qpi; 316 #endif 317 #ifdef __sgi 318 void *fin_hbuf; 319 #endif 320 } fr_info_t; 321 322 #define fin_v fin_fi.fi_v 323 #define fin_p fin_fi.fi_p 324 #define fin_flx fin_fi.fi_flx 325 #define fin_optmsk fin_fi.fi_optmsk 326 #define fin_secmsk fin_fi.fi_secmsk 327 #define fin_auth fin_fi.fi_auth 328 #define fin_src fin_fi.fi_src.in4 329 #define fin_src6 fin_fi.fi_src.in6 330 #define fin_saddr fin_fi.fi_saddr 331 #define fin_dst fin_fi.fi_dst.in4 332 #define fin_dst6 fin_fi.fi_dst.in6 333 #define fin_daddr fin_fi.fi_daddr 334 #define fin_data fin_dat.fid_16 335 #define fin_sport fin_dat.fid_16[0] 336 #define fin_dport fin_dat.fid_16[1] 337 #define fin_ports fin_dat.fid_32 338 339 #define IPF_IN 0 340 #define IPF_OUT 1 341 342 typedef struct frentry *(*ipfunc_t) __P((fr_info_t *, u_32_t *)); 343 typedef int (*ipfuncinit_t) __P((struct frentry *)); 344 345 typedef struct ipfunc_resolve { 346 char ipfu_name[32]; 347 ipfunc_t ipfu_addr; 348 ipfuncinit_t ipfu_init; 349 } ipfunc_resolve_t; 350 351 /* 352 * Size for compares on fr_info structures 353 */ 354 #define FI_CSIZE offsetof(fr_info_t, fin_icode) 355 #define FI_LCSIZE offsetof(fr_info_t, fin_dp) 356 357 /* 358 * Size for copying cache fr_info structure 359 */ 360 #define FI_COPYSIZE offsetof(fr_info_t, fin_dp) 361 362 /* 363 * Structure for holding IPFilter's tag information 364 */ 365 #define IPFTAG_LEN 16 366 typedef struct { 367 union { 368 u_32_t iptu_num[4]; 369 char iptu_tag[IPFTAG_LEN]; 370 } ipt_un; 371 int ipt_not; 372 } ipftag_t; 373 374 #define ipt_tag ipt_un.iptu_tag 375 #define ipt_num ipt_un.iptu_num 376 377 378 /* 379 * This structure is used to hold information about the next hop for where 380 * to forward a packet. 381 */ 382 typedef struct frdest { 383 void *fd_ifp; 384 i6addr_t fd_ip6; 385 char fd_ifname[LIFNAMSIZ]; 386 } frdest_t; 387 388 #define fd_ip fd_ip6.in4 389 390 391 /* 392 * This structure holds information about a port comparison. 393 */ 394 typedef struct frpcmp { 395 int frp_cmp; /* data for port comparisons */ 396 u_short frp_port; /* top port for <> and >< */ 397 u_short frp_top; /* top port for <> and >< */ 398 } frpcmp_t; 399 400 #define FR_NONE 0 401 #define FR_EQUAL 1 402 #define FR_NEQUAL 2 403 #define FR_LESST 3 404 #define FR_GREATERT 4 405 #define FR_LESSTE 5 406 #define FR_GREATERTE 6 407 #define FR_OUTRANGE 7 408 #define FR_INRANGE 8 409 #define FR_INCRANGE 9 410 411 /* 412 * Structure containing all the relevant TCP things that can be checked in 413 * a filter rule. 414 */ 415 typedef struct frtuc { 416 u_char ftu_tcpfm; /* tcp flags mask */ 417 u_char ftu_tcpf; /* tcp flags */ 418 frpcmp_t ftu_src; 419 frpcmp_t ftu_dst; 420 } frtuc_t; 421 422 #define ftu_scmp ftu_src.frp_cmp 423 #define ftu_dcmp ftu_dst.frp_cmp 424 #define ftu_sport ftu_src.frp_port 425 #define ftu_dport ftu_dst.frp_port 426 #define ftu_stop ftu_src.frp_top 427 #define ftu_dtop ftu_dst.frp_top 428 429 #define FR_TCPFMAX 0x3f 430 431 /* 432 * This structure makes up what is considered to be the IPFilter specific 433 * matching components of a filter rule, as opposed to the data structures 434 * used to define the result which are in frentry_t and not here. 435 */ 436 typedef struct fripf { 437 fr_ip_t fri_ip; 438 fr_ip_t fri_mip; /* mask structure */ 439 440 u_short fri_icmpm; /* data for ICMP packets (mask) */ 441 u_short fri_icmp; 442 443 frtuc_t fri_tuc; 444 int fri_satype; /* addres type */ 445 int fri_datype; /* addres type */ 446 int fri_sifpidx; /* doing dynamic addressing */ 447 int fri_difpidx; /* index into fr_ifps[] to use when */ 448 } fripf_t; 449 450 #define fri_dstnum fri_ip.fi_dstnum 451 #define fri_srcnum fri_mip.fi_srcnum 452 #define fri_dstptr fri_ip.fi_dstptr 453 #define fri_srcptr fri_mip.fi_srcptr 454 455 #define FRI_NORMAL 0 /* Normal address */ 456 #define FRI_DYNAMIC 1 /* dynamic address */ 457 #define FRI_LOOKUP 2 /* address is a pool # */ 458 #define FRI_RANGE 3 /* address/mask is a range */ 459 #define FRI_NETWORK 4 /* network address from if */ 460 #define FRI_BROADCAST 5 /* broadcast address from if */ 461 #define FRI_PEERADDR 6 /* Peer address for P-to-P */ 462 #define FRI_NETMASKED 7 /* network address with netmask from if */ 463 464 465 typedef struct frentry * (* frentfunc_t) __P((fr_info_t *)); 466 467 typedef struct frentry { 468 ipfmutex_t fr_lock; 469 struct frentry *fr_next; 470 struct frentry **fr_grp; 471 struct ipscan *fr_isc; 472 void *fr_ifas[4]; 473 void *fr_ptr; /* for use with fr_arg */ 474 char *fr_comment; /* text comment for rule */ 475 int fr_ref; /* reference count - for grouping */ 476 int fr_statecnt; /* state count - for limit rules */ 477 /* 478 * These are only incremented when a packet matches this rule and 479 * it is the last match 480 */ 481 U_QUAD_T fr_hits; 482 U_QUAD_T fr_bytes; 483 484 /* 485 * For PPS rate limiting 486 */ 487 struct timeval fr_lastpkt; 488 int fr_curpps; 489 490 union { 491 void *fru_data; 492 caddr_t fru_caddr; 493 fripf_t *fru_ipf; 494 frentfunc_t fru_func; 495 } fr_dun; 496 497 /* 498 * Fields after this may not change whilst in the kernel. 499 */ 500 ipfunc_t fr_func; /* call this function */ 501 int fr_dsize; 502 int fr_pps; 503 int fr_statemax; /* max reference count */ 504 int fr_flineno; /* line number from conf file */ 505 u_32_t fr_type; 506 u_32_t fr_flags; /* per-rule flags && options (see below) */ 507 u_32_t fr_logtag; /* user defined log tag # */ 508 u_32_t fr_collect; /* collection number */ 509 u_int fr_arg; /* misc. numeric arg for rule */ 510 u_int fr_loglevel; /* syslog log facility + priority */ 511 u_int fr_age[2]; /* non-TCP timeouts */ 512 u_char fr_v; 513 u_char fr_icode; /* return ICMP code */ 514 char fr_group[FR_GROUPLEN]; /* group to which this rule belongs */ 515 char fr_grhead[FR_GROUPLEN]; /* group # which this rule starts */ 516 ipftag_t fr_nattag; 517 char fr_ifnames[4][LIFNAMSIZ]; 518 char fr_isctag[16]; 519 frdest_t fr_tifs[2]; /* "to"/"reply-to" interface */ 520 frdest_t fr_dif; /* duplicate packet interface */ 521 /* 522 * This must be last and will change after loaded into the kernel. 523 */ 524 u_int fr_cksum; /* checksum on filter rules for performance */ 525 } frentry_t; 526 527 #define fr_caddr fr_dun.fru_caddr 528 #define fr_data fr_dun.fru_data 529 #define fr_dfunc fr_dun.fru_func 530 #define fr_ipf fr_dun.fru_ipf 531 #define fr_ip fr_ipf->fri_ip 532 #define fr_mip fr_ipf->fri_mip 533 #define fr_icmpm fr_ipf->fri_icmpm 534 #define fr_icmp fr_ipf->fri_icmp 535 #define fr_tuc fr_ipf->fri_tuc 536 #define fr_satype fr_ipf->fri_satype 537 #define fr_datype fr_ipf->fri_datype 538 #define fr_sifpidx fr_ipf->fri_sifpidx 539 #define fr_difpidx fr_ipf->fri_difpidx 540 #define fr_proto fr_ip.fi_p 541 #define fr_mproto fr_mip.fi_p 542 #define fr_ttl fr_ip.fi_ttl 543 #define fr_mttl fr_mip.fi_ttl 544 #define fr_tos fr_ip.fi_tos 545 #define fr_mtos fr_mip.fi_tos 546 #define fr_tcpfm fr_tuc.ftu_tcpfm 547 #define fr_tcpf fr_tuc.ftu_tcpf 548 #define fr_scmp fr_tuc.ftu_scmp 549 #define fr_dcmp fr_tuc.ftu_dcmp 550 #define fr_dport fr_tuc.ftu_dport 551 #define fr_sport fr_tuc.ftu_sport 552 #define fr_stop fr_tuc.ftu_stop 553 #define fr_dtop fr_tuc.ftu_dtop 554 #define fr_dst fr_ip.fi_dst.in4 555 #define fr_daddr fr_ip.fi_dst.in4.s_addr 556 #define fr_src fr_ip.fi_src.in4 557 #define fr_saddr fr_ip.fi_src.in4.s_addr 558 #define fr_dmsk fr_mip.fi_dst.in4 559 #define fr_dmask fr_mip.fi_dst.in4.s_addr 560 #define fr_smsk fr_mip.fi_src.in4 561 #define fr_smask fr_mip.fi_src.in4.s_addr 562 #define fr_dstnum fr_ip.fi_dstnum 563 #define fr_srcnum fr_ip.fi_srcnum 564 #define fr_dsttype fr_ip.fi_dsttype 565 #define fr_srctype fr_ip.fi_srctype 566 #define fr_dstptr fr_mip.fi_dstptr 567 #define fr_srcptr fr_mip.fi_srcptr 568 #define fr_dstfunc fr_mip.fi_dstfunc 569 #define fr_srcfunc fr_mip.fi_srcfunc 570 #define fr_optbits fr_ip.fi_optmsk 571 #define fr_optmask fr_mip.fi_optmsk 572 #define fr_secbits fr_ip.fi_secmsk 573 #define fr_secmask fr_mip.fi_secmsk 574 #define fr_authbits fr_ip.fi_auth 575 #define fr_authmask fr_mip.fi_auth 576 #define fr_flx fr_ip.fi_flx 577 #define fr_mflx fr_mip.fi_flx 578 #define fr_ifname fr_ifnames[0] 579 #define fr_oifname fr_ifnames[2] 580 #define fr_ifa fr_ifas[0] 581 #define fr_oifa fr_ifas[2] 582 #define fr_tif fr_tifs[0] 583 #define fr_rif fr_tifs[1] 584 585 #define FR_NOLOGTAG 0 586 587 #ifndef offsetof 588 #define offsetof(t,m) (int)((&((t *)0L)->m)) 589 #endif 590 #define FR_CMPSIZ (sizeof(struct frentry) - \ 591 offsetof(struct frentry, fr_func)) 592 593 /* 594 * fr_type 595 */ 596 #define FR_T_NONE 0 597 #define FR_T_IPF 1 /* IPF structures */ 598 #define FR_T_BPFOPC 2 /* BPF opcode */ 599 #define FR_T_CALLFUNC 3 /* callout to function in fr_func only */ 600 #define FR_T_COMPIPF 4 /* compiled C code */ 601 #define FR_T_BUILTIN 0x80000000 /* rule is in kernel space */ 602 603 /* 604 * fr_flags 605 */ 606 #define FR_CALL 0x00000 /* call rule */ 607 #define FR_BLOCK 0x00001 /* do not allow packet to pass */ 608 #define FR_PASS 0x00002 /* allow packet to pass */ 609 #define FR_AUTH 0x00003 /* use authentication */ 610 #define FR_PREAUTH 0x00004 /* require preauthentication */ 611 #define FR_ACCOUNT 0x00005 /* Accounting rule */ 612 #define FR_SKIP 0x00006 /* skip rule */ 613 #define FR_DIVERT 0x00007 /* divert rule */ 614 #define FR_CMDMASK 0x0000f 615 #define FR_LOG 0x00010 /* Log */ 616 #define FR_LOGB 0x00011 /* Log-fail */ 617 #define FR_LOGP 0x00012 /* Log-pass */ 618 #define FR_LOGMASK (FR_LOG|FR_CMDMASK) 619 #define FR_CALLNOW 0x00020 /* call another function (fr_func) if matches */ 620 #define FR_NOTSRCIP 0x00040 621 #define FR_NOTDSTIP 0x00080 622 #define FR_QUICK 0x00100 /* match & stop processing list */ 623 #define FR_KEEPFRAG 0x00200 /* keep fragment information */ 624 #define FR_KEEPSTATE 0x00400 /* keep `connection' state information */ 625 #define FR_FASTROUTE 0x00800 /* bypass normal routing */ 626 #define FR_RETRST 0x01000 /* Return TCP RST packet - reset connection */ 627 #define FR_RETICMP 0x02000 /* Return ICMP unreachable packet */ 628 #define FR_FAKEICMP 0x03000 /* Return ICMP unreachable with fake source */ 629 #define FR_OUTQUE 0x04000 /* outgoing packets */ 630 #define FR_INQUE 0x08000 /* ingoing packets */ 631 #define FR_LOGBODY 0x10000 /* Log the body */ 632 #define FR_LOGFIRST 0x20000 /* Log the first byte if state held */ 633 #define FR_LOGORBLOCK 0x40000 /* block the packet if it can't be logged */ 634 #define FR_DUP 0x80000 /* duplicate packet */ 635 #define FR_FRSTRICT 0x100000 /* strict frag. cache */ 636 #define FR_STSTRICT 0x200000 /* strict keep state */ 637 #define FR_NEWISN 0x400000 /* new ISN for outgoing TCP */ 638 #define FR_NOICMPERR 0x800000 /* do not match ICMP errors in state */ 639 #define FR_STATESYNC 0x1000000 /* synchronize state to slave */ 640 #define FR_NOMATCH 0x8000000 /* no match occured */ 641 /* 0x10000000 FF_LOGPASS */ 642 /* 0x20000000 FF_LOGBLOCK */ 643 /* 0x40000000 FF_LOGNOMATCH */ 644 /* 0x80000000 FF_BLOCKNONIP */ 645 #define FR_COPIED 0x40000000 /* copied from user space */ 646 #define FR_INACTIVE 0x80000000 /* only used when flush'ing rules */ 647 648 #define FR_RETMASK (FR_RETICMP|FR_RETRST|FR_FAKEICMP) 649 #define FR_ISBLOCK(x) (((x) & FR_CMDMASK) == FR_BLOCK) 650 #define FR_ISPASS(x) (((x) & FR_CMDMASK) == FR_PASS) 651 #define FR_ISAUTH(x) (((x) & FR_CMDMASK) == FR_AUTH) 652 #define FR_ISPREAUTH(x) (((x) & FR_CMDMASK) == FR_PREAUTH) 653 #define FR_ISACCOUNT(x) (((x) & FR_CMDMASK) == FR_ACCOUNT) 654 #define FR_ISSKIP(x) (((x) & FR_CMDMASK) == FR_SKIP) 655 #define FR_ISNOMATCH(x) ((x) & FR_NOMATCH) 656 #define FR_INOUT (FR_INQUE|FR_OUTQUE) 657 658 /* 659 * recognized flags for SIOCGETFF and SIOCSETFF, and get put in fr_flags 660 */ 661 #define FF_LOGPASS 0x10000000 662 #define FF_LOGBLOCK 0x20000000 663 #define FF_LOGNOMATCH 0x40000000 664 #define FF_LOGGING (FF_LOGPASS|FF_LOGBLOCK|FF_LOGNOMATCH) 665 #define FF_BLOCKNONIP 0x80000000 /* Solaris2 Only */ 666 667 668 /* 669 * Structure that passes information on what/how to flush to the kernel. 670 */ 671 typedef struct ipfflush { 672 int ipflu_how; 673 int ipflu_arg; 674 } ipfflush_t; 675 676 677 /* 678 * 679 */ 680 typedef struct ipfgetctl { 681 u_int ipfg_min; /* min value */ 682 u_int ipfg_current; /* current value */ 683 u_int ipfg_max; /* max value */ 684 u_int ipfg_default; /* default value */ 685 u_int ipfg_steps; /* value increments */ 686 char ipfg_name[40]; /* tag name for this control */ 687 } ipfgetctl_t; 688 689 typedef struct ipfsetctl { 690 int ipfs_which; /* 0 = min 1 = current 2 = max 3 = default */ 691 u_int ipfs_value; /* min value */ 692 char ipfs_name[40]; /* tag name for this control */ 693 } ipfsetctl_t; 694 695 696 /* 697 * Some of the statistics below are in their own counters, but most are kept 698 * in this single structure so that they can all easily be collected and 699 * copied back as required. 700 * 701 * NOTE: when changing, keep in sync with kstats (below). 702 */ 703 typedef struct filterstats { 704 u_long fr_pass; /* packets allowed */ 705 u_long fr_block; /* packets denied */ 706 u_long fr_nom; /* packets which don't match any rule */ 707 u_long fr_short; /* packets which are short */ 708 u_long fr_ppkl; /* packets allowed and logged */ 709 u_long fr_bpkl; /* packets denied and logged */ 710 u_long fr_npkl; /* packets unmatched and logged */ 711 u_long fr_pkl; /* packets logged */ 712 u_long fr_skip; /* packets to be logged but buffer full */ 713 u_long fr_ret; /* packets for which a return is sent */ 714 u_long fr_acct; /* packets for which counting was performed */ 715 u_long fr_bnfr; /* bad attempts to allocate fragment state */ 716 u_long fr_nfr; /* new fragment state kept */ 717 u_long fr_cfr; /* add new fragment state but complete pkt */ 718 u_long fr_bads; /* bad attempts to allocate packet state */ 719 u_long fr_ads; /* new packet state kept */ 720 u_long fr_chit; /* cached hit */ 721 u_long fr_tcpbad; /* TCP checksum check failures */ 722 u_long fr_pull[2]; /* good and bad pullup attempts */ 723 u_long fr_badsrc; /* source received doesn't match route */ 724 u_long fr_badttl; /* TTL in packet doesn't reach minimum */ 725 u_long fr_bad; /* bad IP packets to the filter */ 726 u_long fr_ipv6; /* IPv6 packets in/out */ 727 u_long fr_ppshit; /* dropped because of pps ceiling */ 728 u_long fr_ipud; /* IP id update failures */ 729 } filterstats_t; 730 731 /* 732 * kstat "copy" of the above - keep in sync! 733 * also keep in sync with initialisation code in solaris.c, ipf_kstat_init(). 734 */ 735 typedef struct filter_kstats { 736 kstat_named_t fks_pass; /* see above for comments */ 737 kstat_named_t fks_block; 738 kstat_named_t fks_nom; 739 kstat_named_t fks_short; 740 kstat_named_t fks_ppkl; 741 kstat_named_t fks_bpkl; 742 kstat_named_t fks_npkl; 743 kstat_named_t fks_pkl; 744 kstat_named_t fks_skip; 745 kstat_named_t fks_ret; 746 kstat_named_t fks_acct; 747 kstat_named_t fks_bnfr; 748 kstat_named_t fks_nfr; 749 kstat_named_t fks_cfr; 750 kstat_named_t fks_bads; 751 kstat_named_t fks_ads; 752 kstat_named_t fks_chit; 753 kstat_named_t fks_tcpbad; 754 kstat_named_t fks_pull[2]; 755 kstat_named_t fks_badsrc; 756 kstat_named_t fks_badttl; 757 kstat_named_t fks_bad; 758 kstat_named_t fks_ipv6; 759 kstat_named_t fks_ppshit; 760 kstat_named_t fks_ipud; 761 } filter_kstats_t; 762 763 /* 764 * Log structure. Each packet header logged is prepended by one of these. 765 * Following this in the log records read from the device will be an ipflog 766 * structure which is then followed by any packet data. 767 */ 768 typedef struct iplog { 769 u_32_t ipl_magic; 770 u_int ipl_count; 771 struct timeval ipl_time; 772 size_t ipl_dsize; 773 struct iplog *ipl_next; 774 } iplog_t; 775 776 #define ipl_sec ipl_time.tv_sec 777 #define ipl_usec ipl_time.tv_usec 778 779 #define IPL_MAGIC 0x49504c4d /* 'IPLM' */ 780 #define IPL_MAGIC_NAT 0x49504c4e /* 'IPLN' */ 781 #define IPL_MAGIC_STATE 0x49504c53 /* 'IPLS' */ 782 #define IPLOG_SIZE sizeof(iplog_t) 783 784 typedef struct ipflog { 785 #if (defined(NetBSD) && (NetBSD <= 1991011) && (NetBSD >= 199603)) || \ 786 (defined(OpenBSD) && (OpenBSD >= 199603)) 787 #else 788 u_int fl_unit; 789 #endif 790 u_32_t fl_rule; 791 u_32_t fl_flags; 792 u_32_t fl_lflags; 793 u_32_t fl_logtag; 794 ipftag_t fl_nattag; 795 u_short fl_plen; /* extra data after hlen */ 796 u_short fl_loglevel; /* syslog log level */ 797 char fl_group[FR_GROUPLEN]; 798 u_char fl_hlen; /* length of IP headers saved */ 799 u_char fl_dir; 800 u_char fl_xxx[2]; /* pad */ 801 char fl_ifname[LIFNAMSIZ]; 802 } ipflog_t; 803 804 #ifndef IPF_LOGGING 805 # define IPF_LOGGING 0 806 #endif 807 #ifndef IPF_DEFAULT_PASS 808 # define IPF_DEFAULT_PASS FR_PASS 809 #endif 810 811 #define DEFAULT_IPFLOGSIZE 8192 812 #ifndef IPFILTER_LOGSIZE 813 # define IPFILTER_LOGSIZE DEFAULT_IPFLOGSIZE 814 #else 815 # if IPFILTER_LOGSIZE < DEFAULT_IPFLOGSIZE 816 # error IPFILTER_LOGSIZE too small. Must be >= DEFAULT_IPFLOGSIZE 817 # endif 818 #endif 819 820 #define IPF_OPTCOPY 0x07ff00 /* bit mask of copied options */ 821 822 /* 823 * Device filenames for reading log information. Use ipf on Solaris2 because 824 * ipl is already a name used by something else. 825 */ 826 #ifndef IPL_NAME 827 # if SOLARIS 828 # define IPL_NAME "/dev/ipf" 829 # else 830 # define IPL_NAME "/dev/ipl" 831 # endif 832 #endif 833 /* 834 * Pathnames for various IP Filter control devices. Used by LKM 835 * and userland, so defined here. 836 */ 837 #define IPNAT_NAME "/dev/ipnat" 838 #define IPSTATE_NAME "/dev/ipstate" 839 #define IPAUTH_NAME "/dev/ipauth" 840 #define IPSYNC_NAME "/dev/ipsync" 841 #define IPSCAN_NAME "/dev/ipscan" 842 #define IPLOOKUP_NAME "/dev/iplookup" 843 844 #define IPL_LOGIPF 0 /* Minor device #'s for accessing logs */ 845 #define IPL_LOGNAT 1 846 #define IPL_LOGSTATE 2 847 #define IPL_LOGAUTH 3 848 #define IPL_LOGSYNC 4 849 #define IPL_LOGSCAN 5 850 #define IPL_LOGLOOKUP 6 851 #define IPL_LOGCOUNT 7 852 #define IPL_LOGMAX 7 853 #define IPL_LOGSIZE IPL_LOGMAX + 1 854 #define IPL_LOGALL -1 855 #define IPL_LOGNONE -2 856 857 /* 858 * For SIOCGETFS 859 */ 860 typedef struct friostat { 861 struct filterstats f_st[2]; 862 struct frentry *f_ipf[2][2]; 863 struct frentry *f_acct[2][2]; 864 struct frentry *f_ipf6[2][2]; 865 struct frentry *f_acct6[2][2]; 866 struct frentry *f_auth; 867 struct frgroup *f_groups[IPL_LOGSIZE][2]; 868 u_long f_froute[2]; 869 u_long f_ticks; 870 int f_locks[IPL_LOGMAX]; 871 size_t f_kmutex_sz; 872 size_t f_krwlock_sz; 873 int f_defpass; /* default pass - from fr_pass */ 874 int f_active; /* 1 or 0 - active rule set */ 875 int f_running; /* 1 if running, else 0 */ 876 int f_logging; /* 1 if enabled, else 0 */ 877 int f_features; 878 char f_version[32]; /* version string */ 879 } friostat_t; 880 881 #define f_fin f_ipf[0] 882 #define f_fin6 f_ipf6[0] 883 #define f_fout f_ipf[1] 884 #define f_fout6 f_ipf6[1] 885 #define f_acctin f_acct[0] 886 #define f_acctin6 f_acct6[0] 887 #define f_acctout f_acct[1] 888 #define f_acctout6 f_acct6[1] 889 890 #define IPF_FEAT_LKM 0x001 891 #define IPF_FEAT_LOG 0x002 892 #define IPF_FEAT_LOOKUP 0x004 893 #define IPF_FEAT_BPF 0x008 894 #define IPF_FEAT_COMPILED 0x010 895 #define IPF_FEAT_CKSUM 0x020 896 #define IPF_FEAT_SYNC 0x040 897 #define IPF_FEAT_SCAN 0x080 898 #define IPF_FEAT_IPV6 0x100 899 900 typedef struct optlist { 901 u_short ol_val; 902 int ol_bit; 903 } optlist_t; 904 905 906 /* 907 * Group list structure. 908 */ 909 typedef struct frgroup { 910 struct frgroup *fg_next; 911 struct frentry *fg_head; 912 struct frentry *fg_start; 913 u_32_t fg_flags; 914 int fg_ref; 915 char fg_name[FR_GROUPLEN]; 916 } frgroup_t; 917 918 #define FG_NAME(g) (*(g)->fg_name == '\0' ? "" : (g)->fg_name) 919 920 921 /* 922 * Used by state and NAT tables 923 */ 924 typedef struct icmpinfo { 925 u_short ici_id; 926 u_short ici_seq; 927 u_char ici_type; 928 } icmpinfo_t; 929 930 typedef struct udpinfo { 931 u_short us_sport; 932 u_short us_dport; 933 } udpinfo_t; 934 935 936 typedef struct tcpdata { 937 u_32_t td_end; 938 u_32_t td_maxend; 939 u_32_t td_maxwin; 940 u_32_t td_winscale; 941 u_32_t td_maxseg; 942 int td_winflags; 943 } tcpdata_t; 944 945 #define TCP_WSCALE_MAX 14 946 947 #define TCP_WSCALE_SEEN 0x00000001 948 #define TCP_WSCALE_FIRST 0x00000002 949 950 951 typedef struct tcpinfo { 952 u_short ts_sport; 953 u_short ts_dport; 954 tcpdata_t ts_data[2]; 955 } tcpinfo_t; 956 957 958 /* 959 * Structures to define a GRE header as seen in a packet. 960 */ 961 struct grebits { 962 u_32_t grb_C:1; 963 u_32_t grb_R:1; 964 u_32_t grb_K:1; 965 u_32_t grb_S:1; 966 u_32_t grb_s:1; 967 u_32_t grb_recur:1; 968 u_32_t grb_A:1; 969 u_32_t grb_flags:3; 970 u_32_t grb_ver:3; 971 u_short grb_ptype; 972 }; 973 974 typedef struct grehdr { 975 union { 976 struct grebits gru_bits; 977 u_short gru_flags; 978 } gr_un; 979 u_short gr_len; 980 u_short gr_call; 981 } grehdr_t; 982 983 #define gr_flags gr_un.gru_flags 984 #define gr_bits gr_un.gru_bits 985 #define gr_ptype gr_bits.grb_ptype 986 #define gr_C gr_bits.grb_C 987 #define gr_R gr_bits.grb_R 988 #define gr_K gr_bits.grb_K 989 #define gr_S gr_bits.grb_S 990 #define gr_s gr_bits.grb_s 991 #define gr_recur gr_bits.grb_recur 992 #define gr_A gr_bits.grb_A 993 #define gr_ver gr_bits.grb_ver 994 995 /* 996 * GRE information tracked by "keep state" 997 */ 998 typedef struct greinfo { 999 u_short gs_call[2]; 1000 u_short gs_flags; 1001 u_short gs_ptype; 1002 } greinfo_t; 1003 1004 #define GRE_REV(x) ((ntohs(x) >> 13) & 7) 1005 1006 1007 /* 1008 * Format of an Authentication header 1009 */ 1010 typedef struct authhdr { 1011 u_char ah_next; 1012 u_char ah_plen; 1013 u_short ah_reserved; 1014 u_32_t ah_spi; 1015 u_32_t ah_seq; 1016 /* Following the sequence number field is 0 or more bytes of */ 1017 /* authentication data, as specified by ah_plen - RFC 2402. */ 1018 } authhdr_t; 1019 1020 1021 /* 1022 * Timeout tail queue list member 1023 */ 1024 typedef struct ipftqent { 1025 struct ipftqent **tqe_pnext; 1026 struct ipftqent *tqe_next; 1027 struct ipftq *tqe_ifq; 1028 void *tqe_parent; /* pointer back to NAT/state struct */ 1029 u_long tqe_die; /* when this entriy is to die */ 1030 u_long tqe_touched; 1031 int tqe_flags; 1032 int tqe_state[2]; /* current state of this entry */ 1033 } ipftqent_t; 1034 1035 #define TQE_RULEBASED 0x00000001 1036 1037 1038 /* 1039 * Timeout tail queue head for IPFilter 1040 */ 1041 typedef struct ipftq { 1042 ipfmutex_t ifq_lock; 1043 u_int ifq_ttl; 1044 ipftqent_t *ifq_head; 1045 ipftqent_t **ifq_tail; 1046 struct ipftq *ifq_next; 1047 struct ipftq **ifq_pnext; 1048 int ifq_ref; 1049 u_int ifq_flags; 1050 } ipftq_t; 1051 1052 #define IFQF_USER 0x01 /* User defined aging */ 1053 #define IFQF_DELETE 0x02 /* Marked for deletion */ 1054 #define IFQF_PROXY 0x04 /* Timeout queue in use by a proxy */ 1055 1056 #define IPF_HZ_MULT 1 1057 #define IPF_HZ_DIVIDE 2 /* How many times a second ipfilter */ 1058 /* checks its timeout queues. */ 1059 #define IPF_TTLVAL(x) (((x) / IPF_HZ_MULT) * IPF_HZ_DIVIDE) 1060 1061 /* 1062 * Structure to define address for pool lookups. 1063 */ 1064 typedef struct { 1065 u_char adf_len; 1066 sa_family_t adf_family; 1067 i6addr_t adf_addr; 1068 } addrfamily_t; 1069 1070 1071 /* 1072 * Object structure description. For passing through in ioctls. 1073 */ 1074 typedef struct ipfobj { 1075 u_32_t ipfo_rev; /* IPFilter version number */ 1076 u_32_t ipfo_size; /* size of object at ipfo_ptr */ 1077 void *ipfo_ptr; /* pointer to object */ 1078 int ipfo_type; /* type of object being pointed to */ 1079 int ipfo_offset; /* bytes from ipfo_ptr where to start */ 1080 u_char ipfo_xxxpad[32]; /* reserved for future use */ 1081 } ipfobj_t; 1082 1083 #define IPFOBJ_FRENTRY 0 /* struct frentry */ 1084 #define IPFOBJ_IPFSTAT 1 /* struct friostat */ 1085 #define IPFOBJ_IPFINFO 2 /* struct fr_info */ 1086 #define IPFOBJ_AUTHSTAT 3 /* struct fr_authstat */ 1087 #define IPFOBJ_FRAGSTAT 4 /* struct ipfrstat */ 1088 #define IPFOBJ_IPNAT 5 /* struct ipnat */ 1089 #define IPFOBJ_NATSTAT 6 /* struct natstat */ 1090 #define IPFOBJ_STATESAVE 7 /* struct ipstate_save */ 1091 #define IPFOBJ_NATSAVE 8 /* struct nat_save */ 1092 #define IPFOBJ_NATLOOKUP 9 /* struct natlookup */ 1093 #define IPFOBJ_IPSTATE 10 /* struct ipstate */ 1094 #define IPFOBJ_STATESTAT 11 /* struct ips_stat */ 1095 #define IPFOBJ_FRAUTH 12 /* struct frauth */ 1096 #define IPFOBJ_TUNEABLE 13 /* struct ipftune */ 1097 1098 1099 typedef union ipftunevalptr { 1100 void *ipftp_void; 1101 u_long *ipftp_long; 1102 u_int *ipftp_int; 1103 u_short *ipftp_short; 1104 u_char *ipftp_char; 1105 } ipftunevalptr_t; 1106 1107 typedef struct ipftuneable { 1108 ipftunevalptr_t ipft_una; 1109 char *ipft_name; 1110 u_long ipft_min; 1111 u_long ipft_max; 1112 int ipft_sz; 1113 int ipft_flags; 1114 struct ipftuneable *ipft_next; 1115 } ipftuneable_t; 1116 1117 #define ipft_addr ipft_una.ipftp_void 1118 #define ipft_plong ipft_una.ipftp_long 1119 #define ipft_pint ipft_una.ipftp_int 1120 #define ipft_pshort ipft_una.ipftp_short 1121 #define ipft_pchar ipft_una.ipftp_char 1122 1123 #define IPFT_RDONLY 1 /* read-only */ 1124 #define IPFT_WRDISABLED 2 /* write when disabled only */ 1125 1126 typedef union ipftuneval { 1127 u_long ipftu_long; 1128 u_int ipftu_int; 1129 u_short ipftu_short; 1130 u_char ipftu_char; 1131 } ipftuneval_t; 1132 1133 typedef struct ipftune { 1134 void *ipft_cookie; 1135 ipftuneval_t ipft_un; 1136 u_long ipft_min; 1137 u_long ipft_max; 1138 int ipft_sz; 1139 int ipft_flags; 1140 char ipft_name[80]; 1141 } ipftune_t; 1142 1143 #define ipft_vlong ipft_un.ipftu_long 1144 #define ipft_vint ipft_un.ipftu_int 1145 #define ipft_vshort ipft_un.ipftu_short 1146 #define ipft_vchar ipft_un.ipftu_char 1147 1148 1149 /* 1150 ** HPUX Port 1151 */ 1152 #ifdef __hpux 1153 /* HP-UX locking sequence deadlock detection module lock MAJOR ID */ 1154 # define IPF_SMAJ 0 /* temp assignment XXX, not critical */ 1155 #endif 1156 1157 #if !defined(CDEV_MAJOR) && defined (__FreeBSD_version) && \ 1158 (__FreeBSD_version >= 220000) 1159 # define CDEV_MAJOR 79 1160 #endif 1161 1162 /* 1163 * Post NetBSD 1.2 has the PFIL interface for packet filters. This turns 1164 * on those hooks. We don't need any special mods in non-IP Filter code 1165 * with this! 1166 */ 1167 #if (defined(NetBSD) && (NetBSD > 199609) && (NetBSD <= 1991011)) || \ 1168 (defined(NetBSD1_2) && NetBSD1_2 > 1) || \ 1169 (defined(__FreeBSD__) && (__FreeBSD_version >= 500043)) 1170 # if (NetBSD >= 199905) 1171 # define PFIL_HOOKS 1172 # endif 1173 # ifdef PFIL_HOOKS 1174 # define NETBSD_PF 1175 # endif 1176 #endif 1177 1178 #ifndef _KERNEL 1179 extern int fr_check __P((struct ip *, int, void *, int, mb_t **)); 1180 extern int (*fr_checkp) __P((ip_t *, int, void *, int, mb_t **)); 1181 extern int ipf_log __P((void)); 1182 extern struct ifnet *get_unit __P((char *, int)); 1183 extern char *get_ifname __P((struct ifnet *)); 1184 # if defined(__NetBSD__) || defined(__OpenBSD__) || \ 1185 (_BSDI_VERSION >= 199701) || (__FreeBSD_version >= 300000) 1186 extern int iplioctl __P((int, ioctlcmd_t, caddr_t, int)); 1187 # else 1188 extern int iplioctl __P((int, ioctlcmd_t, caddr_t, int)); 1189 # endif 1190 extern int iplopen __P((dev_t, int)); 1191 extern int iplclose __P((dev_t, int)); 1192 extern void m_freem __P((mb_t *)); 1193 #else /* #ifndef _KERNEL */ 1194 # if defined(__NetBSD__) && defined(PFIL_HOOKS) 1195 extern void ipfilterattach __P((int)); 1196 # endif 1197 extern int ipl_enable __P((void)); 1198 extern int ipl_disable __P((void)); 1199 # ifdef MENTAT 1200 extern int fr_check __P((struct ip *, int, void *, int, void *, 1201 mblk_t **)); 1202 # if SOLARIS 1203 # if SOLARIS2 >= 7 1204 extern int iplioctl __P((dev_t, int, intptr_t, int, cred_t *, int *)); 1205 # else 1206 extern int iplioctl __P((dev_t, int, int *, int, cred_t *, int *)); 1207 # endif 1208 extern int iplopen __P((dev_t *, int, int, cred_t *)); 1209 extern int iplclose __P((dev_t, int, int, cred_t *)); 1210 extern int iplread __P((dev_t, uio_t *, cred_t *)); 1211 extern int iplwrite __P((dev_t, uio_t *, cred_t *)); 1212 # endif 1213 # ifdef __hpux 1214 extern int iplopen __P((dev_t, int, intptr_t, int)); 1215 extern int iplclose __P((dev_t, int, int)); 1216 extern int iplioctl __P((dev_t, int, caddr_t, int)); 1217 extern int iplread __P((dev_t, uio_t *)); 1218 extern int iplwrite __P((dev_t, uio_t *)); 1219 extern int iplselect __P((dev_t, int)); 1220 # endif 1221 extern int ipfsync __P((void)); 1222 extern int fr_qout __P((queue_t *, mblk_t *)); 1223 # else /* MENTAT */ 1224 extern int fr_check __P((struct ip *, int, void *, int, mb_t **)); 1225 extern int (*fr_checkp) __P((ip_t *, int, void *, int, mb_t **)); 1226 extern size_t mbufchainlen __P((mb_t *)); 1227 # ifdef __sgi 1228 # include <sys/cred.h> 1229 extern int iplioctl __P((dev_t, int, caddr_t, int, cred_t *, int *)); 1230 extern int iplopen __P((dev_t *, int, int, cred_t *)); 1231 extern int iplclose __P((dev_t, int, int, cred_t *)); 1232 extern int iplread __P((dev_t, uio_t *, cred_t *)); 1233 extern int iplwrite __P((dev_t, uio_t *, cred_t *)); 1234 extern int ipfsync __P((void)); 1235 extern int ipfilter_sgi_attach __P((void)); 1236 extern void ipfilter_sgi_detach __P((void)); 1237 extern void ipfilter_sgi_intfsync __P((void)); 1238 # else 1239 # ifdef IPFILTER_LKM 1240 extern int iplidentify __P((char *)); 1241 # endif 1242 # if (_BSDI_VERSION >= 199510) || (__FreeBSD_version >= 220000) || \ 1243 (NetBSD >= 199511) || defined(__OpenBSD__) 1244 # if defined(__NetBSD__) || (_BSDI_VERSION >= 199701) || \ 1245 defined(__OpenBSD__) || (__FreeBSD_version >= 300000) 1246 # if (__FreeBSD_version >= 500024) 1247 # if (__FreeBSD_version >= 502116) 1248 extern int iplioctl __P((struct cdev*, u_long, caddr_t, int, struct thread *)); 1249 # else 1250 extern int iplioctl __P((dev_t, u_long, caddr_t, int, struct thread *)); 1251 # endif /* __FreeBSD_version >= 502116 */ 1252 # else 1253 extern int iplioctl __P((dev_t, u_long, caddr_t, int, struct proc *)); 1254 # endif /* __FreeBSD_version >= 500024 */ 1255 # else 1256 extern int iplioctl __P((dev_t, int, caddr_t, int, struct proc *)); 1257 # endif 1258 # if (__FreeBSD_version >= 500024) 1259 # if (__FreeBSD_version >= 502116) 1260 extern int iplopen __P((struct cdev*, int, int, struct thread *)); 1261 extern int iplclose __P((struct cdev*, int, int, struct thread *)); 1262 # else 1263 extern int iplopen __P((dev_t, int, int, struct thread *)); 1264 extern int iplclose __P((dev_t, int, int, struct thread *)); 1265 # endif /* __FreeBSD_version >= 502116 */ 1266 # else 1267 extern int iplopen __P((dev_t, int, int, struct proc *)); 1268 extern int iplclose __P((dev_t, int, int, struct proc *)); 1269 # endif /* __FreeBSD_version >= 500024 */ 1270 # else 1271 # ifdef linux 1272 extern int iplioctl __P((struct inode *, struct file *, u_int, u_long)); 1273 # else 1274 extern int iplopen __P((dev_t, int)); 1275 extern int iplclose __P((dev_t, int)); 1276 extern int iplioctl __P((dev_t, int, caddr_t, int)); 1277 # endif 1278 # endif /* (_BSDI_VERSION >= 199510) */ 1279 # if BSD >= 199306 1280 # if (__FreeBSD_version >= 502116) 1281 extern int iplread __P((struct cdev*, struct uio *, int)); 1282 extern int iplwrite __P((struct cdev*, struct uio *, int)); 1283 # else 1284 extern int iplread __P((dev_t, struct uio *, int)); 1285 extern int iplwrite __P((dev_t, struct uio *, int)); 1286 # endif /* __FreeBSD_version >= 502116 */ 1287 # else 1288 # ifndef linux 1289 extern int iplread __P((dev_t, struct uio *)); 1290 extern int iplwrite __P((dev_t, struct uio *)); 1291 # endif 1292 # endif /* BSD >= 199306 */ 1293 # endif /* __ sgi */ 1294 # endif /* MENTAT */ 1295 1296 #endif /* #ifndef _KERNEL */ 1297 1298 extern ipfmutex_t ipl_mutex, ipf_authmx, ipf_rw, ipf_hostmap; 1299 extern ipfmutex_t ipf_timeoutlock, ipf_stinsert, ipf_natio, ipf_nat_new; 1300 extern ipfrwlock_t ipf_mutex, ipf_global, ip_poolrw, ipf_ipidfrag; 1301 extern ipfrwlock_t ipf_frag, ipf_state, ipf_nat, ipf_natfrag, ipf_auth; 1302 extern ipfrwlock_t ipf_frcache; 1303 1304 extern char *memstr __P((char *, char *, int, int)); 1305 extern int count4bits __P((u_32_t)); 1306 extern int count6bits __P((u_32_t *)); 1307 extern int frrequest __P((int, ioctlcmd_t, caddr_t, int, int)); 1308 extern char *getifname __P((struct ifnet *)); 1309 extern int iplattach __P((void)); 1310 extern int ipldetach __P((void)); 1311 extern u_short ipf_cksum __P((u_short *, int)); 1312 extern int copyinptr __P((void *, void *, size_t)); 1313 extern int copyoutptr __P((void *, void *, size_t)); 1314 extern int fr_fastroute __P((mb_t *, mb_t **, fr_info_t *, frdest_t *)); 1315 extern int fr_inobj __P((void *, void *, int)); 1316 extern int fr_inobjsz __P((void *, void *, int, int)); 1317 extern int fr_ioctlswitch __P((int, void *, ioctlcmd_t, int)); 1318 extern int fr_ipftune __P((ioctlcmd_t, void *)); 1319 extern int fr_outobj __P((void *, void *, int)); 1320 extern int fr_outobjsz __P((void *, void *, int, int)); 1321 extern void *fr_pullup __P((mb_t *, fr_info_t *, int)); 1322 extern void fr_resolvedest __P((struct frdest *, int)); 1323 extern int fr_resolvefunc __P((void *)); 1324 extern void *fr_resolvenic __P((char *, int)); 1325 extern int fr_send_icmp_err __P((int, fr_info_t *, int)); 1326 extern int fr_send_reset __P((fr_info_t *)); 1327 #if (__FreeBSD_version < 490000) || !defined(_KERNEL) 1328 extern int ppsratecheck __P((struct timeval *, int *, int)); 1329 #endif 1330 extern ipftq_t *fr_addtimeoutqueue __P((ipftq_t **, u_int)); 1331 extern void fr_deletequeueentry __P((ipftqent_t *)); 1332 extern int fr_deletetimeoutqueue __P((ipftq_t *)); 1333 extern void fr_freetimeoutqueue __P((ipftq_t *)); 1334 extern void fr_movequeue __P((ipftqent_t *, ipftq_t *, ipftq_t *)); 1335 extern void fr_queueappend __P((ipftqent_t *, ipftq_t *, void *)); 1336 extern void fr_queueback __P((ipftqent_t *)); 1337 extern void fr_queuefront __P((ipftqent_t *)); 1338 extern void fr_checkv4sum __P((fr_info_t *)); 1339 extern int fr_checkl4sum __P((fr_info_t *)); 1340 extern int fr_ifpfillv4addr __P((int, struct sockaddr_in *, 1341 struct sockaddr_in *, struct in_addr *, 1342 struct in_addr *)); 1343 extern int fr_coalesce __P((fr_info_t *)); 1344 #ifdef USE_INET6 1345 extern void fr_checkv6sum __P((fr_info_t *)); 1346 extern int fr_ifpfillv6addr __P((int, struct sockaddr_in6 *, 1347 struct sockaddr_in6 *, struct in_addr *, 1348 struct in_addr *)); 1349 #endif 1350 1351 extern int fr_addipftune __P((ipftuneable_t *)); 1352 extern int fr_delipftune __P((ipftuneable_t *)); 1353 1354 extern int frflush __P((minor_t, int, int)); 1355 extern void frsync __P((void *)); 1356 extern frgroup_t *fr_addgroup __P((char *, void *, u_32_t, minor_t, int)); 1357 extern int fr_derefrule __P((frentry_t **)); 1358 extern void fr_delgroup __P((char *, minor_t, int)); 1359 extern frgroup_t *fr_findgroup __P((char *, minor_t, int, frgroup_t ***)); 1360 1361 extern int fr_loginit __P((void)); 1362 extern int ipflog_clear __P((minor_t)); 1363 extern int ipflog_read __P((minor_t, uio_t *)); 1364 extern int ipflog __P((fr_info_t *, u_int)); 1365 extern int ipllog __P((int, fr_info_t *, void **, size_t *, int *, int)); 1366 extern void fr_logunload __P((void)); 1367 1368 extern frentry_t *fr_acctpkt __P((fr_info_t *, u_32_t *)); 1369 extern int fr_copytolog __P((int, char *, int)); 1370 extern u_short fr_cksum __P((mb_t *, ip_t *, int, void *)); 1371 extern void fr_deinitialise __P((void)); 1372 extern frentry_t *fr_dolog __P((fr_info_t *, u_32_t *)); 1373 extern frentry_t *fr_dstgrpmap __P((fr_info_t *, u_32_t *)); 1374 extern void fr_fixskip __P((frentry_t **, frentry_t *, int)); 1375 extern void fr_forgetifp __P((void *)); 1376 extern frentry_t *fr_getrulen __P((int, char *, u_32_t)); 1377 extern void fr_getstat __P((struct friostat *)); 1378 extern int fr_ifpaddr __P((int, int, void *, 1379 struct in_addr *, struct in_addr *)); 1380 extern int fr_initialise __P((void)); 1381 extern void fr_lock __P((caddr_t, int *)); 1382 extern int fr_makefrip __P((int, ip_t *, fr_info_t *)); 1383 extern int fr_matchtag __P((ipftag_t *, ipftag_t *)); 1384 extern int fr_matchicmpqueryreply __P((int, icmpinfo_t *, 1385 struct icmp *, int)); 1386 extern u_32_t fr_newisn __P((fr_info_t *)); 1387 extern u_short fr_nextipid __P((fr_info_t *)); 1388 extern int fr_rulen __P((int, frentry_t *)); 1389 extern int fr_scanlist __P((fr_info_t *, u_32_t)); 1390 extern frentry_t *fr_srcgrpmap __P((fr_info_t *, u_32_t *)); 1391 extern int fr_tcpudpchk __P((fr_info_t *, frtuc_t *)); 1392 extern int fr_verifysrc __P((fr_info_t *fin)); 1393 extern int fr_zerostats __P((char *)); 1394 1395 extern int fr_running; 1396 extern u_long fr_frouteok[2]; 1397 extern int fr_pass; 1398 extern int fr_flags; 1399 extern int fr_active; 1400 extern int fr_chksrc; 1401 extern int fr_minttl; 1402 extern int fr_refcnt; 1403 extern int fr_control_forwarding; 1404 extern int fr_update_ipid; 1405 extern int nat_logging; 1406 extern int ipstate_logging; 1407 extern int ipl_suppress; 1408 extern int ipl_buffer_sz; 1409 extern int ipl_logmax; 1410 extern int ipl_logall; 1411 extern int ipl_logsize; 1412 extern u_long fr_ticks; 1413 extern fr_info_t frcache[2][8]; 1414 extern char ipfilter_version[]; 1415 extern iplog_t **iplh[IPL_LOGMAX+1], *iplt[IPL_LOGMAX+1]; 1416 extern int iplused[IPL_LOGMAX + 1]; 1417 extern struct frentry *ipfilter[2][2], *ipacct[2][2]; 1418 #ifdef USE_INET6 1419 extern struct frentry *ipfilter6[2][2], *ipacct6[2][2]; 1420 extern int icmptoicmp6types[ICMP_MAXTYPE+1]; 1421 extern int icmptoicmp6unreach[ICMP_MAX_UNREACH]; 1422 extern int icmpreplytype6[ICMP6_MAXTYPE + 1]; 1423 #endif 1424 extern int icmpreplytype4[ICMP_MAXTYPE + 1]; 1425 extern struct frgroup *ipfgroups[IPL_LOGSIZE][2]; 1426 extern struct filterstats frstats[]; 1427 extern frentry_t *ipfrule_match __P((fr_info_t *)); 1428 extern u_char ipf_iss_secret[32]; 1429 extern ipftuneable_t ipf_tuneables[]; 1430 1431 #endif /* __IP_FIL_H__ */ 1432