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 ea13e1e..447985a 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 a44c097..ef70d47 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 b0455fd..6cfee66 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 0d7aee8..f876275 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 8ed2850..7f8b1f2 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 f69c479..c3e004b 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 4d15b6a..e620f9a 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 904ab3d..4af3b7e 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 393b787..c681cd0 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 bc7611b..0e867d1 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 d1f9794..12386f5 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 1010dc6..34b8edb 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 4184af5..a180e72 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 1ef8fcf..2ef2296 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 f3121c5..e119b4a 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 4c670e7..c5c61ef 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 4b84514..0a3e928 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 ce7008c..754f78b 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 dffa990..bcb673a 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 0c8aa7e..300b08a 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 0251442..8361830 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: