source: rubycfg_asp/trunk/asp_dcre/tinet/netinet/ip_input.c@ 313

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

ソースを追加

  • 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.8 KB
Line 
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 * 上記著作権者
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 313 2017-07-23 04:50:32Z 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#include "tinet_cfg.h"
92
93#endif /* of #ifdef TARGET_KERNEL_ASP */
94
95#ifdef TARGET_KERNEL_JSP
96
97#include <s_services.h>
98#include <t_services.h>
99#include "kernel_id.h"
100#include "tinet_id.h"
101
102#endif /* of #ifdef TARGET_KERNEL_JSP */
103
104#include <tinet_defs.h>
105#include <tinet_config.h>
106
107#include <net/if.h>
108#include <net/if_ppp.h>
109#include <net/if_loop.h>
110#include <net/ethernet.h>
111#include <net/ppp_ipcp.h>
112#include <net/net.h>
113#include <net/net_endian.h>
114#include <net/net_buf.h>
115#include <net/net_count.h>
116#include <net/net_timer.h>
117
118#include <netinet/in.h>
119#include <netinet/in_var.h>
120#include <netinet/ip.h>
121#include <netinet/ip_var.h>
122#include <netinet/ip_icmp.h>
123#include <netinet/tcp.h>
124#include <netinet/tcp_var.h>
125#include <netinet/udp.h>
126#include <netinet/udp_var.h>
127
128#if defined(SUPPORT_IPSEC)
129//#include <stdio.h>
130#include <sys/types.h>
131#include <netinet6/ipsec.h>
132#include <netinet6/esp.h>
133#include <netkey/key.h>
134#include <netkey/key_debug.h>
135#endif /* of defined(SUPPORT_IPSEC) */
136
137#include <net/if_var.h>
138
139#if defined(_IP4_CFG)
140
141/*
142 * 変数
143 */
144
145#ifdef SUPPORT_MIB
146
147/*
148 * SNMP の 管理情
149報ベース (MIB)
150 */
151
152T_IP_STATS ip_stats;
153
154#endif /* of #ifdef SUPPORT_MIB */
155
156#ifdef IP4_CFG_FRAGMENT
157
158/*
159 * データグラム再構成キュー
160 */
161
162static T_NET_BUF *ip_frag_queue[NUM_IP4_FRAG_QUEUE];
163static T_IN4_ADDR frag_dst [NUM_IP4_FRAG_QUEUE];
164
165/*
166 * 関数
167 */
168
169static void ip_freef (int_t ix);
170static T_NET_BUF *ip_reass (T_IP4_HDR *ip4h, T_NET_BUF *input);
171
172/*
173 * ip_get_frag_queue -- データグラム再構成キューを獲得する。
174 */
175
176const T_NET_BUF **
177ip_get_frag_queue (void)
178{
179 return (const T_NET_BUF **)ip_frag_queue;
180 }
181
182/*
183 * ip_freef -- データグラム再構成キューを解放する。
184 */
185
186static void
187ip_freef (int_t ix)
188{
189 T_NET_BUF *frag, *next;
190
191 frag = ip_frag_queue[ix];
192 while (frag != NULL) {
193 next = GET_QIP4_HDR(frag)->next;
194 syscall(rel_net_buf(frag));
195 frag = next;
196 }
197 ip_frag_queue[ix] = NULL;
198 }
199
200/*
201 * ip_frag_timer -- データグラム再構成管理タイマ
202 */
203
204void
205ip_frag_timer (void)
206{
207 T_NET_BUF *frag;
208 int_t ix;
209
210 syscall(wai_sem(SEM_IP4_FRAG_QUEUE));
211 for (ix = NUM_IP4_FRAG_QUEUE; ix -- > 0; ) {
212 frag = ip_frag_queue[ix];
213 if (frag != NULL && GET_QIP4_HDR(frag)->ttl > 0 &&
214 -- GET_QIP4_HDR(frag)->ttl == 0) {
215 NET_COUNT_IP4(net_count_ip4[NC_IP4_FRAG_IN_TMOUT], 1);
216 NET_COUNT_IP4(net_count_ip4[NC_IP4_FRAG_IN_DROP], 1);
217 ip_freef(ix);
218 }
219 }
220 syscall(sig_sem(SEM_IP4_FRAG_QUEUE));
221 }
222
223/*
224 * ip_reass -- データグラムを再構成する。
225 */
226
227static T_NET_BUF *
228ip_reass (T_IP4_HDR *ip4h, T_NET_BUF *input)
229{
230 T_NET_BUF *frag, *prev;
231 T_IN4_ADDR dst, src;
232 int_t ix;
233 uint_t id, off, len;
234
235 NET_COUNT_IP4(net_count_ip4[NC_IP4_FRAG_IN_FRAGS], 1);
236 NET_COUNT_MIB(ip_stats.ipReasmReqds, 1);
237
238 src = ntohl(ip4h->src);
239 dst = ntohl(ip4h->dst);
240 NTOHS(ip4h->id);
241 NTOHS(ip4h->flg_off);
242 id = ip4h->id;
243 ix = id % NUM_IP4_FRAG_QUEUE;
244
245 syscall(wai_sem(SEM_IP4_FRAG_QUEUE));
246
247 /*
248 * ID、IPアドレス、上位プロトコルが異なるフラグメントがキューに有れば破棄する。
249 */
250 frag = ip_frag_queue[ix];
251 if (frag != NULL &&
252 (id != GET_IP4_HDR(frag)->id ||
253 dst != frag_dst[ix] ||
254 src != ntohl(GET_IP4_HDR(frag)->src) ||
255 ip4h->proto != GET_IP4_HDR(frag)->proto)) {
256 NET_COUNT_IP4(net_count_ip4[NC_IP4_FRAG_IN_DROP], 1);
257 NET_COUNT_MIB(ip_stats.ipReasmFails, 1);
258 ip_freef(ix);
259 }
260
261 frag = ip_frag_queue[ix];
262 if (frag == NULL) {
263 NET_COUNT_IP4(net_count_ip4[NC_IP4_FRAG_IN], 1);
264
265 /* 新規の ID なら、宛å…
266ˆã‚¢ãƒ‰ãƒ¬ã‚¹ã‚’保存して、キューにつなぐ。*/
267 frag_dst [ix] = dst;
268 ip_frag_queue[ix] = input;
269 ((T_QIP4_HDR *)ip4h)->next = NULL;
270 input = NULL;
271
272 /* 再構成タイムアウトを設定する。*/
273 ip4h->ttl = IP4_FRAGTTL;
274 }
275 else {
276
277 /* 正しい位置に挿å…
278¥ã™ã‚‹ã€‚*/
279 prev = NULL;
280 while (frag != NULL &&
281 IP4_FLGOFF_OFF(ip4h->flg_off) >
282 IP4_FLGOFF_OFF(GET_QIP4_HDR(frag)->flg_off)) {
283 prev = frag;
284 frag = GET_QIP4_HDR(frag)->next;
285 }
286 ((T_QIP4_HDR *)ip4h)->next = frag;
287 if (prev == NULL) {
288 ip4h->ttl = GET_QIP4_HDR(frag)->ttl;
289 ip_frag_queue[ix] = input;
290 }
291 else
292 GET_QIP4_HDR(prev)->next = input;
293 input = NULL;
294
295 /* å…
296¨ã¦ã®ãƒ•ãƒ©ã‚°ãƒ¡ãƒ³ãƒˆãŒæƒã£ã¦ã„るか調べる。*/
297 off = 0;
298 for (frag = ip_frag_queue[ix]; frag != NULL; frag = GET_QIP4_HDR(frag)->next) {
299 if ((IP4_FLGOFF_OFF(GET_QIP4_HDR(frag)->flg_off) << 3) != off) {
300 /* 途中が抜けていたら終了する。*/
301 syscall(sig_sem(SEM_IP4_FRAG_QUEUE));
302 return NULL;
303 }
304 off += ntohs(GET_QIP4_HDR(frag)->len) - (IP4_VHL_HL(GET_QIP4_HDR(frag)->vhl) << 2);
305 prev = frag;
306 }
307
308 /* å…
309¨ã¦ã®ãƒ•ãƒ©ã‚°ãƒ¡ãƒ³ãƒˆãŒæƒã£ãŸã‚‰å†æ§‹æˆã™ã‚‹ã€‚*/
310 if ((GET_QIP4_HDR(prev)->flg_off & IP4_MF) == 0) {
311
312 /* ネットワークバッファを獲得する。*/
313 if (tget_net_buf(&input, IF_IP4_HDR_SIZE + off, TMO_IP4_FRAG_GET_NET_BUF) == E_OK) {
314 NET_COUNT_IP4(net_count_ip4[NC_IP4_FRAG_IN_OK], 1);
315 NET_COUNT_MIB(ip_stats.ipReasmOKs, 1);
316
317 /* IPv4 ヘッダを設定する。*/
318 frag = ip_frag_queue[ix];
319 ip4h = GET_IP4_HDR(input);
320 *ip4h = *GET_IP4_HDR(frag);
321 ip4h->dst = htonl(frag_dst[ix]);
322 ip4h->len = htons(IP4_HDR_SIZE + off);
323 ip4h->vhl = IP4_MAKE_VHL(IPV4_VERSION, IP4_HDR_SIZE >> 2);
324 ip4h->ttl = GET_QIP4_HDR(prev)->ttl;
325 ip4h->flg_off = ip4h->id = 0;
326
327 /* データグラムを再構成する。*/
328 off = IP4_HDR_SIZE;
329 while (frag != NULL) {
330 len = ntohs(GET_QIP4_HDR(frag)->len) - (IP4_VHL_HL(GET_QIP4_HDR(frag)->vhl) << 2);
331 memcpy((uint8_t *)ip4h + off, GET_QIP4_SDU(frag), len);
332 off += len;
333 frag = GET_QIP4_HDR(frag)->next;
334 }
335 }
336 else {
337 NET_COUNT_IP4(net_count_ip4[NC_IP4_FRAG_IN_NO_BUF], 1);
338 NET_COUNT_IP4(net_count_ip4[NC_IP4_FRAG_IN_DROP], 1);
339 NET_COUNT_MIB(ip_stats.ipReasmFails, 1);
340 }
341 /* キューを空にする。*/
342 ip_freef(ix);
343 }
344 }
345 syscall(sig_sem(SEM_IP4_FRAG_QUEUE));
346 return input;
347 }
348
349#endif /* of #ifdef IP4_CFG_FRAGMENT */
350
351/*
352 * ip_init -- IP の初期化
353 */
354
355void
356ip_init (void)
357{
358 in4_init();
359 }
360
361/*
362 * ip_remove_options -- IPv4 ヘッダのオプションを削除し、以降を前に詰める。
363 */
364
365ER
366ip_remove_options (T_NET_BUF *nbuf)
367{
368 T_IP4_HDR *iph;
369 uint_t hdr_size;
370
371 iph = GET_IP4_HDR(nbuf);
372 hdr_size = GET_IP4_HDR_SIZE(nbuf);
373
374 if (hdr_size > IP4_HDR_SIZE) {
375 memmove((char *)iph + IP4_HDR_SIZE, GET_IP4_SDU(nbuf),
376 (size_t)(iph->len - hdr_size));
377 iph->vhl = IP4_MAKE_VHL(IPV4_VERSION, IP4_HDR_SIZE >> 2);
378 iph->len -= (uint16_t)(hdr_size - IP4_HDR_SIZE);
379 nbuf->len -= (uint16_t)(hdr_size - IP4_HDR_SIZE);
380 }
381
382 return E_OK;
383 }
384
385/*
386 * ip_input -- IP のå…
387¥åŠ›é–¢æ•°
388 */
389
390#if defined(SUPPORT_IPSEC)
391/*
392 * TODO: IPsec SPを検索し、パケットをリジェクトするかどうか判定する処理を実装
393する
394 */
395#endif /* of defined(SUPPORT_IPSEC) */
396
397void
398ip_input (T_NET_BUF *input)
399{
400 T_IP4_HDR *ip4h;
401 T_IFNET *ifp = IF_GET_IFNET();
402 T_IN4_ADDR dst, src, bc;
403 uint_t hlen, off;
404
405 NET_COUNT_IP4(net_count_ip4[NC_IP4_IN_OCTETS], input->len - IF_HDR_SIZE);
406 NET_COUNT_IP4(net_count_ip4[NC_IP4_IN_PACKETS], 1);
407 NET_COUNT_MIB(ip_stats.ipInReceives, 1);
408
409 /* IP ヘッダの長さをチェックする。*/
410 if (input->len < IF_IP4_HDR_SIZE) {
411 NET_COUNT_IP4(net_count_ip4[NC_IP4_IN_ERR_SHORT], 1);
412 NET_COUNT_MIB(ip_stats.ipInHdrErrors, 1);
413 goto buf_rel;
414 }
415
416 ip4h = GET_IP4_HDR(input);
417 hlen = GET_IP4_HDR_SIZE(input);
418
419 /* バージョンをチェックする。*/
420 if (IP4_VHL_V(ip4h->vhl) != IPV4_VERSION) {
421 NET_COUNT_IP4(net_count_ip4[NC_IP4_IN_ERR_VER], 1);
422 NET_COUNT_MIB(ip_stats.ipInHdrErrors, 1);
423 goto buf_rel;
424 }
425
426 /* IP ヘッダの長さをチェックし、オプションを解析する。*/
427 if (hlen > IP4_HDR_SIZE) {
428 NET_COUNT_IP4(net_count_ip4[NC_IP4_OPTS], 1);
429 /* %%% オプションの解析 %%% */
430 }
431
432 /* データグラム長をチェックする。*/
433 if (ntohs(ip4h->len) > input->len - IF_HDR_SIZE) {
434 NET_COUNT_IP4(net_count_ip4[NC_IP4_IN_ERR_SHORT], 1);
435 NET_COUNT_MIB(ip_stats.ipInHdrErrors, 1);
436 goto buf_rel;
437 }
438
439 /* ネットワークバッファの長さをデータグラム長に調整する。*/
440 input->len = (uint16_t)(ntohs(ip4h->len) + IF_HDR_SIZE);
441
442 /* チェックサムをチェックする。*/
443 if (in_cksum(ip4h, hlen) != 0) {
444 NET_COUNT_IP4(net_count_ip4[NC_IP4_IN_ERR_CKSUM], 1);
445 NET_COUNT_MIB(ip_stats.ipInHdrErrors, 1);
446 goto buf_rel;
447 }
448
449 /* IP ヘッダの長さをチェックし、上位が ICMP 以外はオプションを消去する。*/
450 if (hlen > IP4_HDR_SIZE && ip4h->proto != IPPROTO_ICMP) {
451 memset((uint8_t*)ip4h + IP4_HDR_SIZE, 0, hlen - IP4_HDR_SIZE);
452 }
453
454 /* 送信å…
455ƒã‚¢ãƒ‰ãƒ¬ã‚¹ã‚’チェックする。*/
456 src = ntohl(ip4h->src);
457 bc = (ifp->in4_ifaddr.addr & ifp->in4_ifaddr.mask) | ~ifp->in4_ifaddr.mask;
458
459#ifdef SUPPORT_LOOP
460
461 if (src == bc || src == IPV4_ADDR_BROADCAST || src == IPV4_ADDRANY) {
462 NET_COUNT_IP4(net_count_ip4[NC_IP4_IN_ERR_ADDR], 1);
463 NET_COUNT_MIB(ip_stats.ipInAddrErrors, 1);
464 goto buf_rel;
465 }
466
467#else /* of #ifdef SUPPORT_LOOP */
468
469 if (src == ifp->in4_ifaddr.addr || src == bc || src == IPV4_ADDR_BROADCAST || src == IPV4_ADDRANY) {
470 NET_COUNT_IP4(net_count_ip4[NC_IP4_IN_ERR_ADDR], 1);
471 NET_COUNT_MIB(ip_stats.ipInAddrErrors, 1);
472 goto buf_rel;
473 }
474
475#endif /* of #ifdef SUPPORT_LOOP */
476
477 /* あてå…
478ˆã‚¢ãƒ‰ãƒ¬ã‚¹ã‚’チェックする。*/
479 dst = ntohl(ip4h->dst);
480
481#ifdef DHCP_CFG
482
483 /*
484 * DHCP_CFG が定義されているときは、ローカルアドレスが未定義の
485 * 場合もデータグラムを受信する。
486 */
487
488 if ((ifp->in4_ifaddr.addr != IPV4_ADDRANY) &&
489 (!(dst == ifp->in4_ifaddr.addr || dst == bc ||
490 dst == IPV4_ADDR_BROADCAST || dst == IPV4_ADDRANY))) {
491 NET_COUNT_IP4(net_count_ip4[NC_IP4_IN_ERR_ADDR], 1);
492 NET_COUNT_MIB(ip_stats.ipInAddrErrors, 1);
493 goto buf_rel;
494 }
495
496#else /* of #ifdef DHCP_CFG */
497
498 if (!(dst == ifp->in4_ifaddr.addr || dst == bc ||
499 dst == IPV4_ADDR_BROADCAST || dst == IPV4_ADDRANY)) {
500 NET_COUNT_IP4(net_count_ip4[NC_IP4_IN_ERR_ADDR], 1);
501 NET_COUNT_MIB(ip_stats.ipInAddrErrors, 1);
502 goto buf_rel;
503 }
504
505#endif /* of #ifdef DHCP_CFG */
506
507#ifdef IP4_CFG_FRAGMENT
508
509 /* 分割されているかチェックする。*/
510 if (ntohs(ip4h->flg_off) & (IP4_MF | IP4_OFFMASK)) {
511 if ((input = ip_reass(ip4h, input)) == NULL)
512 return;
513 }
514
515#else /* of #ifdef IP4_CFG_FRAGMENT */
516
517 /* 分割されているかチェックする。*/
518 if (ntohs(ip4h->flg_off) & (IP4_MF | IP4_OFFMASK)) {
519 T_IN4_ADDR src;
520
521 NET_COUNT_MIB(ip_stats.ipReasmReqds, 1);
522 if ((ntohs(ip4h->flg_off) & IP4_OFFMASK) == 0) {
523 NET_COUNT_MIB(ip_stats.ipReasmFails, 1);
524 }
525 src = ntohl(ip4h->src);
526 syslog(LOG_WARNING, "[IP] flaged src: %s.", ip2str(NULL, &src));
527 goto buf_rel;
528 }
529
530#endif /* of #ifdef IP4_CFG_FRAGMENT */
531
532 off = (uint_t)(GET_IP4_SDU(input) - input->buf);
533
534#if defined(SUPPORT_IPSEC)
535 /* ここでipsec4_in_rejectを実行する */
536 if ((ip4h->proto != IPPROTO_ESP) && ipsec4_in_reject (input)) {
537 goto buf_rel;
538 }
539#endif /* of #if defined(SUPPORT_IPSEC) */
540
541 /* プロトコルを選択する */
542 switch (ip4h->proto) {
543
544#if defined(SUPPORT_TCP)
545 case IPPROTO_TCP:
546 NET_COUNT_MIB(ip_stats.ipInDelivers, 1);
547 tcp_input(&input, &off, NULL);
548 return;
549 break;
550#endif /* of #if defined(SUPPORT_TCP) */
551
552#if defined(SUPPORT_UDP) && ( (TNUM_UDP4_CEPID > 0) || \
553 ((TNUM_UDP6_CEPID > 0) && defined(API_CFG_IP4MAPPED_ADDR)))
554 case IPPROTO_UDP:
555 NET_COUNT_MIB(ip_stats.ipInDelivers, 1);
556 udp4_input(&input, &off, NULL);
557 return;
558 break;
559#endif /* of #if defined(SUPPORT_UDP) && TNUM_UDP4_CEPID > 0 */
560
561 case IPPROTO_ICMP:
562 NET_COUNT_MIB(ip_stats.ipInDelivers, 1);
563 icmp_input(&input, &off, NULL);
564 return;
565 break;
566
567#if defined(SUPPORT_IPSEC)
568 case IPPROTO_ESP:
569 NET_COUNT_MIB(ip_stats.ipInDelivers, 1);
570 esp4_input(input, &off);
571 return;
572 break;
573#endif /* of #if defined(SUPPORT_IPSEC) */
574
575 default:
576 NET_COUNT_IP4(net_count_ip4[NC_IP4_IN_ERR_PROTO], 1);
577 NET_COUNT_MIB(ip_stats.ipInUnknownProtos, 1);
578
579 /* ローカル IP アドレスに届いたデータグラムのみ ICMP エラーを通知する。*/
580 if (dst == ifp->in4_ifaddr.addr) {
581 T_IN4_ADDR src;
582
583 src = ntohl(ip4h->src);
584 syslog(LOG_INFO, "[IP] unexp proto: %d, src=%s.", ip4h->proto, ip2str(NULL, &src));
585 icmp_error(ICMP4_UNREACH_PROTOCOL, input);
586 }
587 /*
588 * icmp_error では、ネットワークバッファ input を返却しないので
589 * 開放してから終了する。
590 */
591 break;
592 }
593
594buf_rel:
595 NET_COUNT_IP4(net_count_ip4[NC_IP4_IN_ERR_PACKETS], 1);
596 syscall(rel_net_buf(input));
597 }
598
599#endif /* of #if defined(_IP4_CFG) */
Note: See TracBrowser for help on using the repository browser.