ip_fw.h revision 182818
1/*- 2 * Copyright (c) 2002 Luigi Rizzo, Universita` di Pisa 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23 * SUCH DAMAGE. 24 * 25 * $FreeBSD: head/sys/netinet/ip_fw.h 182818 2008-09-06 16:47:07Z rik $ 26 */ 27 28#ifndef _IPFW2_H 29#define _IPFW2_H 30 31/* 32 * The default rule number. It is also the max possible rule number. 33 */ 34#define IPFW_DEFAULT_RULE 65535 35 36/* 37 * The kernel representation of ipfw rules is made of a list of 38 * 'instructions' (for all practical purposes equivalent to BPF 39 * instructions), which specify which fields of the packet 40 * (or its metadata) should be analysed. 41 * 42 * Each instruction is stored in a structure which begins with 43 * "ipfw_insn", and can contain extra fields depending on the 44 * instruction type (listed below). 45 * Note that the code is written so that individual instructions 46 * have a size which is a multiple of 32 bits. This means that, if 47 * such structures contain pointers or other 64-bit entities, 48 * (there is just one instance now) they may end up unaligned on 49 * 64-bit architectures, so the must be handled with care. 50 * 51 * "enum ipfw_opcodes" are the opcodes supported. We can have up 52 * to 256 different opcodes. When adding new opcodes, they should 53 * be appended to the end of the opcode list before O_LAST_OPCODE, 54 * this will prevent the ABI from being broken, otherwise users 55 * will have to recompile ipfw(8) when they update the kernel. 56 */ 57 58enum ipfw_opcodes { /* arguments (4 byte each) */ 59 O_NOP, 60 61 O_IP_SRC, /* u32 = IP */ 62 O_IP_SRC_MASK, /* ip = IP/mask */ 63 O_IP_SRC_ME, /* none */ 64 O_IP_SRC_SET, /* u32=base, arg1=len, bitmap */ 65 66 O_IP_DST, /* u32 = IP */ 67 O_IP_DST_MASK, /* ip = IP/mask */ 68 O_IP_DST_ME, /* none */ 69 O_IP_DST_SET, /* u32=base, arg1=len, bitmap */ 70 71 O_IP_SRCPORT, /* (n)port list:mask 4 byte ea */ 72 O_IP_DSTPORT, /* (n)port list:mask 4 byte ea */ 73 O_PROTO, /* arg1=protocol */ 74 75 O_MACADDR2, /* 2 mac addr:mask */ 76 O_MAC_TYPE, /* same as srcport */ 77 78 O_LAYER2, /* none */ 79 O_IN, /* none */ 80 O_FRAG, /* none */ 81 82 O_RECV, /* none */ 83 O_XMIT, /* none */ 84 O_VIA, /* none */ 85 86 O_IPOPT, /* arg1 = 2*u8 bitmap */ 87 O_IPLEN, /* arg1 = len */ 88 O_IPID, /* arg1 = id */ 89 90 O_IPTOS, /* arg1 = id */ 91 O_IPPRECEDENCE, /* arg1 = precedence << 5 */ 92 O_IPTTL, /* arg1 = TTL */ 93 94 O_IPVER, /* arg1 = version */ 95 O_UID, /* u32 = id */ 96 O_GID, /* u32 = id */ 97 O_ESTAB, /* none (tcp established) */ 98 O_TCPFLAGS, /* arg1 = 2*u8 bitmap */ 99 O_TCPWIN, /* arg1 = desired win */ 100 O_TCPSEQ, /* u32 = desired seq. */ 101 O_TCPACK, /* u32 = desired seq. */ 102 O_ICMPTYPE, /* u32 = icmp bitmap */ 103 O_TCPOPTS, /* arg1 = 2*u8 bitmap */ 104 105 O_VERREVPATH, /* none */ 106 O_VERSRCREACH, /* none */ 107 108 O_PROBE_STATE, /* none */ 109 O_KEEP_STATE, /* none */ 110 O_LIMIT, /* ipfw_insn_limit */ 111 O_LIMIT_PARENT, /* dyn_type, not an opcode. */ 112 113 /* 114 * These are really 'actions'. 115 */ 116 117 O_LOG, /* ipfw_insn_log */ 118 O_PROB, /* u32 = match probability */ 119 120 O_CHECK_STATE, /* none */ 121 O_ACCEPT, /* none */ 122 O_DENY, /* none */ 123 O_REJECT, /* arg1=icmp arg (same as deny) */ 124 O_COUNT, /* none */ 125 O_SKIPTO, /* arg1=next rule number */ 126 O_PIPE, /* arg1=pipe number */ 127 O_QUEUE, /* arg1=queue number */ 128 O_DIVERT, /* arg1=port number */ 129 O_TEE, /* arg1=port number */ 130 O_FORWARD_IP, /* fwd sockaddr */ 131 O_FORWARD_MAC, /* fwd mac */ 132 O_NAT, /* nope */ 133 134 /* 135 * More opcodes. 136 */ 137 O_IPSEC, /* has ipsec history */ 138 O_IP_SRC_LOOKUP, /* arg1=table number, u32=value */ 139 O_IP_DST_LOOKUP, /* arg1=table number, u32=value */ 140 O_ANTISPOOF, /* none */ 141 O_JAIL, /* u32 = id */ 142 O_ALTQ, /* u32 = altq classif. qid */ 143 O_DIVERTED, /* arg1=bitmap (1:loop, 2:out) */ 144 O_TCPDATALEN, /* arg1 = tcp data len */ 145 O_IP6_SRC, /* address without mask */ 146 O_IP6_SRC_ME, /* my addresses */ 147 O_IP6_SRC_MASK, /* address with the mask */ 148 O_IP6_DST, 149 O_IP6_DST_ME, 150 O_IP6_DST_MASK, 151 O_FLOW6ID, /* for flow id tag in the ipv6 pkt */ 152 O_ICMP6TYPE, /* icmp6 packet type filtering */ 153 O_EXT_HDR, /* filtering for ipv6 extension header */ 154 O_IP6, 155 156 /* 157 * actions for ng_ipfw 158 */ 159 O_NETGRAPH, /* send to ng_ipfw */ 160 O_NGTEE, /* copy to ng_ipfw */ 161 162 O_IP4, 163 164 O_UNREACH6, /* arg1=icmpv6 code arg (deny) */ 165 166 O_TAG, /* arg1=tag number */ 167 O_TAGGED, /* arg1=tag number */ 168 169 O_SETFIB, /* arg1=FIB number */ 170 O_FIB, /* arg1=FIB desired fib number */ 171 172 O_LAST_OPCODE /* not an opcode! */ 173}; 174 175/* 176 * The extension header are filtered only for presence using a bit 177 * vector with a flag for each header. 178 */ 179#define EXT_FRAGMENT 0x1 180#define EXT_HOPOPTS 0x2 181#define EXT_ROUTING 0x4 182#define EXT_AH 0x8 183#define EXT_ESP 0x10 184#define EXT_DSTOPTS 0x20 185#define EXT_RTHDR0 0x40 186#define EXT_RTHDR2 0x80 187 188/* 189 * Template for instructions. 190 * 191 * ipfw_insn is used for all instructions which require no operands, 192 * a single 16-bit value (arg1), or a couple of 8-bit values. 193 * 194 * For other instructions which require different/larger arguments 195 * we have derived structures, ipfw_insn_*. 196 * 197 * The size of the instruction (in 32-bit words) is in the low 198 * 6 bits of "len". The 2 remaining bits are used to implement 199 * NOT and OR on individual instructions. Given a type, you can 200 * compute the length to be put in "len" using F_INSN_SIZE(t) 201 * 202 * F_NOT negates the match result of the instruction. 203 * 204 * F_OR is used to build or blocks. By default, instructions 205 * are evaluated as part of a logical AND. An "or" block 206 * { X or Y or Z } contains F_OR set in all but the last 207 * instruction of the block. A match will cause the code 208 * to skip past the last instruction of the block. 209 * 210 * NOTA BENE: in a couple of places we assume that 211 * sizeof(ipfw_insn) == sizeof(u_int32_t) 212 * this needs to be fixed. 213 * 214 */ 215typedef struct _ipfw_insn { /* template for instructions */ 216 enum ipfw_opcodes opcode:8; 217 u_int8_t len; /* numer of 32-byte words */ 218#define F_NOT 0x80 219#define F_OR 0x40 220#define F_LEN_MASK 0x3f 221#define F_LEN(cmd) ((cmd)->len & F_LEN_MASK) 222 223 u_int16_t arg1; 224} ipfw_insn; 225 226/* 227 * The F_INSN_SIZE(type) computes the size, in 4-byte words, of 228 * a given type. 229 */ 230#define F_INSN_SIZE(t) ((sizeof (t))/sizeof(u_int32_t)) 231 232#define MTAG_IPFW 1148380143 /* IPFW-tagged cookie */ 233 234/* 235 * This is used to store an array of 16-bit entries (ports etc.) 236 */ 237typedef struct _ipfw_insn_u16 { 238 ipfw_insn o; 239 u_int16_t ports[2]; /* there may be more */ 240} ipfw_insn_u16; 241 242/* 243 * This is used to store an array of 32-bit entries 244 * (uid, single IPv4 addresses etc.) 245 */ 246typedef struct _ipfw_insn_u32 { 247 ipfw_insn o; 248 u_int32_t d[1]; /* one or more */ 249} ipfw_insn_u32; 250 251/* 252 * This is used to store IP addr-mask pairs. 253 */ 254typedef struct _ipfw_insn_ip { 255 ipfw_insn o; 256 struct in_addr addr; 257 struct in_addr mask; 258} ipfw_insn_ip; 259 260/* 261 * This is used to forward to a given address (ip). 262 */ 263typedef struct _ipfw_insn_sa { 264 ipfw_insn o; 265 struct sockaddr_in sa; 266} ipfw_insn_sa; 267 268/* 269 * This is used for MAC addr-mask pairs. 270 */ 271typedef struct _ipfw_insn_mac { 272 ipfw_insn o; 273 u_char addr[12]; /* dst[6] + src[6] */ 274 u_char mask[12]; /* dst[6] + src[6] */ 275} ipfw_insn_mac; 276 277/* 278 * This is used for interface match rules (recv xx, xmit xx). 279 */ 280typedef struct _ipfw_insn_if { 281 ipfw_insn o; 282 union { 283 struct in_addr ip; 284 int glob; 285 } p; 286 char name[IFNAMSIZ]; 287} ipfw_insn_if; 288 289/* 290 * This is used for storing an altq queue id number. 291 */ 292typedef struct _ipfw_insn_altq { 293 ipfw_insn o; 294 u_int32_t qid; 295} ipfw_insn_altq; 296 297/* 298 * This is used for limit rules. 299 */ 300typedef struct _ipfw_insn_limit { 301 ipfw_insn o; 302 u_int8_t _pad; 303 u_int8_t limit_mask; /* combination of DYN_* below */ 304#define DYN_SRC_ADDR 0x1 305#define DYN_SRC_PORT 0x2 306#define DYN_DST_ADDR 0x4 307#define DYN_DST_PORT 0x8 308 309 u_int16_t conn_limit; 310} ipfw_insn_limit; 311 312/* 313 * This is used for log instructions. 314 */ 315typedef struct _ipfw_insn_log { 316 ipfw_insn o; 317 u_int32_t max_log; /* how many do we log -- 0 = all */ 318 u_int32_t log_left; /* how many left to log */ 319} ipfw_insn_log; 320 321/* 322 * Data structures required by both ipfw(8) and ipfw(4) but not part of the 323 * management API are protected by IPFW_INTERNAL. 324 */ 325#ifdef IPFW_INTERNAL 326/* Server pool support (LSNAT). */ 327struct cfg_spool { 328 LIST_ENTRY(cfg_spool) _next; /* chain of spool instances */ 329 struct in_addr addr; 330 u_short port; 331}; 332#endif 333 334/* Redirect modes id. */ 335#define REDIR_ADDR 0x01 336#define REDIR_PORT 0x02 337#define REDIR_PROTO 0x04 338 339#ifdef IPFW_INTERNAL 340/* Nat redirect configuration. */ 341struct cfg_redir { 342 LIST_ENTRY(cfg_redir) _next; /* chain of redir instances */ 343 u_int16_t mode; /* type of redirect mode */ 344 struct in_addr laddr; /* local ip address */ 345 struct in_addr paddr; /* public ip address */ 346 struct in_addr raddr; /* remote ip address */ 347 u_short lport; /* local port */ 348 u_short pport; /* public port */ 349 u_short rport; /* remote port */ 350 u_short pport_cnt; /* number of public ports */ 351 u_short rport_cnt; /* number of remote ports */ 352 int proto; /* protocol: tcp/udp */ 353 struct alias_link **alink; 354 /* num of entry in spool chain */ 355 u_int16_t spool_cnt; 356 /* chain of spool instances */ 357 LIST_HEAD(spool_chain, cfg_spool) spool_chain; 358}; 359#endif 360 361#define NAT_BUF_LEN 1024 362 363#ifdef IPFW_INTERNAL 364/* Nat configuration data struct. */ 365struct cfg_nat { 366 /* chain of nat instances */ 367 LIST_ENTRY(cfg_nat) _next; 368 int id; /* nat id */ 369 struct in_addr ip; /* nat ip address */ 370 char if_name[IF_NAMESIZE]; /* interface name */ 371 int mode; /* aliasing mode */ 372 struct libalias *lib; /* libalias instance */ 373 /* number of entry in spool chain */ 374 int redir_cnt; 375 /* chain of redir instances */ 376 LIST_HEAD(redir_chain, cfg_redir) redir_chain; 377}; 378#endif 379 380#define SOF_NAT sizeof(struct cfg_nat) 381#define SOF_REDIR sizeof(struct cfg_redir) 382#define SOF_SPOOL sizeof(struct cfg_spool) 383 384/* Nat command. */ 385typedef struct _ipfw_insn_nat { 386 ipfw_insn o; 387 struct cfg_nat *nat; 388} ipfw_insn_nat; 389 390/* Apply ipv6 mask on ipv6 addr */ 391#define APPLY_MASK(addr,mask) \ 392 (addr)->__u6_addr.__u6_addr32[0] &= (mask)->__u6_addr.__u6_addr32[0]; \ 393 (addr)->__u6_addr.__u6_addr32[1] &= (mask)->__u6_addr.__u6_addr32[1]; \ 394 (addr)->__u6_addr.__u6_addr32[2] &= (mask)->__u6_addr.__u6_addr32[2]; \ 395 (addr)->__u6_addr.__u6_addr32[3] &= (mask)->__u6_addr.__u6_addr32[3]; 396 397/* Structure for ipv6 */ 398typedef struct _ipfw_insn_ip6 { 399 ipfw_insn o; 400 struct in6_addr addr6; 401 struct in6_addr mask6; 402} ipfw_insn_ip6; 403 404/* Used to support icmp6 types */ 405typedef struct _ipfw_insn_icmp6 { 406 ipfw_insn o; 407 uint32_t d[7]; /* XXX This number si related to the netinet/icmp6.h 408 * define ICMP6_MAXTYPE 409 * as follows: n = ICMP6_MAXTYPE/32 + 1 410 * Actually is 203 411 */ 412} ipfw_insn_icmp6; 413 414/* 415 * Here we have the structure representing an ipfw rule. 416 * 417 * It starts with a general area (with link fields and counters) 418 * followed by an array of one or more instructions, which the code 419 * accesses as an array of 32-bit values. 420 * 421 * Given a rule pointer r: 422 * 423 * r->cmd is the start of the first instruction. 424 * ACTION_PTR(r) is the start of the first action (things to do 425 * once a rule matched). 426 * 427 * When assembling instruction, remember the following: 428 * 429 * + if a rule has a "keep-state" (or "limit") option, then the 430 * first instruction (at r->cmd) MUST BE an O_PROBE_STATE 431 * + if a rule has a "log" option, then the first action 432 * (at ACTION_PTR(r)) MUST be O_LOG 433 * + if a rule has an "altq" option, it comes after "log" 434 * + if a rule has an O_TAG option, it comes after "log" and "altq" 435 * 436 * NOTE: we use a simple linked list of rules because we never need 437 * to delete a rule without scanning the list. We do not use 438 * queue(3) macros for portability and readability. 439 */ 440 441struct ip_fw { 442 struct ip_fw *next; /* linked list of rules */ 443 struct ip_fw *next_rule; /* ptr to next [skipto] rule */ 444 /* 'next_rule' is used to pass up 'set_disable' status */ 445 446 u_int16_t act_ofs; /* offset of action in 32-bit units */ 447 u_int16_t cmd_len; /* # of 32-bit words in cmd */ 448 u_int16_t rulenum; /* rule number */ 449 u_int8_t set; /* rule set (0..31) */ 450#define RESVD_SET 31 /* set for default and persistent rules */ 451 u_int8_t _pad; /* padding */ 452 453 /* These fields are present in all rules. */ 454 u_int64_t pcnt; /* Packet counter */ 455 u_int64_t bcnt; /* Byte counter */ 456 u_int32_t timestamp; /* tv_sec of last match */ 457 458 ipfw_insn cmd[1]; /* storage for commands */ 459}; 460 461#define ACTION_PTR(rule) \ 462 (ipfw_insn *)( (u_int32_t *)((rule)->cmd) + ((rule)->act_ofs) ) 463 464#define RULESIZE(rule) (sizeof(struct ip_fw) + \ 465 ((struct ip_fw *)(rule))->cmd_len * 4 - 4) 466 467/* 468 * This structure is used as a flow mask and a flow id for various 469 * parts of the code. 470 */ 471struct ipfw_flow_id { 472 u_int32_t dst_ip; 473 u_int32_t src_ip; 474 u_int16_t dst_port; 475 u_int16_t src_port; 476 u_int8_t fib; 477 u_int8_t proto; 478 u_int8_t flags; /* protocol-specific flags */ 479 uint8_t addr_type; /* 4 = ipv4, 6 = ipv6, 1=ether ? */ 480 struct in6_addr dst_ip6; /* could also store MAC addr! */ 481 struct in6_addr src_ip6; 482 u_int32_t flow_id6; 483 u_int32_t frag_id6; 484}; 485 486#define IS_IP6_FLOW_ID(id) ((id)->addr_type == 6) 487 488/* 489 * Dynamic ipfw rule. 490 */ 491typedef struct _ipfw_dyn_rule ipfw_dyn_rule; 492 493struct _ipfw_dyn_rule { 494 ipfw_dyn_rule *next; /* linked list of rules. */ 495 struct ip_fw *rule; /* pointer to rule */ 496 /* 'rule' is used to pass up the rule number (from the parent) */ 497 498 ipfw_dyn_rule *parent; /* pointer to parent rule */ 499 u_int64_t pcnt; /* packet match counter */ 500 u_int64_t bcnt; /* byte match counter */ 501 struct ipfw_flow_id id; /* (masked) flow id */ 502 u_int32_t expire; /* expire time */ 503 u_int32_t bucket; /* which bucket in hash table */ 504 u_int32_t state; /* state of this rule (typically a 505 * combination of TCP flags) 506 */ 507 u_int32_t ack_fwd; /* most recent ACKs in forward */ 508 u_int32_t ack_rev; /* and reverse directions (used */ 509 /* to generate keepalives) */ 510 u_int16_t dyn_type; /* rule type */ 511 u_int16_t count; /* refcount */ 512}; 513 514/* 515 * Definitions for IP option names. 516 */ 517#define IP_FW_IPOPT_LSRR 0x01 518#define IP_FW_IPOPT_SSRR 0x02 519#define IP_FW_IPOPT_RR 0x04 520#define IP_FW_IPOPT_TS 0x08 521 522/* 523 * Definitions for TCP option names. 524 */ 525#define IP_FW_TCPOPT_MSS 0x01 526#define IP_FW_TCPOPT_WINDOW 0x02 527#define IP_FW_TCPOPT_SACK 0x04 528#define IP_FW_TCPOPT_TS 0x08 529#define IP_FW_TCPOPT_CC 0x10 530 531#define ICMP_REJECT_RST 0x100 /* fake ICMP code (send a TCP RST) */ 532#define ICMP6_UNREACH_RST 0x100 /* fake ICMPv6 code (send a TCP RST) */ 533 534/* 535 * These are used for lookup tables. 536 */ 537typedef struct _ipfw_table_entry { 538 in_addr_t addr; /* network address */ 539 u_int32_t value; /* value */ 540 u_int16_t tbl; /* table number */ 541 u_int8_t masklen; /* mask length */ 542} ipfw_table_entry; 543 544typedef struct _ipfw_table { 545 u_int32_t size; /* size of entries in bytes */ 546 u_int32_t cnt; /* # of entries */ 547 u_int16_t tbl; /* table number */ 548 ipfw_table_entry ent[0]; /* entries */ 549} ipfw_table; 550 551#define IP_FW_TABLEARG 65535 552 553/* 554 * Main firewall chains definitions and global var's definitions. 555 */ 556#ifdef _KERNEL 557 558/* Return values from ipfw_chk() */ 559enum { 560 IP_FW_PASS = 0, 561 IP_FW_DENY, 562 IP_FW_DIVERT, 563 IP_FW_TEE, 564 IP_FW_DUMMYNET, 565 IP_FW_NETGRAPH, 566 IP_FW_NGTEE, 567 IP_FW_NAT, 568}; 569 570/* flags for divert mtag */ 571#define IP_FW_DIVERT_LOOPBACK_FLAG 0x00080000 572#define IP_FW_DIVERT_OUTPUT_FLAG 0x00100000 573 574/* 575 * Structure for collecting parameters to dummynet for ip6_output forwarding 576 */ 577struct _ip6dn_args { 578 struct ip6_pktopts *opt_or; 579 struct route_in6 ro_or; 580 int flags_or; 581 struct ip6_moptions *im6o_or; 582 struct ifnet *origifp_or; 583 struct ifnet *ifp_or; 584 struct sockaddr_in6 dst_or; 585 u_long mtu_or; 586 struct route_in6 ro_pmtu_or; 587}; 588 589/* 590 * Arguments for calling ipfw_chk() and dummynet_io(). We put them 591 * all into a structure because this way it is easier and more 592 * efficient to pass variables around and extend the interface. 593 */ 594struct ip_fw_args { 595 struct mbuf *m; /* the mbuf chain */ 596 struct ifnet *oif; /* output interface */ 597 struct sockaddr_in *next_hop; /* forward address */ 598 struct ip_fw *rule; /* matching rule */ 599 struct ether_header *eh; /* for bridged packets */ 600 601 struct ipfw_flow_id f_id; /* grabbed from IP header */ 602 u_int32_t cookie; /* a cookie depending on rule action */ 603 struct inpcb *inp; 604 605 struct _ip6dn_args dummypar; /* dummynet->ip6_output */ 606 struct sockaddr_in hopstore; /* store here if cannot use a pointer */ 607}; 608 609/* 610 * Function definitions. 611 */ 612 613/* Firewall hooks */ 614struct sockopt; 615struct dn_flow_set; 616 617int ipfw_check_in(void *, struct mbuf **, struct ifnet *, int, struct inpcb *inp); 618int ipfw_check_out(void *, struct mbuf **, struct ifnet *, int, struct inpcb *inp); 619 620int ipfw_chk(struct ip_fw_args *); 621 622int ipfw_init(void); 623void ipfw_destroy(void); 624 625typedef int ip_fw_ctl_t(struct sockopt *); 626extern ip_fw_ctl_t *ip_fw_ctl_ptr; 627extern int fw_one_pass; 628extern int fw_enable; 629#ifdef INET6 630extern int fw6_enable; 631#endif 632 633/* For kernel ipfw_ether and ipfw_bridge. */ 634typedef int ip_fw_chk_t(struct ip_fw_args *args); 635extern ip_fw_chk_t *ip_fw_chk_ptr; 636#define IPFW_LOADED (ip_fw_chk_ptr != NULL) 637 638#ifdef IPFW_INTERNAL 639 640#define IPFW_TABLES_MAX 128 641struct ip_fw_chain { 642 struct ip_fw *rules; /* list of rules */ 643 struct ip_fw *reap; /* list of rules to reap */ 644 LIST_HEAD(, cfg_nat) nat; /* list of nat entries */ 645 struct radix_node_head *tables[IPFW_TABLES_MAX]; 646 struct rwlock rwmtx; 647}; 648#define IPFW_LOCK_INIT(_chain) \ 649 rw_init(&(_chain)->rwmtx, "IPFW static rules") 650#define IPFW_LOCK_DESTROY(_chain) rw_destroy(&(_chain)->rwmtx) 651#define IPFW_WLOCK_ASSERT(_chain) rw_assert(&(_chain)->rwmtx, RA_WLOCKED) 652 653#define IPFW_RLOCK(p) rw_rlock(&(p)->rwmtx) 654#define IPFW_RUNLOCK(p) rw_runlock(&(p)->rwmtx) 655#define IPFW_WLOCK(p) rw_wlock(&(p)->rwmtx) 656#define IPFW_WUNLOCK(p) rw_wunlock(&(p)->rwmtx) 657 658#define LOOKUP_NAT(l, i, p) do { \ 659 LIST_FOREACH((p), &(l.nat), _next) { \ 660 if ((p)->id == (i)) { \ 661 break; \ 662 } \ 663 } \ 664 } while (0) 665 666typedef int ipfw_nat_t(struct ip_fw_args *, struct cfg_nat *, struct mbuf *); 667typedef int ipfw_nat_cfg_t(struct sockopt *); 668#endif 669 670#endif /* _KERNEL */ 671#endif /* _IPFW2_H */ 672