2 * Routines for BPDU (Spanning Tree Protocol) disassembly
4 * $Id: packet-bpdu.c,v 1.1 1999/10/08 20:50:38 guy Exp $
6 * Copyright 1999 Christophe Tronche <ch.tronche@computer.org>
8 * Ethereal - Network traffic analyzer
9 * By Gerald Combs <gerald@zing.org>
10 * Copyright 1998 Gerald Combs
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 #ifdef HAVE_SYS_TYPES_H
33 # include <sys/types.h>
36 #ifdef HAVE_NETINET_IN_H
37 # include <netinet/in.h>
47 /* #ifndef __PACKET_IP_H__ */
48 /* #include "packet-ip.h" */
51 /* Offsets of fields within a BPDU */
53 #define BPDU_IDENTIFIER 0
54 #define BPDU_VERSION_IDENTIFIER 2
57 #define BPDU_ROOT_IDENTIFIER 5
58 #define BPDU_ROOT_PATH_COST 13
59 #define BPDU_BRIDGE_IDENTIFIER 17
60 #define BPDU_PORT_IDENTIFIER 25
61 #define BPDU_MESSAGE_AGE 27
62 #define BPDU_MAX_AGE 29
63 #define BPDU_HELLO_TIME 31
64 #define BPDU_FORWARD_DELAY 33
66 static int proto_bpdu = -1;
68 void dissect_bpdu(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
69 guint16 protocol_identifier;
70 guint8 protocol_version_identifier;
73 guint16 root_identifier_bridge_priority;
74 gchar *root_identifier_mac;
75 guint32 root_path_cost;
76 guint16 bridge_identifier_bridge_priority;
77 gchar *bridge_identifier_mac;
78 guint16 port_identifier;
84 proto_tree *bpdu_tree;
89 bpdu_type = (guint8) bpdu[BPDU_TYPE];
90 flags = (guint8) bpdu[BPDU_FLAGS];
91 root_identifier_bridge_priority = pntohs(bpdu + BPDU_ROOT_IDENTIFIER);
92 root_identifier_mac = ether_to_str(bpdu + BPDU_ROOT_IDENTIFIER + 2);
93 root_path_cost = pntohl(bpdu + BPDU_ROOT_PATH_COST);
94 port_identifier = pntohs(bpdu + BPDU_PORT_IDENTIFIER);
96 if (check_col(fd, COL_PROTOCOL)) {
97 col_add_str(fd, COL_PROTOCOL, "STP"); /* Spanning Tree Protocol */
100 if (check_col(fd, COL_INFO)) {
102 col_add_fstr(fd, COL_INFO, "Conf. %sRoot = %d/%s Cost = %d Port = 0x%04x",
103 flags & 0x1 ? "TC + " : "",
104 root_identifier_bridge_priority, root_identifier_mac, root_path_cost,
106 else if (bpdu_type == 0x80)
107 col_add_fstr(fd, COL_INFO, "Topology Change Notification");
111 protocol_identifier = pntohs(bpdu + BPDU_IDENTIFIER);
112 protocol_version_identifier = (guint8) bpdu[BPDU_VERSION_IDENTIFIER];
114 ti = proto_tree_add_item_format(tree, proto_bpdu, offset, 35, NULL, "Spanning Tree Protocol");
115 bpdu_tree = proto_item_add_subtree(ti, ETT_BPDU);
116 proto_tree_add_text(bpdu_tree, offset + BPDU_IDENTIFIER, 2, "Protocol Identifier: 0x%04x (%s)",
118 protocol_identifier == 0 ? "Spanning Tree" : "Unknown Protocol");
120 proto_tree_add_text(bpdu_tree, offset + BPDU_VERSION_IDENTIFIER, 1, "Protocol Version Identifier: %d", protocol_version_identifier);
121 if (protocol_version_identifier != 0)
122 proto_tree_add_text(bpdu_tree, offset + BPDU_VERSION_IDENTIFIER, 1, " (Warning: this version of packet-bpdu only knows about version = 0)");
123 proto_tree_add_text(bpdu_tree, offset + BPDU_TYPE, 1, "BPDU Type: 0x%02x (%s)",
125 bpdu_type == 0 ? "Configuration" :
126 bpdu_type == 0x80 ? "Topology Change Notification" : "Unknown");
128 if (bpdu_type != 0) return;
130 bridge_identifier_bridge_priority = pntohs(bpdu + BPDU_BRIDGE_IDENTIFIER);
131 bridge_identifier_mac = ether_to_str(bpdu + BPDU_BRIDGE_IDENTIFIER + 2);
132 message_age = pntohs(bpdu + BPDU_MESSAGE_AGE) / 256.0;
133 max_age = pntohs(bpdu + BPDU_MAX_AGE) / 256.0;
134 hello_time = pntohs(bpdu + BPDU_HELLO_TIME) / 256.0;
135 forward_delay = pntohs(bpdu + BPDU_FORWARD_DELAY) / 256.0;
137 proto_tree_add_text(bpdu_tree, offset + BPDU_FLAGS, 1, "Flags: 0x%02x", flags);
139 proto_tree_add_text(bpdu_tree, offset + BPDU_FLAGS, 1, " 1... .... Topology Change Acknowledgment");
141 proto_tree_add_text(bpdu_tree, offset + BPDU_FLAGS, 1, " .... ...1 Topology Change");
143 proto_tree_add_text(bpdu_tree, offset + BPDU_ROOT_IDENTIFIER, 8, "Root Identifier: %d / %s", root_identifier_bridge_priority, root_identifier_mac);
144 proto_tree_add_text(bpdu_tree, offset + BPDU_ROOT_PATH_COST, 4, "Root Path Cost: %d", root_path_cost);
145 proto_tree_add_text(bpdu_tree, offset + BPDU_BRIDGE_IDENTIFIER, 8, "Bridge Identifier: %d / %s",
146 bridge_identifier_bridge_priority,
147 bridge_identifier_mac);
148 proto_tree_add_text(bpdu_tree, offset + BPDU_PORT_IDENTIFIER, 2, "Port identifier: 0x%04x", port_identifier);
149 proto_tree_add_text(bpdu_tree, offset + BPDU_MESSAGE_AGE, 2, "Message Age: %f", message_age);
150 proto_tree_add_text(bpdu_tree, offset + BPDU_MAX_AGE, 2, "Max Age: %f", max_age);
151 proto_tree_add_text(bpdu_tree, offset + BPDU_HELLO_TIME, 2, "Hello Time: %f", hello_time);
152 proto_tree_add_text(bpdu_tree, offset + BPDU_FORWARD_DELAY, 2, "Forward Delay: %f", forward_delay);
157 proto_register_bpdu(void)
159 proto_bpdu = proto_register_protocol("Spanning Tree Protocol", "STP");