net: fix IFLA_MTU ignored on NEWLINK for some ip and ipv6 tunnels
Subsystems (3)
cover net: fix IFLA_MTU ignored on NEWLINK for some ip and ipv6 tunnels
The fix for ip_gre follows the way other ip tunnels do: not to set mtu in ndo_init, as ip_tunnel_newlink will take care of it properly.
The fix for ip6_tunnel and sit follows the way ipv6 tunenls do:
to set mtu again according to IFLA_MTU after, as all bind_dev are called in ndo_init where it can't get the tb[IFLA_MTU].
Xin Long (3):
ip_gre: fix IFLA_MTU ignored on NEWLINK
ip6_tunnel: fix IFLA_MTU ignored on NEWLINK
sit: fix IFLA_MTU ignored on NEWLINK
net/ipv4/ip_gre.c | 5 ----- net/ipv6/ip6_tunnel.c | 12 ++++++++---- net/ipv6/sit.c | 7 +++++++ 3 files changed, 15 insertions(+), 9 deletions(-)
Signature · 1 line
2.1.0
PATCH 1/3 ip_gre: fix IFLA_MTU ignored on NEWLINK
It's safe to remove the setting of dev's needed_headroom and mtu in __gre_tunnel_init, as discussed in [1], ip_tunnel_newlink can do it properly.
Now Eric noticed that it could cover the mtu value set in do_setlink when creating a ip_gre dev. It makes IFLA_MTU param not take effect.
So this patch is to remove them to make IFLA_MTU work, as in other ipv4 tunnels.
[1]: https://patchwork.ozlabs.org/patch/823504/
--- net/ipv4/ip_gre.c | 5 ----- 1 file changed, 5 deletions(-)
net/ipv4/ip_gre.c +0 -5
@@ -970,9 +970,6 @@ static void __gre_tunnel_init(struct net_device *dev) t_hlen = tunnel->hlen +sizeof (struct iphdr ); - dev->needed_headroom =LL_MAX_HEADER + t_hlen +4 ; - dev->mtu =ETH_DATA_LEN - t_hlen -4 ; - dev->features |=GRE_FEATURES ; dev->hw_features |=GRE_FEATURES ;
@@ -1290,8 +1287,6 @@ static int erspan_tunnel_init(struct net_device *dev)erspan_hdr_len (tunnel->erspan_ver); t_hlen = tunnel->hlen +sizeof (struct iphdr ); - dev->needed_headroom =LL_MAX_HEADER + t_hlen +4 ; - dev->mtu =ETH_DATA_LEN - t_hlen -4 ; dev->features |=GRE_FEATURES ; dev->hw_features |=GRE_FEATURES ; dev->priv_flags |=IFF_LIVE_ADDR_CHANGE ;
Signature · 1 line
2.1.0
PATCH 2/3 ip6_tunnel: fix IFLA_MTU ignored on NEWLINK
Commit 128bb975dc3c ("ip6_gre: init dev->mtu and dev->hard_header_len correctly") fixed IFLA_MTU ignored on NEWLINK for ip6_gre. The same mtu fix is also needed for ip6_tunnel.
Note that dev->hard_header_len setting for ip6_tunnel works fine, no need to fix it.
--- net/ipv6/ip6_tunnel.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
net/ipv6/ip6_tunnel.c +8 -4
@@ -1982,14 +1982,14 @@ static int ip6_tnl_newlink(struct net *src_net, struct net_device *dev, {struct net *net =dev_net (dev);struct ip6_tnl_net *ip6n =net_generic (net, ip6_tnl_net_id); -struct ip6_tnl *nt, *t;struct ip_tunnel_encap ipencap; +struct ip6_tnl *nt, *t; +int err; nt =netdev_priv (dev);if (ip6_tnl_netlink_encap_parms (data, &ipencap)) { -int err =ip6_tnl_encap_setup (nt, &ipencap); - + err =ip6_tnl_encap_setup (nt, &ipencap);if (err <0 )return err; }
@@ -2005,7 +2005,11 @@ static int ip6_tnl_newlink(struct net *src_net, struct net_device *dev,return -EEXIST ; } -return ip6_tnl_create2 (dev); + err =ip6_tnl_create2 (dev); +if (!err && tb[IFLA_MTU ]) +ip6_tnl_change_mtu (dev,nla_get_u32 (tb[IFLA_MTU ])); + +return err; } static int ip6_tnl_changelink(struct net_device *dev, struct nlattr *tb[],
Signature · 1 line
2.1.0
PATCH 3/3 sit: fix IFLA_MTU ignored on NEWLINK
Commit 128bb975dc3c ("ip6_gre: init dev->mtu and dev->hard_header_len correctly") fixed IFLA_MTU ignored on NEWLINK for ip6_gre. The same mtu fix is also needed for sit.
Note that dev->hard_header_len setting for sit works fine, no need to fix it. sit is actually ipv4 tunnel, it can't call ip6_tnl_change_mtu to set mtu.
--- net/ipv6/sit.c | 7 +++++++ 1 file changed, 7 insertions(+)
net/ipv6/sit.c +7 -0
@@ -1578,6 +1578,13 @@ static int ipip6_newlink(struct net *src_net, struct net_device *dev,if (err <0 )return err; +if (tb[IFLA_MTU ]) { +u32 mtu =nla_get_u32 (tb[IFLA_MTU ]); + +if (mtu >=IPV6_MIN_MTU && mtu <=0xFFF8 - dev->hard_header_len) + dev->mtu = mtu; + } +#ifdef CONFIG_IPV6_SIT_6RD if (ipip6_netlink_6rd_parms (data, &ip6rd)) err =ipip6_tunnel_update_6rd (nt, &ip6rd);
Signature · 1 line
2.1.0
David Miller
maintainerFrom: Xin Long <[email protected]>
Date: Tue, 27 Feb 2018 19:19:38 +0800
Quoted 7 lines
The fix for
ip_grefollows the way other ip tunnels do: not to set mtu inndo_init, asip_tunnel_newlinkwill take care of it properly.The fix for
ip6_tunneland sit follows the way ipv6 tunenls do:
to set mtu again according toIFLA_MTUafter, as allbind_devare called inndo_initwhere it can't get the tb[IFLA_MTU].
Series applied, thanks.