]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Add support for decoding Marvell (E)DSA tags
authorVivien Didelot <[email protected]>
Sat, 6 Apr 2019 15:16:54 +0000 (11:16 -0400)
committerVivien Didelot <[email protected]>
Tue, 16 Apr 2019 16:19:38 +0000 (12:19 -0400)
Similarly to commit 6eaebfe adding support for the Broadcom tagging
format supported by the DSA kernel subsystem, this commit adds support
for the Marvell DSA and Ethertype DSA (EDSA) tagging formats.

Marvell DSA is a 4-byte proprietary tag placed between the ether source
address and the ether length/type. It contains data such as the switch
device and port IDs from which a frame came from, or to which port
a frame is targetting. It also contains additional FPri and IEEE bits.

EDSA is a 8-byte variant including a programmable ethertype, two null
bytes and a standard DSA tag.

CMakeLists.txt
Makefile.in
netdissect.h
print-dsa.c [new file with mode: 0644]
print.c

index 905bc787372f6cae35f66dd83427aee864875a9c..0bac580ef78ed89046d36a04dc46e5a4690e0d11 100644 (file)
@@ -957,6 +957,7 @@ set(NETDISSECT_SOURCE_LIST_C
     print-decnet.c
     print-dhcp6.c
     print-domain.c
+    print-dsa.c
     print-dtp.c
     print-dvmrp.c
     print-eap.c
index 2096afba4afd128036c79e48b42bab9d1e844bf1..fb9ee573dda0b64f48e518a8db270f7b91895ccd 100644 (file)
@@ -120,6 +120,7 @@ LIBNETDISSECT_SRC=\
        print-decnet.c \
        print-dhcp6.c \
        print-domain.c \
+       print-dsa.c \
        print-dtp.c \
        print-dvmrp.c \
        print-eap.c \
index 8cf1c08fed3d111d06bd5797c810cac075158c0a..938c2464a2ca49de9ec17a91863dea5e130f57a5 100644 (file)
@@ -469,6 +469,8 @@ extern u_int brcm_tag_if_print IF_PRINTER_ARGS;
 extern u_int brcm_tag_prepend_if_print IF_PRINTER_ARGS;
 extern u_int chdlc_if_print IF_PRINTER_ARGS;
 extern u_int cip_if_print IF_PRINTER_ARGS;
+extern u_int dsa_if_print IF_PRINTER_ARGS;
+extern u_int edsa_if_print IF_PRINTER_ARGS;
 extern u_int enc_if_print IF_PRINTER_ARGS;
 extern u_int ether_if_print IF_PRINTER_ARGS;
 extern u_int fddi_if_print IF_PRINTER_ARGS;
diff --git a/print-dsa.c b/print-dsa.c
new file mode 100644 (file)
index 0000000..7a6968a
--- /dev/null
@@ -0,0 +1,235 @@
+/*
+ * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
+ *     The Regents of the University of California.  All rights reserved.
+ *
+ * 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, (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, and (3) all advertising materials mentioning
+ * features or use of this software display the following acknowledgement:
+ * ``This product includes software developed by the University of California,
+ * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
+ * the University nor the names of its contributors may be used to endorse
+ * or promote products derived from this software without specific prior
+ * written permission.
+ * 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.
+ */
+
+/* \summary: Marvell (Ethertype) Distributed Switch Architecture printer */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "netdissect-stdinc.h"
+
+#include "netdissect.h"
+#include "ethertype.h"
+#include "addrtoname.h"
+#include "extract.h"
+
+/*
+ * Format of (Ethertyped or not) DSA tagged frames:
+ *
+ *      7   6   5   4   3   2   1   0  
+ *    .   .   .   .   .   .   .   .   .
+ *  0 +---+---+---+---+---+---+---+---+
+ *    |   Ether Destination Address   |
+ * +6 +---+---+---+---+---+---+---+---+
+ *    |     Ether Source Address      |
+ * +6 +---+---+---+---+---+---+---+---+  +-
+ *    |  Prog. DSA Ether Type [15:8]  |  | (8-byte) EDSA Tag
+ * +1 +---+---+---+---+---+---+---+---+  | Contains a programmable Ether type,
+ *    |  Prog. DSA Ether Type [7:0]   |  | two reserved bytes (always 0),
+ * +1 +---+---+---+---+---+---+---+---+  | and a standard DSA tag.
+ *    |     Reserved (0x00 0x00)      |  |
+ * +2 +---+---+---+---+---+---+---+---+  |  +-
+ *    | Mode  |b29|    Src/Trg Dev    |  |  | (4-byte) DSA Tag
+ * +1 +---+---+---+---+---+---+---+---+  |  | Contains a DSA tag mode,
+ *    |Src/Trg Port/Trunk |b18|b17|b16|  |  | source or target switch device,
+ * +1 +---+---+---+---+---+---+---+---+  |  | source or target port or trunk,
+ *    | PRI [2:0] |b12|  VID [11:8]   |  |  | and misc (IEEE and FPri) bits.
+ * +1 +---+---+---+---+---+---+---+---+  |  |
+ *    |           VID [7:0]           |  |  |
+ * +1 +---+---+---+---+---+---+---+---+  +- +-
+ *    |       Ether Length/Type       |
+ * +2 +---+---+---+---+---+---+---+---+
+ *    .   .   .   .   .   .   .   .   .
+ *
+ * Mode: Forward, To_CPU, From_CPU, To_Sniffer
+ * b29: (Source or Target) IEEE Tag Mode
+ * b18: Forward's Src_Is_Trunk, To_CPU's Code[2], To_Sniffer's Rx_Sniff
+ * b17: To_CPU's Code[1]
+ * b16: Original frame's CFI
+ * b12: To_CPU's Code[0]
+ */
+
+#define TOK(tag, byte, mask, shift) ((((const u_char *) tag)[byte] & (mask)) >> (shift))
+
+#define DSA_LEN 4
+#define DSA_MODE(tag) TOK(tag, 0, 0xc0, 6)
+#define  DSA_MODE_TO_CPU 0x0
+#define  DSA_MODE_FROM_CPU 0x1
+#define  DSA_MODE_TO_SNIFFER 0x2
+#define  DSA_MODE_FORWARD 0x3
+#define DSA_TAGGED(tag) TOK(tag, 0, 0x20, 5)
+#define DSA_DEV(tag) TOK(tag, 0, 0x1f, 0)
+#define DSA_PORT(tag) TOK(tag, 1, 0xf8, 3)
+#define DSA_TRUNK(tag) TOK(tag, 1, 0x04, 2)
+#define DSA_RX_SNIFF(tag) TOK(tag, 1, 0x04, 2)
+#define DSA_CFI(tag) TOK(tag, 1, 0x01, 0)
+#define DSA_PRI(tag) TOK(tag, 2, 0xe0, 5)
+#define DSA_VID(tag) ((u_short)((TOK(tag, 2, 0xe0, 5) << 8) | (TOK(tag, 3, 0xff, 0))))
+#define DSA_CODE(tag) ((TOK(tag, 1, 0x06, 1) << 1) | TOK(tag, 2, 0x10, 4))
+
+#define EDSA_LEN 8
+#define EDSA_ETYPE(tag) ((u_short)((TOK(tag, 0, 0xff, 0) << 8) | (TOK(tag, 1, 0xff, 0))))
+
+static const struct tok dsa_mode_values[] = {
+       { DSA_MODE_TO_CPU, "To CPU" },
+       { DSA_MODE_FROM_CPU, "From CPU" },
+       { DSA_MODE_TO_SNIFFER, "To Sniffer"},
+       { DSA_MODE_FORWARD, "Forward" },
+       { 0, NULL }
+};
+
+static const struct tok dsa_code_values[] = {
+       { 0x0, "BPDU (MGMT) Trap" },
+       { 0x1, "Frame2Reg" },
+       { 0x2, "IGMP/MLD Trap" },
+       { 0x3, "Policy Trap" },
+       { 0x4, "ARP Mirror" },
+       { 0x5, "Policy Mirror" },
+       { 0, NULL }
+};
+
+static u_int
+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;
+
+       if (h->caplen < 12 + taglen) {
+               nd_print_trunc(ndo);
+               return (h->caplen);
+       }
+
+       if (h->len < 12 + taglen) {
+               nd_print_trunc(ndo);
+               return (h->len);
+       }
+
+       if (taglen == EDSA_LEN) {
+               edsa = p + 12;
+               dsa = edsa + 4;
+       } else {
+               edsa = NULL;
+               dsa = p + 12;
+       }
+
+       if (ndo->ndo_eflag) {
+               ND_PRINT("%s > %s, ",
+                        etheraddr_string(ndo, p + 6),
+                        etheraddr_string(ndo, p));
+
+               if (edsa) {
+                       ND_PRINT("Marvell EDSA ethertype 0x%04x (%s), ", EDSA_ETYPE(edsa),
+                                tok2str(ethertype_values, "unregistered", EDSA_ETYPE(edsa)));
+                       ND_PRINT("rsvd %u %u, ", edsa[2], edsa[3]);
+               } else {
+                       ND_PRINT("Marvell DSA ");
+               }
+
+               ND_PRINT("mode %s, ", tok2str(dsa_mode_values, "unknown", DSA_MODE(dsa)));
+
+               switch (DSA_MODE(dsa)) {
+               case DSA_MODE_FORWARD:
+                       ND_PRINT("dev %u, %s %u, ", DSA_DEV(dsa),
+                                DSA_TRUNK(dsa) ? "trunk" : "port", DSA_PORT(dsa));
+                       break;
+               case DSA_MODE_FROM_CPU:
+                       ND_PRINT("target dev %u, port %u, ",
+                                DSA_DEV(dsa), DSA_PORT(dsa));
+                       break;
+               case DSA_MODE_TO_CPU:
+                       ND_PRINT("source dev %u, port %u, ",
+                                DSA_DEV(dsa), DSA_PORT(dsa));
+                       ND_PRINT("code %s, ",
+                                tok2str(dsa_code_values, "reserved", DSA_CODE(dsa)));
+                       break;
+               case DSA_MODE_TO_SNIFFER:
+                       ND_PRINT("source dev %u, port %u, ",
+                                DSA_DEV(dsa), DSA_PORT(dsa));
+                       ND_PRINT("%s sniff, ",
+                                DSA_RX_SNIFF(dsa) ? "ingress" : "egress");
+                       break;
+               default:
+                       break;
+               }
+
+               ND_PRINT("%s, ", DSA_TAGGED(dsa) ? "tagged" : "untagged");
+               ND_PRINT("%s", DSA_CFI(dsa) ? "CFI, " : "");
+               ND_PRINT("VID %u, ", DSA_VID(dsa));
+               ND_PRINT("FPri %u, ", DSA_PRI(dsa));
+       } else {
+               if (edsa) {
+                       ND_PRINT("EDSA 0x%04x, ", EDSA_ETYPE(edsa));
+               } else {
+                       ND_PRINT("DSA ");
+               }
+
+               switch (DSA_MODE(dsa)) {
+               case DSA_MODE_FORWARD:
+                       ND_PRINT("Forward %s %u.%u, ",
+                                DSA_TRUNK(dsa) ? "trunk" : "port",
+                                DSA_DEV(dsa), DSA_PORT(dsa));
+                       break;
+               case DSA_MODE_FROM_CPU:
+                       ND_PRINT("CPU > port %u.%u, ",
+                                DSA_DEV(dsa), DSA_PORT(dsa));
+                       break;
+               case DSA_MODE_TO_CPU:
+                       ND_PRINT("port %u.%u > CPU, ",
+                                DSA_DEV(dsa), DSA_PORT(dsa));
+                       break;
+               case DSA_MODE_TO_SNIFFER:
+                       ND_PRINT("port %u.%u > %s Sniffer, ",
+                                DSA_DEV(dsa), DSA_PORT(dsa),
+                                DSA_RX_SNIFF(dsa) ? "Rx" : "Tx");
+                       break;
+               default:
+                       break;
+               }
+
+               ND_PRINT("VLAN %u%c, ", DSA_VID(dsa), DSA_TAGGED(dsa) ? 't' : 'u');
+       }
+
+       eflag = ndo->ndo_eflag;
+       ndo->ndo_eflag = 0;
+       ret = ether_hdr_len_print(ndo, p, h->len, h->caplen, NULL, NULL,
+                                 12 + taglen + 2);
+       ndo->ndo_eflag = eflag;
+
+       return ret;
+}
+
+u_int
+dsa_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p)
+{
+       ndo->ndo_protocol = "dsa";
+
+       return dsa_if_print_full(ndo, h, p, DSA_LEN);
+}
+
+u_int
+edsa_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p)
+{
+       ndo->ndo_protocol = "edsa";
+
+       return dsa_if_print_full(ndo, h, p, EDSA_LEN);
+}
diff --git a/print.c b/print.c
index 44040ecd8550a645cbd784cfe27a405c014fee68..1416d186127bde5215e57bc8b0f36e76ba6238f3 100644 (file)
--- a/print.c
+++ b/print.c
@@ -236,6 +236,12 @@ static const struct printer printers[] = {
 #endif
 #ifdef DLT_VSOCK
        { vsock_if_print,       DLT_VSOCK },
+#endif
+#ifdef DLT_DSA_TAG_DSA
+       { dsa_if_print, DLT_DSA_TAG_DSA },
+#endif
+#ifdef DLT_DSA_TAG_EDSA
+       { edsa_if_print,        DLT_DSA_TAG_EDSA },
 #endif
        { NULL,                 0 },
 };