From: Stephen Hemminger <sthem...@microsoft.com>

If option or qdisc is unknown, still output in JSON.

Signed-off-by: Stephen Hemminger <sthem...@microsoft.com>
---
 tc/tc.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/tc/tc.c b/tc/tc.c
index 0d223281ba25..b6d2a6151793 100644
--- a/tc/tc.c
+++ b/tc/tc.c
@@ -56,9 +56,11 @@ static struct filter_util *filter_list;
 static int print_noqopt(struct qdisc_util *qu, FILE *f,
                        struct rtattr *opt)
 {
-       if (opt && RTA_PAYLOAD(opt))
-               fprintf(f, "[Unknown qdisc, optlen=%u] ",
-                       (unsigned int) RTA_PAYLOAD(opt));
+       if (opt && RTA_PAYLOAD(opt)) {
+               print_string(PRINT_JSON, "qdisc", NULL, "UNKNOWN");
+               print_uint(PRINT_ANY, "optlen", "[Unknown qdisc, optlen=%u] ",
+                          RTA_PAYLOAD(opt));
+       }
        return 0;
 }
 
@@ -76,11 +78,12 @@ static int parse_noqopt(struct qdisc_util *qu, int argc, 
char **argv,
 
 static int print_nofopt(struct filter_util *qu, FILE *f, struct rtattr *opt, 
__u32 fhandle)
 {
-       if (opt && RTA_PAYLOAD(opt))
-               fprintf(f, "fh %08x [Unknown filter, optlen=%u] ",
-                       fhandle, (unsigned int) RTA_PAYLOAD(opt));
-       else if (fhandle)
-               fprintf(f, "fh %08x ", fhandle);
+       if (opt && RTA_PAYLOAD(opt)) {
+               print_0xhex(PRINT_ANY, "handle", "fh %08x ", fhandle);
+               print_uint(PRINT_ANY, "optlen", "[Unknown filter, optlen=%u] ",
+                       RTA_PAYLOAD(opt));
+       } else if (fhandle)
+               print_0xhex(PRINT_ANY, "handle", "fh %08x ", fhandle);
        return 0;
 }
 
-- 
2.18.0

Reply via email to