ip.h revision 121684
11541Srgrimes/*
21541Srgrimes * Copyright (c) 1982, 1986, 1993
31541Srgrimes *	The Regents of the University of California.  All rights reserved.
41541Srgrimes *
51541Srgrimes * Redistribution and use in source and binary forms, with or without
61541Srgrimes * modification, are permitted provided that the following conditions
71541Srgrimes * are met:
81541Srgrimes * 1. Redistributions of source code must retain the above copyright
91541Srgrimes *    notice, this list of conditions and the following disclaimer.
101541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
111541Srgrimes *    notice, this list of conditions and the following disclaimer in the
121541Srgrimes *    documentation and/or other materials provided with the distribution.
131541Srgrimes * 3. All advertising materials mentioning features or use of this software
141541Srgrimes *    must display the following acknowledgement:
151541Srgrimes *	This product includes software developed by the University of
161541Srgrimes *	California, Berkeley and its contributors.
171541Srgrimes * 4. Neither the name of the University nor the names of its contributors
181541Srgrimes *    may be used to endorse or promote products derived from this software
191541Srgrimes *    without specific prior written permission.
201541Srgrimes *
211541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
221541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
231541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
241541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
251541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
261541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
271541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
281541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
291541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
301541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
311541Srgrimes * SUCH DAMAGE.
321541Srgrimes *
3310942Swollman *	@(#)ip.h	8.2 (Berkeley) 6/1/94
3450477Speter * $FreeBSD: head/sys/netinet/ip.h 121684 2003-10-29 15:07:04Z ume $
351541Srgrimes */
361541Srgrimes
372169Spaul#ifndef _NETINET_IP_H_
382169Spaul#define _NETINET_IP_H_
392169Spaul
40112482Smux#include <sys/cdefs.h>
41112482Smux
421541Srgrimes/*
431541Srgrimes * Definitions for internet protocol version 4.
441541Srgrimes * Per RFC 791, September 1981.
451541Srgrimes */
461541Srgrimes#define	IPVERSION	4
471541Srgrimes
481541Srgrimes/*
491541Srgrimes * Structure of an internet header, naked of options.
501541Srgrimes */
511541Srgrimesstruct ip {
528876Srgrimes#if BYTE_ORDER == LITTLE_ENDIAN
5336725Sbde	u_int	ip_hl:4,		/* header length */
541541Srgrimes		ip_v:4;			/* version */
551541Srgrimes#endif
568876Srgrimes#if BYTE_ORDER == BIG_ENDIAN
5736725Sbde	u_int	ip_v:4,			/* version */
581541Srgrimes		ip_hl:4;		/* header length */
591541Srgrimes#endif
601541Srgrimes	u_char	ip_tos;			/* type of service */
6119136Swollman	u_short	ip_len;			/* total length */
621541Srgrimes	u_short	ip_id;			/* identification */
6319136Swollman	u_short	ip_off;			/* fragment offset field */
6433851Sdima#define	IP_RF 0x8000			/* reserved fragment flag */
651541Srgrimes#define	IP_DF 0x4000			/* dont fragment flag */
661541Srgrimes#define	IP_MF 0x2000			/* more fragments flag */
671541Srgrimes#define	IP_OFFMASK 0x1fff		/* mask for fragmenting bits */
681541Srgrimes	u_char	ip_ttl;			/* time to live */
691541Srgrimes	u_char	ip_p;			/* protocol */
701541Srgrimes	u_short	ip_sum;			/* checksum */
711541Srgrimes	struct	in_addr ip_src,ip_dst;	/* source and dest address */
72112482Smux} __packed;
731541Srgrimes
74105586Sphk#ifdef CTASSERT
75105586SphkCTASSERT(sizeof (struct ip) == 20);
7615294Swollman#endif
7715294Swollman
781541Srgrimes#define	IP_MAXPACKET	65535		/* maximum packet size */
791541Srgrimes
801541Srgrimes/*
811541Srgrimes * Definitions for IP type of service (ip_tos)
821541Srgrimes */
831541Srgrimes#define	IPTOS_LOWDELAY		0x10
841541Srgrimes#define	IPTOS_THROUGHPUT	0x08
851541Srgrimes#define	IPTOS_RELIABILITY	0x04
868293Sache#define	IPTOS_MINCOST		0x02
87121684Sume#if 1
88121684Sume/* ECN RFC3168 obsoletes RFC2481, and these will be deprecated soon. */
89121684Sume#define	IPTOS_CE		0x01
90121684Sume#define	IPTOS_ECT		0x02
91121684Sume#endif
921541Srgrimes
931541Srgrimes/*
941541Srgrimes * Definitions for IP precedence (also in ip_tos) (hopefully unused)
951541Srgrimes */
961541Srgrimes#define	IPTOS_PREC_NETCONTROL		0xe0
971541Srgrimes#define	IPTOS_PREC_INTERNETCONTROL	0xc0
981541Srgrimes#define	IPTOS_PREC_CRITIC_ECP		0xa0
991541Srgrimes#define	IPTOS_PREC_FLASHOVERRIDE	0x80
1001541Srgrimes#define	IPTOS_PREC_FLASH		0x60
1011541Srgrimes#define	IPTOS_PREC_IMMEDIATE		0x40
1021541Srgrimes#define	IPTOS_PREC_PRIORITY		0x20
1038293Sache#define	IPTOS_PREC_ROUTINE		0x00
1041541Srgrimes
1051541Srgrimes/*
106121684Sume * ECN (Explicit Congestion Notification) codepoints in RFC3168
107121684Sume * mapped to the lower 2 bits of the TOS field.
108121684Sume */
109121684Sume#define	IPTOS_ECN_NOTECT	0x00	/* not-ECT */
110121684Sume#define	IPTOS_ECN_ECT1		0x01	/* ECN-capable transport (1) */
111121684Sume#define	IPTOS_ECN_ECT0		0x02	/* ECN-capable transport (0) */
112121684Sume#define	IPTOS_ECN_CE		0x03	/* congestion experienced */
113121684Sume#define	IPTOS_ECN_MASK		0x03	/* ECN field mask */
114121684Sume
115121684Sume/*
1161541Srgrimes * Definitions for options.
1171541Srgrimes */
1181541Srgrimes#define	IPOPT_COPIED(o)		((o)&0x80)
1191541Srgrimes#define	IPOPT_CLASS(o)		((o)&0x60)
1201541Srgrimes#define	IPOPT_NUMBER(o)		((o)&0x1f)
1211541Srgrimes
1221541Srgrimes#define	IPOPT_CONTROL		0x00
1231541Srgrimes#define	IPOPT_RESERVED1		0x20
1241541Srgrimes#define	IPOPT_DEBMEAS		0x40
1251541Srgrimes#define	IPOPT_RESERVED2		0x60
1261541Srgrimes
1271541Srgrimes#define	IPOPT_EOL		0		/* end of option list */
1281541Srgrimes#define	IPOPT_NOP		1		/* no operation */
1291541Srgrimes
1301541Srgrimes#define	IPOPT_RR		7		/* record packet route */
1311541Srgrimes#define	IPOPT_TS		68		/* timestamp */
1321541Srgrimes#define	IPOPT_SECURITY		130		/* provide s,c,h,tcc */
1331541Srgrimes#define	IPOPT_LSRR		131		/* loose source route */
13487919Srwatson#define	IPOPT_ESO		133		/* extended security */
13587917Srwatson#define	IPOPT_CIPSO		134		/* commerical security */
1361541Srgrimes#define	IPOPT_SATID		136		/* satnet id */
1371541Srgrimes#define	IPOPT_SSRR		137		/* strict source route */
13814622Sfenner#define	IPOPT_RA		148		/* router alert */
1391541Srgrimes
1401541Srgrimes/*
1411541Srgrimes * Offsets to fields in options other than EOL and NOP.
1421541Srgrimes */
1431541Srgrimes#define	IPOPT_OPTVAL		0		/* option ID */
1441541Srgrimes#define	IPOPT_OLEN		1		/* option length */
1451541Srgrimes#define IPOPT_OFFSET		2		/* offset within option */
1461541Srgrimes#define	IPOPT_MINOFF		4		/* min value of above */
1471541Srgrimes
1481541Srgrimes/*
1491541Srgrimes * Time stamp option structure.
1501541Srgrimes */
1511541Srgrimesstruct	ip_timestamp {
1521541Srgrimes	u_char	ipt_code;		/* IPOPT_TS */
1531541Srgrimes	u_char	ipt_len;		/* size of structure (variable) */
1541541Srgrimes	u_char	ipt_ptr;		/* index of current entry */
1558876Srgrimes#if BYTE_ORDER == LITTLE_ENDIAN
15636725Sbde	u_int	ipt_flg:4,		/* flags, see below */
1571541Srgrimes		ipt_oflw:4;		/* overflow counter */
1581541Srgrimes#endif
1598876Srgrimes#if BYTE_ORDER == BIG_ENDIAN
16036725Sbde	u_int	ipt_oflw:4,		/* overflow counter */
1611541Srgrimes		ipt_flg:4;		/* flags, see below */
1621541Srgrimes#endif
1631541Srgrimes	union ipt_timestamp {
1641541Srgrimes		n_long	ipt_time[1];
1651541Srgrimes		struct	ipt_ta {
1661541Srgrimes			struct in_addr ipt_addr;
1671541Srgrimes			n_long ipt_time;
1681541Srgrimes		} ipt_ta[1];
1691541Srgrimes	} ipt_timestamp;
1701541Srgrimes};
1711541Srgrimes
1721541Srgrimes/* flag bits for ipt_flg */
1731541Srgrimes#define	IPOPT_TS_TSONLY		0		/* timestamps only */
1741541Srgrimes#define	IPOPT_TS_TSANDADDR	1		/* timestamps and addresses */
1751541Srgrimes#define	IPOPT_TS_PRESPEC	3		/* specified modules only */
1761541Srgrimes
1771541Srgrimes/* bits for security (not byte swapped) */
1781541Srgrimes#define	IPOPT_SECUR_UNCLASS	0x0000
1791541Srgrimes#define	IPOPT_SECUR_CONFID	0xf135
1801541Srgrimes#define	IPOPT_SECUR_EFTO	0x789a
1811541Srgrimes#define	IPOPT_SECUR_MMMM	0xbc4d
1821541Srgrimes#define	IPOPT_SECUR_RESTR	0xaf13
1831541Srgrimes#define	IPOPT_SECUR_SECRET	0xd788
1841541Srgrimes#define	IPOPT_SECUR_TOPSECRET	0x6bc5
1851541Srgrimes
1861541Srgrimes/*
1871541Srgrimes * Internet implementation parameters.
1881541Srgrimes */
1891541Srgrimes#define	MAXTTL		255		/* maximum time to live (seconds) */
1901541Srgrimes#define	IPDEFTTL	64		/* default ttl, from RFC 1340 */
1911541Srgrimes#define	IPFRAGTTL	60		/* time to live for frags, slowhz */
1921541Srgrimes#define	IPTTLDEC	1		/* subtracted when forwarding */
1931541Srgrimes
1941541Srgrimes#define	IP_MSS		576		/* default maximum segment size */
1952169Spaul
1962169Spaul#endif
197