1 |
786 |
skrzyp |
//==========================================================================
|
2 |
|
|
//
|
3 |
|
|
// include/netinet6_ipv6.h
|
4 |
|
|
//
|
5 |
|
|
//
|
6 |
|
|
//
|
7 |
|
|
//==========================================================================
|
8 |
|
|
// ####BSDALTCOPYRIGHTBEGIN####
|
9 |
|
|
// -------------------------------------------
|
10 |
|
|
// Portions of this software may have been derived from OpenBSD
|
11 |
|
|
// or other sources, and if so are covered by the appropriate copyright
|
12 |
|
|
// and license included herein.
|
13 |
|
|
// -------------------------------------------
|
14 |
|
|
// ####BSDALTCOPYRIGHTEND####
|
15 |
|
|
//==========================================================================
|
16 |
|
|
//#####DESCRIPTIONBEGIN####
|
17 |
|
|
//
|
18 |
|
|
// Author(s): gthomas
|
19 |
|
|
// Contributors: gthomas
|
20 |
|
|
// Date: 2000-01-10
|
21 |
|
|
// Purpose:
|
22 |
|
|
// Description:
|
23 |
|
|
//
|
24 |
|
|
//
|
25 |
|
|
//####DESCRIPTIONEND####
|
26 |
|
|
//
|
27 |
|
|
//==========================================================================
|
28 |
|
|
|
29 |
|
|
|
30 |
|
|
/* $OpenBSD: ip6.h,v 1.1 1999/12/08 06:50:21 itojun Exp $ */
|
31 |
|
|
|
32 |
|
|
/*
|
33 |
|
|
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
|
34 |
|
|
* All rights reserved.
|
35 |
|
|
*
|
36 |
|
|
* Redistribution and use in source and binary forms, with or without
|
37 |
|
|
* modification, are permitted provided that the following conditions
|
38 |
|
|
* are met:
|
39 |
|
|
* 1. Redistributions of source code must retain the above copyright
|
40 |
|
|
* notice, this list of conditions and the following disclaimer.
|
41 |
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
42 |
|
|
* notice, this list of conditions and the following disclaimer in the
|
43 |
|
|
* documentation and/or other materials provided with the distribution.
|
44 |
|
|
* 3. Neither the name of the project nor the names of its contributors
|
45 |
|
|
* may be used to endorse or promote products derived from this software
|
46 |
|
|
* without specific prior written permission.
|
47 |
|
|
*
|
48 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
|
49 |
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
50 |
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
51 |
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
|
52 |
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
53 |
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
54 |
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
55 |
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
56 |
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
57 |
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
58 |
|
|
* SUCH DAMAGE.
|
59 |
|
|
*/
|
60 |
|
|
|
61 |
|
|
/*
|
62 |
|
|
* Copyright (c) 1982, 1986, 1993
|
63 |
|
|
* The Regents of the University of California. All rights reserved.
|
64 |
|
|
*
|
65 |
|
|
* Redistribution and use in source and binary forms, with or without
|
66 |
|
|
* modification, are permitted provided that the following conditions
|
67 |
|
|
* are met:
|
68 |
|
|
* 1. Redistributions of source code must retain the above copyright
|
69 |
|
|
* notice, this list of conditions and the following disclaimer.
|
70 |
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
71 |
|
|
* notice, this list of conditions and the following disclaimer in the
|
72 |
|
|
* documentation and/or other materials provided with the distribution.
|
73 |
|
|
* 3. All advertising materials mentioning features or use of this software
|
74 |
|
|
* must display the following acknowledgement:
|
75 |
|
|
* This product includes software developed by the University of
|
76 |
|
|
* California, Berkeley and its contributors.
|
77 |
|
|
* 4. Neither the name of the University nor the names of its contributors
|
78 |
|
|
* may be used to endorse or promote products derived from this software
|
79 |
|
|
* without specific prior written permission.
|
80 |
|
|
*
|
81 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
82 |
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
83 |
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
84 |
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
85 |
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
86 |
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
87 |
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
88 |
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
89 |
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
90 |
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
91 |
|
|
* SUCH DAMAGE.
|
92 |
|
|
*
|
93 |
|
|
* @(#)ip.h 8.1 (Berkeley) 6/10/93
|
94 |
|
|
*/
|
95 |
|
|
|
96 |
|
|
#ifndef _NETINET6_IPV6_H_
|
97 |
|
|
#define _NETINET6_IPV6_H_
|
98 |
|
|
|
99 |
|
|
/*
|
100 |
|
|
* Definition for internet protocol version 6.
|
101 |
|
|
* RFC 2460
|
102 |
|
|
*/
|
103 |
|
|
|
104 |
|
|
struct ip6_hdr {
|
105 |
|
|
union {
|
106 |
|
|
struct ip6_hdrctl {
|
107 |
|
|
u_int32_t ip6_un1_flow; /* 20 bits of flow-ID */
|
108 |
|
|
u_int16_t ip6_un1_plen; /* payload length */
|
109 |
|
|
u_int8_t ip6_un1_nxt; /* next header */
|
110 |
|
|
u_int8_t ip6_un1_hlim; /* hop limit */
|
111 |
|
|
} ip6_un1;
|
112 |
|
|
u_int8_t ip6_un2_vfc; /* 4 bits version, 4 bits class */
|
113 |
|
|
} ip6_ctlun;
|
114 |
|
|
struct in6_addr ip6_src; /* source address */
|
115 |
|
|
struct in6_addr ip6_dst; /* destination address */
|
116 |
|
|
};
|
117 |
|
|
|
118 |
|
|
#define ip6_vfc ip6_ctlun.ip6_un2_vfc
|
119 |
|
|
#define ip6_flow ip6_ctlun.ip6_un1.ip6_un1_flow
|
120 |
|
|
#define ip6_plen ip6_ctlun.ip6_un1.ip6_un1_plen
|
121 |
|
|
#define ip6_nxt ip6_ctlun.ip6_un1.ip6_un1_nxt
|
122 |
|
|
#define ip6_hlim ip6_ctlun.ip6_un1.ip6_un1_hlim
|
123 |
|
|
#define ip6_hops ip6_ctlun.ip6_un1.ip6_un1_hlim
|
124 |
|
|
|
125 |
|
|
#define IPV6_VERSION 0x60
|
126 |
|
|
#define IPV6_VERSION_MASK 0xf0
|
127 |
|
|
|
128 |
|
|
#if BYTE_ORDER == BIG_ENDIAN
|
129 |
|
|
#define IPV6_FLOWINFO_MASK 0x0fffffff /* flow info (28 bits) */
|
130 |
|
|
#define IPV6_FLOWLABEL_MASK 0x000fffff /* flow label (20 bits) */
|
131 |
|
|
#else
|
132 |
|
|
#if BYTE_ORDER == LITTLE_ENDIAN
|
133 |
|
|
#define IPV6_FLOWINFO_MASK 0xffffff0f /* flow info (28 bits) */
|
134 |
|
|
#define IPV6_FLOWLABEL_MASK 0xffff0f00 /* flow label (20 bits) */
|
135 |
|
|
#endif /* LITTLE_ENDIAN */
|
136 |
|
|
#endif
|
137 |
|
|
#if 1
|
138 |
|
|
/* ECN bits proposed by Sally Floyd */
|
139 |
|
|
#define IP6TOS_CE 0x01 /* congestion experienced */
|
140 |
|
|
#define IP6TOS_ECT 0x02 /* ECN-capable transport */
|
141 |
|
|
#endif
|
142 |
|
|
|
143 |
|
|
/*
|
144 |
|
|
* Extension Headers
|
145 |
|
|
*/
|
146 |
|
|
|
147 |
|
|
struct ip6_ext {
|
148 |
|
|
u_char ip6e_nxt;
|
149 |
|
|
u_char ip6e_len;
|
150 |
|
|
};
|
151 |
|
|
|
152 |
|
|
/* Hop-by-Hop options header */
|
153 |
|
|
/* XXX should we pad it to force alignment on an 8-byte boundary? */
|
154 |
|
|
struct ip6_hbh {
|
155 |
|
|
u_int8_t ip6h_nxt; /* next header */
|
156 |
|
|
u_int8_t ip6h_len; /* length in units of 8 octets */
|
157 |
|
|
/* followed by options */
|
158 |
|
|
};
|
159 |
|
|
|
160 |
|
|
/* Destination options header */
|
161 |
|
|
/* XXX should we pad it to force alignment on an 8-byte boundary? */
|
162 |
|
|
struct ip6_dest {
|
163 |
|
|
u_int8_t ip6d_nxt; /* next header */
|
164 |
|
|
u_int8_t ip6d_len; /* length in units of 8 octets */
|
165 |
|
|
/* followed by options */
|
166 |
|
|
};
|
167 |
|
|
|
168 |
|
|
/* Option types and related macros */
|
169 |
|
|
#define IP6OPT_PAD1 0x00 /* 00 0 00000 */
|
170 |
|
|
#define IP6OPT_PADN 0x01 /* 00 0 00001 */
|
171 |
|
|
#define IP6OPT_JUMBO 0xC2 /* 11 0 00010 = 194 */
|
172 |
|
|
#define IP6OPT_JUMBO_LEN 6
|
173 |
|
|
#define IP6OPT_RTALERT 0x05 /* 00 0 00101 */
|
174 |
|
|
#define IP6OPT_RTALERT_LEN 4
|
175 |
|
|
#define IP6OPT_RTALERT_MLD 0 /* Datagram contains an MLD message */
|
176 |
|
|
#define IP6OPT_RTALERT_RSVP 1 /* Datagram contains an RSVP message */
|
177 |
|
|
#define IP6OPT_RTALERT_ACTNET 2 /* contains an Active Networks msg */
|
178 |
|
|
#define IP6OPT_MINLEN 2
|
179 |
|
|
|
180 |
|
|
#define IP6OPT_TYPE(o) ((o) & 0xC0)
|
181 |
|
|
#define IP6OPT_TYPE_SKIP 0x00
|
182 |
|
|
#define IP6OPT_TYPE_DISCARD 0x40
|
183 |
|
|
#define IP6OPT_TYPE_FORCEICMP 0x80
|
184 |
|
|
#define IP6OPT_TYPE_ICMP 0xC0
|
185 |
|
|
|
186 |
|
|
#define IP6OPT_MUTABLE 0x20
|
187 |
|
|
|
188 |
|
|
/* Routing header */
|
189 |
|
|
struct ip6_rthdr {
|
190 |
|
|
u_int8_t ip6r_nxt; /* next header */
|
191 |
|
|
u_int8_t ip6r_len; /* length in units of 8 octets */
|
192 |
|
|
u_int8_t ip6r_type; /* routing type */
|
193 |
|
|
u_int8_t ip6r_segleft; /* segments left */
|
194 |
|
|
/* followed by routing type specific data */
|
195 |
|
|
};
|
196 |
|
|
|
197 |
|
|
/* Type 0 Routing header */
|
198 |
|
|
struct ip6_rthdr0 {
|
199 |
|
|
u_int8_t ip6r0_nxt; /* next header */
|
200 |
|
|
u_int8_t ip6r0_len; /* length in units of 8 octets */
|
201 |
|
|
u_int8_t ip6r0_type; /* always zero */
|
202 |
|
|
u_int8_t ip6r0_segleft; /* segments left */
|
203 |
|
|
u_int8_t ip6r0_reserved; /* reserved field */
|
204 |
|
|
u_int8_t ip6r0_slmap[3]; /* strict/loose bit map */
|
205 |
|
|
struct in6_addr ip6r0_addr[1]; /* up to 23 addresses */
|
206 |
|
|
};
|
207 |
|
|
|
208 |
|
|
/* Fragment header */
|
209 |
|
|
struct ip6_frag {
|
210 |
|
|
u_int8_t ip6f_nxt; /* next header */
|
211 |
|
|
u_int8_t ip6f_reserved; /* reserved field */
|
212 |
|
|
u_int16_t ip6f_offlg; /* offset, reserved, and flag */
|
213 |
|
|
u_int32_t ip6f_ident; /* identification */
|
214 |
|
|
};
|
215 |
|
|
|
216 |
|
|
#if BYTE_ORDER == BIG_ENDIAN
|
217 |
|
|
#define IP6F_OFF_MASK 0xfff8 /* mask out offset from _offlg */
|
218 |
|
|
#define IP6F_RESERVED_MASK 0x0006 /* reserved bits in ip6f_offlg */
|
219 |
|
|
#define IP6F_MORE_FRAG 0x0001 /* more-fragments flag */
|
220 |
|
|
#else /* BYTE_ORDER == LITTLE_ENDIAN */
|
221 |
|
|
#define IP6F_OFF_MASK 0xf8ff /* mask out offset from _offlg */
|
222 |
|
|
#define IP6F_RESERVED_MASK 0x0600 /* reserved bits in ip6f_offlg */
|
223 |
|
|
#define IP6F_MORE_FRAG 0x0100 /* more-fragments flag */
|
224 |
|
|
#endif /* BYTE_ORDER == LITTLE_ENDIAN */
|
225 |
|
|
|
226 |
|
|
/*
|
227 |
|
|
* Internet implementation parameters.
|
228 |
|
|
*/
|
229 |
|
|
#define IPV6_MAXHLIM 255 /* maximun hoplimit */
|
230 |
|
|
#define IPV6_DEFHLIM 64 /* default hlim */
|
231 |
|
|
#define IPV6_FRAGTTL 120 /* ttl for fragment packets, in slowtimo tick */
|
232 |
|
|
#define IPV6_HLIMDEC 1 /* subtracted when forwaeding */
|
233 |
|
|
|
234 |
|
|
#define IPV6_MMTU 1280 /* minimal MTU and reassembly. 1024 + 256 */
|
235 |
|
|
#define IPV6_MAXPACKET 65535 /* ip6 max packet size without Jumbo payload*/
|
236 |
|
|
|
237 |
|
|
/*
|
238 |
|
|
* IP6_EXTHDR_CHECK ensures that region between the IP6 header and the
|
239 |
|
|
* target header (including IPv6 itself, extension headers and
|
240 |
|
|
* TCP/UDP/ICMP6 headers) are continuous. KAME requires drivers
|
241 |
|
|
* to store incoming data into one internal mbuf or one or more external
|
242 |
|
|
* mbufs(never into two or more internal mbufs). Thus, the third case is
|
243 |
|
|
* supposed to never be matched but is prepared just in case.
|
244 |
|
|
*/
|
245 |
|
|
|
246 |
|
|
#define IP6_EXTHDR_CHECK(m, off, hlen, ret) \
|
247 |
|
|
do { \
|
248 |
|
|
if ((m)->m_next != NULL) { \
|
249 |
|
|
if (((m)->m_flags & M_LOOP) && \
|
250 |
|
|
((m)->m_len < (off) + (hlen)) && \
|
251 |
|
|
(((m) = m_pullup((m), (off) + (hlen))) == NULL)) { \
|
252 |
|
|
ip6stat.ip6s_exthdrtoolong++; \
|
253 |
|
|
return ret; \
|
254 |
|
|
} else if ((m)->m_flags & M_EXT) { \
|
255 |
|
|
if ((m)->m_len < (off) + (hlen)) { \
|
256 |
|
|
ip6stat.ip6s_exthdrtoolong++; \
|
257 |
|
|
m_freem(m); \
|
258 |
|
|
return ret; \
|
259 |
|
|
} \
|
260 |
|
|
} else { \
|
261 |
|
|
if ((m)->m_len < (off) + (hlen)) { \
|
262 |
|
|
ip6stat.ip6s_exthdrtoolong++; \
|
263 |
|
|
m_freem(m); \
|
264 |
|
|
return ret; \
|
265 |
|
|
} \
|
266 |
|
|
} \
|
267 |
|
|
} \
|
268 |
|
|
else { \
|
269 |
|
|
if ((m)->m_len < (off) + (hlen)) { \
|
270 |
|
|
ip6stat.ip6s_tooshort++; \
|
271 |
|
|
in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_truncated); \
|
272 |
|
|
m_freem(m); \
|
273 |
|
|
return ret; \
|
274 |
|
|
} \
|
275 |
|
|
} \
|
276 |
|
|
} while (0)
|
277 |
|
|
|
278 |
|
|
#ifdef __NetBSD__
|
279 |
|
|
/*
|
280 |
|
|
* IP6_EXTHDR_GET ensures that intermediate protocol header (from "off" to
|
281 |
|
|
* "len") is located in single mbuf, on contiguous memory region.
|
282 |
|
|
* The pointer to the region will be returned to pointer variable "val",
|
283 |
|
|
* with type "typ".
|
284 |
|
|
* IP6_EXTHDR_GET0 does the same, except that it aligns the structure at the
|
285 |
|
|
* very top of mbuf. GET0 is likely to make memory copy than GET.
|
286 |
|
|
*
|
287 |
|
|
* XXX we're now testing this, needs m_pulldown()
|
288 |
|
|
*/
|
289 |
|
|
#define IP6_EXTHDR_GET(val, typ, m, off, len) \
|
290 |
|
|
do { \
|
291 |
|
|
struct mbuf *t; \
|
292 |
|
|
int tmp; \
|
293 |
|
|
t = m_pulldown((m), (off), (len), &tmp); \
|
294 |
|
|
if (t) { \
|
295 |
|
|
if (t->m_len < tmp + (len)) \
|
296 |
|
|
panic("m_pulldown malfunction"); \
|
297 |
|
|
(val) = (typ)(mtod(t, caddr_t) + tmp); \
|
298 |
|
|
} else \
|
299 |
|
|
(val) = (typ)NULL; \
|
300 |
|
|
} while (0)
|
301 |
|
|
|
302 |
|
|
#define IP6_EXTHDR_GET0(val, typ, m, off, len) \
|
303 |
|
|
do { \
|
304 |
|
|
struct mbuf *t; \
|
305 |
|
|
t = m_pulldown((m), (off), (len), NULL); \
|
306 |
|
|
if (t) { \
|
307 |
|
|
if (t->m_len < (len)) \
|
308 |
|
|
panic("m_pulldown malfunction"); \
|
309 |
|
|
(val) = (typ)mtod(t, caddr_t); \
|
310 |
|
|
} else \
|
311 |
|
|
(val) = (typ)NULL; \
|
312 |
|
|
} while (0)
|
313 |
|
|
|
314 |
|
|
#endif /*NetBSD*/
|
315 |
|
|
|
316 |
|
|
#endif /* not _NETINET_IPV6_H_ */
|