xref: /freebsd/sys/netinet/ip_var.h (revision 5923c29332ccda3318fcf6d772c2d7c820c70701)
1c398230bSWarner Losh /*-
2df8bae1dSRodney W. Grimes  * Copyright (c) 1982, 1986, 1993
3df8bae1dSRodney W. Grimes  *	The Regents of the University of California.  All rights reserved.
4df8bae1dSRodney W. Grimes  *
5df8bae1dSRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
6df8bae1dSRodney W. Grimes  * modification, are permitted provided that the following conditions
7df8bae1dSRodney W. Grimes  * are met:
8df8bae1dSRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
9df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
10df8bae1dSRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
11df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
12df8bae1dSRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
13df8bae1dSRodney W. Grimes  * 4. Neither the name of the University nor the names of its contributors
14df8bae1dSRodney W. Grimes  *    may be used to endorse or promote products derived from this software
15df8bae1dSRodney W. Grimes  *    without specific prior written permission.
16df8bae1dSRodney W. Grimes  *
17df8bae1dSRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18df8bae1dSRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19df8bae1dSRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20df8bae1dSRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21df8bae1dSRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22df8bae1dSRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23df8bae1dSRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24df8bae1dSRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25df8bae1dSRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26df8bae1dSRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27df8bae1dSRodney W. Grimes  * SUCH DAMAGE.
28df8bae1dSRodney W. Grimes  *
293271ad14SGarrett Wollman  *	@(#)ip_var.h	8.2 (Berkeley) 1/9/95
30c3aac50fSPeter Wemm  * $FreeBSD$
31df8bae1dSRodney W. Grimes  */
32df8bae1dSRodney W. Grimes 
33707f139eSPaul Richards #ifndef _NETINET_IP_VAR_H_
34707f139eSPaul Richards #define	_NETINET_IP_VAR_H_
35707f139eSPaul Richards 
3633841545SHajimu UMEMOTO #include <sys/queue.h>
3733841545SHajimu UMEMOTO 
38df8bae1dSRodney W. Grimes /*
39df8bae1dSRodney W. Grimes  * Overlay for ip header used by other protocols (tcp, udp).
40df8bae1dSRodney W. Grimes  */
41df8bae1dSRodney W. Grimes struct ipovly {
426effc713SDoug Rabson 	u_char	ih_x1[9];		/* (unused) */
43df8bae1dSRodney W. Grimes 	u_char	ih_pr;			/* protocol */
44430d30d8SBill Fenner 	u_short	ih_len;			/* protocol length */
45df8bae1dSRodney W. Grimes 	struct	in_addr ih_src;		/* source internet address */
46df8bae1dSRodney W. Grimes 	struct	in_addr ih_dst;		/* destination internet address */
47df8bae1dSRodney W. Grimes };
48df8bae1dSRodney W. Grimes 
4969dac2eaSRobert Watson #ifdef _KERNEL
50df8bae1dSRodney W. Grimes /*
51df8bae1dSRodney W. Grimes  * Ip reassembly queue structure.  Each fragment
52df8bae1dSRodney W. Grimes  * being reassembled is attached to one of these structures.
53df8bae1dSRodney W. Grimes  * They are timed out after ipq_ttl drops to 0, and may also
54df8bae1dSRodney W. Grimes  * be reclaimed if memory becomes tight.
55df8bae1dSRodney W. Grimes  */
56df8bae1dSRodney W. Grimes struct ipq {
57462b86feSPoul-Henning Kamp 	TAILQ_ENTRY(ipq) ipq_list;	/* to other reass headers */
58df8bae1dSRodney W. Grimes 	u_char	ipq_ttl;		/* time for reass q to live */
59df8bae1dSRodney W. Grimes 	u_char	ipq_p;			/* protocol of this fragment */
60df8bae1dSRodney W. Grimes 	u_short	ipq_id;			/* sequence id for reassembly */
616effc713SDoug Rabson 	struct mbuf *ipq_frags;		/* to ip headers of fragments */
62df8bae1dSRodney W. Grimes 	struct	in_addr ipq_src,ipq_dst;
63375386e2SMike Silbersack 	u_char	ipq_nfrags;		/* # frags in this packet */
64eca8a663SRobert Watson 	struct label *ipq_label;	/* MAC label */
65df8bae1dSRodney W. Grimes };
6669dac2eaSRobert Watson #endif /* _KERNEL */
67df8bae1dSRodney W. Grimes 
68df8bae1dSRodney W. Grimes /*
69c444cddeSAndre Oppermann  * Structure stored in mbuf in inpcb.ip_options
70c444cddeSAndre Oppermann  * and passed to ip_output when ip options are in use.
71c444cddeSAndre Oppermann  * The actual length of the options (including ipopt_dst)
72c444cddeSAndre Oppermann  * is in m_len.
73c444cddeSAndre Oppermann  */
74c444cddeSAndre Oppermann #define MAX_IPOPTLEN	40
75c444cddeSAndre Oppermann 
76c444cddeSAndre Oppermann struct ipoption {
77c444cddeSAndre Oppermann 	struct	in_addr ipopt_dst;	/* first-hop dst if source routed */
78c444cddeSAndre Oppermann 	char	ipopt_list[MAX_IPOPTLEN];	/* options proper */
79c444cddeSAndre Oppermann };
80c444cddeSAndre Oppermann 
81c444cddeSAndre Oppermann /*
82df8bae1dSRodney W. Grimes  * Structure attached to inpcb.ip_moptions and
83df8bae1dSRodney W. Grimes  * passed to ip_output when IP multicast options are in use.
8471498f30SBruce M Simpson  * This structure is lazy-allocated.
85df8bae1dSRodney W. Grimes  */
86df8bae1dSRodney W. Grimes struct ip_moptions {
87df8bae1dSRodney W. Grimes 	struct	ifnet *imo_multicast_ifp; /* ifp for outgoing multicasts */
8833841545SHajimu UMEMOTO 	struct in_addr imo_multicast_addr; /* ifindex/addr on MULTICAST_IF */
893548bfc9SBruce M Simpson 	u_long	imo_multicast_vif;	/* vif num outgoing multicasts */
90df8bae1dSRodney W. Grimes 	u_char	imo_multicast_ttl;	/* TTL for outgoing multicasts */
91df8bae1dSRodney W. Grimes 	u_char	imo_multicast_loop;	/* 1 => hear sends if a member */
92df8bae1dSRodney W. Grimes 	u_short	imo_num_memberships;	/* no. memberships this socket */
933548bfc9SBruce M Simpson 	u_short	imo_max_memberships;	/* max memberships this socket */
943548bfc9SBruce M Simpson 	struct	in_multi **imo_membership;	/* group memberships */
9571498f30SBruce M Simpson 	struct	in_mfilter *imo_mfilters;	/* source filters */
96c23de1f4SJohn Baldwin 	STAILQ_ENTRY(ip_moptions) imo_link;
97df8bae1dSRodney W. Grimes };
98df8bae1dSRodney W. Grimes 
99df8bae1dSRodney W. Grimes struct	ipstat {
100*5923c293SGleb Smirnoff 	uint64_t ips_total;		/* total packets received */
101*5923c293SGleb Smirnoff 	uint64_t ips_badsum;		/* checksum bad */
102*5923c293SGleb Smirnoff 	uint64_t ips_tooshort;		/* packet too short */
103*5923c293SGleb Smirnoff 	uint64_t ips_toosmall;		/* not enough data */
104*5923c293SGleb Smirnoff 	uint64_t ips_badhlen;		/* ip header length < data size */
105*5923c293SGleb Smirnoff 	uint64_t ips_badlen;		/* ip length < ip header length */
106*5923c293SGleb Smirnoff 	uint64_t ips_fragments;		/* fragments received */
107*5923c293SGleb Smirnoff 	uint64_t ips_fragdropped;	/* frags dropped (dups, out of space) */
108*5923c293SGleb Smirnoff 	uint64_t ips_fragtimeout;	/* fragments timed out */
109*5923c293SGleb Smirnoff 	uint64_t ips_forward;		/* packets forwarded */
110*5923c293SGleb Smirnoff 	uint64_t ips_fastforward;	/* packets fast forwarded */
111*5923c293SGleb Smirnoff 	uint64_t ips_cantforward;	/* packets rcvd for unreachable dest */
112*5923c293SGleb Smirnoff 	uint64_t ips_redirectsent;	/* packets forwarded on same net */
113*5923c293SGleb Smirnoff 	uint64_t ips_noproto;		/* unknown or unsupported protocol */
114*5923c293SGleb Smirnoff 	uint64_t ips_delivered;		/* datagrams delivered to upper level*/
115*5923c293SGleb Smirnoff 	uint64_t ips_localout;		/* total ip packets generated here */
116*5923c293SGleb Smirnoff 	uint64_t ips_odropped;		/* lost packets due to nobufs, etc. */
117*5923c293SGleb Smirnoff 	uint64_t ips_reassembled;	/* total packets reassembled ok */
118*5923c293SGleb Smirnoff 	uint64_t ips_fragmented;	/* datagrams successfully fragmented */
119*5923c293SGleb Smirnoff 	uint64_t ips_ofragments;	/* output fragments created */
120*5923c293SGleb Smirnoff 	uint64_t ips_cantfrag;		/* don't fragment flag was set, etc. */
121*5923c293SGleb Smirnoff 	uint64_t ips_badoptions;		/* error in option processing */
122*5923c293SGleb Smirnoff 	uint64_t ips_noroute;		/* packets discarded due to no route */
123*5923c293SGleb Smirnoff 	uint64_t ips_badvers;		/* ip version != 4 */
124*5923c293SGleb Smirnoff 	uint64_t ips_rawout;		/* total raw ip packets generated */
125*5923c293SGleb Smirnoff 	uint64_t ips_toolong;		/* ip length > max ip packet size */
126*5923c293SGleb Smirnoff 	uint64_t ips_notmember;		/* multicasts for unregistered grps */
127*5923c293SGleb Smirnoff 	uint64_t ips_nogif;		/* no match gif found */
128*5923c293SGleb Smirnoff 	uint64_t ips_badaddr;		/* invalid address on header */
129df8bae1dSRodney W. Grimes };
130df8bae1dSRodney W. Grimes 
131664a31e4SPeter Wemm #ifdef _KERNEL
1325914e1eaSBruce Evans 
133*5923c293SGleb Smirnoff #include <sys/counter.h>
134eddfbb76SRobert Watson #include <net/vnet.h>
135eddfbb76SRobert Watson 
136*5923c293SGleb Smirnoff /* Should match 'struct ipstat' above. */
137*5923c293SGleb Smirnoff struct ipstat_p {
138*5923c293SGleb Smirnoff 	counter_u64_t ips_total;
139*5923c293SGleb Smirnoff 	counter_u64_t ips_badsum;
140*5923c293SGleb Smirnoff 	counter_u64_t ips_tooshort;
141*5923c293SGleb Smirnoff 	counter_u64_t ips_toosmall;
142*5923c293SGleb Smirnoff 	counter_u64_t ips_badhlen;
143*5923c293SGleb Smirnoff 	counter_u64_t ips_badlen;
144*5923c293SGleb Smirnoff 	counter_u64_t ips_fragments;
145*5923c293SGleb Smirnoff 	counter_u64_t ips_fragdropped;
146*5923c293SGleb Smirnoff 	counter_u64_t ips_fragtimeout;
147*5923c293SGleb Smirnoff 	counter_u64_t ips_forward;
148*5923c293SGleb Smirnoff 	counter_u64_t ips_fastforward;
149*5923c293SGleb Smirnoff 	counter_u64_t ips_cantforward;
150*5923c293SGleb Smirnoff 	counter_u64_t ips_redirectsent;
151*5923c293SGleb Smirnoff 	counter_u64_t ips_noproto;
152*5923c293SGleb Smirnoff 	counter_u64_t ips_delivered;
153*5923c293SGleb Smirnoff 	counter_u64_t ips_localout;
154*5923c293SGleb Smirnoff 	counter_u64_t ips_odropped;
155*5923c293SGleb Smirnoff 	counter_u64_t ips_reassembled;
156*5923c293SGleb Smirnoff 	counter_u64_t ips_fragmented;
157*5923c293SGleb Smirnoff 	counter_u64_t ips_ofragments;
158*5923c293SGleb Smirnoff 	counter_u64_t ips_cantfrag;
159*5923c293SGleb Smirnoff 	counter_u64_t ips_badoptions;
160*5923c293SGleb Smirnoff 	counter_u64_t ips_noroute;
161*5923c293SGleb Smirnoff 	counter_u64_t ips_badvers;
162*5923c293SGleb Smirnoff 	counter_u64_t ips_rawout;
163*5923c293SGleb Smirnoff 	counter_u64_t ips_toolong;
164*5923c293SGleb Smirnoff 	counter_u64_t ips_notmember;
165*5923c293SGleb Smirnoff 	counter_u64_t ips_nogif;
166*5923c293SGleb Smirnoff 	counter_u64_t ips_badaddr;
167*5923c293SGleb Smirnoff };
168*5923c293SGleb Smirnoff VNET_DECLARE(struct ipstat_p, ipstatp);
169*5923c293SGleb Smirnoff #define	V_ipstatp VNET(ipstatp)
170*5923c293SGleb Smirnoff 
171315e3e38SRobert Watson /*
172315e3e38SRobert Watson  * In-kernel consumers can use these accessor macros directly to update
173315e3e38SRobert Watson  * stats.
174315e3e38SRobert Watson  */
175*5923c293SGleb Smirnoff #define	IPSTAT_ADD(name, val)	counter_u64_add(V_ipstatp.name, (val))
176*5923c293SGleb Smirnoff #define	IPSTAT_SUB(name, val)	counter_u64_subtract(V_ipstatp.name, (val))
17786425c62SRobert Watson #define	IPSTAT_INC(name)	IPSTAT_ADD(name, 1)
178*5923c293SGleb Smirnoff #define	IPSTAT_DEC(name)	IPSTAT_ADD(name, -1)
17986425c62SRobert Watson 
180315e3e38SRobert Watson /*
181315e3e38SRobert Watson  * Kernel module consumers must use this accessor macro.
182315e3e38SRobert Watson  */
183315e3e38SRobert Watson void	kmod_ipstat_inc(int statnum);
184315e3e38SRobert Watson #define	KMOD_IPSTAT_INC(name)						\
185*5923c293SGleb Smirnoff 	kmod_ipstat_inc(offsetof(struct ipstat_p, name) / sizeof(counter_u64_t))
186315e3e38SRobert Watson void	kmod_ipstat_dec(int statnum);
187315e3e38SRobert Watson #define	KMOD_IPSTAT_DEC(name)						\
188*5923c293SGleb Smirnoff 	kmod_ipstat_dec(offsetof(struct ipstat_p, name) / sizeof(counter_u64_t))
189315e3e38SRobert Watson 
19071498f30SBruce M Simpson /* flags passed to ip_output as last parameter */
19171498f30SBruce M Simpson #define	IP_FORWARDING		0x1		/* most of ip header exists */
19271498f30SBruce M Simpson #define	IP_RAWOUTPUT		0x2		/* raw ip header exists */
19371498f30SBruce M Simpson #define	IP_SENDONES		0x4		/* send all-ones broadcast */
19471498f30SBruce M Simpson #define	IP_SENDTOIF		0x8		/* send on specific ifnet */
195beaa515eSAndre Oppermann #define IP_ROUTETOIF		SO_DONTROUTE	/* 0x10 bypass routing tables */
196beaa515eSAndre Oppermann #define IP_ALLOWBROADCAST	SO_BROADCAST	/* 0x20 can send broadcast packets */
197df8bae1dSRodney W. Grimes 
198beaa515eSAndre Oppermann /*
199beaa515eSAndre Oppermann  * mbuf flag used by ip_fastfwd
200beaa515eSAndre Oppermann  */
201ac9d7e26SMax Laier #define	M_FASTFWD_OURS		M_PROTO1	/* changed dst to local */
202ffdbf9daSAndrey V. Elsukov #define	M_IP_NEXTHOP		M_PROTO2	/* explicit ip nexthop */
203ac9d7e26SMax Laier 
2042fcb030aSAndrew Thompson #ifdef __NO_STRICT_ALIGNMENT
2052fcb030aSAndrew Thompson #define IP_HDR_ALIGNED_P(ip)	1
2062fcb030aSAndrew Thompson #else
2072fcb030aSAndrew Thompson #define IP_HDR_ALIGNED_P(ip)	((((intptr_t) (ip)) & 3) == 0)
2082fcb030aSAndrew Thompson #endif
2092fcb030aSAndrew Thompson 
210cfe8b629SGarrett Wollman struct ip;
211ca5d5e73SBruce Evans struct inpcb;
2125e26bd9aSBruce Evans struct route;
213cfe8b629SGarrett Wollman struct sockopt;
2145e26bd9aSBruce Evans 
215eddfbb76SRobert Watson VNET_DECLARE(u_short, ip_id);			/* ip packet ctr, for ids */
216eddfbb76SRobert Watson VNET_DECLARE(int, ip_defttl);			/* default IP ttl */
217eddfbb76SRobert Watson VNET_DECLARE(int, ipforwarding);		/* ip forwarding */
218c76ff708SAndre Oppermann #ifdef IPSTEALTH
219eddfbb76SRobert Watson VNET_DECLARE(int, ipstealth);			/* stealth forwarding */
220c76ff708SAndre Oppermann #endif
22182cea7e6SBjoern A. Zeeb extern u_char	ip_protox[];
222eddfbb76SRobert Watson VNET_DECLARE(struct socket *, ip_rsvpd);	/* reservation protocol daemon*/
223eddfbb76SRobert Watson VNET_DECLARE(struct socket *, ip_mrouter);	/* multicast routing daemon */
22482cea7e6SBjoern A. Zeeb extern int	(*legal_vif_num)(int);
22582cea7e6SBjoern A. Zeeb extern u_long	(*ip_mcast_src)(int);
22682cea7e6SBjoern A. Zeeb VNET_DECLARE(int, rsvp_on);
2273c2824b9SAlexander V. Chernikov VNET_DECLARE(int, drop_redirect);
22882cea7e6SBjoern A. Zeeb extern struct	pr_usrreqs rip_usrreqs;
229eddfbb76SRobert Watson 
2301e77c105SRobert Watson #define	V_ip_id			VNET(ip_id)
2311e77c105SRobert Watson #define	V_ip_defttl		VNET(ip_defttl)
2321e77c105SRobert Watson #define	V_ipforwarding		VNET(ipforwarding)
233eddfbb76SRobert Watson #ifdef IPSTEALTH
2341e77c105SRobert Watson #define	V_ipstealth		VNET(ipstealth)
235eddfbb76SRobert Watson #endif
2361e77c105SRobert Watson #define	V_ip_rsvpd		VNET(ip_rsvpd)
2371e77c105SRobert Watson #define	V_ip_mrouter		VNET(ip_mrouter)
23882cea7e6SBjoern A. Zeeb #define	V_rsvp_on		VNET(rsvp_on)
2393c2824b9SAlexander V. Chernikov #define	V_drop_redirect		VNET(drop_redirect)
240df8bae1dSRodney W. Grimes 
24171498f30SBruce M Simpson void	inp_freemoptions(struct ip_moptions *);
24271498f30SBruce M Simpson int	inp_getmoptions(struct inpcb *, struct sockopt *);
24371498f30SBruce M Simpson int	inp_setmoptions(struct inpcb *, struct sockopt *);
24471498f30SBruce M Simpson 
2454d77a549SAlfred Perlstein int	ip_ctloutput(struct socket *, struct sockopt *sopt);
2464d77a549SAlfred Perlstein void	ip_drain(void);
2471e78ac21SJeffrey Hsu int	ip_fragment(struct ip *ip, struct mbuf **m_frag, int mtu,
248078468edSGleb Smirnoff 	    u_long if_hwassist_flags);
249ef39adf0SAndre Oppermann void	ip_forward(struct mbuf *m, int srcrt);
2504d77a549SAlfred Perlstein void	ip_init(void);
2519802380eSBjoern A. Zeeb #ifdef VIMAGE
2529802380eSBjoern A. Zeeb void	ip_destroy(void);
2539802380eSBjoern A. Zeeb #endif
254beaa515eSAndre Oppermann extern int
255beaa515eSAndre Oppermann 	(*ip_mforward)(struct ip *, struct ifnet *, struct mbuf *,
2564d77a549SAlfred Perlstein 	    struct ip_moptions *);
2574d77a549SAlfred Perlstein int	ip_output(struct mbuf *,
2585d846453SSam Leffler 	    struct mbuf *, struct route *, int, struct ip_moptions *,
2595d846453SSam Leffler 	    struct inpcb *);
2601b48d245SBjoern A. Zeeb int	ipproto_register(short);
2611b48d245SBjoern A. Zeeb int	ipproto_unregister(short);
2629b932e9eSAndre Oppermann struct mbuf *
2639b932e9eSAndre Oppermann 	ip_reass(struct mbuf *);
264bd714208SRuslan Ermilov struct in_ifaddr *
2658b07e49aSJulian Elischer 	ip_rtaddr(struct in_addr, u_int fibnum);
2664d77a549SAlfred Perlstein void	ip_savecontrol(struct inpcb *, struct mbuf **, struct ip *,
2674d77a549SAlfred Perlstein 	    struct mbuf *);
2684d77a549SAlfred Perlstein void	ip_slowtimo(void);
2691f44b0a1SDavid Malone u_int16_t	ip_randomid(void);
2704d77a549SAlfred Perlstein int	rip_ctloutput(struct socket *, struct sockopt *);
2714d77a549SAlfred Perlstein void	rip_ctlinput(int, struct sockaddr *, void *);
2724d77a549SAlfred Perlstein void	rip_init(void);
273bc29160dSMarko Zec #ifdef VIMAGE
274bc29160dSMarko Zec void	rip_destroy(void);
275bc29160dSMarko Zec #endif
2764d77a549SAlfred Perlstein void	rip_input(struct mbuf *, int);
2774d77a549SAlfred Perlstein int	rip_output(struct mbuf *, struct socket *, u_long);
2784d77a549SAlfred Perlstein void	ipip_input(struct mbuf *, int);
2794d77a549SAlfred Perlstein void	rsvp_input(struct mbuf *, int);
2804d77a549SAlfred Perlstein int	ip_rsvp_init(struct socket *);
2814d77a549SAlfred Perlstein int	ip_rsvp_done(void);
282bbb4330bSLuigi Rizzo extern int	(*ip_rsvp_vif)(struct socket *, struct sockopt *);
283bbb4330bSLuigi Rizzo extern void	(*ip_rsvp_force_done)(struct socket *);
284bbb4330bSLuigi Rizzo extern void	(*rsvp_input_p)(struct mbuf *m, int off);
285bbb4330bSLuigi Rizzo 
2860b4b0b0fSJulian Elischer VNET_DECLARE(struct pfil_head, inet_pfil_hook);	/* packet filter hooks */
2870b4b0b0fSJulian Elischer #define	V_inet_pfil_hook	VNET(inet_pfil_hook)
288134ea224SSam Leffler 
2891c238475SJonathan Lemon void	in_delayed_cksum(struct mbuf *m);
2901c238475SJonathan Lemon 
291b2019e17SLuigi Rizzo /* Hooks for ipfw, dummynet, divert etc. Most are declared in raw_ip.c */
292b2019e17SLuigi Rizzo /*
293b2019e17SLuigi Rizzo  * Reference to an ipfw or packet filter rule that can be carried
294b2019e17SLuigi Rizzo  * outside critical sections.
295b2019e17SLuigi Rizzo  * A rule is identified by rulenum:rule_id which is ordered.
296b2019e17SLuigi Rizzo  * In version chain_id the rule can be found in slot 'slot', so
297b2019e17SLuigi Rizzo  * we don't need a lookup if chain_id == chain->id.
298b2019e17SLuigi Rizzo  *
299b2019e17SLuigi Rizzo  * On exit from the firewall this structure refers to the rule after
300b2019e17SLuigi Rizzo  * the matching one (slot points to the new rule; rulenum:rule_id-1
301b2019e17SLuigi Rizzo  * is the matching rule), and additional info (e.g. info often contains
302b2019e17SLuigi Rizzo  * the insn argument or tablearg in the low 16 bits, in host format).
303b2019e17SLuigi Rizzo  * On entry, the structure is valid if slot>0, and refers to the starting
304b2019e17SLuigi Rizzo  * rules. 'info' contains the reason for reinject, e.g. divert port,
305b2019e17SLuigi Rizzo  * divert direction, and so on.
306b2019e17SLuigi Rizzo  */
307b2019e17SLuigi Rizzo struct ipfw_rule_ref {
308b2019e17SLuigi Rizzo 	uint32_t	slot;		/* slot for matching rule	*/
309b2019e17SLuigi Rizzo 	uint32_t	rulenum;	/* matching rule number		*/
310b2019e17SLuigi Rizzo 	uint32_t	rule_id;	/* matching rule id		*/
311b2019e17SLuigi Rizzo 	uint32_t	chain_id;	/* ruleset id			*/
312b2019e17SLuigi Rizzo 	uint32_t	info;		/* see below			*/
313b2019e17SLuigi Rizzo };
314b2019e17SLuigi Rizzo 
315b2019e17SLuigi Rizzo enum {
316b2019e17SLuigi Rizzo 	IPFW_INFO_MASK	= 0x0000ffff,
317b2019e17SLuigi Rizzo 	IPFW_INFO_OUT	= 0x00000000,	/* outgoing, just for convenience */
318b2019e17SLuigi Rizzo 	IPFW_INFO_IN	= 0x80000000,	/* incoming, overloads dir */
319b2019e17SLuigi Rizzo 	IPFW_ONEPASS	= 0x40000000,	/* One-pass, do not reinject */
320b2019e17SLuigi Rizzo 	IPFW_IS_MASK	= 0x30000000,	/* which source ? */
321b2019e17SLuigi Rizzo 	IPFW_IS_DIVERT	= 0x20000000,
322b2019e17SLuigi Rizzo 	IPFW_IS_DUMMYNET =0x10000000,
323b2019e17SLuigi Rizzo 	IPFW_IS_PIPE	= 0x08000000,	/* pip1=1, queue = 0 */
324b2019e17SLuigi Rizzo };
325b2019e17SLuigi Rizzo #define MTAG_IPFW	1148380143	/* IPFW-tagged cookie */
326b2019e17SLuigi Rizzo #define MTAG_IPFW_RULE	1262273568	/* rule reference */
3279527ec6eSAndrey V. Elsukov #define	MTAG_IPFW_CALL	1308397630	/* call stack */
328b2019e17SLuigi Rizzo 
329115a40c7SLuigi Rizzo struct ip_fw_args;
3300b4b0b0fSJulian Elischer typedef int	(*ip_fw_chk_ptr_t)(struct ip_fw_args *args);
3310b4b0b0fSJulian Elischer typedef int	(*ip_fw_ctl_ptr_t)(struct sockopt *);
3320b4b0b0fSJulian Elischer VNET_DECLARE(ip_fw_ctl_ptr_t, ip_fw_ctl_ptr);
3330b4b0b0fSJulian Elischer #define	V_ip_fw_ctl_ptr		VNET(ip_fw_ctl_ptr)
3340b4b0b0fSJulian Elischer 
335b2019e17SLuigi Rizzo /* Divert hooks. */
336b2019e17SLuigi Rizzo extern void	(*ip_divert_ptr)(struct mbuf *m, int incoming);
337b2019e17SLuigi Rizzo /* ng_ipfw hooks -- XXX make it the same as divert and dummynet */
338b2019e17SLuigi Rizzo extern int	(*ng_ipfw_input_p)(struct mbuf **, int,
339b2019e17SLuigi Rizzo 			struct ip_fw_args *, int);
340b2019e17SLuigi Rizzo 
341115a40c7SLuigi Rizzo extern int	(*ip_dn_ctl_ptr)(struct sockopt *);
342b2019e17SLuigi Rizzo extern int	(*ip_dn_io_ptr)(struct mbuf **, int, struct ip_fw_args *);
343eddfbb76SRobert Watson 
344eddfbb76SRobert Watson VNET_DECLARE(int, ip_do_randomid);
3451e77c105SRobert Watson #define	V_ip_do_randomid	VNET(ip_do_randomid)
346eddfbb76SRobert Watson #define	ip_newid()	((V_ip_do_randomid != 0) ? ip_randomid() : \
347eddfbb76SRobert Watson 			    htons(V_ip_id++))
348eddfbb76SRobert Watson 
349664a31e4SPeter Wemm #endif /* _KERNEL */
350707f139eSPaul Richards 
3515914e1eaSBruce Evans #endif /* !_NETINET_IP_VAR_H_ */
352