]> git.proxmox.com Git - mirror_iproute2.git/commitdiff
tc: skip actions that don't have options attribute when printing
authorVlad Buslov <vladbu@mellanox.com>
Fri, 23 Oct 2020 14:55:35 +0000 (17:55 +0300)
committerDavid Ahern <dsahern@gmail.com>
Sat, 31 Oct 2020 15:14:01 +0000 (09:14 -0600)
Modify implementations that return error from action_until->print_aopt()
callback to silently skip actions that don't have their corresponding
TCA_ACT_OPTIONS attribute set (some actions already behave like this).
Print action kind before returning from action_until->print_aopt()
callbacks. This is necessary to support terse dump mode in following patch
in the series.

Signed-off-by: Vlad Buslov <vladbu@mellanox.com>
Suggested-by: Jamal Hadi Salim <jhs@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
20 files changed:
tc/m_bpf.c
tc/m_connmark.c
tc/m_csum.c
tc/m_ct.c
tc/m_ctinfo.c
tc/m_gact.c
tc/m_ife.c
tc/m_ipt.c
tc/m_mirred.c
tc/m_mpls.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

index e8d704b557f954fb19553709a0241eefffcc14d0..af5ba5ce45dc3dc314682d9766e8acf81cca6c74 100644 (file)
@@ -161,8 +161,9 @@ static int bpf_print_opt(struct action_util *au, FILE *f, struct rtattr *arg)
        struct tc_act_bpf *parm;
        int d_ok = 0;
 
+       print_string(PRINT_ANY, "kind", "%s ", "bpf");
        if (arg == NULL)
-               return -1;
+               return 0;
 
        parse_rtattr_nested(tb, TCA_ACT_BPF_MAX, arg);
 
@@ -172,7 +173,6 @@ static int bpf_print_opt(struct action_util *au, FILE *f, struct rtattr *arg)
        }
 
        parm = RTA_DATA(tb[TCA_ACT_BPF_PARMS]);
