]> git.proxmox.com Git - mirror_iproute2.git/commitdiff
tc: do not output newline in oneline mode
authorStephen Hemminger <stephen@networkplumber.org>
Wed, 4 Dec 2019 23:37:26 +0000 (15:37 -0800)
committerDavid Ahern <dsahern@gmail.com>
Wed, 11 Dec 2019 17:21:10 +0000 (17:21 +0000)
In oneline mode the line seperator should be \
but several parts of tc aren't doing it right.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: David Ahern <dsahern@gmail.com>
16 files changed:
tc/f_flower.c
tc/m_csum.c
tc/m_ct.c
tc/m_gact.c
tc/m_mirred.c
tc/m_mpls.c
tc/m_pedit.c
tc/m_simple.c
tc/m_tunnel_key.c
tc/m_vlan.c
tc/m_xt.c
tc/q_cake.c
tc/q_fq_codel.c
tc/tc_filter.c
tc/tc_qdisc.c
tc/tc_util.c

index a193c0eca22ab7ceb45fac51f84288a20113810e..ce057a72cc7cac08361c51478a57fce3b764ad51 100644 (file)
@@ -1624,7 +1624,8 @@ static void flower_print_eth_type(__be16 *p_eth_type,
        else
                sprintf(out, "%04x", ntohs(eth_type));
 
-       print_string(PRINT_ANY, "eth_type", "\n  eth_type %s", out);
+       print_nl();
+       print_string(PRINT_ANY, "eth_type", "  eth_type %s", out);
        *p_eth_type = eth_type;
 }
 
@@ -1651,7 +1652,8 @@ static void flower_print_ip_proto(__u8 *p_ip_proto,
        else
                sprintf(out, "%02x", ip_proto);
 
-       print_string(PRINT_ANY, "ip_proto", "\n  ip_proto %s", out);
+       print_nl();
+       print_string(PRINT_ANY, "ip_proto", "  ip_proto %s", out);
        *p_ip_proto = ip_proto;
 }
 
