Changeset 331 for EcnlProtoTool/trunk/asp3_dcre/tinet/netinet/ip_icmp.c
- Timestamp:
- Jan 21, 2018, 12:10:09 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
EcnlProtoTool/trunk/asp3_dcre/tinet/netinet/ip_icmp.c
r321 r331 2 2 * TINET (TCP/IP Protocol Stack) 3 3 * 4 * Copyright (C) 2001-20 09by Dep. of Computer Science and Engineering4 * Copyright (C) 2001-2017 by Dep. of Computer Science and Engineering 5 5 * Tomakomai National College of Technology, JAPAN 6 6 * … … 76 76 #include <t_syslog.h> 77 77 #include "kernel_cfg.h" 78 #include "tinet_cfg.h" 78 79 79 80 #endif /* of #ifdef TARGET_KERNEL_ASP */ … … 83 84 #include <s_services.h> 84 85 #include <t_services.h> 86 #include "tinet_id.h" 85 87 86 88 #endif /* of #ifdef TARGET_KERNEL_JSP */ … … 95 97 #include <net/ppp_ipcp.h> 96 98 #include <net/net.h> 99 #include <net/net_endian.h> 97 100 #include <net/net_buf.h> 98 101 #include <net/net_timer.h> … … 106 109 #include <netinet/icmp_var.h> 107 110 #include <netinet/tcp.h> 108 #include <netinet/tcp_timer.h>109 111 #include <netinet/tcp_var.h> 112 #include <netinet/udp_var.h> 113 114 #include <net/if_var.h> 115 116 #if defined(_IP4_CFG) 110 117 111 118 /* … … 130 137 static void icmp_unreach (T_NET_BUF *input, uint_t ihoff); 131 138 139 #if defined(NUM_REDIRECT_ROUTE_ENTRY) 132 140 #if NUM_REDIRECT_ROUTE_ENTRY > 0 133 141 … … 135 143 136 144 #endif /* of #if NUM_REDIRECT_ROUTE_ENTRY > 0 */ 145 #endif /* of #if defined(NUM_REDIRECT_ROUTE_ENTRY) */ 137 146 138 147 /* … … 147 156 T_IP4_HDR *ip4h; 148 157 T_ICMP4_HDR *icmp4h; 149 T_I N4_ADDR addr;158 T_IFNET *ifp = IF_GET_IFNET(); 150 159 151 160 NET_COUNT_MIB(icmp_stats.icmpInEchos, 1); 152 161 153 /* メッセージの型をエコー要求 (8) から エコー応答 (0) に */ 154 /* 変更して送り返す。 */ 155 156 icmp4h = GET_ICMP4_HDR(input, ihoff); 157 icmp4h->type = ICMP4_ECHO_REPLY; 158 159 /* IP ヘッダの宛先と発信元を交換する。*/ 160 ip4h = GET_IP4_HDR(input); 161 addr = ip4h->src; 162 ip4h->src = ip4h->dst; 163 ip4h->dst = addr; 164 165 /* チェックサムを計算する。*/ 166 icmp4h->sum = 0; 167 icmp4h->sum = in_cksum(icmp4h, 168 (uint_t)(((input->len - GET_IF_IP4_HDR_SIZE(input)) + 3) >> 2 << 2)); 169 170 /* 送信する。*/ 171 NET_COUNT_ICMP4(net_count_icmp4.out_octets, 172 input->len - GET_IF_IP4_HDR_SIZE(input)); 173 NET_COUNT_ICMP4(net_count_icmp4.out_packets, 1); 174 NET_COUNT_MIB(icmp_stats.icmpOutMsgs, 1); 175 NET_COUNT_MIB(icmp_stats.icmpOutEchoReps, 1); 176 ip_output(input, TMO_ICMP_OUTPUT); 162 /* IPv4 アドレスが未定義の時は応答しない。*/ 163 if (!IN4_IS_ADDR_ANY(&ifp->in4_ifaddr.addr)) { 164 165 /* 166 * メッセージの型をエコー要求 (8) から 167 * エコー応答 (0) に変更して送り返す。 168 */ 169 170 icmp4h = GET_ICMP4_HDR(input, ihoff); 171 icmp4h->type = ICMP4_ECHO_REPLY; 172 173 /* 174 * 宛先アドレスは受信したメッセージの送信元アドレス。 175 * 送信元アドレスは自 IPv4 アドレス。 176 */ 177 ip4h = GET_IP4_HDR(input); 178 ip4h->dst = ip4h->src; 179 ip4h->src = htonl(ifp->in4_ifaddr.addr); 180 181 /* チェックサムを計算する。*/ 182 icmp4h->sum = 0; 183 icmp4h->sum = in_cksum(icmp4h, 184 (uint_t)(((input->len - GET_IF_IP4_HDR_SIZE(input)) + 3) >> 2 << 2)); 185 186 /* 送信する。*/ 187 NET_COUNT_ICMP4(net_count_icmp4.out_octets, 188 input->len - GET_IF_IP4_HDR_SIZE(input)); 189 NET_COUNT_ICMP4(net_count_icmp4.out_packets, 1); 190 NET_COUNT_MIB(icmp_stats.icmpOutMsgs, 1); 191 NET_COUNT_MIB(icmp_stats.icmpOutEchoReps, 1); 192 ip_output(input, TMO_ICMP_OUTPUT); 193 } 177 194 } 178 195 … … 212 229 code = GET_ICMP4_HDR(input, ihoff)->code; 213 230 error = code2error[code]; 214 if (ip4h->proto == IPPROTO_TCP) { 215 216 #ifdef SUPPORT_TCP 231 232 /* 最終ヘッダが TCP/UDP のみ対応する。*/ 233 if (ip4h->proto == IPPROTO_TCP || ip4h->proto == IPPROTO_UDP) { 217 234 218 235 memcpy(GET_IP4_HDR(input), ip4h, input->len - (IP4_HDR_SIZE + ICMP4_HDR_SIZE)); 219 236 input->len -= IP4_HDR_SIZE + ICMP4_HDR_SIZE; 220 tcp_notify(input, error); 221 222 #endif /* of #ifdef SUPPORT_TCP */ 237 238 #if defined(SUPPORT_TCP) 239 240 if (ip4h->proto == IPPROTO_TCP) 241 tcp_notify(input, error); 242 243 #endif /* of #if defined(SUPPORT_TCP) */ 244 245 #if defined(SUPPORT_UDP) && TNUM_UDP4_CEPID > 0 246 247 if (ip4h->proto == IPPROTO_UDP) 248 udp4_notify(input, error); 249 250 #endif /* of #if defined(SUPPORT_UDP) && TNUM_UDP4_CEPID > 0 */ 223 251 224 252 } … … 227 255 } 228 256 257 #if defined(NUM_REDIRECT_ROUTE_ENTRY) 229 258 #if NUM_REDIRECT_ROUTE_ENTRY > 0 230 259 … … 264 293 265 294 #endif /* of #if NUM_REDIRECT_ROUTE_ENTRY > 0 */ 295 #endif /* of #if defined(NUM_REDIRECT_ROUTE_ENTRY) */ 266 296 267 297 /* … … 314 344 case ICMP4_ECHO_REPLY: 315 345 316 #if def ICMP_CFG_CALLBACK_ECHO_REPLY346 #if defined(SUPPORT_INET4) && defined(ICMP_CFG_CALLBACK_ECHO_REPLY) 317 347 318 348 icmp_echo_reply(input, *offp); 319 349 320 #endif /* of #if def ICMP_CFG_CALLBACK_ECHO_REPLY*/350 #endif /* of #if defined(SUPPORT_INET4) && defined(ICMP_CFG_CALLBACK_ECHO_REPLY) */ 321 351 322 352 break; … … 326 356 case ICMP4_REDIRECT: 327 357 358 #if defined(NUM_REDIRECT_ROUTE_ENTRY) 328 359 #if NUM_REDIRECT_ROUTE_ENTRY > 0 329 360 … … 338 369 339 370 #endif /* of #if NUM_REDIRECT_ROUTE_ENTRY > 0 */ 371 #else /* of #if defined(NUM_REDIRECT_ROUTE_ENTRY) */ 372 373 addr = ntohl(icmp4h->data.addr); 374 syslog(LOG_INFO, "[ICMP] redirect ignored, addr: %s.", ip2str(NULL, &addr)); 375 376 #endif /* of #if defined(NUM_REDIRECT_ROUTE_ENTRY) */ 340 377 341 378 break; … … 371 408 372 409 ip4h = GET_IP4_HDR(input); 373 ip4hl = GET_IP4_HDR_SIZE(i p4h);410 ip4hl = GET_IP4_HDR_SIZE(input); 374 411 375 412 /* 送信用の IP データグラムを獲得する。*/ … … 378 415 else 379 416 len = 8; 380 417 381 418 saddr = ntohl(ip4h->src); 382 419 if (in4_get_datagram(&output, (uint_t)(ICMP4_HDR_SIZE + ip4hl + len), 0, … … 417 454 418 455 #endif /* of #ifdef ICMP_REPLY_ERROR */ 456 457 #endif /* of #if defined(_IP4_CFG) */
Note:
See TracChangeset
for help on using the changeset viewer.