2 * Routines for the disassembly of Cisco's Virtual Trunking Protocol
4 * $Id: packet-vtp.c,v 1.4 2000/05/14 07:19:49 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;
104 if (check_col(fd, COL_PROTOCOL))
105 col_add_str(fd, COL_PROTOCOL, "VTP");
106 if (check_col(fd, COL_INFO))
107 col_add_str(fd, COL_INFO, "Virtual Trunking Protocol");
110 ti = proto_tree_add_item(tree, proto_vtp, NullTVB, offset, END_OF_FRAME,
112 vtp_tree = proto_item_add_subtree(ti, ett_vtp);
114 proto_tree_add_item(vtp_tree, hf_vtp_version, NullTVB, offset, 1,
119 proto_tree_add_item(vtp_tree, hf_vtp_code, NullTVB, offset, 1,
126 proto_tree_add_item(vtp_tree, hf_vtp_followers, NullTVB, offset,
131 proto_tree_add_item(vtp_tree, hf_vtp_md_len, NullTVB, offset,
135 proto_tree_add_string_format(vtp_tree, hf_vtp_md, NullTVB, offset,
136 32, &pd[offset], "Management Domain: %.32s",
140 proto_tree_add_item(vtp_tree, hf_vtp_conf_rev_num, NullTVB,
141 offset, 4, pntohl(&pd[offset]));
144 memcpy(&upd_id, &pd[offset], sizeof upd_id);
145 proto_tree_add_item(vtp_tree, hf_vtp_upd_id, NullTVB,
149 proto_tree_add_string_format(vtp_tree, hf_vtp_upd_ts, NullTVB,
150 offset, 12, &pd[offset],
151 "Update Timestamp: %.2s-%.2s-%.2s %.2s:%.2s:%.2s",
152 &pd[offset], &pd[offset+2], &pd[offset+4],
153 &pd[offset+6], &pd[offset+8], &pd[offset+10]);
156 proto_tree_add_item(vtp_tree, hf_vtp_md5_digest, NullTVB,
157 offset, 16, &pd[offset]);
161 proto_tree_add_item(vtp_tree, hf_vtp_seq_num, NullTVB, offset,
166 proto_tree_add_item(vtp_tree, hf_vtp_md_len, NullTVB, offset,
170 proto_tree_add_string_format(vtp_tree, hf_vtp_md, NullTVB, offset,
171 32, &pd[offset], "Management Domain: %.32s",
175 proto_tree_add_item(vtp_tree, hf_vtp_conf_rev_num, NullTVB,
176 offset, 4, pntohl(&pd[offset]));
181 dissect_vlan_info(pd, offset, vtp_tree);
182 if (vlan_info_len < 0)
184 offset += vlan_info_len;
189 offset += 1; /* skip reserved field */
192 proto_tree_add_item(vtp_tree, hf_vtp_md_len, NullTVB, offset,
196 proto_tree_add_item(vtp_tree, hf_vtp_start_value, NullTVB,
197 offset, 2, pntohs(&pd[offset]));
202 * Mysterious type, seen a lot.
203 * Is this some mutant variant of Advert-Request?
205 offset += 1; /* skip unknown field */
208 proto_tree_add_item(vtp_tree, hf_vtp_md_len, NullTVB, offset,
212 proto_tree_add_string_format(vtp_tree, hf_vtp_md, NullTVB, offset,
213 32, &pd[offset], "Management Domain: %.32s",
217 offset += 2; /* skip unknown field */
219 proto_tree_add_text(vtp_tree, NullTVB, offset, 2,
220 "VLAN ID of some sort: 0x%04x",
221 pntohs(&pd[offset]));
228 #define VLAN_SUSPENDED 0x01
230 static const value_string vlan_type_vals[] = {
231 { 0x01, "Ethernet" },
234 { 0x04, "FDDI-net" },
239 #define SR_RING_NUM 0x01
240 #define SR_BRIDGE_NUM 0x02
241 #define STP_TYPE 0x03
242 #define PARENT_VLAN 0x04
243 #define TR_BRIDGED_VLANS 0x05
245 #define BRIDGE_TYPE 0x07
246 #define MAX_ARE_HOP_CNT 0x08
247 #define MAX_STE_HOP_CNT 0x09
248 #define BACKUP_CRF_MODE 0x0A
250 static const value_string vlan_tlv_type_vals[] = {
251 { SR_RING_NUM, "Source-Routing Ring Number" },
252 { SR_BRIDGE_NUM, "Source-Routing Bridge Number" },
253 { STP_TYPE, "Spanning-Tree Protocol Type" },
254 { PARENT_VLAN, "Parent VLAN" },
255 { TR_BRIDGED_VLANS, "Translationally Bridged VLANs" },
256 { PRUNING, "Pruning" },
257 { BRIDGE_TYPE, "Bridge Type" },
258 { MAX_ARE_HOP_CNT, "Max ARE Hop Count" },
259 { MAX_STE_HOP_CNT, "Max STE Hop Count" },
260 { BACKUP_CRF_MODE, "Backup CRF Mode" },
265 dissect_vlan_info(const u_char *pd, int offset, proto_tree *tree)
268 proto_tree *vlan_info_tree;
269 proto_tree *status_tree;
270 guint8 vlan_info_len;
273 guint8 vlan_name_len;
277 proto_tree *tlv_tree;
279 if (!BYTES_ARE_IN_FRAME(offset, 1))
281 vlan_info_len = pd[offset];
282 ti = proto_tree_add_text(tree, NullTVB, offset, vlan_info_len,
284 vlan_info_tree = proto_item_add_subtree(ti, ett_vtp_vlan_info);
285 vlan_info_left = vlan_info_len;
287 proto_tree_add_item(vlan_info_tree, hf_vtp_vlan_info_len, NullTVB, offset, 1,
292 if (!BYTES_ARE_IN_FRAME(offset, 1) || vlan_info_left < 1)
295 ti = proto_tree_add_text(vlan_info_tree, NullTVB, offset, 1,
296 "Status: 0x%02x%s", status,
297 (status & VLAN_SUSPENDED) ? "(VLAN suspended)" : "");
298 status_tree = proto_item_add_subtree(ti, ett_vtp_vlan_status);
299 proto_tree_add_item(status_tree, hf_vtp_vlan_status_vlan_susp, NullTVB, offset, 1,
304 if (!BYTES_ARE_IN_FRAME(offset, 1) || vlan_info_left < 1)
306 proto_tree_add_item(vlan_info_tree, hf_vtp_vlan_type, NullTVB, offset, 1,
311 if (!BYTES_ARE_IN_FRAME(offset, 1) || vlan_info_left < 1)
313 vlan_name_len = pd[offset];
314 proto_tree_add_item(vlan_info_tree, hf_vtp_vlan_name_len, NullTVB, offset, 1,
319 if (!BYTES_ARE_IN_FRAME(offset, 2) || vlan_info_left < 2)
321 proto_tree_add_item(vlan_info_tree, hf_vtp_isl_vlan_id, NullTVB, offset, 2,
322 pntohs(&pd[offset]));
326 if (!BYTES_ARE_IN_FRAME(offset, 2) || vlan_info_left < 2)
328 proto_tree_add_item(vlan_info_tree, hf_vtp_mtu_size, NullTVB, offset, 2,
329 pntohs(&pd[offset]));
333 if (!BYTES_ARE_IN_FRAME(offset, 4) || vlan_info_left < 4)
335 proto_tree_add_item(vlan_info_tree, hf_vtp_802_10_index, NullTVB, offset, 4,
336 pntohl(&pd[offset]));
340 /* VLAN name length appears to be rounded up to a multiple of
342 vlan_name_len = 4*((vlan_name_len + 3)/4);
343 if (!BYTES_ARE_IN_FRAME(offset, vlan_name_len)
344 || vlan_info_left < vlan_name_len)
346 proto_tree_add_string_format(vlan_info_tree, hf_vtp_vlan_name, NullTVB, offset,
347 vlan_name_len, &pd[offset], "VLAN Name: %.*s", vlan_name_len,
349 offset += vlan_name_len;
350 vlan_info_left -= vlan_name_len;
352 while (IS_DATA_IN_FRAME(offset) && vlan_info_left > 0) {
353 type = pd[offset + 0];
354 length = pd[offset + 1];
355 type_str = val_to_str(type, vlan_tlv_type_vals,
358 ti = proto_tree_add_notext(vlan_info_tree, NullTVB, offset,
360 tlv_tree = proto_item_add_subtree(ti, ett_vtp_tlv);
361 proto_tree_add_item(tlv_tree, hf_vtp_vlan_tlvtype, NullTVB, offset,
363 proto_tree_add_item(tlv_tree, hf_vtp_vlan_tlvlength, NullTVB, offset+1,
368 dissect_vlan_info_tlv(pd, offset, length*2, tlv_tree,
372 vlan_info_left -= length*2;
375 return vlan_info_len;
378 static const value_string stp_type_vals[] = {
385 static const value_string pruning_vals[] = {
391 static const value_string bridge_type_vals[] = {
397 static const value_string backup_crf_mode_vals[] = {
398 { 1, "TrCRF is configured as a backup" },
399 { 2, "TrCRF is not configured as a backup" },
404 dissect_vlan_info_tlv(const u_char *pd, int offset, int length,
405 proto_tree *tree, proto_item *ti, guint8 type)
411 proto_item_set_text(ti,
412 "Source-Routing Ring Number: 0x%04x",
413 pntohs(&pd[offset]));
414 proto_tree_add_text(tree, NullTVB, offset, 2,
415 "Source-Routing Ring Number: 0x%04x",
416 pntohs(&pd[offset]));
418 proto_item_set_text(ti,
419 "Source-Routing Ring Number: Bad length %u",
421 proto_tree_add_text(tree, NullTVB, offset, length,
422 "Source-Routing Ring Number: Bad length %u",
429 proto_item_set_text(ti,
430 "Source-Routing Bridge Number: 0x%04x",
431 pntohs(&pd[offset]));
432 proto_tree_add_text(tree, NullTVB, offset, 2,
433 "Source-Routing Bridge Number: 0x%04x",
434 pntohs(&pd[offset]));
436 proto_item_set_text(ti,
437 "Source-Routing Bridge Number: Bad length %u",
439 proto_tree_add_text(tree, NullTVB, offset, length,
440 "Source-Routing Bridge Number: Bad length %u",
447 proto_item_set_text(ti,
448 "Spanning-Tree Protocol Type: %s",
449 val_to_str(pntohs(&pd[offset]), stp_type_vals,
450 "Unknown (0x%04x)"));
451 proto_tree_add_text(tree, NullTVB, offset, 2,
452 "Spanning-Tree Protocol Type: %s",
453 val_to_str(pntohs(&pd[offset]), stp_type_vals,
454 "Unknown (0x%04x)"));
456 proto_item_set_text(ti,
457 "Spanning-Tree Protocol Type: Bad length %u",
459 proto_tree_add_text(tree, NullTVB, offset, length,
460 "Spanning-Tree Protocol Type: Bad length %u",
467 proto_item_set_text(ti,
468 "Parent VLAN: 0x%04x",
469 pntohs(&pd[offset]));
470 proto_tree_add_text(tree, NullTVB, offset, 2,
471 "Parent VLAN: 0x%04x",
472 pntohs(&pd[offset]));
474 proto_item_set_text(ti,
475 "Parent VLAN: Bad length %u",
477 proto_tree_add_text(tree, NullTVB, offset, length,
478 "Parent VLAN: Bad length %u",
483 case TR_BRIDGED_VLANS:
485 proto_item_set_text(ti,
486 "Translationally Bridged VLANs: 0x%04x",
487 pntohs(&pd[offset]));
488 proto_tree_add_text(tree, NullTVB, offset, 2,
489 "Translationally Bridged VLANs: 0x%04x",
490 pntohs(&pd[offset]));
492 proto_item_set_text(ti,
493 "Translationally Bridged VLANs: Bad length %u",
495 proto_tree_add_text(tree, NullTVB, offset, length,
496 "Translationally Bridged VLANs: Bad length %u",
503 proto_item_set_text(ti,
505 val_to_str(pntohs(&pd[offset]), pruning_vals,
506 "Unknown (0x%04x)"));
507 proto_tree_add_text(tree, NullTVB, offset, 2,
509 val_to_str(pntohs(&pd[offset]), pruning_vals,
510 "Unknown (0x%04x)"));
512 proto_item_set_text(ti,
513 "Pruning: Bad length %u",
515 proto_tree_add_text(tree, NullTVB, offset, length,
516 "Pruning: Bad length %u",
523 proto_item_set_text(ti,
525 val_to_str(pntohs(&pd[offset]), bridge_type_vals,
526 "Unknown (0x%04x)"));
527 proto_tree_add_text(tree, NullTVB, offset, 2,
529 val_to_str(pntohs(&pd[offset]), bridge_type_vals,
530 "Unknown (0x%04x)"));
532 proto_item_set_text(ti,
533 "Bridge Type: Bad length %u",
535 proto_tree_add_text(tree, NullTVB, offset, length,
536 "Bridge Type: Bad length %u",
541 case MAX_ARE_HOP_CNT:
543 proto_item_set_text(ti,
544 "Max ARE Hop Count: %u",
545 pntohs(&pd[offset]));
546 proto_tree_add_text(tree, NullTVB, offset, 2,
547 "Max ARE Hop Count: %u",
548 pntohs(&pd[offset]));
550 proto_item_set_text(ti,
551 "Max ARE Hop Count: Bad length %u",
553 proto_tree_add_text(tree, NullTVB, offset, length,
554 "Max ARE Hop Count: Bad length %u",
559 case MAX_STE_HOP_CNT:
561 proto_item_set_text(ti,
562 "Max STE Hop Count: %u",
563 pntohs(&pd[offset]));
564 proto_tree_add_text(tree, NullTVB, offset, 2,
565 "Max STE Hop Count: %u",
566 pntohs(&pd[offset]));
568 proto_item_set_text(ti,
569 "Max STE Hop Count: Bad length %u",
571 proto_tree_add_text(tree, NullTVB, offset, length,
572 "Max STE Hop Count: Bad length %u",
577 case BACKUP_CRF_MODE:
579 proto_item_set_text(ti,
580 "Backup CRF Mode: %s",
581 val_to_str(pntohs(&pd[offset]), backup_crf_mode_vals,
582 "Unknown (0x%04x)"));
583 proto_tree_add_text(tree, NullTVB, offset, 2,
584 "Backup CRF Mode: %s",
585 val_to_str(pntohs(&pd[offset]), backup_crf_mode_vals,
586 "Unknown (0x%04x)"));
588 proto_item_set_text(ti,
589 "Backup CRF Mode: Bad length %u",
591 proto_tree_add_text(tree, NullTVB, offset, length,
592 "Backup CRF Mode: Bad length %u",
598 proto_item_set_text(ti, "Unknown TLV type: 0x%02x", type);
599 proto_tree_add_text(tree, NullTVB, offset, length, "Data");
605 proto_register_vtp(void)
607 static hf_register_info hf[] = {
609 { "Version", "vtp.version", FT_UINT8, BASE_HEX, NULL, 0x0,
613 { "Code", "vtp.code", FT_UINT8, BASE_HEX, VALS(type_vals), 0x0,
617 { "Followers", "vtp.followers", FT_UINT8, BASE_DEC, NULL, 0x0,
618 "Number of following Subset-Advert messages" }},
621 { "Management Domain Length", "vtp.md_len", FT_UINT8, BASE_DEC, NULL, 0x0,
622 "Length of management domain string" }},
625 { "Management Domain", "vtp.md", FT_STRING, BASE_DEC, NULL, 0,
626 "Management domain" }},
628 { &hf_vtp_conf_rev_num,
629 { "Configuration Revision Number", "vtp.conf_rev_num", FT_UINT32, BASE_DEC, NULL, 0x0,
630 "Revision number of the configuration information" }},
633 { "Updater Identity", "vtp.upd_id", FT_IPv4, BASE_NONE, NULL, 0x0,
634 "IP address of the updater" }},
637 { "Update Timestamp", "vtp.upd_ts", FT_STRING, BASE_DEC, NULL, 0,
638 "Time stamp of the current configuration revision" }},
640 { &hf_vtp_md5_digest,
641 { "MD5 Digest", "vtp.md5_digest", FT_BYTES, BASE_HEX, NULL, 0x0,
645 { "Sequence Number", "vtp.seq_num", FT_UINT8, BASE_DEC, NULL, 0x0,
646 "Order of this frame in the sequence of Subset-Advert frames" }},
648 { &hf_vtp_start_value,
649 { "Start Value", "vtp.start_value", FT_UINT16, BASE_HEX, NULL, 0x0,
650 "Virtual LAN ID of first VLAN for which information is requested" }},
652 { &hf_vtp_vlan_info_len,
653 { "VLAN Information Length", "vtp.vlan_info.len", FT_UINT8, BASE_DEC, NULL, 0x0,
654 "Length of the VLAN information field" }},
656 { &hf_vtp_vlan_status_vlan_susp,
657 { "VLAN suspended", "vtp.vlan_info.status.vlan_susp", FT_BOOLEAN, 8, NULL, VLAN_SUSPENDED,
661 { "VLAN Type", "vtp.vlan_info.vlan_type", FT_UINT8, BASE_HEX, VALS(vlan_type_vals), 0x0,
664 { &hf_vtp_vlan_name_len,
665 { "VLAN Name Length", "vtp.vlan_info.vlan_name_len", FT_UINT8, BASE_DEC, NULL, 0x0,
666 "Length of VLAN name string" }},
668 { &hf_vtp_isl_vlan_id,
669 { "ISL VLAN ID", "vtp.vlan_info.isl_vlan_id", FT_UINT16, BASE_HEX, NULL, 0x0,
670 "ID of this VLAN on ISL trunks" }},
673 { "MTU Size", "vtp.vlan_info.mtu_size", FT_UINT16, BASE_DEC, NULL, 0x0,
674 "MTU for this VLAN" }},
676 { &hf_vtp_802_10_index,
677 { "802.10 Index", "vtp.vlan_info.802_10_index", FT_UINT32, BASE_HEX, NULL, 0x0,
678 "IEEE 802.10 security association identifier for this VLAN" }},
681 { "VLAN Name", "vtp.vlan_info.vlan_name", FT_STRING, BASE_DEC, NULL, 0,
684 { &hf_vtp_vlan_tlvtype,
685 { "Type", "vtp.vlan_info.tlv_type", FT_UINT8, BASE_HEX, VALS(vlan_tlv_type_vals), 0x0,
688 { &hf_vtp_vlan_tlvlength,
689 { "Length", "vtp.vlan_info.tlv_len", FT_UINT8, BASE_DEC, NULL, 0x0,
692 static gint *ett[] = {
695 &ett_vtp_vlan_status,
699 proto_vtp = proto_register_protocol("Virtual Trunking Protocol", "vtp");
700 proto_register_field_array(proto_vtp, hf, array_length(hf));
701 proto_register_subtree_array(ett, array_length(ett));