The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2000 Lennert Buytenhek |
| 3 | * |
| 4 | * This software may be distributed either under the terms of the |
| 5 | * BSD-style license that accompanies tcpdump or the GNU General |
| 6 | * Public License |
| 7 | * |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 8 | * Contributed by Lennert Buytenhek <buytenh@gnu.org> |
| 9 | */ |
| 10 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 11 | /* \summary: IEEE 802.1d Spanning Tree Protocol (STP) printer */ |
| 12 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 13 | #ifdef HAVE_CONFIG_H |
| 14 | #include "config.h" |
| 15 | #endif |
| 16 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 17 | #include <netdissect-stdinc.h> |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 18 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 19 | #include <stdio.h> |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 20 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 21 | #include "netdissect.h" |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 22 | #include "extract.h" |
| 23 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 24 | #define RSTP_EXTRACT_PORT_ROLE(x) (((x)&0x0C)>>2) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 25 | /* STP timers are expressed in multiples of 1/256th second */ |
| 26 | #define STP_TIME_BASE 256 |
| 27 | #define STP_BPDU_MSTP_MIN_LEN 102 |
| 28 | |
| 29 | struct stp_bpdu_ { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 30 | uint8_t protocol_id[2]; |
| 31 | uint8_t protocol_version; |
| 32 | uint8_t bpdu_type; |
| 33 | uint8_t flags; |
| 34 | uint8_t root_id[8]; |
| 35 | uint8_t root_path_cost[4]; |
| 36 | uint8_t bridge_id[8]; |
| 37 | uint8_t port_id[2]; |
| 38 | uint8_t message_age[2]; |
| 39 | uint8_t max_age[2]; |
| 40 | uint8_t hello_time[2]; |
| 41 | uint8_t forward_delay[2]; |
| 42 | uint8_t v1_length; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | #define STP_PROTO_REGULAR 0x00 |
| 46 | #define STP_PROTO_RAPID 0x02 |
| 47 | #define STP_PROTO_MSTP 0x03 |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 48 | #define STP_PROTO_SPB 0x04 |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 49 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 50 | static const struct tok stp_proto_values[] = { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 51 | { STP_PROTO_REGULAR, "802.1d" }, |
| 52 | { STP_PROTO_RAPID, "802.1w" }, |
| 53 | { STP_PROTO_MSTP, "802.1s" }, |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 54 | { STP_PROTO_SPB, "802.1aq" }, |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 55 | { 0, NULL} |
| 56 | }; |
| 57 | |
| 58 | #define STP_BPDU_TYPE_CONFIG 0x00 |
| 59 | #define STP_BPDU_TYPE_RSTP 0x02 |
| 60 | #define STP_BPDU_TYPE_TOPO_CHANGE 0x80 |
| 61 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 62 | static const struct tok stp_bpdu_flag_values[] = { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 63 | { 0x01, "Topology change" }, |
| 64 | { 0x02, "Proposal" }, |
| 65 | { 0x10, "Learn" }, |
| 66 | { 0x20, "Forward" }, |
| 67 | { 0x40, "Agreement" }, |
| 68 | { 0x80, "Topology change ACK" }, |
| 69 | { 0, NULL} |
| 70 | }; |
| 71 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 72 | static const struct tok stp_bpdu_type_values[] = { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 73 | { STP_BPDU_TYPE_CONFIG, "Config" }, |
| 74 | { STP_BPDU_TYPE_RSTP, "Rapid STP" }, |
| 75 | { STP_BPDU_TYPE_TOPO_CHANGE, "Topology Change" }, |
| 76 | { 0, NULL} |
| 77 | }; |
| 78 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 79 | static const struct tok rstp_obj_port_role_values[] = { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 80 | { 0x00, "Unknown" }, |
| 81 | { 0x01, "Alternate" }, |
| 82 | { 0x02, "Root" }, |
| 83 | { 0x03, "Designated" }, |
| 84 | { 0, NULL} |
| 85 | }; |
| 86 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 87 | #define ND_TCHECK_BRIDGE_ID(p) ND_TCHECK2(*(p), 8) |
| 88 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 89 | static char * |
| 90 | stp_print_bridge_id(const u_char *p) |
| 91 | { |
| 92 | static char bridge_id_str[sizeof("pppp.aa:bb:cc:dd:ee:ff")]; |
| 93 | |
| 94 | snprintf(bridge_id_str, sizeof(bridge_id_str), |
| 95 | "%.2x%.2x.%.2x:%.2x:%.2x:%.2x:%.2x:%.2x", |
| 96 | p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]); |
| 97 | |
| 98 | return bridge_id_str; |
| 99 | } |
| 100 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 101 | static int |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 102 | stp_print_config_bpdu(netdissect_options *ndo, const struct stp_bpdu_ *stp_bpdu, |
| 103 | u_int length) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 104 | { |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 105 | ND_TCHECK(stp_bpdu->flags); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 106 | ND_PRINT((ndo, ", Flags [%s]", |
| 107 | bittok2str(stp_bpdu_flag_values, "none", stp_bpdu->flags))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 108 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 109 | ND_TCHECK(stp_bpdu->port_id); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 110 | ND_PRINT((ndo, ", bridge-id %s.%04x, length %u", |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 111 | stp_print_bridge_id((const u_char *)&stp_bpdu->bridge_id), |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 112 | EXTRACT_16BITS(&stp_bpdu->port_id), length)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 113 | |
| 114 | /* in non-verbose mode just print the bridge-id */ |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 115 | if (!ndo->ndo_vflag) { |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 116 | return 1; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 117 | } |
| 118 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 119 | ND_TCHECK(stp_bpdu->forward_delay); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 120 | ND_PRINT((ndo, "\n\tmessage-age %.2fs, max-age %.2fs" |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 121 | ", hello-time %.2fs, forwarding-delay %.2fs", |
| 122 | (float)EXTRACT_16BITS(&stp_bpdu->message_age) / STP_TIME_BASE, |
| 123 | (float)EXTRACT_16BITS(&stp_bpdu->max_age) / STP_TIME_BASE, |
| 124 | (float)EXTRACT_16BITS(&stp_bpdu->hello_time) / STP_TIME_BASE, |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 125 | (float)EXTRACT_16BITS(&stp_bpdu->forward_delay) / STP_TIME_BASE)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 126 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 127 | ND_PRINT((ndo, "\n\troot-id %s, root-pathcost %u", |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 128 | stp_print_bridge_id((const u_char *)&stp_bpdu->root_id), |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 129 | EXTRACT_32BITS(&stp_bpdu->root_path_cost))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 130 | |
| 131 | /* Port role is only valid for 802.1w */ |
| 132 | if (stp_bpdu->protocol_version == STP_PROTO_RAPID) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 133 | ND_PRINT((ndo, ", port-role %s", |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 134 | tok2str(rstp_obj_port_role_values, "Unknown", |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 135 | RSTP_EXTRACT_PORT_ROLE(stp_bpdu->flags)))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 136 | } |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 137 | return 1; |
| 138 | |
| 139 | trunc: |
| 140 | return 0; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | /* |
| 144 | * MSTP packet format |
| 145 | * Ref. IEEE 802.1Q 2003 Ed. Section 14 |
| 146 | * |
| 147 | * MSTP BPDU |
| 148 | * |
| 149 | * 2 - bytes Protocol Id |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 150 | * 1 - byte Protocol Ver. |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 151 | * 1 - byte BPDU tye |
| 152 | * 1 - byte Flags |
| 153 | * 8 - bytes CIST Root Identifier |
| 154 | * 4 - bytes CIST External Path Cost |
| 155 | * 8 - bytes CIST Regional Root Identifier |
| 156 | * 2 - bytes CIST Port Identifier |
| 157 | * 2 - bytes Message Age |
| 158 | * 2 - bytes Max age |
| 159 | * 2 - bytes Hello Time |
| 160 | * 2 - bytes Forward delay |
| 161 | * 1 - byte Version 1 length. Must be 0 |
| 162 | * 2 - bytes Version 3 length |
| 163 | * 1 - byte Config Identifier |
| 164 | * 32 - bytes Config Name |
| 165 | * 2 - bytes Revision level |
| 166 | * 16 - bytes Config Digest [MD5] |
| 167 | * 4 - bytes CIST Internal Root Path Cost |
| 168 | * 8 - bytes CIST Bridge Identifier |
| 169 | * 1 - byte CIST Remaining Hops |
| 170 | * 16 - bytes MSTI information [Max 64 MSTI, each 16 bytes] |
| 171 | * |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 172 | * |
| 173 | * SPB BPDU |
| 174 | * Ref. IEEE 802.1aq. Section 14 |
| 175 | * |
| 176 | * 2 - bytes Version 4 length |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 177 | * 1 - byte Aux Config Identifier |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 178 | * 32 - bytes Aux Config Name |
| 179 | * 2 - bytes Aux Revision level |
| 180 | * 16 - bytes Aux Config Digest [MD5] |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 181 | * 1 - byte (1 - 2) Agreement Number |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 182 | * (3 - 4) Discarded Agreement Number |
| 183 | * (5) Agreement Valid Flag |
| 184 | * (6) Restricted Role Flag |
| 185 | * (7 - 8) Unused sent zero |
| 186 | * 1 - byte Unused |
| 187 | * 1 - byte (1 - 4) Agreement Digest Format Identifier |
| 188 | * (5 - 8) Agreement Digest Format Capabilities |
| 189 | * 1 - byte (1 - 4) Agreement Digest Convention Identifier |
| 190 | * (5 - 8) Agreement Digest Convention Capabilities |
| 191 | * 2 - bytes Agreement Digest Edge Count |
| 192 | * 8 - byte Reserved Set |
| 193 | * 20 - bytes Computed Topology Digest |
| 194 | * |
| 195 | * |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 196 | * MSTI Payload |
| 197 | * |
| 198 | * 1 - byte MSTI flag |
| 199 | * 8 - bytes MSTI Regional Root Identifier |
| 200 | * 4 - bytes MSTI Regional Path Cost |
| 201 | * 1 - byte MSTI Bridge Priority |
| 202 | * 1 - byte MSTI Port Priority |
| 203 | * 1 - byte MSTI Remaining Hops |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 204 | * |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 205 | */ |
| 206 | |
| 207 | #define MST_BPDU_MSTI_LENGTH 16 |
| 208 | #define MST_BPDU_CONFIG_INFO_LENGTH 64 |
| 209 | |
| 210 | /* Offsets of fields from the begginning for the packet */ |
| 211 | #define MST_BPDU_VER3_LEN_OFFSET 36 |
| 212 | #define MST_BPDU_CONFIG_NAME_OFFSET 39 |
| 213 | #define MST_BPDU_CONFIG_DIGEST_OFFSET 73 |
| 214 | #define MST_BPDU_CIST_INT_PATH_COST_OFFSET 89 |
| 215 | #define MST_BPDU_CIST_BRIDGE_ID_OFFSET 93 |
| 216 | #define MST_BPDU_CIST_REMAIN_HOPS_OFFSET 101 |
| 217 | #define MST_BPDU_MSTI_OFFSET 102 |
| 218 | /* Offsets within an MSTI */ |
| 219 | #define MST_BPDU_MSTI_ROOT_PRIO_OFFSET 1 |
| 220 | #define MST_BPDU_MSTI_ROOT_PATH_COST_OFFSET 9 |
| 221 | #define MST_BPDU_MSTI_BRIDGE_PRIO_OFFSET 13 |
| 222 | #define MST_BPDU_MSTI_PORT_PRIO_OFFSET 14 |
| 223 | #define MST_BPDU_MSTI_REMAIN_HOPS_OFFSET 15 |
| 224 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 225 | #define SPB_BPDU_MIN_LEN 87 |
| 226 | #define SPB_BPDU_CONFIG_NAME_OFFSET 3 |
| 227 | #define SPB_BPDU_CONFIG_REV_OFFSET SPB_BPDU_CONFIG_NAME_OFFSET + 32 |
| 228 | #define SPB_BPDU_CONFIG_DIGEST_OFFSET SPB_BPDU_CONFIG_REV_OFFSET + 2 |
| 229 | #define SPB_BPDU_AGREEMENT_OFFSET SPB_BPDU_CONFIG_DIGEST_OFFSET + 16 |
| 230 | #define SPB_BPDU_AGREEMENT_UNUSED_OFFSET SPB_BPDU_AGREEMENT_OFFSET + 1 |
| 231 | #define SPB_BPDU_AGREEMENT_FORMAT_OFFSET SPB_BPDU_AGREEMENT_UNUSED_OFFSET + 1 |
| 232 | #define SPB_BPDU_AGREEMENT_CON_OFFSET SPB_BPDU_AGREEMENT_FORMAT_OFFSET + 1 |
| 233 | #define SPB_BPDU_AGREEMENT_EDGE_OFFSET SPB_BPDU_AGREEMENT_CON_OFFSET + 1 |
| 234 | #define SPB_BPDU_AGREEMENT_RES1_OFFSET SPB_BPDU_AGREEMENT_EDGE_OFFSET + 2 |
| 235 | #define SPB_BPDU_AGREEMENT_RES2_OFFSET SPB_BPDU_AGREEMENT_RES1_OFFSET + 4 |
| 236 | #define SPB_BPDU_AGREEMENT_DIGEST_OFFSET SPB_BPDU_AGREEMENT_RES2_OFFSET + 4 |
| 237 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 238 | static int |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 239 | stp_print_mstp_bpdu(netdissect_options *ndo, const struct stp_bpdu_ *stp_bpdu, |
| 240 | u_int length) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 241 | { |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 242 | const u_char *ptr; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 243 | uint16_t v3len; |
| 244 | uint16_t len; |
| 245 | uint16_t msti; |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 246 | u_int offset; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 247 | |
| 248 | ptr = (const u_char *)stp_bpdu; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 249 | ND_PRINT((ndo, ", CIST Flags [%s], length %u", |
| 250 | bittok2str(stp_bpdu_flag_values, "none", stp_bpdu->flags), length)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 251 | |
| 252 | /* |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 253 | * in non-verbose mode just print the flags. |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 254 | */ |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 255 | if (!ndo->ndo_vflag) { |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 256 | return 1; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 257 | } |
| 258 | |
Elliott Hughes | 9a98642 | 2017-12-19 14:49:10 -0800 | [diff] [blame] | 259 | ND_TCHECK(stp_bpdu->flags); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 260 | ND_PRINT((ndo, "\n\tport-role %s, ", |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 261 | tok2str(rstp_obj_port_role_values, "Unknown", |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 262 | RSTP_EXTRACT_PORT_ROLE(stp_bpdu->flags)))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 263 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 264 | ND_TCHECK(stp_bpdu->root_path_cost); |
| 265 | ND_PRINT((ndo, "CIST root-id %s, CIST ext-pathcost %u", |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 266 | stp_print_bridge_id((const u_char *)&stp_bpdu->root_id), |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 267 | EXTRACT_32BITS(&stp_bpdu->root_path_cost))); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 268 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 269 | ND_TCHECK(stp_bpdu->bridge_id); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 270 | ND_PRINT((ndo, "\n\tCIST regional-root-id %s, ", |
| 271 | stp_print_bridge_id((const u_char *)&stp_bpdu->bridge_id))); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 272 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 273 | ND_TCHECK(stp_bpdu->port_id); |
| 274 | ND_PRINT((ndo, "CIST port-id %04x,", EXTRACT_16BITS(&stp_bpdu->port_id))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 275 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 276 | ND_TCHECK(stp_bpdu->forward_delay); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 277 | ND_PRINT((ndo, "\n\tmessage-age %.2fs, max-age %.2fs" |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 278 | ", hello-time %.2fs, forwarding-delay %.2fs", |
| 279 | (float)EXTRACT_16BITS(&stp_bpdu->message_age) / STP_TIME_BASE, |
| 280 | (float)EXTRACT_16BITS(&stp_bpdu->max_age) / STP_TIME_BASE, |
| 281 | (float)EXTRACT_16BITS(&stp_bpdu->hello_time) / STP_TIME_BASE, |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 282 | (float)EXTRACT_16BITS(&stp_bpdu->forward_delay) / STP_TIME_BASE)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 283 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 284 | ND_TCHECK_16BITS(ptr + MST_BPDU_VER3_LEN_OFFSET); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 285 | ND_PRINT((ndo, "\n\tv3len %d, ", EXTRACT_16BITS(ptr + MST_BPDU_VER3_LEN_OFFSET))); |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 286 | ND_TCHECK_32BITS(ptr + MST_BPDU_CONFIG_DIGEST_OFFSET + 12); |
| 287 | ND_PRINT((ndo, "MCID Name ")); |
| 288 | if (fn_printzp(ndo, ptr + MST_BPDU_CONFIG_NAME_OFFSET, 32, ndo->ndo_snapend)) |
| 289 | goto trunc; |
| 290 | ND_PRINT((ndo, ", rev %u," |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 291 | "\n\t\tdigest %08x%08x%08x%08x, ", |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 292 | EXTRACT_16BITS(ptr + MST_BPDU_CONFIG_NAME_OFFSET + 32), |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 293 | EXTRACT_32BITS(ptr + MST_BPDU_CONFIG_DIGEST_OFFSET), |
| 294 | EXTRACT_32BITS(ptr + MST_BPDU_CONFIG_DIGEST_OFFSET + 4), |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 295 | EXTRACT_32BITS(ptr + MST_BPDU_CONFIG_DIGEST_OFFSET + 8), |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 296 | EXTRACT_32BITS(ptr + MST_BPDU_CONFIG_DIGEST_OFFSET + 12))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 297 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 298 | ND_TCHECK_32BITS(ptr + MST_BPDU_CIST_INT_PATH_COST_OFFSET); |
| 299 | ND_PRINT((ndo, "CIST int-root-pathcost %u,", |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 300 | EXTRACT_32BITS(ptr + MST_BPDU_CIST_INT_PATH_COST_OFFSET))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 301 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 302 | ND_TCHECK_BRIDGE_ID(ptr + MST_BPDU_CIST_BRIDGE_ID_OFFSET); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 303 | ND_PRINT((ndo, "\n\tCIST bridge-id %s, ", |
| 304 | stp_print_bridge_id(ptr + MST_BPDU_CIST_BRIDGE_ID_OFFSET))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 305 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 306 | ND_TCHECK(ptr[MST_BPDU_CIST_REMAIN_HOPS_OFFSET]); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 307 | ND_PRINT((ndo, "CIST remaining-hops %d", ptr[MST_BPDU_CIST_REMAIN_HOPS_OFFSET])); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 308 | |
| 309 | /* Dump all MSTI's */ |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 310 | ND_TCHECK_16BITS(ptr + MST_BPDU_VER3_LEN_OFFSET); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 311 | v3len = EXTRACT_16BITS(ptr + MST_BPDU_VER3_LEN_OFFSET); |
| 312 | if (v3len > MST_BPDU_CONFIG_INFO_LENGTH) { |
| 313 | len = v3len - MST_BPDU_CONFIG_INFO_LENGTH; |
| 314 | offset = MST_BPDU_MSTI_OFFSET; |
| 315 | while (len >= MST_BPDU_MSTI_LENGTH) { |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 316 | ND_TCHECK2(*(ptr + offset), MST_BPDU_MSTI_LENGTH); |
| 317 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 318 | msti = EXTRACT_16BITS(ptr + offset + |
| 319 | MST_BPDU_MSTI_ROOT_PRIO_OFFSET); |
| 320 | msti = msti & 0x0FFF; |
| 321 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 322 | ND_PRINT((ndo, "\n\tMSTI %d, Flags [%s], port-role %s", |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 323 | msti, bittok2str(stp_bpdu_flag_values, "none", ptr[offset]), |
| 324 | tok2str(rstp_obj_port_role_values, "Unknown", |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 325 | RSTP_EXTRACT_PORT_ROLE(ptr[offset])))); |
| 326 | ND_PRINT((ndo, "\n\t\tMSTI regional-root-id %s, pathcost %u", |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 327 | stp_print_bridge_id(ptr + offset + |
| 328 | MST_BPDU_MSTI_ROOT_PRIO_OFFSET), |
| 329 | EXTRACT_32BITS(ptr + offset + |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 330 | MST_BPDU_MSTI_ROOT_PATH_COST_OFFSET))); |
| 331 | ND_PRINT((ndo, "\n\t\tMSTI bridge-prio %d, port-prio %d, hops %d", |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 332 | ptr[offset + MST_BPDU_MSTI_BRIDGE_PRIO_OFFSET] >> 4, |
| 333 | ptr[offset + MST_BPDU_MSTI_PORT_PRIO_OFFSET] >> 4, |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 334 | ptr[offset + MST_BPDU_MSTI_REMAIN_HOPS_OFFSET])); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 335 | |
| 336 | len -= MST_BPDU_MSTI_LENGTH; |
| 337 | offset += MST_BPDU_MSTI_LENGTH; |
| 338 | } |
| 339 | } |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 340 | return 1; |
| 341 | |
| 342 | trunc: |
| 343 | return 0; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 344 | } |
| 345 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 346 | static int |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 347 | stp_print_spb_bpdu(netdissect_options *ndo, const struct stp_bpdu_ *stp_bpdu, |
| 348 | u_int offset) |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 349 | { |
| 350 | const u_char *ptr; |
| 351 | |
| 352 | /* |
| 353 | * in non-verbose mode don't print anything. |
| 354 | */ |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 355 | if (!ndo->ndo_vflag) { |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 356 | return 1; |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | ptr = (const u_char *)stp_bpdu; |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 360 | ND_TCHECK_32BITS(ptr + offset + SPB_BPDU_AGREEMENT_DIGEST_OFFSET + 16); |
| 361 | |
| 362 | ND_PRINT((ndo, "\n\tv4len %d, ", EXTRACT_16BITS (ptr + offset))); |
| 363 | ND_PRINT((ndo, "AUXMCID Name ")); |
| 364 | if (fn_printzp(ndo, ptr + offset + SPB_BPDU_CONFIG_NAME_OFFSET, 32, |
| 365 | ndo->ndo_snapend)) |
| 366 | goto trunc; |
| 367 | ND_PRINT((ndo, ", Rev %u,\n\t\tdigest %08x%08x%08x%08x", |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 368 | EXTRACT_16BITS(ptr + offset + SPB_BPDU_CONFIG_REV_OFFSET), |
| 369 | EXTRACT_32BITS(ptr + offset + SPB_BPDU_CONFIG_DIGEST_OFFSET), |
| 370 | EXTRACT_32BITS(ptr + offset + SPB_BPDU_CONFIG_DIGEST_OFFSET + 4), |
| 371 | EXTRACT_32BITS(ptr + offset + SPB_BPDU_CONFIG_DIGEST_OFFSET + 8), |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 372 | EXTRACT_32BITS(ptr + offset + SPB_BPDU_CONFIG_DIGEST_OFFSET + 12))); |
| 373 | |
| 374 | ND_PRINT((ndo, "\n\tAgreement num %d, Discarded Agreement num %d, Agreement valid-" |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 375 | "flag %d,\n\tRestricted role-flag: %d, Format id %d cap %d, " |
| 376 | "Convention id %d cap %d,\n\tEdge count %d, " |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 377 | "Agreement digest %08x%08x%08x%08x%08x\n", |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 378 | ptr[offset + SPB_BPDU_AGREEMENT_OFFSET]>>6, |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 379 | ptr[offset + SPB_BPDU_AGREEMENT_OFFSET]>>4 & 0x3, |
| 380 | ptr[offset + SPB_BPDU_AGREEMENT_OFFSET]>>3 & 0x1, |
| 381 | ptr[offset + SPB_BPDU_AGREEMENT_OFFSET]>>2 & 0x1, |
| 382 | ptr[offset + SPB_BPDU_AGREEMENT_FORMAT_OFFSET]>>4, |
| 383 | ptr[offset + SPB_BPDU_AGREEMENT_FORMAT_OFFSET]&0x00ff, |
| 384 | ptr[offset + SPB_BPDU_AGREEMENT_CON_OFFSET]>>4, |
| 385 | ptr[offset + SPB_BPDU_AGREEMENT_CON_OFFSET]&0x00ff, |
| 386 | EXTRACT_16BITS(ptr + offset + SPB_BPDU_AGREEMENT_EDGE_OFFSET), |
| 387 | EXTRACT_32BITS(ptr + offset + SPB_BPDU_AGREEMENT_DIGEST_OFFSET), |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 388 | EXTRACT_32BITS(ptr + offset + SPB_BPDU_AGREEMENT_DIGEST_OFFSET+4), |
| 389 | EXTRACT_32BITS(ptr + offset + SPB_BPDU_AGREEMENT_DIGEST_OFFSET+8), |
| 390 | EXTRACT_32BITS(ptr + offset + SPB_BPDU_AGREEMENT_DIGEST_OFFSET+12), |
| 391 | EXTRACT_32BITS(ptr + offset + SPB_BPDU_AGREEMENT_DIGEST_OFFSET+16))); |
| 392 | return 1; |
| 393 | |
| 394 | trunc: |
| 395 | return 0; |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 396 | } |
| 397 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 398 | /* |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 399 | * Print 802.1d / 802.1w / 802.1q (mstp) / 802.1aq (spb) packets. |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 400 | */ |
| 401 | void |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 402 | stp_print(netdissect_options *ndo, const u_char *p, u_int length) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 403 | { |
| 404 | const struct stp_bpdu_ *stp_bpdu; |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 405 | u_int mstp_len; |
| 406 | u_int spb_len; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 407 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 408 | stp_bpdu = (const struct stp_bpdu_*)p; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 409 | |
| 410 | /* Minimum STP Frame size. */ |
| 411 | if (length < 4) |
| 412 | goto trunc; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 413 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 414 | ND_TCHECK(stp_bpdu->protocol_id); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 415 | if (EXTRACT_16BITS(&stp_bpdu->protocol_id)) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 416 | ND_PRINT((ndo, "unknown STP version, length %u", length)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 417 | return; |
| 418 | } |
| 419 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 420 | ND_TCHECK(stp_bpdu->protocol_version); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 421 | ND_PRINT((ndo, "STP %s", tok2str(stp_proto_values, "Unknown STP protocol (0x%02x)", |
| 422 | stp_bpdu->protocol_version))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 423 | |
| 424 | switch (stp_bpdu->protocol_version) { |
| 425 | case STP_PROTO_REGULAR: |
| 426 | case STP_PROTO_RAPID: |
| 427 | case STP_PROTO_MSTP: |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 428 | case STP_PROTO_SPB: |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 429 | break; |
| 430 | default: |
| 431 | return; |
| 432 | } |
| 433 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 434 | ND_TCHECK(stp_bpdu->bpdu_type); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 435 | ND_PRINT((ndo, ", %s", tok2str(stp_bpdu_type_values, "Unknown BPDU Type (0x%02x)", |
| 436 | stp_bpdu->bpdu_type))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 437 | |
| 438 | switch (stp_bpdu->bpdu_type) { |
| 439 | case STP_BPDU_TYPE_CONFIG: |
| 440 | if (length < sizeof(struct stp_bpdu_) - 1) { |
| 441 | goto trunc; |
| 442 | } |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 443 | if (!stp_print_config_bpdu(ndo, stp_bpdu, length)) |
| 444 | goto trunc; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 445 | break; |
| 446 | |
| 447 | case STP_BPDU_TYPE_RSTP: |
| 448 | if (stp_bpdu->protocol_version == STP_PROTO_RAPID) { |
| 449 | if (length < sizeof(struct stp_bpdu_)) { |
| 450 | goto trunc; |
| 451 | } |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 452 | if (!stp_print_config_bpdu(ndo, stp_bpdu, length)) |
| 453 | goto trunc; |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 454 | } else if (stp_bpdu->protocol_version == STP_PROTO_MSTP || |
| 455 | stp_bpdu->protocol_version == STP_PROTO_SPB) { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 456 | if (length < STP_BPDU_MSTP_MIN_LEN) { |
| 457 | goto trunc; |
| 458 | } |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 459 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 460 | ND_TCHECK(stp_bpdu->v1_length); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 461 | if (stp_bpdu->v1_length != 0) { |
| 462 | /* FIX ME: Emit a message here ? */ |
| 463 | goto trunc; |
| 464 | } |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 465 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 466 | /* Validate v3 length */ |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 467 | ND_TCHECK_16BITS(p + MST_BPDU_VER3_LEN_OFFSET); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 468 | mstp_len = EXTRACT_16BITS(p + MST_BPDU_VER3_LEN_OFFSET); |
| 469 | mstp_len += 2; /* length encoding itself is 2 bytes */ |
| 470 | if (length < (sizeof(struct stp_bpdu_) + mstp_len)) { |
| 471 | goto trunc; |
| 472 | } |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 473 | if (!stp_print_mstp_bpdu(ndo, stp_bpdu, length)) |
| 474 | goto trunc; |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 475 | |
| 476 | if (stp_bpdu->protocol_version == STP_PROTO_SPB) |
| 477 | { |
| 478 | /* Validate v4 length */ |
Elliott Hughes | 9a98642 | 2017-12-19 14:49:10 -0800 | [diff] [blame] | 479 | ND_TCHECK_16BITS(p + MST_BPDU_VER3_LEN_OFFSET + mstp_len); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 480 | spb_len = EXTRACT_16BITS (p + MST_BPDU_VER3_LEN_OFFSET + mstp_len); |
| 481 | spb_len += 2; |
| 482 | if (length < (sizeof(struct stp_bpdu_) + mstp_len + spb_len) || |
| 483 | spb_len < SPB_BPDU_MIN_LEN) { |
| 484 | goto trunc; |
| 485 | } |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 486 | if (!stp_print_spb_bpdu(ndo, stp_bpdu, (sizeof(struct stp_bpdu_) + mstp_len))) |
| 487 | goto trunc; |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 488 | } |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 489 | } |
| 490 | break; |
| 491 | |
| 492 | case STP_BPDU_TYPE_TOPO_CHANGE: |
| 493 | /* always empty message - just break out */ |
| 494 | break; |
| 495 | |
| 496 | default: |
| 497 | break; |
| 498 | } |
| 499 | |
| 500 | return; |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 501 | trunc: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 502 | ND_PRINT((ndo, "[|stp %d]", length)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | /* |
| 506 | * Local Variables: |
| 507 | * c-style: whitesmith |
| 508 | * c-basic-offset: 4 |
| 509 | * End: |
| 510 | */ |