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