]> git.proxmox.com Git - mirror_iproute2.git/commitdiff
tc: print all error messages to stderr
authorStephen Hemminger <stephen@networkplumber.org>
Tue, 9 Jul 2019 21:25:14 +0000 (14:25 -0700)
committerStephen Hemminger <stephen@networkplumber.org>
Thu, 11 Jul 2019 22:35:07 +0000 (15:35 -0700)
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>
19 files changed:
tc/m_bpf.c
tc/m_connmark.c
tc/m_csum.c
tc/m_gact.c
tc/m_ife.c
tc/m_ipt.c
tc/m_mirred.c
tc/m_nat.c
tc/m_pedit.c
tc/m_sample.c
tc/m_simple.c
tc/m_skbedit.c
tc/m_skbmod.c
tc/m_tunnel_key.c
tc/m_vlan.c
tc/m_xt.c
tc/m_xt_old.c
tc/tc_filter.c
tc/tc_qdisc.c

index e247da8da579f42a42dc2d8d385524f8e12c4582..e8d704b557f954fb19553709a0241eefffcc14d0 100644 (file)
@@ -167,7 +167,7 @@ static int bpf_print_opt(struct action_util *au, FILE *f, struct rtattr *arg)
        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;
        }
 
index af5ebfc4e40bfda58572ad4a7179f63404903dd4..eac23489fb4cacf650a02b7b208e5d712e319d6c 100644 (file)
@@ -115,7 +115,7 @@ static int print_connmark(struct action_util *au, FILE *f, struct rtattr *arg)
 
        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;
        }
 
index 84396d6a482df9216d22de5778d48c70ce9cab2e..3e3dc251ea383a69c87af2d7cd1eb42921bc0ee5 100644 (file)
@@ -172,7 +172,7 @@ print_csum(struct action_util *au, FILE *f, struct rtattr *arg)
        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]);
index 32617d4ca33333840251eff6aef4a0ae9aaaf946..dca2a2f9692fd0bf9e993d84014482d9cffa981c 100644 (file)
@@ -177,7 +177,7 @@ print_gact(struct action_util *au, FILE *f, struct rtattr *arg)
        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]);
index 67c1df75a96a2c28a79926598572d6c124ff1319..7c612c02d0c9c2e0c4965331247d63ae67bd313e 100644 (file)
@@ -218,7 +218,7 @@ skip_encode:
 
 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;
@@ -233,7 +233,7 @@ static int print_ife(struct action_util *au, FILE *f, struct rtattr *arg)
        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]);
index 1d73cb98895a363943831bf1ac1f972e13268521..cc95eab7fefba7e44c076a62e37d598952ee3d47 100644 (file)
@@ -429,6 +429,8 @@ print_ipt(struct action_util *au, FILE * f, struct rtattr *arg)
 {
        struct rtattr *tb[TCA_IPT_MAX + 1];
        struct ipt_entry_target *t = NULL;
+       struct xtables_target *m;
+       __u32 hook;
 
        if (arg == NULL)
                return -1;
@@ -440,70 +442,68 @@ print_ipt(struct action_util *au, FILE * f, struct rtattr *arg)
        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;
index 23ba638a234d17f5503695f2405d35ed76189466..132095237929551c12613cc4e9e58b7431abe1bf 100644 (file)
@@ -287,7 +287,7 @@ print_mirred(struct action_util *au, FILE *f, struct rtattr *arg)
        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]);
index ee0b7520a605f2b1eeb6af4ffcfae36f253981d0..c4b02a83c3c729ebd417a61111e723f33ff65daa 100644 (file)
@@ -152,7 +152,7 @@ print_nat(struct action_util *au, FILE * f, struct rtattr *arg)
        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]);
index 8eb15f4b276d344aa7dd2213b75db7073badec8a..1cd2d162fc2abec443eb8861be89502291b327d4 100644 (file)
@@ -742,7 +742,7 @@ static int print_pedit(struct action_util *au, FILE *f, struct rtattr *arg)
        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;
        }
 
