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