2000-06-11 04:57:55 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2000 Lennert Buytenhek
|
|
|
|
*
|
|
|
|
* This software may be distributed either under the terms of the
|
|
|
|
* BSD-style license that accompanies tcpdump or the GNU General
|
|
|
|
* Public License
|
|
|
|
*
|
|
|
|
* Contributed by Lennert Buytenhek <buytenh@gnu.org>
|
|
|
|
*/
|
|
|
|
|
2016-08-14 21:42:19 +08:00
|
|
|
/* \summary: IEEE 802.1d Spanning Tree Protocol (STP) printer */
|
|
|
|
|
2000-06-13 20:19:07 +08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2018-01-22 04:27:08 +08:00
|
|
|
#include <config.h>
|
2000-06-11 04:57:55 +08:00
|
|
|
#endif
|
|
|
|
|
2018-01-20 22:59:49 +08:00
|
|
|
#include "netdissect-stdinc.h"
|
2000-06-11 04:57:55 +08:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2015-09-06 05:35:58 +08:00
|
|
|
#include "netdissect.h"
|
2000-06-11 04:57:55 +08:00
|
|
|
#include "extract.h"
|
|
|
|
|
2014-01-02 10:27:54 +08:00
|
|
|
#define RSTP_EXTRACT_PORT_ROLE(x) (((x)&0x0C)>>2)
|
2007-03-06 23:03:51 +08:00
|
|
|
/* STP timers are expressed in multiples of 1/256th second */
|
|
|
|
#define STP_TIME_BASE 256
|
2007-03-08 21:49:46 +08:00
|
|
|
#define STP_BPDU_MSTP_MIN_LEN 102
|
2007-03-06 23:03:51 +08:00
|
|
|
|
|
|
|
struct stp_bpdu_ {
|
2017-12-31 10:37:50 +08:00
|
|
|
nd_uint16_t protocol_id;
|
|
|
|
nd_uint8_t protocol_version;
|
|
|
|
nd_uint8_t bpdu_type;
|
|
|
|
nd_uint8_t flags;
|
|
|
|
nd_byte root_id[8];
|
|
|
|
nd_uint32_t root_path_cost;
|
|
|
|
nd_byte bridge_id[8];
|
|
|
|
nd_uint16_t port_id;
|
|
|
|
nd_uint16_t message_age;
|
|
|
|
nd_uint16_t max_age;
|
|
|
|
nd_uint16_t hello_time;
|
|
|
|
nd_uint16_t forward_delay;
|
|
|
|
nd_uint8_t v1_length;
|
2007-03-06 23:03:51 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#define STP_PROTO_REGULAR 0x00
|
|
|
|
#define STP_PROTO_RAPID 0x02
|
2007-03-08 21:49:46 +08:00
|
|
|
#define STP_PROTO_MSTP 0x03
|
2012-10-04 23:02:12 +08:00
|
|
|
#define STP_PROTO_SPB 0x04
|
2007-03-06 23:03:51 +08:00
|
|
|
|
2013-09-25 00:46:24 +08:00
|
|
|
static const struct tok stp_proto_values[] = {
|
2007-03-06 23:03:51 +08:00
|
|
|
{ STP_PROTO_REGULAR, "802.1d" },
|
|
|
|
{ STP_PROTO_RAPID, "802.1w" },
|
2007-03-08 21:49:46 +08:00
|
|
|
{ STP_PROTO_MSTP, "802.1s" },
|
2012-10-04 23:02:12 +08:00
|
|
|
{ STP_PROTO_SPB, "802.1aq" },
|
2007-03-06 23:03:51 +08:00
|
|
|
{ 0, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
#define STP_BPDU_TYPE_CONFIG 0x00
|
|
|
|
#define STP_BPDU_TYPE_RSTP 0x02
|
|
|
|
#define STP_BPDU_TYPE_TOPO_CHANGE 0x80
|
|
|
|
|
2013-09-25 00:46:24 +08:00
|
|
|
static const struct tok stp_bpdu_flag_values[] = {
|
2007-03-06 23:03:51 +08:00
|
|
|
{ 0x01, "Topology change" },
|
|
|
|
{ 0x02, "Proposal" },
|
|
|
|
{ 0x10, "Learn" },
|
|
|
|
{ 0x20, "Forward" },
|
|
|
|
{ 0x40, "Agreement" },
|
|
|
|
{ 0x80, "Topology change ACK" },
|
|
|
|
{ 0, NULL}
|
|
|
|
};
|
|
|
|
|
2013-09-25 00:46:24 +08:00
|
|
|
static const struct tok stp_bpdu_type_values[] = {
|
2007-03-06 23:03:51 +08:00
|
|
|
{ STP_BPDU_TYPE_CONFIG, "Config" },
|
2007-03-07 20:10:54 +08:00
|
|
|
{ STP_BPDU_TYPE_RSTP, "Rapid STP" },
|
2007-03-06 23:03:51 +08:00
|
|
|
{ STP_BPDU_TYPE_TOPO_CHANGE, "Topology Change" },
|
|
|
|
{ 0, NULL}
|
|
|
|
};
|
|
|
|
|
2013-09-25 00:46:24 +08:00
|
|
|
static const struct tok rstp_obj_port_role_values[] = {
|
2007-03-06 23:03:51 +08:00
|
|
|
{ 0x00, "Unknown" },
|
|
|
|
{ 0x01, "Alternate" },
|
|
|
|
{ 0x02, "Root" },
|
|
|
|
{ 0x03, "Designated" },
|
|
|
|
{ 0, NULL}
|
|
|
|
};
|
|
|
|
|
2017-11-30 04:06:51 +08:00
|
|
|
#define ND_TCHECK_BRIDGE_ID(p) ND_TCHECK_8(p)
|
2015-07-08 02:56:48 +08:00
|
|
|
|
2007-03-06 23:03:51 +08:00
|
|
|
static char *
|
2000-06-11 04:57:55 +08:00
|
|
|
stp_print_bridge_id(const u_char *p)
|
|
|
|
{
|
2007-03-06 23:03:51 +08:00
|
|
|
static char bridge_id_str[sizeof("pppp.aa:bb:cc:dd:ee:ff")];
|
2000-06-11 04:57:55 +08:00
|
|
|
|
2018-01-30 07:48:55 +08:00
|
|
|
nd_snprintf(bridge_id_str, sizeof(bridge_id_str),
|
2007-03-06 23:03:51 +08:00
|
|
|
"%.2x%.2x.%.2x:%.2x:%.2x:%.2x:%.2x:%.2x",
|
2017-12-01 22:19:56 +08:00
|
|
|
EXTRACT_U_1(p), EXTRACT_U_1(p + 1), EXTRACT_U_1(p + 2),
|
|
|
|
EXTRACT_U_1(p + 3), EXTRACT_U_1(p + 4), EXTRACT_U_1(p + 5),
|
|
|
|
EXTRACT_U_1(p + 6), EXTRACT_U_1(p + 7));
|
2000-06-11 04:57:55 +08:00
|
|
|
|
2007-03-06 23:03:51 +08:00
|
|
|
return bridge_id_str;
|
2000-06-11 04:57:55 +08:00
|
|
|
}
|
|
|
|
|
2015-07-08 02:56:48 +08:00
|
|
|
static int
|
2014-03-16 03:25:06 +08:00
|
|
|
stp_print_config_bpdu(netdissect_options *ndo, const struct stp_bpdu_ *stp_bpdu,
|
|
|
|
u_int length)
|
2000-06-11 04:57:55 +08:00
|
|
|
{
|
2017-12-31 10:37:50 +08:00
|
|
|
uint8_t bpdu_flags;
|
|
|
|
|
2018-01-08 04:51:55 +08:00
|
|
|
ND_TCHECK_1(stp_bpdu->flags);
|
2017-12-31 10:37:50 +08:00
|
|
|
bpdu_flags = EXTRACT_U_1(stp_bpdu->flags);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(", Flags [%s]",
|
|
|
|
bittok2str(stp_bpdu_flag_values, "none", bpdu_flags));
|
2007-03-06 23:03:51 +08:00
|
|
|
|
2018-01-08 04:51:55 +08:00
|
|
|
ND_TCHECK_2(stp_bpdu->port_id);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(", bridge-id %s.%04x, length %u",
|
2007-03-06 23:03:51 +08:00
|
|
|
stp_print_bridge_id((const u_char *)&stp_bpdu->bridge_id),
|
2018-01-07 18:47:30 +08:00
|
|
|
EXTRACT_BE_U_2(stp_bpdu->port_id), length);
|
2007-03-06 23:03:51 +08:00
|
|
|
|
|
|
|
/* in non-verbose mode just print the bridge-id */
|
2014-03-16 03:25:06 +08:00
|
|
|
if (!ndo->ndo_vflag) {
|
2015-07-08 02:56:48 +08:00
|
|
|
return 1;
|
2007-03-06 23:03:51 +08:00
|
|
|
}
|
|
|
|
|
2018-01-08 04:51:55 +08:00
|
|
|
ND_TCHECK_2(stp_bpdu->forward_delay);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("\n\tmessage-age %.2fs, max-age %.2fs"
|
2007-03-06 23:03:51 +08:00
|
|
|
", hello-time %.2fs, forwarding-delay %.2fs",
|
2017-12-31 10:37:50 +08:00
|
|
|
(float) EXTRACT_BE_U_2(stp_bpdu->message_age) / STP_TIME_BASE,
|
|
|
|
(float) EXTRACT_BE_U_2(stp_bpdu->max_age) / STP_TIME_BASE,
|
|
|
|
(float) EXTRACT_BE_U_2(stp_bpdu->hello_time) / STP_TIME_BASE,
|
2018-01-07 18:47:30 +08:00
|
|
|
(float) EXTRACT_BE_U_2(stp_bpdu->forward_delay) / STP_TIME_BASE);
|
2007-03-06 23:03:51 +08:00
|
|
|
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("\n\troot-id %s, root-pathcost %u",
|
2007-03-06 23:03:51 +08:00
|
|
|
stp_print_bridge_id((const u_char *)&stp_bpdu->root_id),
|
2018-01-07 18:47:30 +08:00
|
|
|
EXTRACT_BE_U_4(stp_bpdu->root_path_cost));
|
2007-03-06 23:03:51 +08:00
|
|
|
|
|
|
|
/* Port role is only valid for 802.1w */
|
2017-12-31 10:37:50 +08:00
|
|
|
if (EXTRACT_U_1(stp_bpdu->protocol_version) == STP_PROTO_RAPID) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(", port-role %s",
|
2007-03-06 23:03:51 +08:00
|
|
|
tok2str(rstp_obj_port_role_values, "Unknown",
|
2018-01-07 18:47:30 +08:00
|
|
|
RSTP_EXTRACT_PORT_ROLE(bpdu_flags)));
|
2007-03-06 23:03:51 +08:00
|
|
|
}
|
2015-07-08 02:56:48 +08:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
trunc:
|
|
|
|
return 0;
|
2000-06-11 04:57:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-03-08 21:49:46 +08:00
|
|
|
* MSTP packet format
|
|
|
|
* Ref. IEEE 802.1Q 2003 Ed. Section 14
|
|
|
|
*
|
|
|
|
* MSTP BPDU
|
|
|
|
*
|
|
|
|
* 2 - bytes Protocol Id
|
2014-01-02 10:27:54 +08:00
|
|
|
* 1 - byte Protocol Ver.
|
2007-03-08 21:49:46 +08:00
|
|
|
* 1 - byte BPDU tye
|
|
|
|
* 1 - byte Flags
|
|
|
|
* 8 - bytes CIST Root Identifier
|
|
|
|
* 4 - bytes CIST External Path Cost
|
|
|
|
* 8 - bytes CIST Regional Root Identifier
|
|
|
|
* 2 - bytes CIST Port Identifier
|
|
|
|
* 2 - bytes Message Age
|
|
|
|
* 2 - bytes Max age
|
|
|
|
* 2 - bytes Hello Time
|
|
|
|
* 2 - bytes Forward delay
|
|
|
|
* 1 - byte Version 1 length. Must be 0
|
|
|
|
* 2 - bytes Version 3 length
|
|
|
|
* 1 - byte Config Identifier
|
|
|
|
* 32 - bytes Config Name
|
|
|
|
* 2 - bytes Revision level
|
|
|
|
* 16 - bytes Config Digest [MD5]
|
|
|
|
* 4 - bytes CIST Internal Root Path Cost
|
|
|
|
* 8 - bytes CIST Bridge Identifier
|
|
|
|
* 1 - byte CIST Remaining Hops
|
|
|
|
* 16 - bytes MSTI information [Max 64 MSTI, each 16 bytes]
|
2012-10-05 13:41:22 +08:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* SPB BPDU
|
|
|
|
* Ref. IEEE 802.1aq. Section 14
|
|
|
|
*
|
|
|
|
* 2 - bytes Version 4 length
|
2014-01-02 10:27:54 +08:00
|
|
|
* 1 - byte Aux Config Identifier
|
2012-10-05 13:41:22 +08:00
|
|
|
* 32 - bytes Aux Config Name
|
|
|
|
* 2 - bytes Aux Revision level
|
|
|
|
* 16 - bytes Aux Config Digest [MD5]
|
2014-01-02 10:27:54 +08:00
|
|
|
* 1 - byte (1 - 2) Agreement Number
|
2012-10-05 13:41:22 +08:00
|
|
|
* (3 - 4) Discarded Agreement Number
|
|
|
|
* (5) Agreement Valid Flag
|
|
|
|
* (6) Restricted Role Flag
|
|
|
|
* (7 - 8) Unused sent zero
|
|
|
|
* 1 - byte Unused
|
2012-10-08 11:12:40 +08:00
|
|
|
* 1 - byte (1 - 4) Agreement Digest Format Identifier
|
|
|
|
* (5 - 8) Agreement Digest Format Capabilities
|
|
|
|
* 1 - byte (1 - 4) Agreement Digest Convention Identifier
|
|
|
|
* (5 - 8) Agreement Digest Convention Capabilities
|
|
|
|
* 2 - bytes Agreement Digest Edge Count
|
|
|
|
* 8 - byte Reserved Set
|
|
|
|
* 20 - bytes Computed Topology Digest
|
2012-10-05 13:41:22 +08:00
|
|
|
*
|
2007-03-08 21:49:46 +08:00
|
|
|
*
|
|
|
|
* MSTI Payload
|
|
|
|
*
|
|
|
|
* 1 - byte MSTI flag
|
|
|
|
* 8 - bytes MSTI Regional Root Identifier
|
|
|
|
* 4 - bytes MSTI Regional Path Cost
|
|
|
|
* 1 - byte MSTI Bridge Priority
|
|
|
|
* 1 - byte MSTI Port Priority
|
|
|
|
* 1 - byte MSTI Remaining Hops
|
2012-10-05 13:41:22 +08:00
|
|
|
*
|
2007-03-08 21:49:46 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define MST_BPDU_MSTI_LENGTH 16
|
|
|
|
#define MST_BPDU_CONFIG_INFO_LENGTH 64
|
|
|
|
|
|
|
|
/* Offsets of fields from the begginning for the packet */
|
|
|
|
#define MST_BPDU_VER3_LEN_OFFSET 36
|
|
|
|
#define MST_BPDU_CONFIG_NAME_OFFSET 39
|
2007-03-10 02:58:48 +08:00
|
|
|
#define MST_BPDU_CONFIG_DIGEST_OFFSET 73
|
2007-03-08 21:49:46 +08:00
|
|
|
#define MST_BPDU_CIST_INT_PATH_COST_OFFSET 89
|
|
|
|
#define MST_BPDU_CIST_BRIDGE_ID_OFFSET 93
|
|
|
|
#define MST_BPDU_CIST_REMAIN_HOPS_OFFSET 101
|
|
|
|
#define MST_BPDU_MSTI_OFFSET 102
|
|
|
|
/* Offsets within an MSTI */
|
|
|
|
#define MST_BPDU_MSTI_ROOT_PRIO_OFFSET 1
|
|
|
|
#define MST_BPDU_MSTI_ROOT_PATH_COST_OFFSET 9
|
|
|
|
#define MST_BPDU_MSTI_BRIDGE_PRIO_OFFSET 13
|
|
|
|
#define MST_BPDU_MSTI_PORT_PRIO_OFFSET 14
|
|
|
|
#define MST_BPDU_MSTI_REMAIN_HOPS_OFFSET 15
|
|
|
|
|
2012-10-04 23:02:12 +08:00
|
|
|
#define SPB_BPDU_MIN_LEN 87
|
|
|
|
#define SPB_BPDU_CONFIG_NAME_OFFSET 3
|
|
|
|
#define SPB_BPDU_CONFIG_REV_OFFSET SPB_BPDU_CONFIG_NAME_OFFSET + 32
|
|
|
|
#define SPB_BPDU_CONFIG_DIGEST_OFFSET SPB_BPDU_CONFIG_REV_OFFSET + 2
|
|
|
|
#define SPB_BPDU_AGREEMENT_OFFSET SPB_BPDU_CONFIG_DIGEST_OFFSET + 16
|
2012-10-05 13:41:22 +08:00
|
|
|
#define SPB_BPDU_AGREEMENT_UNUSED_OFFSET SPB_BPDU_AGREEMENT_OFFSET + 1
|
|
|
|
#define SPB_BPDU_AGREEMENT_FORMAT_OFFSET SPB_BPDU_AGREEMENT_UNUSED_OFFSET + 1
|
|
|
|
#define SPB_BPDU_AGREEMENT_CON_OFFSET SPB_BPDU_AGREEMENT_FORMAT_OFFSET + 1
|
2012-10-04 23:02:12 +08:00
|
|
|
#define SPB_BPDU_AGREEMENT_EDGE_OFFSET SPB_BPDU_AGREEMENT_CON_OFFSET + 1
|
2012-10-05 13:41:22 +08:00
|
|
|
#define SPB_BPDU_AGREEMENT_RES1_OFFSET SPB_BPDU_AGREEMENT_EDGE_OFFSET + 2
|
|
|
|
#define SPB_BPDU_AGREEMENT_RES2_OFFSET SPB_BPDU_AGREEMENT_RES1_OFFSET + 4
|
|
|
|
#define SPB_BPDU_AGREEMENT_DIGEST_OFFSET SPB_BPDU_AGREEMENT_RES2_OFFSET + 4
|
2012-10-04 23:02:12 +08:00
|
|
|
|
2015-07-08 02:56:48 +08:00
|
|
|
static int
|
2014-03-16 03:25:06 +08:00
|
|
|
stp_print_mstp_bpdu(netdissect_options *ndo, const struct stp_bpdu_ *stp_bpdu,
|
|
|
|
u_int length)
|
2007-03-08 21:49:46 +08:00
|
|
|
{
|
2012-10-05 13:41:22 +08:00
|
|
|
const u_char *ptr;
|
2017-12-31 10:37:50 +08:00
|
|
|
uint8_t bpdu_flags;
|
2014-04-23 15:20:40 +08:00
|
|
|
uint16_t v3len;
|
|
|
|
uint16_t len;
|
|
|
|
uint16_t msti;
|
2013-03-26 17:35:14 +08:00
|
|
|
u_int offset;
|
2007-03-08 21:49:46 +08:00
|
|
|
|
|
|
|
ptr = (const u_char *)stp_bpdu;
|
2018-01-08 04:51:55 +08:00
|
|
|
ND_TCHECK_1(stp_bpdu->flags);
|
2017-12-31 10:37:50 +08:00
|
|
|
bpdu_flags = EXTRACT_U_1(stp_bpdu->flags);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(", CIST Flags [%s], length %u",
|
|
|
|
bittok2str(stp_bpdu_flag_values, "none", bpdu_flags), length);
|
2007-03-08 21:49:46 +08:00
|
|
|
|
|
|
|
/*
|
2013-03-27 16:18:58 +08:00
|
|
|
* in non-verbose mode just print the flags.
|
2007-03-08 21:49:46 +08:00
|
|
|
*/
|
2014-03-16 03:25:06 +08:00
|
|
|
if (!ndo->ndo_vflag) {
|
2015-07-08 02:56:48 +08:00
|
|
|
return 1;
|
2007-03-08 21:49:46 +08:00
|
|
|
}
|
|
|
|
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("\n\tport-role %s, ",
|
2012-10-05 13:41:22 +08:00
|
|
|
tok2str(rstp_obj_port_role_values, "Unknown",
|
2018-01-07 18:47:30 +08:00
|
|
|
RSTP_EXTRACT_PORT_ROLE(bpdu_flags)));
|
2007-03-08 21:49:46 +08:00
|
|
|
|
2018-01-08 04:51:55 +08:00
|
|
|
ND_TCHECK_4(stp_bpdu->root_path_cost);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("CIST root-id %s, CIST ext-pathcost %u",
|
2012-10-05 13:41:22 +08:00
|
|
|
stp_print_bridge_id((const u_char *)&stp_bpdu->root_id),
|
2018-01-07 18:47:30 +08:00
|
|
|
EXTRACT_BE_U_4(stp_bpdu->root_path_cost));
|
2012-10-05 13:41:22 +08:00
|
|
|
|
2018-01-23 23:59:51 +08:00
|
|
|
ND_TCHECK_SIZE(&stp_bpdu->bridge_id);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("\n\tCIST regional-root-id %s, ",
|
|
|
|
stp_print_bridge_id((const u_char *)&stp_bpdu->bridge_id));
|
2012-10-05 13:41:22 +08:00
|
|
|
|
2018-01-08 04:51:55 +08:00
|
|
|
ND_TCHECK_2(stp_bpdu->port_id);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("CIST port-id %04x,", EXTRACT_BE_U_2(stp_bpdu->port_id));
|
2007-03-08 21:49:46 +08:00
|
|
|
|
2018-01-08 04:51:55 +08:00
|
|
|
ND_TCHECK_2(stp_bpdu->forward_delay);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("\n\tmessage-age %.2fs, max-age %.2fs"
|
2007-03-08 21:49:46 +08:00
|
|
|
", hello-time %.2fs, forwarding-delay %.2fs",
|
2017-12-31 10:37:50 +08:00
|
|
|
(float) EXTRACT_BE_U_2(stp_bpdu->message_age) / STP_TIME_BASE,
|
|
|
|
(float) EXTRACT_BE_U_2(stp_bpdu->max_age) / STP_TIME_BASE,
|
|
|
|
(float) EXTRACT_BE_U_2(stp_bpdu->hello_time) / STP_TIME_BASE,
|
2018-01-07 18:47:30 +08:00
|
|
|
(float) EXTRACT_BE_U_2(stp_bpdu->forward_delay) / STP_TIME_BASE);
|
2007-03-08 21:49:46 +08:00
|
|
|
|
2017-11-23 04:58:44 +08:00
|
|
|
ND_TCHECK_2(ptr + MST_BPDU_VER3_LEN_OFFSET);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("\n\tv3len %u, ", EXTRACT_BE_U_2(ptr + MST_BPDU_VER3_LEN_OFFSET));
|
2017-11-23 04:58:44 +08:00
|
|
|
ND_TCHECK_4(ptr + MST_BPDU_CONFIG_DIGEST_OFFSET + 12);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("MCID Name ");
|
2015-11-11 21:31:29 +08:00
|
|
|
if (fn_printzp(ndo, ptr + MST_BPDU_CONFIG_NAME_OFFSET, 32, ndo->ndo_snapend))
|
|
|
|
goto trunc;
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(", rev %u,"
|
2012-10-05 13:41:22 +08:00
|
|
|
"\n\t\tdigest %08x%08x%08x%08x, ",
|
2017-11-23 06:54:09 +08:00
|
|
|
EXTRACT_BE_U_2(ptr + MST_BPDU_CONFIG_NAME_OFFSET + 32),
|
|
|
|
EXTRACT_BE_U_4(ptr + MST_BPDU_CONFIG_DIGEST_OFFSET),
|
|
|
|
EXTRACT_BE_U_4(ptr + MST_BPDU_CONFIG_DIGEST_OFFSET + 4),
|
|
|
|
EXTRACT_BE_U_4(ptr + MST_BPDU_CONFIG_DIGEST_OFFSET + 8),
|
2018-01-07 18:47:30 +08:00
|
|
|
EXTRACT_BE_U_4(ptr + MST_BPDU_CONFIG_DIGEST_OFFSET + 12));
|
2007-03-08 21:49:46 +08:00
|
|
|
|
2017-11-23 04:58:44 +08:00
|
|
|
ND_TCHECK_4(ptr + MST_BPDU_CIST_INT_PATH_COST_OFFSET);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("CIST int-root-pathcost %u,",
|
|
|
|
EXTRACT_BE_U_4(ptr + MST_BPDU_CIST_INT_PATH_COST_OFFSET));
|
2007-03-08 21:49:46 +08:00
|
|
|
|
2015-07-08 02:56:48 +08:00
|
|
|
ND_TCHECK_BRIDGE_ID(ptr + MST_BPDU_CIST_BRIDGE_ID_OFFSET);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("\n\tCIST bridge-id %s, ",
|
|
|
|
stp_print_bridge_id(ptr + MST_BPDU_CIST_BRIDGE_ID_OFFSET));
|
2007-03-08 21:49:46 +08:00
|
|
|
|
2017-12-04 01:18:58 +08:00
|
|
|
ND_TCHECK_1(ptr + MST_BPDU_CIST_REMAIN_HOPS_OFFSET);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("CIST remaining-hops %u", EXTRACT_U_1(ptr + MST_BPDU_CIST_REMAIN_HOPS_OFFSET));
|
2007-03-08 21:49:46 +08:00
|
|
|
|
|
|
|
/* Dump all MSTI's */
|
2017-11-23 04:58:44 +08:00
|
|
|
ND_TCHECK_2(ptr + MST_BPDU_VER3_LEN_OFFSET);
|
2017-11-23 06:54:09 +08:00
|
|
|
v3len = EXTRACT_BE_U_2(ptr + MST_BPDU_VER3_LEN_OFFSET);
|
2007-03-08 21:49:46 +08:00
|
|
|
if (v3len > MST_BPDU_CONFIG_INFO_LENGTH) {
|
|
|
|
len = v3len - MST_BPDU_CONFIG_INFO_LENGTH;
|
|
|
|
offset = MST_BPDU_MSTI_OFFSET;
|
|
|
|
while (len >= MST_BPDU_MSTI_LENGTH) {
|
2017-12-11 19:46:51 +08:00
|
|
|
ND_TCHECK_LEN(ptr + offset, MST_BPDU_MSTI_LENGTH);
|
2015-07-08 02:56:48 +08:00
|
|
|
|
2017-11-23 06:54:09 +08:00
|
|
|
msti = EXTRACT_BE_U_2(ptr + offset + MST_BPDU_MSTI_ROOT_PRIO_OFFSET);
|
2007-03-08 21:49:46 +08:00
|
|
|
msti = msti & 0x0FFF;
|
|
|
|
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("\n\tMSTI %u, Flags [%s], port-role %s",
|
2017-11-23 22:23:12 +08:00
|
|
|
msti, bittok2str(stp_bpdu_flag_values, "none", EXTRACT_U_1(ptr + offset)),
|
2007-03-08 21:49:46 +08:00
|
|
|
tok2str(rstp_obj_port_role_values, "Unknown",
|
2018-01-07 18:47:30 +08:00
|
|
|
RSTP_EXTRACT_PORT_ROLE(EXTRACT_U_1(ptr + offset))));
|
|
|
|
ND_PRINT("\n\t\tMSTI regional-root-id %s, pathcost %u",
|
2007-03-08 21:49:46 +08:00
|
|
|
stp_print_bridge_id(ptr + offset +
|
|
|
|
MST_BPDU_MSTI_ROOT_PRIO_OFFSET),
|
2018-01-07 18:47:30 +08:00
|
|
|
EXTRACT_BE_U_4(ptr + offset + MST_BPDU_MSTI_ROOT_PATH_COST_OFFSET));
|
|
|
|
ND_PRINT("\n\t\tMSTI bridge-prio %u, port-prio %u, hops %u",
|
2017-11-26 20:02:48 +08:00
|
|
|
EXTRACT_U_1(ptr + offset + MST_BPDU_MSTI_BRIDGE_PRIO_OFFSET) >> 4,
|
|
|
|
EXTRACT_U_1(ptr + offset + MST_BPDU_MSTI_PORT_PRIO_OFFSET) >> 4,
|
2018-01-07 18:47:30 +08:00
|
|
|
EXTRACT_U_1(ptr + offset + MST_BPDU_MSTI_REMAIN_HOPS_OFFSET));
|
2007-03-08 21:49:46 +08:00
|
|
|
|
|
|
|
len -= MST_BPDU_MSTI_LENGTH;
|
|
|
|
offset += MST_BPDU_MSTI_LENGTH;
|
|
|
|
}
|
|
|
|
}
|
2015-07-08 02:56:48 +08:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
trunc:
|
|
|
|
return 0;
|
2013-03-26 17:35:14 +08:00
|
|
|
}
|
|
|
|
|
2015-07-08 02:56:48 +08:00
|
|
|
static int
|
2014-03-16 03:25:06 +08:00
|
|
|
stp_print_spb_bpdu(netdissect_options *ndo, const struct stp_bpdu_ *stp_bpdu,
|
|
|
|
u_int offset)
|
2013-03-26 17:35:14 +08:00
|
|
|
{
|
|
|
|
const u_char *ptr;
|
2012-10-04 23:02:12 +08:00
|
|
|
|
2013-03-27 16:18:58 +08:00
|
|
|
/*
|
|
|
|
* in non-verbose mode don't print anything.
|
|
|
|
*/
|
2014-03-16 03:25:06 +08:00
|
|
|
if (!ndo->ndo_vflag) {
|
2015-07-08 02:56:48 +08:00
|
|
|
return 1;
|
2013-03-27 16:18:58 +08:00
|
|
|
}
|
|
|
|
|
2013-03-26 17:35:14 +08:00
|
|
|
ptr = (const u_char *)stp_bpdu;
|
2017-11-23 04:58:44 +08:00
|
|
|
ND_TCHECK_4(ptr + offset + SPB_BPDU_AGREEMENT_DIGEST_OFFSET + 16);
|
2015-11-11 21:31:29 +08:00
|
|
|
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("\n\tv4len %u, ", EXTRACT_BE_U_2(ptr + offset));
|
|
|
|
ND_PRINT("AUXMCID Name ");
|
2015-11-11 21:31:29 +08:00
|
|
|
if (fn_printzp(ndo, ptr + offset + SPB_BPDU_CONFIG_NAME_OFFSET, 32,
|
|
|
|
ndo->ndo_snapend))
|
|
|
|
goto trunc;
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(", Rev %u,\n\t\tdigest %08x%08x%08x%08x",
|
2017-11-23 06:54:09 +08:00
|
|
|
EXTRACT_BE_U_2(ptr + offset + SPB_BPDU_CONFIG_REV_OFFSET),
|
|
|
|
EXTRACT_BE_U_4(ptr + offset + SPB_BPDU_CONFIG_DIGEST_OFFSET),
|
|
|
|
EXTRACT_BE_U_4(ptr + offset + SPB_BPDU_CONFIG_DIGEST_OFFSET + 4),
|
|
|
|
EXTRACT_BE_U_4(ptr + offset + SPB_BPDU_CONFIG_DIGEST_OFFSET + 8),
|
2018-01-07 18:47:30 +08:00
|
|
|
EXTRACT_BE_U_4(ptr + offset + SPB_BPDU_CONFIG_DIGEST_OFFSET + 12));
|
2014-01-02 10:27:54 +08:00
|
|
|
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("\n\tAgreement num %u, Discarded Agreement num %u, Agreement valid-"
|
2017-12-31 10:37:50 +08:00
|
|
|
"flag %u,\n\tRestricted role-flag: %u, Format id %u cap %u, "
|
|
|
|
"Convention id %u cap %u,\n\tEdge count %u, "
|
2013-03-26 17:35:14 +08:00
|
|
|
"Agreement digest %08x%08x%08x%08x%08x\n",
|
2017-11-26 20:02:48 +08:00
|
|
|
EXTRACT_U_1(ptr + offset + SPB_BPDU_AGREEMENT_OFFSET)>>6,
|
|
|
|
EXTRACT_U_1(ptr + offset + SPB_BPDU_AGREEMENT_OFFSET)>>4 & 0x3,
|
|
|
|
EXTRACT_U_1(ptr + offset + SPB_BPDU_AGREEMENT_OFFSET)>>3 & 0x1,
|
|
|
|
EXTRACT_U_1(ptr + offset + SPB_BPDU_AGREEMENT_OFFSET)>>2 & 0x1,
|
|
|
|
EXTRACT_U_1(ptr + offset + SPB_BPDU_AGREEMENT_FORMAT_OFFSET)>>4,
|
|
|
|
EXTRACT_U_1(ptr + offset + SPB_BPDU_AGREEMENT_FORMAT_OFFSET)&0x00ff,
|
|
|
|
EXTRACT_U_1(ptr + offset + SPB_BPDU_AGREEMENT_CON_OFFSET)>>4,
|
|
|
|
EXTRACT_U_1(ptr + offset + SPB_BPDU_AGREEMENT_CON_OFFSET)&0x00ff,
|
2017-11-23 06:54:09 +08:00
|
|
|
EXTRACT_BE_U_2(ptr + offset + SPB_BPDU_AGREEMENT_EDGE_OFFSET),
|
|
|
|
EXTRACT_BE_U_4(ptr + offset + SPB_BPDU_AGREEMENT_DIGEST_OFFSET),
|
|
|
|
EXTRACT_BE_U_4(ptr + offset + SPB_BPDU_AGREEMENT_DIGEST_OFFSET + 4),
|
|
|
|
EXTRACT_BE_U_4(ptr + offset + SPB_BPDU_AGREEMENT_DIGEST_OFFSET + 8),
|
|
|
|
EXTRACT_BE_U_4(ptr + offset + SPB_BPDU_AGREEMENT_DIGEST_OFFSET + 12),
|
2018-01-07 18:47:30 +08:00
|
|
|
EXTRACT_BE_U_4(ptr + offset + SPB_BPDU_AGREEMENT_DIGEST_OFFSET + 16));
|
2015-07-08 02:56:48 +08:00
|
|
|
return 1;
|
2015-11-11 21:31:29 +08:00
|
|
|
|
|
|
|
trunc:
|
|
|
|
return 0;
|
2007-03-08 21:49:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-10-04 23:02:12 +08:00
|
|
|
* Print 802.1d / 802.1w / 802.1q (mstp) / 802.1aq (spb) packets.
|
2000-06-11 04:57:55 +08:00
|
|
|
*/
|
|
|
|
void
|
2014-03-16 03:25:06 +08:00
|
|
|
stp_print(netdissect_options *ndo, const u_char *p, u_int length)
|
2000-06-11 04:57:55 +08:00
|
|
|
{
|
2007-03-06 23:03:51 +08:00
|
|
|
const struct stp_bpdu_ *stp_bpdu;
|
2017-12-31 10:37:50 +08:00
|
|
|
u_int protocol_version;
|
|
|
|
u_int bpdu_type;
|
2013-03-26 17:35:14 +08:00
|
|
|
u_int mstp_len;
|
|
|
|
u_int spb_len;
|
2014-01-02 10:27:54 +08:00
|
|
|
|
2015-04-27 08:24:42 +08:00
|
|
|
stp_bpdu = (const struct stp_bpdu_*)p;
|
2007-03-06 23:03:51 +08:00
|
|
|
|
2007-03-07 20:10:54 +08:00
|
|
|
/* Minimum STP Frame size. */
|
2007-03-06 23:03:51 +08:00
|
|
|
if (length < 4)
|
|
|
|
goto trunc;
|
2014-01-02 10:27:54 +08:00
|
|
|
|
2018-01-08 04:51:55 +08:00
|
|
|
ND_TCHECK_2(stp_bpdu->protocol_id);
|
2017-12-31 10:37:50 +08:00
|
|
|
if (EXTRACT_BE_U_2(stp_bpdu->protocol_id)) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("unknown STP version, length %u", length);
|
2007-03-06 23:03:51 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-08 04:51:55 +08:00
|
|
|
ND_TCHECK_1(stp_bpdu->protocol_version);
|
2017-12-31 10:37:50 +08:00
|
|
|
protocol_version = EXTRACT_U_1(stp_bpdu->protocol_version);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("STP %s", tok2str(stp_proto_values, "Unknown STP protocol (0x%02x)",
|
|
|
|
protocol_version));
|
2007-03-06 23:03:51 +08:00
|
|
|
|
2017-12-31 10:37:50 +08:00
|
|
|
switch (protocol_version) {
|
2007-03-06 23:03:51 +08:00
|
|
|
case STP_PROTO_REGULAR:
|
|
|
|
case STP_PROTO_RAPID:
|
2007-03-08 21:49:46 +08:00
|
|
|
case STP_PROTO_MSTP:
|
2012-10-04 23:02:12 +08:00
|
|
|
case STP_PROTO_SPB:
|
2007-03-06 23:03:51 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-08 04:51:55 +08:00
|
|
|
ND_TCHECK_1(stp_bpdu->bpdu_type);
|
2017-12-31 10:37:50 +08:00
|
|
|
bpdu_type = EXTRACT_U_1(stp_bpdu->bpdu_type);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(", %s", tok2str(stp_bpdu_type_values, "Unknown BPDU Type (0x%02x)",
|
|
|
|
bpdu_type));
|
2007-03-06 23:03:51 +08:00
|
|
|
|
2017-12-31 10:37:50 +08:00
|
|
|
switch (bpdu_type) {
|
2007-03-06 23:03:51 +08:00
|
|
|
case STP_BPDU_TYPE_CONFIG:
|
|
|
|
if (length < sizeof(struct stp_bpdu_) - 1) {
|
|
|
|
goto trunc;
|
|
|
|
}
|
2015-07-08 02:56:48 +08:00
|
|
|
if (!stp_print_config_bpdu(ndo, stp_bpdu, length))
|
|
|
|
goto trunc;
|
2007-03-06 23:03:51 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case STP_BPDU_TYPE_RSTP:
|
2017-12-31 10:37:50 +08:00
|
|
|
if (protocol_version == STP_PROTO_RAPID) {
|
2007-03-08 21:49:46 +08:00
|
|
|
if (length < sizeof(struct stp_bpdu_)) {
|
|
|
|
goto trunc;
|
|
|
|
}
|
2015-07-08 02:56:48 +08:00
|
|
|
if (!stp_print_config_bpdu(ndo, stp_bpdu, length))
|
|
|
|
goto trunc;
|
2017-12-31 10:37:50 +08:00
|
|
|
} else if (protocol_version == STP_PROTO_MSTP ||
|
|
|
|
protocol_version == STP_PROTO_SPB) {
|
2007-03-08 21:49:46 +08:00
|
|
|
if (length < STP_BPDU_MSTP_MIN_LEN) {
|
|
|
|
goto trunc;
|
|
|
|
}
|
2013-02-07 13:37:29 +08:00
|
|
|
|
2018-01-08 04:51:55 +08:00
|
|
|
ND_TCHECK_1(stp_bpdu->v1_length);
|
2017-12-31 10:37:50 +08:00
|
|
|
if (EXTRACT_U_1(stp_bpdu->v1_length) != 0) {
|
2007-03-08 21:49:46 +08:00
|
|
|
/* FIX ME: Emit a message here ? */
|
|
|
|
goto trunc;
|
|
|
|
}
|
2013-02-07 13:37:29 +08:00
|
|
|
|
2007-03-08 21:49:46 +08:00
|
|
|
/* Validate v3 length */
|
2017-11-23 04:58:44 +08:00
|
|
|
ND_TCHECK_2(p + MST_BPDU_VER3_LEN_OFFSET);
|
2017-11-23 06:54:09 +08:00
|
|
|
mstp_len = EXTRACT_BE_U_2(p + MST_BPDU_VER3_LEN_OFFSET);
|
2007-03-08 21:49:46 +08:00
|
|
|
mstp_len += 2; /* length encoding itself is 2 bytes */
|
|
|
|
if (length < (sizeof(struct stp_bpdu_) + mstp_len)) {
|
|
|
|
goto trunc;
|
|
|
|
}
|
2015-07-08 02:56:48 +08:00
|
|
|
if (!stp_print_mstp_bpdu(ndo, stp_bpdu, length))
|
|
|
|
goto trunc;
|
2012-10-04 23:02:12 +08:00
|
|
|
|
2017-12-31 10:37:50 +08:00
|
|
|
if (protocol_version == STP_PROTO_SPB)
|
2012-10-04 23:02:12 +08:00
|
|
|
{
|
2013-02-07 13:37:29 +08:00
|
|
|
/* Validate v4 length */
|
2017-11-23 04:58:44 +08:00
|
|
|
ND_TCHECK_2(p + MST_BPDU_VER3_LEN_OFFSET + mstp_len);
|
2017-11-23 06:54:09 +08:00
|
|
|
spb_len = EXTRACT_BE_U_2(p + MST_BPDU_VER3_LEN_OFFSET + mstp_len);
|
2012-10-04 23:02:12 +08:00
|
|
|
spb_len += 2;
|
|
|
|
if (length < (sizeof(struct stp_bpdu_) + mstp_len + spb_len) ||
|
|
|
|
spb_len < SPB_BPDU_MIN_LEN) {
|
|
|
|
goto trunc;
|
|
|
|
}
|
2015-07-08 02:56:48 +08:00
|
|
|
if (!stp_print_spb_bpdu(ndo, stp_bpdu, (sizeof(struct stp_bpdu_) + mstp_len)))
|
|
|
|
goto trunc;
|
2012-10-04 23:02:12 +08:00
|
|
|
}
|
2007-03-06 23:03:51 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case STP_BPDU_TYPE_TOPO_CHANGE:
|
|
|
|
/* always empty message - just break out */
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
2015-11-11 21:31:29 +08:00
|
|
|
trunc:
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("[|stp %u]", length);
|
2000-06-11 04:57:55 +08:00
|
|
|
}
|
2007-03-06 23:03:51 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Local Variables:
|
|
|
|
* c-style: whitesmith
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* End:
|
|
|
|
*/
|