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_icmp.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 | * @(#)ip_icmp.c 8.2 (Berkeley) 1/4/94
|
---|
79 | * $FreeBSD: src/sys/netinet/ip_icmp.c,v 1.33.2.3 1999/10/14 11:49:38 des Exp $
|
---|
80 | */
|
---|
81 |
|
---|
82 | #include <string.h>
|
---|
83 |
|
---|
84 | #ifdef TARGET_KERNEL_ASP
|
---|
85 |
|
---|
86 | #include <kernel.h>
|
---|
87 | #include <sil.h>
|
---|
88 | #include <t_syslog.h>
|
---|
89 | #include "kernel_cfg.h"
|
---|
90 |
|
---|
91 | #endif /* of #ifdef TARGET_KERNEL_ASP */
|
---|
92 |
|
---|
93 | #ifdef TARGET_KERNEL_JSP
|
---|
94 |
|
---|
95 | #include <s_services.h>
|
---|
96 | #include <t_services.h>
|
---|
97 |
|
---|
98 | #endif /* of #ifdef TARGET_KERNEL_JSP */
|
---|
99 |
|
---|
100 | #include <tinet_defs.h>
|
---|
101 | #include <tinet_config.h>
|
---|
102 |
|
---|
103 | #include <net/if.h>
|
---|
104 | #include <net/if_loop.h>
|
---|
105 | #include <net/if_ppp.h>
|
---|
106 | #include <net/ethernet.h>
|
---|
107 | #include <net/ppp_ipcp.h>
|
---|
108 | #include <net/net.h>
|
---|
109 | #include <net/net_buf.h>
|
---|
110 | #include <net/net_timer.h>
|
---|
111 | #include <net/net_count.h>
|
---|
112 |
|
---|
113 | #include <netinet/in.h>
|
---|
114 | #include <netinet/in_var.h>
|
---|
115 | #include <netinet/ip.h>
|
---|
116 | #include <netinet/ip_var.h>
|
---|
117 | #include <netinet/ip_icmp.h>
|
---|
118 | #include <netinet/icmp_var.h>
|
---|
119 | #include <netinet/tcp.h>
|
---|
120 | #include <netinet/tcp_timer.h>
|
---|
121 | #include <netinet/tcp_var.h>
|
---|
122 |
|
---|
123 | /*
|
---|
124 | * å¤æ°
|
---|
125 | */
|
---|
126 |
|
---|
127 | #ifdef SUPPORT_MIB
|
---|
128 |
|
---|
129 | /*
|
---|
130 | * SNMP 㮠管çæ
|
---|
131 | å ±ãã¼ã¹ (MIB)
|
---|
132 | */
|
---|
133 |
|
---|
134 | T_ICMP_STATS icmp_stats;
|
---|
135 |
|
---|
136 | #endif /* of #ifdef SUPPORT_MIB */
|
---|
137 |
|
---|
138 | /*
|
---|
139 | * é¢æ°
|
---|
140 | */
|
---|
141 |
|
---|
142 | static void icmp_echo (T_NET_BUF *input, uint_t ihoff);
|
---|
143 | static void icmp_unreach (T_NET_BUF *input, uint_t ihoff);
|
---|
144 |
|
---|
145 | #if NUM_REDIRECT_ROUTE_ENTRY > 0
|
---|
146 |
|
---|
147 | static void icmp_redirect (T_NET_BUF *input, uint_t ihoff);
|
---|
148 |
|
---|
149 | #endif /* of #if NUM_REDIRECT_ROUTE_ENTRY > 0 */
|
---|
150 |
|
---|
151 | /*
|
---|
152 | * icmp_echo -- ã¨ã³ã¼è¦æ±ãåä¿¡ããã¨ãã®å¦ç
|
---|
153 | *
|
---|
154 | * input ã«ã¯ IF ããã㨠IP ããããå«ã¾ãã¦ããã
|
---|
155 | */
|
---|
156 |
|
---|
157 | static void
|
---|
158 | icmp_echo (T_NET_BUF *input, uint_t ihoff)
|
---|
159 | {
|
---|
160 | T_IP4_HDR *ip4h;
|
---|
161 | T_ICMP4_HDR *icmp4h;
|
---|
162 | T_IN4_ADDR addr;
|
---|
163 |
|
---|
164 | NET_COUNT_MIB(icmp_stats.icmpInEchos, 1);
|
---|
165 |
|
---|
166 | /* ã¡ãã»ã¼ã¸ã®åãã¨ã³ã¼è¦æ± (8) ãã ã¨ã³ã¼å¿ç (0) ã« */
|
---|
167 | /* å¤æ´ãã¦éãè¿ãã */
|
---|
168 |
|
---|
169 | icmp4h = GET_ICMP4_HDR(input, ihoff);
|
---|
170 | icmp4h->type = ICMP4_ECHO_REPLY;
|
---|
171 |
|
---|
172 | /* IP ãããã®å®å
|
---|
173 | ã¨çºä¿¡å
|
---|
174 | ã交æããã*/
|
---|
175 | ip4h = GET_IP4_HDR(input);
|
---|
176 | addr = ip4h->src;
|
---|
177 | ip4h->src = ip4h->dst;
|
---|
178 | ip4h->dst = addr;
|
---|
179 |
|
---|
180 | /* ãã§ãã¯ãµã ãè¨ç®ããã*/
|
---|
181 | icmp4h->sum = 0;
|
---|
182 | icmp4h->sum = in_cksum(icmp4h,
|
---|
183 | (uint_t)(((input->len - GET_IF_IP4_HDR_SIZE(input)) + 3) >> 2 << 2));
|
---|
184 |
|
---|
185 | /* éä¿¡ããã*/
|
---|
186 | NET_COUNT_ICMP4(net_count_icmp4.out_octets,
|
---|
187 | input->len - GET_IF_IP4_HDR_SIZE(input));
|
---|
188 | NET_COUNT_ICMP4(net_count_icmp4.out_packets, 1);
|
---|
189 | NET_COUNT_MIB(icmp_stats.icmpOutMsgs, 1);
|
---|
190 | NET_COUNT_MIB(icmp_stats.icmpOutEchoReps, 1);
|
---|
191 | ip_output(input, TMO_ICMP_OUTPUT);
|
---|
192 | }
|
---|
193 |
|
---|
194 | /*
|
---|
195 | * icmp_unreach -- ICMP4_UNREACH ãåä¿¡ããã¨ãã®å¦ç
|
---|
196 | */
|
---|
197 |
|
---|
198 | static const int8_t code2error[] = {
|
---|
199 | EV_HURCH, /* ICMP4_UNREACH_NET 0 */
|
---|
200 | EV_HURCH, /* ICMP4_UNREACH_HOST 1 */
|
---|
201 | EV_CNNRF, /* ICMP4_UNREACH_PROTOCOL 2 */
|
---|
202 | EV_CNNRF, /* ICMP4_UNREACH_PORT 3 */
|
---|
203 | EV_MSIZE, /* ICMP4_UNREACH_FLAG 4 */
|
---|
204 | EV_HURCH, /* ICMP4_UNREACH_SRC_FAIL 5 */
|
---|
205 | EV_HURCH, /* ICMP4_UNREACH_NET_UNKNOWN 6 */
|
---|
206 | EV_HURCH, /* ICMP4_UNREACH_HOST_UNKNOWN 7 */
|
---|
207 | EV_HURCH, /* ICMP4_UNREACH_ISOLATED 8 */
|
---|
208 | EV_HURCH, /* ICMP4_UNREACH_NET_PROHIB 9 */
|
---|
209 | EV_HURCH, /* ICMP4_UNREACH_HOST_PROHIB 10 */
|
---|
210 | EV_HURCH, /* ICMP4_UNREACH_TOS_NET 11 */
|
---|
211 | EV_HURCH, /* ICMP4_UNREACH_TOS_HOST 12 */
|
---|
212 | EV_HURCH, /* ICMP4_UNREACH_FILTER_PROHIB 13 */
|
---|
213 | EV_HURCH, /* ICMP4_UNREACH_HOST_PRECEDENCE 14 */
|
---|
214 | EV_HURCH, /* ICMP4_UNREACH_PRECEDENCE_CUTOFF 15 */
|
---|
215 | };
|
---|
216 |
|
---|
217 | static void
|
---|
218 | icmp_unreach (T_NET_BUF *input, uint_t ihoff)
|
---|
219 | {
|
---|
220 | T_IP4_HDR *ip4h;
|
---|
221 | uint8_t code;
|
---|
222 | ER error;
|
---|
223 |
|
---|
224 | NET_COUNT_MIB(icmp_stats.icmpInDestUnreachs, 1);
|
---|
225 |
|
---|
226 | ip4h = (T_IP4_HDR*)GET_ICMP4_SDU(input, ihoff);
|
---|
227 | code = GET_ICMP4_HDR(input, ihoff)->code;
|
---|
228 | error = code2error[code];
|
---|
229 | if (ip4h->proto == IPPROTO_TCP) {
|
---|
230 |
|
---|
231 | #ifdef SUPPORT_TCP
|
---|
232 |
|
---|
233 | memcpy(GET_IP4_HDR(input), ip4h, input->len - (IP4_HDR_SIZE + ICMP4_HDR_SIZE));
|
---|
234 | input->len -= IP4_HDR_SIZE + ICMP4_HDR_SIZE;
|
---|
235 | tcp_notify(input, error);
|
---|
236 |
|
---|
237 | #endif /* of #ifdef SUPPORT_TCP */
|
---|
238 |
|
---|
239 | }
|
---|
240 | else
|
---|
241 | syslog(LOG_NOTICE, "[ICMP] error, code: %d.", code);
|
---|
242 | }
|
---|
243 |
|
---|
244 | #if NUM_REDIRECT_ROUTE_ENTRY > 0
|
---|
245 |
|
---|
246 | /*
|
---|
247 | * icmp_redirect -- åãç´ãã¡ãã»ã¼ã¸ãåä¿¡ããã¨ãã®å¦ç
|
---|
248 | *
|
---|
249 | * input ã«ã¯ IF ããã㨠IP ããããå«ã¾ãã¦ããã
|
---|
250 | */
|
---|
251 |
|
---|
252 | static void
|
---|
253 | icmp_redirect (T_NET_BUF *input, uint_t ihoff)
|
---|
254 | {
|
---|
255 | T_IP4_HDR *ip4h, *sip4h;
|
---|
256 | T_ICMP4_HDR *icmp4h;
|
---|
257 |
|
---|
258 | ip4h = GET_IP4_HDR(input);
|
---|
259 | icmp4h = GET_ICMP4_HDR(input, ihoff);
|
---|
260 | sip4h = (T_IP4_HDR *)GET_ICMP4_SDU(input, ihoff);
|
---|
261 |
|
---|
262 | /*
|
---|
263 | * å
|
---|
264 | 容ãã§ãã¯ã以ä¸ã®å ´åã¯ã¨ã©ã¼
|
---|
265 | *
|
---|
266 | * ã»ICMP ã³ã¼ãããICMP4_REDIRECT_PORT_AND_HOST (3) 以ä¸
|
---|
267 | * ã»ãã¼ã¿ã°ã©ã é·ããICMP ã®æå°é·ããçã (IP ããã + ICMP ããã + IP ããã + 8)
|
---|
268 | * ã»ãã¼ã¿ã°ã©ã é·ããICMP ã®æ大é·ããçã
|
---|
269 | * ã»
|
---|
270 | */
|
---|
271 | if (icmp4h->code > ICMP4_REDIRECT_PORT_AND_HOST ||
|
---|
272 | ip4h->len < GET_IP4_ICMP4_HDR_SIZE(input) + 8 + IP4_HDR_SIZE ||
|
---|
273 | ip4h->len < GET_IP4_ICMP4_HDR_SIZE(input) + 8 + (IP4_VHL_HL(sip4h->vhl) << 2)) {
|
---|
274 | NET_COUNT_ICMP4(net_count_icmp4.in_err_packets, 1);
|
---|
275 | return;
|
---|
276 | }
|
---|
277 |
|
---|
278 | in4_rtredirect(icmp4h->data.addr, sip4h->dst, IN_RTF_REDIRECT, TMO_IN_REDIRECT);
|
---|
279 | }
|
---|
280 |
|
---|
281 | #endif /* of #if NUM_REDIRECT_ROUTE_ENTRY > 0 */
|
---|
282 |
|
---|
283 | /*
|
---|
284 | * icmp_input -- ICMP ã®å
|
---|
285 | ¥åé¢æ°
|
---|
286 | *
|
---|
287 | * input ã«ã¯ IF ããã㨠IP ããããå«ã¾ãã¦ããã
|
---|
288 | */
|
---|
289 |
|
---|
290 | uint_t
|
---|
291 | icmp_input (T_NET_BUF **inputp, uint_t *offp, uint_t *nextp)
|
---|
292 | {
|
---|
293 | T_NET_BUF *input = *inputp;
|
---|
294 | T_ICMP4_HDR *icmp4h;
|
---|
295 | T_IN4_ADDR addr;
|
---|
296 | uint_t len, align;
|
---|
297 |
|
---|
298 | NET_COUNT_ICMP4(net_count_icmp4.in_octets,
|
---|
299 | input->len - GET_IF_IP4_HDR_SIZE(input));
|
---|
300 | NET_COUNT_ICMP4(net_count_icmp4.in_packets, 1);
|
---|
301 |
|
---|
302 | /* ICMP ãããã®é·ãããã§ãã¯ããã*/
|
---|
303 | if (input->len < IF_IP4_ICMP4_HDR_SIZE) {
|
---|
304 | NET_COUNT_ICMP4(net_count_icmp4.in_err_packets, 1);
|
---|
305 | NET_COUNT_MIB(icmp_stats.icmpInErrors, 1);
|
---|
306 | goto buf_rel;
|
---|
307 | }
|
---|
308 |
|
---|
309 | icmp4h = (T_ICMP4_HDR *)(input->buf + *offp);
|
---|
310 |
|
---|
311 | /* 4 ãªã¯ãããå¢çã®ãã¼ã¿é· */
|
---|
312 | len = input->len - *offp;
|
---|
313 | align = (len + 3) >> 2 << 2;
|
---|
314 |
|
---|
315 | /* 4 ãªã¯ãããå¢çã¾ã§ããã£ã³ã°ã§åããã*/
|
---|
316 | if (align > len)
|
---|
317 | memset((uint8_t*)input->buf + input->len, 0, (size_t)(align - len));
|
---|
318 |
|
---|
319 | /* ãã§ãã¯ãµã ãè¨ç®ããã*/
|
---|
320 | if (in_cksum(icmp4h, align) != 0) {
|
---|
321 | NET_COUNT_ICMP4(net_count_icmp4.in_err_packets, 1);
|
---|
322 | goto buf_rel;
|
---|
323 | }
|
---|
324 |
|
---|
325 | /* ã¡ãã»ã¼ã¸ã®åã«ããåå²ããã*/
|
---|
326 | switch (icmp4h->type) {
|
---|
327 | case ICMP4_ECHO_REQUEST:
|
---|
328 | icmp_echo(input, *offp);
|
---|
329 | return IPPROTO_DONE;
|
---|
330 | break;
|
---|
331 | case ICMP4_ECHO_REPLY:
|
---|
332 |
|
---|
333 | #ifdef ICMP_CFG_CALLBACK_ECHO_REPLY
|
---|
334 |
|
---|
335 | icmp_echo_reply(input, *offp);
|
---|
336 |
|
---|
337 | #endif /* of #ifdef ICMP_CFG_CALLBACK_ECHO_REPLY */
|
---|
338 |
|
---|
339 | break;
|
---|
340 | case ICMP4_UNREACH:
|
---|
341 | icmp_unreach(input, *offp);
|
---|
342 | break;
|
---|
343 | case ICMP4_REDIRECT:
|
---|
344 |
|
---|
345 | #if NUM_REDIRECT_ROUTE_ENTRY > 0
|
---|
346 |
|
---|
347 | addr = ntohl(icmp4h->data.addr);
|
---|
348 | syslog(LOG_INFO, "[ICMP] redirect, addr: %s.", ip2str(NULL, &addr));
|
---|
349 | icmp_redirect(input, *offp);
|
---|
350 |
|
---|
351 | #else /* of #if NUM_REDIRECT_ROUTE_ENTRY > 0 */
|
---|
352 |
|
---|
353 | addr = ntohl(icmp4h->data.addr);
|
---|
354 | syslog(LOG_INFO, "[ICMP] redirect ignored, addr: %s.", ip2str(NULL, &addr));
|
---|
355 |
|
---|
356 | #endif /* of #if NUM_REDIRECT_ROUTE_ENTRY > 0 */
|
---|
357 |
|
---|
358 | break;
|
---|
359 | default:
|
---|
360 | syslog(LOG_INFO, "[ICMP] unknown type: %d.", icmp4h->type);
|
---|
361 | NET_COUNT_ICMP4(net_count_icmp4.in_err_packets, 1);
|
---|
362 | break;
|
---|
363 | }
|
---|
364 |
|
---|
365 | buf_rel:
|
---|
366 | syscall(rel_net_buf(input));
|
---|
367 | return IPPROTO_DONE;
|
---|
368 | }
|
---|
369 |
|
---|
370 | #ifdef ICMP_REPLY_ERROR
|
---|
371 |
|
---|
372 | /*
|
---|
373 | * icmp_error -- ICMP ã¨ã©ã¼éä¿¡é¢æ°ã
|
---|
374 | *
|
---|
375 | * input ã«ã¯ IF ããã㨠IP ããããå«ã¾ãã¦ããã
|
---|
376 | * icmp_error ã§ã¯ããããã¯ã¼ã¯ãããã¡ input ãè¿å´ããªãã®ã§ã
|
---|
377 | * å¼åºãå´ã§ãéæ¾ãã¦ããçµäºããã
|
---|
378 | */
|
---|
379 |
|
---|
380 | void
|
---|
381 | icmp_error (uint8_t code, T_NET_BUF *input)
|
---|
382 | {
|
---|
383 | T_IP4_HDR *ip4h;
|
---|
384 | T_ICMP4_HDR *icmp4h;
|
---|
385 | T_NET_BUF *output;
|
---|
386 | T_IN4_ADDR saddr;
|
---|
387 | uint_t len, ip4hl, align;
|
---|
388 |
|
---|
389 | ip4h = GET_IP4_HDR(input);
|
---|
390 | ip4hl = GET_IP4_HDR_SIZE(ip4h);
|
---|
391 |
|
---|
392 | /* éä¿¡ç¨ã® IP ãã¼ã¿ã°ã©ã ãç²å¾ããã*/
|
---|
393 | if (input->len - ip4hl < 8)
|
---|
394 | len = input->len - ip4hl;
|
---|
395 | else
|
---|
396 | len = 8;
|
---|
397 |
|
---|
398 | saddr = ntohl(ip4h->src);
|
---|
399 | if (in4_get_datagram(&output, (uint_t)(ICMP4_HDR_SIZE + ip4hl + len), 0,
|
---|
400 | &saddr, NULL, IPPROTO_ICMP, IP4_DEFTTL,
|
---|
401 | NBA_SEARCH_ASCENT, TMO_ICMP_OUTPUT) != E_OK)
|
---|
402 | return;
|
---|
403 |
|
---|
404 | /* ICMP ããããè¨å®ããã*/
|
---|
405 | icmp4h = GET_ICMP4_HDR(output, IF_IP4_ICMP4_HDR_OFFSET);
|
---|
406 | icmp4h->type = ICMP4_UNREACH;
|
---|
407 | icmp4h->code = code;
|
---|
408 | icmp4h->data.addr= 0;
|
---|
409 |
|
---|
410 | /* ã¨ã©ã¼ãçºçãã IP ããã㨠ãã¼ã¿ 8 ãªã¯ããããã³ãã¼ããã*/
|
---|
411 | memcpy(GET_ICMP4_SDU(output, IF_IP4_ICMP4_HDR_OFFSET),
|
---|
412 | GET_IP4_HDR(input), (size_t)(ip4hl + len));
|
---|
413 |
|
---|
414 | /* 4 ãªã¯ãããå¢çã®ãã¼ã¿é· */
|
---|
415 | align = (len + 3) >> 2 << 2;
|
---|
416 |
|
---|
417 | /* 4 ãªã¯ãããå¢çã¾ã§ããã£ã³ã°ã§åããã*/
|
---|
418 | if (align > len)
|
---|
419 | memset((uint8_t*)GET_ICMP4_SDU(output, IF_IP4_ICMP4_HDR_OFFSET) + ip4hl + len,
|
---|
420 | 0, (size_t)(align - len));
|
---|
421 |
|
---|
422 | /* ãã§ãã¯ãµã ãè¨ç®ããã*/
|
---|
423 | icmp4h->sum = 0;
|
---|
424 | icmp4h->sum = in_cksum(icmp4h, (uint_t)(ICMP4_HDR_SIZE + ip4hl + align));
|
---|
425 |
|
---|
426 | /* éä¿¡ããã*/
|
---|
427 | NET_COUNT_ICMP4(net_count_icmp4.out_octets,
|
---|
428 | output->len - GET_IF_IP4_HDR_SIZE(output));
|
---|
429 | NET_COUNT_ICMP4(net_count_icmp4.out_packets, 1);
|
---|
430 | NET_COUNT_MIB(icmp_stats.icmpOutMsgs, 1);
|
---|
431 | NET_COUNT_MIB(icmp_stats.icmpOutDestUnreachs, 1);
|
---|
432 | ip_output(output, TMO_ICMP_OUTPUT);
|
---|
433 | }
|
---|
434 |
|
---|
435 | #endif /* of #ifdef ICMP_REPLY_ERROR */
|
---|