Skip to contentSkip to conversation

ipv6: Fix the pmtu path for connected UDP socket

PATCH In review Wei Wang 4 participants 5 messages Mar 2, 2016 – Mar 7, 2016

Subsystems (4)
lore
Share & tools
lore

Wei Wang

author
#0 lore raw

PATCH 1/1 ipv6: Fix the pmtu path for connected UDP socket

From: Wei Wang <[email protected]>

When ICMPV6_PKT_TOOBIG message is received by a connected UDP socket, the new mtu value is not properly updated in the dst_entry associated with the socket.
This leads to the issue that the mtu value returned by getsockopt(sockfd, IPPROTO_IPV6, IPV6_MTU, ...) is wrong.
The fix is to call the corresponding pmtu related function for connected socket so that the dst_entry associated with the socket will get updated with the new mtu value.
And before we call the above function to update mtu, we check to make sure the source IP address, destination IP address, source port and destination port are matching between the incoming flow and the socket.

---
 net/ipv6/udp.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
net/ipv6/udp.c +11 -1
index 0711f8f..5e6ba54 100644
@@ -49,6 +49,7 @@
 #include <net/inet6_hashtables.h>
 #include <net/busy_poll.h>
 #include <net/sock_reuseport.h>
+#include <net/inet6_connection_sock.h>
 
 #include <linux/proc_fs.h>
 #include <linux/seq_file.h>
@@ -566,7 +567,16 @@ void __udp6_lib_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
 	if (type == ICMPV6_PKT_TOOBIG) {
 		if (!ip6_sk_accept_pmtu(sk))
 			goto out;
-		ip6_sk_update_pmtu(skb, sk, info);
+		bh_lock_sock(sk);
+		if (sk->sk_state == TCP_ESTABLISHED &&
+		    !sock_owned_by_user(sk) &&
+		    ipv6_addr_equal(saddr, &sk->sk_v6_rcv_saddr) &&
+		    ipv6_addr_equal(daddr, &sk->sk_v6_daddr) &&
+		    uh->dest == sk->sk_dport)
+			inet6_csk_update_pmtu(sk, ntohl(info));
+		else
+			ip6_sk_update_pmtu(skb, sk, info);
+		bh_unlock_sock(sk);
 		if (np->pmtudisc != IPV6_PMTUDISC_DONT)
 			harderr = 1;
 	}
Signature · 1 line
2.7.0.rc3.207.g0ac5344
maintainer
#1 lore raw

From: Wei Wang <[email protected]>
Date: Wed, 2 Mar 2016 11:19:21 -0800

