Skip to contentSkip to conversation

ipsec interfaces: fix sending with bpf_redirect() / AF_PACKET sockets

PATCH Superseded Nicolas Dichtel 2 participants 16 messages Dec 31, 2019 – Jan 27, 2020

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover ipsec interfaces: fix sending with bpf_redirect() / AF_PACKET sockets

Before those patches, packets sent to a vti[6]/xfrm interface via bpf_redirect() or via an AF_PACKET socket were dropped, mostly because no dst was attached.

 net/ipv4/ip_vti.c         | 10 ++++++++--
 net/ipv6/ip6_vti.c        | 11 +++++++++--
 net/xfrm/xfrm_interface.c | 21 +++++++++++++++++----
 3 files changed, 34 insertions(+), 8 deletions(-)

Regards,
Nicolas

#1 lore raw

PATCH 1/2 vti[6]: fix packet tx through bpf_redirect()

With an ebpf program that redirects packets through a vti[6] interface, the packets are dropped because no dst is attached.

This could also be reproduced with an AF_PACKET socket, with the following python script (vti1 is an ip_vti interface):

import socket
send_s = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, 0)

 # scapy
 # p = IP(src='10.100.0.2', dst='10.200.0.1')/ICMP(type='echo-request')
 # raw(p)
 req = b'E\x00\x00\x1c\x00\x01\x00\x00@\x01e\xb2\nd\x00\x02\n\xc8\x00\x01\x08\x00\xf7\xff\x00\x00\x00\x00'
 send_s.sendto(req, ('vti1', 0x800, 0, 0))
---
 net/ipv4/ip_vti.c  | 11 +++++++++--
 net/ipv6/ip6_vti.c | 11 +++++++++--
 2 files changed, 18 insertions(+), 4 deletions(-)
net/ipv4/ip_vti.c +9 -2
index cfb025606793..341e0689456d 100644
@@ -187,8 +187,15 @@ static netdev_tx_t vti_xmit(struct sk_buff *skb, struct net_device *dev,
 	int mtu;
 
 	if (!dst) {
-		dev->stats.tx_carrier_errors++;
-		goto tx_error_icmp;
+		struct rtable *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);
 	}
 
 	dst_hold(dst);
net/ipv6/ip6_vti.c +9 -2
index 024db17386d2..089b9d5dc15e 100644
@@ -449,8 +449,15 @@ vti6_xmit(struct sk_buff *skb, struct net_device *dev, struct flowi *fl)
 	int err = -1;
 	int mtu;
 
-	if (!dst)
-		goto tx_err_link_failure;
+	if (!dst) {
+		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);
+	}
 
 	dst_hold(dst);
 	dst = xfrm_lookup(t->net, dst, fl, NULL, 0);
Signature · 1 line
2.24.0
#2 lore raw

PATCH 2/2 xfrm interface: fix packet tx through bpf_redirect()

In reply to Nicolas Dichtel

With an ebpf program that redirects packets through a xfrm interface, packets are dropped because no dst is attached to skb.

This could also be reproduced with an AF_PACKET socket, with the following python script (xfrm1 is a xfrm interface):

import socket
send_s = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, 0)

 # scapy
 # p = IP(src='10.100.0.2', dst='10.200.0.1')/ICMP(type='echo-request')
 # raw(p)
 req = b'E\x00\x00\x1c\x00\x01\x00\x00@\x01e\xb2\nd\x00\x02\n\xc8\x00\x01\x08\x00\xf7\xff\x00\x00\x00\x00'
 send_s.sendto(req, ('xfrm1', 0x800, 0, 0))

It was also not possible to send an ip packet through an AF_PACKET socket because a LL header was expected. Let's remove those LL header constraints.

---
 net/xfrm/xfrm_interface.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)
