]> The Tcpdump Group git mirrors - tcpdump/blob - print-vtp.c
Updated 802.15.4 code
[tcpdump] / print-vtp.c
1 /*
2 * Copyright (c) 1998-2007 The TCPDUMP project
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that: (1) source code
6 * distributions retain the above copyright notice and this paragraph
7 * in its entirety, and (2) distributions including binary code include
8 * the above copyright notice and this paragraph in its entirety in
9 * the documentation or other materials provided with the distribution.
10 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND
11 * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
12 * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
13 * FOR A PARTICULAR PURPOSE.
14 *
15 * Reference documentation:
16 * http://www.cisco.com/c/en/us/support/docs/lan-switching/vtp/10558-21.html
17 * http://docstore.mik.ua/univercd/cc/td/doc/product/lan/trsrb/frames.htm
18 *
19 * Original code ode by Carles Kishimoto <carles.kishimoto@gmail.com>
20 */
21
22 /* \summary: Cisco VLAN Trunking Protocol (VTP) printer */
23
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27
28 #include "netdissect-stdinc.h"
29
30 #include "netdissect.h"
31 #include "addrtoname.h"
32 #include "extract.h"
33
34 #define VTP_HEADER_LEN 36
35 #define VTP_DOMAIN_NAME_LEN 32
36 #define VTP_MD5_DIGEST_LEN 16
37 #define VTP_UPDATE_TIMESTAMP_LEN 12
38 #define VTP_VLAN_INFO_FIXED_PART_LEN 12 /* length of VLAN info before VLAN name */
39
40 #define VTP_SUMMARY_ADV 0x01
41 #define VTP_SUBSET_ADV 0x02
42 #define VTP_ADV_REQUEST 0x03
43 #define VTP_JOIN_MESSAGE 0x04
44
45 struct vtp_vlan_ {
46 nd_uint8_t len;
47 nd_uint8_t status;
48 nd_uint8_t type;
49 nd_uint8_t name_len;
50 nd_uint16_t vlanid;
51 nd_uint16_t mtu;
52 nd_uint32_t index;
53 };
54
55 static const struct tok vtp_message_type_values[] = {
56 { VTP_SUMMARY_ADV, "Summary advertisement"},
57 { VTP_SUBSET_ADV, "Subset advertisement"},
58 { VTP_ADV_REQUEST, "Advertisement request"},
59 { VTP_JOIN_MESSAGE, "Join message"},
60 { 0, NULL }
61 };
62
63 static const struct tok vtp_header_values[] = {
64 { 0x01, "Followers"}, /* On Summary advertisement, 3rd byte is Followers */
65 { 0x02, "Seq number"}, /* On Subset advertisement, 3rd byte is Sequence number */
66 { 0x03, "Rsvd"}, /* On Adver. requests 3rd byte is Rsvd */
67 { 0x04, "Rsvd"}, /* On Adver. requests 3rd byte is Rsvd */
68 { 0, NULL }
69 };
70
71 static const struct tok vtp_vlan_type_values[] = {
72 { 0x01, "Ethernet"},
73 { 0x02, "FDDI"},
74 { 0x03, "TrCRF"},
75 { 0x04, "FDDI-net"},
76 { 0x05, "TrBRF"},
77 { 0, NULL }
78 };
79
80 static const struct tok vtp_vlan_status[] = {
81 { 0x00, "Operational"},
82 { 0x01, "Suspended"},
83 { 0, NULL }
84 };
85
86 #define VTP_VLAN_SOURCE_ROUTING_RING_NUMBER 0x01
87 #define VTP_VLAN_SOURCE_ROUTING_BRIDGE_NUMBER 0x02
88 #define VTP_VLAN_STP_TYPE 0x03
89 #define VTP_VLAN_PARENT_VLAN 0x04
90 #define VTP_VLAN_TRANS_BRIDGED_VLAN 0x05
91 #define VTP_VLAN_PRUNING 0x06
92 #define VTP_VLAN_BRIDGE_TYPE 0x07
93 #define VTP_VLAN_ARP_HOP_COUNT 0x08
94 #define VTP_VLAN_STE_HOP_COUNT 0x09
95 #define VTP_VLAN_BACKUP_CRF_MODE 0x0A
96
97 static const struct tok vtp_vlan_tlv_values[] = {
98 { VTP_VLAN_SOURCE_ROUTING_RING_NUMBER, "Source-Routing Ring Number TLV"},
99 { VTP_VLAN_SOURCE_ROUTING_BRIDGE_NUMBER, "Source-Routing Bridge Number TLV"},
100 { VTP_VLAN_STP_TYPE, "STP type TLV"},
101 { VTP_VLAN_PARENT_VLAN, "Parent VLAN TLV"},
102 { VTP_VLAN_TRANS_BRIDGED_VLAN, "Translationally bridged VLANs TLV"},
103 { VTP_VLAN_PRUNING, "Pruning TLV"},
104 { VTP_VLAN_BRIDGE_TYPE, "Bridge Type TLV"},
105 { VTP_VLAN_ARP_HOP_COUNT, "Max ARP Hop Count TLV"},
106 { VTP_VLAN_STE_HOP_COUNT, "Max STE Hop Count TLV"},
107 { VTP_VLAN_BACKUP_CRF_MODE, "Backup CRF Mode TLV"},
108 { 0, NULL }
109 };
110
111 static const struct tok vtp_stp_type_values[] = {
112 { 1, "SRT"},
113 { 2, "SRB"},
114 { 3, "Auto"},
115 { 0, NULL }
116 };
117
118 void
119 vtp_print(netdissect_options *ndo,
120 const u_char *pptr, u_int length)
121 {
122 u_int type, len, name_len, tlv_len, tlv_value, mgmtd_len;
123 const u_char *tptr;
124 const struct vtp_vlan_ *vtp_vlan;
125
126 ndo->ndo_protocol = "vtp";
127 if (length < VTP_HEADER_LEN)
128 goto trunc;
129
130 tptr = pptr;
131
132 ND_TCHECK_LEN(tptr, VTP_HEADER_LEN);
133
134 type = EXTRACT_U_1(tptr + 1);
135 ND_PRINT("VTPv%u, Message %s (0x%02x), length %u",
136 EXTRACT_U_1(tptr),
137 tok2str(vtp_message_type_values,"Unknown message type", type),
138 type,
139 length);
140
141 /* In non-verbose mode, just print version and message type */
142 if (ndo->ndo_vflag < 1) {
143 return;
144 }
145
146 /* verbose mode print all fields */
147 ND_PRINT("\n\tDomain name: ");
148 mgmtd_len = EXTRACT_U_1(tptr + 3);
149 if (mgmtd_len < 1 || mgmtd_len > 32) {
150 ND_PRINT(" [invalid MgmtD Len %u]", mgmtd_len);
151 return;
152 }
153 nd_printzp(ndo, tptr + 4, mgmtd_len, NULL);
154 ND_PRINT(", %s: %u",
155 tok2str(vtp_header_values, "Unknown", type),
156 EXTRACT_U_1(tptr + 2));
157
158 tptr += VTP_HEADER_LEN;
159
160 switch (type) {
161
162 case VTP_SUMMARY_ADV:
163
164 /*
165 * SUMMARY ADVERTISEMENT
166 *
167 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
168 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
169 * | Version | Code | Followers | MgmtD Len |
170 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
171 * | Management Domain Name (zero-padded to 32 bytes) |
172 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
173 * | Configuration revision number |
174 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
175 * | Updater Identity IP address |
176 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
177 * | Update Timestamp (12 bytes) |
178 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
179 * | MD5 digest (16 bytes) |
180 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
181 *
182 */
183
184 ND_TCHECK_8(tptr);
185 ND_PRINT("\n\t Config Rev %x, Updater %s",
186 EXTRACT_BE_U_4(tptr),
187 ipaddr_string(ndo, tptr+4));
188 tptr += 8;
189 ND_TCHECK_LEN(tptr, VTP_UPDATE_TIMESTAMP_LEN);
190 ND_PRINT(", Timestamp 0x%08x 0x%08x 0x%08x",
191 EXTRACT_BE_U_4(tptr),
192 EXTRACT_BE_U_4(tptr + 4),
193 EXTRACT_BE_U_4(tptr + 8));
194 tptr += VTP_UPDATE_TIMESTAMP_LEN;
195 ND_TCHECK_LEN(tptr, VTP_MD5_DIGEST_LEN);
196 ND_PRINT(", MD5 digest: %08x%08x%08x%08x",
197 EXTRACT_BE_U_4(tptr),
198 EXTRACT_BE_U_4(tptr + 4),
199 EXTRACT_BE_U_4(tptr + 8),
200 EXTRACT_BE_U_4(tptr + 12));
201 tptr += VTP_MD5_DIGEST_LEN;
202 break;
203
204 case VTP_SUBSET_ADV:
205
206 /*
207 * SUBSET ADVERTISEMENT
208 *
209 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
210 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
211 * | Version | Code | Seq number | MgmtD Len |
212 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
213 * | Management Domain Name (zero-padded to 32 bytes) |
214 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
215 * | Configuration revision number |
216 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
217 * | VLAN info field 1 |
218 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
219 * | ................ |
220 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
221 * | VLAN info field N |
222 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
223 *
224 */
225
226 ND_TCHECK_4(tptr);
227 ND_PRINT(", Config Rev %x", EXTRACT_BE_U_4(tptr));
228
229 /*
230 * VLAN INFORMATION
231 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
232 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
233 * | V info len | Status | VLAN type | VLAN name len |
234 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
235 * | ISL vlan id | MTU size |
236 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
237 * | 802.10 index (SAID) |
238 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
239 * | VLAN name |
240 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
241 *
242 */
243
244 tptr += 4;
245 while (tptr < (pptr+length)) {
246
247 ND_TCHECK_1(tptr);
248 len = EXTRACT_U_1(tptr);
249 if (len == 0)
250 break;
251
252 ND_TCHECK_LEN(tptr, len);
253
254 vtp_vlan = (const struct vtp_vlan_*)tptr;
255 if (len < VTP_VLAN_INFO_FIXED_PART_LEN)
256 goto trunc;
257 ND_TCHECK_SIZE(vtp_vlan);
258 ND_PRINT("\n\tVLAN info status %s, type %s, VLAN-id %u, MTU %u, SAID 0x%08x, Name ",
259 tok2str(vtp_vlan_status,"Unknown",EXTRACT_U_1(vtp_vlan->status)),
260 tok2str(vtp_vlan_type_values,"Unknown",EXTRACT_U_1(vtp_vlan->type)),
261 EXTRACT_BE_U_2(vtp_vlan->vlanid),
262 EXTRACT_BE_U_2(vtp_vlan->mtu),
263 EXTRACT_BE_U_4(vtp_vlan->index));
264 len -= VTP_VLAN_INFO_FIXED_PART_LEN;
265 tptr += VTP_VLAN_INFO_FIXED_PART_LEN;
266 name_len = EXTRACT_U_1(vtp_vlan->name_len);
267 if (len < 4*((name_len + 3)/4))
268 goto trunc;
269 ND_TCHECK_LEN(tptr, name_len);
270 nd_printzp(ndo, tptr, name_len, NULL);
271
272 /*
273 * Vlan names are aligned to 32-bit boundaries.
274 */
275 len -= 4*((name_len + 3)/4);
276 tptr += 4*((name_len + 3)/4);
277
278 /* TLV information follows */
279
280 while (len > 0) {
281
282 /*
283 * Cisco specs say 2 bytes for type + 2 bytes for length;
284 * see http://docstore.mik.ua/univercd/cc/td/doc/product/lan/trsrb/frames.htm
285 * However, actual packets on the wire appear to use 1
286 * byte for the type and 1 byte for the length, so that's
287 * what we do.
288 */
289 if (len < 2)
290 goto trunc;
291 ND_TCHECK_2(tptr);
292 type = EXTRACT_U_1(tptr);
293 tlv_len = EXTRACT_U_1(tptr + 1);
294
295 ND_PRINT("\n\t\t%s (0x%04x) TLV",
296 tok2str(vtp_vlan_tlv_values, "Unknown", type),
297 type);
298
299 if (len < tlv_len * 2 + 2) {
300 ND_PRINT(" (TLV goes past the end of the packet)");
301 return;
302 }
303 ND_TCHECK_LEN(tptr, tlv_len * 2 + 2);
304
305 /*
306 * We assume the value is a 2-byte integer; the length is
307 * in units of 16-bit words.
308 */
309 if (tlv_len != 1) {
310 ND_PRINT(" (invalid TLV length %u != 1)", tlv_len);
311 return;
312 } else {
313 tlv_value = EXTRACT_BE_U_2(tptr + 2);
314
315 switch (type) {
316 case VTP_VLAN_STE_HOP_COUNT:
317 ND_PRINT(", %u", tlv_value);
318 break;
319
320 case VTP_VLAN_PRUNING:
321 ND_PRINT(", %s (%u)",
322 tlv_value == 1 ? "Enabled" : "Disabled",
323 tlv_value);
324 break;
325
326 case VTP_VLAN_STP_TYPE:
327 ND_PRINT(", %s (%u)",
328 tok2str(vtp_stp_type_values, "Unknown", tlv_value),
329 tlv_value);
330 break;
331
332 case VTP_VLAN_BRIDGE_TYPE:
333 ND_PRINT(", %s (%u)",
334 tlv_value == 1 ? "SRB" : "SRT",
335 tlv_value);
336 break;
337
338 case VTP_VLAN_BACKUP_CRF_MODE:
339 ND_PRINT(", %s (%u)",
340 tlv_value == 1 ? "Backup" : "Not backup",
341 tlv_value);
342 break;
343
344 /*
345 * FIXME those are the defined TLVs that lack a decoder
346 * you are welcome to contribute code ;-)
347 */
348
349 case VTP_VLAN_SOURCE_ROUTING_RING_NUMBER:
350 case VTP_VLAN_SOURCE_ROUTING_BRIDGE_NUMBER:
351 case VTP_VLAN_PARENT_VLAN:
352 case VTP_VLAN_TRANS_BRIDGED_VLAN:
353 case VTP_VLAN_ARP_HOP_COUNT:
354 default:
355 print_unknown_data(ndo, tptr, "\n\t\t ", 2 + tlv_len*2);
356 break;
357 }
358 }
359 len -= 2 + tlv_len*2;
360 tptr += 2 + tlv_len*2;
361 }
362 }
363 break;
364
365 case VTP_ADV_REQUEST:
366
367 /*
368 * ADVERTISEMENT REQUEST
369 *
370 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
371 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
372 * | Version | Code | Reserved | MgmtD Len |
373 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
374 * | Management Domain Name (zero-padded to 32 bytes) |
375 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
376 * | Start value |
377 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
378 *
379 */
380
381 ND_TCHECK_4(tptr);
382 ND_PRINT("\n\tStart value: %u", EXTRACT_BE_U_4(tptr));
383 break;
384
385 case VTP_JOIN_MESSAGE:
386
387 /* FIXME - Could not find message format */
388 break;
389
390 default:
391 break;
392 }
393
394 return;
395
396 trunc:
397 nd_print_trunc(ndo);
398 }