]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-ether.c
Compile with '-Wmissing-variable-declarations' if it's available
[tcpdump] / print-ether.c
index d7bc1b401b7f787f2ca57d00047c92d3876680bb..205cc8a7d7c99c0570d99e570981b763530df1a7 100644 (file)
@@ -57,6 +57,7 @@ const struct tok ethertype_values[] = {
     { ETHERTYPE_8021Q9100,     "802.1Q-9100" },
     { ETHERTYPE_8021QinQ,      "802.1Q-QinQ" },
     { ETHERTYPE_8021Q9200,     "802.1Q-9200" },
+    { ETHERTYPE_MACSEC,                "802.1AE MACsec" },
     { ETHERTYPE_VMAN,          "VMAN" },
     { ETHERTYPE_PUP,            "PUP" },
     { ETHERTYPE_ARP,            "ARP"},
@@ -100,6 +101,7 @@ const struct tok ethertype_values[] = {
     { ETHERTYPE_GEONET,         "GeoNet"},
     { ETHERTYPE_CALM_FAST,      "CALM FAST"},
     { ETHERTYPE_AOE,            "AoE" },
+    { ETHERTYPE_PTP,            "PTP" },
     { ETHERTYPE_ARISTA,         "Arista Vendor Specific Protocol" },
     { 0, NULL}
 };
@@ -109,7 +111,7 @@ ether_addresses_print(netdissect_options *ndo, const u_char *src,
                      const u_char *dst)
 {
        ND_PRINT("%s > %s, ",
-                etheraddr_string(ndo, src), etheraddr_string(ndo, dst));
+                GET_ETHERADDR_STRING(src), GET_ETHERADDR_STRING(dst));
 }
 
 static void
@@ -132,7 +134,7 @@ ether_type_print(netdissect_options *ndo, uint16_t type)
  * printing Ethernet header information (such as a LANE ID for ATM LANE).
  */
 static u_int
