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