print-stp.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  1. /*
  2. * Copyright (c) 2000 Lennert Buytenhek
  3. *
  4. * This software may be distributed either under the terms of the
  5. * BSD-style license that accompanies tcpdump or the GNU General
  6. * Public License
  7. *
  8. * Contributed by Lennert Buytenhek <buytenh@gnu.org>
  9. */
  10. /* \summary: IEEE 802.1d Spanning Tree Protocol (STP) printer */
  11. #ifdef HAVE_CONFIG_H
  12. #include "config.h"
  13. #endif
  14. #include <netdissect-stdinc.h>
  15. #include <stdio.h>
  16. #include "netdissect.h"
  17. #include "extract.h"
  18. #define RSTP_EXTRACT_PORT_ROLE(x) (((x)&0x0C)>>2)
  19. /* STP timers are expressed in multiples of 1/256th second */
  20. #define STP_TIME_BASE 256
  21. #define STP_BPDU_MSTP_MIN_LEN 102
  22. struct stp_bpdu_ {
  23. uint8_t protocol_id[2];
  24. uint8_t protocol_version;
  25. uint8_t bpdu_type;
  26. uint8_t flags;
  27. uint8_t root_id[8];
  28. uint8_t root_path_cost[4];
  29. uint8_t bridge_id[8];
  30. uint8_t port_id[2];
  31. uint8_t message_age[2];
  32. uint8_t max_age[2];
  33. uint8_t hello_time[2];
  34. uint8_t forward_delay[2];
  35. uint8_t v1_length;
  36. };
  37. #define STP_PROTO_REGULAR 0x00
  38. #define STP_PROTO_RAPID 0x02
  39. #define STP_PROTO_MSTP 0x03
  40. #define STP_PROTO_SPB 0x04
  41. static const struct tok stp_proto_values[] = {
  42. { STP_PROTO_REGULAR, "802.1d" },
  43. { STP_PROTO_RAPID, "802.1w" },
  44. { STP_PROTO_MSTP, "802.1s" },
  45. { STP_PROTO_SPB, "802.1aq" },
  46. { 0, NULL}
  47. };
  48. #define STP_BPDU_TYPE_CONFIG 0x00
  49. #define STP_BPDU_TYPE_RSTP 0x02
  50. #define STP_BPDU_TYPE_TOPO_CHANGE 0x80
  51. static const struct tok stp_bpdu_flag_values[] = {
  52. { 0x01, "Topology change" },
  53. { 0x02, "Proposal" },
  54. { 0x10, "Learn" },
  55. { 0x20, "Forward" },
  56. { 0x40, "Agreement" },
  57. { 0x80, "Topology change ACK" },
  58. { 0, NULL}
  59. };
  60. static const struct tok stp_bpdu_type_values[] = {
  61. { STP_BPDU_TYPE_CONFIG, "Config" },
  62. { STP_BPDU_TYPE_RSTP, "Rapid STP" },
  63. { STP_BPDU_TYPE_TOPO_CHANGE, "Topology Change" },
  64. { 0, NULL}
  65. };
  66. static const struct tok rstp_obj_port_role_values[] = {
  67. { 0x00, "Unknown" },
  68. { 0x01, "Alternate" },
  69. { 0x02, "Root" },
  70. { 0x03, "Designated" },
  71. { 0, NULL}
  72. };
  73. #define ND_TCHECK_BRIDGE_ID(p) ND_TCHECK2(*(p), 8)
  74. static char *
  75. stp_print_bridge_id(const u_char *p)
  76. {
  77. static char bridge_id_str[sizeof("pppp.aa:bb:cc:dd:ee:ff")];
  78. snprintf(bridge_id_str, sizeof(bridge_id_str),
  79. "%.2x%.2x.%.2x:%.2x:%.2x:%.2x:%.2x:%.2x",
  80. p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]);
  81. return bridge_id_str;
  82. }
  83. static int
  84. stp_print_config_bpdu(netdissect_options *ndo, const struct stp_bpdu_ *stp_bpdu,
  85. u_int length)
  86. {
  87. ND_TCHECK(stp_bpdu->flags);
  88. ND_PRINT((ndo, ", Flags [%s]",
  89. bittok2str(stp_bpdu_flag_values, "none", stp_bpdu->flags)));
  90. ND_TCHECK(stp_bpdu->port_id);
  91. ND_PRINT((ndo, ", bridge-id %s.%04x, length %u",
  92. stp_print_bridge_id((const u_char *)&stp_bpdu->bridge_id),
  93. EXTRACT_16BITS(&stp_bpdu->port_id), length));
  94. /* in non-verbose mode just print the bridge-id */
  95. if (!ndo->ndo_vflag) {
  96. return 1;
  97. }
  98. ND_TCHECK(stp_bpdu->forward_delay);
  99. ND_PRINT((ndo, "\n\tmessage-age %.2fs, max-age %.2fs"
  100. ", hello-time %.2fs, forwarding-delay %.2fs",
  101. (float)EXTRACT_16BITS(&stp_bpdu->message_age) / STP_TIME_BASE,
  102. (float)EXTRACT_16BITS(&stp_bpdu->max_age) / STP_TIME_BASE,
  103. (float)EXTRACT_16BITS(&stp_bpdu->hello_time) / STP_TIME_BASE,
  104. (float)EXTRACT_16BITS(&stp_bpdu->forward_delay) / STP_TIME_BASE));
  105. ND_PRINT((ndo, "\n\troot-id %s, root-pathcost %u",
  106. stp_print_bridge_id((const u_char *)&stp_bpdu->root_id),
  107. EXTRACT_32BITS(&stp_bpdu->root_path_cost)));
  108. /* Port role is only valid for 802.1w */
  109. if (stp_bpdu->protocol_version == STP_PROTO_RAPID) {
  110. ND_PRINT((ndo, ", port-role %s",
  111. tok2str(rstp_obj_port_role_values, "Unknown",
  112. RSTP_EXTRACT_PORT_ROLE(stp_bpdu->flags))));
  113. }
  114. return 1;
  115. trunc:
  116. return 0;
  117. }
  118. /*
  119. * MSTP packet format
  120. * Ref. IEEE 802.1Q 2003 Ed. Section 14
  121. *
  122. * MSTP BPDU
  123. *
  124. * 2 - bytes Protocol Id
  125. * 1 - byte Protocol Ver.
  126. * 1 - byte BPDU tye
  127. * 1 - byte Flags
  128. * 8 - bytes CIST Root Identifier
  129. * 4 - bytes CIST External Path Cost
  130. * 8 - bytes CIST Regional Root Identifier
  131. * 2 - bytes CIST Port Identifier
  132. * 2 - bytes Message Age
  133. * 2 - bytes Max age
  134. * 2 - bytes Hello Time
  135. * 2 - bytes Forward delay
  136. * 1 - byte Version 1 length. Must be 0
  137. * 2 - bytes Version 3 length
  138. * 1 - byte Config Identifier
  139. * 32 - bytes Config Name
  140. * 2 - bytes Revision level
  141. * 16 - bytes Config Digest [MD5]
  142. * 4 - bytes CIST Internal Root Path Cost
  143. * 8 - bytes CIST Bridge Identifier
  144. * 1 - byte CIST Remaining Hops
  145. * 16 - bytes MSTI information [Max 64 MSTI, each 16 bytes]
  146. *
  147. *
  148. * SPB BPDU
  149. * Ref. IEEE 802.1aq. Section 14
  150. *
  151. * 2 - bytes Version 4 length
  152. * 1 - byte Aux Config Identifier
  153. * 32 - bytes Aux Config Name
  154. * 2 - bytes Aux Revision level
  155. * 16 - bytes Aux Config Digest [MD5]
  156. * 1 - byte (1 - 2) Agreement Number
  157. * (3 - 4) Discarded Agreement Number
  158. * (5) Agreement Valid Flag
  159. * (6) Restricted Role Flag
  160. * (7 - 8) Unused sent zero
  161. * 1 - byte Unused
  162. * 1 - byte (1 - 4) Agreement Digest Format Identifier
  163. * (5 - 8) Agreement Digest Format Capabilities
  164. * 1 - byte (1 - 4) Agreement Digest Convention Identifier
  165. * (5 - 8) Agreement Digest Convention Capabilities
  166. * 2 - bytes Agreement Digest Edge Count
  167. * 8 - byte Reserved Set
  168. * 20 - bytes Computed Topology Digest
  169. *
  170. *
  171. * MSTI Payload
  172. *
  173. * 1 - byte MSTI flag
  174. * 8 - bytes MSTI Regional Root Identifier
  175. * 4 - bytes MSTI Regional Path Cost
  176. * 1 - byte MSTI Bridge Priority
  177. * 1 - byte MSTI Port Priority
  178. * 1 - byte MSTI Remaining Hops
  179. *
  180. */
  181. #define MST_BPDU_MSTI_LENGTH 16
  182. #define MST_BPDU_CONFIG_INFO_LENGTH 64
  183. /* Offsets of fields from the begginning for the packet */
  184. #define MST_BPDU_VER3_LEN_OFFSET 36
  185. #define MST_BPDU_CONFIG_NAME_OFFSET 39
  186. #define MST_BPDU_CONFIG_DIGEST_OFFSET 73
  187. #define MST_BPDU_CIST_INT_PATH_COST_OFFSET 89
  188. #define MST_BPDU_CIST_BRIDGE_ID_OFFSET 93
  189. #define MST_BPDU_CIST_REMAIN_HOPS_OFFSET 101
  190. #define MST_BPDU_MSTI_OFFSET 102
  191. /* Offsets within an MSTI */
  192. #define MST_BPDU_MSTI_ROOT_PRIO_OFFSET 1
  193. #define MST_BPDU_MSTI_ROOT_PATH_COST_OFFSET 9
  194. #define MST_BPDU_MSTI_BRIDGE_PRIO_OFFSET 13
  195. #define MST_BPDU_MSTI_PORT_PRIO_OFFSET 14
  196. #define MST_BPDU_MSTI_REMAIN_HOPS_OFFSET 15
  197. #define SPB_BPDU_MIN_LEN 87
  198. #define SPB_BPDU_CONFIG_NAME_OFFSET 3
  199. #define SPB_BPDU_CONFIG_REV_OFFSET SPB_BPDU_CONFIG_NAME_OFFSET + 32
  200. #define SPB_BPDU_CONFIG_DIGEST_OFFSET SPB_BPDU_CONFIG_REV_OFFSET + 2
  201. #define SPB_BPDU_AGREEMENT_OFFSET SPB_BPDU_CONFIG_DIGEST_OFFSET + 16
  202. #define SPB_BPDU_AGREEMENT_UNUSED_OFFSET SPB_BPDU_AGREEMENT_OFFSET + 1
  203. #define SPB_BPDU_AGREEMENT_FORMAT_OFFSET SPB_BPDU_AGREEMENT_UNUSED_OFFSET + 1
  204. #define SPB_BPDU_AGREEMENT_CON_OFFSET SPB_BPDU_AGREEMENT_FORMAT_OFFSET + 1
  205. #define SPB_BPDU_AGREEMENT_EDGE_OFFSET SPB_BPDU_AGREEMENT_CON_OFFSET + 1
  206. #define SPB_BPDU_AGREEMENT_RES1_OFFSET SPB_BPDU_AGREEMENT_EDGE_OFFSET + 2
  207. #define SPB_BPDU_AGREEMENT_RES2_OFFSET SPB_BPDU_AGREEMENT_RES1_OFFSET + 4
  208. #define SPB_BPDU_AGREEMENT_DIGEST_OFFSET SPB_BPDU_AGREEMENT_RES2_OFFSET + 4
  209. static int
  210. stp_print_mstp_bpdu(netdissect_options *ndo, const struct stp_bpdu_ *stp_bpdu,
  211. u_int length)
  212. {
  213. const u_char *ptr;
  214. uint16_t v3len;
  215. uint16_t len;
  216. uint16_t msti;
  217. u_int offset;
  218. ptr = (const u_char *)stp_bpdu;
  219. ND_PRINT((ndo, ", CIST Flags [%s], length %u",
  220. bittok2str(stp_bpdu_flag_values, "none", stp_bpdu->flags), length));
  221. /*
  222. * in non-verbose mode just print the flags.
  223. */
  224. if (!ndo->ndo_vflag) {
  225. return 1;
  226. }
  227. ND_TCHECK(stp_bpdu->flags);
  228. ND_PRINT((ndo, "\n\tport-role %s, ",
  229. tok2str(rstp_obj_port_role_values, "Unknown",
  230. RSTP_EXTRACT_PORT_ROLE(stp_bpdu->flags))));
  231. ND_TCHECK(stp_bpdu->root_path_cost);
  232. ND_PRINT((ndo, "CIST root-id %s, CIST ext-pathcost %u",
  233. stp_print_bridge_id((const u_char *)&stp_bpdu->root_id),
  234. EXTRACT_32BITS(&stp_bpdu->root_path_cost)));
  235. ND_TCHECK(stp_bpdu->bridge_id);
  236. ND_PRINT((ndo, "\n\tCIST regional-root-id %s, ",
  237. stp_print_bridge_id((const u_char *)&stp_bpdu->bridge_id)));
  238. ND_TCHECK(stp_bpdu->port_id);
  239. ND_PRINT((ndo, "CIST port-id %04x,", EXTRACT_16BITS(&stp_bpdu->port_id)));
  240. ND_TCHECK(stp_bpdu->forward_delay);
  241. ND_PRINT((ndo, "\n\tmessage-age %.2fs, max-age %.2fs"
  242. ", hello-time %.2fs, forwarding-delay %.2fs",
  243. (float)EXTRACT_16BITS(&stp_bpdu->message_age) / STP_TIME_BASE,
  244. (float)EXTRACT_16BITS(&stp_bpdu->max_age) / STP_TIME_BASE,
  245. (float)EXTRACT_16BITS(&stp_bpdu->hello_time) / STP_TIME_BASE,
  246. (float)EXTRACT_16BITS(&stp_bpdu->forward_delay) / STP_TIME_BASE));
  247. ND_TCHECK_16BITS(ptr + MST_BPDU_VER3_LEN_OFFSET);
  248. ND_PRINT((ndo, "\n\tv3len %d, ", EXTRACT_16BITS(ptr + MST_BPDU_VER3_LEN_OFFSET)));
  249. ND_TCHECK_32BITS(ptr + MST_BPDU_CONFIG_DIGEST_OFFSET + 12);
  250. ND_PRINT((ndo, "MCID Name "));
  251. if (fn_printzp(ndo, ptr + MST_BPDU_CONFIG_NAME_OFFSET, 32, ndo->ndo_snapend))
  252. goto trunc;
  253. ND_PRINT((ndo, ", rev %u,"
  254. "\n\t\tdigest %08x%08x%08x%08x, ",
  255. EXTRACT_16BITS(ptr + MST_BPDU_CONFIG_NAME_OFFSET + 32),
  256. EXTRACT_32BITS(ptr + MST_BPDU_CONFIG_DIGEST_OFFSET),
  257. EXTRACT_32BITS(ptr + MST_BPDU_CONFIG_DIGEST_OFFSET + 4),
  258. EXTRACT_32BITS(ptr + MST_BPDU_CONFIG_DIGEST_OFFSET + 8),
  259. EXTRACT_32BITS(ptr + MST_BPDU_CONFIG_DIGEST_OFFSET + 12)));
  260. ND_TCHECK_32BITS(ptr + MST_BPDU_CIST_INT_PATH_COST_OFFSET);
  261. ND_PRINT((ndo, "CIST int-root-pathcost %u,",
  262. EXTRACT_32BITS(ptr + MST_BPDU_CIST_INT_PATH_COST_OFFSET)));
  263. ND_TCHECK_BRIDGE_ID(ptr + MST_BPDU_CIST_BRIDGE_ID_OFFSET);
  264. ND_PRINT((ndo, "\n\tCIST bridge-id %s, ",
  265. stp_print_bridge_id(ptr + MST_BPDU_CIST_BRIDGE_ID_OFFSET)));
  266. ND_TCHECK(ptr[MST_BPDU_CIST_REMAIN_HOPS_OFFSET]);
  267. ND_PRINT((ndo, "CIST remaining-hops %d", ptr[MST_BPDU_CIST_REMAIN_HOPS_OFFSET]));
  268. /* Dump all MSTI's */
  269. ND_TCHECK_16BITS(ptr + MST_BPDU_VER3_LEN_OFFSET);
  270. v3len = EXTRACT_16BITS(ptr + MST_BPDU_VER3_LEN_OFFSET);
  271. if (v3len > MST_BPDU_CONFIG_INFO_LENGTH) {
  272. len = v3len - MST_BPDU_CONFIG_INFO_LENGTH;
  273. offset = MST_BPDU_MSTI_OFFSET;
  274. while (len >= MST_BPDU_MSTI_LENGTH) {
  275. ND_TCHECK2(*(ptr + offset), MST_BPDU_MSTI_LENGTH);
  276. msti = EXTRACT_16BITS(ptr + offset +
  277. MST_BPDU_MSTI_ROOT_PRIO_OFFSET);
  278. msti = msti & 0x0FFF;
  279. ND_PRINT((ndo, "\n\tMSTI %d, Flags [%s], port-role %s",
  280. msti, bittok2str(stp_bpdu_flag_values, "none", ptr[offset]),
  281. tok2str(rstp_obj_port_role_values, "Unknown",
  282. RSTP_EXTRACT_PORT_ROLE(ptr[offset]))));
  283. ND_PRINT((ndo, "\n\t\tMSTI regional-root-id %s, pathcost %u",
  284. stp_print_bridge_id(ptr + offset +
  285. MST_BPDU_MSTI_ROOT_PRIO_OFFSET),
  286. EXTRACT_32BITS(ptr + offset +
  287. MST_BPDU_MSTI_ROOT_PATH_COST_OFFSET)));
  288. ND_PRINT((ndo, "\n\t\tMSTI bridge-prio %d, port-prio %d, hops %d",
  289. ptr[offset + MST_BPDU_MSTI_BRIDGE_PRIO_OFFSET] >> 4,
  290. ptr[offset + MST_BPDU_MSTI_PORT_PRIO_OFFSET] >> 4,
  291. ptr[offset + MST_BPDU_MSTI_REMAIN_HOPS_OFFSET]));
  292. len -= MST_BPDU_MSTI_LENGTH;
  293. offset += MST_BPDU_MSTI_LENGTH;
  294. }
  295. }
  296. return 1;
  297. trunc:
  298. return 0;
  299. }
  300. static int
  301. stp_print_spb_bpdu(netdissect_options *ndo, const struct stp_bpdu_ *stp_bpdu,
  302. u_int offset)
  303. {
  304. const u_char *ptr;
  305. /*
  306. * in non-verbose mode don't print anything.
  307. */
  308. if (!ndo->ndo_vflag) {
  309. return 1;
  310. }
  311. ptr = (const u_char *)stp_bpdu;
  312. ND_TCHECK_32BITS(ptr + offset + SPB_BPDU_AGREEMENT_DIGEST_OFFSET + 16);
  313. ND_PRINT((ndo, "\n\tv4len %d, ", EXTRACT_16BITS (ptr + offset)));
  314. ND_PRINT((ndo, "AUXMCID Name "));
  315. if (fn_printzp(ndo, ptr + offset + SPB_BPDU_CONFIG_NAME_OFFSET, 32,
  316. ndo->ndo_snapend))
  317. goto trunc;
  318. ND_PRINT((ndo, ", Rev %u,\n\t\tdigest %08x%08x%08x%08x",
  319. EXTRACT_16BITS(ptr + offset + SPB_BPDU_CONFIG_REV_OFFSET),
  320. EXTRACT_32BITS(ptr + offset + SPB_BPDU_CONFIG_DIGEST_OFFSET),
  321. EXTRACT_32BITS(ptr + offset + SPB_BPDU_CONFIG_DIGEST_OFFSET + 4),
  322. EXTRACT_32BITS(ptr + offset + SPB_BPDU_CONFIG_DIGEST_OFFSET + 8),
  323. EXTRACT_32BITS(ptr + offset + SPB_BPDU_CONFIG_DIGEST_OFFSET + 12)));
  324. ND_PRINT((ndo, "\n\tAgreement num %d, Discarded Agreement num %d, Agreement valid-"
  325. "flag %d,\n\tRestricted role-flag: %d, Format id %d cap %d, "
  326. "Convention id %d cap %d,\n\tEdge count %d, "
  327. "Agreement digest %08x%08x%08x%08x%08x\n",
  328. ptr[offset + SPB_BPDU_AGREEMENT_OFFSET]>>6,
  329. ptr[offset + SPB_BPDU_AGREEMENT_OFFSET]>>4 & 0x3,
  330. ptr[offset + SPB_BPDU_AGREEMENT_OFFSET]>>3 & 0x1,
  331. ptr[offset + SPB_BPDU_AGREEMENT_OFFSET]>>2 & 0x1,
  332. ptr[offset + SPB_BPDU_AGREEMENT_FORMAT_OFFSET]>>4,
  333. ptr[offset + SPB_BPDU_AGREEMENT_FORMAT_OFFSET]&0x00ff,
  334. ptr[offset + SPB_BPDU_AGREEMENT_CON_OFFSET]>>4,
  335. ptr[offset + SPB_BPDU_AGREEMENT_CON_OFFSET]&0x00ff,
  336. EXTRACT_16BITS(ptr + offset + SPB_BPDU_AGREEMENT_EDGE_OFFSET),
  337. EXTRACT_32BITS(ptr + offset + SPB_BPDU_AGREEMENT_DIGEST_OFFSET),
  338. EXTRACT_32BITS(ptr + offset + SPB_BPDU_AGREEMENT_DIGEST_OFFSET+4),
  339. EXTRACT_32BITS(ptr + offset + SPB_BPDU_AGREEMENT_DIGEST_OFFSET+8),
  340. EXTRACT_32BITS(ptr + offset + SPB_BPDU_AGREEMENT_DIGEST_OFFSET+12),
  341. EXTRACT_32BITS(ptr + offset + SPB_BPDU_AGREEMENT_DIGEST_OFFSET+16)));
  342. return 1;
  343. trunc:
  344. return 0;
  345. }
  346. /*
  347. * Print 802.1d / 802.1w / 802.1q (mstp) / 802.1aq (spb) packets.
  348. */
  349. void
  350. stp_print(netdissect_options *ndo, const u_char *p, u_int length)
  351. {
  352. const struct stp_bpdu_ *stp_bpdu;
  353. u_int mstp_len;
  354. u_int spb_len;
  355. stp_bpdu = (const struct stp_bpdu_*)p;
  356. /* Minimum STP Frame size. */
  357. if (length < 4)
  358. goto trunc;
  359. ND_TCHECK(stp_bpdu->protocol_id);
  360. if (EXTRACT_16BITS(&stp_bpdu->protocol_id)) {
  361. ND_PRINT((ndo, "unknown STP version, length %u", length));
  362. return;
  363. }
  364. ND_TCHECK(stp_bpdu->protocol_version);
  365. ND_PRINT((ndo, "STP %s", tok2str(stp_proto_values, "Unknown STP protocol (0x%02x)",
  366. stp_bpdu->protocol_version)));
  367. switch (stp_bpdu->protocol_version) {
  368. case STP_PROTO_REGULAR:
  369. case STP_PROTO_RAPID:
  370. case STP_PROTO_MSTP:
  371. case STP_PROTO_SPB:
  372. break;
  373. default:
  374. return;
  375. }
  376. ND_TCHECK(stp_bpdu->bpdu_type);
  377. ND_PRINT((ndo, ", %s", tok2str(stp_bpdu_type_values, "Unknown BPDU Type (0x%02x)",
  378. stp_bpdu->bpdu_type)));
  379. switch (stp_bpdu->bpdu_type) {
  380. case STP_BPDU_TYPE_CONFIG:
  381. if (length < sizeof(struct stp_bpdu_) - 1) {
  382. goto trunc;
  383. }
  384. if (!stp_print_config_bpdu(ndo, stp_bpdu, length))
  385. goto trunc;
  386. break;
  387. case STP_BPDU_TYPE_RSTP:
  388. if (stp_bpdu->protocol_version == STP_PROTO_RAPID) {
  389. if (length < sizeof(struct stp_bpdu_)) {
  390. goto trunc;
  391. }
  392. if (!stp_print_config_bpdu(ndo, stp_bpdu, length))
  393. goto trunc;
  394. } else if (stp_bpdu->protocol_version == STP_PROTO_MSTP ||
  395. stp_bpdu->protocol_version == STP_PROTO_SPB) {
  396. if (length < STP_BPDU_MSTP_MIN_LEN) {
  397. goto trunc;
  398. }
  399. ND_TCHECK(stp_bpdu->v1_length);
  400. if (stp_bpdu->v1_length != 0) {
  401. /* FIX ME: Emit a message here ? */
  402. goto trunc;
  403. }
  404. /* Validate v3 length */
  405. ND_TCHECK_16BITS(p + MST_BPDU_VER3_LEN_OFFSET);
  406. mstp_len = EXTRACT_16BITS(p + MST_BPDU_VER3_LEN_OFFSET);
  407. mstp_len += 2; /* length encoding itself is 2 bytes */
  408. if (length < (sizeof(struct stp_bpdu_) + mstp_len)) {
  409. goto trunc;
  410. }
  411. if (!stp_print_mstp_bpdu(ndo, stp_bpdu, length))
  412. goto trunc;
  413. if (stp_bpdu->protocol_version == STP_PROTO_SPB)
  414. {
  415. /* Validate v4 length */
  416. ND_TCHECK_16BITS(p + MST_BPDU_VER3_LEN_OFFSET + mstp_len);
  417. spb_len = EXTRACT_16BITS (p + MST_BPDU_VER3_LEN_OFFSET + mstp_len);
  418. spb_len += 2;
  419. if (length < (sizeof(struct stp_bpdu_) + mstp_len + spb_len) ||
  420. spb_len < SPB_BPDU_MIN_LEN) {
  421. goto trunc;
  422. }
  423. if (!stp_print_spb_bpdu(ndo, stp_bpdu, (sizeof(struct stp_bpdu_) + mstp_len)))
  424. goto trunc;
  425. }
  426. }
  427. break;
  428. case STP_BPDU_TYPE_TOPO_CHANGE:
  429. /* always empty message - just break out */
  430. break;
  431. default:
  432. break;
  433. }
  434. return;
  435. trunc:
  436. ND_PRINT((ndo, "[|stp %d]", length));
  437. }
  438. /*
  439. * Local Variables:
  440. * c-style: whitesmith
  441. * c-basic-offset: 4
  442. * End:
  443. */