@@ -1682,7 +1684,8 @@ static void flower_print_matching_flags(char *name,
                        continue;
                if (mtf_mask & flags_str[i].flag) {
                        if (++count == 1) {
-                               print_string(PRINT_FP, NULL, "\n  %s ", name);
+                               print_nl();
+                               print_string(PRINT_FP, NULL, "  %s ", name);
                                open_json_object(name);
                        } else {
                                print_string(PRINT_FP, NULL, "/", NULL);
@@ -1829,7 +1832,8 @@ static void flower_print_ct_state(struct rtattr *flags_attr,
                                        flower_ct_states[i].str);
        }
 
-       print_string(PRINT_ANY, "ct_state", "\n  ct_state %s", out);
+       print_nl();
+       print_string(PRINT_ANY, "ct_state", "  ct_state %s", out);
 }
 
 static void flower_print_ct_label(struct rtattr *attr,
@@ -1864,7 +1868,8 @@ static void flower_print_ct_label(struct rtattr *attr,
        }
        *p = '\0';
 
-       print_string(PRINT_ANY, "ct_label", "\n  ct_label %s", out);
+       print_nl();
+       print_string(PRINT_ANY, "ct_label", "  ct_label %s", out);
 }
 
 static void flower_print_ct_zone(struct rtattr *attr,
@@ -1886,7 +1891,8 @@ static void flower_print_key_id(const char *name, struct rtattr *attr)
        if (!attr)
                return;
 
-       sprintf(namefrm,"\n  %s %%u", name);
+       print_nl();
+       sprintf(namefrm, "  %s %%u", name);
        print_uint(PRINT_ANY, name, namefrm, rta_getattr_be32(attr));
 }
 
@@ -1934,7 +1940,7 @@ static void flower_print_geneve_opts(const char *name, struct rtattr *attr,
 static void flower_print_geneve_parts(const char *name, struct rtattr *attr,
                                      char *key, char *mask)
 {
-       char *namefrm = "\n  geneve_opt %s";
+       char *namefrm = "  geneve_opt %s";
        char *key_token, *mask_token, *out;
        int len;
 
@@ -1952,6 +1958,7 @@ static void flower_print_geneve_parts(const char *name, struct rtattr *attr,
        }
 
        out[len - 1] = '\0';
+       print_nl();
        print_string(PRINT_FP, name, namefrm, out);
        free(out);
 }
@@ -2015,7 +2022,8 @@ static void flower_print_masked_u8(const char *name, struct rtattr *attr,
        if (mask != UINT8_MAX)
                sprintf(out + done, "/%d", mask);
 
-       sprintf(namefrm,"\n  %s %%s", name);
+       print_nl();
+       sprintf(namefrm, "  %s %%s", name);
        print_string(PRINT_ANY, name, namefrm, out);
 }
 
@@ -2031,7 +2039,8 @@ static void flower_print_u32(const char *name, struct rtattr *attr)
        if (!attr)
                return;
 
-       sprintf(namefrm,"\n  %s %%u", name);
+       print_nl();
+       sprintf(namefrm, "  %s %%u", name);
        print_uint(PRINT_ANY, name, namefrm, rta_getattr_u32(attr));
 }
 
@@ -2086,14 +2095,16 @@ static int flower_print_opt(struct filter_util *qu, FILE *f,
        if (tb[TCA_FLOWER_KEY_VLAN_ID]) {
                struct rtattr *attr = tb[TCA_FLOWER_KEY_VLAN_ID];
 
-               print_uint(PRINT_ANY, "vlan_id", "\n  vlan_id %u",
+               print_nl();
+               print_uint(PRINT_ANY, "vlan_id", "  vlan_id %u",
                           rta_getattr_u16(attr));
        }
 
        if (tb[TCA_FLOWER_KEY_VLAN_PRIO]) {
                struct rtattr *attr = tb[TCA_FLOWER_KEY_VLAN_PRIO];
 
-               print_uint(PRINT_ANY, "vlan_prio", "\n  vlan_prio %d",
+               print_nl();
+               print_uint(PRINT_ANY, "vlan_prio", "  vlan_prio %d",
                           rta_getattr_u8(attr));
        }
 
@@ -2101,7 +2112,8 @@ static int flower_print_opt(struct filter_util *qu, FILE *f,
                SPRINT_BUF(buf);
                struct rtattr *attr = tb[TCA_FLOWER_KEY_VLAN_ETH_TYPE];
 
-               print_string(PRINT_ANY, "vlan_ethtype", "\n  vlan_ethtype %s",
+               print_nl();
+               print_string(PRINT_ANY, "vlan_ethtype", "  vlan_ethtype %s",
                             ll_proto_n2a(rta_getattr_u16(attr),
                             buf, sizeof(buf)));
        }
@@ -2109,14 +2121,16 @@ static int flower_print_opt(struct filter_util *qu, FILE *f,
        if (tb[TCA_FLOWER_KEY_CVLAN_ID]) {
                struct rtattr *attr = tb[TCA_FLOWER_KEY_CVLAN_ID];
 
-               print_uint(PRINT_ANY, "cvlan_id", "\n  cvlan_id %u",
+               print_nl();
+               print_uint(PRINT_ANY, "cvlan_id", "  cvlan_id %u",
                           rta_getattr_u16(attr));
        }
 
        if (tb[TCA_FLOWER_KEY_CVLAN_PRIO]) {
                struct rtattr *attr = tb[TCA_FLOWER_KEY_CVLAN_PRIO];
 
-               print_uint(PRINT_ANY, "cvlan_prio", "\n  cvlan_prio %d",
+               print_nl();
+               print_uint(PRINT_ANY, "cvlan_prio", "  cvlan_prio %d",
                           rta_getattr_u8(attr));
        }
 
@@ -2124,7 +2138,8 @@ static int flower_print_opt(struct filter_util *qu, FILE *f,
                SPRINT_BUF(buf);
                struct rtattr *attr = tb[TCA_FLOWER_KEY_CVLAN_ETH_TYPE];
 
-               print_string(PRINT_ANY, "cvlan_ethtype", "\n  cvlan_ethtype %s",
+               print_nl();
+               print_string(PRINT_ANY, "cvlan_ethtype", "  cvlan_ethtype %s",
                             ll_proto_n2a(rta_getattr_u16(attr),
                             buf, sizeof(buf)));
        }
@@ -2254,13 +2269,18 @@ static int flower_print_opt(struct filter_util *qu, FILE *f,
        if (tb[TCA_FLOWER_FLAGS]) {
                __u32 flags = rta_getattr_u32(tb[TCA_FLOWER_FLAGS]);
 
-               if (flags & TCA_CLS_FLAGS_SKIP_HW)
-                       print_bool(PRINT_ANY, "skip_hw", "\n  skip_hw", true);
-               if (flags & TCA_CLS_FLAGS_SKIP_SW)
-                       print_bool(PRINT_ANY, "skip_sw", "\n  skip_sw", true);
+               if (flags & TCA_CLS_FLAGS_SKIP_HW) {
+                       print_nl();
+                       print_bool(PRINT_ANY, "skip_hw", "  skip_hw", true);
+               }
+               if (flags & TCA_CLS_FLAGS_SKIP_SW) {
+                       print_nl();
+                       print_bool(PRINT_ANY, "skip_sw", "  skip_sw", true);
+               }
 
                if (flags & TCA_CLS_FLAGS_IN_HW) {
-                       print_bool(PRINT_ANY, "in_hw", "\n  in_hw", true);
+                       print_nl();
+                       print_bool(PRINT_ANY, "in_hw", "  in_hw", true);
 
                        if (tb[TCA_FLOWER_IN_HW_COUNT]) {
                                __u32 count = rta_getattr_u32(tb[TCA_FLOWER_IN_HW_COUNT]);
@@ -2269,8 +2289,10 @@ static int flower_print_opt(struct filter_util *qu, FILE *f,
                                           " in_hw_count %u", count);
                        }
                }
-               else if (flags & TCA_CLS_FLAGS_NOT_IN_HW)
-                       print_bool(PRINT_ANY, "not_in_hw", "\n  not_in_hw", true);
+               else if (flags & TCA_CLS_FLAGS_NOT_IN_HW) {
+                       print_nl();
+                       print_bool(PRINT_ANY, "not_in_hw", "  not_in_hw", true);
+               }
        }
 
        if (tb[TCA_FLOWER_ACT])
index 3e3dc251ea383a69c87af2d7cd1eb42921bc0ee5..afbee9c8de0f9398623c79a1944d86ad11345cc4 100644 (file)
@@ -205,7 +205,7 @@ print_csum(struct action_util *au, FILE *f, struct rtattr *arg)
                 uflag_4, uflag_5, uflag_6, uflag_7);
        print_string(PRINT_ANY, "csum", "(%s) ", buf);
 
-       print_action_control(f, "action ", sel->action, "\n");
+       print_action_control(f, "action ", sel->action, _SL_);
        print_uint(PRINT_ANY, "index", "\tindex %u", sel->index);
        print_int(PRINT_ANY, "ref", " ref %d", sel->refcnt);
        print_int(PRINT_ANY, "bind", " bind %d", sel->bindcnt);
@@ -217,7 +217,7 @@ print_csum(struct action_util *au, FILE *f, struct rtattr *arg)
                        print_tm(f, tm);
                }
        }
-       print_string(PRINT_FP, NULL, "%s", "\n");
+       print_nl();
 
        return 0;
 }
index 45fa4a8c9ff492005c9f6f803361f6d343e0c529..70d186e859f4b694fbb6c9a75a1014c3f7ac0dba 100644 (file)
--- a/tc/m_ct.c
+++ b/tc/m_ct.c
@@ -473,7 +473,8 @@ static int print_ct(struct action_util *au, FILE *f, struct rtattr *arg)
 
        print_action_control(f, " ", p->action, "");
 
-       print_uint(PRINT_ANY, "index", "\n\t index %u", p->index);
+       print_nl();
+       print_uint(PRINT_ANY, "index", "\t index %u", p->index);
        print_int(PRINT_ANY, "ref", " ref %d", p->refcnt);
        print_int(PRINT_ANY, "bind", " bind %d", p->bindcnt);
 
@@ -484,7 +485,7 @@ static int print_ct(struct action_util *au, FILE *f, struct rtattr *arg)
                        print_tm(f, tm);
                }
        }
-       print_string(PRINT_FP, NULL, "%s", "\n ");
+       print_nl();
 
        return 0;
 }
index b06e8ee95818fde845fcec15c3a1841ec9ec3595..33f326f823d1edb8dd54853df937b5fb36aa01a7 100644 (file)
@@ -193,13 +193,15 @@ print_gact(struct action_util *au, FILE *f, struct rtattr *arg)
                pp = &pp_dummy;
        }
        open_json_object("prob");
-       print_string(PRINT_ANY, "random_type", "\n\t random type %s",
+       print_nl();
+       print_string(PRINT_ANY, "random_type", "\t random type %s",
                     prob_n2a(pp->ptype));
        print_action_control(f, " ", pp->paction, " ");
        print_int(PRINT_ANY, "val", "val %d", pp->pval);
        close_json_object();
 #endif
-       print_uint(PRINT_ANY, "index", "\n\t index %u", p->index);
+       print_nl();
+       print_uint(PRINT_ANY, "index", "\t index %u", p->index);
        print_int(PRINT_ANY, "ref", " ref %d", p->refcnt);
        print_int(PRINT_ANY, "bind", " bind %d", p->bindcnt);
        if (show_stats) {
@@ -209,7 +211,7 @@ print_gact(struct action_util *au, FILE *f, struct rtattr *arg)
                        print_tm(f, tm);
                }
        }
-       print_string(PRINT_FP, NULL, "%s", "\n");
+       print_nl();
        return 0;
 }
 
index 132095237929551c12613cc4e9e58b7431abe1bf..d2bdf4074a73be266ad257333345e962dc004389 100644 (file)
@@ -307,7 +307,8 @@ print_mirred(struct action_util *au, FILE *f, struct rtattr *arg)
        print_string(PRINT_ANY, "to_dev", " to device %s)", dev);
        print_action_control(f, " ", p->action, "");
 
-       print_uint(PRINT_ANY, "index", "\n \tindex %u", p->index);
+       print_nl();
+       print_uint(PRINT_ANY, "index", "\tindex %u", p->index);
        print_int(PRINT_ANY, "ref", " ref %d", p->refcnt);
        print_int(PRINT_ANY, "bind", " bind %d", p->bindcnt);
 
@@ -318,7 +319,7 @@ print_mirred(struct action_util *au, FILE *f, struct rtattr *arg)
                        print_tm(f, tm);
                }
        }
