Skip to content

Commit 28e104d

Browse files
vvfedorenkokuba-moo
authored andcommitted
net: ip_tunnel: fix mtu calculation
dev->hard_header_len for tunnel interface is set only when header_ops are set too and already contains full overhead of any tunnel encapsulation. That's why there is not need to use this overhead twice in mtu calc. Fixes: fdafed4 ("ip_gre: set dev->hard_header_len and dev->needed_headroom properly") Reported-by: Slava Bacherikov <[email protected]> Signed-off-by: Vadim Fedorenko <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent c518ada commit 28e104d

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

net/ipv4/ip_tunnel.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ static int ip_tunnel_bind_dev(struct net_device *dev)
317317
}
318318

319319
dev->needed_headroom = t_hlen + hlen;
320-
mtu -= (dev->hard_header_len + t_hlen);
320+
mtu -= t_hlen;
321321

322322
if (mtu < IPV4_MIN_MTU)
323323
mtu = IPV4_MIN_MTU;
@@ -347,7 +347,7 @@ static struct ip_tunnel *ip_tunnel_create(struct net *net,
347347
nt = netdev_priv(dev);
348348
t_hlen = nt->hlen + sizeof(struct iphdr);
349349
dev->min_mtu = ETH_MIN_MTU;
350-
dev->max_mtu = IP_MAX_MTU - dev->hard_header_len - t_hlen;
350+
dev->max_mtu = IP_MAX_MTU - t_hlen;
351351
ip_tunnel_add(itn, nt);
352352
return nt;
353353

@@ -488,11 +488,10 @@ static int tnl_update_pmtu(struct net_device *dev, struct sk_buff *skb,
488488
int mtu;
489489

490490
tunnel_hlen = md ? tunnel_hlen : tunnel->hlen;
491-
pkt_size = skb->len - tunnel_hlen - dev->hard_header_len;
491+
pkt_size = skb->len - tunnel_hlen;
492492

493493
if (df)
494-
mtu = dst_mtu(&rt->dst) - dev->hard_header_len
495-
- sizeof(struct iphdr) - tunnel_hlen;
494+
mtu = dst_mtu(&rt->dst) - (sizeof(struct iphdr) + tunnel_hlen);
496495
else
497496
mtu = skb_valid_dst(skb) ? dst_mtu(skb_dst(skb)) : dev->mtu;
498497

@@ -972,7 +971,7 @@ int __ip_tunnel_change_mtu(struct net_device *dev, int new_mtu, bool strict)
972971
{
973972
struct ip_tunnel *tunnel = netdev_priv(dev);
974973
int t_hlen = tunnel->hlen + sizeof(struct iphdr);
975-
int max_mtu = IP_MAX_MTU - dev->hard_header_len - t_hlen;
974+
int max_mtu = IP_MAX_MTU - t_hlen;
976975

977976
if (new_mtu < ETH_MIN_MTU)
978977
return -EINVAL;
@@ -1149,10 +1148,9 @@ int ip_tunnel_newlink(struct net_device *dev, struct nlattr *tb[],
11491148

11501149
mtu = ip_tunnel_bind_dev(dev);
11511150
if (tb[IFLA_MTU]) {
1152-
unsigned int max = IP_MAX_MTU - dev->hard_header_len - nt->hlen;
1151+
unsigned int max = IP_MAX_MTU - (nt->hlen + sizeof(struct iphdr));
11531152

1154-
mtu = clamp(dev->mtu, (unsigned int)ETH_MIN_MTU,
1155-
(unsigned int)(max - sizeof(struct iphdr)));
1153+
mtu = clamp(dev->mtu, (unsigned int)ETH_MIN_MTU, max);
11561154
}
11571155

11581156
err = dev_set_mtu(dev, mtu);

0 commit comments

Comments
 (0)