]> The Tcpdump Group git mirrors - tcpdump/blob - print-vtp.c
6f3c18bae223578da12357dc35af9850453ec531
[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 *
21 * Original code ode by Carles Kishimoto <carles.kishimoto@gmail.com>
22 */
23
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27
28 #include <tcpdump-stdinc.h>
29
30 #include <stdio.h>
31 #include <string.h>
32
33 #include "interface.h"
34 #include "addrtoname.h"
35 #include "extract.h"
36 #include "nlpid.h"
37
38 #define VTP_HEADER_LEN 36
39 #define VTP_DOMAIN_NAME_LEN 32
40 #define VTP_MD5_DIGEST_LEN 16
41 #define VTP_UPDATE_TIMESTAMP_LEN 12
42 #define VTP_VLAN_INFO_OFFSET 12
43
44 #define VTP_SUMMARY_ADV 0x01
45 #define VTP_SUBSET_ADV 0x02
46 #define VTP_ADV_REQUEST 0x03
47 #define VTP_JOIN_MESSAGE 0x04
48
49 struct vtp_vlan_ {
50 u_int8_t len;
51 u_int8_t status;
52 u_int8_t type;
53 u_int8_t name_len;
54 u_int16_t vlanid;
55 u_int16_t mtu;
56 u_int32_t index;
57 };
58
59 static struct tok vtp_message_type_values[] = {
60 { VTP_SUMMARY_ADV, "Summary advertisement"},
61 { VTP_SUBSET_ADV, "Subset advertisement"},
62 { VTP_ADV_REQUEST, "Advertisement request"},
63 { VTP_JOIN_MESSAGE, "Join message"},
64 { 0, NULL }
65 };
66
67 static struct tok vtp_header_values[] = {
68 { 0x01, "Followers"}, /* On Summary advertisement, 3rd byte is Followers */
69 { 0x02, "Seq number"}, /* On Subset advertisement, 3rd byte is Sequence number */
70 { 0x03, "Rsvd"}, /* On Adver. requests 3rd byte is Rsvd */
71 { 0x04, "Rsvd"}, /* On Adver. requests 3rd byte is Rsvd */
72 { 0, NULL }
73 };
74
75 static struct tok vtp_vlan_type_values[] = {
76 { 0x01, "Ethernet"},
77 { 0x02, "FDDI"},
78 { 0x03, "TrCRF"},
79 { 0x04, "FDDI-net"},
80 { 0x05, "TrBRF"},
81 { 0, NULL }
82 };
83
84 static struct tok vtp_vlan_status[] = {
85 { 0x00, "Operational"},
86 { 0x01, "Suspended"},
87 { 0, NULL }
88 };
89
90 void
91 vtp_print (const u_char *pptr, u_int length)
92 {
93 int type, len;
94 const u_char *tptr;
95 const struct vtp_vlan_ *vtp_vlan;
96
97 if (length < VTP_HEADER_LEN)
98 goto trunc;
99
100 tptr = pptr;
101
102 if (!TTEST2(*tptr, VTP_HEADER_LEN))
103 goto trunc;
104
105 type = *(tptr+1);
106 printf("VTPv%u, Message %s (0x%02x), length %u",
107 *tptr,
108 tok2str(vtp_message_type_values,"Unknown message type", type),
109 *(tptr+1),
110 length);
111
112 /* In non-verbose mode, just print version and message type */
113 if (vflag < 1) {
114 return;
115 }
116
117 /* verbose mode print all fields */
118 printf("\n\tDomain name: %s, Flags [%s] %u",
119 (tptr+4),
120 tok2str(vtp_header_values,"Unknown",*(tptr+1)),
121 *(tptr+2));
122
123 tptr += VTP_HEADER_LEN;
124
125 switch (type) {
126
127 case VTP_SUMMARY_ADV:
128
129 /*
130 * SUMMARY ADVERTISEMENT
131 *
132 * 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
133 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
134 * | Version | Code | Followers | MmgtD Len |
135 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
136 * | Management Domain Name |
137 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
138 * | Configuration revision number |
139 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
140 * | Updater Identity IP address |
141 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
142 * | Update Timestamp (12 bytes) |
143 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
144 * | MD5 digest (16 bytes) |
145 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
146 *
147 */
148
149 printf("\n\t Config Rev %x, Updater %s",
150 EXTRACT_32BITS(tptr),
151 ipaddr_string(tptr+4));
152 tptr += 8;
153 printf(", Timestamp 0x%08x 0x%08x 0x%08x",
154 EXTRACT_32BITS(tptr),
155 EXTRACT_32BITS(tptr + 4),
156 EXTRACT_32BITS(tptr + 8));
157 tptr += VTP_UPDATE_TIMESTAMP_LEN;
158 printf(", MD5 digest: %08x%08x%08x%08x",
159 EXTRACT_32BITS(tptr),
160 EXTRACT_32BITS(tptr + 4),
161 EXTRACT_32BITS(tptr + 8),
162 EXTRACT_32BITS(tptr + 12));
163 tptr += VTP_MD5_DIGEST_LEN;
164 break;
165
166 case VTP_SUBSET_ADV:
167
168 /*
169 * SUBSET ADVERTISEMENT
170 *
171 * 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
172 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
173 * | Version | Code | Seq number | MmgtD Len |
174 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
175 * | Management Domain Name |
176 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
177 * | Configuration revision number |
178 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
179 * | VLAN info field 1 |
180 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
181 * | ................ |
182 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
183 * | VLAN info field N |
184 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
185 *
186 */
187
188 printf(", Config Rev %x", EXTRACT_32BITS(tptr));
189
190 /*
191 * VLAN INFORMATION
192 * 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
193 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
194 * | V info len | Status | VLAN type | VLAN name len |
195 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
196 * | ISL vlan id | MTU size |
197 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
198 * | 802.10 index (SAID) |
199 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
200 * | VLAN name |
201 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
202 *
203 */
204
205 tptr += 4;
206 while (tptr < (pptr+length)) {
207
208 len = *tptr;
209 if (len == 0)
210 break;
211
212 if (!TTEST2(*tptr, len))
213 goto trunc;
214
215 vtp_vlan = (struct vtp_vlan_*)tptr;
216 printf("\n\tVLAN info status %s, type %s, VLAN-id %u, MTU %u, SAID 0x%08x, Name %s",
217 tok2str(vtp_vlan_status,"Unknown",vtp_vlan->status),
218 tok2str(vtp_vlan_type_values,"Unknown",vtp_vlan->type),
219 EXTRACT_16BITS(&vtp_vlan->vlanid),
220 EXTRACT_16BITS(&vtp_vlan->mtu),
221 EXTRACT_32BITS(&vtp_vlan->index),
222 (tptr + VTP_VLAN_INFO_OFFSET));
223 tptr += len;
224
225 /* FIXME: TLV dissector missing */
226
227 /* The following URL:
228 http://www.cisco.com/univercd/cc/td/doc/product/lan/trsrb/frames.htm
229 talks about type (2 bytes) and length (2 bytes), that is not true...
230 */
231 }
232 break;
233
234 case VTP_ADV_REQUEST:
235
236 /*
237 * ADVERTISEMENT REQUEST
238 *
239 * 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
240 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
241 * | Version | Code | Reserved | MmgtD Len |
242 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
243 * | Management Domain Name |
244 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
245 * | Start value |
246 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
247 *
248 */
249
250 printf("\n\tStart value: %u", EXTRACT_32BITS(tptr));
251 break;
252
253 case VTP_JOIN_MESSAGE:
254
255 /* FIXME - Could not find message format */
256 break;
257
258 default:
259 break;
260 }
261
262 return;
263
264 trunc:
265 printf("[|vtp]");
266 }
267
268 /*
269 * Local Variables:
270 * c-style: whitesmith
271 * c-basic-offset: 4
272 * End:
273 */