Skip to content

Commit 415e38b

Browse files
vbnogueiradavem330
authored andcommitted
net/sched: act_mirred: Add helper function tcf_mirred_replace_dev
The act of replacing a device will be repeated by the init logic for the block ID in the patch that allows mirred to a block. Therefore we encapsulate this functionality in a function (tcf_mirred_replace_dev) so that we can reuse it and avoid code repetition. Co-developed-by: Jamal Hadi Salim <[email protected]> Signed-off-by: Jamal Hadi Salim <[email protected]> Co-developed-by: Pedro Tammela <[email protected]> Signed-off-by: Pedro Tammela <[email protected]> Signed-off-by: Victor Nogueira <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 16085e4 commit 415e38b

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

net/sched/act_mirred.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,16 @@ static const struct nla_policy mirred_policy[TCA_MIRRED_MAX + 1] = {
8989

9090
static struct tc_action_ops act_mirred_ops;
9191

92+
static void tcf_mirred_replace_dev(struct tcf_mirred *m,
93+
struct net_device *ndev)
94+
{
95+
struct net_device *odev;
96+
97+
odev = rcu_replace_pointer(m->tcfm_dev, ndev,
98+
lockdep_is_held(&m->tcf_lock));
99+
netdev_put(odev, &m->tcfm_dev_tracker);
100+
}
101+
92102
static int tcf_mirred_init(struct net *net, struct nlattr *nla,
93103
struct nlattr *est, struct tc_action **a,
94104
struct tcf_proto *tp,
@@ -170,7 +180,7 @@ static int tcf_mirred_init(struct net *net, struct nlattr *nla,
170180
spin_lock_bh(&m->tcf_lock);
171181

172182
if (parm->ifindex) {
173-
struct net_device *odev, *ndev;
183+
struct net_device *ndev;
174184

175185
ndev = dev_get_by_index(net, parm->ifindex);
176186
if (!ndev) {
@@ -179,9 +189,7 @@ static int tcf_mirred_init(struct net *net, struct nlattr *nla,
179189
goto put_chain;
180190
}
181191
mac_header_xmit = dev_is_mac_header_xmit(ndev);
182-
odev = rcu_replace_pointer(m->tcfm_dev, ndev,
183-
lockdep_is_held(&m->tcf_lock));
184-
netdev_put(odev, &m->tcfm_dev_tracker);
192+
tcf_mirred_replace_dev(m, ndev);
185193
netdev_tracker_alloc(ndev, &m->tcfm_dev_tracker, GFP_ATOMIC);
186194
m->tcfm_mac_header_xmit = mac_header_xmit;
187195
}

0 commit comments

Comments
 (0)