]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Add printing function for Generic Protocol Extension for VXLAN
authorbugyo <[email protected]>
Sun, 15 Nov 2015 16:24:19 +0000 (16:24 +0000)
committerFrancois-Xavier Le Bail <[email protected]>
Tue, 22 Mar 2016 15:59:03 +0000 (16:59 +0100)
and Network Service Header.

This code stands for following internet drafts:

- VXLAN GPE: draft-ietf-nvo3-vxlan-gpe-01
- NSH: draft-ietf-sfc-nsh-01

12 files changed:
Makefile.in
netdissect.h
print-nsh.c [new file with mode: 0644]
print-udp.c
print-vxlan-gpe.c [new file with mode: 0644]
tests/TESTLIST
tests/nsh-over-vxlan-gpe-v.out [new file with mode: 0644]
tests/nsh-over-vxlan-gpe-vv.out [new file with mode: 0644]
tests/nsh-over-vxlan-gpe-vvv.out [new file with mode: 0644]
tests/nsh-over-vxlan-gpe.out [new file with mode: 0644]
tests/nsh-over-vxlan-gpe.pcap [new file with mode: 0644]
udp.h

index db50bf74b3cd21d2f5d94d1fee0d6d90cf61bc69..0bd206670edfa39ed8778b44f3a89d99e6daf2f9 100644 (file)
@@ -225,6 +225,8 @@ LIBNETDISSECT_SRC=\
        print-vrrp.c \
        print-vtp.c \
        print-vxlan.c \
+       print-vxlan-gpe.c \
+       print-nsh.c \
        print-wb.c \
        print-zephyr.c \
        print-zeromq.c \