-       print_string(PRINT_ANY, "kind", "%s ", "bpf");
 
        if (tb[TCA_ACT_BPF_NAME])
                print_string(PRINT_ANY, "bpf_name", "%s ",
index 4b2dc4e25ef8fad3dab9b68c82afbdb584871f0d..640bba9da18e61d8764853d59e3013ccda892080 100644 (file)
@@ -110,8 +110,9 @@ static int print_connmark(struct action_util *au, FILE *f, struct rtattr *arg)
        struct rtattr *tb[TCA_CONNMARK_MAX + 1];
        struct tc_connmark *ci;
 
+       print_string(PRINT_ANY, "kind", "%s ", "connmark");
        if (arg == NULL)
-               return -1;
+               return 0;
 
        parse_rtattr_nested(tb, TCA_CONNMARK_MAX, arg);
        if (tb[TCA_CONNMARK_PARMS] == NULL) {
@@ -121,7 +122,6 @@ static int print_connmark(struct action_util *au, FILE *f, struct rtattr *arg)
 
        ci = RTA_DATA(tb[TCA_CONNMARK_PARMS]);
 
-       print_string(PRINT_ANY, "kind", "%s ", "connmark");
        print_uint(PRINT_ANY, "zone", "zone %u", ci->zone);
        print_action_control(f, " ", ci->action, "");
 
index afbee9c8de0f9398623c79a1944d86ad11345cc4..23c5972535c60512bdc3fdb7aca8a2ef8ce9b8c2 100644 (file)
@@ -166,8 +166,9 @@ print_csum(struct action_util *au, FILE *f, struct rtattr *arg)
 
        int uflag_count = 0;
 
+       print_string(PRINT_ANY, "kind", "%s ", "csum");
        if (arg == NULL)
-               return -1;
+               return 0;
 
        parse_rtattr_nested(tb, TCA_CSUM_MAX, arg);
 
@@ -199,7 +200,6 @@ print_csum(struct action_util *au, FILE *f, struct rtattr *arg)
                uflag_1 = "?empty";
        }
 
-       print_string(PRINT_ANY, "kind", "%s ", "csum");
        snprintf(buf, sizeof(buf), "%s%s%s%s%s%s%s",
                 uflag_1, uflag_2, uflag_3,
                 uflag_4, uflag_5, uflag_6, uflag_7);
index 70d186e859f4b694fbb6c9a75a1014c3f7ac0dba..a02bf0cc16556429f8c568ccd94578819eda3921 100644 (file)
--- a/tc/m_ct.c
+++ b/tc/m_ct.c
@@ -443,8 +443,9 @@ static int print_ct(struct action_util *au, FILE *f, struct rtattr *arg)
        struct tc_ct *p;
        int ct_action = 0;
 
+       print_string(PRINT_ANY, "kind", "%s", "ct");
        if (arg == NULL)
-               return -1;
+               return 0;
 
        parse_rtattr_nested(tb, TCA_CT_MAX, arg);
        if (tb[TCA_CT_PARMS] == NULL) {
@@ -454,8 +455,6 @@ static int print_ct(struct action_util *au, FILE *f, struct rtattr *arg)
 
        p = RTA_DATA(tb[TCA_CT_PARMS]);
 
-       print_string(PRINT_ANY, "kind", "%s", "ct");
-
        if (tb[TCA_CT_ACTION])
                ct_action = rta_getattr_u16(tb[TCA_CT_ACTION]);
        if (ct_action & TCA_CT_ACT_COMMIT) {
index e5c1b43642a7c9acc60ae5945c31566431676a62..996a36217dfed6ccecf0bfa96e8ec2997314477c 100644 (file)
@@ -188,8 +188,9 @@ static int print_ctinfo(struct action_util *au, FILE *f, struct rtattr *arg)
        unsigned short zone = 0;
        struct tc_ctinfo *ci;
 
+       print_string(PRINT_ANY, "kind", "%s ", "ctinfo");
        if (arg == NULL)
-               return -1;
+               return 0;
 
        parse_rtattr_nested(tb, TCA_CTINFO_MAX, arg);
        if (!tb[TCA_CTINFO_ACT]) {
@@ -234,7 +235,6 @@ static int print_ctinfo(struct action_util *au, FILE *f, struct rtattr *arg)
            sizeof(__u16))
                zone = rta_getattr_u16(tb[TCA_CTINFO_ZONE]);
 
-       print_string(PRINT_ANY, "kind", "%s ", "ctinfo");
        print_hu(PRINT_ANY, "zone", "zone %u", zone);
        print_action_control(f, " ", ci->action, "");
 
index 33f326f823d1edb8dd54853df937b5fb36aa01a7..2ef52cd1055996067373bc28c3f4e49fb186e342 100644 (file)
@@ -171,8 +171,9 @@ print_gact(struct action_util *au, FILE *f, struct rtattr *arg)
        struct tc_gact *p = NULL;
        struct rtattr *tb[TCA_GACT_MAX + 1];
 
+       print_string(PRINT_ANY, "kind", "%s ", "gact");
        if (arg == NULL)
-               return -1;
+               return 0;
 
        parse_rtattr_nested(tb, TCA_GACT_MAX, arg);
 
@@ -182,7 +183,6 @@ print_gact(struct action_util *au, FILE *f, struct rtattr *arg)
        }
        p = RTA_DATA(tb[TCA_GACT_PARMS]);
 
-       print_string(PRINT_ANY, "kind", "%s ", "gact");
        print_action_control(f, "action ", p->action, "");
 #ifdef CONFIG_GACT_PROB
        if (tb[TCA_GACT_PROB] != NULL) {
index 6a85e087ede1cc2c4085d0c51abb54218fc257aa..70ab1d754fc5da9dd5dec18525e239bebfac4aa0 100644 (file)
@@ -227,8 +227,9 @@ static int print_ife(struct action_util *au, FILE *f, struct rtattr *arg)
        int has_optional = 0;
        SPRINT_BUF(b2);
 
+       print_string(PRINT_ANY, "kind", "%s ", "ife");
        if (arg == NULL)
-               return -1;
+               return 0;
 
        parse_rtattr_nested(tb, TCA_IFE_MAX, arg);
 
@@ -238,7 +239,6 @@ static int print_ife(struct action_util *au, FILE *f, struct rtattr *arg)
        }
        p = RTA_DATA(tb[TCA_IFE_PARMS]);
 
-       print_string(PRINT_ANY, "kind", "%s ", "ife");
        print_string(PRINT_ANY, "mode", "%s ",
                     p->flags & IFE_ENCODE ? "encode" : "decode");
        print_action_control(f, "action ", p->action, " ");
index cc95eab7fefba7e44c076a62e37d598952ee3d47..046b310e64ab752231186bd8f0823bfa1178d57c 100644 (file)
@@ -433,7 +433,7 @@ print_ipt(struct action_util *au, FILE * f, struct rtattr *arg)
        __u32 hook;
 
        if (arg == NULL)
-               return -1;
+               return 0;
 
        lib_dir = getenv("IPTABLES_LIB_DIR");
        if (!lib_dir)
index d2bdf4074a73be266ad257333345e962dc004389..38d8043baa46e857fb4e96a188ce40af6897ef08 100644 (file)
@@ -281,8 +281,9 @@ print_mirred(struct action_util *au, FILE *f, struct rtattr *arg)
        struct rtattr *tb[TCA_MIRRED_MAX + 1];
        const char *dev;
 
+       print_string(PRINT_ANY, "kind", "%s ", "mirred");
        if (arg == NULL)
-               return -1;
+               return 0;
 
        parse_rtattr_nested(tb, TCA_MIRRED_MAX, arg);
 
@@ -298,7 +299,6 @@ print_mirred(struct action_util *au, FILE *f, struct rtattr *arg)
                return -1;
        }
 
-       print_string(PRINT_ANY, "kind", "%s ", "mirred");
        print_string(PRINT_FP, NULL, "(%s", mirred_n2a(p->eaction));
        print_string(PRINT_JSON, "mirred_action", NULL,
                     mirred_action(p->eaction));
index 2c3752bace7481e58ce465ba8b8a51e37fc9f371..79aeeff2a94f99b3ab5f15cdd1226eea32d2237e 100644 (file)
@@ -213,8 +213,9 @@ static int print_mpls(struct action_util *au, FILE *f, struct rtattr *arg)
        SPRINT_BUF(b1);
        __u32 val;
 
+       print_string(PRINT_ANY, "kind", "%s ", "mpls");
        if (!arg)
-               return -1;
+               return 0;
 
        parse_rtattr_nested(tb, TCA_MPLS_MAX, arg);
 
@@ -224,7 +225,6 @@ static int print_mpls(struct action_util *au, FILE *f, struct rtattr *arg)
        }
        parm = RTA_DATA(tb[TCA_MPLS_PARMS]);
 
