ip.h revision 50477
1169695Skan/*
2169695Skan * Copyright (c) 1982, 1986, 1993
3169695Skan *	The Regents of the University of California.  All rights reserved.
4169695Skan *
5169695Skan * Redistribution and use in source and binary forms, with or without
6169695Skan * modification, are permitted provided that the following conditions
7169695Skan * are met:
8169695Skan * 1. Redistributions of source code must retain the above copyright
9169695Skan *    notice, this list of conditions and the following disclaimer.
10169695Skan * 2. Redistributions in binary form must reproduce the above copyright
11169695Skan *    notice, this list of conditions and the following disclaimer in the
12169695Skan *    documentation and/or other materials provided with the distribution.
13169695Skan * 3. All advertising materials mentioning features or use of this software
14169695Skan *    must display the following acknowledgement:
15169695Skan *	This product includes software developed by the University of
16169695Skan *	California, Berkeley and its contributors.
17169695Skan * 4. Neither the name of the University nor the names of its contributors
18169695Skan *    may be used to endorse or promote products derived from this software
19169695Skan *    without specific prior written permission.
20169695Skan *
21169695Skan * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22169695Skan * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23169695Skan * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24169695Skan * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25169695Skan * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26169695Skan * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27169695Skan * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28169695Skan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29169695Skan * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30169695Skan * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31169695Skan * SUCH DAMAGE.
32169695Skan *
33169695Skan *	@(#)ip.h	8.2 (Berkeley) 6/1/94
34169695Skan * $FreeBSD: head/sys/netinet/ip.h 50477 1999-08-28 01:08:13Z peter $
35169695Skan */
36169695Skan
37169695Skan#ifndef _NETINET_IP_H_
38169695Skan#define _NETINET_IP_H_
39169695Skan
40169695Skan/*
41169695Skan * Definitions for internet protocol version 4.
42169695Skan * Per RFC 791, September 1981.
43169695Skan */
44169695Skan#define	IPVERSION	4
45169695Skan
46169695Skan/*
47169695Skan * Structure of an internet header, naked of options.
48169695Skan */
49169695Skanstruct ip {
50169695Skan#ifdef _IP_VHL
51169695Skan	u_char	ip_vhl;			/* version << 4 | header length >> 2 */
52169695Skan#else
53169695Skan#if BYTE_ORDER == LITTLE_ENDIAN
54169695Skan	u_int	ip_hl:4,		/* header length */
55169695Skan		ip_v:4;			/* version */
56169695Skan#endif
57169695Skan#if BYTE_ORDER == BIG_ENDIAN
58169695Skan	u_int	ip_v:4,			/* version */
59169695Skan		ip_hl:4;		/* header length */
60169695Skan#endif
61169695Skan#endif /* not _IP_VHL */
62169695Skan	u_char	ip_tos;			/* type of service */
63169695Skan	u_short	ip_len;			/* total length */
64169695Skan	u_short	ip_id;			/* identification */
65169695Skan	u_short	ip_off;			/* fragment offset field */
66169695Skan#define	IP_RF 0x8000			/* reserved fragment flag */
67169695Skan#define	IP_DF 0x4000			/* dont fragment flag */
68169695Skan#define	IP_MF 0x2000			/* more fragments flag */
69169695Skan#define	IP_OFFMASK 0x1fff		/* mask for fragmenting bits */
70169695Skan	u_char	ip_ttl;			/* time to live */
71169695Skan	u_char	ip_p;			/* protocol */
72169695Skan	u_short	ip_sum;			/* checksum */
73169695Skan	struct	in_addr ip_src,ip_dst;	/* source and dest address */
74169695Skan};
75169695Skan
76169695Skan#ifdef _IP_VHL
77169695Skan#define	IP_MAKE_VHL(v, hl)	((v) << 4 | (hl))
78169695Skan#define	IP_VHL_HL(vhl)		((vhl) & 0x0f)
79169695Skan#define	IP_VHL_V(vhl)		((vhl) >> 4)
80169695Skan#define	IP_VHL_BORING		0x45
81169695Skan#endif
82169695Skan
83169695Skan#define	IP_MAXPACKET	65535		/* maximum packet size */
84169695Skan
85169695Skan/*
86169695Skan * Definitions for IP type of service (ip_tos)
87169695Skan */
88169695Skan#define	IPTOS_LOWDELAY		0x10
89169695Skan#define	IPTOS_THROUGHPUT	0x08
90169695Skan#define	IPTOS_RELIABILITY	0x04
91169695Skan#define	IPTOS_MINCOST		0x02
92169695Skan
93169695Skan/*
94169695Skan * Definitions for IP precedence (also in ip_tos) (hopefully unused)
95169695Skan */
96169695Skan#define	IPTOS_PREC_NETCONTROL		0xe0
97169695Skan#define	IPTOS_PREC_INTERNETCONTROL	0xc0
98169695Skan#define	IPTOS_PREC_CRITIC_ECP		0xa0
99169695Skan#define	IPTOS_PREC_FLASHOVERRIDE	0x80
100169695Skan#define	IPTOS_PREC_FLASH		0x60
101169695Skan#define	IPTOS_PREC_IMMEDIATE		0x40
102169695Skan#define	IPTOS_PREC_PRIORITY		0x20
103169695Skan#define	IPTOS_PREC_ROUTINE		0x00
104169695Skan
105169695Skan/*
106169695Skan * Definitions for options.
107169695Skan */
108169695Skan#define	IPOPT_COPIED(o)		((o)&0x80)
109169695Skan#define	IPOPT_CLASS(o)		((o)&0x60)
110169695Skan#define	IPOPT_NUMBER(o)		((o)&0x1f)
111169695Skan
112169695Skan#define	IPOPT_CONTROL		0x00
113169695Skan#define	IPOPT_RESERVED1		0x20
114169695Skan#define	IPOPT_DEBMEAS		0x40
115169695Skan#define	IPOPT_RESERVED2		0x60
116169695Skan
117169695Skan#define	IPOPT_EOL		0		/* end of option list */
118169695Skan#define	IPOPT_NOP		1		/* no operation */
119169695Skan
120169695Skan#define	IPOPT_RR		7		/* record packet route */
121169695Skan#define	IPOPT_TS		68		/* timestamp */
122169695Skan#define	IPOPT_SECURITY		130		/* provide s,c,h,tcc */
123169695Skan#define	IPOPT_LSRR		131		/* loose source route */
124169695Skan#define	IPOPT_SATID		136		/* satnet id */
125169695Skan#define	IPOPT_SSRR		137		/* strict source route */
126169695Skan#define	IPOPT_RA		148		/* router alert */
127169695Skan
128169695Skan/*
129169695Skan * Offsets to fields in options other than EOL and NOP.
130169695Skan */
131169695Skan#define	IPOPT_OPTVAL		0		/* option ID */
132169695Skan#define	IPOPT_OLEN		1		/* option length */
133169695Skan#define IPOPT_OFFSET		2		/* offset within option */
134169695Skan#define	IPOPT_MINOFF		4		/* min value of above */
135169695Skan
136169695Skan/*
137169695Skan * Time stamp option structure.
138169695Skan */
139169695Skanstruct	ip_timestamp {
140169695Skan	u_char	ipt_code;		/* IPOPT_TS */
141169695Skan	u_char	ipt_len;		/* size of structure (variable) */
142169695Skan	u_char	ipt_ptr;		/* index of current entry */
143169695Skan#if BYTE_ORDER == LITTLE_ENDIAN
144169695Skan	u_int	ipt_flg:4,		/* flags, see below */
145169695Skan		ipt_oflw:4;		/* overflow counter */
146169695Skan#endif
147169695Skan#if BYTE_ORDER == BIG_ENDIAN
148169695Skan	u_int	ipt_oflw:4,		/* overflow counter */
149169695Skan		ipt_flg:4;		/* flags, see below */
150169695Skan#endif
151169695Skan	union ipt_timestamp {
152169695Skan		n_long	ipt_time[1];
153169695Skan		struct	ipt_ta {
154169695Skan			struct in_addr ipt_addr;
155169695Skan			n_long ipt_time;
156169695Skan		} ipt_ta[1];
157169695Skan	} ipt_timestamp;
158169695Skan};
159169695Skan
160169695Skan/* flag bits for ipt_flg */
161169695Skan#define	IPOPT_TS_TSONLY		0		/* timestamps only */
162169695Skan#define	IPOPT_TS_TSANDADDR	1		/* timestamps and addresses */
163169695Skan#define	IPOPT_TS_PRESPEC	3		/* specified modules only */
164169695Skan
165169695Skan/* bits for security (not byte swapped) */
166169695Skan#define	IPOPT_SECUR_UNCLASS	0x0000
167169695Skan#define	IPOPT_SECUR_CONFID	0xf135
168169695Skan#define	IPOPT_SECUR_EFTO	0x789a
169169695Skan#define	IPOPT_SECUR_MMMM	0xbc4d
170169695Skan#define	IPOPT_SECUR_RESTR	0xaf13
171169695Skan#define	IPOPT_SECUR_SECRET	0xd788
172169695Skan#define	IPOPT_SECUR_TOPSECRET	0x6bc5
173169695Skan
174169695Skan/*
175169695Skan * Internet implementation parameters.
176169695Skan */
177169695Skan#define	MAXTTL		255		/* maximum time to live (seconds) */
178169695Skan#define	IPDEFTTL	64		/* default ttl, from RFC 1340 */
179169695Skan#define	IPFRAGTTL	60		/* time to live for frags, slowhz */
180169695Skan#define	IPTTLDEC	1		/* subtracted when forwarding */
181169695Skan
182169695Skan#define	IP_MSS		576		/* default maximum segment size */
183169695Skan
184169695Skan#endif
185169695Skan