]> The Tcpdump Group git mirrors - tcpdump/blob - print-vtp.c
Netdissectify the to-name resolution routines.
[tcpdump] / print-vtp.c
1 /*
2 * Copyright (c) 1998-2007 The TCPDUMP project
3 *
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.
14 *
15 * VLAN TRUNKING PROTOCOL (VTP)
16 *
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
21 *
22 * Original code ode by Carles Kishimoto <carles.kishimoto@gmail.com>
23 */
24
25 #define NETDISSECT_REWORKED
26 #ifdef HAVE_CONFIG_H
27 #include "config.h"
28 #endif
29
30 #include <tcpdump-stdinc.h>
31
32 #include "interface.h"
33 #include "addrtoname.h"
34 #include "extract.h"
35
36 #define VTP_HEADER_LEN 36
37 #define VTP_DOMAIN_NAME_LEN 32
38 #define VTP_MD5_DIGEST_LEN 16
39 #define VTP_UPDATE_TIMESTAMP_LEN 12
40 #define VTP_VLAN_INFO_OFFSET 12
41
42 #define VTP_SUMMARY_ADV 0x01
43 #define VTP_SUBSET_ADV 0x02
44 #define VTP_ADV_REQUEST 0x03
45 #define VTP_JOIN_MESSAGE 0x04
46
47 struct vtp_vlan_ {
48 u_int8_t len;
49 u_int8_t status;
50 u_int8_t type;
51 u_int8_t name_len;
52 u_int16_t vlanid;
53 u_int16_t mtu;
54 u_int32_t index;
55 };
56
57 static const struct tok vtp_message_type_values[] = {
58 { VTP_SUMMARY_ADV, "Summary advertisement"},
59 { VTP_SUBSET_ADV, "Subset advertisement"},
60 { VTP_ADV_REQUEST, "Advertisement request"},
61 { VTP_JOIN_MESSAGE, "Join message"},
62 { 0, NULL }
63 };
64
65 static const struct tok vtp_header_values[] = {
66 { 0x01, "Followers"}, /* On Summary advertisement, 3rd byte is Followers */
67 { 0x02, "Seq number"}, /* On Subset advertisement, 3rd byte is Sequence number */
68 { 0x03, "Rsvd"}, /* On Adver. requests 3rd byte is Rsvd */
69 { 0x04, "Rsvd"}, /* On Adver. requests 3rd byte is Rsvd */
70 { 0, NULL }
71 };
72
73 static const struct tok vtp_vlan_type_values[] = {
74 { 0x01, "Ethernet"},
75 { 0x02, "FDDI"},
76 { 0x03, "TrCRF"},
77 { 0x04, "FDDI-net"},
78 { 0x05, "TrBRF"},
79 { 0, NULL }
80 };
81
82 static const struct tok vtp_vlan_status[] = {
83 { 0x00, "Operational"},
84 { 0x01, "Suspended"},
85 { 0, NULL }
86 };
87
88 #define VTP_VLAN_SOURCE_ROUTING_RING_NUMBER 0x01
89 #define VTP_VLAN_SOURCE_ROUTING_BRIDGE_NUMBER 0x02
90 #define VTP_VLAN_STP_TYPE 0x03
91 #define VTP_VLAN_PARENT_VLAN 0x04
92 #define VTP_VLAN_TRANS_BRIDGED_VLAN 0x05
93 #define VTP_VLAN_PRUNING 0x06
94 #define VTP_VLAN_BRIDGE_TYPE 0x07
95 #define VTP_VLAN_ARP_HOP_COUNT 0x08
96 #define VTP_VLAN_STE_HOP_COUNT 0x09
97 #define VTP_VLAN_BACKUP_CRF_MODE 0x0A
98
99 static const struct tok vtp_vlan_tlv_values[] = {
100 { VTP_VLAN_SOURCE_ROUTING_RING_NUMBER, "Source-Routing Ring Number TLV"},
101 { VTP_VLAN_SOURCE_ROUTING_BRIDGE_NUMBER, "Source-Routing Bridge Number TLV"},
102 { VTP_VLAN_STP_TYPE, "STP type TLV"},
103 { VTP_VLAN_PARENT_VLAN, "Parent VLAN TLV"},
104 { VTP_VLAN_TRANS_BRIDGED_VLAN, "Translationally bridged VLANs TLV"},
105 { VTP_VLAN_PRUNING, "Pruning TLV"},
106 { VTP_VLAN_BRIDGE_TYPE, "Bridge Type TLV"},
107 { VTP_VLAN_ARP_HOP_COUNT, "Max ARP Hop Count TLV"},
108 { VTP_VLAN_STE_HOP_COUNT, "Max STE Hop Count TLV"},
109 { VTP_VLAN_BACKUP_CRF_MODE, "Backup CRF Mode TLV"},
110 { 0, NULL }
111 };
112
113 static const struct tok vtp_stp_type_values[] = {
114 { 1, "SRT"},
115 { 2, "SRB"},
116 { 3, "Auto"},
117 { 0, NULL }
118 };
119
120 void
121 vtp_print (netdissect_options *ndo,
122 const u_char *pptr, u_int length)
123 {
124 int type, len, tlv_len, tlv_value;
125 const u_char *tptr;
126 const struct vtp_vlan_ *vtp_vlan;
127
128 if (length < VTP_HEADER_LEN)
129 goto trunc;
130
131 tptr = pptr;
132
133 if (!ND_TTEST2(*tptr, VTP_HEADER_LEN))
134 goto trunc;
135
136 type = *(tptr+1);
137 ND_PRINT((ndo, "VTPv%u, Message %s (0x%02x), length %u",
138 *tptr,
139 tok2str(vtp_message_type_values,"Unknown message type", type),
140 *(tptr+1),
141 length));
142
143 /* In non-verbose mode, just print version and message type */
144 if (ndo->ndo_vflag < 1) {
145 return;
146 }
147
148 /* verbose mode print all fields */
149 ND_PRINT((ndo, "\n\tDomain name: %s, %s: %u",
150 (tptr+4),
151 tok2str(vtp_header_values,"Unknown",*(tptr+1)),
152 *(tptr+2)));
153
154 tptr += VTP_HEADER_LEN;
155
156 switch (type) {
157
158 case VTP_SUMMARY_ADV:
159
160 /*
161 * SUMMARY ADVERTISEMENT
162 *
163 * 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
164 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
165 * | Version | Code | Followers | MmgtD Len |
166 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
167 * | Management Domain Name |
168 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
169 * | Configuration revision number |
170 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
171 * | Updater Identity IP address |
172 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
173 * | Update Timestamp (12 bytes) |
174 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
175 * | MD5 digest (16 bytes) |
176 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
177 *
178 */
179
180 ND_PRINT((ndo, "\n\t Config Rev %x, Updater %s",
181 EXTRACT_32BITS(tptr),
182 ipaddr_string(ndo, tptr+4)));
183 tptr += 8;
184 ND_PRINT((ndo, ", Timestamp 0x%08x 0x%08x 0x%08x",
185 EXTRACT_32BITS(tptr),
186 EXTRACT_32BITS(tptr + 4),
187 EXTRACT_32BITS(tptr + 8)));
188 tptr += VTP_UPDATE_TIMESTAMP_LEN;
189 ND_PRINT((ndo, ", MD5 digest: %08x%08x%08x%08x",
190 EXTRACT_32BITS(tptr),
191 EXTRACT_32BITS(tptr + 4),
192 EXTRACT_32BITS(tptr + 8),
193 EXTRACT_32BITS(tptr + 12)));
194 tptr += VTP_MD5_DIGEST_LEN;
195 break;
196
197 case VTP_SUBSET_ADV:
198
199 /*
200 * SUBSET ADVERTISEMENT
201 *
202 * 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
203 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
204 * | Version | Code | Seq number | MmgtD Len |
205 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
206 * | Management Domain Name |
207 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
208 * | Configuration revision number |
209 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
210 * | VLAN info field 1 |
211 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
212 * | ................ |
213 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
214 * | VLAN info field N |
215 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
216 *
217 */
218
219 ND_PRINT((ndo, ", Config Rev %x", EXTRACT_32BITS(tptr)));
220
221 /*
222 * VLAN INFORMATION
223 * 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
224 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
225 * | V info len | Status | VLAN type | VLAN name len |
226 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
227 * | ISL vlan id | MTU size |
228 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
229 * | 802.10 index (SAID) |
230 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
231 * | VLAN name |
232 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
233 *
234 */
235
236 tptr += 4;
237 while (tptr < (pptr+length)) {
238
239 len = *tptr;
240 if (len == 0)
241 break;
242
243 if (!ND_TTEST2(*tptr, len))
244 goto trunc;
245
246 vtp_vlan = (struct vtp_vlan_*)tptr;
247 ND_PRINT((ndo, "\n\tVLAN info status %s, type %s, VLAN-id %u, MTU %u, SAID 0x%08x, Name %s",
248 tok2str(vtp_vlan_status,"Unknown",vtp_vlan->status),
249 tok2str(vtp_vlan_type_values,"Unknown",vtp_vlan->type),
250 EXTRACT_16BITS(&vtp_vlan->vlanid),
251 EXTRACT_16BITS(&vtp_vlan->mtu),
252 EXTRACT_32BITS(&vtp_vlan->index),
253 (tptr + VTP_VLAN_INFO_OFFSET)));
254
255 /*
256 * Vlan names are aligned to 32-bit boundaries.
257 */
258 len -= VTP_VLAN_INFO_OFFSET + 4*((vtp_vlan->name_len + 3)/4);
259 tptr += VTP_VLAN_INFO_OFFSET + 4*((vtp_vlan->name_len + 3)/4);
260
261 /* TLV information follows */
262
263 while (len > 0) {
264
265 /*
266 * Cisco specs says 2 bytes for type + 2 bytes for length, take only 1
267 * See: http://www.cisco.com/univercd/cc/td/doc/product/lan/trsrb/frames.htm
268 */
269 type = *tptr;
270 tlv_len = *(tptr+1);
271
272 ND_PRINT((ndo, "\n\t\t%s (0x%04x) TLV",
273 tok2str(vtp_vlan_tlv_values, "Unknown", type),
274 type));
275
276 /*
277 * infinite loop check
278 */
279 if (type == 0 || tlv_len == 0) {
280 return;
281 }
282
283 if (!ND_TTEST2(*tptr, tlv_len*2 +2))
284 goto trunc;
285
286 tlv_value = EXTRACT_16BITS(tptr+2);
287
288 switch (type) {
289 case VTP_VLAN_STE_HOP_COUNT:
290 ND_PRINT((ndo, ", %u", tlv_value));
291 break;
292
293 case VTP_VLAN_PRUNING:
294 ND_PRINT((ndo, ", %s (%u)",
295 tlv_value == 1 ? "Enabled" : "Disabled",
296 tlv_value));
297 break;
298
299 case VTP_VLAN_STP_TYPE:
300 ND_PRINT((ndo, ", %s (%u)",
301 tok2str(vtp_stp_type_values, "Unknown", tlv_value),
302 tlv_value));
303 break;
304
305 case VTP_VLAN_BRIDGE_TYPE:
306 ND_PRINT((ndo, ", %s (%u)",
307 tlv_value == 1 ? "SRB" : "SRT",
308 tlv_value));
309 break;
310
311 case VTP_VLAN_BACKUP_CRF_MODE:
312 ND_PRINT((ndo, ", %s (%u)",
313 tlv_value == 1 ? "Backup" : "Not backup",
314 tlv_value));
315 break;
316
317 /*
318 * FIXME those are the defined TLVs that lack a decoder
319 * you are welcome to contribute code ;-)
320 */
321
322 case VTP_VLAN_SOURCE_ROUTING_RING_NUMBER:
323 case VTP_VLAN_SOURCE_ROUTING_BRIDGE_NUMBER:
324 case VTP_VLAN_PARENT_VLAN:
325 case VTP_VLAN_TRANS_BRIDGED_VLAN:
326 case VTP_VLAN_ARP_HOP_COUNT:
327 default:
328 print_unknown_data(ndo, tptr, "\n\t\t ", 2 + tlv_len*2);
329 break;
330 }
331 len -= 2 + tlv_len*2;
332 tptr += 2 + tlv_len*2;
333 }
334 }
335 break;
336
337 case VTP_ADV_REQUEST:
338
339 /*
340 * ADVERTISEMENT REQUEST
341 *
342 * 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
343 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
344 * | Version | Code | Reserved | MmgtD Len |
345 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
346 * | Management Domain Name |
347 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
348 * | Start value |
349 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
350 *
351 */
352
353 ND_PRINT((ndo, "\n\tStart value: %u", EXTRACT_32BITS(tptr)));
354 break;
355
356 case VTP_JOIN_MESSAGE:
357
358 /* FIXME - Could not find message format */
359 break;
360
361 default:
362 break;
363 }
364
365 return;
366
367 trunc:
368 ND_PRINT((ndo, "[|vtp]"));
369 }
370
371 /*
372 * Local Variables:
373 * c-style: whitesmith
374 * c-basic-offset: 4
375 * End:
376 */