net/sched: introduce ACT_P_BOUND return code
authorPedro Tammela <pctammela@mojatatu.com>
Fri, 29 Dec 2023 13:26:41 +0000 (10:26 -0300)
committerJakub Kicinski <kuba@kernel.org>
Thu, 4 Jan 2024 02:36:24 +0000 (18:36 -0800)
Bound actions always return '0' and as of today we rely on '0'
being returned in order to properly skip bound actions in
tcf_idr_insert_many. In order to further improve maintainability,
introduce the ACT_P_BOUND return code.

Actions are updated to return 'ACT_P_BOUND' instead of plain '0'.
tcf_idr_insert_many is then updated to check for 'ACT_P_BOUND'.

Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>
Link: https://lore.kernel.org/r/20231229132642.1489088-1-pctammela@mojatatu.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
21 files changed:
include/net/act_api.h
net/sched/act_api.c
net/sched/act_bpf.c
net/sched/act_connmark.c
net/sched/act_csum.c
net/sched/act_ct.c
net/sched/act_ctinfo.c
net/sched/act_gact.c
net/sched/act_gate.c
net/sched/act_ife.c
net/sched/act_mirred.c
net/sched/act_mpls.c
net/sched/act_nat.c
net/sched/act_pedit.c
net/sched/act_police.c
net/sched/act_sample.c
net/sched/act_simple.c
net/sched/act_skbedit.c
net/sched/act_skbmod.c
net/sched/act_tunnel_key.c
net/sched/act_vlan.c

