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

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