print-dtp.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * Copyright (c) 1998-2007 The TCPDUMP project
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that: (1) source code
  6. * distributions retain the above copyright notice and this paragraph
  7. * in its entirety, and (2) distributions including binary code include
  8. * the above copyright notice and this paragraph in its entirety in
  9. * the documentation or other materials provided with the distribution.
  10. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND
  11. * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
  12. * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  13. * FOR A PARTICULAR PURPOSE.
  14. *
  15. * Original code by Carles Kishimoto <carles.kishimoto@gmail.com>
  16. */
  17. /* \summary: Dynamic Trunking Protocol (DTP) printer */
  18. #ifdef HAVE_CONFIG_H
  19. #include "config.h"
  20. #endif
  21. #include <netdissect-stdinc.h>
  22. #include "netdissect.h"
  23. #include "addrtoname.h"
  24. #include "extract.h"
  25. static const char tstr[] = " [|dtp]";
  26. #define DTP_HEADER_LEN 1
  27. #define DTP_DOMAIN_TLV 0x0001
  28. #define DTP_STATUS_TLV 0x0002
  29. #define DTP_DTP_TYPE_TLV 0x0003
  30. #define DTP_NEIGHBOR_TLV 0x0004
  31. static const struct tok dtp_tlv_values[] = {
  32. { DTP_DOMAIN_TLV, "Domain TLV"},
  33. { DTP_STATUS_TLV, "Status TLV"},
  34. { DTP_DTP_TYPE_TLV, "DTP type TLV"},
  35. { DTP_NEIGHBOR_TLV, "Neighbor TLV"},
  36. { 0, NULL}
  37. };
  38. void
  39. dtp_print (netdissect_options *ndo, const u_char *pptr, u_int length)
  40. {
  41. int type, len;
  42. const u_char *tptr;
  43. if (length < DTP_HEADER_LEN)
  44. goto trunc;
  45. tptr = pptr;
  46. ND_TCHECK2(*tptr, DTP_HEADER_LEN);
  47. ND_PRINT((ndo, "DTPv%u, length %u",
  48. (*tptr),
  49. length));
  50. /*
  51. * In non-verbose mode, just print version.
  52. */
  53. if (ndo->ndo_vflag < 1) {
  54. return;
  55. }
  56. tptr += DTP_HEADER_LEN;
  57. while (tptr < (pptr+length)) {
  58. ND_TCHECK2(*tptr, 4);
  59. type = EXTRACT_16BITS(tptr);
  60. len = EXTRACT_16BITS(tptr+2);
  61. /* XXX: should not be but sometimes it is, see the test captures */
  62. if (type == 0)
  63. return;
  64. ND_PRINT((ndo, "\n\t%s (0x%04x) TLV, length %u",
  65. tok2str(dtp_tlv_values, "Unknown", type),
  66. type, len));
  67. /* infinite loop check */
  68. if (len < 4)
  69. goto invalid;
  70. ND_TCHECK2(*tptr, len);
  71. switch (type) {
  72. case DTP_DOMAIN_TLV:
  73. ND_PRINT((ndo, ", "));
  74. fn_printzp(ndo, tptr+4, len-4, pptr+length);
  75. break;
  76. case DTP_STATUS_TLV:
  77. case DTP_DTP_TYPE_TLV:
  78. if (len < 5)
  79. goto invalid;
  80. ND_PRINT((ndo, ", 0x%x", *(tptr+4)));
  81. break;
  82. case DTP_NEIGHBOR_TLV:
  83. if (len < 10)
  84. goto invalid;
  85. ND_PRINT((ndo, ", %s", etheraddr_string(ndo, tptr+4)));
  86. break;
  87. default:
  88. break;
  89. }
  90. tptr += len;
  91. }
  92. return;
  93. invalid:
  94. ND_PRINT((ndo, "%s", istr));
  95. return;
  96. trunc:
  97. ND_PRINT((ndo, "%s", tstr));
  98. }
  99. /*
  100. * Local Variables:
  101. * c-style: whitesmith
  102. * c-basic-offset: 4
  103. * End:
  104. */