naccyde / rpms / iproute

Forked from rpms/iproute 5 months ago
Clone

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

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