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; 1792e089d5cSAlexander V. Chernikov void ipfw_expire_dyn_rules(struct ip_fw_chain *, struct ip_fw *, int); 1802e089d5cSAlexander V. Chernikov void ipfw_dyn_unlock(ipfw_dyn_rule *q); 1813b3a8eb9SGleb Smirnoff 1823b3a8eb9SGleb Smirnoff struct tcphdr; 1833b3a8eb9SGleb Smirnoff struct mbuf *ipfw_send_pkt(struct mbuf *, struct ipfw_flow_id *, 1843b3a8eb9SGleb Smirnoff u_int32_t, u_int32_t, int); 1853b3a8eb9SGleb Smirnoff int ipfw_install_state(struct ip_fw *rule, ipfw_insn_limit *cmd, 1863b3a8eb9SGleb Smirnoff struct ip_fw_args *args, uint32_t tablearg); 1873b3a8eb9SGleb Smirnoff ipfw_dyn_rule *ipfw_lookup_dyn_rule(struct ipfw_flow_id *pkt, 1883b3a8eb9SGleb Smirnoff int *match_direction, struct tcphdr *tcp); 1893b3a8eb9SGleb Smirnoff void ipfw_remove_dyn_children(struct ip_fw *rule); 1902e089d5cSAlexander V. Chernikov void ipfw_get_dynamic(struct ip_fw_chain *chain, char **bp, const char *ep); 1913b3a8eb9SGleb Smirnoff 1922e089d5cSAlexander V. Chernikov void ipfw_dyn_init(struct ip_fw_chain *); /* per-vnet initialization */ 1933b3a8eb9SGleb Smirnoff void ipfw_dyn_uninit(int); /* per-vnet deinitialization */ 1943b3a8eb9SGleb Smirnoff int ipfw_dyn_len(void); 1953b3a8eb9SGleb Smirnoff 1963b3a8eb9SGleb Smirnoff /* common variables */ 1973b3a8eb9SGleb Smirnoff VNET_DECLARE(int, fw_one_pass); 1983b3a8eb9SGleb Smirnoff #define V_fw_one_pass VNET(fw_one_pass) 1993b3a8eb9SGleb Smirnoff 2003b3a8eb9SGleb Smirnoff VNET_DECLARE(int, fw_verbose); 2013b3a8eb9SGleb Smirnoff #define V_fw_verbose VNET(fw_verbose) 2023b3a8eb9SGleb Smirnoff 2033b3a8eb9SGleb Smirnoff VNET_DECLARE(struct ip_fw_chain, layer3_chain); 2043b3a8eb9SGleb Smirnoff #define V_layer3_chain VNET(layer3_chain) 2053b3a8eb9SGleb Smirnoff 2063b3a8eb9SGleb Smirnoff VNET_DECLARE(u_int32_t, set_disable); 2073b3a8eb9SGleb Smirnoff #define V_set_disable VNET(set_disable) 2083b3a8eb9SGleb Smirnoff 2093b3a8eb9SGleb Smirnoff VNET_DECLARE(int, autoinc_step); 2103b3a8eb9SGleb Smirnoff #define V_autoinc_step VNET(autoinc_step) 2113b3a8eb9SGleb Smirnoff 2123b3a8eb9SGleb Smirnoff VNET_DECLARE(unsigned int, fw_tables_max); 2133b3a8eb9SGleb Smirnoff #define V_fw_tables_max VNET(fw_tables_max) 2143b3a8eb9SGleb Smirnoff 2153b3a8eb9SGleb Smirnoff struct ip_fw_chain { 2163b3a8eb9SGleb Smirnoff struct ip_fw *rules; /* list of rules */ 2173b3a8eb9SGleb Smirnoff struct ip_fw *reap; /* list of rules to reap */ 2183b3a8eb9SGleb Smirnoff struct ip_fw *default_rule; 2193b3a8eb9SGleb Smirnoff int n_rules; /* number of static rules */ 2203b3a8eb9SGleb Smirnoff int static_len; /* total len of static rules */ 2213b3a8eb9SGleb Smirnoff struct ip_fw **map; /* array of rule ptrs to ease lookup */ 2223b3a8eb9SGleb Smirnoff LIST_HEAD(nat_list, cfg_nat) nat; /* list of nat entries */ 2233b3a8eb9SGleb Smirnoff struct radix_node_head **tables; /* IPv4 tables */ 2243b3a8eb9SGleb Smirnoff struct radix_node_head **xtables; /* extended tables */ 2253b3a8eb9SGleb Smirnoff uint8_t *tabletype; /* Array of table types */ 2263b3a8eb9SGleb Smirnoff #if defined( __linux__ ) || defined( _WIN32 ) 2273b3a8eb9SGleb Smirnoff spinlock_t rwmtx; 2283b3a8eb9SGleb Smirnoff spinlock_t uh_lock; 2293b3a8eb9SGleb Smirnoff #else 2303b3a8eb9SGleb Smirnoff struct rwlock rwmtx; 2313b3a8eb9SGleb Smirnoff struct rwlock uh_lock; /* lock for upper half */ 2323b3a8eb9SGleb Smirnoff #endif 2333b3a8eb9SGleb Smirnoff uint32_t id; /* ruleset id */ 2343b3a8eb9SGleb Smirnoff uint32_t gencnt; /* generation count */ 2353b3a8eb9SGleb Smirnoff }; 2363b3a8eb9SGleb Smirnoff 2373b3a8eb9SGleb Smirnoff struct sockopt; /* used by tcp_var.h */ 2383b3a8eb9SGleb Smirnoff 239*c187c1fbSAlexander V. Chernikov /* Macro for working with various counters */ 240*c187c1fbSAlexander V. Chernikov #define IPFW_INC_RULE_COUNTER(_cntr, _bytes) do { \ 241*c187c1fbSAlexander V. Chernikov (_cntr)->pcnt++; \ 242*c187c1fbSAlexander V. Chernikov (_cntr)->bcnt += _bytes; \ 243*c187c1fbSAlexander V. Chernikov (_cntr)->timestamp = time_uptime; \ 244*c187c1fbSAlexander V. Chernikov } while (0) 245*c187c1fbSAlexander V. Chernikov 246*c187c1fbSAlexander V. Chernikov #define IPFW_INC_DYN_COUNTER(_cntr, _bytes) do { \ 247*c187c1fbSAlexander V. Chernikov (_cntr)->pcnt++; \ 248*c187c1fbSAlexander V. Chernikov (_cntr)->bcnt += _bytes; \ 249*c187c1fbSAlexander V. Chernikov } while (0) 250*c187c1fbSAlexander V. Chernikov 251*c187c1fbSAlexander V. Chernikov #define IPFW_ZERO_RULE_COUNTER(_cntr) do { \ 252*c187c1fbSAlexander V. Chernikov (_cntr)->pcnt = 0; \ 253*c187c1fbSAlexander V. Chernikov (_cntr)->bcnt = 0; \ 254*c187c1fbSAlexander V. Chernikov (_cntr)->timestamp = 0; \ 255*c187c1fbSAlexander V. Chernikov } while (0) 256*c187c1fbSAlexander V. Chernikov 257*c187c1fbSAlexander V. Chernikov #define IPFW_ZERO_DYN_COUNTER(_cntr) do { \ 258*c187c1fbSAlexander V. Chernikov (_cntr)->pcnt = 0; \ 259*c187c1fbSAlexander V. Chernikov (_cntr)->bcnt = 0; \ 260*c187c1fbSAlexander V. Chernikov } while (0) 2613b3a8eb9SGleb Smirnoff /* 2623b3a8eb9SGleb Smirnoff * The lock is heavily used by ip_fw2.c (the main file) and ip_fw_nat.c 2633b3a8eb9SGleb Smirnoff * so the variable and the macros must be here. 2643b3a8eb9SGleb Smirnoff */ 2653b3a8eb9SGleb Smirnoff 2663b3a8eb9SGleb Smirnoff #define IPFW_LOCK_INIT(_chain) do { \ 2673b3a8eb9SGleb Smirnoff rw_init(&(_chain)->rwmtx, "IPFW static rules"); \ 2683b3a8eb9SGleb Smirnoff rw_init(&(_chain)->uh_lock, "IPFW UH lock"); \ 2693b3a8eb9SGleb Smirnoff } while (0) 2703b3a8eb9SGleb Smirnoff 2713b3a8eb9SGleb Smirnoff #define IPFW_LOCK_DESTROY(_chain) do { \ 2723b3a8eb9SGleb Smirnoff rw_destroy(&(_chain)->rwmtx); \ 2733b3a8eb9SGleb Smirnoff rw_destroy(&(_chain)->uh_lock); \ 2743b3a8eb9SGleb Smirnoff } while (0) 2753b3a8eb9SGleb Smirnoff 2765d0cd926SAlexander V. Chernikov #define IPFW_RLOCK_ASSERT(_chain) rw_assert(&(_chain)->rwmtx, RA_RLOCKED) 2773b3a8eb9SGleb Smirnoff #define IPFW_WLOCK_ASSERT(_chain) rw_assert(&(_chain)->rwmtx, RA_WLOCKED) 2783b3a8eb9SGleb Smirnoff 2793b3a8eb9SGleb Smirnoff #define IPFW_RLOCK(p) rw_rlock(&(p)->rwmtx) 2803b3a8eb9SGleb Smirnoff #define IPFW_RUNLOCK(p) rw_runlock(&(p)->rwmtx) 2813b3a8eb9SGleb Smirnoff #define IPFW_WLOCK(p) rw_wlock(&(p)->rwmtx) 2823b3a8eb9SGleb Smirnoff #define IPFW_WUNLOCK(p) rw_wunlock(&(p)->rwmtx) 2833b3a8eb9SGleb Smirnoff 2842e089d5cSAlexander V. Chernikov #define IPFW_UH_RLOCK_ASSERT(_chain) rw_assert(&(_chain)->uh_lock, RA_RLOCKED) 2852e089d5cSAlexander V. Chernikov #define IPFW_UH_WLOCK_ASSERT(_chain) rw_assert(&(_chain)->uh_lock, RA_WLOCKED) 2862e089d5cSAlexander V. Chernikov 2873b3a8eb9SGleb Smirnoff #define IPFW_UH_RLOCK(p) rw_rlock(&(p)->uh_lock) 2883b3a8eb9SGleb Smirnoff #define IPFW_UH_RUNLOCK(p) rw_runlock(&(p)->uh_lock) 2893b3a8eb9SGleb Smirnoff #define IPFW_UH_WLOCK(p) rw_wlock(&(p)->uh_lock) 2903b3a8eb9SGleb Smirnoff #define IPFW_UH_WUNLOCK(p) rw_wunlock(&(p)->uh_lock) 2913b3a8eb9SGleb Smirnoff 2923b3a8eb9SGleb Smirnoff /* In ip_fw_sockopt.c */ 2933b3a8eb9SGleb Smirnoff int ipfw_find_rule(struct ip_fw_chain *chain, uint32_t key, uint32_t id); 2943b3a8eb9SGleb Smirnoff int ipfw_add_rule(struct ip_fw_chain *chain, struct ip_fw *input_rule); 2953b3a8eb9SGleb Smirnoff int ipfw_ctl(struct sockopt *sopt); 2963b3a8eb9SGleb Smirnoff int ipfw_chk(struct ip_fw_args *args); 2973b3a8eb9SGleb Smirnoff void ipfw_reap_rules(struct ip_fw *head); 2983b3a8eb9SGleb Smirnoff 2993b3a8eb9SGleb Smirnoff /* In ip_fw_table.c */ 3003b3a8eb9SGleb Smirnoff struct radix_node; 3013b3a8eb9SGleb Smirnoff int ipfw_lookup_table(struct ip_fw_chain *ch, uint16_t tbl, in_addr_t addr, 3023b3a8eb9SGleb Smirnoff uint32_t *val); 3033b3a8eb9SGleb Smirnoff int ipfw_lookup_table_extended(struct ip_fw_chain *ch, uint16_t tbl, void *paddr, 3043b3a8eb9SGleb Smirnoff uint32_t *val, int type); 3053b3a8eb9SGleb Smirnoff int ipfw_init_tables(struct ip_fw_chain *ch); 3063b3a8eb9SGleb Smirnoff void ipfw_destroy_tables(struct ip_fw_chain *ch); 3073b3a8eb9SGleb Smirnoff int ipfw_flush_table(struct ip_fw_chain *ch, uint16_t tbl); 3083b3a8eb9SGleb Smirnoff int ipfw_add_table_entry(struct ip_fw_chain *ch, uint16_t tbl, void *paddr, 3093b3a8eb9SGleb Smirnoff uint8_t plen, uint8_t mlen, uint8_t type, uint32_t value); 3103b3a8eb9SGleb Smirnoff int ipfw_del_table_entry(struct ip_fw_chain *ch, uint16_t tbl, void *paddr, 3113b3a8eb9SGleb Smirnoff uint8_t plen, uint8_t mlen, uint8_t type); 3123b3a8eb9SGleb Smirnoff int ipfw_count_table(struct ip_fw_chain *ch, uint32_t tbl, uint32_t *cnt); 3133b3a8eb9SGleb Smirnoff int ipfw_dump_table_entry(struct radix_node *rn, void *arg); 3143b3a8eb9SGleb Smirnoff int ipfw_dump_table(struct ip_fw_chain *ch, ipfw_table *tbl); 3153b3a8eb9SGleb Smirnoff int ipfw_count_xtable(struct ip_fw_chain *ch, uint32_t tbl, uint32_t *cnt); 3163b3a8eb9SGleb Smirnoff int ipfw_dump_xtable(struct ip_fw_chain *ch, ipfw_xtable *tbl); 3173b3a8eb9SGleb Smirnoff int ipfw_resize_tables(struct ip_fw_chain *ch, unsigned int ntables); 3183b3a8eb9SGleb Smirnoff 3193b3a8eb9SGleb Smirnoff /* In ip_fw_nat.c -- XXX to be moved to ip_var.h */ 3203b3a8eb9SGleb Smirnoff 3213b3a8eb9SGleb Smirnoff extern struct cfg_nat *(*lookup_nat_ptr)(struct nat_list *, int); 3223b3a8eb9SGleb Smirnoff 3233b3a8eb9SGleb Smirnoff typedef int ipfw_nat_t(struct ip_fw_args *, struct cfg_nat *, struct mbuf *); 3243b3a8eb9SGleb Smirnoff typedef int ipfw_nat_cfg_t(struct sockopt *); 3253b3a8eb9SGleb Smirnoff 3263b3a8eb9SGleb Smirnoff extern ipfw_nat_t *ipfw_nat_ptr; 3273b3a8eb9SGleb Smirnoff #define IPFW_NAT_LOADED (ipfw_nat_ptr != NULL) 3283b3a8eb9SGleb Smirnoff 3293b3a8eb9SGleb Smirnoff extern ipfw_nat_cfg_t *ipfw_nat_cfg_ptr; 3303b3a8eb9SGleb Smirnoff extern ipfw_nat_cfg_t *ipfw_nat_del_ptr; 3313b3a8eb9SGleb Smirnoff extern ipfw_nat_cfg_t *ipfw_nat_get_cfg_ptr; 3323b3a8eb9SGleb Smirnoff extern ipfw_nat_cfg_t *ipfw_nat_get_log_ptr; 3333b3a8eb9SGleb Smirnoff 3343b3a8eb9SGleb Smirnoff #endif /* _KERNEL */ 3353b3a8eb9SGleb Smirnoff #endif /* _IPFW2_PRIVATE_H */ 336