From: David Ahern <dsahern@gmail.com>
To: Vadim Fedorenko <vfedorenko@novek.ru>,
David Ahern <dsahern@kernel.org>,
netdev@vger.kernel.org
Cc: Jakub Kicinski <kuba@kernel.org>,
Hideaki YOSHIFUJI <yoshfuji@linux-ipv6.org>,
"David S. Miller" <davem@davemloft.net>,
Pablo Neira Ayuso <pablo@netfilter.org>,
Florian Westphal <fw@strlen.de>
Subject: Re: [RFC net-next 2/2] net: ipv4: Consolidate ipv4_mtu and ip_dst_mtu_maybe_forward
Date: Wed, 30 Jun 2021 19:40:06 -0600 [thread overview]
Message-ID: <424dcef7-9d5e-ce3a-d9af-190ffca2a093@gmail.com> (raw)
In-Reply-To: <20210701011728.22626-3-vfedorenko@novek.ru>
On 6/30/21 7:17 PM, Vadim Fedorenko wrote:
> Consolidate IPv4 MTU code the same way it is done in IPv6 to have code
> aligned in both address families
>
> Signed-off-by: Vadim Fedorenko <vfedorenko@novek.ru>
> ---
> include/net/ip.h | 22 ++++++++++++++++++----
> net/ipv4/route.c | 21 +--------------------
> 2 files changed, 19 insertions(+), 24 deletions(-)
>
> diff --git a/include/net/ip.h b/include/net/ip.h
> index d9683bef8684..ed261f2a40ac 100644
> --- a/include/net/ip.h
> +++ b/include/net/ip.h
> @@ -436,18 +436,32 @@ static inline bool ip_sk_ignore_df(const struct sock *sk)
> static inline unsigned int ip_dst_mtu_maybe_forward(const struct dst_entry *dst,
> bool forwarding)
> {
> + const struct rtable *rt = (const struct rtable *)dst;
I realize this a code move from ipv4_mtu, but please use container_of
here; I have been removing the typecasts as code is changed.
> struct net *net = dev_net(dst->dev);
> unsigned int mtu;
>
> if (net->ipv4.sysctl_ip_fwd_use_pmtu ||
> ip_mtu_locked(dst) ||
> - !forwarding)
> - return dst_mtu(dst);
> + !forwarding) {
> + mtu = rt->rt_pmtu;
> + if (mtu && time_before(jiffies, rt->dst.expires))
> + goto out;
> + }
>
> /* 'forwarding = true' case should always honour route mtu */
> mtu = dst_metric_raw(dst, RTAX_MTU);
> - if (!mtu)
> - mtu = min(READ_ONCE(dst->dev->mtu), IP_MAX_MTU);
> + if (mtu)
> + goto out;
> +
> + mtu = READ_ONCE(dst->dev->mtu);
> +
> + if (unlikely(ip_mtu_locked(dst))) {
> + if (rt->rt_uses_gateway && mtu > 576)
> + mtu = 576;
> + }
> +
> +out:
> + mtu = min_t(unsigned int, mtu, IP_MAX_MTU);
>
> return mtu - lwtunnel_headroom(dst->lwtstate, mtu);
> }
> diff --git a/net/ipv4/route.c b/net/ipv4/route.c
> index 99c06944501a..04754d55b3c1 100644
> --- a/net/ipv4/route.c
> +++ b/net/ipv4/route.c
> @@ -1299,26 +1299,7 @@ static unsigned int ipv4_default_advmss(const struct dst_entry *dst)
>
> INDIRECT_CALLABLE_SCOPE unsigned int ipv4_mtu(const struct dst_entry *dst)
> {
> - const struct rtable *rt = (const struct rtable *)dst;
> - unsigned int mtu = rt->rt_pmtu;
> -
> - if (!mtu || time_after_eq(jiffies, rt->dst.expires))
> - mtu = dst_metric_raw(dst, RTAX_MTU);
> -
> - if (mtu)
> - goto out;
> -
> - mtu = READ_ONCE(dst->dev->mtu);
> -
> - if (unlikely(ip_mtu_locked(dst))) {
> - if (rt->rt_uses_gateway && mtu > 576)
> - mtu = 576;
> - }
> -
> -out:
> - mtu = min_t(unsigned int, mtu, IP_MAX_MTU);
> -
> - return mtu - lwtunnel_headroom(dst->lwtstate, mtu);
> + return ip_dst_mtu_maybe_forward(dst, false);
> }
> EXPORT_INDIRECT_CALLABLE(ipv4_mtu);
>
>
next prev parent reply other threads:[~2021-07-01 1:40 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-01 1:17 [RFC net-next 0/2] Remove duplicate code around MTU Vadim Fedorenko
2021-07-01 1:17 ` [RFC net-next 1/2] net: ipv6: introduce ip6_dst_mtu_maybe_forward Vadim Fedorenko
2021-07-01 1:17 ` [RFC net-next 2/2] net: ipv4: Consolidate ipv4_mtu and ip_dst_mtu_maybe_forward Vadim Fedorenko
2021-07-01 1:40 ` David Ahern [this message]
2021-07-01 9:14 ` Vadim Fedorenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=424dcef7-9d5e-ce3a-d9af-190ffca2a093@gmail.com \
--to=dsahern@gmail.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=fw@strlen.de \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pablo@netfilter.org \
--cc=vfedorenko@novek.ru \
--cc=yoshfuji@linux-ipv6.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.