print-igrp.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * Copyright (c) 1996, 1997
  3. * The Regents of the University of California. 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 distributions
  7. * retain the above copyright notice and this paragraph in its entirety, (2)
  8. * distributions including binary code include the above copyright notice and
  9. * this paragraph in its entirety in the documentation or other materials
  10. * provided with the distribution, and (3) all advertising materials mentioning
  11. * features or use of this software display the following acknowledgement:
  12. * ``This product includes software developed by the University of California,
  13. * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
  14. * the University nor the names of its contributors may be used to endorse
  15. * or promote products derived from this software without specific prior
  16. * written permission.
  17. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  18. * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  19. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  20. *
  21. * Initial contribution from Francis Dupont (francis.dupont@inria.fr)
  22. */
  23. /* \summary: Interior Gateway Routing Protocol (IGRP) printer */
  24. #ifdef HAVE_CONFIG_H
  25. #include "config.h"
  26. #endif
  27. #include <netdissect-stdinc.h>
  28. #include "netdissect.h"
  29. #include "extract.h"
  30. /* Cisco IGRP definitions */
  31. /* IGRP Header */
  32. struct igrphdr {
  33. uint8_t ig_vop; /* protocol version number / opcode */
  34. #define IGRP_V(x) (((x) & 0xf0) >> 4)
  35. #define IGRP_OP(x) ((x) & 0x0f)
  36. uint8_t ig_ed; /* edition number */
  37. uint16_t ig_as; /* autonomous system number */
  38. uint16_t ig_ni; /* number of subnet in local net */
  39. uint16_t ig_ns; /* number of networks in AS */
  40. uint16_t ig_nx; /* number of networks ouside AS */
  41. uint16_t ig_sum; /* checksum of IGRP header & data */
  42. };
  43. #define IGRP_UPDATE 1
  44. #define IGRP_REQUEST 2
  45. /* IGRP routing entry */
  46. struct igrprte {
  47. uint8_t igr_net[3]; /* 3 significant octets of IP address */
  48. uint8_t igr_dly[3]; /* delay in tens of microseconds */
  49. uint8_t igr_bw[3]; /* bandwidth in units of 1 kb/s */
  50. uint8_t igr_mtu[2]; /* MTU in octets */
  51. uint8_t igr_rel; /* percent packets successfully tx/rx */
  52. uint8_t igr_ld; /* percent of channel occupied */
  53. uint8_t igr_hct; /* hop count */
  54. };
  55. #define IGRP_RTE_SIZE 14 /* don't believe sizeof ! */
  56. static void
  57. igrp_entry_print(netdissect_options *ndo, register const struct igrprte *igr,
  58. register int is_interior, register int is_exterior)
  59. {
  60. register u_int delay, bandwidth;
  61. u_int metric, mtu;
  62. if (is_interior)
  63. ND_PRINT((ndo, " *.%d.%d.%d", igr->igr_net[0],
  64. igr->igr_net[1], igr->igr_net[2]));
  65. else if (is_exterior)
  66. ND_PRINT((ndo, " X%d.%d.%d.0", igr->igr_net[0],
  67. igr->igr_net[1], igr->igr_net[2]));
  68. else
  69. ND_PRINT((ndo, " %d.%d.%d.0", igr->igr_net[0],
  70. igr->igr_net[1], igr->igr_net[2]));
  71. delay = EXTRACT_24BITS(igr->igr_dly);
  72. bandwidth = EXTRACT_24BITS(igr->igr_bw);
  73. metric = bandwidth + delay;
  74. if (metric > 0xffffff)
  75. metric = 0xffffff;
  76. mtu = EXTRACT_16BITS(igr->igr_mtu);
  77. ND_PRINT((ndo, " d=%d b=%d r=%d l=%d M=%d mtu=%d in %d hops",
  78. 10 * delay, bandwidth == 0 ? 0 : 10000000 / bandwidth,
  79. igr->igr_rel, igr->igr_ld, metric,
  80. mtu, igr->igr_hct));
  81. }
  82. static const struct tok op2str[] = {
  83. { IGRP_UPDATE, "update" },
  84. { IGRP_REQUEST, "request" },
  85. { 0, NULL }
  86. };
  87. void
  88. igrp_print(netdissect_options *ndo, register const u_char *bp, u_int length)
  89. {
  90. register const struct igrphdr *hdr;
  91. register const u_char *cp;
  92. u_int nint, nsys, next;
  93. hdr = (const struct igrphdr *)bp;
  94. cp = (const u_char *)(hdr + 1);
  95. ND_PRINT((ndo, "igrp:"));
  96. /* Header */
  97. ND_TCHECK(*hdr);
  98. nint = EXTRACT_16BITS(&hdr->ig_ni);
  99. nsys = EXTRACT_16BITS(&hdr->ig_ns);
  100. next = EXTRACT_16BITS(&hdr->ig_nx);
  101. ND_PRINT((ndo, " %s V%d edit=%d AS=%d (%d/%d/%d)",
  102. tok2str(op2str, "op-#%d", IGRP_OP(hdr->ig_vop)),
  103. IGRP_V(hdr->ig_vop),
  104. hdr->ig_ed,
  105. EXTRACT_16BITS(&hdr->ig_as),
  106. nint,
  107. nsys,
  108. next));
  109. length -= sizeof(*hdr);
  110. while (length >= IGRP_RTE_SIZE) {
  111. if (nint > 0) {
  112. ND_TCHECK2(*cp, IGRP_RTE_SIZE);
  113. igrp_entry_print(ndo, (const struct igrprte *)cp, 1, 0);
  114. --nint;
  115. } else if (nsys > 0) {
  116. ND_TCHECK2(*cp, IGRP_RTE_SIZE);
  117. igrp_entry_print(ndo, (const struct igrprte *)cp, 0, 0);
  118. --nsys;
  119. } else if (next > 0) {
  120. ND_TCHECK2(*cp, IGRP_RTE_SIZE);
  121. igrp_entry_print(ndo, (const struct igrprte *)cp, 0, 1);
  122. --next;
  123. } else {
  124. ND_PRINT((ndo, " [extra bytes %d]", length));
  125. break;
  126. }
  127. cp += IGRP_RTE_SIZE;
  128. length -= IGRP_RTE_SIZE;
  129. }
  130. if (nint == 0 && nsys == 0 && next == 0)
  131. return;
  132. trunc:
  133. ND_PRINT((ndo, " [|igrp]"));
  134. }