net/xfrm/xfrm_interface.c +18 -4
index 7ac1542feaf8..55978a1501ec 100644
@@ -343,6 +343,7 @@ static netdev_tx_t xfrmi_xmit(struct sk_buff *skb, struct net_device *dev)
 {
 	struct xfrm_if *xi = netdev_priv(dev);
 	struct net_device_stats *stats = &xi->dev->stats;
+	struct dst_entry *dst = skb_dst(skb);
 	struct flowi fl;
 	int ret;
 
@@ -352,10 +353,26 @@ static netdev_tx_t xfrmi_xmit(struct sk_buff *skb, struct net_device *dev)
 	case htons(ETH_P_IPV6):
 		xfrm_decode_session(skb, &fl, AF_INET6);
 		memset(IP6CB(skb), 0, sizeof(*IP6CB(skb)));
+		if (!dst) {
+			dst = ip6_route_output(dev_net(dev), NULL, &fl.u.ip6);
+			if (dst->error) {
+				dst_release(dst);
+				goto tx_err;
+			}
+			skb_dst_set(skb, dst);
+		}
 		break;
 	case htons(ETH_P_IP):
 		xfrm_decode_session(skb, &fl, AF_INET);
 		memset(IPCB(skb), 0, sizeof(*IPCB(skb)));
+		if (!dst) {
+			struct rtable *rt = __ip_route_output_key(dev_net(dev),
+								  &fl.u.ip4);
+
+			if (IS_ERR(rt))
+				goto tx_err;
+			skb_dst_set(skb, &rt->dst);
+		}
 		break;
 	default:
 		goto tx_err;
@@ -563,12 +580,9 @@ static void xfrmi_dev_setup(struct net_device *dev)
 {
 	dev->netdev_ops 	= &xfrmi_netdev_ops;
 	dev->type		= ARPHRD_NONE;
-	dev->hard_header_len 	= ETH_HLEN;
-	dev->min_header_len	= ETH_HLEN;
 	dev->mtu		= ETH_DATA_LEN;
 	dev->min_mtu		= ETH_MIN_MTU;
-	dev->max_mtu		= ETH_DATA_LEN;
-	dev->addr_len		= ETH_ALEN;
+	dev->max_mtu		= IP_MAX_MTU;
 	dev->flags 		= IFF_NOARP;
 	dev->needs_free_netdev	= true;
 	dev->priv_destructor	= xfrmi_dev_free;
Signature · 1 line
2.24.0
maintainer
#3 lore raw

Re: [PATCH ipsec 2/2] xfrm interface: fix packet tx through bpf_redirect()

Quoted 46 lines · Nicolas Dichtel

With an ebpf program that redirects packets through a xfrm interface, packets are dropped because no dst is attached to skb.

This could also be reproduced with an AF_PACKET socket, with the following python script (xfrm1 is a xfrm interface):

import socket
send_s = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, 0)

 # scapy
 # p = IP(src='10.100.0.2', dst='10.200.0.1')/ICMP(type='echo-request')
 # raw(p)
 req = b'E\x00\x00\x1c\x00\x01\x00\x00@\x01e\xb2\nd\x00\x02\n\xc8\x00\x01\x08\x00\xf7\xff\x00\x00\x00\x00'
 send_s.sendto(req, ('xfrm1', 0x800, 0, 0))

It was also not possible to send an ip packet through an AF_PACKET socket because a LL header was expected. Let's remove those LL header constraints.

---
 net/xfrm/xfrm_interface.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)