-       print_string(PRINT_ANY, "kind", "%s ", "mpls");
        print_string(PRINT_ANY, "mpls_action", " %s",
                     action_names[parm->m_action]);
 
index 56e8f47cdefddf5955e0c40640c187cd7abba1b5..654f9a3bd95e9136f3f5858a2ba86e1f9d37de78 100644 (file)
@@ -146,8 +146,9 @@ print_nat(struct action_util *au, FILE * f, struct rtattr *arg)
        SPRINT_BUF(buf2);
        int len;
 
+       print_string(PRINT_ANY, "type", " %s ", "nat");
        if (arg == NULL)
-               return -1;
+               return 0;
 
        parse_rtattr_nested(tb, TCA_NAT_MAX, arg);
 
@@ -160,7 +161,6 @@ print_nat(struct action_util *au, FILE * f, struct rtattr *arg)
        len = ffs(sel->mask);
        len = len ? 33 - len : 0;
 
-       print_string(PRINT_ANY, "type", " %s ", "nat");
        print_string(PRINT_ANY, "direction", "%s",
                     sel->flags & TCA_NAT_FLAG_EGRESS ? "egress" : "ingress");
 
index 51dcf10930e812a264481d914ec7efb54cecfd9c..24fede4a7cab60d0eb6226f09c62ad49e98cf33f 100644 (file)
@@ -745,8 +745,9 @@ static int print_pedit(struct action_util *au, FILE *f, struct rtattr *arg)
        struct m_pedit_key_ex *keys_ex = NULL;
        int err;
 
