Skip to contentSkip to conversation

xfrm: fix pmtu discovery (kill xfrm6_update_pmtu)

RFC In review Jiri Bohac 2 participants 4 messages Jan 29, 2013 – Feb 4, 2013

Subsystems (4)
lore
Share & tools
lore

Jiri Bohac

author
#0 lore raw

RFC 1/1 xfrm: fix pmtu discovery (kill xfrm6_update_pmtu)

Hi,

there is a problem in the xfrm PMTU discovery. This happens with IPv6, I'm not sure if the same applies to IPv4:

Let's have e.g. an ESP transport-mode policy mode between two endpoints: A and B. The ESP-encapsulated packets are sent over a router R:

	A <----> R <----> B

and the R <----> B link has a small MTU of 1452.

R sends an ICMPV6_PKT_TOOBIG to A with MTU==1452.
This is what then happens on A:

icmpv6_rcv() -> icmpv6_notify() -> esp6_err() -> ip6_update_pmtu()

This looks up the non-xfrm dst entry to host B (dst_B) and decreases its MTU to 1452

Next time a large TCP segment (len=1452 bytes including TCP/IP headers in this example) from A to B is created:

tcp_sendmsg() -> ... -> inet6_csk_xmit() -> ... -> xfrm_bundle_ok()

dst->child and xdst->route now point to the dst_B with MTU==1452 xdst->route_mtu_cached and xdst->child_mtu_cached are both 1500, so the MTU of the xfrm bundle's dst (dst_B_xfrm) is decreased to xfrm_state_mtu(dst_B_xfrm, 1452)==1414.

When the TCP segment reaches ip6_xmit:

	skb->len > dst_mtu(dst_B_xfrm)
	1452 > 1414

This generates an ICMPV6_PKT_TOOBIG to self with MTU==1414. This is intended to reach the protocol error handler (decrease the MSS in the TCP case):

icmpv6_rcv() -> icmpv6_notify() -> tcp_v6_err().

Then, tcp_v6_mtu_reduced() is either called directly or deferred until the socket is unlocked.

Everything is fine until now. The problem starts here:

tcp_v6_mtu_reduced() -> inet6_csk_update_pmtu():

	dst = inet6_csk_route_socket().
	//dst == dst_B_xfrm
	dst->ops->update_pmtu(dst, sk, NULL, mtu);

dst->ops->update_pmtu == xfrm6_update_pmtu:

       struct dst_entry *path = xdst->route;
       path->ops->update_pmtu(path, sk, skb, mtu);

path == dst_B, so we have now decreased the non-xfrm route's MTU to 1414

The next time xfrm_bundle_ok(dst_B_xfrm) is called, the MTU of dst_B_xfrm is decreased again (!!) to 1366.

If there is a single TCP socket, the loop ends here with both dst_B and dst_B_xfrm being unnecessarily low.

Otherwise this becomes a race between the MSS updates on the TCP sockets and the xfrm6_update_pmtu() + xfrm_bundle_ok() loop decreasing the MTU again and again, until the minimum MTU of 1280 is reached.

xfrm6_update_pmtu() has been doing this since ever. How was this supposed to work? Why would it ever want to adjust the MTU of the non-xfrm route that will be used to send the transformed packets?

Replacing xfrm6_update_pmtu with ip6_rt_update_pmtu fixes the problem for me. But perhaps I am overlooking something that gets broken by this.

Also, the IPv4 version does the same. Perhaps it has the same problems?

include/net/ip6_route.h +3 -0
index 27d8318..1e8cb91 100644
@@ -134,6 +134,9 @@ extern void ip6_update_pmtu(struct sk_buff *skb, struct net *net, __be32 mtu,
 			    int oif, u32 mark);
 extern void ip6_sk_update_pmtu(struct sk_buff *skb, struct sock *sk,
 			       __be32 mtu);
+extern void ip6_rt_update_pmtu(struct dst_entry *dst, struct sock *sk,
+                               struct sk_buff *skb, u32 mtu);
+
 extern void ip6_redirect(struct sk_buff *skb, struct net *net, int oif, u32 mark);
 extern void ip6_sk_redirect(struct sk_buff *skb, struct sock *sk);
 
net/ipv6/route.c +3 -2
index e229a3b..9d32702 100644
@@ -79,7 +79,7 @@ static int		 ip6_dst_gc(struct dst_ops *ops);
 static int		ip6_pkt_discard(struct sk_buff *skb);
 static int		ip6_pkt_discard_out(struct sk_buff *skb);
 static void		ip6_link_failure(struct sk_buff *skb);
-static void		ip6_rt_update_pmtu(struct dst_entry *dst, struct sock *sk,
+void		ip6_rt_update_pmtu(struct dst_entry *dst, struct sock *sk,
 					   struct sk_buff *skb, u32 mtu);
 static void		rt6_do_redirect(struct dst_entry *dst, struct sock *sk,
 					struct sk_buff *skb);
@@ -1125,7 +1125,7 @@ static void ip6_link_failure(struct sk_buff *skb)
 	}
 }
 
-static void ip6_rt_update_pmtu(struct dst_entry *dst, struct sock *sk,
+void ip6_rt_update_pmtu(struct dst_entry *dst, struct sock *sk,
 			       struct sk_buff *skb, u32 mtu)
 {
 	struct rt6_info *rt6 = (struct rt6_info*)dst;
@@ -1145,6 +1145,7 @@ static void ip6_rt_update_pmtu(struct dst_entry *dst, struct sock *sk,
 		rt6_update_expires(rt6, net->ipv6.sysctl.ip6_rt_mtu_expires);
 	}
 }
+EXPORT_SYMBOL_GPL(ip6_rt_update_pmtu);
 
 void ip6_update_pmtu(struct sk_buff *skb, struct net *net, __be32 mtu,
 		     int oif, u32 mark)
net/ipv6/xfrm6_policy.c +1 -1
index c984413..ad070c0 100644
@@ -277,7 +277,7 @@ static struct dst_ops xfrm6_dst_ops = {
 	.family =		AF_INET6,
 	.protocol =		cpu_to_be16(ETH_P_IPV6),
 	.gc =			xfrm6_garbage_collect,
-	.update_pmtu =		xfrm6_update_pmtu,
+	.update_pmtu =		ip6_rt_update_pmtu,
 	.redirect =		xfrm6_redirect,
 	.cow_metrics =		dst_cow_metrics_generic,
 	.destroy =		xfrm6_dst_destroy,
Signature · 2 lines
Jiri Bohac <[email protected]>
SUSE Labs, SUSE CZ
maintainer
#1 lore raw
Quoted 29 lines · Jiri Bohac

Hi,

there is a problem in the xfrm PMTU discovery. This happens with IPv6, I'm not sure if the same applies to IPv4:

Let's have e.g. an ESP transport-mode policy mode between two endpoints: A and B. The ESP-encapsulated packets are sent over a router R:

	A <----> R <----> B

and the R <----> B link has a small MTU of 1452.

R sends an ICMPV6_PKT_TOOBIG to A with MTU==1452.
This is what then happens on A:

icmpv6_rcv() -> icmpv6_notify() -> esp6_err() -> ip6_update_pmtu()

This looks up the non-xfrm dst entry to host B (dst_B) and decreases its MTU to 1452

Next time a large TCP segment (len=1452 bytes including TCP/IP headers in this example) from A to B is created:

tcp_sendmsg() -> ... -> inet6_csk_xmit() -> ... -> xfrm_bundle_ok()

dst->child and xdst->route now point to the dst_B with MTU==1452 xdst->route_mtu_cached and xdst->child_mtu_cached are both 1500, so the MTU of the xfrm bundle's dst (dst_B_xfrm) is decreased to xfrm_state_mtu(dst_B_xfrm, 1452)==1414.

Quoted 6 lines

When the TCP segment reaches ip6_xmit:

	skb->len > dst_mtu(dst_B_xfrm)
	1452 > 1414

This generates an ICMPV6_PKT_TOOBIG to self with MTU==1414. This is intended to reach the protocol error handler (decrease the MSS in the TCP case):

I think the above is the problem, we should not send packet to big messages to ourselves. The reduced mtu is because of some local reason (e.g. IPsec), it is not learned and therefore we should not update the pmtu value.

You could try the patch below. I'm travelling this week, so I can't do tests myself before monday.

Subject: [PATCH] ipv6: Don't send packet to big messages to self

Calling icmpv6_send() on a local message size error leads to an incorrect update of the path mtu in the case when IPsec is used. So use ipv6_local_error() instead to notify the socket about the error.

---
 net/ipv6/ip6_output.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
net/ipv6/ip6_output.c +1 -2
index 7dea45a..14fee26 100644
@@ -242,9 +242,8 @@ int ip6_xmit(struct sock *sk, struct sk_buff *skb, struct flowi6 *fl6,
 			       dst->dev, dst_output);
 	}
 
-	net_dbg_ratelimited("IPv6: sending pkt_too_big to self\n");
 	skb->dev = dst->dev;
-	icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
+	ipv6_local_error(sk, EMSGSIZE, fl6, mtu);
 	IP6_INC_STATS(net, ip6_dst_idev(skb_dst(skb)), IPSTATS_MIB_FRAGFAILS);
 	kfree_skb(skb);
 	return -EMSGSIZE;
Signature · 1 line
1.7.9.5
author
#2 lore raw
Quoted 16 lines · Steffen Klassert
Quoted 6 lines · Jiri Bohac

When the TCP segment reaches ip6_xmit:

	skb->len > dst_mtu(dst_B_xfrm)
	1452 > 1414

This generates an ICMPV6_PKT_TOOBIG to self with MTU==1414. This is intended to reach the protocol error handler (decrease the MSS in the TCP case):

I think the above is the problem, we should not send packet to big messages to ourselves. The reduced mtu is because of some local reason (e.g. IPsec), it is not learned and therefore we should not update the pmtu value.

You could try the patch below. I'm travelling this week, so I can't do tests myself before monday.

Quoted 6 lines

Subject: [PATCH] ipv6: Don't send packet to big messages to self

Calling icmpv6_send() on a local message size error leads to an incorrect update of the path mtu in the case when IPsec is used. So use ipv6_local_error() instead to notify the socket about the error.

It fixes the problem I was trying to fix.
I tested the patch with the PMTU and IPsec parts of the ipv6ready testsuite and it passed.

I wonder if this is going to do everything that should be done e.g. in the TCPv6 case. Now, tcp_v6_err() calls tcp_v6_mtu_reduced() which syncs the MSS and forces a retransmit.

Looking at the code, I don't think this is going to happen with this patch, so the MSS update and retransmit will only be done when the respective TCP timer expires.

So perhaps the individual protocols will need to handle the new error reporting?

And out of curiosity, do you know the reason why xfrm[46]_update_pmtu changes the non-xfrm route's MTU? Is this really intended?

Thanks,

Signature · 2 lines
Jiri Bohac <[email protected]>
SUSE Labs, SUSE CZ
maintainer
#3 lore raw
Quoted 17 lines · Jiri Bohac
Quoted 7 lines · Steffen Klassert

Subject: [PATCH] ipv6: Don't send packet to big messages to self

Calling icmpv6_send() on a local message size error leads to an incorrect update of the path mtu in the case when IPsec is used. So use ipv6_local_error() instead to notify the socket about the error.

It fixes the problem I was trying to fix.
I tested the patch with the PMTU and IPsec parts of the ipv6ready testsuite and it passed.

I wonder if this is going to do everything that should be done e.g. in the TCPv6 case. Now, tcp_v6_err() calls tcp_v6_mtu_reduced() which syncs the MSS and forces a retransmit.

Quoted 7 lines

Looking at the code, I don't think this is going to happen with this patch, so the MSS update and retransmit will only be done when the respective TCP timer expires.

So perhaps the individual protocols will need to handle the new error reporting?

Well, we might loose the fast path retransmit. We could think about implementing a fast path for such situations, but that's another issue. Let's fix the bug first, I'll submit the patch to fix it.

Quoted 5 lines

And out of curiosity, do you know the reason why xfrm[46]_update_pmtu changes the non-xfrm route's MTU? Is this really intended?

The pmtu is a learned measure of the route, it depends on the external environment, not on the question whether we add local overhead. So I think it was intended to change always the pmtu of the original route, even if we use IPsec.