xref: /f-stack/tools/compat/include/netinet/ip.h (revision d4a07e70)
11eaf0ac3Slogwang /*-
2*d4a07e70Sfengbojiang  * SPDX-License-Identifier: BSD-3-Clause
3*d4a07e70Sfengbojiang  *
41eaf0ac3Slogwang  * Copyright (c) 1982, 1986, 1993
51eaf0ac3Slogwang  *	The Regents of the University of California.
61eaf0ac3Slogwang  * All rights reserved.
71eaf0ac3Slogwang  *
81eaf0ac3Slogwang  * Redistribution and use in source and binary forms, with or without
91eaf0ac3Slogwang  * modification, are permitted provided that the following conditions
101eaf0ac3Slogwang  * are met:
111eaf0ac3Slogwang  * 1. Redistributions of source code must retain the above copyright
121eaf0ac3Slogwang  *    notice, this list of conditions and the following disclaimer.
131eaf0ac3Slogwang  * 2. Redistributions in binary form must reproduce the above copyright
141eaf0ac3Slogwang  *    notice, this list of conditions and the following disclaimer in the
151eaf0ac3Slogwang  *    documentation and/or other materials provided with the distribution.
16*d4a07e70Sfengbojiang  * 3. Neither the name of the University nor the names of its contributors
171eaf0ac3Slogwang  *    may be used to endorse or promote products derived from this software
181eaf0ac3Slogwang  *    without specific prior written permission.
191eaf0ac3Slogwang  *
201eaf0ac3Slogwang  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
211eaf0ac3Slogwang  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
221eaf0ac3Slogwang  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
231eaf0ac3Slogwang  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
241eaf0ac3Slogwang  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
251eaf0ac3Slogwang  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
261eaf0ac3Slogwang  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
271eaf0ac3Slogwang  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
281eaf0ac3Slogwang  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
291eaf0ac3Slogwang  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
301eaf0ac3Slogwang  * SUCH DAMAGE.
311eaf0ac3Slogwang  *
321eaf0ac3Slogwang  *	@(#)ip.h	8.2 (Berkeley) 6/1/94
331eaf0ac3Slogwang  * $FreeBSD$
341eaf0ac3Slogwang  */
351eaf0ac3Slogwang 
361eaf0ac3Slogwang #ifndef _NETINET_IP_H_
371eaf0ac3Slogwang #define	_NETINET_IP_H_
381eaf0ac3Slogwang 
391eaf0ac3Slogwang #include <sys/cdefs.h>
401eaf0ac3Slogwang 
411eaf0ac3Slogwang /*
421eaf0ac3Slogwang  * Definitions for internet protocol version 4.
431eaf0ac3Slogwang  *
441eaf0ac3Slogwang  * Per RFC 791, September 1981.
451eaf0ac3Slogwang  */
461eaf0ac3Slogwang #define	IPVERSION	4
471eaf0ac3Slogwang 
481eaf0ac3Slogwang /*
491eaf0ac3Slogwang  * Structure of an internet header, naked of options.
501eaf0ac3Slogwang  */
511eaf0ac3Slogwang struct ip {
521eaf0ac3Slogwang #if BYTE_ORDER == LITTLE_ENDIAN
531eaf0ac3Slogwang 	u_char	ip_hl:4,		/* header length */
541eaf0ac3Slogwang 		ip_v:4;			/* version */
551eaf0ac3Slogwang #endif
561eaf0ac3Slogwang #if BYTE_ORDER == BIG_ENDIAN
571eaf0ac3Slogwang 	u_char	ip_v:4,			/* version */
581eaf0ac3Slogwang 		ip_hl:4;		/* header length */
591eaf0ac3Slogwang #endif
601eaf0ac3Slogwang 	u_char	ip_tos;			/* type of service */
611eaf0ac3Slogwang 	u_short	ip_len;			/* total length */
621eaf0ac3Slogwang 	u_short	ip_id;			/* identification */
631eaf0ac3Slogwang 	u_short	ip_off;			/* fragment offset field */
641eaf0ac3Slogwang #define	IP_RF 0x8000			/* reserved fragment flag */
651eaf0ac3Slogwang #define	IP_DF 0x4000			/* dont fragment flag */
661eaf0ac3Slogwang #define	IP_MF 0x2000			/* more fragments flag */
671eaf0ac3Slogwang #define	IP_OFFMASK 0x1fff		/* mask for fragmenting bits */
681eaf0ac3Slogwang 	u_char	ip_ttl;			/* time to live */
691eaf0ac3Slogwang 	u_char	ip_p;			/* protocol */
701eaf0ac3Slogwang 	u_short	ip_sum;			/* checksum */
711eaf0ac3Slogwang 	struct	in_addr ip_src,ip_dst;	/* source and dest address */
721eaf0ac3Slogwang } __attribute__ ((packed)) __attribute__((__aligned__(2)));
731eaf0ac3Slogwang 
741eaf0ac3Slogwang #define	IP_MAXPACKET	65535		/* maximum packet size */
751eaf0ac3Slogwang 
761eaf0ac3Slogwang /*
771eaf0ac3Slogwang  * Definitions for IP type of service (ip_tos).
781eaf0ac3Slogwang  */
791eaf0ac3Slogwang #define	IPTOS_LOWDELAY		0x10
801eaf0ac3Slogwang #define	IPTOS_THROUGHPUT	0x08
811eaf0ac3Slogwang #define	IPTOS_RELIABILITY	0x04
821eaf0ac3Slogwang #define	IPTOS_MINCOST		0x02
831eaf0ac3Slogwang 
841eaf0ac3Slogwang /*
851eaf0ac3Slogwang  * Definitions for IP precedence (also in ip_tos) (deprecated).
861eaf0ac3Slogwang  */
871eaf0ac3Slogwang #define	IPTOS_PREC_NETCONTROL		IPTOS_DSCP_CS7
881eaf0ac3Slogwang #define	IPTOS_PREC_INTERNETCONTROL	IPTOS_DSCP_CS6
891eaf0ac3Slogwang #define	IPTOS_PREC_CRITIC_ECP		IPTOS_DSCP_CS5
901eaf0ac3Slogwang #define	IPTOS_PREC_FLASHOVERRIDE	IPTOS_DSCP_CS4
911eaf0ac3Slogwang #define	IPTOS_PREC_FLASH		IPTOS_DSCP_CS3
921eaf0ac3Slogwang #define	IPTOS_PREC_IMMEDIATE		IPTOS_DSCP_CS2
931eaf0ac3Slogwang #define	IPTOS_PREC_PRIORITY		IPTOS_DSCP_CS1
941eaf0ac3Slogwang #define	IPTOS_PREC_ROUTINE		IPTOS_DSCP_CS0
951eaf0ac3Slogwang 
961eaf0ac3Slogwang /*
97*d4a07e70Sfengbojiang  * Offset of Diffserv decimal value to convert it to tos value .
98*d4a07e70Sfengbojiang  */
99*d4a07e70Sfengbojiang #define	IPTOS_DSCP_OFFSET		2
100*d4a07e70Sfengbojiang 
101*d4a07e70Sfengbojiang /*
1021eaf0ac3Slogwang  * Definitions for DiffServ Codepoints as per RFC2474 and RFC5865.
1031eaf0ac3Slogwang  */
1041eaf0ac3Slogwang #define	IPTOS_DSCP_CS0		0x00
1051eaf0ac3Slogwang #define	IPTOS_DSCP_CS1		0x20
1061eaf0ac3Slogwang #define	IPTOS_DSCP_AF11		0x28
1071eaf0ac3Slogwang #define	IPTOS_DSCP_AF12		0x30
1081eaf0ac3Slogwang #define	IPTOS_DSCP_AF13		0x38
1091eaf0ac3Slogwang #define	IPTOS_DSCP_CS2		0x40
1101eaf0ac3Slogwang #define	IPTOS_DSCP_AF21		0x48
1111eaf0ac3Slogwang #define	IPTOS_DSCP_AF22		0x50
1121eaf0ac3Slogwang #define	IPTOS_DSCP_AF23		0x58
1131eaf0ac3Slogwang #define	IPTOS_DSCP_CS3		0x60
1141eaf0ac3Slogwang #define	IPTOS_DSCP_AF31		0x68
1151eaf0ac3Slogwang #define	IPTOS_DSCP_AF32		0x70
1161eaf0ac3Slogwang #define	IPTOS_DSCP_AF33		0x78
1171eaf0ac3Slogwang #define	IPTOS_DSCP_CS4		0x80
1181eaf0ac3Slogwang #define	IPTOS_DSCP_AF41		0x88
1191eaf0ac3Slogwang #define	IPTOS_DSCP_AF42		0x90
1201eaf0ac3Slogwang #define	IPTOS_DSCP_AF43		0x98
1211eaf0ac3Slogwang #define	IPTOS_DSCP_CS5		0xa0
1221eaf0ac3Slogwang #define	IPTOS_DSCP_VA		0xb0
1231eaf0ac3Slogwang #define	IPTOS_DSCP_EF		0xb8
1241eaf0ac3Slogwang #define	IPTOS_DSCP_CS6		0xc0
1251eaf0ac3Slogwang #define	IPTOS_DSCP_CS7		0xe0
1261eaf0ac3Slogwang 
1271eaf0ac3Slogwang /*
1281eaf0ac3Slogwang  * ECN (Explicit Congestion Notification) codepoints in RFC3168 mapped to the
1291eaf0ac3Slogwang  * lower 2 bits of the TOS field.
1301eaf0ac3Slogwang  */
1311eaf0ac3Slogwang #define	IPTOS_ECN_NOTECT	0x00	/* not-ECT */
1321eaf0ac3Slogwang #define	IPTOS_ECN_ECT1		0x01	/* ECN-capable transport (1) */
1331eaf0ac3Slogwang #define	IPTOS_ECN_ECT0		0x02	/* ECN-capable transport (0) */
1341eaf0ac3Slogwang #define	IPTOS_ECN_CE		0x03	/* congestion experienced */
1351eaf0ac3Slogwang #define	IPTOS_ECN_MASK		0x03	/* ECN field mask */
1361eaf0ac3Slogwang 
1371eaf0ac3Slogwang /*
1381eaf0ac3Slogwang  * Definitions for options.
1391eaf0ac3Slogwang  */
1401eaf0ac3Slogwang #define	IPOPT_COPIED(o)		((o)&0x80)
1411eaf0ac3Slogwang #define	IPOPT_CLASS(o)		((o)&0x60)
1421eaf0ac3Slogwang #define	IPOPT_NUMBER(o)		((o)&0x1f)
1431eaf0ac3Slogwang 
1441eaf0ac3Slogwang #define	IPOPT_CONTROL		0x00
1451eaf0ac3Slogwang #define	IPOPT_RESERVED1		0x20
1461eaf0ac3Slogwang #define	IPOPT_DEBMEAS		0x40
1471eaf0ac3Slogwang #define	IPOPT_RESERVED2		0x60
1481eaf0ac3Slogwang 
1491eaf0ac3Slogwang #define	IPOPT_EOL		0		/* end of option list */
1501eaf0ac3Slogwang #define	IPOPT_NOP		1		/* no operation */
1511eaf0ac3Slogwang 
1521eaf0ac3Slogwang #define	IPOPT_RR		7		/* record packet route */
1531eaf0ac3Slogwang #define	IPOPT_TS		68		/* timestamp */
1541eaf0ac3Slogwang #define	IPOPT_SECURITY		130		/* provide s,c,h,tcc */
1551eaf0ac3Slogwang #define	IPOPT_LSRR		131		/* loose source route */
1561eaf0ac3Slogwang #define	IPOPT_ESO		133		/* extended security */
1571eaf0ac3Slogwang #define	IPOPT_CIPSO		134		/* commercial security */
1581eaf0ac3Slogwang #define	IPOPT_SATID		136		/* satnet id */
1591eaf0ac3Slogwang #define	IPOPT_SSRR		137		/* strict source route */
1601eaf0ac3Slogwang #define	IPOPT_RA		148		/* router alert */
1611eaf0ac3Slogwang 
1621eaf0ac3Slogwang /*
1631eaf0ac3Slogwang  * Offsets to fields in options other than EOL and NOP.
1641eaf0ac3Slogwang  */
1651eaf0ac3Slogwang #define	IPOPT_OPTVAL		0		/* option ID */
1661eaf0ac3Slogwang #define	IPOPT_OLEN		1		/* option length */
1671eaf0ac3Slogwang #define	IPOPT_OFFSET		2		/* offset within option */
1681eaf0ac3Slogwang #define	IPOPT_MINOFF		4		/* min value of above */
1691eaf0ac3Slogwang 
1701eaf0ac3Slogwang /*
1711eaf0ac3Slogwang  * Time stamp option structure.
1721eaf0ac3Slogwang  */
1731eaf0ac3Slogwang struct	ip_timestamp {
1741eaf0ac3Slogwang 	u_char	ipt_code;		/* IPOPT_TS */
1751eaf0ac3Slogwang 	u_char	ipt_len;		/* size of structure (variable) */
1761eaf0ac3Slogwang 	u_char	ipt_ptr;		/* index of current entry */
1771eaf0ac3Slogwang #if BYTE_ORDER == LITTLE_ENDIAN
1781eaf0ac3Slogwang 	u_char	ipt_flg:4,		/* flags, see below */
1791eaf0ac3Slogwang 		ipt_oflw:4;		/* overflow counter */
1801eaf0ac3Slogwang #endif
1811eaf0ac3Slogwang #if BYTE_ORDER == BIG_ENDIAN
1821eaf0ac3Slogwang 	u_char	ipt_oflw:4,		/* overflow counter */
1831eaf0ac3Slogwang 		ipt_flg:4;		/* flags, see below */
1841eaf0ac3Slogwang #endif
1851eaf0ac3Slogwang 	union ipt_timestamp {
1861eaf0ac3Slogwang 		uint32_t	ipt_time[1];	/* network format */
1871eaf0ac3Slogwang 		struct	ipt_ta {
1881eaf0ac3Slogwang 			struct in_addr ipt_addr;
1891eaf0ac3Slogwang 			uint32_t ipt_time;	/* network format */
1901eaf0ac3Slogwang 		} ipt_ta[1];
1911eaf0ac3Slogwang 	} ipt_timestamp;
1921eaf0ac3Slogwang };
1931eaf0ac3Slogwang 
1941eaf0ac3Slogwang /* Flag bits for ipt_flg. */
1951eaf0ac3Slogwang #define	IPOPT_TS_TSONLY		0		/* timestamps only */
1961eaf0ac3Slogwang #define	IPOPT_TS_TSANDADDR	1		/* timestamps and addresses */
1971eaf0ac3Slogwang #define	IPOPT_TS_PRESPEC	3		/* specified modules only */
1981eaf0ac3Slogwang 
1991eaf0ac3Slogwang /* Bits for security (not byte swapped). */
2001eaf0ac3Slogwang #define	IPOPT_SECUR_UNCLASS	0x0000
2011eaf0ac3Slogwang #define	IPOPT_SECUR_CONFID	0xf135
2021eaf0ac3Slogwang #define	IPOPT_SECUR_EFTO	0x789a
2031eaf0ac3Slogwang #define	IPOPT_SECUR_MMMM	0xbc4d
2041eaf0ac3Slogwang #define	IPOPT_SECUR_RESTR	0xaf13
2051eaf0ac3Slogwang #define	IPOPT_SECUR_SECRET	0xd788
2061eaf0ac3Slogwang #define	IPOPT_SECUR_TOPSECRET	0x6bc5
2071eaf0ac3Slogwang 
2081eaf0ac3Slogwang /*
2091eaf0ac3Slogwang  * Internet implementation parameters.
2101eaf0ac3Slogwang  */
2111eaf0ac3Slogwang #define	MAXTTL		255		/* maximum time to live (seconds) */
2121eaf0ac3Slogwang #define	IPDEFTTL	64		/* default ttl, from RFC 1340 */
2131eaf0ac3Slogwang #define	IPFRAGTTL	60		/* time to live for frags, slowhz */
2141eaf0ac3Slogwang #define	IPTTLDEC	1		/* subtracted when forwarding */
2151eaf0ac3Slogwang #define	IP_MSS		576		/* default maximum segment size */
2161eaf0ac3Slogwang 
2171eaf0ac3Slogwang /*
2181eaf0ac3Slogwang  * This is the real IPv4 pseudo header, used for computing the TCP and UDP
2191eaf0ac3Slogwang  * checksums. For the Internet checksum, struct ipovly can be used instead.
2201eaf0ac3Slogwang  * For stronger checksums, the real thing must be used.
2211eaf0ac3Slogwang  */
2221eaf0ac3Slogwang struct ippseudo {
2231eaf0ac3Slogwang 	struct	in_addr	ippseudo_src;	/* source internet address */
2241eaf0ac3Slogwang 	struct	in_addr	ippseudo_dst;	/* destination internet address */
2251eaf0ac3Slogwang 	u_char		ippseudo_pad;	/* pad, must be zero */
2261eaf0ac3Slogwang 	u_char		ippseudo_p;	/* protocol */
2271eaf0ac3Slogwang 	u_short		ippseudo_len;	/* protocol length */
2281eaf0ac3Slogwang };
2291eaf0ac3Slogwang #endif
230