icmp.c
Go to the documentation of this file.
1 /**
2  * @file icmp.c
3  * @brief ICMP (Internet Control Message Protocol)
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneTCP Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.4.4
29  **/
30 
31 //Switch to the appropriate trace level
32 #define TRACE_LEVEL ICMP_TRACE_LEVEL
33 
34 //Dependencies
35 #include "core/net.h"
36 #include "core/ip.h"
37 #include "ipv4/ipv4.h"
38 #include "ipv4/ipv4_misc.h"
39 #include "ipv4/icmp.h"
40 #include "mibs/mib2_module.h"
41 #include "mibs/ip_mib_module.h"
42 #include "debug.h"
43 
44 //Check TCP/IP stack configuration
45 #if (IPV4_SUPPORT == ENABLED)
46 
47 
48 /**
49  * @brief Enable support for ICMP Echo Request messages
50  * @param[in] interface Underlying network interface
51  * @param[in] enable This flag specifies whether the host will respond to
52  * ICMP Echo Requests. When the flag is set to FALSE, incoming ICMP Echo
53  * Request messages will be dropped
54  * @return Error code
55  **/
56 
58 {
59  //Check parameters
60  if(interface == NULL)
62 
63  //Get exclusive access
65  //Enable or disable support for Echo Request messages
66  interface->ipv4Context.enableEchoReq = enable;
67  //Release exclusive access
69 
70  //Successful processing
71  return NO_ERROR;
72 }
73 
74 
75 /**
76  * @brief Enable support for broadcast ICMP Echo Request messages
77  * @param[in] interface Underlying network interface
78  * @param[in] enable This flag specifies whether the host will respond to
79  * broadcast ICMP Echo Requests. When the flag is set to FALSE, incoming ICMP
80  * Echo Request messages destined to a broadcast address will be dropped
81  * @return Error code
82  **/
83 
85  bool_t enable)
86 {
87  //Check parameters
88  if(interface == NULL)
90 
91  //Get exclusive access
93  //Enable or disable support for broadcast Echo Request messages
94  interface->ipv4Context.enableBroadcastEchoReq = enable;
95  //Release exclusive access
97 
98  //Successful processing
99  return NO_ERROR;
100 }
101 
102 
103 /**
104  * @brief Incoming ICMP message processing
105  * @param[in] interface Underlying network interface
106  * @param[in] requestPseudoHeader IPv4 pseudo header
107  * @param[in] buffer Multi-part buffer containing the incoming ICMP message
108  * @param[in] offset Offset to the first byte of the ICMP message
109  **/
110 
112  const Ipv4PseudoHeader *requestPseudoHeader, const NetBuffer *buffer,
113  size_t offset)
114 {
115  size_t length;
116  IcmpHeader *header;
117 
118  //Total number of ICMP messages which the entity received
119  MIB2_ICMP_INC_COUNTER32(icmpInMsgs, 1);
120  IP_MIB_INC_COUNTER32(icmpStats.icmpStatsInMsgs, 1);
121 
122  //Retrieve the length of the ICMP message
123  length = netBufferGetLength(buffer) - offset;
124 
125  //Ensure the message length is correct
126  if(length < sizeof(IcmpHeader))
127  {
128  //Number of ICMP messages which the entity received but determined
129  //as having ICMP-specific errors
130  MIB2_ICMP_INC_COUNTER32(icmpInErrors, 1);
131  IP_MIB_INC_COUNTER32(icmpStats.icmpStatsInErrors, 1);
132 
133  //Silently discard incoming message
134  return;
135  }
136 
137  //Point to the ICMP message header
138  header = netBufferAt(buffer, offset, 0);
139  //Sanity check
140  if(header == NULL)
141  return;
142 
143  //Debug message
144  TRACE_INFO("ICMP message received (%" PRIuSIZE " bytes)...\r\n", length);
145  //Dump message contents for debugging purpose
146  icmpDumpMessage(header);
147 
148  //Verify checksum value
149  if(ipCalcChecksumEx(buffer, offset, length) != 0x0000)
150  {
151  //Debug message
152  TRACE_WARNING("Wrong ICMP header checksum!\r\n");
153 
154  //Number of ICMP messages which the entity received but determined
155  //as having ICMP-specific errors
156  MIB2_ICMP_INC_COUNTER32(icmpInErrors, 1);
157  IP_MIB_INC_COUNTER32(icmpStats.icmpStatsInErrors, 1);
158 
159  //Drop incoming message
160  return;
161  }
162 
163  //Update ICMP statistics
164  icmpUpdateInStats(header->type);
165 
166  //Check the type of ICMP message
167  switch(header->type)
168  {
169  //Echo Request?
171  //Process Echo Request message
172  icmpProcessEchoRequest(interface, requestPseudoHeader, buffer, offset);
173  break;
174 
175  //Unknown type?
176  default:
177  //Debug message
178  TRACE_WARNING("Unknown ICMP message type!\r\n");
179  //Discard incoming ICMP message
180  break;
181  }
182 }
183 
184 
185 /**
186  * @brief Echo Request message processing
187  * @param[in] interface Underlying network interface
188  * @param[in] requestPseudoHeader IPv4 pseudo header
189  * @param[in] request Multi-part buffer containing the incoming Echo Request message
190  * @param[in] requestOffset Offset to the first byte of the Echo Request message
191  **/
192 
194  const Ipv4PseudoHeader *requestPseudoHeader, const NetBuffer *request,
195  size_t requestOffset)
196 {
197  error_t error;
198  size_t requestLength;
199  size_t replyOffset;
200  size_t replyLength;
201  NetBuffer *reply;
202  IcmpEchoMessage *requestHeader;
203  IcmpEchoMessage *replyHeader;
204  Ipv4PseudoHeader replyPseudoHeader;
205 
206  //Retrieve the length of the Echo Request message
207  requestLength = netBufferGetLength(request) - requestOffset;
208 
209  //Ensure the packet length is correct
210  if(requestLength < sizeof(IcmpEchoMessage))
211  return;
212 
213  //Point to the Echo Request header
214  requestHeader = netBufferAt(request, requestOffset, 0);
215  //Sanity check
216  if(requestHeader == NULL)
217  return;
218 
219  //Debug message
220  TRACE_INFO("ICMP Echo Request message received (%" PRIuSIZE " bytes)...\r\n", requestLength);
221  //Dump message contents for debugging purpose
222  icmpDumpEchoMessage(requestHeader);
223 
224  //If support for Echo Request messages has been explicitly disabled, then
225  //the host shall not respond to the incoming request
226  if(!interface->ipv4Context.enableEchoReq)
227  return;
228 
229  //Check whether the destination address of the Echo Request message is
230  //a broadcast or a multicast address
231  if(ipv4IsBroadcastAddr(interface, requestPseudoHeader->destAddr) ||
232  ipv4IsMulticastAddr(requestPseudoHeader->destAddr))
233  {
235 
236  //If support for broadcast Echo Request messages has been explicitly
237  //disabled, then the host shall not respond to the incoming request
238  if(!interface->ipv4Context.enableBroadcastEchoReq)
239  return;
240 
241  //The source address of the reply must be a unicast address belonging to
242  //the interface on which the broadcast Echo Request message was received
243  error = ipv4SelectSourceAddr(&interface, requestPseudoHeader->srcAddr,
244  &ipAddr);
245  //Any error to report?
246  if(error)
247  return;
248 
249  //Copy the resulting source IP address
250  replyPseudoHeader.srcAddr = ipAddr;
251  }
252  else
253  {
254  //The destination address of the Echo Request message is a unicast address
255  replyPseudoHeader.srcAddr = requestPseudoHeader->destAddr;
256  }
257 
258  //Allocate memory to hold the Echo Reply message
259  reply = ipAllocBuffer(sizeof(IcmpEchoMessage), &replyOffset);
260  //Failed to allocate memory?
261  if(reply == NULL)
262  return;
263 
264  //Point to the Echo Reply header
265  replyHeader = netBufferAt(reply, replyOffset, 0);
266 
267  //Format Echo Reply header
268  replyHeader->type = ICMP_TYPE_ECHO_REPLY;
269  replyHeader->code = 0;
270  replyHeader->checksum = 0;
271  replyHeader->identifier = requestHeader->identifier;
272  replyHeader->sequenceNumber = requestHeader->sequenceNumber;
273 
274  //Point to the first data byte
275  requestOffset += sizeof(IcmpEchoMessage);
276  requestLength -= sizeof(IcmpEchoMessage);
277 
278  //Check the length of the payload
279  if(requestLength > 0)
280  {
281  //Copy payload data
282  error = netBufferConcat(reply, request, requestOffset, requestLength);
283  }
284  else
285  {
286  //The Echo Request message is empty
287  error = NO_ERROR;
288  }
289 
290  //Check status code
291  if(!error)
292  {
293  NetTxAncillary ancillary;
294 
295  //Get the length of the resulting message
296  replyLength = netBufferGetLength(reply) - replyOffset;
297  //Calculate ICMP header checksum
298  replyHeader->checksum = ipCalcChecksumEx(reply, replyOffset, replyLength);
299 
300  //Format IPv4 pseudo header
301  replyPseudoHeader.destAddr = requestPseudoHeader->srcAddr;
302  replyPseudoHeader.reserved = 0;
303  replyPseudoHeader.protocol = IPV4_PROTOCOL_ICMP;
304  replyPseudoHeader.length = htons(replyLength);
305 
306  //Update ICMP statistics
308 
309  //Debug message
310  TRACE_INFO("Sending ICMP Echo Reply message (%" PRIuSIZE " bytes)...\r\n", replyLength);
311  //Dump message contents for debugging purpose
312  icmpDumpEchoMessage(replyHeader);
313 
314  //Additional options can be passed to the stack along with the packet
315  ancillary = NET_DEFAULT_TX_ANCILLARY;
316 
317  //Send Echo Reply message
318  ipv4SendDatagram(interface, &replyPseudoHeader, reply, replyOffset,
319  &ancillary);
320  }
321 
322  //Free previously allocated memory block
323  netBufferFree(reply);
324 }
325 
326 
327 /**
328  * @brief Send an ICMP Error message
329  * @param[in] interface Underlying network interface
330  * @param[in] type Message type
331  * @param[in] code Specific message code
332  * @param[in] parameter Specific message parameter
333  * @param[in] ipPacket Multi-part buffer that holds the invoking IPv4 packet
334  * @param[in] ipPacketOffset Offset to the first byte of the IPv4 packet
335  * @return Error code
336  **/
337 
339  uint8_t code, uint8_t parameter, const NetBuffer *ipPacket,
340  size_t ipPacketOffset)
341 {
342  error_t error;
343  size_t offset;
344  size_t length;
345  Ipv4Header *ipHeader;
346  NetBuffer *icmpMessage;
347  IcmpErrorMessage *icmpHeader;
348  Ipv4PseudoHeader pseudoHeader;
349 
350  //Retrieve the length of the invoking IPv4 packet
351  length = netBufferGetLength(ipPacket) - ipPacketOffset;
352 
353  //Check the length of the IPv4 packet
354  if(length < sizeof(Ipv4Header))
355  return ERROR_INVALID_LENGTH;
356 
357  //Point to the header of the invoking packet
358  ipHeader = netBufferAt(ipPacket, ipPacketOffset, 0);
359  //Sanity check
360  if(ipHeader == NULL)
361  return ERROR_FAILURE;
362 
363  //Never respond to a packet destined to a broadcast or a multicast address
364  if(ipv4IsBroadcastAddr(interface, ipHeader->destAddr) ||
365  ipv4IsMulticastAddr(ipHeader->destAddr))
366  {
367  //Report an error
368  return ERROR_INVALID_ADDRESS;
369  }
370 
371  //Length of the data that will be returned along with the ICMP header
372  length = MIN(length, (size_t) ipHeader->headerLength * 4 + 8);
373 
374  //Allocate a memory buffer to hold the ICMP message
375  icmpMessage = ipAllocBuffer(sizeof(IcmpErrorMessage), &offset);
376  //Failed to allocate memory?
377  if(icmpMessage == NULL)
378  return ERROR_OUT_OF_MEMORY;
379 
380  //Point to the ICMP header
381  icmpHeader = netBufferAt(icmpMessage, offset, 0);
382 
383  //Format ICMP message
384  icmpHeader->type = type;
385  icmpHeader->code = code;
386  icmpHeader->checksum = 0;
387  icmpHeader->parameter = parameter;
388  icmpHeader->unused[0] = 0;
389  icmpHeader->unused[1] = 0;
390  icmpHeader->unused[2] = 0;
391 
392  //Copy the IP header and the first 8 bytes of the original datagram data
393  error = netBufferConcat(icmpMessage, ipPacket, ipPacketOffset, length);
394 
395  //Check status code
396  if(!error)
397  {
398  NetTxAncillary ancillary;
399 
400  //Get the length of the resulting message
401  length = netBufferGetLength(icmpMessage) - offset;
402  //Message checksum calculation
403  icmpHeader->checksum = ipCalcChecksumEx(icmpMessage, offset, length);
404 
405  //Format IPv4 pseudo header
406  pseudoHeader.srcAddr = ipHeader->destAddr;
407  pseudoHeader.destAddr = ipHeader->srcAddr;
408  pseudoHeader.reserved = 0;
409  pseudoHeader.protocol = IPV4_PROTOCOL_ICMP;
410  pseudoHeader.length = htons(length);
411 
412  //Update ICMP statistics
414 
415  //Debug message
416  TRACE_INFO("Sending ICMP Error message (%" PRIuSIZE " bytes)...\r\n", length);
417  //Dump message contents for debugging purpose
418  icmpDumpErrorMessage(icmpHeader);
419 
420  //Additional options can be passed to the stack along with the packet
421  ancillary = NET_DEFAULT_TX_ANCILLARY;
422 
423  //Send ICMP Error message
424  error = ipv4SendDatagram(interface, &pseudoHeader, icmpMessage, offset,
425  &ancillary);
426  }
427 
428  //Free previously allocated memory
429  netBufferFree(icmpMessage);
430 
431  //Return status code
432  return error;
433 }
434 
435 
436 /**
437  * @brief Update ICMP input statistics
438  * @param[in] type ICMP message type
439  **/
440 
441 void icmpUpdateInStats(uint8_t type)
442 {
443  //Check ICMP message type
444  switch(type)
445  {
447  //Number of ICMP Destination Unreachable messages received
448  MIB2_ICMP_INC_COUNTER32(icmpInDestUnreachs, 1);
449  break;
450 
452  //Number of ICMP Time Exceeded messages received
453  MIB2_ICMP_INC_COUNTER32(icmpInTimeExcds, 1);
454  break;
455 
457  //Number of ICMP Parameter Problem messages received
458  MIB2_ICMP_INC_COUNTER32(icmpInParmProbs, 1);
459  break;
460 
462  //Number of ICMP Source Quench messages received
463  MIB2_ICMP_INC_COUNTER32(icmpInSrcQuenchs, 1);
464  break;
465 
466  case ICMP_TYPE_REDIRECT:
467  //Number of ICMP Redirect messages received
468  MIB2_ICMP_INC_COUNTER32(icmpInRedirects, 1);
469  break;
470 
472  //Number of ICMP Echo Request messages received
473  MIB2_ICMP_INC_COUNTER32(icmpInEchos, 1);
474  break;
475 
477  //Number of ICMP Echo Reply messages received
478  MIB2_ICMP_INC_COUNTER32(icmpInEchoReps, 1);
479  break;
480 
482  //Number of ICMP Timestamp Request messages received
483  MIB2_ICMP_INC_COUNTER32(icmpInTimestamps, 1);
484  break;
485 
487  //Number of ICMP Timestamp Reply messages received
488  MIB2_ICMP_INC_COUNTER32(icmpInTimestampReps, 1);
489  break;
490 
492  //Number of ICMP Address Mask Request messages received
493  MIB2_ICMP_INC_COUNTER32(icmpInAddrMasks, 1);
494  break;
495 
497  //Number of ICMP Address Mask Reply messages received
498  MIB2_ICMP_INC_COUNTER32(icmpInAddrMaskReps, 1);
499  break;
500 
501  default:
502  //Just for sanity
503  break;
504  }
505 
506  //Increment per-message type ICMP counter
507  IP_MIB_INC_COUNTER32(icmpMsgStatsTable.icmpMsgStatsInPkts[type], 1);
508 }
509 
510 
511 /**
512  * @brief Update ICMP output statistics
513  * @param[in] type ICMPv6 message type
514  **/
515 
517 {
518  //Total number of ICMP messages which this entity attempted to send
519  MIB2_ICMP_INC_COUNTER32(icmpOutMsgs, 1);
520  IP_MIB_INC_COUNTER32(icmpStats.icmpStatsOutMsgs, 1);
521 
522  //Check ICMP message type
523  switch(type)
524  {
526  //Number of ICMP Destination Unreachable messages sent
527  MIB2_ICMP_INC_COUNTER32(icmpOutDestUnreachs, 1);
528  break;
529 
531  //Number of ICMP Time Exceeded messages sent
532  MIB2_ICMP_INC_COUNTER32(icmpOutTimeExcds, 1);
533  break;
534 
536  //Number of ICMP Parameter Problem messages sent
537  MIB2_ICMP_INC_COUNTER32(icmpOutParmProbs, 1);
538  break;
539 
541  //Number of ICMP Source Quench messages sent
542  MIB2_ICMP_INC_COUNTER32(icmpOutSrcQuenchs, 1);
543  break;
544 
545  case ICMP_TYPE_REDIRECT:
546  //Number of ICMP Redirect messages sent
547  MIB2_ICMP_INC_COUNTER32(icmpOutRedirects, 1);
548  break;
549 
551  //Number of ICMP Echo Request messages sent
552  MIB2_ICMP_INC_COUNTER32(icmpOutEchos, 1);
553  break;
554 
556  //Number of ICMP Echo Reply messages sent
557  MIB2_ICMP_INC_COUNTER32(icmpOutEchoReps, 1);
558  break;
559 
561  //Number of ICMP Timestamp Request messages sent
562  MIB2_ICMP_INC_COUNTER32(icmpOutTimestamps, 1);
563  break;
564 
566  //Number of ICMP Timestamp Reply messages sent
567  MIB2_ICMP_INC_COUNTER32(icmpOutTimestampReps, 1);
568  break;
569 
571  //Number of ICMP Address Mask Request messages sent
572  MIB2_ICMP_INC_COUNTER32(icmpOutAddrMasks, 1);
573  break;
574 
576  //Number of ICMP Address Mask Reply messages sent
577  MIB2_ICMP_INC_COUNTER32(icmpOutAddrMaskReps, 1);
578  break;
579 
580  default:
581  //Just for sanity
582  break;
583  }
584 
585  //Increment per-message type ICMP counter
586  IP_MIB_INC_COUNTER32(icmpMsgStatsTable.icmpMsgStatsOutPkts[type], 1);
587 }
588 
589 
590 /**
591  * @brief Dump ICMP message for debugging purpose
592  * @param[in] message Pointer to the ICMP message
593  **/
594 
596 {
597  //Dump ICMP message
598  TRACE_DEBUG(" Type = %" PRIu8 "\r\n", message->type);
599  TRACE_DEBUG(" Code = %" PRIu8 "\r\n", message->code);
600  TRACE_DEBUG(" Checksum = 0x%04" PRIX16 "\r\n", ntohs(message->checksum));
601 }
602 
603 
604 /**
605  * @brief Dump ICMP Echo Request or Echo Reply message
606  * @param[in] message Pointer to the ICMP message
607  **/
608 
610 {
611  //Dump ICMP message
612  TRACE_DEBUG(" Type = %" PRIu8 "\r\n", message->type);
613  TRACE_DEBUG(" Code = %" PRIu8 "\r\n", message->code);
614  TRACE_DEBUG(" Checksum = 0x%04" PRIX16 "\r\n", ntohs(message->checksum));
615  TRACE_DEBUG(" Identifier = 0x%04" PRIX16 "\r\n", ntohs(message->identifier));
616  TRACE_DEBUG(" Sequence Number = 0x%04" PRIX16 "\r\n", ntohs(message->sequenceNumber));
617 }
618 
619 
620 /**
621  * @brief Dump generic ICMP Error message
622  * @param[in] message Pointer to the ICMP message
623  **/
624 
626 {
627  //Dump ICMP message
628  TRACE_DEBUG(" Type = %" PRIu8 "\r\n", message->type);
629  TRACE_DEBUG(" Code = %" PRIu8 "\r\n", message->code);
630  TRACE_DEBUG(" Checksum = 0x%04" PRIX16 "\r\n", ntohs(message->checksum));
631  TRACE_DEBUG(" Parameter = %" PRIu8 "\r\n", message->parameter);
632 }
633 
634 #endif
#define ipv4IsMulticastAddr(ipAddr)
Definition: ipv4.h:175
#define htons(value)
Definition: cpu_endian.h:413
MIB-II module.
NetBuffer * ipAllocBuffer(size_t length, size_t *offset)
Allocate a buffer to hold an IP packet.
Definition: ip.c:711
@ ICMP_TYPE_ADDR_MASK_REQUEST
Definition: icmp.h:64
uint8_t code
Definition: coap_common.h:179
int bool_t
Definition: compiler_port.h:53
#define Ipv4Header
Definition: ipv4.h:36
void icmpDumpEchoMessage(const IcmpEchoMessage *message)
Dump ICMP Echo Request or Echo Reply message.
Definition: icmp.c:609
@ IPV4_PROTOCOL_ICMP
Definition: ipv4.h:250
uint16_t ipCalcChecksumEx(const NetBuffer *buffer, size_t offset, size_t length)
Calculate IP checksum over a multi-part buffer.
Definition: ip.c:586
const NetTxAncillary NET_DEFAULT_TX_ANCILLARY
Definition: net_misc.c:71
#define netMutex
Definition: net_legacy.h:195
#define IP_MIB_INC_COUNTER32(name, value)
Definition: ip_mib_module.h:46
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:89
uint8_t message[]
Definition: chap.h:154
bool_t ipv4IsBroadcastAddr(NetInterface *interface, Ipv4Addr ipAddr)
Check whether an IPv4 address is a broadcast address.
Definition: ipv4_misc.c:476
error_t ipv4SelectSourceAddr(NetInterface **interface, Ipv4Addr destAddr, Ipv4Addr *srcAddr)
IPv4 source address selection.
Definition: ipv4_misc.c:174
error_t icmpEnableBroadcastEchoRequests(NetInterface *interface, bool_t enable)
Enable support for broadcast ICMP Echo Request messages.
Definition: icmp.c:84
uint8_t type
Definition: coap_common.h:176
@ ERROR_OUT_OF_MEMORY
Definition: error.h:63
@ ICMP_TYPE_TIME_EXCEEDED
Definition: icmp.h:58
uint8_t parameter
Definition: icmp.h:125
@ ICMP_TYPE_PARAM_PROBLEM
Definition: icmp.h:59
uint32_t Ipv4Addr
IPv4 network address.
Definition: ipv4.h:297
uint8_t ipPacket[]
Definition: ndp.h:431
IcmpHeader
Definition: icmp.h:113
error_t netBufferConcat(NetBuffer *dest, const NetBuffer *src, size_t srcOffset, size_t length)
Concatenate two multi-part buffers.
Definition: net_mem.c:460
void icmpProcessMessage(NetInterface *interface, const Ipv4PseudoHeader *requestPseudoHeader, const NetBuffer *buffer, size_t offset)
Incoming ICMP message processing.
Definition: icmp.c:111
Helper functions for IPv4.
void icmpDumpErrorMessage(const IcmpErrorMessage *message)
Dump generic ICMP Error message.
Definition: icmp.c:625
@ ERROR_INVALID_PARAMETER
Invalid parameter.
Definition: error.h:47
ICMP (Internet Control Message Protocol)
error_t
Error codes.
Definition: error.h:43
@ ICMP_TYPE_REDIRECT
Definition: icmp.h:56
@ ERROR_INVALID_ADDRESS
Definition: error.h:103
@ ERROR_FAILURE
Generic error code.
Definition: error.h:45
@ ICMP_TYPE_TIMESTAMP_REPLY
Definition: icmp.h:61
@ ICMP_TYPE_SOURCE_QUENCH
Definition: icmp.h:55
#define MIB2_ICMP_INC_COUNTER32(name, value)
Definition: mib2_module.h:171
#define NetInterface
Definition: net.h:36
void netBufferFree(NetBuffer *buffer)
Dispose a multi-part buffer.
Definition: net_mem.c:282
@ ERROR_INVALID_LENGTH
Definition: error.h:111
#define NetTxAncillary
Definition: net_misc.h:36
IcmpEchoMessage
Definition: icmp.h:186
@ ICMP_TYPE_ECHO_REQUEST
Definition: icmp.h:57
#define Ipv4PseudoHeader
Definition: ipv4.h:39
#define TRACE_INFO(...)
Definition: debug.h:95
uint8_t length
Definition: tcp.h:368
size_t netBufferGetLength(const NetBuffer *buffer)
Get the actual length of a multi-part buffer.
Definition: net_mem.c:297
#define MIN(a, b)
Definition: os_port.h:63
error_t icmpEnableEchoRequests(NetInterface *interface, bool_t enable)
Enable support for ICMP Echo Request messages.
Definition: icmp.c:57
void icmpUpdateInStats(uint8_t type)
Update ICMP input statistics.
Definition: icmp.c:441
@ ICMP_TYPE_INFO_REPLY
Definition: icmp.h:63
#define ntohs(value)
Definition: cpu_endian.h:421
#define TRACE_WARNING(...)
Definition: debug.h:85
#define TRACE_DEBUG(...)
Definition: debug.h:107
IcmpErrorMessage
Definition: icmp.h:128
@ ICMP_TYPE_DEST_UNREACHABLE
Definition: icmp.h:54
error_t ipv4SendDatagram(NetInterface *interface, const Ipv4PseudoHeader *pseudoHeader, NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary)
Send an IPv4 datagram.
Definition: ipv4.c:1010
IPv4 and IPv6 common routines.
@ ICMP_TYPE_ECHO_REPLY
Definition: icmp.h:53
IP MIB module.
void osAcquireMutex(OsMutex *mutex)
Acquire ownership of the specified mutex object.
void osReleaseMutex(OsMutex *mutex)
Release ownership of the specified mutex object.
void icmpDumpMessage(const IcmpHeader *message)
Dump ICMP message for debugging purpose.
Definition: icmp.c:595
@ ICMP_TYPE_ADDR_MASK_REPLY
Definition: icmp.h:65
void * netBufferAt(const NetBuffer *buffer, size_t offset, size_t length)
Returns a pointer to a data segment.
Definition: net_mem.c:418
Ipv4Addr ipAddr
Definition: ipcp.h:105
void icmpProcessEchoRequest(NetInterface *interface, const Ipv4PseudoHeader *requestPseudoHeader, const NetBuffer *request, size_t requestOffset)
Echo Request message processing.
Definition: icmp.c:193
void icmpUpdateOutStats(uint8_t type)
Update ICMP output statistics.
Definition: icmp.c:516
IPv4 (Internet Protocol Version 4)
#define PRIuSIZE
TCP/IP stack core.
error_t icmpSendErrorMessage(NetInterface *interface, uint8_t type, uint8_t code, uint8_t parameter, const NetBuffer *ipPacket, size_t ipPacketOffset)
Send an ICMP Error message.
Definition: icmp.c:338
@ NO_ERROR
Success.
Definition: error.h:44
Debugging facilities.
@ ICMP_TYPE_TIMESTAMP_REQUEST
Definition: icmp.h:60