-       print_string(PRINT_FP, NULL, "%s", "\n ");
+       print_nl();
        return 0;
 }
 
index 4b1ec70e3b4a2570a5f96a696d6220ad5c22b83b..6f3a39f43ce175c6f16e4ba4cf5fd71e2c9b1828 100644 (file)
@@ -252,7 +252,8 @@ static int print_mpls(struct action_util *au, FILE *f, struct rtattr *arg)
        }
        print_action_control(f, " ", parm->action, "");
 
-       print_uint(PRINT_ANY, "index", "\n\t index %u", parm->index);
+       print_nl();
+       print_uint(PRINT_ANY, "index", "\t index %u", parm->index);
        print_int(PRINT_ANY, "ref", " ref %d", parm->refcnt);
        print_int(PRINT_ANY, "bind", " bind %d", parm->bindcnt);
 
index 1cd2d162fc2abec443eb8861be89502291b327d4..fccfd17ca2709ef169e765f476b1374bd0d631a6 100644 (file)
@@ -820,7 +820,7 @@ static int print_pedit(struct action_util *au, FILE *f, struct rtattr *arg)
                        sel->nkeys);
        }
 
-       fprintf(f, "\n ");
+       print_nl();
 
        free(keys_ex);
        return 0;
index 49e250472e04cd364b65e26b7690d5b28ff43cc6..70897d6b7c13819495a06dc2345eca0a5df8779a 100644 (file)
@@ -194,7 +194,7 @@ static int print_simple(struct action_util *au, FILE *f, struct rtattr *arg)
                        print_tm(f, tm);
                }
        }
