Use ENC_NA as encoding for proto_tree_add_item() calls which directly reference an...
[obnox/wireshark/wip.git] / epan / dissectors / packet-vtp.c
1 /* packet-vtp.c
2  * Routines for the disassembly of Cisco's VLAN Trunking Protocol
3  *
4  * $Id$
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 1998 Gerald Combs
9  *
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.
14  *
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.
19  *
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.
23  */
24
25 #include "config.h"
26
27 #include <stdlib.h>
28
29 #include <glib.h>
30 #include <epan/packet.h>
31
32 /*
33  * See
34  *
35  *      http://www.cisco.com/univercd/cc/td/doc/product/lan/trsrb/frames.htm
36  *
37  * for some information on VTP.
38  *
39  * It's incomplete, and it appears to be inaccurate in a number of places,
40  * but it's all I could find....
41  */
42
43 static int proto_vtp = -1;
44 static int hf_vtp_version = -1;
45 static int hf_vtp_code = -1;
46 static int hf_vtp_followers = -1;
47 static int hf_vtp_md_len = -1;
48 static int hf_vtp_md = -1;
49 static int hf_vtp_conf_rev_num = -1;
50 static int hf_vtp_upd_id = -1;
51 static int hf_vtp_upd_ts = -1;
52 static int hf_vtp_md5_digest = -1;
53 static int hf_vtp_seq_num = -1;
54 static int hf_vtp_start_value = -1;
55 static int hf_vtp_vlan_info_len = -1;
56 static int hf_vtp_vlan_status_vlan_susp = -1;
57 static int hf_vtp_vlan_type = -1;
58 static int hf_vtp_vlan_name_len = -1;
59 static int hf_vtp_isl_vlan_id = -1;
60 static int hf_vtp_mtu_size = -1;
61 static int hf_vtp_802_10_index = -1;
62 static int hf_vtp_vlan_name = -1;
63 static int hf_vtp_vlan_tlvtype = -1;
64 static int hf_vtp_vlan_tlvlength = -1;
65 static gint hf_vtp_pruning_first_vid = -1;
66 static gint hf_vtp_pruning_last_vid = -1;
67 static gint hf_vtp_pruning_active_vid = -1;
68
69 static gint ett_vtp = -1;
70 static gint ett_vtp_vlan_info = -1;
71 static gint ett_vtp_vlan_status = -1;
72 static gint ett_vtp_tlv = -1;
73 static gint ett_vtp_pruning = -1;
74
75 static int
76 dissect_vlan_info(tvbuff_t *tvb, int offset, proto_tree *tree);
77 static void
78 dissect_vlan_info_tlv(tvbuff_t *tvb, int offset, int length,
79     proto_tree *tree, proto_item *ti, guint8 type);
80
81 #define SUMMARY_ADVERT          0x01
82 #define SUBSET_ADVERT           0x02
83 #define ADVERT_REQUEST          0x03
84 #define JOIN_MSG                0x04
85
86 static const value_string type_vals[] = {
87         { SUMMARY_ADVERT, "Summary Advertisement" },
88         { SUBSET_ADVERT,  "Subset Advertisement" },
89         { ADVERT_REQUEST, "Advertisement Request" },
90         { JOIN_MSG,       "Join/Prune Message" },
91         { 0,              NULL },
92 };
93
94 static void
95 set_vtp_info_col(tvbuff_t *tvb, packet_info *pinfo)
96 {
97         switch (tvb_get_guint8(tvb, 1)) {
98
99         case SUMMARY_ADVERT:
100                 col_add_fstr(pinfo->cinfo, COL_INFO,
101                     "Summary Advertisement, Revision: %u", tvb_get_ntohl(tvb, 36));
102
103                 if (tvb_get_guint8(tvb, 2) > 0) {
104                         col_append_fstr(pinfo->cinfo, COL_INFO,
105                             ", Followers: %u", tvb_get_guint8(tvb, 2));
106                 }
107
108                 break;
109
110         case SUBSET_ADVERT:
111                 col_add_fstr(pinfo->cinfo, COL_INFO,
112                     "Subset Advertisement, Revision: %u, Seq: %u",
113                     tvb_get_ntohl(tvb, 36), tvb_get_guint8(tvb, 2));
114                 break;
115
116         case ADVERT_REQUEST:
117                 col_set_str(pinfo->cinfo, COL_INFO, "Advertisement Request");
118                 break;
119
120         case JOIN_MSG:
121                 col_set_str(pinfo->cinfo, COL_INFO, "Join");
122                 break;
123
124         default:
125                 col_set_str(pinfo->cinfo, COL_INFO, "Unrecognized VTP message");
126                 break;
127         }
128 }
129
130 static void
131 dissect_vtp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
132 {
133         proto_item *ti;
134         proto_tree *vtp_tree = NULL, *vtp_pruning_tree = NULL;
135         int offset = 0;
136         guint8 code;
137         guint8 md_len;
138         const guint8 *upd_timestamp;
139         int vlan_info_len;
140         int pruning_vlan_id;
141
142         col_set_str(pinfo->cinfo, COL_PROTOCOL, "VTP");
143         set_vtp_info_col(tvb, pinfo);
144
145         if (tree) {
146                 ti = proto_tree_add_item(tree, proto_vtp, tvb, offset, -1,
147                     FALSE);
148                 vtp_tree = proto_item_add_subtree(ti, ett_vtp);
149
150                 proto_tree_add_item(vtp_tree, hf_vtp_version, tvb, offset, 1,
151                     FALSE);
152                 offset += 1;
153
154                 code = tvb_get_guint8(tvb, offset);
155                 proto_tree_add_uint(vtp_tree, hf_vtp_code, tvb, offset, 1,
156                     code);
157                 offset += 1;
158
159                 switch (code) {
160
161                 case SUMMARY_ADVERT:
162                         proto_tree_add_item(vtp_tree, hf_vtp_followers, tvb, offset,
163                             1, FALSE);
164                         offset += 1;
165
166                         md_len = tvb_get_guint8(tvb, offset);
167                         proto_tree_add_uint(vtp_tree, hf_vtp_md_len, tvb, offset,
168                             1, md_len);
169                         offset += 1;
170
171                         proto_tree_add_item(vtp_tree, hf_vtp_md, tvb, offset,
172                             32, FALSE);
173                         offset += 32;
174
175                         proto_tree_add_item(vtp_tree, hf_vtp_conf_rev_num, tvb,
176                             offset, 4, FALSE);
177                         offset += 4;
178
179                         proto_tree_add_item(vtp_tree, hf_vtp_upd_id, tvb,
180                             offset, 4, FALSE);
181                         offset += 4;
182
183                         upd_timestamp = tvb_get_ptr(tvb, offset, 12);
184                         proto_tree_add_string_format(vtp_tree, hf_vtp_upd_ts, tvb,
185                             offset, 12, (gchar*)upd_timestamp,
186                             "Update Timestamp: %.2s-%.2s-%.2s %.2s:%.2s:%.2s",
187                             &upd_timestamp[0], &upd_timestamp[2], &upd_timestamp[4],
188                             &upd_timestamp[6], &upd_timestamp[8], &upd_timestamp[10]);
189                         offset += 12;
190
191                         proto_tree_add_item(vtp_tree, hf_vtp_md5_digest, tvb,
192                             offset, 16, ENC_NA);
193                         break;
194
195                 case SUBSET_ADVERT:
196                         proto_tree_add_item(vtp_tree, hf_vtp_seq_num, tvb, offset,
197                             1, FALSE);
198                         offset += 1;
199
200                         md_len = tvb_get_guint8(tvb, offset);
201                         proto_tree_add_uint(vtp_tree, hf_vtp_md_len, tvb, offset,
202                             1, md_len);
203                         offset += 1;
204
205                         proto_tree_add_item(vtp_tree, hf_vtp_md, tvb, offset,
206                             32, FALSE);
207                         offset += 32;
208
209                         proto_tree_add_item(vtp_tree, hf_vtp_conf_rev_num, tvb,
210                             offset, 4, FALSE);
211                         offset += 4;
212
213                         while (tvb_reported_length_remaining(tvb, offset) > 0) {
214                                 vlan_info_len =
215                                     dissect_vlan_info(tvb, offset, vtp_tree);
216                                 if (vlan_info_len < 0)
217                                         break;
218                                 offset += vlan_info_len;
219                         }
220                         break;
221
222                 case ADVERT_REQUEST:
223                         offset += 1;    /* skip reserved field */
224
225                         md_len = tvb_get_guint8(tvb, offset);
226                         proto_tree_add_uint(vtp_tree, hf_vtp_md_len, tvb, offset,
227                             1, md_len);
228                         offset += 1;
229
230                         proto_tree_add_item(vtp_tree, hf_vtp_md, tvb, offset,
231                             32, FALSE);
232                         offset += 32;
233
234                         proto_tree_add_item(vtp_tree, hf_vtp_start_value, tvb,
235                             offset, 2, FALSE);
236                         break;
237
238                 case JOIN_MSG:
239                         offset += 1;    /* skip reserved/unused field */
240
241                         md_len = tvb_get_guint8(tvb, offset);
242                         proto_tree_add_uint(vtp_tree, hf_vtp_md_len, tvb, offset,
243                             1, md_len);
244                         offset += 1;
245
246                         proto_tree_add_item(vtp_tree, hf_vtp_md, tvb, offset,
247                             32, FALSE);
248                         offset += 32;
249
250                         proto_tree_add_item(vtp_tree, hf_vtp_pruning_first_vid, tvb, offset,
251                             2, FALSE);
252                         pruning_vlan_id = tvb_get_ntohs(tvb, offset);
253                         offset += 2;
254
255                         proto_tree_add_item(vtp_tree, hf_vtp_pruning_last_vid, tvb, offset,
256                             2, FALSE);
257                         offset += 2;
258
259                         ti = proto_tree_add_text (vtp_tree, tvb, offset, -1,
260                             "Advertised active (i.e. not pruned) VLANs");
261                         vtp_pruning_tree = proto_item_add_subtree(ti, ett_vtp_pruning);
262
263                         while (tvb_reported_length_remaining(tvb, offset) > 0) {
264                             guint8 vlan_usage_bitmap;
265                             int shift;
266
267                             vlan_usage_bitmap = tvb_get_guint8(tvb, offset);
268
269                             for (shift = 0; shift < 8; shift++) {
270                                 if (vlan_usage_bitmap & (1<<7)) {
271                                     proto_tree_add_uint(vtp_pruning_tree, hf_vtp_pruning_active_vid,
272                                         tvb, offset, 1, pruning_vlan_id);
273                                 }
274
275                                 pruning_vlan_id += 1;
276                                 vlan_usage_bitmap <<= 1;
277                             }
278
279                             offset += 1;
280                         }
281
282                         break;
283                 }
284         }
285 }
286
287 #define VLAN_SUSPENDED  0x01
288
289 static const value_string vlan_type_vals[] = {
290         { 0x01, "Ethernet" },
291         { 0x02, "FDDI" },
292         { 0x03, "TrCRF" },
293         { 0x04, "FDDI-net" },
294         { 0x05, "TrBRF" },
295         { 0,    NULL },
296 };
297
298 #define SR_RING_NUM             0x01
299 #define SR_BRIDGE_NUM           0x02
300 #define STP_TYPE                0x03
301 #define PARENT_VLAN             0x04
302 #define TR_BRIDGED_VLANS        0x05
303 #define PRUNING                 0x06
304 #define BRIDGE_TYPE             0x07
305 #define MAX_ARE_HOP_CNT         0x08
306 #define MAX_STE_HOP_CNT         0x09
307 #define BACKUP_CRF_MODE         0x0A
308
309 static const value_string vlan_tlv_type_vals[] = {
310         { SR_RING_NUM,      "Source-Routing Ring Number" },
311         { SR_BRIDGE_NUM,    "Source-Routing Bridge Number" },
312         { STP_TYPE,         "Spanning-Tree Protocol Type" },
313         { PARENT_VLAN,      "Parent VLAN" },
314         { TR_BRIDGED_VLANS, "Translationally Bridged VLANs" },
315         { PRUNING,          "Pruning" },
316         { BRIDGE_TYPE,      "Bridge Type" },
317         { MAX_ARE_HOP_CNT,  "Max ARE Hop Count" },
318         { MAX_STE_HOP_CNT,  "Max STE Hop Count" },
319         { BACKUP_CRF_MODE,  "Backup CRF Mode" },
320         { 0,                NULL },
321 };
322
323 static int
324 dissect_vlan_info(tvbuff_t *tvb, int offset, proto_tree *tree)
325 {
326         proto_item *ti;
327         proto_tree *vlan_info_tree;
328         proto_tree *status_tree;
329         guint8 vlan_info_len;
330         int vlan_info_left;
331         guint8 status;
332         guint8 vlan_name_len;
333         guint8 type;
334         int length;
335         proto_tree *tlv_tree;
336
337         vlan_info_len = tvb_get_guint8(tvb, offset);
338         ti = proto_tree_add_text(tree, tvb, offset, vlan_info_len,
339             "VLAN Information");
340         vlan_info_tree = proto_item_add_subtree(ti, ett_vtp_vlan_info);
341         vlan_info_left = vlan_info_len;
342
343         proto_tree_add_uint(vlan_info_tree, hf_vtp_vlan_info_len, tvb, offset, 1,
344             vlan_info_len);
345         offset += 1;
346         vlan_info_left -= 1;
347
348         if (vlan_info_left < 1)
349                 return -1;
350         status = tvb_get_guint8(tvb, offset);
351         ti = proto_tree_add_text(vlan_info_tree, tvb, offset, 1,
352             "Status: 0x%02x%s", status,
353             (status & VLAN_SUSPENDED) ? "(VLAN suspended)" : "");
354         status_tree = proto_item_add_subtree(ti, ett_vtp_vlan_status);
355         proto_tree_add_boolean(status_tree, hf_vtp_vlan_status_vlan_susp, tvb, offset, 1,
356             status);
357         offset += 1;
358         vlan_info_left -= 1;
359
360         if (vlan_info_left < 1)
361                 return -1;
362         proto_tree_add_item(vlan_info_tree, hf_vtp_vlan_type, tvb, offset, 1,
363             FALSE);
364         offset += 1;
365         vlan_info_left -= 1;
366
367         if (vlan_info_left < 1)
368                 return -1;
369         vlan_name_len = tvb_get_guint8(tvb, offset);
370         proto_tree_add_uint(vlan_info_tree, hf_vtp_vlan_name_len, tvb, offset, 1,
371             vlan_name_len);
372         offset += 1;
373         vlan_info_left -= 1;
374
375         if (vlan_info_left < 2)
376                 return -1;
377         proto_tree_add_item(vlan_info_tree, hf_vtp_isl_vlan_id, tvb, offset, 2,
378             FALSE);
379         offset += 2;
380         vlan_info_left -= 2;
381
382         if (vlan_info_left < 2)
383                 return -1;
384         proto_tree_add_item(vlan_info_tree, hf_vtp_mtu_size, tvb, offset, 2,
385             FALSE);
386         offset += 2;
387         vlan_info_left -= 2;
388
389         if (vlan_info_left < 4)
390                 return -1;
391         proto_tree_add_item(vlan_info_tree, hf_vtp_802_10_index, tvb, offset, 4,
392             FALSE);
393         offset += 4;
394         vlan_info_left -= 4;
395
396         /* VLAN name length appears to be rounded up to a multiple of 4. */
397         vlan_name_len = 4*((vlan_name_len + 3)/4);
398         if (vlan_info_left < vlan_name_len)
399                 return -1;
400         proto_tree_add_item(vlan_info_tree, hf_vtp_vlan_name, tvb, offset,
401             vlan_name_len, FALSE);
402         offset += vlan_name_len;
403         vlan_info_left -= vlan_name_len;
404
405         while (vlan_info_left > 0) {
406                 type = tvb_get_guint8(tvb, offset + 0);
407                 length = tvb_get_guint8(tvb, offset + 1);
408
409                 ti = proto_tree_add_text(vlan_info_tree, tvb, offset,
410                     2 + length*2, "%s",
411                     val_to_str(type, vlan_tlv_type_vals,
412                       "Unknown TLV type: 0x%02x"));
413                 tlv_tree = proto_item_add_subtree(ti, ett_vtp_tlv);
414                 proto_tree_add_uint(tlv_tree, hf_vtp_vlan_tlvtype, tvb, offset,
415                     1, type);
416                 proto_tree_add_uint(tlv_tree, hf_vtp_vlan_tlvlength, tvb, offset+1,
417                     1, length);
418                 offset += 2;
419                 vlan_info_left -= 2;
420                 if (length > 0) {
421                         dissect_vlan_info_tlv(tvb, offset, length*2, tlv_tree,
422                             ti, type);
423                 }
424                 offset += length*2;
425                 vlan_info_left -= length*2;
426         }
427
428         return vlan_info_len;
429 }
430
431 static const value_string stp_type_vals[] = {
432         { 1, "SRT" },
433         { 2, "SRB" },
434         { 3, "Auto" },
435         { 0, NULL },
436 };
437
438 static const value_string pruning_vals[] = {
439         { 1, "Enabled" },
440         { 2, "Disabled" },
441         { 0, NULL },
442 };
443
444 static const value_string bridge_type_vals[] = {
445         { 1, "SRT" },
446         { 2, "SRB" },
447         { 0, NULL },
448 };
449
450 static const value_string backup_crf_mode_vals[] = {
451         { 1, "TrCRF is configured as a backup" },
452         { 2, "TrCRF is not configured as a backup" },
453         { 0, NULL },
454 };
455
456 static void
457 dissect_vlan_info_tlv(tvbuff_t *tvb, int offset, int length,
458     proto_tree *tree, proto_item *ti, guint8 type)
459 {
460         switch (type) {
461
462         case SR_RING_NUM:
463                 if (length == 2) {
464                         proto_item_set_text(ti,
465                             "Source-Routing Ring Number: 0x%04x",
466                             tvb_get_ntohs(tvb, offset));
467                         proto_tree_add_text(tree, tvb, offset, 2,
468                             "Source-Routing Ring Number: 0x%04x",
469                             tvb_get_ntohs(tvb, offset));
470                 } else {
471                         proto_item_set_text(ti,
472                             "Source-Routing Ring Number: Bad length %u",
473                             length);
474                         proto_tree_add_text(tree, tvb, offset, length,
475                             "Source-Routing Ring Number: Bad length %u",
476                             length);
477                 }
478                 break;
479
480         case SR_BRIDGE_NUM:
481                 if (length == 2) {
482                         proto_item_set_text(ti,
483                             "Source-Routing Bridge Number: 0x%04x",
484                             tvb_get_ntohs(tvb, offset));
485                         proto_tree_add_text(tree, tvb, offset, 2,
486                             "Source-Routing Bridge Number: 0x%04x",
487                             tvb_get_ntohs(tvb, offset));
488                 } else {
489                         proto_item_set_text(ti,
490                             "Source-Routing Bridge Number: Bad length %u",
491                             length);
492                         proto_tree_add_text(tree, tvb, offset, length,
493                             "Source-Routing Bridge Number: Bad length %u",
494                             length);
495                 }
496                 break;
497
498         case STP_TYPE:
499                 if (length == 2) {
500                         proto_item_set_text(ti,
501                             "Spanning-Tree Protocol Type: %s",
502                             val_to_str(tvb_get_ntohs(tvb, offset), stp_type_vals,
503                               "Unknown (0x%04x)"));
504                         proto_tree_add_text(tree, tvb, offset, 2,
505                             "Spanning-Tree Protocol Type: %s",
506                             val_to_str(tvb_get_ntohs(tvb, offset), stp_type_vals,
507                               "Unknown (0x%04x)"));
508                 } else {
509                         proto_item_set_text(ti,
510                             "Spanning-Tree Protocol Type: Bad length %u",
511                             length);
512                         proto_tree_add_text(tree, tvb, offset, length,
513                             "Spanning-Tree Protocol Type: Bad length %u",
514                             length);
515                 }
516                 break;
517
518         case PARENT_VLAN:
519                 if (length == 2) {
520                         proto_item_set_text(ti,
521                             "Parent VLAN: 0x%04x",
522                             tvb_get_ntohs(tvb, offset));
523                         proto_tree_add_text(tree, tvb, offset, 2,
524                             "Parent VLAN: 0x%04x",
525                             tvb_get_ntohs(tvb, offset));
526                 } else {
527                         proto_item_set_text(ti,
528                             "Parent VLAN: Bad length %u",
529                             length);
530                         proto_tree_add_text(tree, tvb, offset, length,
531                             "Parent VLAN: Bad length %u",
532                             length);
533                 }
534                 break;
535
536         case TR_BRIDGED_VLANS:
537                 if (length == 2) {
538                         proto_item_set_text(ti,
539                             "Translationally Bridged VLANs: 0x%04x",
540                             tvb_get_ntohs(tvb, offset));
541                         proto_tree_add_text(tree, tvb, offset, 2,
542                             "Translationally Bridged VLANs: 0x%04x",
543                             tvb_get_ntohs(tvb, offset));
544                 } else {
545                         proto_item_set_text(ti,
546                             "Translationally Bridged VLANs: Bad length %u",
547                             length);
548                         proto_tree_add_text(tree, tvb, offset, length,
549                             "Translationally Bridged VLANs: Bad length %u",
550                             length);
551                 }
552                 break;
553
554         case PRUNING:
555                 if (length == 2) {
556                         proto_item_set_text(ti,
557                             "Pruning: %s",
558                             val_to_str(tvb_get_ntohs(tvb, offset), pruning_vals,
559                               "Unknown (0x%04x)"));
560                         proto_tree_add_text(tree, tvb, offset, 2,
561                             "Pruning: %s",
562                             val_to_str(tvb_get_ntohs(tvb, offset), pruning_vals,
563                               "Unknown (0x%04x)"));
564                 } else {
565                         proto_item_set_text(ti,
566                             "Pruning: Bad length %u",
567                             length);
568                         proto_tree_add_text(tree, tvb, offset, length,
569                             "Pruning: Bad length %u",
570                             length);
571                 }
572                 break;
573
574         case BRIDGE_TYPE:
575                 if (length == 2) {
576                         proto_item_set_text(ti,
577                             "Bridge Type: %s",
578                             val_to_str(tvb_get_ntohs(tvb, offset), bridge_type_vals,
579                               "Unknown (0x%04x)"));
580                         proto_tree_add_text(tree, tvb, offset, 2,
581                             "Bridge Type: %s",
582                             val_to_str(tvb_get_ntohs(tvb, offset), bridge_type_vals,
583                               "Unknown (0x%04x)"));
584                 } else {
585                         proto_item_set_text(ti,
586                             "Bridge Type: Bad length %u",
587                             length);
588                         proto_tree_add_text(tree, tvb, offset, length,
589                             "Bridge Type: Bad length %u",
590                             length);
591                 }
592                 break;
593
594         case MAX_ARE_HOP_CNT:
595                 if (length == 2) {
596                         proto_item_set_text(ti,
597                             "Max ARE Hop Count: %u",
598                             tvb_get_ntohs(tvb, offset));
599                         proto_tree_add_text(tree, tvb, offset, 2,
600                             "Max ARE Hop Count: %u",
601                             tvb_get_ntohs(tvb, offset));
602                 } else {
603                         proto_item_set_text(ti,
604                             "Max ARE Hop Count: Bad length %u",
605                             length);
606                         proto_tree_add_text(tree, tvb, offset, length,
607                             "Max ARE Hop Count: Bad length %u",
608                             length);
609                 }
610                 break;
611
612         case MAX_STE_HOP_CNT:
613                 if (length == 2) {
614                         proto_item_set_text(ti,
615                             "Max STE Hop Count: %u",
616                             tvb_get_ntohs(tvb, offset));
617                         proto_tree_add_text(tree, tvb, offset, 2,
618                             "Max STE Hop Count: %u",
619                             tvb_get_ntohs(tvb, offset));
620                 } else {
621                         proto_item_set_text(ti,
622                             "Max STE Hop Count: Bad length %u",
623                             length);
624                         proto_tree_add_text(tree, tvb, offset, length,
625                             "Max STE Hop Count: Bad length %u",
626                             length);
627                 }
628                 break;
629
630         case BACKUP_CRF_MODE:
631                 if (length == 2) {
632                         proto_item_set_text(ti,
633                             "Backup CRF Mode: %s",
634                             val_to_str(tvb_get_ntohs(tvb, offset), backup_crf_mode_vals,
635                               "Unknown (0x%04x)"));
636                         proto_tree_add_text(tree, tvb, offset, 2,
637                             "Backup CRF Mode: %s",
638                             val_to_str(tvb_get_ntohs(tvb, offset), backup_crf_mode_vals,
639                               "Unknown (0x%04x)"));
640                 } else {
641                         proto_item_set_text(ti,
642                             "Backup CRF Mode: Bad length %u",
643                             length);
644                         proto_tree_add_text(tree, tvb, offset, length,
645                             "Backup CRF Mode: Bad length %u",
646                             length);
647                 }
648                 break;
649
650         default:
651                 proto_tree_add_text(tree, tvb, offset, length, "Data");
652                 break;
653         }
654 }
655
656 void
657 proto_register_vtp(void)
658 {
659         static hf_register_info hf[] = {
660                 { &hf_vtp_version,
661                 { "Version",    "vtp.version", FT_UINT8, BASE_HEX, NULL, 0x0,
662                         NULL, HFILL }},
663
664                 { &hf_vtp_code,
665                 { "Code",       "vtp.code", FT_UINT8, BASE_HEX, VALS(type_vals), 0x0,
666                         NULL, HFILL }},
667
668                 { &hf_vtp_followers,
669                 { "Followers",  "vtp.followers", FT_UINT8, BASE_DEC, NULL, 0x0,
670                         "Number of following Subset-Advert messages", HFILL }},
671
672                 { &hf_vtp_md_len,
673                 { "Management Domain Length", "vtp.md_len", FT_UINT8, BASE_DEC, NULL, 0x0,
674                         "Length of management domain string", HFILL }},
675
676                 { &hf_vtp_md,
677                 { "Management Domain", "vtp.md", FT_STRING, BASE_NONE, NULL, 0,
678                         NULL, HFILL }},
679
680                 { &hf_vtp_conf_rev_num,
681                 { "Configuration Revision Number", "vtp.conf_rev_num", FT_UINT32, BASE_DEC, NULL, 0x0,
682                         "Revision number of the configuration information", HFILL }},
683
684                 { &hf_vtp_upd_id,
685                 { "Updater Identity", "vtp.upd_id", FT_IPv4, BASE_NONE, NULL, 0x0,
686                         "IP address of the updater", HFILL }},
687
688                 { &hf_vtp_upd_ts,
689                 { "Update Timestamp", "vtp.upd_ts", FT_STRING, BASE_NONE, NULL, 0,
690                         "Time stamp of the current configuration revision", HFILL }},
691
692                 { &hf_vtp_md5_digest,
693                 { "MD5 Digest", "vtp.md5_digest", FT_BYTES, BASE_NONE, NULL, 0x0,
694                         NULL, HFILL }},
695
696                 { &hf_vtp_seq_num,
697                 { "Sequence Number",    "vtp.seq_num", FT_UINT8, BASE_DEC, NULL, 0x0,
698                         "Order of this frame in the sequence of Subset-Advert frames", HFILL }},
699
700                 { &hf_vtp_start_value,
701                 { "Start Value",        "vtp.start_value", FT_UINT16, BASE_HEX, NULL, 0x0,
702                         "Virtual LAN ID of first VLAN for which information is requested", HFILL }},
703
704                 { &hf_vtp_vlan_info_len,
705                 { "VLAN Information Length",    "vtp.vlan_info.len", FT_UINT8, BASE_DEC, NULL, 0x0,
706                         "Length of the VLAN information field", HFILL }},
707
708                 { &hf_vtp_vlan_status_vlan_susp,
709                 { "VLAN suspended",     "vtp.vlan_info.status.vlan_susp", FT_BOOLEAN, 8, NULL, VLAN_SUSPENDED,
710                         NULL, HFILL }},
711
712                 { &hf_vtp_vlan_type,
713                 { "VLAN Type",  "vtp.vlan_info.vlan_type", FT_UINT8, BASE_HEX, VALS(vlan_type_vals), 0x0,
714                         "Type of VLAN", HFILL }},
715
716                 { &hf_vtp_vlan_name_len,
717                 { "VLAN Name Length", "vtp.vlan_info.vlan_name_len", FT_UINT8, BASE_DEC, NULL, 0x0,
718                         "Length of VLAN name string", HFILL }},
719
720                 { &hf_vtp_isl_vlan_id,
721                 { "ISL VLAN ID",        "vtp.vlan_info.isl_vlan_id", FT_UINT16, BASE_HEX, NULL, 0x0,
722                         "ID of this VLAN on ISL trunks", HFILL }},
723
724                 { &hf_vtp_mtu_size,
725                 { "MTU Size",   "vtp.vlan_info.mtu_size", FT_UINT16, BASE_DEC, NULL, 0x0,
726                         "MTU for this VLAN", HFILL }},
727
728                 { &hf_vtp_802_10_index,
729                 { "802.10 Index", "vtp.vlan_info.802_10_index", FT_UINT32, BASE_HEX, NULL, 0x0,
730                         "IEEE 802.10 security association identifier for this VLAN", HFILL }},
731
732                 { &hf_vtp_vlan_name,
733                 { "VLAN Name", "vtp.vlan_info.vlan_name", FT_STRING, BASE_NONE, NULL, 0,
734                         NULL, HFILL }},
735
736                 { &hf_vtp_vlan_tlvtype,
737                 { "Type",       "vtp.vlan_info.tlv_type", FT_UINT8, BASE_HEX, VALS(vlan_tlv_type_vals), 0x0,
738                         NULL, HFILL }},
739
740                 { &hf_vtp_vlan_tlvlength,
741                 { "Length",     "vtp.vlan_info.tlv_len", FT_UINT8, BASE_DEC, NULL, 0x0,
742                         NULL, HFILL }},
743
744                 { &hf_vtp_pruning_first_vid,
745                 { "First VLAN ID",      "vtp.pruning.first", FT_UINT16, BASE_DEC, NULL, 0x0,
746                         "First VLAN ID for which pruning information is present", HFILL }},
747
748                 { &hf_vtp_pruning_last_vid,
749                 { "Last VLAN ID",       "vtp.pruning.last", FT_UINT16, BASE_DEC, NULL, 0x0,
750                         "Last VLAN ID for which pruning information is present", HFILL }},
751
752                 { &hf_vtp_pruning_active_vid,
753                 { "VLAN",       "vtp.pruning.active", FT_UINT16, BASE_DEC, NULL, 0x0,
754                         "Active advertised VLAN ID", HFILL }},
755
756         };
757         static gint *ett[] = {
758                 &ett_vtp,
759                 &ett_vtp_vlan_info,
760                 &ett_vtp_vlan_status,
761                 &ett_vtp_tlv,
762                 &ett_vtp_pruning,
763         };
764
765         proto_vtp = proto_register_protocol("VLAN Trunking Protocol",
766             "VTP", "vtp");
767         proto_register_field_array(proto_vtp, hf, array_length(hf));
768         proto_register_subtree_array(ett, array_length(ett));
769 }
770
771 void
772 proto_reg_handoff_vtp(void)
773 {
774         dissector_handle_t vtp_handle;
775
776         vtp_handle = create_dissector_handle(dissect_vtp, proto_vtp);
777         dissector_add_uint("llc.cisco_pid", 0x2003, vtp_handle);
778 }