NetTribute library with debug turned on in FShandler Donatien Garner -> Segundo Equipo -> this version

Committer:
hexley
Date:
Fri Nov 19 01:54:45 2010 +0000
Revision:
0:281d6ff68967

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hexley 0:281d6ff68967 1 /**
hexley 0:281d6ff68967 2 * @file
hexley 0:281d6ff68967 3 * ICMP - Internet Control Message Protocol
hexley 0:281d6ff68967 4 *
hexley 0:281d6ff68967 5 */
hexley 0:281d6ff68967 6
hexley 0:281d6ff68967 7 /*
hexley 0:281d6ff68967 8 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
hexley 0:281d6ff68967 9 * All rights reserved.
hexley 0:281d6ff68967 10 *
hexley 0:281d6ff68967 11 * Redistribution and use in source and binary forms, with or without modification,
hexley 0:281d6ff68967 12 * are permitted provided that the following conditions are met:
hexley 0:281d6ff68967 13 *
hexley 0:281d6ff68967 14 * 1. Redistributions of source code must retain the above copyright notice,
hexley 0:281d6ff68967 15 * this list of conditions and the following disclaimer.
hexley 0:281d6ff68967 16 * 2. Redistributions in binary form must reproduce the above copyright notice,
hexley 0:281d6ff68967 17 * this list of conditions and the following disclaimer in the documentation
hexley 0:281d6ff68967 18 * and/or other materials provided with the distribution.
hexley 0:281d6ff68967 19 * 3. The name of the author may not be used to endorse or promote products
hexley 0:281d6ff68967 20 * derived from this software without specific prior written permission.
hexley 0:281d6ff68967 21 *
hexley 0:281d6ff68967 22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
hexley 0:281d6ff68967 23 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
hexley 0:281d6ff68967 24 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
hexley 0:281d6ff68967 25 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
hexley 0:281d6ff68967 26 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
hexley 0:281d6ff68967 27 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
hexley 0:281d6ff68967 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
hexley 0:281d6ff68967 29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
hexley 0:281d6ff68967 30 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
hexley 0:281d6ff68967 31 * OF SUCH DAMAGE.
hexley 0:281d6ff68967 32 *
hexley 0:281d6ff68967 33 * This file is part of the lwIP TCP/IP stack.
hexley 0:281d6ff68967 34 *
hexley 0:281d6ff68967 35 * Author: Adam Dunkels <adam@sics.se>
hexley 0:281d6ff68967 36 *
hexley 0:281d6ff68967 37 */
hexley 0:281d6ff68967 38
hexley 0:281d6ff68967 39 /* Some ICMP messages should be passed to the transport protocols. This
hexley 0:281d6ff68967 40 is not implemented. */
hexley 0:281d6ff68967 41
hexley 0:281d6ff68967 42 #include "lwip/opt.h"
hexley 0:281d6ff68967 43
hexley 0:281d6ff68967 44 #if LWIP_ICMP /* don't build if not configured for use in lwipopts.h */
hexley 0:281d6ff68967 45
hexley 0:281d6ff68967 46 #include "lwip/icmp.h"
hexley 0:281d6ff68967 47 #include "lwip/inet_chksum.h"
hexley 0:281d6ff68967 48 #include "lwip/ip.h"
hexley 0:281d6ff68967 49 #include "lwip/def.h"
hexley 0:281d6ff68967 50 #include "lwip/stats.h"
hexley 0:281d6ff68967 51 #include "lwip/snmp.h"
hexley 0:281d6ff68967 52
hexley 0:281d6ff68967 53 #include <string.h>
hexley 0:281d6ff68967 54
hexley 0:281d6ff68967 55 /** Small optimization: set to 0 if incoming PBUF_POOL pbuf always can be
hexley 0:281d6ff68967 56 * used to modify and send a response packet (and to 1 if this is not the case,
hexley 0:281d6ff68967 57 * e.g. when link header is stripped of when receiving) */
hexley 0:281d6ff68967 58 #ifndef LWIP_ICMP_ECHO_CHECK_INPUT_PBUF_LEN
hexley 0:281d6ff68967 59 #define LWIP_ICMP_ECHO_CHECK_INPUT_PBUF_LEN 1
hexley 0:281d6ff68967 60 #endif /* LWIP_ICMP_ECHO_CHECK_INPUT_PBUF_LEN */
hexley 0:281d6ff68967 61
hexley 0:281d6ff68967 62 /* The amount of data from the original packet to return in a dest-unreachable */
hexley 0:281d6ff68967 63 #define ICMP_DEST_UNREACH_DATASIZE 8
hexley 0:281d6ff68967 64
hexley 0:281d6ff68967 65 static void icmp_send_response(struct pbuf *p, u8_t type, u8_t code);
hexley 0:281d6ff68967 66
hexley 0:281d6ff68967 67 /**
hexley 0:281d6ff68967 68 * Processes ICMP input packets, called from ip_input().
hexley 0:281d6ff68967 69 *
hexley 0:281d6ff68967 70 * Currently only processes icmp echo requests and sends
hexley 0:281d6ff68967 71 * out the echo response.
hexley 0:281d6ff68967 72 *
hexley 0:281d6ff68967 73 * @param p the icmp echo request packet, p->payload pointing to the ip header
hexley 0:281d6ff68967 74 * @param inp the netif on which this packet was received
hexley 0:281d6ff68967 75 */
hexley 0:281d6ff68967 76 void
hexley 0:281d6ff68967 77 icmp_input(struct pbuf *p, struct netif *inp)
hexley 0:281d6ff68967 78 {
hexley 0:281d6ff68967 79 u8_t type;
hexley 0:281d6ff68967 80 #ifdef LWIP_DEBUG
hexley 0:281d6ff68967 81 u8_t code;
hexley 0:281d6ff68967 82 #endif /* LWIP_DEBUG */
hexley 0:281d6ff68967 83 struct icmp_echo_hdr *iecho;
hexley 0:281d6ff68967 84 struct ip_hdr *iphdr;
hexley 0:281d6ff68967 85 s16_t hlen;
hexley 0:281d6ff68967 86
hexley 0:281d6ff68967 87 ICMP_STATS_INC(icmp.recv);
hexley 0:281d6ff68967 88 snmp_inc_icmpinmsgs();
hexley 0:281d6ff68967 89
hexley 0:281d6ff68967 90
hexley 0:281d6ff68967 91 iphdr = (struct ip_hdr *)p->payload;
hexley 0:281d6ff68967 92 hlen = IPH_HL(iphdr) * 4;
hexley 0:281d6ff68967 93 if (pbuf_header(p, -hlen) || (p->tot_len < sizeof(u16_t)*2)) {
hexley 0:281d6ff68967 94 LWIP_DEBUGF(ICMP_DEBUG, ("icmp_input: short ICMP (%"U16_F" bytes) received\n", p->tot_len));
hexley 0:281d6ff68967 95 goto lenerr;
hexley 0:281d6ff68967 96 }
hexley 0:281d6ff68967 97
hexley 0:281d6ff68967 98 type = *((u8_t *)p->payload);
hexley 0:281d6ff68967 99 #ifdef LWIP_DEBUG
hexley 0:281d6ff68967 100 code = *(((u8_t *)p->payload)+1);
hexley 0:281d6ff68967 101 #endif /* LWIP_DEBUG */
hexley 0:281d6ff68967 102 switch (type) {
hexley 0:281d6ff68967 103 case ICMP_ER:
hexley 0:281d6ff68967 104 /* This is OK, echo reply might have been parsed by a raw PCB
hexley 0:281d6ff68967 105 (as obviously, an echo request has been sent, too). */
hexley 0:281d6ff68967 106 break;
hexley 0:281d6ff68967 107 case ICMP_ECHO:
hexley 0:281d6ff68967 108 #if !LWIP_MULTICAST_PING || !LWIP_BROADCAST_PING
hexley 0:281d6ff68967 109 {
hexley 0:281d6ff68967 110 int accepted = 1;
hexley 0:281d6ff68967 111 #if !LWIP_MULTICAST_PING
hexley 0:281d6ff68967 112 /* multicast destination address? */
hexley 0:281d6ff68967 113 if (ip_addr_ismulticast(&current_iphdr_dest)) {
hexley 0:281d6ff68967 114 accepted = 0;
hexley 0:281d6ff68967 115 }
hexley 0:281d6ff68967 116 #endif /* LWIP_MULTICAST_PING */
hexley 0:281d6ff68967 117 #if !LWIP_BROADCAST_PING
hexley 0:281d6ff68967 118 /* broadcast destination address? */
hexley 0:281d6ff68967 119 if (ip_addr_isbroadcast(&current_iphdr_dest, inp)) {
hexley 0:281d6ff68967 120 accepted = 0;
hexley 0:281d6ff68967 121 }
hexley 0:281d6ff68967 122 #endif /* LWIP_BROADCAST_PING */
hexley 0:281d6ff68967 123 /* broadcast or multicast destination address not acceptd? */
hexley 0:281d6ff68967 124 if (!accepted) {
hexley 0:281d6ff68967 125 LWIP_DEBUGF(ICMP_DEBUG, ("icmp_input: Not echoing to multicast or broadcast pings\n"));
hexley 0:281d6ff68967 126 ICMP_STATS_INC(icmp.err);
hexley 0:281d6ff68967 127 pbuf_free(p);
hexley 0:281d6ff68967 128 return;
hexley 0:281d6ff68967 129 }
hexley 0:281d6ff68967 130 }
hexley 0:281d6ff68967 131 #endif /* !LWIP_MULTICAST_PING || !LWIP_BROADCAST_PING */
hexley 0:281d6ff68967 132 LWIP_DEBUGF(ICMP_DEBUG, ("icmp_input: ping\n"));
hexley 0:281d6ff68967 133 if (p->tot_len < sizeof(struct icmp_echo_hdr)) {
hexley 0:281d6ff68967 134 LWIP_DEBUGF(ICMP_DEBUG, ("icmp_input: bad ICMP echo received\n"));
hexley 0:281d6ff68967 135 goto lenerr;
hexley 0:281d6ff68967 136 }
hexley 0:281d6ff68967 137 if (inet_chksum_pbuf(p) != 0) {
hexley 0:281d6ff68967 138 LWIP_DEBUGF(ICMP_DEBUG, ("icmp_input: checksum failed for received ICMP echo\n"));
hexley 0:281d6ff68967 139 pbuf_free(p);
hexley 0:281d6ff68967 140 ICMP_STATS_INC(icmp.chkerr);
hexley 0:281d6ff68967 141 snmp_inc_icmpinerrors();
hexley 0:281d6ff68967 142 return;
hexley 0:281d6ff68967 143 }
hexley 0:281d6ff68967 144 #if LWIP_ICMP_ECHO_CHECK_INPUT_PBUF_LEN
hexley 0:281d6ff68967 145 if (pbuf_header(p, (PBUF_IP_HLEN + PBUF_LINK_HLEN))) {
hexley 0:281d6ff68967 146 /* p is not big enough to contain link headers
hexley 0:281d6ff68967 147 * allocate a new one and copy p into it
hexley 0:281d6ff68967 148 */
hexley 0:281d6ff68967 149 struct pbuf *r;
hexley 0:281d6ff68967 150 /* switch p->payload to ip header */
hexley 0:281d6ff68967 151 if (pbuf_header(p, hlen)) {
hexley 0:281d6ff68967 152 LWIP_ASSERT("icmp_input: moving p->payload to ip header failed\n", 0);
hexley 0:281d6ff68967 153 goto memerr;
hexley 0:281d6ff68967 154 }
hexley 0:281d6ff68967 155 /* allocate new packet buffer with space for link headers */
hexley 0:281d6ff68967 156 r = pbuf_alloc(PBUF_LINK, p->tot_len, PBUF_RAM);
hexley 0:281d6ff68967 157 if (r == NULL) {
hexley 0:281d6ff68967 158 LWIP_DEBUGF(ICMP_DEBUG, ("icmp_input: allocating new pbuf failed\n"));
hexley 0:281d6ff68967 159 goto memerr;
hexley 0:281d6ff68967 160 }
hexley 0:281d6ff68967 161 LWIP_ASSERT("check that first pbuf can hold struct the ICMP header",
hexley 0:281d6ff68967 162 (r->len >= hlen + sizeof(struct icmp_echo_hdr)));
hexley 0:281d6ff68967 163 /* copy the whole packet including ip header */
hexley 0:281d6ff68967 164 if (pbuf_copy(r, p) != ERR_OK) {
hexley 0:281d6ff68967 165 LWIP_ASSERT("icmp_input: copying to new pbuf failed\n", 0);
hexley 0:281d6ff68967 166 goto memerr;
hexley 0:281d6ff68967 167 }
hexley 0:281d6ff68967 168 iphdr = (struct ip_hdr *)r->payload;
hexley 0:281d6ff68967 169 /* switch r->payload back to icmp header */
hexley 0:281d6ff68967 170 if (pbuf_header(r, -hlen)) {
hexley 0:281d6ff68967 171 LWIP_ASSERT("icmp_input: restoring original p->payload failed\n", 0);
hexley 0:281d6ff68967 172 goto memerr;
hexley 0:281d6ff68967 173 }
hexley 0:281d6ff68967 174 /* free the original p */
hexley 0:281d6ff68967 175 pbuf_free(p);
hexley 0:281d6ff68967 176 /* we now have an identical copy of p that has room for link headers */
hexley 0:281d6ff68967 177 p = r;
hexley 0:281d6ff68967 178 } else {
hexley 0:281d6ff68967 179 /* restore p->payload to point to icmp header */
hexley 0:281d6ff68967 180 if (pbuf_header(p, -(s16_t)(PBUF_IP_HLEN + PBUF_LINK_HLEN))) {
hexley 0:281d6ff68967 181 LWIP_ASSERT("icmp_input: restoring original p->payload failed\n", 0);
hexley 0:281d6ff68967 182 goto memerr;
hexley 0:281d6ff68967 183 }
hexley 0:281d6ff68967 184 }
hexley 0:281d6ff68967 185 #endif /* LWIP_ICMP_ECHO_CHECK_INPUT_PBUF_LEN */
hexley 0:281d6ff68967 186 /* At this point, all checks are OK. */
hexley 0:281d6ff68967 187 /* We generate an answer by switching the dest and src ip addresses,
hexley 0:281d6ff68967 188 * setting the icmp type to ECHO_RESPONSE and updating the checksum. */
hexley 0:281d6ff68967 189 iecho = (struct icmp_echo_hdr *)p->payload;
hexley 0:281d6ff68967 190 ip_addr_copy(iphdr->src, *ip_current_dest_addr());
hexley 0:281d6ff68967 191 ip_addr_copy(iphdr->dest, *ip_current_src_addr());
hexley 0:281d6ff68967 192 ICMPH_TYPE_SET(iecho, ICMP_ER);
hexley 0:281d6ff68967 193 /* adjust the checksum */
hexley 0:281d6ff68967 194 if (iecho->chksum >= PP_HTONS(0xffff - (ICMP_ECHO << 8))) {
hexley 0:281d6ff68967 195 iecho->chksum += PP_HTONS(ICMP_ECHO << 8) + 1;
hexley 0:281d6ff68967 196 } else {
hexley 0:281d6ff68967 197 iecho->chksum += PP_HTONS(ICMP_ECHO << 8);
hexley 0:281d6ff68967 198 }
hexley 0:281d6ff68967 199
hexley 0:281d6ff68967 200 /* Set the correct TTL and recalculate the header checksum. */
hexley 0:281d6ff68967 201 IPH_TTL_SET(iphdr, ICMP_TTL);
hexley 0:281d6ff68967 202 IPH_CHKSUM_SET(iphdr, 0);
hexley 0:281d6ff68967 203 #if CHECKSUM_GEN_IP
hexley 0:281d6ff68967 204 IPH_CHKSUM_SET(iphdr, inet_chksum(iphdr, IP_HLEN));
hexley 0:281d6ff68967 205 #endif /* CHECKSUM_GEN_IP */
hexley 0:281d6ff68967 206
hexley 0:281d6ff68967 207 ICMP_STATS_INC(icmp.xmit);
hexley 0:281d6ff68967 208 /* increase number of messages attempted to send */
hexley 0:281d6ff68967 209 snmp_inc_icmpoutmsgs();
hexley 0:281d6ff68967 210 /* increase number of echo replies attempted to send */
hexley 0:281d6ff68967 211 snmp_inc_icmpoutechoreps();
hexley 0:281d6ff68967 212
hexley 0:281d6ff68967 213 if(pbuf_header(p, hlen)) {
hexley 0:281d6ff68967 214 LWIP_ASSERT("Can't move over header in packet", 0);
hexley 0:281d6ff68967 215 } else {
hexley 0:281d6ff68967 216 err_t ret;
hexley 0:281d6ff68967 217 /* send an ICMP packet, src addr is the dest addr of the curren packet */
hexley 0:281d6ff68967 218 ret = ip_output_if(p, ip_current_dest_addr(), IP_HDRINCL,
hexley 0:281d6ff68967 219 ICMP_TTL, 0, IP_PROTO_ICMP, inp);
hexley 0:281d6ff68967 220 if (ret != ERR_OK) {
hexley 0:281d6ff68967 221 LWIP_DEBUGF(ICMP_DEBUG, ("icmp_input: ip_output_if returned an error: %c.\n", ret));
hexley 0:281d6ff68967 222 }
hexley 0:281d6ff68967 223 }
hexley 0:281d6ff68967 224 break;
hexley 0:281d6ff68967 225 default:
hexley 0:281d6ff68967 226 LWIP_DEBUGF(ICMP_DEBUG, ("icmp_input: ICMP type %"S16_F" code %"S16_F" not supported.\n",
hexley 0:281d6ff68967 227 (s16_t)type, (s16_t)code));
hexley 0:281d6ff68967 228 ICMP_STATS_INC(icmp.proterr);
hexley 0:281d6ff68967 229 ICMP_STATS_INC(icmp.drop);
hexley 0:281d6ff68967 230 }
hexley 0:281d6ff68967 231 pbuf_free(p);
hexley 0:281d6ff68967 232 return;
hexley 0:281d6ff68967 233 lenerr:
hexley 0:281d6ff68967 234 pbuf_free(p);
hexley 0:281d6ff68967 235 ICMP_STATS_INC(icmp.lenerr);
hexley 0:281d6ff68967 236 snmp_inc_icmpinerrors();
hexley 0:281d6ff68967 237 return;
hexley 0:281d6ff68967 238 #if LWIP_ICMP_ECHO_CHECK_INPUT_PBUF_LEN
hexley 0:281d6ff68967 239 memerr:
hexley 0:281d6ff68967 240 pbuf_free(p);
hexley 0:281d6ff68967 241 ICMP_STATS_INC(icmp.err);
hexley 0:281d6ff68967 242 snmp_inc_icmpinerrors();
hexley 0:281d6ff68967 243 return;
hexley 0:281d6ff68967 244 #endif /* LWIP_ICMP_ECHO_CHECK_INPUT_PBUF_LEN */
hexley 0:281d6ff68967 245 }
hexley 0:281d6ff68967 246
hexley 0:281d6ff68967 247 /**
hexley 0:281d6ff68967 248 * Send an icmp 'destination unreachable' packet, called from ip_input() if
hexley 0:281d6ff68967 249 * the transport layer protocol is unknown and from udp_input() if the local
hexley 0:281d6ff68967 250 * port is not bound.
hexley 0:281d6ff68967 251 *
hexley 0:281d6ff68967 252 * @param p the input packet for which the 'unreachable' should be sent,
hexley 0:281d6ff68967 253 * p->payload pointing to the IP header
hexley 0:281d6ff68967 254 * @param t type of the 'unreachable' packet
hexley 0:281d6ff68967 255 */
hexley 0:281d6ff68967 256 void
hexley 0:281d6ff68967 257 icmp_dest_unreach(struct pbuf *p, enum icmp_dur_type t)
hexley 0:281d6ff68967 258 {
hexley 0:281d6ff68967 259 icmp_send_response(p, ICMP_DUR, t);
hexley 0:281d6ff68967 260 }
hexley 0:281d6ff68967 261
hexley 0:281d6ff68967 262 #if IP_FORWARD || IP_REASSEMBLY
hexley 0:281d6ff68967 263 /**
hexley 0:281d6ff68967 264 * Send a 'time exceeded' packet, called from ip_forward() if TTL is 0.
hexley 0:281d6ff68967 265 *
hexley 0:281d6ff68967 266 * @param p the input packet for which the 'time exceeded' should be sent,
hexley 0:281d6ff68967 267 * p->payload pointing to the IP header
hexley 0:281d6ff68967 268 * @param t type of the 'time exceeded' packet
hexley 0:281d6ff68967 269 */
hexley 0:281d6ff68967 270 void
hexley 0:281d6ff68967 271 icmp_time_exceeded(struct pbuf *p, enum icmp_te_type t)
hexley 0:281d6ff68967 272 {
hexley 0:281d6ff68967 273 icmp_send_response(p, ICMP_TE, t);
hexley 0:281d6ff68967 274 }
hexley 0:281d6ff68967 275
hexley 0:281d6ff68967 276 #endif /* IP_FORWARD || IP_REASSEMBLY */
hexley 0:281d6ff68967 277
hexley 0:281d6ff68967 278 /**
hexley 0:281d6ff68967 279 * Send an icmp packet in response to an incoming packet.
hexley 0:281d6ff68967 280 *
hexley 0:281d6ff68967 281 * @param p the input packet for which the 'unreachable' should be sent,
hexley 0:281d6ff68967 282 * p->payload pointing to the IP header
hexley 0:281d6ff68967 283 * @param type Type of the ICMP header
hexley 0:281d6ff68967 284 * @param code Code of the ICMP header
hexley 0:281d6ff68967 285 */
hexley 0:281d6ff68967 286 static void
hexley 0:281d6ff68967 287 icmp_send_response(struct pbuf *p, u8_t type, u8_t code)
hexley 0:281d6ff68967 288 {
hexley 0:281d6ff68967 289 struct pbuf *q;
hexley 0:281d6ff68967 290 struct ip_hdr *iphdr;
hexley 0:281d6ff68967 291 /* we can use the echo header here */
hexley 0:281d6ff68967 292 struct icmp_echo_hdr *icmphdr;
hexley 0:281d6ff68967 293 ip_addr_t iphdr_src;
hexley 0:281d6ff68967 294
hexley 0:281d6ff68967 295 /* ICMP header + IP header + 8 bytes of data */
hexley 0:281d6ff68967 296 q = pbuf_alloc(PBUF_IP, sizeof(struct icmp_echo_hdr) + IP_HLEN + ICMP_DEST_UNREACH_DATASIZE,
hexley 0:281d6ff68967 297 PBUF_RAM);
hexley 0:281d6ff68967 298 if (q == NULL) {
hexley 0:281d6ff68967 299 LWIP_DEBUGF(ICMP_DEBUG, ("icmp_time_exceeded: failed to allocate pbuf for ICMP packet.\n"));
hexley 0:281d6ff68967 300 return;
hexley 0:281d6ff68967 301 }
hexley 0:281d6ff68967 302 LWIP_ASSERT("check that first pbuf can hold icmp message",
hexley 0:281d6ff68967 303 (q->len >= (sizeof(struct icmp_echo_hdr) + IP_HLEN + ICMP_DEST_UNREACH_DATASIZE)));
hexley 0:281d6ff68967 304
hexley 0:281d6ff68967 305 iphdr = (struct ip_hdr *)p->payload;
hexley 0:281d6ff68967 306 LWIP_DEBUGF(ICMP_DEBUG, ("icmp_time_exceeded from "));
hexley 0:281d6ff68967 307 ip_addr_debug_print(ICMP_DEBUG, &(iphdr->src));
hexley 0:281d6ff68967 308 LWIP_DEBUGF(ICMP_DEBUG, (" to "));
hexley 0:281d6ff68967 309 ip_addr_debug_print(ICMP_DEBUG, &(iphdr->dest));
hexley 0:281d6ff68967 310 LWIP_DEBUGF(ICMP_DEBUG, ("\n"));
hexley 0:281d6ff68967 311
hexley 0:281d6ff68967 312 icmphdr = (struct icmp_echo_hdr *)q->payload;
hexley 0:281d6ff68967 313 icmphdr->type = type;
hexley 0:281d6ff68967 314 icmphdr->code = code;
hexley 0:281d6ff68967 315 icmphdr->id = 0;
hexley 0:281d6ff68967 316 icmphdr->seqno = 0;
hexley 0:281d6ff68967 317
hexley 0:281d6ff68967 318 /* copy fields from original packet */
hexley 0:281d6ff68967 319 SMEMCPY((u8_t *)q->payload + sizeof(struct icmp_echo_hdr), (u8_t *)p->payload,
hexley 0:281d6ff68967 320 IP_HLEN + ICMP_DEST_UNREACH_DATASIZE);
hexley 0:281d6ff68967 321
hexley 0:281d6ff68967 322 /* calculate checksum */
hexley 0:281d6ff68967 323 icmphdr->chksum = 0;
hexley 0:281d6ff68967 324 icmphdr->chksum = inet_chksum(icmphdr, q->len);
hexley 0:281d6ff68967 325 ICMP_STATS_INC(icmp.xmit);
hexley 0:281d6ff68967 326 /* increase number of messages attempted to send */
hexley 0:281d6ff68967 327 snmp_inc_icmpoutmsgs();
hexley 0:281d6ff68967 328 /* increase number of destination unreachable messages attempted to send */
hexley 0:281d6ff68967 329 snmp_inc_icmpouttimeexcds();
hexley 0:281d6ff68967 330 ip_addr_copy(iphdr_src, iphdr->src);
hexley 0:281d6ff68967 331 ip_output(q, NULL, &iphdr_src, ICMP_TTL, 0, IP_PROTO_ICMP);
hexley 0:281d6ff68967 332 pbuf_free(q);
hexley 0:281d6ff68967 333 }
hexley 0:281d6ff68967 334
hexley 0:281d6ff68967 335 #endif /* LWIP_ICMP */