source: EcnlProtoTool/trunk/asp3_dcre/tinet/netinet/ip_input.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: 16.9 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: ip_input.c 270 2017-02-09 04:03:47Z coas-nagasima $
44 */
45
46/*
47 * Copyright (c) 1982, 1986, 1988, 1993
48 * The Regents of the University of California. All rights reserved.
49 *
50 * Redistribution and use in source and binary forms, with or without
51 * modification, are permitted provided that the following conditions
52 * are met:
53 * 1. Redistributions of source code must retain the above copyright
54 * notice, this list of conditions and the following disclaimer.
55 * 2. Redistributions in binary form must reproduce the above copyright
56 * notice, this list of conditions and the following disclaimer in the
57 * documentation and/or other materials provided with the distribution.
58 * 3. All advertising materials mentioning features or use of this software
59 * must display the following acknowledgement:
60 * This product includes software developed by the University of
61 * California, Berkeley and its contributors.
62 * 4. Neither the name of the University nor the names of its contributors
63 * may be used to endorse or promote products derived from this software
64 * without specific prior written permission.
65 *
66 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
67 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
68 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
69 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
70 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
71 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
72 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
73 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
74 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
75 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
76 * SUCH DAMAGE.
77 *
78 * @(#)input.c 8.2 (Berkeley) 1/4/94
79 * $FreeBSD: src/sys/netinet/input.c,v 1.111.2.4 1999/11/01 22:23:53 des Exp $
80 * $ANA: input.c,v 1.5 1996/09/18 14:34:59 wollman Exp $
81 */
82
83#include <string.h>
84
85#ifdef TARGET_KERNEL_ASP
86
87#include <kernel.h>
88#include <sil.h>
89#include <t_syslog.h>
90#include "kernel_cfg.h"
91
92#endif /* of #ifdef TARGET_KERNEL_ASP */
93
94#ifdef TARGET_KERNEL_JSP
95
96#include <s_services.h>
97#include <t_services.h>
98#include "kernel_id.h"
99
100#endif /* of #ifdef TARGET_KERNEL_JSP */
101
102#include <tinet_defs.h>
103#include <tinet_config.h>
104
105#include <net/if.h>
106#include <net/if_ppp.h>
107#include <net/if_loop.h>
108#include <net/ethernet.h>
109#include <net/ppp_ipcp.h>
110#include <net/net.h>
111#include <net/net_buf.h>
112#include <net/net_count.h>
113#include <net/net_timer.h>
114
115#include <netinet/in.h>
116#include <netinet/in_var.h>
117#include <netinet/ip.h>
118#include <netinet/ip_var.h>
119#include <netinet/ip_icmp.h>
120#include <netinet/tcp.h>
121#include <netinet/tcp_timer.h>
122#include <netinet/tcp_var.h>
123#include <netinet/udp.h>
124#include <netinet/udp_var.h>
125
126#if defined(SUPPORT_IPSEC)
127//#include <stdio.h>
128#include <sys/types.h>
129#include <netinet6/ipsec.h>
130#include <netinet6/esp.h>
131#include <netkey/key.h>
132#include <netkey/key_debug.h>
133#endif /* of defined(SUPPORT_IPSEC) */
134
135#include <net/if_var.h>
136
137/*
138 * 変数
139 */
140
141#ifdef SUPPORT_MIB
142
143/*
144 * SNMP の 管理情
145報ベース (MIB)
146 */
147
148T_IP_STATS ip_stats;
149
150#endif /* of #ifdef SUPPORT_MIB */
151
152#ifdef IP4_CFG_FRAGMENT
153
154/*
155 * データグラム再構成キュー
156 */
157
158static T_NET_BUF *ip_frag_queue[NUM_IP4_FRAG_QUEUE];
159static T_IN4_ADDR frag_dst [NUM_IP4_FRAG_QUEUE];
160
161/*
162 * 関数
163 */
164
165static void ip_freef (int_t ix);
166static T_NET_BUF *ip_reass (T_IP4_HDR *ip4h, T_NET_BUF *input);
167
168/*
169 * ip_get_frag_queue -- データグラム再構成キューを獲得する。
170 */
171
172const T_NET_BUF **
173ip_get_frag_queue (void)
174{
175 return (const T_NET_BUF **)ip_frag_queue;
176 }
177
178/*
179 * ip_freef -- データグラム再構成キューを解放する。
180 */
181
182static void
183ip_freef (int_t ix)
184{
185 T_NET_BUF *frag, *next;
186
187 frag = ip_frag_queue[ix];
188 while (frag != NULL) {
189 next = GET_QIP4_HDR(frag)->next;
190 syscall(rel_net_buf(frag));
191 frag = next;
192 }
193 ip_frag_queue[ix] = NULL;
194 }
195
196/*
197 * ip_frag_timer -- データグラム再構成管理タイマ
198 */
199
200void
201ip_frag_timer (void)
202{
203 T_NET_BUF *frag;
204 int_t ix;
205
206 syscall(wai_sem(SEM_IP4_FRAG_QUEUE));
207 for (ix = NUM_IP4_FRAG_QUEUE; ix -- > 0; ) {
208 frag = ip_frag_queue[ix];
209 if (frag != NULL && GET_QIP4_HDR(frag)->ttl > 0 &&
210 -- GET_QIP4_HDR(frag)->ttl == 0) {
211 NET_COUNT_IP4(net_count_ip4[NC_IP4_FRAG_IN_TMOUT], 1);
212 NET_COUNT_IP4(net_count_ip4[NC_IP4_FRAG_IN_DROP], 1);
213 ip_freef(ix);
214 }
215 }
216 syscall(sig_sem(SEM_IP4_FRAG_QUEUE));
217 }
218
219/*
220 * ip_reass -- データグラムを再構成する。
221 */
222
223static T_NET_BUF *
224ip_reass (T_IP4_HDR *ip4h, T_NET_BUF *input)
225{
226 T_NET_BUF *frag, *prev;
227 T_IN4_ADDR dst, src;
228 int_t ix;
229 uint_t id, off, len;
230
231 NET_COUNT_IP4(net_count_ip4[NC_IP4_FRAG_IN_FRAGS], 1);
232 NET_COUNT_MIB(ip_stats.ipReasmReqds, 1);
233
234 src = ntohl(ip4h->src);
235 dst = ntohl(ip4h->dst);
236 NTOHS(ip4h->id);
237 NTOHS(ip4h->flg_off);
238 id = ip4h->id;
239 ix = id % NUM_IP4_FRAG_QUEUE;
240
241 syscall(wai_sem(SEM_IP4_FRAG_QUEUE));
242
243 /*
244 * ID、IPアドレス、上位プロトコルが異なるフラグメントがキューに有れば破棄する。
245 */
246 frag = ip_frag_queue[ix];
247 if (frag != NULL &&
248 (id != GET_IP4_HDR(frag)->id ||
249 dst != frag_dst[ix] ||
250 src != ntohl(GET_IP4_HDR(frag)->src) ||
251 ip4h->proto != GET_IP4_HDR(frag)->proto)) {
252 NET_COUNT_IP4(net_count_ip4[NC_IP4_FRAG_IN_DROP], 1);
253 NET_COUNT_MIB(ip_stats.ipReasmFails, 1);
254 ip_freef(ix);
255 }
256
257 frag = ip_frag_queue[ix];
258 if (frag == NULL) {
259 NET_COUNT_IP4(net_count_ip4[NC_IP4_FRAG_IN], 1);
260
261 /* 新規の ID なら、宛å…
262ˆã‚¢ãƒ‰ãƒ¬ã‚¹ã‚’保存して、キューにつなぐ。*/
263 frag_dst [ix] = dst;
264 ip_frag_queue[ix] = input;
265 ((T_QIP4_HDR *)ip4h)->next = NULL;
266 input = NULL;
267
268 /* 再構成タイムアウトを設定する。*/
269 ip4h->ttl = IP4_FRAGTTL;
270 }
271 else {
272
273 /* 正しい位置に挿å…
274¥ã™ã‚‹ã€‚*/
275 prev = NULL;
276 while (frag != NULL &&
277 IP4_FLGOFF_OFF(ip4h->flg_off) >
278 IP4_FLGOFF_OFF(GET_QIP4_HDR(frag)->flg_off)) {
279 prev = frag;
280 frag = GET_QIP4_HDR(frag)->next;
281 }
282 ((T_QIP4_HDR *)ip4h)->next = frag;
283 if (prev == NULL) {
284 ip4h->ttl = GET_QIP4_HDR(frag)->ttl;
285 ip_frag_queue[ix] = input;
286 }
287 else
288 GET_QIP4_HDR(prev)->next = input;
289 input = NULL;
290
291 /* å…
292¨ã¦ã®ãƒ•ãƒ©ã‚°ãƒ¡ãƒ³ãƒˆãŒæƒã£ã¦ã„るか調べる。*/
293 off = 0;
294 for (frag = ip_frag_queue[ix]; frag != NULL; frag = GET_QIP4_HDR(frag)->next) {
295 if ((IP4_FLGOFF_OFF(GET_QIP4_HDR(frag)->flg_off) << 3) != off) {
296 /* 途中が抜けていたら終了する。*/
297 syscall(sig_sem(SEM_IP4_FRAG_QUEUE));
298 return NULL;
299 }
300 off += ntohs(GET_QIP4_HDR(frag)->len) - (IP4_VHL_HL(GET_QIP4_HDR(frag)->vhl) << 2);
301 prev = frag;
302 }
303
304 /* å…
305¨ã¦ã®ãƒ•ãƒ©ã‚°ãƒ¡ãƒ³ãƒˆãŒæƒã£ãŸã‚‰å†æ§‹æˆã™ã‚‹ã€‚*/
306 if ((GET_QIP4_HDR(prev)->flg_off & IP4_MF) == 0) {
307
308 /* ネットワークバッファを獲得する。*/
309 if (tget_net_buf(&input, IF_IP4_HDR_SIZE + off, TMO_IP4_FRAG_GET_NET_BUF) == E_OK) {
310 NET_COUNT_IP4(net_count_ip4[NC_IP4_FRAG_IN_OK], 1);
311 NET_COUNT_MIB(ip_stats.ipReasmOKs, 1);
312
313 /* IPv4 ヘッダを設定する。*/
314 frag = ip_frag_queue[ix];
315 ip4h = GET_IP4_HDR(input);
316 *ip4h = *GET_IP4_HDR(frag);
317 ip4h->dst = htonl(frag_dst[ix]);
318 ip4h->len = htons(IP4_HDR_SIZE + off);
319 ip4h->vhl = IP4_MAKE_VHL(IPV4_VERSION, IP4_HDR_SIZE >> 2);
320 ip4h->ttl = GET_QIP4_HDR(prev)->ttl;
321 ip4h->flg_off = ip4h->id = 0;
322
323 /* データグラムを再構成する。*/
324 off = IP4_HDR_SIZE;
325 while (frag != NULL) {
326 len = ntohs(GET_QIP4_HDR(frag)->len) - (IP4_VHL_HL(GET_QIP4_HDR(frag)->vhl) << 2);
327 memcpy((uint8_t *)ip4h + off, GET_QIP4_SDU(frag), len);
328 off += len;
329 frag = GET_QIP4_HDR(frag)->next;
330 }
331 }
332 else {
333 NET_COUNT_IP4(net_count_ip4[NC_IP4_FRAG_IN_NO_BUF], 1);
334 NET_COUNT_IP4(net_count_ip4[NC_IP4_FRAG_IN_DROP], 1);
335 NET_COUNT_MIB(ip_stats.ipReasmFails, 1);
336 }
337 /* キューを空にする。*/
338 ip_freef(ix);
339 }
340 }
341 syscall(sig_sem(SEM_IP4_FRAG_QUEUE));
342 return input;
343 }
344
345#endif /* of #ifdef IP4_CFG_FRAGMENT */
346
347/*
348 * ip_init -- IP の初期化
349 */
350
351void
352ip_init (void)
353{
354 in4_init();
355 }
356
357/*
358 * ip_remove_options -- IPv4 ヘッダのオプションを削除し、以降を前に詰める。
359 */
360
361ER
362ip_remove_options (T_NET_BUF *nbuf)
363{
364 T_IP_HDR *iph;
365
366 iph = GET_IP_HDR(nbuf);
367
368 if (GET_IP_HDR_SIZE(iph) > IP4_HDR_SIZE) {
369 memmove((char *)iph + IP4_HDR_SIZE, GET_IP_SDU(nbuf),
370 (size_t)(iph->len - GET_IP_HDR_SIZE(iph)));
371 iph->vhl = IP4_MAKE_VHL(IPV4_VERSION, IP4_HDR_SIZE >> 2);
372 iph->len -= (uint16_t)(GET_IP_HDR_SIZE(iph) - IP4_HDR_SIZE);
373 nbuf->len -= (uint16_t)(GET_IP_HDR_SIZE(iph) - IP4_HDR_SIZE);
374 }
375
376 return E_OK;
377 }
378
379/*
380 * ip_input -- IP のå…
381¥åŠ›é–¢æ•°
382 */
383
384#if defined(SUPPORT_IPSEC)
385/*
386 * TODO: IPsec SPを検索し、パケットをリジェクトするかどうか判定する処理を実装
387する
388 */
389#endif /* of defined(SUPPORT_IPSEC) */
390
391void
392ip_input (T_NET_BUF *input)
393{
394 T_IP4_HDR *ip4h;
395 T_IFNET *ifp = IF_GET_IFNET();
396 T_IN4_ADDR dst, src, bc;
397 uint_t hlen, off;
398
399 NET_COUNT_IP4(net_count_ip4[NC_IP4_IN_OCTETS], input->len - IF_HDR_SIZE);
400 NET_COUNT_IP4(net_count_ip4[NC_IP4_IN_PACKETS], 1);
401 NET_COUNT_MIB(ip_stats.ipInReceives, 1);
402
403 /* IP ヘッダの長さをチェックする。*/
404 if (input->len < IF_IP4_HDR_SIZE) {
405 NET_COUNT_IP4(net_count_ip4[NC_IP4_IN_ERR_SHORT], 1);
406 NET_COUNT_MIB(ip_stats.ipInHdrErrors, 1);
407 goto buf_rel;
408 }
409
410 ip4h = GET_IP4_HDR(input);
411 hlen = GET_IP4_HDR_SIZE(ip4h);
412
413 /* バージョンをチェックする。*/
414 if (IP4_VHL_V(ip4h->vhl) != IPV4_VERSION) {
415 NET_COUNT_IP4(net_count_ip4[NC_IP4_IN_ERR_VER], 1);
416 NET_COUNT_MIB(ip_stats.ipInHdrErrors, 1);
417 goto buf_rel;
418 }
419
420 /* IP ヘッダの長さをチェックし、オプションを解析する。*/
421 if (hlen > IP4_HDR_SIZE) {
422 NET_COUNT_IP4(net_count_ip4[NC_IP4_OPTS], 1);
423 /* %%% オプションの解析 %%% */
424 }
425
426 /* データグラム長をチェックする。*/
427 if (ntohs(ip4h->len) > input->len - IF_HDR_SIZE) {
428 NET_COUNT_IP4(net_count_ip4[NC_IP4_IN_ERR_SHORT], 1);
429 NET_COUNT_MIB(ip_stats.ipInHdrErrors, 1);
430 goto buf_rel;
431 }
432
433 /* ネットワークバッファの長さをデータグラム長に調整する。*/
434 input->len = (uint16_t)(ntohs(ip4h->len) + IF_HDR_SIZE);
435
436 /* チェックサムをチェックする。*/
437 if (in_cksum(ip4h, hlen) != 0) {
438 NET_COUNT_IP4(net_count_ip4[NC_IP4_IN_ERR_CKSUM], 1);
439 NET_COUNT_MIB(ip_stats.ipInHdrErrors, 1);
440 goto buf_rel;
441 }
442
443 /* IP ヘッダの長さをチェックし、上位が ICMP 以外はオプションを消去する。*/
444 if (hlen > IP4_HDR_SIZE && ip4h->proto != IPPROTO_ICMP) {
445 memset((uint8_t*)ip4h + IP4_HDR_SIZE, 0, hlen - IP4_HDR_SIZE);
446 }
447
448 /* 送信å…
449ƒã‚¢ãƒ‰ãƒ¬ã‚¹ã‚’チェックする。*/
450 src = ntohl(ip4h->src);
451 bc = (ifp->in_ifaddr.addr & ifp->in_ifaddr.mask) | ~ifp->in_ifaddr.mask;
452
453#ifdef SUPPORT_LOOP
454
455 if (src == bc || src == IPV4_ADDR_BROADCAST || src == IPV4_ADDRANY) {
456 NET_COUNT_IP4(net_count_ip4[NC_IP4_IN_ERR_ADDR], 1);
457 NET_COUNT_MIB(ip_stats.ipInAddrErrors, 1);
458 goto buf_rel;
459 }
460
461#else /* of #ifdef SUPPORT_LOOP */
462
463 if (src == ifp->in_ifaddr.addr || src == bc || src == IPV4_ADDR_BROADCAST || src == IPV4_ADDRANY) {
464 NET_COUNT_IP4(net_count_ip4[NC_IP4_IN_ERR_ADDR], 1);
465 NET_COUNT_MIB(ip_stats.ipInAddrErrors, 1);
466 goto buf_rel;
467 }
468
469#endif /* of #ifdef SUPPORT_LOOP */
470
471 /* あてå…
472ˆã‚¢ãƒ‰ãƒ¬ã‚¹ã‚’チェックする。*/
473 dst = ntohl(ip4h->dst);
474
475#ifdef DHCP_CFG
476
477 /*
478 * DHCP_CFG が定義されているときは、ローカルアドレスが未定義の
479 * 場合もデータグラムを受信する。
480 */
481
482 if ((ifp->in_ifaddr.addr != IPV4_ADDRANY) &&
483 (!(dst == ifp->in_ifaddr.addr || dst == bc ||
484 dst == IPV4_ADDR_BROADCAST || dst == IPV4_ADDRANY))) {
485 NET_COUNT_IP4(net_count_ip4[NC_IP4_IN_ERR_ADDR], 1);
486 NET_COUNT_MIB(ip_stats.ipInAddrErrors, 1);
487 goto buf_rel;
488 }
489
490#else /* of #ifdef DHCP_CFG */
491
492#if defined(ETHER_CFG_MULTICAST)
493 if (!(dst == ifp->in_ifaddr.addr || dst == bc ||
494 dst == IPV4_ADDR_BROADCAST || dst == IPV4_ADDRANY ||
495 IN4_IS_ADDR_MULTICAST(dst))) {
496 NET_COUNT_IP4(net_count_ip4[NC_IP4_IN_ERR_ADDR], 1);
497 NET_COUNT_MIB(ip_stats.ipInAddrErrors, 1);
498 goto buf_rel;
499 }
500#else
501 if (!(dst == ifp->in_ifaddr.addr || dst == bc ||
502 dst == IPV4_ADDR_BROADCAST || dst == IPV4_ADDRANY)) {
503 NET_COUNT_IP4(net_count_ip4[NC_IP4_IN_ERR_ADDR], 1);
504 NET_COUNT_MIB(ip_stats.ipInAddrErrors, 1);
505 goto buf_rel;
506 }
507#endif
508
509#endif /* of #ifdef DHCP_CFG */
510
511#ifdef IP4_CFG_FRAGMENT
512
513 /* 分割されているかチェックする。*/
514 if (ntohs(ip4h->flg_off) & (IP4_MF | IP4_OFFMASK)) {
515 if ((input = ip_reass(ip4h, input)) == NULL)
516 return;
517 }
518
519#else /* of #ifdef IP4_CFG_FRAGMENT */
520
521 /* 分割されているかチェックする。*/
522 if (ntohs(ip4h->flg_off) & (IP4_MF | IP4_OFFMASK)) {
523 T_IN4_ADDR src;
524
525 NET_COUNT_MIB(ip_stats.ipReasmReqds, 1);
526 if ((ntohs(ip4h->flg_off) & IP4_OFFMASK) == 0) {
527 NET_COUNT_MIB(ip_stats.ipReasmFails, 1);
528 }
529 src = ntohl(ip4h->src);
530 syslog(LOG_WARNING, "[IP] flaged src: %s.", ip2str(NULL, &src));
531 goto buf_rel;
532 }
533
534#endif /* of #ifdef IP4_CFG_FRAGMENT */
535
536 off = (uint_t)(GET_IP4_SDU(input) - input->buf);
537
538#if defined(SUPPORT_IPSEC)
539 /* ここでipsec4_in_rejectを実行する */
540 if ((ip4h->proto != IPPROTO_ESP) && ipsec4_in_reject (input)) {
541 goto buf_rel;
542 }
543#endif /* of #if defined(SUPPORT_IPSEC) */
544
545 /* プロトコルを選択する */
546 switch (ip4h->proto) {
547
548#ifdef SUPPORT_UDP
549 case IPPROTO_UDP:
550 NET_COUNT_MIB(ip_stats.ipInDelivers, 1);
551 udp_input(&input, &off, NULL);
552 return;
553 break;
554#endif /* of #ifdef SUPPORT_UDP */
555
556#ifdef SUPPORT_TCP
557 case IPPROTO_TCP:
558 NET_COUNT_MIB(ip_stats.ipInDelivers, 1);
559 tcp_input(&input, &off, NULL);
560 return;
561 break;
562#endif /* of #ifdef SUPPORT_UDP */
563
564 case IPPROTO_ICMP:
565 NET_COUNT_MIB(ip_stats.ipInDelivers, 1);
566 icmp_input(&input, &off, NULL);
567 return;
568 break;
569
570#if defined(SUPPORT_IPSEC)
571 case IPPROTO_ESP:
572 NET_COUNT_MIB(ip_stats.ipInDelivers, 1);
573 esp4_input(input, &off);
574 return;
575 break;
576#endif /* of #if defined(SUPPORT_IPSEC) */
577
578 default:
579 NET_COUNT_IP4(net_count_ip4[NC_IP4_IN_ERR_PROTO], 1);
580 NET_COUNT_MIB(ip_stats.ipInUnknownProtos, 1);
581
582 /* ローカル IP アドレスに届いたデータグラムのみ ICMP エラーを通知する。*/
583 if (dst == ifp->in_ifaddr.addr) {
584 T_IN4_ADDR src;
585
586 src = ntohl(ip4h->src);
587 syslog(LOG_INFO, "[IP] unexp proto: %d, src=%s.", ip4h->proto, ip2str(NULL, &src));
588 icmp_error(ICMP4_UNREACH_PROTOCOL, input);
589 }
590 /*
591 * icmp_error では、ネットワークバッファ input を返却しないので
592 * 開放してから終了する。
593 */
594 break;
595 }
596
597buf_rel:
598 NET_COUNT_IP4(net_count_ip4[NC_IP4_IN_ERR_PACKETS], 1);
599 syscall(rel_net_buf(input));
600 }
Note: See TracBrowser for help on using the repository browser.