]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-geneve.c
Add EXTRACT_ calls.
[tcpdump] / print-geneve.c
index 28cb92bddedde412c15664e90457257a49f5bcf2..724e9f02f4edc8e39be0137a2aa1c846bc7d89ff 100644 (file)
  * FOR A PARTICULAR PURPOSE.
  */
 
+/* \summary: Generic Network Virtualization Encapsulation (Geneve) printer */
+
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
 
-#include <tcpdump-stdinc.h>
+#include <netdissect-stdinc.h>
 
-#include "interface.h"
+#include "netdissect.h"
 #include "extract.h"
 #include "ethertype.h"
 
 /*
- * Geneve header, draft-gross-geneve-02
+ * Geneve header, draft-ietf-nvo3-geneve
  *
  *    0                   1                   2                   3
  *    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
@@ -76,12 +78,25 @@ static const struct tok geneve_flag_values[] = {
 static const char *
 format_opt_class(uint16_t opt_class)
 {
-    if (opt_class <= 0xff)
-        return "Standard";
-    else if (opt_class == 0xffff)
-        return "Experimental";
-    else
-        return "Unknown";
+    switch (opt_class) {
+    case 0x0100:
+        return "Linux";
+    case 0x0101:
+        return "Open vSwitch";
+    case 0x0102:
+        return "Open Virtual Networking (OVN)";
+    case 0x0103:
+        return "In-band Network Telemetry (INT)";
+    case 0x0104:
+        return "VMware";
+    default:
+        if (opt_class <= 0x00ff)
+            return "Standard";
+        else if (opt_class >= 0xfff0)
+            return "Experimental";
+    }
+
+    return "Unknown";
 }
 
 static void
@@ -97,9 +112,9 @@ geneve_opts_print(netdissect_options *ndo, const u_char *bp, u_int len)
         ND_PRINT((ndo, "%s", sep));
         sep = ", ";
 
-        opt_class = EXTRACT_16BITS(bp);
-        opt_type = *(bp + 2);
-        opt_len = 4 + ((*(bp + 3) & OPT_LEN_MASK) * 4);
+        opt_class = EXTRACT_BE_U_2(bp);
+        opt_type = EXTRACT_U_1(bp + 2);
+        opt_len = 4 + ((EXTRACT_U_1(bp + 3) & OPT_LEN_MASK) * 4);
 
         ND_PRINT((ndo, "class %s (0x%x) type 0x%x%s len %u",
                   format_opt_class(opt_class), opt_class, opt_type,
@@ -117,7 +132,7 @@ geneve_opts_print(netdissect_options *ndo, const u_char *bp, u_int len)
             ND_PRINT((ndo, " data"));
 
             for (i = 4; i < opt_len; i += 4) {
-                ND_PRINT((ndo, " %08x", EXTRACT_32BITS(data)));
+                ND_PRINT((ndo, " %08x", EXTRACT_BE_U_4(data)));
                 data++;
             }
         }
@@ -131,7 +146,7 @@ void
 geneve_print(netdissect_options *ndo, const u_char *bp, u_int len)
 {
     uint8_t ver_opt;
-    uint version;
+    u_int version;
     uint8_t flags;
     uint16_t prot;
     uint32_t vni;
@@ -140,9 +155,9 @@ geneve_print(netdissect_options *ndo, const u_char *bp, u_int len)
 
     ND_PRINT((ndo, "Geneve"));
 
-    ND_TCHECK2(*bp, 8);
+    ND_TCHECK_8(bp);
 
-    ver_opt = *bp;
+    ver_opt = EXTRACT_U_1(bp);
     bp += 1;
     len -= 1;
 
@@ -152,19 +167,19 @@ geneve_print(netdissect_options *ndo, const u_char *bp, u_int len)
         return;
     }
 
-    flags = *bp;
+    flags = EXTRACT_U_1(bp);
     bp += 1;
     len -= 1;
 
-    prot = EXTRACT_16BITS(bp);
+    prot = EXTRACT_BE_U_2(bp);
     bp += 2;
     len -= 2;
 
-    vni = EXTRACT_24BITS(bp);
+    vni = EXTRACT_BE_U_3(bp);
     bp += 3;
     len -= 3;
 
-    reserved = *bp;
+    reserved = EXTRACT_U_1(bp);
     bp += 1;
     len -= 1;
 
@@ -183,11 +198,11 @@ geneve_print(netdissect_options *ndo, const u_char *bp, u_int len)
 
     if (len < opts_len) {
         ND_PRINT((ndo, " truncated-geneve - %u bytes missing",
-                  len - opts_len));
+                  opts_len - len));
         return;
     }
 
-    ND_TCHECK2(*bp, opts_len);
+    ND_TCHECK_LEN(bp, opts_len);
 
     if (opts_len > 0) {
         ND_PRINT((ndo, ", options ["));
@@ -208,9 +223,9 @@ geneve_print(netdissect_options *ndo, const u_char *bp, u_int len)
     else
         ND_PRINT((ndo, "\n\t"));
 
-    if (ethertype_print(ndo, prot, bp, len, len) == 0) {
+    if (ethertype_print(ndo, prot, bp, len, ndo->ndo_snapend - bp, NULL, NULL) == 0) {
         if (prot == ETHERTYPE_TEB)
-            ether_print(ndo, bp, len, len, NULL, NULL);
+            ether_print(ndo, bp, len, ndo->ndo_snapend - bp, NULL, NULL);
         else
             ND_PRINT((ndo, "geneve-proto-0x%x", prot));
     }