X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/c0af6af3011d4c55bdadf3dd76cd5fc1115c50d0..5ef0bcb5edd748de9d9af13c40da0395dfdd94e8:/print-brcmtag.c diff --git a/print-brcmtag.c b/print-brcmtag.c index 51966e3c..1e0c5884 100644 --- a/print-brcmtag.c +++ b/print-brcmtag.c @@ -32,13 +32,6 @@ #include "addrtoname.h" #include "extract.h" -struct ether_header { - nd_mac_addr ether_dhost; - nd_mac_addr ether_shost; - nd_uint16_t ether_length_type; -}; - -#define ETHER_SA_OFFSET 12 #define ETHER_TYPE_LEN 2 #define BRCM_TAG_LEN 4 @@ -66,40 +59,39 @@ struct ether_header { #define BRCM_EG_TC_MASK 0x7 #define BRCM_EG_PID_MASK 0x1f -const struct tok brcm_tag_te_values[] = { +static const struct tok brcm_tag_te_values[] = { { 0, "None" }, { 1, "Untag" }, { 2, "Header"}, { 3, "Reserved" }, + { 0, NULL } }; -const struct tok brcm_tag_rc_values[] = { +static const struct tok brcm_tag_rc_values[] = { { 1, "mirror" }, { 2, "MAC learning" }, { 4, "switching" }, { 8, "prot term" }, { 16, "prot snoop" }, { 32, "exception" }, + { 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] = EXTRACT_U_1(bp + i); + tag[i] = GET_U_1(bp + i); ND_PRINT("BRCM tag OP: %s", tag[0] ? "IG" : "EG"); if (tag[0] & (1 << BRCM_OPCODE_SHIFT)) { /* Ingress Broadcom tag */ ND_PRINT(", TC: %d", (tag[1] >> BRCM_IG_TC_SHIFT) & - BRCM_IG_TC_MASK); + BRCM_IG_TC_MASK); ND_PRINT(", TE: %s", tok2str(brcm_tag_te_values, "unknown", (tag[1] & BRCM_IG_TE_MASK))); @@ -110,70 +102,28 @@ static int brcm_tag_print_full(netdissect_options *ndo, const u_char *bp, /* Egress Broadcom tag */ ND_PRINT(", CID: %d", tag[1]); ND_PRINT(", RC: %s", tok2str(brcm_tag_rc_values, - "reserved", tag[2])); + "reserved", tag[2])); ND_PRINT(", TC: %d", (tag[3] >> BRCM_EG_TC_SHIFT) & - BRCM_EG_TC_MASK); + BRCM_EG_TC_MASK); 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) { - const struct ether_header *ehp; - int old_eflag = ndo->ndo_eflag; u_int caplen = h->caplen; u_int length = h->len; - int ret; ndo->ndo_protocol = "brcm-tag"; - if (caplen < ETHER_SA_OFFSET + BRCM_TAG_LEN) { - nd_print_trunc(ndo); - return (caplen); - } - - if (length < ETHER_SA_OFFSET + BRCM_TAG_LEN) { - nd_print_trunc(ndo); - return (length); - } - - ehp = (const struct ether_header *)p; - if (ndo->ndo_eflag) - ND_PRINT("%s > %s, ", - etheraddr_string(ndo, ehp->ether_shost), - etheraddr_string(ndo, ehp->ether_dhost)); - - if (brcm_tag_print_full(ndo, p + ETHER_SA_OFFSET, - caplen - ETHER_SA_OFFSET)) - return (1); - - /* We printed the Ethernet header already */ - ndo->ndo_eflag = 0; - - /* Parse the Ethernet frame regularly telling how big the non - * standard Ethernet header is. - * - * +-----------++-----------++----------------++--------------+ - * | MAC DA (6)|| MAC SA (6)||Broadcom tag (4)||Type/Length(2)| - * +-----------++-----------++----------------++--------------+ - */ - ret = ether_print_hdr_len(ndo, p, length, caplen, NULL, NULL, - ETHER_SA_OFFSET + BRCM_TAG_LEN + 2); - ndo->ndo_eflag = old_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) { @@ -182,23 +132,22 @@ brcm_tag_prepend_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, ndo->ndo_protocol = "brcm-tag-prepend"; if (caplen < BRCM_TAG_LEN) { + ndo->ndo_ll_hdr_len += caplen; nd_print_trunc(ndo); - return (caplen); + return; } - 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); }