-ether_print_common(netdissect_options *ndo, const u_char *p, u_int length,
+ether_common_print(netdissect_options *ndo, const u_char *p, u_int length,
     u_int caplen,
     void (*print_switch_tag)(netdissect_options *ndo, const u_char *),
     u_int switch_tag_len,
@@ -203,9 +205,47 @@ recurse:
        hdrlen += 2;
 
        /*
-        * Process VLAN tag types.
+        * Process 802.1AE MACsec headers.
         */
        printed_length = 0;
+       if (length_type == ETHERTYPE_MACSEC) {
+               /*
+                * MACsec, aka IEEE 802.1AE-2006
+                * Print the header, and try to print the payload if it's not encrypted
+                */
+               if (ndo->ndo_eflag) {
+                       ether_type_print(ndo, length_type);
+                       ND_PRINT(", length %u: ", orig_length);
+                       printed_length = 1;
+               }
+
+               int ret = macsec_print(ndo, &p, &length, &caplen, &hdrlen,
+                   &src, &dst);
+
+               if (ret == 0) {
+                       /* Payload is encrypted; print it as raw data. */
+                       if (!ndo->ndo_suppress_default_print)
+                               ND_DEFAULTPRINT(p, caplen);
+                       return (hdrlen);
+               } else if (ret > 0) {
+                       /* Problem printing the header; just quit. */
+                       return (ret);
+               } else {
+                       /*
+                        * Keep processing type/length fields.
+                        */
+                       length_type = GET_BE_U_2(p);
+
+                       length -= 2;
+                       caplen -= 2;
+                       p += 2;
+                       hdrlen += 2;
+               }
+       }
+
+       /*
+        * Process VLAN tag types.
+        */
        while (length_type == ETHERTYPE_8021Q  ||
                length_type == ETHERTYPE_8021Q9100 ||
                length_type == ETHERTYPE_8021Q9200 ||
@@ -289,7 +329,7 @@ recurse:
                 * It's a type field, with the type for Alteon jumbo frames.
                 * See
                 *
-                *      http://tools.ietf.org/html/draft-ietf-isis-ext-eth-01
+                *      https://tools.ietf.org/html/draft-ietf-isis-ext-eth-01
                 *
                 * which indicates that, following the type field,
                 * there's an LLC header and payload.
@@ -303,34 +343,34 @@ recurse:
                        llc_hdrlen = -llc_hdrlen;
                }
                hdrlen += llc_hdrlen;
-               } else if (length_type == ETHERTYPE_ARISTA) {
-                       if (caplen < 2) {
-                               ND_PRINT("[|arista]");
-                               return (hdrlen + caplen);
-                       }
-                       if (length < 2) {
-                               ND_PRINT("[|arista]");
-                               return (hdrlen + length);
-                       }
-                       ether_type_print(ndo, length_type);
-                       ND_PRINT(", length %u: ", orig_length);
-                       int bytesConsumed = arista_print_ethertype(ndo, p, length);
-                       if (bytesConsumed > 0) {
-                               p += bytesConsumed;
-                               length -= bytesConsumed;
-                               caplen -= bytesConsumed;
-                               hdrlen += bytesConsumed;
-                               goto recurse;
-                       } else {
-                               /* subtype/version not known, print raw packet */
-                               if (!ndo->ndo_eflag && length_type > MAX_ETHERNET_LENGTH_VAL) {
-                                       ether_addresses_print(ndo, src.addr, dst.addr);
-                                       ether_type_print(ndo, length_type);
-                                       ND_PRINT(", length %u: ", orig_length);
-                               }
-                                if (!ndo->ndo_suppress_default_print)
-                                        ND_DEFAULTPRINT(p, caplen);
+       } else if (length_type == ETHERTYPE_ARISTA) {
+               if (caplen < 2) {
+                       ND_PRINT("[|arista]");
+                       return (hdrlen + caplen);
+               }
+               if (length < 2) {
+                       ND_PRINT("[|arista]");
+                       return (hdrlen + length);
+               }
+               ether_type_print(ndo, length_type);
+               ND_PRINT(", length %u: ", orig_length);
+               int bytesConsumed = arista_ethertype_print(ndo, p, length);
+               if (bytesConsumed > 0) {
+                       p += bytesConsumed;
+                       length -= bytesConsumed;
+                       caplen -= bytesConsumed;
+                       hdrlen += bytesConsumed;
+                       goto recurse;
+               } else {
+                       /* subtype/version not known, print raw packet */
+                       if (!ndo->ndo_eflag && length_type > MAX_ETHERNET_LENGTH_VAL) {
+                               ether_addresses_print(ndo, src.addr, dst.addr);
+                               ether_type_print(ndo, length_type);
+                               ND_PRINT(", length %u: ", orig_length);
                        }
+                        if (!ndo->ndo_suppress_default_print)
+                                ND_DEFAULTPRINT(p, caplen);
+               }
        } else {
                /*
                 * It's a type field with some other value.
@@ -374,12 +414,12 @@ recurse:
  * FIXME: caplen can and should be derived from ndo->ndo_snapend and p.
  */
 u_int
-ether_print_switch_tag(netdissect_options *ndo, const u_char *p, u_int length,
+ether_switch_tag_print(netdissect_options *ndo, const u_char *p, u_int length,
     u_int caplen,
     void (*print_switch_tag)(netdissect_options *, const u_char *),
     u_int switch_tag_len)
 {
-       return (ether_print_common(ndo, p, length, caplen, print_switch_tag,
+       return (ether_common_print(ndo, p, length, caplen, print_switch_tag,
                                   switch_tag_len, NULL, NULL));
 }
 
@@ -398,8 +438,8 @@ ether_print(netdissect_options *ndo,
            const u_char *encap_header_arg)
 {
        ndo->ndo_protocol = "ether";
-       return (ether_print_common(ndo, p, length, caplen, NULL, 0,
-                                   print_encap_header, encap_header_arg));
+       return (ether_common_print(ndo, p, length, caplen, NULL, 0,
+                                  print_encap_header, encap_header_arg));
 }
 
 /*
@@ -600,6 +640,10 @@ ethertype_print(netdissect_options *ndo,
                aoe_print(ndo, p, length);
                return (1);
 
+       case ETHERTYPE_PTP:
+               ptp_print(ndo, p, length);
+               return (1);
+
        case ETHERTYPE_LAT:
        case ETHERTYPE_SCA:
        case ETHERTYPE_MOPRC: