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