tc: do not output newline in oneline mode

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>
This commit is contained in:
Stephen Hemminger 2019-12-04 15:37:26 -08:00 committed by David Ahern
parent f39da545b6
commit 7b0d424abe
16 changed files with 78 additions and 48 deletions

View File

@ -1624,7 +1624,8 @@ static void flower_print_eth_type(__be16 *p_eth_type,
else else
sprintf(out, "%04x", ntohs(eth_type)); 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; *p_eth_type = eth_type;
} }
@ -1651,7 +1652,8 @@ static void flower_print_ip_proto(__u8 *p_ip_proto,
else else
sprintf(out, "%02x", ip_proto); 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; *p_ip_proto = ip_proto;
} }
@ -1682,7 +1684,8 @@ static void flower_print_matching_flags(char *name,
continue; continue;
if (mtf_mask & flags_str[i].flag) { if (mtf_mask & flags_str[i].flag) {
if (++count == 1) { if (++count == 1) {
print_string(PRINT_FP, NULL, "\n %s ", name); print_nl();
print_string(PRINT_FP, NULL, " %s ", name);
open_json_object(name); open_json_object(name);
} else { } else {
print_string(PRINT_FP, NULL, "/", NULL); 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); 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, static void flower_print_ct_label(struct rtattr *attr,
@ -1864,7 +1868,8 @@ static void flower_print_ct_label(struct rtattr *attr,
} }
*p = '\0'; *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, 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) if (!attr)
return; return;
sprintf(namefrm,"\n %s %%u", name); print_nl();
sprintf(namefrm, " %s %%u", name);
print_uint(PRINT_ANY, name, namefrm, rta_getattr_be32(attr)); 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, static void flower_print_geneve_parts(const char *name, struct rtattr *attr,
char *key, char *mask) char *key, char *mask)
{ {
char *namefrm = "\n geneve_opt %s"; char *namefrm = " geneve_opt %s";
char *key_token, *mask_token, *out; char *key_token, *mask_token, *out;
int len; int len;
@ -1952,6 +1958,7 @@ static void flower_print_geneve_parts(const char *name, struct rtattr *attr,
} }
out[len - 1] = '\0'; out[len - 1] = '\0';
print_nl();
print_string(PRINT_FP, name, namefrm, out); print_string(PRINT_FP, name, namefrm, out);
free(out); free(out);
} }
@ -2015,7 +2022,8 @@ static void flower_print_masked_u8(const char *name, struct rtattr *attr,
if (mask != UINT8_MAX) if (mask != UINT8_MAX)
sprintf(out + done, "/%d", mask); 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); print_string(PRINT_ANY, name, namefrm, out);
} }
@ -2031,7 +2039,8 @@ static void flower_print_u32(const char *name, struct rtattr *attr)
if (!attr) if (!attr)
return; return;
sprintf(namefrm,"\n %s %%u", name); print_nl();
sprintf(namefrm, " %s %%u", name);
print_uint(PRINT_ANY, name, namefrm, rta_getattr_u32(attr)); 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]) { if (tb[TCA_FLOWER_KEY_VLAN_ID]) {
struct rtattr *attr = 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)); rta_getattr_u16(attr));
} }
if (tb[TCA_FLOWER_KEY_VLAN_PRIO]) { if (tb[TCA_FLOWER_KEY_VLAN_PRIO]) {
struct rtattr *attr = 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)); rta_getattr_u8(attr));
} }
@ -2101,7 +2112,8 @@ static int flower_print_opt(struct filter_util *qu, FILE *f,
SPRINT_BUF(buf); SPRINT_BUF(buf);
struct rtattr *attr = tb[TCA_FLOWER_KEY_VLAN_ETH_TYPE]; 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), ll_proto_n2a(rta_getattr_u16(attr),
buf, sizeof(buf))); 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]) { if (tb[TCA_FLOWER_KEY_CVLAN_ID]) {
struct rtattr *attr = 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)); rta_getattr_u16(attr));
} }
if (tb[TCA_FLOWER_KEY_CVLAN_PRIO]) { if (tb[TCA_FLOWER_KEY_CVLAN_PRIO]) {
struct rtattr *attr = 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)); rta_getattr_u8(attr));
} }
@ -2124,7 +2138,8 @@ static int flower_print_opt(struct filter_util *qu, FILE *f,
SPRINT_BUF(buf); SPRINT_BUF(buf);
struct rtattr *attr = tb[TCA_FLOWER_KEY_CVLAN_ETH_TYPE]; 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), ll_proto_n2a(rta_getattr_u16(attr),
buf, sizeof(buf))); buf, sizeof(buf)));
} }
@ -2254,13 +2269,18 @@ static int flower_print_opt(struct filter_util *qu, FILE *f,
if (tb[TCA_FLOWER_FLAGS]) { if (tb[TCA_FLOWER_FLAGS]) {
__u32 flags = rta_getattr_u32(tb[TCA_FLOWER_FLAGS]); __u32 flags = rta_getattr_u32(tb[TCA_FLOWER_FLAGS]);
if (flags & TCA_CLS_FLAGS_SKIP_HW) if (flags & TCA_CLS_FLAGS_SKIP_HW) {
print_bool(PRINT_ANY, "skip_hw", "\n skip_hw", true); print_nl();
if (flags & TCA_CLS_FLAGS_SKIP_SW) print_bool(PRINT_ANY, "skip_hw", " skip_hw", true);
print_bool(PRINT_ANY, "skip_sw", "\n skip_sw", 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) { 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]) { if (tb[TCA_FLOWER_IN_HW_COUNT]) {
__u32 count = rta_getattr_u32(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); " in_hw_count %u", count);
} }
} }
else if (flags & TCA_CLS_FLAGS_NOT_IN_HW) else if (flags & TCA_CLS_FLAGS_NOT_IN_HW) {
print_bool(PRINT_ANY, "not_in_hw", "\n not_in_hw", true); print_nl();
print_bool(PRINT_ANY, "not_in_hw", " not_in_hw", true);
}
} }
if (tb[TCA_FLOWER_ACT]) if (tb[TCA_FLOWER_ACT])

