Commit 8a118015 authored by David S. Miller's avatar David S. Miller

Merge branch 'tunnel-mtus'

Nicolas Dichtel says:

====================
ip[6] tunnels: fix mtu calculations

The first patch restores the possibility to bind an ip4 tunnel to an
interface whith a large mtu.
The second patch was spotted after the first fix. I also target it to net
because it fixes the max mtu value that can be used for ipv6 tunnels.

v2: remove the 0xfff8 in ip_tunnel_newlink()
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents ccfde6e2 f7ff1fde
...@@ -328,7 +328,7 @@ static int ip_tunnel_bind_dev(struct net_device *dev) ...@@ -328,7 +328,7 @@ static int ip_tunnel_bind_dev(struct net_device *dev)
if (tdev) { if (tdev) {
hlen = tdev->hard_header_len + tdev->needed_headroom; hlen = tdev->hard_header_len + tdev->needed_headroom;
mtu = tdev->mtu; mtu = min(tdev->mtu, IP_MAX_MTU);
} }
dev->needed_headroom = t_hlen + hlen; dev->needed_headroom = t_hlen + hlen;
...@@ -362,7 +362,7 @@ static struct ip_tunnel *ip_tunnel_create(struct net *net, ...@@ -362,7 +362,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 = 0xFFF8 - dev->hard_header_len - t_hlen; dev->max_mtu = IP_MAX_MTU - dev->hard_header_len - t_hlen;
ip_tunnel_add(itn, nt); ip_tunnel_add(itn, nt);
return nt; return nt;
...@@ -930,7 +930,7 @@ int __ip_tunnel_change_mtu(struct net_device *dev, int new_mtu, bool strict) ...@@ -930,7 +930,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 = 0xFFF8 - dev->hard_header_len - t_hlen; int max_mtu = IP_MAX_MTU - dev->hard_header_len - t_hlen;
if (new_mtu < ETH_MIN_MTU) if (new_mtu < ETH_MIN_MTU)
return -EINVAL; return -EINVAL;
...@@ -1107,7 +1107,7 @@ int ip_tunnel_newlink(struct net_device *dev, struct nlattr *tb[], ...@@ -1107,7 +1107,7 @@ 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 = 0xfff8 - dev->hard_header_len - nt->hlen; unsigned int max = IP_MAX_MTU - dev->hard_header_len - nt->hlen;
mtu = clamp(dev->mtu, (unsigned int)ETH_MIN_MTU, mtu = clamp(dev->mtu, (unsigned int)ETH_MIN_MTU,
(unsigned int)(max - sizeof(struct iphdr))); (unsigned int)(max - sizeof(struct iphdr)));
......
...@@ -1692,8 +1692,13 @@ int ip6_tnl_change_mtu(struct net_device *dev, int new_mtu) ...@@ -1692,8 +1692,13 @@ int ip6_tnl_change_mtu(struct net_device *dev, int new_mtu)
if (new_mtu < ETH_MIN_MTU) if (new_mtu < ETH_MIN_MTU)
return -EINVAL; return -EINVAL;
} }
if (new_mtu > 0xFFF8 - dev->hard_header_len) if (tnl->parms.proto == IPPROTO_IPV6 || tnl->parms.proto == 0) {
return -EINVAL; if (new_mtu > IP6_MAX_MTU - dev->hard_header_len)
return -EINVAL;
} else {
if (new_mtu > IP_MAX_MTU - dev->hard_header_len)
return -EINVAL;
}
dev->mtu = new_mtu; dev->mtu = new_mtu;
return 0; return 0;
} }
...@@ -1841,7 +1846,7 @@ ip6_tnl_dev_init_gen(struct net_device *dev) ...@@ -1841,7 +1846,7 @@ ip6_tnl_dev_init_gen(struct net_device *dev)
if (!(t->parms.flags & IP6_TNL_F_IGN_ENCAP_LIMIT)) if (!(t->parms.flags & IP6_TNL_F_IGN_ENCAP_LIMIT))
dev->mtu -= 8; dev->mtu -= 8;
dev->min_mtu = ETH_MIN_MTU; dev->min_mtu = ETH_MIN_MTU;
dev->max_mtu = 0xFFF8 - dev->hard_header_len; dev->max_mtu = IP6_MAX_MTU - dev->hard_header_len;
return 0; return 0;
......
...@@ -1371,7 +1371,7 @@ static void ipip6_tunnel_setup(struct net_device *dev) ...@@ -1371,7 +1371,7 @@ static void ipip6_tunnel_setup(struct net_device *dev)
dev->hard_header_len = LL_MAX_HEADER + t_hlen; dev->hard_header_len = LL_MAX_HEADER + t_hlen;
dev->mtu = ETH_DATA_LEN - t_hlen; dev->mtu = ETH_DATA_LEN - t_hlen;
dev->min_mtu = IPV6_MIN_MTU; dev->min_mtu = IPV6_MIN_MTU;
dev->max_mtu = 0xFFF8 - t_hlen; dev->max_mtu = IP6_MAX_MTU - t_hlen;
dev->flags = IFF_NOARP; dev->flags = IFF_NOARP;
netif_keep_dst(dev); netif_keep_dst(dev);
dev->addr_len = 4; dev->addr_len = 4;
...@@ -1583,7 +1583,8 @@ static int ipip6_newlink(struct net *src_net, struct net_device *dev, ...@@ -1583,7 +1583,8 @@ static int ipip6_newlink(struct net *src_net, struct net_device *dev,
if (tb[IFLA_MTU]) { if (tb[IFLA_MTU]) {
u32 mtu = nla_get_u32(tb[IFLA_MTU]); u32 mtu = nla_get_u32(tb[IFLA_MTU]);
if (mtu >= IPV6_MIN_MTU && mtu <= 0xFFF8 - dev->hard_header_len) if (mtu >= IPV6_MIN_MTU &&
mtu <= IP6_MAX_MTU - dev->hard_header_len)
dev->mtu = mtu; dev->mtu = 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