index 8a6b01880152af0dd04451f517e63e33a32f543a..87f5e3ece6e672c5192cd1638f864975098d5909 100644 (file)
@@ -585,10 +585,12 @@ extern void vqp_print(netdissect_options *, register const u_char *, register u_
 extern void vrrp_print(netdissect_options *, const u_char *, u_int, const u_char *, int);
 extern void vtp_print(netdissect_options *, const u_char *, u_int);
 extern void vxlan_print(netdissect_options *, const u_char *, u_int);
+extern void vxlan_gpe_print(netdissect_options *ndo, const u_char *bp, u_int len);
 extern void wb_print(netdissect_options *, const void *, u_int);
 extern void zephyr_print(netdissect_options *, const u_char *, int);
 extern void zmtp1_print(netdissect_options *, const u_char *, u_int);
 extern void zmtp1_print_datagram(netdissect_options *, const u_char *, const u_int);
+extern void nsh_print(netdissect_options *ndo, const u_char *bp, u_int len);
 
 /* checksum routines */
 extern void init_checksum(void);
diff --git a/print-nsh.c b/print-nsh.c
new file mode 100644 (file)
index 0000000..a5b464e
--- /dev/null
@@ -0,0 +1,174 @@
+/* Copyright (c) 2015, bugyo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <netdissect-stdinc.h>
+
+#include "netdissect.h"
+#include "extract.h"
+
+static const char tstr[] = " [|NSH]";
+static const struct tok nsh_flags [] = {
+    { 0x20, "O" },
+    { 0x10, "C" },
+    { 0, NULL }
+};
+
+#define NSH_BASE_HDR_LEN 4
+#define NSH_SERVICE_PATH_HDR_LEN 4
+#define NSH_HDR_WORD_SIZE 4
+
+/*
+ * NSH, draft-ietf-sfc-nsh-01 Network Service Header
+ */
+
+void
+nsh_print(netdissect_options *ndo, const u_char *bp, u_int len)
+{
+    int n, vn;
+    uint8_t ver;
+    uint8_t flags;
+    uint8_t length;
+    uint8_t md_type;
+    uint8_t next_protocol;
+    uint32_t service_path_id;
+    uint8_t service_index;
+    uint32_t ctx;
+    uint16_t tlv_class;
+    uint8_t tlv_type;
+    uint8_t tlv_len;
+    u_int next_len;
+
+    /* print Base Header and Service Path Header */
+    if (len < NSH_BASE_HDR_LEN + NSH_SERVICE_PATH_HDR_LEN)
+        goto trunc;
+
+    ND_TCHECK2(*bp, NSH_BASE_HDR_LEN + NSH_SERVICE_PATH_HDR_LEN);
+
+    ver = (uint8_t)(*bp >> 6);
+    flags = *bp;
+    bp += 1;
+    length = *bp;
+    bp += 1;
+    md_type = *bp;
+    bp += 1;
+    next_protocol = *bp;
+    bp += 1;
+    service_path_id = EXTRACT_24BITS(bp);
+    bp += 3;
+    service_index = *bp;
+    bp += 1;
+
+    ND_PRINT((ndo, "NSH, "));
+    if (ndo->ndo_vflag > 1) {
+        ND_PRINT((ndo, "ver %d, ", ver));
+    }
+    ND_PRINT((ndo, "flags [%s], ", bittok2str_nosep(nsh_flags, "none", flags)));
+    if (ndo->ndo_vflag > 2) {
+        ND_PRINT((ndo, "length %d, ", length));
+        ND_PRINT((ndo, "md type 0x%x, ", md_type));
+    }
+    if (ndo->ndo_vflag > 1) {
+        ND_PRINT((ndo, "next-protocol 0x%x, ", next_protocol));
+    }
+    ND_PRINT((ndo, "service-path-id 0x%06x, ", service_path_id));
+    ND_PRINT((ndo, "service-index 0x%x", service_index));
+
+    /* print Context Headers */
+    if (len < length * NSH_HDR_WORD_SIZE)
+        goto trunc;
+
+    ND_TCHECK2(*bp, length * NSH_HDR_WORD_SIZE);
+
+    if (ndo->ndo_vflag > 2) {
+        if (md_type == 0x01) {
+            for (n = 0; n < length - 2; n++) {
+                ctx = EXTRACT_32BITS(bp);
+                bp += NSH_HDR_WORD_SIZE;
+                ND_PRINT((ndo, "\n        Context[%02d]: 0x%08x", n, ctx));
+            }
+        }
+        else if (md_type == 0x02) {
+            n = 0;
+            while (n < length - 2) {
+                tlv_class = EXTRACT_16BITS(bp);
+                bp += 2;
+                tlv_type  = *bp;
+                bp += 1;
+                tlv_len   = *bp;
+                bp += 1;
+
+                ND_PRINT((ndo, "\n        TLV Class %d, Type %d, Len %d",
+                          tlv_class, tlv_type, tlv_len));
+
+                n += 1;
+
+                if (length - 2 < n + tlv_len) {
+                    ND_PRINT((ndo, " ERROR: invalid-tlv-length"));
+                    return;
+                }
+
+                for (vn = 0; vn < tlv_len; vn++) {
+                    ctx = EXTRACT_32BITS(bp);
+                    bp += NSH_HDR_WORD_SIZE;
+                    ND_PRINT((ndo, "\n            Value[%02d]: 0x%08x", vn, ctx));
+                }
+                n += tlv_len;
+            }
+        }
+        else {
+            ND_PRINT((ndo, "ERROR: unknown-next-protocol"));
+            return;
+        }
+    }
+    else {
+        bp += (length - 2) * NSH_HDR_WORD_SIZE;
+    }
+    ND_PRINT((ndo, ndo->ndo_vflag ? "\n    " : ": "));
+
+    /* print Next Protocol */
+    next_len = len - length * NSH_HDR_WORD_SIZE;
+    switch (next_protocol) {
+    case 0x1:
+        ip_print(ndo, bp, next_len);
+        break;
+    case 0x2:
+        ip6_print(ndo, bp, next_len);
+        break;
+    case 0x3:
+        ether_print(ndo, bp, next_len, next_len, NULL, NULL);
+        break;
+    default:
+        ND_PRINT((ndo, "ERROR: unknown-next-protocol"));
+        return;
+    }
+
+    return;
+
+trunc:
+    ND_PRINT((ndo, "%s", tstr));
+}
+
index 2fc603ae6e690c83e4f23d478dbb40ac52e22862..bf7195fac4f265d35c0ad6a4fb91f8bec0a5f5f4 100644 (file)
@@ -646,6 +646,8 @@ udp_print(netdissect_options *ndo, register const u_char *bp, u_int length,
                        geneve_print(ndo, (const u_char *)(up + 1), length);
                else if (IS_SRC_OR_DST_PORT(LISP_CONTROL_PORT))
                        lisp_print(ndo, (const u_char *)(up + 1), length);
+               else if (IS_SRC_OR_DST_PORT(VXLAN_GPE_PORT))
+                       vxlan_gpe_print(ndo, (const u_char *)(up + 1), length);
                else if (ND_TTEST(((const struct LAP *)cp)->type) &&
                    ((const struct LAP *)cp)->type == lapDDP &&
                    (atalk_port(sport) || atalk_port(dport))) {
diff --git a/print-vxlan-gpe.c b/print-vxlan-gpe.c
new file mode 100644 (file)
index 0000000..92be1e2
--- /dev/null
@@ -0,0 +1,109 @@
+/* Copyright (c) 2015, bugyo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <netdissect-stdinc.h>
+
+#include "netdissect.h"
+#include "extract.h"
+
+static const char tstr[] = " [|VXLAN-GPE]";
+static const struct tok vxlan_gpe_flags [] = {
+    { 0x08, "I" },
+    { 0x04, "P" },
+    { 0x01, "O" },
+    { 0, NULL }
+};
+
+#define VXLAN_GPE_HDR_LEN 8
+
+/*
+ * VXLAN GPE header, draft-ietf-nvo3-vxlan-gpe-01
+ *                   Generic Protocol Extension for VXLAN
+ *
+ *     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
+ *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *    |R|R|Ver|I|P|R|O|       Reserved                |Next Protocol  |
+ *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *    |                VXLAN Network Identifier (VNI) |   Reserved    |
+ *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ */
+
+void
+vxlan_gpe_print(netdissect_options *ndo, const u_char *bp, u_int len)
+{
+    uint8_t flags;
+    uint8_t next_protocol;
+    uint32_t vni;
+
+    if (len < VXLAN_GPE_HDR_LEN)
+        goto trunc;
+
+    ND_TCHECK2(*bp, VXLAN_GPE_HDR_LEN);
+
+    flags = *bp;
+    bp += 3;
+
+    next_protocol = *bp;
+    bp += 1;
+
+    vni = EXTRACT_24BITS(bp);
+    bp += 4;
+
+    ND_PRINT((ndo, "VXLAN-GPE, "));
+    ND_PRINT((ndo, "flags [%s], ",
+              bittok2str_nosep(vxlan_gpe_flags, "none", flags)));
+    ND_PRINT((ndo, "vni %u", vni));
+    ND_PRINT((ndo, ndo->ndo_vflag ? "\n    " : ": "));
+
+    switch (next_protocol) {
+    case 0x1:
+        ip_print(ndo, bp, len - 8);
+        break;
+    case 0x2:
+        ip6_print(ndo, bp, len - 8);
+        break;
+    case 0x3:
+        ether_print(ndo, bp, len - 8, len - 8, NULL, NULL);
+        break;
+    case 0x4:
+        nsh_print(ndo, bp, len - 8);
+        break;
+    case 0x5:
+        mpls_print(ndo, bp, len - 8);
+        break;
+    default:
+        ND_PRINT((ndo, "ERROR: unknown-next-protocol"));
+        return;
+    }
+
+       return;
+
+trunc:
+       ND_PRINT((ndo, "%s", tstr));
+}
+
index a732040605631f97bfb3ed4b922f1deb0824dc04..bc7c58c71efcce2c5490bd014b5c842686a2f8fe 100644 (file)
@@ -336,3 +336,9 @@ pcap-invalid-version-2 pcap-invalid-version-2.pcap pcap-invalid-version-2.out -t
 # pcap-ng invalid version (first: version = 0.1 ; second: version = 1.1)
 pcap-ng-invalid-vers-1 pcap-ng-invalid-vers-1.pcap pcap-ng-invalid-vers-1.out -t
 pcap-ng-invalid-vers-2 pcap-ng-invalid-vers-2.pcap pcap-ng-invalid-vers-2.out -t
+
+# NSH over VxLAN-GPE
+nsh-over-vxlan-gpe     nsh-over-vxlan-gpe.pcap nsh-over-vxlan-gpe.out     -t
+nsh-over-vxlan-gpe-v   nsh-over-vxlan-gpe.pcap nsh-over-vxlan-gpe-v.out   -t -v
+nsh-over-vxlan-gpe-vv  nsh-over-vxlan-gpe.pcap nsh-over-vxlan-gpe-vv.out  -t -vv
+nsh-over-vxlan-gpe-vvv nsh-over-vxlan-gpe.pcap nsh-over-vxlan-gpe-vvv.out -t -vvv
diff --git a/tests/nsh-over-vxlan-gpe-v.out b/tests/nsh-over-vxlan-gpe-v.out
new file mode 100644 (file)
index 0000000..f8db332
--- /dev/null
@@ -0,0 +1,5 @@
+IP (tos 0x0, ttl 64, id 16419, offset 0, flags [DF], proto UDP (17), length 92)
+    127.0.0.1.4790 > 127.0.0.1.4790: VXLAN-GPE, flags [IP], vni 16777215
+    NSH, flags [OC], service-path-id 0xffffff, service-index 0xff
+    IP (tos 0x0, ttl 255, id 54321, offset 0, flags [none], proto UDP (17), length 32)
+    192.168.0.1.10000 > 192.168.0.2.20000: UDP, length 4
diff --git a/tests/nsh-over-vxlan-gpe-vv.out b/tests/nsh-over-vxlan-gpe-vv.out
new file mode 100644 (file)
index 0000000..5233701
--- /dev/null
@@ -0,0 +1,5 @@
+IP (tos 0x0, ttl 64, id 16419, offset 0, flags [DF], proto UDP (17), length 92)
+    127.0.0.1.4790 > 127.0.0.1.4790: [udp sum ok] VXLAN-GPE, flags [IP], vni 16777215
+    NSH, ver 0, flags [OC], next-protocol 0x1, service-path-id 0xffffff, service-index 0xff
+    IP (tos 0x0, ttl 255, id 54321, offset 0, flags [none], proto UDP (17), length 32)
+    192.168.0.1.10000 > 192.168.0.2.20000: [udp sum ok] UDP, length 4
diff --git a/tests/nsh-over-vxlan-gpe-vvv.out b/tests/nsh-over-vxlan-gpe-vvv.out
new file mode 100644 (file)
index 0000000..f8af283
--- /dev/null
@@ -0,0 +1,9 @@
+IP (tos 0x0, ttl 64, id 16419, offset 0, flags [DF], proto UDP (17), length 92)
+    127.0.0.1.4790 > 127.0.0.1.4790: [udp sum ok] VXLAN-GPE, flags [IP], vni 16777215
+    NSH, ver 0, flags [OC], length 6, md type 0x2, next-protocol 0x1, service-path-id 0xffffff, service-index 0xff
+        TLV Class 1, Type 2, Len 1
+            Value[00]: 0x12345678
+        TLV Class 2, Type 3, Len 1
+            Value[00]: 0x12345678
+    IP (tos 0x0, ttl 255, id 54321, offset 0, flags [none], proto UDP (17), length 32)
+    192.168.0.1.10000 > 192.168.0.2.20000: [udp sum ok] UDP, length 4
diff --git a/tests/nsh-over-vxlan-gpe.out b/tests/nsh-over-vxlan-gpe.out
new file mode 100644 (file)
index 0000000..3348a42
--- /dev/null
@@ -0,0 +1 @@
+IP 127.0.0.1.4790 > 127.0.0.1.4790: VXLAN-GPE, flags [IP], vni 16777215: NSH, flags [OC], service-path-id 0xffffff, service-index 0xff: IP 192.168.0.1.10000 > 192.168.0.2.20000: UDP, length 4
diff --git a/tests/nsh-over-vxlan-gpe.pcap b/tests/nsh-over-vxlan-gpe.pcap
new file mode 100644 (file)
index 0000000..0cc3b67
Binary files /dev/null and b/tests/nsh-over-vxlan-gpe.pcap differ
diff --git a/udp.h b/udp.h
index 0e7cf9702aa1f1752ceb2372e474523089ef0076..264a938ac24834562179c5ff4f576a30c03de0f4 100644 (file)
--- a/udp.h
+++ b/udp.h
@@ -263,6 +263,9 @@ struct udphdr {
 #ifndef VXLAN_PORT
 #define VXLAN_PORT                     4789    /* RFC 7348 */
 #endif
+#ifndef VXLAN_GPE_PORT
+#define VXLAN_GPE_PORT                 4790    /* draft-ietf-nvo3-vxlan-gpe-01 */
+#endif
 #ifndef SIP_DS_PORT
 #define SIP_DS_PORT                    5059    /*XXX*/
 #endif