Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2712004pxv; Sun, 11 Jul 2021 23:30:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyAsyGq0dgFHfQFPPSTeGXgKf55+NCx9Yi4D9VGm3Ga3gEDQBXuGaW/Yu5UhqAgKikujdDm X-Received: by 2002:a05:6402:d5a:: with SMTP id ec26mr15379480edb.4.1626071453318; Sun, 11 Jul 2021 23:30:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626071453; cv=none; d=google.com; s=arc-20160816; b=bAo6NbExrEZNe7FEW8BSnwzpF3DObKcd0Yu7s5JcmXAW/0oZMxhgwNhqwsSs+NRLZe +oIX8YD8WmsfdTwhos12xS9ds0y70OJNzRg7x8eMGqgS51MXBFZ1/PenPJpv5+JwxgqL 2sAYjDTc6VmWsHOCID79ERhy54Bl8XJdT0w4dCA/DpuJwpJ9gbxj6viMk4e2ZzvcAQnq /qwYsdjJJFNjx0AJWWyfJCLTVA4IgdUE9v2qAircyDDzo6XKmUwEJjbCDsdLa/Oc2cJm t3BKVc9AjF4aSqpWgQqplElgfDk42ZFb7PXSozeUS5VydeJ/aP2nfCSTHjjZUIlHTZy1 sSrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Vvkg2gs4xmbiSUzir5qo3dUeuOH6pQfjoXYayzlKkzE=; b=U6axco1lAHuLaLTonl54xIYuVwZGw3mAWBGjXtXZJMYenfg9nS9rb4oQ7+5NrBCfsO szp0GsojtW+w2q3sr44cHqffy6gZNppLJQP5NxXw/2CSQNxJ61outBibIIwcGKHoIzx7 TZbW0dj7nqg67xLKXd9VKqFhiV0UjifDi18ACOXrRYDT9wnio/XHwGgr73Ss8W0DXD3/ xiJ6fA8lJ+MidVHQ/vewDBpfVgcgwdztBl+51cGLemndfZJY1bg/M1Vu96AEAJRtdMoj Lfly5YreMF1V7JLe3SeR6okeyx2ciluV/uUwNHtzcT7U7APd582gl7CVnJ2PynHsSjJb LqNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=MiNHsJda; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id jz3si15521271ejb.9.2021.07.11.23.30.30; Sun, 11 Jul 2021 23:30:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=MiNHsJda; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236982AbhGLGcS (ORCPT + 99 others); Mon, 12 Jul 2021 02:32:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:46882 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235202AbhGLG1k (ORCPT ); Mon, 12 Jul 2021 02:27:40 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3A1D761164; Mon, 12 Jul 2021 06:24:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626071048; bh=QLXHfgOV7qA2SeLRwkpIPdFum1k9PZZuDuX/jrTv4N4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MiNHsJdaGu5YnaRc+eD8ZwRwMaJXghttR6c1ZrG+c1J/WjSOV4sJEKj8QpMp4c2MU Nn4zk2jZMiaDacy8m2ImbBdq7iG4FfFu5l4c+R1lvRk94ubMeQ1jpCtkzfM2KLWkqi F/qaskzWoNPXA5FvMN2G0mI5gDEo8/OWrnuLLNRg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, David Ahern , Vadim Fedorenko , David Ahern , "David S. Miller" , Sasha Levin Subject: [PATCH 5.4 250/348] net: lwtunnel: handle MTU calculation in forwading Date: Mon, 12 Jul 2021 08:10:34 +0200 Message-Id: <20210712060735.863063128@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210712060659.886176320@linuxfoundation.org> References: <20210712060659.886176320@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vadim Fedorenko [ Upstream commit fade56410c22cacafb1be9f911a0afd3701d8366 ] Commit 14972cbd34ff ("net: lwtunnel: Handle fragmentation") moved fragmentation logic away from lwtunnel by carry encap headroom and use it in output MTU calculation. But the forwarding part was not covered and created difference in MTU for output and forwarding and further to silent drops on ipv4 forwarding path. Fix it by taking into account lwtunnel encap headroom. The same commit also introduced difference in how to treat RTAX_MTU in IPv4 and IPv6 where latter explicitly removes lwtunnel encap headroom from route MTU. Make IPv4 version do the same. Fixes: 14972cbd34ff ("net: lwtunnel: Handle fragmentation") Suggested-by: David Ahern Signed-off-by: Vadim Fedorenko Reviewed-by: David Ahern Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- include/net/ip.h | 12 ++++++++---- include/net/ip6_route.h | 16 ++++++++++++---- net/ipv4/route.c | 3 ++- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/include/net/ip.h b/include/net/ip.h index 0278d63c1527..52abfc00b5e3 100644 --- a/include/net/ip.h +++ b/include/net/ip.h @@ -30,6 +30,7 @@ #include #include #include +#include #define IPV4_MAX_PMTU 65535U /* RFC 2675, Section 5.1 */ #define IPV4_MIN_MTU 68 /* RFC 791 */ @@ -448,22 +449,25 @@ static inline unsigned int ip_dst_mtu_maybe_forward(const struct dst_entry *dst, /* 'forwarding = true' case should always honour route mtu */ mtu = dst_metric_raw(dst, RTAX_MTU); - if (mtu) - return mtu; + if (!mtu) + mtu = min(READ_ONCE(dst->dev->mtu), IP_MAX_MTU); - return min(READ_ONCE(dst->dev->mtu), IP_MAX_MTU); + return mtu - lwtunnel_headroom(dst->lwtstate, mtu); } static inline unsigned int ip_skb_dst_mtu(struct sock *sk, const struct sk_buff *skb) { + unsigned int mtu; + if (!sk || !sk_fullsock(sk) || ip_sk_use_pmtu(sk)) { bool forwarding = IPCB(skb)->flags & IPSKB_FORWARDED; return ip_dst_mtu_maybe_forward(skb_dst(skb), forwarding); } - return min(READ_ONCE(skb_dst(skb)->dev->mtu), IP_MAX_MTU); + mtu = min(READ_ONCE(skb_dst(skb)->dev->mtu), IP_MAX_MTU); + return mtu - lwtunnel_headroom(skb_dst(skb)->lwtstate, mtu); } struct dst_metrics *ip_fib_metrics_init(struct net *net, struct nlattr *fc_mx, diff --git a/include/net/ip6_route.h b/include/net/ip6_route.h index 2d0d91070268..40602def3fe7 100644 --- a/include/net/ip6_route.h +++ b/include/net/ip6_route.h @@ -263,11 +263,18 @@ int ip6_fragment(struct net *net, struct sock *sk, struct sk_buff *skb, static inline int ip6_skb_dst_mtu(struct sk_buff *skb) { + int mtu; + struct ipv6_pinfo *np = skb->sk && !dev_recursion_level() ? inet6_sk(skb->sk) : NULL; - return (np && np->pmtudisc >= IPV6_PMTUDISC_PROBE) ? - skb_dst(skb)->dev->mtu : dst_mtu(skb_dst(skb)); + if (np && np->pmtudisc >= IPV6_PMTUDISC_PROBE) { + mtu = READ_ONCE(skb_dst(skb)->dev->mtu); + mtu -= lwtunnel_headroom(skb_dst(skb)->lwtstate, mtu); + } else + mtu = dst_mtu(skb_dst(skb)); + + return mtu; } static inline bool ip6_sk_accept_pmtu(const struct sock *sk) @@ -315,7 +322,7 @@ static inline unsigned int ip6_dst_mtu_forward(const struct dst_entry *dst) if (dst_metric_locked(dst, RTAX_MTU)) { mtu = dst_metric_raw(dst, RTAX_MTU); if (mtu) - return mtu; + goto out; } mtu = IPV6_MIN_MTU; @@ -325,7 +332,8 @@ static inline unsigned int ip6_dst_mtu_forward(const struct dst_entry *dst) mtu = idev->cnf.mtu6; rcu_read_unlock(); - return mtu; +out: + return mtu - lwtunnel_headroom(dst->lwtstate, mtu); } u32 ip6_mtu_from_fib6(const struct fib6_result *res, diff --git a/net/ipv4/route.c b/net/ipv4/route.c index 3ff702380b62..0e976848d4bb 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c @@ -1321,7 +1321,7 @@ static unsigned int ipv4_mtu(const struct dst_entry *dst) mtu = dst_metric_raw(dst, RTAX_MTU); if (mtu) - return mtu; + goto out; mtu = READ_ONCE(dst->dev->mtu); @@ -1330,6 +1330,7 @@ static unsigned int ipv4_mtu(const struct dst_entry *dst) mtu = 576; } +out: mtu = min_t(unsigned int, mtu, IP_MAX_MTU); return mtu - lwtunnel_headroom(dst->lwtstate, mtu); -- 2.30.2