xref: /freebsd/sys/netinet/ip_var.h (revision 86425c62a0067a5c61d3c87ab5f3a489e3c4fd25)
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>
37603724d3SBjoern A. Zeeb #ifdef _KERNEL
38603724d3SBjoern A. Zeeb #include <sys/vimage.h>
39603724d3SBjoern A. Zeeb #endif
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.
56df8bae1dSRodney W. Grimes  * They are timed out after ipq_ttl drops to 0, and may also
57df8bae1dSRodney W. Grimes  * be 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 */
61df8bae1dSRodney W. Grimes 	u_char	ipq_ttl;		/* time for reass q to live */
62df8bae1dSRodney W. Grimes 	u_char	ipq_p;			/* protocol of this fragment */
63df8bae1dSRodney W. Grimes 	u_short	ipq_id;			/* sequence id for reassembly */
646effc713SDoug Rabson 	struct mbuf *ipq_frags;		/* to ip headers of fragments */
65df8bae1dSRodney W. Grimes 	struct	in_addr ipq_src,ipq_dst;
66375386e2SMike Silbersack 	u_char	ipq_nfrags;		/* # frags in this packet */
67eca8a663SRobert Watson 	struct label *ipq_label;	/* MAC label */
68df8bae1dSRodney W. Grimes };
6969dac2eaSRobert Watson #endif /* _KERNEL */
70df8bae1dSRodney W. Grimes 
71df8bae1dSRodney W. Grimes /*
72c444cddeSAndre Oppermann  * Structure stored in mbuf in inpcb.ip_options
73c444cddeSAndre Oppermann  * and passed to ip_output when ip options are in use.
74c444cddeSAndre Oppermann  * The actual length of the options (including ipopt_dst)
75c444cddeSAndre Oppermann  * is in m_len.
76c444cddeSAndre Oppermann  */
77c444cddeSAndre Oppermann #define MAX_IPOPTLEN	40
78c444cddeSAndre Oppermann 
79c444cddeSAndre Oppermann struct ipoption {
80c444cddeSAndre Oppermann 	struct	in_addr ipopt_dst;	/* first-hop dst if source routed */
81c444cddeSAndre Oppermann 	char	ipopt_list[MAX_IPOPTLEN];	/* options proper */
82c444cddeSAndre Oppermann };
83c444cddeSAndre Oppermann 
84c444cddeSAndre Oppermann /*
85df8bae1dSRodney W. Grimes  * Structure attached to inpcb.ip_moptions and
86df8bae1dSRodney W. Grimes  * passed to ip_output when IP multicast options are in use.
8771498f30SBruce M Simpson  * This structure is lazy-allocated.
88df8bae1dSRodney W. Grimes  */
89df8bae1dSRodney W. Grimes struct ip_moptions {
90df8bae1dSRodney W. Grimes 	struct	ifnet *imo_multicast_ifp; /* ifp for outgoing multicasts */
9133841545SHajimu UMEMOTO 	struct in_addr imo_multicast_addr; /* ifindex/addr on MULTICAST_IF */
923548bfc9SBruce M Simpson 	u_long	imo_multicast_vif;	/* vif num outgoing multicasts */
93df8bae1dSRodney W. Grimes 	u_char	imo_multicast_ttl;	/* TTL for outgoing multicasts */
94df8bae1dSRodney W. Grimes 	u_char	imo_multicast_loop;	/* 1 => hear sends if a member */
95df8bae1dSRodney W. Grimes 	u_short	imo_num_memberships;	/* no. memberships this socket */
963548bfc9SBruce M Simpson 	u_short	imo_max_memberships;	/* max memberships this socket */
973548bfc9SBruce M Simpson 	struct	in_multi **imo_membership;	/* group memberships */
9871498f30SBruce M Simpson 	struct	in_mfilter *imo_mfilters;	/* source filters */
99df8bae1dSRodney W. Grimes };
100df8bae1dSRodney W. Grimes 
101df8bae1dSRodney W. Grimes struct	ipstat {
102df8bae1dSRodney W. Grimes 	u_long	ips_total;		/* total packets received */
103df8bae1dSRodney W. Grimes 	u_long	ips_badsum;		/* checksum bad */
104df8bae1dSRodney W. Grimes 	u_long	ips_tooshort;		/* packet too short */
105df8bae1dSRodney W. Grimes 	u_long	ips_toosmall;		/* not enough data */
106df8bae1dSRodney W. Grimes 	u_long	ips_badhlen;		/* ip header length < data size */
107df8bae1dSRodney W. Grimes 	u_long	ips_badlen;		/* ip length < ip header length */
108df8bae1dSRodney W. Grimes 	u_long	ips_fragments;		/* fragments received */
109df8bae1dSRodney W. Grimes 	u_long	ips_fragdropped;	/* frags dropped (dups, out of space) */
110df8bae1dSRodney W. Grimes 	u_long	ips_fragtimeout;	/* fragments timed out */
111df8bae1dSRodney W. Grimes 	u_long	ips_forward;		/* packets forwarded */
1121f91d8c5SDavid Greenman 	u_long	ips_fastforward;	/* packets fast forwarded */
113df8bae1dSRodney W. Grimes 	u_long	ips_cantforward;	/* packets rcvd for unreachable dest */
114df8bae1dSRodney W. Grimes 	u_long	ips_redirectsent;	/* packets forwarded on same net */
115df8bae1dSRodney W. Grimes 	u_long	ips_noproto;		/* unknown or unsupported protocol */
116df8bae1dSRodney W. Grimes 	u_long	ips_delivered;		/* datagrams delivered to upper level*/
117df8bae1dSRodney W. Grimes 	u_long	ips_localout;		/* total ip packets generated here */
118df8bae1dSRodney W. Grimes 	u_long	ips_odropped;		/* lost packets due to nobufs, etc. */
119df8bae1dSRodney W. Grimes 	u_long	ips_reassembled;	/* total packets reassembled ok */
1206c5e9bbdSMike Pritchard 	u_long	ips_fragmented;		/* datagrams successfully fragmented */
121df8bae1dSRodney W. Grimes 	u_long	ips_ofragments;		/* output fragments created */
122df8bae1dSRodney W. Grimes 	u_long	ips_cantfrag;		/* don't fragment flag was set, etc. */
123df8bae1dSRodney W. Grimes 	u_long	ips_badoptions;		/* error in option processing */
124df8bae1dSRodney W. Grimes 	u_long	ips_noroute;		/* packets discarded due to no route */
125df8bae1dSRodney W. Grimes 	u_long	ips_badvers;		/* ip version != 4 */
126df8bae1dSRodney W. Grimes 	u_long	ips_rawout;		/* total raw ip packets generated */
127430d30d8SBill Fenner 	u_long	ips_toolong;		/* ip length > max ip packet size */
12882c39223SGarrett Wollman 	u_long	ips_notmember;		/* multicasts for unregistered grps */
12976429de4SYoshinobu Inoue 	u_long	ips_nogif;		/* no match gif found */
13033841545SHajimu UMEMOTO 	u_long	ips_badaddr;		/* invalid address on header */
131df8bae1dSRodney W. Grimes };
132df8bae1dSRodney W. Grimes 
133664a31e4SPeter Wemm #ifdef _KERNEL
1345914e1eaSBruce Evans 
13586425c62SRobert Watson #define	IPSTAT_ADD(name, val)	V_ipstat.name += (val)
13686425c62SRobert Watson #define	IPSTAT_SUB(name, val)	V_ipstat.name -= (val)
13786425c62SRobert Watson #define	IPSTAT_INC(name)	IPSTAT_ADD(name, 1)
13886425c62SRobert Watson #define	IPSTAT_DEC(name)	IPSTAT_SUB(name, 1)
13986425c62SRobert Watson 
14071498f30SBruce M Simpson /* flags passed to ip_output as last parameter */
14171498f30SBruce M Simpson #define	IP_FORWARDING		0x1		/* most of ip header exists */
14271498f30SBruce M Simpson #define	IP_RAWOUTPUT		0x2		/* raw ip header exists */
14371498f30SBruce M Simpson #define	IP_SENDONES		0x4		/* send all-ones broadcast */
14471498f30SBruce M Simpson #define	IP_SENDTOIF		0x8		/* send on specific ifnet */
145beaa515eSAndre Oppermann #define IP_ROUTETOIF		SO_DONTROUTE	/* 0x10 bypass routing tables */
146beaa515eSAndre Oppermann #define IP_ALLOWBROADCAST	SO_BROADCAST	/* 0x20 can send broadcast packets */
147df8bae1dSRodney W. Grimes 
148beaa515eSAndre Oppermann /*
149beaa515eSAndre Oppermann  * mbuf flag used by ip_fastfwd
150beaa515eSAndre Oppermann  */
151ac9d7e26SMax Laier #define	M_FASTFWD_OURS		M_PROTO1	/* changed dst to local */
152ac9d7e26SMax Laier 
1532fcb030aSAndrew Thompson #ifdef __NO_STRICT_ALIGNMENT
1542fcb030aSAndrew Thompson #define IP_HDR_ALIGNED_P(ip)	1
1552fcb030aSAndrew Thompson #else
1562fcb030aSAndrew Thompson #define IP_HDR_ALIGNED_P(ip)	((((intptr_t) (ip)) & 3) == 0)
1572fcb030aSAndrew Thompson #endif
1582fcb030aSAndrew Thompson 
159cfe8b629SGarrett Wollman struct ip;
160ca5d5e73SBruce Evans struct inpcb;
1615e26bd9aSBruce Evans struct route;
162cfe8b629SGarrett Wollman struct sockopt;
1635e26bd9aSBruce Evans 
16486413abfSBjoern A. Zeeb #ifdef VIMAGE_GLOBALS
165f23b4c91SGarrett Wollman extern struct	ipstat	ipstat;
166f23b4c91SGarrett Wollman extern u_short	ip_id;			/* ip packet ctr, for ids */
167385195c0SMarko Zec extern int	ip_do_randomid;
168f23b4c91SGarrett Wollman extern int	ip_defttl;		/* default IP ttl */
1691f91d8c5SDavid Greenman extern int	ipforwarding;		/* ip forwarding */
170c76ff708SAndre Oppermann #ifdef IPSTEALTH
171c76ff708SAndre Oppermann extern int	ipstealth;		/* stealth forwarding */
172c76ff708SAndre Oppermann #endif
17386413abfSBjoern A. Zeeb extern int rsvp_on;
174f0068c4aSGarrett Wollman extern struct socket *ip_rsvpd;		/* reservation protocol daemon */
175f0068c4aSGarrett Wollman extern struct socket *ip_mrouter;	/* multicast routing daemon */
17686413abfSBjoern A. Zeeb #endif
17786413abfSBjoern A. Zeeb extern u_char	ip_protox[];
1784d77a549SAlfred Perlstein extern int	(*legal_vif_num)(int);
1794d77a549SAlfred Perlstein extern u_long	(*ip_mcast_src)(int);
180117bcae7SGarrett Wollman extern struct	pr_usrreqs rip_usrreqs;
181df8bae1dSRodney W. Grimes 
18271498f30SBruce M Simpson void	inp_freemoptions(struct ip_moptions *);
18371498f30SBruce M Simpson int	inp_getmoptions(struct inpcb *, struct sockopt *);
18471498f30SBruce M Simpson int	inp_setmoptions(struct inpcb *, struct sockopt *);
18571498f30SBruce M Simpson 
1864d77a549SAlfred Perlstein int	ip_ctloutput(struct socket *, struct sockopt *sopt);
1874d77a549SAlfred Perlstein void	ip_drain(void);
1885f311da2SMike Silbersack void	ip_fini(void *xtp);
1891e78ac21SJeffrey Hsu int	ip_fragment(struct ip *ip, struct mbuf **m_frag, int mtu,
1901e78ac21SJeffrey Hsu 	    u_long if_hwassist_flags, int sw_csum);
191ef39adf0SAndre Oppermann void	ip_forward(struct mbuf *m, int srcrt);
1924d77a549SAlfred Perlstein void	ip_init(void);
193beaa515eSAndre Oppermann extern int
194beaa515eSAndre Oppermann 	(*ip_mforward)(struct ip *, struct ifnet *, struct mbuf *,
1954d77a549SAlfred Perlstein 	    struct ip_moptions *);
1964d77a549SAlfred Perlstein int	ip_output(struct mbuf *,
1975d846453SSam Leffler 	    struct mbuf *, struct route *, int, struct ip_moptions *,
1985d846453SSam Leffler 	    struct inpcb *);
199de38924dSAndre Oppermann int	ipproto_register(u_char);
200de38924dSAndre Oppermann int	ipproto_unregister(u_char);
2019b932e9eSAndre Oppermann struct mbuf *
2029b932e9eSAndre Oppermann 	ip_reass(struct mbuf *);
203bd714208SRuslan Ermilov struct in_ifaddr *
2048b07e49aSJulian Elischer 	ip_rtaddr(struct in_addr, u_int fibnum);
2054d77a549SAlfred Perlstein void	ip_savecontrol(struct inpcb *, struct mbuf **, struct ip *,
2064d77a549SAlfred Perlstein 	    struct mbuf *);
2074d77a549SAlfred Perlstein void	ip_slowtimo(void);
2081f44b0a1SDavid Malone u_int16_t	ip_randomid(void);
2094d77a549SAlfred Perlstein int	rip_ctloutput(struct socket *, struct sockopt *);
2104d77a549SAlfred Perlstein void	rip_ctlinput(int, struct sockaddr *, void *);
2114d77a549SAlfred Perlstein void	rip_init(void);
2124d77a549SAlfred Perlstein void	rip_input(struct mbuf *, int);
2134d77a549SAlfred Perlstein int	rip_output(struct mbuf *, struct socket *, u_long);
2144d77a549SAlfred Perlstein void	ipip_input(struct mbuf *, int);
2154d77a549SAlfred Perlstein void	rsvp_input(struct mbuf *, int);
2164d77a549SAlfred Perlstein int	ip_rsvp_init(struct socket *);
2174d77a549SAlfred Perlstein int	ip_rsvp_done(void);
218bbb4330bSLuigi Rizzo extern int	(*ip_rsvp_vif)(struct socket *, struct sockopt *);
219bbb4330bSLuigi Rizzo extern void	(*ip_rsvp_force_done)(struct socket *);
220bbb4330bSLuigi Rizzo extern void	(*rsvp_input_p)(struct mbuf *m, int off);
221bbb4330bSLuigi Rizzo 
222c21fd232SAndre Oppermann extern	struct pfil_head inet_pfil_hook;	/* packet filter hooks */
223134ea224SSam Leffler 
2241c238475SJonathan Lemon void	in_delayed_cksum(struct mbuf *m);
2251c238475SJonathan Lemon 
226664a31e4SPeter Wemm #endif /* _KERNEL */
227707f139eSPaul Richards 
2285914e1eaSBruce Evans #endif /* !_NETINET_IP_VAR_H_ */
229