Dirk-Willem van Gulik (NXP/mbed) / Mbed 2 deprecated Bonjour

Dependencies:   mbed

Committer:
dirkx
Date:
Sat Aug 14 15:54:31 2010 +0000
Revision:
5:8e53abda9900
Parent:
0:355018f44c9f

        

Who changed what in which revision?

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