-       fprintf(f, "\n");
+       print_nl();
 
        return 0;
 }
index 4e65e444776a2b93756b6371bad805806c7e3076..8fde689137fd7b784cbefd626271825fa48d4da4 100644 (file)
@@ -420,7 +420,8 @@ static void tunnel_key_print_geneve_options(const char *name,
        uint8_t type;
 
        open_json_array(PRINT_JSON, name);
-       print_string(PRINT_FP, name, "\n\t%s ", "geneve_opt");
+       print_nl();
+       print_string(PRINT_FP, name, "\t%s ", "geneve_opt");
 
        while (rem) {
                parse_rtattr(tb, TCA_TUNNEL_KEY_ENC_OPT_GENEVE_MAX, i, rem);
index 9c8071e9dbbe0f18d9709c31a66ecfab04330862..1096ba0fbf12a7638531c2b2650c3a1b48a76a48 100644 (file)
@@ -219,7 +219,8 @@ static int print_vlan(struct action_util *au, FILE *f, struct rtattr *arg)
        }
        print_action_control(f, " ", parm->action, "");
 
-       print_uint(PRINT_ANY, "index", "\n\t index %u", parm->index);
+       print_nl();
+       print_uint(PRINT_ANY, "index", "\t index %u", parm->index);
        print_int(PRINT_ANY, "ref", " ref %d", parm->refcnt);
        print_int(PRINT_ANY, "bind", " bind %d", parm->bindcnt);
 
@@ -231,7 +232,7 @@ static int print_vlan(struct action_util *au, FILE *f, struct rtattr *arg)
                }
        }
 
