aboutsummaryrefslogtreecommitdiffstats
path: root/net/core/dev.c
diff options
context:
space:
mode:
authorDavid Woodhouse <dwmw2@infradead.org>2006-05-15 20:19:52 -0400
committerDavid Woodhouse <dwmw2@infradead.org>2006-05-15 20:19:52 -0400
commit18594822fcb01d4b35e05b9018f770a0b4156d1a (patch)
tree38d35c38086a564beaac215f8e52694cdbfab1c3 /net/core/dev.c
parent5b5ffbc1e6d62d89747f3f59c09b2e488a7d7fce (diff)
parentc4694c76ce28dd7e415b4f3014d8c6e580b5f3d2 (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
Signed-off-by: David Woodhouse <dwmw2@infradead.org>
Diffstat (limited to 'net/core/dev.c')
-rw-r--r--net/core/dev.c99
1 files changed, 45 insertions, 54 deletions
diff --git a/net/core/dev.c b/net/core/dev.c
index 3bad1afc89fa..2dce673a039b 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -193,7 +193,7 @@ static inline struct hlist_head *dev_index_hash(int ifindex)
193 * Our notifier list 193 * Our notifier list
194 */ 194 */
195 195
196static BLOCKING_NOTIFIER_HEAD(netdev_chain); 196static RAW_NOTIFIER_HEAD(netdev_chain);
197 197
198/* 198/*
199 * Device drivers call our routines to queue packets here. We empty the 199 * Device drivers call our routines to queue packets here. We empty the
@@ -736,7 +736,7 @@ int dev_change_name(struct net_device *dev, char *newname)
736 if (!err) { 736 if (!err) {
737 hlist_del(&dev->name_hlist); 737 hlist_del(&dev->name_hlist);
738 hlist_add_head(&dev->name_hlist, dev_name_hash(dev->name)); 738 hlist_add_head(&dev->name_hlist, dev_name_hash(dev->name));
739 blocking_notifier_call_chain(&netdev_chain, 739 raw_notifier_call_chain(&netdev_chain,
740 NETDEV_CHANGENAME, dev); 740 NETDEV_CHANGENAME, dev);
741 } 741 }
742 742
@@ -751,7 +751,7 @@ int dev_change_name(struct net_device *dev, char *newname)
751 */ 751 */
752void netdev_features_change(struct net_device *dev) 752void netdev_features_change(struct net_device *dev)
753{ 753{
754 blocking_notifier_call_chain(&netdev_chain, NETDEV_FEAT_CHANGE, dev); 754 raw_notifier_call_chain(&netdev_chain, NETDEV_FEAT_CHANGE, dev);
755} 755}
756EXPORT_SYMBOL(netdev_features_change); 756EXPORT_SYMBOL(netdev_features_change);
757 757
@@ -766,7 +766,7 @@ EXPORT_SYMBOL(netdev_features_change);
766void netdev_state_change(struct net_device *dev) 766void netdev_state_change(struct net_device *dev)
767{ 767{
768 if (dev->flags & IFF_UP) { 768 if (dev->flags & IFF_UP) {
769 blocking_notifier_call_chain(&netdev_chain, 769 raw_notifier_call_chain(&netdev_chain,
770 NETDEV_CHANGE, dev); 770 NETDEV_CHANGE, dev);
771 rtmsg_ifinfo(RTM_NEWLINK, dev, 0); 771 rtmsg_ifinfo(RTM_NEWLINK, dev, 0);
772 } 772 }
@@ -864,7 +864,7 @@ int dev_open(struct net_device *dev)
864 /* 864 /*
865 * ... and announce new interface. 865 * ... and announce new interface.
866 */ 866 */
867 blocking_notifier_call_chain(&netdev_chain, NETDEV_UP, dev); 867 raw_notifier_call_chain(&netdev_chain, NETDEV_UP, dev);
868 } 868 }
869 return ret; 869 return ret;
870} 870}
@@ -887,7 +887,7 @@ int dev_close(struct net_device *dev)
887 * Tell people we are going down, so that they can 887 * Tell people we are going down, so that they can
888 * prepare to death, when device is still operating. 888 * prepare to death, when device is still operating.
889 */ 889 */
890 blocking_notifier_call_chain(&netdev_chain, NETDEV_GOING_DOWN, dev); 890 raw_notifier_call_chain(&netdev_chain, NETDEV_GOING_DOWN, dev);
891 891
892 dev_deactivate(dev); 892 dev_deactivate(dev);
893 893
@@ -924,7 +924,7 @@ int dev_close(struct net_device *dev)
924 /* 924 /*
925 * Tell people we are down 925 * Tell people we are down
926 */ 926 */
927 blocking_notifier_call_chain(&netdev_chain, NETDEV_DOWN, dev); 927 raw_notifier_call_chain(&netdev_chain, NETDEV_DOWN, dev);
928 928
929 return 0; 929 return 0;
930} 930}
@@ -955,7 +955,7 @@ int register_netdevice_notifier(struct notifier_block *nb)
955 int err; 955 int err;
956 956
957 rtnl_lock(); 957 rtnl_lock();
958 err = blocking_notifier_chain_register(&netdev_chain, nb); 958 err = raw_notifier_chain_register(&netdev_chain, nb);
959 if (!err) { 959 if (!err) {
960 for (dev = dev_base; dev; dev = dev->next) { 960 for (dev = dev_base; dev; dev = dev->next) {
961 nb->notifier_call(nb, NETDEV_REGISTER, dev); 961 nb->notifier_call(nb, NETDEV_REGISTER, dev);
@@ -983,7 +983,7 @@ int unregister_netdevice_notifier(struct notifier_block *nb)
983 int err; 983 int err;
984 984
985 rtnl_lock(); 985 rtnl_lock();
986 err = blocking_notifier_chain_unregister(&netdev_chain, nb); 986 err = raw_notifier_chain_unregister(&netdev_chain, nb);
987 rtnl_unlock(); 987 rtnl_unlock();
988 return err; 988 return err;
989} 989}
@@ -994,12 +994,12 @@ int unregister_netdevice_notifier(struct notifier_block *nb)
994 * @v: pointer passed unmodified to notifier function 994 * @v: pointer passed unmodified to notifier function
995 * 995 *
996 * Call all network notifier blocks. Parameters and return value 996 * Call all network notifier blocks. Parameters and return value
997 * are as for blocking_notifier_call_chain(). 997 * are as for raw_notifier_call_chain().
998 */ 998 */
999 999
1000int call_netdevice_notifiers(unsigned long val, void *v) 1000int call_netdevice_notifiers(unsigned long val, void *v)
1001{ 1001{
1002 return blocking_notifier_call_chain(&netdev_chain, val, v); 1002 return raw_notifier_call_chain(&netdev_chain, val, v);
1003} 1003}
1004 1004
1005/* When > 0 there are consumers of rx skb time stamps */ 1005/* When > 0 there are consumers of rx skb time stamps */
@@ -2308,7 +2308,7 @@ int dev_change_flags(struct net_device *dev, unsigned flags)
2308 if (dev->flags & IFF_UP && 2308 if (dev->flags & IFF_UP &&
2309 ((old_flags ^ dev->flags) &~ (IFF_UP | IFF_PROMISC | IFF_ALLMULTI | 2309 ((old_flags ^ dev->flags) &~ (IFF_UP | IFF_PROMISC | IFF_ALLMULTI |
2310 IFF_VOLATILE))) 2310 IFF_VOLATILE)))
2311 blocking_notifier_call_chain(&netdev_chain, 2311 raw_notifier_call_chain(&netdev_chain,
2312 NETDEV_CHANGE, dev); 2312 NETDEV_CHANGE, dev);
2313 2313
2314 if ((flags ^ dev->gflags) & IFF_PROMISC) { 2314 if ((flags ^ dev->gflags) & IFF_PROMISC) {
@@ -2353,7 +2353,7 @@ int dev_set_mtu(struct net_device *dev, int new_mtu)
2353 else 2353 else
2354 dev->mtu = new_mtu; 2354 dev->mtu = new_mtu;
2355 if (!err && dev->flags & IFF_UP) 2355 if (!err && dev->flags & IFF_UP)
2356 blocking_notifier_call_chain(&netdev_chain, 2356 raw_notifier_call_chain(&netdev_chain,
2357 NETDEV_CHANGEMTU, dev); 2357 NETDEV_CHANGEMTU, dev);
2358 return err; 2358 return err;
2359} 2359}
@@ -2370,7 +2370,7 @@ int dev_set_mac_address(struct net_device *dev, struct sockaddr *sa)
2370 return -ENODEV; 2370 return -ENODEV;
2371 err = dev->set_mac_address(dev, sa); 2371 err = dev->set_mac_address(dev, sa);
2372 if (!err) 2372 if (!err)
2373 blocking_notifier_call_chain(&netdev_chain, 2373 raw_notifier_call_chain(&netdev_chain,
2374 NETDEV_CHANGEADDR, dev); 2374 NETDEV_CHANGEADDR, dev);
2375 return err; 2375 return err;
2376} 2376}
@@ -2427,7 +2427,7 @@ static int dev_ifsioc(struct ifreq *ifr, unsigned int cmd)
2427 return -EINVAL; 2427 return -EINVAL;
2428 memcpy(dev->broadcast, ifr->ifr_hwaddr.sa_data, 2428 memcpy(dev->broadcast, ifr->ifr_hwaddr.sa_data,
2429 min(sizeof ifr->ifr_hwaddr.sa_data, (size_t) dev->addr_len)); 2429 min(sizeof ifr->ifr_hwaddr.sa_data, (size_t) dev->addr_len));
2430 blocking_notifier_call_chain(&netdev_chain, 2430 raw_notifier_call_chain(&netdev_chain,
2431 NETDEV_CHANGEADDR, dev); 2431 NETDEV_CHANGEADDR, dev);
2432 return 0; 2432 return 0;
2433 2433
@@ -2777,6 +2777,8 @@ int register_netdevice(struct net_device *dev)
2777 BUG_ON(dev_boot_phase); 2777 BUG_ON(dev_boot_phase);
2778 ASSERT_RTNL(); 2778 ASSERT_RTNL();
2779 2779
2780 might_sleep();
2781
2780 /* When net_device's are persistent, this will be fatal. */ 2782 /* When net_device's are persistent, this will be fatal. */
2781 BUG_ON(dev->reg_state != NETREG_UNINITIALIZED); 2783 BUG_ON(dev->reg_state != NETREG_UNINITIALIZED);
2782 2784
@@ -2863,6 +2865,11 @@ int register_netdevice(struct net_device *dev)
2863 if (!dev->rebuild_header) 2865 if (!dev->rebuild_header)
2864 dev->rebuild_header = default_rebuild_header; 2866 dev->rebuild_header = default_rebuild_header;
2865 2867
2868 ret = netdev_register_sysfs(dev);
2869 if (ret)
2870 goto out_err;
2871 dev->reg_state = NETREG_REGISTERED;
2872
2866 /* 2873 /*
2867 * Default initial state at registry is that the 2874 * Default initial state at registry is that the
2868 * device is present. 2875 * device is present.
@@ -2878,14 +2885,11 @@ int register_netdevice(struct net_device *dev)
2878 hlist_add_head(&dev->name_hlist, head); 2885 hlist_add_head(&dev->name_hlist, head);
2879 hlist_add_head(&dev->index_hlist, dev_index_hash(dev->ifindex)); 2886 hlist_add_head(&dev->index_hlist, dev_index_hash(dev->ifindex));
2880 dev_hold(dev); 2887 dev_hold(dev);
2881 dev->reg_state = NETREG_REGISTERING;
2882 write_unlock_bh(&dev_base_lock); 2888 write_unlock_bh(&dev_base_lock);
2883 2889
2884 /* Notify protocols, that a new device appeared. */ 2890 /* Notify protocols, that a new device appeared. */
2885 blocking_notifier_call_chain(&netdev_chain, NETDEV_REGISTER, dev); 2891 raw_notifier_call_chain(&netdev_chain, NETDEV_REGISTER, dev);
2886 2892
2887 /* Finish registration after unlock */
2888 net_set_todo(dev);
2889 ret = 0; 2893 ret = 0;
2890 2894
2891out: 2895out:
@@ -2961,7 +2965,7 @@ static void netdev_wait_allrefs(struct net_device *dev)
2961 rtnl_lock(); 2965 rtnl_lock();
2962 2966
2963 /* Rebroadcast unregister notification */ 2967 /* Rebroadcast unregister notification */
2964 blocking_notifier_call_chain(&netdev_chain, 2968 raw_notifier_call_chain(&netdev_chain,
2965 NETDEV_UNREGISTER, dev); 2969 NETDEV_UNREGISTER, dev);
2966 2970
2967 if (test_bit(__LINK_STATE_LINKWATCH_PENDING, 2971 if (test_bit(__LINK_STATE_LINKWATCH_PENDING,
@@ -3008,7 +3012,7 @@ static void netdev_wait_allrefs(struct net_device *dev)
3008 * 3012 *
3009 * We are invoked by rtnl_unlock() after it drops the semaphore. 3013 * We are invoked by rtnl_unlock() after it drops the semaphore.
3010 * This allows us to deal with problems: 3014 * This allows us to deal with problems:
3011 * 1) We can create/delete sysfs objects which invoke hotplug 3015 * 1) We can delete sysfs objects which invoke hotplug
3012 * without deadlocking with linkwatch via keventd. 3016 * without deadlocking with linkwatch via keventd.
3013 * 2) Since we run with the RTNL semaphore not held, we can sleep 3017 * 2) Since we run with the RTNL semaphore not held, we can sleep
3014 * safely in order to wait for the netdev refcnt to drop to zero. 3018 * safely in order to wait for the netdev refcnt to drop to zero.
@@ -3017,8 +3021,6 @@ static DEFINE_MUTEX(net_todo_run_mutex);
3017void netdev_run_todo(void) 3021void netdev_run_todo(void)
3018{ 3022{
3019 struct list_head list = LIST_HEAD_INIT(list); 3023 struct list_head list = LIST_HEAD_INIT(list);
3020 int err;
3021
3022 3024
3023 /* Need to guard against multiple cpu's getting out of order. */ 3025 /* Need to guard against multiple cpu's getting out of order. */
3024 mutex_lock(&net_todo_run_mutex); 3026 mutex_lock(&net_todo_run_mutex);
@@ -3041,40 +3043,29 @@ void netdev_run_todo(void)
3041 = list_entry(list.next, struct net_device, todo_list); 3043 = list_entry(list.next, struct net_device, todo_list);
3042 list_del(&dev->todo_list); 3044 list_del(&dev->todo_list);
3043 3045
3044 switch(dev->reg_state) { 3046 if (unlikely(dev->reg_state != NETREG_UNREGISTERING)) {
3045 case NETREG_REGISTERING: 3047 printk(KERN_ERR "network todo '%s' but state %d\n",
3046 dev->reg_state = NETREG_REGISTERED; 3048 dev->name, dev->reg_state);
3047 err = netdev_register_sysfs(dev); 3049 dump_stack();
3048 if (err) 3050 continue;
3049 printk(KERN_ERR "%s: failed sysfs registration (%d)\n", 3051 }
3050 dev->name, err);
3051 break;
3052
3053 case NETREG_UNREGISTERING:
3054 netdev_unregister_sysfs(dev);
3055 dev->reg_state = NETREG_UNREGISTERED;
3056
3057 netdev_wait_allrefs(dev);
3058 3052
3059 /* paranoia */ 3053 netdev_unregister_sysfs(dev);
3060 BUG_ON(atomic_read(&dev->refcnt)); 3054 dev->reg_state = NETREG_UNREGISTERED;
3061 BUG_TRAP(!dev->ip_ptr);
3062 BUG_TRAP(!dev->ip6_ptr);
3063 BUG_TRAP(!dev->dn_ptr);
3064 3055
3056 netdev_wait_allrefs(dev);
3065 3057
3066 /* It must be the very last action, 3058 /* paranoia */
3067 * after this 'dev' may point to freed up memory. 3059 BUG_ON(atomic_read(&dev->refcnt));
3068 */ 3060 BUG_TRAP(!dev->ip_ptr);
3069 if (dev->destructor) 3061 BUG_TRAP(!dev->ip6_ptr);
3070 dev->destructor(dev); 3062 BUG_TRAP(!dev->dn_ptr);
3071 break;
3072 3063
3073 default: 3064 /* It must be the very last action,
3074 printk(KERN_ERR "network todo '%s' but state %d\n", 3065 * after this 'dev' may point to freed up memory.
3075 dev->name, dev->reg_state); 3066 */
3076 break; 3067 if (dev->destructor)
3077 } 3068 dev->destructor(dev);
3078 } 3069 }
3079 3070
3080out: 3071out:
@@ -3216,7 +3207,7 @@ int unregister_netdevice(struct net_device *dev)
3216 /* Notify protocols, that we are about to destroy 3207 /* Notify protocols, that we are about to destroy
3217 this device. They should clean all the things. 3208 this device. They should clean all the things.
3218 */ 3209 */
3219 blocking_notifier_call_chain(&netdev_chain, NETDEV_UNREGISTER, dev); 3210 raw_notifier_call_chain(&netdev_chain, NETDEV_UNREGISTER, dev);
3220 3211
3221 /* 3212 /*
3222 * Flush the multicast chain 3213 * Flush the multicast chain