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