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-2025 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.5.0
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;
346  Ipv4Header *ipHeader;
347  NetBuffer *icmpMessage;
348  IcmpErrorMessage *icmpHeader;
349  Ipv4PseudoHeader pseudoHeader;
350 
351  //Retrieve the length of the invoking IPv4 packet
352  length = netBufferGetLength(ipPacket) - ipPacketOffset;
353 
354  //Check the length of the IPv4 packet
355  if(length < sizeof(Ipv4Header))
356  return ERROR_INVALID_LENGTH;
357 
358  //Point to the header of the invoking packet
359  ipHeader = netBufferAt(ipPacket, ipPacketOffset, sizeof(Ipv4Header));
360  //Sanity check
361  if(ipHeader == NULL)
362  return ERROR_FAILURE;
363 
364  //Check the type of the invoking packet
365  if(ipHeader->protocol == IPV4_PROTOCOL_ICMP)
366  {
367  //Make sure the ICMP message is valid
368  if(length >= (ipHeader->headerLength * 4 + sizeof(IcmpHeader)))
369  {
370  //Point to the ICMP header
371  icmpHeader = netBufferAt(ipPacket, ipPacketOffset +
372  ipHeader->headerLength * 4, sizeof(IcmpHeader));
373 
374  //Sanity check
375  if(icmpHeader != NULL)
376  {
377  //An ICMP error message must not be originated as a result of
378  //receiving an ICMP error or redirect message
379  if(icmpHeader->type == ICMP_TYPE_DEST_UNREACHABLE ||
380  icmpHeader->type == ICMP_TYPE_TIME_EXCEEDED ||
381  icmpHeader->type == ICMP_TYPE_PARAM_PROBLEM ||
382  icmpHeader->type == ICMP_TYPE_REDIRECT)
383  {
384  //Do not send any ICMP error message
385  return ERROR_INVALID_TYPE;
386  }
387  }
388  }
389  }
390 
391  //Never respond to a packet destined to a broadcast or a multicast address
392  if(ipv4IsBroadcastAddr(interface, ipHeader->destAddr) ||
393  ipv4IsMulticastAddr(ipHeader->destAddr))
394  {
395  //Report an error
396  return ERROR_INVALID_ADDRESS;
397  }
398 
399  //Length of the data that will be returned along with the ICMP header
400  length = MIN(length, (size_t) ipHeader->headerLength * 4 + 8);
401 
402  //Allocate a memory buffer to hold the ICMP message
403  icmpMessage = ipAllocBuffer(sizeof(IcmpErrorMessage), &offset);
404  //Failed to allocate memory?
405  if(icmpMessage == NULL)
406  return ERROR_OUT_OF_MEMORY;
407 
408  //Point to the ICMP header
409  icmpHeader = netBufferAt(icmpMessage, offset, 0);
410 
411  //Format ICMP message
412  icmpHeader->type = type;
413  icmpHeader->code = code;
414  icmpHeader->checksum = 0;
415  icmpHeader->parameter = parameter;
416  icmpHeader->unused[0] = 0;
417  icmpHeader->unused[1] = 0;
418  icmpHeader->unused[2] = 0;
419 
420  //Copy the IP header and the first 8 bytes of the original datagram data
421  error = netBufferConcat(icmpMessage, ipPacket, ipPacketOffset, length);
422 
423  //Check status code
424  if(!error)
425  {
426  //Get the length of the resulting message
427  length = netBufferGetLength(icmpMessage) - offset;
428  //Message checksum calculation
429  icmpHeader->checksum = ipCalcChecksumEx(icmpMessage, offset, length);
430 
431  //Check whether the destination address of the invoking packet matches a
432  //valid unicast address assigned to the interface
433  error = ipv4CheckDestAddr(interface, ipHeader->destAddr);
434 
435  //The source address must be the address of the gateway or host that
436  //composes the ICMP message (refer to RFC 792)
437  if(!error)
438  {
439  srcIpAddr = ipHeader->destAddr;
440  }
441  else
442  {
443  error = ipv4SelectSourceAddr(&interface, ipHeader->srcAddr,
444  &srcIpAddr);
445  }
446 
447  //Check status code
448  if(!error)
449  {
450  NetTxAncillary ancillary;
451 
452  //Format IPv4 pseudo header
453  pseudoHeader.srcAddr = srcIpAddr;
454  pseudoHeader.destAddr = ipHeader->srcAddr;
455  pseudoHeader.reserved = 0;
456  pseudoHeader.protocol = IPV4_PROTOCOL_ICMP;
457  pseudoHeader.length = htons(length);
458 
459  //Update ICMP statistics
461 
462  //Debug message
463  TRACE_INFO("Sending ICMP Error message (%" PRIuSIZE " bytes)...\r\n", length);
464  //Dump message contents for debugging purpose
465  icmpDumpErrorMessage(icmpHeader);
466 
467  //Additional options can be passed to the stack along with the packet
468  ancillary = NET_DEFAULT_TX_ANCILLARY;
469 
470  //Send ICMP Error message
471  error = ipv4SendDatagram(interface, &pseudoHeader, icmpMessage, offset,
472  &ancillary);
473  }
474  }
475 
476  //Free previously allocated memory
477  netBufferFree(icmpMessage);
478 
479  //Return status code
480  return error;
481 }
482 
483 
484 /**
485  * @brief Update ICMP input statistics
486  * @param[in] type ICMP message type
487  **/
488 
489 void icmpUpdateInStats(uint8_t type)
490 {
491  //Check ICMP message type
492  switch(type)
493  {
495  //Number of ICMP Destination Unreachable messages received
496  MIB2_ICMP_INC_COUNTER32(icmpInDestUnreachs, 1);
497  break;
498 
500  //Number of ICMP Time Exceeded messages received
501  MIB2_ICMP_INC_COUNTER32(icmpInTimeExcds, 1);
502  break;
503 
505  //Number of ICMP Parameter Problem messages received
506  MIB2_ICMP_INC_COUNTER32(icmpInParmProbs, 1);
507  break;
508 
510  //Number of ICMP Source Quench messages received
511  MIB2_ICMP_INC_COUNTER32(icmpInSrcQuenchs, 1);
512  break;
513 
514  case ICMP_TYPE_REDIRECT:
515  //Number of ICMP Redirect messages received
516  MIB2_ICMP_INC_COUNTER32(icmpInRedirects, 1);
517  break;
518 
520  //Number of ICMP Echo Request messages received
521  MIB2_ICMP_INC_COUNTER32(icmpInEchos, 1);
522  break;
523 
525  //Number of ICMP Echo Reply messages received
526  MIB2_ICMP_INC_COUNTER32(icmpInEchoReps, 1);
527  break;
528 
530  //Number of ICMP Timestamp Request messages received
531  MIB2_ICMP_INC_COUNTER32(icmpInTimestamps, 1);
532  break;
533 
535  //Number of ICMP Timestamp Reply messages received
536  MIB2_ICMP_INC_COUNTER32(icmpInTimestampReps, 1);
537  break;
538 
540  //Number of ICMP Address Mask Request messages received
541  MIB2_ICMP_INC_COUNTER32(icmpInAddrMasks, 1);
542  break;
543 
545  //Number of ICMP Address Mask Reply messages received
546  MIB2_ICMP_INC_COUNTER32(icmpInAddrMaskReps, 1);
547  break;
548 
549  default:
550  //Just for sanity
551  break;
552  }
553 
554  //Increment per-message type ICMP counter
555  IP_MIB_INC_COUNTER32(icmpMsgStatsTable.icmpMsgStatsInPkts[type], 1);
556 }
557 
558 
559 /**
560  * @brief Update ICMP output statistics
561  * @param[in] type ICMPv6 message type
562  **/
563 
565 {
566  //Total number of ICMP messages which this entity attempted to send
567  MIB2_ICMP_INC_COUNTER32(icmpOutMsgs, 1);
568  IP_MIB_INC_COUNTER32(icmpStats.icmpStatsOutMsgs, 1);
569 
570  //Check ICMP message type
571  switch(type)
572  {
574  //Number of ICMP Destination Unreachable messages sent
575  MIB2_ICMP_INC_COUNTER32(icmpOutDestUnreachs, 1);
576  break;
577 
579  //Number of ICMP Time Exceeded messages sent
580  MIB2_ICMP_INC_COUNTER32(icmpOutTimeExcds, 1);
581  break;
582 
584  //Number of ICMP Parameter Problem messages sent
585  MIB2_ICMP_INC_COUNTER32(icmpOutParmProbs, 1);
586  break;
587 
589  //Number of ICMP Source Quench messages sent
590  MIB2_ICMP_INC_COUNTER32(icmpOutSrcQuenchs, 1);
591  break;
592 
593  case ICMP_TYPE_REDIRECT:
594  //Number of ICMP Redirect messages sent
595  MIB2_ICMP_INC_COUNTER32(icmpOutRedirects, 1);
596  break;
597 
599  //Number of ICMP Echo Request messages sent
600  MIB2_ICMP_INC_COUNTER32(icmpOutEchos, 1);
601  break;
602 
604  //Number of ICMP Echo Reply messages sent
605  MIB2_ICMP_INC_COUNTER32(icmpOutEchoReps, 1);
606  break;
607 
609  //Number of ICMP Timestamp Request messages sent
610  MIB2_ICMP_INC_COUNTER32(icmpOutTimestamps, 1);
611  break;
612 
614  //Number of ICMP Timestamp Reply messages sent
615  MIB2_ICMP_INC_COUNTER32(icmpOutTimestampReps, 1);
616  break;
617 
619  //Number of ICMP Address Mask Request messages sent
620  MIB2_ICMP_INC_COUNTER32(icmpOutAddrMasks, 1);
621  break;
622 
624  //Number of ICMP Address Mask Reply messages sent
625  MIB2_ICMP_INC_COUNTER32(icmpOutAddrMaskReps, 1);
626  break;
627 
628  default:
629  //Just for sanity
630  break;
631  }
632 
633  //Increment per-message type ICMP counter
634  IP_MIB_INC_COUNTER32(icmpMsgStatsTable.icmpMsgStatsOutPkts[type], 1);
635 }
636 
637 
638 /**
639  * @brief Dump ICMP message for debugging purpose
640  * @param[in] message Pointer to the ICMP message
641  **/
642 
644 {
645  //Dump ICMP message
646  TRACE_DEBUG(" Type = %" PRIu8 "\r\n", message->type);
647  TRACE_DEBUG(" Code = %" PRIu8 "\r\n", message->code);
648  TRACE_DEBUG(" Checksum = 0x%04" PRIX16 "\r\n", ntohs(message->checksum));
649 }
650 
651 
652 /**
653  * @brief Dump ICMP Echo Request or Echo Reply message
654  * @param[in] message Pointer to the ICMP message
655  **/
656 
658 {
659  //Dump ICMP message
660  TRACE_DEBUG(" Type = %" PRIu8 "\r\n", message->type);
661  TRACE_DEBUG(" Code = %" PRIu8 "\r\n", message->code);
662  TRACE_DEBUG(" Checksum = 0x%04" PRIX16 "\r\n", ntohs(message->checksum));
663  TRACE_DEBUG(" Identifier = 0x%04" PRIX16 "\r\n", ntohs(message->identifier));
664  TRACE_DEBUG(" Sequence Number = 0x%04" PRIX16 "\r\n", ntohs(message->sequenceNumber));
665 }
666 
667 
668 /**
669  * @brief Dump generic ICMP Error message
670  * @param[in] message Pointer to the ICMP message
671  **/
672 
674 {
675  //Dump ICMP message
676  TRACE_DEBUG(" Type = %" PRIu8 "\r\n", message->type);
677  TRACE_DEBUG(" Code = %" PRIu8 "\r\n", message->code);
678  TRACE_DEBUG(" Checksum = 0x%04" PRIX16 "\r\n", ntohs(message->checksum));
679  TRACE_DEBUG(" Parameter = %" PRIu8 "\r\n", message->parameter);
680 }
681 
682 #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:710
@ ICMP_TYPE_ADDR_MASK_REQUEST
Definition: icmp.h:81
uint8_t code
Definition: coap_common.h:179
int bool_t
Definition: compiler_port.h:61
#define Ipv4Header
Definition: ipv4.h:36
void icmpDumpEchoMessage(const IcmpEchoMessage *message)
Dump ICMP Echo Request or Echo Reply message.
Definition: icmp.c:657
@ IPV4_PROTOCOL_ICMP
Definition: ipv4.h:251
uint16_t ipCalcChecksumEx(const NetBuffer *buffer, size_t offset, size_t length)
Calculate IP checksum over a multi-part buffer.
Definition: ip.c:585
const NetTxAncillary NET_DEFAULT_TX_ANCILLARY
Definition: net_misc.c:72
#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:75
uint8_t parameter
Definition: icmp.h:173
Ipv4Addr srcIpAddr
Definition: ipcp.h:79
@ ICMP_TYPE_PARAM_PROBLEM
Definition: icmp.h:76
uint32_t Ipv4Addr
IPv4 network address.
Definition: ipv4.h:298
uint8_t ipPacket[]
Definition: ndp.h:431
IcmpHeader
Definition: icmp.h:131
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
error_t ipv4CheckDestAddr(NetInterface *interface, Ipv4Addr ipAddr)
Destination IPv4 address filtering.
Definition: ipv4_misc.c:116
Helper functions for IPv4.
void icmpDumpErrorMessage(const IcmpErrorMessage *message)
Dump generic ICMP Error message.
Definition: icmp.c:673
@ 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:70
@ ERROR_INVALID_ADDRESS
Definition: error.h:103
@ ERROR_FAILURE
Generic error code.
Definition: error.h:45
@ ICMP_TYPE_TIMESTAMP_REPLY
Definition: icmp.h:78
@ ICMP_TYPE_SOURCE_QUENCH
Definition: icmp.h:69
#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:161
@ ERROR_INVALID_TYPE
Definition: error.h:115
@ ICMP_TYPE_ECHO_REQUEST
Definition: icmp.h:72
#define Ipv4PseudoHeader
Definition: ipv4.h:39
#define TRACE_INFO(...)
Definition: debug.h:105
uint8_t length
Definition: tcp.h:375
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:489
@ ICMP_TYPE_INFO_REPLY
Definition: icmp.h:80
#define ntohs(value)
Definition: cpu_endian.h:421
#define TRACE_WARNING(...)
Definition: debug.h:93
#define TRACE_DEBUG(...)
Definition: debug.h:119
IcmpErrorMessage
Definition: icmp.h:176
@ ICMP_TYPE_DEST_UNREACHABLE
Definition: icmp.h:68
error_t ipv4SendDatagram(NetInterface *interface, const Ipv4PseudoHeader *pseudoHeader, NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary)
Send an IPv4 datagram.
Definition: ipv4.c:1031
IPv4 and IPv6 common routines.
@ ICMP_TYPE_ECHO_REPLY
Definition: icmp.h:67
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:643
@ ICMP_TYPE_ADDR_MASK_REPLY
Definition: icmp.h:82
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:564
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:77