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