1 | /*
|
---|
2 | * TINET (TCP/IP Protocol Stack)
|
---|
3 | *
|
---|
4 | * Copyright (C) 2001-2009 by Dep. of Computer Science and Engineering
|
---|
5 | * Tomakomai National College of Technology, JAPAN
|
---|
6 | *
|
---|
7 | * 上記著作権者は,以下の (1)~(4) の条件か,Free Software Foundation
|
---|
8 | * によって公表されている GNU General Public License の Version 2 に記
|
---|
9 | * 述されている条件を満たす場合に限り,本ソフトウェア(本ソフトウェア
|
---|
10 | * を改変したものを含む.以下同じ)を使用・複製・改変・再配布(以下,
|
---|
11 | * 利用と呼ぶ)することを無償で許諾する.
|
---|
12 | * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
|
---|
13 | * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
|
---|
14 | * スコード中に含まれていること.
|
---|
15 | * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
|
---|
16 | * 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
|
---|
17 | * 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
|
---|
18 | * の無保証規定を掲載すること.
|
---|
19 | * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
|
---|
20 | * 用できない形で再配布する場合には,次の条件を満たすこと.
|
---|
21 | * (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
|
---|
22 | * 作権表示,この利用条件および下記の無保証規定を掲載すること.
|
---|
23 | * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
|
---|
24 | * 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
|
---|
25 | *
|
---|
26 | * 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
|
---|
27 | * よびTOPPERSプロジェクトは,本ソフトウェアに関して,その適用可能性も
|
---|
28 | * 含めて,いかなる保証も行わない.また,本ソフトウェアの利用により直
|
---|
29 | * 接的または間接的に生じたいかなる損害に関しても,その責任を負わない.
|
---|
30 | *
|
---|
31 | * @(#) $Id$
|
---|
32 | */
|
---|
33 |
|
---|
34 | /* $FreeBSD: src/sys/netinet6/in6.h,v 1.7.2.4 2001/07/04 09:45:23 ume Exp $ */
|
---|
35 | /* $KAME: in6.h,v 1.89 2001/05/27 13:28:35 itojun Exp $ */
|
---|
36 |
|
---|
37 | /*
|
---|
38 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
|
---|
39 | * 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. Neither the name of the project nor the names of its contributors
|
---|
50 | * may be used to endorse or promote products derived from this software
|
---|
51 | * without specific prior written permission.
|
---|
52 | *
|
---|
53 | * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
|
---|
54 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
---|
55 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
---|
56 | * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
|
---|
57 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
---|
58 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
---|
59 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
---|
60 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
---|
61 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
---|
62 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
---|
63 | * SUCH DAMAGE.
|
---|
64 | */
|
---|
65 |
|
---|
66 | /*
|
---|
67 | * Copyright (c) 1982, 1986, 1990, 1993
|
---|
68 | * The Regents of the University of California. All rights reserved.
|
---|
69 | *
|
---|
70 | * Redistribution and use in source and binary forms, with or without
|
---|
71 | * modification, are permitted provided that the following conditions
|
---|
72 | * are met:
|
---|
73 | * 1. Redistributions of source code must retain the above copyright
|
---|
74 | * notice, this list of conditions and the following disclaimer.
|
---|
75 | * 2. Redistributions in binary form must reproduce the above copyright
|
---|
76 | * notice, this list of conditions and the following disclaimer in the
|
---|
77 | * documentation and/or other materials provided with the distribution.
|
---|
78 | * 3. All advertising materials mentioning features or use of this software
|
---|
79 | * must display the following acknowledgement:
|
---|
80 | * This product includes software developed by the University of
|
---|
81 | * California, Berkeley and its contributors.
|
---|
82 | * 4. Neither the name of the University nor the names of its contributors
|
---|
83 | * may be used to endorse or promote products derived from this software
|
---|
84 | * without specific prior written permission.
|
---|
85 | *
|
---|
86 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
---|
87 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
---|
88 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
---|
89 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
---|
90 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
---|
91 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
---|
92 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
---|
93 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
---|
94 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
---|
95 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
---|
96 | * SUCH DAMAGE.
|
---|
97 | *
|
---|
98 | * @(#)in.h 8.3 (Berkeley) 1/3/94
|
---|
99 | */
|
---|
100 |
|
---|
101 | #ifndef _IN6_H_
|
---|
102 | #define _IN6_H_
|
---|
103 |
|
---|
104 | /*
|
---|
105 | * IPv6 アドレス
|
---|
106 | */
|
---|
107 |
|
---|
108 | struct t_in6_addr {
|
---|
109 | union {
|
---|
110 | uint8_t __u6_addr8[16];
|
---|
111 | uint16_t __u6_addr16[8];
|
---|
112 | uint32_t __u6_addr32[4];
|
---|
113 | } __u6_addr;
|
---|
114 | };
|
---|
115 |
|
---|
116 | #define s6_addr __u6_addr.__u6_addr8
|
---|
117 | #define s6_addr8 __u6_addr.__u6_addr8
|
---|
118 | #define s6_addr16 __u6_addr.__u6_addr16
|
---|
119 | #define s6_addr32 __u6_addr.__u6_addr32
|
---|
120 |
|
---|
121 | #ifndef T_IN6_ADDR_DEFINED
|
---|
122 |
|
---|
123 | typedef struct t_in6_addr T_IN6_ADDR;
|
---|
124 |
|
---|
125 | #define T_IN6_ADDR_DEFINED
|
---|
126 |
|
---|
127 | #endif /* of #ifndef T_IN6_ADDR_DEFINED */
|
---|
128 |
|
---|
129 | /*
|
---|
130 | * IPv6 アドレスの初期化データ
|
---|
131 | */
|
---|
132 |
|
---|
133 | #define IPV6_ADDR_UNSPECIFIED_INIT \
|
---|
134 | {{{ UINT_C(0x00), UINT_C(0x00), UINT_C(0x00), UINT_C(0x00), \
|
---|
135 | UINT_C(0x00), UINT_C(0x00), UINT_C(0x00), UINT_C(0x00), \
|
---|
136 | UINT_C(0x00), UINT_C(0x00), UINT_C(0x00), UINT_C(0x00), \
|
---|
137 | UINT_C(0x00), UINT_C(0x00), UINT_C(0x00), UINT_C(0x00) }}}
|
---|
138 |
|
---|
139 | #define IPV6_ADDR_LINKLOCAL_ALLNODES_INIT \
|
---|
140 | {{{ UINT_C(0xff), UINT_C(0x02), UINT_C(0x00), UINT_C(0x00), \
|
---|
141 | UINT_C(0x00), UINT_C(0x00), UINT_C(0x00), UINT_C(0x00), \
|
---|
142 | UINT_C(0x00), UINT_C(0x00), UINT_C(0x00), UINT_C(0x00), \
|
---|
143 | UINT_C(0x00), UINT_C(0x00), UINT_C(0x00), UINT_C(0x01) }}}
|
---|
144 |
|
---|
145 | #define IPV6_ADDR_LINKLOCAL_ALLROUTERS_INIT \
|
---|
146 | {{{ UINT_C(0xff), UINT_C(0x02), UINT_C(0x00), UINT_C(0x00), \
|
---|
147 | UINT_C(0x00), UINT_C(0x00), UINT_C(0x00), UINT_C(0x00), \
|
---|
148 | UINT_C(0x00), UINT_C(0x00), UINT_C(0x00), UINT_C(0x00), \
|
---|
149 | UINT_C(0x00), UINT_C(0x00), UINT_C(0x00), UINT_C(0x02) }}}
|
---|
150 |
|
---|
151 | /*
|
---|
152 | * アドレスの定義
|
---|
153 | */
|
---|
154 |
|
---|
155 | #ifdef _NET_CFG_BYTE_ORDER
|
---|
156 |
|
---|
157 | #if _NET_CFG_BYTE_ORDER == _NET_CFG_BIG_ENDIAN
|
---|
158 |
|
---|
159 | #define IPV6_ADDR_INT32_ONE ULONG_C(0x00000001)
|
---|
160 | #define IPV6_ADDR_INT32_TWO ULONG_C(0x00000002)
|
---|
161 | #define IPV6_ADDR_INT32_0000FFFF ULONG_C(0x0000ffff)
|
---|
162 | #define IPV6_ADDR_INT32_MNL ULONG_C(0xff010000)
|
---|
163 | #define IPV6_ADDR_INT32_MLL ULONG_C(0xff020000)
|
---|
164 | #define IPV6_ADDR_INT32_ULL ULONG_C(0xfe800000)
|
---|
165 | #define IPV6_ADDR_INT16_ULL UINT_C(0xfe80)
|
---|
166 | #define IPV6_ADDR_INT16_USL UINT_C(0xfec0)
|
---|
167 | #define IPV6_ADDR_INT16_MLL UINT_C(0xff02)
|
---|
168 |
|
---|
169 | #elif _NET_CFG_BYTE_ORDER == _NET_CFG_LITTLE_ENDIAN
|
---|
170 |
|
---|
171 | #define IPV6_ADDR_INT32_ONE ULONG_C(0x01000000)
|
---|
172 | #define IPV6_ADDR_INT32_TWO ULONG_C(0x02000000)
|
---|
173 | #define IPV6_ADDR_INT32_0000FFFF ULONG_C(0xffff0000)
|
---|
174 | #define IPV6_ADDR_INT32_MNL ULONG_C(0x000001ff)
|
---|
175 | #define IPV6_ADDR_INT32_MLL ULONG_C(0x000002ff)
|
---|
176 | #define IPV6_ADDR_INT32_ULL ULONG_C(0x000080fe)
|
---|
177 | #define IPV6_ADDR_INT16_ULL UINT_C(0x80fe)
|
---|
178 | #define IPV6_ADDR_INT16_USL UINT_C(0xc0fe)
|
---|
179 | #define IPV6_ADDR_INT16_MLL UINT_C(0x02ff)
|
---|
180 |
|
---|
181 | #endif /* #if _NET_CFG_BYTE_ORDER == _NET_CFG_BIG_ENDIAN */
|
---|
182 |
|
---|
183 | #endif /* of #ifdef _NET_CFG_BYTE_ORDER */
|
---|
184 |
|
---|
185 | /*
|
---|
186 | * 特別なアドレスのチェック
|
---|
187 | */
|
---|
188 |
|
---|
189 | /* 無指定 */
|
---|
190 |
|
---|
191 | #define IN6_IS_ADDR_UNSPECIFIED(a) \
|
---|
192 | (memcmp((void *)(a), (void *)&in6_addr_unspecified, sizeof(T_IN6_ADDR)) == 0)
|
---|
193 |
|
---|
194 | /* ループバック */
|
---|
195 |
|
---|
196 | #define IN6_IS_ADDR_LOOPBACK(a) \
|
---|
197 | (memcmp((void *)(a), (void *)&in6_addr_unspecified, sizeof(T_IN6_ADDR) - 1) == 0 && \
|
---|
198 | (a)->s6_addr8[15] == 0x01)
|
---|
199 |
|
---|
200 | /* IPv4 互換 */
|
---|
201 |
|
---|
202 | #define IN6_IS_ADDR_V4COMPAT(a) \
|
---|
203 | (memcmp((void *)(a), (void *)&in6_addr_unspecified, sizeof(T_IN6_ADDR) - 4) == 0 && \
|
---|
204 | (a)->s6_addr32[3] > IPV6_ADDR_INT32_ONE)
|
---|
205 |
|
---|
206 | /* IPv4 マップ */
|
---|
207 |
|
---|
208 | #define IN6_IS_ADDR_V4MAPPED(a) \
|
---|
209 | (((a)->s6_addr32[0] == ULONG_C(0x00000000)) && \
|
---|
210 | ((a)->s6_addr32[1] == ULONG_C(0x00000000)) && \
|
---|
211 | ((a)->s6_addr32[2] == IPV6_ADDR_INT32_0000FFFF))
|
---|
212 |
|
---|
213 | /*
|
---|
214 | * スコープ ID
|
---|
215 | */
|
---|
216 |
|
---|
217 | #define IPV6_ADDR_SCOPE_NODELOCAL UINT_C(0x01)
|
---|
218 | #define IPV6_ADDR_SCOPE_LINKLOCAL UINT_C(0x02)
|
---|
219 | #define IPV6_ADDR_SCOPE_SITELOCAL UINT_C(0x05)
|
---|
220 | #define IPV6_ADDR_SCOPE_ORGLOCAL UINT_C(0x08)
|
---|
221 | #define IPV6_ADDR_SCOPE_GLOBAL UINT_C(0x0e)
|
---|
222 |
|
---|
223 | /*
|
---|
224 | * ユニキャスト・スコープ
|
---|
225 | *
|
---|
226 | * 注意: 上位 10 ビットのみチェックしなければならない。RFC2373 参照
|
---|
227 | */
|
---|
228 |
|
---|
229 | /* リンクローカル */
|
---|
230 |
|
---|
231 | #define IN6_IS_ADDR_LINKLOCAL(a) \
|
---|
232 | (((a)->s6_addr8[0] == UINT_C(0xfe)) && (((a)->s6_addr8[1] & UINT_C(0xc0)) == UINT_C(0x80)))
|
---|
233 |
|
---|
234 | /* サイトローカル */
|
---|
235 |
|
---|
236 | #define IN6_IS_ADDR_SITELOCAL(a) \
|
---|
237 | (((a)->s6_addr8[0] == UINT_C(0xfe)) && (((a)->s6_addr8[1] & UINT_C(0xc0)) == UINT_C(0xc0)))
|
---|
238 |
|
---|
239 | /* 集約可能ユニキャスト (グローバル) */
|
---|
240 |
|
---|
241 | #define IN6_IS_ADDR_AGGREGATE_UNICAST(a) \
|
---|
242 | (((a)->s6_addr8[0] & UINT_C(0xe0)) == UINT_C(0x20))
|
---|
243 |
|
---|
244 | /*
|
---|
245 | * マルチキャスト
|
---|
246 | */
|
---|
247 |
|
---|
248 | #define IN6_IS_ADDR_MULTICAST(a) ((a)->s6_addr8[0] == UINT_C(0xff))
|
---|
249 |
|
---|
250 | /* 要請マルチキャスト */
|
---|
251 |
|
---|
252 | #define IN6_IS_ADDR_NS_MULTICAST(a) \
|
---|
253 | (((a)->s6_addr32[0] == IPV6_ADDR_INT32_MLL) && \
|
---|
254 | ((a)->s6_addr32[1] == ULONG_C(0x00000000)) && \
|
---|
255 | ((a)->s6_addr32[2] == IPV6_ADDR_INT32_ONE) && \
|
---|
256 | ((a)->s6_addr8[12] == UINT_C(0xff)))
|
---|
257 |
|
---|
258 | /*
|
---|
259 | * 同一のチェック
|
---|
260 | */
|
---|
261 |
|
---|
262 | #define IN6_ARE_ADDR_EQUAL(a,b) (memcmp((a), (b), sizeof(T_IN6_ADDR)) == 0)
|
---|
263 |
|
---|
264 | /*
|
---|
265 | * 経路制御用定義
|
---|
266 | */
|
---|
267 |
|
---|
268 | #define IPV6_RTHDR_TYPE_0 UINT_C(0) /* IPv6 経路制御ヘッダタイプ 0 */
|
---|
269 |
|
---|
270 | /*
|
---|
271 | * 規定値と制限値
|
---|
272 | */
|
---|
273 |
|
---|
274 | #define IPV6_DEFAULT_MULTICAST_HOPS 1 /* マルチキャスト時のホップリミットの規定値 */
|
---|
275 |
|
---|
276 | /*
|
---|
277 | * ITRON TCP/IPv6 アドレス/ポート番号の定義
|
---|
278 | */
|
---|
279 |
|
---|
280 | typedef struct t_ipv6ep {
|
---|
281 | T_IN6_ADDR ipaddr; /* IPv6 アドレス */
|
---|
282 | uint16_t portno; /* ポート番号 */
|
---|
283 | } T_IPV6EP;
|
---|
284 |
|
---|
285 | /*
|
---|
286 | * ITRON/TCP/IP 用 IP アドレスの定義
|
---|
287 | */
|
---|
288 |
|
---|
289 | #define IPV6_ADDRANY IPV6_ADDR_UNSPECIFIED_INIT
|
---|
290 |
|
---|
291 | /*
|
---|
292 | * 動的生成用 IPv6 TCP 受付口
|
---|
293 | */
|
---|
294 |
|
---|
295 | typedef struct t_tcp6_crep {
|
---|
296 | /* 標準 */
|
---|
297 | ATR repatr; /* 受付口属性 */
|
---|
298 | T_IPV6EP myaddr; /* 自分のアドレス */
|
---|
299 | /* 実装依存 */
|
---|
300 | } T_TCP6_CREP;
|
---|
301 |
|
---|
302 | #if defined(SUPPORT_INET6)
|
---|
303 | #define T_TCP_CREP T_TCP6_CREP
|
---|
304 | #endif
|
---|
305 |
|
---|
306 | /*
|
---|
307 | * 動的生成用 IPv6 UDP 通信端点
|
---|
308 | */
|
---|
309 |
|
---|
310 | typedef struct t_udp6_ccep {
|
---|
311 | /* 標準 */
|
---|
312 | ATR cepatr; /* UDP 通信端点属性 */
|
---|
313 | T_IPV6EP myaddr; /* 自分のアドレス */
|
---|
314 | FP callback; /* コールバック関数 */
|
---|
315 | /* 実装依存 */
|
---|
316 | } T_UDP6_CCEP;
|
---|
317 |
|
---|
318 | #if defined(SUPPORT_INET6)
|
---|
319 | #define T_UDP_CCEP T_UDP6_CCEP
|
---|
320 | #endif
|
---|
321 |
|
---|
322 | /*
|
---|
323 | * IPv4 と IPv6 をコンパイル時に選択するためのマクロ
|
---|
324 | */
|
---|
325 |
|
---|
326 | #if defined(SUPPORT_INET6)
|
---|
327 |
|
---|
328 | #define T_IN_ADDR T_IN6_ADDR
|
---|
329 | #define T_IPEP T_IPV6EP
|
---|
330 | #define IP_ADDRANY IPV6_ADDRANY
|
---|
331 |
|
---|
332 | #define IN_ARE_ADDR_EQUAL(n,h) IN6_ARE_ADDR_EQUAL(n,h)
|
---|
333 | #define IN_ARE_NET_ADDR_EQUAL(n,h) IN6_ARE_ADDR_EQUAL(n,h)
|
---|
334 | #define IN_COPY_TO_NET(d,s) memcpy(d,s,sizeof(T_IN6_ADDR))
|
---|
335 | #define IN_COPY_TO_HOST(d,s) memcpy(d,s,sizeof(T_IN6_ADDR))
|
---|
336 | #define IN_IS_ADDR_MULTICAST(a) IN6_IS_ADDR_MULTICAST(a)
|
---|
337 | #define IN_IS_NET_ADDR_MULTICAST(a) IN6_IS_ADDR_MULTICAST(a)
|
---|
338 | #define IN_IS_ADDR_ANY(a) IN6_IS_ADDR_UNSPECIFIED(a)
|
---|
339 |
|
---|
340 | #endif /* of #if defined(SUPPORT_INET6) */
|
---|
341 |
|
---|
342 | /*
|
---|
343 | * 前方参照
|
---|
344 | */
|
---|
345 |
|
---|
346 | #ifndef T_IFNET_DEFINED
|
---|
347 |
|
---|
348 | typedef struct t_ifnet T_IFNET;
|
---|
349 |
|
---|
350 | #define T_IFNET_DEFINED
|
---|
351 |
|
---|
352 | #endif /* of #ifndef T_IFNET_DEFINED */
|
---|
353 |
|
---|
354 | /*
|
---|
355 | * 全域変数
|
---|
356 | */
|
---|
357 |
|
---|
358 | extern T_IN6_ADDR in6_addr_unspecified;
|
---|
359 | extern T_IN6_ADDR in6_addr_linklocal_allnodes;
|
---|
360 | extern T_IN6_ADDR in6_addr_linklocal_allrouters;
|
---|
361 |
|
---|
362 | #define ipv6_addrany in6_addr_unspecified
|
---|
363 |
|
---|
364 | /*
|
---|
365 | * TINET 独自 API
|
---|
366 | */
|
---|
367 |
|
---|
368 | extern char *ipv62str (char *buf, const T_IN6_ADDR *p_ip6addr);
|
---|
369 | extern ER_UINT in6_get_maxnum_ifaddr (void);
|
---|
370 | extern const T_IN6_ADDR *in6_get_ifaddr (int_t index);
|
---|
371 |
|
---|
372 | #endif /* of #ifndef _IN6_H_ */
|
---|