1 | /*
|
---|
2 | * TINET (TCP/IP Protocol Stack)
|
---|
3 | *
|
---|
4 | * Copyright (C) 2001-2017 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/ip6_var.h,v 1.10 2002/10/16 01:54:45 sam Exp $ */
|
---|
35 | /* $KAME: ip6_var.h,v 1.62 2001/05/03 14:51:48 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, 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 | * @(#)ip_var.h 8.1 (Berkeley) 6/10/93
|
---|
99 | */
|
---|
100 |
|
---|
101 | #ifndef _IP6_VAR_H_
|
---|
102 | #define _IP6_VAR_H_
|
---|
103 |
|
---|
104 | /*
|
---|
105 | * IPv6 ヘッダ・ペイロードアクセスマクロ
|
---|
106 | */
|
---|
107 |
|
---|
108 | #define IF_IP6_HDR_SIZE (IF_HDR_SIZE + IP6_HDR_SIZE)
|
---|
109 |
|
---|
110 | #define GET_IP6_HDR(nbuf) ((T_IP6_HDR*)((nbuf)->buf + IF_HDR_SIZE))
|
---|
111 | #define GET_IP6_SDU(nbuf) ((uint8_t*)((nbuf)->buf) + GET_IF_IP6_HDR_SIZE(nbuf))
|
---|
112 | #define GET_IP6_NEXT_HDR(nbuf) ((uint8_t*)((nbuf)->buf) + IF_IP6_HDR_SIZE)
|
---|
113 |
|
---|
114 | #define GET_IP6_HDR_SIZE(nbuf) (get_ip6_hdr_size(nbuf))
|
---|
115 | #define GET_IP6_SDU_SIZE(nbuf) (ntohs(GET_IP6_HDR(nbuf)->plen))
|
---|
116 | #define GET_IF_IP6_HDR_SIZE(nbuf) (IF_HDR_SIZE + (GET_IP6_HDR_SIZE(nbuf)))
|
---|
117 |
|
---|
118 | #define SET_IP6_CF(nbuf,cf) (GET_IP6_HDR(nbuf)->vcf=htonl(IP6_MAKE_VCF(IP6_VCF_V(ntohl(GET_IP6_HDR(nbuf)->vcf)),cf)))
|
---|
119 | #define SET_IP6_SDU_SIZE(nbuf,slen) (GET_IP6_HDR(nbuf)->plen=htons(slen))
|
---|
120 |
|
---|
121 | /* ip6_output のフラグ */
|
---|
122 |
|
---|
123 | #define IPV6_OUT_FLG_DAD 0x0100 /* 重複アドレス検出 */
|
---|
124 | #define IPV6_OUT_FLG_HOP_LIMIT 0x0200 /* ホップリミット指定 */
|
---|
125 |
|
---|
126 | /* ホップリミットフラグが付く時、ホップリミット値を操作するマクロ */
|
---|
127 |
|
---|
128 | #define IPV6_OUT_GET_HOP_LIMIT(f) ((f)&0x00ff)
|
---|
129 | #define IPV6_OUT_SET_HOP_LIMIT(f,l) ((f)|(l))
|
---|
130 |
|
---|
131 | /*
|
---|
132 | * ip6_unknown_opt -- 未知のオプションの処理
|
---|
133 | *
|
---|
134 | * 戻り値:
|
---|
135 | *
|
---|
136 | * 0 以上 正常、オプション長。
|
---|
137 | * IP6_OPT_RET_ERR (-1) エラー、呼出側でネットワークバッファを開放する。
|
---|
138 | * IP6_OPT_RET_REL (-2) エラー、ネットワークバッファは開放されている。
|
---|
139 | */
|
---|
140 |
|
---|
141 | #define IP6_OPT_RET_ERR (-1)
|
---|
142 | #define IP6_OPT_RET_REL (-2)
|
---|
143 |
|
---|
144 | /*
|
---|
145 | * IPv6 の MMTU サイズのネットワークバッファ
|
---|
146 | */
|
---|
147 |
|
---|
148 | #if defined(IF_HDR_SIZE)
|
---|
149 |
|
---|
150 | typedef struct t_net_buf_ipv6_mmtu {
|
---|
151 | uint16_t len; /* データの長さ */
|
---|
152 | uint8_t idix; /* mpfid のインデックス */
|
---|
153 | uint8_t unit; /* インタフェース番号 */
|
---|
154 | #ifdef IF_ETHER_NIC_NET_BUF_ALIGN
|
---|
155 | uint8_t nalign[IF_ETHER_NIC_NET_BUF_ALIGN];
|
---|
156 | #endif
|
---|
157 | #if CPU_NET_ALIGN == 4 && IF_HDR_ALIGN != 4
|
---|
158 | uint8_t halign[4 - IF_HDR_ALIGN];
|
---|
159 | #endif
|
---|
160 | uint8_t buf[IF_HDR_SIZE + IPV6_MMTU];
|
---|
161 | /* バッファ本体 */
|
---|
162 | } T_NET_BUF_IPV6_MMTU;
|
---|
163 |
|
---|
164 | #endif /* of #if defined(IF_HDR_SIZE) */
|
---|
165 |
|
---|
166 | /*
|
---|
167 | * 65536 オクテットサイズのネットワークバッファ
|
---|
168 | */
|
---|
169 |
|
---|
170 | typedef struct t_net_buf6_65536 {
|
---|
171 | uint16_t len; /* データの長さ */
|
---|
172 | uint8_t idix; /* mpfid のインデックス */
|
---|
173 | uint8_t flags; /* フラグ */
|
---|
174 | #ifdef IF_ETHER_NIC_NET_BUF_ALIGN
|
---|
175 | uint8_t nalign[IF_ETHER_NIC_NET_BUF_ALIGN];
|
---|
176 | #endif
|
---|
177 | #if CPU_NET_ALIGN == 4 && IF_HDR_ALIGN != 4
|
---|
178 | uint8_t halign[4 - IF_HDR_ALIGN];
|
---|
179 | #endif
|
---|
180 | uint8_t buf[IF_IP6_HDR_SIZE + 65536];
|
---|
181 | /* バッファ本体 */
|
---|
182 | #if defined(IF_PDU_HDR_PADDING)
|
---|
183 | uint8_t padding[IF_PDU_HDR_PADDING];
|
---|
184 | #endif /* ヘッダの余分 */
|
---|
185 | } T_NET_BUF6_65536;
|
---|
186 |
|
---|
187 | #ifdef IP6_CFG_FRAGMENT
|
---|
188 |
|
---|
189 | /*
|
---|
190 | * 再構成キュー用 IPv6 ヘッダの定義
|
---|
191 | */
|
---|
192 |
|
---|
193 | typedef struct t_qip6_hdr {
|
---|
194 | uint32_t vcf; /* Version: 4 bit */
|
---|
195 | /* Traffic Class: 8 bit */
|
---|
196 | /* Flow Label: 20 bit */
|
---|
197 | uint16_t plen; /* Payload Length */
|
---|
198 | uint8_t next; /* Next Header */
|
---|
199 | uint8_t hlim; /* Hop Limit */
|
---|
200 | T_IN6_ADDR src; /* Source Address */
|
---|
201 | T_NET_BUF *next_frag; /* 次の IPv6 フラグメント */
|
---|
202 | uint16_t foff; /* 断片ヘッダのオフセット */
|
---|
203 | uint16_t flen; /* 断片長 */
|
---|
204 | uint16_t ftim; /* 再構成タイムアウト */
|
---|
205 | uint16_t dummy1;
|
---|
206 | uint8_t dummy2[sizeof(T_IN6_ADDR) - (sizeof(T_NET_BUF*) + sizeof(uint16_t) * 4)];
|
---|
207 | } __attribute__((packed, aligned(2)))T_QIP6_HDR;
|
---|
208 |
|
---|
209 | #define QIP6_HDR_SIZE (sizeof(T_QIP6_HDR))
|
---|
210 | #define IF_QIP6_HDR_SIZE (IF_HDR_SIZE + QIP6_HDR_SIZE)
|
---|
211 |
|
---|
212 | #define GET_QIP6_HDR(nbuf) ((T_QIP6_HDR*)((nbuf)->buf + IF_HDR_SIZE))
|
---|
213 | #define GET_QIP6_SDU(nbuf) ((uint8_t*)(nbuf)->buf + GET_IF_QIP6_HDR_SIZE(nbuf))
|
---|
214 |
|
---|
215 | #define GET_QIP6_HDR_SIZE(iph) ((uint8_t)IP6_VHL_HL((iph)->vhl) << 2)
|
---|
216 | #define GET_IF_QIP6_HDR_SIZE(nbuf) (IF_HDR_SIZE + (GET_QIP6_HDR_SIZE(GET_QIP6_HDR(nbuf))))
|
---|
217 |
|
---|
218 | /*
|
---|
219 | * データグラム再構成用ネットワークバッファ
|
---|
220 | */
|
---|
221 |
|
---|
222 | typedef struct t_net_buf6_reassm {
|
---|
223 | uint16_t len; /* データの長さ */
|
---|
224 | uint8_t idix; /* mpfid のインデックス */
|
---|
225 | uint8_t flags; /* フラグ */
|
---|
226 | #ifdef IF_ETHER_NIC_NET_BUF_ALIGN
|
---|
227 | uint8_t nalign[IF_ETHER_NIC_NET_BUF_ALIGN];
|
---|
228 | #endif
|
---|
229 | #if CPU_NET_ALIGN == 4 && IF_HDR_ALIGN != 4
|
---|
230 | uint8_t align[4 - IF_HDR_ALIGN];
|
---|
231 | #endif
|
---|
232 | uint8_t buf[IP6_CFG_FRAG_REASSM_SIZE];
|
---|
233 | /* バッファ本体 */
|
---|
234 | } T_NET_BUF6_REASSM;
|
---|
235 |
|
---|
236 | #endif /* of #ifdef IP6_CFG_FRAGMENT */
|
---|
237 |
|
---|
238 | /*
|
---|
239 | * TCP の再構成キューにおける IPv6 ヘッダの定義
|
---|
240 | */
|
---|
241 |
|
---|
242 | typedef struct t_ip6_tcp_q_hdr {
|
---|
243 | uint8_t vc; /* Version: 4 bit */
|
---|
244 | uint8_t cf; /* Traffic Class: 8 bit */
|
---|
245 | /* Flow Label: 4 bit (20 bit) */
|
---|
246 | uint16_t thoff; /* TCP ヘッダのオフセット */
|
---|
247 | uint16_t plen; /* Payload Length */
|
---|
248 | uint8_t next; /* Next Header */
|
---|
249 | uint8_t hlim; /* Hop Limit */
|
---|
250 | T_IN6_ADDR src; /* Source Address */
|
---|
251 | T_IN6_ADDR dst; /* Destination Address */
|
---|
252 | } __attribute__((packed, aligned(2))) T_IP6_TCP_Q_HDR;
|
---|
253 |
|
---|
254 | #ifdef SUPPORT_MIB
|
---|
255 |
|
---|
256 | /*
|
---|
257 | * SNMP の 管理情報ベース (MIB)
|
---|
258 | */
|
---|
259 |
|
---|
260 | typedef struct t_in6_ifstat {
|
---|
261 | uint32_t ipv6IfStatsInReceives;
|
---|
262 | uint32_t ipv6IfStatsInHdrErrors;
|
---|
263 | /* uint32_t ipv6IfStatsInTooBigErrors;*/
|
---|
264 | /* uint32_t ipv6IfStatsInNoRoutes;*/
|
---|
265 | uint32_t ipv6IfStatsInAddrErrors;
|
---|
266 | uint32_t ipv6IfStatsInUnknownProtos;
|
---|
267 | uint32_t ipv6IfStatsInTruncatedPkts;
|
---|
268 | /* uint32_t ipv6IfStatsInDiscards;*/
|
---|
269 | /* uint32_t ipv6IfStatsInDelivers;*/
|
---|
270 | /* uint32_t ipv6IfStatsOutForwDatagrams;*/
|
---|
271 | uint32_t ipv6IfStatsOutRequests;
|
---|
272 | uint32_t ipv6IfStatsOutDiscards;
|
---|
273 | uint32_t ipv6IfStatsOutFragOKs;
|
---|
274 | uint32_t ipv6IfStatsOutFragFails;
|
---|
275 | uint32_t ipv6IfStatsOutFragCreates;
|
---|
276 | uint32_t ipv6IfStatsReasmReqds;
|
---|
277 | uint32_t ipv6IfStatsReasmOKs;
|
---|
278 | uint32_t ipv6IfStatsReasmFails;
|
---|
279 | uint32_t ipv6IfStatsInMcastPkts;
|
---|
280 | uint32_t ipv6IfStatsOutMcastPkts;
|
---|
281 | } T_IN6_IFSTAT;
|
---|
282 |
|
---|
283 | extern T_IN6_IFSTAT in6_ifstat;
|
---|
284 |
|
---|
285 | #endif /* of #ifdef SUPPORT_MIB */
|
---|
286 |
|
---|
287 | /*
|
---|
288 | * 変数
|
---|
289 | */
|
---|
290 |
|
---|
291 | extern uint8_t ip6_defhlim;
|
---|
292 |
|
---|
293 | /*
|
---|
294 | * 関数
|
---|
295 | */
|
---|
296 |
|
---|
297 | extern ER ip6_output (T_NET_BUF *output, uint16_t flags, TMO tmout);
|
---|
298 | extern void ip6_init (void);
|
---|
299 | extern uint8_t *ip6_get_prev_hdr (T_NET_BUF *nbuf, uint_t off);
|
---|
300 | extern uint_t get_ip6_hdr_size (T_NET_BUF *nbuf);
|
---|
301 | extern ER_UINT ip6_nexthdr (T_NET_BUF *nbuf, uint_t off, uint_t proto, uint_t *nextp);
|
---|
302 | extern ER_UINT ip6_lasthdr (T_NET_BUF *nbuf, uint_t off, uint_t proto, uint_t *nextp);
|
---|
303 | extern ER_UINT ip6_unknown_opt (T_NET_BUF *input, uint8_t *opt);
|
---|
304 | extern uint_t dest6_input (T_NET_BUF **inputp, uint_t *offp, uint_t *nextp);
|
---|
305 | extern uint_t route6_input (T_NET_BUF **inputp, uint_t *offp, uint_t *nextp);
|
---|
306 | extern uint_t frag6_input (T_NET_BUF **inputp, uint_t *offp, uint_t *nextp);
|
---|
307 | extern void frag6_timer (void);
|
---|
308 | extern ER ip6_remove_exthdrs (T_NET_BUF *nbuf);
|
---|
309 |
|
---|
310 | #endif /* of #ifndef _IP6_VAR_H_ */
|
---|