提交 9f8a739e 编写于 作者: C Cong Wang 提交者: David S. Miller

act_mirred: get rid of tcfm_ifindex from struct tcf_mirred

tcfm_dev always points to the correct netdev and we already
hold a refcnt, so no need to use tcfm_ifindex to lookup again.

If we would support moving target netdev across netns, using
pointer would be better than ifindex.

This also fixes dumping obsolete ifindex, now after the
target device is gone we just dump 0 as ifindex.

Cc: Jiri Pirko <jiri@mellanox.com>
Cc: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: NCong Wang <xiyou.wangcong@gmail.com>
Acked-by: NJiri Pirko <jiri@mellanox.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 3a9ab393
...@@ -54,12 +54,10 @@ static int bnxt_tc_parse_redir(struct bnxt *bp, ...@@ -54,12 +54,10 @@ static int bnxt_tc_parse_redir(struct bnxt *bp,
struct bnxt_tc_actions *actions, struct bnxt_tc_actions *actions,
const struct tc_action *tc_act) const struct tc_action *tc_act)
{ {
int ifindex = tcf_mirred_ifindex(tc_act); struct net_device *dev = tcf_mirred_dev(tc_act);
struct net_device *dev;
dev = __dev_get_by_index(dev_net(bp->dev), ifindex);
if (!dev) { if (!dev) {
netdev_info(bp->dev, "no dev for ifindex=%d", ifindex); netdev_info(bp->dev, "no dev in mirred action");
return -EINVAL; return -EINVAL;
} }
......
...@@ -405,9 +405,7 @@ static void cxgb4_process_flow_actions(struct net_device *in, ...@@ -405,9 +405,7 @@ static void cxgb4_process_flow_actions(struct net_device *in,
} else if (is_tcf_gact_shot(a)) { } else if (is_tcf_gact_shot(a)) {
fs->action = FILTER_DROP; fs->action = FILTER_DROP;
} else if (is_tcf_mirred_egress_redirect(a)) { } else if (is_tcf_mirred_egress_redirect(a)) {
int ifindex = tcf_mirred_ifindex(a); struct net_device *out = tcf_mirred_dev(a);
struct net_device *out = __dev_get_by_index(dev_net(in),
ifindex);
struct port_info *pi = netdev_priv(out); struct port_info *pi = netdev_priv(out);
fs->action = FILTER_SWITCH; fs->action = FILTER_SWITCH;
...@@ -582,14 +580,14 @@ static int cxgb4_validate_flow_actions(struct net_device *dev, ...@@ -582,14 +580,14 @@ static int cxgb4_validate_flow_actions(struct net_device *dev,
/* Do nothing */ /* Do nothing */
} else if (is_tcf_mirred_egress_redirect(a)) { } else if (is_tcf_mirred_egress_redirect(a)) {
struct adapter *adap = netdev2adap(dev); struct adapter *adap = netdev2adap(dev);
struct net_device *n_dev; struct net_device *n_dev, *target_dev;
unsigned int i, ifindex; unsigned int i;
bool found = false; bool found = false;
ifindex = tcf_mirred_ifindex(a); target_dev = tcf_mirred_dev(a);
for_each_port(adap, i) { for_each_port(adap, i) {
n_dev = adap->port[i]; n_dev = adap->port[i];
if (ifindex == n_dev->ifindex) { if (target_dev == n_dev) {
found = true; found = true;
break; break;
} }
......
...@@ -114,14 +114,14 @@ static int fill_action_fields(struct adapter *adap, ...@@ -114,14 +114,14 @@ static int fill_action_fields(struct adapter *adap,
/* Re-direct to specified port in hardware. */ /* Re-direct to specified port in hardware. */
if (is_tcf_mirred_egress_redirect(a)) { if (is_tcf_mirred_egress_redirect(a)) {
struct net_device *n_dev; struct net_device *n_dev, *target_dev;
unsigned int i, index;
bool found = false; bool found = false;
unsigned int i;
index = tcf_mirred_ifindex(a); target_dev = tcf_mirred_dev(a);
for_each_port(adap, i) { for_each_port(adap, i) {
n_dev = adap->port[i]; n_dev = adap->port[i];
if (index == n_dev->ifindex) { if (target_dev == n_dev) {
fs->action = FILTER_SWITCH; fs->action = FILTER_SWITCH;
fs->eport = i; fs->eport = i;
found = true; found = true;
......
...@@ -9101,9 +9101,11 @@ static int parse_tc_actions(struct ixgbe_adapter *adapter, ...@@ -9101,9 +9101,11 @@ static int parse_tc_actions(struct ixgbe_adapter *adapter,
/* Redirect to a VF or a offloaded macvlan */ /* Redirect to a VF or a offloaded macvlan */
if (is_tcf_mirred_egress_redirect(a)) { if (is_tcf_mirred_egress_redirect(a)) {
int ifindex = tcf_mirred_ifindex(a); struct net_device *dev = tcf_mirred_dev(a);
err = handle_redirect_action(adapter, ifindex, queue, if (!dev)
return -EINVAL;
err = handle_redirect_action(adapter, dev->ifindex, queue,
action); action);
if (err == 0) if (err == 0)
return err; return err;
......
...@@ -1982,11 +1982,10 @@ static int parse_tc_fdb_actions(struct mlx5e_priv *priv, struct tcf_exts *exts, ...@@ -1982,11 +1982,10 @@ static int parse_tc_fdb_actions(struct mlx5e_priv *priv, struct tcf_exts *exts,
} }
if (is_tcf_mirred_egress_redirect(a)) { if (is_tcf_mirred_egress_redirect(a)) {
int ifindex = tcf_mirred_ifindex(a);
struct net_device *out_dev; struct net_device *out_dev;
struct mlx5e_priv *out_priv; struct mlx5e_priv *out_priv;
out_dev = __dev_get_by_index(dev_net(priv->netdev), ifindex); out_dev = tcf_mirred_dev(a);
if (switchdev_port_same_parent_id(priv->netdev, if (switchdev_port_same_parent_id(priv->netdev,
out_dev)) { out_dev)) {
...@@ -1996,7 +1995,7 @@ static int parse_tc_fdb_actions(struct mlx5e_priv *priv, struct tcf_exts *exts, ...@@ -1996,7 +1995,7 @@ static int parse_tc_fdb_actions(struct mlx5e_priv *priv, struct tcf_exts *exts,
rpriv = out_priv->ppriv; rpriv = out_priv->ppriv;
attr->out_rep = rpriv->rep; attr->out_rep = rpriv->rep;
} else if (encap) { } else if (encap) {
parse_attr->mirred_ifindex = ifindex; parse_attr->mirred_ifindex = out_dev->ifindex;
parse_attr->tun_info = *info; parse_attr->tun_info = *info;
attr->parse_attr = parse_attr; attr->parse_attr = parse_attr;
attr->action |= MLX5_FLOW_CONTEXT_ACTION_ENCAP | attr->action |= MLX5_FLOW_CONTEXT_ACTION_ENCAP |
......
...@@ -1571,14 +1571,11 @@ mlxsw_sp_port_add_cls_matchall_mirror(struct mlxsw_sp_port *mlxsw_sp_port, ...@@ -1571,14 +1571,11 @@ mlxsw_sp_port_add_cls_matchall_mirror(struct mlxsw_sp_port *mlxsw_sp_port,
const struct tc_action *a, const struct tc_action *a,
bool ingress) bool ingress)
{ {
struct net *net = dev_net(mlxsw_sp_port->dev);
enum mlxsw_sp_span_type span_type; enum mlxsw_sp_span_type span_type;
struct mlxsw_sp_port *to_port; struct mlxsw_sp_port *to_port;
struct net_device *to_dev; struct net_device *to_dev;
int ifindex;
ifindex = tcf_mirred_ifindex(a); to_dev = tcf_mirred_dev(a);
to_dev = __dev_get_by_index(net, ifindex);
if (!to_dev) { if (!to_dev) {
netdev_err(mlxsw_sp_port->dev, "Could not find requested device\n"); netdev_err(mlxsw_sp_port->dev, "Could not find requested device\n");
return -EINVAL; return -EINVAL;
......
...@@ -92,7 +92,6 @@ static int mlxsw_sp_flower_parse_actions(struct mlxsw_sp *mlxsw_sp, ...@@ -92,7 +92,6 @@ static int mlxsw_sp_flower_parse_actions(struct mlxsw_sp *mlxsw_sp,
if (err) if (err)
return err; return err;
} else if (is_tcf_mirred_egress_redirect(a)) { } else if (is_tcf_mirred_egress_redirect(a)) {
int ifindex = tcf_mirred_ifindex(a);
struct net_device *out_dev; struct net_device *out_dev;
struct mlxsw_sp_fid *fid; struct mlxsw_sp_fid *fid;
u16 fid_index; u16 fid_index;
...@@ -104,7 +103,7 @@ static int mlxsw_sp_flower_parse_actions(struct mlxsw_sp *mlxsw_sp, ...@@ -104,7 +103,7 @@ static int mlxsw_sp_flower_parse_actions(struct mlxsw_sp *mlxsw_sp,
if (err) if (err)
return err; return err;
out_dev = __dev_get_by_index(dev_net(dev), ifindex); out_dev = tcf_mirred_dev(a);
if (out_dev == dev) if (out_dev == dev)
out_dev = NULL; out_dev = NULL;
......
...@@ -93,13 +93,11 @@ nfp_fl_output(struct nfp_fl_output *output, const struct tc_action *action, ...@@ -93,13 +93,11 @@ nfp_fl_output(struct nfp_fl_output *output, const struct tc_action *action,
size_t act_size = sizeof(struct nfp_fl_output); size_t act_size = sizeof(struct nfp_fl_output);
struct net_device *out_dev; struct net_device *out_dev;
u16 tmp_flags; u16 tmp_flags;
int ifindex;
output->head.jump_id = NFP_FL_ACTION_OPCODE_OUTPUT; output->head.jump_id = NFP_FL_ACTION_OPCODE_OUTPUT;
output->head.len_lw = act_size >> NFP_FL_LW_SIZ; output->head.len_lw = act_size >> NFP_FL_LW_SIZ;
ifindex = tcf_mirred_ifindex(action); out_dev = tcf_mirred_dev(action);
out_dev = __dev_get_by_index(dev_net(in_dev), ifindex);
if (!out_dev) if (!out_dev)
return -EOPNOTSUPP; return -EOPNOTSUPP;
......
...@@ -8,10 +8,8 @@ ...@@ -8,10 +8,8 @@
struct tcf_mirred { struct tcf_mirred {
struct tc_action common; struct tc_action common;
int tcfm_eaction; int tcfm_eaction;
int tcfm_ifindex;
bool tcfm_mac_header_xmit; bool tcfm_mac_header_xmit;
struct net_device __rcu *tcfm_dev; struct net_device __rcu *tcfm_dev;
struct net *net;
struct list_head tcfm_list; struct list_head tcfm_list;
}; };
#define to_mirred(a) ((struct tcf_mirred *)a) #define to_mirred(a) ((struct tcf_mirred *)a)
...@@ -34,9 +32,9 @@ static inline bool is_tcf_mirred_egress_mirror(const struct tc_action *a) ...@@ -34,9 +32,9 @@ static inline bool is_tcf_mirred_egress_mirror(const struct tc_action *a)
return false; return false;
} }
static inline int tcf_mirred_ifindex(const struct tc_action *a) static inline struct net_device *tcf_mirred_dev(const struct tc_action *a)
{ {
return to_mirred(a)->tcfm_ifindex; return rtnl_dereference(to_mirred(a)->tcfm_dev);
} }
#endif /* __NET_TC_MIR_H */ #endif /* __NET_TC_MIR_H */
...@@ -709,14 +709,12 @@ static int dsa_slave_add_cls_matchall(struct net_device *dev, ...@@ -709,14 +709,12 @@ static int dsa_slave_add_cls_matchall(struct net_device *dev,
struct dsa_slave_priv *p = netdev_priv(dev); struct dsa_slave_priv *p = netdev_priv(dev);
struct dsa_mall_tc_entry *mall_tc_entry; struct dsa_mall_tc_entry *mall_tc_entry;
__be16 protocol = cls->common.protocol; __be16 protocol = cls->common.protocol;
struct net *net = dev_net(dev);
struct dsa_switch *ds = dp->ds; struct dsa_switch *ds = dp->ds;
struct net_device *to_dev; struct net_device *to_dev;
const struct tc_action *a; const struct tc_action *a;
struct dsa_port *to_dp; struct dsa_port *to_dp;
int err = -EOPNOTSUPP; int err = -EOPNOTSUPP;
LIST_HEAD(actions); LIST_HEAD(actions);
int ifindex;
if (!ds->ops->port_mirror_add) if (!ds->ops->port_mirror_add)
return err; return err;
...@@ -730,8 +728,7 @@ static int dsa_slave_add_cls_matchall(struct net_device *dev, ...@@ -730,8 +728,7 @@ static int dsa_slave_add_cls_matchall(struct net_device *dev,
if (is_tcf_mirred_egress_mirror(a) && protocol == htons(ETH_P_ALL)) { if (is_tcf_mirred_egress_mirror(a) && protocol == htons(ETH_P_ALL)) {
struct dsa_mall_mirror_tc_entry *mirror; struct dsa_mall_mirror_tc_entry *mirror;
ifindex = tcf_mirred_ifindex(a); to_dev = tcf_mirred_dev(a);
to_dev = __dev_get_by_index(net, ifindex);
if (!to_dev) if (!to_dev)
return -EINVAL; return -EINVAL;
......
...@@ -139,8 +139,6 @@ static int tcf_mirred_init(struct net *net, struct nlattr *nla, ...@@ -139,8 +139,6 @@ static int tcf_mirred_init(struct net *net, struct nlattr *nla,
m->tcf_action = parm->action; m->tcf_action = parm->action;
m->tcfm_eaction = parm->eaction; m->tcfm_eaction = parm->eaction;
if (dev != NULL) { if (dev != NULL) {
m->tcfm_ifindex = parm->ifindex;
m->net = net;
if (ret != ACT_P_CREATED) if (ret != ACT_P_CREATED)
dev_put(rcu_dereference_protected(m->tcfm_dev, 1)); dev_put(rcu_dereference_protected(m->tcfm_dev, 1));
dev_hold(dev); dev_hold(dev);
...@@ -247,13 +245,14 @@ static int tcf_mirred_dump(struct sk_buff *skb, struct tc_action *a, int bind, ...@@ -247,13 +245,14 @@ static int tcf_mirred_dump(struct sk_buff *skb, struct tc_action *a, int bind,
{ {
unsigned char *b = skb_tail_pointer(skb); unsigned char *b = skb_tail_pointer(skb);
struct tcf_mirred *m = to_mirred(a); struct tcf_mirred *m = to_mirred(a);
struct net_device *dev = rtnl_dereference(m->tcfm_dev);
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 = m->tcf_refcnt - ref,
.bindcnt = m->tcf_bindcnt - bind, .bindcnt = m->tcf_bindcnt - bind,
.eaction = m->tcfm_eaction, .eaction = m->tcfm_eaction,
.ifindex = m->tcfm_ifindex, .ifindex = dev ? dev->ifindex : 0,
}; };
struct tcf_t t; struct tcf_t t;
...@@ -318,7 +317,7 @@ static struct net_device *tcf_mirred_get_dev(const struct tc_action *a) ...@@ -318,7 +317,7 @@ static struct net_device *tcf_mirred_get_dev(const struct tc_action *a)
{ {
struct tcf_mirred *m = to_mirred(a); struct tcf_mirred *m = to_mirred(a);
return __dev_get_by_index(m->net, m->tcfm_ifindex); return rtnl_dereference(m->tcfm_dev);
} }
static struct tc_action_ops act_mirred_ops = { static struct tc_action_ops act_mirred_ops = {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册