From 30f1962cb4491cfaabcd98715535f4bd7eba4307 Mon Sep 17 00:00:00 2001 From: David L Stevens Date: Sat, 6 Jan 2007 01:06:28 +0100 Subject: [IPV4/IPV6]: Fix inet{,6} device initialization order. It is important that we only assign dev->ip{,6}_ptr only after all portions of the inet{,6} are setup. Otherwise we can receive packets before the multicast spinlocks et al. are initialized. Signed-off-by: David L Stevens Signed-off-by: David S. Miller Signed-off-by: Adrian Bunk --- net/ipv4/devinet.c | 5 +++-- net/ipv6/addrconf.c | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c index 3ffa60dadc0c..73a62007e36e 100644 --- a/net/ipv4/devinet.c +++ b/net/ipv4/devinet.c @@ -158,9 +158,8 @@ struct in_device *inetdev_init(struct net_device *dev) NET_IPV4_NEIGH, "ipv4", NULL, NULL); #endif - /* Account for reference dev->ip_ptr */ + /* Account for reference dev->ip_ptr (below) */ in_dev_hold(in_dev); - rcu_assign_pointer(dev->ip_ptr, in_dev); #ifdef CONFIG_SYSCTL devinet_sysctl_register(in_dev, &in_dev->cnf); @@ -169,6 +168,8 @@ struct in_device *inetdev_init(struct net_device *dev) if (dev->flags & IFF_UP) ip_mc_up(in_dev); out: + /* we can receive as soon as ip_ptr is set -- do this last */ + rcu_assign_pointer(dev->ip_ptr, in_dev); return in_dev; out_kfree: kfree(in_dev); diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index 77da3a81cc03..c5005b23ec05 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -393,10 +393,6 @@ static struct inet6_dev * ipv6_add_dev(struct net_device *dev) if (netif_carrier_ok(dev)) ndev->if_flags |= IF_READY; - write_lock_bh(&addrconf_lock); - dev->ip6_ptr = ndev; - write_unlock_bh(&addrconf_lock); - ipv6_mc_init_dev(ndev); ndev->tstamp = jiffies; #ifdef CONFIG_SYSCTL @@ -406,6 +402,10 @@ static struct inet6_dev * ipv6_add_dev(struct net_device *dev) NULL); addrconf_sysctl_register(ndev, &ndev->cnf); #endif + write_lock_bh(&addrconf_lock); + dev->ip6_ptr = ndev; + write_unlock_bh(&addrconf_lock); + } return ndev; } -- cgit v1.2.3