1a5779b6eSRui Paulo /* 2a5779b6eSRui Paulo * Copyright (c) 1998-2006 The TCPDUMP project 3a5779b6eSRui Paulo * 4a5779b6eSRui Paulo * Redistribution and use in source and binary forms, with or without 5a5779b6eSRui Paulo * modification, are permitted provided that: (1) source code 6a5779b6eSRui Paulo * distributions retain the above copyright notice and this paragraph 7a5779b6eSRui Paulo * in its entirety, and (2) distributions including binary code include 8a5779b6eSRui Paulo * the above copyright notice and this paragraph in its entirety in 9a5779b6eSRui Paulo * the documentation or other materials provided with the distribution. 10a5779b6eSRui Paulo * THIS SOFTWARE IS PROVIDED ``AS IS'' AND 11a5779b6eSRui Paulo * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT 12a5779b6eSRui Paulo * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 13a5779b6eSRui Paulo * FOR A PARTICULAR PURPOSE. 14a5779b6eSRui Paulo * 15a5779b6eSRui Paulo * support for the Cisco prop. VQP Protocol 16a5779b6eSRui Paulo * 17a5779b6eSRui Paulo * Original code by Carles Kishimoto <Carles.Kishimoto@bsc.es> 18a5779b6eSRui Paulo */ 19a5779b6eSRui Paulo 20a5779b6eSRui Paulo #ifndef lint 21a5779b6eSRui Paulo static const char rcsid[] _U_ = 22a5779b6eSRui Paulo "@(#) $Header: /tcpdump/master/tcpdump/print-vqp.c,v 1.3 2006-08-19 06:51:13 guy Exp $"; 23a5779b6eSRui Paulo #endif 24a5779b6eSRui Paulo 25a5779b6eSRui Paulo #ifdef HAVE_CONFIG_H 26a5779b6eSRui Paulo #include "config.h" 27a5779b6eSRui Paulo #endif 28a5779b6eSRui Paulo 29a5779b6eSRui Paulo #include <tcpdump-stdinc.h> 30a5779b6eSRui Paulo 31a5779b6eSRui Paulo #include <stdio.h> 32a5779b6eSRui Paulo #include <stdlib.h> 33a5779b6eSRui Paulo #include <string.h> 34a5779b6eSRui Paulo 35a5779b6eSRui Paulo #include "interface.h" 36a5779b6eSRui Paulo #include "extract.h" 37a5779b6eSRui Paulo #include "addrtoname.h" 38a5779b6eSRui Paulo 39a5779b6eSRui Paulo #define VQP_VERSION 1 40a5779b6eSRui Paulo #define VQP_EXTRACT_VERSION(x) ((x)&0xFF) 41a5779b6eSRui Paulo 42a5779b6eSRui Paulo /* 43a5779b6eSRui Paulo * VQP common header 44a5779b6eSRui Paulo * 45a5779b6eSRui Paulo * 0 1 2 3 46a5779b6eSRui Paulo * 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 47a5779b6eSRui Paulo * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 48a5779b6eSRui Paulo * | Constant | Packet type | Error Code | nitems | 49a5779b6eSRui Paulo * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 50a5779b6eSRui Paulo * | Packet Sequence Number (4 bytes) | 51a5779b6eSRui Paulo * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 52a5779b6eSRui Paulo */ 53a5779b6eSRui Paulo 54a5779b6eSRui Paulo struct vqp_common_header_t { 55a5779b6eSRui Paulo u_int8_t version; 56a5779b6eSRui Paulo u_int8_t msg_type; 57a5779b6eSRui Paulo u_int8_t error_code; 58a5779b6eSRui Paulo u_int8_t nitems; 59a5779b6eSRui Paulo u_int8_t sequence[4]; 60a5779b6eSRui Paulo }; 61a5779b6eSRui Paulo 62a5779b6eSRui Paulo struct vqp_obj_tlv_t { 63a5779b6eSRui Paulo u_int8_t obj_type[4]; 64a5779b6eSRui Paulo u_int8_t obj_length[2]; 65a5779b6eSRui Paulo }; 66a5779b6eSRui Paulo 67a5779b6eSRui Paulo #define VQP_OBJ_REQ_JOIN_PORT 0x01 68a5779b6eSRui Paulo #define VQP_OBJ_RESP_VLAN 0x02 69a5779b6eSRui Paulo #define VQP_OBJ_REQ_RECONFIRM 0x03 70a5779b6eSRui Paulo #define VQP_OBJ_RESP_RECONFIRM 0x04 71a5779b6eSRui Paulo 72a5779b6eSRui Paulo static const struct tok vqp_msg_type_values[] = { 73a5779b6eSRui Paulo { VQP_OBJ_REQ_JOIN_PORT, "Request, Join Port"}, 74a5779b6eSRui Paulo { VQP_OBJ_RESP_VLAN, "Response, VLAN"}, 75a5779b6eSRui Paulo { VQP_OBJ_REQ_RECONFIRM, "Request, Reconfirm"}, 76a5779b6eSRui Paulo { VQP_OBJ_RESP_RECONFIRM, "Response, Reconfirm"}, 77a5779b6eSRui Paulo { 0, NULL} 78a5779b6eSRui Paulo }; 79a5779b6eSRui Paulo 80a5779b6eSRui Paulo static const struct tok vqp_error_code_values[] = { 81a5779b6eSRui Paulo { 0x00, "No error"}, 82a5779b6eSRui Paulo { 0x03, "Access denied"}, 83a5779b6eSRui Paulo { 0x04, "Shutdown port"}, 84a5779b6eSRui Paulo { 0x05, "Wrong VTP domain"}, 85a5779b6eSRui Paulo { 0, NULL} 86a5779b6eSRui Paulo }; 87a5779b6eSRui Paulo 88a5779b6eSRui Paulo /* FIXME the heading 0x0c looks ugly - those must be flags etc. */ 89a5779b6eSRui Paulo #define VQP_OBJ_IP_ADDRESS 0x0c01 90a5779b6eSRui Paulo #define VQP_OBJ_PORT_NAME 0x0c02 91a5779b6eSRui Paulo #define VQP_OBJ_VLAN_NAME 0x0c03 92a5779b6eSRui Paulo #define VQP_OBJ_VTP_DOMAIN 0x0c04 93a5779b6eSRui Paulo #define VQP_OBJ_ETHERNET_PKT 0x0c05 94a5779b6eSRui Paulo #define VQP_OBJ_MAC_NULL 0x0c06 95a5779b6eSRui Paulo #define VQP_OBJ_MAC_ADDRESS 0x0c08 96a5779b6eSRui Paulo 97a5779b6eSRui Paulo static const struct tok vqp_obj_values[] = { 98a5779b6eSRui Paulo { VQP_OBJ_IP_ADDRESS, "Client IP Address" }, 99a5779b6eSRui Paulo { VQP_OBJ_PORT_NAME, "Port Name" }, 100a5779b6eSRui Paulo { VQP_OBJ_VLAN_NAME, "VLAN Name" }, 101a5779b6eSRui Paulo { VQP_OBJ_VTP_DOMAIN, "VTP Domain" }, 102a5779b6eSRui Paulo { VQP_OBJ_ETHERNET_PKT, "Ethernet Packet" }, 103a5779b6eSRui Paulo { VQP_OBJ_MAC_NULL, "MAC Null" }, 104a5779b6eSRui Paulo { VQP_OBJ_MAC_ADDRESS, "MAC Address" }, 105a5779b6eSRui Paulo { 0, NULL} 106a5779b6eSRui Paulo }; 107a5779b6eSRui Paulo 108a5779b6eSRui Paulo void 109a5779b6eSRui Paulo vqp_print(register const u_char *pptr, register u_int len) 110a5779b6eSRui Paulo { 111a5779b6eSRui Paulo const struct vqp_common_header_t *vqp_common_header; 112a5779b6eSRui Paulo const struct vqp_obj_tlv_t *vqp_obj_tlv; 113a5779b6eSRui Paulo 114a5779b6eSRui Paulo const u_char *tptr; 115a5779b6eSRui Paulo u_int16_t vqp_obj_len; 116a5779b6eSRui Paulo u_int32_t vqp_obj_type; 117a5779b6eSRui Paulo int tlen; 118a5779b6eSRui Paulo u_int8_t nitems; 119a5779b6eSRui Paulo 120a5779b6eSRui Paulo tptr=pptr; 121a5779b6eSRui Paulo tlen = len; 122a5779b6eSRui Paulo vqp_common_header = (const struct vqp_common_header_t *)pptr; 123a5779b6eSRui Paulo TCHECK(*vqp_common_header); 124a5779b6eSRui Paulo 125a5779b6eSRui Paulo /* 126a5779b6eSRui Paulo * Sanity checking of the header. 127a5779b6eSRui Paulo */ 128a5779b6eSRui Paulo if (VQP_EXTRACT_VERSION(vqp_common_header->version) != VQP_VERSION) { 129a5779b6eSRui Paulo printf("VQP version %u packet not supported", 130a5779b6eSRui Paulo VQP_EXTRACT_VERSION(vqp_common_header->version)); 131a5779b6eSRui Paulo return; 132a5779b6eSRui Paulo } 133a5779b6eSRui Paulo 134a5779b6eSRui Paulo /* in non-verbose mode just lets print the basic Message Type */ 135a5779b6eSRui Paulo if (vflag < 1) { 136a5779b6eSRui Paulo printf("VQPv%u %s Message, error-code %s (%u), length %u", 137a5779b6eSRui Paulo VQP_EXTRACT_VERSION(vqp_common_header->version), 138a5779b6eSRui Paulo tok2str(vqp_msg_type_values, "unknown (%u)",vqp_common_header->msg_type), 139a5779b6eSRui Paulo tok2str(vqp_error_code_values, "unknown (%u)",vqp_common_header->error_code), 140a5779b6eSRui Paulo vqp_common_header->error_code, 141a5779b6eSRui Paulo len); 142a5779b6eSRui Paulo return; 143a5779b6eSRui Paulo } 144a5779b6eSRui Paulo 145a5779b6eSRui Paulo /* ok they seem to want to know everything - lets fully decode it */ 146a5779b6eSRui Paulo nitems = vqp_common_header->nitems; 147a5779b6eSRui Paulo printf("\n\tVQPv%u, %s Message, error-code %s (%u), seq 0x%08x, items %u, length %u", 148a5779b6eSRui Paulo VQP_EXTRACT_VERSION(vqp_common_header->version), 149a5779b6eSRui Paulo tok2str(vqp_msg_type_values, "unknown (%u)",vqp_common_header->msg_type), 150a5779b6eSRui Paulo tok2str(vqp_error_code_values, "unknown (%u)",vqp_common_header->error_code), 151a5779b6eSRui Paulo vqp_common_header->error_code, 152a5779b6eSRui Paulo EXTRACT_32BITS(&vqp_common_header->sequence), 153a5779b6eSRui Paulo nitems, 154a5779b6eSRui Paulo len); 155a5779b6eSRui Paulo 156a5779b6eSRui Paulo /* skip VQP Common header */ 157a5779b6eSRui Paulo tptr+=sizeof(const struct vqp_common_header_t); 158a5779b6eSRui Paulo tlen-=sizeof(const struct vqp_common_header_t); 159a5779b6eSRui Paulo 160a5779b6eSRui Paulo while (nitems > 0 && tlen > 0) { 161a5779b6eSRui Paulo 162a5779b6eSRui Paulo vqp_obj_tlv = (const struct vqp_obj_tlv_t *)tptr; 163a5779b6eSRui Paulo vqp_obj_type = EXTRACT_32BITS(vqp_obj_tlv->obj_type); 164a5779b6eSRui Paulo vqp_obj_len = EXTRACT_16BITS(vqp_obj_tlv->obj_length); 165a5779b6eSRui Paulo tptr+=sizeof(struct vqp_obj_tlv_t); 166a5779b6eSRui Paulo tlen-=sizeof(struct vqp_obj_tlv_t); 167a5779b6eSRui Paulo 168a5779b6eSRui Paulo printf("\n\t %s Object (0x%08x), length %u, value: ", 169a5779b6eSRui Paulo tok2str(vqp_obj_values, "Unknown", vqp_obj_type), 170a5779b6eSRui Paulo vqp_obj_type, vqp_obj_len); 171a5779b6eSRui Paulo 172a5779b6eSRui Paulo /* basic sanity check */ 173a5779b6eSRui Paulo if (vqp_obj_type == 0 || vqp_obj_len ==0) { 174a5779b6eSRui Paulo return; 175a5779b6eSRui Paulo } 176a5779b6eSRui Paulo 177a5779b6eSRui Paulo /* did we capture enough for fully decoding the object ? */ 178a5779b6eSRui Paulo if (!TTEST2(*tptr, vqp_obj_len)) 179a5779b6eSRui Paulo goto trunc; 180a5779b6eSRui Paulo 181a5779b6eSRui Paulo switch(vqp_obj_type) { 182a5779b6eSRui Paulo case VQP_OBJ_IP_ADDRESS: 183a5779b6eSRui Paulo printf("%s (0x%08x)", ipaddr_string(tptr), EXTRACT_32BITS(tptr)); 184a5779b6eSRui Paulo break; 185a5779b6eSRui Paulo /* those objects have similar semantics - fall through */ 186a5779b6eSRui Paulo case VQP_OBJ_PORT_NAME: 187a5779b6eSRui Paulo case VQP_OBJ_VLAN_NAME: 188a5779b6eSRui Paulo case VQP_OBJ_VTP_DOMAIN: 189a5779b6eSRui Paulo case VQP_OBJ_ETHERNET_PKT: 190a5779b6eSRui Paulo safeputs((const char *)tptr, vqp_obj_len); 191a5779b6eSRui Paulo break; 192a5779b6eSRui Paulo /* those objects have similar semantics - fall through */ 193a5779b6eSRui Paulo case VQP_OBJ_MAC_ADDRESS: 194a5779b6eSRui Paulo case VQP_OBJ_MAC_NULL: 195a5779b6eSRui Paulo printf("%s", etheraddr_string(tptr)); 196a5779b6eSRui Paulo break; 197a5779b6eSRui Paulo default: 198a5779b6eSRui Paulo if (vflag <= 1) 199a5779b6eSRui Paulo print_unknown_data(tptr, "\n\t ", vqp_obj_len); 200a5779b6eSRui Paulo break; 201a5779b6eSRui Paulo } 202a5779b6eSRui Paulo tptr += vqp_obj_len; 203a5779b6eSRui Paulo tlen -= vqp_obj_len; 204a5779b6eSRui Paulo nitems--; 205a5779b6eSRui Paulo } 206a5779b6eSRui Paulo return; 207a5779b6eSRui Paulo trunc: 208a5779b6eSRui Paulo printf("\n\t[|VQP]"); 209a5779b6eSRui Paulo } 210