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

Merge branch 'ingress-actions'

Shmulik Ladkani says:

====================
act_mirred: Ingress actions support

This patch series implements action mirred 'ingress' actions
TCA_INGRESS_REDIR and TCA_INGRESS_MIRROR.

This allows attaching filters whose target is to hand matching skbs into
the rx processing of a specified device.

v4:
  in 4/4, check ret code of netif_receive_skb, as suggested by Cong Wang
v3:
  in 4/4, addressed non coherency due to reading m->tcfm_eaction multiple
  times, as spotted by Eric Dumazet
v2:
  in 1/4, declare tcfm_mac_header_xmit as bool instead of int
====================
Acked-by: default avatarCong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 4f58e6dc 53592b36
...@@ -113,7 +113,7 @@ static int fill_action_fields(struct adapter *adap, ...@@ -113,7 +113,7 @@ 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_redirect(a)) { if (is_tcf_mirred_egress_redirect(a)) {
struct net_device *n_dev; struct net_device *n_dev;
unsigned int i, index; unsigned int i, index;
bool found = false; bool found = false;
......
...@@ -8410,7 +8410,7 @@ static int parse_tc_actions(struct ixgbe_adapter *adapter, ...@@ -8410,7 +8410,7 @@ 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_redirect(a)) { if (is_tcf_mirred_egress_redirect(a)) {
int ifindex = tcf_mirred_ifindex(a); int ifindex = tcf_mirred_ifindex(a);
err = handle_redirect_action(adapter, ifindex, queue, err = handle_redirect_action(adapter, ifindex, queue,
......
...@@ -404,7 +404,7 @@ static int parse_tc_fdb_actions(struct mlx5e_priv *priv, struct tcf_exts *exts, ...@@ -404,7 +404,7 @@ static int parse_tc_fdb_actions(struct mlx5e_priv *priv, struct tcf_exts *exts,
continue; continue;
} }
if (is_tcf_mirred_redirect(a)) { if (is_tcf_mirred_egress_redirect(a)) {
int ifindex = tcf_mirred_ifindex(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;
......
...@@ -1237,8 +1237,10 @@ static int mlxsw_sp_port_add_cls_matchall(struct mlxsw_sp_port *mlxsw_sp_port, ...@@ -1237,8 +1237,10 @@ static int mlxsw_sp_port_add_cls_matchall(struct mlxsw_sp_port *mlxsw_sp_port,
tcf_exts_to_list(cls->exts, &actions); tcf_exts_to_list(cls->exts, &actions);
list_for_each_entry(a, &actions, list) { list_for_each_entry(a, &actions, list) {
if (!is_tcf_mirred_mirror(a) || protocol != htons(ETH_P_ALL)) if (!is_tcf_mirred_egress_mirror(a) ||
protocol != htons(ETH_P_ALL)) {
return -ENOTSUPP; return -ENOTSUPP;
}
err = mlxsw_sp_port_add_cls_matchall_mirror(mlxsw_sp_port, cls, err = mlxsw_sp_port_add_cls_matchall_mirror(mlxsw_sp_port, cls,
a, ingress); a, ingress);
......
...@@ -128,7 +128,7 @@ nfp_net_bpf_get_act(struct nfp_net *nn, struct tc_cls_bpf_offload *cls_bpf) ...@@ -128,7 +128,7 @@ nfp_net_bpf_get_act(struct nfp_net *nn, struct tc_cls_bpf_offload *cls_bpf)
if (is_tcf_gact_shot(a)) if (is_tcf_gact_shot(a))
return NN_ACT_TC_DROP; return NN_ACT_TC_DROP;
if (is_tcf_mirred_redirect(a) && if (is_tcf_mirred_egress_redirect(a) &&
tcf_mirred_ifindex(a) == nn->netdev->ifindex) tcf_mirred_ifindex(a) == nn->netdev->ifindex)
return NN_ACT_TC_REDIR; return NN_ACT_TC_REDIR;
} }
......
...@@ -8,13 +8,13 @@ struct tcf_mirred { ...@@ -8,13 +8,13 @@ struct tcf_mirred {
struct tc_action common; struct tc_action common;
int tcfm_eaction; int tcfm_eaction;
int tcfm_ifindex; int tcfm_ifindex;
int tcfm_ok_push; bool tcfm_mac_header_xmit;
struct net_device __rcu *tcfm_dev; struct net_device __rcu *tcfm_dev;
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)
static inline bool is_tcf_mirred_redirect(const struct tc_action *a) static inline bool is_tcf_mirred_egress_redirect(const struct tc_action *a)
{ {
#ifdef CONFIG_NET_CLS_ACT #ifdef CONFIG_NET_CLS_ACT
if (a->ops && a->ops->type == TCA_ACT_MIRRED) if (a->ops && a->ops->type == TCA_ACT_MIRRED)
...@@ -23,7 +23,7 @@ static inline bool is_tcf_mirred_redirect(const struct tc_action *a) ...@@ -23,7 +23,7 @@ static inline bool is_tcf_mirred_redirect(const struct tc_action *a)
return false; return false;
} }
static inline bool is_tcf_mirred_mirror(const struct tc_action *a) static inline bool is_tcf_mirred_egress_mirror(const struct tc_action *a)
{ {
#ifdef CONFIG_NET_CLS_ACT #ifdef CONFIG_NET_CLS_ACT
if (a->ops && a->ops->type == TCA_ACT_MIRRED) if (a->ops && a->ops->type == TCA_ACT_MIRRED)
......
...@@ -33,6 +33,25 @@ ...@@ -33,6 +33,25 @@
static LIST_HEAD(mirred_list); static LIST_HEAD(mirred_list);
static DEFINE_SPINLOCK(mirred_list_lock); static DEFINE_SPINLOCK(mirred_list_lock);
static bool tcf_mirred_is_act_redirect(int action)
{
return action == TCA_EGRESS_REDIR || action == TCA_INGRESS_REDIR;
}
static u32 tcf_mirred_act_direction(int action)
{
switch (action) {
case TCA_EGRESS_REDIR:
case TCA_EGRESS_MIRROR:
return AT_EGRESS;
case TCA_INGRESS_REDIR:
case TCA_INGRESS_MIRROR:
return AT_INGRESS;
default:
BUG();
}
}
static void tcf_mirred_release(struct tc_action *a, int bind) static void tcf_mirred_release(struct tc_action *a, int bind)
{ {
struct tcf_mirred *m = to_mirred(a); struct tcf_mirred *m = to_mirred(a);
...@@ -54,17 +73,32 @@ static const struct nla_policy mirred_policy[TCA_MIRRED_MAX + 1] = { ...@@ -54,17 +73,32 @@ static const struct nla_policy mirred_policy[TCA_MIRRED_MAX + 1] = {
static int mirred_net_id; static int mirred_net_id;
static struct tc_action_ops act_mirred_ops; static struct tc_action_ops act_mirred_ops;
static bool dev_is_mac_header_xmit(const struct net_device *dev)
{
switch (dev->type) {
case ARPHRD_TUNNEL:
case ARPHRD_TUNNEL6:
case ARPHRD_SIT:
case ARPHRD_IPGRE:
case ARPHRD_VOID:
case ARPHRD_NONE:
return false;
}
return true;
}
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 ovr,
int bind) int bind)
{ {
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];
bool mac_header_xmit = false;
struct tc_mirred *parm; struct tc_mirred *parm;
struct tcf_mirred *m; struct tcf_mirred *m;
struct net_device *dev; struct net_device *dev;
int ret, ok_push = 0;
bool exists = false; bool exists = false;
int ret;
if (nla == NULL) if (nla == NULL)
return -EINVAL; return -EINVAL;
...@@ -82,6 +116,8 @@ static int tcf_mirred_init(struct net *net, struct nlattr *nla, ...@@ -82,6 +116,8 @@ static int tcf_mirred_init(struct net *net, struct nlattr *nla,
switch (parm->eaction) { switch (parm->eaction) {
case TCA_EGRESS_MIRROR: case TCA_EGRESS_MIRROR:
case TCA_EGRESS_REDIR: case TCA_EGRESS_REDIR:
case TCA_INGRESS_REDIR:
case TCA_INGRESS_MIRROR:
break; break;
default: default:
if (exists) if (exists)
...@@ -95,19 +131,7 @@ static int tcf_mirred_init(struct net *net, struct nlattr *nla, ...@@ -95,19 +131,7 @@ static int tcf_mirred_init(struct net *net, struct nlattr *nla,
tcf_hash_release(*a, bind); tcf_hash_release(*a, bind);
return -ENODEV; return -ENODEV;
} }
switch (dev->type) { mac_header_xmit = dev_is_mac_header_xmit(dev);
case ARPHRD_TUNNEL:
case ARPHRD_TUNNEL6:
case ARPHRD_SIT:
case ARPHRD_IPGRE:
case ARPHRD_VOID:
case ARPHRD_NONE:
ok_push = 0;
break;
default:
ok_push = 1;
break;
}
} else { } else {
dev = NULL; dev = NULL;
} }
...@@ -136,7 +160,7 @@ static int tcf_mirred_init(struct net *net, struct nlattr *nla, ...@@ -136,7 +160,7 @@ static int tcf_mirred_init(struct net *net, struct nlattr *nla,
dev_put(rcu_dereference_protected(m->tcfm_dev, 1)); dev_put(rcu_dereference_protected(m->tcfm_dev, 1));
dev_hold(dev); dev_hold(dev);
rcu_assign_pointer(m->tcfm_dev, dev); rcu_assign_pointer(m->tcfm_dev, dev);
m->tcfm_ok_push = ok_push; m->tcfm_mac_header_xmit = mac_header_xmit;
} }
if (ret == ACT_P_CREATED) { if (ret == ACT_P_CREATED) {
...@@ -153,15 +177,20 @@ static int tcf_mirred(struct sk_buff *skb, const struct tc_action *a, ...@@ -153,15 +177,20 @@ static int tcf_mirred(struct sk_buff *skb, const struct tc_action *a,
struct tcf_result *res) struct tcf_result *res)
{ {
struct tcf_mirred *m = to_mirred(a); struct tcf_mirred *m = to_mirred(a);
bool m_mac_header_xmit;
struct net_device *dev; struct net_device *dev;
struct sk_buff *skb2; struct sk_buff *skb2;
int retval, err; int retval, err = 0;
int m_eaction;
int mac_len;
u32 at; u32 at;
tcf_lastuse_update(&m->tcf_tm); tcf_lastuse_update(&m->tcf_tm);
bstats_cpu_update(this_cpu_ptr(m->common.cpu_bstats), skb); bstats_cpu_update(this_cpu_ptr(m->common.cpu_bstats), skb);
rcu_read_lock(); rcu_read_lock();
m_mac_header_xmit = READ_ONCE(m->tcfm_mac_header_xmit);
m_eaction = READ_ONCE(m->tcfm_eaction);
retval = READ_ONCE(m->tcf_action); retval = READ_ONCE(m->tcf_action);
dev = rcu_dereference(m->tcfm_dev); dev = rcu_dereference(m->tcfm_dev);
if (unlikely(!dev)) { if (unlikely(!dev)) {
...@@ -180,23 +209,36 @@ static int tcf_mirred(struct sk_buff *skb, const struct tc_action *a, ...@@ -180,23 +209,36 @@ static int tcf_mirred(struct sk_buff *skb, const struct tc_action *a,
if (!skb2) if (!skb2)
goto out; goto out;
if (!(at & AT_EGRESS)) { /* If action's target direction differs than filter's direction,
if (m->tcfm_ok_push) * and devices expect a mac header on xmit, then mac push/pull is
* needed.
*/
if (at != tcf_mirred_act_direction(m_eaction) && m_mac_header_xmit) {
if (at & AT_EGRESS) {
/* caught at egress, act ingress: pull mac */
mac_len = skb_network_header(skb) - skb_mac_header(skb);
skb_pull_rcsum(skb2, mac_len);
} else {
/* caught at ingress, act egress: push mac */
skb_push_rcsum(skb2, skb->mac_len); skb_push_rcsum(skb2, skb->mac_len);
}
} }
/* mirror is always swallowed */ /* mirror is always swallowed */
if (m->tcfm_eaction != TCA_EGRESS_MIRROR) if (tcf_mirred_is_act_redirect(m_eaction))
skb2->tc_verd = SET_TC_FROM(skb2->tc_verd, at); skb2->tc_verd = SET_TC_FROM(skb2->tc_verd, at);
skb2->skb_iif = skb->dev->ifindex; skb2->skb_iif = skb->dev->ifindex;
skb2->dev = dev; skb2->dev = dev;
err = dev_queue_xmit(skb2); if (tcf_mirred_act_direction(m_eaction) & AT_EGRESS)
err = dev_queue_xmit(skb2);
else
err = netif_receive_skb(skb2);
if (err) { if (err) {
out: out:
qstats_overlimit_inc(this_cpu_ptr(m->common.cpu_qstats)); qstats_overlimit_inc(this_cpu_ptr(m->common.cpu_qstats));
if (m->tcfm_eaction != TCA_EGRESS_MIRROR) if (tcf_mirred_is_act_redirect(m_eaction))
retval = TC_ACT_SHOT; retval = TC_ACT_SHOT;
} }
rcu_read_unlock(); rcu_read_unlock();
......
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