Many tc modules were printing error messages to stdout.
This is problematic if using JSON or other output formats.
Change all these places to use fprintf(stderr, ...) instead.
Also, remove unnecessary initialization and places
where else is used after error return.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
parse_rtattr_nested(tb, TCA_ACT_BPF_MAX, arg);
if (!tb[TCA_ACT_BPF_PARMS]) {
- fprintf(f, "[NULL bpf parameters]");
+ fprintf(stderr, "Missing bpf parameters\n");
return -1;
}
parse_rtattr_nested(tb, TCA_CONNMARK_MAX, arg);
if (tb[TCA_CONNMARK_PARMS] == NULL) {
- print_string(PRINT_FP, NULL, "%s", "[NULL connmark parameters]");
+ fprintf(stderr, "Missing connmark parameters\n");
return -1;
}
parse_rtattr_nested(tb, TCA_CSUM_MAX, arg);
if (tb[TCA_CSUM_PARMS] == NULL) {
- fprintf(f, "[NULL csum parameters]");
+ fprintf(stderr, "Missing csum parameters\n");
return -1;
}
sel = RTA_DATA(tb[TCA_CSUM_PARMS]);
parse_rtattr_nested(tb, TCA_GACT_MAX, arg);
if (tb[TCA_GACT_PARMS] == NULL) {
- print_string(PRINT_FP, NULL, "%s", "[NULL gact parameters]");
+ fprintf(stderr, "Missing gact parameters\n");
return -1;
}
p = RTA_DATA(tb[TCA_GACT_PARMS]);
static int print_ife(struct action_util *au, FILE *f, struct rtattr *arg)
{
- struct tc_ife *p = NULL;
+ struct tc_ife *p;
struct rtattr *tb[TCA_IFE_MAX + 1];
__u16 ife_type = 0;
__u32 mmark = 0;
parse_rtattr_nested(tb, TCA_IFE_MAX, arg);
if (tb[TCA_IFE_PARMS] == NULL) {
- print_string(PRINT_FP, NULL, "%s", "[NULL ife parameters]");
+ fprintf(stderr, "Missing ife parameters\n");
return -1;
}
p = RTA_DATA(tb[TCA_IFE_PARMS]);
{
struct rtattr *tb[TCA_IPT_MAX + 1];
struct ipt_entry_target *t = NULL;
+ struct xtables_target *m;
+ __u32 hook;
if (arg == NULL)
return -1;
parse_rtattr_nested(tb, TCA_IPT_MAX, arg);
if (tb[TCA_IPT_TABLE] == NULL) {
- fprintf(f, "[NULL ipt table name ] assuming mangle ");
+ fprintf(stderr, "Missing ipt table name, assuming mangle\n");
} else {
fprintf(f, "tablename: %s ",
rta_getattr_str(tb[TCA_IPT_TABLE]));
}
if (tb[TCA_IPT_HOOK] == NULL) {
- fprintf(f, "[NULL ipt hook name ]\n ");
+ fprintf(stderr, "Missing ipt hook name\n ");
return -1;
- } else {
- __u32 hook;
-
- hook = rta_getattr_u32(tb[TCA_IPT_HOOK]);
- fprintf(f, " hook: %s\n", ipthooks[hook]);
}
+ hook = rta_getattr_u32(tb[TCA_IPT_HOOK]);
+ fprintf(f, " hook: %s\n", ipthooks[hook]);
+
if (tb[TCA_IPT_TARG] == NULL) {
- fprintf(f, "\t[NULL ipt target parameters ]\n");
+ fprintf(stderr, "Missing ipt target parameters\n");
return -1;
- } else {
- struct xtables_target *m = NULL;
+ }
- t = RTA_DATA(tb[TCA_IPT_TARG]);
- m = get_target_name(t->u.user.name);
- if (m != NULL) {
- if (build_st(m, t) < 0) {
- fprintf(stderr, " %s error\n", m->name);
- return -1;
- }
- opts =
- merge_options(opts, m->extra_opts,
- &m->option_offset);
- } else {
- fprintf(stderr, " failed to find target %s\n\n",
- t->u.user.name);
+ t = RTA_DATA(tb[TCA_IPT_TARG]);
+ m = get_target_name(t->u.user.name);
+ if (m != NULL) {
+ if (build_st(m, t) < 0) {
+ fprintf(stderr, " %s error\n", m->name);
return -1;
}
- fprintf(f, "\ttarget ");
- m->print(NULL, m->t, 0);
- if (tb[TCA_IPT_INDEX] == NULL) {
- fprintf(f, " [NULL ipt target index ]\n");
- } else {
- __u32 index;
- index = rta_getattr_u32(tb[TCA_IPT_INDEX]);
- fprintf(f, "\n\tindex %u", index);
- }
+ opts =
+ merge_options(opts, m->extra_opts,
+ &m->option_offset);
+ } else {
+ fprintf(stderr, " failed to find target %s\n\n",
+ t->u.user.name);
+ return -1;
+ }
- if (tb[TCA_IPT_CNT]) {
- struct tc_cnt *c = RTA_DATA(tb[TCA_IPT_CNT]);
+ fprintf(f, "\ttarget ");
+ m->print(NULL, m->t, 0);
+ if (tb[TCA_IPT_INDEX] == NULL) {
+ fprintf(stderr, "Missing ipt target index\n");
+ } else {
+ __u32 index;
- fprintf(f, " ref %d bind %d", c->refcnt, c->bindcnt);
- }
- if (show_stats) {
- if (tb[TCA_IPT_TM]) {
- struct tcf_t *tm = RTA_DATA(tb[TCA_IPT_TM]);
+ index = rta_getattr_u32(tb[TCA_IPT_INDEX]);
+ fprintf(f, "\n\tindex %u", index);
+ }
- print_tm(f, tm);
- }
- }
- fprintf(f, "\n");
+ if (tb[TCA_IPT_CNT]) {
+ struct tc_cnt *c = RTA_DATA(tb[TCA_IPT_CNT]);
+
+ fprintf(f, " ref %d bind %d", c->refcnt, c->bindcnt);
+ }
+ if (show_stats) {
+ if (tb[TCA_IPT_TM]) {
+ struct tcf_t *tm = RTA_DATA(tb[TCA_IPT_TM]);
+ print_tm(f, tm);
+ }
}
+ fprintf(f, "\n");
+
free_opts(opts);
return 0;
parse_rtattr_nested(tb, TCA_MIRRED_MAX, arg);
if (tb[TCA_MIRRED_PARMS] == NULL) {
- print_string(PRINT_FP, NULL, "%s", "[NULL mirred parameters]");
+ fprintf(stderr, "Missing mirred parameters\n");
return -1;
}
p = RTA_DATA(tb[TCA_MIRRED_PARMS]);
parse_rtattr_nested(tb, TCA_NAT_MAX, arg);
if (tb[TCA_NAT_PARMS] == NULL) {
- print_string(PRINT_FP, NULL, "%s", "[NULL nat parameters]");
+ fprintf(stderr, "Missing nat parameters\n");
return -1;
}
sel = RTA_DATA(tb[TCA_NAT_PARMS]);
parse_rtattr_nested(tb, TCA_PEDIT_MAX, arg);
if (!tb[TCA_PEDIT_PARMS] && !tb[TCA_PEDIT_PARMS_EX]) {
- fprintf(f, "[NULL pedit parameters]");
+ fprintf(stderr, "Missing pedit parameters\n");
return -1;
}
if (!tb[TCA_SAMPLE_PARMS] || !tb[TCA_SAMPLE_RATE] ||
!tb[TCA_SAMPLE_PSAMPLE_GROUP]) {
- print_string(PRINT_FP, NULL, "%s", "[NULL sample parameters]");
+ fprintf(stderr, "Missing sample parameters\n");
return -1;
}
p = RTA_DATA(tb[TCA_SAMPLE_PARMS]);
parse_rtattr_nested(tb, TCA_DEF_MAX, arg);
if (tb[TCA_DEF_PARMS] == NULL) {
- fprintf(f, "[NULL simple parameters]");
+ fprintf(stderr, "Missing simple parameters\n");
return -1;
}
sel = RTA_DATA(tb[TCA_DEF_PARMS]);
if (tb[TCA_DEF_DATA] == NULL) {
- fprintf(f, "[missing simple string]");
+ fprintf(stderr, "Missing simple string\n");
return -1;
}
SPRINT_BUF(b1);
__u32 priority;
__u16 ptype;
- struct tc_skbedit *p = NULL;
+ struct tc_skbedit *p;
if (arg == NULL)
return -1;
parse_rtattr_nested(tb, TCA_SKBEDIT_MAX, arg);
if (tb[TCA_SKBEDIT_PARMS] == NULL) {
- print_string(PRINT_FP, NULL, "%s", "[NULL skbedit parameters]");
+ fprintf(stderr, "Missing skbedit parameters\n");
return -1;
}
p = RTA_DATA(tb[TCA_SKBEDIT_PARMS]);
static int print_skbmod(struct action_util *au, FILE *f, struct rtattr *arg)
{
- struct tc_skbmod *p = NULL;
+ struct tc_skbmod *p;
struct rtattr *tb[TCA_SKBMOD_MAX + 1];
__u16 skbmod_etype = 0;
int has_optional = 0;
parse_rtattr_nested(tb, TCA_SKBMOD_MAX, arg);
if (tb[TCA_SKBMOD_PARMS] == NULL) {
- fprintf(f, "[NULL skbmod parameters]");
+ fprintf(stderr, "Missing skbmod parameters\n");
return -1;
}
parse_rtattr_nested(tb, TCA_TUNNEL_KEY_MAX, arg);
if (!tb[TCA_TUNNEL_KEY_PARMS]) {
- print_string(PRINT_FP, NULL, "%s",
- "[NULL tunnel_key parameters]");
+ fprintf(stderr, "Missing tunnel_key parameters\n");
return -1;
}
parm = RTA_DATA(tb[TCA_TUNNEL_KEY_PARMS]);
parse_rtattr_nested(tb, TCA_VLAN_MAX, arg);
if (!tb[TCA_VLAN_PARMS]) {
- print_string(PRINT_FP, NULL, "%s", "[NULL vlan parameters]");
+ fprintf(stderr, "Missing vlanparameters\n");
return -1;
}
parm = RTA_DATA(tb[TCA_VLAN_PARMS]);
struct xtables_target *m;
struct rtattr *tb[TCA_IPT_MAX + 1];
struct xt_entry_target *t = NULL;
+ __u32 hook;
if (arg == NULL)
return -1;
parse_rtattr_nested(tb, TCA_IPT_MAX, arg);
if (tb[TCA_IPT_TABLE] == NULL) {
- fprintf(f, "[NULL ipt table name ] assuming mangle ");
+ fprintf(stderr, "Missing ipt table name, assuming mangle\n");
} else {
fprintf(f, "tablename: %s ",
rta_getattr_str(tb[TCA_IPT_TABLE]));
}
if (tb[TCA_IPT_HOOK] == NULL) {
- fprintf(f, "[NULL ipt hook name ]\n ");
+ fprintf(stderr, "Missing ipt hook name\n ");
return -1;
- } else {
- __u32 hook;
-
- hook = rta_getattr_u32(tb[TCA_IPT_HOOK]);
- fprintf(f, " hook: %s\n", ipthooks[hook]);
}
if (tb[TCA_IPT_TARG] == NULL) {
- fprintf(f, "\t[NULL ipt target parameters ]\n");
+ fprintf(stderr, "Missing ipt target parameters\n");
return -1;
}
+ hook = rta_getattr_u32(tb[TCA_IPT_HOOK]);
+ fprintf(f, " hook: %s\n", ipthooks[hook]);
+
t = RTA_DATA(tb[TCA_IPT_TARG]);
m = xtables_find_target(t->u.user.name, XTF_TRY_LOAD);
if (!m) {
{
struct rtattr *tb[TCA_IPT_MAX + 1];
struct xt_entry_target *t = NULL;
+ struct xtables_target *m;
+ __u32 hook;
if (arg == NULL)
return -1;
parse_rtattr_nested(tb, TCA_IPT_MAX, arg);
if (tb[TCA_IPT_TABLE] == NULL) {
- fprintf(f, "[NULL ipt table name ] assuming mangle ");
+ fprintf(stderr, "Missing ipt table name, assuming mangle\n");
} else {
fprintf(f, "tablename: %s ",
rta_getattr_str(tb[TCA_IPT_TABLE]));
}
if (tb[TCA_IPT_HOOK] == NULL) {
- fprintf(f, "[NULL ipt hook name ]\n ");
+ fprintf(stderr, "Missing ipt hook name\n");
return -1;
- } else {
- __u32 hook;
-
- hook = rta_getattr_u32(tb[TCA_IPT_HOOK]);
- fprintf(f, " hook: %s\n", ipthooks[hook]);
}
if (tb[TCA_IPT_TARG] == NULL) {
- fprintf(f, "\t[NULL ipt target parameters ]\n");
+ fprintf(stderr, "Missing ipt target parameters\n");
return -1;
- } else {
- struct xtables_target *m = NULL;
+ }
- t = RTA_DATA(tb[TCA_IPT_TARG]);
- m = find_target(t->u.user.name, TRY_LOAD);
- if (m != NULL) {
- if (build_st(m, t) < 0) {
- fprintf(stderr, " %s error\n", m->name);
- return -1;
- }
+ hook = rta_getattr_u32(tb[TCA_IPT_HOOK]);
+ fprintf(f, " hook: %s\n", ipthooks[hook]);
- opts =
- merge_options(opts, m->extra_opts,
- &m->option_offset);
- } else {
- fprintf(stderr, " failed to find target %s\n\n",
- t->u.user.name);
+ t = RTA_DATA(tb[TCA_IPT_TARG]);
+ m = find_target(t->u.user.name, TRY_LOAD);
+ if (m != NULL) {
+ if (build_st(m, t) < 0) {
+ fprintf(stderr, " %s error\n", m->name);
return -1;
}
- fprintf(f, "\ttarget ");
- m->print(NULL, m->t, 0);
- if (tb[TCA_IPT_INDEX] == NULL) {
- fprintf(f, " [NULL ipt target index ]\n");
- } else {
- __u32 index;
- index = rta_getattr_u32(tb[TCA_IPT_INDEX]);
- fprintf(f, "\n\tindex %u", index);
- }
+ opts =
+ merge_options(opts, m->extra_opts,
+ &m->option_offset);
+ } else {
+ fprintf(stderr, " failed to find target %s\n\n",
+ t->u.user.name);
+ return -1;
+ }
+ fprintf(f, "\ttarget ");
+ m->print(NULL, m->t, 0);
+ if (tb[TCA_IPT_INDEX] == NULL) {
+ fprintf(f, " [NULL ipt target index ]\n");
+ } else {
+ __u32 index;
- if (tb[TCA_IPT_CNT]) {
- struct tc_cnt *c = RTA_DATA(tb[TCA_IPT_CNT]);
+ index = rta_getattr_u32(tb[TCA_IPT_INDEX]);
+ fprintf(f, "\n\tindex %u", index);
+ }
- fprintf(f, " ref %d bind %d", c->refcnt, c->bindcnt);
- }
- if (show_stats) {
- if (tb[TCA_IPT_TM]) {
- struct tcf_t *tm = RTA_DATA(tb[TCA_IPT_TM]);
+ if (tb[TCA_IPT_CNT]) {
+ struct tc_cnt *c = RTA_DATA(tb[TCA_IPT_CNT]);
- print_tm(f, tm);
- }
- }
- fprintf(f, "\n");
+ fprintf(f, " ref %d bind %d", c->refcnt, c->bindcnt);
+ }
+ if (show_stats) {
+ if (tb[TCA_IPT_TM]) {
+ struct tcf_t *tm = RTA_DATA(tb[TCA_IPT_TM]);
+ print_tm(f, tm);
+ }
}
+ fprintf(f, "\n");
+
free_opts(opts);
return 0;
if (q)
q->print_fopt(q, fp, tb[TCA_OPTIONS], t->tcm_handle);
else
- print_string(PRINT_FP, NULL,
- "[cannot parse parameters]", NULL);
+ fprintf(stderr, "cannot parse option parameters\n");
close_json_object();
}
}
if (q)
q->print_qopt(q, fp, tb[TCA_OPTIONS]);
else
- print_string(PRINT_FP, NULL,
- "[cannot parse qdisc parameters]", NULL);
+ fprintf(stderr, "Cannot parse qdisc parameters\n");
}
close_json_object();