]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Add support for the Marvell Extended Distributed Switch Architecture header
authorAndrew Lunn <[email protected]>
Sun, 19 Apr 2015 20:35:00 +0000 (15:35 -0500)
committerFrancois-Xavier Le Bail <[email protected]>
Sat, 25 Apr 2015 20:44:15 +0000 (22:44 +0200)
This header can be used with Marvell switches to direct packets in/out
of a specific port in a tree of interconnected switches. The header
uses its own Ethertype of 0xdada.

By default, only brief output is printed, showing the switch device,
port, and vlan the packet is to/from. However if -e is given, to print
the link-level header, all fields are printed.

Makefile.in
ethertype.h
netdissect.h
print-ether.c
print-medsa.c [new file with mode: 0644]
tests/TESTLIST
tests/medsa-e.out [new file with mode: 0644]
tests/medsa.out [new file with mode: 0644]
tests/medsa.pcap [new file with mode: 0644]

index ddb24981e99cafbb2af3cfaed943eeb4891454da..548ad0cf8532d17d25cf1d1a24d161c638cae57e 100644 (file)
@@ -155,6 +155,7 @@ LIBNETDISSECT_SRC=\
        print-lwapp.c \
        print-lwres.c \
        print-m3ua.c \
+       print-medsa.c \
        print-mobile.c \
        print-mpcp.c \
        print-mpls.c \
index 803991735eb297a748a5fe3ea35ed86510be7b53..2aa53a08823dd6d755b80a33632a03013a7eb566 100644 (file)
 #ifndef        ETHERTYPE_GEONET
 #define        ETHERTYPE_GEONET        0x8947  /* ETSI GeoNetworking (Official IEEE registration from Jan 2013) */
 #endif
+#ifndef        ETHERTYPE_MEDSA
+#define        ETHERTYPE_MEDSA         0xdada  /* Marvel Distributed Switch Architecture */
+#endif
 
 extern const struct tok ethertype_values[];
index be78857e5afe1271c69d5d2e21ec1fcd363c573c..159dde6823f77c50a1a6b68aa891f6d613813421 100644 (file)
@@ -370,6 +370,7 @@ extern int esp_print(netdissect_options *,
                     const u_char *bp, const int length, const u_char *bp2,
                     int *nhdr, int *padlen);
 extern void arp_print(netdissect_options *,const u_char *, u_int, u_int);
