From b3ba57ac9423a9285ace015882f2783d8fddc7b8 Mon Sep 17 00:00:00 2001
From: Christian Poessinger <christian@poessinger.com>
Date: Fri, 9 Apr 2021 13:10:00 +0200
Subject: iproute2: patches: add fix for erspan JSON output

See thread [1] for more infomration.

[1] https://lore.kernel.org/netdev/3ac544c09842410fb863b332917a03ad@poessinger.com/
---
 packages/iproute2/Jenkinsfile                      |  2 +-
 packages/iproute2/build.sh                         | 20 ++++++++
 .../0001-erspan-erspan6-fix-JSON-output.patch      | 56 ++++++++++++++++++++++
 3 files changed, 77 insertions(+), 1 deletion(-)
 create mode 100755 packages/iproute2/build.sh
 create mode 100644 packages/iproute2/patches/0001-erspan-erspan6-fix-JSON-output.patch

diff --git a/packages/iproute2/Jenkinsfile b/packages/iproute2/Jenkinsfile
index b5654439..20ec19c7 100644
--- a/packages/iproute2/Jenkinsfile
+++ b/packages/iproute2/Jenkinsfile
@@ -25,7 +25,7 @@ def pkgList = [
     ['name': 'iproute2',
      'scmCommit': 'debian/5.10.0-4_bpo10+1',
      'scmUrl': 'https://salsa.debian.org/debian/iproute2',
-     'buildCmd': 'dpkg-buildpackage -uc -us -tc -b -d'],
+     'buildCmd': 'cd ..; ./build.sh'],
 ]
 
 // Start package build using library function from https://github.com/vyos/vyos-build
diff --git a/packages/iproute2/build.sh b/packages/iproute2/build.sh
new file mode 100755
index 00000000..09babb95
--- /dev/null
+++ b/packages/iproute2/build.sh
@@ -0,0 +1,20 @@
+#!/bin/sh
+CWD=$(pwd)
+set -e
+
+SRC=iproute2
+if [ ! -d ${SRC} ]; then
+    echo "Source directory does not exists, please 'git clone'"
+    exit 1
+fi
+
+cd ${SRC}
+PATCH_DIR=${CWD}/patches
+for patch in $(ls ${PATCH_DIR})
+do
+    echo "I: Apply patch: ${PATCH_DIR}/${patch}"
+    patch -p1 < ${PATCH_DIR}/${patch}
+done
+
+echo "I: Build Debian Package"
+dpkg-buildpackage -uc -us -tc -b -d
diff --git a/packages/iproute2/patches/0001-erspan-erspan6-fix-JSON-output.patch b/packages/iproute2/patches/0001-erspan-erspan6-fix-JSON-output.patch
new file mode 100644
index 00000000..e21c13c0
--- /dev/null
+++ b/packages/iproute2/patches/0001-erspan-erspan6-fix-JSON-output.patch
@@ -0,0 +1,56 @@
+From 50d6a22e0c1368bcc662bbfea75ce21378825b0d Mon Sep 17 00:00:00 2001
+From: Christian Poessinger <christian@poessinger.com>
+Date: Fri, 9 Apr 2021 12:45:00 +0200
+Subject: [PATCH] erspan/erspan6: fix JSON output
+
+The format for erspan/erspan6 output is not valid JSON, as on version 2 a
+valueless key was presented. The direction should be value and erspan_dir
+should be the key.
+
+Fixes: 289763626721 ("erspan: add erspan version II support")
+Cc: u9012063@gmail.com
+Cc: Stephen Hemminger <stephen@networkplumber.org>
+Reported-by: Christian Poessinger <christian@poessinger.com>
+Signed-off-by: Christian Poessinger <christian@poessinger.com>
+---
+ ip/link_gre.c  | 4 ++--
+ ip/link_gre6.c | 4 ++--
+ 2 files changed, 4 insertions(+), 4 deletions(-)
+
+diff --git a/ip/link_gre.c b/ip/link_gre.c
+index 0461e5d0..6d4a8be8 100644
+--- a/ip/link_gre.c
++++ b/ip/link_gre.c
+@@ -536,10 +536,10 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
+ 
+ 		if (erspan_dir == 0)
+ 			print_string(PRINT_ANY, "erspan_dir",
+-				     "erspan_dir ingress ", NULL);
++				     "erspan_dir %s ", "ingress");
+ 		else
+ 			print_string(PRINT_ANY, "erspan_dir",
+-				     "erspan_dir egress ", NULL);
++				     "erspan_dir %s ", "egress");
+ 	}
+ 
+ 	if (tb[IFLA_GRE_ERSPAN_HWID]) {
+diff --git a/ip/link_gre6.c b/ip/link_gre6.c
+index 9d270f4b..f33598af 100644
+--- a/ip/link_gre6.c
++++ b/ip/link_gre6.c
+@@ -594,10 +594,10 @@ static void gre_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
+ 
+ 		if (erspan_dir == 0)
+ 			print_string(PRINT_ANY, "erspan_dir",
+-				     "erspan_dir ingress ", NULL);
++				     "erspan_dir %s ", "ingress");
+ 		else
+ 			print_string(PRINT_ANY, "erspan_dir",
+-				     "erspan_dir egress ", NULL);
++				     "erspan_dir %s ", "egress");
+ 	}
+ 
+ 	if (tb[IFLA_GRE_ERSPAN_HWID]) {
+-- 
+2.20.1
+
-- 
cgit v1.2.3