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