View File

@ -205,7 +205,7 @@ print_csum(struct action_util *au, FILE *f, struct rtattr *arg)
uflag_4, uflag_5, uflag_6, uflag_7); uflag_4, uflag_5, uflag_6, uflag_7);
print_string(PRINT_ANY, "csum", "(%s) ", buf); 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_uint(PRINT_ANY, "index", "\tindex %u", sel->index);
print_int(PRINT_ANY, "ref", " ref %d", sel->refcnt); print_int(PRINT_ANY, "ref", " ref %d", sel->refcnt);
print_int(PRINT_ANY, "bind", " bind %d", sel->bindcnt); 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_tm(f, tm);
} }
} }
print_string(PRINT_FP, NULL, "%s", "\n"); print_nl();
return 0; return 0;
} }

View File

@ -473,7 +473,8 @@ static int print_ct(struct action_util *au, FILE *f, struct rtattr *arg)
print_action_control(f, " ", p->action, ""); 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, "ref", " ref %d", p->refcnt);
print_int(PRINT_ANY, "bind", " bind %d", p->bindcnt); 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_tm(f, tm);
} }
} }
print_string(PRINT_FP, NULL, "%s", "\n "); print_nl();
return 0; return 0;
} }

View File

@ -193,13 +193,15 @@ print_gact(struct action_util *au, FILE *f, struct rtattr *arg)
pp = &pp_dummy; pp = &pp_dummy;
} }
open_json_object("prob"); 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)); prob_n2a(pp->ptype));
print_action_control(f, " ", pp->paction, " "); print_action_control(f, " ", pp->paction, " ");
print_int(PRINT_ANY, "val", "val %d", pp->pval); print_int(PRINT_ANY, "val", "val %d", pp->pval);
close_json_object(); close_json_object();
#endif #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, "ref", " ref %d", p->refcnt);
print_int(PRINT_ANY, "bind", " bind %d", p->bindcnt); print_int(PRINT_ANY, "bind", " bind %d", p->bindcnt);
if (show_stats) { if (show_stats) {
@ -209,7 +211,7 @@ print_gact(struct action_util *au, FILE *f, struct rtattr *arg)
print_tm(f, tm); print_tm(f, tm);
} }
} }
print_string(PRINT_FP, NULL, "%s", "\n"); print_nl();
return 0; return 0;
} }

View 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_string(PRINT_ANY, "to_dev", " to device %s)", dev);
print_action_control(f, " ", p->action, ""); 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, "ref", " ref %d", p->refcnt);
print_int(PRINT_ANY, "bind", " bind %d", p->bindcnt); 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_tm(f, tm);
} }
} }
print_string(PRINT_FP, NULL, "%s", "\n "); print_nl();
return 0; return 0;
} }

View 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_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, "ref", " ref %d", parm->refcnt);
print_int(PRINT_ANY, "bind", " bind %d", parm->bindcnt); print_int(PRINT_ANY, "bind", " bind %d", parm->bindcnt);

View File

@ -820,7 +820,7 @@ static int print_pedit(struct action_util *au, FILE *f, struct rtattr *arg)
sel->nkeys); sel->nkeys);
} }
fprintf(f, "\n "); print_nl();
free(keys_ex); free(keys_ex);
return 0; return 0;

View File

@ -194,7 +194,7 @@ static int print_simple(struct action_util *au, FILE *f, struct rtattr *arg)
print_tm(f, tm); print_tm(f, tm);
} }
} }
fprintf(f, "\n"); print_nl();
return 0; return 0;
} }

View File

