提交 4ccc75e9 编写于 作者: M Martin Willi 提交者: Cheng Jian

vrf: Fix fast path output packet handling with async Netfilter rules

stable inclusion
from linux-4.19.158
commit 200c2f68407601b1bed3dba5e027f34cd284ec92

--------------------------------

[ Upstream commit 9e2b7fa2 ]

VRF devices use an optimized direct path on output if a default qdisc
is involved, calling Netfilter hooks directly. This path, however, does
not consider Netfilter rules completing asynchronously, such as with
NFQUEUE. The Netfilter okfn() is called for asynchronously accepted
packets, but the VRF never passes that packet down the stack to send
it out over the slave device. Using the slower redirect path for this
seems not feasible, as we do not know beforehand if a Netfilter hook
has asynchronously completing rules.

Fix the use of asynchronously completing Netfilter rules in OUTPUT and
POSTROUTING by using a special completion function that additionally
calls dst_output() to pass the packet down the stack. Also, slightly
adjust the use of nf_reset_ct() so that is called in the asynchronous
case, too.

Fixes: dcdd43c4 ("net: vrf: performance improvements for IPv4")
Fixes: a9ec54d1 ("net: vrf: performance improvements for IPv6")
Signed-off-by: NMartin Willi <martin@strongswan.org>
Link: https://lore.kernel.org/r/20201106073030.3974927-1-martin@strongswan.orgSigned-off-by: NJakub Kicinski <kuba@kernel.org>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
Signed-off-by: NAichun Li <liaichun@huawei.com>
reviewed-by: Nwangxiaopeng <wangxiaopeng7@huawei.com>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
Signed-off-by: NCheng Jian <cj.chengjian@huawei.com>
上级 01bbad21
...@@ -336,8 +336,7 @@ static netdev_tx_t vrf_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -336,8 +336,7 @@ static netdev_tx_t vrf_xmit(struct sk_buff *skb, struct net_device *dev)
return ret; return ret;
} }
static int vrf_finish_direct(struct net *net, struct sock *sk, static void vrf_finish_direct(struct sk_buff *skb)
struct sk_buff *skb)
{ {
struct net_device *vrf_dev = skb->dev; struct net_device *vrf_dev = skb->dev;
...@@ -356,7 +355,8 @@ static int vrf_finish_direct(struct net *net, struct sock *sk, ...@@ -356,7 +355,8 @@ static int vrf_finish_direct(struct net *net, struct sock *sk,
skb_pull(skb, ETH_HLEN); skb_pull(skb, ETH_HLEN);
} }
return 1; /* reset skb device */
nf_reset(skb);
} }
#if IS_ENABLED(CONFIG_IPV6) #if IS_ENABLED(CONFIG_IPV6)
...@@ -435,15 +435,41 @@ static struct sk_buff *vrf_ip6_out_redirect(struct net_device *vrf_dev, ...@@ -435,15 +435,41 @@ static struct sk_buff *vrf_ip6_out_redirect(struct net_device *vrf_dev,
return skb; return skb;
} }
static int vrf_output6_direct_finish(struct net *net, struct sock *sk,
struct sk_buff *skb)
{
vrf_finish_direct(skb);
return vrf_ip6_local_out(net, sk, skb);
}
static int vrf_output6_direct(struct net *net, struct sock *sk, static int vrf_output6_direct(struct net *net, struct sock *sk,
struct sk_buff *skb) struct sk_buff *skb)
{ {
int err = 1;
skb->protocol = htons(ETH_P_IPV6); skb->protocol = htons(ETH_P_IPV6);
return NF_HOOK_COND(NFPROTO_IPV6, NF_INET_POST_ROUTING, if (!(IPCB(skb)->flags & IPSKB_REROUTED))
net, sk, skb, NULL, skb->dev, err = nf_hook(NFPROTO_IPV6, NF_INET_POST_ROUTING, net, sk, skb,
vrf_finish_direct, NULL, skb->dev, vrf_output6_direct_finish);
!(IPCB(skb)->flags & IPSKB_REROUTED));
if (likely(err == 1))
vrf_finish_direct(skb);
return err;
}
static int vrf_ip6_out_direct_finish(struct net *net, struct sock *sk,
struct sk_buff *skb)
{
int err;
err = vrf_output6_direct(net, sk, skb);
if (likely(err == 1))
err = vrf_ip6_local_out(net, sk, skb);
return err;
} }
static struct sk_buff *vrf_ip6_out_direct(struct net_device *vrf_dev, static struct sk_buff *vrf_ip6_out_direct(struct net_device *vrf_dev,
...@@ -456,18 +482,15 @@ static struct sk_buff *vrf_ip6_out_direct(struct net_device *vrf_dev, ...@@ -456,18 +482,15 @@ static struct sk_buff *vrf_ip6_out_direct(struct net_device *vrf_dev,
skb->dev = vrf_dev; skb->dev = vrf_dev;
err = nf_hook(NFPROTO_IPV6, NF_INET_LOCAL_OUT, net, sk, err = nf_hook(NFPROTO_IPV6, NF_INET_LOCAL_OUT, net, sk,
skb, NULL, vrf_dev, vrf_output6_direct); skb, NULL, vrf_dev, vrf_ip6_out_direct_finish);
if (likely(err == 1)) if (likely(err == 1))
err = vrf_output6_direct(net, sk, skb); err = vrf_output6_direct(net, sk, skb);
/* reset skb device */
if (likely(err == 1)) if (likely(err == 1))
nf_reset(skb); return skb;
else
skb = NULL;
return skb; return NULL;
} }
static struct sk_buff *vrf_ip6_out(struct net_device *vrf_dev, static struct sk_buff *vrf_ip6_out(struct net_device *vrf_dev,
...@@ -649,15 +672,41 @@ static struct sk_buff *vrf_ip_out_redirect(struct net_device *vrf_dev, ...@@ -649,15 +672,41 @@ static struct sk_buff *vrf_ip_out_redirect(struct net_device *vrf_dev,
return skb; return skb;
} }
static int vrf_output_direct_finish(struct net *net, struct sock *sk,
struct sk_buff *skb)
{
vrf_finish_direct(skb);
return vrf_ip_local_out(net, sk, skb);
}
static int vrf_output_direct(struct net *net, struct sock *sk, static int vrf_output_direct(struct net *net, struct sock *sk,
struct sk_buff *skb) struct sk_buff *skb)
{ {
int err = 1;
skb->protocol = htons(ETH_P_IP); skb->protocol = htons(ETH_P_IP);
return NF_HOOK_COND(NFPROTO_IPV4, NF_INET_POST_ROUTING, if (!(IPCB(skb)->flags & IPSKB_REROUTED))
net, sk, skb, NULL, skb->dev, err = nf_hook(NFPROTO_IPV4, NF_INET_POST_ROUTING, net, sk, skb,
vrf_finish_direct, NULL, skb->dev, vrf_output_direct_finish);
!(IPCB(skb)->flags & IPSKB_REROUTED));
if (likely(err == 1))
vrf_finish_direct(skb);
return err;
}
static int vrf_ip_out_direct_finish(struct net *net, struct sock *sk,
struct sk_buff *skb)
{
int err;
err = vrf_output_direct(net, sk, skb);
if (likely(err == 1))
err = vrf_ip_local_out(net, sk, skb);
return err;
} }
static struct sk_buff *vrf_ip_out_direct(struct net_device *vrf_dev, static struct sk_buff *vrf_ip_out_direct(struct net_device *vrf_dev,
...@@ -670,18 +719,15 @@ static struct sk_buff *vrf_ip_out_direct(struct net_device *vrf_dev, ...@@ -670,18 +719,15 @@ static struct sk_buff *vrf_ip_out_direct(struct net_device *vrf_dev,
skb->dev = vrf_dev; skb->dev = vrf_dev;
err = nf_hook(NFPROTO_IPV4, NF_INET_LOCAL_OUT, net, sk, err = nf_hook(NFPROTO_IPV4, NF_INET_LOCAL_OUT, net, sk,
skb, NULL, vrf_dev, vrf_output_direct); skb, NULL, vrf_dev, vrf_ip_out_direct_finish);
if (likely(err == 1)) if (likely(err == 1))
err = vrf_output_direct(net, sk, skb); err = vrf_output_direct(net, sk, skb);
/* reset skb device */
if (likely(err == 1)) if (likely(err == 1))
nf_reset(skb); return skb;
else
skb = NULL;
return skb; return NULL;
} }
static struct sk_buff *vrf_ip_out(struct net_device *vrf_dev, static struct sk_buff *vrf_ip_out(struct net_device *vrf_dev,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册