xref: /aosp_15_r20/external/tcpdump/ip6.h (revision 05b00f6010a2396e3db2409989fc67270046269f)
1*05b00f60SXin Li /*	NetBSD: ip6.h,v 1.9 2000/07/13 05:34:21 itojun Exp	*/
2*05b00f60SXin Li /*	$KAME: ip6.h,v 1.9 2000/07/02 21:01:32 itojun Exp $	*/
3*05b00f60SXin Li 
4*05b00f60SXin Li /*
5*05b00f60SXin Li  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
6*05b00f60SXin Li  * All rights reserved.
7*05b00f60SXin Li  *
8*05b00f60SXin Li  * Redistribution and use in source and binary forms, with or without
9*05b00f60SXin Li  * modification, are permitted provided that the following conditions
10*05b00f60SXin Li  * are met:
11*05b00f60SXin Li  * 1. Redistributions of source code must retain the above copyright
12*05b00f60SXin Li  *    notice, this list of conditions and the following disclaimer.
13*05b00f60SXin Li  * 2. Redistributions in binary form must reproduce the above copyright
14*05b00f60SXin Li  *    notice, this list of conditions and the following disclaimer in the
15*05b00f60SXin Li  *    documentation and/or other materials provided with the distribution.
16*05b00f60SXin Li  * 3. Neither the name of the project nor the names of its contributors
17*05b00f60SXin Li  *    may be used to endorse or promote products derived from this software
18*05b00f60SXin Li  *    without specific prior written permission.
19*05b00f60SXin Li  *
20*05b00f60SXin Li  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
21*05b00f60SXin Li  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22*05b00f60SXin Li  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23*05b00f60SXin Li  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
24*05b00f60SXin Li  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25*05b00f60SXin Li  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26*05b00f60SXin Li  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27*05b00f60SXin Li  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28*05b00f60SXin Li  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29*05b00f60SXin Li  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30*05b00f60SXin Li  * SUCH DAMAGE.
31*05b00f60SXin Li  */
32*05b00f60SXin Li 
33*05b00f60SXin Li /*
34*05b00f60SXin Li  * Copyright (c) 1982, 1986, 1993
35*05b00f60SXin Li  *	The Regents of the University of California.  All rights reserved.
36*05b00f60SXin Li  *
37*05b00f60SXin Li  * Redistribution and use in source and binary forms, with or without
38*05b00f60SXin Li  * modification, are permitted provided that the following conditions
39*05b00f60SXin Li  * are met:
40*05b00f60SXin Li  * 1. Redistributions of source code must retain the above copyright
41*05b00f60SXin Li  *    notice, this list of conditions and the following disclaimer.
42*05b00f60SXin Li  * 2. Redistributions in binary form must reproduce the above copyright
43*05b00f60SXin Li  *    notice, this list of conditions and the following disclaimer in the
44*05b00f60SXin Li  *    documentation and/or other materials provided with the distribution.
45*05b00f60SXin Li  * 3. All advertising materials mentioning features or use of this software
46*05b00f60SXin Li  *    must display the following acknowledgement:
47*05b00f60SXin Li  *	This product includes software developed by the University of
48*05b00f60SXin Li  *	California, Berkeley and its contributors.
49*05b00f60SXin Li  * 4. Neither the name of the University nor the names of its contributors
50*05b00f60SXin Li  *    may be used to endorse or promote products derived from this software
51*05b00f60SXin Li  *    without specific prior written permission.
52*05b00f60SXin Li  *
53*05b00f60SXin Li  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
54*05b00f60SXin Li  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
55*05b00f60SXin Li  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
56*05b00f60SXin Li  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
57*05b00f60SXin Li  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
58*05b00f60SXin Li  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
59*05b00f60SXin Li  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
60*05b00f60SXin Li  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
61*05b00f60SXin Li  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
62*05b00f60SXin Li  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63*05b00f60SXin Li  * SUCH DAMAGE.
64*05b00f60SXin Li  *
65*05b00f60SXin Li  *	@(#)ip.h	8.1 (Berkeley) 6/10/93
66*05b00f60SXin Li  */
67*05b00f60SXin Li 
68*05b00f60SXin Li #ifndef ND_IP6_H_
69*05b00f60SXin Li #define ND_IP6_H_
70*05b00f60SXin Li 
71*05b00f60SXin Li /*
72*05b00f60SXin Li  * Definition for internet protocol version 6.
73*05b00f60SXin Li  * RFC 2460
74*05b00f60SXin Li  */
75*05b00f60SXin Li 
76*05b00f60SXin Li struct ip6_hdr {
77*05b00f60SXin Li 	union {
78*05b00f60SXin Li 		struct ip6_hdrctl {
79*05b00f60SXin Li 			nd_uint32_t ip6_un1_flow;	/* 20 bits of flow-ID */
80*05b00f60SXin Li 			nd_uint16_t ip6_un1_plen;	/* payload length */
81*05b00f60SXin Li 			nd_uint8_t  ip6_un1_nxt;	/* next header */
82*05b00f60SXin Li 			nd_uint8_t  ip6_un1_hlim;	/* hop limit */
83*05b00f60SXin Li 		} ip6_un1;
84*05b00f60SXin Li 		nd_uint8_t ip6_un2_vfc;	/* 4 bits version, top 4 bits class */
85*05b00f60SXin Li 	} ip6_ctlun;
86*05b00f60SXin Li 	nd_ipv6 ip6_src;	/* source address */
87*05b00f60SXin Li 	nd_ipv6 ip6_dst;	/* destination address */
88*05b00f60SXin Li };
89*05b00f60SXin Li 
90*05b00f60SXin Li #define ip6_vfc		ip6_ctlun.ip6_un2_vfc
91*05b00f60SXin Li #define IP6_VERSION(ip6_hdr)	((GET_U_1((ip6_hdr)->ip6_vfc) & 0xf0) >> 4)
92*05b00f60SXin Li #define ip6_flow	ip6_ctlun.ip6_un1.ip6_un1_flow
93*05b00f60SXin Li #define ip6_plen	ip6_ctlun.ip6_un1.ip6_un1_plen
94*05b00f60SXin Li #define ip6_nxt		ip6_ctlun.ip6_un1.ip6_un1_nxt
95*05b00f60SXin Li #define ip6_hlim	ip6_ctlun.ip6_un1.ip6_un1_hlim
96*05b00f60SXin Li #define ip6_hops	ip6_ctlun.ip6_un1.ip6_un1_hlim
97*05b00f60SXin Li 
98*05b00f60SXin Li /* in network endian */
99*05b00f60SXin Li #define IPV6_FLOWINFO_MASK	((uint32_t)htonl(0x0fffffff))	/* flow info (28 bits) */
100*05b00f60SXin Li #define IPV6_FLOWLABEL_MASK	((uint32_t)htonl(0x000fffff))	/* flow label (20 bits) */
101*05b00f60SXin Li 
102*05b00f60SXin Li /*
103*05b00f60SXin Li  * Extension Headers
104*05b00f60SXin Li  */
105*05b00f60SXin Li 
106*05b00f60SXin Li struct	ip6_ext {
107*05b00f60SXin Li 	nd_uint8_t ip6e_nxt;
108*05b00f60SXin Li 	nd_uint8_t ip6e_len;
109*05b00f60SXin Li };
110*05b00f60SXin Li 
111*05b00f60SXin Li /* Hop-by-Hop options header */
112*05b00f60SXin Li struct ip6_hbh {
113*05b00f60SXin Li 	nd_uint8_t ip6h_nxt;	/* next header */
114*05b00f60SXin Li 	nd_uint8_t ip6h_len;	/* length in units of 8 octets */
115*05b00f60SXin Li 	/* followed by options */
116*05b00f60SXin Li };
117*05b00f60SXin Li 
118*05b00f60SXin Li /* Destination options header */
119*05b00f60SXin Li struct ip6_dest {
120*05b00f60SXin Li 	nd_uint8_t ip6d_nxt;	/* next header */
121*05b00f60SXin Li 	nd_uint8_t ip6d_len;	/* length in units of 8 octets */
122*05b00f60SXin Li 	/* followed by options */
123*05b00f60SXin Li };
124*05b00f60SXin Li 
125*05b00f60SXin Li /* https://www.iana.org/assignments/ipv6-parameters/ipv6-parameters.xhtml */
126*05b00f60SXin Li 
127*05b00f60SXin Li /* Option types and related macros */
128*05b00f60SXin Li #define IP6OPT_PAD1		0x00	/* 00 0 00000 */
129*05b00f60SXin Li #define IP6OPT_PADN		0x01	/* 00 0 00001 */
130*05b00f60SXin Li #define IP6OPT_JUMBO		0xC2	/* 11 0 00010 = 194 */
131*05b00f60SXin Li #define IP6OPT_JUMBO_LEN	6
132*05b00f60SXin Li #define IP6OPT_RPL		0x63	/* 01 1 00011 */
133*05b00f60SXin Li #define IP6OPT_TUN_ENC_LIMIT	0x04	/* 00 0 00100 */
134*05b00f60SXin Li #define IP6OPT_ROUTER_ALERT	0x05	/* 00 0 00101 */
135*05b00f60SXin Li 
136*05b00f60SXin Li #define IP6OPT_RTALERT_LEN	4
137*05b00f60SXin Li #define IP6OPT_RTALERT_MLD	0	/* Datagram contains an MLD message */
138*05b00f60SXin Li #define IP6OPT_RTALERT_RSVP	1	/* Datagram contains an RSVP message */
139*05b00f60SXin Li #define IP6OPT_RTALERT_ACTNET	2	/* contains an Active Networks msg */
140*05b00f60SXin Li #define IP6OPT_MINLEN		2
141*05b00f60SXin Li 
142*05b00f60SXin Li #define IP6OPT_QUICK_START	0x26	/* 00 1 00110 */
143*05b00f60SXin Li #define IP6OPT_CALIPSO		0x07	/* 00 0 00111 */
144*05b00f60SXin Li #define IP6OPT_SMF_DPD		0x08	/* 00 0 01000 */
145*05b00f60SXin Li #define IP6OPT_HOME_ADDRESS	0xc9	/* 11 0 01001 */
146*05b00f60SXin Li #define IP6OPT_HOMEADDR_MINLEN	18
147*05b00f60SXin Li #define IP6OPT_EID		0x8a	/* 10 0 01010 */
148*05b00f60SXin Li #define IP6OPT_ILNP_NOTICE	0x8b	/* 10 0 01011 */
149*05b00f60SXin Li #define IP6OPT_LINE_ID		0x8c	/* 10 0 01100 */
150*05b00f60SXin Li #define IP6OPT_MPL		0x6d	/* 01 1 01101 */
151*05b00f60SXin Li #define IP6OPT_IP_DFF		0xee	/* 11 1 01110 */
152*05b00f60SXin Li 
153*05b00f60SXin Li #define IP6OPT_TYPE(o)		((o) & 0xC0)
154*05b00f60SXin Li #define IP6OPT_TYPE_SKIP	0x00
155*05b00f60SXin Li #define IP6OPT_TYPE_DISCARD	0x40
156*05b00f60SXin Li #define IP6OPT_TYPE_FORCEICMP	0x80
157*05b00f60SXin Li #define IP6OPT_TYPE_ICMP	0xC0
158*05b00f60SXin Li 
159*05b00f60SXin Li #define IP6OPT_MUTABLE		0x20
160*05b00f60SXin Li 
161*05b00f60SXin Li /* Routing header */
162*05b00f60SXin Li struct ip6_rthdr {
163*05b00f60SXin Li 	nd_uint8_t  ip6r_nxt;		/* next header */
164*05b00f60SXin Li 	nd_uint8_t  ip6r_len;		/* length in units of 8 octets */
165*05b00f60SXin Li 	nd_uint8_t  ip6r_type;		/* routing type */
166*05b00f60SXin Li 	nd_uint8_t  ip6r_segleft;	/* segments left */
167*05b00f60SXin Li 	/* followed by routing type specific data */
168*05b00f60SXin Li };
169*05b00f60SXin Li 
170*05b00f60SXin Li #define IPV6_RTHDR_TYPE_0 0
171*05b00f60SXin Li #define IPV6_RTHDR_TYPE_2 2
172*05b00f60SXin Li #define IPV6_RTHDR_TYPE_4 4
173*05b00f60SXin Li 
174*05b00f60SXin Li /* Type 0 Routing header */
175*05b00f60SXin Li /* Also used for Type 2 */
176*05b00f60SXin Li struct ip6_rthdr0 {
177*05b00f60SXin Li 	nd_uint8_t  ip6r0_nxt;		/* next header */
178*05b00f60SXin Li 	nd_uint8_t  ip6r0_len;		/* length in units of 8 octets */
179*05b00f60SXin Li 	nd_uint8_t  ip6r0_type;		/* always zero */
180*05b00f60SXin Li 	nd_uint8_t  ip6r0_segleft;	/* segments left */
181*05b00f60SXin Li 	nd_uint32_t ip6r0_reserved;	/* reserved field */
182*05b00f60SXin Li 	nd_ipv6     ip6r0_addr[1];	/* up to 23 addresses */
183*05b00f60SXin Li };
184*05b00f60SXin Li 
185*05b00f60SXin Li /**
186*05b00f60SXin Li  * Type 4 Routing header
187*05b00f60SXin Li  * known as Segment Routing Header 'SRH'
188*05b00f60SXin Li  */
189*05b00f60SXin Li struct ip6_srh {
190*05b00f60SXin Li 	nd_uint8_t	srh_nxt;		/* next header */
191*05b00f60SXin Li 	nd_uint8_t	srh_len;		/* length in units of 8 octets */
192*05b00f60SXin Li 	nd_uint8_t	srh_type;		/* Routing Type 4 */
193*05b00f60SXin Li 	nd_uint8_t	srh_segleft;		/* segments left */
194*05b00f60SXin Li 	nd_uint8_t	srh_last_ent;		/* Last Entry*/
195*05b00f60SXin Li 	nd_uint8_t	srh_flags;		/* Flags */
196*05b00f60SXin Li 	nd_uint16_t	srh_tag;		/* Tag */
197*05b00f60SXin Li 	nd_ipv6		srh_segments[1];	/* SRH segments list*/
198*05b00f60SXin Li };
199*05b00f60SXin Li 
200*05b00f60SXin Li /* Fragment header */
201*05b00f60SXin Li struct ip6_frag {
202*05b00f60SXin Li 	nd_uint8_t  ip6f_nxt;		/* next header */
203*05b00f60SXin Li 	nd_uint8_t  ip6f_reserved;	/* reserved field */
204*05b00f60SXin Li 	nd_uint16_t ip6f_offlg;		/* offset, reserved, and flag */
205*05b00f60SXin Li 	nd_uint32_t ip6f_ident;		/* identification */
206*05b00f60SXin Li };
207*05b00f60SXin Li 
208*05b00f60SXin Li #define IP6F_OFF_MASK		0xfff8	/* mask out offset from ip6f_offlg */
209*05b00f60SXin Li #define IP6F_RESERVED_MASK	0x0006	/* reserved bits in ip6f_offlg */
210*05b00f60SXin Li #define IP6F_MORE_FRAG		0x0001	/* more-fragments flag */
211*05b00f60SXin Li 
212*05b00f60SXin Li #endif /* not ND_IP6_H_ */
213