A modified version of http://mbed.org/users/segundo/libraries/NetServices/ljhqix to add HTTP proxy feature (based on http://mbed.org/users/igorsk/programs/NetServicesSource/ltjpag)

Dependents:   SenseClient

Committer:
mimil
Date:
Tue Sep 06 13:26:45 2011 +0000
Revision:
0:308f83189a3f

        

Who changed what in which revision?

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