2 * Routines for the disassembly of Cisco's Virtual Trunking Protocol
4 * $Id: packet-vtp.c,v 1.1 2000/02/05 09:19:04 guy 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(const u_char *pd, int offset, proto_tree *tree);
80 dissect_vlan_info_tlv(const u_char *pd, 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(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
98 proto_tree *vtp_tree = NULL;
103 if (check_col(fd, COL_PROTOCOL))
104 col_add_str(fd, COL_PROTOCOL, "VTP");
105 if (check_col(fd, COL_INFO))
106 col_add_str(fd, COL_INFO, "Virtual Trunking Protocol");
109 ti = proto_tree_add_item(tree, proto_vtp, offset, END_OF_FRAME,
111 vtp_tree = proto_item_add_subtree(ti, ett_vtp);
113 proto_tree_add_item(vtp_tree, hf_vtp_version, offset, 1,
118 proto_tree_add_item(vtp_tree, hf_vtp_code, offset, 1,
125 proto_tree_add_item(vtp_tree, hf_vtp_followers, offset,
130 proto_tree_add_item(vtp_tree, hf_vtp_md_len, offset,
134 proto_tree_add_item_format(vtp_tree, hf_vtp_md, offset,
135 32, &pd[offset], "Management Domain: %.32s",
139 proto_tree_add_item(vtp_tree, hf_vtp_conf_rev_num,
140 offset, 4, pntohl(&pd[offset]));
143 proto_tree_add_item(vtp_tree, hf_vtp_upd_id,
144 offset, 4, &pd[offset]);
147 proto_tree_add_item_format(vtp_tree, hf_vtp_upd_ts,
148 offset, 12, &pd[offset],
149 "Update Timestamp: %.2s-%.2s-%.2s %.2s:%.2s:%.2s",
150 &pd[offset], &pd[offset+2], &pd[offset+4],
151 &pd[offset+6], &pd[offset+8], &pd[offset+10]);
154 proto_tree_add_item(vtp_tree, hf_vtp_md5_digest,
155 offset, 16, &pd[offset]);
159 proto_tree_add_item(vtp_tree, hf_vtp_seq_num, offset,
164 proto_tree_add_item(vtp_tree, hf_vtp_md_len, offset,
168 proto_tree_add_item_format(vtp_tree, hf_vtp_md, offset,
169 32, &pd[offset], "Management Domain: %.32s",
173 proto_tree_add_item(vtp_tree, hf_vtp_conf_rev_num,
174 offset, 4, pntohl(&pd[offset]));
179 dissect_vlan_info(pd, offset, vtp_tree);
180 if (vlan_info_len < 0)
182 offset += vlan_info_len;
187 offset += 1; /* skip reserved field */
190 proto_tree_add_item(vtp_tree, hf_vtp_md_len, offset,
194 proto_tree_add_item(vtp_tree, hf_vtp_start_value,
195 offset, 2, pntohs(&pd[offset]));
200 * Mysterious type, seen a lot.
201 * Is this some mutant variant of Advert-Request?
203 offset += 1; /* skip unknown field */
206 proto_tree_add_item(vtp_tree, hf_vtp_md_len, offset,
210 proto_tree_add_item_format(vtp_tree, hf_vtp_md, offset,
211 32, &pd[offset], "Management Domain: %.32s",
215 offset += 2; /* skip unknown field */
217 proto_tree_add_text(vtp_tree, offset, 2,
218 "VLAN ID of some sort: 0x%04x",
219 pntohs(&pd[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(const u_char *pd, 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 if (!BYTES_ARE_IN_FRAME(offset, 1))
279 vlan_info_len = pd[offset];
280 ti = proto_tree_add_text(tree, offset, vlan_info_len,
282 vlan_info_tree = proto_item_add_subtree(ti, ett_vtp_vlan_info);
283 vlan_info_left = vlan_info_len;
285 proto_tree_add_item(vlan_info_tree, hf_vtp_vlan_info_len, offset, 1,
290 if (!BYTES_ARE_IN_FRAME(offset, 1) || vlan_info_left < 1)
293 ti = proto_tree_add_text(vlan_info_tree, offset, 1,
294 "Status: 0x%02x%s", status,
295 (status & VLAN_SUSPENDED) ? "(VLAN suspended)" : "");
296 status_tree = proto_item_add_subtree(ti, ett_vtp_vlan_status);
297 proto_tree_add_item(status_tree, hf_vtp_vlan_status_vlan_susp, offset, 1,
302 if (!BYTES_ARE_IN_FRAME(offset, 1) || vlan_info_left < 1)
304 proto_tree_add_item(vlan_info_tree, hf_vtp_vlan_type, offset, 1,
309 if (!BYTES_ARE_IN_FRAME(offset, 1) || vlan_info_left < 1)
311 vlan_name_len = pd[offset];
312 proto_tree_add_item(vlan_info_tree, hf_vtp_vlan_name_len, offset, 1,
317 if (!BYTES_ARE_IN_FRAME(offset, 2) || vlan_info_left < 2)
319 proto_tree_add_item(vlan_info_tree, hf_vtp_isl_vlan_id, offset, 2,
320 pntohs(&pd[offset]));
324 if (!BYTES_ARE_IN_FRAME(offset, 2) || vlan_info_left < 2)
326 proto_tree_add_item(vlan_info_tree, hf_vtp_mtu_size, offset, 2,
327 pntohs(&pd[offset]));
331 if (!BYTES_ARE_IN_FRAME(offset, 4) || vlan_info_left < 4)
333 proto_tree_add_item(vlan_info_tree, hf_vtp_802_10_index, offset, 4,
334 pntohl(&pd[offset]));
338 /* VLAN name length appears to be rounded up to a multiple of
340 vlan_name_len = 4*((vlan_name_len + 3)/4);
341 if (!BYTES_ARE_IN_FRAME(offset, vlan_name_len)
342 || vlan_info_left < vlan_name_len)
344 proto_tree_add_item_format(vlan_info_tree, hf_vtp_vlan_name, offset,
345 vlan_name_len, &pd[offset], "VLAN Name: %.*s", vlan_name_len,
347 offset += vlan_name_len;
348 vlan_info_left -= vlan_name_len;
350 while (IS_DATA_IN_FRAME(offset) && vlan_info_left > 0) {
351 type = pd[offset + 0];
352 length = pd[offset + 1];
353 type_str = val_to_str(type, vlan_tlv_type_vals,
356 ti = proto_tree_add_notext(vlan_info_tree, offset,
358 tlv_tree = proto_item_add_subtree(ti, ett_vtp_tlv);
359 proto_tree_add_item(tlv_tree, hf_vtp_vlan_tlvtype, offset,
361 proto_tree_add_item(tlv_tree, hf_vtp_vlan_tlvlength, offset+1,
366 dissect_vlan_info_tlv(pd, offset, length*2, tlv_tree,
370 vlan_info_left -= length*2;
373 return vlan_info_len;
376 static const value_string stp_type_vals[] = {
383 static const value_string pruning_vals[] = {
389 static const value_string bridge_type_vals[] = {
395 static const value_string backup_crf_mode_vals[] = {
396 { 1, "TrCRF is configured as a backup" },
397 { 2, "TrCRF is not configured as a backup" },
402 dissect_vlan_info_tlv(const u_char *pd, int offset, int length,
403 proto_tree *tree, proto_item *ti, guint8 type)
409 proto_item_set_text(ti,
410 "Source-Routing Ring Number: 0x%04x",
411 pntohs(&pd[offset]));
412 proto_tree_add_text(tree, offset, 2,
413 "Source-Routing Ring Number: 0x%04x",
414 pntohs(&pd[offset]));
416 proto_item_set_text(ti,
417 "Source-Routing Ring Number: Bad length %u",
419 proto_tree_add_text(tree, offset, length,
420 "Source-Routing Ring Number: Bad length %u",
427 proto_item_set_text(ti,
428 "Source-Routing Bridge Number: 0x%04x",
429 pntohs(&pd[offset]));
430 proto_tree_add_text(tree, offset, 2,
431 "Source-Routing Bridge Number: 0x%04x",
432 pntohs(&pd[offset]));
434 proto_item_set_text(ti,
435 "Source-Routing Bridge Number: Bad length %u",
437 proto_tree_add_text(tree, offset, length,
438 "Source-Routing Bridge Number: Bad length %u",
445 proto_item_set_text(ti,
446 "Spanning-Tree Protocol Type: %s",
447 val_to_str(pntohs(&pd[offset]), stp_type_vals,
448 "Unknown (0x%04x)"));
449 proto_tree_add_text(tree, offset, 2,
450 "Spanning-Tree Protocol Type: %s",
451 val_to_str(pntohs(&pd[offset]), stp_type_vals,
452 "Unknown (0x%04x)"));
454 proto_item_set_text(ti,
455 "Spanning-Tree Protocol Type: Bad length %u",
457 proto_tree_add_text(tree, offset, length,
458 "Spanning-Tree Protocol Type: Bad length %u",
465 proto_item_set_text(ti,
466 "Parent VLAN: 0x%04x",
467 pntohs(&pd[offset]));
468 proto_tree_add_text(tree, offset, 2,
469 "Parent VLAN: 0x%04x",
470 pntohs(&pd[offset]));
472 proto_item_set_text(ti,
473 "Parent VLAN: Bad length %u",
475 proto_tree_add_text(tree, offset, length,
476 "Parent VLAN: Bad length %u",
481 case TR_BRIDGED_VLANS:
483 proto_item_set_text(ti,
484 "Translationally Bridged VLANs: 0x%04x",
485 pntohs(&pd[offset]));
486 proto_tree_add_text(tree, offset, 2,
487 "Translationally Bridged VLANs: 0x%04x",
488 pntohs(&pd[offset]));
490 proto_item_set_text(ti,
491 "Translationally Bridged VLANs: Bad length %u",
493 proto_tree_add_text(tree, offset, length,
494 "Translationally Bridged VLANs: Bad length %u",
501 proto_item_set_text(ti,
503 val_to_str(pntohs(&pd[offset]), pruning_vals,
504 "Unknown (0x%04x)"));
505 proto_tree_add_text(tree, offset, 2,
507 val_to_str(pntohs(&pd[offset]), pruning_vals,
508 "Unknown (0x%04x)"));
510 proto_item_set_text(ti,
511 "Pruning: Bad length %u",
513 proto_tree_add_text(tree, offset, length,
514 "Pruning: Bad length %u",
521 proto_item_set_text(ti,
523 val_to_str(pntohs(&pd[offset]), bridge_type_vals,
524 "Unknown (0x%04x)"));
525 proto_tree_add_text(tree, offset, 2,
527 val_to_str(pntohs(&pd[offset]), bridge_type_vals,
528 "Unknown (0x%04x)"));
530 proto_item_set_text(ti,
531 "Bridge Type: Bad length %u",
533 proto_tree_add_text(tree, offset, length,
534 "Bridge Type: Bad length %u",
539 case MAX_ARE_HOP_CNT:
541 proto_item_set_text(ti,
542 "Max ARE Hop Count: %u",
543 pntohs(&pd[offset]));
544 proto_tree_add_text(tree, offset, 2,
545 "Max ARE Hop Count: %u",
546 pntohs(&pd[offset]));
548 proto_item_set_text(ti,
549 "Max ARE Hop Count: Bad length %u",
551 proto_tree_add_text(tree, offset, length,
552 "Max ARE Hop Count: Bad length %u",
557 case MAX_STE_HOP_CNT:
559 proto_item_set_text(ti,
560 "Max STE Hop Count: %u",
561 pntohs(&pd[offset]));
562 proto_tree_add_text(tree, offset, 2,
563 "Max STE Hop Count: %u",
564 pntohs(&pd[offset]));
566 proto_item_set_text(ti,
567 "Max STE Hop Count: Bad length %u",
569 proto_tree_add_text(tree, offset, length,
570 "Max STE Hop Count: Bad length %u",
575 case BACKUP_CRF_MODE:
577 proto_item_set_text(ti,
578 "Backup CRF Mode: %s",
579 val_to_str(pntohs(&pd[offset]), backup_crf_mode_vals,
580 "Unknown (0x%04x)"));
581 proto_tree_add_text(tree, offset, 2,
582 "Backup CRF Mode: %s",
583 val_to_str(pntohs(&pd[offset]), backup_crf_mode_vals,
584 "Unknown (0x%04x)"));
586 proto_item_set_text(ti,
587 "Backup CRF Mode: Bad length %u",
589 proto_tree_add_text(tree, offset, length,
590 "Backup CRF Mode: Bad length %u",
596 proto_item_set_text(ti, "Unknown TLV type: 0x%02x", type);
597 proto_tree_add_text(tree, offset, length, "Data");
603 proto_register_vtp(void)
605 static hf_register_info hf[] = {
607 { "Version", "vtp.version", FT_UINT8, BASE_HEX, NULL, 0x0,
611 { "Code", "vtp.code", FT_UINT8, BASE_HEX, VALS(type_vals), 0x0,
615 { "Followers", "vtp.followers", FT_UINT8, BASE_DEC, NULL, 0x0,
616 "Number of following Subset-Advert messages" }},
619 { "Management Domain Length", "vtp.md_len", FT_UINT8, BASE_DEC, NULL, 0x0,
620 "Length of management domain string" }},
623 { "Management Domain", "vtp.md", FT_STRING, BASE_DEC, NULL, 0,
624 "Management domain" }},
626 { &hf_vtp_conf_rev_num,
627 { "Configuration Revision Number", "vtp.conf_rev_num", FT_UINT32, BASE_DEC, NULL, 0x0,
628 "Revision number of the configuration information" }},
631 { "Updater Identity", "vtp.upd_id", FT_IPv4, BASE_NONE, NULL, 0x0,
632 "IP address of the updater" }},
635 { "Update Timestamp", "vtp.upd_ts", FT_STRING, BASE_DEC, NULL, 0,
636 "Time stamp of the current configuration revision" }},
638 { &hf_vtp_md5_digest,
639 { "MD5 Digest", "vtp.md5_digest", FT_BYTES, BASE_HEX, NULL, 0x0,
643 { "Sequence Number", "vtp.seq_num", FT_UINT8, BASE_DEC, NULL, 0x0,
644 "Order of this frame in the sequence of Subset-Advert frames" }},
646 { &hf_vtp_start_value,
647 { "Start Value", "vtp.start_value", FT_UINT16, BASE_HEX, NULL, 0x0,
648 "Virtual LAN ID of first VLAN for which information is requested" }},
650 { &hf_vtp_vlan_info_len,
651 { "VLAN Information Length", "vtp.vlan_info.len", FT_UINT8, BASE_DEC, NULL, 0x0,
652 "Length of the VLAN information field" }},
654 { &hf_vtp_vlan_status_vlan_susp,
655 { "VLAN suspended", "vtp.vlan_info.status.vlan_susp", FT_BOOLEAN, 8, NULL, VLAN_SUSPENDED,
659 { "VLAN Type", "vtp.vlan_info.vlan_type", FT_UINT8, BASE_HEX, VALS(vlan_type_vals), 0x0,
662 { &hf_vtp_vlan_name_len,
663 { "VLAN Name Length", "vtp.vlan_info.vlan_name_len", FT_UINT8, BASE_DEC, NULL, 0x0,
664 "Length of VLAN name string" }},
666 { &hf_vtp_isl_vlan_id,
667 { "ISL VLAN ID", "vtp.vlan_info.isl_vlan_id", FT_UINT16, BASE_HEX, NULL, 0x0,
668 "ID of this VLAN on ISL trunks" }},
671 { "MTU Size", "vtp.vlan_info.mtu_size", FT_UINT16, BASE_DEC, NULL, 0x0,
672 "MTU for this VLAN" }},
674 { &hf_vtp_802_10_index,
675 { "802.10 Index", "vtp.vlan_info.802_10_index", FT_UINT32, BASE_HEX, NULL, 0x0,
676 "IEEE 802.10 security association identifier for this VLAN" }},
679 { "VLAN Name", "vtp.vlan_info.vlan_name", FT_STRING, BASE_DEC, NULL, 0,
682 { &hf_vtp_vlan_tlvtype,
683 { "Type", "vtp.vlan_info.tlv_type", FT_UINT8, BASE_HEX, VALS(vlan_tlv_type_vals), 0x0,
686 { &hf_vtp_vlan_tlvlength,
687 { "Length", "vtp.vlan_info.tlv_len", FT_UINT8, BASE_DEC, NULL, 0x0,
690 static gint *ett[] = {
693 &ett_vtp_vlan_status,
697 proto_vtp = proto_register_protocol("Virtual Trunking Protocol", "vtp");
698 proto_register_field_array(proto_vtp, hf, array_length(hf));
699 proto_register_subtree_array(ett, array_length(ett));