icmpv6.c
Go to the documentation of this file.
1 /**
2  * @file icmpv6.c
3  * @brief ICMPv6 (Internet Control Message Protocol Version 6)
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  * @section Description
28  *
29  * ICMPv6 is used by IPv6 nodes to report errors encountered in
30  * processing packets, and to perform other Internet-layer functions.
31  * ICMPv6 is an integral part of IPv6 and must be fully implemented
32  * by every IPv6 node. Refer to the RFC 2463 for more details
33  *
34  * @author Oryx Embedded SARL (www.oryx-embedded.com)
35  * @version 2.4.4
36  **/
37 
38 //Switch to the appropriate trace level
39 #define TRACE_LEVEL ICMPV6_TRACE_LEVEL
40 
41 //Dependencies
42 #include "core/net.h"
43 #include "core/ip.h"
44 #include "ipv6/ipv6.h"
45 #include "ipv6/ipv6_pmtu.h"
46 #include "ipv6/ipv6_misc.h"
47 #include "ipv6/icmpv6.h"
48 #include "ipv6/ndp.h"
50 #include "mld/mld_node_misc.h"
51 #include "mibs/ip_mib_module.h"
52 #include "debug.h"
53 
54 //Check TCP/IP stack configuration
55 #if (IPV6_SUPPORT == ENABLED)
56 
57 
58 /**
59  * @brief Enable support for ICMPv6 Echo Request messages
60  * @param[in] interface Underlying network interface
61  * @param[in] enable This flag specifies whether the host will respond to
62  * ICMPv6 Echo Requests. When the flag is set to FALSE, incoming ICMPv6 Echo
63  * Request messages will be dropped
64  * @return Error code
65  **/
66 
68 {
69  //Check parameters
70  if(interface == NULL)
72 
73  //Get exclusive access
75  //Enable or disable support for Echo Request messages
76  interface->ipv6Context.enableEchoReq = enable;
77  //Release exclusive access
79 
80  //Successful processing
81  return NO_ERROR;
82 }
83 
84 
85 /**
86  * @brief Enable support for multicast ICMPv6 Echo Request messages
87  * @param[in] interface Underlying network interface
88  * @param[in] enable This flag specifies whether the host will respond to
89  * multicast ICMPv6 Echo Requests. When the flag is set to FALSE, incoming
90  * ICMPv6 Echo Request messages destined to a multicast address will be
91  * dropped
92  * @return Error code
93  **/
94 
96  bool_t enable)
97 {
98  //Check parameters
99  if(interface == NULL)
101 
102  //Get exclusive access
104  //Enable or disable support for multicast Echo Request messages
105  interface->ipv6Context.enableMulticastEchoReq = enable;
106  //Release exclusive access
108 
109  //Successful processing
110  return NO_ERROR;
111 }
112 
113 
114 /**
115  * @brief Incoming ICMPv6 message processing
116  * @param[in] interface Underlying network interface
117  * @param[in] pseudoHeader IPv6 pseudo header
118  * @param[in] buffer Multi-part buffer containing the incoming ICMPv6 message
119  * @param[in] offset Offset to the first byte of the ICMPv6 message
120  * @param[in] ancillary Additional options passed to the stack along with
121  * the packet
122  **/
123 
125  const Ipv6PseudoHeader *pseudoHeader, const NetBuffer *buffer,
126  size_t offset, const NetRxAncillary *ancillary)
127 {
128  size_t length;
129  Icmpv6Header *header;
130 
131  //Total number of ICMP messages which the entity received
132  IP_MIB_INC_COUNTER32(icmpv6Stats.icmpStatsInMsgs, 1);
133 
134  //Retrieve the length of the ICMPv6 message
135  length = netBufferGetLength(buffer) - offset;
136 
137  //Ensure the message length is correct
138  if(length < sizeof(Icmpv6Header))
139  {
140  //Number of ICMP messages which the entity received but determined
141  //as having ICMP-specific errors
142  IP_MIB_INC_COUNTER32(icmpv6Stats.icmpStatsInErrors, 1);
143 
144  //Silently discard incoming message
145  return;
146  }
147 
148  //Point to the ICMPv6 message header
149  header = netBufferAt(buffer, offset, 0);
150 
151  //Sanity check
152  if(header == NULL)
153  return;
154 
155  //Debug message
156  TRACE_INFO("ICMPv6 message received (%" PRIuSIZE " bytes)...\r\n", length);
157  //Dump message contents for debugging purpose
158  icmpv6DumpMessage(header);
159 
160  //Verify checksum value
161  if(ipCalcUpperLayerChecksumEx(pseudoHeader,
162  sizeof(Ipv6PseudoHeader), buffer, offset, length) != 0x0000)
163  {
164  //Debug message
165  TRACE_WARNING("Wrong ICMPv6 header checksum!\r\n");
166 
167  //Number of ICMP messages which the entity received but determined
168  //as having ICMP-specific errors
169  IP_MIB_INC_COUNTER32(icmpv6Stats.icmpStatsInErrors, 1);
170 
171  //Exit immediately
172  return;
173  }
174 
175  //Check whether the destination address is the tentative address
176  if(ipv6IsTentativeAddr(interface, &pseudoHeader->destAddr))
177  {
178  //The interface must accept Neighbor Solicitation and
179  //Neighbor Advertisement messages
180  if(header->type != ICMPV6_TYPE_NEIGHBOR_SOL &&
181  header->type != ICMPV6_TYPE_NEIGHBOR_ADV)
182  {
183  //Other packets addressed to the tentative address
184  //should be silently discarded
185  return;
186  }
187  }
188 
189  //Increment per-message type ICMP counter
190  IP_MIB_INC_COUNTER32(icmpv6MsgStatsTable.icmpMsgStatsInPkts[header->type], 1);
191 
192  //Check the type of message
193  switch(header->type)
194  {
195  //Destination Unreachable message?
197  //Process Destination Unreachable message
198  icmpv6ProcessDestUnreachable(interface, pseudoHeader, buffer, offset);
199  break;
200  //Packet Too Big message?
202  //Process Packet Too Big message
203  icmpv6ProcessPacketTooBig(interface, pseudoHeader, buffer, offset);
204  break;
205  //Echo Request message?
207  //Process Echo Request message
208  icmpv6ProcessEchoRequest(interface, pseudoHeader, buffer, offset);
209  break;
210 #if (MLD_NODE_SUPPORT == ENABLED)
211  //MLD message?
216  //Process MLD message
217  mldProcessMessage(interface, pseudoHeader, buffer, offset, ancillary);
218  break;
219 #endif
220 #if (NDP_ROUTER_ADV_SUPPORT == ENABLED)
221  //Router Solicitation message?
223  //Process Router Solicitation message
224  ndpProcessRouterSol(interface, pseudoHeader, buffer, offset, ancillary);
225  break;
226 #endif
227 #if (NDP_SUPPORT == ENABLED)
228  //Router Advertisement message?
230  //Process Router Advertisement message
231  ndpProcessRouterAdv(interface, pseudoHeader, buffer, offset, ancillary);
232  break;
233  //Neighbor Solicitation message?
235  //Process Neighbor Solicitation message
236  ndpProcessNeighborSol(interface, pseudoHeader, buffer, offset, ancillary);
237  break;
238  //Neighbor Advertisement message?
240  //Process Neighbor Advertisement message
241  ndpProcessNeighborAdv(interface, pseudoHeader, buffer, offset, ancillary);
242  break;
243  //Redirect message?
245  //Process Redirect message
246  ndpProcessRedirect(interface, pseudoHeader, buffer, offset, ancillary);
247  break;
248 #endif
249  //Unknown type?
250  default:
251  //Debug message
252  TRACE_WARNING("Unknown ICMPv6 message type!\r\n");
253  //Discard incoming ICMPv6 message
254  break;
255  }
256 }
257 
258 
259 /**
260  * @brief Destination Unreachable message processing
261  * @param[in] interface Underlying network interface
262  * @param[in] pseudoHeader IPv6 pseudo header
263  * @param[in] buffer Multi-part buffer containing the incoming ICMPv6 message
264  * @param[in] offset Offset to the first byte of the ICMPv6 message
265  **/
266 
268  const Ipv6PseudoHeader *pseudoHeader, const NetBuffer *buffer,
269  size_t offset)
270 {
271  size_t length;
272  Icmpv6DestUnreachableMessage *icmpHeader;
273 
274  //Retrieve the length of the Destination Unreachable message
275  length = netBufferGetLength(buffer) - offset;
276 
277  //Ensure the packet length is correct
279  return;
280 
281  //Point to the ICMPv6 header
282  icmpHeader = netBufferAt(buffer, offset, 0);
283 
284  //Sanity check
285  if(icmpHeader == NULL)
286  return;
287 
288  //Debug message
289  TRACE_INFO("ICMPv6 Destination Unreachable message received (%" PRIuSIZE " bytes)...\r\n", length);
290  //Dump message contents for debugging purpose
292 }
293 
294 
295 /**
296  * @brief Packet Too Big message processing
297  * @param[in] interface Underlying network interface
298  * @param[in] pseudoHeader IPv6 pseudo header
299  * @param[in] buffer Multi-part buffer containing the incoming ICMPv6 message
300  * @param[in] offset Offset to the first byte of the ICMPv6 message
301  **/
302 
304  const Ipv6PseudoHeader *pseudoHeader, const NetBuffer *buffer,
305  size_t offset)
306 {
307  size_t length;
308  Icmpv6PacketTooBigMessage *icmpHeader;
309 
310 #if (IPV6_PMTU_SUPPORT == ENABLED)
311  uint32_t tentativePathMtu;
312  Ipv6Header *ipHeader;
313 #endif
314 
315  //Retrieve the length of the Packet Too Big message
316  length = netBufferGetLength(buffer) - offset;
317 
318  //Ensure the packet length is correct
319  if(length < sizeof(Icmpv6PacketTooBigMessage))
320  return;
321 
322  //Point to the ICMPv6 header
323  icmpHeader = netBufferAt(buffer, offset, 0);
324 
325  //Sanity check
326  if(icmpHeader == NULL)
327  return;
328 
329  //Debug message
330  TRACE_INFO("ICMPv6 Packet Too Big message received (%" PRIuSIZE " bytes)...\r\n", length);
331  //Dump message contents for debugging purpose
332  icmpv6DumpPacketTooBigMessage(icmpHeader);
333 
334 #if (IPV6_PMTU_SUPPORT == ENABLED)
335  //Move to the beginning of the original IPv6 packet
336  offset += sizeof(Icmpv6PacketTooBigMessage);
338 
339  //Ensure the packet length is correct
340  if(length < sizeof(Ipv6Header))
341  return;
342 
343  //Point to the original IPv6 header
344  ipHeader = netBufferAt(buffer, offset, 0);
345 
346  //Sanity check
347  if(ipHeader == NULL)
348  return;
349 
350  //The node uses the value in the MTU field in the Packet Too Big
351  //message as a tentative PMTU value
352  tentativePathMtu = ntohl(icmpHeader->mtu);
353 
354  //Update the PMTU for the specified destination address
355  ipv6UpdatePathMtu(interface, &ipHeader->destAddr, tentativePathMtu);
356 #endif
357 }
358 
359 
360 /**
361  * @brief Echo Request message processing
362  * @param[in] interface Underlying network interface
363  * @param[in] requestPseudoHeader IPv6 pseudo header
364  * @param[in] request Multi-part buffer containing the incoming ICMPv6 message
365  * @param[in] requestOffset Offset to the first byte of the ICMPv6 message
366  **/
367 
369  const Ipv6PseudoHeader *requestPseudoHeader, const NetBuffer *request,
370  size_t requestOffset)
371 {
372  error_t error;
373  size_t requestLength;
374  size_t replyOffset;
375  size_t replyLength;
376  NetBuffer *reply;
377  Icmpv6EchoMessage *requestHeader;
378  Icmpv6EchoMessage *replyHeader;
379  Ipv6PseudoHeader replyPseudoHeader;
380 
381  //Retrieve the length of the Echo Request message
382  requestLength = netBufferGetLength(request) - requestOffset;
383 
384  //Ensure the packet length is correct
385  if(requestLength < sizeof(Icmpv6EchoMessage))
386  return;
387 
388  //Point to the Echo Request header
389  requestHeader = netBufferAt(request, requestOffset, 0);
390 
391  //Sanity check
392  if(requestHeader == NULL)
393  return;
394 
395  //Debug message
396  TRACE_INFO("ICMPv6 Echo Request message received (%" PRIuSIZE " bytes)...\r\n", requestLength);
397  //Dump message contents for debugging purpose
398  icmpv6DumpEchoMessage(requestHeader);
399 
400  //If support for Echo Request messages has been explicitly disabled, then
401  //the host shall not respond to the incoming request
402  if(!interface->ipv6Context.enableEchoReq)
403  return;
404 
405  //Check whether the destination address of the Echo Request message is
406  //a multicast address
407  if(ipv6IsMulticastAddr(&requestPseudoHeader->destAddr))
408  {
409  //If support for multicast Echo Request messages has been explicitly
410  //disabled, then the host shall not respond to the incoming request
411  if(!interface->ipv6Context.enableMulticastEchoReq)
412  return;
413 
414  //The source address of the reply must be a unicast address belonging to
415  //the interface on which the multicast Echo Request message was received
416  error = ipv6SelectSourceAddr(&interface, &requestPseudoHeader->srcAddr,
417  &replyPseudoHeader.srcAddr);
418  //Any error to report?
419  if(error)
420  return;
421  }
422  else
423  {
424  //The destination address of the Echo Request message is a unicast address
425  replyPseudoHeader.srcAddr = requestPseudoHeader->destAddr;
426  }
427 
428  //Allocate memory to hold the Echo Reply message
429  reply = ipAllocBuffer(sizeof(Icmpv6EchoMessage), &replyOffset);
430  //Failed to allocate memory?
431  if(reply == NULL)
432  return;
433 
434  //Point to the Echo Reply header
435  replyHeader = netBufferAt(reply, replyOffset, 0);
436 
437  //Format Echo Reply header
438  replyHeader->type = ICMPV6_TYPE_ECHO_REPLY;
439  replyHeader->code = 0;
440  replyHeader->checksum = 0;
441  replyHeader->identifier = requestHeader->identifier;
442  replyHeader->sequenceNumber = requestHeader->sequenceNumber;
443 
444  //Point to the first data byte
445  requestOffset += sizeof(Icmpv6EchoMessage);
446  requestLength -= sizeof(Icmpv6EchoMessage);
447 
448  //The data received in the ICMPv6 Echo Request message must be returned
449  //entirely and unmodified in the ICMPv6 Echo Reply message
450  error = netBufferConcat(reply, request, requestOffset, requestLength);
451 
452  //Check status code
453  if(!error)
454  {
455  NetTxAncillary ancillary;
456 
457  //Get the length of the resulting message
458  replyLength = netBufferGetLength(reply) - replyOffset;
459 
460  //Format IPv6 pseudo header
461  replyPseudoHeader.destAddr = requestPseudoHeader->srcAddr;
462  replyPseudoHeader.length = htonl(replyLength);
463  replyPseudoHeader.reserved[0] = 0;
464  replyPseudoHeader.reserved[1] = 0;
465  replyPseudoHeader.reserved[2] = 0;
466  replyPseudoHeader.nextHeader = IPV6_ICMPV6_HEADER;
467 
468  //Message checksum calculation
469  replyHeader->checksum = ipCalcUpperLayerChecksumEx(&replyPseudoHeader,
470  sizeof(Ipv6PseudoHeader), reply, replyOffset, replyLength);
471 
472  //Total number of ICMP messages which this entity attempted to send
473  IP_MIB_INC_COUNTER32(icmpv6Stats.icmpStatsOutMsgs, 1);
474  //Increment per-message type ICMP counter
475  IP_MIB_INC_COUNTER32(icmpv6MsgStatsTable.icmpMsgStatsOutPkts[ICMPV6_TYPE_ECHO_REPLY], 1);
476 
477  //Debug message
478  TRACE_INFO("Sending ICMPv6 Echo Reply message (%" PRIuSIZE " bytes)...\r\n", replyLength);
479  //Dump message contents for debugging purpose
480  icmpv6DumpEchoMessage(replyHeader);
481 
482  //Additional options can be passed to the stack along with the packet
483  ancillary = NET_DEFAULT_TX_ANCILLARY;
484 
485  //Send Echo Reply message
486  ipv6SendDatagram(interface, &replyPseudoHeader, reply, replyOffset,
487  &ancillary);
488  }
489 
490  //Free previously allocated memory block
491  netBufferFree(reply);
492 }
493 
494 
495 /**
496  * @brief Send an ICMPv6 Error message
497  * @param[in] interface Underlying network interface
498  * @param[in] type Message type
499  * @param[in] code Specific message code
500  * @param[in] parameter Specific message parameter
501  * @param[in] ipPacket Multi-part buffer that holds the invoking IPv6 packet
502  * @param[in] ipPacketOffset Offset to the first byte of the IPv6 packet
503  * @return Error code
504  **/
505 
507  uint8_t code, uint32_t parameter, const NetBuffer *ipPacket,
508  size_t ipPacketOffset)
509 {
510  error_t error;
511  size_t offset;
512  size_t length;
513  NetBuffer *icmpMessage;
514  Icmpv6ErrorMessage *icmpHeader;
515  Ipv6Header *ipHeader;
516  Ipv6PseudoHeader pseudoHeader;
517 
518  //Retrieve the length of the invoking IPv6 packet
519  length = netBufferGetLength(ipPacket) - ipPacketOffset;
520 
521  //Check the length of the IPv6 packet
522  if(length < sizeof(Ipv6Header))
523  return ERROR_INVALID_LENGTH;
524 
525  //Point to the header of the invoking packet
526  ipHeader = netBufferAt(ipPacket, ipPacketOffset, 0);
527 
528  //Sanity check
529  if(ipHeader == NULL)
530  return ERROR_FAILURE;
531 
532  //Check the type of the invoking packet
533  if(ipHeader->nextHeader == IPV6_ICMPV6_HEADER)
534  {
535  //Make sure the ICMPv6 message is valid
536  if(length >= (sizeof(Ipv6Header) + sizeof(Icmpv6Header)))
537  {
538  //Point to the ICMPv6 header
539  icmpHeader = netBufferAt(ipPacket, ipPacketOffset + sizeof(Ipv6Header), 0);
540 
541  //Sanity check
542  if(icmpHeader != NULL)
543  {
544  //An ICMPv6 error message must not be originated as a result
545  //of receiving an ICMPv6 error or redirect message
546  if(icmpHeader->type == ICMPV6_TYPE_DEST_UNREACHABLE ||
547  icmpHeader->type == ICMPV6_TYPE_PACKET_TOO_BIG ||
548  icmpHeader->type == ICMPV6_TYPE_TIME_EXCEEDED ||
549  icmpHeader->type == ICMPV6_TYPE_PARAM_PROBLEM ||
550  icmpHeader->type == ICMPV6_TYPE_REDIRECT)
551  {
552  //Do not send the ICMPv6 error message...
553  return ERROR_INVALID_TYPE;
554  }
555  }
556  }
557  }
558 
559  //An ICMPv6 error message must not be originated as a result of
560  //receiving a packet destined to an IPv6 multicast address
561  if(ipv6IsMulticastAddr(&ipHeader->destAddr))
562  {
563  //There are two exceptions to this rule
565  {
566  //The Packet Too Big Message to allow Path MTU discovery to
567  //work for IPv6 multicast
568  }
569  else if(type == ICMPV6_TYPE_PARAM_PROBLEM &&
571  {
572  //The Parameter Problem Message, reporting an unrecognized IPv6
573  //option that has the Option Type highest-order two bits set to 10
574  }
575  else
576  {
577  //Do not send the ICMPv6 error message...
578  return ERROR_INVALID_ADDRESS;
579  }
580  }
581 
582  //An ICMPv6 error message must not be originated as a result of receiving a
583  //packet whose source address does not uniquely identify a single node (e.g.
584  //the IPv6 unspecified address, an IPv6 multicast address, or an address
585  //known by the ICMPv6 message originator to be an IPv6 anycast address)
586  if(ipv6IsAnycastAddr(interface, &ipHeader->srcAddr))
587  return ERROR_INVALID_ADDRESS;
588 
589  //Return as much of invoking IPv6 packet as possible without the ICMPv6
590  //packet exceeding the minimum IPv6 MTU
592  sizeof(Icmpv6ErrorMessage));
593 
594  //Allocate a memory buffer to hold the ICMPv6 message
595  icmpMessage = ipAllocBuffer(sizeof(Icmpv6ErrorMessage), &offset);
596 
597  //Failed to allocate memory?
598  if(icmpMessage == NULL)
599  return ERROR_OUT_OF_MEMORY;
600 
601  //Point to the ICMPv6 header
602  icmpHeader = netBufferAt(icmpMessage, offset, 0);
603 
604  //Format ICMPv6 Error message
605  icmpHeader->type = type;
606  icmpHeader->code = code;
607  icmpHeader->checksum = 0;
608  icmpHeader->parameter = htonl(parameter);
609 
610  //Copy incoming IPv6 packet contents
611  error = netBufferConcat(icmpMessage, ipPacket, ipPacketOffset, length);
612 
613  //Check status code
614  if(!error)
615  {
616  //Get the length of the resulting message
617  length = netBufferGetLength(icmpMessage) - offset;
618 
619  //Format IPv6 pseudo header
620  pseudoHeader.destAddr = ipHeader->srcAddr;
621  pseudoHeader.length = htonl(length);
622  pseudoHeader.reserved[0] = 0;
623  pseudoHeader.reserved[1] = 0;
624  pseudoHeader.reserved[2] = 0;
625  pseudoHeader.nextHeader = IPV6_ICMPV6_HEADER;
626 
627  //Select the relevant source address
628  error = ipv6SelectSourceAddr(&interface, &pseudoHeader.destAddr,
629  &pseudoHeader.srcAddr);
630 
631  //Check status code
632  if(!error)
633  {
634  NetTxAncillary ancillary;
635 
636  //Message checksum calculation
637  icmpHeader->checksum = ipCalcUpperLayerChecksumEx(&pseudoHeader,
638  sizeof(Ipv6PseudoHeader), icmpMessage, offset, length);
639 
640  //Total number of ICMP messages which this entity attempted to send
641  IP_MIB_INC_COUNTER32(icmpv6Stats.icmpStatsOutMsgs, 1);
642  //Increment per-message type ICMP counter
643  IP_MIB_INC_COUNTER32(icmpv6MsgStatsTable.icmpMsgStatsOutPkts[type], 1);
644 
645  //Debug message
646  TRACE_INFO("Sending ICMPv6 Error message (%" PRIuSIZE " bytes)...\r\n", length);
647  //Dump message contents for debugging purpose
648  icmpv6DumpErrorMessage(icmpHeader);
649 
650  //Additional options can be passed to the stack along with the packet
651  ancillary = NET_DEFAULT_TX_ANCILLARY;
652 
653  //Send ICMPv6 Error message
654  error = ipv6SendDatagram(interface, &pseudoHeader, icmpMessage, offset,
655  &ancillary);
656  }
657  }
658 
659  //Free previously allocated memory
660  netBufferFree(icmpMessage);
661 
662  //Return status code
663  return error;
664 }
665 
666 
667 /**
668  * @brief Dump ICMPv6 message for debugging purpose
669  * @param[in] message Pointer to the ICMP message
670  **/
671 
673 {
674  //Dump ICMPv6 message
675  TRACE_DEBUG(" Type = %" PRIu8 "\r\n", message->type);
676  TRACE_DEBUG(" Code = %" PRIu8 "\r\n", message->code);
677  TRACE_DEBUG(" Checksum = 0x%04" PRIX16 "\r\n", ntohs(message->checksum));
678 }
679 
680 
681 /**
682  * @brief Dump ICMPv6 Destination Unreachable message
683  * @param[in] message Pointer to the ICMPv6 message
684  **/
685 
687 {
688  //Dump ICMPv6 message
689  TRACE_DEBUG(" Type = %" PRIu8 "\r\n", message->type);
690  TRACE_DEBUG(" Code = %" PRIu8 "\r\n", message->code);
691  TRACE_DEBUG(" Checksum = 0x%04" PRIX16 "\r\n", ntohs(message->checksum));
692 }
693 
694 
695 /**
696  * @brief Dump ICMPv6 Packet Too Big message
697  * @param[in] message Pointer to the ICMPv6 message
698  **/
699 
701 {
702  //Dump ICMPv6 message
703  TRACE_DEBUG(" Type = %" PRIu8 "\r\n", message->type);
704  TRACE_DEBUG(" Code = %" PRIu8 "\r\n", message->code);
705  TRACE_DEBUG(" Checksum = 0x%04" PRIX16 "\r\n", ntohs(message->checksum));
706  TRACE_DEBUG(" MTU = %" PRIu32 "\r\n", ntohl(message->mtu));
707 }
708 
709 
710 /**
711  * @brief Dump ICMPv6 Echo Request or Echo Reply message
712  * @param[in] message Pointer to the ICMPv6 message
713  **/
714 
716 {
717  //Dump ICMPv6 message
718  TRACE_DEBUG(" Type = %" PRIu8 "\r\n", message->type);
719  TRACE_DEBUG(" Code = %" PRIu8 "\r\n", message->code);
720  TRACE_DEBUG(" Checksum = 0x%04" PRIX16 "\r\n", ntohs(message->checksum));
721  TRACE_DEBUG(" Identifier = 0x%04" PRIX16 "\r\n", ntohs(message->identifier));
722  TRACE_DEBUG(" Sequence Number = 0x%04" PRIX16 "\r\n", ntohs(message->sequenceNumber));
723 }
724 
725 
726 /**
727  * @brief Dump generic ICMPv6 Error message
728  * @param[in] message Pointer to the ICMPv6 message
729  **/
730 
732 {
733  //Dump ICMP message
734  TRACE_DEBUG(" Type = %" PRIu8 "\r\n", message->type);
735  TRACE_DEBUG(" Code = %" PRIu8 "\r\n", message->code);
736  TRACE_DEBUG(" Checksum = 0x%04" PRIX16 "\r\n", ntohs(message->checksum));
737  TRACE_DEBUG(" Parameter = %" PRIu32 "\r\n", ntohl(message->parameter));
738 }
739 
740 #endif
@ ICMPV6_TYPE_ROUTER_ADV
Definition: icmpv6.h:63
IPv6 (Internet Protocol Version 6)
@ ICMPV6_TYPE_PACKET_TOO_BIG
Definition: icmpv6.h:54
@ ICMPV6_TYPE_DEST_UNREACHABLE
Definition: icmpv6.h:53
void icmpv6ProcessDestUnreachable(NetInterface *interface, const Ipv6PseudoHeader *pseudoHeader, const NetBuffer *buffer, size_t offset)
Destination Unreachable message processing.
Definition: icmpv6.c:267
NetBuffer * ipAllocBuffer(size_t length, size_t *offset)
Allocate a buffer to hold an IP packet.
Definition: ip.c:711
uint8_t code
Definition: coap_common.h:179
int bool_t
Definition: compiler_port.h:53
const NetTxAncillary NET_DEFAULT_TX_ANCILLARY
Definition: net_misc.c:71
void icmpv6DumpEchoMessage(const Icmpv6EchoMessage *message)
Dump ICMPv6 Echo Request or Echo Reply message.
Definition: icmpv6.c:715
void icmpv6DumpErrorMessage(const Icmpv6ErrorMessage *message)
Dump generic ICMPv6 Error message.
Definition: icmpv6.c:731
#define netMutex
Definition: net_legacy.h:195
Icmpv6EchoMessage
Definition: icmpv6.h:233
void icmpv6DumpPacketTooBigMessage(const Icmpv6PacketTooBigMessage *message)
Dump ICMPv6 Packet Too Big message.
Definition: icmpv6.c:700
#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
#define Ipv6Header
Definition: ipv6.h:36
Icmpv6ErrorMessage
Definition: icmpv6.h:139
uint8_t type
Definition: coap_common.h:176
@ ERROR_OUT_OF_MEMORY
Definition: error.h:63
bool_t ipv6IsTentativeAddr(NetInterface *interface, const Ipv6Addr *ipAddr)
Check whether an IPv6 address is a tentative address.
Definition: ipv6_misc.c:1100
@ IPV6_ICMPV6_HEADER
Definition: ipv6.h:193
void ipv6UpdatePathMtu(NetInterface *interface, const Ipv6Addr *destAddr, size_t tentativePathMtu)
Update the PMTU for the specified path.
Definition: ipv6_pmtu.c:93
uint8_t parameter
Definition: icmp.h:125
@ ICMPV6_TYPE_MCAST_LISTENER_QUERY
Definition: icmpv6.h:59
void icmpv6DumpDestUnreachableMessage(const Icmpv6DestUnreachableMessage *message)
Dump ICMPv6 Destination Unreachable message.
Definition: icmpv6.c:686
uint8_t ipPacket[]
Definition: ndp.h:431
@ ICMPV6_TYPE_ECHO_REQUEST
Definition: icmpv6.h:57
error_t netBufferConcat(NetBuffer *dest, const NetBuffer *src, size_t srcOffset, size_t length)
Concatenate two multi-part buffers.
Definition: net_mem.c:460
@ ICMPV6_TYPE_ECHO_REPLY
Definition: icmpv6.h:58
#define ipv6IsMulticastAddr(ipAddr)
Definition: ipv6.h:139
error_t icmpv6SendErrorMessage(NetInterface *interface, uint8_t type, uint8_t code, uint32_t parameter, const NetBuffer *ipPacket, size_t ipPacketOffset)
Send an ICMPv6 Error message.
Definition: icmpv6.c:506
void ndpProcessRouterSol(NetInterface *interface, const Ipv6PseudoHeader *pseudoHeader, const NetBuffer *buffer, size_t offset, const NetRxAncillary *ancillary)
Router Solicitation message processing.
void ndpProcessRedirect(NetInterface *interface, const Ipv6PseudoHeader *pseudoHeader, const NetBuffer *buffer, size_t offset, const NetRxAncillary *ancillary)
Redirect message processing.
Definition: ndp.c:1363
ICMPv6 (Internet Control Message Protocol Version 6)
@ ERROR_INVALID_PARAMETER
Invalid parameter.
Definition: error.h:47
#define htonl(value)
Definition: cpu_endian.h:414
error_t
Error codes.
Definition: error.h:43
#define Ipv6PseudoHeader
Definition: ipv6.h:42
@ ICMPV6_TYPE_REDIRECT
Definition: icmpv6.h:66
error_t ipv6SelectSourceAddr(NetInterface **interface, const Ipv6Addr *destAddr, Ipv6Addr *srcAddr)
IPv6 source address selection.
Definition: ipv6_misc.c:870
@ ICMPV6_TYPE_MCAST_LISTENER_REPORT_V1
Definition: icmpv6.h:60
@ ERROR_INVALID_ADDRESS
Definition: error.h:103
@ ERROR_FAILURE
Generic error code.
Definition: error.h:45
void icmpv6DumpMessage(const Icmpv6Header *message)
Dump ICMPv6 message for debugging purpose.
Definition: icmpv6.c:672
@ ICMPV6_CODE_UNKNOWN_IPV6_OPTION
Definition: icmpv6.h:103
#define NetRxAncillary
Definition: net_misc.h:40
void icmpv6ProcessMessage(NetInterface *interface, const Ipv6PseudoHeader *pseudoHeader, const NetBuffer *buffer, size_t offset, const NetRxAncillary *ancillary)
Incoming ICMPv6 message processing.
Definition: icmpv6.c:124
#define NetInterface
Definition: net.h:36
void icmpv6ProcessPacketTooBig(NetInterface *interface, const Ipv6PseudoHeader *pseudoHeader, const NetBuffer *buffer, size_t offset)
Packet Too Big message processing.
Definition: icmpv6.c:303
void netBufferFree(NetBuffer *buffer)
Dispose a multi-part buffer.
Definition: net_mem.c:282
@ ERROR_INVALID_LENGTH
Definition: error.h:111
Helper functions for IPv6.
@ ICMPV6_TYPE_NEIGHBOR_ADV
Definition: icmpv6.h:65
#define NetTxAncillary
Definition: net_misc.h:36
@ ERROR_INVALID_TYPE
Definition: error.h:115
#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 icmpv6EnableMulticastEchoRequests(NetInterface *interface, bool_t enable)
Enable support for multicast ICMPv6 Echo Request messages.
Definition: icmpv6.c:95
Path MTU Discovery for IPv6.
NDP (Neighbor Discovery Protocol)
void ndpProcessNeighborSol(NetInterface *interface, const Ipv6PseudoHeader *pseudoHeader, const NetBuffer *buffer, size_t offset, const NetRxAncillary *ancillary)
Neighbor Solicitation message processing.
Definition: ndp.c:869
void ndpProcessNeighborAdv(NetInterface *interface, const Ipv6PseudoHeader *pseudoHeader, const NetBuffer *buffer, size_t offset, const NetRxAncillary *ancillary)
Neighbor Advertisement message processing.
Definition: ndp.c:1115
#define ntohs(value)
Definition: cpu_endian.h:421
#define TRACE_WARNING(...)
Definition: debug.h:85
#define TRACE_DEBUG(...)
Definition: debug.h:107
error_t icmpv6EnableEchoRequests(NetInterface *interface, bool_t enable)
Enable support for ICMPv6 Echo Request messages.
Definition: icmpv6.c:67
uint16_t ipCalcUpperLayerChecksumEx(const void *pseudoHeader, size_t pseudoHeaderLen, const NetBuffer *buffer, size_t offset, size_t length)
Calculate IP upper-layer checksum over a multi-part buffer.
Definition: ip.c:686
@ ICMPV6_TYPE_ROUTER_SOL
Definition: icmpv6.h:62
#define IPV6_DEFAULT_MTU
Definition: ipv6.h:115
IPv4 and IPv6 common routines.
error_t ipv6SendDatagram(NetInterface *interface, const Ipv6PseudoHeader *pseudoHeader, NetBuffer *buffer, size_t offset, NetTxAncillary *ancillary)
Send an IPv6 datagram.
Definition: ipv6.c:1703
void mldProcessMessage(NetInterface *interface, const Ipv6PseudoHeader *pseudoHeader, const NetBuffer *buffer, size_t offset, const NetRxAncillary *ancillary)
Process incoming MLD message.
Definition: mld_common.c:226
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.
bool_t ipv6IsAnycastAddr(NetInterface *interface, const Ipv6Addr *ipAddr)
Check whether an IPv6 address is an anycast address.
Definition: ipv6_misc.c:1064
@ ICMPV6_TYPE_MCAST_LISTENER_DONE_V1
Definition: icmpv6.h:61
void * netBufferAt(const NetBuffer *buffer, size_t offset, size_t length)
Returns a pointer to a data segment.
Definition: net_mem.c:418
Icmpv6DestUnreachableMessage
Definition: icmpv6.h:158
@ ICMPV6_TYPE_PARAM_PROBLEM
Definition: icmpv6.h:56
@ ICMPV6_TYPE_MCAST_LISTENER_REPORT_V2
Definition: icmpv6.h:67
Helper functions for MLD node.
#define PRIuSIZE
Icmpv6Header
Definition: icmpv6.h:125
Helper functions for router advertisement service.
TCP/IP stack core.
@ ICMPV6_TYPE_NEIGHBOR_SOL
Definition: icmpv6.h:64
void ndpProcessRouterAdv(NetInterface *interface, const Ipv6PseudoHeader *pseudoHeader, const NetBuffer *buffer, size_t offset, const NetRxAncillary *ancillary)
Router Advertisement message processing.
Definition: ndp.c:579
#define ntohl(value)
Definition: cpu_endian.h:422
void icmpv6ProcessEchoRequest(NetInterface *interface, const Ipv6PseudoHeader *requestPseudoHeader, const NetBuffer *request, size_t requestOffset)
Echo Request message processing.
Definition: icmpv6.c:368
@ NO_ERROR
Success.
Definition: error.h:44
@ ICMPV6_TYPE_TIME_EXCEEDED
Definition: icmpv6.h:55
Debugging facilities.
Icmpv6PacketTooBigMessage
Definition: icmpv6.h:177