Skip to content

Commit

Permalink
net/sched: introduce ACT_P_BOUND return code
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Pedro Tammela authored and Jakub Kicinski committed Jan 4, 2024
1 parent d3d344a commit c2a67de
Show file tree
Hide file tree
Showing 21 changed files with 22 additions and 21 deletions.
1 change: 1 addition & 0 deletions include/net/act_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion net/sched/act_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion net/sched/act_bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion net/sched/act_connmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
4 changes: 2 additions & 2 deletions net/sched/act_csum.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion net/sched/act_ct.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion net/sched/act_ctinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion net/sched/act_gact.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion net/sched/act_gate.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion net/sched/act_ife.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion net/sched/act_mirred.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion net/sched/act_mpls.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion net/sched/act_nat.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion net/sched/act_pedit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion net/sched/act_police.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion net/sched/act_sample.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion net/sched/act_simple.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion net/sched/act_skbedit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion net/sched/act_skbmod.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion net/sched/act_tunnel_key.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion net/sched/act_vlan.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit c2a67de

Please sign in to comment.