+       print_string(PRINT_ANY, "kind", " %s ", "pedit");
        if (arg == NULL)
-               return -1;
+               return 0;
 
        parse_rtattr_nested(tb, TCA_PEDIT_MAX, arg);
 
@@ -783,7 +784,6 @@ static int print_pedit(struct action_util *au, FILE *f, struct rtattr *arg)
                }
        }
 
-       print_string(PRINT_ANY, "kind", " %s ", "pedit");
        print_action_control(f, "action ", sel->action, " ");
        print_uint(PRINT_ANY, "nkeys", "keys %d\n", sel->nkeys);
        print_uint(PRINT_ANY, "index", " \t index %u", sel->index);
index 4a30513a6247398a194b33f5f23a368a908706d2..696d76095ae6d0df9e016ea518381379f0c5debf 100644 (file)
@@ -143,8 +143,9 @@ static int print_sample(struct action_util *au, FILE *f, struct rtattr *arg)
        struct rtattr *tb[TCA_SAMPLE_MAX + 1];
        struct tc_sample *p;
 
+       print_string(PRINT_ANY, "kind", "%s ", "sample");
        if (arg == NULL)
-               return -1;
+               return 0;
 
        parse_rtattr_nested(tb, TCA_SAMPLE_MAX, arg);
 
@@ -155,7 +156,6 @@ static int print_sample(struct action_util *au, FILE *f, struct rtattr *arg)
        }
        p = RTA_DATA(tb[TCA_SAMPLE_PARMS]);
 
-       print_string(PRINT_ANY, "kind", "%s ", "sample");
        print_uint(PRINT_ANY, "rate", "rate 1/%u ",
                   rta_getattr_u32(tb[TCA_SAMPLE_RATE]));
        print_uint(PRINT_ANY, "group", "group %u",
index 70897d6b7c13819495a06dc2345eca0a5df8779a..bc86be27cbccfee76f1d2acbbb6426450f927a1c 100644 (file)
@@ -166,7 +166,7 @@ static int print_simple(struct action_util *au, FILE *f, struct rtattr *arg)
        char *simpdata;
 
        if (arg == NULL)
-               return -1;
+               return 0;
 
        parse_rtattr_nested(tb, TCA_DEF_MAX, arg);
 
index 9afe2f0c049d1a440c655abc0df9cee22eefa50c..46d92b25582f6e896e5f6d2244d1f6b8f5913ecd 100644 (file)
@@ -198,8 +198,9 @@ static int print_skbedit(struct action_util *au, FILE *f, struct rtattr *arg)
        __u16 ptype;
        struct tc_skbedit *p;
 
+       print_string(PRINT_ANY, "kind", "%s ", "skbedit");
        if (arg == NULL)
-               return -1;
+               return 0;
 
        parse_rtattr_nested(tb, TCA_SKBEDIT_MAX, arg);
 
@@ -209,8 +210,6 @@ static int print_skbedit(struct action_util *au, FILE *f, struct rtattr *arg)
        }
        p = RTA_DATA(tb[TCA_SKBEDIT_PARMS]);
 
