Skip to content

Commit b96f9af

Browse files
jarodwilsondavem330
authored andcommitted
ipv4/6: use core net MTU range checking
ipv4/ip_tunnel: - min_mtu = 68, max_mtu = 0xFFF8 - dev->hard_header_len - t_hlen - preserve all ndo_change_mtu checks for now to prevent regressions ipv6/ip6_tunnel: - min_mtu = 68, max_mtu = 0xFFF8 - dev->hard_header_len - preserve all ndo_change_mtu checks for now to prevent regressions ipv6/ip6_vti: - min_mtu = 1280, max_mtu = 65535 - remove redundant vti6_change_mtu ipv6/sit: - min_mtu = 1280, max_mtu = 0xFFF8 - t_hlen - remove redundant ipip6_tunnel_change_mtu CC: [email protected] CC: "David S. Miller" <[email protected]> CC: Alexey Kuznetsov <[email protected]> CC: James Morris <[email protected]> CC: Hideaki YOSHIFUJI <[email protected]> CC: Patrick McHardy <[email protected]> Signed-off-by: Jarod Wilson <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 46b3ef4 commit b96f9af

File tree

4 files changed

+12
-33
lines changed

4 files changed

+12
-33
lines changed

net/ipv4/ip_tunnel.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ static struct ip_tunnel *ip_tunnel_create(struct net *net,
358358
{
359359
struct ip_tunnel *nt;
360360
struct net_device *dev;
361+
int t_hlen;
361362

362363
BUG_ON(!itn->fb_tunnel_dev);
363364
dev = __ip_tunnel_create(net, itn->fb_tunnel_dev->rtnl_link_ops, parms);
@@ -367,6 +368,9 @@ static struct ip_tunnel *ip_tunnel_create(struct net *net,
367368
dev->mtu = ip_tunnel_bind_dev(dev);
368369

369370
nt = netdev_priv(dev);
371+
t_hlen = nt->hlen + sizeof(struct iphdr);
372+
dev->min_mtu = ETH_MIN_MTU;
373+
dev->max_mtu = 0xFFF8 - dev->hard_header_len - t_hlen;
370374
ip_tunnel_add(itn, nt);
371375
return nt;
372376
}
@@ -929,7 +933,7 @@ int __ip_tunnel_change_mtu(struct net_device *dev, int new_mtu, bool strict)
929933
int t_hlen = tunnel->hlen + sizeof(struct iphdr);
930934
int max_mtu = 0xFFF8 - dev->hard_header_len - t_hlen;
931935

932-
if (new_mtu < 68)
936+
if (new_mtu < ETH_MIN_MTU)
933937
return -EINVAL;
934938

935939
if (new_mtu > max_mtu) {

net/ipv6/ip6_tunnel.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1634,7 +1634,7 @@ int ip6_tnl_change_mtu(struct net_device *dev, int new_mtu)
16341634
struct ip6_tnl *tnl = netdev_priv(dev);
16351635

16361636
if (tnl->parms.proto == IPPROTO_IPIP) {
1637-
if (new_mtu < 68)
1637+
if (new_mtu < ETH_MIN_MTU)
16381638
return -EINVAL;
16391639
} else {
16401640
if (new_mtu < IPV6_MIN_MTU)
@@ -1787,6 +1787,8 @@ ip6_tnl_dev_init_gen(struct net_device *dev)
17871787
dev->mtu = ETH_DATA_LEN - t_hlen;
17881788
if (!(t->parms.flags & IP6_TNL_F_IGN_ENCAP_LIMIT))
17891789
dev->mtu -= 8;
1790+
dev->min_mtu = ETH_MIN_MTU;
1791+
dev->max_mtu = 0xFFF8 - dev->hard_header_len;
17901792

17911793
return 0;
17921794

net/ipv6/ip6_vti.c

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -812,30 +812,11 @@ vti6_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
812812
return err;
813813
}
814814

815-
/**
816-
* vti6_tnl_change_mtu - change mtu manually for tunnel device
817-
* @dev: virtual device associated with tunnel
818-
* @new_mtu: the new mtu
819-
*
820-
* Return:
821-
* 0 on success,
822-
* %-EINVAL if mtu too small
823-
**/
824-
static int vti6_change_mtu(struct net_device *dev, int new_mtu)
825-
{
826-
if (new_mtu < IPV6_MIN_MTU)
827-
return -EINVAL;
828-
829-
dev->mtu = new_mtu;
830-
return 0;
831-
}
832-
833815
static const struct net_device_ops vti6_netdev_ops = {
834816
.ndo_init = vti6_dev_init,
835817
.ndo_uninit = vti6_dev_uninit,
836818
.ndo_start_xmit = vti6_tnl_xmit,
837819
.ndo_do_ioctl = vti6_ioctl,
838-
.ndo_change_mtu = vti6_change_mtu,
839820
.ndo_get_stats64 = ip_tunnel_get_stats64,
840821
.ndo_get_iflink = ip6_tnl_get_iflink,
841822
};
@@ -855,6 +836,8 @@ static void vti6_dev_setup(struct net_device *dev)
855836
dev->type = ARPHRD_TUNNEL6;
856837
dev->hard_header_len = LL_MAX_HEADER + sizeof(struct ipv6hdr);
857838
dev->mtu = ETH_DATA_LEN;
839+
dev->min_mtu = IPV6_MIN_MTU;
840+
dev->max_mtu = IP_MAX_MTU;
858841
dev->flags |= IFF_NOARP;
859842
dev->addr_len = sizeof(struct in6_addr);
860843
netif_keep_dst(dev);

net/ipv6/sit.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,23 +1318,11 @@ ipip6_tunnel_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
13181318
return err;
13191319
}
13201320

1321-
static int ipip6_tunnel_change_mtu(struct net_device *dev, int new_mtu)
1322-
{
1323-
struct ip_tunnel *tunnel = netdev_priv(dev);
1324-
int t_hlen = tunnel->hlen + sizeof(struct iphdr);
1325-
1326-
if (new_mtu < IPV6_MIN_MTU || new_mtu > 0xFFF8 - t_hlen)
1327-
return -EINVAL;
1328-
dev->mtu = new_mtu;
1329-
return 0;
1330-
}
1331-
13321321
static const struct net_device_ops ipip6_netdev_ops = {
13331322
.ndo_init = ipip6_tunnel_init,
13341323
.ndo_uninit = ipip6_tunnel_uninit,
13351324
.ndo_start_xmit = sit_tunnel_xmit,
13361325
.ndo_do_ioctl = ipip6_tunnel_ioctl,
1337-
.ndo_change_mtu = ipip6_tunnel_change_mtu,
13381326
.ndo_get_stats64 = ip_tunnel_get_stats64,
13391327
.ndo_get_iflink = ip_tunnel_get_iflink,
13401328
};
@@ -1365,6 +1353,8 @@ static void ipip6_tunnel_setup(struct net_device *dev)
13651353
dev->type = ARPHRD_SIT;
13661354
dev->hard_header_len = LL_MAX_HEADER + t_hlen;
13671355
dev->mtu = ETH_DATA_LEN - t_hlen;
1356+
dev->min_mtu = IPV6_MIN_MTU;
1357+
dev->max_mtu = 0xFFF8 - t_hlen;
13681358
dev->flags = IFF_NOARP;
13691359
netif_keep_dst(dev);
13701360
dev->addr_len = 4;

0 commit comments

Comments
 (0)