5046e8a
From 731abb9cb27aef6013ce60808a04e04a545f3f4e Mon Sep 17 00:00:00 2001
5046e8a
From: Josh Boyer <jwboyer@redhat.com>
5046e8a
Date: Thu, 10 Nov 2011 15:10:23 +0000
5046e8a
Subject: [PATCH] ip6_tunnel: copy parms.name after register_netdevice
5046e8a
5046e8a
Commit 1c5cae815d removed an explicit call to dev_alloc_name in ip6_tnl_create
5046e8a
because register_netdevice will now create a valid name.  This works for the
5046e8a
net_device itself.
5046e8a
5046e8a
However the tunnel keeps a copy of the name in the parms structure for the
5046e8a
ip6_tnl associated with the tunnel.  parms.name is set by copying the net_device
5046e8a
name in ip6_tnl_dev_init_gen.  That function is called from ip6_tnl_dev_init in
5046e8a
ip6_tnl_create, but it is done before register_netdevice is called so the name
5046e8a
is set to a bogus value in the parms.name structure.
5046e8a
5046e8a
This shows up if you do a simple tunnel add, followed by a tunnel show:
5046e8a
5046e8a
[root@localhost ~]# ip -6 tunnel add remote fec0::100 local fec0::200
5046e8a
[root@localhost ~]# ip -6 tunnel show
5046e8a
ip6tnl0: ipv6/ipv6 remote :: local :: encaplimit 0 hoplimit 0 tclass 0x00 flowlabel 0x00000 (flowinfo 0x00000000)
5046e8a
ip6tnl%d: ipv6/ipv6 remote fec0::100 local fec0::200 encaplimit 4 hoplimit 64 tclass 0x00 flowlabel 0x00000 (flowinfo 0x00000000)
5046e8a
[root@localhost ~]#
5046e8a
5046e8a
Fix this by moving the strcpy out of ip6_tnl_dev_init_gen, and calling it after
5046e8a
register_netdevice has successfully returned.
5046e8a
5046e8a
Cc: stable@vger.kernel.org
5046e8a
Signed-off-by: Josh Boyer <jwboyer@redhat.com>
5046e8a
Signed-off-by: David S. Miller <davem@davemloft.net>
5046e8a
---
5046e8a
 net/ipv6/ip6_tunnel.c |    8 +++++++-
5046e8a
 1 files changed, 7 insertions(+), 1 deletions(-)
5046e8a
5046e8a
diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
5046e8a
index bdc15c9..4e2e9ff 100644
5046e8a
--- a/net/ipv6/ip6_tunnel.c
5046e8a
+++ b/net/ipv6/ip6_tunnel.c
5046e8a
@@ -289,6 +289,8 @@ static struct ip6_tnl *ip6_tnl_create(struct net *net, struct ip6_tnl_parm *p)
5046e8a
 	if ((err = register_netdevice(dev)) < 0)
5046e8a
 		goto failed_free;
5046e8a
 
5046e8a
+	strcpy(t->parms.name, dev->name);
5046e8a
+
5046e8a
 	dev_hold(dev);
5046e8a
 	ip6_tnl_link(ip6n, t);
5046e8a
 	return t;
5046e8a
@@ -1407,7 +1409,6 @@ ip6_tnl_dev_init_gen(struct net_device *dev)
5046e8a
 	struct ip6_tnl *t = netdev_priv(dev);
5046e8a
 
5046e8a
 	t->dev = dev;
5046e8a
-	strcpy(t->parms.name, dev->name);
5046e8a
 	dev->tstats = alloc_percpu(struct pcpu_tstats);
5046e8a
 	if (!dev->tstats)
5046e8a
 		return -ENOMEM;
5046e8a
@@ -1487,6 +1488,7 @@ static void __net_exit ip6_tnl_destroy_tunnels(struct ip6_tnl_net *ip6n)
5046e8a
 static int __net_init ip6_tnl_init_net(struct net *net)
5046e8a
 {
5046e8a
 	struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id);
5046e8a
+	struct ip6_tnl *t = NULL;
5046e8a
 	int err;
5046e8a
 
5046e8a
 	ip6n->tnls[0] = ip6n->tnls_wc;
5046e8a
@@ -1507,6 +1509,10 @@ static int __net_init ip6_tnl_init_net(struct net *net)
5046e8a
 	err = register_netdev(ip6n->fb_tnl_dev);
5046e8a
 	if (err < 0)
5046e8a
 		goto err_register;
5046e8a
+
5046e8a
+	t = netdev_priv(ip6n->fb_tnl_dev);
5046e8a
+
5046e8a
+	strcpy(t->parms.name, ip6n->fb_tnl_dev->name);
5046e8a
 	return 0;
5046e8a
 
5046e8a
 err_register:
5046e8a
-- 
5046e8a
1.7.6.2
5046e8a