@ -420,7 +420,8 @@ static void tunnel_key_print_geneve_options(const char *name,
uint8_t type; uint8_t type;
open_json_array(PRINT_JSON, name); 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) { while (rem) {
parse_rtattr(tb, TCA_TUNNEL_KEY_ENC_OPT_GENEVE_MAX, i, rem); parse_rtattr(tb, TCA_TUNNEL_KEY_ENC_OPT_GENEVE_MAX, i, rem);

View 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_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, "ref", " ref %d", parm->refcnt);
print_int(PRINT_ANY, "bind", " bind %d", parm->bindcnt); 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; return 0;
} }

View File

@ -391,7 +391,7 @@ print_ipt(struct action_util *au, FILE *f, struct rtattr *arg)
print_tm(f, tm); print_tm(f, tm);
} }
} }
fprintf(f, "\n"); print_nl();
xtables_free_opts(1); xtables_free_opts(1);

View File

@ -766,7 +766,7 @@ static int cake_print_xstats(struct qdisc_util *qu, FILE *f,
fprintf(f, " "); fprintf(f, " ");
for (i = 0; i < num_tins; i++) for (i = 0; i < num_tins; i++)
fprintf(f, " Tin %u", 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]) #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); \ fprintf(f, name); \
for (i = 0; i < num_tins; i++) \ for (i = 0; i < num_tins; i++) \
fprintf(f, " %12" fmts, val); \ fprintf(f, " %12" fmts, val); \
fprintf(f, "\n"); \ fprintf(f, "%s", _SL_); \
} \ } \
} while (0) } while (0)

View File

@ -257,7 +257,8 @@ static int fq_codel_print_xstats(struct qdisc_util *qu, FILE *f,
if (st->qdisc_stats.drop_overmemory) if (st->qdisc_stats.drop_overmemory)
print_uint(PRINT_ANY, "drop_overmemory", " drop_overmemory %u", print_uint(PRINT_ANY, "drop_overmemory", " drop_overmemory %u",
st->qdisc_stats.drop_overmemory); 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); st->qdisc_stats.new_flows_len);
print_uint(PRINT_ANY, "old_flows_len", " old_flows_len %u", print_uint(PRINT_ANY, "old_flows_len", " old_flows_len %u",
st->qdisc_stats.old_flows_len); st->qdisc_stats.old_flows_len);

View File

@ -364,11 +364,11 @@ int print_filter(struct nlmsghdr *n, void *arg)
close_json_object(); close_json_object();
} }
} }
print_string(PRINT_FP, NULL, "\n", NULL); print_nl();
if (show_stats && (tb[TCA_STATS] || tb[TCA_STATS2])) { if (show_stats && (tb[TCA_STATS] || tb[TCA_STATS2])) {
print_tcstats_attr(fp, tb, " ", NULL); print_tcstats_attr(fp, tb, " ", NULL);
print_string(PRINT_FP, NULL, "\n", NULL); print_nl();
} }
close_json_object(); close_json_object();

View File

@ -317,11 +317,11 @@ int print_qdisc(struct nlmsghdr *n, void *arg)
} }
close_json_object(); close_json_object();
print_string(PRINT_FP, NULL, "\n", NULL); print_nl();
if (show_details && tb[TCA_STAB]) { if (show_details && tb[TCA_STAB]) {
print_size_table(fp, " ", tb[TCA_STAB]); print_size_table(fp, " ", tb[TCA_STAB]);
print_string(PRINT_FP, NULL, "\n", NULL); print_nl();
} }
if (show_stats) { 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]) { if (tb[TCA_STATS] || tb[TCA_STATS2] || tb[TCA_XSTATS]) {
print_tcstats_attr(fp, tb, " ", &xstats); print_tcstats_attr(fp, tb, " ", &xstats);
print_string(PRINT_FP, NULL, "\n", NULL); print_nl();
} }
if (q && xstats && q->print_xstats) { if (q && xstats && q->print_xstats) {
q->print_xstats(q, fp, xstats); q->print_xstats(q, fp, xstats);
print_string(PRINT_FP, NULL, "\n", NULL); print_nl();
} }
} }
close_json_object(); close_json_object();

View 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]), memcpy(&q, RTA_DATA(tbs[TCA_STATS_QUEUE]),
MIN(RTA_PAYLOAD(tbs[TCA_STATS_QUEUE]), sizeof(q))); MIN(RTA_PAYLOAD(tbs[TCA_STATS_QUEUE]), sizeof(q)));
if (!tbs[TCA_STATS_RATE_EST]) if (!tbs[TCA_STATS_RATE_EST])
print_string(PRINT_FP, NULL, "\n", ""); print_nl();
print_uint(PRINT_JSON, "backlog", NULL, q.backlog); print_uint(PRINT_JSON, "backlog", NULL, q.backlog);
print_string(PRINT_FP, NULL, "%s", prefix); print_string(PRINT_FP, NULL, "%s", prefix);
print_string(PRINT_FP, NULL, "backlog %s", print_string(PRINT_FP, NULL, "backlog %s",