ip_var.h revision 60765
1219820Sjeff/*
2219820Sjeff * Copyright (c) 1982, 1986, 1993
3219820Sjeff *	The Regents of the University of California.  All rights reserved.
4219820Sjeff *
5219820Sjeff * Redistribution and use in source and binary forms, with or without
6219820Sjeff * modification, are permitted provided that the following conditions
7219820Sjeff * are met:
8219820Sjeff * 1. Redistributions of source code must retain the above copyright
9219820Sjeff *    notice, this list of conditions and the following disclaimer.
10219820Sjeff * 2. Redistributions in binary form must reproduce the above copyright
11219820Sjeff *    notice, this list of conditions and the following disclaimer in the
12219820Sjeff *    documentation and/or other materials provided with the distribution.
13219820Sjeff * 3. All advertising materials mentioning features or use of this software
14219820Sjeff *    must display the following acknowledgement:
15219820Sjeff *	This product includes software developed by the University of
16219820Sjeff *	California, Berkeley and its contributors.
17219820Sjeff * 4. Neither the name of the University nor the names of its contributors
18219820Sjeff *    may be used to endorse or promote products derived from this software
19219820Sjeff *    without specific prior written permission.
20219820Sjeff *
21219820Sjeff * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22219820Sjeff * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23219820Sjeff * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24219820Sjeff * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25219820Sjeff * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26219820Sjeff * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27219820Sjeff * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28219820Sjeff * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29219820Sjeff * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30219820Sjeff * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31219820Sjeff * SUCH DAMAGE.
32219820Sjeff *
33219820Sjeff *	@(#)ip_var.h	8.2 (Berkeley) 1/9/95
34219820Sjeff * $FreeBSD: head/sys/netinet/ip_var.h 60765 2000-05-21 21:26:06Z jlemon $
35219820Sjeff */
36219820Sjeff
37219820Sjeff#ifndef _NETINET_IP_VAR_H_
38219820Sjeff#define	_NETINET_IP_VAR_H_
39219820Sjeff
40219820Sjeff/*
41219820Sjeff * Overlay for ip header used by other protocols (tcp, udp).
42219820Sjeff */
43219820Sjeffstruct ipovly {
44219820Sjeff	u_char	ih_x1[9];		/* (unused) */
45219820Sjeff	u_char	ih_pr;			/* protocol */
46219820Sjeff	u_short	ih_len;			/* protocol length */
47219820Sjeff	struct	in_addr ih_src;		/* source internet address */
48219820Sjeff	struct	in_addr ih_dst;		/* destination internet address */
49219820Sjeff};
50219820Sjeff
51219820Sjeff/*
52219820Sjeff * Ip reassembly queue structure.  Each fragment
53219820Sjeff * being reassembled is attached to one of these structures.
54219820Sjeff * They are timed out after ipq_ttl drops to 0, and may also
55219820Sjeff * be reclaimed if memory becomes tight.
56219820Sjeff */
57219820Sjeffstruct ipq {
58219820Sjeff	struct	ipq *next,*prev;	/* to other reass headers */
59219820Sjeff	u_char	ipq_ttl;		/* time for reass q to live */
60219820Sjeff	u_char	ipq_p;			/* protocol of this fragment */
61219820Sjeff	u_short	ipq_id;			/* sequence id for reassembly */
62219820Sjeff	struct mbuf *ipq_frags;		/* to ip headers of fragments */
63219820Sjeff	struct	in_addr ipq_src,ipq_dst;
64219820Sjeff#ifdef IPDIVERT
65219820Sjeff	u_int32_t ipq_div_info;		/* ipfw divert port & flags */
66219820Sjeff	u_int16_t ipq_div_cookie;	/* ipfw divert cookie */
67219820Sjeff#endif
68219820Sjeff};
69219820Sjeff
70219820Sjeff/*
71219820Sjeff * Structure stored in mbuf in inpcb.ip_options
72219820Sjeff * and passed to ip_output when ip options are in use.
73219820Sjeff * The actual length of the options (including ipopt_dst)
74219820Sjeff * is in m_len.
75219820Sjeff */
76219820Sjeff#define MAX_IPOPTLEN	40
77219820Sjeff
78219820Sjeffstruct ipoption {
79219820Sjeff	struct	in_addr ipopt_dst;	/* first-hop dst if source routed */
80219820Sjeff	char	ipopt_list[MAX_IPOPTLEN];	/* options proper */
81219820Sjeff};
82219820Sjeff
83219820Sjeff/*
84219820Sjeff * Structure attached to inpcb.ip_moptions and
85219820Sjeff * passed to ip_output when IP multicast options are in use.
86219820Sjeff */
87219820Sjeffstruct ip_moptions {
88219820Sjeff	struct	ifnet *imo_multicast_ifp; /* ifp for outgoing multicasts */
89219820Sjeff	u_char	imo_multicast_ttl;	/* TTL for outgoing multicasts */
90219820Sjeff	u_char	imo_multicast_loop;	/* 1 => hear sends if a member */
91219820Sjeff	u_short	imo_num_memberships;	/* no. memberships this socket */
92219820Sjeff	struct	in_multi *imo_membership[IP_MAX_MEMBERSHIPS];
93219820Sjeff	u_long	imo_multicast_vif;	/* vif num outgoing multicasts */
94219820Sjeff};
95219820Sjeff
96219820Sjeffstruct	ipstat {
97219820Sjeff	u_long	ips_total;		/* total packets received */
98219820Sjeff	u_long	ips_badsum;		/* checksum bad */
99219820Sjeff	u_long	ips_tooshort;		/* packet too short */
100219820Sjeff	u_long	ips_toosmall;		/* not enough data */
101219820Sjeff	u_long	ips_badhlen;		/* ip header length < data size */
102219820Sjeff	u_long	ips_badlen;		/* ip length < ip header length */
103219820Sjeff	u_long	ips_fragments;		/* fragments received */
104219820Sjeff	u_long	ips_fragdropped;	/* frags dropped (dups, out of space) */
105219820Sjeff	u_long	ips_fragtimeout;	/* fragments timed out */
106219820Sjeff	u_long	ips_forward;		/* packets forwarded */
107219820Sjeff	u_long	ips_fastforward;	/* packets fast forwarded */
108219820Sjeff	u_long	ips_cantforward;	/* packets rcvd for unreachable dest */
109219820Sjeff	u_long	ips_redirectsent;	/* packets forwarded on same net */
110219820Sjeff	u_long	ips_noproto;		/* unknown or unsupported protocol */
111219820Sjeff	u_long	ips_delivered;		/* datagrams delivered to upper level*/
112219820Sjeff	u_long	ips_localout;		/* total ip packets generated here */
113219820Sjeff	u_long	ips_odropped;		/* lost packets due to nobufs, etc. */
114219820Sjeff	u_long	ips_reassembled;	/* total packets reassembled ok */
115219820Sjeff	u_long	ips_fragmented;		/* datagrams successfully fragmented */
116219820Sjeff	u_long	ips_ofragments;		/* output fragments created */
117219820Sjeff	u_long	ips_cantfrag;		/* don't fragment flag was set, etc. */
118219820Sjeff	u_long	ips_badoptions;		/* error in option processing */
119219820Sjeff	u_long	ips_noroute;		/* packets discarded due to no route */
120219820Sjeff	u_long	ips_badvers;		/* ip version != 4 */
121219820Sjeff	u_long	ips_rawout;		/* total raw ip packets generated */
122219820Sjeff	u_long	ips_toolong;		/* ip length > max ip packet size */
123219820Sjeff	u_long	ips_notmember;		/* multicasts for unregistered grps */
124219820Sjeff	u_long	ips_nogif;		/* no match gif found */
125219820Sjeff};
126219820Sjeff
127219820Sjeff#ifdef _KERNEL
128219820Sjeff
129219820Sjeff/* flags passed to ip_output as last parameter */
130219820Sjeff#define	IP_FORWARDING		0x1		/* most of ip header exists */
131219820Sjeff#define	IP_RAWOUTPUT		0x2		/* raw ip header exists */
132219820Sjeff#define	IP_ROUTETOIF		SO_DONTROUTE	/* bypass routing tables */
133219820Sjeff#define	IP_ALLOWBROADCAST	SO_BROADCAST	/* can send broadcast packets */
134219820Sjeff#define	IP_SOCKINMRCVIF		0x100		/* IPSEC hack;
135219820Sjeff						 * socket pointer in sending
136219820Sjeff						 * packet's m_pkthdr.rcvif */
137219820Sjeff
138219820Sjeffstruct ip;
139219820Sjeffstruct inpcb;
140219820Sjeffstruct route;
141219820Sjeffstruct sockopt;
142219820Sjeff
143248084Sattilioextern struct	ipstat	ipstat;
144219820Sjeffextern u_short	ip_id;				/* ip packet ctr, for ids */
145219820Sjeffextern int	ip_defttl;			/* default IP ttl */
146248084Sattilioextern int	ipforwarding;			/* ip forwarding */
147219820Sjeffextern u_char	ip_protox[];
148219820Sjeffextern struct socket *ip_rsvpd;	/* reservation protocol daemon */
149219820Sjeffextern struct socket *ip_mrouter; /* multicast routing daemon */
150219820Sjeffextern int	(*legal_vif_num) __P((int));
151219820Sjeffextern u_long	(*ip_mcast_src) __P((int));
152219820Sjeffextern int rsvp_on;
153219820Sjeffextern struct	pr_usrreqs rip_usrreqs;
154248084Sattilio
155219820Sjeffint	 ip_ctloutput __P((struct socket *, struct sockopt *sopt));
156219820Sjeffvoid	 ip_drain __P((void));
157219820Sjeffvoid	 ip_freemoptions __P((struct ip_moptions *));
158219820Sjeffvoid	 ip_init __P((void));
159219820Sjeffextern int	 (*ip_mforward) __P((struct ip *, struct ifnet *, struct mbuf *,
160219820Sjeff			  struct ip_moptions *));
161219820Sjeffint	 ip_output __P((struct mbuf *,
162219820Sjeff	    struct mbuf *, struct route *, int, struct ip_moptions *));
163219820Sjeffvoid	 ip_savecontrol __P((struct inpcb *, struct mbuf **, struct ip *,
164219820Sjeff		struct mbuf *));
165219820Sjeffvoid	 ip_slowtimo __P((void));
166219820Sjeffstruct mbuf *
167219820Sjeff	 ip_srcroute __P((void));
168219820Sjeffvoid	 ip_stripoptions __P((struct mbuf *, struct mbuf *));
169219820Sjeffint	 rip_ctloutput __P((struct socket *, struct sockopt *));
170219820Sjeffvoid	 rip_ctlinput __P((int, struct sockaddr *, void *));
171219820Sjeffvoid	 rip_init __P((void));
172219820Sjeffvoid	 rip_input __P((struct mbuf *, int, int));
173219820Sjeffint	 rip_output __P((struct mbuf *, struct socket *, u_long));
174219820Sjeffvoid	ipip_input __P((struct mbuf *, int, int));
175219820Sjeffvoid	rsvp_input __P((struct mbuf *, int, int));
176219820Sjeffint	ip_rsvp_init __P((struct socket *));
177219820Sjeffint	ip_rsvp_done __P((void));
178219820Sjeffint	ip_rsvp_vif_init __P((struct socket *, struct sockopt *));
179219820Sjeffint	ip_rsvp_vif_done __P((struct socket *, struct sockopt *));
180219820Sjeffvoid	ip_rsvp_force_done __P((struct socket *));
181219820Sjeff
182219820Sjeff#ifdef IPDIVERT
183219820Sjeffvoid	div_init __P((void));
184219820Sjeffvoid	div_input __P((struct mbuf *, int, int));
185219820Sjeffvoid	divert_packet __P((struct mbuf *, int, int));
186219820Sjeffextern struct pr_usrreqs div_usrreqs;
187219820Sjeffextern u_int16_t ip_divert_cookie;
188219820Sjeff#endif
189219820Sjeff
190219820Sjeffextern struct sockaddr_in *ip_fw_fwd_addr;
191219820Sjeff
192219820Sjeffvoid	in_delayed_cksum(struct mbuf *m);
193219820Sjeff
194219820Sjeff#endif /* _KERNEL */
195219820Sjeff
196219820Sjeff#endif /* !_NETINET_IP_VAR_H_ */
197219820Sjeff