Skip to content

Commit ac6627a

Browse files
vvfedorenkodavem330
authored andcommitted
net: ipv4: Consolidate ipv4_mtu and ip_dst_mtu_maybe_forward
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> Reviewed-by: David Ahern <dsahern@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 427faee commit ac6627a

File tree

2 files changed

+19
-24
lines changed

2 files changed

+19
-24
lines changed

include/net/ip.h

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -436,18 +436,32 @@ static inline bool ip_sk_ignore_df(const struct sock *sk)
436436
static inline unsigned int ip_dst_mtu_maybe_forward(const struct dst_entry *dst,
437437
bool forwarding)
438438
{
439+
const struct rtable *rt = container_of(dst, struct rtable, dst);
439440
struct net *net = dev_net(dst->dev);
440441
unsigned int mtu;
441442

442443
if (net->ipv4.sysctl_ip_fwd_use_pmtu ||
443444
ip_mtu_locked(dst) ||
444-
!forwarding)
445-
return dst_mtu(dst);
445+
!forwarding) {
446+
mtu = rt->rt_pmtu;
447+
if (mtu && time_before(jiffies, rt->dst.expires))
448+
goto out;
449+
}
446450

447451
/* 'forwarding = true' case should always honour route mtu */
448452
mtu = dst_metric_raw(dst, RTAX_MTU);
449-
if (!mtu)
450-
mtu = min(READ_ONCE(dst->dev->mtu), IP_MAX_MTU);
453+
if (mtu)
454+
goto out;
455+
456+
mtu = READ_ONCE(dst->dev->mtu);
457+
458+
if (unlikely(ip_mtu_locked(dst))) {
459+
if (rt->rt_uses_gateway && mtu > 576)
460+
mtu = 576;
461+
}
462+
463+
out:
464+
mtu = min_t(unsigned int, mtu, IP_MAX_MTU);
451465

452466
return mtu - lwtunnel_headroom(dst->lwtstate, mtu);
453467
}

net/ipv4/route.c

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,26 +1299,7 @@ static unsigned int ipv4_default_advmss(const struct dst_entry *dst)
12991299

13001300
INDIRECT_CALLABLE_SCOPE unsigned int ipv4_mtu(const struct dst_entry *dst)
13011301
{
1302-
const struct rtable *rt = (const struct rtable *)dst;
1303-
unsigned int mtu = rt->rt_pmtu;
1304-
1305-
if (!mtu || time_after_eq(jiffies, rt->dst.expires))
1306-
mtu = dst_metric_raw(dst, RTAX_MTU);
1307-
1308-
if (mtu)
1309-
goto out;
1310-
1311-
mtu = READ_ONCE(dst->dev->mtu);
1312-
1313-
if (unlikely(ip_mtu_locked(dst))) {
1314-
if (rt->rt_uses_gateway && mtu > 576)
1315-
mtu = 576;
1316-
}
1317-
1318-
out:
1319-
mtu = min_t(unsigned int, mtu, IP_MAX_MTU);
1320-
1321-
return mtu - lwtunnel_headroom(dst->lwtstate, mtu);
1302+
return ip_dst_mtu_maybe_forward(dst, false);
13221303
}
13231304
EXPORT_INDIRECT_CALLABLE(ipv4_mtu);
13241305

0 commit comments

Comments
 (0)