2 * Routines for the disassembly of Cisco's Virtual Trunking Protocol
4 * $Id: packet-vtp.c,v 1.13 2001/03/13 21:34:24 gram Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@zing.org>
8 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 #ifdef HAVE_SYS_TYPES_H
29 #include <sys/types.h>
41 * http://www.cisco.com/univercd/cc/td/doc/product/lan/trsrb/frames.htm
43 * for some information on VTP.
45 * It's incomplete, and it appears to be inaccurate in a number of places,
46 * but it's all I could find....
49 static int proto_vtp = -1;
50 static int hf_vtp_version = -1;
51 static int hf_vtp_code = -1;
52 static int hf_vtp_followers = -1;
53 static int hf_vtp_md_len = -1;
54 static int hf_vtp_md = -1;
55 static int hf_vtp_conf_rev_num = -1;
56 static int hf_vtp_upd_id = -1;
57 static int hf_vtp_upd_ts = -1;
58 static int hf_vtp_md5_digest = -1;
59 static int hf_vtp_seq_num = -1;
60 static int hf_vtp_start_value = -1;
61 static int hf_vtp_vlan_info_len = -1;
62 static int hf_vtp_vlan_status_vlan_susp = -1;
63 static int hf_vtp_vlan_type = -1;
64 static int hf_vtp_vlan_name_len = -1;
65 static int hf_vtp_isl_vlan_id = -1;
66 static int hf_vtp_mtu_size = -1;
67 static int hf_vtp_802_10_index = -1;
68 static int hf_vtp_vlan_name = -1;
69 static int hf_vtp_vlan_tlvtype = -1;
70 static int hf_vtp_vlan_tlvlength = -1;
72 static gint ett_vtp = -1;
73 static gint ett_vtp_vlan_info = -1;
74 static gint ett_vtp_vlan_status = -1;
75 static gint ett_vtp_tlv = -1;
78 dissect_vlan_info(tvbuff_t *tvb, int offset, proto_tree *tree);
80 dissect_vlan_info_tlv(tvbuff_t *tvb, int offset, int length,
81 proto_tree *tree, proto_item *ti, guint8 type);
83 #define SUMMARY_ADVERT 0x01
84 #define SUBSET_ADVERT 0x02
85 #define ADVERT_REQUEST 0x03
87 static const value_string type_vals[] = {
88 { SUMMARY_ADVERT, "Summary-Advert" },
89 { SUBSET_ADVERT, "Subset-Advert" },
90 { ADVERT_REQUEST, "Advert-Request" },
95 dissect_vtp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
98 proto_tree *vtp_tree = NULL;
102 const guint8 *upd_timestamp;
105 if (check_col(pinfo->fd, COL_PROTOCOL))
106 col_set_str(pinfo->fd, COL_PROTOCOL, "VTP");
107 if (check_col(pinfo->fd, COL_INFO))
108 col_set_str(pinfo->fd, COL_INFO, "Virtual Trunking Protocol");
111 ti = proto_tree_add_item(tree, proto_vtp, tvb, offset,
112 tvb_length_remaining(tvb, offset), FALSE);
113 vtp_tree = proto_item_add_subtree(ti, ett_vtp);
115 proto_tree_add_item(vtp_tree, hf_vtp_version, tvb, offset, 1,
119 code = tvb_get_guint8(tvb, offset);
120 proto_tree_add_uint(vtp_tree, hf_vtp_code, tvb, offset, 1,
127 proto_tree_add_item(vtp_tree, hf_vtp_followers, tvb, offset,
131 md_len = tvb_get_guint8(tvb, offset);
132 proto_tree_add_uint(vtp_tree, hf_vtp_md_len, tvb, offset,
136 proto_tree_add_item(vtp_tree, hf_vtp_md, tvb, offset,
140 proto_tree_add_item(vtp_tree, hf_vtp_conf_rev_num, tvb,
144 proto_tree_add_item(vtp_tree, hf_vtp_upd_id, tvb,
148 upd_timestamp = tvb_get_ptr(tvb, offset, 12);
149 proto_tree_add_string_format(vtp_tree, hf_vtp_upd_ts, tvb,
150 offset, 12, upd_timestamp,
151 "Update Timestamp: %.2s-%.2s-%.2s %.2s:%.2s:%.2s",
152 &upd_timestamp[0], &upd_timestamp[2], &upd_timestamp[4],
153 &upd_timestamp[6], &upd_timestamp[8], &upd_timestamp[10]);
156 proto_tree_add_item(vtp_tree, hf_vtp_md5_digest, tvb,
161 proto_tree_add_item(vtp_tree, hf_vtp_seq_num, tvb, offset,
165 md_len = tvb_get_guint8(tvb, offset);
166 proto_tree_add_uint(vtp_tree, hf_vtp_md_len, tvb, offset,
170 proto_tree_add_item(vtp_tree, hf_vtp_md, tvb, offset,
174 proto_tree_add_item(vtp_tree, hf_vtp_conf_rev_num, tvb,
178 while (tvb_reported_length_remaining(tvb, offset) > 0) {
180 dissect_vlan_info(tvb, offset, vtp_tree);
181 if (vlan_info_len < 0)
183 offset += vlan_info_len;
188 offset += 1; /* skip reserved field */
190 md_len = tvb_get_guint8(tvb, offset);
191 proto_tree_add_uint(vtp_tree, hf_vtp_md_len, tvb, offset,
195 proto_tree_add_item(vtp_tree, hf_vtp_start_value, tvb,
201 * Mysterious type, seen a lot.
202 * Is this some mutant variant of Advert-Request?
204 offset += 1; /* skip unknown field */
206 md_len = tvb_get_guint8(tvb, offset);
207 proto_tree_add_uint(vtp_tree, hf_vtp_md_len, tvb, offset,
211 proto_tree_add_item(vtp_tree, hf_vtp_md, tvb, offset,
215 offset += 2; /* skip unknown field */
217 proto_tree_add_text(vtp_tree, tvb, offset, 2,
218 "VLAN ID of some sort: 0x%04x",
219 tvb_get_ntohs(tvb, offset));
226 #define VLAN_SUSPENDED 0x01
228 static const value_string vlan_type_vals[] = {
229 { 0x01, "Ethernet" },
232 { 0x04, "FDDI-net" },
237 #define SR_RING_NUM 0x01
238 #define SR_BRIDGE_NUM 0x02
239 #define STP_TYPE 0x03
240 #define PARENT_VLAN 0x04
241 #define TR_BRIDGED_VLANS 0x05
243 #define BRIDGE_TYPE 0x07
244 #define MAX_ARE_HOP_CNT 0x08
245 #define MAX_STE_HOP_CNT 0x09
246 #define BACKUP_CRF_MODE 0x0A
248 static const value_string vlan_tlv_type_vals[] = {
249 { SR_RING_NUM, "Source-Routing Ring Number" },
250 { SR_BRIDGE_NUM, "Source-Routing Bridge Number" },
251 { STP_TYPE, "Spanning-Tree Protocol Type" },
252 { PARENT_VLAN, "Parent VLAN" },
253 { TR_BRIDGED_VLANS, "Translationally Bridged VLANs" },
254 { PRUNING, "Pruning" },
255 { BRIDGE_TYPE, "Bridge Type" },
256 { MAX_ARE_HOP_CNT, "Max ARE Hop Count" },
257 { MAX_STE_HOP_CNT, "Max STE Hop Count" },
258 { BACKUP_CRF_MODE, "Backup CRF Mode" },
263 dissect_vlan_info(tvbuff_t *tvb, int offset, proto_tree *tree)
266 proto_tree *vlan_info_tree;
267 proto_tree *status_tree;
268 guint8 vlan_info_len;
271 guint8 vlan_name_len;
275 proto_tree *tlv_tree;
277 vlan_info_len = tvb_get_guint8(tvb, offset);
278 ti = proto_tree_add_text(tree, tvb, offset, vlan_info_len,
280 vlan_info_tree = proto_item_add_subtree(ti, ett_vtp_vlan_info);
281 vlan_info_left = vlan_info_len;
283 proto_tree_add_uint(vlan_info_tree, hf_vtp_vlan_info_len, tvb, offset, 1,
288 if (vlan_info_left < 1)
290 status = tvb_get_guint8(tvb, offset);
291 ti = proto_tree_add_text(vlan_info_tree, tvb, offset, 1,
292 "Status: 0x%02x%s", status,
293 (status & VLAN_SUSPENDED) ? "(VLAN suspended)" : "");
294 status_tree = proto_item_add_subtree(ti, ett_vtp_vlan_status);
295 proto_tree_add_boolean(status_tree, hf_vtp_vlan_status_vlan_susp, tvb, offset, 1,
300 if (vlan_info_left < 1)
302 proto_tree_add_item(vlan_info_tree, hf_vtp_vlan_type, tvb, offset, 1,
307 if (vlan_info_left < 1)
309 vlan_name_len = tvb_get_guint8(tvb, offset);
310 proto_tree_add_uint(vlan_info_tree, hf_vtp_vlan_name_len, tvb, offset, 1,
315 if (vlan_info_left < 2)
317 proto_tree_add_item(vlan_info_tree, hf_vtp_isl_vlan_id, tvb, offset, 2,
322 if (vlan_info_left < 2)
324 proto_tree_add_item(vlan_info_tree, hf_vtp_mtu_size, tvb, offset, 2,
329 if (vlan_info_left < 4)
331 proto_tree_add_item(vlan_info_tree, hf_vtp_802_10_index, tvb, offset, 4,
336 /* VLAN name length appears to be rounded up to a multiple of 4. */
337 vlan_name_len = 4*((vlan_name_len + 3)/4);
338 if (vlan_info_left < vlan_name_len)
340 proto_tree_add_item(vlan_info_tree, hf_vtp_vlan_name, tvb, offset,
341 vlan_name_len, FALSE);
342 offset += vlan_name_len;
343 vlan_info_left -= vlan_name_len;
345 while (vlan_info_left > 0) {
346 type = tvb_get_guint8(tvb, offset + 0);
347 length = tvb_get_guint8(tvb, offset + 1);
348 type_str = val_to_str(type, vlan_tlv_type_vals,
351 ti = proto_tree_add_notext(vlan_info_tree, tvb, offset,
353 tlv_tree = proto_item_add_subtree(ti, ett_vtp_tlv);
354 proto_tree_add_uint(tlv_tree, hf_vtp_vlan_tlvtype, tvb, offset,
356 proto_tree_add_uint(tlv_tree, hf_vtp_vlan_tlvlength, tvb, offset+1,
361 dissect_vlan_info_tlv(tvb, offset, length*2, tlv_tree,
365 vlan_info_left -= length*2;
368 return vlan_info_len;
371 static const value_string stp_type_vals[] = {
378 static const value_string pruning_vals[] = {
384 static const value_string bridge_type_vals[] = {
390 static const value_string backup_crf_mode_vals[] = {
391 { 1, "TrCRF is configured as a backup" },
392 { 2, "TrCRF is not configured as a backup" },
397 dissect_vlan_info_tlv(tvbuff_t *tvb, int offset, int length,
398 proto_tree *tree, proto_item *ti, guint8 type)
404 proto_item_set_text(ti,
405 "Source-Routing Ring Number: 0x%04x",
406 tvb_get_ntohs(tvb, offset));
407 proto_tree_add_text(tree, tvb, offset, 2,
408 "Source-Routing Ring Number: 0x%04x",
409 tvb_get_ntohs(tvb, offset));
411 proto_item_set_text(ti,
412 "Source-Routing Ring Number: Bad length %u",
414 proto_tree_add_text(tree, tvb, offset, length,
415 "Source-Routing Ring Number: Bad length %u",
422 proto_item_set_text(ti,
423 "Source-Routing Bridge Number: 0x%04x",
424 tvb_get_ntohs(tvb, offset));
425 proto_tree_add_text(tree, tvb, offset, 2,
426 "Source-Routing Bridge Number: 0x%04x",
427 tvb_get_ntohs(tvb, offset));
429 proto_item_set_text(ti,
430 "Source-Routing Bridge Number: Bad length %u",
432 proto_tree_add_text(tree, tvb, offset, length,
433 "Source-Routing Bridge Number: Bad length %u",
440 proto_item_set_text(ti,
441 "Spanning-Tree Protocol Type: %s",
442 val_to_str(tvb_get_ntohs(tvb, offset), stp_type_vals,
443 "Unknown (0x%04x)"));
444 proto_tree_add_text(tree, tvb, offset, 2,
445 "Spanning-Tree Protocol Type: %s",
446 val_to_str(tvb_get_ntohs(tvb, offset), stp_type_vals,
447 "Unknown (0x%04x)"));
449 proto_item_set_text(ti,
450 "Spanning-Tree Protocol Type: Bad length %u",
452 proto_tree_add_text(tree, tvb, offset, length,
453 "Spanning-Tree Protocol Type: Bad length %u",
460 proto_item_set_text(ti,
461 "Parent VLAN: 0x%04x",
462 tvb_get_ntohs(tvb, offset));
463 proto_tree_add_text(tree, tvb, offset, 2,
464 "Parent VLAN: 0x%04x",
465 tvb_get_ntohs(tvb, offset));
467 proto_item_set_text(ti,
468 "Parent VLAN: Bad length %u",
470 proto_tree_add_text(tree, tvb, offset, length,
471 "Parent VLAN: Bad length %u",
476 case TR_BRIDGED_VLANS:
478 proto_item_set_text(ti,
479 "Translationally Bridged VLANs: 0x%04x",
480 tvb_get_ntohs(tvb, offset));
481 proto_tree_add_text(tree, tvb, offset, 2,
482 "Translationally Bridged VLANs: 0x%04x",
483 tvb_get_ntohs(tvb, offset));
485 proto_item_set_text(ti,
486 "Translationally Bridged VLANs: Bad length %u",
488 proto_tree_add_text(tree, tvb, offset, length,
489 "Translationally Bridged VLANs: Bad length %u",
496 proto_item_set_text(ti,
498 val_to_str(tvb_get_ntohs(tvb, offset), pruning_vals,
499 "Unknown (0x%04x)"));
500 proto_tree_add_text(tree, tvb, offset, 2,
502 val_to_str(tvb_get_ntohs(tvb, offset), pruning_vals,
503 "Unknown (0x%04x)"));
505 proto_item_set_text(ti,
506 "Pruning: Bad length %u",
508 proto_tree_add_text(tree, tvb, offset, length,
509 "Pruning: Bad length %u",
516 proto_item_set_text(ti,
518 val_to_str(tvb_get_ntohs(tvb, offset), bridge_type_vals,
519 "Unknown (0x%04x)"));
520 proto_tree_add_text(tree, tvb, offset, 2,
522 val_to_str(tvb_get_ntohs(tvb, offset), bridge_type_vals,
523 "Unknown (0x%04x)"));
525 proto_item_set_text(ti,
526 "Bridge Type: Bad length %u",
528 proto_tree_add_text(tree, tvb, offset, length,
529 "Bridge Type: Bad length %u",
534 case MAX_ARE_HOP_CNT:
536 proto_item_set_text(ti,
537 "Max ARE Hop Count: %u",
538 tvb_get_ntohs(tvb, offset));
539 proto_tree_add_text(tree, tvb, offset, 2,
540 "Max ARE Hop Count: %u",
541 tvb_get_ntohs(tvb, offset));
543 proto_item_set_text(ti,
544 "Max ARE Hop Count: Bad length %u",
546 proto_tree_add_text(tree, tvb, offset, length,
547 "Max ARE Hop Count: Bad length %u",
552 case MAX_STE_HOP_CNT:
554 proto_item_set_text(ti,
555 "Max STE Hop Count: %u",
556 tvb_get_ntohs(tvb, offset));
557 proto_tree_add_text(tree, tvb, offset, 2,
558 "Max STE Hop Count: %u",
559 tvb_get_ntohs(tvb, offset));
561 proto_item_set_text(ti,
562 "Max STE Hop Count: Bad length %u",
564 proto_tree_add_text(tree, tvb, offset, length,
565 "Max STE Hop Count: Bad length %u",
570 case BACKUP_CRF_MODE:
572 proto_item_set_text(ti,
573 "Backup CRF Mode: %s",
574 val_to_str(tvb_get_ntohs(tvb, offset), backup_crf_mode_vals,
575 "Unknown (0x%04x)"));
576 proto_tree_add_text(tree, tvb, offset, 2,
577 "Backup CRF Mode: %s",
578 val_to_str(tvb_get_ntohs(tvb, offset), backup_crf_mode_vals,
579 "Unknown (0x%04x)"));
581 proto_item_set_text(ti,
582 "Backup CRF Mode: Bad length %u",
584 proto_tree_add_text(tree, tvb, offset, length,
585 "Backup CRF Mode: Bad length %u",
591 proto_item_set_text(ti, "Unknown TLV type: 0x%02x", type);
592 proto_tree_add_text(tree, tvb, offset, length, "Data");
598 proto_register_vtp(void)
600 static hf_register_info hf[] = {
602 { "Version", "vtp.version", FT_UINT8, BASE_HEX, NULL, 0x0,
606 { "Code", "vtp.code", FT_UINT8, BASE_HEX, VALS(type_vals), 0x0,
610 { "Followers", "vtp.followers", FT_UINT8, BASE_DEC, NULL, 0x0,
611 "Number of following Subset-Advert messages" }},
614 { "Management Domain Length", "vtp.md_len", FT_UINT8, BASE_DEC, NULL, 0x0,
615 "Length of management domain string" }},
618 { "Management Domain", "vtp.md", FT_STRING, BASE_DEC, NULL, 0,
619 "Management domain" }},
621 { &hf_vtp_conf_rev_num,
622 { "Configuration Revision Number", "vtp.conf_rev_num", FT_UINT32, BASE_DEC, NULL, 0x0,
623 "Revision number of the configuration information" }},
626 { "Updater Identity", "vtp.upd_id", FT_IPv4, BASE_NONE, NULL, 0x0,
627 "IP address of the updater" }},
630 { "Update Timestamp", "vtp.upd_ts", FT_STRING, BASE_DEC, NULL, 0,
631 "Time stamp of the current configuration revision" }},
633 { &hf_vtp_md5_digest,
634 { "MD5 Digest", "vtp.md5_digest", FT_BYTES, BASE_HEX, NULL, 0x0,
638 { "Sequence Number", "vtp.seq_num", FT_UINT8, BASE_DEC, NULL, 0x0,
639 "Order of this frame in the sequence of Subset-Advert frames" }},
641 { &hf_vtp_start_value,
642 { "Start Value", "vtp.start_value", FT_UINT16, BASE_HEX, NULL, 0x0,
643 "Virtual LAN ID of first VLAN for which information is requested" }},
645 { &hf_vtp_vlan_info_len,
646 { "VLAN Information Length", "vtp.vlan_info.len", FT_UINT8, BASE_DEC, NULL, 0x0,
647 "Length of the VLAN information field" }},
649 { &hf_vtp_vlan_status_vlan_susp,
650 { "VLAN suspended", "vtp.vlan_info.status.vlan_susp", FT_BOOLEAN, 8, NULL, VLAN_SUSPENDED,
654 { "VLAN Type", "vtp.vlan_info.vlan_type", FT_UINT8, BASE_HEX, VALS(vlan_type_vals), 0x0,
657 { &hf_vtp_vlan_name_len,
658 { "VLAN Name Length", "vtp.vlan_info.vlan_name_len", FT_UINT8, BASE_DEC, NULL, 0x0,
659 "Length of VLAN name string" }},
661 { &hf_vtp_isl_vlan_id,
662 { "ISL VLAN ID", "vtp.vlan_info.isl_vlan_id", FT_UINT16, BASE_HEX, NULL, 0x0,
663 "ID of this VLAN on ISL trunks" }},
666 { "MTU Size", "vtp.vlan_info.mtu_size", FT_UINT16, BASE_DEC, NULL, 0x0,
667 "MTU for this VLAN" }},
669 { &hf_vtp_802_10_index,
670 { "802.10 Index", "vtp.vlan_info.802_10_index", FT_UINT32, BASE_HEX, NULL, 0x0,
671 "IEEE 802.10 security association identifier for this VLAN" }},
674 { "VLAN Name", "vtp.vlan_info.vlan_name", FT_STRING, BASE_DEC, NULL, 0,
677 { &hf_vtp_vlan_tlvtype,
678 { "Type", "vtp.vlan_info.tlv_type", FT_UINT8, BASE_HEX, VALS(vlan_tlv_type_vals), 0x0,
681 { &hf_vtp_vlan_tlvlength,
682 { "Length", "vtp.vlan_info.tlv_len", FT_UINT8, BASE_DEC, NULL, 0x0,
685 static gint *ett[] = {
688 &ett_vtp_vlan_status,
692 proto_vtp = proto_register_protocol("Virtual Trunking Protocol",
694 proto_register_field_array(proto_vtp, hf, array_length(hf));
695 proto_register_subtree_array(ett, array_length(ett));
699 proto_reg_handoff_vtp(void)
701 dissector_add("llc.cisco_pid", 0x2003, dissect_vtp, proto_vtp);