Commit e9ec8045 authored by David S. Miller's avatar David S. Miller

Merge branch 'Modify-action-API-for-implementing-lockless-actions'

Vlad Buslov says:

====================
Modify action API for implementing lockless actions

Currently, all netlink protocol handlers for updating rules, actions and
qdiscs are protected with single global rtnl lock which removes any
possibility for parallelism. This patch set is a first step to remove
rtnl lock dependency from TC rules update path.

Recently, new rtnl registration flag RTNL_FLAG_DOIT_UNLOCKED was added.
Handlers registered with this flag are called without RTNL taken. End
goal is to have rule update handlers(RTM_NEWTFILTER, RTM_DELTFILTER,
etc.) to be registered with UNLOCKED flag to allow parallel execution.
However, there is no intention to completely remove or split rtnl lock
itself. This patch set addresses specific problems in action API that
prevents it from being executed concurrently. This patch set does not
completely unlock rules or actions update path. Additional patch sets
are required to refactor individual actions and filters update for
parallel execution.

As a preparation for executing TC rules update handlers without rtnl
lock, action API code was audited to determine areas that assume
external synchronization with rtnl lock and must be changed to allow
safe concurrent access with following results:

1. Action idr is already protected with spinlock. However, some code
   paths assume that idr state is not changes between several
   consecutive tcf_idr_* function calls.
2. tc_action reference and bind counters are implemented as plain
   integers. They purpose was to allow single actions to be shared
   between multiple filters, not to provide means for concurrent
   modification.
3. tc_action 'cookie' pointer field is not protected against
   modification.
4. Action API functions, that work with set of actions, use intrusive
   linked list, which cannot be used concurrently without additional
   synchronization.
5. Action API functions don't take reference to actions while using
   them, assuming external synchronization with rtnl lock.

Following solutions to these problems are implemented:

1. To remove assumption that idr state doesn't change between tcf_idr_*
   calls, implement new functions that atomically perform several
   operations on idr without releasing idr spinlock. (function to
   atomically lookup and delete action by index, function to atomically
   check if action exists and allocate new one if necessary, etc.)
2. Use atomic operations on counters to make them suitable for
   concurrent get/put operations.
3. Data that 'cookie' points to is never modified, so it enough to
   refactor it to rcu pointer to prevent concurrent de-allocation.
4. Action API doesn't actually use any linked list specific operations
   on actions intrusive linked list, so it can be refactored to array in
   straightforward manner.
5. Always take reference to action while accessing it in action API.
   tcf_idr_search function modified to take reference to action before
   returning it, so there is no way to lookup an action without
   incrementing its reference counter. All users of this function are
   modified to release the reference, after they done using action. With
   all users using reference counting, it is now safe to concurrently
   delete actions.

Additionally, actions init function signature was expanded with
'rtnl_held' argument, that allows actions that have internal dependency
on rtnl lock to take/release it when necessary.

Since only shared state in action API module are actions themselves and
action idr, these changes are sufficient to not to rely on global rtnl
lock for protection of internal action API data structures.

Changes from V5 to V6:
- Rebase on current net-next
- When action is deleted, set pointer in actions array to NULL to
  prevent double freeing.

Changes from V4 to V5:
- Change action delete API to track actions that were deleted, to
  prevent releasing them on error.

Changes from V3 to V4:
- Expand cover letter.
- Reduce actions array size in tcf_action_init_1.
- Rebase on latest net-next.

Changes from V2 to V3:
- Re-send with changelog copied to individual patches.

Changes from V1 to V2:
- Removed redundant actions ops lookup during delete.
- Merge action ops delete definition and implementation.
- Assume all actions have delete implemented and don't check for it
  explicitly.
- Resplit action lookup/release code to prevent memory leaks in
  individual patches.
- Make __tcf_idr_check function static
- Remove unique idr insertion function. Change original idr insert to do
  the same thing.
- Merge changes that take reference to action when performing lookup and
  changes that account for this additional reference when dumping action
  to user space into single patch.
- Change convoluted commit message.
- Rename "unlocked" to "rtnl_held" for clarity.
- Remove estimator lock add patch.
- Refactor action check-alloc code into standalone function.
- Rename tcf_idr_find_delete to tcf_idr_delete_index.
- Rearrange variable definitions in tc_action_delete.
- Add patch that refactors action API code to use array of pointers to
  actions instead of intrusive linked list.