-       print_string(PRINT_FP, NULL, "%s", "\n");
+       print_nl();
 
        return 0;
 }
index bf0db2be99a4b91a7e4d3de48758f8d32294e776..487ba25ad391169cb8d518c59b2e10196ef71bde 100644 (file)
--- a/tc/m_xt.c
+++ b/tc/m_xt.c
@@ -391,7 +391,7 @@ print_ipt(struct action_util *au, FILE *f, struct rtattr *arg)
                        print_tm(f, tm);
                }
        }
-       fprintf(f, "\n");
+       print_nl();
 
        xtables_free_opts(1);
 
index 65ea07ef6cb59e7d1abf4e0194a9ea160d815a59..3c78b1767e0b1678a502b3350b2b4e5daf352eeb 100644 (file)
@@ -766,7 +766,7 @@ static int cake_print_xstats(struct qdisc_util *qu, FILE *f,
                        fprintf(f, "          ");
                        for (i = 0; i < num_tins; i++)
                                fprintf(f, "        Tin %u", i);
-                       fprintf(f, "\n");
+                       fprintf(f, "%s", _SL_);
                };
 
 #define GET_TSTAT(i, attr) (tstat[i][TCA_CAKE_TIN_STATS_ ## attr])
@@ -775,7 +775,7 @@ static int cake_print_xstats(struct qdisc_util *qu, FILE *f,
                                fprintf(f, name);               \
                                for (i = 0; i < num_tins; i++)  \
                                        fprintf(f, " %12" fmts, val);   \
-                               fprintf(f, "\n");                       \
+                               fprintf(f, "%s", _SL_);                 \
                        }                                               \
                } while (0)
 
