naccyde / rpms / iproute

Forked from rpms/iproute 9 months ago
Clone

Blame SOURCES/0008-tc-flower-fix-json-output-with-mpls-lse.patch

26f871
From 52754e4b7d4b52e9852869d7e2f6af1b890677f1 Mon Sep 17 00:00:00 2001
26f871
Message-Id: <52754e4b7d4b52e9852869d7e2f6af1b890677f1.1611877215.git.aclaudi@redhat.com>
26f871
In-Reply-To: <cb7ce51cc1abd7b98370b903ec96205ebfe48661.1611877215.git.aclaudi@redhat.com>
26f871
References: <cb7ce51cc1abd7b98370b903ec96205ebfe48661.1611877215.git.aclaudi@redhat.com>
26f871
From: Andrea Claudi <aclaudi@redhat.com>
26f871
Date: Fri, 29 Jan 2021 00:35:04 +0100
26f871
Subject: [PATCH] tc: flower: fix json output with mpls lse
26f871
26f871
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1885770
26f871
Upstream Status: unknown commit 676a1a70
26f871
26f871
commit 676a1a708f8e99d6a4faa3de8a093f8f8c14b9da
26f871
Author: Guillaume Nault <gnault@redhat.com>
26f871
Date:   Tue Jan 12 11:30:53 2021 +0100
26f871
26f871
    tc: flower: fix json output with mpls lse
26f871
26f871
    The json output of the TCA_FLOWER_KEY_MPLS_OPTS attribute was invalid.
26f871
26f871
    Example:
26f871
26f871
      $ tc filter add dev eth0 ingress protocol mpls_uc flower mpls \
26f871
          lse depth 1 label 100                                     \
26f871
          lse depth 2 label 200
26f871
26f871
      $ tc -json filter show dev eth0 ingress
26f871
        ...{"eth_type":"8847",
26f871
            "  mpls":["    lse":["depth":1,"label":100],
26f871
                      "    lse":["depth":2,"label":200]]}...
26f871
26f871
    This is invalid as the arrays, introduced by "[", can't contain raw
26f871
    string:value pairs. Those must be enclosed into "{}" to form valid json
26f871
    ojects. Also, there are spurious whitespaces before the mpls and lse
26f871
    strings because of the indentation used for normal output.
26f871
26f871
    Fix this by putting all LSE parameters (depth, label, tc, bos and ttl)
26f871
    into the same json object. The "mpls" key now directly contains a list
26f871
    of such objects.
26f871
26f871
    Also, handle strings differently for normal and json output, so that
26f871
    json strings don't get spurious indentation whitespaces.
26f871
26f871
    Normal output isn't modified.
26f871
    The json output now looks like:
26f871
26f871
      $ tc -json filter show dev eth0 ingress
26f871
        ...{"eth_type":"8847",
26f871
            "mpls":[{"depth":1,"label":100},
26f871
                    {"depth":2,"label":200}]}...
26f871
26f871
    Fixes: eb09a15c12fb ("tc: flower: support multiple MPLS LSE match")
26f871
    Signed-off-by: Guillaume Nault <gnault@redhat.com>
26f871
    Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
26f871
---
26f871
 tc/f_flower.c | 16 +++++++++-------
26f871
 1 file changed, 9 insertions(+), 7 deletions(-)
26f871
26f871
diff --git a/tc/f_flower.c b/tc/f_flower.c
26f871
index 00c919fd..27731078 100644
26f871
--- a/tc/f_flower.c
26f871
+++ b/tc/f_flower.c
26f871
@@ -2476,7 +2476,7 @@ static void flower_print_u32(const char *name, struct rtattr *attr)
26f871
 	print_uint(PRINT_ANY, name, namefrm, rta_getattr_u32(attr));
26f871
 }
26f871
 
26f871
-static void flower_print_mpls_opt_lse(const char *name, struct rtattr *lse)
26f871
+static void flower_print_mpls_opt_lse(struct rtattr *lse)
26f871
 {
26f871
 	struct rtattr *tb[TCA_FLOWER_KEY_MPLS_OPT_LSE_MAX + 1];
26f871
 	struct rtattr *attr;
26f871
@@ -2493,7 +2493,8 @@ static void flower_print_mpls_opt_lse(const char *name, struct rtattr *lse)
26f871
 		     RTA_PAYLOAD(lse));
26f871
 
26f871
 	print_nl();
26f871
-	open_json_array(PRINT_ANY, name);
26f871
+	print_string(PRINT_FP, NULL, "    lse", NULL);
26f871
+	open_json_object(NULL);
26f871
 	attr = tb[TCA_FLOWER_KEY_MPLS_OPT_LSE_DEPTH];
26f871
 	if (attr)
26f871
 		print_hhu(PRINT_ANY, "depth", " depth %u",
26f871
@@ -2511,10 +2512,10 @@ static void flower_print_mpls_opt_lse(const char *name, struct rtattr *lse)
26f871
 	attr = tb[TCA_FLOWER_KEY_MPLS_OPT_LSE_TTL];
26f871
 	if (attr)
26f871
 		print_hhu(PRINT_ANY, "ttl", " ttl %u", rta_getattr_u8(attr));
26f871
-	close_json_array(PRINT_JSON, NULL);
26f871
+	close_json_object();
26f871
 }
26f871
 
26f871
-static void flower_print_mpls_opts(const char *name, struct rtattr *attr)
26f871
+static void flower_print_mpls_opts(struct rtattr *attr)
26f871
 {
26f871
 	struct rtattr *lse;
26f871
 	int rem;
26f871
@@ -2523,11 +2524,12 @@ static void flower_print_mpls_opts(const char *name, struct rtattr *attr)
26f871
 		return;
26f871
 
26f871
 	print_nl();
26f871
-	open_json_array(PRINT_ANY, name);
26f871
+	print_string(PRINT_FP, NULL, "  mpls", NULL);
26f871
+	open_json_array(PRINT_JSON, "mpls");
26f871
 	rem = RTA_PAYLOAD(attr);
26f871
 	lse = RTA_DATA(attr);
26f871
 	while (RTA_OK(lse, rem)) {
26f871
-		flower_print_mpls_opt_lse("    lse", lse);
26f871
+		flower_print_mpls_opt_lse(lse);
26f871
 		lse = RTA_NEXT(lse, rem);
26f871
 	};
26f871
 	if (rem)
26f871
@@ -2650,7 +2652,7 @@ static int flower_print_opt(struct filter_util *qu, FILE *f,
26f871
 	flower_print_ip_attr("ip_ttl", tb[TCA_FLOWER_KEY_IP_TTL],
26f871
 			    tb[TCA_FLOWER_KEY_IP_TTL_MASK]);
26f871
 
26f871
-	flower_print_mpls_opts("  mpls", tb[TCA_FLOWER_KEY_MPLS_OPTS]);
26f871
+	flower_print_mpls_opts(tb[TCA_FLOWER_KEY_MPLS_OPTS]);
26f871
 	flower_print_u32("mpls_label", tb[TCA_FLOWER_KEY_MPLS_LABEL]);
26f871
 	flower_print_u8("mpls_tc", tb[TCA_FLOWER_KEY_MPLS_TC]);
26f871
 	flower_print_u8("mpls_bos", tb[TCA_FLOWER_KEY_MPLS_BOS]);
26f871
-- 
26f871
2.29.2
26f871