- Expand cover letter.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents b2335040 90b73b77
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
* Public action API for classifiers/qdiscs * Public action API for classifiers/qdiscs
*/ */
#include <linux/refcount.h>
#include <net/sch_generic.h> #include <net/sch_generic.h>
#include <net/pkt_sched.h> #include <net/pkt_sched.h>
#include <net/net_namespace.h> #include <net/net_namespace.h>
...@@ -26,8 +27,8 @@ struct tc_action { ...@@ -26,8 +27,8 @@ struct tc_action {
struct tcf_idrinfo *idrinfo; struct tcf_idrinfo *idrinfo;
u32 tcfa_index; u32 tcfa_index;
int tcfa_refcnt; refcount_t tcfa_refcnt;
int tcfa_bindcnt; atomic_t tcfa_bindcnt;
u32 tcfa_capab; u32 tcfa_capab;
int tcfa_action; int tcfa_action;
struct tcf_t tcfa_tm; struct tcf_t tcfa_tm;
...@@ -37,7 +38,7 @@ struct tc_action { ...@@ -37,7 +38,7 @@ struct tc_action {
spinlock_t tcfa_lock; spinlock_t tcfa_lock;
struct gnet_stats_basic_cpu __percpu *cpu_bstats; struct gnet_stats_basic_cpu __percpu *cpu_bstats;
struct gnet_stats_queue __percpu *cpu_qstats; struct gnet_stats_queue __percpu *cpu_qstats;
struct tc_cookie *act_cookie; struct tc_cookie __rcu *act_cookie;
struct tcf_chain *goto_chain; struct tcf_chain *goto_chain;
}; };
#define tcf_index common.tcfa_index #define tcf_index common.tcfa_index
...@@ -91,7 +92,8 @@ struct tc_action_ops { ...@@ -91,7 +92,8 @@ struct tc_action_ops {
struct netlink_ext_ack *extack); struct netlink_ext_ack *extack);
int (*init)(struct net *net, struct nlattr *nla, int (*init)(struct net *net, struct nlattr *nla,
struct nlattr *est, struct tc_action **act, int ovr, struct nlattr *est, struct tc_action **act, int ovr,
int bind, struct netlink_ext_ack *extack); int bind, bool rtnl_held,
struct netlink_ext_ack *extack);
int (*walk)(struct net *, struct sk_buff *, int (*walk)(struct net *, struct sk_buff *,
struct netlink_callback *, int, struct netlink_callback *, int,
const struct tc_action_ops *, const struct tc_action_ops *,
...@@ -99,6 +101,7 @@ struct tc_action_ops { ...@@ -99,6 +101,7 @@ struct tc_action_ops {
void (*stats_update)(struct tc_action *, u64, u32, u64); void (*stats_update)(struct tc_action *, u64, u32, u64);
size_t (*get_fill_size)(const struct tc_action *act); size_t (*get_fill_size)(const struct tc_action *act);
struct net_device *(*get_dev)(const struct tc_action *a); struct net_device *(*get_dev)(const struct tc_action *a);
int (*delete)(struct net *net, u32 index);
}; };
struct tc_action_net { struct tc_action_net {
...@@ -151,6 +154,10 @@ int tcf_idr_create(struct tc_action_net *tn, u32 index, struct nlattr *est, ...@@ -151,6 +154,10 @@ int tcf_idr_create(struct tc_action_net *tn, u32 index, struct nlattr *est,
int bind, bool cpustats); int bind, bool cpustats);
void tcf_idr_insert(struct tc_action_net *tn, struct tc_action *a); void tcf_idr_insert(struct tc_action_net *tn, struct tc_action *a);
void tcf_idr_cleanup(struct tc_action_net *tn, u32 index);
int tcf_idr_check_alloc(struct tc_action_net *tn, u32 *index,
struct tc_action **a, int bind);
int tcf_idr_delete_index(struct tc_action_net *tn, u32 index);
int __tcf_idr_release(struct tc_action *a, bool bind, bool strict); int __tcf_idr_release(struct tc_action *a, bool bind, bool strict);
static inline int tcf_idr_release(struct tc_action *a, bool bind) static inline int tcf_idr_release(struct tc_action *a, bool bind)
...@@ -161,18 +168,20 @@ static inline int tcf_idr_release(struct tc_action *a, bool bind) ...@@ -161,18 +168,20 @@ static inline int tcf_idr_release(struct tc_action *a, bool bind)
int tcf_register_action(struct tc_action_ops *a, struct pernet_operations *ops); int tcf_register_action(struct tc_action_ops *a, struct pernet_operations *ops);
int tcf_unregister_action(struct tc_action_ops *a, int tcf_unregister_action(struct tc_action_ops *a,
struct pernet_operations *ops); struct pernet_operations *ops);
int tcf_action_destroy(struct list_head *actions, int bind); int tcf_action_destroy(struct tc_action *actions[], int bind);
int tcf_action_exec(struct sk_buff *skb, struct tc_action **actions, int tcf_action_exec(struct sk_buff *skb, struct tc_action **actions,
int nr_actions, struct tcf_result *res); int nr_actions, struct tcf_result *res);
int tcf_action_init(struct net *net, struct tcf_proto *tp, struct nlattr *nla, int tcf_action_init(struct net *net, struct tcf_proto *tp, struct nlattr *nla,
struct nlattr *est, char *name, int ovr, int bind, struct nlattr *est, char *name, int ovr, int bind,
struct list_head *actions, size_t *attr_size, struct tc_action *actions[], size_t *attr_size,
struct netlink_ext_ack *extack); bool rtnl_held, struct netlink_ext_ack *extack);
struct tc_action *tcf_action_init_1(struct net *net, struct tcf_proto *tp, struct tc_action *tcf_action_init_1(struct net *net, struct tcf_proto *tp,
struct nlattr *nla, struct nlattr *est, struct nlattr *nla, struct nlattr *est,
char *name, int ovr, int bind, char *name, int ovr, int bind,
bool rtnl_held,
struct netlink_ext_ack *extack); struct netlink_ext_ack *extack);
int tcf_action_dump(struct sk_buff *skb, struct list_head *, int, int); int tcf_action_dump(struct sk_buff *skb, struct tc_action *actions[], int bind,
int ref);
int tcf_action_dump_old(struct sk_buff *skb, struct tc_action *a, int, int); int tcf_action_dump_old(struct sk_buff *skb, struct tc_action *a, int, int);
int tcf_action_dump_1(struct sk_buff *skb, struct tc_action *a, int, int); int tcf_action_dump_1(struct sk_buff *skb, struct tc_action *a, int, int);
int tcf_action_copy_stats(struct sk_buff *, struct tc_action *, int); int tcf_action_copy_stats(struct sk_buff *, struct tc_action *, int);
......
...@@ -781,6 +781,7 @@ struct tc_mqprio_qopt_offload { ...@@ -781,6 +781,7 @@ struct tc_mqprio_qopt_offload {
struct tc_cookie { struct tc_cookie {
u8 *data; u8 *data;
u32 len; u32 len;
struct rcu_head rcu;
}; };
struct tc_qopt_offload_stats { struct tc_qopt_offload_stats {
......
This diff is collapsed.
...@@ -141,8 +141,8 @@ static int tcf_bpf_dump(struct sk_buff *skb, struct tc_action *act, ...@@ -141,8 +141,8 @@ static int tcf_bpf_dump(struct sk_buff *skb, struct tc_action *act,
struct tcf_bpf *prog = to_bpf(act); struct tcf_bpf *prog = to_bpf(act);
struct tc_act_bpf opt = { struct tc_act_bpf opt = {
.index = prog->tcf_index, .index = prog->tcf_index,
.refcnt = prog->tcf_refcnt - ref, .refcnt = refcount_read(&prog->tcf_refcnt) - ref,
.bindcnt = prog->tcf_bindcnt - bind, .bindcnt = atomic_read(&prog->tcf_bindcnt) - bind,
.action = prog->tcf_action, .action = prog->tcf_action,
}; };
struct tcf_t tm; struct tcf_t tm;
...@@ -276,7 +276,8 @@ static void tcf_bpf_prog_fill_cfg(const struct tcf_bpf *prog, ...@@ -276,7 +276,8 @@ static void tcf_bpf_prog_fill_cfg(const struct tcf_bpf *prog,
static int tcf_bpf_init(struct net *net, struct nlattr *nla, static int tcf_bpf_init(struct net *net, struct nlattr *nla,
struct nlattr *est, struct tc_action **act, struct nlattr *est, struct tc_action **act,
int replace, int bind, struct netlink_ext_ack *extack) int replace, int bind, bool rtnl_held,
struct netlink_ext_ack *extack)
{ {
struct tc_action_net *tn = net_generic(net, bpf_net_id); struct tc_action_net *tn = net_generic(net, bpf_net_id);
struct nlattr *tb[TCA_ACT_BPF_MAX + 1]; struct nlattr *tb[TCA_ACT_BPF_MAX + 1];
...@@ -298,22 +299,28 @@ static int tcf_bpf_init(struct net *net, struct nlattr *nla, ...@@ -298,22 +299,28 @@ static int tcf_bpf_init(struct net *net, struct nlattr *nla,
parm = nla_data(tb[TCA_ACT_BPF_PARMS]); parm = nla_data(tb[TCA_ACT_BPF_PARMS]);
if (!tcf_idr_check(tn, parm->index, act, bind)) { ret = tcf_idr_check_alloc(tn, &parm->index, act, bind);
if (!ret) {
ret = tcf_idr_create(tn, parm->index, est, act, ret = tcf_idr_create(tn, parm->index, est, act,
&act_bpf_ops, bind, true); &act_bpf_ops, bind, true);
if (ret < 0) if (ret < 0) {
tcf_idr_cleanup(tn, parm->index);
return ret; return ret;
}
res = ACT_P_CREATED; res = ACT_P_CREATED;
} else { } else if (ret > 0) {
/* Don't override defaults. */ /* Don't override defaults. */
if (bind) if (bind)
return 0; return 0;
if (!replace) {
tcf_idr_release(*act, bind); tcf_idr_release(*act, bind);
if (!replace)
return -EEXIST; return -EEXIST;
} }
} else {
return ret;
}
is_bpf = tb[TCA_ACT_BPF_OPS_LEN] && tb[TCA_ACT_BPF_OPS]; is_bpf = tb[TCA_ACT_BPF_OPS_LEN] && tb[TCA_ACT_BPF_OPS];
is_ebpf = tb[TCA_ACT_BPF_FD]; is_ebpf = tb[TCA_ACT_BPF_FD];
...@@ -355,7 +362,6 @@ static int tcf_bpf_init(struct net *net, struct nlattr *nla, ...@@ -355,7 +362,6 @@ static int tcf_bpf_init(struct net *net, struct nlattr *nla,
return res; return res;
out: out:
if (res == ACT_P_CREATED)
tcf_idr_release(*act, bind); tcf_idr_release(*act, bind);
return ret; return ret;
...@@ -387,6 +393,13 @@ static int tcf_bpf_search(struct net *net, struct tc_action **a, u32 index, ...@@ -387,6 +393,13 @@ static int tcf_bpf_search(struct net *net, struct tc_action **a, u32 index,
return tcf_idr_search(tn, a, index); return tcf_idr_search(tn, a, index);
} }
static int tcf_bpf_delete(struct net *net, u32 index)
{
struct tc_action_net *tn = net_generic(net, bpf_net_id);
return tcf_idr_delete_index(tn, index);
}
static struct tc_action_ops act_bpf_ops __read_mostly = { static struct tc_action_ops act_bpf_ops __read_mostly = {
.kind = "bpf", .kind = "bpf",
.type = TCA_ACT_BPF, .type = TCA_ACT_BPF,
...@@ -397,6 +410,7 @@ static struct tc_action_ops act_bpf_ops __read_mostly = { ...@@ -397,6 +410,7 @@ static struct tc_action_ops act_bpf_ops __read_mostly = {
.init = tcf_bpf_init, .init = tcf_bpf_init,
.walk = tcf_bpf_walker, .walk = tcf_bpf_walker,
.lookup = tcf_bpf_search, .lookup = tcf_bpf_search,
.delete = tcf_bpf_delete,
.size = sizeof(struct tcf_bpf), .size = sizeof(struct tcf_bpf),
}; };
......
...@@ -96,7 +96,7 @@ static const struct nla_policy connmark_policy[TCA_CONNMARK_MAX + 1] = { ...@@ -96,7 +96,7 @@ static const struct nla_policy connmark_policy[TCA_CONNMARK_MAX + 1] = {
static int tcf_connmark_init(struct net *net, struct nlattr *nla, static int tcf_connmark_init(struct net *net, struct nlattr *nla,
struct nlattr *est, struct tc_action **a, struct nlattr *est, struct tc_action **a,
int ovr, int bind, int ovr, int bind, bool rtnl_held,
struct netlink_ext_ack *extack) struct netlink_ext_ack *extack)
{ {
struct tc_action_net *tn = net_generic(net, connmark_net_id); struct tc_action_net *tn = net_generic(net, connmark_net_id);
...@@ -118,11 +118,14 @@ static int tcf_connmark_init(struct net *net, struct nlattr *nla, ...@@ -118,11 +118,14 @@ static int tcf_connmark_init(struct net *net, struct nlattr *nla,
parm = nla_data(tb[TCA_CONNMARK_PARMS]); parm = nla_data(tb[TCA_CONNMARK_PARMS]);
if (!tcf_idr_check(tn, parm->index, a, bind)) { ret = tcf_idr_check_alloc(tn, &parm->index, a, bind);
if (!ret) {
ret = tcf_idr_create(tn, parm->index, est, a, ret = tcf_idr_create(tn, parm->index, est, a,
&act_connmark_ops, bind, false); &act_connmark_ops, bind, false);
if (ret) if (ret) {
tcf_idr_cleanup(tn, parm->index);
return ret; return ret;
}
ci = to_connmark(*a); ci = to_connmark(*a);
ci->tcf_action = parm->action; ci->tcf_action = parm->action;
...@@ -131,16 +134,18 @@ static int tcf_connmark_init(struct net *net, struct nlattr *nla, ...@@ -131,16 +134,18 @@ static int tcf_connmark_init(struct net *net, struct nlattr *nla,
tcf_idr_insert(tn, *a); tcf_idr_insert(tn, *a);
ret = ACT_P_CREATED; ret = ACT_P_CREATED;
} else { } else if (ret > 0) {
ci = to_connmark(*a); ci = to_connmark(*a);
if (bind) if (bind)
return 0; return 0;
if (!ovr) {
tcf_idr_release(*a, bind); tcf_idr_release(*a, bind);
if (!ovr)
return -EEXIST; return -EEXIST;
}
/* replacing action and zone */ /* replacing action and zone */
ci->tcf_action = parm->action; ci->tcf_action = parm->action;
ci->zone = parm->zone; ci->zone = parm->zone;
ret = 0;
} }
return ret; return ret;
...@@ -154,8 +159,8 @@ static inline int tcf_connmark_dump(struct sk_buff *skb, struct tc_action *a, ...@@ -154,8 +159,8 @@ static inline int tcf_connmark_dump(struct sk_buff *skb, struct tc_action *a,
struct tc_connmark opt = { struct tc_connmark opt = {
.index = ci->tcf_index, .index = ci->tcf_index,
.refcnt = ci->tcf_refcnt - ref, .refcnt = refcount_read(&ci->tcf_refcnt) - ref,
.bindcnt = ci->tcf_bindcnt - bind, .bindcnt = atomic_read(&ci->tcf_bindcnt) - bind,
.action = ci->tcf_action, .action = ci->tcf_action,
.zone = ci->zone, .zone = ci->zone,
}; };
...@@ -193,6 +198,13 @@ static int tcf_connmark_search(struct net *net, struct tc_action **a, u32 index, ...@@ -193,6 +198,13 @@ static int tcf_connmark_search(struct net *net, struct tc_action **a, u32 index,
return tcf_idr_search(tn, a, index); return tcf_idr_search(tn, a, index);
} }
static int tcf_connmark_delete(struct net *net, u32 index)
{
struct tc_action_net *tn = net_generic(net, connmark_net_id);
return tcf_idr_delete_index(tn, index);
}
static struct tc_action_ops act_connmark_ops = { static struct tc_action_ops act_connmark_ops = {
.kind = "connmark", .kind = "connmark",
.type = TCA_ACT_CONNMARK, .type = TCA_ACT_CONNMARK,
...@@ -202,6 +214,7 @@ static struct tc_action_ops act_connmark_ops = { ...@@ -202,6 +214,7 @@ static struct tc_action_ops act_connmark_ops = {
.init = tcf_connmark_init, .init = tcf_connmark_init,
.walk = tcf_connmark_walker, .walk = tcf_connmark_walker,
.lookup = tcf_connmark_search, .lookup = tcf_connmark_search,
.delete = tcf_connmark_delete,
.size = sizeof(struct tcf_connmark_info), .size = sizeof(struct tcf_connmark_info),
}; };
......
...@@ -46,7 +46,8 @@ static struct tc_action_ops act_csum_ops; ...@@ -46,7 +46,8 @@ static struct tc_action_ops act_csum_ops;
static int tcf_csum_init(struct net *net, struct nlattr *nla, static int tcf_csum_init(struct net *net, struct nlattr *nla,
struct nlattr *est, struct tc_action **a, int ovr, struct nlattr *est, struct tc_action **a, int ovr,
int bind, struct netlink_ext_ack *extack) int bind, bool rtnl_held,
struct netlink_ext_ack *extack)
{ {
struct tc_action_net *tn = net_generic(net, csum_net_id); struct tc_action_net *tn = net_generic(net, csum_net_id);
struct tcf_csum_params *params_old, *params_new; struct tcf_csum_params *params_old, *params_new;
...@@ -66,26 +67,31 @@ static int tcf_csum_init(struct net *net, struct nlattr *nla, ...@@ -66,26 +67,31 @@ static int tcf_csum_init(struct net *net, struct nlattr *nla,
return -EINVAL; return -EINVAL;
parm = nla_data(tb[TCA_CSUM_PARMS]); parm = nla_data(tb[TCA_CSUM_PARMS]);
if (!tcf_idr_check(tn, parm->index, a, bind)) { err = tcf_idr_check_alloc(tn, &parm->index, a, bind);
if (!err) {
ret = tcf_idr_create(tn, parm->index, est, a, ret = tcf_idr_create(tn, parm->index, est, a,
&act_csum_ops, bind, true); &act_csum_ops, bind, true);
if (ret) if (ret) {
tcf_idr_cleanup(tn, parm->index);
return ret; return ret;
}
ret = ACT_P_CREATED; ret = ACT_P_CREATED;
} else { } else if (err > 0) {
if (bind)/* dont override defaults */ if (bind)/* dont override defaults */
return 0; return 0;
if (!ovr) {
tcf_idr_release(*a, bind); tcf_idr_release(*a, bind);
if (!ovr)
return -EEXIST; return -EEXIST;
} }
} else {
return err;
}
p = to_tcf_csum(*a); p = to_tcf_csum(*a);
ASSERT_RTNL(); ASSERT_RTNL();
params_new = kzalloc(sizeof(*params_new), GFP_KERNEL); params_new = kzalloc(sizeof(*params_new), GFP_KERNEL);
if (unlikely(!params_new)) { if (unlikely(!params_new)) {
if (ret == ACT_P_CREATED)
tcf_idr_release(*a, bind); tcf_idr_release(*a, bind);
return -ENOMEM; return -ENOMEM;
} }
...@@ -597,8 +603,8 @@ static int tcf_csum_dump(struct sk_buff *skb, struct tc_action *a, int bind, ...@@ -597,8 +603,8 @@ static int tcf_csum_dump(struct sk_buff *skb, struct tc_action *a, int bind,
struct tcf_csum_params *params; struct tcf_csum_params *params;
struct tc_csum opt = { struct tc_csum opt = {
.index = p->tcf_index, .index = p->tcf_index,
.refcnt = p->tcf_refcnt - ref, .refcnt = refcount_read(&p->tcf_refcnt) - ref,
.bindcnt = p->tcf_bindcnt - bind, .bindcnt = atomic_read(&p->tcf_bindcnt) - bind,
}; };
struct tcf_t t; struct tcf_t t;
...@@ -653,6 +659,13 @@ static size_t tcf_csum_get_fill_size(const struct tc_action *act) ...@@ -653,6 +659,13 @@ static size_t tcf_csum_get_fill_size(const struct tc_action *act)
return nla_total_size(sizeof(struct tc_csum)); return nla_total_size(sizeof(struct tc_csum));
} }
static int tcf_csum_delete(struct net *net, u32 index)
{
struct tc_action_net *tn = net_generic(net, csum_net_id);
return tcf_idr_delete_index(tn, index);
}
static struct tc_action_ops act_csum_ops = { static struct tc_action_ops act_csum_ops = {
.kind = "csum", .kind = "csum",
.type = TCA_ACT_CSUM, .type = TCA_ACT_CSUM,
...@@ -664,6 +677,7 @@ static struct tc_action_ops act_csum_ops = { ...@@ -664,6 +677,7 @@ static struct tc_action_ops act_csum_ops = {
.walk = tcf_csum_walker, .walk = tcf_csum_walker,
.lookup = tcf_csum_search, .lookup = tcf_csum_search,
.get_fill_size = tcf_csum_get_fill_size, .get_fill_size = tcf_csum_get_fill_size,
.delete = tcf_csum_delete,
.size = sizeof(struct tcf_csum), .size = sizeof(struct tcf_csum),
}; };
......
...@@ -56,7 +56,8 @@ static const struct nla_policy gact_policy[TCA_GACT_MAX + 1] = { ...@@ -56,7 +56,8 @@ static const struct nla_policy gact_policy[TCA_GACT_MAX + 1] = {
static int tcf_gact_init(struct net *net, struct nlattr *nla, static int tcf_gact_init(struct net *net, struct nlattr *nla,
struct nlattr *est, struct tc_action **a, struct nlattr *est, struct tc_action **a,
int ovr, int bind, struct netlink_ext_ack *extack) int ovr, int bind, bool rtnl_held,
struct netlink_ext_ack *extack)
{ {
struct tc_action_net *tn = net_generic(net, gact_net_id); struct tc_action_net *tn = net_generic(net, gact_net_id);
struct nlattr *tb[TCA_GACT_MAX + 1]; struct nlattr *tb[TCA_GACT_MAX + 1];
...@@ -90,19 +91,25 @@ static int tcf_gact_init(struct net *net, struct nlattr *nla, ...@@ -90,19 +91,25 @@ static int tcf_gact_init(struct net *net, struct nlattr *nla,
} }
#endif #endif
if (!tcf_idr_check(tn, parm->index, a, bind)) { err = tcf_idr_check_alloc(tn, &parm->index, a, bind);
if (!err) {
ret = tcf_idr_create(tn, parm->index, est, a, ret = tcf_idr_create(tn, parm->index, est, a,
&act_gact_ops, bind, true); &act_gact_ops, bind, true);
if (ret) if (ret) {
tcf_idr_cleanup(tn, parm->index);
return ret; return ret;
}
ret = ACT_P_CREATED; ret = ACT_P_CREATED;
} else { } else if (err > 0) {
if (bind)/* dont override defaults */ if (bind)/* dont override defaults */
return 0; return 0;
if (!ovr) {
tcf_idr_release(*a, bind); tcf_idr_release(*a, bind);
if (!ovr)
return -EEXIST; return -EEXIST;
} }
} else {
return err;
}
gact = to_gact(*a); gact = to_gact(*a);
...@@ -169,8 +176,8 @@ static int tcf_gact_dump(struct sk_buff *skb, struct tc_action *a, ...@@ -169,8 +176,8 @@ static int tcf_gact_dump(struct sk_buff *skb, struct tc_action *a,
struct tcf_gact *gact = to_gact(a); struct tcf_gact *gact = to_gact(a);
struct tc_gact opt = { struct tc_gact opt = {
.index = gact->tcf_index, .index = gact->tcf_index,
.refcnt = gact->tcf_refcnt - ref, .refcnt = refcount_read(&gact->tcf_refcnt) - ref,
.bindcnt = gact->tcf_bindcnt - bind, .bindcnt = atomic_read(&gact->tcf_bindcnt) - bind,
.action = gact->tcf_action, .action = gact->tcf_action,
}; };
struct tcf_t t; struct tcf_t t;
...@@ -230,6 +237,13 @@ static size_t tcf_gact_get_fill_size(const struct tc_action *act) ...@@ -230,6 +237,13 @@ static size_t tcf_gact_get_fill_size(const struct tc_action *act)
return sz; return sz;
} }
static int tcf_gact_delete(struct net *net, u32 index)
{
struct tc_action_net *tn = net_generic(net, gact_net_id);
return tcf_idr_delete_index(tn, index);
}
static struct tc_action_ops act_gact_ops = { static struct tc_action_ops act_gact_ops = {
.kind = "gact", .kind = "gact",
.type = TCA_ACT_GACT, .type = TCA_ACT_GACT,
...@@ -241,6 +255,7 @@ static struct tc_action_ops act_gact_ops = { ...@@ -241,6 +255,7 @@ static struct tc_action_ops act_gact_ops = {
.walk = tcf_gact_walker, .walk = tcf_gact_walker,
.lookup = tcf_gact_search, .lookup = tcf_gact_search,
.get_fill_size = tcf_gact_get_fill_size, .get_fill_size = tcf_gact_get_fill_size,
.delete = tcf_gact_delete,
.size = sizeof(struct tcf_gact), .size = sizeof(struct tcf_gact),
}; };
......
...@@ -448,7 +448,8 @@ static int populate_metalist(struct tcf_ife_info *ife, struct nlattr **tb, ...@@ -448,7 +448,8 @@ static int populate_metalist(struct tcf_ife_info *ife, struct nlattr **tb,
static int tcf_ife_init(struct net *net, struct nlattr *nla, static int tcf_ife_init(struct net *net, struct nlattr *nla,
struct nlattr *est, struct tc_action **a, struct nlattr *est, struct tc_action **a,
int ovr, int bind, struct netlink_ext_ack *extack) int ovr, int bind, bool rtnl_held,
struct netlink_ext_ack *extack)
{ {
struct tc_action_net *tn = net_generic(net, ife_net_id); struct tc_action_net *tn = net_generic(net, ife_net_id);
struct nlattr *tb[TCA_IFE_MAX + 1]; struct nlattr *tb[TCA_IFE_MAX + 1];
...@@ -483,7 +484,10 @@ static int tcf_ife_init(struct net *net, struct nlattr *nla, ...@@ -483,7 +484,10 @@ static int tcf_ife_init(struct net *net, struct nlattr *nla,
if (!p) if (!p)
return -ENOMEM; return -ENOMEM;
exists = tcf_idr_check(tn, parm->index, a, bind); err = tcf_idr_check_alloc(tn, &parm->index, a, bind);
if (err < 0)
return err;
exists = err;
if (exists && bind) { if (exists && bind) {
kfree(p); kfree(p);
return 0; return 0;
...@@ -493,17 +497,16 @@ static int tcf_ife_init(struct net *net, struct nlattr *nla, ...@@ -493,17 +497,16 @@ static int tcf_ife_init(struct net *net, struct nlattr *nla,
ret = tcf_idr_create(tn, parm->index, est, a, &act_ife_ops, ret = tcf_idr_create(tn, parm->index, est, a, &act_ife_ops,
bind, true); bind, true);
if (ret) { if (ret) {
tcf_idr_cleanup(tn, parm->index);
kfree(p); kfree(p);
return ret; return ret;
} }
ret = ACT_P_CREATED; ret = ACT_P_CREATED;
} else { } else if (!ovr) {
tcf_idr_release(*a, bind); tcf_idr_release(*a, bind);
if (!ovr) {
kfree(p); kfree(p);
return -EEXIST; return -EEXIST;
} }
}
ife = to_ife(*a); ife = to_ife(*a);
p->flags = parm->flags; p->flags = parm->flags;
...@@ -547,6 +550,8 @@ static int tcf_ife_init(struct net *net, struct nlattr *nla, ...@@ -547,6 +550,8 @@ static int tcf_ife_init(struct net *net, struct nlattr *nla,
if (exists) if (exists)
spin_unlock_bh(&ife->tcf_lock); spin_unlock_bh(&ife->tcf_lock);
tcf_idr_release(*a, bind);
kfree(p); kfree(p);
return err; return err;
} }
...@@ -596,8 +601,8 @@ static int tcf_ife_dump(struct sk_buff *skb, struct tc_action *a, int bind, ...@@ -596,8 +601,8 @@ static int tcf_ife_dump(struct sk_buff *skb, struct tc_action *a, int bind,
struct tcf_ife_params *p = rtnl_dereference(ife->params); struct tcf_ife_params *p = rtnl_dereference(ife->params);
struct tc_ife opt = { struct tc_ife opt = {
.index = ife->tcf_index, .index = ife->tcf_index,
.refcnt = ife->tcf_refcnt - ref, .refcnt = refcount_read(&ife->tcf_refcnt) - ref,
.bindcnt = ife->tcf_bindcnt - bind, .bindcnt = atomic_read(&ife->tcf_bindcnt) - bind,
.action = ife->tcf_action, .action = ife->tcf_action,
.flags = p->flags, .flags = p->flags,
}; };
...@@ -843,6 +848,13 @@ static int tcf_ife_search(struct net *net, struct tc_action **a, u32 index, ...@@ -843,6 +848,13 @@ static int tcf_ife_search(struct net *net, struct tc_action **a, u32 index,
return tcf_idr_search(tn, a, index); return tcf_idr_search(tn, a, index);
} }
static int tcf_ife_delete(struct net *net, u32 index)
{
struct tc_action_net *tn = net_generic(net, ife_net_id);
return tcf_idr_delete_index(tn, index);
}
static struct tc_action_ops act_ife_ops = { static struct tc_action_ops act_ife_ops = {
.kind = "ife", .kind = "ife",
.type = TCA_ACT_IFE, .type = TCA_ACT_IFE,
...@@ -853,6 +865,7 @@ static struct tc_action_ops act_ife_ops = { ...@@ -853,6 +865,7 @@ static struct tc_action_ops act_ife_ops = {
.init = tcf_ife_init, .init = tcf_ife_init,
.walk = tcf_ife_walker, .walk = tcf_ife_walker,
.lookup = tcf_ife_search, .lookup = tcf_ife_search,
.delete = tcf_ife_delete,
.size = sizeof(struct tcf_ife_info), .size = sizeof(struct tcf_ife_info),
}; };
......
...@@ -119,13 +119,18 @@ static int __tcf_ipt_init(struct net *net, unsigned int id, struct nlattr *nla, ...@@ -119,13 +119,18 @@ static int __tcf_ipt_init(struct net *net, unsigned int id, struct nlattr *nla,
if (tb[TCA_IPT_INDEX] != NULL) if (tb[TCA_IPT_INDEX] != NULL)
index = nla_get_u32(tb[TCA_IPT_INDEX]); index = nla_get_u32(tb[TCA_IPT_INDEX]);
exists = tcf_idr_check(tn, index, a, bind); err = tcf_idr_check_alloc(tn, &index, a, bind);
if (err < 0)
return err;
exists = err;
if (exists && bind) if (exists && bind)
return 0; return 0;
if (tb[TCA_IPT_HOOK] == NULL || tb[TCA_IPT_TARG] == NULL) { if (tb[TCA_IPT_HOOK] == NULL || tb[TCA_IPT_TARG] == NULL) {
if (exists) if (exists)
tcf_idr_release(*a, bind); tcf_idr_release(*a, bind);
else
tcf_idr_cleanup(tn, index);
return -EINVAL; return -EINVAL;
} }
...@@ -133,23 +138,28 @@ static int __tcf_ipt_init(struct net *net, unsigned int id, struct nlattr *nla, ...@@ -133,23 +138,28 @@ static int __tcf_ipt_init(struct net *net, unsigned int id, struct nlattr *nla,
if (nla_len(tb[TCA_IPT_TARG]) < td->u.target_size) { if (nla_len(tb[TCA_IPT_TARG]) < td->u.target_size) {
if (exists) if (exists)
tcf_idr_release(*a, bind); tcf_idr_release(*a, bind);
else
tcf_idr_cleanup(tn, index);
return -EINVAL; return -EINVAL;
} }
if (!exists) { if (!exists) {
ret = tcf_idr_create(tn, index, est, a, ops, bind, ret = tcf_idr_create(tn, index, est, a, ops, bind,
false); false);
if (ret) if (ret) {
tcf_idr_cleanup(tn, index);
return ret; return ret;
}
ret = ACT_P_CREATED; ret = ACT_P_CREATED;
} else { } else {
if (bind)/* dont override defaults */ if (bind)/* dont override defaults */
return 0; return 0;
tcf_idr_release(*a, bind);
if (!ovr) if (!ovr) {
tcf_idr_release(*a, bind);
return -EEXIST; return -EEXIST;
} }
}
hook = nla_get_u32(tb[TCA_IPT_HOOK]); hook = nla_get_u32(tb[TCA_IPT_HOOK]);
err = -ENOMEM; err = -ENOMEM;
...@@ -196,7 +206,8 @@ static int __tcf_ipt_init(struct net *net, unsigned int id, struct nlattr *nla, ...@@ -196,7 +206,8 @@ static int __tcf_ipt_init(struct net *net, unsigned int id, struct nlattr *nla,
static int tcf_ipt_init(struct net *net, struct nlattr *nla, static int tcf_ipt_init(struct net *net, struct nlattr *nla,
struct nlattr *est, struct tc_action **a, int ovr, struct nlattr *est, struct tc_action **a, int ovr,
int bind, struct netlink_ext_ack *extack) int bind, bool rtnl_held,
struct netlink_ext_ack *extack)
{ {
return __tcf_ipt_init(net, ipt_net_id, nla, est, a, &act_ipt_ops, ovr, return __tcf_ipt_init(net, ipt_net_id, nla, est, a, &act_ipt_ops, ovr,
bind); bind);
...@@ -204,7 +215,8 @@ static int tcf_ipt_init(struct net *net, struct nlattr *nla, ...@@ -204,7 +215,8 @@ static int tcf_ipt_init(struct net *net, struct nlattr *nla,
static int tcf_xt_init(struct net *net, struct nlattr *nla, static int tcf_xt_init(struct net *net, struct nlattr *nla,
struct nlattr *est, struct tc_action **a, int ovr, struct nlattr *est, struct tc_action **a, int ovr,
int bind, struct netlink_ext_ack *extack) int bind, bool unlocked,
struct netlink_ext_ack *extack)
{ {
return __tcf_ipt_init(net, xt_net_id, nla, est, a, &act_xt_ops, ovr, return __tcf_ipt_init(net, xt_net_id, nla, est, a, &act_xt_ops, ovr,
bind); bind);
...@@ -280,8 +292,8 @@ static int tcf_ipt_dump(struct sk_buff *skb, struct tc_action *a, int bind, ...@@ -280,8 +292,8 @@ static int tcf_ipt_dump(struct sk_buff *skb, struct tc_action *a, int bind,
if (unlikely(!t)) if (unlikely(!t))
goto nla_put_failure; goto nla_put_failure;
c.bindcnt = ipt->tcf_bindcnt - bind; c.bindcnt = atomic_read(&ipt->tcf_bindcnt) - bind;
c.refcnt = ipt->tcf_refcnt - ref; c.refcnt = refcount_read(&ipt->tcf_refcnt) - ref;
strcpy(t->u.user.name, ipt->tcfi_t->u.kernel.target->name); strcpy(t->u.user.name, ipt->tcfi_t->u.kernel.target->name);
if (nla_put(skb, TCA_IPT_TARG, ipt->tcfi_t->u.user.target_size, t) || if (nla_put(skb, TCA_IPT_TARG, ipt->tcfi_t->u.user.target_size, t) ||
...@@ -322,6 +334,13 @@ static int tcf_ipt_search(struct net *net, struct tc_action **a, u32 index, ...@@ -322,6 +334,13 @@ static int tcf_ipt_search(struct net *net, struct tc_action **a, u32 index,
return tcf_idr_search(tn, a, index); return tcf_idr_search(tn, a, index);
} }
static int tcf_ipt_delete(struct net *net, u32 index)
{
struct tc_action_net *tn = net_generic(net, ipt_net_id);
return tcf_idr_delete_index(tn, index);
}
static struct tc_action_ops act_ipt_ops = { static struct tc_action_ops act_ipt_ops = {
.kind = "ipt", .kind = "ipt",
.type = TCA_ACT_IPT, .type = TCA_ACT_IPT,
...@@ -332,6 +351,7 @@ static struct tc_action_ops act_ipt_ops = { ...@@ -332,6 +351,7 @@ static struct tc_action_ops act_ipt_ops = {
.init = tcf_ipt_init, .init = tcf_ipt_init,
.walk = tcf_ipt_walker, .walk = tcf_ipt_walker,
.lookup = tcf_ipt_search, .lookup = tcf_ipt_search,
.delete = tcf_ipt_delete,
.size = sizeof(struct tcf_ipt), .size = sizeof(struct tcf_ipt),
}; };
...@@ -372,6 +392,13 @@ static int tcf_xt_search(struct net *net, struct tc_action **a, u32 index, ...@@ -372,6 +392,13 @@ static int tcf_xt_search(struct net *net, struct tc_action **a, u32 index,
return tcf_idr_search(tn, a, index); return tcf_idr_search(tn, a, index);
} }
static int tcf_xt_delete(struct net *net, u32 index)
{
struct tc_action_net *tn = net_generic(net, xt_net_id);
return tcf_idr_delete_index(tn, index);
}
static struct tc_action_ops act_xt_ops = { static struct tc_action_ops act_xt_ops = {
.kind = "xt", .kind = "xt",
.type = TCA_ACT_XT, .type = TCA_ACT_XT,
...@@ -382,6 +409,7 @@ static struct tc_action_ops act_xt_ops = { ...@@ -382,6 +409,7 @@ static struct tc_action_ops act_xt_ops = {
.init = tcf_xt_init, .init = tcf_xt_init,
.walk = tcf_xt_walker, .walk = tcf_xt_walker,
.lookup = tcf_xt_search, .lookup = tcf_xt_search,
.delete = tcf_xt_delete,
.size = sizeof(struct tcf_ipt), .size = sizeof(struct tcf_ipt),
}; };
......
...@@ -68,8 +68,9 @@ static unsigned int mirred_net_id; ...@@ -68,8 +68,9 @@ static unsigned int mirred_net_id;
static struct tc_action_ops act_mirred_ops; static struct tc_action_ops act_mirred_ops;
static int tcf_mirred_init(struct net *net, struct nlattr *nla, static int tcf_mirred_init(struct net *net, struct nlattr *nla,
struct nlattr *est, struct tc_action **a, int ovr, struct nlattr *est, struct tc_action **a,
int bind, struct netlink_ext_ack *extack) int ovr, int bind, bool rtnl_held,
struct netlink_ext_ack *extack)
{ {
struct tc_action_net *tn = net_generic(net, mirred_net_id); struct tc_action_net *tn = net_generic(net, mirred_net_id);
struct nlattr *tb[TCA_MIRRED_MAX + 1]; struct nlattr *tb[TCA_MIRRED_MAX + 1];
...@@ -78,7 +79,7 @@ static int tcf_mirred_init(struct net *net, struct nlattr *nla, ...@@ -78,7 +79,7 @@ static int tcf_mirred_init(struct net *net, struct nlattr *nla,
struct tcf_mirred *m; struct tcf_mirred *m;
struct net_device *dev; struct net_device *dev;
bool exists = false; bool exists = false;
int ret; int ret, err;
if (!nla) { if (!nla) {
NL_SET_ERR_MSG_MOD(extack, "Mirred requires attributes to be passed"); NL_SET_ERR_MSG_MOD(extack, "Mirred requires attributes to be passed");
...@@ -93,7 +94,10 @@ static int tcf_mirred_init(struct net *net, struct nlattr *nla, ...@@ -93,7 +94,10 @@ static int tcf_mirred_init(struct net *net, struct nlattr *nla,
} }
parm = nla_data(tb[TCA_MIRRED_PARMS]); parm = nla_data(tb[TCA_MIRRED_PARMS]);
exists = tcf_idr_check(tn, parm->index, a, bind); err = tcf_idr_check_alloc(tn, &parm->index, a, bind);
if (err < 0)
return err;
exists = err;
if (exists && bind) if (exists && bind)
return 0; return 0;
...@@ -106,6 +110,8 @@ static int tcf_mirred_init(struct net *net, struct nlattr *nla, ...@@ -106,6 +110,8 @@ static int tcf_mirred_init(struct net *net, struct nlattr *nla,
default: default:
if (exists) if (exists)
tcf_idr_release(*a, bind); tcf_idr_release(*a, bind);
else
tcf_idr_cleanup(tn, parm->index);
NL_SET_ERR_MSG_MOD(extack, "Unknown mirred option"); NL_SET_ERR_MSG_MOD(extack, "Unknown mirred option");
return -EINVAL; return -EINVAL;
} }
...@@ -114,6 +120,8 @@ static int tcf_mirred_init(struct net *net, struct nlattr *nla, ...@@ -114,6 +120,8 @@ static int tcf_mirred_init(struct net *net, struct nlattr *nla,
if (dev == NULL) { if (dev == NULL) {
if (exists) if (exists)
tcf_idr_release(*a, bind); tcf_idr_release(*a, bind);
else
tcf_idr_cleanup(tn, parm->index);
return -ENODEV; return -ENODEV;
} }
mac_header_xmit = dev_is_mac_header_xmit(dev); mac_header_xmit = dev_is_mac_header_xmit(dev);
...@@ -123,17 +131,19 @@ static int tcf_mirred_init(struct net *net, struct nlattr *nla, ...@@ -123,17 +131,19 @@ static int tcf_mirred_init(struct net *net, struct nlattr *nla,
if (!exists) { if (!exists) {
if (!dev) { if (!dev) {
tcf_idr_cleanup(tn, parm->index);
NL_SET_ERR_MSG_MOD(extack, "Specified device does not exist"); NL_SET_ERR_MSG_MOD(extack, "Specified device does not exist");
return -EINVAL; return -EINVAL;
} }
ret = tcf_idr_create(tn, parm->index, est, a, ret = tcf_idr_create(tn, parm->index, est, a,
&act_mirred_ops, bind, true); &act_mirred_ops, bind, true);
if (ret) if (ret) {
tcf_idr_cleanup(tn, parm->index);
return ret; return ret;
}
ret = ACT_P_CREATED; ret = ACT_P_CREATED;
} else { } else if (!ovr) {
tcf_idr_release(*a, bind); tcf_idr_release(*a, bind);
if (!ovr)
return -EEXIST; return -EEXIST;
} }
m = to_mirred(*a); m = to_mirred(*a);
...@@ -250,8 +260,8 @@ static int tcf_mirred_dump(struct sk_buff *skb, struct tc_action *a, int bind, ...@@ -250,8 +260,8 @@ static int tcf_mirred_dump(struct sk_buff *skb, struct tc_action *a, int bind,
struct tc_mirred opt = { struct tc_mirred opt = {
.index = m->tcf_index, .index = m->tcf_index,
.action = m->tcf_action, .action = m->tcf_action,
.refcnt = m->tcf_refcnt - ref, .refcnt = refcount_read(&m->tcf_refcnt) - ref,
.bindcnt = m->tcf_bindcnt - bind, .bindcnt = atomic_read(&m->tcf_bindcnt) - bind,
.eaction = m->tcfm_eaction, .eaction = m->tcfm_eaction,
.ifindex = dev ? dev->ifindex : 0, .ifindex = dev ? dev->ifindex : 0,
}; };
...@@ -321,6 +331,13 @@ static struct net_device *tcf_mirred_get_dev(const struct tc_action *a) ...@@ -321,6 +331,13 @@ static struct net_device *tcf_mirred_get_dev(const struct tc_action *a)
return rtnl_dereference(m->tcfm_dev); return rtnl_dereference(m->tcfm_dev);
} }
static int tcf_mirred_delete(struct net *net, u32 index)
{
struct tc_action_net *tn = net_generic(net, mirred_net_id);
return tcf_idr_delete_index(tn, index);
}
static struct tc_action_ops act_mirred_ops = { static struct tc_action_ops act_mirred_ops = {
.kind = "mirred", .kind = "mirred",
.type = TCA_ACT_MIRRED, .type = TCA_ACT_MIRRED,
...@@ -334,6 +351,7 @@ static struct tc_action_ops act_mirred_ops = { ...@@ -334,6 +351,7 @@ static struct tc_action_ops act_mirred_ops = {
.lookup = tcf_mirred_search, .lookup = tcf_mirred_search,
.size = sizeof(struct tcf_mirred), .size = sizeof(struct tcf_mirred),
.get_dev = tcf_mirred_get_dev, .get_dev = tcf_mirred_get_dev,
.delete = tcf_mirred_delete,
}; };
static __net_init int mirred_init_net(struct net *net) static __net_init int mirred_init_net(struct net *net)
......
...@@ -38,7 +38,7 @@ static const struct nla_policy nat_policy[TCA_NAT_MAX + 1] = { ...@@ -38,7 +38,7 @@ static const struct nla_policy nat_policy[TCA_NAT_MAX + 1] = {
static int tcf_nat_init(struct net *net, struct nlattr *nla, struct nlattr *est, static int tcf_nat_init(struct net *net, struct nlattr *nla, struct nlattr *est,
struct tc_action **a, int ovr, int bind, struct tc_action **a, int ovr, int bind,
struct netlink_ext_ack *extack) bool rtnl_held, struct netlink_ext_ack *extack)
{ {
struct tc_action_net *tn = net_generic(net, nat_net_id); struct tc_action_net *tn = net_generic(net, nat_net_id);
struct nlattr *tb[TCA_NAT_MAX + 1]; struct nlattr *tb[TCA_NAT_MAX + 1];
...@@ -57,19 +57,25 @@ static int tcf_nat_init(struct net *net, struct nlattr *nla, struct nlattr *est, ...@@ -57,19 +57,25 @@ static int tcf_nat_init(struct net *net, struct nlattr *nla, struct nlattr *est,
return -EINVAL; return -EINVAL;
parm = nla_data(tb[TCA_NAT_PARMS]); parm = nla_data(tb[TCA_NAT_PARMS]);
if (!tcf_idr_check(tn, parm->index, a, bind)) { err = tcf_idr_check_alloc(tn, &parm->index, a, bind);
if (!err) {
ret = tcf_idr_create(tn, parm->index, est, a, ret = tcf_idr_create(tn, parm->index, est, a,
&act_nat_ops, bind, false); &act_nat_ops, bind, false);
if (ret) if (ret) {
tcf_idr_cleanup(tn, parm->index);
return ret; return ret;
}
ret = ACT_P_CREATED; ret = ACT_P_CREATED;
} else { } else if (err > 0) {
if (bind) if (bind)
return 0; return 0;
if (!ovr) {
tcf_idr_release(*a, bind); tcf_idr_release(*a, bind);
if (!ovr)
return -EEXIST; return -EEXIST;
} }
} else {
return err;
}
p = to_tcf_nat(*a); p = to_tcf_nat(*a);
spin_lock_bh(&p->tcf_lock); spin_lock_bh(&p->tcf_lock);
...@@ -257,8 +263,8 @@ static int tcf_nat_dump(struct sk_buff *skb, struct tc_action *a, ...@@ -257,8 +263,8 @@ static int tcf_nat_dump(struct sk_buff *skb, struct tc_action *a,
.index = p->tcf_index, .index = p->tcf_index,
.action = p->tcf_action, .action = p->tcf_action,
.refcnt = p->tcf_refcnt - ref, .refcnt = refcount_read(&p->tcf_refcnt) - ref,
.bindcnt = p->tcf_bindcnt - bind, .bindcnt = atomic_read(&p->tcf_bindcnt) - bind,
}; };
struct tcf_t t; struct tcf_t t;
...@@ -294,6 +300,13 @@ static int tcf_nat_search(struct net *net, struct tc_action **a, u32 index, ...@@ -294,6 +300,13 @@ static int tcf_nat_search(struct net *net, struct tc_action **a, u32 index,
return tcf_idr_search(tn, a, index); return tcf_idr_search(tn, a, index);
} }
static int tcf_nat_delete(struct net *net, u32 index)
{
struct tc_action_net *tn = net_generic(net, nat_net_id);
return tcf_idr_delete_index(tn, index);
}
static struct tc_action_ops act_nat_ops = { static struct tc_action_ops act_nat_ops = {
.kind = "nat", .kind = "nat",
.type = TCA_ACT_NAT, .type = TCA_ACT_NAT,
...@@ -303,6 +316,7 @@ static struct tc_action_ops act_nat_ops = { ...@@ -303,6 +316,7 @@ static struct tc_action_ops act_nat_ops = {
.init = tcf_nat_init, .init = tcf_nat_init,
.walk = tcf_nat_walker, .walk = tcf_nat_walker,
.lookup = tcf_nat_search, .lookup = tcf_nat_search,
.delete = tcf_nat_delete,
.size = sizeof(struct tcf_nat), .size = sizeof(struct tcf_nat),
}; };
......
...@@ -132,7 +132,8 @@ static int tcf_pedit_key_ex_dump(struct sk_buff *skb, ...@@ -132,7 +132,8 @@ static int tcf_pedit_key_ex_dump(struct sk_buff *skb,
static int tcf_pedit_init(struct net *net, struct nlattr *nla, static int tcf_pedit_init(struct net *net, struct nlattr *nla,
struct nlattr *est, struct tc_action **a, struct nlattr *est, struct tc_action **a,
int ovr, int bind, struct netlink_ext_ack *extack) int ovr, int bind, bool rtnl_held,
struct netlink_ext_ack *extack)
{ {
struct tc_action_net *tn = net_generic(net, pedit_net_id); struct tc_action_net *tn = net_generic(net, pedit_net_id);
struct nlattr *tb[TCA_PEDIT_MAX + 1]; struct nlattr *tb[TCA_PEDIT_MAX + 1];
...@@ -172,16 +173,20 @@ static int tcf_pedit_init(struct net *net, struct nlattr *nla, ...@@ -172,16 +173,20 @@ static int tcf_pedit_init(struct net *net, struct nlattr *nla,
if (IS_ERR(keys_ex)) if (IS_ERR(keys_ex))
return PTR_ERR(keys_ex); return PTR_ERR(keys_ex);
if (!tcf_idr_check(tn, parm->index, a, bind)) { err = tcf_idr_check_alloc(tn, &parm->index, a, bind);
if (!err) {
if (!parm->nkeys) { if (!parm->nkeys) {
tcf_idr_cleanup(tn, parm->index);
NL_SET_ERR_MSG_MOD(extack, "Pedit requires keys to be passed"); NL_SET_ERR_MSG_MOD(extack, "Pedit requires keys to be passed");
ret = -EINVAL; ret = -EINVAL;
goto out_free; goto out_free;
} }
ret = tcf_idr_create(tn, parm->index, est, a, ret = tcf_idr_create(tn, parm->index, est, a,
&act_pedit_ops, bind, false); &act_pedit_ops, bind, false);
if (ret) if (ret) {
tcf_idr_cleanup(tn, parm->index);
goto out_free; goto out_free;
}
p = to_pedit(*a); p = to_pedit(*a);
keys = kmalloc(ksize, GFP_KERNEL); keys = kmalloc(ksize, GFP_KERNEL);
if (!keys) { if (!keys) {
...@@ -190,11 +195,11 @@ static int tcf_pedit_init(struct net *net, struct nlattr *nla, ...@@ -190,11 +195,11 @@ static int tcf_pedit_init(struct net *net, struct nlattr *nla,
goto out_free; goto out_free;
} }
ret = ACT_P_CREATED; ret = ACT_P_CREATED;
} else { } else if (err > 0) {
if (bind) if (bind)
goto out_free; goto out_free;
tcf_idr_release(*a, bind);
if (!ovr) { if (!ovr) {
tcf_idr_release(*a, bind);
ret = -EEXIST; ret = -EEXIST;
goto out_free; goto out_free;
} }
...@@ -206,6 +211,8 @@ static int tcf_pedit_init(struct net *net, struct nlattr *nla, ...@@ -206,6 +211,8 @@ static int tcf_pedit_init(struct net *net, struct nlattr *nla,
goto out_free; goto out_free;
} }
} }
} else {
return err;
} }
spin_lock_bh(&p->tcf_lock); spin_lock_bh(&p->tcf_lock);
...@@ -409,8 +416,8 @@ static int tcf_pedit_dump(struct sk_buff *skb, struct tc_action *a, ...@@ -409,8 +416,8 @@ static int tcf_pedit_dump(struct sk_buff *skb, struct tc_action *a,
opt->nkeys = p->tcfp_nkeys; opt->nkeys = p->tcfp_nkeys;
opt->flags = p->tcfp_flags; opt->flags = p->tcfp_flags;
opt->action = p->tcf_action; opt->action = p->tcf_action;
opt->refcnt = p->tcf_refcnt - ref; opt->refcnt = refcount_read(&p->tcf_refcnt) - ref;
opt->bindcnt = p->tcf_bindcnt - bind; opt->bindcnt = atomic_read(&p->tcf_bindcnt) - bind;
if (p->tcfp_keys_ex) { if (p->tcfp_keys_ex) {
tcf_pedit_key_ex_dump(skb, p->tcfp_keys_ex, p->tcfp_nkeys); tcf_pedit_key_ex_dump(skb, p->tcfp_keys_ex, p->tcfp_nkeys);
...@@ -453,6 +460,13 @@ static int tcf_pedit_search(struct net *net, struct tc_action **a, u32 index, ...@@ -453,6 +460,13 @@ static int tcf_pedit_search(struct net *net, struct tc_action **a, u32 index,
return tcf_idr_search(tn, a, index); return tcf_idr_search(tn, a, index);
} }
static int tcf_pedit_delete(struct net *net, u32 index)
{
struct tc_action_net *tn = net_generic(net, pedit_net_id);
return tcf_idr_delete_index(tn, index);
}
static struct tc_action_ops act_pedit_ops = { static struct tc_action_ops act_pedit_ops = {
.kind = "pedit", .kind = "pedit",
.type = TCA_ACT_PEDIT, .type = TCA_ACT_PEDIT,
...@@ -463,6 +477,7 @@ static struct tc_action_ops act_pedit_ops = { ...@@ -463,6 +477,7 @@ static struct tc_action_ops act_pedit_ops = {
.init = tcf_pedit_init, .init = tcf_pedit_init,
.walk = tcf_pedit_walker, .walk = tcf_pedit_walker,
.lookup = tcf_pedit_search, .lookup = tcf_pedit_search,
.delete = tcf_pedit_delete,
.size = sizeof(struct tcf_pedit), .size = sizeof(struct tcf_pedit),
}; };
......
...@@ -75,7 +75,7 @@ static const struct nla_policy police_policy[TCA_POLICE_MAX + 1] = { ...@@ -75,7 +75,7 @@ static const struct nla_policy police_policy[TCA_POLICE_MAX + 1] = {
static int tcf_act_police_init(struct net *net, struct nlattr *nla, static int tcf_act_police_init(struct net *net, struct nlattr *nla,
struct nlattr *est, struct tc_action **a, struct nlattr *est, struct tc_action **a,
int ovr, int bind, int ovr, int bind, bool rtnl_held,
struct netlink_ext_ack *extack) struct netlink_ext_ack *extack)
{ {
int ret = 0, err; int ret = 0, err;
...@@ -101,19 +101,23 @@ static int tcf_act_police_init(struct net *net, struct nlattr *nla, ...@@ -101,19 +101,23 @@ static int tcf_act_police_init(struct net *net, struct nlattr *nla,
return -EINVAL; return -EINVAL;
parm = nla_data(tb[TCA_POLICE_TBF]); parm = nla_data(tb[TCA_POLICE_TBF]);
exists = tcf_idr_check(tn, parm->index, a, bind); err = tcf_idr_check_alloc(tn, &parm->index, a, bind);
if (err < 0)
return err;
exists = err;
if (exists && bind) if (exists && bind)
return 0; return 0;
if (!exists) { if (!exists) {
ret = tcf_idr_create(tn, parm->index, NULL, a, ret = tcf_idr_create(tn, parm->index, NULL, a,
&act_police_ops, bind, false); &act_police_ops, bind, false);
if (ret) if (ret) {
tcf_idr_cleanup(tn, parm->index);
return ret; return ret;
}
ret = ACT_P_CREATED; ret = ACT_P_CREATED;
} else { } else if (!ovr) {
tcf_idr_release(*a, bind); tcf_idr_release(*a, bind);
if (!ovr)
return -EEXIST; return -EEXIST;
} }
...@@ -195,7 +199,6 @@ static int tcf_act_police_init(struct net *net, struct nlattr *nla, ...@@ -195,7 +199,6 @@ static int tcf_act_police_init(struct net *net, struct nlattr *nla,
failure: failure:
qdisc_put_rtab(P_tab); qdisc_put_rtab(P_tab);
qdisc_put_rtab(R_tab); qdisc_put_rtab(R_tab);
if (ret == ACT_P_CREATED)
tcf_idr_release(*a, bind); tcf_idr_release(*a, bind);
return err; return err;
} }
...@@ -274,8 +277,8 @@ static int tcf_act_police_dump(struct sk_buff *skb, struct tc_action *a, ...@@ -274,8 +277,8 @@ static int tcf_act_police_dump(struct sk_buff *skb, struct tc_action *a,
.action = police->tcf_action, .action = police->tcf_action,
.mtu = police->tcfp_mtu, .mtu = police->tcfp_mtu,
.burst = PSCHED_NS2TICKS(police->tcfp_burst), .burst = PSCHED_NS2TICKS(police->tcfp_burst),
.refcnt = police->tcf_refcnt - ref, .refcnt = refcount_read(&police->tcf_refcnt) - ref,
.bindcnt = police->tcf_bindcnt - bind, .bindcnt = atomic_read(&police->tcf_bindcnt) - bind,
}; };
struct tcf_t t; struct tcf_t t;
...@@ -314,6 +317,13 @@ static int tcf_police_search(struct net *net, struct tc_action **a, u32 index, ...@@ -314,6 +317,13 @@ static int tcf_police_search(struct net *net, struct tc_action **a, u32 index,
return tcf_idr_search(tn, a, index); return tcf_idr_search(tn, a, index);
} }
static int tcf_police_delete(struct net *net, u32 index)
{
struct tc_action_net *tn = net_generic(net, police_net_id);
return tcf_idr_delete_index(tn, index);
}
MODULE_AUTHOR("Alexey Kuznetsov"); MODULE_AUTHOR("Alexey Kuznetsov");
MODULE_DESCRIPTION("Policing actions"); MODULE_DESCRIPTION("Policing actions");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
...@@ -327,6 +337,7 @@ static struct tc_action_ops act_police_ops = { ...@@ -327,6 +337,7 @@ static struct tc_action_ops act_police_ops = {
.init = tcf_act_police_init, .init = tcf_act_police_init,
.walk = tcf_act_police_walker, .walk = tcf_act_police_walker,
.lookup = tcf_police_search, .lookup = tcf_police_search,
.delete = tcf_police_delete,
.size = sizeof(struct tcf_police), .size = sizeof(struct tcf_police),
}; };
......
...@@ -37,7 +37,8 @@ static const struct nla_policy sample_policy[TCA_SAMPLE_MAX + 1] = { ...@@ -37,7 +37,8 @@ static const struct nla_policy sample_policy[TCA_SAMPLE_MAX + 1] = {
static int tcf_sample_init(struct net *net, struct nlattr *nla, static int tcf_sample_init(struct net *net, struct nlattr *nla,
struct nlattr *est, struct tc_action **a, int ovr, struct nlattr *est, struct tc_action **a, int ovr,
int bind, struct netlink_ext_ack *extack) int bind, bool rtnl_held,
struct netlink_ext_ack *extack)
{ {
struct tc_action_net *tn = net_generic(net, sample_net_id); struct tc_action_net *tn = net_generic(net, sample_net_id);
struct nlattr *tb[TCA_SAMPLE_MAX + 1]; struct nlattr *tb[TCA_SAMPLE_MAX + 1];
...@@ -45,7 +46,7 @@ static int tcf_sample_init(struct net *net, struct nlattr *nla, ...@@ -45,7 +46,7 @@ static int tcf_sample_init(struct net *net, struct nlattr *nla,
struct tc_sample *parm; struct tc_sample *parm;
struct tcf_sample *s; struct tcf_sample *s;
bool exists = false; bool exists = false;
int ret; int ret, err;
if (!nla) if (!nla)
return -EINVAL; return -EINVAL;
...@@ -58,19 +59,23 @@ static int tcf_sample_init(struct net *net, struct nlattr *nla, ...@@ -58,19 +59,23 @@ static int tcf_sample_init(struct net *net, struct nlattr *nla,
parm = nla_data(tb[TCA_SAMPLE_PARMS]); parm = nla_data(tb[TCA_SAMPLE_PARMS]);
exists = tcf_idr_check(tn, parm->index, a, bind); err = tcf_idr_check_alloc(tn, &parm->index, a, bind);
if (err < 0)
return err;
exists = err;
if (exists && bind) if (exists && bind)
return 0; return 0;
if (!exists) { if (!exists) {
ret = tcf_idr_create(tn, parm->index, est, a, ret = tcf_idr_create(tn, parm->index, est, a,
&act_sample_ops, bind, false); &act_sample_ops, bind, false);
if (ret) if (ret) {
tcf_idr_cleanup(tn, parm->index);
return ret; return ret;
}
ret = ACT_P_CREATED; ret = ACT_P_CREATED;
} else { } else if (!ovr) {
tcf_idr_release(*a, bind); tcf_idr_release(*a, bind);
if (!ovr)
return -EEXIST; return -EEXIST;
} }
s = to_sample(*a); s = to_sample(*a);
...@@ -80,7 +85,6 @@ static int tcf_sample_init(struct net *net, struct nlattr *nla, ...@@ -80,7 +85,6 @@ static int tcf_sample_init(struct net *net, struct nlattr *nla,
s->psample_group_num = nla_get_u32(tb[TCA_SAMPLE_PSAMPLE_GROUP]); s->psample_group_num = nla_get_u32(tb[TCA_SAMPLE_PSAMPLE_GROUP]);
psample_group = psample_group_get(net, s->psample_group_num); psample_group = psample_group_get(net, s->psample_group_num);
if (!psample_group) { if (!psample_group) {
if (ret == ACT_P_CREATED)
tcf_idr_release(*a, bind); tcf_idr_release(*a, bind);
return -ENOMEM; return -ENOMEM;
} }
...@@ -173,8 +177,8 @@ static int tcf_sample_dump(struct sk_buff *skb, struct tc_action *a, ...@@ -173,8 +177,8 @@ static int tcf_sample_dump(struct sk_buff *skb, struct tc_action *a,
struct tc_sample opt = { struct tc_sample opt = {
.index = s->tcf_index, .index = s->tcf_index,
.action = s->tcf_action, .action = s->tcf_action,
.refcnt = s->tcf_refcnt - ref, .refcnt = refcount_read(&s->tcf_refcnt) - ref,
.bindcnt = s->tcf_bindcnt - bind, .bindcnt = atomic_read(&s->tcf_bindcnt) - bind,
}; };
struct tcf_t t; struct tcf_t t;
...@@ -219,6 +223,13 @@ static int tcf_sample_search(struct net *net, struct tc_action **a, u32 index, ...@@ -219,6 +223,13 @@ static int tcf_sample_search(struct net *net, struct tc_action **a, u32 index,
return tcf_idr_search(tn, a, index); return tcf_idr_search(tn, a, index);
} }
static int tcf_sample_delete(struct net *net, u32 index)
{
struct tc_action_net *tn = net_generic(net, sample_net_id);
return tcf_idr_delete_index(tn, index);
}
static struct tc_action_ops act_sample_ops = { static struct tc_action_ops act_sample_ops = {
.kind = "sample", .kind = "sample",
.type = TCA_ACT_SAMPLE, .type = TCA_ACT_SAMPLE,
...@@ -229,6 +240,7 @@ static struct tc_action_ops act_sample_ops = { ...@@ -229,6 +240,7 @@ static struct tc_action_ops act_sample_ops = {
.cleanup = tcf_sample_cleanup, .cleanup = tcf_sample_cleanup,
.walk = tcf_sample_walker, .walk = tcf_sample_walker,
.lookup = tcf_sample_search, .lookup = tcf_sample_search,
.delete = tcf_sample_delete,
.size = sizeof(struct tcf_sample), .size = sizeof(struct tcf_sample),
}; };
......
...@@ -79,7 +79,8 @@ static const struct nla_policy simple_policy[TCA_DEF_MAX + 1] = { ...@@ -79,7 +79,8 @@ static const struct nla_policy simple_policy[TCA_DEF_MAX + 1] = {
static int tcf_simp_init(struct net *net, struct nlattr *nla, static int tcf_simp_init(struct net *net, struct nlattr *nla,
struct nlattr *est, struct tc_action **a, struct nlattr *est, struct tc_action **a,
int ovr, int bind, struct netlink_ext_ack *extack) int ovr, int bind, bool rtnl_held,
struct netlink_ext_ack *extack)
{ {
struct tc_action_net *tn = net_generic(net, simp_net_id); struct tc_action_net *tn = net_generic(net, simp_net_id);
struct nlattr *tb[TCA_DEF_MAX + 1]; struct nlattr *tb[TCA_DEF_MAX + 1];
...@@ -99,21 +100,28 @@ static int tcf_simp_init(struct net *net, struct nlattr *nla, ...@@ -99,21 +100,28 @@ static int tcf_simp_init(struct net *net, struct nlattr *nla,
return -EINVAL; return -EINVAL;
parm = nla_data(tb[TCA_DEF_PARMS]); parm = nla_data(tb[TCA_DEF_PARMS]);
exists = tcf_idr_check(tn, parm->index, a, bind); err = tcf_idr_check_alloc(tn, &parm->index, a, bind);
if (err < 0)
return err;
exists = err;
if (exists && bind) if (exists && bind)
return 0; return 0;
if (tb[TCA_DEF_DATA] == NULL) { if (tb[TCA_DEF_DATA] == NULL) {
if (exists) if (exists)
tcf_idr_release(*a, bind); tcf_idr_release(*a, bind);
else
tcf_idr_cleanup(tn, parm->index);
return -EINVAL; return -EINVAL;
} }
if (!exists) { if (!exists) {
ret = tcf_idr_create(tn, parm->index, est, a, ret = tcf_idr_create(tn, parm->index, est, a,
&act_simp_ops, bind, false); &act_simp_ops, bind, false);
if (ret) if (ret) {
tcf_idr_cleanup(tn, parm->index);
return ret; return ret;
}
d = to_defact(*a); d = to_defact(*a);
ret = alloc_defdata(d, tb[TCA_DEF_DATA]); ret = alloc_defdata(d, tb[TCA_DEF_DATA]);
...@@ -126,9 +134,10 @@ static int tcf_simp_init(struct net *net, struct nlattr *nla, ...@@ -126,9 +134,10 @@ static int tcf_simp_init(struct net *net, struct nlattr *nla,
} else { } else {
d = to_defact(*a); d = to_defact(*a);
if (!ovr) {
tcf_idr_release(*a, bind); tcf_idr_release(*a, bind);
if (!ovr)
return -EEXIST; return -EEXIST;
}
reset_policy(d, tb[TCA_DEF_DATA], parm); reset_policy(d, tb[TCA_DEF_DATA], parm);
} }
...@@ -145,8 +154,8 @@ static int tcf_simp_dump(struct sk_buff *skb, struct tc_action *a, ...@@ -145,8 +154,8 @@ static int tcf_simp_dump(struct sk_buff *skb, struct tc_action *a,
struct tcf_defact *d = to_defact(a); struct tcf_defact *d = to_defact(a);
struct tc_defact opt = { struct tc_defact opt = {
.index = d->tcf_index, .index = d->tcf_index,
.refcnt = d->tcf_refcnt - ref, .refcnt = refcount_read(&d->tcf_refcnt) - ref,
.bindcnt = d->tcf_bindcnt - bind, .bindcnt = atomic_read(&d->tcf_bindcnt) - bind,
.action = d->tcf_action, .action = d->tcf_action,
}; };
struct tcf_t t; struct tcf_t t;
...@@ -183,6 +192,13 @@ static int tcf_simp_search(struct net *net, struct tc_action **a, u32 index, ...@@ -183,6 +192,13 @@ static int tcf_simp_search(struct net *net, struct tc_action **a, u32 index,
return tcf_idr_search(tn, a, index); return tcf_idr_search(tn, a, index);
} }
static int tcf_simp_delete(struct net *net, u32 index)
{
struct tc_action_net *tn = net_generic(net, simp_net_id);
return tcf_idr_delete_index(tn, index);
}
static struct tc_action_ops act_simp_ops = { static struct tc_action_ops act_simp_ops = {
.kind = "simple", .kind = "simple",
.type = TCA_ACT_SIMP, .type = TCA_ACT_SIMP,
...@@ -193,6 +209,7 @@ static struct tc_action_ops act_simp_ops = { ...@@ -193,6 +209,7 @@ static struct tc_action_ops act_simp_ops = {
.init = tcf_simp_init, .init = tcf_simp_init,
.walk = tcf_simp_walker, .walk = tcf_simp_walker,
.lookup = tcf_simp_search, .lookup = tcf_simp_search,
.delete = tcf_simp_delete,
.size = sizeof(struct tcf_defact), .size = sizeof(struct tcf_defact),
}; };
......
...@@ -94,7 +94,8 @@ static const struct nla_policy skbedit_policy[TCA_SKBEDIT_MAX + 1] = { ...@@ -94,7 +94,8 @@ static const struct nla_policy skbedit_policy[TCA_SKBEDIT_MAX + 1] = {
static int tcf_skbedit_init(struct net *net, struct nlattr *nla, static int tcf_skbedit_init(struct net *net, struct nlattr *nla,
struct nlattr *est, struct tc_action **a, struct nlattr *est, struct tc_action **a,
int ovr, int bind, struct netlink_ext_ack *extack) int ovr, int bind, bool rtnl_held,
struct netlink_ext_ack *extack)
{ {
struct tc_action_net *tn = net_generic(net, skbedit_net_id); struct tc_action_net *tn = net_generic(net, skbedit_net_id);
struct nlattr *tb[TCA_SKBEDIT_MAX + 1]; struct nlattr *tb[TCA_SKBEDIT_MAX + 1];
...@@ -151,30 +152,38 @@ static int tcf_skbedit_init(struct net *net, struct nlattr *nla, ...@@ -151,30 +152,38 @@ static int tcf_skbedit_init(struct net *net, struct nlattr *nla,
parm = nla_data(tb[TCA_SKBEDIT_PARMS]); parm = nla_data(tb[TCA_SKBEDIT_PARMS]);
exists = tcf_idr_check(tn, parm->index, a, bind); err = tcf_idr_check_alloc(tn, &parm->index, a, bind);
if (err < 0)
return err;
exists = err;
if (exists && bind) if (exists && bind)
return 0; return 0;
if (!flags) { if (!flags) {
if (exists) if (exists)
tcf_idr_release(*a, bind); tcf_idr_release(*a, bind);
else
tcf_idr_cleanup(tn, parm->index);
return -EINVAL; return -EINVAL;
} }
if (!exists) { if (!exists) {
ret = tcf_idr_create(tn, parm->index, est, a, ret = tcf_idr_create(tn, parm->index, est, a,
&act_skbedit_ops, bind, false); &act_skbedit_ops, bind, false);
if (ret) if (ret) {
tcf_idr_cleanup(tn, parm->index);
return ret; return ret;
}
d = to_skbedit(*a); d = to_skbedit(*a);
ret = ACT_P_CREATED; ret = ACT_P_CREATED;
} else { } else {
d = to_skbedit(*a); d = to_skbedit(*a);
if (!ovr) {
tcf_idr_release(*a, bind); tcf_idr_release(*a, bind);
if (!ovr)
return -EEXIST; return -EEXIST;
} }
}
spin_lock_bh(&d->tcf_lock); spin_lock_bh(&d->tcf_lock);
...@@ -208,8 +217,8 @@ static int tcf_skbedit_dump(struct sk_buff *skb, struct tc_action *a, ...@@ -208,8 +217,8 @@ static int tcf_skbedit_dump(struct sk_buff *skb, struct tc_action *a,
struct tcf_skbedit *d = to_skbedit(a); struct tcf_skbedit *d = to_skbedit(a);
struct tc_skbedit opt = { struct tc_skbedit opt = {
.index = d->tcf_index, .index = d->tcf_index,
.refcnt = d->tcf_refcnt - ref, .refcnt = refcount_read(&d->tcf_refcnt) - ref,
.bindcnt = d->tcf_bindcnt - bind, .bindcnt = atomic_read(&d->tcf_bindcnt) - bind,
.action = d->tcf_action, .action = d->tcf_action,
}; };
struct tcf_t t; struct tcf_t t;
...@@ -266,6 +275,13 @@ static int tcf_skbedit_search(struct net *net, struct tc_action **a, u32 index, ...@@ -266,6 +275,13 @@ static int tcf_skbedit_search(struct net *net, struct tc_action **a, u32 index,
return tcf_idr_search(tn, a, index); return tcf_idr_search(tn, a, index);
} }
static int tcf_skbedit_delete(struct net *net, u32 index)
{
struct tc_action_net *tn = net_generic(net, skbedit_net_id);
return tcf_idr_delete_index(tn, index);
}
static struct tc_action_ops act_skbedit_ops = { static struct tc_action_ops act_skbedit_ops = {
.kind = "skbedit", .kind = "skbedit",
.type = TCA_ACT_SKBEDIT, .type = TCA_ACT_SKBEDIT,
...@@ -275,6 +291,7 @@ static struct tc_action_ops act_skbedit_ops = { ...@@ -275,6 +291,7 @@ static struct tc_action_ops act_skbedit_ops = {
.init = tcf_skbedit_init, .init = tcf_skbedit_init,
.walk = tcf_skbedit_walker, .walk = tcf_skbedit_walker,
.lookup = tcf_skbedit_search, .lookup = tcf_skbedit_search,
.delete = tcf_skbedit_delete,
.size = sizeof(struct tcf_skbedit), .size = sizeof(struct tcf_skbedit),
}; };
......
...@@ -84,7 +84,8 @@ static const struct nla_policy skbmod_policy[TCA_SKBMOD_MAX + 1] = { ...@@ -84,7 +84,8 @@ static const struct nla_policy skbmod_policy[TCA_SKBMOD_MAX + 1] = {
static int tcf_skbmod_init(struct net *net, struct nlattr *nla, static int tcf_skbmod_init(struct net *net, struct nlattr *nla,
struct nlattr *est, struct tc_action **a, struct nlattr *est, struct tc_action **a,
int ovr, int bind, struct netlink_ext_ack *extack) int ovr, int bind, bool rtnl_held,
struct netlink_ext_ack *extack)
{ {
struct tc_action_net *tn = net_generic(net, skbmod_net_id); struct tc_action_net *tn = net_generic(net, skbmod_net_id);
struct nlattr *tb[TCA_SKBMOD_MAX + 1]; struct nlattr *tb[TCA_SKBMOD_MAX + 1];
...@@ -127,26 +128,32 @@ static int tcf_skbmod_init(struct net *net, struct nlattr *nla, ...@@ -127,26 +128,32 @@ static int tcf_skbmod_init(struct net *net, struct nlattr *nla,
if (parm->flags & SKBMOD_F_SWAPMAC) if (parm->flags & SKBMOD_F_SWAPMAC)
lflags = SKBMOD_F_SWAPMAC; lflags = SKBMOD_F_SWAPMAC;
exists = tcf_idr_check(tn, parm->index, a, bind); err = tcf_idr_check_alloc(tn, &parm->index, a, bind);
if (err < 0)
return err;
exists = err;
if (exists && bind) if (exists && bind)
return 0; return 0;
if (!lflags) { if (!lflags) {
if (exists) if (exists)
tcf_idr_release(*a, bind); tcf_idr_release(*a, bind);
else
tcf_idr_cleanup(tn, parm->index);
return -EINVAL; return -EINVAL;
} }
if (!exists) { if (!exists) {
ret = tcf_idr_create(tn, parm->index, est, a, ret = tcf_idr_create(tn, parm->index, est, a,
&act_skbmod_ops, bind, true); &act_skbmod_ops, bind, true);
if (ret) if (ret) {
tcf_idr_cleanup(tn, parm->index);
return ret; return ret;
}
ret = ACT_P_CREATED; ret = ACT_P_CREATED;
} else { } else if (!ovr) {
tcf_idr_release(*a, bind); tcf_idr_release(*a, bind);
if (!ovr)
return -EEXIST; return -EEXIST;
} }
...@@ -155,7 +162,6 @@ static int tcf_skbmod_init(struct net *net, struct nlattr *nla, ...@@ -155,7 +162,6 @@ static int tcf_skbmod_init(struct net *net, struct nlattr *nla,
ASSERT_RTNL(); ASSERT_RTNL();
p = kzalloc(sizeof(struct tcf_skbmod_params), GFP_KERNEL); p = kzalloc(sizeof(struct tcf_skbmod_params), GFP_KERNEL);
if (unlikely(!p)) { if (unlikely(!p)) {
if (ret == ACT_P_CREATED)
tcf_idr_release(*a, bind); tcf_idr_release(*a, bind);
return -ENOMEM; return -ENOMEM;
} }
...@@ -205,8 +211,8 @@ static int tcf_skbmod_dump(struct sk_buff *skb, struct tc_action *a, ...@@ -205,8 +211,8 @@ static int tcf_skbmod_dump(struct sk_buff *skb, struct tc_action *a,
struct tcf_skbmod_params *p = rtnl_dereference(d->skbmod_p); struct tcf_skbmod_params *p = rtnl_dereference(d->skbmod_p);
struct tc_skbmod opt = { struct tc_skbmod opt = {
.index = d->tcf_index, .index = d->tcf_index,
.refcnt = d->tcf_refcnt - ref, .refcnt = refcount_read(&d->tcf_refcnt) - ref,
.bindcnt = d->tcf_bindcnt - bind, .bindcnt = atomic_read(&d->tcf_bindcnt) - bind,
.action = d->tcf_action, .action = d->tcf_action,
}; };
struct tcf_t t; struct tcf_t t;
...@@ -252,6 +258,13 @@ static int tcf_skbmod_search(struct net *net, struct tc_action **a, u32 index, ...@@ -252,6 +258,13 @@ static int tcf_skbmod_search(struct net *net, struct tc_action **a, u32 index,
return tcf_idr_search(tn, a, index); return tcf_idr_search(tn, a, index);
} }
static int tcf_skbmod_delete(struct net *net, u32 index)
{
struct tc_action_net *tn = net_generic(net, skbmod_net_id);
return tcf_idr_delete_index(tn, index);
}
static struct tc_action_ops act_skbmod_ops = { static struct tc_action_ops act_skbmod_ops = {
.kind = "skbmod", .kind = "skbmod",
.type = TCA_ACT_SKBMOD, .type = TCA_ACT_SKBMOD,
...@@ -262,6 +275,7 @@ static struct tc_action_ops act_skbmod_ops = { ...@@ -262,6 +275,7 @@ static struct tc_action_ops act_skbmod_ops = {
.cleanup = tcf_skbmod_cleanup, .cleanup = tcf_skbmod_cleanup,
.walk = tcf_skbmod_walker, .walk = tcf_skbmod_walker,
.lookup = tcf_skbmod_search, .lookup = tcf_skbmod_search,
.delete = tcf_skbmod_delete,
.size = sizeof(struct tcf_skbmod), .size = sizeof(struct tcf_skbmod),
}; };
......
...@@ -201,7 +201,8 @@ static const struct nla_policy tunnel_key_policy[TCA_TUNNEL_KEY_MAX + 1] = { ...@@ -201,7 +201,8 @@ static const struct nla_policy tunnel_key_policy[TCA_TUNNEL_KEY_MAX + 1] = {
static int tunnel_key_init(struct net *net, struct nlattr *nla, static int tunnel_key_init(struct net *net, struct nlattr *nla,
struct nlattr *est, struct tc_action **a, struct nlattr *est, struct tc_action **a,
int ovr, int bind, struct netlink_ext_ack *extack) int ovr, int bind, bool rtnl_held,
struct netlink_ext_ack *extack)
{ {
struct tc_action_net *tn = net_generic(net, tunnel_key_net_id); struct tc_action_net *tn = net_generic(net, tunnel_key_net_id);
struct nlattr *tb[TCA_TUNNEL_KEY_MAX + 1]; struct nlattr *tb[TCA_TUNNEL_KEY_MAX + 1];
...@@ -236,7 +237,10 @@ static int tunnel_key_init(struct net *net, struct nlattr *nla, ...@@ -236,7 +237,10 @@ static int tunnel_key_init(struct net *net, struct nlattr *nla,
} }
parm = nla_data(tb[TCA_TUNNEL_KEY_PARMS]); parm = nla_data(tb[TCA_TUNNEL_KEY_PARMS]);
exists = tcf_idr_check(tn, parm->index, a, bind); err = tcf_idr_check_alloc(tn, &parm->index, a, bind);
if (err < 0)
return err;
exists = err;
if (exists && bind) if (exists && bind)
return 0; return 0;
...@@ -324,24 +328,21 @@ static int tunnel_key_init(struct net *net, struct nlattr *nla, ...@@ -324,24 +328,21 @@ static int tunnel_key_init(struct net *net, struct nlattr *nla,
&act_tunnel_key_ops, bind, true); &act_tunnel_key_ops, bind, true);
if (ret) { if (ret) {
NL_SET_ERR_MSG(extack, "Cannot create TC IDR"); NL_SET_ERR_MSG(extack, "Cannot create TC IDR");
return ret; goto err_out;
} }
ret = ACT_P_CREATED; ret = ACT_P_CREATED;
} else { } else if (!ovr) {
tcf_idr_release(*a, bind); tcf_idr_release(*a, bind);
if (!ovr) {
NL_SET_ERR_MSG(extack, "TC IDR already exists"); NL_SET_ERR_MSG(extack, "TC IDR already exists");
return -EEXIST; return -EEXIST;
} }
}
t = to_tunnel_key(*a); t = to_tunnel_key(*a);
ASSERT_RTNL(); ASSERT_RTNL();
params_new = kzalloc(sizeof(*params_new), GFP_KERNEL); params_new = kzalloc(sizeof(*params_new), GFP_KERNEL);
if (unlikely(!params_new)) { if (unlikely(!params_new)) {
if (ret == ACT_P_CREATED)
tcf_idr_release(*a, bind); tcf_idr_release(*a, bind);
NL_SET_ERR_MSG(extack, "Cannot allocate tunnel key parameters"); NL_SET_ERR_MSG(extack, "Cannot allocate tunnel key parameters");
return -ENOMEM; return -ENOMEM;
...@@ -366,6 +367,8 @@ static int tunnel_key_init(struct net *net, struct nlattr *nla, ...@@ -366,6 +367,8 @@ static int tunnel_key_init(struct net *net, struct nlattr *nla,
err_out: err_out:
if (exists) if (exists)
tcf_idr_release(*a, bind); tcf_idr_release(*a, bind);
else
tcf_idr_cleanup(tn, parm->index);
return ret; return ret;
} }
...@@ -474,8 +477,8 @@ static int tunnel_key_dump(struct sk_buff *skb, struct tc_action *a, ...@@ -474,8 +477,8 @@ static int tunnel_key_dump(struct sk_buff *skb, struct tc_action *a,
struct tcf_tunnel_key_params *params; struct tcf_tunnel_key_params *params;
struct tc_tunnel_key opt = { struct tc_tunnel_key opt = {
.index = t->tcf_index, .index = t->tcf_index,
.refcnt = t->tcf_refcnt - ref, .refcnt = refcount_read(&t->tcf_refcnt) - ref,
.bindcnt = t->tcf_bindcnt - bind, .bindcnt = atomic_read(&t->tcf_bindcnt) - bind,
}; };
struct tcf_t tm; struct tcf_t tm;
...@@ -533,6 +536,13 @@ static int tunnel_key_search(struct net *net, struct tc_action **a, u32 index, ...@@ -533,6 +536,13 @@ static int tunnel_key_search(struct net *net, struct tc_action **a, u32 index,
return tcf_idr_search(tn, a, index); return tcf_idr_search(tn, a, index);
} }
static int tunnel_key_delete(struct net *net, u32 index)
{
struct tc_action_net *tn = net_generic(net, tunnel_key_net_id);
return tcf_idr_delete_index(tn, index);
}
static struct tc_action_ops act_tunnel_key_ops = { static struct tc_action_ops act_tunnel_key_ops = {
.kind = "tunnel_key", .kind = "tunnel_key",
.type = TCA_ACT_TUNNEL_KEY, .type = TCA_ACT_TUNNEL_KEY,
...@@ -543,6 +553,7 @@ static struct tc_action_ops act_tunnel_key_ops = { ...@@ -543,6 +553,7 @@ static struct tc_action_ops act_tunnel_key_ops = {
.cleanup = tunnel_key_release, .cleanup = tunnel_key_release,
.walk = tunnel_key_walker, .walk = tunnel_key_walker,
.lookup = tunnel_key_search, .lookup = tunnel_key_search,
.delete = tunnel_key_delete,
.size = sizeof(struct tcf_tunnel_key), .size = sizeof(struct tcf_tunnel_key),
}; };
......
...@@ -109,7 +109,8 @@ static const struct nla_policy vlan_policy[TCA_VLAN_MAX + 1] = { ...@@ -109,7 +109,8 @@ static const struct nla_policy vlan_policy[TCA_VLAN_MAX + 1] = {
static int tcf_vlan_init(struct net *net, struct nlattr *nla, static int tcf_vlan_init(struct net *net, struct nlattr *nla,
struct nlattr *est, struct tc_action **a, struct nlattr *est, struct tc_action **a,
int ovr, int bind, struct netlink_ext_ack *extack) int ovr, int bind, bool rtnl_held,
struct netlink_ext_ack *extack)
{ {
struct tc_action_net *tn = net_generic(net, vlan_net_id); struct tc_action_net *tn = net_generic(net, vlan_net_id);
struct nlattr *tb[TCA_VLAN_MAX + 1]; struct nlattr *tb[TCA_VLAN_MAX + 1];
...@@ -133,7 +134,10 @@ static int tcf_vlan_init(struct net *net, struct nlattr *nla, ...@@ -133,7 +134,10 @@ static int tcf_vlan_init(struct net *net, struct nlattr *nla,
if (!tb[TCA_VLAN_PARMS]) if (!tb[TCA_VLAN_PARMS])
return -EINVAL; return -EINVAL;
parm = nla_data(tb[TCA_VLAN_PARMS]); parm = nla_data(tb[TCA_VLAN_PARMS]);
exists = tcf_idr_check(tn, parm->index, a, bind); err = tcf_idr_check_alloc(tn, &parm->index, a, bind);
if (err < 0)
return err;
exists = err;
if (exists && bind) if (exists && bind)
return 0; return 0;
...@@ -145,12 +149,16 @@ static int tcf_vlan_init(struct net *net, struct nlattr *nla, ...@@ -145,12 +149,16 @@ static int tcf_vlan_init(struct net *net, struct nlattr *nla,
if (!tb[TCA_VLAN_PUSH_VLAN_ID]) { if (!tb[TCA_VLAN_PUSH_VLAN_ID]) {
if (exists) if (exists)
tcf_idr_release(*a, bind); tcf_idr_release(*a, bind);
else
tcf_idr_cleanup(tn, parm->index);
return -EINVAL; return -EINVAL;
} }
push_vid = nla_get_u16(tb[TCA_VLAN_PUSH_VLAN_ID]); push_vid = nla_get_u16(tb[TCA_VLAN_PUSH_VLAN_ID]);
if (push_vid >= VLAN_VID_MASK) { if (push_vid >= VLAN_VID_MASK) {
if (exists) if (exists)
tcf_idr_release(*a, bind); tcf_idr_release(*a, bind);
else
tcf_idr_cleanup(tn, parm->index);
return -ERANGE; return -ERANGE;
} }
...@@ -163,6 +171,8 @@ static int tcf_vlan_init(struct net *net, struct nlattr *nla, ...@@ -163,6 +171,8 @@ static int tcf_vlan_init(struct net *net, struct nlattr *nla,
default: default:
if (exists) if (exists)
tcf_idr_release(*a, bind); tcf_idr_release(*a, bind);
else
tcf_idr_cleanup(tn, parm->index);
return -EPROTONOSUPPORT; return -EPROTONOSUPPORT;
} }
} else { } else {
...@@ -175,6 +185,8 @@ static int tcf_vlan_init(struct net *net, struct nlattr *nla, ...@@ -175,6 +185,8 @@ static int tcf_vlan_init(struct net *net, struct nlattr *nla,
default: default:
if (exists) if (exists)
tcf_idr_release(*a, bind); tcf_idr_release(*a, bind);
else
tcf_idr_cleanup(tn, parm->index);
return -EINVAL; return -EINVAL;
} }
action = parm->v_action; action = parm->v_action;
...@@ -182,13 +194,14 @@ static int tcf_vlan_init(struct net *net, struct nlattr *nla, ...@@ -182,13 +194,14 @@ static int tcf_vlan_init(struct net *net, struct nlattr *nla,
if (!exists) { if (!exists) {
ret = tcf_idr_create(tn, parm->index, est, a, ret = tcf_idr_create(tn, parm->index, est, a,
&act_vlan_ops, bind, true); &act_vlan_ops, bind, true);
if (ret) if (ret) {
tcf_idr_cleanup(tn, parm->index);
return ret; return ret;
}
ret = ACT_P_CREATED; ret = ACT_P_CREATED;
} else { } else if (!ovr) {
tcf_idr_release(*a, bind); tcf_idr_release(*a, bind);
if (!ovr)
return -EEXIST; return -EEXIST;
} }
...@@ -197,7 +210,6 @@ static int tcf_vlan_init(struct net *net, struct nlattr *nla, ...@@ -197,7 +210,6 @@ static int tcf_vlan_init(struct net *net, struct nlattr *nla,
ASSERT_RTNL(); ASSERT_RTNL();
p = kzalloc(sizeof(*p), GFP_KERNEL); p = kzalloc(sizeof(*p), GFP_KERNEL);
if (!p) { if (!p) {
if (ret == ACT_P_CREATED)
tcf_idr_release(*a, bind); tcf_idr_release(*a, bind);
return -ENOMEM; return -ENOMEM;
} }
...@@ -239,8 +251,8 @@ static int tcf_vlan_dump(struct sk_buff *skb, struct tc_action *a, ...@@ -239,8 +251,8 @@ static int tcf_vlan_dump(struct sk_buff *skb, struct tc_action *a,
struct tcf_vlan_params *p = rtnl_dereference(v->vlan_p); struct tcf_vlan_params *p = rtnl_dereference(v->vlan_p);
struct tc_vlan opt = { struct tc_vlan opt = {
.index = v->tcf_index, .index = v->tcf_index,
.refcnt = v->tcf_refcnt - ref, .refcnt = refcount_read(&v->tcf_refcnt) - ref,
.bindcnt = v->tcf_bindcnt - bind, .bindcnt = atomic_read(&v->tcf_bindcnt) - bind,
.action = v->tcf_action, .action = v->tcf_action,
.v_action = p->tcfv_action, .v_action = p->tcfv_action,
}; };
...@@ -286,6 +298,13 @@ static int tcf_vlan_search(struct net *net, struct tc_action **a, u32 index, ...@@ -286,6 +298,13 @@ static int tcf_vlan_search(struct net *net, struct tc_action **a, u32 index,
return tcf_idr_search(tn, a, index); return tcf_idr_search(tn, a, index);
} }
static int tcf_vlan_delete(struct net *net, u32 index)
{
struct tc_action_net *tn = net_generic(net, vlan_net_id);
return tcf_idr_delete_index(tn, index);
}
static struct tc_action_ops act_vlan_ops = { static struct tc_action_ops act_vlan_ops = {
.kind = "vlan", .kind = "vlan",
.type = TCA_ACT_VLAN, .type = TCA_ACT_VLAN,
...@@ -296,6 +315,7 @@ static struct tc_action_ops act_vlan_ops = { ...@@ -296,6 +315,7 @@ static struct tc_action_ops act_vlan_ops = {
.cleanup = tcf_vlan_cleanup, .cleanup = tcf_vlan_cleanup,
.walk = tcf_vlan_walker, .walk = tcf_vlan_walker,
.lookup = tcf_vlan_search, .lookup = tcf_vlan_search,
.delete = tcf_vlan_delete,
.size = sizeof(struct tcf_vlan), .size = sizeof(struct tcf_vlan),
}; };
......
...@@ -1609,11 +1609,7 @@ static int tc_dump_tfilter(struct sk_buff *skb, struct netlink_callback *cb) ...@@ -1609,11 +1609,7 @@ static int tc_dump_tfilter(struct sk_buff *skb, struct netlink_callback *cb)
void tcf_exts_destroy(struct tcf_exts *exts) void tcf_exts_destroy(struct tcf_exts *exts)
{ {
#ifdef CONFIG_NET_CLS_ACT #ifdef CONFIG_NET_CLS_ACT
LIST_HEAD(actions); tcf_action_destroy(exts->actions, TCA_ACT_UNBIND);
ASSERT_RTNL();
tcf_exts_to_list(exts, &actions);
tcf_action_destroy(&actions, TCA_ACT_UNBIND);
kfree(exts->actions); kfree(exts->actions);
exts->nr_actions = 0; exts->nr_actions = 0;
#endif #endif
...@@ -1632,7 +1628,7 @@ int tcf_exts_validate(struct net *net, struct tcf_proto *tp, struct nlattr **tb, ...@@ -1632,7 +1628,7 @@ int tcf_exts_validate(struct net *net, struct tcf_proto *tp, struct nlattr **tb,
if (exts->police && tb[exts->police]) { if (exts->police && tb[exts->police]) {
act = tcf_action_init_1(net, tp, tb[exts->police], act = tcf_action_init_1(net, tp, tb[exts->police],
rate_tlv, "police", ovr, rate_tlv, "police", ovr,
TCA_ACT_BIND, extack); TCA_ACT_BIND, true, extack);
if (IS_ERR(act)) if (IS_ERR(act))
return PTR_ERR(act); return PTR_ERR(act);
...@@ -1640,17 +1636,15 @@ int tcf_exts_validate(struct net *net, struct tcf_proto *tp, struct nlattr **tb, ...@@ -1640,17 +1636,15 @@ int tcf_exts_validate(struct net *net, struct tcf_proto *tp, struct nlattr **tb,
exts->actions[0] = act; exts->actions[0] = act;
exts->nr_actions = 1; exts->nr_actions = 1;
} else if (exts->action && tb[exts->action]) { } else if (exts->action && tb[exts->action]) {
LIST_HEAD(actions); int err;
int err, i = 0;
err = tcf_action_init(net, tp, tb[exts->action], err = tcf_action_init(net, tp, tb[exts->action],
rate_tlv, NULL, ovr, TCA_ACT_BIND, rate_tlv, NULL, ovr, TCA_ACT_BIND,
&actions, &attr_size, extack); exts->actions, &attr_size, true,
if (err) extack);
if (err < 0)
return err; return err;
list_for_each_entry(act, &actions, list) exts->nr_actions = err;
exts->actions[i++] = act;
exts->nr_actions = i;
} }
exts->net = net; exts->net = net;
} }
...@@ -1699,14 +1693,11 @@ int tcf_exts_dump(struct sk_buff *skb, struct tcf_exts *exts) ...@@ -1699,14 +1693,11 @@ int tcf_exts_dump(struct sk_buff *skb, struct tcf_exts *exts)
* tc data even if iproute2 was newer - jhs * tc data even if iproute2 was newer - jhs
*/ */
if (exts->type != TCA_OLD_COMPAT) { if (exts->type != TCA_OLD_COMPAT) {
LIST_HEAD(actions);
nest = nla_nest_start(skb, exts->action); nest = nla_nest_start(skb, exts->action);
if (nest == NULL) if (nest == NULL)
goto nla_put_failure; goto nla_put_failure;
tcf_exts_to_list(exts, &actions); if (tcf_action_dump(skb, exts->actions, 0, 0) < 0)
if (tcf_action_dump(skb, &actions, 0, 0) < 0)
goto nla_put_failure; goto nla_put_failure;
nla_nest_end(skb, nest); nla_nest_end(skb, nest);
} else if (exts->police) { } else if (exts->police) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment