1139823Simp/*-
21541Srgrimes * Copyright (c) 1982, 1986, 1993
3169466Srwatson *	The Regents of the University of California.
4169466Srwatson * All rights reserved.
51541Srgrimes *
61541Srgrimes * Redistribution and use in source and binary forms, with or without
71541Srgrimes * modification, are permitted provided that the following conditions
81541Srgrimes * are met:
91541Srgrimes * 1. Redistributions of source code must retain the above copyright
101541Srgrimes *    notice, this list of conditions and the following disclaimer.
111541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
121541Srgrimes *    notice, this list of conditions and the following disclaimer in the
131541Srgrimes *    documentation and/or other materials provided with the distribution.
141541Srgrimes * 4. Neither the name of the University nor the names of its contributors
151541Srgrimes *    may be used to endorse or promote products derived from this software
161541Srgrimes *    without specific prior written permission.
171541Srgrimes *
181541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
191541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
201541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
211541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
221541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
231541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
241541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
251541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
261541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
271541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
281541Srgrimes * SUCH DAMAGE.
291541Srgrimes *
3010942Swollman *	@(#)ip.h	8.2 (Berkeley) 6/1/94
3150477Speter * $FreeBSD$
321541Srgrimes */
331541Srgrimes
342169Spaul#ifndef _NETINET_IP_H_
35169466Srwatson#define	_NETINET_IP_H_
362169Spaul
37112482Smux#include <sys/cdefs.h>
38112482Smux
391541Srgrimes/*
401541Srgrimes * Definitions for internet protocol version 4.
41169466Srwatson *
421541Srgrimes * Per RFC 791, September 1981.
431541Srgrimes */
441541Srgrimes#define	IPVERSION	4
451541Srgrimes
461541Srgrimes/*
471541Srgrimes * Structure of an internet header, naked of options.
481541Srgrimes */
491541Srgrimesstruct ip {
508876Srgrimes#if BYTE_ORDER == LITTLE_ENDIAN
51203343Sluigi	u_char	ip_hl:4,		/* header length */
521541Srgrimes		ip_v:4;			/* version */
531541Srgrimes#endif
548876Srgrimes#if BYTE_ORDER == BIG_ENDIAN
55203343Sluigi	u_char	ip_v:4,			/* version */
561541Srgrimes		ip_hl:4;		/* header length */
571541Srgrimes#endif
581541Srgrimes	u_char	ip_tos;			/* type of service */
5919136Swollman	u_short	ip_len;			/* total length */
601541Srgrimes	u_short	ip_id;			/* identification */
6119136Swollman	u_short	ip_off;			/* fragment offset field */
6233851Sdima#define	IP_RF 0x8000			/* reserved fragment flag */
631541Srgrimes#define	IP_DF 0x4000			/* dont fragment flag */
641541Srgrimes#define	IP_MF 0x2000			/* more fragments flag */
651541Srgrimes#define	IP_OFFMASK 0x1fff		/* mask for fragmenting bits */
661541Srgrimes	u_char	ip_ttl;			/* time to live */
671541Srgrimes	u_char	ip_p;			/* protocol */
681541Srgrimes	u_short	ip_sum;			/* checksum */
691541Srgrimes	struct	in_addr ip_src,ip_dst;	/* source and dest address */
70165966Simp} __packed __aligned(4);
711541Srgrimes
721541Srgrimes#define	IP_MAXPACKET	65535		/* maximum packet size */
731541Srgrimes
741541Srgrimes/*
75169466Srwatson * Definitions for IP type of service (ip_tos).
761541Srgrimes */
771541Srgrimes#define	IPTOS_LOWDELAY		0x10
781541Srgrimes#define	IPTOS_THROUGHPUT	0x08
791541Srgrimes#define	IPTOS_RELIABILITY	0x04
808293Sache#define	IPTOS_MINCOST		0x02
811541Srgrimes
821541Srgrimes/*
83169466Srwatson * Definitions for IP precedence (also in ip_tos) (hopefully unused).
841541Srgrimes */
851541Srgrimes#define	IPTOS_PREC_NETCONTROL		0xe0
861541Srgrimes#define	IPTOS_PREC_INTERNETCONTROL	0xc0
871541Srgrimes#define	IPTOS_PREC_CRITIC_ECP		0xa0
881541Srgrimes#define	IPTOS_PREC_FLASHOVERRIDE	0x80
891541Srgrimes#define	IPTOS_PREC_FLASH		0x60
901541Srgrimes#define	IPTOS_PREC_IMMEDIATE		0x40
911541Srgrimes#define	IPTOS_PREC_PRIORITY		0x20
928293Sache#define	IPTOS_PREC_ROUTINE		0x00
931541Srgrimes
941541Srgrimes/*
95235036Sdelphij * Definitions for DiffServ Codepoints as per RFC2474
96235036Sdelphij */
97235036Sdelphij#define	IPTOS_DSCP_CS0		0x00
98235036Sdelphij#define	IPTOS_DSCP_CS1		0x20
99235036Sdelphij#define	IPTOS_DSCP_AF11		0x28
100235036Sdelphij#define	IPTOS_DSCP_AF12		0x30
101235036Sdelphij#define	IPTOS_DSCP_AF13		0x38
102235036Sdelphij#define	IPTOS_DSCP_CS2		0x40
103235036Sdelphij#define	IPTOS_DSCP_AF21		0x48
104235036Sdelphij#define	IPTOS_DSCP_AF22		0x50
105235036Sdelphij#define	IPTOS_DSCP_AF23		0x58
106235036Sdelphij#define	IPTOS_DSCP_CS3		0x60
107235036Sdelphij#define	IPTOS_DSCP_AF31		0x68
108235036Sdelphij#define	IPTOS_DSCP_AF32		0x70
109235036Sdelphij#define	IPTOS_DSCP_AF33		0x78
110235036Sdelphij#define	IPTOS_DSCP_CS4		0x80
111235036Sdelphij#define	IPTOS_DSCP_AF41		0x88
112235036Sdelphij#define	IPTOS_DSCP_AF42		0x90
113235036Sdelphij#define	IPTOS_DSCP_AF43		0x98
114235036Sdelphij#define	IPTOS_DSCP_CS5		0xa0
115235036Sdelphij#define	IPTOS_DSCP_EF		0xb8
116235036Sdelphij#define	IPTOS_DSCP_CS6		0xc0
117235036Sdelphij#define	IPTOS_DSCP_CS7		0xe0
118235036Sdelphij
119235036Sdelphij/*
120169466Srwatson * ECN (Explicit Congestion Notification) codepoints in RFC3168 mapped to the
121169466Srwatson * lower 2 bits of the TOS field.
122121684Sume */
123121684Sume#define	IPTOS_ECN_NOTECT	0x00	/* not-ECT */
124121684Sume#define	IPTOS_ECN_ECT1		0x01	/* ECN-capable transport (1) */
125121684Sume#define	IPTOS_ECN_ECT0		0x02	/* ECN-capable transport (0) */
126121684Sume#define	IPTOS_ECN_CE		0x03	/* congestion experienced */
127121684Sume#define	IPTOS_ECN_MASK		0x03	/* ECN field mask */
128121684Sume
129121684Sume/*
1301541Srgrimes * Definitions for options.
1311541Srgrimes */
1321541Srgrimes#define	IPOPT_COPIED(o)		((o)&0x80)
1331541Srgrimes#define	IPOPT_CLASS(o)		((o)&0x60)
1341541Srgrimes#define	IPOPT_NUMBER(o)		((o)&0x1f)
1351541Srgrimes
1361541Srgrimes#define	IPOPT_CONTROL		0x00
1371541Srgrimes#define	IPOPT_RESERVED1		0x20
1381541Srgrimes#define	IPOPT_DEBMEAS		0x40
1391541Srgrimes#define	IPOPT_RESERVED2		0x60
1401541Srgrimes
1411541Srgrimes#define	IPOPT_EOL		0		/* end of option list */
1421541Srgrimes#define	IPOPT_NOP		1		/* no operation */
1431541Srgrimes
1441541Srgrimes#define	IPOPT_RR		7		/* record packet route */
1451541Srgrimes#define	IPOPT_TS		68		/* timestamp */
1461541Srgrimes#define	IPOPT_SECURITY		130		/* provide s,c,h,tcc */
1471541Srgrimes#define	IPOPT_LSRR		131		/* loose source route */
14887919Srwatson#define	IPOPT_ESO		133		/* extended security */
14987917Srwatson#define	IPOPT_CIPSO		134		/* commerical security */
1501541Srgrimes#define	IPOPT_SATID		136		/* satnet id */
1511541Srgrimes#define	IPOPT_SSRR		137		/* strict source route */
15214622Sfenner#define	IPOPT_RA		148		/* router alert */
1531541Srgrimes
1541541Srgrimes/*
1551541Srgrimes * Offsets to fields in options other than EOL and NOP.
1561541Srgrimes */
1571541Srgrimes#define	IPOPT_OPTVAL		0		/* option ID */
1581541Srgrimes#define	IPOPT_OLEN		1		/* option length */
159169466Srwatson#define	IPOPT_OFFSET		2		/* offset within option */
1601541Srgrimes#define	IPOPT_MINOFF		4		/* min value of above */
1611541Srgrimes
1621541Srgrimes/*
1631541Srgrimes * Time stamp option structure.
1641541Srgrimes */
1651541Srgrimesstruct	ip_timestamp {
1661541Srgrimes	u_char	ipt_code;		/* IPOPT_TS */
1671541Srgrimes	u_char	ipt_len;		/* size of structure (variable) */
1681541Srgrimes	u_char	ipt_ptr;		/* index of current entry */
1698876Srgrimes#if BYTE_ORDER == LITTLE_ENDIAN
170203343Sluigi	u_char	ipt_flg:4,		/* flags, see below */
1711541Srgrimes		ipt_oflw:4;		/* overflow counter */
1721541Srgrimes#endif
1738876Srgrimes#if BYTE_ORDER == BIG_ENDIAN
174203343Sluigi	u_char	ipt_oflw:4,		/* overflow counter */
1751541Srgrimes		ipt_flg:4;		/* flags, see below */
1761541Srgrimes#endif
1771541Srgrimes	union ipt_timestamp {
178188578Sluigi		uint32_t	ipt_time[1];	/* network format */
1791541Srgrimes		struct	ipt_ta {
1801541Srgrimes			struct in_addr ipt_addr;
181188578Sluigi			uint32_t ipt_time;	/* network format */
1821541Srgrimes		} ipt_ta[1];
1831541Srgrimes	} ipt_timestamp;
1841541Srgrimes};
1851541Srgrimes
186169466Srwatson/* Flag bits for ipt_flg. */
1871541Srgrimes#define	IPOPT_TS_TSONLY		0		/* timestamps only */
1881541Srgrimes#define	IPOPT_TS_TSANDADDR	1		/* timestamps and addresses */
1891541Srgrimes#define	IPOPT_TS_PRESPEC	3		/* specified modules only */
1901541Srgrimes
191169466Srwatson/* Bits for security (not byte swapped). */
1921541Srgrimes#define	IPOPT_SECUR_UNCLASS	0x0000
1931541Srgrimes#define	IPOPT_SECUR_CONFID	0xf135
1941541Srgrimes#define	IPOPT_SECUR_EFTO	0x789a
1951541Srgrimes#define	IPOPT_SECUR_MMMM	0xbc4d
1961541Srgrimes#define	IPOPT_SECUR_RESTR	0xaf13
1971541Srgrimes#define	IPOPT_SECUR_SECRET	0xd788
1981541Srgrimes#define	IPOPT_SECUR_TOPSECRET	0x6bc5
1991541Srgrimes
2001541Srgrimes/*
2011541Srgrimes * Internet implementation parameters.
2021541Srgrimes */
2031541Srgrimes#define	MAXTTL		255		/* maximum time to live (seconds) */
2041541Srgrimes#define	IPDEFTTL	64		/* default ttl, from RFC 1340 */
2051541Srgrimes#define	IPFRAGTTL	60		/* time to live for frags, slowhz */
2061541Srgrimes#define	IPTTLDEC	1		/* subtracted when forwarding */
2071541Srgrimes#define	IP_MSS		576		/* default maximum segment size */
2082169Spaul
209125680Sbms/*
210125680Sbms * This is the real IPv4 pseudo header, used for computing the TCP and UDP
211125680Sbms * checksums. For the Internet checksum, struct ipovly can be used instead.
212125680Sbms * For stronger checksums, the real thing must be used.
213125680Sbms */
214125680Sbmsstruct ippseudo {
215125680Sbms	struct	in_addr	ippseudo_src;	/* source internet address */
216125680Sbms	struct	in_addr	ippseudo_dst;	/* destination internet address */
217125870Sbms	u_char		ippseudo_pad;	/* pad, must be zero */
218125870Sbms	u_char		ippseudo_p;	/* protocol */
219125870Sbms	u_short		ippseudo_len;	/* protocol length */
220125870Sbms};
2212169Spaul#endif
222