index 376ac50da1a5d6f6d3fee2655a96db5745918d81..12ce3fbfd2032a5752578a166a391599e14fcb4d 100644 (file)
@@ -257,7 +257,8 @@ static int fq_codel_print_xstats(struct qdisc_util *qu, FILE *f,
                if (st->qdisc_stats.drop_overmemory)
                        print_uint(PRINT_ANY, "drop_overmemory", " drop_overmemory %u",
                                st->qdisc_stats.drop_overmemory);
-               print_uint(PRINT_ANY, "new_flows_len", "\n  new_flows_len %u",
+               print_nl();
+               print_uint(PRINT_ANY, "new_flows_len", "  new_flows_len %u",
                        st->qdisc_stats.new_flows_len);
                print_uint(PRINT_ANY, "old_flows_len", " old_flows_len %u",
                        st->qdisc_stats.old_flows_len);
index f7d2e4a66a35b138dd4bbd7d01b019a84b1e9b20..dcddca77ef1b0a460ebcca8b16e1d115f338c260 100644 (file)
@@ -364,11 +364,11 @@ int print_filter(struct nlmsghdr *n, void *arg)
                        close_json_object();
                }
        }
-       print_string(PRINT_FP, NULL, "\n", NULL);
+       print_nl();
 
        if (show_stats && (tb[TCA_STATS] || tb[TCA_STATS2])) {
                print_tcstats_attr(fp, tb, " ", NULL);
-               print_string(PRINT_FP, NULL, "\n", NULL);
+               print_nl();
        }
 
        close_json_object();
index 17e399830a75d81b0a34f5c727367c275a2536a0..75a146721c403dc38ccbac8de8d2c918f5500bca 100644 (file)
@@ -317,11 +317,11 @@ int print_qdisc(struct nlmsghdr *n, void *arg)
        }
        close_json_object();
 
-       print_string(PRINT_FP, NULL, "\n", NULL);
+       print_nl();
 
        if (show_details && tb[TCA_STAB]) {
                print_size_table(fp, " ", tb[TCA_STAB]);
-               print_string(PRINT_FP, NULL, "\n", NULL);
+               print_nl();
        }
 
        if (show_stats) {
@@ -329,12 +329,12 @@ int print_qdisc(struct nlmsghdr *n, void *arg)
 
                if (tb[TCA_STATS] || tb[TCA_STATS2] || tb[TCA_XSTATS]) {
                        print_tcstats_attr(fp, tb, " ", &xstats);
-                       print_string(PRINT_FP, NULL, "\n", NULL);
+                       print_nl();
                }
 
                if (q && xstats && q->print_xstats) {
                        q->print_xstats(q, fp, xstats);
-                       print_string(PRINT_FP, NULL, "\n", NULL);
+                       print_nl();
                }
        }
        close_json_object();
index 0e70632d731a736d0e3e592e60ab76ba6ecfe72e..5f13d729bf52ee7d88916859de58d8061616cbf0 100644 (file)
@@ -869,7 +869,7 @@ void print_tcstats2_attr(FILE *fp, struct rtattr *rta, char *prefix, struct rtat
                memcpy(&q, RTA_DATA(tbs[TCA_STATS_QUEUE]),
                       MIN(RTA_PAYLOAD(tbs[TCA_STATS_QUEUE]), sizeof(q)));
                if (!tbs[TCA_STATS_RATE_EST])
-                       print_string(PRINT_FP, NULL, "\n", "");
+                       print_nl();
                print_uint(PRINT_JSON, "backlog", NULL, q.backlog);
                print_string(PRINT_FP, NULL, "%s", prefix);
                print_string(PRINT_FP, NULL, "backlog %s",