-       print_string(PRINT_ANY, "kind", "%s ", "skbedit");
-
        if (tb[TCA_SKBEDIT_QUEUE_MAPPING] != NULL) {
                print_uint(PRINT_ANY, "queue_mapping", "queue_mapping %u",
                           rta_getattr_u16(tb[TCA_SKBEDIT_QUEUE_MAPPING]));
index d38a5c1921e7a2030a71519d8c2c60206c92d8d0..e13d3f16bfcbff3d0c98cb71cbef5efb133a3a76 100644 (file)
@@ -169,7 +169,7 @@ static int print_skbmod(struct action_util *au, FILE *f, struct rtattr *arg)
        SPRINT_BUF(b2);
 
        if (arg == NULL)
-               return -1;
+               return 0;
 
        parse_rtattr_nested(tb, TCA_SKBMOD_MAX, arg);
 
index bfec90724d728bf93e49b391c140637c495fba3e..ca0dff119a49bec6997c527a54256a60269ce5c3 100644 (file)
@@ -670,8 +670,9 @@ static int print_tunnel_key(struct action_util *au, FILE *f, struct rtattr *arg)
        struct rtattr *tb[TCA_TUNNEL_KEY_MAX + 1];
        struct tc_tunnel_key *parm;
 
+       print_string(PRINT_ANY, "kind", "%s ", "tunnel_key");
        if (!arg)
-               return -1;
+               return 0;
 
        parse_rtattr_nested(tb, TCA_TUNNEL_KEY_MAX, arg);
 
@@ -681,8 +682,6 @@ static int print_tunnel_key(struct action_util *au, FILE *f, struct rtattr *arg)
        }
        parm = RTA_DATA(tb[TCA_TUNNEL_KEY_PARMS]);
 
-       print_string(PRINT_ANY, "kind", "%s ", "tunnel_key");
-
        switch (parm->t_action) {
        case TCA_TUNNEL_KEY_ACT_RELEASE:
                print_string(PRINT_ANY, "mode", " %s", "unset");
index e6b21330a05a6407bfe79678da464f8d4a0fa09a..dbb0912eff22a785cfb579d8378576ee1d277155 100644 (file)
@@ -238,8 +238,9 @@ static int print_vlan(struct action_util *au, FILE *f, struct rtattr *arg)
        __u16 val;
        struct tc_vlan *parm;
 
+       print_string(PRINT_ANY, "kind", "%s ", "vlan");
        if (arg == NULL)
-               return -1;
+               return 0;
 
        parse_rtattr_nested(tb, TCA_VLAN_MAX, arg);
 
@@ -249,7 +250,6 @@ static int print_vlan(struct action_util *au, FILE *f, struct rtattr *arg)
        }
        parm = RTA_DATA(tb[TCA_VLAN_PARMS]);
 
-       print_string(PRINT_ANY, "kind", "%s ", "vlan");
        print_string(PRINT_ANY, "vlan_action", " %s",
                     action_names[parm->v_action]);
 
index 487ba25ad391169cb8d518c59b2e10196ef71bde..deaf96a26f7517665973ff110a2b7354127437ce 100644 (file)
--- a/tc/m_xt.c
+++ b/tc/m_xt.c
@@ -320,7 +320,7 @@ print_ipt(struct action_util *au, FILE *f, struct rtattr *arg)
        __u32 hook;
 
        if (arg == NULL)
-               return -1;
+               return 0;
 
        /* copy tcipt_globals because .opts will be modified by iptables */
        struct xtables_globals tmp_tcipt_globals = tcipt_globals;
index 6a4509a9982ffc313f1999f60162c4cd9ee8dac6..db014898590d8252b506e33d0e2ae1c0220adc48 100644 (file)
@@ -358,7 +358,7 @@ print_ipt(struct action_util *au, FILE * f, struct rtattr *arg)
        __u32 hook;
 
        if (arg == NULL)
-               return -1;
+               return 0;
 
        set_lib_dir();