28
28
#include "addrtoname.h"
29
29
#include "extract.h"
31
#define RSTP_EXTRACT_PORT_ROLE(x) (((x)&0x0C)>>2)
32
/* STP timers are expressed in multiples of 1/256th second */
33
#define STP_TIME_BASE 256
34
#define STP_BPDU_MSTP_MIN_LEN 102
37
u_int8_t protocol_id[2];
38
u_int8_t protocol_version;
42
u_int8_t root_path_cost[4];
43
u_int8_t bridge_id[8];
45
u_int8_t message_age[2];
47
u_int8_t hello_time[2];
48
u_int8_t forward_delay[2];
52
#define STP_PROTO_REGULAR 0x00
53
#define STP_PROTO_RAPID 0x02
54
#define STP_PROTO_MSTP 0x03
56
struct tok stp_proto_values[] = {
57
{ STP_PROTO_REGULAR, "802.1d" },
58
{ STP_PROTO_RAPID, "802.1w" },
59
{ STP_PROTO_MSTP, "802.1s" },
63
#define STP_BPDU_TYPE_CONFIG 0x00
64
#define STP_BPDU_TYPE_RSTP 0x02
65
#define STP_BPDU_TYPE_TOPO_CHANGE 0x80
67
struct tok stp_bpdu_flag_values[] = {
68
{ 0x01, "Topology change" },
72
{ 0x40, "Agreement" },
73
{ 0x80, "Topology change ACK" },
77
struct tok stp_bpdu_type_values[] = {
78
{ STP_BPDU_TYPE_CONFIG, "Config" },
79
{ STP_BPDU_TYPE_RSTP, "Rapid STP" },
80
{ STP_BPDU_TYPE_TOPO_CHANGE, "Topology Change" },
84
struct tok rstp_obj_port_role_values[] = {
86
{ 0x01, "Alternate" },
88
{ 0x03, "Designated" },
32
93
stp_print_bridge_id(const u_char *p)
34
printf("%.2x%.2x.%.2x:%.2x:%.2x:%.2x:%.2x:%.2x",
35
p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]);
39
stp_print_config_bpdu(const u_char *p)
43
printf("TOP_CHANGE ");
45
printf("TOP_CHANGE_ACK ");
47
stp_print_bridge_id(p+17);
48
printf(".%.2x%.2x ", p[25], p[26]);
51
stp_print_bridge_id(p+5);
53
printf(" pathcost %i ", (p[13] << 24) | (p[14] << 16) | (p[15] << 8) | p[16]);
55
printf("age %i ", p[27]);
56
printf("max %i ", p[29]);
57
printf("hello %i ", p[31]);
58
printf("fdelay %i ", p[33]);
62
stp_print_tcn_bpdu(void)
68
* Print 802.1d packets.
95
static char bridge_id_str[sizeof("pppp.aa:bb:cc:dd:ee:ff")];
97
snprintf(bridge_id_str, sizeof(bridge_id_str),
98
"%.2x%.2x.%.2x:%.2x:%.2x:%.2x:%.2x:%.2x",
99
p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]);
101
return bridge_id_str;
105
stp_print_config_bpdu(const struct stp_bpdu_ *stp_bpdu, u_int length)
107
printf(", Flags [%s]",
108
bittok2str(stp_bpdu_flag_values, "none", stp_bpdu->flags));
110
printf(", bridge-id %s.%04x, length %u",
111
stp_print_bridge_id((const u_char *)&stp_bpdu->bridge_id),
112
EXTRACT_16BITS(&stp_bpdu->port_id), length);
114
/* in non-verbose mode just print the bridge-id */
119
printf("\n\tmessage-age %.2fs, max-age %.2fs"
120
", hello-time %.2fs, forwarding-delay %.2fs",
121
(float)EXTRACT_16BITS(&stp_bpdu->message_age) / STP_TIME_BASE,
122
(float)EXTRACT_16BITS(&stp_bpdu->max_age) / STP_TIME_BASE,
123
(float)EXTRACT_16BITS(&stp_bpdu->hello_time) / STP_TIME_BASE,
124
(float)EXTRACT_16BITS(&stp_bpdu->forward_delay) / STP_TIME_BASE);
126
printf("\n\troot-id %s, root-pathcost %u",
127
stp_print_bridge_id((const u_char *)&stp_bpdu->root_id),
128
EXTRACT_32BITS(&stp_bpdu->root_path_cost));
130
/* Port role is only valid for 802.1w */
131
if (stp_bpdu->protocol_version == STP_PROTO_RAPID) {
132
printf(", port-role %s",
133
tok2str(rstp_obj_port_role_values, "Unknown",
134
RSTP_EXTRACT_PORT_ROLE(stp_bpdu->flags)));
140
* Ref. IEEE 802.1Q 2003 Ed. Section 14
144
* 2 - bytes Protocol Id
145
* 1 - byte Protocol Ver.
148
* 8 - bytes CIST Root Identifier
149
* 4 - bytes CIST External Path Cost
150
* 8 - bytes CIST Regional Root Identifier
151
* 2 - bytes CIST Port Identifier
152
* 2 - bytes Message Age
154
* 2 - bytes Hello Time
155
* 2 - bytes Forward delay
156
* 1 - byte Version 1 length. Must be 0
157
* 2 - bytes Version 3 length
158
* 1 - byte Config Identifier
159
* 32 - bytes Config Name
160
* 2 - bytes Revision level
161
* 16 - bytes Config Digest [MD5]
162
* 4 - bytes CIST Internal Root Path Cost
163
* 8 - bytes CIST Bridge Identifier
164
* 1 - byte CIST Remaining Hops
165
* 16 - bytes MSTI information [Max 64 MSTI, each 16 bytes]
170
* 8 - bytes MSTI Regional Root Identifier
171
* 4 - bytes MSTI Regional Path Cost
172
* 1 - byte MSTI Bridge Priority
173
* 1 - byte MSTI Port Priority
174
* 1 - byte MSTI Remaining Hops
177
#define MST_BPDU_MSTI_LENGTH 16
178
#define MST_BPDU_CONFIG_INFO_LENGTH 64
180
/* Offsets of fields from the begginning for the packet */
181
#define MST_BPDU_VER3_LEN_OFFSET 36
182
#define MST_BPDU_CONFIG_NAME_OFFSET 39
183
#define MST_BPDU_CONFIG_DIGEST_OFFSET 73
184
#define MST_BPDU_CIST_INT_PATH_COST_OFFSET 89
185
#define MST_BPDU_CIST_BRIDGE_ID_OFFSET 93
186
#define MST_BPDU_CIST_REMAIN_HOPS_OFFSET 101
187
#define MST_BPDU_MSTI_OFFSET 102
188
/* Offsets within an MSTI */
189
#define MST_BPDU_MSTI_ROOT_PRIO_OFFSET 1
190
#define MST_BPDU_MSTI_ROOT_PATH_COST_OFFSET 9
191
#define MST_BPDU_MSTI_BRIDGE_PRIO_OFFSET 13
192
#define MST_BPDU_MSTI_PORT_PRIO_OFFSET 14
193
#define MST_BPDU_MSTI_REMAIN_HOPS_OFFSET 15
196
stp_print_mstp_bpdu(const struct stp_bpdu_ *stp_bpdu, u_int length)
204
ptr = (const u_char *)stp_bpdu;
205
printf(", CIST Flags [%s]",
206
bittok2str(stp_bpdu_flag_values, "none", stp_bpdu->flags));
209
* in non-verbose mode just print the flags. We dont read that much
210
* of the packet (DEFAULT_SNAPLEN) to print out cist bridge-id
216
printf(", CIST bridge-id %s.%04x, length %u",
217
stp_print_bridge_id(ptr + MST_BPDU_CIST_BRIDGE_ID_OFFSET),
218
EXTRACT_16BITS(&stp_bpdu->port_id), length);
221
printf("\n\tmessage-age %.2fs, max-age %.2fs"
222
", hello-time %.2fs, forwarding-delay %.2fs",
223
(float)EXTRACT_16BITS(&stp_bpdu->message_age) / STP_TIME_BASE,
224
(float)EXTRACT_16BITS(&stp_bpdu->max_age) / STP_TIME_BASE,
225
(float)EXTRACT_16BITS(&stp_bpdu->hello_time) / STP_TIME_BASE,
226
(float)EXTRACT_16BITS(&stp_bpdu->forward_delay) / STP_TIME_BASE);
228
printf("\n\tCIST root-id %s, ext-pathcost %u int-pathcost %u",
229
stp_print_bridge_id((const u_char *)&stp_bpdu->root_id),
230
EXTRACT_32BITS(&stp_bpdu->root_path_cost),
231
EXTRACT_32BITS(ptr + MST_BPDU_CIST_INT_PATH_COST_OFFSET));
233
printf(", port-role %s",
234
tok2str(rstp_obj_port_role_values, "Unknown",
235
RSTP_EXTRACT_PORT_ROLE(stp_bpdu->flags)));
237
printf("\n\tCIST regional-root-id %s",
238
stp_print_bridge_id((const u_char *)&stp_bpdu->bridge_id));
240
printf("\n\tMSTP Configuration Name %s, revision %u, digest %08x%08x%08x%08x",
241
ptr + MST_BPDU_CONFIG_NAME_OFFSET,
242
EXTRACT_16BITS(ptr + MST_BPDU_CONFIG_NAME_OFFSET + 32),
243
EXTRACT_32BITS(ptr + MST_BPDU_CONFIG_DIGEST_OFFSET),
244
EXTRACT_32BITS(ptr + MST_BPDU_CONFIG_DIGEST_OFFSET + 4),
245
EXTRACT_32BITS(ptr + MST_BPDU_CONFIG_DIGEST_OFFSET + 8),
246
EXTRACT_32BITS(ptr + MST_BPDU_CONFIG_DIGEST_OFFSET + 12));
248
printf("\n\tCIST remaining-hops %d", ptr[MST_BPDU_CIST_REMAIN_HOPS_OFFSET]);
250
/* Dump all MSTI's */
251
v3len = EXTRACT_16BITS(ptr + MST_BPDU_VER3_LEN_OFFSET);
252
if (v3len > MST_BPDU_CONFIG_INFO_LENGTH) {
253
len = v3len - MST_BPDU_CONFIG_INFO_LENGTH;
254
offset = MST_BPDU_MSTI_OFFSET;
255
while (len >= MST_BPDU_MSTI_LENGTH) {
256
msti = EXTRACT_16BITS(ptr + offset +
257
MST_BPDU_MSTI_ROOT_PRIO_OFFSET);
258
msti = msti & 0x0FFF;
260
printf("\n\tMSTI %d, Flags [%s], port-role %s",
261
msti, bittok2str(stp_bpdu_flag_values, "none", ptr[offset]),
262
tok2str(rstp_obj_port_role_values, "Unknown",
263
RSTP_EXTRACT_PORT_ROLE(ptr[offset])));
264
printf("\n\t\tMSTI regional-root-id %s, pathcost %u",
265
stp_print_bridge_id(ptr + offset +
266
MST_BPDU_MSTI_ROOT_PRIO_OFFSET),
267
EXTRACT_32BITS(ptr + offset +
268
MST_BPDU_MSTI_ROOT_PATH_COST_OFFSET));
269
printf("\n\t\tMSTI bridge-prio %d, port-prio %d, hops %d",
270
ptr[offset + MST_BPDU_MSTI_BRIDGE_PRIO_OFFSET] >> 4,
271
ptr[offset + MST_BPDU_MSTI_PORT_PRIO_OFFSET] >> 4,
272
ptr[offset + MST_BPDU_MSTI_REMAIN_HOPS_OFFSET]);
274
len -= MST_BPDU_MSTI_LENGTH;
275
offset += MST_BPDU_MSTI_LENGTH;
281
* Print 802.1d / 802.1w / 802.1q (mstp) packets.
71
284
stp_print(const u_char *p, u_int length)
77
if (p[0] || p[1] || p[2]) {
78
printf("unknown version");
87
stp_print_config_bpdu(p);
95
printf("unknown type %i", p[3]);
101
printf("[|stp %d]", length);
286
const struct stp_bpdu_ *stp_bpdu;
289
stp_bpdu = (struct stp_bpdu_*)p;
291
/* Minimum STP Frame size. */
295
if (EXTRACT_16BITS(&stp_bpdu->protocol_id)) {
296
printf("unknown STP version, length %u", length);
300
printf("STP %s", tok2str(stp_proto_values, "Unknown STP protocol (0x%02x)",
301
stp_bpdu->protocol_version));
303
switch (stp_bpdu->protocol_version) {
304
case STP_PROTO_REGULAR:
305
case STP_PROTO_RAPID:
312
printf(", %s", tok2str(stp_bpdu_type_values, "Unknown BPDU Type (0x%02x)",
313
stp_bpdu->bpdu_type));
315
switch (stp_bpdu->bpdu_type) {
316
case STP_BPDU_TYPE_CONFIG:
317
if (length < sizeof(struct stp_bpdu_) - 1) {
320
stp_print_config_bpdu(stp_bpdu, length);
323
case STP_BPDU_TYPE_RSTP:
324
if (stp_bpdu->protocol_version == STP_PROTO_RAPID) {
325
if (length < sizeof(struct stp_bpdu_)) {
328
stp_print_config_bpdu(stp_bpdu, length);
329
} else if (stp_bpdu->protocol_version == STP_PROTO_MSTP) {
330
if (length < STP_BPDU_MSTP_MIN_LEN) {
333
if (stp_bpdu->v1_length != 0) {
334
/* FIX ME: Emit a message here ? */
337
/* Validate v3 length */
338
mstp_len = EXTRACT_16BITS(p + MST_BPDU_VER3_LEN_OFFSET);
339
mstp_len += 2; /* length encoding itself is 2 bytes */
340
if (length < (sizeof(struct stp_bpdu_) + mstp_len)) {
343
stp_print_mstp_bpdu(stp_bpdu, length);
347
case STP_BPDU_TYPE_TOPO_CHANGE:
348
/* always empty message - just break out */
357
printf("[|stp %d]", length);
362
* c-style: whitesmith