net/xfrm/xfrm_interface.c +9 -0
index 7ac1542feaf8..55978a1501ec 100644
@@ -343,6 +343,7 @@ static netdev_tx_t xfrmi_xmit(struct sk_buff *skb, struct net_device *dev)
 {
 	struct xfrm_if *xi = netdev_priv(dev);
 	struct net_device_stats *stats = &xi->dev->stats;
+	struct dst_entry *dst = skb_dst(skb);
 	struct flowi fl;
 	int ret;
 
@@ -352,10 +353,26 @@ static netdev_tx_t xfrmi_xmit(struct sk_buff *skb, struct net_device *dev)
 	case htons(ETH_P_IPV6):
 		xfrm_decode_session(skb, &fl, AF_INET6);
 		memset(IP6CB(skb), 0, sizeof(*IP6CB(skb)));
+		if (!dst) {
+			dst = ip6_route_output(dev_net(dev), NULL, &fl.u.ip6);
+			if (dst->error) {
+				dst_release(dst);
+				goto tx_err;
+			}
+			skb_dst_set(skb, dst);
+		}

net/xfrm/xfrm_interface.c static netdev_tx_t xfrmi_xmit(struct sk_buff *skb, struct net_device *dev) · line 373

Quoted 10 lines
net/xfrm/xfrm_interface.c +6 -0
 		break;
 	case htons(ETH_P_IP):
 		xfrm_decode_session(skb, &fl, AF_INET);
 		memset(IPCB(skb), 0, sizeof(*IPCB(skb)));
+		if (!dst) {
+			struct rtable *rt = __ip_route_output_key(dev_net(dev),
+								  &fl.u.ip4);
+
+			if (IS_ERR(rt))
+				goto tx_err;

With this change, the 'if (!dst)' in xfrmi_xmit2() is meaningless and we don't handle this error as a link failure anymore.

Please make sure that the error path is not changed.

#4 lore raw

Re: [PATCH ipsec 2/2] xfrm interface: fix packet tx through bpf_redirect()

Le 09/01/2020 à 09:40, Steffen Klassert a écrit :
[snip]

Quoted 16 lines
Quoted 16 lines
net/xfrm/xfrm_interface.c +8 -0
@@ -352,10 +353,26 @@ static netdev_tx_t xfrmi_xmit(struct sk_buff *skb, struct net_device *dev)
 	case htons(ETH_P_IPV6):
 		xfrm_decode_session(skb, &fl, AF_INET6);
 		memset(IP6CB(skb), 0, sizeof(*IP6CB(skb)));
+		if (!dst) {
+			dst = ip6_route_output(dev_net(dev), NULL, &fl.u.ip6);
+			if (dst->error) {
+				dst_release(dst);
+				goto tx_err;
+			}
+			skb_dst_set(skb, dst);
+		}
 		break;
 	case htons(ETH_P_IP):
 		xfrm_decode_session(skb, &fl, AF_INET);
 		memset(IPCB(skb), 0, sizeof(*IPCB(skb)));
Quoted 8 lines

net/xfrm/xfrm_interface.c static netdev_tx_t xfrmi_xmit(struct sk_buff *skb, struct net_device *dev) · line 373

Quoted 6 lines
net/xfrm/xfrm_interface.c +6 -0
+		if (!dst) {
+			struct rtable *rt = __ip_route_output_key(dev_net(dev),
+								  &fl.u.ip4);
+
+			if (IS_ERR(rt))
+				goto tx_err;

With this change, the 'if (!dst)' in xfrmi_xmit2() is meaningless

Yep, I was hesitant to remove it :)

Quoted 1 line

and we don't handle this error as a link failure anymore.

Good point, will send a v2.

Thank you,
Nicolas

#5 lore raw

v2 cover ipsec interfaces: fix sending with bpf_redirect() / AF_PACKET sockets

In reply to Steffen Klassert

Before those patches, packets sent to a vti[6]/xfrm interface via bpf_redirect() or via an AF_PACKET socket were dropped, mostly because no dst was attached.

v1 -> v2:
- remove useless check against skb_dst() in xfrmi_xmit2()
- keep incrementing tx_carrier_errors in case of route lookup failure

 net/ipv4/ip_vti.c         | 11 +++++++++--
 net/ipv6/ip6_vti.c        | 11 +++++++++--
 net/xfrm/xfrm_interface.c | 28 +++++++++++++++++++++-------
 3 files changed, 39 insertions(+), 11 deletions(-)

Regards,
Nicolas

#6 lore raw

PATCH v2 1/2 vti[6]: fix packet tx through bpf_redirect()

With an ebpf program that redirects packets through a vti[6] interface, the packets are dropped because no dst is attached.

This could also be reproduced with an AF_PACKET socket, with the following python script (vti1 is an ip_vti interface):

import socket
send_s = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, 0)

 # scapy
 # p = IP(src='10.100.0.2', dst='10.200.0.1')/ICMP(type='echo-request')
 # raw(p)
 req = b'E\x00\x00\x1c\x00\x01\x00\x00@\x01e\xb2\nd\x00\x02\n\xc8\x00\x01\x08\x00\xf7\xff\x00\x00\x00\x00'
 send_s.sendto(req, ('vti1', 0x800, 0, 0))
---
 net/ipv4/ip_vti.c  | 11 +++++++++--
 net/ipv6/ip6_vti.c | 11 +++++++++--
 2 files changed, 18 insertions(+), 4 deletions(-)
net/ipv4/ip_vti.c +9 -2
index e90b600c7a25..085d7aea82e7 100644
@@ -187,8 +187,15 @@ static netdev_tx_t vti_xmit(struct sk_buff *skb, struct net_device *dev,
 	int mtu;
 
 	if (!dst) {
-		dev->stats.tx_carrier_errors++;
-		goto tx_error_icmp;
+		struct rtable *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);
 	}
 
 	dst_hold(dst);
net/ipv6/ip6_vti.c +9 -2
index 6f08b760c2a7..a6609803e8b1 100644
@@ -449,8 +449,15 @@ vti6_xmit(struct sk_buff *skb, struct net_device *dev, struct flowi *fl)
 	int err = -1;
 	int mtu;
 
-	if (!dst)
-		goto tx_err_link_failure;
+	if (!dst) {
+		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);
+	}
 
 	dst_hold(dst);
 	dst = xfrm_lookup(t->net, dst, fl, NULL, 0);
Signature · 1 line
2.24.0
#7 lore raw

PATCH v2 2/2 xfrm interface: fix packet tx through bpf_redirect()

In reply to Nicolas Dichtel

With an ebpf program that redirects packets through a xfrm interface, packets are dropped because no dst is attached to skb.

This could also be reproduced with an AF_PACKET socket, with the following python script (xfrm1 is a xfrm interface):

import socket
send_s = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, 0)

 # scapy
 # p = IP(src='10.100.0.2', dst='10.200.0.1')/ICMP(type='echo-request')
 # raw(p)
 req = b'E\x00\x00\x1c\x00\x01\x00\x00@\x01e\xb2\nd\x00\x02\n\xc8\x00\x01\x08\x00\xf7\xff\x00\x00\x00\x00'
 send_s.sendto(req, ('xfrm1', 0x800, 0, 0))

It was also not possible to send an ip packet through an AF_PACKET socket because a LL header was expected. Let's remove those LL header constraints.

---
 net/xfrm/xfrm_interface.c | 28 +++++++++++++++++++++-------
 1 file changed, 21 insertions(+), 7 deletions(-)
net/xfrm/xfrm_interface.c +21 -7
index 7ac1542feaf8..60481acb10d2 100644
@@ -268,9 +268,6 @@ xfrmi_xmit2(struct sk_buff *skb, struct net_device *dev, struct flowi *fl)
 	int err = -1;
 	int mtu;
 
-	if (!dst)
-		goto tx_err_link_failure;
-
 	dst_hold(dst);
 	dst = xfrm_lookup_with_ifid(xi->net, dst, fl, NULL, 0, xi->p.if_id);
 	if (IS_ERR(dst)) {
@@ -343,6 +340,7 @@ static netdev_tx_t xfrmi_xmit(struct sk_buff *skb, struct net_device *dev)
 {
 	struct xfrm_if *xi = netdev_priv(dev);
 	struct net_device_stats *stats = &xi->dev->stats;
+	struct dst_entry *dst = skb_dst(skb);
 	struct flowi fl;
 	int ret;
 
@@ -352,10 +350,29 @@ static netdev_tx_t xfrmi_xmit(struct sk_buff *skb, struct net_device *dev)
 	case htons(ETH_P_IPV6):
 		xfrm_decode_session(skb, &fl, AF_INET6);
 		memset(IP6CB(skb), 0, sizeof(*IP6CB(skb)));
+		if (!dst) {
+			dst = ip6_route_output(dev_net(dev), NULL, &fl.u.ip6);
+			if (dst->error) {
+				dst_release(dst);
+				stats->tx_carrier_errors++;
+				goto tx_err;
+			}
+			skb_dst_set(skb, dst);
+		}
 		break;
 	case htons(ETH_P_IP):
 		xfrm_decode_session(skb, &fl, AF_INET);
 		memset(IPCB(skb), 0, sizeof(*IPCB(skb)));
+		if (!dst) {
+			struct rtable *rt = __ip_route_output_key(dev_net(dev),
+								  &fl.u.ip4);
+
+			if (IS_ERR(rt)) {
+				stats->tx_carrier_errors++;
+				goto tx_err;
+			}
+			skb_dst_set(skb, &rt->dst);
+		}
 		break;
 	default:
 		goto tx_err;
@@ -563,12 +580,9 @@ static void xfrmi_dev_setup(struct net_device *dev)
 {
 	dev->netdev_ops 	= &xfrmi_netdev_ops;
 	dev->type		= ARPHRD_NONE;
-	dev->hard_header_len 	= ETH_HLEN;
-	dev->min_header_len	= ETH_HLEN;
 	dev->mtu		= ETH_DATA_LEN;
 	dev->min_mtu		= ETH_MIN_MTU;
-	dev->max_mtu		= ETH_DATA_LEN;
-	dev->addr_len		= ETH_ALEN;
+	dev->max_mtu		= IP_MAX_MTU;
 	dev->flags 		= IFF_NOARP;
 	dev->needs_free_netdev	= true;
 	dev->priv_destructor	= xfrmi_dev_free;
Signature · 1 line
2.24.0
#8 lore raw
In reply to Nicolas Dichtel

Le 09/01/2020 à 14:35, Nicolas Dichtel a écrit :

Quoted 3 lines

Before those patches, packets sent to a vti[6]/xfrm interface via bpf_redirect() or via an AF_PACKET socket were dropped, mostly because no dst was attached.

Please, drop this version, I will send an update.

Regards,
Nicolas

#9 lore raw

v3 cover ipsec interfaces: fix sending with bpf_redirect() / AF_PACKET sockets

Before those patches, packets sent to a vti[6]/xfrm interface via bpf_redirect() or via an AF_PACKET socket were dropped, mostly because no dst was attached.

v2 -> v3:
- fix flowi info for the route lookup

v1 -> v2:
- remove useless check against skb_dst() in xfrmi_xmit2()
- keep incrementing tx_carrier_errors in case of route lookup failure

 net/ipv4/ip_vti.c         | 13 +++++++++++--
 net/ipv6/ip6_vti.c        | 13 +++++++++++--
 net/xfrm/xfrm_interface.c | 32 +++++++++++++++++++++++++-------
 3 files changed, 47 insertions(+), 11 deletions(-)

Regards,
Nicolas

#10 lore raw

PATCH v3 1/2 vti[6]: fix packet tx through bpf_redirect()

With an ebpf program that redirects packets through a vti[6] interface, the packets are dropped because no dst is attached.

This could also be reproduced with an AF_PACKET socket, with the following python script (vti1 is an ip_vti interface):

import socket
send_s = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, 0)

 # scapy
 # p = IP(src='10.100.0.2', dst='10.200.0.1')/ICMP(type='echo-request')
 # raw(p)
 req = b'E\x00\x00\x1c\x00\x01\x00\x00@\x01e\xb2\nd\x00\x02\n\xc8\x00\x01\x08\x00\xf7\xff\x00\x00\x00\x00'
 send_s.sendto(req, ('vti1', 0x800, 0, 0))
---
 net/ipv4/ip_vti.c  | 13 +++++++++++--
 net/ipv6/ip6_vti.c | 13 +++++++++++--
 2 files changed, 22 insertions(+), 4 deletions(-)
net/ipv4/ip_vti.c +11 -2
index e90b600c7a25..37cddd18f282 100644
@@ -187,8 +187,17 @@ static netdev_tx_t vti_xmit(struct sk_buff *skb, struct net_device *dev,
 	int mtu;
 
 	if (!dst) {
-		dev->stats.tx_carrier_errors++;
-		goto tx_error_icmp;
+		struct rtable *rt;
+
+		fl->u.ip4.flowi4_oif = dev->ifindex;
+		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);
 	}
 
 	dst_hold(dst);
net/ipv6/ip6_vti.c +11 -2
index 6f08b760c2a7..524006aa0d78 100644
@@ -449,8 +449,17 @@ vti6_xmit(struct sk_buff *skb, struct net_device *dev, struct flowi *fl)
 	int err = -1;
 	int mtu;
 
-	if (!dst)
-		goto tx_err_link_failure;
+	if (!dst) {
+		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);
+	}
 
 	dst_hold(dst);
 	dst = xfrm_lookup(t->net, dst, fl, NULL, 0);
Signature · 1 line
2.24.0
#11 lore raw

PATCH v3 2/2 xfrm interface: fix packet tx through bpf_redirect()

In reply to Nicolas Dichtel

With an ebpf program that redirects packets through a xfrm interface, packets are dropped because no dst is attached to skb.

This could also be reproduced with an AF_PACKET socket, with the following python script (xfrm1 is a xfrm interface):

import socket
send_s = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, 0)

 # scapy
 # p = IP(src='10.100.0.2', dst='10.200.0.1')/ICMP(type='echo-request')
 # raw(p)
 req = b'E\x00\x00\x1c\x00\x01\x00\x00@\x01e\xb2\nd\x00\x02\n\xc8\x00\x01\x08\x00\xf7\xff\x00\x00\x00\x00'
 send_s.sendto(req, ('xfrm1', 0x800, 0, 0))

It was also not possible to send an ip packet through an AF_PACKET socket because a LL header was expected. Let's remove those LL header constraints.

---
 net/xfrm/xfrm_interface.c | 32 +++++++++++++++++++++++++-------
 1 file changed, 25 insertions(+), 7 deletions(-)
net/xfrm/xfrm_interface.c +25 -7
index 7ac1542feaf8..00393179f185 100644
@@ -268,9 +268,6 @@ xfrmi_xmit2(struct sk_buff *skb, struct net_device *dev, struct flowi *fl)
 	int err = -1;
 	int mtu;
 
-	if (!dst)
-		goto tx_err_link_failure;
-
 	dst_hold(dst);
 	dst = xfrm_lookup_with_ifid(xi->net, dst, fl, NULL, 0, xi->p.if_id);
 	if (IS_ERR(dst)) {
@@ -343,6 +340,7 @@ static netdev_tx_t xfrmi_xmit(struct sk_buff *skb, struct net_device *dev)
 {
 	struct xfrm_if *xi = netdev_priv(dev);
 	struct net_device_stats *stats = &xi->dev->stats;
+	struct dst_entry *dst = skb_dst(skb);
 	struct flowi fl;
 	int ret;
 
@@ -352,10 +350,33 @@ static netdev_tx_t xfrmi_xmit(struct sk_buff *skb, struct net_device *dev)
 	case htons(ETH_P_IPV6):
 		xfrm_decode_session(skb, &fl, AF_INET6);
 		memset(IP6CB(skb), 0, sizeof(*IP6CB(skb)));
+		if (!dst) {
+			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);
+				stats->tx_carrier_errors++;
+				goto tx_err;
+			}
+			skb_dst_set(skb, dst);
+		}
 		break;
 	case htons(ETH_P_IP):
 		xfrm_decode_session(skb, &fl, AF_INET);
 		memset(IPCB(skb), 0, sizeof(*IPCB(skb)));
+		if (!dst) {
+			struct rtable *rt;
+
+			fl.u.ip4.flowi4_oif = dev->ifindex;
+			fl.u.ip4.flowi4_flags |= FLOWI_FLAG_ANYSRC;
+			rt = __ip_route_output_key(dev_net(dev), &fl.u.ip4);
+			if (IS_ERR(rt)) {
+				stats->tx_carrier_errors++;
+				goto tx_err;
+			}
+			skb_dst_set(skb, &rt->dst);
+		}
 		break;
 	default:
 		goto tx_err;
@@ -563,12 +584,9 @@ static void xfrmi_dev_setup(struct net_device *dev)
 {
 	dev->netdev_ops 	= &xfrmi_netdev_ops;
 	dev->type		= ARPHRD_NONE;
-	dev->hard_header_len 	= ETH_HLEN;
-	dev->min_header_len	= ETH_HLEN;
 	dev->mtu		= ETH_DATA_LEN;
 	dev->min_mtu		= ETH_MIN_MTU;
-	dev->max_mtu		= ETH_DATA_LEN;
-	dev->addr_len		= ETH_ALEN;
+	dev->max_mtu		= IP_MAX_MTU;
 	dev->flags 		= IFF_NOARP;
 	dev->needs_free_netdev	= true;
 	dev->priv_destructor	= xfrmi_dev_free;
Signature · 1 line
2.24.0
maintainer Applied
#12 lore raw
In reply to Nicolas Dichtel
Quoted 7 lines · Nicolas Dichtel

Before those patches, packets sent to a vti[6]/xfrm interface via bpf_redirect() or via an AF_PACKET socket were dropped, mostly because no dst was attached.

v2 -> v3:
- fix flowi info for the route lookup

Quoted 8 lines

v1 -> v2:
- remove useless check against skb_dst() in xfrmi_xmit2()
- keep incrementing tx_carrier_errors in case of route lookup failure

 net/ipv4/ip_vti.c         | 13 +++++++++++--
 net/ipv6/ip6_vti.c        | 13 +++++++++++--
 net/xfrm/xfrm_interface.c | 32 +++++++++++++++++++++++++-------
 3 files changed, 47 insertions(+), 11 deletions(-)

Applied to the ipsec tree, thanks a lot!

#13 lore raw

Le 15/01/2020 à 10:56, Steffen Klassert a écrit :

Quoted 12 lines · Nicolas Dichtel
Quoted 11 lines

Before those patches, packets sent to a vti[6]/xfrm interface via bpf_redirect() or via an AF_PACKET socket were dropped, mostly because no dst was attached.

v2 -> v3:
- fix flowi info for the route lookup

v1 -> v2:
- remove useless check against skb_dst() in xfrmi_xmit2()
- keep incrementing tx_carrier_errors in case of route lookup failure

Quoted 7 lines
Quoted 4 lines
 net/ipv4/ip_vti.c         | 13 +++++++++++--
 net/ipv6/ip6_vti.c        | 13 +++++++++++--
 net/xfrm/xfrm_interface.c | 32 +++++++++++++++++++++++++-------
 3 files changed, 47 insertions(+), 11 deletions(-)

Applied to the ipsec tree, thanks a lot!

Thanks. Those patches are now in Linus tree:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=95224166a903
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=f042365dbffe

Could you queue them for stable trees?

Thank you,
Nicolas

maintainer
#14 lore raw
Quoted 18 lines · Nicolas Dichtel

Le 15/01/2020 à 10:56, Steffen Klassert a écrit :

Quoted 17 lines · Nicolas Dichtel
Quoted 15 lines

Before those patches, packets sent to a vti[6]/xfrm interface via bpf_redirect() or via an AF_PACKET socket were dropped, mostly because no dst was attached.

v2 -> v3:
- fix flowi info for the route lookup

v1 -> v2:
- remove useless check against skb_dst() in xfrmi_xmit2()
- keep incrementing tx_carrier_errors in case of route lookup failure

 net/ipv4/ip_vti.c         | 13 +++++++++++--
 net/ipv6/ip6_vti.c        | 13 +++++++++++--
 net/xfrm/xfrm_interface.c | 32 +++++++++++++++++++++++++-------
 3 files changed, 47 insertions(+), 11 deletions(-)
Quoted 8 lines
Quoted 2 lines

Applied to the ipsec tree, thanks a lot!

Thanks. Those patches are now in Linus tree:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=95224166a903
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=f042365dbffe

Could you queue them for stable trees?

I'll do an ipsec stable submission the next days.

#15 lore raw

Le 27/01/2020 à 10:58, Steffen Klassert a écrit :
[snip]

Quoted 2 lines

I'll do an ipsec stable submission the next days.

Thanks!