Commit 28e104d0 authored by Vadim Fedorenko's avatar Vadim Fedorenko Committed by Jakub Kicinski

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: fdafed45 ("ip_gre: set dev->hard_header_len and dev->needed_headroom properly")
Reported-by: default avatarSlava Bacherikov <mail@slava.cc>
Signed-off-by: default avatarVadim Fedorenko <vfedorenko@novek.ru>
Link: https://lore.kernel.org/r/1611959267-20536-1-git-send-email-vfedorenko@novek.ruSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent c518adaf
...@@ -317,7 +317,7 @@ static int ip_tunnel_bind_dev(struct net_device *dev) ...@@ -317,7 +317,7 @@ static int ip_tunnel_bind_dev(struct net_device *dev)
} }
dev->needed_headroom = t_hlen + hlen; dev->needed_headroom = t_hlen + hlen;
mtu -= (dev->hard_header_len + t_hlen); mtu -= t_hlen;
if (mtu < IPV4_MIN_MTU) if (mtu < IPV4_MIN_MTU)
mtu = IPV4_MIN_MTU; mtu = IPV4_MIN_MTU;
...@@ -347,7 +347,7 @@ static struct ip_tunnel *ip_tunnel_create(struct net *net, ...@@ -347,7 +347,7 @@ static struct ip_tunnel *ip_tunnel_create(struct net *net,
nt = netdev_priv(dev); nt = netdev_priv(dev);
t_hlen = nt->hlen + sizeof(struct iphdr); t_hlen = nt->hlen + sizeof(struct iphdr);
dev->min_mtu = ETH_MIN_MTU; dev->min_mtu = ETH_MIN_MTU;
dev->max_mtu = IP_MAX_MTU - dev->hard_header_len - t_hlen; dev->max_mtu = IP_MAX_MTU - t_hlen;
ip_tunnel_add(itn, nt); ip_tunnel_add(itn, nt);
return nt; return nt;
...@@ -488,11 +488,10 @@ static int tnl_update_pmtu(struct net_device *dev, struct sk_buff *skb, ...@@ -488,11 +488,10 @@ static int tnl_update_pmtu(struct net_device *dev, struct sk_buff *skb,
int mtu; int mtu;
tunnel_hlen = md ? tunnel_hlen : tunnel->hlen; tunnel_hlen = md ? tunnel_hlen : tunnel->hlen;
pkt_size = skb->len - tunnel_hlen - dev->hard_header_len; pkt_size = skb->len - tunnel_hlen;
if (df) if (df)
mtu = dst_mtu(&rt->dst) - dev->hard_header_len mtu = dst_mtu(&rt->dst) - (sizeof(struct iphdr) + tunnel_hlen);
- sizeof(struct iphdr) - tunnel_hlen;
else else
mtu = skb_valid_dst(skb) ? dst_mtu(skb_dst(skb)) : dev->mtu; mtu = skb_valid_dst(skb) ? dst_mtu(skb_dst(skb)) : dev->mtu;
...@@ -972,7 +971,7 @@ int __ip_tunnel_change_mtu(struct net_device *dev, int new_mtu, bool strict) ...@@ -972,7 +971,7 @@ int __ip_tunnel_change_mtu(struct net_device *dev, int new_mtu, bool strict)
{ {
struct ip_tunnel *tunnel = netdev_priv(dev); struct ip_tunnel *tunnel = netdev_priv(dev);
int t_hlen = tunnel->hlen + sizeof(struct iphdr); int t_hlen = tunnel->hlen + sizeof(struct iphdr);
int max_mtu = IP_MAX_MTU - dev->hard_header_len - t_hlen; int max_mtu = IP_MAX_MTU - t_hlen;
if (new_mtu < ETH_MIN_MTU) if (new_mtu < ETH_MIN_MTU)
return -EINVAL; return -EINVAL;
...@@ -1149,10 +1148,9 @@ int ip_tunnel_newlink(struct net_device *dev, struct nlattr *tb[], ...@@ -1149,10 +1148,9 @@ int ip_tunnel_newlink(struct net_device *dev, struct nlattr *tb[],
mtu = ip_tunnel_bind_dev(dev); mtu = ip_tunnel_bind_dev(dev);
if (tb[IFLA_MTU]) { if (tb[IFLA_MTU]) {
unsigned int max = IP_MAX_MTU - dev->hard_header_len - nt->hlen; unsigned int max = IP_MAX_MTU - (nt->hlen + sizeof(struct iphdr));
mtu = clamp(dev->mtu, (unsigned int)ETH_MIN_MTU, mtu = clamp(dev->mtu, (unsigned int)ETH_MIN_MTU, max);
(unsigned int)(max - sizeof(struct iphdr)));
} }
err = dev_set_mtu(dev, mtu); err = dev_set_mtu(dev, mtu);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment