Commit d3cee865 authored by Nicolas Dichtel's avatar Nicolas Dichtel Committed by Kelsey Skunberg

vti[6]: fix packet tx through bpf_redirect() in XinY cases

BugLink: https://bugs.launchpad.net/bugs/1873852

commit f1ed1026 upstream.

I forgot the 4in6/6in4 cases in my previous patch. Let's fix them.

Fixes: 95224166 ("vti[6]: fix packet tx through bpf_redirect()")
Signed-off-by: default avatarNicolas Dichtel <nicolas.dichtel@6wind.com>
Signed-off-by: default avatarSteffen Klassert <steffen.klassert@secunet.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarKleber Sacilotto de Souza <kleber.souza@canonical.com>
Signed-off-by: default avatarKelsey Skunberg <kelsey.skunberg@canonical.com>
parent e6962297
...@@ -298,6 +298,7 @@ config SYN_COOKIES ...@@ -298,6 +298,7 @@ config SYN_COOKIES
config NET_IPVTI config NET_IPVTI
tristate "Virtual (secure) IP: tunneling" tristate "Virtual (secure) IP: tunneling"
depends on IPV6 || IPV6=n
select INET_TUNNEL select INET_TUNNEL
select NET_IP_TUNNEL select NET_IP_TUNNEL
depends on INET_XFRM_MODE_TUNNEL depends on INET_XFRM_MODE_TUNNEL
......
...@@ -195,17 +195,39 @@ static netdev_tx_t vti_xmit(struct sk_buff *skb, struct net_device *dev, ...@@ -195,17 +195,39 @@ static netdev_tx_t vti_xmit(struct sk_buff *skb, struct net_device *dev,
int err; int err;
if (!dst) { if (!dst) {
struct rtable *rt; switch (skb->protocol) {
case htons(ETH_P_IP): {
fl->u.ip4.flowi4_oif = dev->ifindex; struct rtable *rt;
fl->u.ip4.flowi4_flags |= FLOWI_FLAG_ANYSRC;
rt = __ip_route_output_key(dev_net(dev), &fl->u.ip4); fl->u.ip4.flowi4_oif = dev->ifindex;
if (IS_ERR(rt)) { fl->u.ip4.flowi4_flags |= FLOWI_FLAG_ANYSRC;
rt = __ip_route_output_key(dev_net(dev), &fl->u.ip4);
if (IS_ERR(rt)) {
dev->stats.tx_carrier_errors++;
goto tx_error_icmp;
}
dst = &rt->dst;
skb_dst_set(skb, dst);
break;
}
#if IS_ENABLED(CONFIG_IPV6)
case htons(ETH_P_IPV6):
fl->u.ip6.flowi6_oif = dev->ifindex;
fl->u.ip6.flowi6_flags |= FLOWI_FLAG_ANYSRC;
dst = ip6_route_output(dev_net(dev), NULL, &fl->u.ip6);
if (dst->error) {
dst_release(dst);
dst = NULL;
dev->stats.tx_carrier_errors++;
goto tx_error_icmp;
}
skb_dst_set(skb, dst);
break;
#endif
default:
dev->stats.tx_carrier_errors++; dev->stats.tx_carrier_errors++;
goto tx_error_icmp; goto tx_error_icmp;
} }
dst = &rt->dst;
skb_dst_set(skb, dst);
} }
dst_hold(dst); dst_hold(dst);
......
...@@ -442,15 +442,33 @@ vti6_xmit(struct sk_buff *skb, struct net_device *dev, struct flowi *fl) ...@@ -442,15 +442,33 @@ vti6_xmit(struct sk_buff *skb, struct net_device *dev, struct flowi *fl)
int mtu; int mtu;
if (!dst) { if (!dst) {
fl->u.ip6.flowi6_oif = dev->ifindex; switch (skb->protocol) {
fl->u.ip6.flowi6_flags |= FLOWI_FLAG_ANYSRC; case htons(ETH_P_IP): {
dst = ip6_route_output(dev_net(dev), NULL, &fl->u.ip6); struct rtable *rt;
if (dst->error) {
dst_release(dst); fl->u.ip4.flowi4_oif = dev->ifindex;
dst = NULL; fl->u.ip4.flowi4_flags |= FLOWI_FLAG_ANYSRC;
rt = __ip_route_output_key(dev_net(dev), &fl->u.ip4);
if (IS_ERR(rt))
goto tx_err_link_failure;
dst = &rt->dst;
skb_dst_set(skb, dst);
break;
}
case htons(ETH_P_IPV6):
fl->u.ip6.flowi6_oif = dev->ifindex;
fl->u.ip6.flowi6_flags |= FLOWI_FLAG_ANYSRC;
dst = ip6_route_output(dev_net(dev), NULL, &fl->u.ip6);
if (dst->error) {
dst_release(dst);
dst = NULL;
goto tx_err_link_failure;
}
skb_dst_set(skb, dst);
break;
default:
goto tx_err_link_failure; goto tx_err_link_failure;
} }
skb_dst_set(skb, dst);
} }
dst_hold(dst); dst_hold(dst);
......
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