2006-03-04 06:31:16 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1998-2006 The TCPDUMP project
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that: (1) source code
|
|
|
|
* distributions retain the above copyright notice and this paragraph
|
|
|
|
* in its entirety, and (2) distributions including binary code include
|
|
|
|
* the above copyright notice and this paragraph in its entirety in
|
|
|
|
* the documentation or other materials provided with the distribution.
|
|
|
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND
|
|
|
|
* WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
|
|
|
|
* LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE.
|
|
|
|
*
|
|
|
|
* Original code by Carles Kishimoto <Carles.Kishimoto@bsc.es>
|
|
|
|
*/
|
|
|
|
|
2016-08-15 21:27:28 +08:00
|
|
|
/* \summary: Cisco VLAN Query Protocol (VQP) printer */
|
|
|
|
|
2006-03-04 06:31:16 +08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2015-09-10 04:42:38 +08:00
|
|
|
#include <netdissect-stdinc.h>
|
2006-03-04 06:31:16 +08:00
|
|
|
|
2015-09-06 05:35:58 +08:00
|
|
|
#include "netdissect.h"
|
2006-03-04 06:31:16 +08:00
|
|
|
#include "extract.h"
|
|
|
|
#include "addrtoname.h"
|
|
|
|
|
|
|
|
#define VQP_VERSION 1
|
|
|
|
|
|
|
|
/*
|
|
|
|
* VQP common header
|
|
|
|
*
|
|
|
|
* 0 1 2 3
|
|
|
|
* 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
|
|
|
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
* | Constant | Packet type | Error Code | nitems |
|
|
|
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
* | Packet Sequence Number (4 bytes) |
|
|
|
|
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct vqp_common_header_t {
|
2017-12-31 10:44:32 +08:00
|
|
|
nd_uint8_t version;
|
|
|
|
nd_uint8_t msg_type;
|
|
|
|
nd_uint8_t error_code;
|
|
|
|
nd_uint8_t nitems;
|
|
|
|
nd_uint32_t sequence;
|
2006-03-04 06:31:16 +08:00
|
|
|
};
|
|
|
|
|
2006-03-08 22:30:12 +08:00
|
|
|
struct vqp_obj_tlv_t {
|
2017-12-31 10:44:32 +08:00
|
|
|
nd_uint32_t obj_type;
|
|
|
|
nd_uint16_t obj_length;
|
2006-03-04 06:31:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#define VQP_OBJ_REQ_JOIN_PORT 0x01
|
|
|
|
#define VQP_OBJ_RESP_VLAN 0x02
|
|
|
|
#define VQP_OBJ_REQ_RECONFIRM 0x03
|
|
|
|
#define VQP_OBJ_RESP_RECONFIRM 0x04
|
|
|
|
|
|
|
|
static const struct tok vqp_msg_type_values[] = {
|
|
|
|
{ VQP_OBJ_REQ_JOIN_PORT, "Request, Join Port"},
|
|
|
|
{ VQP_OBJ_RESP_VLAN, "Response, VLAN"},
|
|
|
|
{ VQP_OBJ_REQ_RECONFIRM, "Request, Reconfirm"},
|
|
|
|
{ VQP_OBJ_RESP_RECONFIRM, "Response, Reconfirm"},
|
|
|
|
{ 0, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct tok vqp_error_code_values[] = {
|
|
|
|
{ 0x00, "No error"},
|
|
|
|
{ 0x03, "Access denied"},
|
|
|
|
{ 0x04, "Shutdown port"},
|
|
|
|
{ 0x05, "Wrong VTP domain"},
|
|
|
|
{ 0, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* FIXME the heading 0x0c looks ugly - those must be flags etc. */
|
|
|
|
#define VQP_OBJ_IP_ADDRESS 0x0c01
|
|
|
|
#define VQP_OBJ_PORT_NAME 0x0c02
|
|
|
|
#define VQP_OBJ_VLAN_NAME 0x0c03
|
|
|
|
#define VQP_OBJ_VTP_DOMAIN 0x0c04
|
|
|
|
#define VQP_OBJ_ETHERNET_PKT 0x0c05
|
|
|
|
#define VQP_OBJ_MAC_NULL 0x0c06
|
|
|
|
#define VQP_OBJ_MAC_ADDRESS 0x0c08
|
|
|
|
|
|
|
|
static const struct tok vqp_obj_values[] = {
|
|
|
|
{ VQP_OBJ_IP_ADDRESS, "Client IP Address" },
|
|
|
|
{ VQP_OBJ_PORT_NAME, "Port Name" },
|
|
|
|
{ VQP_OBJ_VLAN_NAME, "VLAN Name" },
|
|
|
|
{ VQP_OBJ_VTP_DOMAIN, "VTP Domain" },
|
|
|
|
{ VQP_OBJ_ETHERNET_PKT, "Ethernet Packet" },
|
|
|
|
{ VQP_OBJ_MAC_NULL, "MAC Null" },
|
|
|
|
{ VQP_OBJ_MAC_ADDRESS, "MAC Address" },
|
|
|
|
{ 0, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
2017-12-14 02:17:47 +08:00
|
|
|
vqp_print(netdissect_options *ndo, const u_char *pptr, u_int len)
|
2006-03-04 06:31:16 +08:00
|
|
|
{
|
|
|
|
const struct vqp_common_header_t *vqp_common_header;
|
2006-03-08 22:30:12 +08:00
|
|
|
const struct vqp_obj_tlv_t *vqp_obj_tlv;
|
2006-03-04 06:31:16 +08:00
|
|
|
|
|
|
|
const u_char *tptr;
|
2017-12-31 10:44:32 +08:00
|
|
|
uint8_t version;
|
2014-04-23 15:20:40 +08:00
|
|
|
uint16_t vqp_obj_len;
|
|
|
|
uint32_t vqp_obj_type;
|
2017-07-30 06:21:00 +08:00
|
|
|
u_int tlen;
|
2014-04-23 15:20:40 +08:00
|
|
|
uint8_t nitems;
|
2006-03-04 06:31:16 +08:00
|
|
|
|
|
|
|
tptr=pptr;
|
|
|
|
tlen = len;
|
|
|
|
vqp_common_header = (const struct vqp_common_header_t *)pptr;
|
2014-03-14 20:10:54 +08:00
|
|
|
ND_TCHECK(*vqp_common_header);
|
2017-07-30 06:21:00 +08:00
|
|
|
if (sizeof(struct vqp_common_header_t) > tlen)
|
|
|
|
goto trunc;
|
2017-12-31 10:44:32 +08:00
|
|
|
version = EXTRACT_U_1(vqp_common_header->version);
|
2006-03-04 06:31:16 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Sanity checking of the header.
|
|
|
|
*/
|
2017-12-31 10:44:32 +08:00
|
|
|
if (version != VQP_VERSION) {
|
2014-03-14 20:10:54 +08:00
|
|
|
ND_PRINT((ndo, "VQP version %u packet not supported",
|
2017-12-31 10:44:32 +08:00
|
|
|
version));
|
2006-03-04 06:31:16 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* in non-verbose mode just lets print the basic Message Type */
|
2014-03-14 20:10:54 +08:00
|
|
|
if (ndo->ndo_vflag < 1) {
|
|
|
|
ND_PRINT((ndo, "VQPv%u %s Message, error-code %s (%u), length %u",
|
2017-12-31 10:44:32 +08:00
|
|
|
version,
|
|
|
|
tok2str(vqp_msg_type_values, "unknown (%u)",EXTRACT_U_1(vqp_common_header->msg_type)),
|
|
|
|
tok2str(vqp_error_code_values, "unknown (%u)",EXTRACT_U_1(vqp_common_header->error_code)),
|
|
|
|
EXTRACT_U_1(vqp_common_header->error_code),
|
2014-03-14 20:10:54 +08:00
|
|
|
len));
|
2006-03-04 06:31:16 +08:00
|
|
|
return;
|
|
|
|
}
|
2014-01-02 10:27:54 +08:00
|
|
|
|
2006-03-04 06:31:16 +08:00
|
|
|
/* ok they seem to want to know everything - lets fully decode it */
|
2017-12-31 10:44:32 +08:00
|
|
|
nitems = EXTRACT_U_1(vqp_common_header->nitems);
|
2014-03-14 20:10:54 +08:00
|
|
|
ND_PRINT((ndo, "\n\tVQPv%u, %s Message, error-code %s (%u), seq 0x%08x, items %u, length %u",
|
2017-12-31 10:44:32 +08:00
|
|
|
version,
|
|
|
|
tok2str(vqp_msg_type_values, "unknown (%u)",EXTRACT_U_1(vqp_common_header->msg_type)),
|
|
|
|
tok2str(vqp_error_code_values, "unknown (%u)",EXTRACT_U_1(vqp_common_header->error_code)),
|
|
|
|
EXTRACT_U_1(vqp_common_header->error_code),
|
|
|
|
EXTRACT_BE_U_4(vqp_common_header->sequence),
|
2006-03-04 06:31:16 +08:00
|
|
|
nitems,
|
2014-03-14 20:10:54 +08:00
|
|
|
len));
|
2006-03-04 06:31:16 +08:00
|
|
|
|
|
|
|
/* skip VQP Common header */
|
2017-09-13 20:26:02 +08:00
|
|
|
tptr+=sizeof(struct vqp_common_header_t);
|
|
|
|
tlen-=sizeof(struct vqp_common_header_t);
|
2006-03-04 06:31:16 +08:00
|
|
|
|
2017-12-31 10:44:32 +08:00
|
|
|
while (nitems != 0 && tlen != 0) {
|
2006-03-04 06:31:16 +08:00
|
|
|
|
2006-03-08 22:30:12 +08:00
|
|
|
vqp_obj_tlv = (const struct vqp_obj_tlv_t *)tptr;
|
2017-07-30 06:21:00 +08:00
|
|
|
ND_TCHECK(*vqp_obj_tlv);
|
|
|
|
if (sizeof(struct vqp_obj_tlv_t) > tlen)
|
|
|
|
goto trunc;
|
2017-11-23 06:54:09 +08:00
|
|
|
vqp_obj_type = EXTRACT_BE_U_4(vqp_obj_tlv->obj_type);
|
|
|
|
vqp_obj_len = EXTRACT_BE_U_2(vqp_obj_tlv->obj_length);
|
2006-03-08 22:30:12 +08:00
|
|
|
tptr+=sizeof(struct vqp_obj_tlv_t);
|
|
|
|
tlen-=sizeof(struct vqp_obj_tlv_t);
|
2006-03-04 06:31:16 +08:00
|
|
|
|
2014-03-14 20:10:54 +08:00
|
|
|
ND_PRINT((ndo, "\n\t %s Object (0x%08x), length %u, value: ",
|
2006-03-04 06:31:16 +08:00
|
|
|
tok2str(vqp_obj_values, "Unknown", vqp_obj_type),
|
2014-03-14 20:10:54 +08:00
|
|
|
vqp_obj_type, vqp_obj_len));
|
2006-03-04 06:31:16 +08:00
|
|
|
|
|
|
|
/* basic sanity check */
|
|
|
|
if (vqp_obj_type == 0 || vqp_obj_len ==0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-03-08 22:30:12 +08:00
|
|
|
/* did we capture enough for fully decoding the object ? */
|
2017-12-11 19:46:51 +08:00
|
|
|
ND_TCHECK_LEN(tptr, vqp_obj_len);
|
2017-07-30 06:21:00 +08:00
|
|
|
if (vqp_obj_len > tlen)
|
|
|
|
goto trunc;
|
2006-03-08 22:30:12 +08:00
|
|
|
|
2006-03-04 06:31:16 +08:00
|
|
|
switch(vqp_obj_type) {
|
|
|
|
case VQP_OBJ_IP_ADDRESS:
|
2017-07-30 06:21:00 +08:00
|
|
|
if (vqp_obj_len != 4)
|
|
|
|
goto trunc;
|
2017-11-23 06:54:09 +08:00
|
|
|
ND_PRINT((ndo, "%s (0x%08x)", ipaddr_string(ndo, tptr), EXTRACT_BE_U_4(tptr)));
|
2006-03-04 06:31:16 +08:00
|
|
|
break;
|
|
|
|
/* those objects have similar semantics - fall through */
|
|
|
|
case VQP_OBJ_PORT_NAME:
|
|
|
|
case VQP_OBJ_VLAN_NAME:
|
|
|
|
case VQP_OBJ_VTP_DOMAIN:
|
|
|
|
case VQP_OBJ_ETHERNET_PKT:
|
2014-04-01 21:29:55 +08:00
|
|
|
safeputs(ndo, tptr, vqp_obj_len);
|
2006-03-04 06:31:16 +08:00
|
|
|
break;
|
|
|
|
/* those objects have similar semantics - fall through */
|
|
|
|
case VQP_OBJ_MAC_ADDRESS:
|
|
|
|
case VQP_OBJ_MAC_NULL:
|
2017-12-13 02:36:21 +08:00
|
|
|
if (vqp_obj_len != MAC_ADDR_LEN)
|
2017-07-30 06:21:00 +08:00
|
|
|
goto trunc;
|
2014-04-04 15:43:46 +08:00
|
|
|
ND_PRINT((ndo, "%s", etheraddr_string(ndo, tptr)));
|
2006-03-04 06:31:16 +08:00
|
|
|
break;
|
|
|
|
default:
|
2014-03-14 20:10:54 +08:00
|
|
|
if (ndo->ndo_vflag <= 1)
|
|
|
|
print_unknown_data(ndo,tptr, "\n\t ", vqp_obj_len);
|
2006-03-04 06:31:16 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
tptr += vqp_obj_len;
|
|
|
|
tlen -= vqp_obj_len;
|
|
|
|
nitems--;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
trunc:
|
2014-03-14 20:10:54 +08:00
|
|
|
ND_PRINT((ndo, "\n\t[|VQP]"));
|
2006-03-04 06:31:16 +08:00
|
|
|
}
|