ip_var.h revision 121093
1171626Scognet/*
2171626Scognet * Copyright (c) 1982, 1986, 1993
3171626Scognet *	The Regents of the University of California.  All rights reserved.
4171626Scognet *
5171626Scognet * Redistribution and use in source and binary forms, with or without
6171626Scognet * modification, are permitted provided that the following conditions
7171626Scognet * are met:
8171626Scognet * 1. Redistributions of source code must retain the above copyright
9171626Scognet *    notice, this list of conditions and the following disclaimer.
10171626Scognet * 2. Redistributions in binary form must reproduce the above copyright
11171626Scognet *    notice, this list of conditions and the following disclaimer in the
12171626Scognet *    documentation and/or other materials provided with the distribution.
13171626Scognet * 3. All advertising materials mentioning features or use of this software
14171626Scognet *    must display the following acknowledgement:
15171626Scognet *	This product includes software developed by the University of
16171626Scognet *	California, Berkeley and its contributors.
17171626Scognet * 4. Neither the name of the University nor the names of its contributors
18171626Scognet *    may be used to endorse or promote products derived from this software
19171626Scognet *    without specific prior written permission.
20171626Scognet *
21171626Scognet * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22171626Scognet * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23171626Scognet * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24171626Scognet * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25171626Scognet * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26171626Scognet * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27171626Scognet * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28171626Scognet * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29171626Scognet * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30171626Scognet * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31171626Scognet * SUCH DAMAGE.
32171626Scognet *
33171626Scognet *	@(#)ip_var.h	8.2 (Berkeley) 1/9/95
34171626Scognet * $FreeBSD: head/sys/netinet/ip_var.h 121093 2003-10-14 19:19:12Z sam $
35171626Scognet */
36171626Scognet
37171626Scognet#ifndef _NETINET_IP_VAR_H_
38171626Scognet#define	_NETINET_IP_VAR_H_
39171626Scognet
40171626Scognet#include <sys/queue.h>
41171626Scognet
42171626Scognet#ifdef _KERNEL
43171626Scognet#include <sys/_label.h>
44171626Scognet#endif
45171626Scognet
46171626Scognet/*
47171626Scognet * Overlay for ip header used by other protocols (tcp, udp).
48171626Scognet */
49171626Scognetstruct ipovly {
50171626Scognet	u_char	ih_x1[9];		/* (unused) */
51171626Scognet	u_char	ih_pr;			/* protocol */
52171626Scognet	u_short	ih_len;			/* protocol length */
53171626Scognet	struct	in_addr ih_src;		/* source internet address */
54171626Scognet	struct	in_addr ih_dst;		/* destination internet address */
55171626Scognet};
56171626Scognet
57171626Scognet#ifdef _KERNEL
58171626Scognet/*
59171626Scognet * Ip reassembly queue structure.  Each fragment
60171626Scognet * being reassembled is attached to one of these structures.
61171626Scognet * They are timed out after ipq_ttl drops to 0, and may also
62171626Scognet * be reclaimed if memory becomes tight.
63171626Scognet */
64171626Scognetstruct ipq {
65171626Scognet	TAILQ_ENTRY(ipq) ipq_list;	/* to other reass headers */
66171626Scognet	u_char	ipq_ttl;		/* time for reass q to live */
67171626Scognet	u_char	ipq_p;			/* protocol of this fragment */
68171626Scognet	u_short	ipq_id;			/* sequence id for reassembly */
69171626Scognet	struct mbuf *ipq_frags;		/* to ip headers of fragments */
70171626Scognet	struct	in_addr ipq_src,ipq_dst;
71171626Scognet	u_char	ipq_nfrags;		/* # frags in this packet */
72171626Scognet	u_int32_t ipq_div_info;		/* ipfw divert port & flags */
73171626Scognet	u_int16_t ipq_div_cookie;	/* ipfw divert cookie */
74171626Scognet	struct label ipq_label;		/* MAC label */
75171626Scognet};
76171626Scognet#endif /* _KERNEL */
77171626Scognet
78171626Scognet/*
79171626Scognet * Structure stored in mbuf in inpcb.ip_options
80171626Scognet * and passed to ip_output when ip options are in use.
81171626Scognet * The actual length of the options (including ipopt_dst)
82171626Scognet * is in m_len.
83171626Scognet */
84171626Scognet#define MAX_IPOPTLEN	40
85171626Scognet
86171626Scognetstruct ipoption {
87171626Scognet	struct	in_addr ipopt_dst;	/* first-hop dst if source routed */
88171626Scognet	char	ipopt_list[MAX_IPOPTLEN];	/* options proper */
89171626Scognet};
90171626Scognet
91171626Scognet/*
92171626Scognet * Structure attached to inpcb.ip_moptions and
93171626Scognet * passed to ip_output when IP multicast options are in use.
94171626Scognet */
95171626Scognetstruct ip_moptions {
96171626Scognet	struct	ifnet *imo_multicast_ifp; /* ifp for outgoing multicasts */
97171626Scognet	struct in_addr imo_multicast_addr; /* ifindex/addr on MULTICAST_IF */
98171626Scognet	u_char	imo_multicast_ttl;	/* TTL for outgoing multicasts */
99171626Scognet	u_char	imo_multicast_loop;	/* 1 => hear sends if a member */
100171626Scognet	u_short	imo_num_memberships;	/* no. memberships this socket */
101171626Scognet	struct	in_multi *imo_membership[IP_MAX_MEMBERSHIPS];
102171626Scognet	u_long	imo_multicast_vif;	/* vif num outgoing multicasts */
103171626Scognet};
104171626Scognet
105171626Scognetstruct	ipstat {
106171626Scognet	u_long	ips_total;		/* total packets received */
107171626Scognet	u_long	ips_badsum;		/* checksum bad */
108171626Scognet	u_long	ips_tooshort;		/* packet too short */
109171626Scognet	u_long	ips_toosmall;		/* not enough data */
110171626Scognet	u_long	ips_badhlen;		/* ip header length < data size */
111171626Scognet	u_long	ips_badlen;		/* ip length < ip header length */
112171626Scognet	u_long	ips_fragments;		/* fragments received */
113171626Scognet	u_long	ips_fragdropped;	/* frags dropped (dups, out of space) */
114171626Scognet	u_long	ips_fragtimeout;	/* fragments timed out */
115171626Scognet	u_long	ips_forward;		/* packets forwarded */
116171626Scognet	u_long	ips_fastforward;	/* packets fast forwarded */
117171626Scognet	u_long	ips_cantforward;	/* packets rcvd for unreachable dest */
118171626Scognet	u_long	ips_redirectsent;	/* packets forwarded on same net */
119171626Scognet	u_long	ips_noproto;		/* unknown or unsupported protocol */
120171626Scognet	u_long	ips_delivered;		/* datagrams delivered to upper level*/
121171626Scognet	u_long	ips_localout;		/* total ip packets generated here */
122171626Scognet	u_long	ips_odropped;		/* lost packets due to nobufs, etc. */
123171626Scognet	u_long	ips_reassembled;	/* total packets reassembled ok */
124171626Scognet	u_long	ips_fragmented;		/* datagrams successfully fragmented */
125171626Scognet	u_long	ips_ofragments;		/* output fragments created */
126171626Scognet	u_long	ips_cantfrag;		/* don't fragment flag was set, etc. */
127171626Scognet	u_long	ips_badoptions;		/* error in option processing */
128171626Scognet	u_long	ips_noroute;		/* packets discarded due to no route */
129171626Scognet	u_long	ips_badvers;		/* ip version != 4 */
130171626Scognet	u_long	ips_rawout;		/* total raw ip packets generated */
131171626Scognet	u_long	ips_toolong;		/* ip length > max ip packet size */
132171626Scognet	u_long	ips_notmember;		/* multicasts for unregistered grps */
133171626Scognet	u_long	ips_nogif;		/* no match gif found */
134171626Scognet	u_long	ips_badaddr;		/* invalid address on header */
135171626Scognet};
136171626Scognet
137171626Scognet#ifdef _KERNEL
138171626Scognet
139171626Scognet/* flags passed to ip_output as last parameter */
140171626Scognet#define	IP_FORWARDING		0x1		/* most of ip header exists */
141171626Scognet#define	IP_RAWOUTPUT		0x2		/* raw ip header exists */
142171626Scognet#define	IP_SENDONES		0x4		/* send all-ones broadcast */
143171626Scognet#define	IP_ROUTETOIF		SO_DONTROUTE	/* bypass routing tables */
144171626Scognet#define	IP_ALLOWBROADCAST	SO_BROADCAST	/* can send broadcast packets */
145171626Scognet
146171626Scognetstruct ip;
147171626Scognetstruct inpcb;
148171626Scognetstruct route;
149171626Scognetstruct sockopt;
150171626Scognet
151171626Scognetextern struct	ipstat	ipstat;
152171626Scognet#ifndef RANDOM_IP_ID
153171626Scognetextern u_short	ip_id;				/* ip packet ctr, for ids */
154171626Scognet#endif
155171626Scognetextern int	ip_defttl;			/* default IP ttl */
156171626Scognetextern int	ipforwarding;			/* ip forwarding */
157171626Scognetextern u_char	ip_protox[];
158171626Scognetextern struct socket *ip_rsvpd;	/* reservation protocol daemon */
159171626Scognetextern struct socket *ip_mrouter; /* multicast routing daemon */
160171626Scognetextern int	(*legal_vif_num)(int);
161171626Scognetextern u_long	(*ip_mcast_src)(int);
162171626Scognetextern int rsvp_on;
163171626Scognetextern struct	pr_usrreqs rip_usrreqs;
164171626Scognet
165171626Scognetint	 ip_ctloutput(struct socket *, struct sockopt *sopt);
166171626Scognetvoid	 ip_drain(void);
167171626Scognetint	 ip_fragment(struct ip *ip, struct mbuf **m_frag, int mtu,
168171626Scognet	    u_long if_hwassist_flags, int sw_csum);
169171626Scognetvoid	 ip_forward_cacheinval(void);
170171626Scognetvoid	 ip_freemoptions(struct ip_moptions *);
171171626Scognetvoid	 ip_init(void);
172171626Scognetextern int	 (*ip_mforward)(struct ip *, struct ifnet *, struct mbuf *,
173171626Scognet			  struct ip_moptions *);
174171626Scognetint	 ip_output(struct mbuf *,
175171626Scognet	    struct mbuf *, struct route *, int, struct ip_moptions *,
176171626Scognet	    struct inpcb *);
177171626Scognetstruct in_ifaddr *
178171626Scognet	 ip_rtaddr(struct in_addr, struct route *);
179171626Scognetvoid	 ip_savecontrol(struct inpcb *, struct mbuf **, struct ip *,
180171626Scognet		struct mbuf *);
181171626Scognetvoid	 ip_slowtimo(void);
182171626Scognetstruct mbuf *
183171626Scognet	 ip_srcroute(void);
184171626Scognetvoid	 ip_stripoptions(struct mbuf *, struct mbuf *);
185171626Scognet#ifdef RANDOM_IP_ID
186171626Scognetu_int16_t
187171626Scognet	 ip_randomid(void);
188171626Scognet#endif
189171626Scognetint	rip_ctloutput(struct socket *, struct sockopt *);
190171626Scognetvoid	rip_ctlinput(int, struct sockaddr *, void *);
191171626Scognetvoid	rip_init(void);
192171626Scognetvoid	rip_input(struct mbuf *, int);
193171626Scognetint	rip_output(struct mbuf *, struct socket *, u_long);
194171626Scognetvoid	ipip_input(struct mbuf *, int);
195171626Scognetvoid	rsvp_input(struct mbuf *, int);
196171626Scognetint	ip_rsvp_init(struct socket *);
197171626Scognetint	ip_rsvp_done(void);
198171626Scognetextern int	(*ip_rsvp_vif)(struct socket *, struct sockopt *);
199171626Scognetextern void	(*ip_rsvp_force_done)(struct socket *);
200171626Scognetextern void	(*rsvp_input_p)(struct mbuf *m, int off);
201171626Scognet
202171626Scognet
203171626Scognet#ifdef IPDIVERT
204171626Scognetvoid	div_init(void);
205171626Scognetvoid	div_input(struct mbuf *, int);
206171626Scognetvoid	divert_packet(struct mbuf *m, int incoming, int port, int rule);
207171626Scognetextern struct pr_usrreqs div_usrreqs;
208171626Scognet#endif
209171626Scognet
210171626Scognet#ifdef PFIL_HOOKS
211171626Scognetextern	struct pfil_head inet_pfil_hook;
212171626Scognet#endif
213171626Scognet
214171626Scognetvoid	in_delayed_cksum(struct mbuf *m);
215171626Scognet
216171626Scognet#endif /* _KERNEL */
217171626Scognet
218171626Scognet#endif /* !_NETINET_IP_VAR_H_ */
219171626Scognet