1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 2002-2009 Luigi Rizzo, Universita` di Pisa 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 */ 27 28 #ifndef _IPFW2_H 29 #define _IPFW2_H 30 31 /* 32 * The default rule number. By the design of ip_fw, the default rule 33 * is the last one, so its number can also serve as the highest number 34 * allowed for a rule. The ip_fw code relies on both meanings of this 35 * constant. 36 */ 37 #define IPFW_DEFAULT_RULE 65535 38 39 #define RESVD_SET 31 /*set for default and persistent rules*/ 40 #define IPFW_MAX_SETS 32 /* Number of sets supported by ipfw*/ 41 42 /* 43 * Compat values for old clients 44 */ 45 #ifndef _KERNEL 46 #define IPFW_TABLES_MAX 65535 47 #define IPFW_TABLES_DEFAULT 128 48 #endif 49 50 /* 51 * Most commands (queue, pipe, tag, untag, limit...) can have a 16-bit 52 * argument between 1 and 65534. The value 0 (IP_FW_TARG) is used 53 * to represent 'tablearg' value, e.g. indicate the use of a 'tablearg' 54 * result of the most recent table() lookup. 55 * Note that 16bit is only a historical limit, resulting from 56 * the use of a 16-bit fields for that value. In reality, we can have 57 * 2^32 pipes, queues, tag values and so on. 58 */ 59 #define IPFW_ARG_MIN 1 60 #define IPFW_ARG_MAX 65534 61 #define IP_FW_TABLEARG 65535 /* Compat value for old clients */ 62 #define IP_FW_TARG 0 /* Current tablearg value */ 63 #define IP_FW_NAT44_GLOBAL 65535 /* arg1 value for "nat global" */ 64 65 /* 66 * Number of entries in the call stack of the call/return commands. 67 * Call stack currently is an uint16_t array with rule numbers. 68 */ 69 #define IPFW_CALLSTACK_SIZE 16 70 71 /* IP_FW3 header/opcodes */ 72 typedef struct _ip_fw3_opheader { 73 uint16_t opcode; /* Operation opcode */ 74 uint16_t version; /* Opcode version */ 75 uint16_t reserved[2]; /* Align to 64-bit boundary */ 76 } ip_fw3_opheader; 77 78 #define IP_FW3_OPVER_0 0 79 #define IP_FW3_OPVER_1 1 /* 32bit rulenum */ 80 #define IP_FW3_OPVER IP_FW3_OPVER_1 81 82 /* IP_FW3 opcodes */ 83 #define IP_FW_TABLE_XADD 86 /* add entry */ 84 #define IP_FW_TABLE_XDEL 87 /* delete entry */ 85 #define IP_FW_TABLE_XGETSIZE 88 /* get table size (deprecated) */ 86 #define IP_FW_TABLE_XLIST 89 /* list table contents */ 87 #define IP_FW_TABLE_XDESTROY 90 /* destroy table */ 88 #define IP_FW_TABLES_XLIST 92 /* list all tables */ 89 #define IP_FW_TABLE_XINFO 93 /* request info for one table */ 90 #define IP_FW_TABLE_XFLUSH 94 /* flush table data */ 91 #define IP_FW_TABLE_XCREATE 95 /* create new table */ 92 #define IP_FW_TABLE_XMODIFY 96 /* modify existing table */ 93 #define IP_FW_XGET 97 /* Retrieve configuration */ 94 #define IP_FW_XADD 98 /* add rule */ 95 #define IP_FW_XDEL 99 /* del rule */ 96 #define IP_FW_XMOVE 100 /* move rules to different set */ 97 #define IP_FW_XZERO 101 /* clear accounting */ 98 #define IP_FW_XRESETLOG 102 /* zero rules logs */ 99 #define IP_FW_SET_SWAP 103 /* Swap between 2 sets */ 100 #define IP_FW_SET_MOVE 104 /* Move one set to another one */ 101 #define IP_FW_SET_ENABLE 105 /* Enable/disable sets */ 102 #define IP_FW_TABLE_XFIND 106 /* finds an entry */ 103 #define IP_FW_XIFLIST 107 /* list tracked interfaces */ 104 #define IP_FW_TABLES_ALIST 108 /* list table algorithms */ 105 #define IP_FW_TABLE_XSWAP 109 /* swap two tables */ 106 #define IP_FW_TABLE_VLIST 110 /* dump table value hash */ 107 108 #define IP_FW_NAT44_XCONFIG 111 /* Create/modify NAT44 instance */ 109 #define IP_FW_NAT44_DESTROY 112 /* Destroys NAT44 instance */ 110 #define IP_FW_NAT44_XGETCONFIG 113 /* Get NAT44 instance config */ 111 #define IP_FW_NAT44_LIST_NAT 114 /* List all NAT44 instances */ 112 #define IP_FW_NAT44_XGETLOG 115 /* Get log from NAT44 instance */ 113 114 #define IP_FW_DUMP_SOPTCODES 116 /* Dump available sopts/versions */ 115 #define IP_FW_DUMP_SRVOBJECTS 117 /* Dump existing named objects */ 116 #define IP_FW_SKIPTO_CACHE 118 /* Manage skipto cache */ 117 118 #define IP_FW_NAT64STL_CREATE 130 /* Create stateless NAT64 instance */ 119 #define IP_FW_NAT64STL_DESTROY 131 /* Destroy stateless NAT64 instance */ 120 #define IP_FW_NAT64STL_CONFIG 132 /* Modify stateless NAT64 instance */ 121 #define IP_FW_NAT64STL_LIST 133 /* List stateless NAT64 instances */ 122 #define IP_FW_NAT64STL_STATS 134 /* Get NAT64STL instance statistics */ 123 #define IP_FW_NAT64STL_RESET_STATS 135 /* Reset NAT64STL instance statistics */ 124 125 #define IP_FW_NAT64LSN_CREATE 140 /* Create stateful NAT64 instance */ 126 #define IP_FW_NAT64LSN_DESTROY 141 /* Destroy stateful NAT64 instance */ 127 #define IP_FW_NAT64LSN_CONFIG 142 /* Modify stateful NAT64 instance */ 128 #define IP_FW_NAT64LSN_LIST 143 /* List stateful NAT64 instances */ 129 #define IP_FW_NAT64LSN_STATS 144 /* Get NAT64LSN instance statistics */ 130 #define IP_FW_NAT64LSN_LIST_STATES 145 /* Get stateful NAT64 states */ 131 #define IP_FW_NAT64LSN_RESET_STATS 146 /* Reset NAT64LSN instance statistics */ 132 133 #define IP_FW_NPTV6_CREATE 150 /* Create NPTv6 instance */ 134 #define IP_FW_NPTV6_DESTROY 151 /* Destroy NPTv6 instance */ 135 #define IP_FW_NPTV6_CONFIG 152 /* Modify NPTv6 instance */ 136 #define IP_FW_NPTV6_LIST 153 /* List NPTv6 instances */ 137 #define IP_FW_NPTV6_STATS 154 /* Get NPTv6 instance statistics */ 138 #define IP_FW_NPTV6_RESET_STATS 155 /* Reset NPTv6 instance statistics */ 139 140 #define IP_FW_NAT64CLAT_CREATE 160 /* Create clat NAT64 instance */ 141 #define IP_FW_NAT64CLAT_DESTROY 161 /* Destroy clat NAT64 instance */ 142 #define IP_FW_NAT64CLAT_CONFIG 162 /* Modify clat NAT64 instance */ 143 #define IP_FW_NAT64CLAT_LIST 163 /* List clat NAT64 instances */ 144 #define IP_FW_NAT64CLAT_STATS 164 /* Get NAT64CLAT instance statistics */ 145 #define IP_FW_NAT64CLAT_RESET_STATS 165 /* Reset NAT64CLAT instance statistics */ 146 147 /* 148 * The kernel representation of ipfw rules is made of a list of 149 * 'instructions' (for all practical purposes equivalent to BPF 150 * instructions), which specify which fields of the packet 151 * (or its metadata) should be analysed. 152 * 153 * Each instruction is stored in a structure which begins with 154 * "ipfw_insn", and can contain extra fields depending on the 155 * instruction type (listed below). 156 * Note that the code is written so that individual instructions 157 * have a size which is a multiple of 32 bits. This means that, if 158 * such structures contain pointers or other 64-bit entities, 159 * (there is just one instance now) they may end up unaligned on 160 * 64-bit architectures, so the must be handled with care. 161 * 162 * "enum ipfw_opcodes" are the opcodes supported. We can have up 163 * to 256 different opcodes. When adding new opcodes, they should 164 * be appended to the end of the opcode list before O_LAST_OPCODE, 165 * this will prevent the ABI from being broken, otherwise users 166 * will have to recompile ipfw(8) when they update the kernel. 167 */ 168 169 enum ipfw_opcodes { /* arguments (4 byte each) */ 170 O_NOP = 0, 171 172 O_IP_SRC = 1, /* u32 = IP */ 173 O_IP_SRC_MASK = 2, /* ip = IP/mask */ 174 O_IP_SRC_ME = 3, /* none */ 175 O_IP_SRC_SET = 4, /* u32=base, arg1=len, bitmap */ 176 177 O_IP_DST = 5, /* u32 = IP */ 178 O_IP_DST_MASK = 6, /* ip = IP/mask */ 179 O_IP_DST_ME = 7, /* none */ 180 O_IP_DST_SET = 8, /* u32=base, arg1=len, bitmap */ 181 182 O_IP_SRCPORT = 9, /* (n)port list:mask 4 byte ea */ 183 O_IP_DSTPORT = 10, /* (n)port list:mask 4 byte ea */ 184 O_PROTO = 11, /* arg1=protocol */ 185 186 O_MACADDR2 = 12, /* 2 mac addr:mask */ 187 O_MAC_TYPE = 13, /* same as srcport */ 188 189 O_LAYER2 = 14, /* none */ 190 O_IN = 15, /* none */ 191 O_FRAG = 16, /* none */ 192 193 O_RECV = 17, /* none */ 194 O_XMIT = 18, /* none */ 195 O_VIA = 19, /* none */ 196 197 O_IPOPT = 20, /* arg1 = 2*u8 bitmap */ 198 O_IPLEN = 21, /* arg1 = len */ 199 O_IPID = 22, /* arg1 = id */ 200 201 O_IPTOS = 23, /* arg1 = id */ 202 O_IPPRECEDENCE = 24, /* arg1 = precedence << 5 */ 203 O_IPTTL = 25, /* arg1 = TTL */ 204 205 O_IPVER = 26, /* arg1 = version */ 206 O_UID = 27, /* u32 = id */ 207 O_GID = 28, /* u32 = id */ 208 O_ESTAB = 29, /* none (tcp established) */ 209 O_TCPFLAGS = 30, /* arg1 = 2*u8 bitmap */ 210 O_TCPWIN = 31, /* arg1 = desired win */ 211 O_TCPSEQ = 32, /* u32 = desired seq. */ 212 O_TCPACK = 33, /* u32 = desired seq. */ 213 O_ICMPTYPE = 34, /* u32 = icmp bitmap */ 214 O_TCPOPTS = 35, /* arg1 = 2*u8 bitmap */ 215 216 O_VERREVPATH = 36, /* none */ 217 O_VERSRCREACH = 37, /* none */ 218 219 O_PROBE_STATE = 38, /* kidx=kidx */ 220 O_KEEP_STATE = 39, /* kidx=kidx */ 221 O_LIMIT = 40, /* ipfw_insn_limit */ 222 O_LIMIT_PARENT = 41, /* dyn_type, not an opcode. */ 223 224 /* 225 * These are really 'actions'. 226 */ 227 228 O_LOG = 42, /* ipfw_insn_log */ 229 O_PROB = 43, /* u32 = match probability */ 230 231 O_CHECK_STATE = 44, /* kidx=kidx */ 232 O_ACCEPT = 45, /* none */ 233 O_DENY = 46, /* none */ 234 O_REJECT = 47, /* arg1=icmp arg (same as deny) */ 235 O_COUNT = 48, /* none */ 236 O_SKIPTO = 49, /* u32= next rule number */ 237 O_PIPE = 50, /* arg1=pipe number */ 238 O_QUEUE = 51, /* arg1=queue number */ 239 O_DIVERT = 52, /* arg1=port number */ 240 O_TEE = 53, /* arg1=port number */ 241 O_FORWARD_IP = 54, /* fwd sockaddr */ 242 O_FORWARD_MAC = 55, /* fwd mac */ 243 O_NAT = 56, /* nope */ 244 O_REASS = 57, /* none */ 245 246 /* 247 * More opcodes. 248 */ 249 O_IPSEC = 58, /* has ipsec history */ 250 O_IP_SRC_LOOKUP = 59, /* kidx=name */ 251 /* lookup: kidx=name, arg1=key */ 252 /* and flags, bitmask */ 253 O_IP_DST_LOOKUP = 60, /* kidx=name */ 254 /* lookup: kidx=name, arg1=key */ 255 /* and flags, bitmask */ 256 O_ANTISPOOF = 61, /* none */ 257 O_JAIL = 62, /* u32 = id */ 258 O_ALTQ = 63, /* u32 = altq classif. qid */ 259 O_DIVERTED = 64, /* arg1=bitmap (1:loop, 2:out) */ 260 O_TCPDATALEN = 65, /* arg1 = tcp data len */ 261 O_IP6_SRC = 66, /* address without mask */ 262 O_IP6_SRC_ME = 67, /* my addresses */ 263 O_IP6_SRC_MASK = 68, /* address with the mask */ 264 O_IP6_DST = 69, 265 O_IP6_DST_ME = 70, 266 O_IP6_DST_MASK = 71, 267 O_FLOW6ID = 72, /* for flow id tag in the ipv6 pkt */ 268 O_ICMP6TYPE = 73, /* icmp6 packet type filtering */ 269 O_EXT_HDR = 74, /* filtering for ipv6 extension header */ 270 O_IP6 = 75, 271 272 /* 273 * actions for ng_ipfw 274 */ 275 O_NETGRAPH = 76, /* send to ng_ipfw */ 276 O_NGTEE = 77, /* copy to ng_ipfw */ 277 278 O_IP4 = 78, 279 280 O_UNREACH6 = 79, /* arg1=icmpv6 code arg (deny) */ 281 282 O_TAG = 80, /* arg1=tag number */ 283 O_TAGGED = 81, /* arg1=tag number */ 284 285 O_SETFIB = 82, /* arg1=FIB number */ 286 O_FIB = 83, /* arg1=FIB desired fib number */ 287 288 O_SOCKARG = 84, /* socket argument */ 289 290 O_CALLRETURN = 85, /* u32=called rule number */ 291 292 O_FORWARD_IP6 = 86, /* fwd sockaddr_in6 */ 293 294 O_DSCP = 87, /* 2 u32 = DSCP mask */ 295 O_SETDSCP = 88, /* arg1=DSCP value */ 296 O_IP_FLOW_LOOKUP = 89, /* kidx=name */ 297 /* lookup: kidx=name, arg1=key */ 298 /* and flags, bitmask */ 299 300 O_EXTERNAL_ACTION = 90, /* kidx=id of external action handler */ 301 O_EXTERNAL_INSTANCE = 91, /* kidx=id of eaction handler instance */ 302 O_EXTERNAL_DATA = 92, /* variable length data */ 303 304 O_SKIP_ACTION = 93, /* none */ 305 O_TCPMSS = 94, /* arg1=MSS value */ 306 307 O_MAC_SRC_LOOKUP = 95, /* kidx=name */ 308 /* lookup: kidx=name, arg1=key */ 309 /* and flags, bitmask */ 310 O_MAC_DST_LOOKUP = 96, /* kidx=name */ 311 /* lookup: kidx=name, arg1=key */ 312 /* and flags, bitmask */ 313 314 O_SETMARK = 97, /* u32 = value */ 315 O_MARK = 98, /* 2 u32 = value, bitmask */ 316 317 O_TABLE_LOOKUP = 99, /* lookup: kidx=name, arg1=key */ 318 /* and flags, bitmask */ 319 320 O_LAST_OPCODE /* not an opcode! */ 321 }; 322 323 /* 324 * The extension header are filtered only for presence using a bit 325 * vector with a flag for each header. 326 */ 327 #define EXT_FRAGMENT 0x1 328 #define EXT_HOPOPTS 0x2 329 #define EXT_ROUTING 0x4 330 #define EXT_AH 0x8 331 #define EXT_ESP 0x10 332 #define EXT_DSTOPTS 0x20 333 #define EXT_RTHDR0 0x40 334 #define EXT_RTHDR2 0x80 335 336 /* 337 * Template for instructions. 338 * 339 * ipfw_insn is used for all instructions which require no operands, 340 * a single 16-bit value (arg1), or a couple of 8-bit values. 341 * 342 * For other instructions which require different/larger arguments 343 * we have derived structures, ipfw_insn_*. 344 * 345 * The size of the instruction (in 32-bit words) is in the low 346 * 6 bits of "len". The 2 remaining bits are used to implement 347 * NOT and OR on individual instructions. Given a type, you can 348 * compute the length to be put in "len" using F_INSN_SIZE(t) 349 * 350 * F_NOT negates the match result of the instruction. 351 * 352 * F_OR is used to build or blocks. By default, instructions 353 * are evaluated as part of a logical AND. An "or" block 354 * { X or Y or Z } contains F_OR set in all but the last 355 * instruction of the block. A match will cause the code 356 * to skip past the last instruction of the block. 357 * 358 * NOTA BENE: in a couple of places we assume that 359 * sizeof(ipfw_insn) == sizeof(u_int32_t) 360 * this needs to be fixed. 361 * 362 */ 363 typedef struct _ipfw_insn { /* template for instructions */ 364 _Alignas(_Alignof(u_int32_t)) u_int8_t opcode; 365 u_int8_t len; /* number of 32-bit words */ 366 #define F_NOT 0x80 367 #define F_OR 0x40 368 #define F_LEN_MASK 0x3f 369 #define F_LEN(cmd) ((cmd)->len & F_LEN_MASK) 370 371 u_int16_t arg1; 372 } ipfw_insn; 373 374 /* 375 * The F_INSN_SIZE(type) computes the size, in 4-byte words, of 376 * a given type. 377 */ 378 #define F_INSN_SIZE(t) ((sizeof (t))/sizeof(u_int32_t)) 379 380 /* 381 * This is used to store an array of 16-bit entries (ports etc.) 382 */ 383 typedef struct _ipfw_insn_u16 { 384 ipfw_insn o; 385 u_int16_t ports[2]; /* there may be more */ 386 } ipfw_insn_u16; 387 388 /* 389 * This is used to store an array of 32-bit entries 390 * (uid, single IPv4 addresses etc.) 391 */ 392 typedef struct _ipfw_insn_u32 { 393 ipfw_insn o; 394 u_int32_t d[1]; /* one or more */ 395 } ipfw_insn_u32; 396 397 typedef struct _ipfw_insn_kidx { 398 ipfw_insn o; 399 uint32_t kidx; 400 } ipfw_insn_kidx; 401 402 /* 403 * This is used to store IP addr-mask pairs. 404 */ 405 typedef struct _ipfw_insn_ip { 406 ipfw_insn o; 407 struct in_addr addr; 408 struct in_addr mask; 409 } ipfw_insn_ip; 410 411 typedef struct _ipfw_insn_table { 412 ipfw_insn o; /* arg1 is optional lookup key */ 413 uint32_t kidx; /* table name index */ 414 uint32_t value; /* table value */ 415 } ipfw_insn_table; 416 417 typedef struct _ipfw_insn_lookup { 418 ipfw_insn o; /* arg1 is flags and lookup key */ 419 uint32_t kidx; /* table name index */ 420 union { /* lookup mask */ 421 uint64_t __mask64[2]; 422 struct in6_addr ip6; 423 struct in_addr ip4; 424 char mac[6]; 425 uint32_t u32; 426 }; 427 } ipfw_insn_lookup; 428 429 #define IPFW_LOOKUP_TYPE_MASK 0x007F 430 #define IPFW_LOOKUP_TYPE(insn) ((insn)->arg1 & IPFW_LOOKUP_TYPE_MASK) 431 #define IPFW_SET_LOOKUP_TYPE(insn, type) do { \ 432 (insn)->arg1 &= ~IPFW_LOOKUP_TYPE_MASK; \ 433 (insn)->arg1 |= (type) & IPFW_LOOKUP_TYPE_MASK; \ 434 } while (0) 435 #define IPFW_LOOKUP_F_MASKING 0x0080 436 #define IPFW_LOOKUP_MASKING(insn) ((insn)->arg1 & IPFW_LOOKUP_F_MASKING) 437 #define IPFW_SET_LOOKUP_MASKING(insn, value) do { \ 438 if (value) \ 439 (insn)->arg1 |= IPFW_LOOKUP_F_MASKING; \ 440 else \ 441 (insn)->arg1 &= ~IPFW_LOOKUP_F_MASKING; \ 442 } while (0) 443 444 /* 445 * Defines key types used by lookup instruction 446 */ 447 enum ipfw_table_lookup_type { 448 LOOKUP_NONE = 0, 449 LOOKUP_DST_IP, 450 LOOKUP_SRC_IP, 451 LOOKUP_DST_PORT, 452 LOOKUP_SRC_PORT, 453 LOOKUP_UID, 454 LOOKUP_JAIL, 455 LOOKUP_DSCP, 456 LOOKUP_DST_MAC, 457 LOOKUP_SRC_MAC, 458 LOOKUP_MARK, 459 LOOKUP_RULENUM, 460 LOOKUP_DST_IP4, 461 LOOKUP_SRC_IP4, 462 LOOKUP_DST_IP6, 463 LOOKUP_SRC_IP6, 464 }; 465 466 enum ipfw_return_type { 467 RETURN_NEXT_RULENUM = 0, 468 RETURN_NEXT_RULE, 469 }; 470 471 enum ipfw_skipto_cache_op { 472 SKIPTO_CACHE_DISABLE = 0, 473 SKIPTO_CACHE_ENABLE, 474 }; 475 476 /* 477 * This is used to forward to a given address (ip). 478 */ 479 typedef struct _ipfw_insn_sa { 480 ipfw_insn o; 481 struct sockaddr_in sa; 482 } ipfw_insn_sa; 483 484 /* 485 * This is used to forward to a given address (ipv6). 486 */ 487 typedef struct _ipfw_insn_sa6 { 488 ipfw_insn o; 489 struct sockaddr_in6 sa; 490 } ipfw_insn_sa6; 491 492 /* 493 * This is used for MAC addr-mask pairs. 494 */ 495 typedef struct _ipfw_insn_mac { 496 ipfw_insn o; 497 u_char addr[12]; /* dst[6] + src[6] */ 498 u_char mask[12]; /* dst[6] + src[6] */ 499 } ipfw_insn_mac; 500 501 /* 502 * This is used for interface match rules (recv xx, xmit xx). 503 */ 504 typedef struct _ipfw_insn_if { 505 ipfw_insn o; 506 union { 507 struct in_addr ip; 508 int glob; 509 uint16_t kidx_v0; 510 uint32_t kidx; 511 } p; 512 char name[IFNAMSIZ]; 513 } ipfw_insn_if; 514 515 /* 516 * This is used for storing an altq queue id number. 517 */ 518 typedef struct _ipfw_insn_altq { 519 ipfw_insn o; 520 u_int32_t qid; 521 } ipfw_insn_altq; 522 523 /* 524 * This is used for limit rules. 525 */ 526 typedef struct _ipfw_insn_limit { 527 ipfw_insn o; 528 u_int32_t kidx; 529 u_int8_t _pad; 530 u_int8_t limit_mask; /* combination of DYN_* below */ 531 #define DYN_SRC_ADDR 0x1 532 #define DYN_SRC_PORT 0x2 533 #define DYN_DST_ADDR 0x4 534 #define DYN_DST_PORT 0x8 535 536 u_int16_t conn_limit; 537 } ipfw_insn_limit; 538 539 /* MAC/InfiniBand/etc address length */ 540 #define IPFW_MAX_L2_ADDR_LEN 20 541 542 /* 543 * This is used for log instructions. 544 */ 545 typedef struct _ipfw_insn_log { 546 ipfw_insn o; 547 u_int32_t max_log; /* how many do we log -- 0 = all */ 548 u_int32_t log_left; /* how many left to log */ 549 } ipfw_insn_log; 550 551 /* ipfw_insn_log->o.arg1 bitmasks */ 552 #define IPFW_LOG_DEFAULT 0x0000 553 #define IPFW_LOG_SYSLOG (1 << 15) 554 #define IPFW_LOG_IPFW0 (1 << 14) 555 #define IPFW_LOG_RTSOCK (1 << 13) 556 557 typedef struct _ipfwlog_rtsock_hdr_v2 { 558 uint32_t rulenum; 559 uint32_t tablearg; 560 ipfw_insn cmd; 561 u_char ether_shost[IPFW_MAX_L2_ADDR_LEN]; 562 u_char ether_dhost[IPFW_MAX_L2_ADDR_LEN]; 563 uint32_t mark; 564 char comment[0]; 565 } ipfwlog_rtsock_hdr_v2; 566 567 /* Legacy NAT structures, compat only */ 568 #ifndef _KERNEL 569 /* 570 * Data structures required by both ipfw(8) and ipfw(4) but not part of the 571 * management API are protected by IPFW_INTERNAL. 572 */ 573 #ifdef IPFW_INTERNAL 574 /* Server pool support (LSNAT). */ 575 struct cfg_spool { 576 LIST_ENTRY(cfg_spool) _next; /* chain of spool instances */ 577 struct in_addr addr; 578 u_short port; 579 }; 580 #endif 581 582 /* Redirect modes id. */ 583 #define REDIR_ADDR 0x01 584 #define REDIR_PORT 0x02 585 #define REDIR_PROTO 0x04 586 587 #ifdef IPFW_INTERNAL 588 /* Nat redirect configuration. */ 589 struct cfg_redir { 590 LIST_ENTRY(cfg_redir) _next; /* chain of redir instances */ 591 u_int16_t mode; /* type of redirect mode */ 592 struct in_addr laddr; /* local ip address */ 593 struct in_addr paddr; /* public ip address */ 594 struct in_addr raddr; /* remote ip address */ 595 u_short lport; /* local port */ 596 u_short pport; /* public port */ 597 u_short rport; /* remote port */ 598 u_short pport_cnt; /* number of public ports */ 599 u_short rport_cnt; /* number of remote ports */ 600 int proto; /* protocol: tcp/udp */ 601 struct alias_link **alink; 602 /* num of entry in spool chain */ 603 u_int16_t spool_cnt; 604 /* chain of spool instances */ 605 LIST_HEAD(spool_chain, cfg_spool) spool_chain; 606 }; 607 #endif 608 609 #ifdef IPFW_INTERNAL 610 /* Nat configuration data struct. */ 611 struct cfg_nat { 612 /* chain of nat instances */ 613 LIST_ENTRY(cfg_nat) _next; 614 int id; /* nat id */ 615 struct in_addr ip; /* nat ip address */ 616 char if_name[IF_NAMESIZE]; /* interface name */ 617 int mode; /* aliasing mode */ 618 struct libalias *lib; /* libalias instance */ 619 /* number of entry in spool chain */ 620 int redir_cnt; 621 /* chain of redir instances */ 622 LIST_HEAD(redir_chain, cfg_redir) redir_chain; 623 }; 624 #endif 625 626 #define SOF_NAT sizeof(struct cfg_nat) 627 #define SOF_REDIR sizeof(struct cfg_redir) 628 #define SOF_SPOOL sizeof(struct cfg_spool) 629 630 #endif /* ifndef _KERNEL */ 631 632 struct nat44_cfg_spool { 633 struct in_addr addr; 634 uint16_t port; 635 uint16_t spare; 636 }; 637 #define NAT44_REDIR_ADDR 0x01 638 #define NAT44_REDIR_PORT 0x02 639 #define NAT44_REDIR_PROTO 0x04 640 641 /* Nat redirect configuration. */ 642 struct nat44_cfg_redir { 643 struct in_addr laddr; /* local ip address */ 644 struct in_addr paddr; /* public ip address */ 645 struct in_addr raddr; /* remote ip address */ 646 uint16_t lport; /* local port */ 647 uint16_t pport; /* public port */ 648 uint16_t rport; /* remote port */ 649 uint16_t pport_cnt; /* number of public ports */ 650 uint16_t rport_cnt; /* number of remote ports */ 651 uint16_t mode; /* type of redirect mode */ 652 uint16_t spool_cnt; /* num of entry in spool chain */ 653 uint16_t spare; 654 uint32_t proto; /* protocol: tcp/udp */ 655 }; 656 657 /* Nat configuration data struct. */ 658 struct nat44_cfg_nat { 659 char name[64]; /* nat name */ 660 char if_name[64]; /* interface name */ 661 uint32_t size; /* structure size incl. redirs */ 662 struct in_addr ip; /* nat IPv4 address */ 663 uint32_t mode; /* aliasing mode */ 664 uint32_t redir_cnt; /* number of entry in spool chain */ 665 u_short alias_port_lo; /* low range for port aliasing */ 666 u_short alias_port_hi; /* high range for port aliasing */ 667 }; 668 669 /* Nat command. */ 670 typedef struct _ipfw_insn_nat { 671 ipfw_insn o; 672 struct cfg_nat *nat; 673 } ipfw_insn_nat; 674 675 /* Apply ipv6 mask on ipv6 addr */ 676 #define APPLY_MASK(addr,mask) do { \ 677 (addr)->__u6_addr.__u6_addr32[0] &= (mask)->__u6_addr.__u6_addr32[0]; \ 678 (addr)->__u6_addr.__u6_addr32[1] &= (mask)->__u6_addr.__u6_addr32[1]; \ 679 (addr)->__u6_addr.__u6_addr32[2] &= (mask)->__u6_addr.__u6_addr32[2]; \ 680 (addr)->__u6_addr.__u6_addr32[3] &= (mask)->__u6_addr.__u6_addr32[3]; \ 681 } while (0) 682 683 /* Structure for ipv6 */ 684 typedef struct _ipfw_insn_ip6 { 685 ipfw_insn o; 686 struct in6_addr addr6; 687 struct in6_addr mask6; 688 } ipfw_insn_ip6; 689 690 /* Used to support icmp6 types */ 691 typedef struct _ipfw_insn_icmp6 { 692 ipfw_insn o; 693 uint32_t d[7]; /* XXX This number si related to the netinet/icmp6.h 694 * define ICMP6_MAXTYPE 695 * as follows: n = ICMP6_MAXTYPE/32 + 1 696 * Actually is 203 697 */ 698 } ipfw_insn_icmp6; 699 700 /* Convert pointer to instruction with specified type */ 701 #define insntod(p, type) ((ipfw_insn_ ## type *)(p)) 702 #define insntoc(p, type) ((const ipfw_insn_ ## type *)(p)) 703 704 /* 705 * Here we have the structure representing an ipfw rule. 706 * 707 * Layout: 708 * struct ip_fw_rule 709 * [ counter block, size = rule->cntr_len ] 710 * [ one or more instructions, size = rule->cmd_len * 4 ] 711 * 712 * It starts with a general area (with link fields). 713 * Counter block may be next (if rule->cntr_len > 0), 714 * followed by an array of one or more instructions, which the code 715 * accesses as an array of 32-bit values. rule->cmd_len represents 716 * the total instructions legth in u32 worrd, while act_ofs represents 717 * rule action offset in u32 words. 718 * 719 * When assembling instruction, remember the following: 720 * 721 * + if a rule has a "keep-state" (or "limit") option, then the 722 * first instruction (at r->cmd) MUST BE an O_PROBE_STATE 723 * + if a rule has a "log" option, then the first action 724 * (at ACTION_PTR(r)) MUST be O_LOG 725 * + if a rule has an "altq" option, it comes after "log" 726 * + if a rule has an O_TAG option, it comes after "log" and "altq" 727 * 728 * 729 * All structures (excluding instructions) are u64-aligned. 730 * Please keep this. 731 */ 732 733 struct ip_fw_rule { 734 uint16_t act_ofs; /* offset of action in 32-bit units */ 735 uint16_t cmd_len; /* # of 32-bit words in cmd */ 736 uint16_t spare; 737 uint8_t set; /* rule set (0..31) */ 738 uint8_t flags; /* rule flags */ 739 uint32_t rulenum; /* rule number */ 740 uint32_t id; /* rule id */ 741 742 ipfw_insn cmd[1]; /* storage for commands */ 743 }; 744 #define IPFW_RULE_NOOPT 0x01 /* Has no options in body */ 745 #define IPFW_RULE_JUSTOPTS 0x02 /* new format of rule body */ 746 747 /* Unaligned version */ 748 749 /* Base ipfw rule counter block. */ 750 struct ip_fw_bcounter { 751 uint16_t size; /* Size of counter block, bytes */ 752 uint8_t flags; /* flags for given block */ 753 uint8_t spare; 754 uint32_t timestamp; /* tv_sec of last match */ 755 uint64_t pcnt; /* Packet counter */ 756 uint64_t bcnt; /* Byte counter */ 757 }; 758 759 #ifndef _KERNEL 760 /* 761 * Legacy rule format 762 */ 763 struct ip_fw { 764 struct ip_fw *x_next; /* linked list of rules */ 765 struct ip_fw *next_rule; /* ptr to next [skipto] rule */ 766 /* 'next_rule' is used to pass up 'set_disable' status */ 767 768 uint16_t act_ofs; /* offset of action in 32-bit units */ 769 uint16_t cmd_len; /* # of 32-bit words in cmd */ 770 uint16_t rulenum; /* rule number */ 771 uint8_t set; /* rule set (0..31) */ 772 uint8_t _pad; /* padding */ 773 uint32_t id; /* rule id */ 774 775 /* These fields are present in all rules. */ 776 uint64_t pcnt; /* Packet counter */ 777 uint64_t bcnt; /* Byte counter */ 778 uint32_t timestamp; /* tv_sec of last match */ 779 780 ipfw_insn cmd[1]; /* storage for commands */ 781 }; 782 #endif 783 784 #define ACTION_PTR(rule) \ 785 ((ipfw_insn *)( (uint32_t *)((rule)->cmd) + ((rule)->act_ofs) )) 786 787 #define RULESIZE(rule) (sizeof(*(rule)) + (rule)->cmd_len * 4 - 4) 788 789 #if 1 // should be moved to in.h 790 /* 791 * This structure is used as a flow mask and a flow id for various 792 * parts of the code. 793 * addr_type is used in userland and kernel to mark the address type. 794 * fib is used in the kernel to record the fib in use. 795 * _flags is used in the kernel to store tcp flags for dynamic rules. 796 */ 797 struct ipfw_flow_id { 798 uint32_t dst_ip; 799 uint32_t src_ip; 800 uint16_t dst_port; 801 uint16_t src_port; 802 uint8_t fib; /* XXX: must be uint16_t */ 803 uint8_t proto; 804 uint8_t _flags; /* protocol-specific flags */ 805 uint8_t addr_type; /* 4=ip4, 6=ip6, 1=ether ? */ 806 struct in6_addr dst_ip6; 807 struct in6_addr src_ip6; 808 uint32_t flow_id6; 809 uint32_t extra; /* queue/pipe or frag_id */ 810 }; 811 #endif 812 813 #define IS_IP4_FLOW_ID(id) ((id)->addr_type == 4) 814 #define IS_IP6_FLOW_ID(id) ((id)->addr_type == 6) 815 816 /* 817 * Dynamic ipfw rule. 818 */ 819 #define IPFW_DYN_ORPHANED 0x40000 /* state's parent rule was deleted */ 820 821 typedef struct _ipfw_dyn_rule { 822 struct ipfw_flow_id id; /* (masked) flow id */ 823 uint8_t set; 824 uint8_t type; /* rule type */ 825 uint16_t pad; 826 uint32_t expire; /* expire time */ 827 uint32_t rulenum; /* parent's rule number */ 828 uint32_t kidx; /* index of named object */ 829 uint64_t pcnt; /* packet match counter */ 830 uint64_t bcnt; /* byte match counter */ 831 uint32_t hashval; /* hash value */ 832 union { 833 uint32_t state; /* state of this rule (typically a 834 * combination of TCP flags) 835 */ 836 uint32_t count; /* number of linked states */ 837 }; 838 uint32_t ack_fwd; /* most recent ACKs in forward */ 839 uint32_t ack_rev; /* and reverse directions (used */ 840 /* to generate keepalives) */ 841 } __packed __aligned(8) ipfw_dyn_rule; 842 843 /* 844 * Definitions for IP option names. 845 */ 846 #define IP_FW_IPOPT_LSRR 0x01 847 #define IP_FW_IPOPT_SSRR 0x02 848 #define IP_FW_IPOPT_RR 0x04 849 #define IP_FW_IPOPT_TS 0x08 850 851 /* 852 * Definitions for TCP option names. 853 */ 854 #define IP_FW_TCPOPT_MSS 0x01 855 #define IP_FW_TCPOPT_WINDOW 0x02 856 #define IP_FW_TCPOPT_SACK 0x04 857 #define IP_FW_TCPOPT_TS 0x08 858 #define IP_FW_TCPOPT_CC 0x10 859 860 #define ICMP_REJECT_RST 0x100 /* fake ICMP code (send a TCP RST) */ 861 #define ICMP6_UNREACH_RST 0x100 /* fake ICMPv6 code (send a TCP RST) */ 862 #define ICMP_REJECT_ABORT 0x101 /* fake ICMP code (send an SCTP ABORT) */ 863 #define ICMP6_UNREACH_ABORT 0x101 /* fake ICMPv6 code (send an SCTP ABORT) */ 864 865 /* 866 * These are used for lookup tables. 867 */ 868 869 #define IPFW_TABLE_ADDR 1 /* Table for holding IPv4/IPv6 prefixes */ 870 #define IPFW_TABLE_INTERFACE 2 /* Table for holding interface names */ 871 #define IPFW_TABLE_NUMBER 3 /* Table for holding ports/uid/gid/etc */ 872 #define IPFW_TABLE_FLOW 4 /* Table for holding flow data */ 873 #define IPFW_TABLE_MAC 5 /* Table for holding mac address prefixes */ 874 #define IPFW_TABLE_MAXTYPE 5 /* Maximum valid number */ 875 876 #define IPFW_TABLE_CIDR IPFW_TABLE_ADDR /* compat */ 877 878 /* Value types */ 879 #define IPFW_VTYPE_LEGACY 0xFFFFFFFF /* All data is filled in */ 880 #define IPFW_VTYPE_SKIPTO 0x00000001 /* skipto/call/callreturn */ 881 #define IPFW_VTYPE_PIPE 0x00000002 /* pipe/queue */ 882 #define IPFW_VTYPE_FIB 0x00000004 /* setfib */ 883 #define IPFW_VTYPE_NAT 0x00000008 /* nat */ 884 #define IPFW_VTYPE_DSCP 0x00000010 /* dscp */ 885 #define IPFW_VTYPE_TAG 0x00000020 /* tag/untag */ 886 #define IPFW_VTYPE_DIVERT 0x00000040 /* divert/tee */ 887 #define IPFW_VTYPE_NETGRAPH 0x00000080 /* netgraph/ngtee */ 888 #define IPFW_VTYPE_LIMIT 0x00000100 /* limit */ 889 #define IPFW_VTYPE_NH4 0x00000200 /* IPv4 nexthop */ 890 #define IPFW_VTYPE_NH6 0x00000400 /* IPv6 nexthop */ 891 #define IPFW_VTYPE_MARK 0x00000800 /* [fw]mark */ 892 893 typedef struct _ipfw_table_xentry { 894 uint16_t len; /* Total entry length */ 895 uint8_t type; /* entry type */ 896 uint8_t masklen; /* mask length */ 897 uint16_t tbl; /* table number */ 898 uint16_t flags; /* record flags */ 899 uint32_t value; /* value */ 900 union { 901 /* Longest field needs to be aligned by 4-byte boundary */ 902 struct in6_addr addr6; /* IPv6 address */ 903 char iface[IF_NAMESIZE]; /* interface name */ 904 } k; 905 } ipfw_table_xentry; 906 #define IPFW_TCF_INET 0x01 /* CIDR flags: IPv4 record */ 907 908 typedef struct _ipfw_xtable { 909 ip_fw3_opheader opheader; /* IP_FW3 opcode */ 910 uint32_t size; /* size of entries in bytes */ 911 uint32_t cnt; /* # of entries */ 912 uint16_t tbl; /* table number */ 913 uint8_t type; /* table type */ 914 ipfw_table_xentry xent[0]; /* entries */ 915 } ipfw_xtable; 916 917 typedef struct _ipfw_obj_tlv { 918 uint16_t type; /* TLV type */ 919 uint16_t flags; /* TLV-specific flags */ 920 uint32_t length; /* Total length, aligned to u64 */ 921 } ipfw_obj_tlv; 922 #define IPFW_TLV_TBL_NAME 1 923 #define IPFW_TLV_TBLNAME_LIST 2 924 #define IPFW_TLV_RULE_LIST 3 925 #define IPFW_TLV_DYNSTATE_LIST 4 926 #define IPFW_TLV_TBL_ENT 5 927 #define IPFW_TLV_DYN_ENT 6 928 #define IPFW_TLV_RULE_ENT 7 929 #define IPFW_TLV_TBLENT_LIST 8 930 #define IPFW_TLV_RANGE 9 931 #define IPFW_TLV_EACTION 10 932 #define IPFW_TLV_COUNTERS 11 933 #define IPFW_TLV_OBJDATA 12 934 #define IPFW_TLV_STATE_NAME 14 935 936 #define IPFW_TLV_EACTION_BASE 1000 937 #define IPFW_TLV_EACTION_NAME(arg) (IPFW_TLV_EACTION_BASE + (arg)) 938 939 typedef struct _ipfw_obj_data { 940 ipfw_obj_tlv head; 941 void *data[0]; 942 } ipfw_obj_data; 943 944 /* Object name TLV */ 945 typedef struct _ipfw_obj_ntlv { 946 ipfw_obj_tlv head; /* TLV header */ 947 uint32_t idx; /* Name index */ 948 uint8_t set; /* set, if applicable */ 949 uint8_t type; /* object type, if applicable */ 950 uint16_t spare; /* unused */ 951 char name[64]; /* Null-terminated name */ 952 } ipfw_obj_ntlv; 953 954 /* IPv4/IPv6 L4 flow description */ 955 struct tflow_entry { 956 uint8_t af; 957 uint8_t proto; 958 uint16_t spare; 959 uint16_t sport; 960 uint16_t dport; 961 union { 962 struct { 963 struct in_addr sip; 964 struct in_addr dip; 965 } a4; 966 struct { 967 struct in6_addr sip6; 968 struct in6_addr dip6; 969 } a6; 970 } a; 971 }; 972 973 #define IPFW_TVALUE_TYPE_MASK 0x7F00 974 #define IPFW_TVALUE_TYPE(insn) (((insn)->arg1 & IPFW_TVALUE_TYPE_MASK) >> 8) 975 #define IPFW_SET_TVALUE_TYPE(insn, type) do { \ 976 (insn)->arg1 &= ~IPFW_TVALUE_TYPE_MASK; \ 977 (insn)->arg1 |= ((type) << 8) & IPFW_TVALUE_TYPE_MASK; \ 978 } while (0) 979 #define IPFW_LOOKUP_F_MATCH_TVALUE 0x8000 980 #define IPFW_LOOKUP_MATCH_TVALUE(insn) ((insn)->arg1 & IPFW_LOOKUP_F_MATCH_TVALUE) 981 #define IPFW_SET_LOOKUP_MATCH_TVALUE(insn, value) do { \ 982 if (value) \ 983 (insn)->arg1 |= IPFW_LOOKUP_F_MATCH_TVALUE; \ 984 else \ 985 (insn)->arg1 &= ~IPFW_LOOKUP_F_MATCH_TVALUE; \ 986 } while (0) 987 988 enum ipfw_table_value_type { 989 TVALUE_TAG = 0, 990 TVALUE_PIPE, 991 TVALUE_DIVERT, 992 TVALUE_SKIPTO, 993 TVALUE_NETGRAPH, 994 TVALUE_FIB, 995 TVALUE_NAT, 996 TVALUE_NH4, 997 TVALUE_DSCP, 998 TVALUE_LIMIT, 999 TVALUE_MARK, 1000 TVALUE_NH6, 1001 }; 1002 1003 /* 64-byte structure representing multi-field table value */ 1004 typedef struct _ipfw_table_value { 1005 uint32_t tag; /* O_TAG/O_TAGGED */ 1006 uint16_t pipe; /* O_PIPE/O_QUEUE */ 1007 uint16_t divert; /* O_DIVERT/O_TEE */ 1008 uint32_t skipto; /* skipto, CALLRET */ 1009 uint32_t netgraph; /* O_NETGRAPH/O_NGTEE */ 1010 uint32_t nat; /* O_NAT */ 1011 uint32_t nh4; 1012 uint16_t fib; /* O_SETFIB */ 1013 uint8_t dscp; 1014 uint8_t spare0; 1015 uint32_t kidx; /* value kernel index */ 1016 struct in6_addr nh6; 1017 uint32_t limit; /* O_LIMIT */ 1018 uint32_t zoneid; /* scope zone id for nh6 */ 1019 uint32_t mark; /* O_SETMARK/O_MARK */ 1020 uint32_t refcnt; /* XXX 64-bit in kernel */ 1021 } ipfw_table_value; 1022 1023 /* Table entry TLV */ 1024 typedef struct _ipfw_obj_tentry { 1025 ipfw_obj_tlv head; /* TLV header */ 1026 uint8_t subtype; /* subtype (IPv4,IPv6) */ 1027 uint8_t masklen; /* mask length */ 1028 uint8_t result; /* request result */ 1029 uint8_t spare0; 1030 uint32_t idx; /* Table name index */ 1031 union { 1032 /* Longest field needs to be aligned by 8-byte boundary */ 1033 struct in_addr addr; /* IPv4 address */ 1034 uint32_t key; /* uid/gid/port */ 1035 struct in6_addr addr6; /* IPv6 address */ 1036 char iface[IF_NAMESIZE]; /* interface name */ 1037 u_char mac[IPFW_MAX_L2_ADDR_LEN]; /* MAC address */ 1038 struct tflow_entry flow; 1039 } k; 1040 union { 1041 ipfw_table_value value; /* value data */ 1042 uint32_t kidx; /* value kernel index */ 1043 } v; 1044 } ipfw_obj_tentry; 1045 #define IPFW_TF_UPDATE 0x01 /* Update record if exists */ 1046 /* Container TLV */ 1047 #define IPFW_CTF_ATOMIC 0x01 /* Perform atomic operation */ 1048 /* Operation results */ 1049 #define IPFW_TR_IGNORED 0 /* Entry was ignored (rollback) */ 1050 #define IPFW_TR_ADDED 1 /* Entry was successfully added */ 1051 #define IPFW_TR_UPDATED 2 /* Entry was successfully updated*/ 1052 #define IPFW_TR_DELETED 3 /* Entry was successfully deleted*/ 1053 #define IPFW_TR_LIMIT 4 /* Entry was ignored (limit) */ 1054 #define IPFW_TR_NOTFOUND 5 /* Entry was not found */ 1055 #define IPFW_TR_EXISTS 6 /* Entry already exists */ 1056 #define IPFW_TR_ERROR 7 /* Request has failed (unknown) */ 1057 1058 typedef struct _ipfw_obj_dyntlv { 1059 ipfw_obj_tlv head; 1060 ipfw_dyn_rule state; 1061 } ipfw_obj_dyntlv; 1062 #define IPFW_DF_LAST 0x01 /* Last state in chain */ 1063 1064 /* Containter TLVs */ 1065 typedef struct _ipfw_obj_ctlv { 1066 ipfw_obj_tlv head; /* TLV header */ 1067 uint32_t count; /* Number of sub-TLVs */ 1068 uint16_t objsize; /* Single object size */ 1069 uint8_t version; /* TLV version */ 1070 uint8_t flags; /* TLV-specific flags */ 1071 } ipfw_obj_ctlv; 1072 1073 /* Range TLV */ 1074 typedef struct _ipfw_range_tlv { 1075 ipfw_obj_tlv head; /* TLV header */ 1076 uint32_t flags; /* Range flags */ 1077 uint32_t start_rule; /* Range start */ 1078 uint32_t end_rule; /* Range end */ 1079 uint32_t set; /* Range set to match */ 1080 uint32_t new_set; /* New set to move/swap to */ 1081 } ipfw_range_tlv; 1082 #define IPFW_RCFLAG_RANGE 0x01 /* rule range is set */ 1083 #define IPFW_RCFLAG_ALL 0x02 /* match ALL rules */ 1084 #define IPFW_RCFLAG_SET 0x04 /* match rules in given set */ 1085 #define IPFW_RCFLAG_DYNAMIC 0x08 /* match only dynamic states */ 1086 /* User-settable flags */ 1087 #define IPFW_RCFLAG_USER (IPFW_RCFLAG_RANGE | IPFW_RCFLAG_ALL | \ 1088 IPFW_RCFLAG_SET | IPFW_RCFLAG_DYNAMIC) 1089 /* Internally used flags */ 1090 #define IPFW_RCFLAG_DEFAULT 0x0100 /* Do not skip default rule */ 1091 1092 typedef struct _ipfw_ta_tinfo { 1093 uint32_t flags; /* Format flags */ 1094 uint32_t spare; 1095 uint8_t taclass4; /* algorithm class */ 1096 uint8_t spare4; 1097 uint16_t itemsize4; /* item size in runtime */ 1098 uint32_t size4; /* runtime structure size */ 1099 uint32_t count4; /* number of items in runtime */ 1100 uint8_t taclass6; /* algorithm class */ 1101 uint8_t spare6; 1102 uint16_t itemsize6; /* item size in runtime */ 1103 uint32_t size6; /* runtime structure size */ 1104 uint32_t count6; /* number of items in runtime */ 1105 } ipfw_ta_tinfo; 1106 #define IPFW_TACLASS_HASH 1 /* algo is based on hash */ 1107 #define IPFW_TACLASS_ARRAY 2 /* algo is based on array */ 1108 #define IPFW_TACLASS_RADIX 3 /* algo is based on radix tree */ 1109 1110 #define IPFW_TATFLAGS_DATA 0x0001 /* Has data filled in */ 1111 #define IPFW_TATFLAGS_AFDATA 0x0002 /* Separate data per AF */ 1112 #define IPFW_TATFLAGS_AFITEM 0x0004 /* diff. items per AF */ 1113 1114 typedef struct _ipfw_xtable_info { 1115 uint8_t type; /* table type (addr,iface,..) */ 1116 uint8_t tflags; /* type flags */ 1117 uint16_t mflags; /* modification flags */ 1118 uint16_t flags; /* generic table flags */ 1119 uint16_t spare[3]; 1120 uint32_t vmask; /* bitmask with value types */ 1121 uint32_t set; /* set table is in */ 1122 uint32_t kidx; /* kernel index */ 1123 uint32_t refcnt; /* number of references */ 1124 uint32_t count; /* Number of records */ 1125 uint32_t size; /* Total size of records(export)*/ 1126 uint32_t limit; /* Max number of records */ 1127 char tablename[64]; /* table name */ 1128 char algoname[64]; /* algorithm name */ 1129 ipfw_ta_tinfo ta_info; /* additional algo stats */ 1130 } ipfw_xtable_info; 1131 /* Generic table flags */ 1132 #define IPFW_TGFLAGS_LOCKED 0x01 /* Tables is locked from changes*/ 1133 /* Table type-specific flags */ 1134 #define IPFW_TFFLAG_SRCIP 0x01 1135 #define IPFW_TFFLAG_DSTIP 0x02 1136 #define IPFW_TFFLAG_SRCPORT 0x04 1137 #define IPFW_TFFLAG_DSTPORT 0x08 1138 #define IPFW_TFFLAG_PROTO 0x10 1139 /* Table modification flags */ 1140 #define IPFW_TMFLAGS_LIMIT 0x0002 /* Change limit value */ 1141 #define IPFW_TMFLAGS_LOCK 0x0004 /* Change table lock state */ 1142 1143 typedef struct _ipfw_iface_info { 1144 char ifname[64]; /* interface name */ 1145 uint32_t ifindex; /* interface index */ 1146 uint32_t flags; /* flags */ 1147 uint32_t refcnt; /* number of references */ 1148 uint32_t gencnt; /* number of changes */ 1149 uint64_t spare; 1150 } ipfw_iface_info; 1151 #define IPFW_IFFLAG_RESOLVED 0x01 /* Interface exists */ 1152 1153 typedef struct _ipfw_ta_info { 1154 char algoname[64]; /* algorithm name */ 1155 uint32_t type; /* lookup type */ 1156 uint32_t flags; 1157 uint32_t refcnt; 1158 uint32_t spare0; 1159 uint64_t spare1; 1160 } ipfw_ta_info; 1161 1162 typedef struct _ipfw_cmd_header { /* control command header */ 1163 ip_fw3_opheader opheader; /* IP_FW3 opcode */ 1164 uint32_t size; /* Total size (incl. header) */ 1165 uint32_t cmd; /* command */ 1166 } ipfw_cmd_header; 1167 1168 typedef struct _ipfw_obj_header { 1169 ip_fw3_opheader opheader; /* IP_FW3 opcode */ 1170 uint32_t idx; /* object name index */ 1171 uint16_t spare; 1172 uint8_t objtype; /* object type */ 1173 uint8_t objsubtype; /* object subtype */ 1174 ipfw_obj_ntlv ntlv; /* object name tlv */ 1175 } ipfw_obj_header; 1176 1177 typedef struct _ipfw_obj_lheader { 1178 ip_fw3_opheader opheader; /* IP_FW3 opcode */ 1179 uint32_t set_mask; /* disabled set mask */ 1180 uint32_t count; /* Total objects count */ 1181 uint32_t size; /* Total size (incl. header) */ 1182 uint32_t objsize; /* Size of one object */ 1183 } ipfw_obj_lheader; 1184 1185 #define IPFW_CFG_GET_STATIC 0x01 1186 #define IPFW_CFG_GET_STATES 0x02 1187 #define IPFW_CFG_GET_COUNTERS 0x04 1188 typedef struct _ipfw_cfg_lheader { 1189 ip_fw3_opheader opheader; /* IP_FW3 opcode */ 1190 uint32_t set_mask; /* enabled set mask */ 1191 uint32_t spare; 1192 uint32_t flags; /* Request flags */ 1193 uint32_t size; /* neded buffer size */ 1194 uint32_t start_rule; 1195 uint32_t end_rule; 1196 } ipfw_cfg_lheader; 1197 1198 typedef struct _ipfw_range_header { 1199 ip_fw3_opheader opheader; /* IP_FW3 opcode */ 1200 ipfw_range_tlv range; 1201 } ipfw_range_header; 1202 1203 typedef struct _ipfw_sopt_info { 1204 uint16_t opcode; 1205 uint8_t version; 1206 uint8_t dir; 1207 uint8_t spare; 1208 uint64_t refcnt; 1209 } ipfw_sopt_info; 1210 1211 #endif /* _IPFW2_H */ 1212