print-vtp.c (313537) | print-vtp.c (327234) |
---|---|
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 * Reference documentation: | 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 * Reference documentation: |
16 * http://www.cisco.com/en/US/tech/tk389/tk689/technologies_tech_note09186a0080094c52.shtml 17 * http://www.cisco.com/warp/public/473/21.html 18 * http://www.cisco.com/univercd/cc/td/doc/product/lan/trsrb/frames.htm | 16 * http://www.cisco.com/c/en/us/support/docs/lan-switching/vtp/10558-21.html 17 * http://docstore.mik.ua/univercd/cc/td/doc/product/lan/trsrb/frames.htm |
19 * 20 * Original code ode by Carles Kishimoto <carles.kishimoto@gmail.com> 21 */ 22 23/* \summary: Cisco VLAN Trunking Protocol (VTP) printer */ 24 25#ifdef HAVE_CONFIG_H 26#include "config.h" --- 4 unchanged lines hidden (view full) --- 31#include "netdissect.h" 32#include "addrtoname.h" 33#include "extract.h" 34 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 | 18 * 19 * Original code ode by Carles Kishimoto <carles.kishimoto@gmail.com> 20 */ 21 22/* \summary: Cisco VLAN Trunking Protocol (VTP) printer */ 23 24#ifdef HAVE_CONFIG_H 25#include "config.h" --- 4 unchanged lines hidden (view full) --- 30#include "netdissect.h" 31#include "addrtoname.h" 32#include "extract.h" 33 34#define VTP_HEADER_LEN 36 35#define VTP_DOMAIN_NAME_LEN 32 36#define VTP_MD5_DIGEST_LEN 16 37#define VTP_UPDATE_TIMESTAMP_LEN 12 |
39#define VTP_VLAN_INFO_OFFSET 12 | 38#define VTP_VLAN_INFO_FIXED_PART_LEN 12 /* length of VLAN info before VLAN name */ |
40 41#define VTP_SUMMARY_ADV 0x01 42#define VTP_SUBSET_ADV 0x02 43#define VTP_ADV_REQUEST 0x03 44#define VTP_JOIN_MESSAGE 0x04 45 46struct vtp_vlan_ { 47 uint8_t len; --- 170 unchanged lines hidden (view full) --- 218 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 219 * | ................ | 220 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 221 * | VLAN info field N | 222 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 223 * 224 */ 225 | 39 40#define VTP_SUMMARY_ADV 0x01 41#define VTP_SUBSET_ADV 0x02 42#define VTP_ADV_REQUEST 0x03 43#define VTP_JOIN_MESSAGE 0x04 44 45struct vtp_vlan_ { 46 uint8_t len; --- 170 unchanged lines hidden (view full) --- 217 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 218 * | ................ | 219 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 220 * | VLAN info field N | 221 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 222 * 223 */ 224 |
225 ND_TCHECK_32BITS(tptr); |
|
226 ND_PRINT((ndo, ", Config Rev %x", EXTRACT_32BITS(tptr))); 227 228 /* 229 * VLAN INFORMATION 230 * 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 231 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 232 * | V info len | Status | VLAN type | VLAN name len | 233 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ --- 4 unchanged lines hidden (view full) --- 238 * | VLAN name | 239 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 240 * 241 */ 242 243 tptr += 4; 244 while (tptr < (pptr+length)) { 245 | 226 ND_PRINT((ndo, ", Config Rev %x", EXTRACT_32BITS(tptr))); 227 228 /* 229 * VLAN INFORMATION 230 * 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 231 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 232 * | V info len | Status | VLAN type | VLAN name len | 233 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ --- 4 unchanged lines hidden (view full) --- 238 * | VLAN name | 239 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 240 * 241 */ 242 243 tptr += 4; 244 while (tptr < (pptr+length)) { 245 |
246 ND_TCHECK_8BITS(tptr); |
|
246 len = *tptr; 247 if (len == 0) 248 break; 249 250 ND_TCHECK2(*tptr, len); 251 252 vtp_vlan = (const struct vtp_vlan_*)tptr; | 247 len = *tptr; 248 if (len == 0) 249 break; 250 251 ND_TCHECK2(*tptr, len); 252 253 vtp_vlan = (const struct vtp_vlan_*)tptr; |
254 if (len < VTP_VLAN_INFO_FIXED_PART_LEN) 255 goto trunc; |
|
253 ND_TCHECK(*vtp_vlan); 254 ND_PRINT((ndo, "\n\tVLAN info status %s, type %s, VLAN-id %u, MTU %u, SAID 0x%08x, Name ", 255 tok2str(vtp_vlan_status,"Unknown",vtp_vlan->status), 256 tok2str(vtp_vlan_type_values,"Unknown",vtp_vlan->type), 257 EXTRACT_16BITS(&vtp_vlan->vlanid), 258 EXTRACT_16BITS(&vtp_vlan->mtu), 259 EXTRACT_32BITS(&vtp_vlan->index))); | 256 ND_TCHECK(*vtp_vlan); 257 ND_PRINT((ndo, "\n\tVLAN info status %s, type %s, VLAN-id %u, MTU %u, SAID 0x%08x, Name ", 258 tok2str(vtp_vlan_status,"Unknown",vtp_vlan->status), 259 tok2str(vtp_vlan_type_values,"Unknown",vtp_vlan->type), 260 EXTRACT_16BITS(&vtp_vlan->vlanid), 261 EXTRACT_16BITS(&vtp_vlan->mtu), 262 EXTRACT_32BITS(&vtp_vlan->index))); |
260 fn_printzp(ndo, tptr + VTP_VLAN_INFO_OFFSET, vtp_vlan->name_len, NULL); | 263 len -= VTP_VLAN_INFO_FIXED_PART_LEN; 264 tptr += VTP_VLAN_INFO_FIXED_PART_LEN; 265 if (len < 4*((vtp_vlan->name_len + 3)/4)) 266 goto trunc; 267 ND_TCHECK2(*tptr, vtp_vlan->name_len); 268 fn_printzp(ndo, tptr, vtp_vlan->name_len, NULL); |
261 | 269 |
262 /* 263 * Vlan names are aligned to 32-bit boundaries. 264 */ 265 len -= VTP_VLAN_INFO_OFFSET + 4*((vtp_vlan->name_len + 3)/4); 266 tptr += VTP_VLAN_INFO_OFFSET + 4*((vtp_vlan->name_len + 3)/4); | 270 /* 271 * Vlan names are aligned to 32-bit boundaries. 272 */ 273 len -= 4*((vtp_vlan->name_len + 3)/4); 274 tptr += 4*((vtp_vlan->name_len + 3)/4); |
267 268 /* TLV information follows */ 269 270 while (len > 0) { 271 272 /* | 275 276 /* TLV information follows */ 277 278 while (len > 0) { 279 280 /* |
273 * Cisco specs says 2 bytes for type + 2 bytes for length, take only 1 274 * See: http://www.cisco.com/univercd/cc/td/doc/product/lan/trsrb/frames.htm | 281 * Cisco specs say 2 bytes for type + 2 bytes for length; 282 * see http://docstore.mik.ua/univercd/cc/td/doc/product/lan/trsrb/frames.htm 283 * However, actual packets on the wire appear to use 1 284 * byte for the type and 1 byte for the length, so that's 285 * what we do. |
275 */ | 286 */ |
287 if (len < 2) 288 goto trunc; 289 ND_TCHECK2(*tptr, 2); |
|
276 type = *tptr; 277 tlv_len = *(tptr+1); 278 279 ND_PRINT((ndo, "\n\t\t%s (0x%04x) TLV", 280 tok2str(vtp_vlan_tlv_values, "Unknown", type), 281 type)); 282 | 290 type = *tptr; 291 tlv_len = *(tptr+1); 292 293 ND_PRINT((ndo, "\n\t\t%s (0x%04x) TLV", 294 tok2str(vtp_vlan_tlv_values, "Unknown", type), 295 type)); 296 |
283 /* 284 * infinite loop check 285 */ 286 if (type == 0 || tlv_len == 0) { | 297 if (len < tlv_len * 2 + 2) { 298 ND_PRINT((ndo, " (TLV goes past the end of the packet)")); |
287 return; 288 } | 299 return; 300 } |
289 | |
290 ND_TCHECK2(*tptr, tlv_len * 2 +2); 291 | 301 ND_TCHECK2(*tptr, tlv_len * 2 +2); 302 |
292 tlv_value = EXTRACT_16BITS(tptr+2); | 303 /* 304 * We assume the value is a 2-byte integer; the length is 305 * in units of 16-bit words. 306 */ 307 if (tlv_len != 1) { 308 ND_PRINT((ndo, " (invalid TLV length %u != 1)", tlv_len)); 309 return; 310 } else { 311 tlv_value = EXTRACT_16BITS(tptr+2); |
293 | 312 |
294 switch (type) { 295 case VTP_VLAN_STE_HOP_COUNT: 296 ND_PRINT((ndo, ", %u", tlv_value)); 297 break; | 313 switch (type) { 314 case VTP_VLAN_STE_HOP_COUNT: 315 ND_PRINT((ndo, ", %u", tlv_value)); 316 break; |
298 | 317 |
299 case VTP_VLAN_PRUNING: 300 ND_PRINT((ndo, ", %s (%u)", 301 tlv_value == 1 ? "Enabled" : "Disabled", 302 tlv_value)); 303 break; | 318 case VTP_VLAN_PRUNING: 319 ND_PRINT((ndo, ", %s (%u)", 320 tlv_value == 1 ? "Enabled" : "Disabled", 321 tlv_value)); 322 break; |
304 | 323 |
305 case VTP_VLAN_STP_TYPE: 306 ND_PRINT((ndo, ", %s (%u)", 307 tok2str(vtp_stp_type_values, "Unknown", tlv_value), 308 tlv_value)); 309 break; | 324 case VTP_VLAN_STP_TYPE: 325 ND_PRINT((ndo, ", %s (%u)", 326 tok2str(vtp_stp_type_values, "Unknown", tlv_value), 327 tlv_value)); 328 break; |
310 | 329 |
311 case VTP_VLAN_BRIDGE_TYPE: 312 ND_PRINT((ndo, ", %s (%u)", 313 tlv_value == 1 ? "SRB" : "SRT", 314 tlv_value)); 315 break; | 330 case VTP_VLAN_BRIDGE_TYPE: 331 ND_PRINT((ndo, ", %s (%u)", 332 tlv_value == 1 ? "SRB" : "SRT", 333 tlv_value)); 334 break; |
316 | 335 |
317 case VTP_VLAN_BACKUP_CRF_MODE: 318 ND_PRINT((ndo, ", %s (%u)", 319 tlv_value == 1 ? "Backup" : "Not backup", 320 tlv_value)); 321 break; | 336 case VTP_VLAN_BACKUP_CRF_MODE: 337 ND_PRINT((ndo, ", %s (%u)", 338 tlv_value == 1 ? "Backup" : "Not backup", 339 tlv_value)); 340 break; |
322 | 341 |
323 /* 324 * FIXME those are the defined TLVs that lack a decoder 325 * you are welcome to contribute code ;-) 326 */ | 342 /* 343 * FIXME those are the defined TLVs that lack a decoder 344 * you are welcome to contribute code ;-) 345 */ |
327 | 346 |
328 case VTP_VLAN_SOURCE_ROUTING_RING_NUMBER: 329 case VTP_VLAN_SOURCE_ROUTING_BRIDGE_NUMBER: 330 case VTP_VLAN_PARENT_VLAN: 331 case VTP_VLAN_TRANS_BRIDGED_VLAN: 332 case VTP_VLAN_ARP_HOP_COUNT: 333 default: 334 print_unknown_data(ndo, tptr, "\n\t\t ", 2 + tlv_len*2); 335 break; | 347 case VTP_VLAN_SOURCE_ROUTING_RING_NUMBER: 348 case VTP_VLAN_SOURCE_ROUTING_BRIDGE_NUMBER: 349 case VTP_VLAN_PARENT_VLAN: 350 case VTP_VLAN_TRANS_BRIDGED_VLAN: 351 case VTP_VLAN_ARP_HOP_COUNT: 352 default: 353 print_unknown_data(ndo, tptr, "\n\t\t ", 2 + tlv_len*2); 354 break; 355 } |
336 } 337 len -= 2 + tlv_len*2; 338 tptr += 2 + tlv_len*2; 339 } 340 } 341 break; 342 343 case VTP_ADV_REQUEST: --- 40 unchanged lines hidden --- | 356 } 357 len -= 2 + tlv_len*2; 358 tptr += 2 + tlv_len*2; 359 } 360 } 361 break; 362 363 case VTP_ADV_REQUEST: --- 40 unchanged lines hidden --- |