ip_fw.h revision 141351
1139823Simp/*-
298943Sluigi * Copyright (c) 2002 Luigi Rizzo, Universita` di Pisa
33969Sjkh *
498943Sluigi * Redistribution and use in source and binary forms, with or without
598943Sluigi * modification, are permitted provided that the following conditions
698943Sluigi * are met:
798943Sluigi * 1. Redistributions of source code must retain the above copyright
898943Sluigi *    notice, this list of conditions and the following disclaimer.
998943Sluigi * 2. Redistributions in binary form must reproduce the above copyright
1098943Sluigi *    notice, this list of conditions and the following disclaimer in the
1198943Sluigi *    documentation and/or other materials provided with the distribution.
123969Sjkh *
1398943Sluigi * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1498943Sluigi * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1598943Sluigi * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1698943Sluigi * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1798943Sluigi * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1898943Sluigi * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1998943Sluigi * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2098943Sluigi * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2198943Sluigi * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2298943Sluigi * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2398943Sluigi * SUCH DAMAGE.
243969Sjkh *
2550477Speter * $FreeBSD: head/sys/netinet/ip_fw.h 141351 2005-02-05 12:06:33Z glebius $
263969Sjkh */
273969Sjkh
2898943Sluigi#ifndef _IPFW2_H
2998943Sluigi#define _IPFW2_H
30100228Sluigi#define IPFW2  1
31133920Sandre
323969Sjkh/*
3398943Sluigi * The kernel representation of ipfw rules is made of a list of
3498943Sluigi * 'instructions' (for all practical purposes equivalent to BPF
3598943Sluigi * instructions), which specify which fields of the packet
36115793Sticso * (or its metadata) should be analysed.
3726359Sjulian *
3898943Sluigi * Each instruction is stored in a structure which begins with
3998943Sluigi * "ipfw_insn", and can contain extra fields depending on the
4098943Sluigi * instruction type (listed below).
41115793Sticso * Note that the code is written so that individual instructions
42115793Sticso * have a size which is a multiple of 32 bits. This means that, if
43115793Sticso * such structures contain pointers or other 64-bit entities,
44115793Sticso * (there is just one instance now) they may end up unaligned on
45115793Sticso * 64-bit architectures, so the must be handled with care.
4698943Sluigi *
4798943Sluigi * "enum ipfw_opcodes" are the opcodes supported. We can have up
48133600Scsjp * to 256 different opcodes. When adding new opcodes, they should
49133600Scsjp * be appended to the end of the opcode list before O_LAST_OPCODE,
50133600Scsjp * this will prevent the ABI from being broken, otherwise users
51133600Scsjp * will have to recompile ipfw(8) when they update the kernel.
5226359Sjulian */
5326359Sjulian
5498943Sluigienum ipfw_opcodes {		/* arguments (4 byte each)	*/
5598943Sluigi	O_NOP,
5698943Sluigi
5798943Sluigi	O_IP_SRC,		/* u32 = IP			*/
5898943Sluigi	O_IP_SRC_MASK,		/* ip = IP/mask			*/
5998943Sluigi	O_IP_SRC_ME,		/* none				*/
6098943Sluigi	O_IP_SRC_SET,		/* u32=base, arg1=len, bitmap	*/
6198943Sluigi
6298943Sluigi	O_IP_DST,		/* u32 = IP			*/
6398943Sluigi	O_IP_DST_MASK,		/* ip = IP/mask			*/
6498943Sluigi	O_IP_DST_ME,		/* none				*/
6598943Sluigi	O_IP_DST_SET,		/* u32=base, arg1=len, bitmap	*/
6698943Sluigi
6798943Sluigi	O_IP_SRCPORT,		/* (n)port list:mask 4 byte ea	*/
6898943Sluigi	O_IP_DSTPORT,		/* (n)port list:mask 4 byte ea	*/
6998943Sluigi	O_PROTO,		/* arg1=protocol		*/
7098943Sluigi
7198943Sluigi	O_MACADDR2,		/* 2 mac addr:mask		*/
7298943Sluigi	O_MAC_TYPE,		/* same as srcport		*/
7398943Sluigi
7498943Sluigi	O_LAYER2,		/* none				*/
7598943Sluigi	O_IN,			/* none				*/
7698943Sluigi	O_FRAG,			/* none				*/
7798943Sluigi
7898943Sluigi	O_RECV,			/* none				*/
7998943Sluigi	O_XMIT,			/* none				*/
8098943Sluigi	O_VIA,			/* none				*/
8198943Sluigi
8298943Sluigi	O_IPOPT,		/* arg1 = 2*u8 bitmap		*/
8398943Sluigi	O_IPLEN,		/* arg1 = len			*/
8498943Sluigi	O_IPID,			/* arg1 = id			*/
8598943Sluigi
8698943Sluigi	O_IPTOS,		/* arg1 = id			*/
8799475Sluigi	O_IPPRECEDENCE,		/* arg1 = precedence << 5	*/
8898943Sluigi	O_IPTTL,		/* arg1 = TTL			*/
8998943Sluigi
9098943Sluigi	O_IPVER,		/* arg1 = version		*/
9198943Sluigi	O_UID,			/* u32 = id			*/
9298943Sluigi	O_GID,			/* u32 = id			*/
9398943Sluigi	O_ESTAB,		/* none (tcp established)	*/
9498943Sluigi	O_TCPFLAGS,		/* arg1 = 2*u8 bitmap		*/
9598943Sluigi	O_TCPWIN,		/* arg1 = desired win		*/
9698943Sluigi	O_TCPSEQ,		/* u32 = desired seq.		*/
9798943Sluigi	O_TCPACK,		/* u32 = desired seq.		*/
9898943Sluigi	O_ICMPTYPE,		/* u32 = icmp bitmap		*/
9998943Sluigi	O_TCPOPTS,		/* arg1 = 2*u8 bitmap		*/
10098943Sluigi
101112250Scjc	O_VERREVPATH,		/* none				*/
102128575Sandre	O_VERSRCREACH,		/* none				*/
103112250Scjc
10498943Sluigi	O_PROBE_STATE,		/* none				*/
10598943Sluigi	O_KEEP_STATE,		/* none				*/
10698943Sluigi	O_LIMIT,		/* ipfw_insn_limit		*/
10798943Sluigi	O_LIMIT_PARENT,		/* dyn_type, not an opcode.	*/
108117240Sluigi
10998943Sluigi	/*
110117240Sluigi	 * These are really 'actions'.
11198943Sluigi	 */
11298943Sluigi
11398943Sluigi	O_LOG,			/* ipfw_insn_log		*/
11498943Sluigi	O_PROB,			/* u32 = match probability	*/
11598943Sluigi
11698943Sluigi	O_CHECK_STATE,		/* none				*/
11798943Sluigi	O_ACCEPT,		/* none				*/
11898943Sluigi	O_DENY,			/* none 			*/
11998943Sluigi	O_REJECT,		/* arg1=icmp arg (same as deny)	*/
12098943Sluigi	O_COUNT,		/* none				*/
12198943Sluigi	O_SKIPTO,		/* arg1=next rule number	*/
12298943Sluigi	O_PIPE,			/* arg1=pipe number		*/
12398943Sluigi	O_QUEUE,		/* arg1=queue number		*/
12498943Sluigi	O_DIVERT,		/* arg1=port number		*/
12598943Sluigi	O_TEE,			/* arg1=port number		*/
12698943Sluigi	O_FORWARD_IP,		/* fwd sockaddr			*/
12798943Sluigi	O_FORWARD_MAC,		/* fwd mac			*/
128117240Sluigi
129117240Sluigi	/*
130117240Sluigi	 * More opcodes.
131117240Sluigi	 */
132117240Sluigi	O_IPSEC,		/* has ipsec history 		*/
133130281Sru	O_IP_SRC_LOOKUP,	/* arg1=table number, u32=value	*/
134130281Sru	O_IP_DST_LOOKUP,	/* arg1=table number, u32=value	*/
135133849Sobrien	O_ANTISPOOF,		/* none				*/
136133600Scsjp	O_JAIL,			/* u32 = id			*/
137136071Sgreen	O_ALTQ,			/* u32 = altq classif. qid	*/
138136073Sgreen	O_DIVERTED,		/* arg1=bitmap (1:loop, 2:out)	*/
139136075Sgreen	O_TCPDATALEN,		/* arg1 = tcp data len		*/
140117240Sluigi
141141351Sglebius	/*
142141351Sglebius	 * actions for ng_ipfw
143141351Sglebius	 */
144141351Sglebius	O_NETGRAPH,		/* send to ng_ipfw		*/
145141351Sglebius	O_NGTEE,		/* copy to ng_ipfw		*/
146141351Sglebius
14798943Sluigi	O_LAST_OPCODE		/* not an opcode!		*/
14826359Sjulian};
14926359Sjulian
15026359Sjulian/*
15198943Sluigi * Template for instructions.
1523969Sjkh *
15398943Sluigi * ipfw_insn is used for all instructions which require no operands,
15498943Sluigi * a single 16-bit value (arg1), or a couple of 8-bit values.
15598943Sluigi *
15698943Sluigi * For other instructions which require different/larger arguments
15798943Sluigi * we have derived structures, ipfw_insn_*.
15898943Sluigi *
15998943Sluigi * The size of the instruction (in 32-bit words) is in the low
16098943Sluigi * 6 bits of "len". The 2 remaining bits are used to implement
16198943Sluigi * NOT and OR on individual instructions. Given a type, you can
16298943Sluigi * compute the length to be put in "len" using F_INSN_SIZE(t)
16398943Sluigi *
16498943Sluigi * F_NOT	negates the match result of the instruction.
16598943Sluigi *
16698943Sluigi * F_OR		is used to build or blocks. By default, instructions
16798943Sluigi *		are evaluated as part of a logical AND. An "or" block
16898943Sluigi *		{ X or Y or Z } contains F_OR set in all but the last
16998943Sluigi *		instruction of the block. A match will cause the code
17098943Sluigi *		to skip past the last instruction of the block.
17198943Sluigi *
17298943Sluigi * NOTA BENE: in a couple of places we assume that
17398943Sluigi *	sizeof(ipfw_insn) == sizeof(u_int32_t)
17498943Sluigi * this needs to be fixed.
17598943Sluigi *
1763969Sjkh */
17798943Sluigitypedef struct	_ipfw_insn {	/* template for instructions */
17898943Sluigi	enum ipfw_opcodes	opcode:8;
17998943Sluigi	u_int8_t	len;	/* numer of 32-byte words */
18098943Sluigi#define	F_NOT		0x80
18198943Sluigi#define	F_OR		0x40
18298943Sluigi#define	F_LEN_MASK	0x3f
18398943Sluigi#define	F_LEN(cmd)	((cmd)->len & F_LEN_MASK)
1843969Sjkh
18598943Sluigi	u_int16_t	arg1;
18698943Sluigi} ipfw_insn;
18798943Sluigi
18896245Sluigi/*
18998943Sluigi * The F_INSN_SIZE(type) computes the size, in 4-byte words, of
19098943Sluigi * a given type.
19196245Sluigi */
19298943Sluigi#define	F_INSN_SIZE(t)	((sizeof (t))/sizeof(u_int32_t))
19396245Sluigi
19498943Sluigi/*
19598943Sluigi * This is used to store an array of 16-bit entries (ports etc.)
19698943Sluigi */
19798943Sluigitypedef struct	_ipfw_insn_u16 {
19898943Sluigi	ipfw_insn o;
19998943Sluigi	u_int16_t ports[2];	/* there may be more */
20098943Sluigi} ipfw_insn_u16;
20196245Sluigi
20298943Sluigi/*
20398943Sluigi * This is used to store an array of 32-bit entries
20498943Sluigi * (uid, single IPv4 addresses etc.)
20598943Sluigi */
20698943Sluigitypedef struct	_ipfw_insn_u32 {
20798943Sluigi	ipfw_insn o;
20898943Sluigi	u_int32_t d[1];	/* one or more */
20998943Sluigi} ipfw_insn_u32;
21084058Sluigi
21198943Sluigi/*
21298943Sluigi * This is used to store IP addr-mask pairs.
21398943Sluigi */
21498943Sluigitypedef struct	_ipfw_insn_ip {
21598943Sluigi	ipfw_insn o;
21698943Sluigi	struct in_addr	addr;
21798943Sluigi	struct in_addr	mask;
21898943Sluigi} ipfw_insn_ip;
2193969Sjkh
22098943Sluigi/*
221117240Sluigi * This is used to forward to a given address (ip).
22298943Sluigi */
22398943Sluigitypedef struct  _ipfw_insn_sa {
22498943Sluigi	ipfw_insn o;
22598943Sluigi	struct sockaddr_in sa;
22698943Sluigi} ipfw_insn_sa;
22785665Sjoe
22898943Sluigi/*
22998943Sluigi * This is used for MAC addr-mask pairs.
23098943Sluigi */
23198943Sluigitypedef struct	_ipfw_insn_mac {
23298943Sluigi	ipfw_insn o;
23398943Sluigi	u_char addr[12];	/* dst[6] + src[6] */
23498943Sluigi	u_char mask[12];	/* dst[6] + src[6] */
23598943Sluigi} ipfw_insn_mac;
23685665Sjoe
23798943Sluigi/*
238117240Sluigi * This is used for interface match rules (recv xx, xmit xx).
23998943Sluigi */
24098943Sluigitypedef struct	_ipfw_insn_if {
24198943Sluigi	ipfw_insn o;
24298943Sluigi	union {
24398943Sluigi		struct in_addr ip;
244121816Sbrooks		int glob;
24598943Sluigi	} p;
24698943Sluigi	char name[IFNAMSIZ];
24798943Sluigi} ipfw_insn_if;
24898943Sluigi
24998943Sluigi/*
25098943Sluigi * This is used for pipe and queue actions, which need to store
25198943Sluigi * a single pointer (which can have different size on different
25298943Sluigi * architectures.
253115793Sticso * Note that, because of previous instructions, pipe_ptr might
254115793Sticso * be unaligned in the overall structure, so it needs to be
255115793Sticso * manipulated with care.
25698943Sluigi */
25798943Sluigitypedef struct	_ipfw_insn_pipe {
25898943Sluigi	ipfw_insn	o;
259115793Sticso	void		*pipe_ptr;	/* XXX */
26098943Sluigi} ipfw_insn_pipe;
26198943Sluigi
26298943Sluigi/*
263136071Sgreen * This is used for storing an altq queue id number.
264136071Sgreen */
265136071Sgreentypedef struct _ipfw_insn_altq {
266136071Sgreen	ipfw_insn	o;
267136071Sgreen	u_int32_t	qid;
268136071Sgreen} ipfw_insn_altq;
269136071Sgreen
270136071Sgreen/*
27198943Sluigi * This is used for limit rules.
27298943Sluigi */
27398943Sluigitypedef struct	_ipfw_insn_limit {
27498943Sluigi	ipfw_insn o;
27598943Sluigi	u_int8_t _pad;
27698943Sluigi	u_int8_t limit_mask;	/* combination of DYN_* below	*/
27784058Sluigi#define	DYN_SRC_ADDR	0x1
27884058Sluigi#define	DYN_SRC_PORT	0x2
27984058Sluigi#define	DYN_DST_ADDR	0x4
28084058Sluigi#define	DYN_DST_PORT	0x8
28185665Sjoe
28298943Sluigi	u_int16_t conn_limit;
28398943Sluigi} ipfw_insn_limit;
28449630Sluigi
28598943Sluigi/*
286117240Sluigi * This is used for log instructions.
28798943Sluigi */
28898943Sluigitypedef struct  _ipfw_insn_log {
28998943Sluigi        ipfw_insn o;
29098943Sluigi	u_int32_t max_log;	/* how many do we log -- 0 = all */
29198943Sluigi	u_int32_t log_left;	/* how many left to log 	*/
29298943Sluigi} ipfw_insn_log;
29326359Sjulian
29485689Sjoe/*
29598943Sluigi * Here we have the structure representing an ipfw rule.
29683725Sluigi *
29798943Sluigi * It starts with a general area (with link fields and counters)
29898943Sluigi * followed by an array of one or more instructions, which the code
29998943Sluigi * accesses as an array of 32-bit values.
30083725Sluigi *
30198943Sluigi * Given a rule pointer  r:
30298943Sluigi *
30398943Sluigi *  r->cmd		is the start of the first instruction.
30498943Sluigi *  ACTION_PTR(r)	is the start of the first action (things to do
30598943Sluigi *			once a rule matched).
30698943Sluigi *
30798943Sluigi * When assembling instruction, remember the following:
30898943Sluigi *
30998943Sluigi *  + if a rule has a "keep-state" (or "limit") option, then the
31098943Sluigi *	first instruction (at r->cmd) MUST BE an O_PROBE_STATE
31198943Sluigi *  + if a rule has a "log" option, then the first action
31298943Sluigi *	(at ACTION_PTR(r)) MUST be O_LOG
313136071Sgreen *  + if a rule has an "altq" option, it comes after "log"
31498943Sluigi *
31598943Sluigi * NOTE: we use a simple linked list of rules because we never need
31698943Sluigi * 	to delete a rule without scanning the list. We do not use
31798943Sluigi *	queue(3) macros for portability and readability.
31883725Sluigi */
31983725Sluigi
32098943Sluigistruct ip_fw {
321100004Sluigi	struct ip_fw	*next;		/* linked list of rules		*/
322101628Sluigi	struct ip_fw	*next_rule;	/* ptr to next [skipto] rule	*/
323117240Sluigi	/* 'next_rule' is used to pass up 'set_disable' status		*/
324117240Sluigi
32598943Sluigi	u_int16_t	act_ofs;	/* offset of action in 32-bit units */
32698943Sluigi	u_int16_t	cmd_len;	/* # of 32-bit words in cmd	*/
32798943Sluigi	u_int16_t	rulenum;	/* rule number			*/
328101628Sluigi	u_int8_t	set;		/* rule set (0..31)		*/
329117654Sluigi#define	RESVD_SET	31	/* set for default and persistent rules */
330101628Sluigi	u_int8_t	_pad;		/* padding			*/
33198943Sluigi
33298943Sluigi	/* These fields are present in all rules.			*/
33398943Sluigi	u_int64_t	pcnt;		/* Packet counter		*/
33498943Sluigi	u_int64_t	bcnt;		/* Byte counter			*/
33598943Sluigi	u_int32_t	timestamp;	/* tv_sec of last match		*/
33698943Sluigi
33798943Sluigi	ipfw_insn	cmd[1];		/* storage for commands		*/
33898943Sluigi};
33998943Sluigi
34098943Sluigi#define ACTION_PTR(rule)				\
34198943Sluigi	(ipfw_insn *)( (u_int32_t *)((rule)->cmd) + ((rule)->act_ofs) )
34298943Sluigi
34398943Sluigi#define RULESIZE(rule)  (sizeof(struct ip_fw) + \
34498943Sluigi	((struct ip_fw *)(rule))->cmd_len * 4 - 4)
34598943Sluigi
3464277Sjkh/*
34798943Sluigi * This structure is used as a flow mask and a flow id for various
34898943Sluigi * parts of the code.
34957113Sluigi */
35057113Sluigistruct ipfw_flow_id {
35185665Sjoe	u_int32_t	dst_ip;
35285665Sjoe	u_int32_t	src_ip;
35385665Sjoe	u_int16_t	dst_port;
35485665Sjoe	u_int16_t	src_port;
35585665Sjoe	u_int8_t	proto;
35685665Sjoe	u_int8_t	flags;	/* protocol-specific flags */
35785665Sjoe};
35857113Sluigi
35957113Sluigi/*
360117240Sluigi * Dynamic ipfw rule.
36157113Sluigi */
36298943Sluigitypedef struct _ipfw_dyn_rule ipfw_dyn_rule;
36398943Sluigi
36498943Sluigistruct _ipfw_dyn_rule {
36598943Sluigi	ipfw_dyn_rule	*next;		/* linked list of rules.	*/
36698943Sluigi	struct ip_fw *rule;		/* pointer to rule		*/
367117240Sluigi	/* 'rule' is used to pass up the rule number (from the parent)	*/
368117240Sluigi
36998943Sluigi	ipfw_dyn_rule *parent;		/* pointer to parent rule	*/
37098943Sluigi	u_int64_t	pcnt;		/* packet match counter		*/
37198943Sluigi	u_int64_t	bcnt;		/* byte match counter		*/
372115793Sticso	struct ipfw_flow_id id;		/* (masked) flow id		*/
373115793Sticso	u_int32_t	expire;		/* expire time			*/
37498943Sluigi	u_int32_t	bucket;		/* which bucket in hash table	*/
37585665Sjoe	u_int32_t	state;		/* state of this rule (typically a
37685665Sjoe					 * combination of TCP flags)
37785665Sjoe					 */
378100004Sluigi	u_int32_t	ack_fwd;	/* most recent ACKs in forward	*/
379100004Sluigi	u_int32_t	ack_rev;	/* and reverse directions (used	*/
380100004Sluigi					/* to generate keepalives)	*/
38198943Sluigi	u_int16_t	dyn_type;	/* rule type			*/
38298943Sluigi	u_int16_t	count;		/* refcount			*/
38385665Sjoe};
38457113Sluigi
38557113Sluigi/*
38611119Sugen * Definitions for IP option names.
38711119Sugen */
38885665Sjoe#define	IP_FW_IPOPT_LSRR	0x01
38985665Sjoe#define	IP_FW_IPOPT_SSRR	0x02
39085665Sjoe#define	IP_FW_IPOPT_RR		0x04
39185665Sjoe#define	IP_FW_IPOPT_TS		0x08
39211119Sugen
39311119Sugen/*
39461420Sdan * Definitions for TCP option names.
39561420Sdan */
39685665Sjoe#define	IP_FW_TCPOPT_MSS	0x01
39785665Sjoe#define	IP_FW_TCPOPT_WINDOW	0x02
39885665Sjoe#define	IP_FW_TCPOPT_SACK	0x04
39985665Sjoe#define	IP_FW_TCPOPT_TS		0x08
40085665Sjoe#define	IP_FW_TCPOPT_CC		0x10
40161420Sdan
40298943Sluigi#define	ICMP_REJECT_RST		0x100	/* fake ICMP code (send a TCP RST) */
40398943Sluigi
40461420Sdan/*
405130281Sru * These are used for lookup tables.
406130281Sru */
407130281Srutypedef struct	_ipfw_table_entry {
408130281Sru	in_addr_t	addr;		/* network address		*/
409130281Sru	u_int32_t	value;		/* value			*/
410130281Sru	u_int16_t	tbl;		/* table number			*/
411130281Sru	u_int8_t	masklen;	/* mask length			*/
412130281Sru} ipfw_table_entry;
413130281Sru
414130281Srutypedef struct	_ipfw_table {
415130281Sru	u_int32_t	size;		/* size of entries in bytes	*/
416130281Sru	u_int32_t	cnt;		/* # of entries			*/
417130281Sru	u_int16_t	tbl;		/* table number			*/
418130281Sru	ipfw_table_entry ent[0];	/* entries			*/
419130281Sru} ipfw_table;
420130281Sru
421130281Sru/*
4224277Sjkh * Main firewall chains definitions and global var's definitions.
4234277Sjkh */
42455205Speter#ifdef _KERNEL
4255543Sugen
426140224Sglebius/* Return values from ipfw_chk() */
427140224Sglebiusenum {
428140224Sglebius	IP_FW_PASS = 0,
429140224Sglebius	IP_FW_DENY,
430140224Sglebius	IP_FW_DIVERT,
431140224Sglebius	IP_FW_TEE,
432140224Sglebius	IP_FW_DUMMYNET,
433140224Sglebius	IP_FW_NETGRAPH,
434141351Sglebius	IP_FW_NGTEE,
435140224Sglebius};
436140224Sglebius
437140224Sglebius/* flags for divert mtag */
438136073Sgreen#define	IP_FW_DIVERT_LOOPBACK_FLAG	0x00080000
439136073Sgreen#define	IP_FW_DIVERT_OUTPUT_FLAG	0x00100000
44054175Sarchie
4415543Sugen/*
442117240Sluigi * Arguments for calling ipfw_chk() and dummynet_io(). We put them
44398613Sluigi * all into a structure because this way it is easier and more
44498613Sluigi * efficient to pass variables around and extend the interface.
44598613Sluigi */
44698613Sluigistruct ip_fw_args {
44798613Sluigi	struct mbuf	*m;		/* the mbuf chain		*/
44898613Sluigi	struct ifnet	*oif;		/* output interface		*/
44998613Sluigi	struct sockaddr_in *next_hop;	/* forward address		*/
45098613Sluigi	struct ip_fw	*rule;		/* matching rule		*/
45198613Sluigi	struct ether_header *eh;	/* for bridged packets		*/
45298613Sluigi
45398613Sluigi	int flags;			/* for dummynet			*/
45498613Sluigi
45598613Sluigi	struct ipfw_flow_id f_id;	/* grabbed from IP header	*/
456140224Sglebius	u_int32_t	cookie;		/* a cookie depending on rule action */
457135920Smlaier	struct inpcb	*inp;
45898613Sluigi};
45998613Sluigi
46098613Sluigi/*
4615543Sugen * Function definitions.
4625543Sugen */
4635543Sugen
46438482Swollman/* Firewall hooks */
46538482Swollmanstruct sockopt;
46698943Sluigistruct dn_flow_set;
46798943Sluigi
468135920Smlaierint ipfw_check_in(void *, struct mbuf **, struct ifnet *, int, struct inpcb *inp);
469135920Smlaierint ipfw_check_out(void *, struct mbuf **, struct ifnet *, int, struct inpcb *inp);
470133920Sandre
471133920Sandreint ipfw_chk(struct ip_fw_args *);
472133920Sandre
473133920Sandreint ipfw_init(void);
474133920Sandrevoid ipfw_destroy(void);
475133920Sandre
47698943Sluigivoid flush_pipe_ptrs(struct dn_flow_set *match); /* used by dummynet */
47798943Sluigi
478133920Sandretypedef int ip_fw_ctl_t(struct sockopt *);
47985665Sjoeextern ip_fw_ctl_t *ip_fw_ctl_ptr;
48057113Sluigiextern int fw_one_pass;
481134022Sandreextern int fw_enable;
482133920Sandre
483133920Sandre/* For kernel ipfw_ether and ipfw_bridge. */
484133920Sandretypedef	int ip_fw_chk_t(struct ip_fw_args *args);
485133920Sandreextern	ip_fw_chk_t	*ip_fw_chk_ptr;
48686047Sluigi#define	IPFW_LOADED	(ip_fw_chk_ptr != NULL)
487133920Sandre
48855205Speter#endif /* _KERNEL */
48998943Sluigi#endif /* _IPFW2_H */
490