From: Stephen Hemminger Subject: [PATCH v2 iproute2-next 28/31] tc/atm: convert to JSON output Date: Tue, 10 Jul 2018 14:05:55 -0700 Message-ID: <20180710210558.20278-29-stephen@networkplumber.org> References: <20180710210558.20278-1-stephen@networkplumber.org> Cc: Stephen Hemminger , Stephen Hemminger To: netdev@vger.kernel.org Return-path: Received: from mail-pf0-f177.google.com ([209.85.192.177]:45806 "EHLO mail-pf0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732205AbeGJVPe (ORCPT ); Tue, 10 Jul 2018 17:15:34 -0400 Received: by mail-pf0-f177.google.com with SMTP id i26-v6so5492955pfo.12 for ; Tue, 10 Jul 2018 14:14:40 -0700 (PDT) In-Reply-To: <20180710210558.20278-1-stephen@networkplumber.org> Sender: netdev-owner@vger.kernel.org List-ID: From: Stephen Hemminger Signed-off-by: Stephen Hemminger --- tc/q_atm.c | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/tc/q_atm.c b/tc/q_atm.c index f8215f06507a..d5ab7a06b28f 100644 --- a/tc/q_atm.c +++ b/tc/q_atm.c @@ -194,37 +194,45 @@ static int atm_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) fprintf(stderr, "ATM: address too short\n"); else { if (atm2text(buffer, MAX_ATM_ADDR_LEN, - RTA_DATA(tb[TCA_ATM_ADDR]), A2T_PRETTY | A2T_NAME) < - 0) fprintf(stderr, "atm2text error\n"); - fprintf(f, "pvc %s ", buffer); + RTA_DATA(tb[TCA_ATM_ADDR]), A2T_PRETTY | A2T_NAME) < 0) + fprintf(stderr, "atm2text error\n"); + else + print_string(PRINT_ANY, "pvc", + "pvc %s ", buffer); } } + if (tb[TCA_ATM_HDR]) { int i; const __u8 *hdr = RTA_DATA(tb[TCA_ATM_HDR]); - fprintf(f, "hdr"); - for (i = 0; i < RTA_PAYLOAD(tb[TCA_ATM_HDR]); i++) - fprintf(f, "%c%02x", i ? '.' : ' ', hdr[i]); - if (!i) fprintf(f, " ."); - fprintf(f, " "); + open_json_array(PRINT_ANY, "hdr"); + for (i = 0; i < RTA_PAYLOAD(tb[TCA_ATM_HDR]); i++) { + print_string(PRINT_FP, NULL, "%s", + i ? "." : " "); + print_0xhex(PRINT_ANY, NULL, "%02x", hdr[i]); + } + + print_string(PRINT_FP, NULL, "%s ", i ? "" : " ."); } + if (tb[TCA_ATM_EXCESS]) { __u32 excess; if (RTA_PAYLOAD(tb[TCA_ATM_EXCESS]) < sizeof(excess)) fprintf(stderr, "ATM: excess class ID too short\n"); else { - excess = rta_getattr_u32(tb[TCA_ATM_EXCESS]); - if (!excess) fprintf(f, "excess clp "); - else { - char buf[64]; + char buf[64]; + excess = rta_getattr_u32(tb[TCA_ATM_EXCESS]); + if (!excess) + strcpy(buf, "clp"); + else print_tc_classid(buf, sizeof(buf), excess); - fprintf(f, "excess %s ", buf); - } + print_string(PRINT_ANY, "excess", "excess %s ", buf); } } + if (tb[TCA_ATM_STATE]) { static const char *map[] = { ATM_VS2TXT_MAP }; int state; @@ -233,7 +241,7 @@ static int atm_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) fprintf(stderr, "ATM: state field too short\n"); else { state = rta_getattr_u32(tb[TCA_ATM_STATE]); - fprintf(f, "%s ", map[state]); + print_string(PRINT_ANY, "state", "%s ", map[state]); } } return 0; -- 2.18.0