2 * Routines for the disassembly of Cisco's Virtual Trunking Protocol
4 * $Id: packet-vtp.c,v 1.19 2002/01/24 09:20:52 guy Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@ethereal.com>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 #ifdef HAVE_SYS_TYPES_H
28 #include <sys/types.h>
35 #include <epan/packet.h>
40 * http://www.cisco.com/univercd/cc/td/doc/product/lan/trsrb/frames.htm
42 * for some information on VTP.
44 * It's incomplete, and it appears to be inaccurate in a number of places,
45 * but it's all I could find....
48 static int proto_vtp = -1;
49 static int hf_vtp_version = -1;
50 static int hf_vtp_code = -1;
51 static int hf_vtp_followers = -1;
52 static int hf_vtp_md_len = -1;
53 static int hf_vtp_md = -1;
54 static int hf_vtp_conf_rev_num = -1;
55 static int hf_vtp_upd_id = -1;
56 static int hf_vtp_upd_ts = -1;
57 static int hf_vtp_md5_digest = -1;
58 static int hf_vtp_seq_num = -1;
59 static int hf_vtp_start_value = -1;
60 static int hf_vtp_vlan_info_len = -1;
61 static int hf_vtp_vlan_status_vlan_susp = -1;
62 static int hf_vtp_vlan_type = -1;
63 static int hf_vtp_vlan_name_len = -1;
64 static int hf_vtp_isl_vlan_id = -1;
65 static int hf_vtp_mtu_size = -1;
66 static int hf_vtp_802_10_index = -1;
67 static int hf_vtp_vlan_name = -1;
68 static int hf_vtp_vlan_tlvtype = -1;
69 static int hf_vtp_vlan_tlvlength = -1;
71 static gint ett_vtp = -1;
72 static gint ett_vtp_vlan_info = -1;
73 static gint ett_vtp_vlan_status = -1;
74 static gint ett_vtp_tlv = -1;
77 dissect_vlan_info(tvbuff_t *tvb, int offset, proto_tree *tree);
79 dissect_vlan_info_tlv(tvbuff_t *tvb, int offset, int length,
80 proto_tree *tree, proto_item *ti, guint8 type);
82 #define SUMMARY_ADVERT 0x01
83 #define SUBSET_ADVERT 0x02
84 #define ADVERT_REQUEST 0x03
86 static const value_string type_vals[] = {
87 { SUMMARY_ADVERT, "Summary-Advert" },
88 { SUBSET_ADVERT, "Subset-Advert" },
89 { ADVERT_REQUEST, "Advert-Request" },
94 dissect_vtp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
97 proto_tree *vtp_tree = NULL;
101 const guint8 *upd_timestamp;
104 if (check_col(pinfo->cinfo, COL_PROTOCOL))
105 col_set_str(pinfo->cinfo, COL_PROTOCOL, "VTP");
106 if (check_col(pinfo->cinfo, COL_INFO))
107 col_set_str(pinfo->cinfo, COL_INFO, "Virtual Trunking Protocol");
110 ti = proto_tree_add_item(tree, proto_vtp, tvb, offset, -1,
112 vtp_tree = proto_item_add_subtree(ti, ett_vtp);
114 proto_tree_add_item(vtp_tree, hf_vtp_version, tvb, offset, 1,
118 code = tvb_get_guint8(tvb, offset);
119 proto_tree_add_uint(vtp_tree, hf_vtp_code, tvb, offset, 1,
126 proto_tree_add_item(vtp_tree, hf_vtp_followers, tvb, offset,
130 md_len = tvb_get_guint8(tvb, offset);
131 proto_tree_add_uint(vtp_tree, hf_vtp_md_len, tvb, offset,
135 proto_tree_add_item(vtp_tree, hf_vtp_md, tvb, offset,
139 proto_tree_add_item(vtp_tree, hf_vtp_conf_rev_num, tvb,
143 proto_tree_add_item(vtp_tree, hf_vtp_upd_id, tvb,
147 upd_timestamp = tvb_get_ptr(tvb, offset, 12);
148 proto_tree_add_string_format(vtp_tree, hf_vtp_upd_ts, tvb,
149 offset, 12, upd_timestamp,
150 "Update Timestamp: %.2s-%.2s-%.2s %.2s:%.2s:%.2s",
151 &upd_timestamp[0], &upd_timestamp[2], &upd_timestamp[4],
152 &upd_timestamp[6], &upd_timestamp[8], &upd_timestamp[10]);
155 proto_tree_add_item(vtp_tree, hf_vtp_md5_digest, tvb,
160 proto_tree_add_item(vtp_tree, hf_vtp_seq_num, tvb, offset,
164 md_len = tvb_get_guint8(tvb, offset);
165 proto_tree_add_uint(vtp_tree, hf_vtp_md_len, tvb, offset,
169 proto_tree_add_item(vtp_tree, hf_vtp_md, tvb, offset,
173 proto_tree_add_item(vtp_tree, hf_vtp_conf_rev_num, tvb,
177 while (tvb_reported_length_remaining(tvb, offset) > 0) {
179 dissect_vlan_info(tvb, offset, vtp_tree);
180 if (vlan_info_len < 0)
182 offset += vlan_info_len;
187 offset += 1; /* skip reserved field */
189 md_len = tvb_get_guint8(tvb, offset);
190 proto_tree_add_uint(vtp_tree, hf_vtp_md_len, tvb, offset,
194 proto_tree_add_item(vtp_tree, hf_vtp_start_value, tvb,
200 * Mysterious type, seen a lot.
201 * Is this some mutant variant of Advert-Request?
203 offset += 1; /* skip unknown field */
205 md_len = tvb_get_guint8(tvb, offset);
206 proto_tree_add_uint(vtp_tree, hf_vtp_md_len, tvb, offset,
210 proto_tree_add_item(vtp_tree, hf_vtp_md, tvb, offset,
214 offset += 2; /* skip unknown field */
216 proto_tree_add_text(vtp_tree, tvb, offset, 2,
217 "VLAN ID of some sort: 0x%04x",
218 tvb_get_ntohs(tvb, offset));
225 #define VLAN_SUSPENDED 0x01
227 static const value_string vlan_type_vals[] = {
228 { 0x01, "Ethernet" },
231 { 0x04, "FDDI-net" },
236 #define SR_RING_NUM 0x01
237 #define SR_BRIDGE_NUM 0x02
238 #define STP_TYPE 0x03
239 #define PARENT_VLAN 0x04
240 #define TR_BRIDGED_VLANS 0x05
242 #define BRIDGE_TYPE 0x07
243 #define MAX_ARE_HOP_CNT 0x08
244 #define MAX_STE_HOP_CNT 0x09
245 #define BACKUP_CRF_MODE 0x0A
247 static const value_string vlan_tlv_type_vals[] = {
248 { SR_RING_NUM, "Source-Routing Ring Number" },
249 { SR_BRIDGE_NUM, "Source-Routing Bridge Number" },
250 { STP_TYPE, "Spanning-Tree Protocol Type" },
251 { PARENT_VLAN, "Parent VLAN" },
252 { TR_BRIDGED_VLANS, "Translationally Bridged VLANs" },
253 { PRUNING, "Pruning" },
254 { BRIDGE_TYPE, "Bridge Type" },
255 { MAX_ARE_HOP_CNT, "Max ARE Hop Count" },
256 { MAX_STE_HOP_CNT, "Max STE Hop Count" },
257 { BACKUP_CRF_MODE, "Backup CRF Mode" },
262 dissect_vlan_info(tvbuff_t *tvb, int offset, proto_tree *tree)
265 proto_tree *vlan_info_tree;
266 proto_tree *status_tree;
267 guint8 vlan_info_len;
270 guint8 vlan_name_len;
273 proto_tree *tlv_tree;
275 vlan_info_len = tvb_get_guint8(tvb, offset);
276 ti = proto_tree_add_text(tree, tvb, offset, vlan_info_len,
278 vlan_info_tree = proto_item_add_subtree(ti, ett_vtp_vlan_info);
279 vlan_info_left = vlan_info_len;
281 proto_tree_add_uint(vlan_info_tree, hf_vtp_vlan_info_len, tvb, offset, 1,
286 if (vlan_info_left < 1)
288 status = tvb_get_guint8(tvb, offset);
289 ti = proto_tree_add_text(vlan_info_tree, tvb, offset, 1,
290 "Status: 0x%02x%s", status,
291 (status & VLAN_SUSPENDED) ? "(VLAN suspended)" : "");
292 status_tree = proto_item_add_subtree(ti, ett_vtp_vlan_status);
293 proto_tree_add_boolean(status_tree, hf_vtp_vlan_status_vlan_susp, tvb, offset, 1,
298 if (vlan_info_left < 1)
300 proto_tree_add_item(vlan_info_tree, hf_vtp_vlan_type, tvb, offset, 1,
305 if (vlan_info_left < 1)
307 vlan_name_len = tvb_get_guint8(tvb, offset);
308 proto_tree_add_uint(vlan_info_tree, hf_vtp_vlan_name_len, tvb, offset, 1,
313 if (vlan_info_left < 2)
315 proto_tree_add_item(vlan_info_tree, hf_vtp_isl_vlan_id, tvb, offset, 2,
320 if (vlan_info_left < 2)
322 proto_tree_add_item(vlan_info_tree, hf_vtp_mtu_size, tvb, offset, 2,
327 if (vlan_info_left < 4)
329 proto_tree_add_item(vlan_info_tree, hf_vtp_802_10_index, tvb, offset, 4,
334 /* VLAN name length appears to be rounded up to a multiple of 4. */
335 vlan_name_len = 4*((vlan_name_len + 3)/4);
336 if (vlan_info_left < vlan_name_len)
338 proto_tree_add_item(vlan_info_tree, hf_vtp_vlan_name, tvb, offset,
339 vlan_name_len, FALSE);
340 offset += vlan_name_len;
341 vlan_info_left -= vlan_name_len;
343 while (vlan_info_left > 0) {
344 type = tvb_get_guint8(tvb, offset + 0);
345 length = tvb_get_guint8(tvb, offset + 1);
347 ti = proto_tree_add_text(vlan_info_tree, tvb, offset,
349 val_to_str(type, vlan_tlv_type_vals,
350 "Unknown TLV type: 0x%02x"));
351 tlv_tree = proto_item_add_subtree(ti, ett_vtp_tlv);
352 proto_tree_add_uint(tlv_tree, hf_vtp_vlan_tlvtype, tvb, offset,
354 proto_tree_add_uint(tlv_tree, hf_vtp_vlan_tlvlength, tvb, offset+1,
359 dissect_vlan_info_tlv(tvb, offset, length*2, tlv_tree,
363 vlan_info_left -= length*2;
366 return vlan_info_len;
369 static const value_string stp_type_vals[] = {
376 static const value_string pruning_vals[] = {
382 static const value_string bridge_type_vals[] = {
388 static const value_string backup_crf_mode_vals[] = {
389 { 1, "TrCRF is configured as a backup" },
390 { 2, "TrCRF is not configured as a backup" },
395 dissect_vlan_info_tlv(tvbuff_t *tvb, int offset, int length,
396 proto_tree *tree, proto_item *ti, guint8 type)
402 proto_item_set_text(ti,
403 "Source-Routing Ring Number: 0x%04x",
404 tvb_get_ntohs(tvb, offset));
405 proto_tree_add_text(tree, tvb, offset, 2,
406 "Source-Routing Ring Number: 0x%04x",
407 tvb_get_ntohs(tvb, offset));
409 proto_item_set_text(ti,
410 "Source-Routing Ring Number: Bad length %u",
412 proto_tree_add_text(tree, tvb, offset, length,
413 "Source-Routing Ring Number: Bad length %u",
420 proto_item_set_text(ti,
421 "Source-Routing Bridge Number: 0x%04x",
422 tvb_get_ntohs(tvb, offset));
423 proto_tree_add_text(tree, tvb, offset, 2,
424 "Source-Routing Bridge Number: 0x%04x",
425 tvb_get_ntohs(tvb, offset));
427 proto_item_set_text(ti,
428 "Source-Routing Bridge Number: Bad length %u",
430 proto_tree_add_text(tree, tvb, offset, length,
431 "Source-Routing Bridge Number: Bad length %u",
438 proto_item_set_text(ti,
439 "Spanning-Tree Protocol Type: %s",
440 val_to_str(tvb_get_ntohs(tvb, offset), stp_type_vals,
441 "Unknown (0x%04x)"));
442 proto_tree_add_text(tree, tvb, offset, 2,
443 "Spanning-Tree Protocol Type: %s",
444 val_to_str(tvb_get_ntohs(tvb, offset), stp_type_vals,
445 "Unknown (0x%04x)"));
447 proto_item_set_text(ti,
448 "Spanning-Tree Protocol Type: Bad length %u",
450 proto_tree_add_text(tree, tvb, offset, length,
451 "Spanning-Tree Protocol Type: Bad length %u",
458 proto_item_set_text(ti,
459 "Parent VLAN: 0x%04x",
460 tvb_get_ntohs(tvb, offset));
461 proto_tree_add_text(tree, tvb, offset, 2,
462 "Parent VLAN: 0x%04x",
463 tvb_get_ntohs(tvb, offset));
465 proto_item_set_text(ti,
466 "Parent VLAN: Bad length %u",
468 proto_tree_add_text(tree, tvb, offset, length,
469 "Parent VLAN: Bad length %u",
474 case TR_BRIDGED_VLANS:
476 proto_item_set_text(ti,
477 "Translationally Bridged VLANs: 0x%04x",
478 tvb_get_ntohs(tvb, offset));
479 proto_tree_add_text(tree, tvb, offset, 2,
480 "Translationally Bridged VLANs: 0x%04x",
481 tvb_get_ntohs(tvb, offset));
483 proto_item_set_text(ti,
484 "Translationally Bridged VLANs: Bad length %u",
486 proto_tree_add_text(tree, tvb, offset, length,
487 "Translationally Bridged VLANs: Bad length %u",
494 proto_item_set_text(ti,
496 val_to_str(tvb_get_ntohs(tvb, offset), pruning_vals,
497 "Unknown (0x%04x)"));
498 proto_tree_add_text(tree, tvb, offset, 2,
500 val_to_str(tvb_get_ntohs(tvb, offset), pruning_vals,
501 "Unknown (0x%04x)"));
503 proto_item_set_text(ti,
504 "Pruning: Bad length %u",
506 proto_tree_add_text(tree, tvb, offset, length,
507 "Pruning: Bad length %u",
514 proto_item_set_text(ti,
516 val_to_str(tvb_get_ntohs(tvb, offset), bridge_type_vals,
517 "Unknown (0x%04x)"));
518 proto_tree_add_text(tree, tvb, offset, 2,
520 val_to_str(tvb_get_ntohs(tvb, offset), bridge_type_vals,
521 "Unknown (0x%04x)"));
523 proto_item_set_text(ti,
524 "Bridge Type: Bad length %u",
526 proto_tree_add_text(tree, tvb, offset, length,
527 "Bridge Type: Bad length %u",
532 case MAX_ARE_HOP_CNT:
534 proto_item_set_text(ti,
535 "Max ARE Hop Count: %u",
536 tvb_get_ntohs(tvb, offset));
537 proto_tree_add_text(tree, tvb, offset, 2,
538 "Max ARE Hop Count: %u",
539 tvb_get_ntohs(tvb, offset));
541 proto_item_set_text(ti,
542 "Max ARE Hop Count: Bad length %u",
544 proto_tree_add_text(tree, tvb, offset, length,
545 "Max ARE Hop Count: Bad length %u",
550 case MAX_STE_HOP_CNT:
552 proto_item_set_text(ti,
553 "Max STE Hop Count: %u",
554 tvb_get_ntohs(tvb, offset));
555 proto_tree_add_text(tree, tvb, offset, 2,
556 "Max STE Hop Count: %u",
557 tvb_get_ntohs(tvb, offset));
559 proto_item_set_text(ti,
560 "Max STE Hop Count: Bad length %u",
562 proto_tree_add_text(tree, tvb, offset, length,
563 "Max STE Hop Count: Bad length %u",
568 case BACKUP_CRF_MODE:
570 proto_item_set_text(ti,
571 "Backup CRF Mode: %s",
572 val_to_str(tvb_get_ntohs(tvb, offset), backup_crf_mode_vals,
573 "Unknown (0x%04x)"));
574 proto_tree_add_text(tree, tvb, offset, 2,
575 "Backup CRF Mode: %s",
576 val_to_str(tvb_get_ntohs(tvb, offset), backup_crf_mode_vals,
577 "Unknown (0x%04x)"));
579 proto_item_set_text(ti,
580 "Backup CRF Mode: Bad length %u",
582 proto_tree_add_text(tree, tvb, offset, length,
583 "Backup CRF Mode: Bad length %u",
589 proto_tree_add_text(tree, tvb, offset, length, "Data");
595 proto_register_vtp(void)
597 static hf_register_info hf[] = {
599 { "Version", "vtp.version", FT_UINT8, BASE_HEX, NULL, 0x0,
603 { "Code", "vtp.code", FT_UINT8, BASE_HEX, VALS(type_vals), 0x0,
607 { "Followers", "vtp.followers", FT_UINT8, BASE_DEC, NULL, 0x0,
608 "Number of following Subset-Advert messages", HFILL }},
611 { "Management Domain Length", "vtp.md_len", FT_UINT8, BASE_DEC, NULL, 0x0,
612 "Length of management domain string", HFILL }},
615 { "Management Domain", "vtp.md", FT_STRING, BASE_DEC, NULL, 0,
616 "Management domain", HFILL }},
618 { &hf_vtp_conf_rev_num,
619 { "Configuration Revision Number", "vtp.conf_rev_num", FT_UINT32, BASE_DEC, NULL, 0x0,
620 "Revision number of the configuration information", HFILL }},
623 { "Updater Identity", "vtp.upd_id", FT_IPv4, BASE_NONE, NULL, 0x0,
624 "IP address of the updater", HFILL }},
627 { "Update Timestamp", "vtp.upd_ts", FT_STRING, BASE_DEC, NULL, 0,
628 "Time stamp of the current configuration revision", HFILL }},
630 { &hf_vtp_md5_digest,
631 { "MD5 Digest", "vtp.md5_digest", FT_BYTES, BASE_HEX, NULL, 0x0,
635 { "Sequence Number", "vtp.seq_num", FT_UINT8, BASE_DEC, NULL, 0x0,
636 "Order of this frame in the sequence of Subset-Advert frames", HFILL }},
638 { &hf_vtp_start_value,
639 { "Start Value", "vtp.start_value", FT_UINT16, BASE_HEX, NULL, 0x0,
640 "Virtual LAN ID of first VLAN for which information is requested", HFILL }},
642 { &hf_vtp_vlan_info_len,
643 { "VLAN Information Length", "vtp.vlan_info.len", FT_UINT8, BASE_DEC, NULL, 0x0,
644 "Length of the VLAN information field", HFILL }},
646 { &hf_vtp_vlan_status_vlan_susp,
647 { "VLAN suspended", "vtp.vlan_info.status.vlan_susp", FT_BOOLEAN, 8, NULL, VLAN_SUSPENDED,
648 "VLAN suspended", HFILL }},
651 { "VLAN Type", "vtp.vlan_info.vlan_type", FT_UINT8, BASE_HEX, VALS(vlan_type_vals), 0x0,
652 "Type of VLAN", HFILL }},
654 { &hf_vtp_vlan_name_len,
655 { "VLAN Name Length", "vtp.vlan_info.vlan_name_len", FT_UINT8, BASE_DEC, NULL, 0x0,
656 "Length of VLAN name string", HFILL }},
658 { &hf_vtp_isl_vlan_id,
659 { "ISL VLAN ID", "vtp.vlan_info.isl_vlan_id", FT_UINT16, BASE_HEX, NULL, 0x0,
660 "ID of this VLAN on ISL trunks", HFILL }},
663 { "MTU Size", "vtp.vlan_info.mtu_size", FT_UINT16, BASE_DEC, NULL, 0x0,
664 "MTU for this VLAN", HFILL }},
666 { &hf_vtp_802_10_index,
667 { "802.10 Index", "vtp.vlan_info.802_10_index", FT_UINT32, BASE_HEX, NULL, 0x0,
668 "IEEE 802.10 security association identifier for this VLAN", HFILL }},
671 { "VLAN Name", "vtp.vlan_info.vlan_name", FT_STRING, BASE_DEC, NULL, 0,
672 "VLAN name", HFILL }},
674 { &hf_vtp_vlan_tlvtype,
675 { "Type", "vtp.vlan_info.tlv_type", FT_UINT8, BASE_HEX, VALS(vlan_tlv_type_vals), 0x0,
678 { &hf_vtp_vlan_tlvlength,
679 { "Length", "vtp.vlan_info.tlv_len", FT_UINT8, BASE_DEC, NULL, 0x0,
682 static gint *ett[] = {
685 &ett_vtp_vlan_status,
689 proto_vtp = proto_register_protocol("Virtual Trunking Protocol",
691 proto_register_field_array(proto_vtp, hf, array_length(hf));
692 proto_register_subtree_array(ett, array_length(ett));
696 proto_reg_handoff_vtp(void)
698 dissector_handle_t vtp_handle;
700 vtp_handle = create_dissector_handle(dissect_vtp, proto_vtp);
701 dissector_add("llc.cisco_pid", 0x2003, vtp_handle);