index 3c840d3f62c6c43e7a08199e52f560486ecad650..c068e6323b0cb4f8f58dde8e4e104ffeda8fcb39 100644 (file)
@@ -150,7 +150,7 @@ static int print_sample(struct action_util *au, FILE *f, struct rtattr *arg)
 
        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]);
index 34d1bab4cd201562f6596e873d5d655b5e26c178..49e250472e04cd364b65e26b7690d5b28ff43cc6 100644 (file)
@@ -171,13 +171,13 @@ static int print_simple(struct action_util *au, FILE *f, struct rtattr *arg)
        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;
        }
 
index 70e3a2e4eade3f23f3f7346ce6fa6d35a024c6ce..761cad586864b9d2342c5964d3285aeb44d8938a 100644 (file)
@@ -196,7 +196,7 @@ static int print_skbedit(struct action_util *au, FILE *f, struct rtattr *arg)
        SPRINT_BUF(b1);
        __u32 priority;
        __u16 ptype;
-       struct tc_skbedit *p = NULL;
+       struct tc_skbedit *p;
 
        if (arg == NULL)
                return -1;
@@ -204,7 +204,7 @@ static int print_skbedit(struct action_util *au, FILE *f, struct rtattr *arg)
        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]);
index 2dd1bb7e3d6dbe0e584703b4ecd6bb30769703a7..d38a5c1921e7a2030a71519d8c2c60206c92d8d0 100644 (file)
@@ -161,7 +161,7 @@ static int parse_skbmod(struct action_util *a, int *argc_p, char ***argv_p,
 
 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;
@@ -174,7 +174,7 @@ static int print_skbmod(struct action_util *au, FILE *f, struct rtattr *arg)
        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;
        }
 
index fd699017cfa780e829d6f277a50615979a8caf66..4e65e444776a2b93756b6371bad805806c7e3076 100644 (file)
@@ -493,8 +493,7 @@ static int print_tunnel_key(struct action_util *au, FILE *f, struct rtattr *arg)
        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]);
index 412f6aa1000e86fd2fff02039dace7912a997c45..9c8071e9dbbe0f18d9709c31a66ecfab04330862 100644 (file)
@@ -188,7 +188,7 @@ static int print_vlan(struct action_util *au, FILE *f, struct rtattr *arg)
        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]);
index 29574bd41f93eefb46214e969cec8772f568e72c..bf0db2be99a4b91a7e4d3de48758f8d32294e776 100644 (file)
--- a/tc/m_xt.c
+++ b/tc/m_xt.c
@@ -317,6 +317,7 @@ print_ipt(struct action_util *au, FILE *f, struct rtattr *arg)
        struct xtables_target *m;
        struct rtattr *tb[TCA_IPT_MAX + 1];
        struct xt_entry_target *t = NULL;
+       __u32 hook;
 
        if (arg == NULL)
                return -1;
@@ -330,27 +331,25 @@ print_ipt(struct action_util *au, FILE *f, struct rtattr *arg)
        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) {
index 25d3677857868b3b84a08a5ae8de18533c5d10c6..6a4509a9982ffc313f1999f60162c4cd9ee8dac6 100644 (file)
@@ -354,6 +354,8 @@ print_ipt(struct action_util *au, FILE * f, struct rtattr *arg)
 {
        struct rtattr *tb[TCA_IPT_MAX + 1];
        struct xt_entry_target *t = NULL;
+       struct xtables_target *m;
+       __u32 hook;
 
        if (arg == NULL)
                return -1;
@@ -363,70 +365,66 @@ print_ipt(struct action_util *au, FILE * f, struct rtattr *arg)
        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;
index e5c7bc4605a2abdb5649c8e75ea09e35e7ffd7c6..cd78c2441efa1061eb1e2c80a3678620780b4409 100644 (file)
@@ -375,8 +375,7 @@ int print_filter(struct nlmsghdr *n, void *arg)
                        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();
                }
        }
index e573a1df4e1ad557bae0f2e419061006cf7632d5..17e399830a75d81b0a34f5c727367c275a2536a0 100644 (file)
@@ -313,8 +313,7 @@ int print_qdisc(struct nlmsghdr *n, void *arg)
                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();