2 * Routines for BPDU (Spanning Tree Protocol) disassembly
6 * Copyright 1999 Christophe Tronche <ch.tronche@computer.org>
8 * Ethereal - Network traffic analyzer
9 * By Gerald Combs <gerald@ethereal.com>
10 * Copyright 1998 Gerald Combs
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 #include <epan/packet.h>
37 #include "chdlctypes.h"
38 #include <epan/resolv.h>
40 /* Offsets of fields within a BPDU */
42 #define BPDU_IDENTIFIER 0
43 #define BPDU_VERSION_IDENTIFIER 2
46 #define BPDU_ROOT_IDENTIFIER 5
47 #define BPDU_ROOT_PATH_COST 13
48 #define BPDU_BRIDGE_IDENTIFIER 17
49 #define BPDU_PORT_IDENTIFIER 25
50 #define BPDU_MESSAGE_AGE 27
51 #define BPDU_MAX_AGE 29
52 #define BPDU_HELLO_TIME 31
53 #define BPDU_FORWARD_DELAY 33
54 #define BPDU_VERSION_1_LENGTH 35
55 #define BPDU_VERSION_3_LENGTH 36
56 #define BPDU_MST_CONFIG_FORMAT_SELECTOR 38
57 #define BPDU_MST_CONFIG_NAME 39
58 #define BPDU_MST_CONFIG_REVISION_LEVEL 71
59 #define BPDU_MST_CONFIG_DIGEST 73
60 #define BPDU_CIST_INTERNAL_ROOT_PATH_COST 89
61 #define BPDU_CIST_BRIDGE_IDENTIFIER 93
62 #define BPDU_CIST_REMAINING_HOPS 101
65 #define MSTI_REGIONAL_ROOT 1
66 #define MSTI_INTERNAL_ROOT_PATH_COST 9
67 #define MSTI_BRIDGE_IDENTIFIER_PRIORITY 13
68 #define MSTI_PORT_IDENTIFIER_PRIORITY 14
69 #define MSTI_REMAINING_HOPS 15
71 #define CONF_BPDU_SIZE 35
72 #define TC_BPDU_SIZE 4
73 #define RST_BPDU_SIZE 36
74 #define VERSION_3_STATIC_LENGTH 66
75 #define MSTI_MESSAGE_SIZE 16
79 #define BPDU_FLAGS_TCACK 0x80
80 #define BPDU_FLAGS_AGREEMENT 0x40
81 #define BPDU_FLAGS_FORWARDING 0x20
82 #define BPDU_FLAGS_LEARNING 0x10
83 #define BPDU_FLAGS_PORT_ROLE_MASK 0x0C
84 #define BPDU_FLAGS_PORT_ROLE_SHIFT 2
85 #define BPDU_FLAGS_PROPOSAL 0x02
86 #define BPDU_FLAGS_TC 0x01
88 static int proto_bpdu = -1;
89 static int hf_bpdu_proto_id = -1;
90 static int hf_bpdu_version_id = -1;
91 static int hf_bpdu_type = -1;
92 static int hf_bpdu_flags = -1;
93 static int hf_bpdu_flags_tcack = -1;
94 static int hf_bpdu_flags_agreement = -1;
95 static int hf_bpdu_flags_forwarding = -1;
96 static int hf_bpdu_flags_learning = -1;
97 static int hf_bpdu_flags_port_role = -1;
98 static int hf_bpdu_flags_proposal = -1;
99 static int hf_bpdu_flags_tc = -1;
100 static int hf_bpdu_root_mac = -1;
101 static int hf_bpdu_root_cost = -1;
102 static int hf_bpdu_bridge_mac = -1;
103 static int hf_bpdu_port_id = -1;
104 static int hf_bpdu_msg_age = -1;
105 static int hf_bpdu_max_age = -1;
106 static int hf_bpdu_hello_time = -1;
107 static int hf_bpdu_forward_delay = -1;
108 static int hf_bpdu_version_1_length = -1;
109 static int hf_bpdu_version_3_length = -1;
110 static int hf_bpdu_mst_config_format_selector = -1;
111 static int hf_bpdu_mst_config_name = -1;
112 static int hf_bpdu_mst_config_revision_level = -1;
113 static int hf_bpdu_mst_config_digest = -1;
114 static int hf_bpdu_cist_internal_root_path_cost = -1;
115 static int hf_bpdu_cist_bridge_identifier_mac = -1;
116 static int hf_bpdu_cist_remaining_hops = -1;
117 static int hf_bpdu_msti_flags = -1;
118 static int hf_bpdu_msti_regional_root_mac = -1;
119 static int hf_bpdu_msti_internal_root_path_cost = -1;
120 static int hf_bpdu_msti_bridge_identifier_priority = -1;
121 static int hf_bpdu_msti_port_identifier_priority = -1;
122 static int hf_bpdu_msti_remaining_hops = -1;
124 static gint ett_bpdu = -1;
125 static gint ett_bpdu_flags = -1;
126 static gint ett_mstp = -1;
127 static gint ett_msti = -1;
129 static dissector_handle_t gvrp_handle;
130 static dissector_handle_t gmrp_handle;
131 static dissector_handle_t data_handle;
133 static const value_string protocol_id_vals[] = {
134 { 0, "Spanning Tree Protocol" },
138 #define BPDU_TYPE_CONF 0x00 /* STP Configuration BPDU */
139 #define BPDU_TYPE_RST 0x02 /* RST BPDU (or MST) */
140 #define BPDU_TYPE_TOPOLOGY_CHANGE 0x80 /* STP TCN (Topology change notify) BPDU */
142 static const value_string bpdu_type_vals[] = {
143 { BPDU_TYPE_CONF, "Configuration" },
144 { BPDU_TYPE_RST, "Rapid/Multiple Spanning Tree" },
145 { BPDU_TYPE_TOPOLOGY_CHANGE, "Topology Change Notification" },
149 #define PROTO_VERSION_STP 0
150 #define PROTO_VERSION_RSTP 2
151 #define PROTO_VERSION_MSTP 3
153 static const value_string version_id_vals[] = {
154 { PROTO_VERSION_STP, "Spanning Tree" },
155 { PROTO_VERSION_RSTP, "Rapid Spanning Tree" },
156 { PROTO_VERSION_MSTP, "Multiple Spanning Tree" },
159 static const value_string role_vals[] = {
160 { 1, "Alternate or Backup" },
166 static const char initial_sep[] = " (";
167 static const char cont_sep[] = ", ";
169 #define APPEND_BOOLEAN_FLAG(flag, item, string) \
172 proto_item_append_text(item, string, sep); \
177 dissect_bpdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
179 guint16 protocol_identifier;
180 guint8 protocol_version_identifier;
183 guint16 root_identifier_bridge_priority;
184 const guint8 *root_identifier_mac;
185 gchar *root_identifier_mac_str;
186 guint32 root_path_cost;
187 guint16 bridge_identifier_bridge_priority;
188 const guint8 *bridge_identifier_mac;
189 gchar *bridge_identifier_mac_str;
190 guint16 port_identifier;
194 double forward_delay;
195 guint16 version_3_length;
196 guint32 cist_internal_root_path_cost;
197 guint8 mst_config_format_selector;
198 guint16 cist_bridge_identifier_bridge_priority;
199 const guint8 *cist_bridge_identifier_mac;
200 gchar *cist_bridge_identifier_mac_str;
201 const guint8 *mst_config_name;
202 guint16 mst_config_revision_level;
203 guint8 cist_remaining_hops, msti_remaining_hops;
204 guint32 msti_internal_root_path_cost;
205 guint32 msti_regional_root_mstid, msti_regional_root_priority;
206 const guint8 *msti_regional_root_mac;
207 gchar *msti_regional_root_mac_str;
208 guint8 msti_bridge_identifier_priority, msti_port_identifier_priority;
209 int length, offset, msti;
211 proto_tree *bpdu_tree;
212 proto_tree *mstp_tree, *msti_tree;
213 proto_item *bpdu_item;
214 proto_item *mstp_item, *msti_item;
215 proto_tree *flags_tree;
216 proto_item *flags_item;
217 guint8 rstp_bpdu, mstp_bpdu=0;
220 /* GARP application frames require special interpretation of the
221 destination address field; otherwise, they will be mistaken as
223 Fortunately, they can be recognized by checking the first 6 octets
224 of the destination address, which are in the range from
225 01-80-C2-00-00-20 to 01-80-C2-00-00-2F.
227 Yes - we *do* need to check the destination address type;
228 on Linux cooked captures, there *is* no destination address,
230 if (pinfo->dl_dst.type == AT_ETHER &&
231 pinfo->dl_dst.data[0] == 0x01 && pinfo->dl_dst.data[1] == 0x80 &&
232 pinfo->dl_dst.data[2] == 0xC2 && pinfo->dl_dst.data[3] == 0x00 &&
233 pinfo->dl_dst.data[4] == 0x00 && ((pinfo->dl_dst.data[5] & 0xF0) == 0x20)) {
235 protocol_identifier = tvb_get_ntohs(tvb, BPDU_IDENTIFIER);
237 switch (pinfo->dl_dst.data[5]) {
241 call_dissector(gmrp_handle, tvb, pinfo, tree);
246 call_dissector(gvrp_handle, tvb, pinfo, tree);
250 pinfo->current_proto = "GARP";
252 if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
253 col_set_str(pinfo->cinfo, COL_PROTOCOL, "GARP");
254 /* Generic Attribute Registration Protocol */
257 if (check_col(pinfo->cinfo, COL_INFO)) {
258 col_add_fstr(pinfo->cinfo, COL_INFO,
259 "Unknown GARP application (0x%02X)",
260 pinfo->dl_dst.data[5]);
266 if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
267 col_set_str(pinfo->cinfo, COL_PROTOCOL, "STP"); /* Spanning Tree Protocol */
269 if (check_col(pinfo->cinfo, COL_INFO)) {
270 col_clear(pinfo->cinfo, COL_INFO);
273 bpdu_type = tvb_get_guint8(tvb, BPDU_TYPE);
275 protocol_version_identifier = tvb_get_guint8(tvb, BPDU_VERSION_IDENTIFIER);
281 flags = tvb_get_guint8(tvb, BPDU_FLAGS);
282 root_identifier_bridge_priority = tvb_get_ntohs(tvb,BPDU_ROOT_IDENTIFIER);
283 root_identifier_mac = tvb_get_ptr(tvb, BPDU_ROOT_IDENTIFIER + 2, 6);
284 root_identifier_mac_str = ether_to_str(root_identifier_mac);
285 root_path_cost = tvb_get_ntohl(tvb, BPDU_ROOT_PATH_COST);
286 port_identifier = tvb_get_ntohs(tvb, BPDU_PORT_IDENTIFIER);
290 /* Squelch GCC complaints. */
292 root_identifier_bridge_priority = 0;
293 root_identifier_mac = NULL;
294 root_identifier_mac_str = NULL;
300 if (check_col(pinfo->cinfo, COL_INFO)) {
304 col_add_fstr(pinfo->cinfo, COL_INFO, "Conf. %sRoot = %d/%s Cost = %d Port = 0x%04x",
305 flags & 0x1 ? "TC + " : "",
306 root_identifier_bridge_priority, root_identifier_mac_str, root_path_cost,
310 case BPDU_TYPE_TOPOLOGY_CHANGE:
311 col_add_fstr(pinfo->cinfo, COL_INFO, "Topology Change Notification");
315 col_add_fstr(pinfo->cinfo, COL_INFO, "%cST. %sRoot = %d/%s Cost = %d Port = 0x%04x",
316 protocol_version_identifier == 3 ? 'M':'R',
317 flags & 0x1 ? "TC + " : "",
318 root_identifier_bridge_priority, root_identifier_mac_str, root_path_cost,
323 col_add_fstr(pinfo->cinfo, COL_INFO, "Unknown BPDU type (%u)",
332 set_actual_length(tvb, CONF_BPDU_SIZE);
335 case BPDU_TYPE_TOPOLOGY_CHANGE:
336 set_actual_length(tvb, TC_BPDU_SIZE);
340 if (protocol_version_identifier == 3) {
341 version_3_length = tvb_get_ntohs(tvb, BPDU_VERSION_3_LENGTH);
343 * XXX - there appears to be an ambiguity in the 802.1s spec.
344 * In 14.6.q and Figure 14-1, the "Version 3 Length" field
345 * "is the number of octets taken by the parameters that
346 * follow in the BPDU", but item 14.4.e.3 speaks of "a
347 * Version 3 length representing an integral number, from 0
348 * to 64 inclusive, of MSTI Configuration Messages".
350 * According to mail from a member of the stds-802-1@ieee.org
351 * list, item 14.4.e.3 is just saying that the length must
352 * not have a value that implies that there's a partial
353 * MSTI message in the packet, and that it's in units of
354 * bytes, not messages.
356 * However, it appears that Cisco's C3550 software
357 * (C3550-I5Q3L2-M, Version 12.1(12c)EA1) might be sending out
358 * lengths in units of messages.
360 * So if the length is too short, we assume it's because it's
361 * in units of messages, not bytes.
363 if (version_3_length < VERSION_3_STATIC_LENGTH - 2) {
364 set_actual_length(tvb, RST_BPDU_SIZE +
365 VERSION_3_STATIC_LENGTH +
366 version_3_length * MSTI_MESSAGE_SIZE);
368 set_actual_length(tvb, RST_BPDU_SIZE + 2 + version_3_length);
370 set_actual_length(tvb, RST_BPDU_SIZE);
375 bpdu_item = proto_tree_add_protocol_format(tree, proto_bpdu, tvb,
376 0, -1, "Spanning Tree Protocol");
377 bpdu_tree = proto_item_add_subtree(bpdu_item, ett_bpdu);
379 protocol_identifier = tvb_get_ntohs(tvb, BPDU_IDENTIFIER);
380 proto_tree_add_uint(bpdu_tree, hf_bpdu_proto_id, tvb,
381 BPDU_IDENTIFIER, 2, protocol_identifier);
383 proto_tree_add_uint(bpdu_tree, hf_bpdu_version_id, tvb,
384 BPDU_VERSION_IDENTIFIER, 1,
385 protocol_version_identifier);
386 switch (protocol_version_identifier) {
393 proto_tree_add_text(bpdu_tree, tvb, BPDU_VERSION_IDENTIFIER, 1,
394 " (Warning: this version of Ethereal only knows about versions 0, 2 & 3)");
397 proto_tree_add_uint(bpdu_tree, hf_bpdu_type, tvb,
401 if (bpdu_type != BPDU_TYPE_CONF && bpdu_type != BPDU_TYPE_RST) {
402 call_dissector(data_handle,
403 tvb_new_subset(tvb, BPDU_TYPE + 1, -1, -1),
408 rstp_bpdu = (bpdu_type == BPDU_TYPE_RST);
409 if (rstp_bpdu) mstp_bpdu = (protocol_version_identifier == 3);
411 bridge_identifier_bridge_priority = tvb_get_ntohs(tvb, BPDU_BRIDGE_IDENTIFIER);
412 bridge_identifier_mac = tvb_get_ptr(tvb, BPDU_BRIDGE_IDENTIFIER + 2, 6);
413 bridge_identifier_mac_str = ether_to_str(bridge_identifier_mac);
415 flags_item = proto_tree_add_uint(bpdu_tree, hf_bpdu_flags, tvb,
416 BPDU_FLAGS, 1, flags);
417 flags_tree = proto_item_add_subtree(flags_item, ett_bpdu_flags);
419 APPEND_BOOLEAN_FLAG(flags & BPDU_FLAGS_TCACK, flags_item,
420 "%sTopology Change Acknowledgment");
421 proto_tree_add_boolean(flags_tree, hf_bpdu_flags_tcack, tvb,
422 BPDU_FLAGS, 1, flags);
424 APPEND_BOOLEAN_FLAG(flags & BPDU_FLAGS_AGREEMENT, flags_item,
426 proto_tree_add_boolean(flags_tree, hf_bpdu_flags_agreement, tvb,
427 BPDU_FLAGS, 1, flags);
428 APPEND_BOOLEAN_FLAG(flags & BPDU_FLAGS_FORWARDING, flags_item,
430 proto_tree_add_boolean(flags_tree, hf_bpdu_flags_forwarding, tvb,
431 BPDU_FLAGS, 1, flags);
432 APPEND_BOOLEAN_FLAG(flags & BPDU_FLAGS_LEARNING, flags_item,
434 proto_tree_add_boolean(flags_tree, hf_bpdu_flags_learning, tvb,
435 BPDU_FLAGS, 1, flags);
439 port_role = (flags & BPDU_FLAGS_PORT_ROLE_MASK) >> BPDU_FLAGS_PORT_ROLE_SHIFT;
440 proto_item_append_text(flags_item, "%sPort Role: %s", sep,
441 val_to_str(port_role, role_vals,
445 proto_tree_add_uint(flags_tree, hf_bpdu_flags_port_role, tvb,
446 BPDU_FLAGS, 1, flags);
447 APPEND_BOOLEAN_FLAG(flags & BPDU_FLAGS_PROPOSAL, flags_item,
449 proto_tree_add_boolean(flags_tree, hf_bpdu_flags_proposal, tvb,
450 BPDU_FLAGS, 1, flags);
452 APPEND_BOOLEAN_FLAG(flags & BPDU_FLAGS_TC, flags_item,
453 "%sTopology Change");
454 proto_tree_add_boolean(flags_tree, hf_bpdu_flags_tc, tvb,
455 BPDU_FLAGS, 1, flags);
456 if (sep != initial_sep) {
457 /* We put something in; put in the terminating ")" */
458 proto_item_append_text(flags_item, ")");
461 proto_tree_add_ether_hidden(bpdu_tree, hf_bpdu_root_mac, tvb,
462 BPDU_ROOT_IDENTIFIER + 2, 6,
463 root_identifier_mac);
464 proto_tree_add_text(bpdu_tree, tvb,
465 BPDU_ROOT_IDENTIFIER, 8,
466 "Root Identifier: %d / %s",
467 root_identifier_bridge_priority,
468 root_identifier_mac_str);
469 proto_tree_add_uint(bpdu_tree, hf_bpdu_root_cost, tvb,
470 BPDU_ROOT_PATH_COST, 4,
472 proto_tree_add_text(bpdu_tree, tvb,
473 BPDU_BRIDGE_IDENTIFIER, 8,
474 "Bridge Identifier: %d / %s",
475 bridge_identifier_bridge_priority,
476 bridge_identifier_mac_str);
477 proto_tree_add_ether_hidden(bpdu_tree, hf_bpdu_bridge_mac, tvb,
478 BPDU_BRIDGE_IDENTIFIER + 2, 6,
479 bridge_identifier_mac);
480 proto_tree_add_uint(bpdu_tree, hf_bpdu_port_id, tvb,
481 BPDU_PORT_IDENTIFIER, 2,
483 message_age = tvb_get_ntohs(tvb, BPDU_MESSAGE_AGE) / 256.0;
484 proto_tree_add_double(bpdu_tree, hf_bpdu_msg_age, tvb,
487 max_age = tvb_get_ntohs(tvb, BPDU_MAX_AGE) / 256.0;
488 proto_tree_add_double(bpdu_tree, hf_bpdu_max_age, tvb,
491 hello_time = tvb_get_ntohs(tvb, BPDU_HELLO_TIME) / 256.0;
492 proto_tree_add_double(bpdu_tree, hf_bpdu_hello_time, tvb,
495 forward_delay = tvb_get_ntohs(tvb, BPDU_FORWARD_DELAY) / 256.0;
496 proto_tree_add_double(bpdu_tree, hf_bpdu_forward_delay, tvb,
497 BPDU_FORWARD_DELAY, 2,
500 proto_tree_add_item(bpdu_tree, hf_bpdu_version_1_length, tvb,
501 BPDU_VERSION_1_LENGTH, 1, FALSE);
504 version_3_length = tvb_get_ntohs(tvb, BPDU_VERSION_3_LENGTH);
506 mstp_item = proto_tree_add_uint(bpdu_tree, hf_bpdu_version_3_length, tvb,
507 BPDU_VERSION_3_LENGTH, 2, version_3_length);
509 * XXX - see comment above about the interpretation of the
510 * "Version 3 Length" field not being clear.
512 if (version_3_length < VERSION_3_STATIC_LENGTH - 2) {
513 proto_item_append_text(mstp_item,
514 " (Malformed: number of MSTI messages!!! Must be %u)",
515 (VERSION_3_STATIC_LENGTH - 2 + version_3_length * MSTI_MESSAGE_SIZE));
517 proto_item_append_text(mstp_item,
518 " (Number of MSTI messages: %u)",
519 (version_3_length - (VERSION_3_STATIC_LENGTH - 2)) / MSTI_MESSAGE_SIZE);
521 mstp_tree = proto_item_add_subtree(mstp_item, ett_mstp);
523 mst_config_format_selector = tvb_get_guint8(tvb, BPDU_MST_CONFIG_FORMAT_SELECTOR);
524 proto_tree_add_uint(mstp_tree, hf_bpdu_mst_config_format_selector, tvb,
525 BPDU_MST_CONFIG_FORMAT_SELECTOR, 1, mst_config_format_selector);
526 mst_config_name = tvb_get_ptr (tvb, BPDU_MST_CONFIG_NAME, 32);
527 proto_tree_add_string(mstp_tree, hf_bpdu_mst_config_name, tvb, BPDU_MST_CONFIG_NAME, 32, mst_config_name);
529 mst_config_revision_level = tvb_get_ntohs(tvb, BPDU_MST_CONFIG_REVISION_LEVEL);
530 proto_tree_add_uint(mstp_tree, hf_bpdu_mst_config_revision_level, tvb,
531 BPDU_MST_CONFIG_REVISION_LEVEL, 2, mst_config_revision_level);
532 proto_tree_add_bytes(mstp_tree, hf_bpdu_mst_config_digest, tvb,
533 BPDU_MST_CONFIG_DIGEST, 16, tvb_get_ptr(tvb, BPDU_MST_CONFIG_DIGEST, 16));
535 cist_internal_root_path_cost = tvb_get_ntohl(tvb, BPDU_CIST_INTERNAL_ROOT_PATH_COST);
536 proto_tree_add_uint(mstp_tree, hf_bpdu_cist_internal_root_path_cost, tvb,
537 BPDU_CIST_INTERNAL_ROOT_PATH_COST, 4, cist_internal_root_path_cost);
539 cist_bridge_identifier_bridge_priority = tvb_get_ntohs(tvb,BPDU_CIST_BRIDGE_IDENTIFIER);
540 cist_bridge_identifier_mac = tvb_get_ptr(tvb, BPDU_CIST_BRIDGE_IDENTIFIER + 2, 6);
541 cist_bridge_identifier_mac_str = ether_to_str(cist_bridge_identifier_mac);
542 proto_tree_add_text(mstp_tree, tvb, BPDU_CIST_BRIDGE_IDENTIFIER, 8,
543 "CIST Bridge Identifier: %d / %s",
544 cist_bridge_identifier_bridge_priority,
545 cist_bridge_identifier_mac_str);
546 proto_tree_add_ether_hidden(mstp_tree, hf_bpdu_cist_bridge_identifier_mac, tvb,
547 BPDU_CIST_BRIDGE_IDENTIFIER + 2, 6,
548 cist_bridge_identifier_mac);
550 cist_remaining_hops = tvb_get_guint8(tvb, BPDU_CIST_REMAINING_HOPS);
551 proto_tree_add_uint(mstp_tree, hf_bpdu_cist_remaining_hops, tvb,
552 BPDU_CIST_REMAINING_HOPS, 1, cist_remaining_hops);
556 length = tvb_reported_length_remaining(tvb, offset);
558 while (length >= MSTI_MESSAGE_SIZE) {
559 msti_regional_root_mstid = tvb_get_guint8(tvb, offset+ MSTI_REGIONAL_ROOT);
560 msti_regional_root_priority = (msti_regional_root_mstid &0xf0) << 8;
561 msti_regional_root_mstid = ((msti_regional_root_mstid & 0x0f) << 8) +
562 tvb_get_guint8(tvb, offset+ MSTI_REGIONAL_ROOT+1);
563 msti_regional_root_mac = tvb_get_ptr(tvb, offset+ MSTI_REGIONAL_ROOT + 2, 6);
564 msti_regional_root_mac_str = ether_to_str(msti_regional_root_mac);
566 msti_item = proto_tree_add_text(mstp_tree, tvb, offset, 16,
567 "MSTID %d, Regional Root Identifier %d / %s",
568 msti_regional_root_mstid, msti_regional_root_priority,
569 msti_regional_root_mac_str);
570 msti_tree = proto_item_add_subtree(msti_item, ett_msti);
573 flags = tvb_get_guint8(tvb, offset+MSTI_FLAGS);
574 flags_item = proto_tree_add_uint(msti_tree, hf_bpdu_msti_flags, tvb,
575 offset+MSTI_FLAGS, 1, flags);
576 flags_tree = proto_item_add_subtree(flags_item, ett_bpdu_flags);
579 APPEND_BOOLEAN_FLAG(flags & BPDU_FLAGS_TCACK, flags_item, "%sMaster");
580 proto_tree_add_boolean(flags_tree, hf_bpdu_flags_tcack, tvb,
581 offset+MSTI_FLAGS, 1, flags);
582 APPEND_BOOLEAN_FLAG(flags & BPDU_FLAGS_AGREEMENT, flags_item, "%sAgreement");
583 proto_tree_add_boolean(flags_tree, hf_bpdu_flags_agreement, tvb,
584 offset+MSTI_FLAGS, 1, flags);
585 APPEND_BOOLEAN_FLAG(flags & BPDU_FLAGS_FORWARDING, flags_item, "%sForwarding");
586 proto_tree_add_boolean(flags_tree, hf_bpdu_flags_forwarding, tvb,
587 offset+MSTI_FLAGS, 1, flags);
588 APPEND_BOOLEAN_FLAG(flags & BPDU_FLAGS_LEARNING, flags_item, "%sLearning");
589 proto_tree_add_boolean(flags_tree, hf_bpdu_flags_learning, tvb,
590 offset+MSTI_FLAGS, 1, flags);
593 port_role = (flags & BPDU_FLAGS_PORT_ROLE_MASK) >> BPDU_FLAGS_PORT_ROLE_SHIFT;
594 proto_item_append_text(flags_item, "%sPort Role: %s", sep,
595 val_to_str(port_role, role_vals, "Unknown (%u)"));
597 proto_tree_add_uint(flags_tree, hf_bpdu_flags_port_role, tvb,
598 offset+MSTI_FLAGS, 1, flags);
600 APPEND_BOOLEAN_FLAG(flags & BPDU_FLAGS_PROPOSAL, flags_item, "%sProposal");
601 proto_tree_add_boolean(flags_tree, hf_bpdu_flags_proposal, tvb,
602 offset+MSTI_FLAGS, 1, flags);
603 APPEND_BOOLEAN_FLAG(flags & BPDU_FLAGS_TC, flags_item, "%sTopology Change");
604 proto_tree_add_boolean(flags_tree, hf_bpdu_flags_tc, tvb,
605 offset+MSTI_FLAGS, 1, flags);
606 if (sep != initial_sep) { /* We put something in; put in the terminating ")" */
607 proto_item_append_text(flags_item, ")");
610 /* pri, MSTID, Regional root */
611 proto_tree_add_ether_hidden(msti_tree, hf_bpdu_msti_regional_root_mac, tvb,
612 offset + MSTI_REGIONAL_ROOT + 2, 6,
613 msti_regional_root_mac);
614 proto_tree_add_text(msti_tree, tvb, offset + MSTI_REGIONAL_ROOT, 8,
615 "MSTID %d, priority %d Root Identifier %s",
616 msti_regional_root_mstid, msti_regional_root_priority,
617 msti_regional_root_mac_str);
620 msti_internal_root_path_cost = tvb_get_ntohs(tvb, offset+MSTI_INTERNAL_ROOT_PATH_COST);
621 proto_tree_add_uint(msti_tree, hf_bpdu_msti_internal_root_path_cost, tvb,
622 offset+MSTI_INTERNAL_ROOT_PATH_COST, 4, msti_internal_root_path_cost);
624 msti_bridge_identifier_priority = tvb_get_guint8(tvb, offset+MSTI_BRIDGE_IDENTIFIER_PRIORITY) >> 4;
625 msti_port_identifier_priority = tvb_get_guint8(tvb, offset+MSTI_PORT_IDENTIFIER_PRIORITY) >> 4;
627 proto_tree_add_uint(msti_tree, hf_bpdu_msti_bridge_identifier_priority, tvb,
628 offset+MSTI_BRIDGE_IDENTIFIER_PRIORITY, 1, msti_bridge_identifier_priority);
629 proto_tree_add_uint(msti_tree, hf_bpdu_msti_port_identifier_priority, tvb,
630 offset+MSTI_PORT_IDENTIFIER_PRIORITY, 1, msti_port_identifier_priority);
632 msti_remaining_hops = tvb_get_guint8(tvb, offset+MSTI_REMAINING_HOPS);
633 proto_tree_add_uint(msti_tree, hf_bpdu_msti_remaining_hops, tvb,
634 offset + MSTI_REMAINING_HOPS, 1, msti_remaining_hops);
636 length -= MSTI_MESSAGE_SIZE;
637 offset += MSTI_MESSAGE_SIZE;
645 static const true_false_string yesno = {
651 proto_register_bpdu(void)
654 static hf_register_info hf[] = {
656 { "Protocol Identifier", "stp.protocol",
657 FT_UINT16, BASE_HEX, VALS(&protocol_id_vals), 0x0,
659 { &hf_bpdu_version_id,
660 { "Protocol Version Identifier", "stp.version",
661 FT_UINT8, BASE_DEC, VALS(&version_id_vals), 0x0,
664 { "BPDU Type", "stp.type",
665 FT_UINT8, BASE_HEX, VALS(&bpdu_type_vals), 0x0,
668 { "BPDU flags", "stp.flags",
669 FT_UINT8, BASE_HEX, NULL, 0x0,
671 { &hf_bpdu_flags_tcack,
672 { "Topology Change Acknowledgment", "stp.flags.tcack",
673 FT_BOOLEAN, 8, TFS(&yesno), BPDU_FLAGS_TCACK,
675 { &hf_bpdu_flags_agreement,
676 { "Agreement", "stp.flags.agreement",
677 FT_BOOLEAN, 8, TFS(&yesno), BPDU_FLAGS_AGREEMENT,
679 { &hf_bpdu_flags_forwarding,
680 { "Forwarding", "stp.flags.forwarding",
681 FT_BOOLEAN, 8, TFS(&yesno), BPDU_FLAGS_FORWARDING,
683 { &hf_bpdu_flags_learning,
684 { "Learning", "stp.flags.learning",
685 FT_BOOLEAN, 8, TFS(&yesno), BPDU_FLAGS_LEARNING,
687 { &hf_bpdu_flags_port_role,
688 { "Port Role", "stp.flags.port_role",
689 FT_UINT8, BASE_DEC, VALS(role_vals), BPDU_FLAGS_PORT_ROLE_MASK,
691 { &hf_bpdu_flags_proposal,
692 { "Proposal", "stp.flags.proposal",
693 FT_BOOLEAN, 8, TFS(&yesno), BPDU_FLAGS_PROPOSAL,
696 { "Topology Change", "stp.flags.tc",
697 FT_BOOLEAN, 8, TFS(&yesno), BPDU_FLAGS_TC,
700 { "Root Identifier", "stp.root.hw",
701 FT_ETHER, BASE_NONE, NULL, 0x0,
703 { &hf_bpdu_root_cost,
704 { "Root Path Cost", "stp.root.cost",
705 FT_UINT32, BASE_DEC, NULL, 0x0,
707 { &hf_bpdu_bridge_mac,
708 { "Bridge Identifier", "stp.bridge.hw",
709 FT_ETHER, BASE_NONE, NULL, 0x0,
712 { "Port identifier", "stp.port",
713 FT_UINT16, BASE_HEX, NULL, 0x0,
716 { "Message Age", "stp.msg_age",
717 FT_DOUBLE, BASE_NONE, NULL, 0x0,
720 { "Max Age", "stp.max_age",
721 FT_DOUBLE, BASE_NONE, NULL, 0x0,
723 { &hf_bpdu_hello_time,
724 { "Hello Time", "stp.hello",
725 FT_DOUBLE, BASE_NONE, NULL, 0x0,
727 { &hf_bpdu_forward_delay,
728 { "Forward Delay", "stp.forward",
729 FT_DOUBLE, BASE_NONE, NULL, 0x0,
731 { &hf_bpdu_version_1_length,
732 { "Version 1 Length", "stp.version_1_length",
733 FT_UINT8, BASE_DEC, NULL, 0x0,
735 { &hf_bpdu_version_3_length,
736 { "MST Extension, Length", "mstp.version_3_length",
737 FT_UINT16, BASE_DEC, NULL, 0x0,
739 { &hf_bpdu_mst_config_format_selector,
740 { "MST Config ID format selector", "mstp.config_format_selector",
741 FT_UINT8, BASE_DEC, NULL, 0x0,
743 { &hf_bpdu_mst_config_name,
744 { "MST Config name", "mstp.config_name",
745 FT_STRING, BASE_DEC, NULL, 0x0,
747 { &hf_bpdu_mst_config_revision_level,
748 { "MST Config revision", "mstp.config_revision_level",
749 FT_UINT16, BASE_DEC, NULL, 0x0,
751 { &hf_bpdu_mst_config_digest,
752 { "MST Config digest", "mstp.config_digest",
753 FT_BYTES, BASE_DEC, NULL, 0x0,
755 { &hf_bpdu_cist_internal_root_path_cost,
756 { "CIST Internal Root Path Cost", "mstp.cist_internal_root_path_cost",
757 FT_UINT32, BASE_DEC, NULL, 0x0,
759 { &hf_bpdu_cist_bridge_identifier_mac,
760 { "CIST Bridge Identifier", "mstp.cist_bridge.hw",
761 FT_ETHER, BASE_DEC, NULL, 0x0,
763 { &hf_bpdu_cist_remaining_hops,
764 { "CIST Remaining hops", "mstp.cist_remaining_hops",
765 FT_UINT8, BASE_DEC, NULL, 0x0,
767 { &hf_bpdu_msti_flags,
768 { "MSTI flags", "mstp.msti.flags",
769 FT_UINT8, BASE_HEX, NULL, 0x0,
771 { &hf_bpdu_msti_regional_root_mac,
772 { "Regional Root", "mstp.msti.root.hw",
773 FT_ETHER, BASE_DEC, NULL, 0x0,
775 { &hf_bpdu_msti_internal_root_path_cost,
776 { "Internal root path cost", "mstp.msti.root_cost",
777 FT_UINT32, BASE_DEC, NULL, 0x0,
779 { &hf_bpdu_msti_bridge_identifier_priority,
780 { "Bridge Identifier Priority", "mstp.msti.bridge_priority",
781 FT_UINT8, BASE_DEC, NULL, 0x0,
783 { &hf_bpdu_msti_port_identifier_priority,
784 { "Port identifier prority", "mstp.msti.port_priority",
785 FT_UINT8, BASE_DEC, NULL, 0x0,
787 { &hf_bpdu_msti_remaining_hops,
788 { "Remaining hops", "mstp.msti.remaining_hops",
789 FT_UINT8, BASE_DEC, NULL, 0x0,
793 static gint *ett[] = {
800 proto_bpdu = proto_register_protocol("Spanning Tree Protocol", "STP", "stp");
801 proto_register_field_array(proto_bpdu, hf, array_length(hf));
802 proto_register_subtree_array(ett, array_length(ett));
804 register_dissector("bpdu", dissect_bpdu, proto_bpdu);
808 proto_reg_handoff_bpdu(void)
810 dissector_handle_t bpdu_handle;
813 * Get handle for the GVRP dissector.
815 gvrp_handle = find_dissector("gvrp");
818 * Get handle for the GMRP dissector.
820 gmrp_handle = find_dissector("gmrp");
821 data_handle = find_dissector("data");
823 bpdu_handle = find_dissector("bpdu");
824 dissector_add("llc.dsap", SAP_BPDU, bpdu_handle);
825 dissector_add("ppp.protocol", PPP_BPDU, bpdu_handle);
826 dissector_add("chdlctype", CHDLCTYPE_BPDU, bpdu_handle);
827 dissector_add("llc.cisco_pid", 0x010b, bpdu_handle);