Blame SOURCES/0025-iproute_lwtunnel-add-options-support-for-vxlan-metad.patch

0ac2f3
From 873511fb86756c40631f80963356179627d69d49 Mon Sep 17 00:00:00 2001
0ac2f3
From: Andrea Claudi <aclaudi@redhat.com>
0ac2f3
Date: Thu, 4 Jun 2020 21:43:01 +0200
0ac2f3
Subject: [PATCH] iproute_lwtunnel: add options support for vxlan metadata
0ac2f3
0ac2f3
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1830485
0ac2f3
Upstream Status: unknown commit b1bc0f3892222
0ac2f3
0ac2f3
commit b1bc0f38922220b379ed39552a5e2a7cf9dccd92
0ac2f3
Author: Xin Long <lucien.xin@gmail.com>
0ac2f3
Date:   Mon Apr 27 18:27:46 2020 +0800
0ac2f3
0ac2f3
    iproute_lwtunnel: add options support for vxlan metadata
0ac2f3
0ac2f3
    This patch is to add LWTUNNEL_IP_OPTS_VXLAN's parse and print to implement
0ac2f3
    vxlan options support in iproute_lwtunnel.
0ac2f3
0ac2f3
    Option is expressed a number for gbp only, and vxlan doesn't support
0ac2f3
    multiple options.
0ac2f3
0ac2f3
    With this patch, users can add and dump vxlan options like:
0ac2f3
0ac2f3
      # ip netns add a
0ac2f3
      # ip netns add b
0ac2f3
      # ip -n a link add eth0 type veth peer name eth0 netns b
0ac2f3
      # ip -n a link set eth0 up
0ac2f3
      # ip -n b link set eth0 up
0ac2f3
      # ip -n a addr add 10.1.0.1/24 dev eth0
0ac2f3
      # ip -n b addr add 10.1.0.2/24 dev eth0
0ac2f3
      # ip -n b link add vxlan1 type vxlan id 1 local 10.1.0.2 \
0ac2f3
        remote 10.1.0.1 dev eth0 ttl 64 gbp
0ac2f3
      # ip -n b addr add 1.1.1.1/24 dev vxlan1
0ac2f3
      # ip -n b link set vxlan1 up
0ac2f3
      # ip -n b route add 2.1.1.0/24 dev vxlan1
0ac2f3
      # ip -n a link add vxlan1 type vxlan local 10.1.0.1 dev eth0 ttl 64 \
0ac2f3
        gbp external
0ac2f3
      # ip -n a addr add 2.1.1.1/24 dev vxlan1
0ac2f3
      # ip -n a link set vxlan1 up
0ac2f3
      # ip -n a route add 1.1.1.0/24 encap ip id 1 \
0ac2f3
        vxlan_opts 1110 dst 10.1.0.2 dev vxlan1
0ac2f3
      # ip -n a route show
0ac2f3
      # ip netns exec a ping 1.1.1.1 -c 1
0ac2f3
0ac2f3
       1.1.1.0/24  encap ip id 1 src 0.0.0.0 dst 10.1.0.2 ttl 0 tos 0
0ac2f3
         vxlan_opts 1110 dev vxlan1 scope link
0ac2f3
0ac2f3
       PING 1.1.1.1 (1.1.1.1) 56(84) bytes of data.
0ac2f3
       64 bytes from 1.1.1.1: icmp_seq=1 ttl=64 time=0.111 ms
0ac2f3
0ac2f3
    v1->v2:
0ac2f3
      - improve the changelog.
0ac2f3
      - get_u32 with base = 0 for gbp.
0ac2f3
      - use PRINT_ANY to support dumping with json format.
0ac2f3
    v2->v3:
0ac2f3
      - implement proper JSON array for opts.
0ac2f3
    v3->v4:
0ac2f3
      - keep the same format between input and output, json and non json.
0ac2f3
      - print gbp as uint.
0ac2f3
0ac2f3
    Signed-off-by: Xin Long <lucien.xin@gmail.com>
0ac2f3
    Signed-off-by: David Ahern <dsahern@gmail.com>
0ac2f3
---
0ac2f3
 ip/iproute_lwtunnel.c | 68 +++++++++++++++++++++++++++++++++++++++++++
0ac2f3
 1 file changed, 68 insertions(+)
0ac2f3
0ac2f3
diff --git a/ip/iproute_lwtunnel.c b/ip/iproute_lwtunnel.c
0ac2f3
index 76d906c47c44f..17514dcad9219 100644
0ac2f3
--- a/ip/iproute_lwtunnel.c
0ac2f3
+++ b/ip/iproute_lwtunnel.c
0ac2f3
@@ -330,6 +330,26 @@ static void lwtunnel_print_geneve_opts(struct rtattr *attr)
0ac2f3
 	close_json_array(PRINT_JSON, name);
0ac2f3
 }
0ac2f3
 
0ac2f3
+static void lwtunnel_print_vxlan_opts(struct rtattr *attr)
0ac2f3
+{
0ac2f3
+	struct rtattr *tb[LWTUNNEL_IP_OPT_VXLAN_MAX + 1];
0ac2f3
+	struct rtattr *i = RTA_DATA(attr);
0ac2f3
+	int rem = RTA_PAYLOAD(attr);
0ac2f3
+	char *name = "vxlan_opts";
0ac2f3
+	__u32 gbp;
0ac2f3
+
0ac2f3
+	parse_rtattr(tb, LWTUNNEL_IP_OPT_VXLAN_MAX, i, rem);
0ac2f3
+	gbp = rta_getattr_u32(tb[LWTUNNEL_IP_OPT_VXLAN_GBP]);
0ac2f3
+
0ac2f3
+	print_nl();
0ac2f3
+	print_string(PRINT_FP, name, "\t%s ", name);
0ac2f3
+	open_json_array(PRINT_JSON, name);
0ac2f3
+	open_json_object(NULL);
0ac2f3
+	print_uint(PRINT_ANY, "gbp", "%u ", gbp);
0ac2f3
+	close_json_object();
0ac2f3
+	close_json_array(PRINT_JSON, name);
0ac2f3
+}
0ac2f3
+
0ac2f3
 static void lwtunnel_print_opts(struct rtattr *attr)
