xref: /freebsd/sys/netpfil/ipfw/ip_fw_private.h (revision 132636325388b11fec38a24e4b41d33d2cf59e9f)
13b3a8eb9SGleb Smirnoff /*-
23b3a8eb9SGleb Smirnoff  * Copyright (c) 2002-2009 Luigi Rizzo, Universita` di Pisa
33b3a8eb9SGleb Smirnoff  *
43b3a8eb9SGleb Smirnoff  * Redistribution and use in source and binary forms, with or without
53b3a8eb9SGleb Smirnoff  * modification, are permitted provided that the following conditions
63b3a8eb9SGleb Smirnoff  * are met:
73b3a8eb9SGleb Smirnoff  * 1. Redistributions of source code must retain the above copyright
83b3a8eb9SGleb Smirnoff  *    notice, this list of conditions and the following disclaimer.
93b3a8eb9SGleb Smirnoff  * 2. Redistributions in binary form must reproduce the above copyright
103b3a8eb9SGleb Smirnoff  *    notice, this list of conditions and the following disclaimer in the
113b3a8eb9SGleb Smirnoff  *    documentation and/or other materials provided with the distribution.
123b3a8eb9SGleb Smirnoff  *
133b3a8eb9SGleb Smirnoff  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
143b3a8eb9SGleb Smirnoff  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
153b3a8eb9SGleb Smirnoff  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
163b3a8eb9SGleb Smirnoff  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
173b3a8eb9SGleb Smirnoff  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
183b3a8eb9SGleb Smirnoff  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
193b3a8eb9SGleb Smirnoff  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
203b3a8eb9SGleb Smirnoff  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
213b3a8eb9SGleb Smirnoff  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
223b3a8eb9SGleb Smirnoff  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
233b3a8eb9SGleb Smirnoff  * SUCH DAMAGE.
243b3a8eb9SGleb Smirnoff  *
253b3a8eb9SGleb Smirnoff  * $FreeBSD$
263b3a8eb9SGleb Smirnoff  */
273b3a8eb9SGleb Smirnoff 
283b3a8eb9SGleb Smirnoff #ifndef _IPFW2_PRIVATE_H
293b3a8eb9SGleb Smirnoff #define _IPFW2_PRIVATE_H
303b3a8eb9SGleb Smirnoff 
313b3a8eb9SGleb Smirnoff /*
323b3a8eb9SGleb Smirnoff  * Internal constants and data structures used by ipfw components
333b3a8eb9SGleb Smirnoff  * and not meant to be exported outside the kernel.
343b3a8eb9SGleb Smirnoff  */
353b3a8eb9SGleb Smirnoff 
363b3a8eb9SGleb Smirnoff #ifdef _KERNEL
373b3a8eb9SGleb Smirnoff 
383b3a8eb9SGleb Smirnoff /*
393b3a8eb9SGleb Smirnoff  * For platforms that do not have SYSCTL support, we wrap the
403b3a8eb9SGleb Smirnoff  * SYSCTL_* into a function (one per file) to collect the values
413b3a8eb9SGleb Smirnoff  * into an array at module initialization. The wrapping macros,
423b3a8eb9SGleb Smirnoff  * SYSBEGIN() and SYSEND, are empty in the default case.
433b3a8eb9SGleb Smirnoff  */
443b3a8eb9SGleb Smirnoff #ifndef SYSBEGIN
453b3a8eb9SGleb Smirnoff #define SYSBEGIN(x)
463b3a8eb9SGleb Smirnoff #endif
473b3a8eb9SGleb Smirnoff #ifndef SYSEND
483b3a8eb9SGleb Smirnoff #define SYSEND
493b3a8eb9SGleb Smirnoff #endif
503b3a8eb9SGleb Smirnoff 
513b3a8eb9SGleb Smirnoff /* Return values from ipfw_chk() */
523b3a8eb9SGleb Smirnoff enum {
533b3a8eb9SGleb Smirnoff 	IP_FW_PASS = 0,
543b3a8eb9SGleb Smirnoff 	IP_FW_DENY,
553b3a8eb9SGleb Smirnoff 	IP_FW_DIVERT,
563b3a8eb9SGleb Smirnoff 	IP_FW_TEE,
573b3a8eb9SGleb Smirnoff 	IP_FW_DUMMYNET,
583b3a8eb9SGleb Smirnoff 	IP_FW_NETGRAPH,
593b3a8eb9SGleb Smirnoff 	IP_FW_NGTEE,
603b3a8eb9SGleb Smirnoff 	IP_FW_NAT,
613b3a8eb9SGleb Smirnoff 	IP_FW_REASS,
623b3a8eb9SGleb Smirnoff };
633b3a8eb9SGleb Smirnoff 
643b3a8eb9SGleb Smirnoff /*
653b3a8eb9SGleb Smirnoff  * Structure for collecting parameters to dummynet for ip6_output forwarding
663b3a8eb9SGleb Smirnoff  */
673b3a8eb9SGleb Smirnoff struct _ip6dn_args {
683b3a8eb9SGleb Smirnoff        struct ip6_pktopts *opt_or;
693b3a8eb9SGleb Smirnoff        struct route_in6 ro_or;
703b3a8eb9SGleb Smirnoff        int flags_or;
713b3a8eb9SGleb Smirnoff        struct ip6_moptions *im6o_or;
723b3a8eb9SGleb Smirnoff        struct ifnet *origifp_or;
733b3a8eb9SGleb Smirnoff        struct ifnet *ifp_or;
743b3a8eb9SGleb Smirnoff        struct sockaddr_in6 dst_or;
753b3a8eb9SGleb Smirnoff        u_long mtu_or;
763b3a8eb9SGleb Smirnoff        struct route_in6 ro_pmtu_or;
773b3a8eb9SGleb Smirnoff };
783b3a8eb9SGleb Smirnoff 
793b3a8eb9SGleb Smirnoff 
803b3a8eb9SGleb Smirnoff /*
813b3a8eb9SGleb Smirnoff  * Arguments for calling ipfw_chk() and dummynet_io(). We put them
823b3a8eb9SGleb Smirnoff  * all into a structure because this way it is easier and more
833b3a8eb9SGleb Smirnoff  * efficient to pass variables around and extend the interface.
843b3a8eb9SGleb Smirnoff  */
853b3a8eb9SGleb Smirnoff struct ip_fw_args {
863b3a8eb9SGleb Smirnoff 	struct mbuf	*m;		/* the mbuf chain		*/
873b3a8eb9SGleb Smirnoff 	struct ifnet	*oif;		/* output interface		*/
883b3a8eb9SGleb Smirnoff 	struct sockaddr_in *next_hop;	/* forward address		*/
893b3a8eb9SGleb Smirnoff 	struct sockaddr_in6 *next_hop6; /* ipv6 forward address		*/
903b3a8eb9SGleb Smirnoff 
913b3a8eb9SGleb Smirnoff 	/*
923b3a8eb9SGleb Smirnoff 	 * On return, it points to the matching rule.
933b3a8eb9SGleb Smirnoff 	 * On entry, rule.slot > 0 means the info is valid and
943b3a8eb9SGleb Smirnoff 	 * contains the starting rule for an ipfw search.
953b3a8eb9SGleb Smirnoff 	 * If chain_id == chain->id && slot >0 then jump to that slot.
963b3a8eb9SGleb Smirnoff 	 * Otherwise, we locate the first rule >= rulenum:rule_id
973b3a8eb9SGleb Smirnoff 	 */
983b3a8eb9SGleb Smirnoff 	struct ipfw_rule_ref rule;	/* match/restart info		*/
993b3a8eb9SGleb Smirnoff 
1003b3a8eb9SGleb Smirnoff 	struct ether_header *eh;	/* for bridged packets		*/
1013b3a8eb9SGleb Smirnoff 
1023b3a8eb9SGleb Smirnoff 	struct ipfw_flow_id f_id;	/* grabbed from IP header	*/
1033b3a8eb9SGleb Smirnoff 	//uint32_t	cookie;		/* a cookie depending on rule action */
1043b3a8eb9SGleb Smirnoff 	struct inpcb	*inp;
1053b3a8eb9SGleb Smirnoff 
1063b3a8eb9SGleb Smirnoff 	struct _ip6dn_args	dummypar; /* dummynet->ip6_output */
1073b3a8eb9SGleb Smirnoff 	struct sockaddr_in hopstore;	/* store here if cannot use a pointer */
1083b3a8eb9SGleb Smirnoff };
1093b3a8eb9SGleb Smirnoff 
1103b3a8eb9SGleb Smirnoff MALLOC_DECLARE(M_IPFW);
1113b3a8eb9SGleb Smirnoff 
1123b3a8eb9SGleb Smirnoff /*
1133b3a8eb9SGleb Smirnoff  * Hooks sometime need to know the direction of the packet
1143b3a8eb9SGleb Smirnoff  * (divert, dummynet, netgraph, ...)
1153b3a8eb9SGleb Smirnoff  * We use a generic definition here, with bit0-1 indicating the
1163b3a8eb9SGleb Smirnoff  * direction, bit 2 indicating layer2 or 3, bit 3-4 indicating the
1173b3a8eb9SGleb Smirnoff  * specific protocol
1183b3a8eb9SGleb Smirnoff  * indicating the protocol (if necessary)
1193b3a8eb9SGleb Smirnoff  */
1203b3a8eb9SGleb Smirnoff enum {
1213b3a8eb9SGleb Smirnoff 	DIR_MASK =	0x3,
1223b3a8eb9SGleb Smirnoff 	DIR_OUT =	0,
1233b3a8eb9SGleb Smirnoff 	DIR_IN =	1,
1243b3a8eb9SGleb Smirnoff 	DIR_FWD =	2,
1253b3a8eb9SGleb Smirnoff 	DIR_DROP =	3,
1263b3a8eb9SGleb Smirnoff 	PROTO_LAYER2 =	0x4, /* set for layer 2 */
1273b3a8eb9SGleb Smirnoff 	/* PROTO_DEFAULT = 0, */
1283b3a8eb9SGleb Smirnoff 	PROTO_IPV4 =	0x08,
1293b3a8eb9SGleb Smirnoff 	PROTO_IPV6 =	0x10,
1303b3a8eb9SGleb Smirnoff 	PROTO_IFB =	0x0c, /* layer2 + ifbridge */
1313b3a8eb9SGleb Smirnoff    /*	PROTO_OLDBDG =	0x14, unused, old bridge */
1323b3a8eb9SGleb Smirnoff };
1333b3a8eb9SGleb Smirnoff 
1343b3a8eb9SGleb Smirnoff /* wrapper for freeing a packet, in case we need to do more work */
1353b3a8eb9SGleb Smirnoff #ifndef FREE_PKT
1363b3a8eb9SGleb Smirnoff #if defined(__linux__) || defined(_WIN32)
1373b3a8eb9SGleb Smirnoff #define FREE_PKT(m)	netisr_dispatch(-1, m)
1383b3a8eb9SGleb Smirnoff #else
1393b3a8eb9SGleb Smirnoff #define FREE_PKT(m)	m_freem(m)
1403b3a8eb9SGleb Smirnoff #endif
1413b3a8eb9SGleb Smirnoff #endif /* !FREE_PKT */
1423b3a8eb9SGleb Smirnoff 
1433b3a8eb9SGleb Smirnoff /*
1443b3a8eb9SGleb Smirnoff  * Function definitions.
1453b3a8eb9SGleb Smirnoff  */
1463b3a8eb9SGleb Smirnoff 
1473b3a8eb9SGleb Smirnoff /* attach (arg = 1) or detach (arg = 0) hooks */
1483b3a8eb9SGleb Smirnoff int ipfw_attach_hooks(int);
1493b3a8eb9SGleb Smirnoff #ifdef NOTYET
1503b3a8eb9SGleb Smirnoff void ipfw_nat_destroy(void);
1513b3a8eb9SGleb Smirnoff #endif
1523b3a8eb9SGleb Smirnoff 
1533b3a8eb9SGleb Smirnoff /* In ip_fw_log.c */
1543b3a8eb9SGleb Smirnoff struct ip;
1553b3a8eb9SGleb Smirnoff void ipfw_log_bpf(int);
1563b3a8eb9SGleb Smirnoff void ipfw_log(struct ip_fw *f, u_int hlen, struct ip_fw_args *args,
1573b3a8eb9SGleb Smirnoff 	struct mbuf *m, struct ifnet *oif, u_short offset, uint32_t tablearg,
1583b3a8eb9SGleb Smirnoff 	struct ip *ip);
1593b3a8eb9SGleb Smirnoff VNET_DECLARE(u_int64_t, norule_counter);
1603b3a8eb9SGleb Smirnoff #define	V_norule_counter	VNET(norule_counter)
1613b3a8eb9SGleb Smirnoff VNET_DECLARE(int, verbose_limit);
1623b3a8eb9SGleb Smirnoff #define	V_verbose_limit		VNET(verbose_limit)
1633b3a8eb9SGleb Smirnoff 
1643b3a8eb9SGleb Smirnoff /* In ip_fw_dynamic.c */
1653b3a8eb9SGleb Smirnoff 
1663b3a8eb9SGleb Smirnoff enum { /* result for matching dynamic rules */
1673b3a8eb9SGleb Smirnoff 	MATCH_REVERSE = 0,
1683b3a8eb9SGleb Smirnoff 	MATCH_FORWARD,
1693b3a8eb9SGleb Smirnoff 	MATCH_NONE,
1703b3a8eb9SGleb Smirnoff 	MATCH_UNKNOWN,
1713b3a8eb9SGleb Smirnoff };
1723b3a8eb9SGleb Smirnoff 
1733b3a8eb9SGleb Smirnoff /*
1743b3a8eb9SGleb Smirnoff  * The lock for dynamic rules is only used once outside the file,
1753b3a8eb9SGleb Smirnoff  * and only to release the result of lookup_dyn_rule().
1763b3a8eb9SGleb Smirnoff  * Eventually we may implement it with a callback on the function.
1773b3a8eb9SGleb Smirnoff  */
1782e089d5cSAlexander V. Chernikov struct ip_fw_chain;
179563b5ab1SAlexander V. Chernikov struct sockopt_data;
180a73d728dSAlexander V. Chernikov int ipfw_is_dyn_rule(struct ip_fw *rule);
181a73d728dSAlexander V. Chernikov void ipfw_expire_dyn_rules(struct ip_fw_chain *, ipfw_range_tlv *);
1822e089d5cSAlexander V. Chernikov void ipfw_dyn_unlock(ipfw_dyn_rule *q);
1833b3a8eb9SGleb Smirnoff 
1843b3a8eb9SGleb Smirnoff struct tcphdr;
1853b3a8eb9SGleb Smirnoff struct mbuf *ipfw_send_pkt(struct mbuf *, struct ipfw_flow_id *,
1863b3a8eb9SGleb Smirnoff     u_int32_t, u_int32_t, int);
1873b3a8eb9SGleb Smirnoff int ipfw_install_state(struct ip_fw *rule, ipfw_insn_limit *cmd,
1883b3a8eb9SGleb Smirnoff     struct ip_fw_args *args, uint32_t tablearg);
1893b3a8eb9SGleb Smirnoff ipfw_dyn_rule *ipfw_lookup_dyn_rule(struct ipfw_flow_id *pkt,
1903b3a8eb9SGleb Smirnoff 	int *match_direction, struct tcphdr *tcp);
1913b3a8eb9SGleb Smirnoff void ipfw_remove_dyn_children(struct ip_fw *rule);
1922e089d5cSAlexander V. Chernikov void ipfw_get_dynamic(struct ip_fw_chain *chain, char **bp, const char *ep);
193563b5ab1SAlexander V. Chernikov int ipfw_dump_states(struct ip_fw_chain *chain, struct sockopt_data *sd);
1943b3a8eb9SGleb Smirnoff 
1952e089d5cSAlexander V. Chernikov void ipfw_dyn_init(struct ip_fw_chain *);	/* per-vnet initialization */
1963b3a8eb9SGleb Smirnoff void ipfw_dyn_uninit(int);	/* per-vnet deinitialization */
1973b3a8eb9SGleb Smirnoff int ipfw_dyn_len(void);
1986447bae6SAlexander V. Chernikov int ipfw_dyn_get_count(void);
1993b3a8eb9SGleb Smirnoff 
2003b3a8eb9SGleb Smirnoff /* common variables */
2013b3a8eb9SGleb Smirnoff VNET_DECLARE(int, fw_one_pass);
2023b3a8eb9SGleb Smirnoff #define	V_fw_one_pass		VNET(fw_one_pass)
2033b3a8eb9SGleb Smirnoff 
2043b3a8eb9SGleb Smirnoff VNET_DECLARE(int, fw_verbose);
2053b3a8eb9SGleb Smirnoff #define	V_fw_verbose		VNET(fw_verbose)
2063b3a8eb9SGleb Smirnoff 
2073b3a8eb9SGleb Smirnoff VNET_DECLARE(struct ip_fw_chain, layer3_chain);
2083b3a8eb9SGleb Smirnoff #define	V_layer3_chain		VNET(layer3_chain)
2093b3a8eb9SGleb Smirnoff 
21098eff10eSAlexander V. Chernikov VNET_DECLARE(int, ipfw_vnet_ready);
21198eff10eSAlexander V. Chernikov #define	V_ipfw_vnet_ready	VNET(ipfw_vnet_ready)
21298eff10eSAlexander V. Chernikov 
2133b3a8eb9SGleb Smirnoff VNET_DECLARE(u_int32_t, set_disable);
2143b3a8eb9SGleb Smirnoff #define	V_set_disable		VNET(set_disable)
2153b3a8eb9SGleb Smirnoff 
2163b3a8eb9SGleb Smirnoff VNET_DECLARE(int, autoinc_step);
2173b3a8eb9SGleb Smirnoff #define V_autoinc_step		VNET(autoinc_step)
2183b3a8eb9SGleb Smirnoff 
2193b3a8eb9SGleb Smirnoff VNET_DECLARE(unsigned int, fw_tables_max);
2203b3a8eb9SGleb Smirnoff #define V_fw_tables_max		VNET(fw_tables_max)
2213b3a8eb9SGleb Smirnoff 
222b074b7bbSAlexander V. Chernikov VNET_DECLARE(unsigned int, fw_tables_sets);
223b074b7bbSAlexander V. Chernikov #define V_fw_tables_sets	VNET(fw_tables_sets)
224b074b7bbSAlexander V. Chernikov 
225b074b7bbSAlexander V. Chernikov struct tables_config;
226b074b7bbSAlexander V. Chernikov 
2277e767c79SAlexander V. Chernikov #ifdef _KERNEL
2287e767c79SAlexander V. Chernikov typedef struct ip_fw_cntr {
2297e767c79SAlexander V. Chernikov 	uint64_t	pcnt;	   /* Packet counter		*/
2307e767c79SAlexander V. Chernikov 	uint64_t	bcnt;	   /* Byte counter		 */
2317e767c79SAlexander V. Chernikov 	uint64_t	timestamp;      /* tv_sec of last match	 */
2327e767c79SAlexander V. Chernikov } ip_fw_cntr;
2337e767c79SAlexander V. Chernikov 
2347e767c79SAlexander V. Chernikov /*
2357e767c79SAlexander V. Chernikov  * Here we have the structure representing an ipfw rule.
2367e767c79SAlexander V. Chernikov  *
2377e767c79SAlexander V. Chernikov  * It starts with a general area
2387e767c79SAlexander V. Chernikov  * followed by an array of one or more instructions, which the code
2397e767c79SAlexander V. Chernikov  * accesses as an array of 32-bit values.
2407e767c79SAlexander V. Chernikov  *
2417e767c79SAlexander V. Chernikov  * Given a rule pointer  r:
2427e767c79SAlexander V. Chernikov  *
2437e767c79SAlexander V. Chernikov  *  r->cmd		is the start of the first instruction.
2447e767c79SAlexander V. Chernikov  *  ACTION_PTR(r)	is the start of the first action (things to do
2457e767c79SAlexander V. Chernikov  *			once a rule matched).
2467e767c79SAlexander V. Chernikov  */
2477e767c79SAlexander V. Chernikov 
2487e767c79SAlexander V. Chernikov struct ip_fw {
2497e767c79SAlexander V. Chernikov 	uint16_t	act_ofs;	/* offset of action in 32-bit units */
2507e767c79SAlexander V. Chernikov 	uint16_t	cmd_len;	/* # of 32-bit words in cmd	*/
2517e767c79SAlexander V. Chernikov 	uint16_t	rulenum;	/* rule number			*/
2527e767c79SAlexander V. Chernikov 	uint8_t		set;		/* rule set (0..31)		*/
2537e767c79SAlexander V. Chernikov 	uint8_t		flags;		/* currently unused		*/
2547e767c79SAlexander V. Chernikov 	counter_u64_t	cntr;		/* Pointer to rule counters	*/
2557e767c79SAlexander V. Chernikov 	uint32_t	timestamp;	/* tv_sec of last match		*/
2567e767c79SAlexander V. Chernikov 	uint32_t	id;		/* rule id			*/
257030b184fSAlexander V. Chernikov 	uint32_t	cached_id;	/* used by jump_fast		*/
258030b184fSAlexander V. Chernikov 	uint32_t	cached_pos;	/* used by jump_fast		*/
2597e767c79SAlexander V. Chernikov 
2607e767c79SAlexander V. Chernikov 	ipfw_insn	cmd[1];		/* storage for commands		*/
2617e767c79SAlexander V. Chernikov };
2627e767c79SAlexander V. Chernikov 
2637e767c79SAlexander V. Chernikov #endif
2647e767c79SAlexander V. Chernikov 
2653b3a8eb9SGleb Smirnoff struct ip_fw_chain {
2663b3a8eb9SGleb Smirnoff 	struct ip_fw	**map;		/* array of rule ptrs to ease lookup */
2675fa3fdd3SAlexander V. Chernikov 	uint32_t	id;		/* ruleset id */
2685fa3fdd3SAlexander V. Chernikov 	int		n_rules;	/* number of static rules */
2693b3a8eb9SGleb Smirnoff 	LIST_HEAD(nat_list, cfg_nat) nat;       /* list of nat entries */
2709f7d47b0SAlexander V. Chernikov 	void		*tablestate;	/* runtime table info */
271d5eb80cbSAlexander V. Chernikov 	int		*idxmap;	/* skipto array of rules */
2723b3a8eb9SGleb Smirnoff #if defined( __linux__ ) || defined( _WIN32 )
2733b3a8eb9SGleb Smirnoff 	spinlock_t rwmtx;
2743b3a8eb9SGleb Smirnoff #else
2753b3a8eb9SGleb Smirnoff 	struct rwlock	rwmtx;
2765fa3fdd3SAlexander V. Chernikov #endif
2777e767c79SAlexander V. Chernikov 	int		static_len;	/* total len of static rules (v0) */
2785fa3fdd3SAlexander V. Chernikov 	uint32_t	gencnt;		/* NAT generation count */
2795fa3fdd3SAlexander V. Chernikov 	struct ip_fw	*default_rule;
280b074b7bbSAlexander V. Chernikov 	struct tables_config *tblcfg;	/* tables module data */
28168394ec8SAlexander V. Chernikov 	void		*ifcfg;		/* interface module data */
282d5eb80cbSAlexander V. Chernikov 	int		*idxmap_back;	/* standby skipto array of rules */
2835fa3fdd3SAlexander V. Chernikov #if defined( __linux__ ) || defined( _WIN32 )
2845fa3fdd3SAlexander V. Chernikov 	spinlock_t uh_lock;
2855fa3fdd3SAlexander V. Chernikov #else
2863b3a8eb9SGleb Smirnoff 	struct rwlock	uh_lock;	/* lock for upper half */
2873b3a8eb9SGleb Smirnoff #endif
2883b3a8eb9SGleb Smirnoff };
2893b3a8eb9SGleb Smirnoff 
29068394ec8SAlexander V. Chernikov struct namedobj_instance;
29168394ec8SAlexander V. Chernikov 
29268394ec8SAlexander V. Chernikov struct named_object {
29368394ec8SAlexander V. Chernikov 	TAILQ_ENTRY(named_object)	nn_next;	/* namehash */
29468394ec8SAlexander V. Chernikov 	TAILQ_ENTRY(named_object)	nv_next;	/* valuehash */
29568394ec8SAlexander V. Chernikov 	char			*name;	/* object name */
29668394ec8SAlexander V. Chernikov 	uint8_t			type;	/* object type */
29768394ec8SAlexander V. Chernikov 	uint8_t			compat;	/* Object name is number */
29868394ec8SAlexander V. Chernikov 	uint16_t		kidx;	/* object kernel index */
29968394ec8SAlexander V. Chernikov 	uint16_t		uidx;	/* userland idx for compat records */
30068394ec8SAlexander V. Chernikov 	uint32_t		set;	/* set object belongs to */
30168394ec8SAlexander V. Chernikov 	uint32_t		refcnt;	/* number of references */
30268394ec8SAlexander V. Chernikov };
30368394ec8SAlexander V. Chernikov TAILQ_HEAD(namedobjects_head, named_object);
30468394ec8SAlexander V. Chernikov 
3053b3a8eb9SGleb Smirnoff struct sockopt;	/* used by tcp_var.h */
3062d99a349SAlexander V. Chernikov struct sockopt_data {
3072d99a349SAlexander V. Chernikov 	caddr_t		kbuf;		/* allocated buffer */
3082d99a349SAlexander V. Chernikov 	size_t		ksize;		/* given buffer size */
3092d99a349SAlexander V. Chernikov 	size_t		koff;		/* data already used */
3102d99a349SAlexander V. Chernikov 	size_t		kavail;		/* number of bytes available */
3112d99a349SAlexander V. Chernikov 	size_t		ktotal;		/* total bytes pushed */
3122d99a349SAlexander V. Chernikov 	struct sockopt	*sopt;		/* socket data */
313b6ee846eSAlexander V. Chernikov 	caddr_t		sopt_val;	/* sopt user buffer */
3142d99a349SAlexander V. Chernikov 	size_t		valsize;	/* original data size */
3152d99a349SAlexander V. Chernikov };
3163b3a8eb9SGleb Smirnoff 
31768394ec8SAlexander V. Chernikov struct ipfw_ifc;
31868394ec8SAlexander V. Chernikov 
31968394ec8SAlexander V. Chernikov typedef void (ipfw_ifc_cb)(struct ip_fw_chain *ch, void *cbdata,
32068394ec8SAlexander V. Chernikov     uint16_t ifindex);
32168394ec8SAlexander V. Chernikov 
32268394ec8SAlexander V. Chernikov struct ipfw_iface {
32368394ec8SAlexander V. Chernikov 	struct named_object	no;
32468394ec8SAlexander V. Chernikov 	char ifname[64];
32568394ec8SAlexander V. Chernikov 	int resolved;
32668394ec8SAlexander V. Chernikov 	uint16_t ifindex;
32768394ec8SAlexander V. Chernikov 	uint16_t spare;
32868394ec8SAlexander V. Chernikov 	uint64_t gencnt;
32968394ec8SAlexander V. Chernikov 	TAILQ_HEAD(, ipfw_ifc)	consumers;
33068394ec8SAlexander V. Chernikov };
33168394ec8SAlexander V. Chernikov 
33268394ec8SAlexander V. Chernikov struct ipfw_ifc {
33368394ec8SAlexander V. Chernikov 	TAILQ_ENTRY(ipfw_ifc)	next;
33468394ec8SAlexander V. Chernikov 	struct ipfw_iface	*iface;
33568394ec8SAlexander V. Chernikov 	ipfw_ifc_cb		*cb;
33668394ec8SAlexander V. Chernikov 	void			*cbdata;
33768394ec8SAlexander V. Chernikov 	int			linked;
33868394ec8SAlexander V. Chernikov 	int			spare;
33968394ec8SAlexander V. Chernikov };
34068394ec8SAlexander V. Chernikov 
341c187c1fbSAlexander V. Chernikov /* Macro for working with various counters */
3427e767c79SAlexander V. Chernikov #ifdef USERSPACE
343c187c1fbSAlexander V. Chernikov #define	IPFW_INC_RULE_COUNTER(_cntr, _bytes)	do {	\
344c187c1fbSAlexander V. Chernikov 	(_cntr)->pcnt++;				\
345c187c1fbSAlexander V. Chernikov 	(_cntr)->bcnt += _bytes;			\
346c187c1fbSAlexander V. Chernikov 	(_cntr)->timestamp = time_uptime;		\
347c187c1fbSAlexander V. Chernikov 	} while (0)
348c187c1fbSAlexander V. Chernikov 
349c187c1fbSAlexander V. Chernikov #define	IPFW_INC_DYN_COUNTER(_cntr, _bytes)	do {		\
350c187c1fbSAlexander V. Chernikov 	(_cntr)->pcnt++;				\
351c187c1fbSAlexander V. Chernikov 	(_cntr)->bcnt += _bytes;			\
352c187c1fbSAlexander V. Chernikov 	} while (0)
353c187c1fbSAlexander V. Chernikov 
354c187c1fbSAlexander V. Chernikov #define	IPFW_ZERO_RULE_COUNTER(_cntr) do {		\
355c187c1fbSAlexander V. Chernikov 	(_cntr)->pcnt = 0;				\
356c187c1fbSAlexander V. Chernikov 	(_cntr)->bcnt = 0;				\
357c187c1fbSAlexander V. Chernikov 	(_cntr)->timestamp = 0;				\
358c187c1fbSAlexander V. Chernikov 	} while (0)
359c187c1fbSAlexander V. Chernikov 
360c187c1fbSAlexander V. Chernikov #define	IPFW_ZERO_DYN_COUNTER(_cntr) do {		\
361c187c1fbSAlexander V. Chernikov 	(_cntr)->pcnt = 0;				\
362c187c1fbSAlexander V. Chernikov 	(_cntr)->bcnt = 0;				\
363c187c1fbSAlexander V. Chernikov 	} while (0)
3647e767c79SAlexander V. Chernikov #else
3657e767c79SAlexander V. Chernikov #define	IPFW_INC_RULE_COUNTER(_cntr, _bytes)	do {	\
3667e767c79SAlexander V. Chernikov 	counter_u64_add((_cntr)->cntr, 1);		\
3677e767c79SAlexander V. Chernikov 	counter_u64_add((_cntr)->cntr + 1, _bytes);	\
3687e767c79SAlexander V. Chernikov 	if ((_cntr)->timestamp != time_uptime)		\
3697e767c79SAlexander V. Chernikov 		(_cntr)->timestamp = time_uptime;	\
3707e767c79SAlexander V. Chernikov 	} while (0)
3717e767c79SAlexander V. Chernikov 
3727e767c79SAlexander V. Chernikov #define	IPFW_INC_DYN_COUNTER(_cntr, _bytes)	do {		\
3737e767c79SAlexander V. Chernikov 	(_cntr)->pcnt++;				\
3747e767c79SAlexander V. Chernikov 	(_cntr)->bcnt += _bytes;			\
3757e767c79SAlexander V. Chernikov 	} while (0)
3767e767c79SAlexander V. Chernikov 
3777e767c79SAlexander V. Chernikov #define	IPFW_ZERO_RULE_COUNTER(_cntr) do {		\
3787e767c79SAlexander V. Chernikov 	counter_u64_zero((_cntr)->cntr);		\
3797e767c79SAlexander V. Chernikov 	counter_u64_zero((_cntr)->cntr + 1);		\
3807e767c79SAlexander V. Chernikov 	(_cntr)->timestamp = 0;				\
3817e767c79SAlexander V. Chernikov 	} while (0)
3827e767c79SAlexander V. Chernikov 
3837e767c79SAlexander V. Chernikov #define	IPFW_ZERO_DYN_COUNTER(_cntr) do {		\
3847e767c79SAlexander V. Chernikov 	(_cntr)->pcnt = 0;				\
3857e767c79SAlexander V. Chernikov 	(_cntr)->bcnt = 0;				\
3867e767c79SAlexander V. Chernikov 	} while (0)
3877e767c79SAlexander V. Chernikov #endif
3887e767c79SAlexander V. Chernikov 
389f37de965SAlexander V. Chernikov 
3901940fa77SAlexander V. Chernikov #define	IP_FW_ARG_TABLEARG(a)	(((a) == IP_FW_TARG) ? tablearg : (a))
3913b3a8eb9SGleb Smirnoff /*
3923b3a8eb9SGleb Smirnoff  * The lock is heavily used by ip_fw2.c (the main file) and ip_fw_nat.c
3933b3a8eb9SGleb Smirnoff  * so the variable and the macros must be here.
3943b3a8eb9SGleb Smirnoff  */
3953b3a8eb9SGleb Smirnoff 
3963b3a8eb9SGleb Smirnoff #define	IPFW_LOCK_INIT(_chain) do {			\
3973b3a8eb9SGleb Smirnoff 	rw_init(&(_chain)->rwmtx, "IPFW static rules");	\
3983b3a8eb9SGleb Smirnoff 	rw_init(&(_chain)->uh_lock, "IPFW UH lock");	\
3993b3a8eb9SGleb Smirnoff 	} while (0)
4003b3a8eb9SGleb Smirnoff 
4013b3a8eb9SGleb Smirnoff #define	IPFW_LOCK_DESTROY(_chain) do {			\
4023b3a8eb9SGleb Smirnoff 	rw_destroy(&(_chain)->rwmtx);			\
4033b3a8eb9SGleb Smirnoff 	rw_destroy(&(_chain)->uh_lock);			\
4043b3a8eb9SGleb Smirnoff 	} while (0)
4053b3a8eb9SGleb Smirnoff 
4065d0cd926SAlexander V. Chernikov #define	IPFW_RLOCK_ASSERT(_chain)	rw_assert(&(_chain)->rwmtx, RA_RLOCKED)
4073b3a8eb9SGleb Smirnoff #define	IPFW_WLOCK_ASSERT(_chain)	rw_assert(&(_chain)->rwmtx, RA_WLOCKED)
4083b3a8eb9SGleb Smirnoff 
4093b3a8eb9SGleb Smirnoff #define	IPFW_RLOCK(p)			rw_rlock(&(p)->rwmtx)
4103b3a8eb9SGleb Smirnoff #define	IPFW_RUNLOCK(p)			rw_runlock(&(p)->rwmtx)
4113b3a8eb9SGleb Smirnoff #define	IPFW_WLOCK(p)			rw_wlock(&(p)->rwmtx)
4123b3a8eb9SGleb Smirnoff #define	IPFW_WUNLOCK(p)			rw_wunlock(&(p)->rwmtx)
41393bb4f9eSAndrey V. Elsukov #define	IPFW_PF_RLOCK(p)		IPFW_RLOCK(p)
41493bb4f9eSAndrey V. Elsukov #define	IPFW_PF_RUNLOCK(p)		IPFW_RUNLOCK(p)
4153b3a8eb9SGleb Smirnoff 
4162e089d5cSAlexander V. Chernikov #define	IPFW_UH_RLOCK_ASSERT(_chain)	rw_assert(&(_chain)->uh_lock, RA_RLOCKED)
4172e089d5cSAlexander V. Chernikov #define	IPFW_UH_WLOCK_ASSERT(_chain)	rw_assert(&(_chain)->uh_lock, RA_WLOCKED)
4182e089d5cSAlexander V. Chernikov 
4193b3a8eb9SGleb Smirnoff #define IPFW_UH_RLOCK(p) rw_rlock(&(p)->uh_lock)
4203b3a8eb9SGleb Smirnoff #define IPFW_UH_RUNLOCK(p) rw_runlock(&(p)->uh_lock)
4213b3a8eb9SGleb Smirnoff #define IPFW_UH_WLOCK(p) rw_wlock(&(p)->uh_lock)
4223b3a8eb9SGleb Smirnoff #define IPFW_UH_WUNLOCK(p) rw_wunlock(&(p)->uh_lock)
4233b3a8eb9SGleb Smirnoff 
424b074b7bbSAlexander V. Chernikov struct obj_idx {
425b074b7bbSAlexander V. Chernikov 	uint16_t	uidx;	/* internal index supplied by userland */
426b074b7bbSAlexander V. Chernikov 	uint16_t	kidx;	/* kernel object index */
427b074b7bbSAlexander V. Chernikov 	uint16_t	off;	/* tlv offset from rule end in 4-byte words */
4280468c5baSAlexander V. Chernikov 	uint8_t		spare;
429b074b7bbSAlexander V. Chernikov 	uint8_t		type;	/* object type within its category */
430b074b7bbSAlexander V. Chernikov };
431b074b7bbSAlexander V. Chernikov 
432b074b7bbSAlexander V. Chernikov struct rule_check_info {
4333a845e10SAlexander V. Chernikov 	uint16_t	flags;		/* rule-specific check flags */
434b074b7bbSAlexander V. Chernikov 	uint16_t	table_opcodes;	/* count of opcodes referencing table */
4357e767c79SAlexander V. Chernikov 	uint16_t	urule_numoff;	/* offset of rulenum in bytes */
4367e767c79SAlexander V. Chernikov 	uint8_t		version;	/* rule version */
4373a845e10SAlexander V. Chernikov 	uint8_t		spare;
4386c2997ffSAlexander V. Chernikov 	ipfw_obj_ctlv	*ctlv;		/* name TLV containter */
439b074b7bbSAlexander V. Chernikov 	struct ip_fw	*krule;		/* resulting rule pointer */
4407e767c79SAlexander V. Chernikov 	caddr_t		urule;		/* original rule pointer */
441b074b7bbSAlexander V. Chernikov 	struct obj_idx	obuf[8];	/* table references storage */
442b074b7bbSAlexander V. Chernikov };
443b074b7bbSAlexander V. Chernikov 
4447e767c79SAlexander V. Chernikov /* Legacy interface support */
4457e767c79SAlexander V. Chernikov /*
4467e767c79SAlexander V. Chernikov  * FreeBSD 8 export rule format
4477e767c79SAlexander V. Chernikov  */
4487e767c79SAlexander V. Chernikov struct ip_fw_rule0 {
4497e767c79SAlexander V. Chernikov 	struct ip_fw	*x_next;	/* linked list of rules		*/
4507e767c79SAlexander V. Chernikov 	struct ip_fw	*next_rule;	/* ptr to next [skipto] rule	*/
4517e767c79SAlexander V. Chernikov 	/* 'next_rule' is used to pass up 'set_disable' status		*/
4527e767c79SAlexander V. Chernikov 
4537e767c79SAlexander V. Chernikov 	uint16_t	act_ofs;	/* offset of action in 32-bit units */
4547e767c79SAlexander V. Chernikov 	uint16_t	cmd_len;	/* # of 32-bit words in cmd	*/
4557e767c79SAlexander V. Chernikov 	uint16_t	rulenum;	/* rule number			*/
4567e767c79SAlexander V. Chernikov 	uint8_t		set;		/* rule set (0..31)		*/
4577e767c79SAlexander V. Chernikov 	uint8_t		_pad;		/* padding			*/
4587e767c79SAlexander V. Chernikov 	uint32_t	id;		/* rule id */
4597e767c79SAlexander V. Chernikov 
4607e767c79SAlexander V. Chernikov 	/* These fields are present in all rules.			*/
4617e767c79SAlexander V. Chernikov 	uint64_t	pcnt;		/* Packet counter		*/
4627e767c79SAlexander V. Chernikov 	uint64_t	bcnt;		/* Byte counter			*/
4637e767c79SAlexander V. Chernikov 	uint32_t	timestamp;	/* tv_sec of last match		*/
4647e767c79SAlexander V. Chernikov 
4657e767c79SAlexander V. Chernikov 	ipfw_insn	cmd[1];		/* storage for commands		*/
4667e767c79SAlexander V. Chernikov };
4677e767c79SAlexander V. Chernikov 
4687e767c79SAlexander V. Chernikov struct ip_fw_bcounter0 {
4697e767c79SAlexander V. Chernikov 	uint64_t	pcnt;		/* Packet counter		*/
4707e767c79SAlexander V. Chernikov 	uint64_t	bcnt;		/* Byte counter			*/
4717e767c79SAlexander V. Chernikov 	uint32_t	timestamp;	/* tv_sec of last match		*/
4727e767c79SAlexander V. Chernikov };
4737e767c79SAlexander V. Chernikov 
4747e767c79SAlexander V. Chernikov /* Kernel rule length */
4757e767c79SAlexander V. Chernikov /*
4767e767c79SAlexander V. Chernikov  * RULE _K_ SIZE _V_ ->
4777e767c79SAlexander V. Chernikov  * get kernel size from userland rool version _V_.
4787e767c79SAlexander V. Chernikov  * RULE _U_ SIZE _V_ ->
4797e767c79SAlexander V. Chernikov  * get user size version _V_ from kernel rule
4807e767c79SAlexander V. Chernikov  * RULESIZE _V_ ->
4817e767c79SAlexander V. Chernikov  * get user size rule length
4827e767c79SAlexander V. Chernikov  */
4837e767c79SAlexander V. Chernikov /* FreeBSD8 <> current kernel format */
4847e767c79SAlexander V. Chernikov #define	RULEUSIZE0(r)	(sizeof(struct ip_fw_rule0) + (r)->cmd_len * 4 - 4)
4857e767c79SAlexander V. Chernikov #define	RULEKSIZE0(r)	roundup2((sizeof(struct ip_fw) + (r)->cmd_len*4 - 4), 8)
4867e767c79SAlexander V. Chernikov /* FreeBSD11 <> current kernel format */
4877e767c79SAlexander V. Chernikov #define	RULEUSIZE1(r)	(roundup2(sizeof(struct ip_fw_rule) + \
4887e767c79SAlexander V. Chernikov     (r)->cmd_len * 4 - 4, 8))
4897e767c79SAlexander V. Chernikov #define	RULEKSIZE1(r)	roundup2((sizeof(struct ip_fw) + (r)->cmd_len*4 - 4), 8)
4907e767c79SAlexander V. Chernikov 
4917e767c79SAlexander V. Chernikov 
49268394ec8SAlexander V. Chernikov /* In ip_fw_iface.c */
49368394ec8SAlexander V. Chernikov int ipfw_iface_init(void);
49468394ec8SAlexander V. Chernikov void ipfw_iface_destroy(void);
49568394ec8SAlexander V. Chernikov void vnet_ipfw_iface_destroy(struct ip_fw_chain *ch);
49668394ec8SAlexander V. Chernikov int ipfw_iface_ref(struct ip_fw_chain *ch, char *name,
49768394ec8SAlexander V. Chernikov     struct ipfw_ifc *ic);
49868394ec8SAlexander V. Chernikov void ipfw_iface_unref(struct ip_fw_chain *ch, struct ipfw_ifc *ic);
49968394ec8SAlexander V. Chernikov void ipfw_iface_add_notify(struct ip_fw_chain *ch, struct ipfw_ifc *ic);
50068394ec8SAlexander V. Chernikov void ipfw_iface_del_notify(struct ip_fw_chain *ch, struct ipfw_ifc *ic);
50168394ec8SAlexander V. Chernikov int ipfw_list_ifaces(struct ip_fw_chain *ch, struct sockopt_data *sd);
50268394ec8SAlexander V. Chernikov 
5033b3a8eb9SGleb Smirnoff /* In ip_fw_sockopt.c */
504d5eb80cbSAlexander V. Chernikov void ipfw_init_skipto_cache(struct ip_fw_chain *chain);
505d5eb80cbSAlexander V. Chernikov void ipfw_destroy_skipto_cache(struct ip_fw_chain *chain);
5063b3a8eb9SGleb Smirnoff int ipfw_find_rule(struct ip_fw_chain *chain, uint32_t key, uint32_t id);
507b429d43cSAlexander V. Chernikov int ipfw_ctl3(struct sockopt *sopt);
5083b3a8eb9SGleb Smirnoff int ipfw_chk(struct ip_fw_args *args);
509030b184fSAlexander V. Chernikov void ipfw_reap_add(struct ip_fw_chain *chain, struct ip_fw **head,
510030b184fSAlexander V. Chernikov     struct ip_fw *rule);
5113b3a8eb9SGleb Smirnoff void ipfw_reap_rules(struct ip_fw *head);
5127e767c79SAlexander V. Chernikov void ipfw_init_counters(void);
5137e767c79SAlexander V. Chernikov void ipfw_destroy_counters(void);
5147e767c79SAlexander V. Chernikov struct ip_fw *ipfw_alloc_rule(struct ip_fw_chain *chain, size_t rulesize);
515a73d728dSAlexander V. Chernikov int ipfw_match_range(struct ip_fw *rule, ipfw_range_tlv *rt);
5163b3a8eb9SGleb Smirnoff 
5172d99a349SAlexander V. Chernikov caddr_t ipfw_get_sopt_space(struct sockopt_data *sd, size_t needed);
5182d99a349SAlexander V. Chernikov caddr_t ipfw_get_sopt_header(struct sockopt_data *sd, size_t needed);
5192d99a349SAlexander V. Chernikov 
520b074b7bbSAlexander V. Chernikov typedef void (objhash_cb_t)(struct namedobj_instance *ni, struct named_object *,
521b074b7bbSAlexander V. Chernikov     void *arg);
522*13263632SAlexander V. Chernikov typedef uint32_t (objhash_hash_f)(struct namedobj_instance *ni, void *key,
523*13263632SAlexander V. Chernikov     uint32_t kopt);
524*13263632SAlexander V. Chernikov typedef int (objhash_cmp_f)(struct named_object *no, void *key, uint32_t kopt);
525b074b7bbSAlexander V. Chernikov struct namedobj_instance *ipfw_objhash_create(uint32_t items);
526b074b7bbSAlexander V. Chernikov void ipfw_objhash_destroy(struct namedobj_instance *);
527b074b7bbSAlexander V. Chernikov void ipfw_objhash_bitmap_alloc(uint32_t items, void **idx, int *pblocks);
5289f7d47b0SAlexander V. Chernikov void ipfw_objhash_bitmap_merge(struct namedobj_instance *ni,
5299f7d47b0SAlexander V. Chernikov     void **idx, int *blocks);
5309f7d47b0SAlexander V. Chernikov void ipfw_objhash_bitmap_swap(struct namedobj_instance *ni,
531b074b7bbSAlexander V. Chernikov     void **idx, int *blocks);
532b074b7bbSAlexander V. Chernikov void ipfw_objhash_bitmap_free(void *idx, int blocks);
533*13263632SAlexander V. Chernikov void ipfw_objhash_set_hashf(struct namedobj_instance *ni, objhash_hash_f *f);
534b074b7bbSAlexander V. Chernikov struct named_object *ipfw_objhash_lookup_name(struct namedobj_instance *ni,
535b074b7bbSAlexander V. Chernikov     uint32_t set, char *name);
536ac35ff17SAlexander V. Chernikov struct named_object *ipfw_objhash_lookup_kidx(struct namedobj_instance *ni,
537ac35ff17SAlexander V. Chernikov     uint16_t idx);
5389490a627SAlexander V. Chernikov int ipfw_objhash_same_name(struct namedobj_instance *ni, struct named_object *a,
5399490a627SAlexander V. Chernikov     struct named_object *b);
540b074b7bbSAlexander V. Chernikov void ipfw_objhash_add(struct namedobj_instance *ni, struct named_object *no);
541b074b7bbSAlexander V. Chernikov void ipfw_objhash_del(struct namedobj_instance *ni, struct named_object *no);
5429f7d47b0SAlexander V. Chernikov uint32_t ipfw_objhash_count(struct namedobj_instance *ni);
543b074b7bbSAlexander V. Chernikov void ipfw_objhash_foreach(struct namedobj_instance *ni, objhash_cb_t *f,
544b074b7bbSAlexander V. Chernikov     void *arg);
545ac35ff17SAlexander V. Chernikov int ipfw_objhash_free_idx(struct namedobj_instance *ni, uint16_t idx);
546ac35ff17SAlexander V. Chernikov int ipfw_objhash_alloc_idx(void *n, uint16_t *pidx);
547*13263632SAlexander V. Chernikov void ipfw_objhash_set_funcs(struct namedobj_instance *ni,
548*13263632SAlexander V. Chernikov     objhash_hash_f *hash_f, objhash_cmp_f *cmp_f);
549b074b7bbSAlexander V. Chernikov 
5503b3a8eb9SGleb Smirnoff /* In ip_fw_table.c */
5519f7d47b0SAlexander V. Chernikov struct table_info;
5529f7d47b0SAlexander V. Chernikov 
5539f7d47b0SAlexander V. Chernikov typedef int (table_lookup_t)(struct table_info *ti, void *key, uint32_t keylen,
5549f7d47b0SAlexander V. Chernikov     uint32_t *val);
5559f7d47b0SAlexander V. Chernikov 
5563b3a8eb9SGleb Smirnoff int ipfw_lookup_table(struct ip_fw_chain *ch, uint16_t tbl, in_addr_t addr,
5573b3a8eb9SGleb Smirnoff     uint32_t *val);
5589f7d47b0SAlexander V. Chernikov int ipfw_lookup_table_extended(struct ip_fw_chain *ch, uint16_t tbl, uint16_t plen,
5599f7d47b0SAlexander V. Chernikov     void *paddr, uint32_t *val);
5603b3a8eb9SGleb Smirnoff int ipfw_init_tables(struct ip_fw_chain *ch);
5613b3a8eb9SGleb Smirnoff int ipfw_resize_tables(struct ip_fw_chain *ch, unsigned int ntables);
562a73d728dSAlexander V. Chernikov int ipfw_switch_tables_namespace(struct ip_fw_chain *ch, unsigned int nsets);
563ea761a5dSAlexander V. Chernikov void ipfw_destroy_tables(struct ip_fw_chain *ch);
5649f7d47b0SAlexander V. Chernikov 
5653b3a8eb9SGleb Smirnoff /* In ip_fw_nat.c -- XXX to be moved to ip_var.h */
5663b3a8eb9SGleb Smirnoff 
5673b3a8eb9SGleb Smirnoff extern struct cfg_nat *(*lookup_nat_ptr)(struct nat_list *, int);
5683b3a8eb9SGleb Smirnoff 
5693b3a8eb9SGleb Smirnoff typedef int ipfw_nat_t(struct ip_fw_args *, struct cfg_nat *, struct mbuf *);
5703b3a8eb9SGleb Smirnoff typedef int ipfw_nat_cfg_t(struct sockopt *);
5713b3a8eb9SGleb Smirnoff 
5728856400bSMikolaj Golub VNET_DECLARE(int, ipfw_nat_ready);
5738856400bSMikolaj Golub #define	V_ipfw_nat_ready	VNET(ipfw_nat_ready)
5748856400bSMikolaj Golub #define	IPFW_NAT_LOADED	(V_ipfw_nat_ready)
5753b3a8eb9SGleb Smirnoff 
5768856400bSMikolaj Golub extern ipfw_nat_t *ipfw_nat_ptr;
5773b3a8eb9SGleb Smirnoff extern ipfw_nat_cfg_t *ipfw_nat_cfg_ptr;
5783b3a8eb9SGleb Smirnoff extern ipfw_nat_cfg_t *ipfw_nat_del_ptr;
5793b3a8eb9SGleb Smirnoff extern ipfw_nat_cfg_t *ipfw_nat_get_cfg_ptr;
5803b3a8eb9SGleb Smirnoff extern ipfw_nat_cfg_t *ipfw_nat_get_log_ptr;
5813b3a8eb9SGleb Smirnoff 
5823b3a8eb9SGleb Smirnoff #endif /* _KERNEL */
5833b3a8eb9SGleb Smirnoff #endif /* _IPFW2_PRIVATE_H */
584