+extern void medsa_print(netdissect_options *, const u_char *, u_int, u_int);
 extern void tipc_print(netdissect_options *, const u_char *, u_int, u_int);
 extern void msnlb_print(netdissect_options *, const u_char *);
 extern void icmp6_print(netdissect_options *ndo, const u_char *,
index f4906260baad56d9cc82f9555f42b7b44e7abb48..83cc4e5f8e750bcb11a0f2f91d6bc9dd84bba956 100644 (file)
@@ -82,6 +82,7 @@ const struct tok ethertype_values[] = {
     { ETHERTYPE_GEONET,         "GeoNet"},
     { ETHERTYPE_CALM_FAST,      "CALM FAST"},
     { ETHERTYPE_AOE,            "AoE" },
+    { ETHERTYPE_MEDSA,          "MEDSA" },
     { 0, NULL}
 };
 
@@ -421,6 +422,10 @@ ethertype_print(netdissect_options *ndo,
                aoe_print(ndo, p, length);
                return (1);
 
+       case ETHERTYPE_MEDSA:
+               medsa_print(ndo, p, length, caplen);
+               return (1);
+
        case ETHERTYPE_LAT:
        case ETHERTYPE_SCA:
        case ETHERTYPE_MOPRC:
diff --git a/print-medsa.c b/print-medsa.c
new file mode 100644 (file)
index 0000000..8eedfaa
--- /dev/null
@@ -0,0 +1,182 @@
+/*
+ * 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <tcpdump-stdinc.h>
+
+#include "interface.h"
+#include "ether.h"
+#include "ethertype.h"
+#include "extract.h"                   /* must come after interface.h */
+
+static const char tstr[] = "[|MEDSA]";
+
+/*
+ * Marvell Extended Distributed Switch Archiecture.
+ *
+ * A Marvell propriatary header used for passing packets to/from
+ * specific ports of a switch. There is no open specification of this
+ * header, but is documented in the Marvell Switch data sheets. For
+ * background, see:
+ *
+ * https://lwn.net/Articles/302333/
+ */
+struct medsa_pkthdr {
+       u_char bytes[6];
+       u_short ether_type;
+};
+
+/* Bytes 0 and 1 are reserved and should contain 0 */
+#define TAG(medsa)     (medsa->bytes[2] >> 6)
+#define TAG_TO_CPU     0
+#define TAG_FROM_CPU   1
+#define TAG_FORWARD    3
+#define SRC_TAG(medsa) ((medsa->bytes[2] >> 5) & 0x01)
+#define SRC_DEV(medsa) (medsa->bytes[2] & 0x1f)
+#define SRC_PORT(medsa)        ((medsa->bytes[3] >> 3) & 0x01f)
+#define TRUNK(medsa)   ((medsa->bytes[3] >> 2) & 0x01)
+#define CODE(medsa)    ((medsa->bytes[3] & 0x06) |     \
+                        ((medsa->bytes[4] >> 4) & 0x01))
+#define CODE_BDPU      0
+#define CODE_IGMP_MLD  2
+#define CODE_ARP_MIRROR        4
+#define CFI(medsa)     (medsa->bytes[3] & 0x01)
+#define PRI(medsa)     (medsa->bytes[4] >> 5)
+#define VID(medsa)     (((u_short)(medsa->bytes[4] & 0xf) << 8 |       \
+                         medsa->bytes[5]))
+
+static const struct tok tag_values[] = {
+       { TAG_TO_CPU, "To_CPU" },
+       { TAG_FROM_CPU, "From_CPU" },
+       { TAG_FORWARD, "Forward" },
+       { 0, NULL },
+};
+
+static const struct tok code_values[] = {
+       { CODE_BDPU, "BDPU" },
+       { CODE_IGMP_MLD, "IGMP/MLD" },
+       { CODE_ARP_MIRROR, "APR_Mirror" },
+       { 0, NULL },
+};
+
+static void medsa_print_full(netdissect_options *ndo,
+                           const struct medsa_pkthdr *medsa,
+                           u_int caplen)
+{
+       u_char tag = TAG(medsa);
+
+       ND_PRINT((ndo, "%s",
+                 tok2str(tag_values, "Unknown (%u)", tag)));
+
+       switch (tag) {
+       case TAG_TO_CPU:
+               ND_PRINT((ndo, ", %stagged", SRC_TAG(medsa) ? "" : "un"));
+               ND_PRINT((ndo, ", dev.port:vlan %d.%d:%d",
+                         SRC_DEV(medsa), SRC_PORT(medsa), VID(medsa)));
+
+               ND_PRINT((ndo, ", %s",
+                         tok2str(code_values, "Unknown (%u)", CODE(medsa))));
+               if (CFI(medsa))
+                       ND_PRINT((ndo, ", CFI"));
+
+               ND_PRINT((ndo, ", pri %d: ", PRI(medsa)));
+               break;
+       case TAG_FROM_CPU:
+               ND_PRINT((ndo, ", %stagged", SRC_TAG(medsa) ? "" : "un"));
+               ND_PRINT((ndo, ", dev.port:vlan %d.%d:%d",
+                         SRC_DEV(medsa), SRC_PORT(medsa), VID(medsa)));
+
+               if (CFI(medsa))
+                       ND_PRINT((ndo, ", CFI"));
+
+               ND_PRINT((ndo, ", pri %d: ", PRI(medsa)));
+               break;
+       case TAG_FORWARD:
+               ND_PRINT((ndo, ", %stagged", SRC_TAG(medsa) ? "" : "un"));
+               if (TRUNK(medsa))
+                       ND_PRINT((ndo, ", dev.trunk:vlan %d.%d:%d",
+                                 SRC_DEV(medsa), SRC_PORT(medsa), VID(medsa)));
+               else
+                       ND_PRINT((ndo, ", dev.port:vlan %d.%d:%d",
+                                 SRC_DEV(medsa), SRC_PORT(medsa), VID(medsa)));
+
+               if (CFI(medsa))
+                       ND_PRINT((ndo, ", CFI"));
+
+               ND_PRINT((ndo, ", pri %d: ", PRI(medsa)));
+               break;
+       default:
+               ND_DEFAULTPRINT((const u_char *)medsa, caplen);
+               return;
+       }
+}
+
+void
+medsa_print(netdissect_options *ndo,
+          const u_char *bp, u_int length, u_int caplen)
+{
+       register const struct ether_header *ep;
+       const struct medsa_pkthdr *medsa;
+       u_short ether_type;
+
+       medsa = (const struct medsa_pkthdr *)bp;
+       ep = (const struct ether_header *)(bp - sizeof(*ep));
+       ND_TCHECK(*medsa);
+
+       if (!ndo->ndo_eflag)
+               ND_PRINT((ndo, "MEDSA %d.%d:%d: ",
+                         SRC_DEV(medsa), SRC_PORT(medsa), VID(medsa)));
+       else
+               medsa_print_full(ndo, medsa, caplen);
+
+       bp += 8;
+       length -= 8;
+       caplen -= 8;
+
+       ether_type = EXTRACT_16BITS(&medsa->ether_type);
+       if (ether_type <= ETHERMTU) {
+               /* Try to print the LLC-layer header & higher layers */
+               if (llc_print(ndo, bp, length, caplen, ESRC(ep), EDST(ep)) < 0)
+                       /* ether_type not known, print raw packet */
+                       ND_DEFAULTPRINT(bp, caplen);
+       } else {
+               if (ndo->ndo_eflag)
+                       ND_PRINT((ndo, "ethertype %s (0x%04x) ",
+                                 tok2str(ethertype_values, "Unknown",
+                                         ether_type),
+                                 ether_type));
+
+               ethertype_print(ndo, ether_type, bp, length, caplen);
+       }
+       return;
+trunc:
+       ND_PRINT((ndo, "%s", tstr));
+}
+
+/*
+ * Local Variables:
+ * c-style: bsd
+ * End:
+ */
+
index 35963c62260b3ee717abec229ea92fb040daf87d..af3c76178557d8fd278e71f35b86d5cfaef716f1 100644 (file)
@@ -268,6 +268,11 @@ geneve-tcp geneve.pcap             geneve-tcp.out  -t "geneve && tcp"
 dhcp-rfc3004   dhcp-rfc3004.pcap       dhcp-rfc3004-v.out      -t -v
 dhcp-rfc5859   dhcp-rfc5859.pcap       dhcp-rfc5859-v.out      -t -v
 
