]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Clean up the switch-tagged header code.
authorGuy Harris <[email protected]>
Sat, 20 Apr 2019 10:17:03 +0000 (03:17 -0700)
committerGuy Harris <[email protected]>
Sat, 20 Apr 2019 10:17:03 +0000 (03:17 -0700)
Use MAC_ADDR_LEN in expressions representing offsets and lengths.

Don't declare the Ethernet header structure ourselves in the Broadcom
code, just print it the same way it's printed in the Marvell code.  Make
the two routines similar in other places as well.

Use "Unknown" rather than "unregistered" when printing the Ethernet type
field in the EDSA header - the value may well be registered even if it's
not in ethertype_values, it's just not a value we happen to have in that
table.

print-brcmtag.c
print-dsa.c
tests/edsa-e.out

index 06150f55dad6cc52d528030992f527adaf4b83e1..47b114bbee704703f308a8df7fc091aef243676e 100644 (file)
 #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
@@ -126,46 +119,46 @@ u_int
 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 save_eflag;
        int ret;
 
        ndo->ndo_protocol = "brcm-tag";
-       if (caplen < ETHER_SA_OFFSET + BRCM_TAG_LEN) {
+       if (caplen < 2*MAC_ADDR_LEN + BRCM_TAG_LEN) {
                nd_print_trunc(ndo);
                return (caplen);
        }
 
-       if (length < ETHER_SA_OFFSET + BRCM_TAG_LEN) {
+       if (length < 2*MAC_ADDR_LEN + 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));
+                        etheraddr_string(ndo, p + MAC_ADDR_LEN),
+                        etheraddr_string(ndo, p));
 
-       if (brcm_tag_print_full(ndo, p + ETHER_SA_OFFSET,
-                               caplen - ETHER_SA_OFFSET))
+       if (brcm_tag_print_full(ndo, p + 2*MAC_ADDR_LEN,
+                               caplen - 2*MAC_ADDR_LEN))
                return (1);
 
-       /* We printed the Ethernet header already */
+       /* We printed the Ethernet destination and source addresses already */
+       save_eflag = ndo->ndo_eflag;
        ndo->ndo_eflag = 0;
 
-       /* Parse the Ethernet frame regularly telling how big the non
-        * standard Ethernet header is.
+       /* 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)|
-        * +-----------++-----------++----------------++--------------+
+        * +-----------+-----------+----------------+--------------+
+        * | MAC DA (6)| MAC SA (6)|Broadcom tag (4)|Type/Length(2)|
+        * +-----------+-----------+----------------+--------------+
         */
        ret = ether_hdr_len_print(ndo, p, length, caplen, NULL, NULL,
-                                 ETHER_SA_OFFSET + BRCM_TAG_LEN + ETHER_TYPE_LEN);
-       ndo->ndo_eflag = old_eflag;
+                                 2*MAC_ADDR_LEN + BRCM_TAG_LEN + ETHER_TYPE_LEN);
+       ndo->ndo_eflag = save_eflag;
        return ret;
 }
 
