2 * Routines for BPDU (Spanning Tree Protocol) disassembly
4 * $Id: packet-bpdu.c,v 1.7 2000/01/16 02:54:44 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>
46 /* Offsets of fields within a BPDU */
48 #define BPDU_IDENTIFIER 0
49 #define BPDU_VERSION_IDENTIFIER 2
52 #define BPDU_ROOT_IDENTIFIER 5
53 #define BPDU_ROOT_PATH_COST 13
54 #define BPDU_BRIDGE_IDENTIFIER 17
55 #define BPDU_PORT_IDENTIFIER 25
56 #define BPDU_MESSAGE_AGE 27
57 #define BPDU_MAX_AGE 29
58 #define BPDU_HELLO_TIME 31
59 #define BPDU_FORWARD_DELAY 33
61 static int proto_bpdu = -1;
62 static int hf_bpdu_proto_id = -1;
63 static int hf_bpdu_version_id = -1;
64 static int hf_bpdu_type = -1;
65 static int hf_bpdu_flags = -1;
66 static int hf_bpdu_root_mac = -1;
67 static int hf_bpdu_root_cost = -1;
68 static int hf_bpdu_bridge_mac = -1;
69 static int hf_bpdu_port_id = -1;
70 static int hf_bpdu_msg_age = -1;
71 static int hf_bpdu_max_age = -1;
72 static int hf_bpdu_hello_time = -1;
73 static int hf_bpdu_forward_delay = -1;
75 static gint ett_bpdu = -1;
77 void dissect_bpdu(const u_char *pd, int offset, frame_data *fd, proto_tree *tree) {
78 guint16 protocol_identifier;
79 guint8 protocol_version_identifier;
82 guint16 root_identifier_bridge_priority;
83 gchar *root_identifier_mac;
84 guint32 root_path_cost;
85 guint16 bridge_identifier_bridge_priority;
86 gchar *bridge_identifier_mac;
87 guint16 port_identifier;
93 proto_tree *bpdu_tree;
98 bpdu_type = (guint8) bpdu[BPDU_TYPE];
99 flags = (guint8) bpdu[BPDU_FLAGS];
100 root_identifier_bridge_priority = pntohs(bpdu + BPDU_ROOT_IDENTIFIER);
101 root_identifier_mac = ether_to_str(bpdu + BPDU_ROOT_IDENTIFIER + 2);
102 root_path_cost = pntohl(bpdu + BPDU_ROOT_PATH_COST);
103 port_identifier = pntohs(bpdu + BPDU_PORT_IDENTIFIER);
105 if (check_col(fd, COL_PROTOCOL)) {
106 col_add_str(fd, COL_PROTOCOL, "STP"); /* Spanning Tree Protocol */
109 if (check_col(fd, COL_INFO)) {
111 col_add_fstr(fd, COL_INFO, "Conf. %sRoot = %d/%s Cost = %d Port = 0x%04x",
112 flags & 0x1 ? "TC + " : "",
113 root_identifier_bridge_priority, root_identifier_mac, root_path_cost,
115 else if (bpdu_type == 0x80)
116 col_add_fstr(fd, COL_INFO, "Topology Change Notification");
120 protocol_identifier = pntohs(bpdu + BPDU_IDENTIFIER);
121 protocol_version_identifier = (guint8) bpdu[BPDU_VERSION_IDENTIFIER];
123 ti = proto_tree_add_item_format(tree, proto_bpdu, offset, 35, NULL, "Spanning Tree Protocol");
124 bpdu_tree = proto_item_add_subtree(ti, ett_bpdu);
125 proto_tree_add_item_format(bpdu_tree, hf_bpdu_proto_id,
126 offset + BPDU_IDENTIFIER, 2,
128 "Protocol Identifier: 0x%04x (%s)",
130 protocol_identifier == 0 ?
131 "Spanning Tree" : "Unknown Protocol");
133 proto_tree_add_item(bpdu_tree, hf_bpdu_version_id,
134 offset + BPDU_VERSION_IDENTIFIER, 1,
135 protocol_version_identifier);
136 if (protocol_version_identifier != 0)
137 proto_tree_add_text(bpdu_tree, offset + BPDU_VERSION_IDENTIFIER, 1, " (Warning: this version of packet-bpdu only knows about version = 0)");
138 proto_tree_add_item_format(bpdu_tree, hf_bpdu_type,
139 offset + BPDU_TYPE, 1,
141 "BPDU Type: 0x%02x (%s)",
143 bpdu_type == 0 ? "Configuration" :
144 bpdu_type == 0x80 ? "Topology Change Notification" : "Unknown");
146 if (bpdu_type != 0) {
147 dissect_data(pd, offset + BPDU_TYPE + 1, fd, tree);
151 bridge_identifier_bridge_priority = pntohs(bpdu + BPDU_BRIDGE_IDENTIFIER);
152 bridge_identifier_mac = ether_to_str(bpdu + BPDU_BRIDGE_IDENTIFIER + 2);
153 message_age = pntohs(bpdu + BPDU_MESSAGE_AGE) / 256.0;
154 max_age = pntohs(bpdu + BPDU_MAX_AGE) / 256.0;
155 hello_time = pntohs(bpdu + BPDU_HELLO_TIME) / 256.0;
156 forward_delay = pntohs(bpdu + BPDU_FORWARD_DELAY) / 256.0;
158 proto_tree_add_item(bpdu_tree, hf_bpdu_flags,
159 offset + BPDU_FLAGS, 1, flags);
161 proto_tree_add_text(bpdu_tree, offset + BPDU_FLAGS, 1, " 1... .... Topology Change Acknowledgment");
163 proto_tree_add_text(bpdu_tree, offset + BPDU_FLAGS, 1, " .... ...1 Topology Change");
165 proto_tree_add_item_hidden(bpdu_tree, hf_bpdu_root_mac,
166 offset + BPDU_ROOT_IDENTIFIER + 2, 6,
167 bpdu + BPDU_ROOT_IDENTIFIER + 2);
168 proto_tree_add_text(bpdu_tree,
169 offset + BPDU_ROOT_IDENTIFIER, 8,
170 "Root Identifier: %d / %s",
171 root_identifier_bridge_priority,
172 root_identifier_mac);
173 proto_tree_add_item(bpdu_tree, hf_bpdu_root_cost,
174 offset + BPDU_ROOT_PATH_COST, 4,
176 proto_tree_add_text(bpdu_tree,
177 offset + BPDU_BRIDGE_IDENTIFIER, 8,
178 "Bridge Identifier: %d / %s",
179 bridge_identifier_bridge_priority,
180 bridge_identifier_mac);
181 proto_tree_add_item_hidden(bpdu_tree, hf_bpdu_bridge_mac,
182 offset + BPDU_BRIDGE_IDENTIFIER + 2, 6,
183 bpdu + BPDU_BRIDGE_IDENTIFIER + 2);
184 proto_tree_add_item(bpdu_tree, hf_bpdu_port_id,
185 offset + BPDU_PORT_IDENTIFIER, 2,
187 proto_tree_add_item(bpdu_tree, hf_bpdu_msg_age,
188 offset + BPDU_MESSAGE_AGE, 2,
190 proto_tree_add_item(bpdu_tree, hf_bpdu_max_age,
191 offset + BPDU_MAX_AGE, 2,
193 proto_tree_add_item(bpdu_tree, hf_bpdu_hello_time,
194 offset + BPDU_HELLO_TIME, 2,
196 proto_tree_add_item(bpdu_tree, hf_bpdu_forward_delay,
197 offset + BPDU_FORWARD_DELAY, 2,
203 proto_register_bpdu(void)
206 static hf_register_info hf[] = {
208 { "Protocol Identifier", "stp.protocol",
209 FT_UINT16, BASE_HEX, NULL, 0x0,
211 { &hf_bpdu_version_id,
212 { "Protocol Version Identifier", "stp.version",
213 FT_UINT8, BASE_DEC, NULL, 0x0,
216 { "BPDU type", "stp.type",
217 FT_UINT8, BASE_HEX, NULL, 0x0,
220 { "BPDU flags", "stp.flags",
221 FT_UINT8, BASE_HEX, NULL, 0x0,
224 { "Root Identifier", "stp.root.hw",
225 FT_ETHER, BASE_NONE, NULL, 0x0,
227 { &hf_bpdu_root_cost,
228 { "Root Path Cost", "stp.root.cost",
229 FT_UINT32, BASE_DEC, NULL, 0x0,
231 { &hf_bpdu_bridge_mac,
232 { "Bridge Identifier", "stp.bridge.hw",
233 FT_ETHER, BASE_NONE, NULL, 0x0,
236 { "Port identifier", "stp.port",
237 FT_UINT16, BASE_HEX, NULL, 0x0,
240 { "Message Age", "stp.msg_age",
241 FT_DOUBLE, BASE_NONE, NULL, 0x0,
244 { "Max Age", "stp.max_age",
245 FT_DOUBLE, BASE_NONE, NULL, 0x0,
247 { &hf_bpdu_hello_time,
248 { "Hello Time", "stp.hello",
249 FT_DOUBLE, BASE_NONE, NULL, 0x0,
251 { &hf_bpdu_forward_delay,
252 { "Forward Delay", "stp.forward",
253 FT_DOUBLE, BASE_NONE, NULL, 0x0,
256 static gint *ett[] = {
260 proto_bpdu = proto_register_protocol("Spanning Tree Protocol", "stp");
261 proto_register_field_array(proto_bpdu, hf, array_length(hf));
262 proto_register_subtree_array(ett, array_length(ett));