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