Skip to content

Commit

Permalink
net: ipv4: Consolidate ipv4_mtu and ip_dst_mtu_maybe_forward
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: David Ahern <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
vvfedorenko authored and davem330 committed Jul 21, 2021
1 parent 427faee commit ac6627a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 24 deletions.
22 changes: 18 additions & 4 deletions include/net/ip.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 = container_of(dst, struct rtable, dst);
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);
}
Expand Down
21 changes: 1 addition & 20 deletions net/ipv4/route.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit ac6627a

Please sign in to comment.