+# MEDSA tests
+
+medsa          medsa.pcap              medsa.out       -t
+medsa-e                medsa.pcap              medsa-e.out     -t -e
+
 # bad packets from Kevin Day
 # cve-2015-2155 -- futz testing on FORCES printer
 kday1           kday1.pcap              kday1.out       -t -v
diff --git a/tests/medsa-e.out b/tests/medsa-e.out
new file mode 100644 (file)
index 0000000..265be0d
--- /dev/null
@@ -0,0 +1,20 @@
+26:a1:fb:92:da:73 > 01:80:c2:00:00:00, ethertype MEDSA (0xdada), length 68: To_CPU, untagged, dev.port:vlan 0.2:0, BDPU, pri 7: LLC, dsap STP (0x42) Individual, ssap STP (0x42) Command, ctrl 0x03: STP 802.1d, Config, Flags [none], bridge-id 8000.26:a1:fb:92:da:73.8001, length 43
+94:10:3e:80:bc:f3 > 00:22:02:00:18:44, ethertype MEDSA (0xdada), length 98: From_CPU, untagged, dev.port:vlan 0.3:0, pri 0: ethertype IPv4 (0x0800) 10.0.0.12.59483 > 198.110.48.12.123: NTPv4, Client, length 48
+00:22:02:00:18:44 > 94:10:3e:80:bc:f3, ethertype MEDSA (0xdada), length 98: Forward, untagged, dev.port:vlan 0.3:0, pri 0: ethertype IPv4 (0x0800) 198.110.48.12.123 > 10.0.0.12.59483: NTPv4, Server, length 48
+26:a1:fb:92:da:73 > 01:80:c2:00:00:00, ethertype MEDSA (0xdada), length 68: To_CPU, untagged, dev.port:vlan 0.2:0, BDPU, pri 7: LLC, dsap STP (0x42) Individual, ssap STP (0x42) Command, ctrl 0x03: STP 802.1d, Config, Flags [none], bridge-id 8000.26:a1:fb:92:da:73.8001, length 43
+26:a1:fb:92:da:73 > 01:80:c2:00:00:00, ethertype MEDSA (0xdada), length 68: To_CPU, untagged, dev.port:vlan 0.2:0, BDPU, pri 7: LLC, dsap STP (0x42) Individual, ssap STP (0x42) Command, ctrl 0x03: STP 802.1d, Config, Flags [none], bridge-id 8000.26:a1:fb:92:da:73.8001, length 43
+94:10:3e:80:bc:f3 > 00:22:02:00:18:44, ethertype MEDSA (0xdada), length 98: From_CPU, untagged, dev.port:vlan 0.3:0, pri 0: ethertype IPv4 (0x0800) 10.0.0.12.59809 > 66.228.42.59.123: NTPv4, Client, length 48
+94:10:3e:80:bc:f3 > 00:22:02:00:18:44, ethertype MEDSA (0xdada), length 98: From_CPU, untagged, dev.port:vlan 0.3:0, pri 0: ethertype IPv4 (0x0800) 10.0.0.12.58880 > 199.102.46.76.123: NTPv4, Client, length 48
+00:22:02:00:18:44 > 94:10:3e:80:bc:f3, ethertype MEDSA (0xdada), length 98: Forward, untagged, dev.port:vlan 0.3:0, pri 0: ethertype IPv4 (0x0800) 199.102.46.76.123 > 10.0.0.12.58880: NTPv4, Server, length 48
+00:22:02:00:18:44 > 94:10:3e:80:bc:f3, ethertype MEDSA (0xdada), length 98: Forward, untagged, dev.port:vlan 0.3:0, pri 0: ethertype IPv4 (0x0800) 66.228.42.59.123 > 10.0.0.12.59809: NTPv4, Server, length 48
+26:a1:fb:92:da:73 > 01:80:c2:00:00:00, ethertype MEDSA (0xdada), length 68: To_CPU, untagged, dev.port:vlan 0.2:0, BDPU, pri 7: LLC, dsap STP (0x42) Individual, ssap STP (0x42) Command, ctrl 0x03: STP 802.1d, Config, Flags [none], bridge-id 8000.26:a1:fb:92:da:73.8001, length 43
+94:10:3e:80:bc:f3 > 00:22:02:00:18:44, ethertype MEDSA (0xdada), length 98: From_CPU, untagged, dev.port:vlan 0.3:0, pri 0: ethertype IPv4 (0x0800) 10.0.0.12.41068 > 208.97.140.69.123: NTPv4, Client, length 48
+00:22:02:00:18:44 > 94:10:3e:80:bc:f3, ethertype MEDSA (0xdada), length 98: Forward, untagged, dev.port:vlan 0.3:0, pri 0: ethertype IPv4 (0x0800) 208.97.140.69.123 > 10.0.0.12.41068: NTPv4, Server, length 48
+26:a1:fb:92:da:73 > 01:80:c2:00:00:00, ethertype MEDSA (0xdada), length 68: To_CPU, untagged, dev.port:vlan 0.2:0, BDPU, pri 7: LLC, dsap STP (0x42) Individual, ssap STP (0x42) Command, ctrl 0x03: STP 802.1d, Config, Flags [none], bridge-id 8000.26:a1:fb:92:da:73.8001, length 43
+26:a1:fb:92:da:73 > 01:80:c2:00:00:00, ethertype MEDSA (0xdada), length 68: To_CPU, untagged, dev.port:vlan 0.2:0, BDPU, pri 7: LLC, dsap STP (0x42) Individual, ssap STP (0x42) Command, ctrl 0x03: STP 802.1d, Config, Flags [none], bridge-id 8000.26:a1:fb:92:da:73.8001, length 43
+94:10:3e:80:bc:f3 > 00:22:02:00:18:44, ethertype MEDSA (0xdada), length 350: From_CPU, untagged, dev.port:vlan 0.3:0, pri 0: ethertype IPv4 (0x0800) 10.0.0.12.68 > 10.0.0.1.67: BOOTP/DHCP, Request from 94:10:3e:80:bc:f3, length 300
+00:22:02:00:18:44 > 94:10:3e:80:bc:f3, ethertype MEDSA (0xdada), length 350: Forward, untagged, dev.port:vlan 0.3:0, pri 0: ethertype IPv4 (0x0800) 10.0.0.1.67 > 10.0.0.12.68: BOOTP/DHCP, Reply, length 300
+26:a1:fb:92:da:73 > 01:80:c2:00:00:00, ethertype MEDSA (0xdada), length 68: To_CPU, untagged, dev.port:vlan 0.2:0, BDPU, pri 7: LLC, dsap STP (0x42) Individual, ssap STP (0x42) Command, ctrl 0x03: STP 802.1d, Config, Flags [none], bridge-id 8000.26:a1:fb:92:da:73.8001, length 43
+26:a1:fb:92:da:73 > 01:80:c2:00:00:00, ethertype MEDSA (0xdada), length 68: To_CPU, untagged, dev.port:vlan 0.2:0, BDPU, pri 7: LLC, dsap STP (0x42) Individual, ssap STP (0x42) Command, ctrl 0x03: STP 802.1d, Config, Flags [none], bridge-id 8000.26:a1:fb:92:da:73.8001, length 43
+94:10:3e:80:bc:f3 > 00:22:02:00:18:44, ethertype MEDSA (0xdada), length 98: From_CPU, untagged, dev.port:vlan 0.3:0, pri 0: ethertype IPv4 (0x0800) 10.0.0.12.45651 > 171.66.97.126.123: NTPv4, Client, length 48
+00:22:02:00:18:44 > 94:10:3e:80:bc:f3, ethertype MEDSA (0xdada), length 98: Forward, untagged, dev.port:vlan 0.3:0, pri 0: ethertype IPv4 (0x0800) 171.66.97.126.123 > 10.0.0.12.45651: NTPv4, Server, length 48
diff --git a/tests/medsa.out b/tests/medsa.out
new file mode 100644 (file)
index 0000000..c81ce48
--- /dev/null
@@ -0,0 +1,20 @@
+MEDSA 0.2:0: STP 802.1d, Config, Flags [none], bridge-id 8000.26:a1:fb:92:da:73.8001, length 43
+MEDSA 0.3:0: IP 10.0.0.12.59483 > 198.110.48.12.123: NTPv4, Client, length 48
+MEDSA 0.3:0: IP 198.110.48.12.123 > 10.0.0.12.59483: NTPv4, Server, length 48
+MEDSA 0.2:0: STP 802.1d, Config, Flags [none], bridge-id 8000.26:a1:fb:92:da:73.8001, length 43
+MEDSA 0.2:0: STP 802.1d, Config, Flags [none], bridge-id 8000.26:a1:fb:92:da:73.8001, length 43
+MEDSA 0.3:0: IP 10.0.0.12.59809 > 66.228.42.59.123: NTPv4, Client, length 48
+MEDSA 0.3:0: IP 10.0.0.12.58880 > 199.102.46.76.123: NTPv4, Client, length 48
+MEDSA 0.3:0: IP 199.102.46.76.123 > 10.0.0.12.58880: NTPv4, Server, length 48
+MEDSA 0.3:0: IP 66.228.42.59.123 > 10.0.0.12.59809: NTPv4, Server, length 48
+MEDSA 0.2:0: STP 802.1d, Config, Flags [none], bridge-id 8000.26:a1:fb:92:da:73.8001, length 43
+MEDSA 0.3:0: IP 10.0.0.12.41068 > 208.97.140.69.123: NTPv4, Client, length 48
+MEDSA 0.3:0: IP 208.97.140.69.123 > 10.0.0.12.41068: NTPv4, Server, length 48
+MEDSA 0.2:0: STP 802.1d, Config, Flags [none], bridge-id 8000.26:a1:fb:92:da:73.8001, length 43
+MEDSA 0.2:0: STP 802.1d, Config, Flags [none], bridge-id 8000.26:a1:fb:92:da:73.8001, length 43
+MEDSA 0.3:0: IP 10.0.0.12.68 > 10.0.0.1.67: BOOTP/DHCP, Request from 94:10:3e:80:bc:f3, length 300
+MEDSA 0.3:0: IP 10.0.0.1.67 > 10.0.0.12.68: BOOTP/DHCP, Reply, length 300
+MEDSA 0.2:0: STP 802.1d, Config, Flags [none], bridge-id 8000.26:a1:fb:92:da:73.8001, length 43
+MEDSA 0.2:0: STP 802.1d, Config, Flags [none], bridge-id 8000.26:a1:fb:92:da:73.8001, length 43
+MEDSA 0.3:0: IP 10.0.0.12.45651 > 171.66.97.126.123: NTPv4, Client, length 48
+MEDSA 0.3:0: IP 171.66.97.126.123 > 10.0.0.12.45651: NTPv4, Server, length 48
diff --git a/tests/medsa.pcap b/tests/medsa.pcap
new file mode 100644 (file)
index 0000000..ab20710
Binary files /dev/null and b/tests/medsa.pcap differ