From: Stephen Hemminger <sthem...@microsoft.com> Signed-off-by: Stephen Hemminger <step...@networkplumber.org> --- 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