print-msdp.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Copyright (c) 2001 William C. Fenner.
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that: (1) source code
  7. * distributions retain the above copyright notice and this paragraph
  8. * in its entirety, and (2) distributions including binary code include
  9. * the above copyright notice and this paragraph in its entirety in
  10. * the documentation or other materials provided with the distribution.
  11. * The name of William C. Fenner may not be used to endorse or
  12. * promote products derived from this software without specific prior
  13. * written permission. THIS SOFTWARE IS PROVIDED ``AS IS'' AND
  14. * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
  15. * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  16. * FOR A PARTICULAR PURPOSE.
  17. */
  18. /* \summary: Multicast Source Discovery Protocol (MSDP) printer */
  19. #ifdef HAVE_CONFIG_H
  20. #include "config.h"
  21. #endif
  22. #include <netdissect-stdinc.h>
  23. #include "netdissect.h"
  24. #include "addrtoname.h"
  25. #include "extract.h"
  26. #define MSDP_TYPE_MAX 7
  27. void
  28. msdp_print(netdissect_options *ndo, const u_char *sp, u_int length)
  29. {
  30. unsigned int type, len;
  31. ND_TCHECK2(*sp, 3);
  32. /* See if we think we're at the beginning of a compound packet */
  33. type = *sp;
  34. len = EXTRACT_16BITS(sp + 1);
  35. if (len > 1500 || len < 3 || type == 0 || type > MSDP_TYPE_MAX)
  36. goto trunc; /* not really truncated, but still not decodable */
  37. ND_PRINT((ndo, " msdp:"));
  38. while (length > 0) {
  39. ND_TCHECK2(*sp, 3);
  40. type = *sp;
  41. len = EXTRACT_16BITS(sp + 1);
  42. if (len > 1400 || ndo->ndo_vflag)
  43. ND_PRINT((ndo, " [len %u]", len));
  44. if (len < 3)
  45. goto trunc;
  46. sp += 3;
  47. length -= 3;
  48. switch (type) {
  49. case 1: /* IPv4 Source-Active */
  50. case 3: /* IPv4 Source-Active Response */
  51. if (type == 1)
  52. ND_PRINT((ndo, " SA"));
  53. else
  54. ND_PRINT((ndo, " SA-Response"));
  55. ND_TCHECK(*sp);
  56. ND_PRINT((ndo, " %u entries", *sp));
  57. if ((u_int)((*sp * 12) + 8) < len) {
  58. ND_PRINT((ndo, " [w/data]"));
  59. if (ndo->ndo_vflag > 1) {
  60. ND_PRINT((ndo, " "));
  61. ip_print(ndo, sp + *sp * 12 + 8 - 3,
  62. len - (*sp * 12 + 8));
  63. }
  64. }
  65. break;
  66. case 2:
  67. ND_PRINT((ndo, " SA-Request"));
  68. ND_TCHECK2(*sp, 5);
  69. ND_PRINT((ndo, " for %s", ipaddr_string(ndo, sp + 1)));
  70. break;
  71. case 4:
  72. ND_PRINT((ndo, " Keepalive"));
  73. if (len != 3)
  74. ND_PRINT((ndo, "[len=%d] ", len));
  75. break;
  76. case 5:
  77. ND_PRINT((ndo, " Notification"));
  78. break;
  79. default:
  80. ND_PRINT((ndo, " [type=%d len=%d]", type, len));
  81. break;
  82. }
  83. sp += (len - 3);
  84. length -= (len - 3);
  85. }
  86. return;
  87. trunc:
  88. ND_PRINT((ndo, " [|msdp]"));
  89. }
  90. /*
  91. * Local Variables:
  92. * c-style: whitesmith
  93. * c-basic-offset: 8
  94. * End:
  95. */