0ac2f3
 {
0ac2f3
 	struct rtattr *tb_opt[LWTUNNEL_IP_OPTS_MAX + 1];
0ac2f3
@@ -337,6 +357,8 @@ static void lwtunnel_print_opts(struct rtattr *attr)
0ac2f3
 	parse_rtattr_nested(tb_opt, LWTUNNEL_IP_OPTS_MAX, attr);
0ac2f3
 	if (tb_opt[LWTUNNEL_IP_OPTS_GENEVE])
0ac2f3
 		lwtunnel_print_geneve_opts(tb_opt[LWTUNNEL_IP_OPTS_GENEVE]);
0ac2f3
+	else if (tb_opt[LWTUNNEL_IP_OPTS_VXLAN])
0ac2f3
+		lwtunnel_print_vxlan_opts(tb_opt[LWTUNNEL_IP_OPTS_VXLAN]);
0ac2f3
 }
0ac2f3
 
0ac2f3
 static void print_encap_ip(FILE *fp, struct rtattr *encap)
0ac2f3
@@ -935,6 +957,22 @@ static int lwtunnel_parse_geneve_opts(char *str, size_t len, struct rtattr *rta)
0ac2f3
 	return 0;
0ac2f3
 }
0ac2f3
 
0ac2f3
+static int lwtunnel_parse_vxlan_opts(char *str, size_t len, struct rtattr *rta)
0ac2f3
+{
0ac2f3
+	struct rtattr *nest;
0ac2f3
+	__u32 gbp;
0ac2f3
+	int err;
0ac2f3
+
0ac2f3
+	nest = rta_nest(rta, len, LWTUNNEL_IP_OPTS_VXLAN | NLA_F_NESTED);
0ac2f3
+	err = get_u32(&gbp, str, 0);
0ac2f3
+	if (err)
0ac2f3
+		return err;
0ac2f3
+	rta_addattr32(rta, len, LWTUNNEL_IP_OPT_VXLAN_GBP, gbp);
0ac2f3
+
0ac2f3
+	rta_nest_end(rta, nest);
0ac2f3
+	return 0;
0ac2f3
+}
0ac2f3
+
0ac2f3
 static int parse_encap_ip(struct rtattr *rta, size_t len,
0ac2f3
 			  int *argcp, char ***argvp)
0ac2f3
 {
0ac2f3
@@ -1006,6 +1044,21 @@ static int parse_encap_ip(struct rtattr *rta, size_t len,
0ac2f3
 				invarg("\"geneve_opts\" value is invalid\n",
0ac2f3
 				       *argv);
0ac2f3
 			rta_nest_end(rta, nest);
0ac2f3
+		} else if (strcmp(*argv, "vxlan_opts") == 0) {
0ac2f3
+			struct rtattr *nest;
0ac2f3
+
0ac2f3
+			if (opts_ok++)
0ac2f3
+				duparg2("opts", *argv);
0ac2f3
+
0ac2f3
+			NEXT_ARG();
0ac2f3
+
0ac2f3
+			nest = rta_nest(rta, len,
0ac2f3
+					LWTUNNEL_IP_OPTS | NLA_F_NESTED);
0ac2f3
+			ret = lwtunnel_parse_vxlan_opts(*argv, len, rta);
0ac2f3
+			if (ret)
0ac2f3
+				invarg("\"vxlan_opts\" value is invalid\n",
0ac2f3
+				       *argv);
0ac2f3
+			rta_nest_end(rta, nest);
0ac2f3
 		} else if (strcmp(*argv, "key") == 0) {
0ac2f3
 			if (key_ok++)
0ac2f3
 				duparg2("key", *argv);
0ac2f3
@@ -1190,6 +1243,21 @@ static int parse_encap_ip6(struct rtattr *rta, size_t len,
0ac2f3
 				invarg("\"geneve_opts\" value is invalid\n",
0ac2f3
 				       *argv);
0ac2f3
 			rta_nest_end(rta, nest);
0ac2f3
+		} else if (strcmp(*argv, "vxlan_opts") == 0) {
0ac2f3
+			struct rtattr *nest;
0ac2f3
+
0ac2f3
+			if (opts_ok++)
0ac2f3
+				duparg2("opts", *argv);
0ac2f3
+
0ac2f3
+			NEXT_ARG();
0ac2f3
+
0ac2f3
+			nest = rta_nest(rta, len,
0ac2f3
+					LWTUNNEL_IP_OPTS | NLA_F_NESTED);
0ac2f3
+			ret = lwtunnel_parse_vxlan_opts(*argv, len, rta);
0ac2f3
+			if (ret)
0ac2f3
+				invarg("\"vxlan_opts\" value is invalid\n",
0ac2f3
+				       *argv);
0ac2f3
+			rta_nest_end(rta, nest);
0ac2f3
 		} else if (strcmp(*argv, "key") == 0) {
0ac2f3
 			if (key_ok++)
0ac2f3
 				duparg2("key", *argv);
0ac2f3
-- 
0ac2f3
2.26.2
0ac2f3