Skip to content

Commit

Permalink
net: sched: use get_dev() action API in flow_action infra
Browse files Browse the repository at this point in the history
When filling in hardware intermediate representation tc_setup_flow_action()
directly obtains, checks and takes reference to dev used by mirred action,
instead of using act->ops->get_dev() API created specifically for this
purpose. In order to remove code duplication, refactor flow_action infra to
use action API when obtaining mirred action target dev. Extend get_dev()
with additional argument that is used to provide dev destructor to the
user.

Fixes: 5a6ff4b ("net: sched: take reference to action dev before calling offloads")
Signed-off-by: Vlad Buslov <[email protected]>
Acked-by: Jiri Pirko <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
w1ldptr authored and davem330 committed Sep 16, 2019
1 parent 4a5da47 commit 470d506
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 20 deletions.
4 changes: 2 additions & 2 deletions include/net/act_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ struct tc_action_ops {
struct netlink_ext_ack *);
void (*stats_update)(struct tc_action *, u64, u32, u64, bool);
size_t (*get_fill_size)(const struct tc_action *act);
struct net_device *(*get_dev)(const struct tc_action *a);
void (*put_dev)(struct net_device *dev);
struct net_device *(*get_dev)(const struct tc_action *a,
tc_action_priv_destructor *destructor);
struct psample_group *
(*get_psample_group)(const struct tc_action *a,
tc_action_priv_destructor *destructor);
Expand Down
21 changes: 13 additions & 8 deletions net/sched/act_mirred.c
Original file line number Diff line number Diff line change
Expand Up @@ -408,25 +408,31 @@ static struct notifier_block mirred_device_notifier = {
.notifier_call = mirred_device_event,
};

static struct net_device *tcf_mirred_get_dev(const struct tc_action *a)
static void tcf_mirred_dev_put(void *priv)
{
struct net_device *dev = priv;

dev_put(dev);
}

static struct net_device *
tcf_mirred_get_dev(const struct tc_action *a,
tc_action_priv_destructor *destructor)
{
struct tcf_mirred *m = to_mirred(a);
struct net_device *dev;

rcu_read_lock();
dev = rcu_dereference(m->tcfm_dev);
if (dev)
if (dev) {
dev_hold(dev);
*destructor = tcf_mirred_dev_put;
}
rcu_read_unlock();

return dev;
}

static void tcf_mirred_put_dev(struct net_device *dev)
{
dev_put(dev);
}

static size_t tcf_mirred_get_fill_size(const struct tc_action *act)
{
return nla_total_size(sizeof(struct tc_mirred));
Expand All @@ -446,7 +452,6 @@ static struct tc_action_ops act_mirred_ops = {
.get_fill_size = tcf_mirred_get_fill_size,
.size = sizeof(struct tcf_mirred),
.get_dev = tcf_mirred_get_dev,
.put_dev = tcf_mirred_put_dev,
};

static __net_init int mirred_init_net(struct net *net)
Expand Down
13 changes: 3 additions & 10 deletions net/sched/cls_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -3288,22 +3288,15 @@ void tc_cleanup_flow_action(struct flow_action *flow_action)
}
EXPORT_SYMBOL(tc_cleanup_flow_action);

static void tcf_mirred_put_dev(void *priv)
{
struct net_device *dev = priv;

dev_put(dev);
}

static void tcf_mirred_get_dev(struct flow_action_entry *entry,
const struct tc_action *act)
{
entry->dev = tcf_mirred_dev(act);
#ifdef CONFIG_NET_CLS_ACT
entry->dev = act->ops->get_dev(act, &entry->destructor);
if (!entry->dev)
return;
dev_hold(entry->dev);
entry->destructor = tcf_mirred_put_dev;
entry->destructor_priv = entry->dev;
#endif
}

static void tcf_tunnel_encap_put_tunnel(void *priv)
Expand Down

0 comments on commit 470d506

Please sign in to comment.