net/ipv6/udp.c void __udp6_lib_err(struct sk_buff *skb, struct inet6_skb_parm *opt, · line 576

Quoted 12 lines
net/ipv6/udp.c +7 -1
@@ -566,7 +567,16 @@ void __udp6_lib_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
 	if (type == ICMPV6_PKT_TOOBIG) {
 		if (!ip6_sk_accept_pmtu(sk))
 			goto out;
-		ip6_sk_update_pmtu(skb, sk, info);
+		bh_lock_sock(sk);
+		if (sk->sk_state == TCP_ESTABLISHED &&
+		    !sock_owned_by_user(sk) &&
+		    ipv6_addr_equal(saddr, &sk->sk_v6_rcv_saddr) &&
+		    ipv6_addr_equal(daddr, &sk->sk_v6_daddr) &&
+		    uh->dest == sk->sk_dport)
+			inet6_csk_update_pmtu(sk, ntohl(info));

If I apply this patch it will hide a bug.

Why isn't ip6_sk_update_pmtu() matching the same route as the one attached to the socket?

I'd prefer you figure out what part of the lookup key used is wrong, and fix that instead.

Thanks.

#2 lore raw
Quoted 18 lines · David Miller

From: Wei Wang <[email protected]>
Date: Wed, 2 Mar 2016 11:19:21 -0800

net/ipv6/udp.c void __udp6_lib_err(struct sk_buff *skb, struct inet6_skb_parm *opt, · line 576

Quoted 12 lines
net/ipv6/udp.c +7 -1
@@ -566,7 +567,16 @@ void __udp6_lib_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
      if (type == ICMPV6_PKT_TOOBIG) {
              if (!ip6_sk_accept_pmtu(sk))
                      goto out;
-             ip6_sk_update_pmtu(skb, sk, info);
+             bh_lock_sock(sk);
+             if (sk->sk_state == TCP_ESTABLISHED &&
+                 !sock_owned_by_user(sk) &&
+                 ipv6_addr_equal(saddr, &sk->sk_v6_rcv_saddr) &&
+                 ipv6_addr_equal(daddr, &sk->sk_v6_daddr) &&
+                 uh->dest == sk->sk_dport)
+                     inet6_csk_update_pmtu(sk, ntohl(info));

If I apply this patch it will hide a bug.

Quoted 6 lines

Why isn't ip6_sk_update_pmtu() matching the same route as the one attached to the socket?

I'd prefer you figure out what part of the lookup key used is wrong, and fix that instead.

The dst itself is the same than the socket sk_dst_cache, but __ip6_rt_update_pmtu() sees rt6_cache_allowed_for_pmtu()

We endup doing :

                nrt6 = ip6_rt_cache_alloc(rt6, daddr, saddr);
                if (nrt6) {
                        rt6_do_update_pmtu(nrt6, mtu);

                        /* ip6_ins_rt(nrt6) will bump the
                         * rt6->rt6i_node->fn_sernum
                         * which will fail the next rt6_check() and
                         * invalidate the sk->sk_dst_cache.
                         */
                        ip6_ins_rt(nrt6);
                }

But apparently the sk->sk_dst_cache is _not_ invalidated, even if the comment loudly claims so.

#3 lore raw
Quoted 44 lines · Eric Dumazet
Quoted 18 lines · David Miller

From: Wei Wang <[email protected]>
Date: Wed, 2 Mar 2016 11:19:21 -0800

Review void __udp6_lib_err(struct sk_buff *skb, struct inet6_skb_parm *opt, · line 576

Quoted 12 lines
(quoted diff) +7 -1
@@ -566,7 +567,16 @@ void __udp6_lib_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
      if (type == ICMPV6_PKT_TOOBIG) {
              if (!ip6_sk_accept_pmtu(sk))
                      goto out;
-             ip6_sk_update_pmtu(skb, sk, info);
+             bh_lock_sock(sk);
+             if (sk->sk_state == TCP_ESTABLISHED &&
+                 !sock_owned_by_user(sk) &&
+                 ipv6_addr_equal(saddr, &sk->sk_v6_rcv_saddr) &&
+                 ipv6_addr_equal(daddr, &sk->sk_v6_daddr) &&
+                 uh->dest == sk->sk_dport)
+                     inet6_csk_update_pmtu(sk, ntohl(info));

If I apply this patch it will hide a bug.

Quoted 6 lines

Why isn't ip6_sk_update_pmtu() matching the same route as the one attached to the socket?

I'd prefer you figure out what part of the lookup key used is wrong, and fix that instead.

The dst itself is the same than the socket sk_dst_cache, but __ip6_rt_update_pmtu() sees rt6_cache_allowed_for_pmtu()

We endup doing :

                nrt6 = ip6_rt_cache_alloc(rt6, daddr, saddr);
                if (nrt6) {
                        rt6_do_update_pmtu(nrt6, mtu);

                        /* ip6_ins_rt(nrt6) will bump the
                         * rt6->rt6i_node->fn_sernum
                         * which will fail the next rt6_check() and
                         * invalidate the sk->sk_dst_cache.
                         */
                        ip6_ins_rt(nrt6);
                }
Quoted 2 lines

But apparently the sk->sk_dst_cache is _not_ invalidated, even if the comment loudly claims so.

Wei and Martin, what do you think of :

net/ipv6/route.c +0 -0
index ed446639219c..17e5db80be62 100644
@@ -1342,7 +1342,7 @@ static void rt6_do_update_pmtu(struct rt6_info

*rt, u32 mtu)

static bool rt6_cache_allowed_for_pmtu(const struct rt6_info *rt) {
- return !(rt->rt6i_flags & RTF_CACHE) &&
+ return (rt->rt6i_flags & RTF_CACHE) &&

                (rt->rt6i_flags & RTF_PCPU || rt->rt6i_node);

}

@@ -1359,7 +1359,7 @@ static void __ip6_rt_update_pmtu(struct dst_entry *dst, const struct sock *sk,

        if (mtu >= dst_mtu(dst))
                return;

- if (!rt6_cache_allowed_for_pmtu(rt6)) {

+       if (rt6_cache_allowed_for_pmtu(rt6)) {
                rt6_do_update_pmtu(rt6, mtu);
        } else {
                const struct in6_addr *daddr, *saddr;
#4 lore raw
In reply to Wei Wang
Quoted 10 lines · Wei Wang

From: Wei Wang <[email protected]>

When ICMPV6_PKT_TOOBIG message is received by a connected UDP socket, the new mtu value is not properly updated in the dst_entry associated with the socket.
This leads to the issue that the mtu value returned by getsockopt(sockfd, IPPROTO_IPV6, IPV6_MTU, ...) is wrong.
The fix is to call the corresponding pmtu related function for connected socket so that the dst_entry associated with the socket will get updated with the new mtu value.

Would it be a better fix if ip6_sk_update_pmtu() does a dst_check() and updates sk->sk_dst_cache (if needed) before it returns? It seems ipv4_sk_update_pmtu() is also doing it.

or

sk->sk_dst_cache is still valid after ip6_sk_update_pmtu() returns?