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