X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/577621026df8d4a33a34d4e125f9ec964fc0e53c..9169e4e1949c3fa879f0a2f98cfbd8c444743c27:/print-vqp.c diff --git a/print-vqp.c b/print-vqp.c index 0db04fd6..b990538d 100644 --- a/print-vqp.c +++ b/print-vqp.c @@ -18,18 +18,17 @@ /* \summary: Cisco VLAN Query Protocol (VQP) printer */ #ifdef HAVE_CONFIG_H -#include "config.h" +#include #endif -#include +#include "netdissect-stdinc.h" +#define ND_LONGJMP_FROM_TCHECK #include "netdissect.h" #include "extract.h" #include "addrtoname.h" -#include "ether.h" #define VQP_VERSION 1 -#define VQP_EXTRACT_VERSION(x) ((x)&0xFF) /* * VQP common header @@ -44,16 +43,16 @@ */ struct vqp_common_header_t { - uint8_t version; - uint8_t msg_type; - uint8_t error_code; - uint8_t nitems; - uint8_t sequence[4]; + nd_uint8_t version; + nd_uint8_t msg_type; + nd_uint8_t error_code; + nd_uint8_t nitems; + nd_uint32_t sequence; }; struct vqp_obj_tlv_t { - uint8_t obj_type[4]; - uint8_t obj_length[2]; + nd_uint32_t obj_type; + nd_uint16_t obj_length; }; #define VQP_OBJ_REQ_JOIN_PORT 0x01 @@ -98,73 +97,76 @@ static const struct tok vqp_obj_values[] = { }; void -vqp_print(netdissect_options *ndo, register const u_char *pptr, register u_int len) +vqp_print(netdissect_options *ndo, const u_char *pptr, u_int len) { const struct vqp_common_header_t *vqp_common_header; const struct vqp_obj_tlv_t *vqp_obj_tlv; const u_char *tptr; + uint8_t version; uint16_t vqp_obj_len; uint32_t vqp_obj_type; u_int tlen; uint8_t nitems; + ndo->ndo_protocol = "vqp"; tptr=pptr; tlen = len; vqp_common_header = (const struct vqp_common_header_t *)pptr; - ND_TCHECK(*vqp_common_header); + ND_TCHECK_SIZE(vqp_common_header); if (sizeof(struct vqp_common_header_t) > tlen) - goto trunc; + goto invalid; + version = GET_U_1(vqp_common_header->version); /* * Sanity checking of the header. */ - if (VQP_EXTRACT_VERSION(vqp_common_header->version) != VQP_VERSION) { - ND_PRINT((ndo, "VQP version %u packet not supported", - VQP_EXTRACT_VERSION(vqp_common_header->version))); + if (version != VQP_VERSION) { + ND_PRINT("VQP version %u packet not supported", + version); return; } /* in non-verbose mode just lets print the basic Message Type */ if (ndo->ndo_vflag < 1) { - ND_PRINT((ndo, "VQPv%u %s Message, error-code %s (%u), length %u", - VQP_EXTRACT_VERSION(vqp_common_header->version), - tok2str(vqp_msg_type_values, "unknown (%u)",vqp_common_header->msg_type), - tok2str(vqp_error_code_values, "unknown (%u)",vqp_common_header->error_code), - vqp_common_header->error_code, - len)); + ND_PRINT("VQPv%u %s Message, error-code %s (%u), length %u", + version, + tok2str(vqp_msg_type_values, "unknown (%u)",GET_U_1(vqp_common_header->msg_type)), + tok2str(vqp_error_code_values, "unknown (%u)",GET_U_1(vqp_common_header->error_code)), + GET_U_1(vqp_common_header->error_code), + len); return; } /* ok they seem to want to know everything - lets fully decode it */ - nitems = vqp_common_header->nitems; - ND_PRINT((ndo, "\n\tVQPv%u, %s Message, error-code %s (%u), seq 0x%08x, items %u, length %u", - VQP_EXTRACT_VERSION(vqp_common_header->version), - tok2str(vqp_msg_type_values, "unknown (%u)",vqp_common_header->msg_type), - tok2str(vqp_error_code_values, "unknown (%u)",vqp_common_header->error_code), - vqp_common_header->error_code, - EXTRACT_BE_32BITS(&vqp_common_header->sequence), - nitems, - len)); + nitems = GET_U_1(vqp_common_header->nitems); + ND_PRINT("\n\tVQPv%u, %s Message, error-code %s (%u), seq 0x%08x, items %u, length %u", + version, + tok2str(vqp_msg_type_values, "unknown (%u)",GET_U_1(vqp_common_header->msg_type)), + tok2str(vqp_error_code_values, "unknown (%u)",GET_U_1(vqp_common_header->error_code)), + GET_U_1(vqp_common_header->error_code), + GET_BE_U_4(vqp_common_header->sequence), + nitems, + len); /* skip VQP Common header */ tptr+=sizeof(struct vqp_common_header_t); tlen-=sizeof(struct vqp_common_header_t); - while (nitems > 0 && tlen > 0) { + while (nitems != 0 && tlen != 0) { vqp_obj_tlv = (const struct vqp_obj_tlv_t *)tptr; - ND_TCHECK(*vqp_obj_tlv); + ND_TCHECK_SIZE(vqp_obj_tlv); if (sizeof(struct vqp_obj_tlv_t) > tlen) - goto trunc; - vqp_obj_type = EXTRACT_BE_32BITS(vqp_obj_tlv->obj_type); - vqp_obj_len = EXTRACT_BE_16BITS(vqp_obj_tlv->obj_length); + goto invalid; + vqp_obj_type = GET_BE_U_4(vqp_obj_tlv->obj_type); + vqp_obj_len = GET_BE_U_2(vqp_obj_tlv->obj_length); tptr+=sizeof(struct vqp_obj_tlv_t); tlen-=sizeof(struct vqp_obj_tlv_t); - ND_PRINT((ndo, "\n\t %s Object (0x%08x), length %u, value: ", + ND_PRINT("\n\t %s Object (0x%08x), length %u, value: ", tok2str(vqp_obj_values, "Unknown", vqp_obj_type), - vqp_obj_type, vqp_obj_len)); + vqp_obj_type, vqp_obj_len); /* basic sanity check */ if (vqp_obj_type == 0 || vqp_obj_len ==0) { @@ -172,29 +174,30 @@ vqp_print(netdissect_options *ndo, register const u_char *pptr, register u_int l } /* did we capture enough for fully decoding the object ? */ - ND_TCHECK2(*tptr, vqp_obj_len); + ND_TCHECK_LEN(tptr, vqp_obj_len); if (vqp_obj_len > tlen) - goto trunc; + goto invalid; switch(vqp_obj_type) { case VQP_OBJ_IP_ADDRESS: if (vqp_obj_len != 4) - goto trunc; - ND_PRINT((ndo, "%s (0x%08x)", ipaddr_string(ndo, tptr), EXTRACT_BE_32BITS(tptr))); + goto invalid; + ND_PRINT("%s (0x%08x)", GET_IPADDR_STRING(tptr), + GET_BE_U_4(tptr)); 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: - safeputs(ndo, tptr, vqp_obj_len); + (void)nd_printzp(ndo, tptr, vqp_obj_len, NULL); break; /* those objects have similar semantics - fall through */ case VQP_OBJ_MAC_ADDRESS: case VQP_OBJ_MAC_NULL: - if (vqp_obj_len != ETHER_ADDR_LEN) - goto trunc; - ND_PRINT((ndo, "%s", etheraddr_string(ndo, tptr))); + if (vqp_obj_len != MAC_ADDR_LEN) + goto invalid; + ND_PRINT("%s", GET_ETHERADDR_STRING(tptr)); break; default: if (ndo->ndo_vflag <= 1) @@ -206,6 +209,6 @@ vqp_print(netdissect_options *ndo, register const u_char *pptr, register u_int l nitems--; } return; -trunc: - ND_PRINT((ndo, "\n\t[|VQP]")); +invalid: + nd_print_invalid(ndo); }