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