source: EcnlProtoTool/trunk/asp3_dcre/tinet/netinet6/frag6.c@ 270

Last change on this file since 270 was 270, checked in by coas-nagasima, 7 years ago

mruby版ECNLプロトタイピング・ツールを追加

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-csrc
File size: 21.5 KB
Line 
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 * 上記著作権者
8は,以下の (1)~(4) の条件か,Free Software Foundation
9 * によってå…
10¬è¡¨ã•ã‚Œã¦ã„ã‚‹ GNU General Public License の Version 2 に記
11 * 述されている条件を満たす場合に限り,本ソフトウェア(本ソフトウェア
12 * を改変したものを含む.以下同じ)を使用・複製・改変・再é…
13å¸ƒï¼ˆä»¥ä¸‹ï¼Œ
14 * 利用と呼ぶ)することを無償で許諾する.
15 * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
16 * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
17 * スコード中に含まれていること.
18 * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
19 * 用できる形で再é…
20å¸ƒã™ã‚‹å ´åˆã«ã¯ï¼Œå†é…
21å¸ƒã«ä¼´ã†ãƒ‰ã‚­ãƒ¥ãƒ¡ãƒ³ãƒˆï¼ˆåˆ©ç”¨
22 * 者
23マニュアルなど)に,上記の著作権表示,この利用条件および下記
24 * の無保証規定を掲載すること.
25 * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
26 * 用できない形で再é…
27å¸ƒã™ã‚‹å ´åˆã«ã¯ï¼Œæ¬¡ã®æ¡ä»¶ã‚’満たすこと.
28 * (a) 再é…
29å¸ƒã«ä¼´ã†ãƒ‰ã‚­ãƒ¥ãƒ¡ãƒ³ãƒˆï¼ˆåˆ©ç”¨è€…
30マニュアルなど)に,上記の著
31 * 作権表示,この利用条件および下記の無保証規定を掲載すること.
32 * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
33 * 害からも,上記著作権者
34およびTOPPERSプロジェクトをå…
35è²¬ã™ã‚‹ã“と.
36 *
37 * 本ソフトウェアは,無保証で提供されているものである.上記著作権者
38お
39 * よびTOPPERSプロジェクトは,本ソフトウェアに関して,その適用可能性も
40 * 含めて,いかなる保証も行わない.また,本ソフトウェアの利用により直
41 * 接的または間接的に生じたいかなる損害に関しても,その責任を負わない.
42 *
43 * @(#) $Id: frag6.c 270 2017-02-09 04:03:47Z coas-nagasima $
44 */
45
46/* $FreeBSD: src/sys/netinet6/frag6.c,v 1.9 2002/04/19 04:46:22 suz Exp $ */
47/* $KAME: frag6.c,v 1.33 2002/01/07 11:34:48 kjc Exp $ */
48
49/*
50 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
51 * All rights reserved.
52 *
53 * Redistribution and use in source and binary forms, with or without
54 * modification, are permitted provided that the following conditions
55 * are met:
56 * 1. Redistributions of source code must retain the above copyright
57 * notice, this list of conditions and the following disclaimer.
58 * 2. Redistributions in binary form must reproduce the above copyright
59 * notice, this list of conditions and the following disclaimer in the
60 * documentation and/or other materials provided with the distribution.
61 * 3. Neither the name of the project nor the names of its contributors
62 * may be used to endorse or promote products derived from this software
63 * without specific prior written permission.
64 *
65 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
66 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
67 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
68 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
69 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
70 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
71 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
72 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
73 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
74 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
75 * SUCH DAMAGE.
76 */
77
78#include <string.h>
79
80#ifdef TARGET_KERNEL_ASP
81
82#include <kernel.h>
83#include <sil.h>
84#include "kernel_cfg.h"
85
86#endif /* of #ifdef TARGET_KERNEL_ASP */
87
88#ifdef TARGET_KERNEL_JSP
89
90#include <s_services.h>
91#include <t_services.h>
92#include "kernel_id.h"
93
94#endif /* of #ifdef TARGET_KERNEL_JSP */
95
96#include <tinet_defs.h>
97#include <tinet_config.h>
98
99#include <net/if.h>
100#include <net/if_loop.h>
101#include <net/if_ppp.h>
102#include <net/ethernet.h>
103#include <net/if_arp.h>
104#include <net/ppp_ipcp.h>
105#include <net/net.h>
106#include <net/net_buf.h>
107#include <net/net_var.h>
108#include <net/net_count.h>
109
110#include <netinet/in.h>
111#include <netinet6/in6.h>
112#include <netinet6/in6_var.h>
113#include <netinet6/nd6.h>
114#include <netinet/ip6.h>
115#include <netinet6/ip6_var.h>
116#include <netinet/icmp6.h>
117
118#ifdef SUPPORT_INET6
119
120#ifdef IP6_CFG_FRAGMENT
121
122/*
123 * データグラム再構成キューé…
124åˆ—
125 */
126
127static T_NET_BUF *ip6_frag_queue[NUM_IP6_FRAG_QUEUE];
128static T_IN6_ADDR ip6_frag_dest [NUM_IP6_FRAG_QUEUE];
129
130/*
131 * ip6_get_frag_queue -- データグラム再構成キューを獲得する。
132 */
133
134const T_NET_BUF **
135ip6_get_frag_queue (void)
136{
137 return (const T_NET_BUF **)ip6_frag_queue;
138 }
139
140/*
141 * frag6_free_queue -- データグラム再構成キューを解放する。
142 *
143 * 注意: データグラム再構成キューé…
144åˆ—をロックしてから呼び出すこと。
145 */
146
147static void
148frag6_free_queue (T_NET_BUF **queue)
149{
150 T_NET_BUF *frag, *next;
151 T_QIP6_HDR *qip6h;
152
153 frag = *queue;
154 while (frag != NULL) {
155 qip6h = GET_QIP6_HDR(frag);
156 next = qip6h->next_frag;
157 syscall(rel_net_buf(frag));
158 frag = next;
159 }
160 *queue = NULL;
161 }
162
163/*
164 * frag6_timer -- データグラム再構成管理タイマ
165 */
166
167void
168frag6_timer (void)
169{
170 T_NET_BUF *frag;
171 T_QIP6_HDR *qip6h;
172 T_IP6_FRAG_HDR *qip6fh;
173 int_t ix;
174
175 syscall(wai_sem(SEM_IP6_FRAG_QUEUE));
176 for (ix = NUM_IP6_FRAG_QUEUE; ix -- > 0; ) {
177 frag = ip6_frag_queue[ix];
178 if (frag != NULL) {
179 qip6h = GET_QIP6_HDR(frag);
180 if (qip6h->ftim > 0 && -- qip6h->ftim == 0) {
181
182 qip6fh = (T_IP6_FRAG_HDR *)(frag->buf + qip6h->foff);
183 if (ntohs(qip6fh->off_flag & IP6F_OFF_MASK) == 0) {
184
185 /*
186 * å…
187ˆé ­ã®æ–­ç‰‡ã®ã‚ªãƒ•ã‚»ãƒƒãƒˆãŒ 0 の時のみ
188 * ICMPv6 エラーメッセージを送信する。
189 */
190
191 /* å…
192ˆé ­ã®æ–­ç‰‡ã‚’データグラム再構成キューから外す。*/
193 ip6_frag_queue[ix] = qip6h->next_frag;
194
195 /* あてå…
196ˆã‚¢ãƒ‰ãƒ¬ã‚¹ã‚’å…
197ƒã«æˆ»ã™ã€‚*/
198 GET_IP6_HDR(frag)->dst = ip6_frag_dest[ix];
199
200 /* ICMPv6 エラーメッセージを送信する。*/
201 icmp6_error(frag, ICMP6_TIME_EXCEEDED,
202 ICMP6_TIME_EXCEED_REASSEMBLY, 0);
203 }
204
205 /* データグラム再構成キューを解放する。*/
206 NET_COUNT_IP6(net_count_ip6[NC_IP6_FRAG_IN_TMOUT], 1);
207 NET_COUNT_IP6(net_count_ip6[NC_IP6_FRAG_IN_DROP], 1);
208 frag6_free_queue(&ip6_frag_queue[ix]);
209 }
210 }
211 }
212 syscall(sig_sem(SEM_IP6_FRAG_QUEUE));
213 }
214
215#endif /* #ifdef IP6_CFG_FRAGMENT */
216
217/*
218 * frag6_input -- 断片ヘッダのå…
219¥åŠ›é–¢æ•°
220 */
221
222uint_t
223frag6_input (T_NET_BUF **inputp, uint_t *offp, uint_t *nextp)
224{
225 T_IP6_HDR *ip6h;
226 T_IP6_FRAG_HDR *ip6fh;
227 T_NET_BUF *input = *inputp;
228 uint_t off = *offp;
229
230#ifdef IP6_CFG_FRAGMENT
231
232 T_QIP6_HDR *qip6h, *rip6h;
233 T_IP6_FRAG_HDR *qip6fh = NULL;
234 T_NET_BUF **ip6fq = NULL, *prev, *next, *frag;
235 int_t ix;
236 int32_t unfraglen, diff;
237 uint16_t fragpartlen, qfragpartlen, fragoff, qfragoff, plen;
238 uint8_t ftim, *prev_next;
239 uint_t nextproto = IPPROTO_DONE;
240
241#endif /* #ifdef IP6_CFG_FRAGMENT */
242
243 /* ネットワークバッファの残りの長さをチェックする。*/
244 if (input->len - off < sizeof(T_IP6_FRAG_HDR))
245 goto buf_rel;
246
247 /*
248 * 巨大ペイロードオプションと断片ヘッダを同時に使用することは
249 * できない。ペイロード長がが 0 なら、巨大ペイロードオプションが
250 * 指定されていることになるので ICMP でエラーを送信者
251に
252 * 通知する。
253 */
254 ip6h = GET_IP6_HDR(input);
255 if (ip6h->plen == 0) {
256 icmp6_error(input, ICMP6_PARAM_PROB,
257 ICMP6_PARAMPROB_HEADER,
258 off - IF_HDR_SIZE);
259 NET_COUNT_MIB(in6_stats.ipv6IfStatsReasmFails, 1);
260 return IPPROTO_DONE;
261 }
262
263 /*
264 * オフセットが 0 で、最終フラグメントであれば、
265 * 分割不要のデータグラムなので、
266 * 次ヘッダを指す変数を調整して終了する。
267 */
268 ip6fh = (T_IP6_FRAG_HDR *)(input->buf + off);
269 if (ip6fh->off_flag == 0) {
270 *nextp = *offp - IF_HDR_SIZE + offsetof(T_IP6_FRAG_HDR, next);
271 *offp = off + sizeof(T_IP6_FRAG_HDR);
272 return ip6fh->next;
273 }
274
275#ifdef IP6_CFG_FRAGMENT
276
277 /*
278 * ペイロード長をチェックする。
279 */
280 if ((ip6fh->off_flag & IP6F_MORE_FRAG) &&
281 ((ntohs(ip6h->plen) - (off - IF_HDR_SIZE)) & 0x7) != 0) {
282 icmp6_error(input, ICMP6_PARAM_PROB,
283 ICMP6_PARAMPROB_HEADER,
284 offsetof(T_IP6_HDR, plen));
285 NET_COUNT_MIB(in6_stats.ipv6IfStatsReasmFails, 1);
286 return nextproto;
287 }
288 NET_COUNT_MIB(in6_stats.ipv6IfStatsReasmReqds, 1);
289
290 syscall(wai_sem(SEM_IP6_FRAG_QUEUE));
291
292 /*
293 * データグラム再構成キューé…
294åˆ—から、対応するエントリを探す。
295 */
296 for (ix = NUM_IP6_FRAG_QUEUE; ix -- > 0; ) {
297 if (ip6_frag_queue[ix] != NULL) {
298 qip6h = GET_QIP6_HDR(ip6_frag_queue[ix]);
299 qip6fh = (T_IP6_FRAG_HDR *)(ip6_frag_queue[ix]->buf + qip6h->foff);
300 if (ip6fh->ident == qip6fh->ident &&
301 IN6_ARE_ADDR_EQUAL(&ip6h->src, &qip6h->src) &&
302 IN6_ARE_ADDR_EQUAL(&ip6h->dst, &ip6_frag_dest[ix])) {
303 ip6fq = &ip6_frag_queue[ix];
304 break;
305 }
306 }
307 }
308
309 if (ip6fq == NULL) {
310
311 /*
312 * 断片の正当性をチェックする。
313 */
314 unfraglen = 0;
315 fragoff = ntohs(ip6fh->off_flag & IP6F_OFF_MASK);
316 if (fragoff == 0) {
317
318 /*
319 * å…
320¥åŠ›ã—た断片がå…
321ˆé ­ã®æ–­ç‰‡
322 * 分割できない部分の長さ unfraglen を計算する。
323 */
324 unfraglen = (off - IF_HDR_SIZE) - sizeof(T_IP6_HDR);
325 }
326
327 /*
328 * off
329 * |<--------------------------->|
330 * | off - IF_HDR_SIZE |
331 * | |<------------------>|
332 * | | off - IF_HDR_SIZE + IP6_FRAG_HDR_SIZE |
333 * | |<------------------------------------->|
334 * +--------+----------+---------+------------------+-------------+
335 * | IF HDR | IPv6 HDR | EXT HDR | FRAG HDR | Payload |
336 * +--------+----------+---------+------------------+-------------+
337 * |<---------------------------------------->|
338 * | Payload Size |
339 * |<--------------------------------------------------->|
340 * | IP6_HDR_SIZE + Payload Size |
341 * |<----------->|
342 * | fragpartlen |
343 */
344 fragpartlen = sizeof(T_IP6_HDR) + ntohs(ip6h->plen) - (off - IF_HDR_SIZE + sizeof(T_IP6_FRAG_HDR));
345 if (unfraglen + fragoff + fragpartlen > IPV6_MAXPACKET) {
346 icmp6_error(input, ICMP6_PARAM_PROB,
347 ICMP6_PARAMPROB_HEADER,
348 (off - IF_HDR_SIZE) +
349 offsetof(T_IP6_FRAG_HDR, off_flag));
350 goto sig_ret;
351 }
352
353 /*
354 * ip6fq == NULL であれば、対応するエントリは無いので、
355 * データグラム再構成キューé…
356åˆ—に、エントリを追加する。
357 */
358 for (ix = NUM_IP6_FRAG_QUEUE; ix -- > 0; ) {
359
360 /* 空きエントリを探す。*/
361 if (ip6_frag_queue[ix] == NULL) {
362 ip6fq = &ip6_frag_queue[ix];
363 break;
364 }
365 }
366
367 /*
368 * ip6fq == NULL であれば、空きエントリが無いので、
369 * タイムアウト(hlim)が短いエントリを開放する。
370 */
371 if (ip6fq == NULL) {
372
373 ftim = IPV6_MAXHLIM;
374 for (ix = NUM_IP6_FRAG_QUEUE; ix -- > 0; ) {
375 if (ip6_frag_queue[ix] != NULL) {
376 rip6h = GET_QIP6_HDR(ip6_frag_queue[ix]);
377 if (rip6h->ftim < ftim) {
378 ftim = rip6h->ftim;
379 ip6fq = &ip6_frag_queue[ix];
380 }
381 }
382 }
383 frag6_free_queue(ip6fq);
384 }
385
386 /*
387 * エントリを設定する。
388 */
389 *ip6fq = input;
390 ip6_frag_dest[ip6fq - ip6_frag_queue] = ip6h->dst;
391 qip6h = GET_QIP6_HDR(*ip6fq);
392 qip6h->ftim = IPV6_FRAGTTL;
393 qip6h->foff = off;
394 qip6h->flen = fragpartlen;
395 qip6h->next_frag = NULL;
396 }
397 else {
398
399 /*
400 * 断片の正当性をチェックする。
401 */
402 unfraglen = 0;
403 fragoff = ntohs(((T_IP6_FRAG_HDR *)((*ip6fq)->buf + GET_QIP6_HDR(*ip6fq)->foff))->off_flag & IP6F_OFF_MASK);
404 if (fragoff == 0) {
405
406 /*
407 * データグラム再構成キューの最初の断片がå…
408ˆé ­ã®æ–­ç‰‡
409 * 分割できない部分の長さ unfraglen を計算する。
410 */
411 unfraglen = (GET_QIP6_HDR(*ip6fq)->foff - IF_HDR_SIZE) - sizeof(T_IP6_HDR);
412 }
413
414 fragoff = ntohs(ip6fh->off_flag & IP6F_OFF_MASK);
415 if (fragoff == 0) {
416
417 /*
418 * å…
419¥åŠ›ã—た断片がå…
420ˆé ­ã®æ–­ç‰‡
421 * 分割できない部分の長さ unfraglen を計算する。
422 */
423 unfraglen = (off - IF_HDR_SIZE) - sizeof(T_IP6_HDR);
424 }
425
426 /*
427 * off
428 * |<--------------------------->|
429 * | off - IF_HDR_SIZE |
430 * | |<------------------>|
431 * | | off - IF_HDR_SIZE + IP6_FRAG_HDR_SIZE |
432 * | |<------------------------------------->|
433 * +--------+----------+---------+------------------+-------------+
434 * | IF HDR | IPv6 HDR | EXT HDR | FRAG HDR | Payload |
435 * +--------+----------+---------+------------------+-------------+
436 * |<---------------------------------------->|
437 * | Payload Size |
438 * |<--------------------------------------------------->|
439 * | IP6_HDR_SIZE + Payload Size |
440 * |<----------->|
441 * | fragpartlen |
442 */
443 fragpartlen = sizeof(T_IP6_HDR) + ntohs(ip6h->plen) - (off - IF_HDR_SIZE + sizeof(T_IP6_FRAG_HDR));
444 if (unfraglen + fragoff + fragpartlen > IPV6_MAXPACKET) {
445 icmp6_error(input, ICMP6_PARAM_PROB,
446 ICMP6_PARAMPROB_HEADER,
447 (off - IF_HDR_SIZE) +
448 offsetof(T_IP6_FRAG_HDR, off_flag));
449 goto sig_ret;
450 }
451
452 if (ntohs(ip6fh->off_flag & IP6F_OFF_MASK) == 0) {
453
454 /*
455 * å…
456¥åŠ›ã—た断片がå…
457ˆé ­ã®æ–­ç‰‡
458 * データグラム再構成キューの最後の断片が、
459 * データグラムの最大長を超
460えていないかチェックする。
461 */
462
463 /* 最後の断片を探索する。*/
464 next = *ip6fq;
465 while ((qip6h = GET_QIP6_HDR(next))->next_frag != NULL)
466 next = qip6h->next_frag;
467
468 /* 最後の断片のオフセットと断片サイズを計算する。*/
469 qip6fh = (T_IP6_FRAG_HDR *)(next->buf + qip6h->foff);
470 fragoff = ntohs(qip6fh->off_flag & IP6F_OFF_MASK);
471 fragpartlen = sizeof(T_IP6_HDR) + ntohs(qip6h->plen) - (qip6h->foff - IF_HDR_SIZE + sizeof(T_IP6_FRAG_HDR));
472 if (unfraglen + fragoff + fragpartlen > IPV6_MAXPACKET) {
473
474 /*
475 * データグラムの最大長を超
476えている場合は、
477 * データグラム再構成キューå…
478¨ä½“を破棄する。
479 */
480 frag6_free_queue(ip6fq);
481 syscall(rel_net_buf(input));
482 goto sig_ret;
483 }
484 }
485
486 /* ECN の正当性チェックは未実装
487 */
488
489 /*
490 * 断片をエントリに挿å…
491¥ã™ã‚‹ã€‚
492 * データグラム再構成キューから、å…
493¥åŠ›ã—た断片より前の断片を探索する。
494 */
495 prev = NULL;
496 next = *ip6fq;
497 while (next != NULL) {
498 qip6h = GET_QIP6_HDR(next);
499 qip6fh = (T_IP6_FRAG_HDR *)(next->buf + qip6h->foff);
500 if (ntohs(ip6fh->off_flag & IP6F_OFF_MASK) <= ntohs(qip6fh->off_flag & IP6F_OFF_MASK))
501 break;
502 prev = next;
503 next = qip6h->next_frag;
504 }
505
506 /*
507 * prev は、å…
508¥åŠ›ã—た断片より前の断片。ただし NULL の場合は、
509 * å…
510¥åŠ›ã—た断片がデータグラム再構成キューの中で最も前の断片。
511 * next は、å…
512¥åŠ›ã—た断片より後の断片。ただし NULL の場合は、
513 * å…
514¥åŠ›ã—た断片がデータグラム再構成キューの中で最も後の断片。
515 */
516 fragoff = ntohs(ip6fh->off_flag & IP6F_OFF_MASK);
517 if (prev != NULL) {
518
519 /*
520 * 前の断片と、å…
521¥åŠ›ã—た断片が重なっていないかチェックする。
522 *
523 * qfragoff
524 * | qfragparglen
525 * |<------------------>|
526 * +--------------------+
527 * | prev |
528 * +--------------------+
529 *
530 * +--------------------+
531 * | input |
532 * +--------------------+
533 * |
534 * fragoff
535 */
536 qip6h = GET_QIP6_HDR(prev);
537 qip6fh = (T_IP6_FRAG_HDR *)(prev->buf + qip6h->foff);
538 qfragoff = ntohs(qip6fh->off_flag & IP6F_OFF_MASK);
539 qfragpartlen = sizeof(T_IP6_HDR) + ntohs(qip6h->plen) - (off - IF_HDR_SIZE + sizeof(T_IP6_FRAG_HDR));
540
541 diff = ((int32_t)qfragoff + qfragpartlen) - fragoff;
542 if (diff > 0) {
543
544 /* 重なっていれば、å…
545¥åŠ›ã—た断片を破棄して終了する。*/
546 syscall(rel_net_buf(input));
547 goto sig_ret;
548 }
549 }
550
551 if (next != NULL) {
552
553 /*
554 * 後の断片と、å…
555¥åŠ›ã—た断片が重なっていないかチェックする。
556 *
557 * fragoff
558 * | fragparglen
559 * |<------------------>|
560 * +--------------------+
561 * | input |
562 * +--------------------+
563 *
564 * +--------------------+
565 * | next |
566 * +--------------------+
567 * |
568 * qfragoff
569 */
570 qip6h = GET_QIP6_HDR(next);
571 qip6fh = (T_IP6_FRAG_HDR *)(next->buf + qip6h->foff);
572 qfragoff = ntohs(qip6fh->off_flag & IP6F_OFF_MASK);
573 fragpartlen = sizeof(T_IP6_HDR) + ntohs(ip6h->plen) - (off - IF_HDR_SIZE + sizeof(T_IP6_FRAG_HDR));
574
575 diff = ((int32_t)fragoff + fragpartlen) - qfragoff;
576 if (diff > 0) {
577
578 /* 重なっていれば、å…
579¥åŠ›ã—た断片を破棄して終了する。*/
580 syscall(rel_net_buf(input));
581 goto sig_ret;
582 }
583 }
584
585 /* å…
586¥åŠ›ã—た断片を設定する。*/
587 qip6h = GET_QIP6_HDR(input);
588 qip6h->foff = off;
589 qip6h->flen = sizeof(T_IP6_HDR) + ntohs(qip6h->plen) - (off - IF_HDR_SIZE + sizeof(T_IP6_FRAG_HDR));
590
591 if (prev == NULL) {
592 *ip6fq = input;
593 qip6h->ftim = IPV6_FRAGTTL;
594 }
595 else
596 GET_QIP6_HDR(prev)->next_frag = input;
597 qip6h->next_frag = next;
598
599 /*
600 * å…
601¨ã¦ã®æ–­ç‰‡ã‚’受信したかチェックする。
602 */
603 plen = 0;
604 frag = *ip6fq;
605 while (frag != NULL) {
606 qip6h = GET_QIP6_HDR(frag);
607 qip6fh = (T_IP6_FRAG_HDR *)(frag->buf + qip6h->foff);
608 if (ntohs(qip6fh->off_flag & IP6F_OFF_MASK) != plen) {
609
610 /* 断片が連続していない。*/
611 goto sig_ret;
612 }
613 plen += qip6h->flen;
614 frag = qip6h->next_frag;
615 }
616 if (ntohs(qip6fh->off_flag & IP6F_MORE_FRAG) != 0) {
617
618 /* 最後の断片を受信していない。*/
619 goto sig_ret;
620 }
621
622 /*
623 * å…
624¨ã¦ã®æ–­ç‰‡ã‚’受信したので、再構成する。
625 */
626
627 /* ネットワークバッファを獲得する。*/
628 qip6h = GET_QIP6_HDR(*ip6fq);
629 qip6fh = (T_IP6_FRAG_HDR *)((*ip6fq)->buf + qip6h->foff);
630 if (tget_net_buf(inputp, qip6h->foff + plen, TMO_IP6_FRAG_GET_NET_BUF) == E_OK) {
631
632 /*
633 * 断片ヘッダの直前のヘッダの NEXT フィールドのアドレスを獲得し、
634 * å…
635ƒã«æˆ»ã™ã€‚
636 */
637 if ((prev_next = ip6_get_prev_hdr(*ip6fq, qip6h->foff)) == NULL) {
638 syscall(rel_net_buf(input));
639 goto sig_ret;
640 }
641 *prev_next = qip6fh->next;
642 input = *inputp;
643
644 NET_COUNT_IP6(net_count_ip6[NC_IP6_FRAG_IN_OK], 1);
645 NET_COUNT_MIB(in6_stats.ipv6IfStatsReasmOKs, 1);
646
647 /*
648 * IPv6 ヘッダと分割できない部分を
649 * データグラム再構成キューの中のå…
650ˆé ­ã®æ–­ç‰‡ã‹ã‚‰ã‚³ãƒ”ーする。
651 */
652 memcpy(input->buf, (*ip6fq)->buf, qip6h->foff);
653
654 /* 送信å…
655ˆã‚¢ãƒ‰ãƒ¬ã‚¹ã‚’å…
656ƒã«æˆ»ã™ã€‚*/
657 ip6h = GET_IP6_HDR(input);
658 ip6h->dst = ip6_frag_dest[ip6fq - ip6_frag_queue];
659
660 /* offp を、再構成した断片のå…
661ˆé ­ã«è¨­å®šã™ã‚‹ã€‚*/
662 *offp = qip6h->foff;
663
664 /* ネットワークバッファ長を設定する。*/
665 input->len = plen + qip6h->foff;
666
667 /*
668 * å…
669¨ã¦ã®æ–­ç‰‡ã‚’コピーする。
670 */
671 frag = *ip6fq;
672 off = qip6h->foff;
673 while (frag != NULL) {
674 qip6h = GET_QIP6_HDR(frag);
675 memcpy(input->buf + off,
676 frag->buf + qip6h->foff + sizeof(T_IP6_FRAG_HDR),
677 qip6h->flen);
678 off += qip6h->flen;
679 frag = qip6h->next_frag;
680 }
681
682 /* ペイロード長を設定する。*/
683 ip6h->plen = htons(plen);
684
685 *nextp = offsetof(T_IP6_HDR, next);
686 nextproto = ip6h->next;
687 }
688 else {
689 NET_COUNT_IP6(net_count_ip6[NC_IP6_FRAG_IN_NO_BUF], 1);
690 NET_COUNT_IP6(net_count_ip6[NC_IP6_FRAG_IN_DROP], 1);
691 NET_COUNT_MIB(in6_stats.ipv6IfStatsReasmFails, 1);
692 }
693
694 /* データグラム再構成キューを解放する。*/
695 frag6_free_queue(ip6fq);
696 }
697
698sig_ret:
699 syscall(sig_sem(SEM_IP6_FRAG_QUEUE));
700 return nextproto;
701
702#else /* #ifdef IP6_CFG_FRAGMENT */
703
704 /*
705 * データグラムの分割・再構成行わない場合は、å…
706¨æ–­ç‰‡ã‚’破棄し、
707 * 最後の断片を受信したとき、
708 * ICMP エラーを送信者
709に通知する。
710 */
711 if ((ip6fh->off_flag & IP6F_MORE_FRAG) == 0) {
712 icmp6_error(input, ICMP6_TIME_EXCEEDED,
713 ICMP6_TIME_EXCEED_REASSEMBLY, 0);
714 NET_COUNT_MIB(in6_stats.ipv6IfStatsReasmFails, 1);
715 return IPPROTO_DONE;
716 }
717
718#endif /* #ifdef IP6_CFG_FRAGMENT */
719
720buf_rel:
721 syscall(rel_net_buf(input));
722 return IPPROTO_DONE;
723 }
724
725#endif /* of #ifdef SUPPORT_INET6 */
Note: See TracBrowser for help on using the repository browser.