2 * Copyright (c) 1998-2007 The TCPDUMP project
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that: (1) source code
6 * distributions retain the above copyright notice and this paragraph
7 * in its entirety, and (2) distributions including binary code include
8 * the above copyright notice and this paragraph in its entirety in
9 * the documentation or other materials provided with the distribution.
10 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND
11 * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
12 * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
13 * FOR A PARTICULAR PURPOSE.
15 * VLAN TRUNKING PROTOCOL (VTP)
17 * Reference documentation:
18 * http://www.cisco.com/en/US/tech/tk389/tk689/technologies_tech_note09186a0080094c52.shtml
19 * http://www.cisco.com/warp/public/473/21.html
20 * http://www.cisco.com/univercd/cc/td/doc/product/lan/trsrb/frames.htm
22 * Original code ode by Carles Kishimoto <carles.kishimoto@gmail.com>
29 #include <tcpdump-stdinc.h>
31 #include "interface.h"
32 #include "addrtoname.h"
35 #define VTP_HEADER_LEN 36
36 #define VTP_DOMAIN_NAME_LEN 32
37 #define VTP_MD5_DIGEST_LEN 16
38 #define VTP_UPDATE_TIMESTAMP_LEN 12
39 #define VTP_VLAN_INFO_OFFSET 12
41 #define VTP_SUMMARY_ADV 0x01
42 #define VTP_SUBSET_ADV 0x02
43 #define VTP_ADV_REQUEST 0x03
44 #define VTP_JOIN_MESSAGE 0x04
56 static const struct tok vtp_message_type_values
[] = {
57 { VTP_SUMMARY_ADV
, "Summary advertisement"},
58 { VTP_SUBSET_ADV
, "Subset advertisement"},
59 { VTP_ADV_REQUEST
, "Advertisement request"},
60 { VTP_JOIN_MESSAGE
, "Join message"},
64 static const struct tok vtp_header_values
[] = {
65 { 0x01, "Followers"}, /* On Summary advertisement, 3rd byte is Followers */
66 { 0x02, "Seq number"}, /* On Subset advertisement, 3rd byte is Sequence number */
67 { 0x03, "Rsvd"}, /* On Adver. requests 3rd byte is Rsvd */
68 { 0x04, "Rsvd"}, /* On Adver. requests 3rd byte is Rsvd */
72 static const struct tok vtp_vlan_type_values
[] = {
81 static const struct tok vtp_vlan_status
[] = {
82 { 0x00, "Operational"},
87 #define VTP_VLAN_SOURCE_ROUTING_RING_NUMBER 0x01
88 #define VTP_VLAN_SOURCE_ROUTING_BRIDGE_NUMBER 0x02
89 #define VTP_VLAN_STP_TYPE 0x03
90 #define VTP_VLAN_PARENT_VLAN 0x04
91 #define VTP_VLAN_TRANS_BRIDGED_VLAN 0x05
92 #define VTP_VLAN_PRUNING 0x06
93 #define VTP_VLAN_BRIDGE_TYPE 0x07
94 #define VTP_VLAN_ARP_HOP_COUNT 0x08
95 #define VTP_VLAN_STE_HOP_COUNT 0x09
96 #define VTP_VLAN_BACKUP_CRF_MODE 0x0A
98 static const struct tok vtp_vlan_tlv_values
[] = {
99 { VTP_VLAN_SOURCE_ROUTING_RING_NUMBER
, "Source-Routing Ring Number TLV"},
100 { VTP_VLAN_SOURCE_ROUTING_BRIDGE_NUMBER
, "Source-Routing Bridge Number TLV"},
101 { VTP_VLAN_STP_TYPE
, "STP type TLV"},
102 { VTP_VLAN_PARENT_VLAN
, "Parent VLAN TLV"},
103 { VTP_VLAN_TRANS_BRIDGED_VLAN
, "Translationally bridged VLANs TLV"},
104 { VTP_VLAN_PRUNING
, "Pruning TLV"},
105 { VTP_VLAN_BRIDGE_TYPE
, "Bridge Type TLV"},
106 { VTP_VLAN_ARP_HOP_COUNT
, "Max ARP Hop Count TLV"},
107 { VTP_VLAN_STE_HOP_COUNT
, "Max STE Hop Count TLV"},
108 { VTP_VLAN_BACKUP_CRF_MODE
, "Backup CRF Mode TLV"},
112 static const struct tok vtp_stp_type_values
[] = {
120 vtp_print (netdissect_options
*ndo
,
121 const u_char
*pptr
, u_int length
)
123 int type
, len
, tlv_len
, tlv_value
;
125 const struct vtp_vlan_
*vtp_vlan
;
127 if (length
< VTP_HEADER_LEN
)
132 ND_TCHECK2(*tptr
, VTP_HEADER_LEN
);
135 ND_PRINT((ndo
, "VTPv%u, Message %s (0x%02x), length %u",
137 tok2str(vtp_message_type_values
,"Unknown message type", type
),
141 /* In non-verbose mode, just print version and message type */
142 if (ndo
->ndo_vflag
< 1) {
146 /* verbose mode print all fields */
147 ND_PRINT((ndo
, "\n\tDomain name: %s, %s: %u",
149 tok2str(vtp_header_values
,"Unknown",*(tptr
+1)),
152 tptr
+= VTP_HEADER_LEN
;
156 case VTP_SUMMARY_ADV
:
159 * SUMMARY ADVERTISEMENT
161 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
162 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
163 * | Version | Code | Followers | MmgtD Len |
164 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
165 * | Management Domain Name |
166 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
167 * | Configuration revision number |
168 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
169 * | Updater Identity IP address |
170 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
171 * | Update Timestamp (12 bytes) |
172 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
173 * | MD5 digest (16 bytes) |
174 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
178 ND_PRINT((ndo
, "\n\t Config Rev %x, Updater %s",
179 EXTRACT_32BITS(tptr
),
180 ipaddr_string(ndo
, tptr
+4)));
182 ND_PRINT((ndo
, ", Timestamp 0x%08x 0x%08x 0x%08x",
183 EXTRACT_32BITS(tptr
),
184 EXTRACT_32BITS(tptr
+ 4),
185 EXTRACT_32BITS(tptr
+ 8)));
186 tptr
+= VTP_UPDATE_TIMESTAMP_LEN
;
187 ND_PRINT((ndo
, ", MD5 digest: %08x%08x%08x%08x",
188 EXTRACT_32BITS(tptr
),
189 EXTRACT_32BITS(tptr
+ 4),
190 EXTRACT_32BITS(tptr
+ 8),
191 EXTRACT_32BITS(tptr
+ 12)));
192 tptr
+= VTP_MD5_DIGEST_LEN
;
198 * SUBSET ADVERTISEMENT
200 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
201 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
202 * | Version | Code | Seq number | MmgtD Len |
203 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
204 * | Management Domain Name |
205 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
206 * | Configuration revision number |
207 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
208 * | VLAN info field 1 |
209 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
210 * | ................ |
211 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
212 * | VLAN info field N |
213 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
217 ND_PRINT((ndo
, ", Config Rev %x", EXTRACT_32BITS(tptr
)));
221 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
222 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
223 * | V info len | Status | VLAN type | VLAN name len |
224 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
225 * | ISL vlan id | MTU size |
226 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
227 * | 802.10 index (SAID) |
228 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
230 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
235 while (tptr
< (pptr
+length
)) {
241 ND_TCHECK2(*tptr
, len
);
243 vtp_vlan
= (struct vtp_vlan_
*)tptr
;
244 ND_PRINT((ndo
, "\n\tVLAN info status %s, type %s, VLAN-id %u, MTU %u, SAID 0x%08x, Name %s",
245 tok2str(vtp_vlan_status
,"Unknown",vtp_vlan
->status
),
246 tok2str(vtp_vlan_type_values
,"Unknown",vtp_vlan
->type
),
247 EXTRACT_16BITS(&vtp_vlan
->vlanid
),
248 EXTRACT_16BITS(&vtp_vlan
->mtu
),
249 EXTRACT_32BITS(&vtp_vlan
->index
),
250 (tptr
+ VTP_VLAN_INFO_OFFSET
)));
253 * Vlan names are aligned to 32-bit boundaries.
255 len
-= VTP_VLAN_INFO_OFFSET
+ 4*((vtp_vlan
->name_len
+ 3)/4);
256 tptr
+= VTP_VLAN_INFO_OFFSET
+ 4*((vtp_vlan
->name_len
+ 3)/4);
258 /* TLV information follows */
263 * Cisco specs says 2 bytes for type + 2 bytes for length, take only 1
264 * See: http://www.cisco.com/univercd/cc/td/doc/product/lan/trsrb/frames.htm
269 ND_PRINT((ndo
, "\n\t\t%s (0x%04x) TLV",
270 tok2str(vtp_vlan_tlv_values
, "Unknown", type
),
274 * infinite loop check
276 if (type
== 0 || tlv_len
== 0) {
280 ND_TCHECK2(*tptr
, tlv_len
* 2 +2);
282 tlv_value
= EXTRACT_16BITS(tptr
+2);
285 case VTP_VLAN_STE_HOP_COUNT
:
286 ND_PRINT((ndo
, ", %u", tlv_value
));
289 case VTP_VLAN_PRUNING
:
290 ND_PRINT((ndo
, ", %s (%u)",
291 tlv_value
== 1 ? "Enabled" : "Disabled",
295 case VTP_VLAN_STP_TYPE
:
296 ND_PRINT((ndo
, ", %s (%u)",
297 tok2str(vtp_stp_type_values
, "Unknown", tlv_value
),
301 case VTP_VLAN_BRIDGE_TYPE
:
302 ND_PRINT((ndo
, ", %s (%u)",
303 tlv_value
== 1 ? "SRB" : "SRT",
307 case VTP_VLAN_BACKUP_CRF_MODE
:
308 ND_PRINT((ndo
, ", %s (%u)",
309 tlv_value
== 1 ? "Backup" : "Not backup",
314 * FIXME those are the defined TLVs that lack a decoder
315 * you are welcome to contribute code ;-)
318 case VTP_VLAN_SOURCE_ROUTING_RING_NUMBER
:
319 case VTP_VLAN_SOURCE_ROUTING_BRIDGE_NUMBER
:
320 case VTP_VLAN_PARENT_VLAN
:
321 case VTP_VLAN_TRANS_BRIDGED_VLAN
:
322 case VTP_VLAN_ARP_HOP_COUNT
:
324 print_unknown_data(ndo
, tptr
, "\n\t\t ", 2 + tlv_len
*2);
327 len
-= 2 + tlv_len
*2;
328 tptr
+= 2 + tlv_len
*2;
333 case VTP_ADV_REQUEST
:
336 * ADVERTISEMENT REQUEST
338 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
339 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
340 * | Version | Code | Reserved | MmgtD Len |
341 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
342 * | Management Domain Name |
343 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
345 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
349 ND_PRINT((ndo
, "\n\tStart value: %u", EXTRACT_32BITS(tptr
)));
352 case VTP_JOIN_MESSAGE
:
354 /* FIXME - Could not find message format */
364 ND_PRINT((ndo
, "[|vtp]"));
369 * c-style: whitesmith