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 20*3c602fabSXin LI #define NETDISSECT_REWORKED 21a5779b6eSRui Paulo #ifdef HAVE_CONFIG_H 22a5779b6eSRui Paulo #include "config.h" 23a5779b6eSRui Paulo #endif 24a5779b6eSRui Paulo 25a5779b6eSRui Paulo #include <tcpdump-stdinc.h> 26a5779b6eSRui Paulo 27a5779b6eSRui Paulo #include "interface.h" 28a5779b6eSRui Paulo #include "extract.h" 29a5779b6eSRui Paulo #include "addrtoname.h" 30a5779b6eSRui Paulo 31a5779b6eSRui Paulo #define VQP_VERSION 1 32a5779b6eSRui Paulo #define VQP_EXTRACT_VERSION(x) ((x)&0xFF) 33a5779b6eSRui Paulo 34a5779b6eSRui Paulo /* 35a5779b6eSRui Paulo * VQP common header 36a5779b6eSRui Paulo * 37a5779b6eSRui Paulo * 0 1 2 3 38a5779b6eSRui 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 39a5779b6eSRui Paulo * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 40a5779b6eSRui Paulo * | Constant | Packet type | Error Code | nitems | 41a5779b6eSRui Paulo * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 42a5779b6eSRui Paulo * | Packet Sequence Number (4 bytes) | 43a5779b6eSRui Paulo * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 44a5779b6eSRui Paulo */ 45a5779b6eSRui Paulo 46a5779b6eSRui Paulo struct vqp_common_header_t { 47*3c602fabSXin LI uint8_t version; 48*3c602fabSXin LI uint8_t msg_type; 49*3c602fabSXin LI uint8_t error_code; 50*3c602fabSXin LI uint8_t nitems; 51*3c602fabSXin LI uint8_t sequence[4]; 52a5779b6eSRui Paulo }; 53a5779b6eSRui Paulo 54a5779b6eSRui Paulo struct vqp_obj_tlv_t { 55*3c602fabSXin LI uint8_t obj_type[4]; 56*3c602fabSXin LI uint8_t obj_length[2]; 57a5779b6eSRui Paulo }; 58a5779b6eSRui Paulo 59a5779b6eSRui Paulo #define VQP_OBJ_REQ_JOIN_PORT 0x01 60a5779b6eSRui Paulo #define VQP_OBJ_RESP_VLAN 0x02 61a5779b6eSRui Paulo #define VQP_OBJ_REQ_RECONFIRM 0x03 62a5779b6eSRui Paulo #define VQP_OBJ_RESP_RECONFIRM 0x04 63a5779b6eSRui Paulo 64a5779b6eSRui Paulo static const struct tok vqp_msg_type_values[] = { 65a5779b6eSRui Paulo { VQP_OBJ_REQ_JOIN_PORT, "Request, Join Port"}, 66a5779b6eSRui Paulo { VQP_OBJ_RESP_VLAN, "Response, VLAN"}, 67a5779b6eSRui Paulo { VQP_OBJ_REQ_RECONFIRM, "Request, Reconfirm"}, 68a5779b6eSRui Paulo { VQP_OBJ_RESP_RECONFIRM, "Response, Reconfirm"}, 69a5779b6eSRui Paulo { 0, NULL} 70a5779b6eSRui Paulo }; 71a5779b6eSRui Paulo 72a5779b6eSRui Paulo static const struct tok vqp_error_code_values[] = { 73a5779b6eSRui Paulo { 0x00, "No error"}, 74a5779b6eSRui Paulo { 0x03, "Access denied"}, 75a5779b6eSRui Paulo { 0x04, "Shutdown port"}, 76a5779b6eSRui Paulo { 0x05, "Wrong VTP domain"}, 77a5779b6eSRui Paulo { 0, NULL} 78a5779b6eSRui Paulo }; 79a5779b6eSRui Paulo 80a5779b6eSRui Paulo /* FIXME the heading 0x0c looks ugly - those must be flags etc. */ 81a5779b6eSRui Paulo #define VQP_OBJ_IP_ADDRESS 0x0c01 82a5779b6eSRui Paulo #define VQP_OBJ_PORT_NAME 0x0c02 83a5779b6eSRui Paulo #define VQP_OBJ_VLAN_NAME 0x0c03 84a5779b6eSRui Paulo #define VQP_OBJ_VTP_DOMAIN 0x0c04 85a5779b6eSRui Paulo #define VQP_OBJ_ETHERNET_PKT 0x0c05 86a5779b6eSRui Paulo #define VQP_OBJ_MAC_NULL 0x0c06 87a5779b6eSRui Paulo #define VQP_OBJ_MAC_ADDRESS 0x0c08 88a5779b6eSRui Paulo 89a5779b6eSRui Paulo static const struct tok vqp_obj_values[] = { 90a5779b6eSRui Paulo { VQP_OBJ_IP_ADDRESS, "Client IP Address" }, 91a5779b6eSRui Paulo { VQP_OBJ_PORT_NAME, "Port Name" }, 92a5779b6eSRui Paulo { VQP_OBJ_VLAN_NAME, "VLAN Name" }, 93a5779b6eSRui Paulo { VQP_OBJ_VTP_DOMAIN, "VTP Domain" }, 94a5779b6eSRui Paulo { VQP_OBJ_ETHERNET_PKT, "Ethernet Packet" }, 95a5779b6eSRui Paulo { VQP_OBJ_MAC_NULL, "MAC Null" }, 96a5779b6eSRui Paulo { VQP_OBJ_MAC_ADDRESS, "MAC Address" }, 97a5779b6eSRui Paulo { 0, NULL} 98a5779b6eSRui Paulo }; 99a5779b6eSRui Paulo 100a5779b6eSRui Paulo void 101*3c602fabSXin LI vqp_print(netdissect_options *ndo, register const u_char *pptr, register u_int len) 102a5779b6eSRui Paulo { 103a5779b6eSRui Paulo const struct vqp_common_header_t *vqp_common_header; 104a5779b6eSRui Paulo const struct vqp_obj_tlv_t *vqp_obj_tlv; 105a5779b6eSRui Paulo 106a5779b6eSRui Paulo const u_char *tptr; 107*3c602fabSXin LI uint16_t vqp_obj_len; 108*3c602fabSXin LI uint32_t vqp_obj_type; 109a5779b6eSRui Paulo int tlen; 110*3c602fabSXin LI uint8_t nitems; 111a5779b6eSRui Paulo 112a5779b6eSRui Paulo tptr=pptr; 113a5779b6eSRui Paulo tlen = len; 114a5779b6eSRui Paulo vqp_common_header = (const struct vqp_common_header_t *)pptr; 115*3c602fabSXin LI ND_TCHECK(*vqp_common_header); 116a5779b6eSRui Paulo 117a5779b6eSRui Paulo /* 118a5779b6eSRui Paulo * Sanity checking of the header. 119a5779b6eSRui Paulo */ 120a5779b6eSRui Paulo if (VQP_EXTRACT_VERSION(vqp_common_header->version) != VQP_VERSION) { 121*3c602fabSXin LI ND_PRINT((ndo, "VQP version %u packet not supported", 122*3c602fabSXin LI VQP_EXTRACT_VERSION(vqp_common_header->version))); 123a5779b6eSRui Paulo return; 124a5779b6eSRui Paulo } 125a5779b6eSRui Paulo 126a5779b6eSRui Paulo /* in non-verbose mode just lets print the basic Message Type */ 127*3c602fabSXin LI if (ndo->ndo_vflag < 1) { 128*3c602fabSXin LI ND_PRINT((ndo, "VQPv%u %s Message, error-code %s (%u), length %u", 129a5779b6eSRui Paulo VQP_EXTRACT_VERSION(vqp_common_header->version), 130a5779b6eSRui Paulo tok2str(vqp_msg_type_values, "unknown (%u)",vqp_common_header->msg_type), 131a5779b6eSRui Paulo tok2str(vqp_error_code_values, "unknown (%u)",vqp_common_header->error_code), 132a5779b6eSRui Paulo vqp_common_header->error_code, 133*3c602fabSXin LI len)); 134a5779b6eSRui Paulo return; 135a5779b6eSRui Paulo } 136a5779b6eSRui Paulo 137a5779b6eSRui Paulo /* ok they seem to want to know everything - lets fully decode it */ 138a5779b6eSRui Paulo nitems = vqp_common_header->nitems; 139*3c602fabSXin LI ND_PRINT((ndo, "\n\tVQPv%u, %s Message, error-code %s (%u), seq 0x%08x, items %u, length %u", 140a5779b6eSRui Paulo VQP_EXTRACT_VERSION(vqp_common_header->version), 141a5779b6eSRui Paulo tok2str(vqp_msg_type_values, "unknown (%u)",vqp_common_header->msg_type), 142a5779b6eSRui Paulo tok2str(vqp_error_code_values, "unknown (%u)",vqp_common_header->error_code), 143a5779b6eSRui Paulo vqp_common_header->error_code, 144a5779b6eSRui Paulo EXTRACT_32BITS(&vqp_common_header->sequence), 145a5779b6eSRui Paulo nitems, 146*3c602fabSXin LI len)); 147a5779b6eSRui Paulo 148a5779b6eSRui Paulo /* skip VQP Common header */ 149a5779b6eSRui Paulo tptr+=sizeof(const struct vqp_common_header_t); 150a5779b6eSRui Paulo tlen-=sizeof(const struct vqp_common_header_t); 151a5779b6eSRui Paulo 152a5779b6eSRui Paulo while (nitems > 0 && tlen > 0) { 153a5779b6eSRui Paulo 154a5779b6eSRui Paulo vqp_obj_tlv = (const struct vqp_obj_tlv_t *)tptr; 155a5779b6eSRui Paulo vqp_obj_type = EXTRACT_32BITS(vqp_obj_tlv->obj_type); 156a5779b6eSRui Paulo vqp_obj_len = EXTRACT_16BITS(vqp_obj_tlv->obj_length); 157a5779b6eSRui Paulo tptr+=sizeof(struct vqp_obj_tlv_t); 158a5779b6eSRui Paulo tlen-=sizeof(struct vqp_obj_tlv_t); 159a5779b6eSRui Paulo 160*3c602fabSXin LI ND_PRINT((ndo, "\n\t %s Object (0x%08x), length %u, value: ", 161a5779b6eSRui Paulo tok2str(vqp_obj_values, "Unknown", vqp_obj_type), 162*3c602fabSXin LI vqp_obj_type, vqp_obj_len)); 163a5779b6eSRui Paulo 164a5779b6eSRui Paulo /* basic sanity check */ 165a5779b6eSRui Paulo if (vqp_obj_type == 0 || vqp_obj_len ==0) { 166a5779b6eSRui Paulo return; 167a5779b6eSRui Paulo } 168a5779b6eSRui Paulo 169a5779b6eSRui Paulo /* did we capture enough for fully decoding the object ? */ 170*3c602fabSXin LI ND_TCHECK2(*tptr, vqp_obj_len); 171a5779b6eSRui Paulo 172a5779b6eSRui Paulo switch(vqp_obj_type) { 173a5779b6eSRui Paulo case VQP_OBJ_IP_ADDRESS: 174*3c602fabSXin LI ND_PRINT((ndo, "%s (0x%08x)", ipaddr_string(ndo, tptr), EXTRACT_32BITS(tptr))); 175a5779b6eSRui Paulo break; 176a5779b6eSRui Paulo /* those objects have similar semantics - fall through */ 177a5779b6eSRui Paulo case VQP_OBJ_PORT_NAME: 178a5779b6eSRui Paulo case VQP_OBJ_VLAN_NAME: 179a5779b6eSRui Paulo case VQP_OBJ_VTP_DOMAIN: 180a5779b6eSRui Paulo case VQP_OBJ_ETHERNET_PKT: 181*3c602fabSXin LI safeputs(ndo, tptr, vqp_obj_len); 182a5779b6eSRui Paulo break; 183a5779b6eSRui Paulo /* those objects have similar semantics - fall through */ 184a5779b6eSRui Paulo case VQP_OBJ_MAC_ADDRESS: 185a5779b6eSRui Paulo case VQP_OBJ_MAC_NULL: 186*3c602fabSXin LI ND_PRINT((ndo, "%s", etheraddr_string(ndo, tptr))); 187a5779b6eSRui Paulo break; 188a5779b6eSRui Paulo default: 189*3c602fabSXin LI if (ndo->ndo_vflag <= 1) 190*3c602fabSXin LI print_unknown_data(ndo,tptr, "\n\t ", vqp_obj_len); 191a5779b6eSRui Paulo break; 192a5779b6eSRui Paulo } 193a5779b6eSRui Paulo tptr += vqp_obj_len; 194a5779b6eSRui Paulo tlen -= vqp_obj_len; 195a5779b6eSRui Paulo nitems--; 196a5779b6eSRui Paulo } 197a5779b6eSRui Paulo return; 198a5779b6eSRui Paulo trunc: 199*3c602fabSXin LI ND_PRINT((ndo, "\n\t[|VQP]")); 200a5779b6eSRui Paulo } 201