1c398230bSWarner Losh /*- 251369649SPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause 351369649SPedro F. Giffuni * 4df8bae1dSRodney W. Grimes * Copyright (c) 1982, 1986, 1993 5df8bae1dSRodney W. Grimes * The Regents of the University of California. All rights reserved. 6df8bae1dSRodney W. Grimes * 7df8bae1dSRodney W. Grimes * Redistribution and use in source and binary forms, with or without 8df8bae1dSRodney W. Grimes * modification, are permitted provided that the following conditions 9df8bae1dSRodney W. Grimes * are met: 10df8bae1dSRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 11df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer. 12df8bae1dSRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 13df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 14df8bae1dSRodney W. Grimes * documentation and/or other materials provided with the distribution. 15fbbd9655SWarner Losh * 3. Neither the name of the University nor the names of its contributors 16df8bae1dSRodney W. Grimes * may be used to endorse or promote products derived from this software 17df8bae1dSRodney W. Grimes * without specific prior written permission. 18df8bae1dSRodney W. Grimes * 19df8bae1dSRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20df8bae1dSRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21df8bae1dSRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22df8bae1dSRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23df8bae1dSRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24df8bae1dSRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25df8bae1dSRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26df8bae1dSRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27df8bae1dSRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28df8bae1dSRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29df8bae1dSRodney W. Grimes * SUCH DAMAGE. 30df8bae1dSRodney W. Grimes */ 31df8bae1dSRodney W. Grimes 32707f139eSPaul Richards #ifndef _NETINET_IP_VAR_H_ 33707f139eSPaul Richards #define _NETINET_IP_VAR_H_ 34707f139eSPaul Richards 35cb6bb230SMatt Macy #include <sys/epoch.h> 36aa70361dSKristof Provost #include <sys/queue.h> 37aa70361dSKristof Provost #include <sys/types.h> 38aa70361dSKristof Provost 39aa70361dSKristof Provost #include <netinet/in.h> 4033841545SHajimu UMEMOTO 41df8bae1dSRodney W. Grimes /* 42df8bae1dSRodney W. Grimes * Overlay for ip header used by other protocols (tcp, udp). 43df8bae1dSRodney W. Grimes */ 44df8bae1dSRodney W. Grimes struct ipovly { 456effc713SDoug Rabson u_char ih_x1[9]; /* (unused) */ 46df8bae1dSRodney W. Grimes u_char ih_pr; /* protocol */ 47430d30d8SBill Fenner u_short ih_len; /* protocol length */ 48df8bae1dSRodney W. Grimes struct in_addr ih_src; /* source internet address */ 49df8bae1dSRodney W. Grimes struct in_addr ih_dst; /* destination internet address */ 50df8bae1dSRodney W. Grimes }; 51df8bae1dSRodney W. Grimes 5269dac2eaSRobert Watson #ifdef _KERNEL 53df8bae1dSRodney W. Grimes /* 54df8bae1dSRodney W. Grimes * Ip reassembly queue structure. Each fragment 55df8bae1dSRodney W. Grimes * being reassembled is attached to one of these structures. 56a30cb315SGleb Smirnoff * They are timed out after net.inet.ip.fragttl seconds, and may also be 57a30cb315SGleb Smirnoff * reclaimed if memory becomes tight. 58df8bae1dSRodney W. Grimes */ 59df8bae1dSRodney W. Grimes struct ipq { 60462b86feSPoul-Henning Kamp TAILQ_ENTRY(ipq) ipq_list; /* to other reass headers */ 61a30cb315SGleb Smirnoff time_t ipq_expire; /* time_uptime when ipq expires */ 62a30cb315SGleb Smirnoff u_char ipq_nfrags; /* # frags in this packet */ 63df8bae1dSRodney W. Grimes u_char ipq_p; /* protocol of this fragment */ 64df8bae1dSRodney W. Grimes u_short ipq_id; /* sequence id for reassembly */ 652157f3c3SJonathan T. Looney int ipq_maxoff; /* total length of packet */ 666effc713SDoug Rabson struct mbuf *ipq_frags; /* to ip headers of fragments */ 67df8bae1dSRodney W. Grimes struct in_addr ipq_src,ipq_dst; 68eca8a663SRobert Watson struct label *ipq_label; /* MAC label */ 69df8bae1dSRodney W. Grimes }; 7069dac2eaSRobert Watson #endif /* _KERNEL */ 71df8bae1dSRodney W. Grimes 72df8bae1dSRodney W. Grimes /* 73c444cddeSAndre Oppermann * Structure stored in mbuf in inpcb.ip_options 74c444cddeSAndre Oppermann * and passed to ip_output when ip options are in use. 75c444cddeSAndre Oppermann * The actual length of the options (including ipopt_dst) 76c444cddeSAndre Oppermann * is in m_len. 77c444cddeSAndre Oppermann */ 78c444cddeSAndre Oppermann #define MAX_IPOPTLEN 40 79c444cddeSAndre Oppermann 80c444cddeSAndre Oppermann struct ipoption { 81c444cddeSAndre Oppermann struct in_addr ipopt_dst; /* first-hop dst if source routed */ 82c444cddeSAndre Oppermann char ipopt_list[MAX_IPOPTLEN]; /* options proper */ 83c444cddeSAndre Oppermann }; 84c444cddeSAndre Oppermann 8559854ecfSHans Petter Selasky #if defined(_NETINET_IN_VAR_H_) && defined(_KERNEL) 86c444cddeSAndre Oppermann /* 87df8bae1dSRodney W. Grimes * Structure attached to inpcb.ip_moptions and 88df8bae1dSRodney W. Grimes * passed to ip_output when IP multicast options are in use. 8971498f30SBruce M Simpson * This structure is lazy-allocated. 90df8bae1dSRodney W. Grimes */ 91df8bae1dSRodney W. Grimes struct ip_moptions { 92df8bae1dSRodney W. Grimes struct ifnet *imo_multicast_ifp; /* ifp for outgoing multicasts */ 9333841545SHajimu UMEMOTO struct in_addr imo_multicast_addr; /* ifindex/addr on MULTICAST_IF */ 943548bfc9SBruce M Simpson u_long imo_multicast_vif; /* vif num outgoing multicasts */ 95df8bae1dSRodney W. Grimes u_char imo_multicast_ttl; /* TTL for outgoing multicasts */ 96df8bae1dSRodney W. Grimes u_char imo_multicast_loop; /* 1 => hear sends if a member */ 9759854ecfSHans Petter Selasky struct ip_mfilter_head imo_head; /* group membership list */ 98df8bae1dSRodney W. Grimes }; 9959854ecfSHans Petter Selasky #else 10059854ecfSHans Petter Selasky struct ip_moptions; 10159854ecfSHans Petter Selasky #endif 102df8bae1dSRodney W. Grimes 103df8bae1dSRodney W. Grimes struct ipstat { 1045923c293SGleb Smirnoff uint64_t ips_total; /* total packets received */ 1055923c293SGleb Smirnoff uint64_t ips_badsum; /* checksum bad */ 1065923c293SGleb Smirnoff uint64_t ips_tooshort; /* packet too short */ 1075923c293SGleb Smirnoff uint64_t ips_toosmall; /* not enough data */ 1085923c293SGleb Smirnoff uint64_t ips_badhlen; /* ip header length < data size */ 1095923c293SGleb Smirnoff uint64_t ips_badlen; /* ip length < ip header length */ 1105923c293SGleb Smirnoff uint64_t ips_fragments; /* fragments received */ 1115923c293SGleb Smirnoff uint64_t ips_fragdropped; /* frags dropped (dups, out of space) */ 1125923c293SGleb Smirnoff uint64_t ips_fragtimeout; /* fragments timed out */ 1135923c293SGleb Smirnoff uint64_t ips_forward; /* packets forwarded */ 1145923c293SGleb Smirnoff uint64_t ips_fastforward; /* packets fast forwarded */ 1155923c293SGleb Smirnoff uint64_t ips_cantforward; /* packets rcvd for unreachable dest */ 1165923c293SGleb Smirnoff uint64_t ips_redirectsent; /* packets forwarded on same net */ 1175923c293SGleb Smirnoff uint64_t ips_noproto; /* unknown or unsupported protocol */ 1185923c293SGleb Smirnoff uint64_t ips_delivered; /* datagrams delivered to upper level*/ 1195923c293SGleb Smirnoff uint64_t ips_localout; /* total ip packets generated here */ 1205923c293SGleb Smirnoff uint64_t ips_odropped; /* lost packets due to nobufs, etc. */ 1215923c293SGleb Smirnoff uint64_t ips_reassembled; /* total packets reassembled ok */ 1225923c293SGleb Smirnoff uint64_t ips_fragmented; /* datagrams successfully fragmented */ 1235923c293SGleb Smirnoff uint64_t ips_ofragments; /* output fragments created */ 1245923c293SGleb Smirnoff uint64_t ips_cantfrag; /* don't fragment flag was set, etc. */ 1255923c293SGleb Smirnoff uint64_t ips_badoptions; /* error in option processing */ 1265923c293SGleb Smirnoff uint64_t ips_noroute; /* packets discarded due to no route */ 1275923c293SGleb Smirnoff uint64_t ips_badvers; /* ip version != 4 */ 1285923c293SGleb Smirnoff uint64_t ips_rawout; /* total raw ip packets generated */ 1295923c293SGleb Smirnoff uint64_t ips_toolong; /* ip length > max ip packet size */ 1305923c293SGleb Smirnoff uint64_t ips_notmember; /* multicasts for unregistered grps */ 1315923c293SGleb Smirnoff uint64_t ips_nogif; /* no match gif found */ 1325923c293SGleb Smirnoff uint64_t ips_badaddr; /* invalid address on header */ 133df8bae1dSRodney W. Grimes }; 134df8bae1dSRodney W. Grimes 135664a31e4SPeter Wemm #ifdef _KERNEL 1365914e1eaSBruce Evans 1375923c293SGleb Smirnoff #include <sys/counter.h> 138eddfbb76SRobert Watson #include <net/vnet.h> 139*60d8dbbeSKristof Provost #include <netinet/in_kdtrace.h> 140eddfbb76SRobert Watson 1415da0521fSAndrey V. Elsukov VNET_PCPUSTAT_DECLARE(struct ipstat, ipstat); 142315e3e38SRobert Watson /* 143315e3e38SRobert Watson * In-kernel consumers can use these accessor macros directly to update 144315e3e38SRobert Watson * stats. 145315e3e38SRobert Watson */ 1465da0521fSAndrey V. Elsukov #define IPSTAT_ADD(name, val) \ 147*60d8dbbeSKristof Provost do { \ 148*60d8dbbeSKristof Provost MIB_SDT_PROBE1(ip, count, name, (val)); \ 149*60d8dbbeSKristof Provost VNET_PCPUSTAT_ADD(struct ipstat, ipstat, name, (val)); \ 150*60d8dbbeSKristof Provost } while (0) 151e3389419SAndrey V. Elsukov #define IPSTAT_SUB(name, val) IPSTAT_ADD(name, -(val)) 15286425c62SRobert Watson #define IPSTAT_INC(name) IPSTAT_ADD(name, 1) 153e3389419SAndrey V. Elsukov #define IPSTAT_DEC(name) IPSTAT_SUB(name, 1) 15486425c62SRobert Watson 155315e3e38SRobert Watson /* 156315e3e38SRobert Watson * Kernel module consumers must use this accessor macro. 157315e3e38SRobert Watson */ 158315e3e38SRobert Watson void kmod_ipstat_inc(int statnum); 159315e3e38SRobert Watson #define KMOD_IPSTAT_INC(name) \ 160*60d8dbbeSKristof Provost do { \ 161*60d8dbbeSKristof Provost MIB_SDT_PROBE1(ip, count, name, 1); \ 162*60d8dbbeSKristof Provost kmod_ipstat_inc( \ 163*60d8dbbeSKristof Provost offsetof(struct ipstat, name) / sizeof(uint64_t)); \ 164*60d8dbbeSKristof Provost } while (0) 165315e3e38SRobert Watson void kmod_ipstat_dec(int statnum); 166315e3e38SRobert Watson #define KMOD_IPSTAT_DEC(name) \ 167*60d8dbbeSKristof Provost do { \ 168*60d8dbbeSKristof Provost MIB_SDT_PROBE1(ip, count, name, -1); \ 169*60d8dbbeSKristof Provost kmod_ipstat_dec( \ 170*60d8dbbeSKristof Provost offsetof(struct ipstat, name) / sizeof(uint64_t)); \ 171*60d8dbbeSKristof Provost } while (0) 172315e3e38SRobert Watson 17371498f30SBruce M Simpson /* flags passed to ip_output as last parameter */ 17471498f30SBruce M Simpson #define IP_FORWARDING 0x1 /* most of ip header exists */ 17571498f30SBruce M Simpson #define IP_RAWOUTPUT 0x2 /* raw ip header exists */ 17671498f30SBruce M Simpson #define IP_SENDONES 0x4 /* send all-ones broadcast */ 17771498f30SBruce M Simpson #define IP_SENDTOIF 0x8 /* send on specific ifnet */ 178beaa515eSAndre Oppermann #define IP_ROUTETOIF SO_DONTROUTE /* 0x10 bypass routing tables */ 179beaa515eSAndre Oppermann #define IP_ALLOWBROADCAST SO_BROADCAST /* 0x20 can send broadcast packets */ 180061a4b4cSAdrian Chadd #define IP_NODEFAULTFLOWID 0x40 /* Don't set the flowid from inp */ 18135c7bb34SRandall Stewart #define IP_NO_SND_TAG_RL 0x80 /* Don't send down the ratelimit tag */ 182df8bae1dSRodney W. Grimes 1832fcb030aSAndrew Thompson #ifdef __NO_STRICT_ALIGNMENT 1842fcb030aSAndrew Thompson #define IP_HDR_ALIGNED_P(ip) 1 1852fcb030aSAndrew Thompson #else 1862fcb030aSAndrew Thompson #define IP_HDR_ALIGNED_P(ip) ((((intptr_t) (ip)) & 3) == 0) 1872fcb030aSAndrew Thompson #endif 1882fcb030aSAndrew Thompson 189cfe8b629SGarrett Wollman struct ip; 190ca5d5e73SBruce Evans struct inpcb; 1915e26bd9aSBruce Evans struct route; 192cfe8b629SGarrett Wollman struct sockopt; 19328c00100SMatt Macy struct inpcbinfo; 1945e26bd9aSBruce Evans 195eddfbb76SRobert Watson VNET_DECLARE(int, ip_defttl); /* default IP ttl */ 196eddfbb76SRobert Watson VNET_DECLARE(int, ipforwarding); /* ip forwarding */ 1978ad114c0SGeorge V. Neville-Neil VNET_DECLARE(int, ipsendredirects); 198c76ff708SAndre Oppermann #ifdef IPSTEALTH 199eddfbb76SRobert Watson VNET_DECLARE(int, ipstealth); /* stealth forwarding */ 200c76ff708SAndre Oppermann #endif 201eddfbb76SRobert Watson VNET_DECLARE(struct socket *, ip_rsvpd); /* reservation protocol daemon*/ 202eddfbb76SRobert Watson VNET_DECLARE(struct socket *, ip_mrouter); /* multicast routing daemon */ 20382cea7e6SBjoern A. Zeeb extern int (*legal_vif_num)(int); 20482cea7e6SBjoern A. Zeeb extern u_long (*ip_mcast_src)(int); 20582cea7e6SBjoern A. Zeeb VNET_DECLARE(int, rsvp_on); 2063c2824b9SAlexander V. Chernikov VNET_DECLARE(int, drop_redirect); 207eddfbb76SRobert Watson 2081e77c105SRobert Watson #define V_ip_id VNET(ip_id) 2091e77c105SRobert Watson #define V_ip_defttl VNET(ip_defttl) 2101e77c105SRobert Watson #define V_ipforwarding VNET(ipforwarding) 2118ad114c0SGeorge V. Neville-Neil #define V_ipsendredirects VNET(ipsendredirects) 212eddfbb76SRobert Watson #ifdef IPSTEALTH 2131e77c105SRobert Watson #define V_ipstealth VNET(ipstealth) 214eddfbb76SRobert Watson #endif 2151e77c105SRobert Watson #define V_ip_rsvpd VNET(ip_rsvpd) 2161e77c105SRobert Watson #define V_ip_mrouter VNET(ip_mrouter) 21782cea7e6SBjoern A. Zeeb #define V_rsvp_on VNET(rsvp_on) 2183c2824b9SAlexander V. Chernikov #define V_drop_redirect VNET(drop_redirect) 219df8bae1dSRodney W. Grimes 220cb6bb230SMatt Macy void inp_freemoptions(struct ip_moptions *); 22171498f30SBruce M Simpson int inp_getmoptions(struct inpcb *, struct sockopt *); 22271498f30SBruce M Simpson int inp_setmoptions(struct inpcb *, struct sockopt *); 22371498f30SBruce M Simpson 2244d77a549SAlfred Perlstein int ip_ctloutput(struct socket *, struct sockopt *sopt); 2251e78ac21SJeffrey Hsu int ip_fragment(struct ip *ip, struct mbuf **m_frag, int mtu, 226078468edSGleb Smirnoff u_long if_hwassist_flags); 227ef39adf0SAndre Oppermann void ip_forward(struct mbuf *m, int srcrt); 228beaa515eSAndre Oppermann extern int 229beaa515eSAndre Oppermann (*ip_mforward)(struct ip *, struct ifnet *, struct mbuf *, 2304d77a549SAlfred Perlstein struct ip_moptions *); 2314d77a549SAlfred Perlstein int ip_output(struct mbuf *, 2325d846453SSam Leffler struct mbuf *, struct route *, int, struct ip_moptions *, 2335d846453SSam Leffler struct inpcb *); 2349b932e9eSAndre Oppermann struct mbuf * 2359b932e9eSAndre Oppermann ip_reass(struct mbuf *); 2364d77a549SAlfred Perlstein void ip_savecontrol(struct inpcb *, struct mbuf **, struct ip *, 2374d77a549SAlfred Perlstein struct mbuf *); 2386d947416SGleb Smirnoff void ip_fillid(struct ip *); 2394d77a549SAlfred Perlstein int rip_ctloutput(struct socket *, struct sockopt *); 2408f5a8818SKevin Lo int ipip_input(struct mbuf **, int *, int); 2418f5a8818SKevin Lo int rsvp_input(struct mbuf **, int *, int); 24278b1fc05SGleb Smirnoff 2434d77a549SAlfred Perlstein int ip_rsvp_init(struct socket *); 2444d77a549SAlfred Perlstein int ip_rsvp_done(void); 245bbb4330bSLuigi Rizzo extern int (*ip_rsvp_vif)(struct socket *, struct sockopt *); 246bbb4330bSLuigi Rizzo extern void (*ip_rsvp_force_done)(struct socket *); 2478f5a8818SKevin Lo extern int (*rsvp_input_p)(struct mbuf **, int *, int); 248bbb4330bSLuigi Rizzo 24924b96f35SGleb Smirnoff typedef int ipproto_input_t(struct mbuf **, int *, int); 250fcb3f813SGleb Smirnoff struct icmp; 251fcb3f813SGleb Smirnoff typedef void ipproto_ctlinput_t(struct icmp *); 25224b96f35SGleb Smirnoff int ipproto_register(uint8_t, ipproto_input_t, ipproto_ctlinput_t); 25324b96f35SGleb Smirnoff int ipproto_unregister(uint8_t); 25424b96f35SGleb Smirnoff #define IPPROTO_REGISTER(prot, input, ctl) do { \ 25524b96f35SGleb Smirnoff int error __diagused; \ 25624b96f35SGleb Smirnoff error = ipproto_register(prot, input, ctl); \ 25724b96f35SGleb Smirnoff MPASS(error == 0); \ 25824b96f35SGleb Smirnoff } while (0) 25924b96f35SGleb Smirnoff 26043d39ca7SGleb Smirnoff ipproto_input_t rip_input; 26143d39ca7SGleb Smirnoff ipproto_ctlinput_t rip_ctlinput; 26243d39ca7SGleb Smirnoff 263b252313fSGleb Smirnoff VNET_DECLARE(struct pfil_head *, inet_pfil_head); 264b252313fSGleb Smirnoff #define V_inet_pfil_head VNET(inet_pfil_head) 265b252313fSGleb Smirnoff #define PFIL_INET_NAME "inet" 266134ea224SSam Leffler 2675ab15157SDoug Rabson VNET_DECLARE(struct pfil_head *, inet_local_pfil_head); 2685ab15157SDoug Rabson #define V_inet_local_pfil_head VNET(inet_local_pfil_head) 2695ab15157SDoug Rabson #define PFIL_INET_LOCAL_NAME "inet-local" 2705ab15157SDoug Rabson 2711c238475SJonathan Lemon void in_delayed_cksum(struct mbuf *m); 2721c238475SJonathan Lemon 273b2019e17SLuigi Rizzo /* Hooks for ipfw, dummynet, divert etc. Most are declared in raw_ip.c */ 274b2019e17SLuigi Rizzo /* 275b2019e17SLuigi Rizzo * Reference to an ipfw or packet filter rule that can be carried 276b2019e17SLuigi Rizzo * outside critical sections. 277b2019e17SLuigi Rizzo * A rule is identified by rulenum:rule_id which is ordered. 278b2019e17SLuigi Rizzo * In version chain_id the rule can be found in slot 'slot', so 279b2019e17SLuigi Rizzo * we don't need a lookup if chain_id == chain->id. 280b2019e17SLuigi Rizzo * 281b2019e17SLuigi Rizzo * On exit from the firewall this structure refers to the rule after 282b2019e17SLuigi Rizzo * the matching one (slot points to the new rule; rulenum:rule_id-1 283b2019e17SLuigi Rizzo * is the matching rule), and additional info (e.g. info often contains 284b2019e17SLuigi Rizzo * the insn argument or tablearg in the low 16 bits, in host format). 285b2019e17SLuigi Rizzo * On entry, the structure is valid if slot>0, and refers to the starting 286b2019e17SLuigi Rizzo * rules. 'info' contains the reason for reinject, e.g. divert port, 287b2019e17SLuigi Rizzo * divert direction, and so on. 288fc727ad6SBoris Lytochkin * 289fc727ad6SBoris Lytochkin * Packet Mark is an analogue to ipfw tags with O(1) lookup from mbuf while 290fc727ad6SBoris Lytochkin * regular tags require a single-linked list traversal. Mark is a 32-bit 291fc727ad6SBoris Lytochkin * number that can be looked up in a table [with 'number' table-type], matched 292fc727ad6SBoris Lytochkin * or compared with a number with optional mask applied before comparison. 293fc727ad6SBoris Lytochkin * Having generic nature, Mark can be used in a variety of needs. 294fc727ad6SBoris Lytochkin * For example, it could be used as a security group: mark will hold a 295fc727ad6SBoris Lytochkin * security group id and represent a group of packet flows that shares same 296fc727ad6SBoris Lytochkin * access control policy. 297fc727ad6SBoris Lytochkin * O_MASK opcode can match mark value bitwise so one can build a hierarchical 298fc727ad6SBoris Lytochkin * model designating different meanings for a bit range(s). 299b2019e17SLuigi Rizzo */ 300b2019e17SLuigi Rizzo struct ipfw_rule_ref { 301fc727ad6SBoris Lytochkin /* struct m_tag spans 24 bytes above this point, see mbuf_tags(9) */ 302fc727ad6SBoris Lytochkin /* spare space just to be save in case struct m_tag grows */ 303fc727ad6SBoris Lytochkin /* -- 32 bytes -- */ 304b2019e17SLuigi Rizzo uint32_t slot; /* slot for matching rule */ 305b2019e17SLuigi Rizzo uint32_t rulenum; /* matching rule number */ 306b2019e17SLuigi Rizzo uint32_t rule_id; /* matching rule id */ 307b2019e17SLuigi Rizzo uint32_t chain_id; /* ruleset id */ 308b2019e17SLuigi Rizzo uint32_t info; /* see below */ 309fc727ad6SBoris Lytochkin uint32_t pkt_mark; /* packet mark */ 310fc727ad6SBoris Lytochkin uint32_t spare[2]; 311fc727ad6SBoris Lytochkin /* -- 64 bytes -- */ 312b2019e17SLuigi Rizzo }; 313b2019e17SLuigi Rizzo 314b2019e17SLuigi Rizzo enum { 315b2019e17SLuigi Rizzo IPFW_INFO_MASK = 0x0000ffff, 316b2019e17SLuigi Rizzo IPFW_INFO_OUT = 0x00000000, /* outgoing, just for convenience */ 317b2019e17SLuigi Rizzo IPFW_INFO_IN = 0x80000000, /* incoming, overloads dir */ 318b2019e17SLuigi Rizzo IPFW_ONEPASS = 0x40000000, /* One-pass, do not reinject */ 319b2019e17SLuigi Rizzo IPFW_IS_MASK = 0x30000000, /* which source ? */ 320b2019e17SLuigi Rizzo IPFW_IS_DIVERT = 0x20000000, 321b2019e17SLuigi Rizzo IPFW_IS_DUMMYNET =0x10000000, 322a6e8e924SLuigi Rizzo IPFW_IS_PIPE = 0x08000000, /* pipe=1, queue = 0 */ 323b2019e17SLuigi Rizzo }; 324b2019e17SLuigi Rizzo #define MTAG_IPFW 1148380143 /* IPFW-tagged cookie */ 325b2019e17SLuigi Rizzo #define MTAG_IPFW_RULE 1262273568 /* rule reference */ 3269527ec6eSAndrey V. Elsukov #define MTAG_IPFW_CALL 1308397630 /* call stack */ 327b2019e17SLuigi Rizzo 328115a40c7SLuigi Rizzo struct ip_fw_args; 3290b4b0b0fSJulian Elischer typedef int (*ip_fw_ctl_ptr_t)(struct sockopt *); 3300b4b0b0fSJulian Elischer VNET_DECLARE(ip_fw_ctl_ptr_t, ip_fw_ctl_ptr); 3310b4b0b0fSJulian Elischer #define V_ip_fw_ctl_ptr VNET(ip_fw_ctl_ptr) 3320b4b0b0fSJulian Elischer 333b2019e17SLuigi Rizzo /* Divert hooks. */ 3341830dae3SGleb Smirnoff extern void (*ip_divert_ptr)(struct mbuf *m, bool incoming); 335b2019e17SLuigi Rizzo /* ng_ipfw hooks -- XXX make it the same as divert and dummynet */ 336cef9f220SGleb Smirnoff extern int (*ng_ipfw_input_p)(struct mbuf **, struct ip_fw_args *, bool); 337115a40c7SLuigi Rizzo extern int (*ip_dn_ctl_ptr)(struct sockopt *); 338dc0fa4f7SGleb Smirnoff extern int (*ip_dn_io_ptr)(struct mbuf **, struct ip_fw_args *); 339fabf705fSIgor Ostapenko 340fabf705fSIgor Ostapenko /* pf specific mtag for divert(4) support */ 341c1146e6aSKristof Provost __enum_uint8_decl(pf_mtag_dir) { 342c1146e6aSKristof Provost PF_DIVERT_MTAG_DIR_IN = 1, 343c1146e6aSKristof Provost PF_DIVERT_MTAG_DIR_OUT = 2 344c1146e6aSKristof Provost }; 345fabf705fSIgor Ostapenko struct pf_divert_mtag { 346b68d2789SIgor Ostapenko __enum_uint8(pf_mtag_dir) idir; /* initial pkt direction */ 347c1146e6aSKristof Provost union { 348b68d2789SIgor Ostapenko __enum_uint8(pf_mtag_dir) ndir; /* new dir after re-enter */ 349b68d2789SIgor Ostapenko uint16_t port; /* initial divert(4) port */ 350c1146e6aSKristof Provost }; 351fabf705fSIgor Ostapenko }; 352fabf705fSIgor Ostapenko #define MTAG_PF_DIVERT 1262273569 353fabf705fSIgor Ostapenko 354664a31e4SPeter Wemm #endif /* _KERNEL */ 355707f139eSPaul Richards 3565914e1eaSBruce Evans #endif /* !_NETINET_IP_VAR_H_ */ 357