index ea13e1e4a7c292bfdc6603650dd665de14fd4002..447985a45ef699605b0a16ad66b32ce8163f941e 100644 (file)
@@ -137,6 +137,7 @@ struct tc_action_ops {
 
 #ifdef CONFIG_NET_CLS_ACT
 
+#define ACT_P_BOUND 0
 #define ACT_P_CREATED 1
 #define ACT_P_DELETED 1
 
index a44c097a880d3f4d47ef1939427da590d3176f84..ef70d4771811637eb0ce92c5510a063645abe77c 100644 (file)
@@ -1313,7 +1313,7 @@ void tcf_idr_insert_many(struct tc_action *actions[], int init_res[])
        tcf_act_for_each_action(i, a, actions) {
                struct tcf_idrinfo *idrinfo;
 
-               if (init_res[i] == 0) /* Bound */
+               if (init_res[i] == ACT_P_BOUND)
                        continue;
 
                idrinfo = a->idrinfo;
index b0455fda7d0bafdb7ec0e587301e3a4b5df472d8..6cfee6658103df8996197699c984af27f5eb77cb 100644 (file)
@@ -318,7 +318,7 @@ static int tcf_bpf_init(struct net *net, struct nlattr *nla,
        } else if (ret > 0) {
                /* Don't override defaults. */
                if (bind)
-                       return 0;
+                       return ACT_P_BOUND;
 
                if (!(flags & TCA_ACT_FLAGS_REPLACE)) {
                        tcf_idr_release(*act, bind);
index 0d7aee8933c5ffdc5acdb78138a9725ef63824f5..f8762756657d3cdf3644e89344eadf046cc68ed1 100644 (file)
@@ -146,7 +146,7 @@ static int tcf_connmark_init(struct net *net, struct nlattr *nla,
        } else if (ret > 0) {
                ci = to_connmark(*a);
                if (bind) {
-                       err = 0;
+                       err = ACT_P_BOUND;
                        goto out_free;
                }
                if (!(flags & TCA_ACT_FLAGS_REPLACE)) {
index 8ed285023a40a8009c212a8832e61bff7fe377c7..7f8b1f2f2ed927ad27e47c757c202549227f764a 100644 (file)
@@ -77,8 +77,8 @@ static int tcf_csum_init(struct net *net, struct nlattr *nla,
                }
                ret = ACT_P_CREATED;
        } else if (err > 0) {
-               if (bind)/* dont override defaults */
-                       return 0;
+               if (bind) /* dont override defaults */
+                       return ACT_P_BOUND;
                if (!(flags & TCA_ACT_FLAGS_REPLACE)) {
                        tcf_idr_release(*a, bind);
                        return -EEXIST;
index f69c47945175b657da6d7368c94693e81465296f..c3e004b5b820a4145b67fc03cfb73300cc8f24c5 100644 (file)
@@ -1349,7 +1349,7 @@ static int tcf_ct_init(struct net *net, struct nlattr *nla,
                res = ACT_P_CREATED;
        } else {
                if (bind)
-                       return 0;
+                       return ACT_P_BOUND;
 
                if (!(flags & TCA_ACT_FLAGS_REPLACE)) {
                        tcf_idr_release(*a, bind);
index 4d15b6a6169c45407eb4cabbdae67418514c9c34..e620f9a84afe503c74d4f34b0bf5bc021b4ce3e8 100644 (file)
@@ -221,7 +221,7 @@ static int tcf_ctinfo_init(struct net *net, struct nlattr *nla,
                ret = ACT_P_CREATED;
        } else if (err > 0) {
                if (bind) /* don't override defaults */
-                       return 0;
+                       return ACT_P_BOUND;
                if (!(flags & TCA_ACT_FLAGS_REPLACE)) {
                        tcf_idr_release(*a, bind);
                        return -EEXIST;
index 904ab3d457ef8b9d1ae6851dd129fa1c6596ec96..4af3b7ec249fa388d5c90773ea323d2fca538664 100644 (file)
@@ -108,7 +108,7 @@ static int tcf_gact_init(struct net *net, struct nlattr *nla,
                ret = ACT_P_CREATED;
        } else if (err > 0) {
                if (bind)/* dont override defaults */
-                       return 0;
+                       return ACT_P_BOUND;
                if (!(flags & TCA_ACT_FLAGS_REPLACE)) {
                        tcf_idr_release(*a, bind);
                        return -EEXIST;
index 393b78729216cc3c5b1eeffebcfd9cebd8cda448..c681cd011afd0f837c604a5b02c5a8c18c96cdf4 100644 (file)
@@ -356,7 +356,7 @@ static int tcf_gate_init(struct net *net, struct nlattr *nla,
                return err;
 
        if (err && bind)
-               return 0;
+               return ACT_P_BOUND;
 
        if (!err) {
                ret = tcf_idr_create_from_flags(tn, index, est, a,
index bc7611b0744c41c7ec26b3b1ae4ee8743bcdfbd5..0e867d13beb5d3a4732ee45dbf2c2c02ae129898 100644 (file)
@@ -548,7 +548,7 @@ static int tcf_ife_init(struct net *net, struct nlattr *nla,
        exists = err;
        if (exists && bind) {
                kfree(p);
-               return 0;
+               return ACT_P_BOUND;
        }
 
        if (!exists) {
index d1f9794ca9b7930a36f45034152a87959ae9cf8c..12386f590b0f61f45e4ff40c9ec3605326671a2d 100644 (file)
@@ -135,7 +135,7 @@ static int tcf_mirred_init(struct net *net, struct nlattr *nla,
                return err;
        exists = err;
        if (exists && bind)
-               return 0;
+               return ACT_P_BOUND;
 
        if (tb[TCA_MIRRED_BLOCKID] && parm->ifindex) {
                NL_SET_ERR_MSG_MOD(extack,
index 1010dc632874ec5f4f0517f0512ab3ed30f14e24..34b8edb6cc77a0fa9e8d9a1c23bf83575b316731 100644 (file)
@@ -195,7 +195,7 @@ static int tcf_mpls_init(struct net *net, struct nlattr *nla,
                return err;
        exists = err;
        if (exists && bind)
-               return 0;
+               return ACT_P_BOUND;
 
        if (!exists) {
                ret = tcf_idr_create(tn, index, est, a, &act_mpls_ops, bind,
index 4184af5abbf36bae40aa5bb9fb441038d6ab0332..a180e724634edf4d45bbb9e8ee08bcef11ecfa15 100644 (file)
@@ -69,7 +69,7 @@ static int tcf_nat_init(struct net *net, struct nlattr *nla, struct nlattr *est,
                ret = ACT_P_CREATED;
        } else if (err > 0) {
                if (bind)
-                       return 0;
+                       return ACT_P_BOUND;
                if (!(flags & TCA_ACT_FLAGS_REPLACE)) {
                        tcf_idr_release(*a, bind);
                        return -EEXIST;
index 1ef8fcfa9997d1bda0314101fd3b050a270b717e..2ef22969f274d1fd1e2b293c3366626f778425e1 100644 (file)
@@ -202,7 +202,7 @@ static int tcf_pedit_init(struct net *net, struct nlattr *nla,
                ret = ACT_P_CREATED;
        } else if (err > 0) {
                if (bind)
-                       return 0;
+                       return ACT_P_BOUND;
                if (!(flags & TCA_ACT_FLAGS_REPLACE)) {
                        ret = -EEXIST;
                        goto out_release;
index f3121c5a85e9f76bef80c34c02d224d826ecdb7b..e119b4a3db9ffb5b73bd2f5327b17cc15ee8a8b7 100644 (file)
@@ -77,7 +77,7 @@ static int tcf_police_init(struct net *net, struct nlattr *nla,
                return err;
        exists = err;
        if (exists && bind)
-               return 0;
+               return ACT_P_BOUND;
 
        if (!exists) {
                ret = tcf_idr_create(tn, index, NULL, a,
index 4c670e7568dc617c696ce38b2093558e5a36aa96..c5c61efe6db425fce7646986792ef2a92d9421bf 100644 (file)
@@ -66,7 +66,7 @@ static int tcf_sample_init(struct net *net, struct nlattr *nla,
                return err;
        exists = err;
        if (exists && bind)
-               return 0;
+               return ACT_P_BOUND;
 
        if (!exists) {
                ret = tcf_idr_create(tn, index, est, a,
index 4b84514534f39ae19f51363be9ab6a1de61bbaff..0a3e92888295519b54735f6e050eeafa50890336 100644 (file)
@@ -118,7 +118,7 @@ static int tcf_simp_init(struct net *net, struct nlattr *nla,
                return err;
        exists = err;
        if (exists && bind)
-               return 0;
+               return ACT_P_BOUND;
 
        if (tb[TCA_DEF_DATA] == NULL) {
                if (exists)
index ce7008cf291c3f531fc1aa27cc07f58aa62e563c..754f78b35bb81384f215c4b7ea837997cd42c746 100644 (file)
@@ -209,7 +209,7 @@ static int tcf_skbedit_init(struct net *net, struct nlattr *nla,
                return err;
        exists = err;
        if (exists && bind)
-               return 0;
+               return ACT_P_BOUND;
 
        if (!flags) {
                if (exists)
index dffa990a9629f0ca3d04c4667534908968f7a8d2..bcb673ab0008dae8a7c4016bd23d6d2665f326ad 100644 (file)
@@ -157,7 +157,7 @@ static int tcf_skbmod_init(struct net *net, struct nlattr *nla,
                return err;
        exists = err;
        if (exists && bind)
-               return 0;
+               return ACT_P_BOUND;
 
        if (!lflags) {
                if (exists)
index 0c8aa7e686eab0cb3f9d8d27faf5996e80ec293f..300b08aa82831dd622c1956eec3ef67f89d831e9 100644 (file)
@@ -401,7 +401,7 @@ static int tunnel_key_init(struct net *net, struct nlattr *nla,
                return err;
        exists = err;
        if (exists && bind)
-               return 0;
+               return ACT_P_BOUND;
 
        switch (parm->t_action) {
        case TCA_TUNNEL_KEY_ACT_RELEASE:
index 0251442f5f29d0796e82daab833bd1922c16c030..836183011a7c9f91b8719bdbfcfcfb2f81946071 100644 (file)
@@ -151,7 +151,7 @@ static int tcf_vlan_init(struct net *net, struct nlattr *nla,
                return err;
        exists = err;
        if (exists && bind)
-               return 0;
+               return ACT_P_BOUND;
 
        switch (parm->v_action) {
        case TCA_VLAN_ACT_POP: