]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Add support for Generic Network Virtualization Encapsulation (Geneve). 411/head
authorJesse Gross <[email protected]>
Wed, 5 Nov 2014 02:47:24 +0000 (18:47 -0800)
committerJesse Gross <[email protected]>
Thu, 6 Nov 2014 05:44:29 +0000 (21:44 -0800)
Defined in http://tools.ietf.org/html/draft-gross-geneve-02

CREDITS
Makefile.in
netdissect.h
print-geneve.c [new file with mode: 0644]
print-udp.c
tests/TESTLIST
tests/geneve-vv.out [new file with mode: 0644]
tests/geneve.pcap [new file with mode: 0644]
udp.h

diff --git a/CREDITS b/CREDITS
index d7e823a720529bf6dde147d8952a58ff187df968..4076edc829c0eb3e3ebe776cf881d1541d2843c0 100644 (file)
--- a/CREDITS
+++ b/CREDITS
@@ -96,6 +96,7 @@ Additional people who have contributed patches:
     Jefferson Ogata               <jogata at nodc dot noaa dot gov>
     Jeffrey Hutzelman             <jhutz at cmu dot edu>
     Jesper Peterson               <jesper at endace dot com>
+    Jesse Gross                   <jesse at nicira dot com>
     Jim Hutchins                  <jim at ca dot sandia dot gov>
     João Medeiros                 <ignotus21 at sourceforge dot net>
     Joerg Mayer                   <jmayer at loplof dot de>
index d6836f698d1b2466badf5db208a5b07d4de99409..1296d1d04c6d6c3da66bcbfaaaaad7fbdfeeaf89 100644 (file)
@@ -125,6 +125,7 @@ LIBNETDISSECT_SRC=\
        print-forces.c \
        print-fr.c \
        print-ftp.c \
+       print-geneve.c \
        print-geonet.c \
        print-gre.c \
        print-hsrp.c \
index a554eae2cafeeef639bc33804eb097601b54a778..e0a0205d94dbc08560c138cbad2c2963b6cb7421 100644 (file)
@@ -556,6 +556,7 @@ extern void ftp_print(netdissect_options *, const u_char *, u_int);
 extern void http_print(netdissect_options *, const u_char *, u_int);
 extern void rtsp_print(netdissect_options *, const u_char *, u_int);
 extern void smtp_print(netdissect_options *, const u_char *, u_int);
+extern void geneve_print(netdissect_options *, const u_char *, u_int);
 
 /* stuff that has not yet been rototiled */
 
diff --git a/print-geneve.c b/print-geneve.c
new file mode 100644 (file)
index 0000000..2187ab8
--- /dev/null
@@ -0,0 +1,223 @@
+/*
+ * Copyright (c) 2014 VMware, Inc. All Rights Reserved.
+ *
+ * Jesse Gross <[email protected]>
+ *
+ * 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, and (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.
+ * 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.
+ */
+
+#define NETDISSECT_REWORKED
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <tcpdump-stdinc.h>
+
+#include "interface.h"
+#include "extract.h"
+#include "ethertype.h"
+
+/*
+ * Geneve header, draft-gross-geneve-02
+ *
+ *    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
+ *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *    |Ver|  Opt Len  |O|C|    Rsvd.  |          Protocol Type        |
+ *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *    |        Virtual Network Identifier (VNI)       |    Reserved   |
+ *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *    |                    Variable Length Options                    |
+ *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *
+ * Options:
+ *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *    |          Option Class         |      Type     |R|R|R| Length  |
+ *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *    |                      Variable Option Data                     |
+ *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ */
+
+#define VER_SHIFT 6
+#define HDR_OPTS_LEN_MASK 0x3F
+
+#define FLAG_OAM      (1 << 7)
+#define FLAG_CRITICAL (1 << 6)
+#define FLAG_R1       (1 << 5)
+#define FLAG_R2       (1 << 4)
+#define FLAG_R3       (1 << 3)
+#define FLAG_R4       (1 << 2)
+#define FLAG_R5       (1 << 1)
+#define FLAG_R6       (1 << 0)
+
+#define OPT_TYPE_CRITICAL (1 << 7)
+#define OPT_LEN_MASK 0x1F
+
+static const struct tok geneve_flag_values[] = {
+        { FLAG_OAM, "O" },
+        { FLAG_CRITICAL, "C" },
+        { FLAG_R1, "R1" },
+        { FLAG_R2, "R2" },
+        { FLAG_R3, "R3" },
+        { FLAG_R4, "R4" },
+        { FLAG_R5, "R5" },
+        { FLAG_R6, "R6" },
+        { 0, NULL }
+};
+
+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";
+}
+
+static void
+geneve_opts_print(netdissect_options *ndo, const u_char *bp, u_int len)
+{
+    const char *sep = "";
+
+    while (len > 0) {
+        uint16_t opt_class;
+        uint8_t opt_type;
+        uint8_t opt_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);
+
+        ND_PRINT((ndo, "class %s (0x%x) type 0x%x%s len %u",
+                  format_opt_class(opt_class), opt_class, opt_type,
+                  opt_type & OPT_TYPE_CRITICAL ? "(C)" : "", opt_len));
+
+        if (opt_len > len) {
+            ND_PRINT((ndo, " [bad length]"));
+            return;
+        }
+
+        if (ndo->ndo_vflag > 1 && opt_len > 4) {
+            uint32_t *print_data = (uint32_t *)(bp + 4);
+            int i;
+
+            ND_PRINT((ndo, " data"));
+
+            for (i = 4; i < opt_len; i += 4) {
+                ND_PRINT((ndo, " %08x", EXTRACT_32BITS(print_data)));
+                print_data++;
+            }
+        }
+
+        bp += opt_len;
+        len -= opt_len;
+    }
+}
+
+void
+geneve_print(netdissect_options *ndo, const u_char *bp, u_int len)
+{
+    uint8_t ver_opt;
+    uint version;
+    uint8_t flags;
+    uint16_t prot;
+    uint32_t vni;
+    uint8_t reserved;
+    u_int opts_len;
+
+    ND_PRINT((ndo, "Geneve"));
+
+    ND_TCHECK2(*bp, 8);
+
+    ver_opt = *bp;
+    bp += 1;
+    len -= 1;
+
+    version = ver_opt >> VER_SHIFT;
+    if (version != 0) {
+        ND_PRINT((ndo, " ERROR: unknown-version %u", version));
+        return;
+    }
+
+    flags = *bp;
+    bp += 1;
+    len -= 1;
+
+    prot = EXTRACT_16BITS(bp);
+    bp += 2;
+    len -= 2;
+
+    vni = EXTRACT_24BITS(bp);
+    bp += 3;
+    len -= 3;
+
+    reserved = *bp;
+    bp += 1;
+    len -= 1;
+
+    ND_PRINT((ndo, ", Flags [%s]",
+              bittok2str_nosep(geneve_flag_values, "none", flags)));
+    ND_PRINT((ndo, ", vni 0x%x", vni));
+
+    if (reserved)
+        ND_PRINT((ndo, ", rsvd 0x%x", reserved));
+
+    if (ndo->ndo_eflag)
+        ND_PRINT((ndo, ", proto %s (0x%04x)",
+                  tok2str(ethertype_values, "unknown", prot), prot));
+
+    opts_len = (ver_opt & HDR_OPTS_LEN_MASK) * 4;
+
+    if (len < opts_len) {
+        ND_PRINT((ndo, " truncated-geneve - %u bytes missing",
+                  len - opts_len));
+        return;
+    }
+
+    ND_TCHECK2(*bp, opts_len);
+
+    if (opts_len > 0) {
+        ND_PRINT((ndo, ", options ["));
+
+        if (ndo->ndo_vflag)
+            geneve_opts_print(ndo, bp, opts_len);
+        else
+            ND_PRINT((ndo, "%u bytes", opts_len));
+
+        ND_PRINT((ndo, "]"));
+    }
+
+    bp += opts_len;
+    len -= opts_len;
+
+    if (ndo->ndo_vflag < 1)
+        ND_PRINT((ndo, ": "));
+    else
+        ND_PRINT((ndo, "\n\t"));
+
+    if (ethertype_print(ndo, prot, bp, len, len) == 0) {
+        if (prot == ETHERTYPE_TEB)
+            ether_print(ndo, bp, len, len, NULL, NULL);
+        else
+            ND_PRINT((ndo, "geneve-proto-0x%x", prot));
+    }
+
+    return;
+
+trunc:
+    ND_PRINT((ndo, " [|geneve]"));
+}
index eafdaf88748c0932196e19deb0d005c930d1b135..49097daa391967506a110436d054af082fa00a44 100644 (file)
@@ -679,6 +679,8 @@ udp_print(netdissect_options *ndo, register const u_char *bp, u_int length,
                        otv_print(ndo, (const u_char *)(up + 1), length);
                 else if (ISPORT(VXLAN_PORT))
                        vxlan_print(ndo, (const u_char *)(up + 1), length);
+                else if (ISPORT(GENEVE_PORT))
+                       geneve_print(ndo, (const u_char *)(up + 1), length);
                else {
                        if (ulen > length)
                                ND_PRINT((ndo, "UDP, bad length %u > %u",
index 55841851fd07d9d30a60d51cc9b4f2f7b9e47742..094f0f2f6bc48ea779ca25fabef3cdc06512d561 100644 (file)
@@ -257,3 +257,6 @@ isis_4-v    ISIS_p2p_adjacency.pcap         isis_4-v.out    -t -v
 # ATA-over-Ethernet tests
 aoe_1          AoE_Linux.pcap          aoe_1.out       -t
 aoe_1-v                AoE_Linux.pcap          aoe_1-v.out     -t -v
+
+# Geneve tests
+geneve-v       geneve.pcap             geneve-vv.out   -t -vv
diff --git a/tests/geneve-vv.out b/tests/geneve-vv.out
new file mode 100644 (file)
index 0000000..4412017
--- /dev/null
@@ -0,0 +1,40 @@
+IP (tos 0x0, ttl 64, id 7071, offset 0, flags [DF], proto UDP (17), length 142)
+    20.0.0.1.587 > 20.0.0.2.6081: [no cksum] Geneve, Flags [C], vni 0xb, options [class Experimental (0xffff) type 0x8a(C) len 8 data 0000000a]
+       IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto ICMP (1), length 84)
+    30.0.0.1 > 30.0.0.2: ICMP echo request, id 4349, seq 40, length 64
+IP (tos 0x0, ttl 64, id 49690, offset 0, flags [DF], proto UDP (17), length 134)
+    20.0.0.2.1 > 20.0.0.1.6081: [no cksum] Geneve, Flags [none], vni 0xb
+       IP (tos 0x0, ttl 64, id 4796, offset 0, flags [none], proto ICMP (1), length 84)
+    30.0.0.2 > 30.0.0.1: ICMP echo reply, id 4349, seq 40, length 64
+IP (tos 0x0, ttl 64, id 7072, offset 0, flags [DF], proto UDP (17), length 142)
+    20.0.0.1.587 > 20.0.0.2.6081: [no cksum] Geneve, Flags [C], vni 0xb, options [class Experimental (0xffff) type 0x8a(C) len 8 data 0000000a]
+       IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto ICMP (1), length 84)
+    30.0.0.1 > 30.0.0.2: ICMP echo request, id 4349, seq 41, length 64
+IP (tos 0x0, ttl 64, id 49691, offset 0, flags [DF], proto UDP (17), length 134)
+    20.0.0.2.1 > 20.0.0.1.6081: [no cksum] Geneve, Flags [none], vni 0xb
+       IP (tos 0x0, ttl 64, id 4797, offset 0, flags [none], proto ICMP (1), length 84)
+    30.0.0.2 > 30.0.0.1: ICMP echo reply, id 4349, seq 41, length 64
+IP (tos 0x0, ttl 64, id 7073, offset 0, flags [DF], proto UDP (17), length 142)
+    20.0.0.1.587 > 20.0.0.2.6081: [no cksum] Geneve, Flags [C], vni 0xb, options [class Experimental (0xffff) type 0x8a(C) len 8 data 0000000a]
+       IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto ICMP (1), length 84)
+    30.0.0.1 > 30.0.0.2: ICMP echo request, id 4349, seq 42, length 64
+IP (tos 0x0, ttl 64, id 49692, offset 0, flags [DF], proto UDP (17), length 134)
+    20.0.0.2.1 > 20.0.0.1.6081: [no cksum] Geneve, Flags [none], vni 0xb
+       IP (tos 0x0, ttl 64, id 4798, offset 0, flags [none], proto ICMP (1), length 84)
+    30.0.0.2 > 30.0.0.1: ICMP echo reply, id 4349, seq 42, length 64
+IP (tos 0x0, ttl 64, id 7074, offset 0, flags [DF], proto UDP (17), length 142)
+    20.0.0.1.587 > 20.0.0.2.6081: [no cksum] Geneve, Flags [C], vni 0xb, options [class Experimental (0xffff) type 0x8a(C) len 8 data 0000000a]
+       IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto ICMP (1), length 84)
+    30.0.0.1 > 30.0.0.2: ICMP echo request, id 4349, seq 43, length 64
+IP (tos 0x0, ttl 64, id 49693, offset 0, flags [DF], proto UDP (17), length 134)
+    20.0.0.2.1 > 20.0.0.1.6081: [no cksum] Geneve, Flags [none], vni 0xb
+       IP (tos 0x0, ttl 64, id 4799, offset 0, flags [none], proto ICMP (1), length 84)
+    30.0.0.2 > 30.0.0.1: ICMP echo reply, id 4349, seq 43, length 64
+IP (tos 0x0, ttl 64, id 7075, offset 0, flags [DF], proto UDP (17), length 142)
+    20.0.0.1.587 > 20.0.0.2.6081: [no cksum] Geneve, Flags [C], vni 0xb, options [class Experimental (0xffff) type 0x8a(C) len 8 data 0000000a]
+       IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto ICMP (1), length 84)
+    30.0.0.1 > 30.0.0.2: ICMP echo request, id 4349, seq 44, length 64
+IP (tos 0x0, ttl 64, id 49694, offset 0, flags [DF], proto UDP (17), length 134)
+    20.0.0.2.1 > 20.0.0.1.6081: [no cksum] Geneve, Flags [none], vni 0xb
+       IP (tos 0x0, ttl 64, id 4800, offset 0, flags [none], proto ICMP (1), length 84)
+    30.0.0.2 > 30.0.0.1: ICMP echo reply, id 4349, seq 44, length 64
diff --git a/tests/geneve.pcap b/tests/geneve.pcap
new file mode 100644 (file)
index 0000000..9844c56
Binary files /dev/null and b/tests/geneve.pcap differ
diff --git a/udp.h b/udp.h
index 1df7e646a8c74cb396ad4eb9c492e3e46bb5f56d..09724523033ef95318027d919e901c261d51cf96 100644 (file)
--- a/udp.h
+++ b/udp.h
@@ -91,6 +91,7 @@ struct udphdr {
 #define LWAPP_CONTROL_PORT      12223 /* draft-ohara-capwap-lwapp-04.txt */
 #define OTV_PORT                8472  /* draft-hasmit-otv-04 */
 #define VXLAN_PORT              4789  /* draft-mahalingam-dutt-dcops-vxlan-04 */
+#define GENEVE_PORT             6081  /* draft-gross-geneve-02 */
 
 #ifdef INET6
 #define RIPNG_PORT 521         /*XXX*/