index 3d142b28faf38c58d3fbb0bc5aad2127fa79b4fb..ad247959b558d3a870ca5c4fc6307a900b83216e 100644 (file)
@@ -112,34 +112,35 @@ dsa_if_print_full(netdissect_options *ndo, const struct pcap_pkthdr *h,
                  const u_char *p, u_int taglen)
 {
        const u_char *edsa, *dsa;
-       int eflag, ret;
+       int save_eflag;
+       int ret;
 
-       if (h->caplen < 12 + taglen) {
+       if (h->caplen < 2*MAC_ADDR_LEN + taglen) {
                nd_print_trunc(ndo);
                return (h->caplen);
        }
 
-       if (h->len < 12 + taglen) {
+       if (h->len < 2*MAC_ADDR_LEN + taglen) {
                nd_print_trunc(ndo);
                return (h->len);
        }
 
        if (taglen == EDSA_LEN) {
-               edsa = p + 12;
+               edsa = p + 2*MAC_ADDR_LEN;
                dsa = edsa + 4;
        } else {
                edsa = NULL;
-               dsa = p + 12;
+               dsa = p + 2*MAC_ADDR_LEN;
        }
 
        if (ndo->ndo_eflag) {
                ND_PRINT("%s > %s, ",
-                        etheraddr_string(ndo, p + 6),
+                        etheraddr_string(ndo, p + MAC_ADDR_LEN),
                         etheraddr_string(ndo, p));
 
                if (edsa) {
                        ND_PRINT("Marvell EDSA ethertype 0x%04x (%s), ", EDSA_ETYPE(edsa),
-                                tok2str(ethertype_values, "unregistered", EDSA_ETYPE(edsa)));
+                                tok2str(ethertype_values, "Unknown", EDSA_ETYPE(edsa)));
                        ND_PRINT("rsvd %u %u, ", edsa[2], edsa[3]);
                } else {
                        ND_PRINT("Marvell DSA ");
@@ -209,11 +210,22 @@ dsa_if_print_full(netdissect_options *ndo, const struct pcap_pkthdr *h,
                ND_PRINT("VLAN %u%c, ", DSA_VID(dsa), DSA_TAGGED(dsa) ? 't' : 'u');
        }
 
-       eflag = ndo->ndo_eflag;
+       /* 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)|DSA/EDSA tag (taglen)|Type/Length(2)|
+        * +-----------+-----------+---------------------+--------------+
+        */
        ret = ether_hdr_len_print(ndo, p, h->len, h->caplen, NULL, NULL,
-                                 12 + taglen + 2);
-       ndo->ndo_eflag = eflag;
+                                 2*MAC_ADDR_LEN + taglen + 2);
+
+       ndo->ndo_eflag = save_eflag;
 
        return ret;
 }
index 5839c808253bb9179035cf0174d90c0bf329bbae..314eccfde4f873b03007131e6094a901b2ec1114 100644 (file)
@@ -1,10 +1,10 @@
-    1  22:21:44.604675 00:50:b6:29:10:7e > c6:e8:9f:7d:69:da, Marvell EDSA ethertype 0xdada (unregistered), rsvd 0 0, mode Forward, dev 0, port 0, untagged, VID 0, FPri 0, IP 192.168.20.1 > 192.168.20.2: ICMP echo request, id 13583, seq 1, length 64
-    2  22:21:44.604995 c6:e8:9f:7d:69:da > 00:50:b6:29:10:7e, Marvell EDSA ethertype 0xdada (unregistered), rsvd 0 0, mode From CPU, target dev 0, port 0, untagged, VID 0, FPri 0, IP 192.168.20.2 > 192.168.20.1: ICMP echo reply, id 13583, seq 1, length 64
-    3  22:21:45.622749 00:50:b6:29:10:7e > c6:e8:9f:7d:69:da, Marvell EDSA ethertype 0xdada (unregistered), rsvd 0 0, mode Forward, dev 0, port 0, untagged, VID 0, FPri 0, IP 192.168.20.1 > 192.168.20.2: ICMP echo request, id 13583, seq 2, length 64
-    4  22:21:45.622883 c6:e8:9f:7d:69:da > 00:50:b6:29:10:7e, Marvell EDSA ethertype 0xdada (unregistered), rsvd 0 0, mode From CPU, target dev 0, port 0, untagged, VID 0, FPri 0, IP 192.168.20.2 > 192.168.20.1: ICMP echo reply, id 13583, seq 2, length 64
-    5  22:21:46.636035 00:50:b6:29:10:7e > c6:e8:9f:7d:69:da, Marvell EDSA ethertype 0xdada (unregistered), rsvd 0 0, mode Forward, dev 0, port 0, untagged, VID 0, FPri 0, IP 192.168.20.1 > 192.168.20.2: ICMP echo request, id 13583, seq 3, length 64
-    6  22:21:46.636142 c6:e8:9f:7d:69:da > 00:50:b6:29:10:7e, Marvell EDSA ethertype 0xdada (unregistered), rsvd 0 0, mode From CPU, target dev 0, port 0, untagged, VID 0, FPri 0, IP 192.168.20.2 > 192.168.20.1: ICMP echo reply, id 13583, seq 3, length 64
-    7  22:21:49.680084 c6:e8:9f:7d:69:da > 00:50:b6:29:10:7e, Marvell EDSA ethertype 0xdada (unregistered), rsvd 0 0, mode From CPU, target dev 0, port 0, untagged, VID 0, FPri 0, ARP, Request who-has 192.168.20.1 tell 192.168.20.2, length 28
-    8  22:21:49.680474 00:50:b6:29:10:7e > c6:e8:9f:7d:69:da, Marvell EDSA ethertype 0xdada (unregistered), rsvd 0 0, mode Forward, dev 0, port 0, untagged, VID 0, FPri 0, ARP, Reply 192.168.20.1 is-at 00:50:b6:29:10:7e, length 46
-    9  22:21:49.809266 00:50:b6:29:10:7e > c6:e8:9f:7d:69:da, Marvell EDSA ethertype 0xdada (unregistered), rsvd 0 0, mode Forward, dev 0, port 0, untagged, VID 0, FPri 0, ARP, Request who-has 192.168.20.2 tell 192.168.20.1, length 46
-   10  22:21:49.809342 c6:e8:9f:7d:69:da > 00:50:b6:29:10:7e, Marvell EDSA ethertype 0xdada (unregistered), rsvd 0 0, mode From CPU, target dev 0, port 0, untagged, VID 0, FPri 0, ARP, Reply 192.168.20.2 is-at c6:e8:9f:7d:69:da, length 28
+    1  22:21:44.604675 00:50:b6:29:10:7e > c6:e8:9f:7d:69:da, Marvell EDSA ethertype 0xdada (Unknown), rsvd 0 0, mode Forward, dev 0, port 0, untagged, VID 0, FPri 0, IP 192.168.20.1 > 192.168.20.2: ICMP echo request, id 13583, seq 1, length 64
+    2  22:21:44.604995 c6:e8:9f:7d:69:da > 00:50:b6:29:10:7e, Marvell EDSA ethertype 0xdada (Unknown), rsvd 0 0, mode From CPU, target dev 0, port 0, untagged, VID 0, FPri 0, IP 192.168.20.2 > 192.168.20.1: ICMP echo reply, id 13583, seq 1, length 64
+    3  22:21:45.622749 00:50:b6:29:10:7e > c6:e8:9f:7d:69:da, Marvell EDSA ethertype 0xdada (Unknown), rsvd 0 0, mode Forward, dev 0, port 0, untagged, VID 0, FPri 0, IP 192.168.20.1 > 192.168.20.2: ICMP echo request, id 13583, seq 2, length 64
+    4  22:21:45.622883 c6:e8:9f:7d:69:da > 00:50:b6:29:10:7e, Marvell EDSA ethertype 0xdada (Unknown), rsvd 0 0, mode From CPU, target dev 0, port 0, untagged, VID 0, FPri 0, IP 192.168.20.2 > 192.168.20.1: ICMP echo reply, id 13583, seq 2, length 64
+    5  22:21:46.636035 00:50:b6:29:10:7e > c6:e8:9f:7d:69:da, Marvell EDSA ethertype 0xdada (Unknown), rsvd 0 0, mode Forward, dev 0, port 0, untagged, VID 0, FPri 0, IP 192.168.20.1 > 192.168.20.2: ICMP echo request, id 13583, seq 3, length 64
+    6  22:21:46.636142 c6:e8:9f:7d:69:da > 00:50:b6:29:10:7e, Marvell EDSA ethertype 0xdada (Unknown), rsvd 0 0, mode From CPU, target dev 0, port 0, untagged, VID 0, FPri 0, IP 192.168.20.2 > 192.168.20.1: ICMP echo reply, id 13583, seq 3, length 64
+    7  22:21:49.680084 c6:e8:9f:7d:69:da > 00:50:b6:29:10:7e, Marvell EDSA ethertype 0xdada (Unknown), rsvd 0 0, mode From CPU, target dev 0, port 0, untagged, VID 0, FPri 0, ARP, Request who-has 192.168.20.1 tell 192.168.20.2, length 28
+    8  22:21:49.680474 00:50:b6:29:10:7e > c6:e8:9f:7d:69:da, Marvell EDSA ethertype 0xdada (Unknown), rsvd 0 0, mode Forward, dev 0, port 0, untagged, VID 0, FPri 0, ARP, Reply 192.168.20.1 is-at 00:50:b6:29:10:7e, length 46
+    9  22:21:49.809266 00:50:b6:29:10:7e > c6:e8:9f:7d:69:da, Marvell EDSA ethertype 0xdada (Unknown), rsvd 0 0, mode Forward, dev 0, port 0, untagged, VID 0, FPri 0, ARP, Request who-has 192.168.20.2 tell 192.168.20.1, length 46
+   10  22:21:49.809342 c6:e8:9f:7d:69:da > 00:50:b6:29:10:7e, Marvell EDSA ethertype 0xdada (Unknown), rsvd 0 0, mode From CPU, target dev 0, port 0, untagged, VID 0, FPri 0, ARP, Reply 192.168.20.2 is-at c6:e8:9f:7d:69:da, length 28