dhcpv6_debug.c
Go to the documentation of this file.
1 /**
2  * @file dhcpv6_debug.c
3  * @brief Data logging functions for debugging purpose (DHCPv6)
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  * @author Oryx Embedded SARL (www.oryx-embedded.com)
26  * @version 1.9.0
27  **/
28 
29 //Switch to the appropriate trace level
30 #define TRACE_LEVEL DHCPV6_TRACE_LEVEL
31 
32 //Dependencies
33 #include "core/net.h"
34 #include "dhcpv6/dhcpv6_debug.h"
35 #include "debug.h"
36 
37 //Check TCP/IP stack configuration
38 #if (IPV6_SUPPORT == ENABLED && DHCPV6_TRACE_LEVEL >= TRACE_LEVEL_DEBUG)
39 
40 //DHCPv6 message types
41 static const char_t *messageLabel[] =
42 {
43  "",
44  "SOLICIT",
45  "ADVERTISE",
46  "REQUEST",
47  "CONFIRM",
48  "RENEW",
49  "REBIND",
50  "REPLY",
51  "RELEASE",
52  "DECLINE",
53  "RECONFIGURE",
54  "INFO-REQUEST",
55  "RELAY-FORW",
56  "RELAY-REPL"
57 };
58 
59 //DHCPv6 options
60 static const char_t *optionLabel[] =
61 {
62  "",
63  "Client Identifier",
64  "Server Identifier",
65  "IA_NA",
66  "IA_TA",
67  "IA Address",
68  "Option Request",
69  "Preference",
70  "Elapsed time",
71  "Relay Message",
72  "",
73  "Authentication",
74  "Server Unicast",
75  "Status Code",
76  "Rapid Commit",
77  "User Class",
78  "Vendor Class",
79  "Vendor Specific Information",
80  "Interface ID",
81  "Reconfigure Message",
82  "Reconfigure Accept",
83  "",
84  "",
85  "DNS Recursive Name Server",
86  "Domain Search List"
87 };
88 
89 //DHCPv6 status codes
90 static const char_t *statusLabel[] =
91 {
92  "Success",
93  "Unspecified Failure",
94  "No Address Available",
95  "No Binding",
96  "Not On Link",
97  "Use Multicast",
98 };
99 
100 //Prefix used to format the structure
101 static const char_t *prefix[8] =
102 {
103  "",
104  " ",
105  " ",
106  " ",
107  " ",
108  " ",
109  " ",
110  " "
111 };
112 
113 
114 /**
115  * @brief Dump DHCPv6 message for debugging purpose
116  * @param[in] message Pointer to the DHCPv6 message to dump
117  * @param[in] length Length of the message
118  * @return Error code
119  **/
120 
122 {
123  error_t error;
124  uint8_t type;
125  const char_t *label;
126 
127  //Empty message?
128  if(!length)
129  return ERROR_INVALID_LENGTH;
130 
131  //Retrieve the message type
132  type = *((uint8_t *) message);
133  //Get the corresponding label
134  label = (type < arraysize(messageLabel)) ? messageLabel[type] : "Unknown";
135 
136  //Relay agent/server message?
138  {
139  //Ensure the length of the DHCPv6 message is acceptable
140  if(length < sizeof(Dhcpv6RelayMessage))
141  {
142  //Report an error
143  error = ERROR_INVALID_LENGTH;
144  }
145  else
146  {
147  //Point to the DHCPv6 message
148  const Dhcpv6RelayMessage *relayMessage = message;
149 
150  //Dump message header
151  TRACE_DEBUG(" Message Type = %" PRIu8 " (%s)\r\n", relayMessage->msgType, label);
152  TRACE_DEBUG(" Hop Count = %" PRIu8 "\r\n", relayMessage->hopCount);
153  TRACE_DEBUG(" Link Address = %s\r\n", ipv6AddrToString(&relayMessage->linkAddress, NULL));
154  TRACE_DEBUG(" Peer Address = %s\r\n", ipv6AddrToString(&relayMessage->peerAddress, NULL));
155 
156  //Dump message options
157  error = dhcpv6DumpOptions(relayMessage->options, length - sizeof(Dhcpv6RelayMessage), 1);
158  }
159 
160  }
161  //Client/server message?
162  else
163  {
164  //Ensure the length of the DHCPv6 message is acceptable
165  if(length < sizeof(Dhcpv6Message))
166  {
167  //Report an error
168  error = ERROR_INVALID_LENGTH;
169  }
170  else
171  {
172  //Point to the DHCPv6 message
173  const Dhcpv6Message *clientMessage = message;
174 
175  //Dump message header
176  TRACE_DEBUG(" Message Type = %" PRIu8 " (%s)\r\n", clientMessage->msgType, label);
177  TRACE_DEBUG(" Transaction ID = 0x%06" PRIX32 "\r\n", LOAD24BE(clientMessage->transactionId));
178 
179  //Dump message options
180  error = dhcpv6DumpOptions(clientMessage->options, length - sizeof(Dhcpv6Message), 1);
181  }
182  }
183 
184  //Did we encounter an error?
185  if(error)
186  {
187  //Debug message
188  TRACE_WARNING("DHCPv6 message is not valid!\r\n");
189  //Dump message contents for debugging purpose
191  }
192 
193  //Return status code
194  return error;
195 }
196 
197 
198 /**
199  * @brief Dump DHCPv6 options for debugging purpose
200  * @param[in] options Pointer to the DHCPv6 options to dump
201  * @param[in] length Length of the options
202  * @param[in] level Current level of recursion
203  * @return Error code
204  **/
205 
207 {
208  error_t error;
209  size_t i;
210  Dhcpv6Option *option;
211 
212  //Check whether the maximum level of recursion is reached
213  if(level >= 6)
214  {
215  //If the maximum level of recursion is reached, then dump contents
216  TRACE_DEBUG("%sOptions (%" PRIuSIZE " bytes)\r\n", prefix[level], length);
218  //Exit immediately
219  return NO_ERROR;
220  }
221 
222  //Parse DHCPv6 options
223  for(i = 0; i < length; )
224  {
225  //Point to the current option
226  option = (Dhcpv6Option *) (options + i);
227 
228  //Make sure the option is valid
229  if((i + sizeof(Dhcpv6Option)) > length)
230  return ERROR_INVALID_OPTION;
231  //Check the length of the option data
232  if((i + sizeof(Dhcpv6Option) + ntohs(option->length)) > length)
233  return ERROR_INVALID_OPTION;
234 
235  //Check option code
236  switch(ntohs(option->code))
237  {
238  //Client Identifier option
240  error = dhcpv6DumpClientIdOption(option, level);
241  break;
242  //Server Identifier option
244  error = dhcpv6DumpServerIdOption(option, level);
245  break;
246  //IA_NA option
247  case DHCPV6_OPTION_IA_NA:
248  error = dhcpv6DumpIaNaOption(option, level);
249  break;
250  //IA_TA option
251  case DHCPV6_OPTION_IA_TA:
252  error = dhcpv6DumpIaTaOption(option, level);
253  break;
254  //IA Address option
256  error = dhcpv6DumpIaAddrOption(option, level);
257  break;
258  //Option Request option
259  case DHCPV6_OPTION_ORO:
260  error = dhcpv6DumpOroOption(option, level);
261  break;
262  //Preference option
264  error = dhcpv6DumpPreferenceOption(option, level);
265  break;
266  //Elapsed Time option
268  error = dhcpv6DumpElapsedTimeOption(option, level);
269  break;
270  //Relay Message option
272  error = dhcpv6DumpRelayMessageOption(option, level);
273  break;
274  //Authentication option
275  case DHCPV6_OPTION_AUTH:
276  error = dhcpv6DumpAuthOption(option, level);
277  break;
278  //Server Unicast option
280  error = dhcpv6DumpServerUnicastOption(option, level);
281  break;
282  //Status Code option
284  error = dhcpv6DumpStatusCodeOption(option, level);
285  break;
286  //Rapid Commit option
288  error = dhcpv6DumpRapidCommitOption(option, level);
289  break;
290  //User Class option
292  error = dhcpv6DumpUserClassOption(option, level);
293  break;
294  //Vendor Class option
296  error = dhcpv6DumpVendorClassOption(option, level);
297  break;
298  //Vendor Specific Information option
300  error = dhcpv6DumpVendorSpecificInfoOption(option, level);
301  break;
302  //Interface ID option
304  error = dhcpv6DumpInterfaceIdOption(option, level);
305  break;
306  //Reconfigure Message option
308  error = dhcpv6DumpReconfMessageOption(option, level);
309  break;
310  //Reconfigure Accept option
312  error = dhcpv6DumpReconfAcceptOption(option, level);
313  break;
314  //DNS Recursive Name Server option
316  error = dhcpv6DumpDnsServersOption(option, level);
317  break;
318  //Domain Search List option
320  error = dhcpv6DumpDomainListOption(option, level);
321  break;
322  //Unknown option...
323  default:
324  error = dhcpv6DumpGenericOption(option, level);
325  break;
326  }
327 
328  //Failed to parse current option?
329  if(error)
330  return error;
331 
332  //Jump to the next option
333  i += sizeof(Dhcpv6Option) + ntohs(option->length);
334  }
335 
336  //No error to report
337  return NO_ERROR;
338 
339 }
340 
341 
342 /**
343  * @brief Dump generic DHCPv6 option
344  * @param[in] option Pointer to the option to dump
345  * @param[in] level Current level of recursion
346  * @return Error code
347  **/
348 
350 {
351  //Dump contents
352  TRACE_DEBUG("%sOption %" PRIu16 " (%" PRIu16 " bytes)\r\n", prefix[level], ntohs(option->code), ntohs(option->length));
353  TRACE_DEBUG_ARRAY(prefix[level + 1], option->value, ntohs(option->length));
354 
355  //No error to report
356  return NO_ERROR;
357 }
358 
359 
360 /**
361  * @brief Dump Client Identifier option
362  * @param[in] option Pointer to the option to dump
363  * @param[in] level Current level of recursion
364  * @return Error code
365  **/
366 
368 {
369  //Dump contents
370  TRACE_DEBUG("%sClient Identifier option (%" PRIu16 " bytes)\r\n", prefix[level], ntohs(option->length));
371  TRACE_DEBUG_ARRAY(prefix[level + 1], option->value, ntohs(option->length));
372 
373  //No error to report
374  return NO_ERROR;
375 }
376 
377 
378 /**
379  * @brief Dump Server Identifier option
380  * @param[in] option Pointer to the option to dump
381  * @param[in] level Current level of recursion
382  * @return Error code
383  **/
384 
386 {
387  //Dump contents
388  TRACE_DEBUG("%sServer Identifier option (%" PRIu16 " bytes)\r\n", prefix[level], ntohs(option->length));
389  TRACE_DEBUG_ARRAY(prefix[level + 1], option->value, ntohs(option->length));
390 
391  //No error to report
392  return NO_ERROR;
393 }
394 
395 
396 /**
397  * @brief Dump IA_NA option
398  * @param[in] option Pointer to the option to dump
399  * @param[in] level Current level of recursion
400  * @return Error code
401  **/
402 
404 {
405  Dhcpv6IaNaOption *iaNaOption;
406 
407  //Check the length of the option
408  if(ntohs(option->length) < sizeof(Dhcpv6IaNaOption))
409  return ERROR_INVALID_OPTION;
410 
411  //Point to the option contents
412  iaNaOption = (Dhcpv6IaNaOption *) option->value;
413 
414  //Dump contents
415  TRACE_DEBUG("%sIA_NA option (%" PRIu16 " bytes)\r\n", prefix[level], ntohs(option->length));
416  TRACE_DEBUG("%sIA ID = 0x%08" PRIX32 "\r\n", prefix[level + 1], ntohl(iaNaOption->iaId));
417  TRACE_DEBUG("%sT1 = %" PRIu32 "s\r\n", prefix[level + 1], ntohl(iaNaOption->t1));
418  TRACE_DEBUG("%sT2 = %" PRIu32 "s\r\n", prefix[level + 1], ntohl(iaNaOption->t2));
419 
420  //Dump the options associated with this IA_NA
421  dhcpv6DumpOptions(iaNaOption->options, ntohs(option->length) - sizeof(Dhcpv6IaNaOption), level + 1);
422 
423  //No error to report
424  return NO_ERROR;
425 }
426 
427 
428 /**
429  * @brief Dump IA_TA option
430  * @param[in] option Pointer to the option to dump
431  * @param[in] level Current level of recursion
432  * @return Error code
433  **/
434 
436 {
437  Dhcpv6IaTaOption *iaTaOption;
438 
439  //Check the length of the option
440  if(ntohs(option->length) < sizeof(Dhcpv6IaTaOption))
441  return ERROR_INVALID_OPTION;
442 
443  //Point to the option contents
444  iaTaOption = (Dhcpv6IaTaOption *) option->value;
445 
446  //Dump contents
447  TRACE_DEBUG("%sIA_TA option (%" PRIu16 " bytes)\r\n", prefix[level], ntohs(option->length));
448  TRACE_DEBUG("%sIA ID = 0x%08" PRIX32 "\r\n", prefix[level + 1], ntohl(iaTaOption->iaId));
449 
450  //Dump the options associated with this IA_TA
451  dhcpv6DumpOptions(iaTaOption->options, ntohs(option->length) - sizeof(Dhcpv6IaTaOption), level + 1);
452 
453  //No error to report
454  return NO_ERROR;
455 }
456 
457 
458 /**
459  * @brief Dump IA Address option
460  * @param[in] option Pointer to the option to dump
461  * @param[in] level Current level of recursion
462  * @return Error code
463  **/
464 
466 {
467  Dhcpv6IaAddrOption *iaAddrOption;
468 
469  //Check the length of the option
470  if(ntohs(option->length) < sizeof(Dhcpv6IaAddrOption))
471  return ERROR_INVALID_OPTION;
472 
473  //Point to the option contents
474  iaAddrOption = (Dhcpv6IaAddrOption *) option->value;
475 
476  //Dump contents
477  TRACE_DEBUG("%sIA Address option (%" PRIu16 " bytes)\r\n", prefix[level], ntohs(option->length));
478  TRACE_DEBUG("%sIPv6 Address = %s\r\n", prefix[level + 1], ipv6AddrToString(&iaAddrOption->address, NULL));
479  TRACE_DEBUG("%sPreferred Lifetime = %" PRIu32 "s\r\n", prefix[level + 1], ntohl(iaAddrOption->preferredLifetime));
480  TRACE_DEBUG("%sValid Lifetime = %" PRIu32 "s\r\n", prefix[level + 1], ntohl(iaAddrOption->validLifetime));
481 
482  //Dump the options associated with this IA address
483  dhcpv6DumpOptions(iaAddrOption->options, ntohs(option->length) - sizeof(Dhcpv6IaAddrOption), level + 1);
484 
485  //No error to report
486  return NO_ERROR;
487 }
488 
489 
490 /**
491  * @brief Dump Option Request option
492  * @param[in] option Pointer to the option to dump
493  * @param[in] level Current level of recursion
494  * @return Error code
495  **/
496 
498 {
499  uint_t i;
500  uint_t n;
501  uint16_t code;
502  const char_t *label;
503  Dhcpv6OroOption *oroOption;
504 
505  //Check the length of the option
506  if(ntohs(option->length) % 2)
507  return ERROR_INVALID_OPTION;
508 
509  //Point to the option contents
510  oroOption = (Dhcpv6OroOption *) option->value;
511  //Get the number of requested options
512  n = ntohs(option->length) / 2;
513 
514  //Dump contents
515  TRACE_DEBUG("%sOption Request option (%" PRIu16 " bytes)\r\n", prefix[level], ntohs(option->length));
516 
517  //Parse the list of requested options
518  for(i = 0; i < n; i++)
519  {
520  //Get current option code
521  code = ntohs(oroOption->requestedOption[i]);
522  //Find the name associated with this option code
523  label = (code < arraysize(optionLabel)) ? optionLabel[code] : "Unknown";
524  //Display option code and option name
525  TRACE_DEBUG("%s%" PRIu16 " (%s option)\r\n", prefix[level + 1], code, label);
526  }
527 
528  //No error to report
529  return NO_ERROR;
530 }
531 
532 
533 /**
534  * @brief Dump Preference option
535  * @param[in] option Pointer to the option to dump
536  * @param[in] level Current level of recursion
537  * @return Error code
538  **/
539 
541 {
542  Dhcpv6PreferenceOption *preferenceOption;
543 
544  //Check the length of the option
545  if(ntohs(option->length) != sizeof(Dhcpv6PreferenceOption))
546  return ERROR_INVALID_OPTION;
547 
548  //Point to the option contents
549  preferenceOption = (Dhcpv6PreferenceOption *) option->value;
550 
551  //Dump contents
552  TRACE_DEBUG("%sPreference option (%" PRIu16 " bytes)\r\n", prefix[level], ntohs(option->length));
553  TRACE_DEBUG("%s%" PRIu8 "\r\n", prefix[level + 1], preferenceOption->value);
554 
555  //No error to report
556  return NO_ERROR;
557 }
558 
559 
560 /**
561  * @brief Dump Elapsed Time option
562  * @param[in] option Pointer to the option to dump
563  * @param[in] level Current level of recursion
564  * @return Error code
565  **/
566 
568 {
569  uint32_t value;
570  Dhcpv6ElapsedTimeOption *elapsedTimeOption;
571 
572  //Check the length of the option
573  if(ntohs(option->length) != sizeof(Dhcpv6ElapsedTimeOption))
574  return ERROR_INVALID_OPTION;
575 
576  //Point to the option contents
577  elapsedTimeOption = (Dhcpv6ElapsedTimeOption *) option->value;
578  //Convert the value to milliseconds
579  value = ntohs(elapsedTimeOption->value) * 10;
580 
581  //Dump contents
582  TRACE_DEBUG("%sElapsed Time option (%" PRIu16 " bytes)\r\n", prefix[level], ntohs(option->length));
583  TRACE_DEBUG("%s%" PRIu32 "ms\r\n", prefix[level + 1], value);
584 
585  //No error to report
586  return NO_ERROR;
587 }
588 
589 
590 /**
591  * @brief Dump Relay Message option
592  * @param[in] option Pointer to the option to dump
593  * @param[in] level Current level of recursion
594  * @return Error code
595  **/
596 
598 {
599  uint8_t type;
600  const char_t *label;
601 
602  //Check the length of the option
603  if(!ntohs(option->length))
604  return ERROR_INVALID_OPTION;
605 
606  //Retrieve the message type
607  type = option->value[0];
608  //Get the corresponding label
609  label = (type < arraysize(messageLabel)) ? messageLabel[type] : "Unknown";
610 
611  //Relay agent/server message?
613  {
614  //Get the inner message
615  const Dhcpv6RelayMessage *message = (Dhcpv6RelayMessage *) option->value;
616 
617  //Ensure the length of the DHCPv6 message is acceptable
618  if(ntohs(option->length) < sizeof(Dhcpv6RelayMessage))
619  return ERROR_INVALID_OPTION;
620 
621  //Dump message header
622  TRACE_DEBUG("%sRelay Message option (%" PRIu16 " bytes)\r\n", prefix[level], ntohs(option->length));
623  TRACE_DEBUG("%sMessage Type = %" PRIu8 " (%s)\r\n", prefix[level + 1], message->msgType, label);
624  TRACE_DEBUG("%sHop Count = %" PRIu8 "\r\n", prefix[level + 1], message->hopCount);
625  TRACE_DEBUG("%sLink Address = %s\r\n", prefix[level + 1], ipv6AddrToString(&message->linkAddress, NULL));
626  TRACE_DEBUG("%sPeer Address = %s\r\n", prefix[level + 1], ipv6AddrToString(&message->peerAddress, NULL));
627 
628  //Dump message options
629  return dhcpv6DumpOptions(message->options, ntohs(option->length) - sizeof(Dhcpv6RelayMessage), level + 1);
630  }
631  //Client/server message?
632  else
633  {
634  //Get the inner message
635  const Dhcpv6Message *message = (Dhcpv6Message *) option->value;
636 
637  //Ensure the length of the DHCPv6 message is acceptable
638  if(ntohs(option->length) < sizeof(Dhcpv6Message))
639  return ERROR_INVALID_OPTION;
640 
641  //Dump message header
642  TRACE_DEBUG("%sRelay Message option (%" PRIu16 " bytes)\r\n", prefix[level], ntohs(option->length));
643  TRACE_DEBUG("%sMessage Type = %" PRIu8 " (%s)\r\n", prefix[level + 1], message->msgType, label);
644  TRACE_DEBUG("%sTransaction ID = 0x%06" PRIX32 "\r\n", prefix[level + 1], LOAD24BE(message->transactionId));
645 
646  //Dump message options
647  return dhcpv6DumpOptions(message->options, ntohs(option->length) - sizeof(Dhcpv6Message), level + 1);
648  }
649 }
650 
651 
652 /**
653  * @brief Dump Authentication option
654  * @param[in] option Pointer to the option to dump
655  * @param[in] level Current level of recursion
656  * @return Error code
657  **/
658 
660 {
661  size_t n;
662  Dhcpv6AuthOption *authOption;
663 
664  //Check the length of the option
665  if(ntohs(option->length) < sizeof(Dhcpv6AuthOption))
666  return ERROR_INVALID_OPTION;
667 
668  //Point to the option contents
669  authOption = (Dhcpv6AuthOption *) option->value;
670  //Get the length of the authentication information
671  n = ntohs(option->length) - sizeof(Dhcpv6AuthOption);
672 
673  //Dump contents
674  TRACE_DEBUG("%sAuthentication option (%" PRIu16 " bytes)\r\n", prefix[level], ntohs(option->length));
675  TRACE_DEBUG("%sProtocol = %" PRIu8 "\r\n", prefix[level + 1], authOption->protocol);
676  TRACE_DEBUG("%sAlgorithm = %" PRIu8 "\r\n", prefix[level + 1], authOption->algorithm);
677  TRACE_DEBUG("%sRDM = %" PRIu8 "\r\n", prefix[level + 1], authOption->rdm);
678  TRACE_DEBUG("%sReplay Detection\r\n", prefix[level + 1]);
679  TRACE_DEBUG_ARRAY(prefix[level + 2], authOption->replayDetection, 8);
680  TRACE_DEBUG("%sAuthentication Information (%" PRIuSIZE " bytes)\r\n", prefix[level + 1], n);
681  TRACE_DEBUG_ARRAY(prefix[level + 2], authOption->authInfo, n);
682 
683  //No error to report
684  return NO_ERROR;
685 }
686 
687 
688 /**
689  * @brief Dump Server Unicast option
690  * @param[in] option Pointer to the option to dump
691  * @param[in] level Current level of recursion
692  * @return Error code
693  **/
694 
696 {
697  Dhcpv6ServerUnicastOption *serverUnicastOption;
698 
699  //Check the length of the option
700  if(ntohs(option->length) != sizeof(Dhcpv6ServerUnicastOption))
701  return ERROR_INVALID_OPTION;
702 
703  //Point to the option contents
704  serverUnicastOption = (Dhcpv6ServerUnicastOption *) option->value;
705 
706  //Dump contents
707  TRACE_DEBUG("%sServer Unicast option (%" PRIu16 " bytes)\r\n", prefix[level], ntohs(option->length));
708  TRACE_DEBUG("%s%s\r\n", prefix[level + 1], ipv6AddrToString(&serverUnicastOption->serverAddr, NULL));
709 
710  //No error to report
711  return NO_ERROR;
712 }
713 
714 
715 /**
716  * @brief Dump Status Code option
717  * @param[in] option Pointer to the option to dump
718  * @param[in] level Current level of recursion
719  * @return Error code
720  **/
721 
723 {
724  uint16_t code;
725  const char_t *label;
726  Dhcpv6StatusCodeOption *statusCodeOption;
727 
728  //Check the length of the option
729  if(ntohs(option->length) < sizeof(Dhcpv6StatusCodeOption))
730  return ERROR_INVALID_OPTION;
731 
732  //Point to the option contents
733  statusCodeOption = (Dhcpv6StatusCodeOption *) option->value;
734  //Get the status code
735  code = ntohs(statusCodeOption->statusCode);
736  //Get the label associated with the status code
737  label = (code < arraysize(statusLabel)) ? statusLabel[code] : "Unknown";
738 
739  //Dump contents
740  TRACE_DEBUG("%sStatus Code option (%" PRIu16 " bytes)\r\n", prefix[level], ntohs(option->length));
741  TRACE_DEBUG("%sCode = %" PRIu16 " (%s)\r\n", prefix[level + 1], code, label);
742  TRACE_DEBUG("%sMessage = %s\r\n", prefix[level + 1], statusCodeOption->statusMessage);
743 
744  //No error to report
745  return NO_ERROR;
746 }
747 
748 
749 /**
750  * @brief Dump Rapid Commit option
751  * @param[in] option Pointer to the option to dump
752  * @param[in] level Current level of recursion
753  * @return Error code
754  **/
755 
757 {
758  //Check the length of the option
759  if(ntohs(option->length) != 0)
760  return ERROR_INVALID_OPTION;
761 
762  //Dump contents
763  TRACE_DEBUG("%sRapid Commit option (%" PRIu16 " bytes)\r\n", prefix[level], ntohs(option->length));
764 
765  //No error to report
766  return NO_ERROR;
767 }
768 
769 
770 /**
771  * @brief Dump User Class option
772  * @param[in] option Pointer to the option to dump
773  * @param[in] level Current level of recursion
774  * @return Error code
775  **/
776 
778 {
779  //Dump contents
780  TRACE_DEBUG("%sUser Class option (%" PRIu16 " bytes)\r\n", prefix[level], ntohs(option->length));
781  TRACE_DEBUG_ARRAY(prefix[level + 1], option->value, ntohs(option->length));
782 
783  //No error to report
784  return NO_ERROR;
785 }
786 
787 
788 /**
789  * @brief Dump Vendor Class option
790  * @param[in] option Pointer to the option to dump
791  * @param[in] level Current level of recursion
792  * @return Error code
793  **/
794 
796 {
797  //Dump contents
798  TRACE_DEBUG("%sVendor Class option (%" PRIu16 " bytes)\r\n", prefix[level], ntohs(option->length));
799  TRACE_DEBUG_ARRAY(prefix[level + 1], option->value, ntohs(option->length));
800 
801  //No error to report
802  return NO_ERROR;
803 }
804 
805 
806 /**
807  * @brief Dump Vendor Specific Information option
808  * @param[in] option Pointer to the option to dump
809  * @param[in] level Current level of recursion
810  * @return Error code
811  **/
812 
814 {
815  //Dump contents
816  TRACE_DEBUG("%sVendor Specific Information option (%" PRIu16 " bytes)\r\n", prefix[level], ntohs(option->length));
817  TRACE_DEBUG_ARRAY(prefix[level + 1], option->value, ntohs(option->length));
818 
819  //No error to report
820  return NO_ERROR;
821 }
822 
823 
824 /**
825  * @brief Dump Interface ID option
826  * @param[in] option Pointer to the option to dump
827  * @param[in] level Current level of recursion
828  * @return Error code
829  **/
830 
832 {
833  //Dump contents
834  TRACE_DEBUG("%sInterface ID option (%" PRIu16 " bytes)\r\n", prefix[level], ntohs(option->length));
835  TRACE_DEBUG_ARRAY(prefix[level + 1], option->value, ntohs(option->length));
836 
837  //No error to report
838  return NO_ERROR;
839 }
840 
841 
842 /**
843  * @brief Dump Reconfigure Message option
844  * @param[in] option Pointer to the option to dump
845  * @param[in] level Current level of recursion
846  * @return Error code
847  **/
848 
850 {
851  Dhcpv6ReconfMessageOption *reconfMessageOption;
852 
853  //Check the length of the option
854  if(ntohs(option->length) != sizeof(Dhcpv6ReconfMessageOption))
855  return ERROR_INVALID_OPTION;
856 
857  //Point to the option contents
858  reconfMessageOption = (Dhcpv6ReconfMessageOption *) option->value;
859 
860  //Dump contents
861  TRACE_DEBUG("%sReconfigure Message option (%" PRIu16 " bytes)\r\n", prefix[level], ntohs(option->length));
862  TRACE_DEBUG("%sMessage Type = %" PRIu8 "\r\n", prefix[level + 1], reconfMessageOption->msgType);
863 
864  //No error to report
865  return NO_ERROR;
866 }
867 
868 
869 /**
870  * @brief Dump Reconfigure Accept option
871  * @param[in] option Pointer to the option to dump
872  * @param[in] level Current level of recursion
873  * @return Error code
874  **/
875 
877 {
878  //Check the length of the option
879  if(ntohs(option->length) != 0)
880  return ERROR_INVALID_OPTION;
881 
882  //Dump contents
883  TRACE_DEBUG("%sReconfigure Accept option (%" PRIu16 " bytes)\r\n", prefix[level], ntohs(option->length));
884 
885  //No error to report
886  return NO_ERROR;
887 }
888 
889 
890 /**
891  * @brief Dump DNS Recursive Name Server option
892  * @param[in] option Pointer to the option to dump
893  * @param[in] level Current level of recursion
894  * @return Error code
895  **/
896 
898 {
899  uint_t i;
900  uint_t n;
901  Dhcpv6DnsServersOption *dnsServersOption;
902 
903  //Check the length of the option
904  if(ntohs(option->length) % sizeof(Ipv6Addr))
905  return ERROR_INVALID_OPTION;
906 
907  //Point to the option contents
908  dnsServersOption = (Dhcpv6DnsServersOption *) option->value;
909  //Calculate the number of IPv6 addresses in the list
910  n = ntohs(option->length) / sizeof(Ipv6Addr);
911 
912  //Dump contents
913  TRACE_DEBUG("%sDNS Recursive Name Server option (%" PRIu16 " bytes)\r\n", prefix[level], ntohs(option->length));
914 
915  //Diplay the DNS servers
916  for(i = 0; i < n; i++)
917  TRACE_DEBUG("%s%s\r\n", prefix[level + 1], ipv6AddrToString(dnsServersOption->address + i, NULL));
918 
919  //No error to report
920  return NO_ERROR;
921 }
922 
923 
924 /**
925  * @brief Dump Domain Search List option
926  * @param[in] option Pointer to the option to dump
927  * @param[in] level Current level of recursion
928  * @return Error code
929  **/
930 
932 {
933  //Dump contents
934  TRACE_DEBUG("%sDomain Search List option (%" PRIu16 " bytes)\r\n", prefix[level], ntohs(option->length));
935  TRACE_DEBUG_ARRAY(prefix[level + 1], option->value, ntohs(option->length));
936 
937  //No error to report
938  return NO_ERROR;
939 }
940 
941 #endif
__start_packed struct @134 Dhcpv6Option
DHCPv6 option.
error_t dhcpv6DumpAuthOption(const Dhcpv6Option *option, uint_t level)
Dump Authentication option.
Definition: dhcpv6_debug.c:659
char char_t
Definition: compiler_port.h:41
uint8_t options[]
Definition: tcp.h:318
error_t dhcpv6DumpUserClassOption(const Dhcpv6Option *option, uint_t level)
Dump User Class option.
Definition: dhcpv6_debug.c:777
error_t dhcpv6DumpReconfMessageOption(const Dhcpv6Option *option, uint_t level)
Dump Reconfigure Message option.
Definition: dhcpv6_debug.c:849
TCP/IP stack core.
error_t dhcpv6DumpRelayMessageOption(const Dhcpv6Option *option, uint_t level)
Dump Relay Message option.
Definition: dhcpv6_debug.c:597
error_t dhcpv6DumpIaTaOption(const Dhcpv6Option *option, uint_t level)
Dump IA_TA option.
Definition: dhcpv6_debug.c:435
Debugging facilities.
__start_packed struct @136 Dhcpv6IaTaOption
Identity Association for Temporary Addresses option.
error_t dhcpv6DumpClientIdOption(const Dhcpv6Option *option, uint_t level)
Dump Client Identifier option.
Definition: dhcpv6_debug.c:367
__start_packed struct @138 Dhcpv6OroOption
Option Request option.
uint8_t message[]
Definition: chap.h:150
error_t dhcpv6DumpVendorClassOption(const Dhcpv6Option *option, uint_t level)
Dump Vendor Class option.
Definition: dhcpv6_debug.c:795
error_t dhcpv6DumpDomainListOption(const Dhcpv6Option *option, uint_t level)
Dump Domain Search List option.
Definition: dhcpv6_debug.c:931
error_t dhcpv6DumpRapidCommitOption(const Dhcpv6Option *option, uint_t level)
Dump Rapid Commit option.
Definition: dhcpv6_debug.c:756
__start_packed struct @144 Dhcpv6ReconfMessageOption
Reconfigure Message option.
__start_packed struct @133 Dhcpv6RelayMessage
DHCPv6 relay agent message.
__start_packed struct @183 Ipv6Addr
IPv6 network address.
__start_packed struct @142 Dhcpv6ServerUnicastOption
Server Unicast option.
char_t type
#define TRACE_DEBUG_ARRAY(p, a, n)
Definition: debug.h:99
uint8_t level
Definition: tls.h:1696
error_t dhcpv6DumpIaNaOption(const Dhcpv6Option *option, uint_t level)
Dump IA_NA option.
Definition: dhcpv6_debug.c:403
error_t dhcpv6DumpServerIdOption(const Dhcpv6Option *option, uint_t level)
Dump Server Identifier option.
Definition: dhcpv6_debug.c:385
__start_packed struct @135 Dhcpv6IaNaOption
Identity Association for Non-temporary Addresses option.
error_t dhcpv6DumpStatusCodeOption(const Dhcpv6Option *option, uint_t level)
Dump Status Code option.
Definition: dhcpv6_debug.c:722
#define arraysize(a)
Definition: os_port.h:68
__start_packed struct @143 Dhcpv6StatusCodeOption
Status Code option.
error_t dhcpv6DumpOroOption(const Dhcpv6Option *option, uint_t level)
Dump Option Request option.
Definition: dhcpv6_debug.c:497
error_t dhcpv6DumpPreferenceOption(const Dhcpv6Option *option, uint_t level)
Dump Preference option.
Definition: dhcpv6_debug.c:540
error_t dhcpv6DumpVendorSpecificInfoOption(const Dhcpv6Option *option, uint_t level)
Dump Vendor Specific Information option.
Definition: dhcpv6_debug.c:813
#define ntohl(value)
Definition: cpu_endian.h:397
#define ntohs(value)
Definition: cpu_endian.h:396
error_t dhcpv6DumpReconfAcceptOption(const Dhcpv6Option *option, uint_t level)
Dump Reconfigure Accept option.
Definition: dhcpv6_debug.c:876
Data logging functions for debugging purpose (DHCPv6)
#define LOAD24BE(p)
Definition: cpu_endian.h:179
error_t dhcpv6DumpElapsedTimeOption(const Dhcpv6Option *option, uint_t level)
Dump Elapsed Time option.
Definition: dhcpv6_debug.c:567
error_t dhcpv6DumpDnsServersOption(const Dhcpv6Option *option, uint_t level)
Dump DNS Recursive Name Server option.
Definition: dhcpv6_debug.c:897
Success.
Definition: error.h:42
Ipv6Addr prefix
error_t
Error codes.
Definition: error.h:40
#define TRACE_WARNING(...)
Definition: debug.h:78
error_t dhcpv6DumpOptions(const uint8_t *options, size_t length, uint_t level)
Dump DHCPv6 options for debugging purpose.
Definition: dhcpv6_debug.c:206
uint8_t code
Definition: coap_common.h:179
__start_packed struct @140 Dhcpv6ElapsedTimeOption
Elapsed Time option.
unsigned int uint_t
Definition: compiler_port.h:43
#define PRIuSIZE
Definition: compiler_port.h:72
__start_packed struct @141 Dhcpv6AuthOption
Authentication option.
uint8_t value[]
Definition: dtls_misc.h:141
error_t dhcpv6DumpMessage(const void *message, size_t length)
Dump DHCPv6 message for debugging purpose.
Definition: dhcpv6_debug.c:121
__start_packed struct @145 Dhcpv6DnsServersOption
DNS Recursive Name Server option.
error_t dhcpv6DumpServerUnicastOption(const Dhcpv6Option *option, uint_t level)
Dump Server Unicast option.
Definition: dhcpv6_debug.c:695
char_t * ipv6AddrToString(const Ipv6Addr *ipAddr, char_t *str)
Convert a binary IPv6 address to a string representation.
Definition: ipv6.c:2298
error_t dhcpv6DumpGenericOption(const Dhcpv6Option *option, uint_t level)
Dump generic DHCPv6 option.
Definition: dhcpv6_debug.c:349
error_t dhcpv6DumpIaAddrOption(const Dhcpv6Option *option, uint_t level)
Dump IA Address option.
Definition: dhcpv6_debug.c:465
uint8_t length
Definition: dtls_misc.h:140
uint8_t n
__start_packed struct @139 Dhcpv6PreferenceOption
Preference option.
__start_packed struct @132 Dhcpv6Message
DHCPv6 message.
error_t dhcpv6DumpInterfaceIdOption(const Dhcpv6Option *option, uint_t level)
Dump Interface ID option.
Definition: dhcpv6_debug.c:831
__start_packed struct @137 Dhcpv6IaAddrOption
IA Address option.
#define TRACE_DEBUG(...)
Definition: debug.h:98