X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/1b30fb060a3fb06a364bb86b0c7f9b485f43b77c..0023eaa78f123676bfa9c5fba72ea4b8a59aaa70:/print-brcmtag.c diff --git a/print-brcmtag.c b/print-brcmtag.c index 47b114bb..a3d15e28 100644 --- a/print-brcmtag.c +++ b/print-brcmtag.c @@ -21,14 +21,12 @@ /* \summary: Broadcom Ethernet switches tag (4 bytes) printer */ -#ifdef HAVE_CONFIG_H #include -#endif #include "netdissect-stdinc.h" +#define ND_LONGJMP_FROM_TCHECK #include "netdissect.h" -#include "ethertype.h" #include "addrtoname.h" #include "extract.h" @@ -77,16 +75,13 @@ static const struct tok brcm_tag_rc_values[] = { { 0, NULL } }; -static int brcm_tag_print_full(netdissect_options *ndo, const u_char *bp, - u_int length) +static void +brcm_tag_print(netdissect_options *ndo, const u_char *bp) { uint8_t tag[BRCM_TAG_LEN]; uint16_t dst_map; unsigned int i; - if (length < BRCM_TAG_LEN) - return (1); - for (i = 0; i < BRCM_TAG_LEN; i++) tag[i] = GET_U_1(bp + i); @@ -111,64 +106,22 @@ static int brcm_tag_print_full(netdissect_options *ndo, const u_char *bp, ND_PRINT(", port: %d", tag[3] & BRCM_EG_PID_MASK); } ND_PRINT(", "); - - return (0); } -u_int +void brcm_tag_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p) { u_int caplen = h->caplen; u_int length = h->len; - int save_eflag; - int ret; ndo->ndo_protocol = "brcm-tag"; - if (caplen < 2*MAC_ADDR_LEN + BRCM_TAG_LEN) { - nd_print_trunc(ndo); - return (caplen); - } - - if (length < 2*MAC_ADDR_LEN + BRCM_TAG_LEN) { - nd_print_trunc(ndo); - return (length); - } - - if (ndo->ndo_eflag) - ND_PRINT("%s > %s, ", - etheraddr_string(ndo, p + MAC_ADDR_LEN), - etheraddr_string(ndo, p)); - - if (brcm_tag_print_full(ndo, p + 2*MAC_ADDR_LEN, - caplen - 2*MAC_ADDR_LEN)) - return (1); - - /* We printed the Ethernet destination and source addresses already */ - save_eflag = ndo->ndo_eflag; - ndo->ndo_eflag = 0; - - /* Parse the rest of the Ethernet header, and the frame payload, - * telling ether_hdr_len_print() how big the non-standard Ethernet - * header is. - * - * +-----------+-----------+----------------+--------------+ - * | MAC DA (6)| MAC SA (6)|Broadcom tag (4)|Type/Length(2)| - * +-----------+-----------+----------------+--------------+ - */ - ret = ether_hdr_len_print(ndo, p, length, caplen, NULL, NULL, - 2*MAC_ADDR_LEN + BRCM_TAG_LEN + ETHER_TYPE_LEN); - ndo->ndo_eflag = save_eflag; - return ret; + ndo->ndo_ll_hdr_len += + ether_switch_tag_print(ndo, p, length, caplen, + brcm_tag_print, BRCM_TAG_LEN); } -static void brcm_tag_print_encap(netdissect_options *ndo, - const u_char *p) -{ - brcm_tag_print_full(ndo, p, BRCM_TAG_LEN); -} - -u_int +void brcm_tag_prepend_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p) { @@ -176,24 +129,20 @@ brcm_tag_prepend_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, u_int length = h->len; ndo->ndo_protocol = "brcm-tag-prepend"; - if (caplen < BRCM_TAG_LEN) { - nd_print_trunc(ndo); - return (caplen); - } + ND_TCHECK_LEN(p, BRCM_TAG_LEN); + ndo->ndo_ll_hdr_len += BRCM_TAG_LEN; - if (length < BRCM_TAG_LEN) { - nd_print_trunc(ndo); - return (length); + if (ndo->ndo_eflag) { + /* Print the prepended Broadcom tag. */ + brcm_tag_print(ndo, p); } + p += BRCM_TAG_LEN; + length -= BRCM_TAG_LEN; + caplen -= BRCM_TAG_LEN; - /* Parse the Ethernet frame regularly and utilize the encapsulation - * header printing facility to pring the pre-pended Broadcom tag. - * - * +-----------------++-----------++-----------++--------------+ - * | Broadcom tag (4)|| MAC DA (6)|| MAC SA (6)||Type/Length(2)| - * +-----------------++-----------++-----------++--------------+ + /* + * Now print the Ethernet frame following it. */ - return ether_print(ndo, p + BRCM_TAG_LEN, - length - BRCM_TAG_LEN, - caplen - BRCM_TAG_LEN, brcm_tag_print_encap, p); + ndo->ndo_ll_hdr_len += + ether_print(ndo, p, length, caplen, NULL, NULL); }