FAILED: patch "[PATCH] net: advertise TCP MSS from the configured MTU, not the" failed to apply to 6.12-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 6.12-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.12.y
git checkout FETCH_HEAD
git cherry-pick -x 2640e64195948a601430d230c9864f5426574cde
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026083114-maturing-resize-d958@gregkh' --subject-prefix 'PATCH 6.12.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 2640e64195948a601430d230c9864f5426574cde Mon Sep 17 00:00:00 2001
From: Jiayuan Chen <[email protected]>
Date: Sat, 15 Aug 2026 15:03:36 +0800
Subject: [PATCH] net: advertise TCP MSS from the configured MTU, not the
learned PMTU
The MSS a host puts in its SYN tells the peer how big a segment it may send us. Right now we can shrink it with a PMTU we learned on our own send path, which is the wrong direction entirely.
On asymmetric paths this bites - think DSR load balancers, where the request side goes through a smaller-MTU overlay. We learn a small PMTU going out, then advertise a small MSS, and the peer stays capped for the whole connection even though its path back to us is wide. MSS only shows up in the SYN and never grows back.
On symmetric paths we lose nothing by dropping it either: the peer runs its own PMTU discovery and usually already knows the real path MTU.
So work out the advertised MSS from the configured route or device MTU and ignore the learned PMTU. Our send side is unchanged, still clamped by tcp_current_mss(). Add ip_dst_mtu_configured()/ip6_dst_mtu_configured() and use them from the two default_advmss() paths.
include/net/ip.h +25 -0
@@ -506,6 +506,31 @@ static inline unsigned int ip_dst_mtu_maybe_forward(const struct dst_entry *dst,return res; } +/* Configured/administrative MTU of a route, for advertising the TCP MSS. +* +* Unlike ip_dst_mtu_maybe_forward(), this deliberately ignores the +* ICMP-learned path MTU (rt->rt_pmtu). The advertised MSS bounds what the +* peer may send to us and must reflect our receive capability (the device or +* route-configured MTU), not a path MTU learned on the reverse (send) +* direction, which may not apply to the peer->us path and outlives the fnhe +* for the whole connection. See RFC 2923 section 2.3 and the comment above +* tcp_advertise_mss(). +*/ +static inline unsigned int ip_dst_mtu_configured (const struct dst_entry *dst) +{ +unsigned int mtu, res; + +rcu_read_lock (); + mtu =dst_metric_raw (dst,RTAX_MTU ); +if (!mtu) + mtu =READ_ONCE (dst_dev_rcu (dst)->mtu); + mtu = min_t(unsigned int, mtu, IP_MAX_MTU); + res = mtu -lwtunnel_headroom (dst->lwtstate, mtu); +rcu_read_unlock (); + +return res; +} +static inline unsigned int ip_skb_dst_mtu (struct sock *sk,const struct sk_buff *skb) {
include/net/ip6_route.h +37 -0
@@ -387,6 +387,43 @@ static inline unsigned int ip6_dst_mtu_maybe_forward(const struct dst_entry *dstreturn mtu -lwtunnel_headroom (dst->lwtstate, mtu); } +/* Configured/administrative MTU of a route, for advertising the TCP MSS. +* +* Unlike ip6_dst_mtu_maybe_forward(), this ignores any ICMPv6-learned path +* MTU (which is kept on the RTF_CACHE exception route) and returns the MTU of +* the underlying route (fib6_pmtu) or the egress device. The advertised MSS +* bounds what the peer may send to us and must reflect our receive +* capability, not a path MTU learned on the reverse (send) direction. See +* RFC 2923 section 2.3 and the comment above tcp_advertise_mss(). +*/ +static inline unsigned int ip6_dst_mtu_configured (const struct dst_entry *dst) +{ +const struct rt6_info *rt =dst_rt6_info (dst); +const struct fib6_info *from; +struct inet6_dev *idev; +unsigned int mtu =0 ; + +rcu_read_lock (); +/* IPv6 keeps the learned PMTU and the configured MTU in the same +* RTAX_MTU slot: the learned value sits on this (possibly RTF_CACHE) +* dst, the configured one on the underlying route. Reach the latter +* via ->from (fib6_pmtu), populated by ip6_route_info_create(). +*/ + from =rcu_dereference (rt->from); +if (from) + mtu = from->fib6_pmtu; +if (!mtu) { + mtu =IPV6_MIN_MTU ; + idev =__in6_dev_get (dst_dev_rcu (dst)); +if (idev) + mtu = max_t(unsigned int, mtu, READ_ONCE(idev->cnf.mtu6)); + } +rcu_read_unlock (); + + mtu = min_t(unsigned int, mtu, IP6_MAX_MTU); +return mtu -lwtunnel_headroom (dst->lwtstate, mtu); +} +u32 ip6_mtu_from_fib6 (const struct fib6_result *res,const struct in6_addr *daddr,const struct in6_addr *saddr);
net/ipv4/route.c +2 -2
@@ -1363,8 +1363,8 @@ static unsigned int ipv4_default_advmss(const struct dst_entry *dst)rcu_read_lock (); net =dst_dev_net_rcu (dst); - advmss = max_t(unsigned int, ipv4_mtu(dst) - header_size, - net->ipv4.ip_rt_min_advmss); + advmss = max_t(unsigned int, ip_dst_mtu_configured(dst) - header_size, + net->ipv4.ip_rt_min_advmss);rcu_read_unlock ();return min (advmss,IPV4_MAX_PMTU - header_size);
net/ipv6/route.c +1 -1
@@ -3261,7 +3261,7 @@ void ip6_sk_redirect(struct sk_buff *skb, struct sock *sk)static unsigned int ip6_default_advmss (const struct dst_entry *dst) { -unsigned int mtu =dst6_mtu (dst); +unsigned int mtu =ip6_dst_mtu_configured (dst);struct net *net; mtu -=sizeof (struct ipv6hdr ) +sizeof (struct tcphdr );
Sasha Levin
maintainerPATCH 1/5 ipv6: start using dst_dev_rcu()
From: Eric Dumazet <[email protected]>
[ Upstream commit b775ecf1655cedbc465fd6699ab18a2bc4e7a352 ]
Refactor icmpv6_xrlim_allow() and ip6_dst_hoplimit() so that we acquire rcu_read_lock() a bit longer to be able to use dst_dev_rcu() instead of dst_dev().
__ip6_rt_update_pmtu() and rt6_do_redirect can directly use dst_dev_rcu() in sections already holding rcu_read_lock().
Small changes to use dst_dev_net_rcu() inip6_default_advmss(), ipv6_sock_ac_join(),ip6_mc_find_dev() and ndisc_send_skb().
Stable-dep-of: 2640e6419594 ("net: advertise TCP MSS from the configured MTU, not the learned PMTU")
--- include/net/ip6_route.h | 3 +++ net/ipv6/anycast.c | 4 +++- net/ipv6/icmp.c | 6 +++--- net/ipv6/mcast.c | 4 +++- net/ipv6/ndisc.c | 2 +- net/ipv6/output_core.c | 8 +++++--- net/ipv6/route.c | 9 ++++----- 7 files changed, 22 insertions(+), 14 deletions(-)
include/net/ip6_route.h +3 -0
@@ -266,6 +266,9 @@ static inline bool ipv6_anycast_destination(const struct dst_entry *dst,int ip6_fragment (struct net *net,struct sock *sk,struct sk_buff *skb,int (*output)(struct net *,struct sock *,struct sk_buff *)); +/* Compatibility form of the later IPv6-specific dst_mtu() wrapper. */ +#define dst6_mtu (dst) dst_mtu(dst) +static inline unsigned int ip6_skb_dst_mtu (const struct sk_buff *skb) { const struct ipv6_pinfo *np = skb->sk && !dev_recursion_level() ?
net/ipv6/anycast.c +3 -1
@@ -94,7 +94,9 @@ int ipv6_sock_ac_join(struct sock *sk, int ifindex, const struct in6_addr *addr) rt =rt6_lookup (net, addr,NULL ,0 ,NULL ,0 );if (rt) { - dev = rt->dst.dev; +rcu_read_lock (); + dev =dst_dev_rcu (&rt->dst); +rcu_read_unlock ();ip6_rt_put (rt); }else if (ishost) { err = -EADDRNOTAVAIL ;
net/ipv6/icmp.c +3 -3
@@ -209,7 +209,8 @@ static bool icmpv6_xrlim_allow(struct sock *sk, u8 type,* this lookup should be more aggressive (not longer than timeout). */ dst =ip6_route_output (net, sk, fl6); - dev =dst_dev (dst); +rcu_read_lock (); + dev =dst_dev_rcu (dst);if (dst->error) {IP6_INC_STATS (net,ip6_dst_idev (dst),IPSTATS_MIB_OUTNOROUTES );
@@ -224,11 +225,10 @@ static bool icmpv6_xrlim_allow(struct sock *sk, u8 type,if (rt->rt6i_dst.plen <128 ) tmo >>= ((128 - rt->rt6i_dst.plen)>>5 ); -rcu_read_lock (); peer =inet_getpeer_v6 (net->ipv6.peers, &fl6->daddr); res =inet_peer_xrlim_allow (peer, tmo); -rcu_read_unlock (); } +rcu_read_unlock ();if (!res)__ICMP6_INC_STATS (net,ip6_dst_idev (dst),ICMP6_MIB_RATELIMITHOST );
net/ipv6/mcast.c +3 -1
@@ -201,7 +201,9 @@ static int __ipv6_sock_mc_join(struct sock *sk, int ifindex,struct rt6_info *rt; rt =rt6_lookup (net, addr,NULL ,0 ,NULL ,0 );if (rt) { - dev = rt->dst.dev; +rcu_read_lock (); + dev =dst_dev_rcu (&rt->dst); +rcu_read_unlock ();ip6_rt_put (rt); } }else
net/ipv6/ndisc.c +1 -1
@@ -508,7 +508,7 @@ void ndisc_send_skb(struct sk_buff *skb, const struct in6_addr *daddr,ip6_nd_hdr (skb, saddr, daddr,READ_ONCE (inet6_sk (sk)->hop_limit), skb->len); - dev =dst_dev (dst); + dev =dst_dev_rcu (dst); idev =__in6_dev_get (dev);IP6_INC_STATS (net, idev,IPSTATS_MIB_OUTREQUESTS );
net/ipv6/output_core.c +5 -3
@@ -104,18 +104,20 @@ EXPORT_SYMBOL(ip6_find_1stfragopt);int ip6_dst_hoplimit (struct dst_entry *dst) {int hoplimit =dst_metric_raw (dst,RTAX_HOPLIMIT ); + +rcu_read_lock ();if (hoplimit ==0 ) { -struct net_device *dev =dst_dev (dst); +struct net_device *dev =dst_dev_rcu (dst);struct inet6_dev *idev; -rcu_read_lock (); idev =__in6_dev_get (dev);if (idev) hoplimit =READ_ONCE (idev->cnf.hop_limit);else hoplimit =READ_ONCE (dev_net (dev)->ipv6.devconf_all->hop_limit); -rcu_read_unlock (); } +rcu_read_unlock (); +return hoplimit; }EXPORT_SYMBOL (ip6_dst_hoplimit);
net/ipv6/route.c +4 -5
@@ -2949,7 +2949,7 @@ static void __ip6_rt_update_pmtu(struct dst_entry *dst, const struct sock *sk,if (res.f6i->nh) {struct fib6_nh_match_arg arg = { - .dev =dst_dev (dst), + .dev =dst_dev_rcu (dst), .gw = &rt6->rt6i_gateway, };
@@ -3244,15 +3244,14 @@ EXPORT_SYMBOL_GPL(ip6_sk_redirect);static unsigned int ip6_default_advmss (const struct dst_entry *dst) { -struct net_device *dev =dst_dev (dst); -unsigned int mtu =dst_mtu (dst); +unsigned int mtu =dst6_mtu (dst);struct net *net; mtu -=sizeof (struct ipv6hdr ) +sizeof (struct tcphdr );rcu_read_lock (); - net =dev_net_rcu (dev); + net =dst_dev_net_rcu (dst);if (mtu < net->ipv6.sysctl.ip6_rt_min_advmss) mtu = net->ipv6.sysctl.ip6_rt_min_advmss;
@@ -4266,7 +4265,7 @@ static void rt6_do_redirect(struct dst_entry *dst, struct sock *sk, struct sk_buif (res.f6i->nh) {struct fib6_nh_match_arg arg = { - .dev =dst_dev (dst), + .dev =dst_dev_rcu (dst), .gw = &rt->rt6i_gateway, };
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/5 ipv6: pass proto by value to ipv6_push_nfrag_opts() and ipv6_push_frag_opts()
From: Eric Dumazet <[email protected]>
[ Upstream commit 1bc46dd209667346c5aa56c351995e7c260696d0 ]
With CONFIG_STACKPROTECTOR_STRONG=y, it is better to avoid passing a pointer to an automatic variable.
Change these exported functions to return 'u8 proto' instead of void.
- ipv6_push_nfrag_opts()
- ipv6_push_frag_opts()
For instance, replace
ipv6_push_frag_opts(skb, opt, &proto); with: proto = ipv6_push_frag_opts(skb, opt, proto);
Note that even after this change, ip6_xmit() has to use a stack canary because of @first_hop variable.
Stable-dep-of: 2640e6419594 ("net: advertise TCP MSS from the configured MTU, not the learned PMTU")
--- include/net/ipv6.h | 10 ++++---- net/ipv6/exthdrs.c | 55 +++++++++++++++++++++++-------------------- net/ipv6/ip6_output.c | 19 ++++++++------- net/ipv6/ip6_tunnel.c | 2 +- 4 files changed, 46 insertions(+), 40 deletions(-)
include/net/ipv6.h +5 -5
@@ -1142,11 +1142,11 @@ int ip6_local_out(struct net *net, struct sock *sk, struct sk_buff *skb);* Extension header (options) processing */ -void ipv6_push_nfrag_opts (struct sk_buff *skb,struct ipv6_txoptions *opt, -u8 *proto,struct in6_addr **daddr_p, -struct in6_addr *saddr); -void ipv6_push_frag_opts (struct sk_buff *skb,struct ipv6_txoptions *opt, -u8 *proto); +u8 ipv6_push_nfrag_opts (struct sk_buff *skb,struct ipv6_txoptions *opt, +u8 proto,struct in6_addr **daddr_p, +struct in6_addr *saddr); +u8 ipv6_push_frag_opts (struct sk_buff *skb,struct ipv6_txoptions *opt, +u8 proto);int ipv6_skip_exthdr (const struct sk_buff *,int start,u8 *nexthdrp,__be16 *frag_offp);
net/ipv6/exthdrs.c +29 -26
109 lines not on this page · raw message
net/ipv6/ip6_output.c +11 -8
@@ -305,11 +305,12 @@ int ip6_xmit(const struct sock *sk, struct sk_buff *skb, struct flowi6 *fl6, seg_len += opt->opt_nflen + opt->opt_flen;if (opt->opt_flen) -ipv6_push_frag_opts (skb, opt, &proto); + proto =ipv6_push_frag_opts (skb, opt, proto);if (opt->opt_nflen) -ipv6_push_nfrag_opts (skb, opt, &proto, &first_hop, - &fl6->saddr); + proto =ipv6_push_nfrag_opts (skb, opt, proto, + &first_hop, + &fl6->saddr); }if (unlikely (seg_len >IPV6_MAXPLEN )) {
@@ -1927,11 +1928,13 @@ struct sk_buff *__ip6_make_skb(struct sock *sk,__skb_pull (skb,skb_network_header_len (skb)); final_dst = &fl6->daddr; -if (opt && opt->opt_flen) -ipv6_push_frag_opts (skb, opt, &proto); -if (opt && opt->opt_nflen) -ipv6_push_nfrag_opts (skb, opt, &proto, &final_dst, &fl6->saddr); - +if (opt) { +if (opt->opt_flen) + proto =ipv6_push_frag_opts (skb, opt, proto); +if (opt->opt_nflen) + proto =ipv6_push_nfrag_opts (skb, opt, proto, + &final_dst, &fl6->saddr); + }skb_push (skb,sizeof (struct ipv6hdr ));skb_reset_network_header (skb); hdr =ipv6_hdr (skb);
net/ipv6/ip6_tunnel.c +1 -1
@@ -1273,7 +1273,7 @@ int ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev, __u8 dsfield,if (encap_limit >=0 ) {init_tel_txopt (&opt, encap_limit); -ipv6_push_frag_opts (skb, &opt.ops, &proto); + proto =ipv6_push_frag_opts (skb, &opt.ops, proto); }skb_push (skb,sizeof (struct ipv6hdr ));
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 3/5 ipv6: add some unlikely()/likely() clauses in ip6_output.c
In reply to Sasha LevinFrom: Eric Dumazet <[email protected]>
[ Upstream commit 2855e4925416c5900a9c6cece11f4a2e56bf6e63 ]
1) daddr is unlikely a multicast in ip6_finish_output2().
2) ip6_finish_output_gso_slowpath_drop() should not be called often.
3) ip6_fragment() should not be called often.
4) opt is unlikely to be set.
5) ip6_xmit() and ip6_forward() mostly sends not too big packets.
6) Most __ip6_make_skb() calls are for UDP packets, not ICMPV6 ones.
Stable-dep-of: 2640e6419594 ("net: advertise TCP MSS from the configured MTU, not the learned PMTU")
--- net/ipv6/ip6_output.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
net/ipv6/ip6_output.c +12 -12
@@ -83,7 +83,7 @@ static int ip6_finish_output2(struct net *net, struct sock *sk, struct sk_buff * hdr =ipv6_hdr (skb); daddr = &hdr->daddr; -if (ipv6_addr_is_multicast (daddr)) { +if (unlikely (ipv6_addr_is_multicast (daddr))) { if (!(dev->flags & IFF_LOOPBACK) && sk_mc_loop(sk) && ((mroute6_is_socket(net, skb) && !(IP6CB(skb)->flags & IP6SKB_FORWARDED)) ||
@@ -187,8 +187,8 @@ ip6_finish_output_gso_slowpath_drop(struct net *net, struct sock *sk,static int ip6_finish_output_gso (struct net *net,struct sock *sk,struct sk_buff *skb,unsigned int mtu) { -if (!(IP6CB (skb)->flags &IP6SKB_FAKEJUMBO ) && - !skb_gso_validate_network_len (skb, mtu)) +if (unlikely (!(IP6CB (skb)->flags &IP6SKB_FAKEJUMBO ) && + !skb_gso_validate_network_len (skb, mtu)))return ip6_finish_output_gso_slowpath_drop (net, sk, skb, mtu);return ip6_finish_output2 (net, sk, skb);
@@ -210,8 +210,8 @@ static int __ip6_finish_output(struct net *net, struct sock *sk, struct sk_buffif (skb_is_gso (skb))return ip6_finish_output_gso (net, sk, skb, mtu); -if (skb->len > mtu || - (IP6CB (skb)->frag_max_size && skb->len >IP6CB (skb)->frag_max_size)) +if (unlikely (skb->len > mtu || + (IP6CB (skb)->frag_max_size && skb->len >IP6CB (skb)->frag_max_size)))return ip6_fragment (net, sk, skb, ip6_finish_output2);return ip6_finish_output2 (net, sk, skb);
@@ -301,7 +301,7 @@ int ip6_xmit(const struct sock *sk, struct sk_buff *skb, struct flowi6 *fl6, } } -if (opt) { +if (unlikely (opt)) { seg_len += opt->opt_nflen + opt->opt_flen;if (opt->opt_flen)
@@ -354,7 +354,7 @@ int ip6_xmit(const struct sock *sk, struct sk_buff *skb, struct flowi6 *fl6, skb->mark = mark; mtu =dst_mtu (dst); -if ((skb->len <= mtu) || skb->ignore_df ||skb_is_gso (skb)) { +if (likely ((skb->len <= mtu) || skb->ignore_df ||skb_is_gso (skb))) {IP6_INC_STATS (net, idev,IPSTATS_MIB_OUTREQUESTS );/* if egress device is enslaved to an L3 master device pass the
@@ -653,7 +653,7 @@ int ip6_forward(struct sk_buff *skb)if (mtu <IPV6_MIN_MTU ) mtu =IPV6_MIN_MTU ; -if (ip6_pkt_too_big (skb, mtu)) { +if (unlikely (ip6_pkt_too_big (skb, mtu))) {/* Again, force OUTPUT device used as source address */ skb->dev = dev;icmpv6_send (skb,ICMPV6_PKT_TOOBIG ,0 , mtu);
@@ -1365,7 +1365,7 @@ static int ip6_setup_cork(struct sock *sk, struct inet_cork_full *cork,/* * setup for corking */ -if (opt) { +if (unlikely (opt)) {if (WARN_ON (v6_cork->opt))return -EINVAL ;
@@ -1872,7 +1872,7 @@ static void ip6_cork_steal_dst(struct sk_buff *skb, struct inet_cork_full *cork)static void ip6_cork_release (struct inet_cork_full *cork,struct inet6_cork *v6_cork) { -if (v6_cork->opt) { +if (unlikely (v6_cork->opt)) {struct ipv6_txoptions *opt = v6_cork->opt;kfree (opt->dst0opt);
@@ -1928,7 +1928,7 @@ struct sk_buff *__ip6_make_skb(struct sock *sk,__skb_pull (skb,skb_network_header_len (skb)); final_dst = &fl6->daddr; -if (opt) { +if (unlikely (opt)) {if (opt->opt_flen) proto =ipv6_push_frag_opts (skb, opt, proto);if (opt->opt_nflen)
@@ -1956,7 +1956,7 @@ struct sk_buff *__ip6_make_skb(struct sock *sk,ip6_cork_steal_dst (skb, cork);IP6_INC_STATS (net, rt->rt6i_idev,IPSTATS_MIB_OUTREQUESTS ); -if (proto ==IPPROTO_ICMPV6 ) { +if (unlikely (proto ==IPPROTO_ICMPV6 )) {struct inet6_dev *idev =ip6_dst_idev (skb_dst (skb));u8 icmp6_type;
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 4/5 ipv6: use dst6_mtu() instead of dst_mtu()
In reply to Sasha LevinFrom: Eric Dumazet <[email protected]>
[ Upstream commit b40f0130a23b6bab8b359e158a40af81f11f14be ]
When we expect an IPv6 dst, use dst6_mtu() instead of dst_mtu() to save some code space.
Due to current dst6_mtu() implementation, only convert users in IPv6 stack.
Stable-dep-of: 2640e6419594 ("net: advertise TCP MSS from the configured MTU, not the learned PMTU")
--- net/ipv6/ip6_gre.c | 2 +- net/ipv6/ip6_output.c | 6 +++--- net/ipv6/ip6_tunnel.c | 4 ++-- net/ipv6/ipv6_sockglue.c | 4 ++-- net/ipv6/route.c | 8 +++++--- net/ipv6/tcp_ipv6.c | 9 +++++---- 6 files changed, 18 insertions(+), 15 deletions(-)
net/ipv6/ip6_gre.c +1 -1
@@ -1086,7 +1086,7 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,/* TooBig packet may have updated dst->dev's mtu */ if (!t->parms.collect_md && dst) { mtu =READ_ONCE (dst_dev (dst)->mtu); -if (dst_mtu (dst) > mtu) +if (dst6_mtu (dst) > mtu) dst->ops->update_pmtu (dst,NULL , skb, mtu, false); } err = ip6_tnl_xmit(skb, dev, dsfield, &fl6, encap_limit, &mtu,
net/ipv6/ip6_output.c +3 -3
@@ -353,7 +353,7 @@ int ip6_xmit(const struct sock *sk, struct sk_buff *skb, struct flowi6 *fl6, skb->priority = priority; skb->mark = mark; - mtu =dst_mtu (dst); + mtu =dst6_mtu (dst);if (likely ((skb->len <= mtu) || skb->ignore_df ||skb_is_gso (skb))) {IP6_INC_STATS (net, idev,IPSTATS_MIB_OUTREQUESTS );
@@ -1400,10 +1400,10 @@ static int ip6_setup_cork(struct sock *sk, struct inet_cork_full *cork, v6_cork->dontfrag = ipc6->dontfrag;if (rt->dst.flags &DST_XFRM_TUNNEL ) mtu =READ_ONCE (np->pmtudisc) >=IPV6_PMTUDISC_PROBE ? -READ_ONCE (rt->dst.dev->mtu) :dst_mtu (&rt->dst); +READ_ONCE (rt->dst.dev->mtu) :dst6_mtu (&rt->dst);else mtu =READ_ONCE (np->pmtudisc) >=IPV6_PMTUDISC_PROBE ? -READ_ONCE (rt->dst.dev->mtu) :dst_mtu (xfrm_dst_path (&rt->dst)); +READ_ONCE (rt->dst.dev->mtu) :dst6_mtu (xfrm_dst_path (&rt->dst)); frag_size =READ_ONCE (np->frag_size);if (frag_size && frag_size < mtu)
net/ipv6/ip6_tunnel.c +2 -2
@@ -643,7 +643,7 @@ ip4ip6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,/* change mtu on this route */ if (rel_type ==ICMP_DEST_UNREACH && rel_code ==ICMP_FRAG_NEEDED ) { -if (rel_info >dst_mtu (skb_dst (skb2))) +if (rel_info >dst6_mtu (skb_dst (skb2))) goto out;skb_dst_update_pmtu_no_confirm (skb2, rel_info);
@@ -1195,7 +1195,7 @@ int ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev, __u8 dsfield, t->parms.name); goto tx_err_dst_release; } - mtu =dst_mtu (dst) - eth_hlen - psh_hlen - t->tun_hlen; + mtu =dst6_mtu (dst) - eth_hlen - psh_hlen - t->tun_hlen;if (encap_limit >=0 ) { max_headroom +=8 ; mtu -=8 ;
net/ipv6/ipv6_sockglue.c +2 -2
@@ -1204,7 +1204,7 @@ int do_ipv6_getsockopt(struct sock *sk, int level, int optname,rcu_read_lock (); dst =__sk_dst_get (sk);if (dst) - val =dst_mtu (dst); + val =dst6_mtu (dst);rcu_read_unlock ();if (!val)return -ENOTCONN ;
@@ -1303,7 +1303,7 @@ int do_ipv6_getsockopt(struct sock *sk, int level, int optname,rcu_read_lock (); dst =__sk_dst_get (sk);if (dst) - mtuinfo.ip6m_mtu =dst_mtu (dst); + mtuinfo.ip6m_mtu =dst6_mtu (dst);rcu_read_unlock ();if (!mtuinfo.ip6m_mtu)return -ENOTCONN ;
net/ipv6/route.c +5 -3
@@ -2051,6 +2051,8 @@ static void rt6_update_exception_stamp_rt(struct rt6_info *rt)static bool rt6_mtu_change_route_allowed (struct inet6_dev *idev,struct rt6_info *rt,int mtu) { +u32 dmtu =dst6_mtu (&rt->dst); +/* If the new MTU is lower than the route PMTU, this new MTU will be the * lowest MTU in the path: always allow updating the route PMTU to * reflect PMTU decreases.
@@ -2061,10 +2063,10 @@ static bool rt6_mtu_change_route_allowed(struct inet6_dev *idev,* handle this. */ -if (dst_mtu (&rt->dst) >= mtu) +if (dmtu >= mtu)return true; -if (dst_mtu (&rt->dst) == idev->cnf.mtu6) +if (dmtu == idev->cnf.mtu6)return true;return false;
@@ -2927,7 +2929,7 @@ static void __ip6_rt_update_pmtu(struct dst_entry *dst, const struct sock *sk,if (mtu <IPV6_MIN_MTU )return ; -if (mtu >=dst_mtu (dst)) +if (mtu >=dst6_mtu (dst))return ;if (!rt6_cache_allowed_for_pmtu (rt6)) {
net/ipv6/tcp_ipv6.c +5 -4
@@ -347,7 +347,7 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr *uaddr,static void tcp_v6_mtu_reduced (struct sock *sk) {struct dst_entry *dst; -u32 mtu; +u32 mtu, dmtu;if ((1 << sk->sk_state) & (TCPF_LISTEN |TCPF_CLOSE ))return ;
@@ -364,8 +364,9 @@ static void tcp_v6_mtu_reduced(struct sock *sk)if (!dst)return ; -if (inet_csk (sk)->icsk_pmtu_cookie >dst_mtu (dst)) { -tcp_sync_mss (sk,dst_mtu (dst)); + dmtu =dst6_mtu (dst); +if (inet_csk (sk)->icsk_pmtu_cookie > dmtu) { +tcp_sync_mss (sk, dmtu);tcp_simple_retransmit (sk); } }
@@ -1500,7 +1501,7 @@ static struct sock *tcp_v6_syn_recv_sock(const struct sock *sk, struct sk_buff *tcp_ca_openreq_child (newsk, dst); -tcp_sync_mss (newsk,dst_mtu (dst)); +tcp_sync_mss (newsk,dst6_mtu (dst)); newtp->advmss =tcp_mss_clamp (tcp_sk (sk),dst_metric_advmss (dst));tcp_initialize_rcv_mss (newsk);
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 5/5 net: advertise TCP MSS from the configured MTU, not the learned PMTU
In reply to Sasha LevinFrom: Jiayuan Chen <[email protected]>
[ Upstream commit 2640e64195948a601430d230c9864f5426574cde ]
The MSS a host puts in its SYN tells the peer how big a segment it may send us. Right now we can shrink it with a PMTU we learned on our own send path, which is the wrong direction entirely.
On asymmetric paths this bites - think DSR load balancers, where the request side goes through a smaller-MTU overlay. We learn a small PMTU going out, then advertise a small MSS, and the peer stays capped for the whole connection even though its path back to us is wide. MSS only shows up in the SYN and never grows back.
On symmetric paths we lose nothing by dropping it either: the peer runs its own PMTU discovery and usually already knows the real path MTU.
So work out the advertised MSS from the configured route or device MTU and ignore the learned PMTU. Our send side is unchanged, still clamped by tcp_current_mss(). Add ip_dst_mtu_configured()/ip6_dst_mtu_configured() and use them from the two default_advmss() paths.
--- include/net/ip.h | 25 +++++++++++++++++++++++++ include/net/ip6_route.h | 37 +++++++++++++++++++++++++++++++++++++ net/ipv4/route.c | 4 ++-- net/ipv6/route.c | 2 +- 4 files changed, 65 insertions(+), 3 deletions(-)
include/net/ip.h +25 -0
@@ -508,6 +508,31 @@ static inline unsigned int ip_dst_mtu_maybe_forward(const struct dst_entry *dst,return res; } +/* Configured/administrative MTU of a route, for advertising the TCP MSS. +* +* Unlike ip_dst_mtu_maybe_forward(), this deliberately ignores the +* ICMP-learned path MTU (rt->rt_pmtu). The advertised MSS bounds what the +* peer may send to us and must reflect our receive capability (the device or +* route-configured MTU), not a path MTU learned on the reverse (send) +* direction, which may not apply to the peer->us path and outlives the fnhe +* for the whole connection. See RFC 2923 section 2.3 and the comment above +* tcp_advertise_mss(). +*/ +static inline unsigned int ip_dst_mtu_configured (const struct dst_entry *dst) +{ +unsigned int mtu, res; + +rcu_read_lock (); + mtu =dst_metric_raw (dst,RTAX_MTU ); +if (!mtu) + mtu =READ_ONCE (dst_dev_rcu (dst)->mtu); + mtu = min_t(unsigned int, mtu, IP_MAX_MTU); + res = mtu -lwtunnel_headroom (dst->lwtstate, mtu); +rcu_read_unlock (); + +return res; +} +static inline unsigned int ip_skb_dst_mtu (struct sock *sk,const struct sk_buff *skb) {
include/net/ip6_route.h +37 -0
@@ -349,6 +349,43 @@ static inline unsigned int ip6_dst_mtu_maybe_forward(const struct dst_entry *dstreturn mtu -lwtunnel_headroom (dst->lwtstate, mtu); } +/* Configured/administrative MTU of a route, for advertising the TCP MSS. +* +* Unlike ip6_dst_mtu_maybe_forward(), this ignores any ICMPv6-learned path +* MTU (which is kept on the RTF_CACHE exception route) and returns the MTU of +* the underlying route (fib6_pmtu) or the egress device. The advertised MSS +* bounds what the peer may send to us and must reflect our receive +* capability, not a path MTU learned on the reverse (send) direction. See +* RFC 2923 section 2.3 and the comment above tcp_advertise_mss(). +*/ +static inline unsigned int ip6_dst_mtu_configured (const struct dst_entry *dst) +{ +const struct rt6_info *rt =dst_rt6_info (dst); +const struct fib6_info *from; +struct inet6_dev *idev; +unsigned int mtu =0 ; + +rcu_read_lock (); +/* IPv6 keeps the learned PMTU and the configured MTU in the same +* RTAX_MTU slot: the learned value sits on this (possibly RTF_CACHE) +* dst, the configured one on the underlying route. Reach the latter +* via ->from (fib6_pmtu), populated by ip6_route_info_create(). +*/ + from =rcu_dereference (rt->from); +if (from) + mtu = from->fib6_pmtu; +if (!mtu) { + mtu =IPV6_MIN_MTU ; + idev =__in6_dev_get (dst_dev_rcu (dst)); +if (idev) + mtu = max_t(unsigned int, mtu, READ_ONCE(idev->cnf.mtu6)); + } +rcu_read_unlock (); + + mtu = min_t(unsigned int, mtu, IP6_MAX_MTU); +return mtu -lwtunnel_headroom (dst->lwtstate, mtu); +} +u32 ip6_mtu_from_fib6 (const struct fib6_result *res,const struct in6_addr *daddr,const struct in6_addr *saddr);
net/ipv4/route.c +2 -2
@@ -1356,8 +1356,8 @@ static unsigned int ipv4_default_advmss(const struct dst_entry *dst)rcu_read_lock (); net =dst_dev_net_rcu (dst); - advmss = max_t(unsigned int, ipv4_mtu(dst) - header_size, - net->ipv4.ip_rt_min_advmss); + advmss = max_t(unsigned int, ip_dst_mtu_configured(dst) - header_size, + net->ipv4.ip_rt_min_advmss);rcu_read_unlock ();return min (advmss,IPV4_MAX_PMTU - header_size);
net/ipv6/route.c +1 -1
@@ -3246,7 +3246,7 @@ EXPORT_SYMBOL_GPL(ip6_sk_redirect);static unsigned int ip6_default_advmss (const struct dst_entry *dst) { -unsigned int mtu =dst6_mtu (dst); +unsigned int mtu =ip6_dst_mtu_configured (dst);struct net *net; mtu -=sizeof (struct ipv6hdr ) +sizeof (struct tcphdr );
Signature · 1 line
2.53.0