xref: /freebsd/sys/netinet/ip_var.h (revision bbb4330b6156ef2827cc03ff4aab7a0fe307683c)
1df8bae1dSRodney W. Grimes /*
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  * 3. All advertising materials mentioning features or use of this software
14df8bae1dSRodney W. Grimes  *    must display the following acknowledgement:
15df8bae1dSRodney W. Grimes  *	This product includes software developed by the University of
16df8bae1dSRodney W. Grimes  *	California, Berkeley and its contributors.
17df8bae1dSRodney W. Grimes  * 4. Neither the name of the University nor the names of its contributors
18df8bae1dSRodney W. Grimes  *    may be used to endorse or promote products derived from this software
19df8bae1dSRodney W. Grimes  *    without specific prior written permission.
20df8bae1dSRodney W. Grimes  *
21df8bae1dSRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22df8bae1dSRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23df8bae1dSRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24df8bae1dSRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25df8bae1dSRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26df8bae1dSRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27df8bae1dSRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28df8bae1dSRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29df8bae1dSRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30df8bae1dSRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31df8bae1dSRodney W. Grimes  * SUCH DAMAGE.
32df8bae1dSRodney W. Grimes  *
333271ad14SGarrett Wollman  *	@(#)ip_var.h	8.2 (Berkeley) 1/9/95
34c3aac50fSPeter Wemm  * $FreeBSD$
35df8bae1dSRodney W. Grimes  */
36df8bae1dSRodney W. Grimes 
37707f139eSPaul Richards #ifndef _NETINET_IP_VAR_H_
38707f139eSPaul Richards #define	_NETINET_IP_VAR_H_
39707f139eSPaul Richards 
4033841545SHajimu UMEMOTO #include <sys/queue.h>
4133841545SHajimu UMEMOTO 
429daf40feSRobert Watson #ifdef _KERNEL
439daf40feSRobert Watson #include <sys/_label.h>
449daf40feSRobert Watson #endif
459daf40feSRobert Watson 
46df8bae1dSRodney W. Grimes /*
47df8bae1dSRodney W. Grimes  * Overlay for ip header used by other protocols (tcp, udp).
48df8bae1dSRodney W. Grimes  */
49df8bae1dSRodney W. Grimes struct ipovly {
506effc713SDoug Rabson 	u_char	ih_x1[9];		/* (unused) */
51df8bae1dSRodney W. Grimes 	u_char	ih_pr;			/* protocol */
52430d30d8SBill Fenner 	u_short	ih_len;			/* protocol length */
53df8bae1dSRodney W. Grimes 	struct	in_addr ih_src;		/* source internet address */
54df8bae1dSRodney W. Grimes 	struct	in_addr ih_dst;		/* destination internet address */
55df8bae1dSRodney W. Grimes };
56df8bae1dSRodney W. Grimes 
5769dac2eaSRobert Watson #ifdef _KERNEL
58df8bae1dSRodney W. Grimes /*
59df8bae1dSRodney W. Grimes  * Ip reassembly queue structure.  Each fragment
60df8bae1dSRodney W. Grimes  * being reassembled is attached to one of these structures.
61df8bae1dSRodney W. Grimes  * They are timed out after ipq_ttl drops to 0, and may also
62df8bae1dSRodney W. Grimes  * be reclaimed if memory becomes tight.
63df8bae1dSRodney W. Grimes  */
64df8bae1dSRodney W. Grimes struct ipq {
65462b86feSPoul-Henning Kamp 	TAILQ_ENTRY(ipq) ipq_list;	/* to other reass headers */
66df8bae1dSRodney W. Grimes 	u_char	ipq_ttl;		/* time for reass q to live */
67df8bae1dSRodney W. Grimes 	u_char	ipq_p;			/* protocol of this fragment */
68df8bae1dSRodney W. Grimes 	u_short	ipq_id;			/* sequence id for reassembly */
696effc713SDoug Rabson 	struct mbuf *ipq_frags;		/* to ip headers of fragments */
70df8bae1dSRodney W. Grimes 	struct	in_addr ipq_src,ipq_dst;
718948e4baSArchie Cobbs 	u_int32_t ipq_div_info;		/* ipfw divert port & flags */
728948e4baSArchie Cobbs 	u_int16_t ipq_div_cookie;	/* ipfw divert cookie */
73549e4c9eSRobert Watson 	struct label ipq_label;		/* MAC label */
74df8bae1dSRodney W. Grimes };
7569dac2eaSRobert Watson #endif /* _KERNEL */
76df8bae1dSRodney W. Grimes 
77df8bae1dSRodney W. Grimes /*
78df8bae1dSRodney W. Grimes  * Structure stored in mbuf in inpcb.ip_options
79df8bae1dSRodney W. Grimes  * and passed to ip_output when ip options are in use.
80df8bae1dSRodney W. Grimes  * The actual length of the options (including ipopt_dst)
81df8bae1dSRodney W. Grimes  * is in m_len.
82df8bae1dSRodney W. Grimes  */
83df8bae1dSRodney W. Grimes #define MAX_IPOPTLEN	40
84df8bae1dSRodney W. Grimes 
85df8bae1dSRodney W. Grimes struct ipoption {
86df8bae1dSRodney W. Grimes 	struct	in_addr ipopt_dst;	/* first-hop dst if source routed */
87df8bae1dSRodney W. Grimes 	char	ipopt_list[MAX_IPOPTLEN];	/* options proper */
88df8bae1dSRodney W. Grimes };
89df8bae1dSRodney W. Grimes 
90df8bae1dSRodney W. Grimes /*
91df8bae1dSRodney W. Grimes  * Structure attached to inpcb.ip_moptions and
92df8bae1dSRodney W. Grimes  * passed to ip_output when IP multicast options are in use.
93df8bae1dSRodney W. Grimes  */
94df8bae1dSRodney W. Grimes struct ip_moptions {
95df8bae1dSRodney W. Grimes 	struct	ifnet *imo_multicast_ifp; /* ifp for outgoing multicasts */
9633841545SHajimu UMEMOTO 	struct in_addr imo_multicast_addr; /* ifindex/addr on MULTICAST_IF */
97df8bae1dSRodney W. Grimes 	u_char	imo_multicast_ttl;	/* TTL for outgoing multicasts */
98df8bae1dSRodney W. Grimes 	u_char	imo_multicast_loop;	/* 1 => hear sends if a member */
99df8bae1dSRodney W. Grimes 	u_short	imo_num_memberships;	/* no. memberships this socket */
100df8bae1dSRodney W. Grimes 	struct	in_multi *imo_membership[IP_MAX_MEMBERSHIPS];
1011c5de19aSGarrett Wollman 	u_long	imo_multicast_vif;	/* vif num outgoing multicasts */
102df8bae1dSRodney W. Grimes };
103df8bae1dSRodney W. Grimes 
104df8bae1dSRodney W. Grimes struct	ipstat {
105df8bae1dSRodney W. Grimes 	u_long	ips_total;		/* total packets received */
106df8bae1dSRodney W. Grimes 	u_long	ips_badsum;		/* checksum bad */
107df8bae1dSRodney W. Grimes 	u_long	ips_tooshort;		/* packet too short */
108df8bae1dSRodney W. Grimes 	u_long	ips_toosmall;		/* not enough data */
109df8bae1dSRodney W. Grimes 	u_long	ips_badhlen;		/* ip header length < data size */
110df8bae1dSRodney W. Grimes 	u_long	ips_badlen;		/* ip length < ip header length */
111df8bae1dSRodney W. Grimes 	u_long	ips_fragments;		/* fragments received */
112df8bae1dSRodney W. Grimes 	u_long	ips_fragdropped;	/* frags dropped (dups, out of space) */
113df8bae1dSRodney W. Grimes 	u_long	ips_fragtimeout;	/* fragments timed out */
114df8bae1dSRodney W. Grimes 	u_long	ips_forward;		/* packets forwarded */
1151f91d8c5SDavid Greenman 	u_long	ips_fastforward;	/* packets fast forwarded */
116df8bae1dSRodney W. Grimes 	u_long	ips_cantforward;	/* packets rcvd for unreachable dest */
117df8bae1dSRodney W. Grimes 	u_long	ips_redirectsent;	/* packets forwarded on same net */
118df8bae1dSRodney W. Grimes 	u_long	ips_noproto;		/* unknown or unsupported protocol */
119df8bae1dSRodney W. Grimes 	u_long	ips_delivered;		/* datagrams delivered to upper level*/
120df8bae1dSRodney W. Grimes 	u_long	ips_localout;		/* total ip packets generated here */
121df8bae1dSRodney W. Grimes 	u_long	ips_odropped;		/* lost packets due to nobufs, etc. */
122df8bae1dSRodney W. Grimes 	u_long	ips_reassembled;	/* total packets reassembled ok */
1236c5e9bbdSMike Pritchard 	u_long	ips_fragmented;		/* datagrams successfully fragmented */
124df8bae1dSRodney W. Grimes 	u_long	ips_ofragments;		/* output fragments created */
125df8bae1dSRodney W. Grimes 	u_long	ips_cantfrag;		/* don't fragment flag was set, etc. */
126df8bae1dSRodney W. Grimes 	u_long	ips_badoptions;		/* error in option processing */
127df8bae1dSRodney W. Grimes 	u_long	ips_noroute;		/* packets discarded due to no route */
128df8bae1dSRodney W. Grimes 	u_long	ips_badvers;		/* ip version != 4 */
129df8bae1dSRodney W. Grimes 	u_long	ips_rawout;		/* total raw ip packets generated */
130430d30d8SBill Fenner 	u_long	ips_toolong;		/* ip length > max ip packet size */
13182c39223SGarrett Wollman 	u_long	ips_notmember;		/* multicasts for unregistered grps */
13276429de4SYoshinobu Inoue 	u_long	ips_nogif;		/* no match gif found */
13333841545SHajimu UMEMOTO 	u_long	ips_badaddr;		/* invalid address on header */
134df8bae1dSRodney W. Grimes };
135df8bae1dSRodney W. Grimes 
136664a31e4SPeter Wemm #ifdef _KERNEL
1375914e1eaSBruce Evans 
138df8bae1dSRodney W. Grimes /* flags passed to ip_output as last parameter */
139df8bae1dSRodney W. Grimes #define	IP_FORWARDING		0x1		/* most of ip header exists */
140df8bae1dSRodney W. Grimes #define	IP_RAWOUTPUT		0x2		/* raw ip header exists */
141df8bae1dSRodney W. Grimes #define	IP_ROUTETOIF		SO_DONTROUTE	/* bypass routing tables */
142df8bae1dSRodney W. Grimes #define	IP_ALLOWBROADCAST	SO_BROADCAST	/* can send broadcast packets */
143df8bae1dSRodney W. Grimes 
144cfe8b629SGarrett Wollman struct ip;
145ca5d5e73SBruce Evans struct inpcb;
1465e26bd9aSBruce Evans struct route;
147cfe8b629SGarrett Wollman struct sockopt;
1485e26bd9aSBruce Evans 
149f23b4c91SGarrett Wollman extern struct	ipstat	ipstat;
15064dddc18SKris Kennaway #ifndef RANDOM_IP_ID
151f23b4c91SGarrett Wollman extern u_short	ip_id;				/* ip packet ctr, for ids */
15264dddc18SKris Kennaway #endif
153f23b4c91SGarrett Wollman extern int	ip_defttl;			/* default IP ttl */
1541f91d8c5SDavid Greenman extern int	ipforwarding;			/* ip forwarding */
1551e3d5af0SRuslan Ermilov extern struct route ipforward_rt;		/* ip forwarding cached route */
156b5e8ce9fSBruce Evans extern u_char	ip_protox[];
157f0068c4aSGarrett Wollman extern struct socket *ip_rsvpd;	/* reservation protocol daemon */
158f0068c4aSGarrett Wollman extern struct socket *ip_mrouter; /* multicast routing daemon */
1594d77a549SAlfred Perlstein extern int	(*legal_vif_num)(int);
1604d77a549SAlfred Perlstein extern u_long	(*ip_mcast_src)(int);
161b124e4f2SGarrett Wollman extern int rsvp_on;
162117bcae7SGarrett Wollman extern struct	pr_usrreqs rip_usrreqs;
163df8bae1dSRodney W. Grimes 
1644d77a549SAlfred Perlstein int	 ip_ctloutput(struct socket *, struct sockopt *sopt);
1654d77a549SAlfred Perlstein void	 ip_drain(void);
1664d77a549SAlfred Perlstein void	 ip_freemoptions(struct ip_moptions *);
1674d77a549SAlfred Perlstein void	 ip_init(void);
1684d77a549SAlfred Perlstein extern int	 (*ip_mforward)(struct ip *, struct ifnet *, struct mbuf *,
1694d77a549SAlfred Perlstein 			  struct ip_moptions *);
1704d77a549SAlfred Perlstein int	 ip_output(struct mbuf *,
1715d846453SSam Leffler 	    struct mbuf *, struct route *, int, struct ip_moptions *,
1725d846453SSam Leffler 	    struct inpcb *);
173bd714208SRuslan Ermilov struct in_ifaddr *
1744d77a549SAlfred Perlstein 	 ip_rtaddr(struct in_addr, struct route *);
1754d77a549SAlfred Perlstein void	 ip_savecontrol(struct inpcb *, struct mbuf **, struct ip *,
1764d77a549SAlfred Perlstein 		struct mbuf *);
1774d77a549SAlfred Perlstein void	 ip_slowtimo(void);
178df8bae1dSRodney W. Grimes struct mbuf *
1794d77a549SAlfred Perlstein 	 ip_srcroute(void);
1804d77a549SAlfred Perlstein void	 ip_stripoptions(struct mbuf *, struct mbuf *);
18164dddc18SKris Kennaway #ifdef RANDOM_IP_ID
18264dddc18SKris Kennaway u_int16_t
1834d77a549SAlfred Perlstein 	 ip_randomid(void);
18464dddc18SKris Kennaway #endif
1854d77a549SAlfred Perlstein int	rip_ctloutput(struct socket *, struct sockopt *);
1864d77a549SAlfred Perlstein void	rip_ctlinput(int, struct sockaddr *, void *);
1874d77a549SAlfred Perlstein void	rip_init(void);
1884d77a549SAlfred Perlstein void	rip_input(struct mbuf *, int);
1894d77a549SAlfred Perlstein int	rip_output(struct mbuf *, struct socket *, u_long);
1904d77a549SAlfred Perlstein void	ipip_input(struct mbuf *, int);
1914d77a549SAlfred Perlstein void	rsvp_input(struct mbuf *, int);
1924d77a549SAlfred Perlstein int	ip_rsvp_init(struct socket *);
1934d77a549SAlfred Perlstein int	ip_rsvp_done(void);
194bbb4330bSLuigi Rizzo extern int	(*ip_rsvp_vif)(struct socket *, struct sockopt *);
195bbb4330bSLuigi Rizzo extern void	(*ip_rsvp_force_done)(struct socket *);
196bbb4330bSLuigi Rizzo extern void	(*rsvp_input_p)(struct mbuf *m, int off);
197bbb4330bSLuigi Rizzo 
198d99c7a23SGarrett Wollman 
19993e0e116SJulian Elischer #ifdef IPDIVERT
2004d77a549SAlfred Perlstein void	div_init(void);
2014d77a549SAlfred Perlstein void	div_input(struct mbuf *, int);
2022b25acc1SLuigi Rizzo void	divert_packet(struct mbuf *m, int incoming, int port, int rule);
20377d1915bSPeter Wemm extern struct pr_usrreqs div_usrreqs;
2045914e1eaSBruce Evans #endif
205f9e354dfSJulian Elischer 
2061c238475SJonathan Lemon void	in_delayed_cksum(struct mbuf *m);
2071c238475SJonathan Lemon 
208664a31e4SPeter Wemm #endif /* _KERNEL */
209707f139eSPaul Richards 
2105914e1eaSBruce Evans #endif /* !_NETINET_IP_VAR_H_ */
211