xref: /illumos-gate/usr/src/uts/common/netinet/ip6.h (revision 7c478bd95313f5f23a4c958a745db2134aa0324)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2003 Sun Microsystems, Inc.
24*7c478bd9Sstevel@tonic-gate  * All rights reserved.
25*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
26*7c478bd9Sstevel@tonic-gate  */
27*7c478bd9Sstevel@tonic-gate 
28*7c478bd9Sstevel@tonic-gate /*
29*7c478bd9Sstevel@tonic-gate  * ip6.h - Common structures and definitions as defined by
30*7c478bd9Sstevel@tonic-gate  * advanced BSD API.
31*7c478bd9Sstevel@tonic-gate  */
32*7c478bd9Sstevel@tonic-gate 
33*7c478bd9Sstevel@tonic-gate #ifndef	_NETINET_IP6_H
34*7c478bd9Sstevel@tonic-gate #define	_NETINET_IP6_H
35*7c478bd9Sstevel@tonic-gate 
36*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
37*7c478bd9Sstevel@tonic-gate 
38*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
39*7c478bd9Sstevel@tonic-gate extern "C" {
40*7c478bd9Sstevel@tonic-gate #endif
41*7c478bd9Sstevel@tonic-gate 
42*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
43*7c478bd9Sstevel@tonic-gate #include <netinet/in.h>
44*7c478bd9Sstevel@tonic-gate 
45*7c478bd9Sstevel@tonic-gate struct	ip6_hdr {
46*7c478bd9Sstevel@tonic-gate 	union {
47*7c478bd9Sstevel@tonic-gate 		struct ip6_hdrctl {
48*7c478bd9Sstevel@tonic-gate 			uint32_t	ip6_un1_flow;   /* 4 bits version, */
49*7c478bd9Sstevel@tonic-gate 							/* 8 bits tclass, and */
50*7c478bd9Sstevel@tonic-gate 							/* 20 bits flow-ID */
51*7c478bd9Sstevel@tonic-gate 			uint16_t	ip6_un1_plen;   /* payload length */
52*7c478bd9Sstevel@tonic-gate 			uint8_t		ip6_un1_nxt;    /* next header */
53*7c478bd9Sstevel@tonic-gate 			uint8_t		ip6_un1_hlim;   /* hop limit */
54*7c478bd9Sstevel@tonic-gate 		} ip6_un1;
55*7c478bd9Sstevel@tonic-gate 		uint8_t	ip6_un2_vfc;	/* 4 bits version and */
56*7c478bd9Sstevel@tonic-gate 					/* top 4 bits of tclass */
57*7c478bd9Sstevel@tonic-gate 	} ip6_ctlun;
58*7c478bd9Sstevel@tonic-gate 	struct in6_addr ip6_src;	/* source address */
59*7c478bd9Sstevel@tonic-gate 	struct in6_addr ip6_dst;	/* destination address */
60*7c478bd9Sstevel@tonic-gate };
61*7c478bd9Sstevel@tonic-gate typedef struct ip6_hdr	ip6_t;
62*7c478bd9Sstevel@tonic-gate 
63*7c478bd9Sstevel@tonic-gate #define	ip6_vfc		ip6_ctlun.ip6_un2_vfc	/* 4 bits version and */
64*7c478bd9Sstevel@tonic-gate 						/* top 4 bits of tclass */
65*7c478bd9Sstevel@tonic-gate #define	ip6_flow	ip6_ctlun.ip6_un1.ip6_un1_flow
66*7c478bd9Sstevel@tonic-gate #define	ip6_vcf		ip6_flow		/* Version, tclass, flow-ID */
67*7c478bd9Sstevel@tonic-gate #define	ip6_plen	ip6_ctlun.ip6_un1.ip6_un1_plen
68*7c478bd9Sstevel@tonic-gate #define	ip6_nxt		ip6_ctlun.ip6_un1.ip6_un1_nxt
69*7c478bd9Sstevel@tonic-gate #define	ip6_hlim	ip6_ctlun.ip6_un1.ip6_un1_hlim
70*7c478bd9Sstevel@tonic-gate #define	ip6_hops	ip6_ctlun.ip6_un1.ip6_un1_hlim
71*7c478bd9Sstevel@tonic-gate 
72*7c478bd9Sstevel@tonic-gate /* Hop-by-Hop options header */
73*7c478bd9Sstevel@tonic-gate struct ip6_hbh {
74*7c478bd9Sstevel@tonic-gate 	uint8_t	ip6h_nxt;	/* next header */
75*7c478bd9Sstevel@tonic-gate 	uint8_t	ip6h_len;	/* length in units of 8 octets */
76*7c478bd9Sstevel@tonic-gate 		/* followed by options */
77*7c478bd9Sstevel@tonic-gate };
78*7c478bd9Sstevel@tonic-gate typedef struct ip6_hbh	ip6_hbh_t;
79*7c478bd9Sstevel@tonic-gate 
80*7c478bd9Sstevel@tonic-gate /* Destination options header */
81*7c478bd9Sstevel@tonic-gate struct ip6_dest {
82*7c478bd9Sstevel@tonic-gate 	uint8_t	ip6d_nxt;	/* next header */
83*7c478bd9Sstevel@tonic-gate 	uint8_t	ip6d_len;	/* length in units of 8 octets */
84*7c478bd9Sstevel@tonic-gate 		/* followed by options */
85*7c478bd9Sstevel@tonic-gate };
86*7c478bd9Sstevel@tonic-gate typedef struct ip6_dest	ip6_dest_t;
87*7c478bd9Sstevel@tonic-gate 
88*7c478bd9Sstevel@tonic-gate /* Routing header */
89*7c478bd9Sstevel@tonic-gate struct ip6_rthdr {
90*7c478bd9Sstevel@tonic-gate 	uint8_t	ip6r_nxt;	/* next header */
91*7c478bd9Sstevel@tonic-gate 	uint8_t	ip6r_len;	/* length in units of 8 octets */
92*7c478bd9Sstevel@tonic-gate 	uint8_t	ip6r_type;	/* routing type */
93*7c478bd9Sstevel@tonic-gate 	uint8_t	ip6r_segleft;	/* segments left */
94*7c478bd9Sstevel@tonic-gate 		/* followed by routing type specific data */
95*7c478bd9Sstevel@tonic-gate };
96*7c478bd9Sstevel@tonic-gate typedef struct ip6_rthdr	ip6_rthdr_t;
97*7c478bd9Sstevel@tonic-gate 
98*7c478bd9Sstevel@tonic-gate /* Type 0 Routing header */
99*7c478bd9Sstevel@tonic-gate struct ip6_rthdr0 {
100*7c478bd9Sstevel@tonic-gate 	uint8_t	ip6r0_nxt;		/* next header */
101*7c478bd9Sstevel@tonic-gate 	uint8_t	ip6r0_len;		/* length in units of 8 octets */
102*7c478bd9Sstevel@tonic-gate 	uint8_t	ip6r0_type;		/* always zero */
103*7c478bd9Sstevel@tonic-gate 	uint8_t	ip6r0_segleft;		/* segments left */
104*7c478bd9Sstevel@tonic-gate 	uint32_t ip6r0_reserved;	/* reserved field */
105*7c478bd9Sstevel@tonic-gate };
106*7c478bd9Sstevel@tonic-gate typedef struct ip6_rthdr0	ip6_rthdr0_t;
107*7c478bd9Sstevel@tonic-gate 
108*7c478bd9Sstevel@tonic-gate /* Fragment header */
109*7c478bd9Sstevel@tonic-gate struct ip6_frag {
110*7c478bd9Sstevel@tonic-gate 	uint8_t		ip6f_nxt;	/* next header */
111*7c478bd9Sstevel@tonic-gate 	uint8_t		ip6f_reserved;	/* reserved field */
112*7c478bd9Sstevel@tonic-gate 	uint16_t	ip6f_offlg;	/* offset, reserved, and flag */
113*7c478bd9Sstevel@tonic-gate 	uint32_t	ip6f_ident;	/* identification */
114*7c478bd9Sstevel@tonic-gate };
115*7c478bd9Sstevel@tonic-gate typedef struct ip6_frag	ip6_frag_t;
116*7c478bd9Sstevel@tonic-gate 
117*7c478bd9Sstevel@tonic-gate /* ip6f_offlg field related constants (in network byte order) */
118*7c478bd9Sstevel@tonic-gate #ifdef _BIG_ENDIAN
119*7c478bd9Sstevel@tonic-gate #define	IP6F_OFF_MASK		0xfff8	/* mask out offset from _offlg */
120*7c478bd9Sstevel@tonic-gate #define	IP6F_RESERVED_MASK	0x0006	/* reserved bits in ip6f_offlg */
121*7c478bd9Sstevel@tonic-gate #define	IP6F_MORE_FRAG		0x0001	/* more-fragments flag */
122*7c478bd9Sstevel@tonic-gate #else
123*7c478bd9Sstevel@tonic-gate #define	IP6F_OFF_MASK		0xf8ff	/* mask out offset from _offlg */
124*7c478bd9Sstevel@tonic-gate #define	IP6F_RESERVED_MASK	0x0600	/* reserved bits in ip6f_offlg */
125*7c478bd9Sstevel@tonic-gate #define	IP6F_MORE_FRAG		0x0100	/* more-fragments flag */
126*7c478bd9Sstevel@tonic-gate #endif
127*7c478bd9Sstevel@tonic-gate 
128*7c478bd9Sstevel@tonic-gate /* IPv6 options */
129*7c478bd9Sstevel@tonic-gate struct	ip6_opt {
130*7c478bd9Sstevel@tonic-gate 	uint8_t	ip6o_type;
131*7c478bd9Sstevel@tonic-gate 	uint8_t	ip6o_len;
132*7c478bd9Sstevel@tonic-gate };
133*7c478bd9Sstevel@tonic-gate 
134*7c478bd9Sstevel@tonic-gate /*
135*7c478bd9Sstevel@tonic-gate  * The high-order 3 bits of the option type define the behavior
136*7c478bd9Sstevel@tonic-gate  * when processing an unknown option and whether or not the option
137*7c478bd9Sstevel@tonic-gate  * content changes in flight.
138*7c478bd9Sstevel@tonic-gate  */
139*7c478bd9Sstevel@tonic-gate #define	IP6OPT_TYPE(o)		((o) & 0xc0)
140*7c478bd9Sstevel@tonic-gate #define	IP6OPT_TYPE_SKIP	0x00
141*7c478bd9Sstevel@tonic-gate #define	IP6OPT_TYPE_DISCARD	0x40
142*7c478bd9Sstevel@tonic-gate #define	IP6OPT_TYPE_FORCEICMP	0x80
143*7c478bd9Sstevel@tonic-gate #define	IP6OPT_TYPE_ICMP	0xc0
144*7c478bd9Sstevel@tonic-gate #define	IP6OPT_MUTABLE		0x20
145*7c478bd9Sstevel@tonic-gate 
146*7c478bd9Sstevel@tonic-gate #define	IP6OPT_PAD1			0x00	/* 00 0 00000 */
147*7c478bd9Sstevel@tonic-gate #define	IP6OPT_PADN			0x01	/* 00 0 00001 */
148*7c478bd9Sstevel@tonic-gate #define	IP6OPT_JUMBO			0xc2	/* 11 0 00010 = 194 */
149*7c478bd9Sstevel@tonic-gate #define	IP6OPT_NSAP_ADDR		0xc3	/* 11 0 00011 */
150*7c478bd9Sstevel@tonic-gate #define	IP6OPT_TUNNEL_LIMIT		0x04	/* 00 0 00100 */
151*7c478bd9Sstevel@tonic-gate #define	IP6OPT_ROUTER_ALERT		0x05	/* 00 0 00101 */
152*7c478bd9Sstevel@tonic-gate #define	IP6OPT_BINDING_UPDATE		0xc6	/* 11 0 00110 */
153*7c478bd9Sstevel@tonic-gate #define	IP6OPT_BINDING_ACK		0x07	/* 00 0 00111 */
154*7c478bd9Sstevel@tonic-gate #define	IP6OPT_BINDING_REQ		0x08	/* 00 0 01000 */
155*7c478bd9Sstevel@tonic-gate #define	IP6OPT_HOME_ADDRESS		0xc9	/* 11 0 01001 */
156*7c478bd9Sstevel@tonic-gate #define	IP6OPT_EID			0x8a	/* 10 0 01010 */
157*7c478bd9Sstevel@tonic-gate 
158*7c478bd9Sstevel@tonic-gate /* Jumbo Payload Option */
159*7c478bd9Sstevel@tonic-gate struct	ip6_opt_jumbo {
160*7c478bd9Sstevel@tonic-gate 	uint8_t	ip6oj_type;
161*7c478bd9Sstevel@tonic-gate 	uint8_t	ip6oj_len;
162*7c478bd9Sstevel@tonic-gate 	uint8_t ip6oj_jumbo_len[4];
163*7c478bd9Sstevel@tonic-gate };
164*7c478bd9Sstevel@tonic-gate #define	IP6OPT_JUMBO_LEN	6
165*7c478bd9Sstevel@tonic-gate 
166*7c478bd9Sstevel@tonic-gate /* NSAP Address Option */
167*7c478bd9Sstevel@tonic-gate struct	ip6_opt_nsap {
168*7c478bd9Sstevel@tonic-gate 	uint8_t	ip6on_type;
169*7c478bd9Sstevel@tonic-gate 	uint8_t	ip6on_len;
170*7c478bd9Sstevel@tonic-gate 	uint8_t ip6on_src_nsap_len;
171*7c478bd9Sstevel@tonic-gate 	uint8_t ip6on_dst_nsap_len;
172*7c478bd9Sstevel@tonic-gate 	/* Followed by source NSAP */
173*7c478bd9Sstevel@tonic-gate 	/* Followed by destination NSAP */
174*7c478bd9Sstevel@tonic-gate };
175*7c478bd9Sstevel@tonic-gate 
176*7c478bd9Sstevel@tonic-gate /* Tunnel Limit Option */
177*7c478bd9Sstevel@tonic-gate struct	ip6_opt_tunnel {
178*7c478bd9Sstevel@tonic-gate 	uint8_t	ip6ot_type;
179*7c478bd9Sstevel@tonic-gate 	uint8_t	ip6ot_len;
180*7c478bd9Sstevel@tonic-gate 	uint8_t ip6ot_encap_limit;
181*7c478bd9Sstevel@tonic-gate };
182*7c478bd9Sstevel@tonic-gate 
183*7c478bd9Sstevel@tonic-gate /* Router Alert Option */
184*7c478bd9Sstevel@tonic-gate struct	ip6_opt_router {
185*7c478bd9Sstevel@tonic-gate 	uint8_t	ip6or_type;
186*7c478bd9Sstevel@tonic-gate 	uint8_t	ip6or_len;
187*7c478bd9Sstevel@tonic-gate 	uint8_t ip6or_value[2];
188*7c478bd9Sstevel@tonic-gate };
189*7c478bd9Sstevel@tonic-gate 
190*7c478bd9Sstevel@tonic-gate /* Router alert values (in network byte order) */
191*7c478bd9Sstevel@tonic-gate #ifdef _BIG_ENDIAN
192*7c478bd9Sstevel@tonic-gate #define	IP6_ALERT_MLD			0x0000
193*7c478bd9Sstevel@tonic-gate #define	IP6_ALERT_RSVP			0x0001
194*7c478bd9Sstevel@tonic-gate #define	IP6_ALERT_AN			0x0002
195*7c478bd9Sstevel@tonic-gate #else
196*7c478bd9Sstevel@tonic-gate #define	IP6_ALERT_MLD			0x0000
197*7c478bd9Sstevel@tonic-gate #define	IP6_ALERT_RSVP			0x0100
198*7c478bd9Sstevel@tonic-gate #define	IP6_ALERT_AN			0x0200
199*7c478bd9Sstevel@tonic-gate #endif
200*7c478bd9Sstevel@tonic-gate 
201*7c478bd9Sstevel@tonic-gate /* Binding Update Option */
202*7c478bd9Sstevel@tonic-gate struct	ip6_opt_binding_update {
203*7c478bd9Sstevel@tonic-gate 	uint8_t	ip6ou_type;
204*7c478bd9Sstevel@tonic-gate 	uint8_t	ip6ou_len;
205*7c478bd9Sstevel@tonic-gate 	uint8_t ip6ou_flags;
206*7c478bd9Sstevel@tonic-gate 	uint8_t ip6ou_prefixlen;
207*7c478bd9Sstevel@tonic-gate 	uint8_t ip6ou_seqno[2];
208*7c478bd9Sstevel@tonic-gate 	uint8_t ip6ou_lifetime[4];
209*7c478bd9Sstevel@tonic-gate 	uint8_t ip6ou_coa[16];		/* Optional based on flags */
210*7c478bd9Sstevel@tonic-gate 	/* Followed by sub-options */
211*7c478bd9Sstevel@tonic-gate };
212*7c478bd9Sstevel@tonic-gate 
213*7c478bd9Sstevel@tonic-gate /* Binding Update Flags */
214*7c478bd9Sstevel@tonic-gate #define	IP6_BUF_ACK	0x80	/* Request a binding ack */
215*7c478bd9Sstevel@tonic-gate #define	IP6_BUF_HOME	0x40	/* Home Registration */
216*7c478bd9Sstevel@tonic-gate #define	IP6_BUF_COA	0x20	/* Care-of-address present in option */
217*7c478bd9Sstevel@tonic-gate #define	IP6_BUF_ROUTER	0x10	/* Sending mobile node is a router */
218*7c478bd9Sstevel@tonic-gate 
219*7c478bd9Sstevel@tonic-gate /* Binding Ack Option */
220*7c478bd9Sstevel@tonic-gate struct	ip6_opt_binding_ack {
221*7c478bd9Sstevel@tonic-gate 	uint8_t	ip6oa_type;
222*7c478bd9Sstevel@tonic-gate 	uint8_t	ip6oa_len;
223*7c478bd9Sstevel@tonic-gate 	uint8_t ip6oa_status;
224*7c478bd9Sstevel@tonic-gate 	uint8_t ip6oa_seqno[2];
225*7c478bd9Sstevel@tonic-gate 	uint8_t ip6oa_lifetime[4];
226*7c478bd9Sstevel@tonic-gate 	uint8_t ip6oa_refresh[4];
227*7c478bd9Sstevel@tonic-gate 	/* Followed by sub-options */
228*7c478bd9Sstevel@tonic-gate };
229*7c478bd9Sstevel@tonic-gate 
230*7c478bd9Sstevel@tonic-gate /* Binding Request Option */
231*7c478bd9Sstevel@tonic-gate struct	ip6_opt_binding_request {
232*7c478bd9Sstevel@tonic-gate 	uint8_t	ip6or_type;
233*7c478bd9Sstevel@tonic-gate 	uint8_t	ip6or_len;
234*7c478bd9Sstevel@tonic-gate 	/* Followed by sub-options */
235*7c478bd9Sstevel@tonic-gate };
236*7c478bd9Sstevel@tonic-gate 
237*7c478bd9Sstevel@tonic-gate /* Home Address Option */
238*7c478bd9Sstevel@tonic-gate struct	ip6_opt_home_address {
239*7c478bd9Sstevel@tonic-gate 	uint8_t	ip6oh_type;
240*7c478bd9Sstevel@tonic-gate 	uint8_t	ip6oh_len;
241*7c478bd9Sstevel@tonic-gate 	uint8_t ip6oh_addr[16];		/* Home Address */
242*7c478bd9Sstevel@tonic-gate 	/* Followed by sub-options */
243*7c478bd9Sstevel@tonic-gate };
244*7c478bd9Sstevel@tonic-gate 
245*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
246*7c478bd9Sstevel@tonic-gate }
247*7c478bd9Sstevel@tonic-gate #endif
248*7c478bd9Sstevel@tonic-gate 
249*7c478bd9Sstevel@tonic-gate #endif	/* _NETINET_IP6_H */
250