aboutsummaryrefslogtreecommitdiffstats
path: root/net/core/dev.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/core/dev.c')
-rw-r--r--net/core/dev.c122
1 files changed, 84 insertions, 38 deletions
diff --git a/net/core/dev.c b/net/core/dev.c
index 2afb0de95329..a3ab11f34153 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -81,6 +81,7 @@
81#include <linux/types.h> 81#include <linux/types.h>
82#include <linux/kernel.h> 82#include <linux/kernel.h>
83#include <linux/sched.h> 83#include <linux/sched.h>
84#include <linux/mutex.h>
84#include <linux/string.h> 85#include <linux/string.h>
85#include <linux/mm.h> 86#include <linux/mm.h>
86#include <linux/socket.h> 87#include <linux/socket.h>
@@ -110,11 +111,10 @@
110#include <linux/netpoll.h> 111#include <linux/netpoll.h>
111#include <linux/rcupdate.h> 112#include <linux/rcupdate.h>
112#include <linux/delay.h> 113#include <linux/delay.h>
113#ifdef CONFIG_NET_RADIO 114#include <linux/wireless.h>
114#include <linux/wireless.h> /* Note : will define WIRELESS_EXT */
115#include <net/iw_handler.h> 115#include <net/iw_handler.h>
116#endif /* CONFIG_NET_RADIO */
117#include <asm/current.h> 116#include <asm/current.h>
117#include <linux/audit.h>
118 118
119/* 119/*
120 * The list of packet types we will receive (as opposed to discard) 120 * The list of packet types we will receive (as opposed to discard)
@@ -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 struct notifier_block *netdev_chain; 196static BLOCKING_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,8 @@ 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 notifier_call_chain(&netdev_chain, NETDEV_CHANGENAME, dev); 739 blocking_notifier_call_chain(&netdev_chain,
740 NETDEV_CHANGENAME, dev);
740 } 741 }
741 742
742 return err; 743 return err;
@@ -750,7 +751,7 @@ int dev_change_name(struct net_device *dev, char *newname)
750 */ 751 */
751void netdev_features_change(struct net_device *dev) 752void netdev_features_change(struct net_device *dev)
752{ 753{
753 notifier_call_chain(&netdev_chain, NETDEV_FEAT_CHANGE, dev); 754 blocking_notifier_call_chain(&netdev_chain, NETDEV_FEAT_CHANGE, dev);
754} 755}
755EXPORT_SYMBOL(netdev_features_change); 756EXPORT_SYMBOL(netdev_features_change);
756 757
@@ -765,7 +766,8 @@ EXPORT_SYMBOL(netdev_features_change);
765void netdev_state_change(struct net_device *dev) 766void netdev_state_change(struct net_device *dev)
766{ 767{
767 if (dev->flags & IFF_UP) { 768 if (dev->flags & IFF_UP) {
768 notifier_call_chain(&netdev_chain, NETDEV_CHANGE, dev); 769 blocking_notifier_call_chain(&netdev_chain,
770 NETDEV_CHANGE, dev);
769 rtmsg_ifinfo(RTM_NEWLINK, dev, 0); 771 rtmsg_ifinfo(RTM_NEWLINK, dev, 0);
770 } 772 }
771} 773}
@@ -862,7 +864,7 @@ int dev_open(struct net_device *dev)
862 /* 864 /*
863 * ... and announce new interface. 865 * ... and announce new interface.
864 */ 866 */
865 notifier_call_chain(&netdev_chain, NETDEV_UP, dev); 867 blocking_notifier_call_chain(&netdev_chain, NETDEV_UP, dev);
866 } 868 }
867 return ret; 869 return ret;
868} 870}
@@ -885,7 +887,7 @@ int dev_close(struct net_device *dev)
885 * Tell people we are going down, so that they can 887 * Tell people we are going down, so that they can
886 * prepare to death, when device is still operating. 888 * prepare to death, when device is still operating.
887 */ 889 */
888 notifier_call_chain(&netdev_chain, NETDEV_GOING_DOWN, dev); 890 blocking_notifier_call_chain(&netdev_chain, NETDEV_GOING_DOWN, dev);
889 891
890 dev_deactivate(dev); 892 dev_deactivate(dev);
891 893
@@ -922,7 +924,7 @@ int dev_close(struct net_device *dev)
922 /* 924 /*
923 * Tell people we are down 925 * Tell people we are down
924 */ 926 */
925 notifier_call_chain(&netdev_chain, NETDEV_DOWN, dev); 927 blocking_notifier_call_chain(&netdev_chain, NETDEV_DOWN, dev);
926 928
927 return 0; 929 return 0;
928} 930}
@@ -953,7 +955,7 @@ int register_netdevice_notifier(struct notifier_block *nb)
953 int err; 955 int err;
954 956
955 rtnl_lock(); 957 rtnl_lock();
956 err = notifier_chain_register(&netdev_chain, nb); 958 err = blocking_notifier_chain_register(&netdev_chain, nb);
957 if (!err) { 959 if (!err) {
958 for (dev = dev_base; dev; dev = dev->next) { 960 for (dev = dev_base; dev; dev = dev->next) {
959 nb->notifier_call(nb, NETDEV_REGISTER, dev); 961 nb->notifier_call(nb, NETDEV_REGISTER, dev);
@@ -978,7 +980,12 @@ int register_netdevice_notifier(struct notifier_block *nb)
978 980
979int unregister_netdevice_notifier(struct notifier_block *nb) 981int unregister_netdevice_notifier(struct notifier_block *nb)
980{ 982{
981 return notifier_chain_unregister(&netdev_chain, nb); 983 int err;
984
985 rtnl_lock();
986 err = blocking_notifier_chain_unregister(&netdev_chain, nb);
987 rtnl_unlock();
988 return err;
982} 989}
983 990
984/** 991/**
@@ -987,12 +994,12 @@ int unregister_netdevice_notifier(struct notifier_block *nb)
987 * @v: pointer passed unmodified to notifier function 994 * @v: pointer passed unmodified to notifier function
988 * 995 *
989 * Call all network notifier blocks. Parameters and return value 996 * Call all network notifier blocks. Parameters and return value
990 * are as for notifier_call_chain(). 997 * are as for blocking_notifier_call_chain().
991 */ 998 */
992 999
993int call_netdevice_notifiers(unsigned long val, void *v) 1000int call_netdevice_notifiers(unsigned long val, void *v)
994{ 1001{
995 return notifier_call_chain(&netdev_chain, val, v); 1002 return blocking_notifier_call_chain(&netdev_chain, val, v);
996} 1003}
997 1004
998/* When > 0 there are consumers of rx skb time stamps */ 1005/* When > 0 there are consumers of rx skb time stamps */
@@ -1448,8 +1455,29 @@ static inline struct net_device *skb_bond(struct sk_buff *skb)
1448{ 1455{
1449 struct net_device *dev = skb->dev; 1456 struct net_device *dev = skb->dev;
1450 1457
1451 if (dev->master) 1458 if (dev->master) {
1459 /*
1460 * On bonding slaves other than the currently active
1461 * slave, suppress duplicates except for 802.3ad
1462 * ETH_P_SLOW and alb non-mcast/bcast.
1463 */
1464 if (dev->priv_flags & IFF_SLAVE_INACTIVE) {
1465 if (dev->master->priv_flags & IFF_MASTER_ALB) {
1466 if (skb->pkt_type != PACKET_BROADCAST &&
1467 skb->pkt_type != PACKET_MULTICAST)
1468 goto keep;
1469 }
1470
1471 if (dev->master->priv_flags & IFF_MASTER_8023AD &&
1472 skb->protocol == __constant_htons(ETH_P_SLOW))
1473 goto keep;
1474
1475 kfree_skb(skb);
1476 return NULL;
1477 }
1478keep:
1452 skb->dev = dev->master; 1479 skb->dev = dev->master;
1480 }
1453 1481
1454 return dev; 1482 return dev;
1455} 1483}
@@ -1593,6 +1621,9 @@ int netif_receive_skb(struct sk_buff *skb)
1593 1621
1594 orig_dev = skb_bond(skb); 1622 orig_dev = skb_bond(skb);
1595 1623
1624 if (!orig_dev)
1625 return NET_RX_DROP;
1626
1596 __get_cpu_var(netdev_rx_stat).total++; 1627 __get_cpu_var(netdev_rx_stat).total++;
1597 1628
1598 skb->h.raw = skb->nh.raw = skb->data; 1629 skb->h.raw = skb->nh.raw = skb->data;
@@ -1737,8 +1768,7 @@ static void net_rx_action(struct softirq_action *h)
1737 if (dev->quota <= 0 || dev->poll(dev, &budget)) { 1768 if (dev->quota <= 0 || dev->poll(dev, &budget)) {
1738 netpoll_poll_unlock(have); 1769 netpoll_poll_unlock(have);
1739 local_irq_disable(); 1770 local_irq_disable();
1740 list_del(&dev->poll_list); 1771 list_move_tail(&dev->poll_list, &queue->poll_list);
1741 list_add_tail(&dev->poll_list, &queue->poll_list);
1742 if (dev->quota < 0) 1772 if (dev->quota < 0)
1743 dev->quota += dev->weight; 1773 dev->quota += dev->weight;
1744 else 1774 else
@@ -2028,7 +2058,7 @@ static struct file_operations softnet_seq_fops = {
2028 .release = seq_release, 2058 .release = seq_release,
2029}; 2059};
2030 2060
2031#ifdef WIRELESS_EXT 2061#ifdef CONFIG_WIRELESS_EXT
2032extern int wireless_proc_init(void); 2062extern int wireless_proc_init(void);
2033#else 2063#else
2034#define wireless_proc_init() 0 2064#define wireless_proc_init() 0
@@ -2120,6 +2150,12 @@ void dev_set_promiscuity(struct net_device *dev, int inc)
2120 printk(KERN_INFO "device %s %s promiscuous mode\n", 2150 printk(KERN_INFO "device %s %s promiscuous mode\n",
2121 dev->name, (dev->flags & IFF_PROMISC) ? "entered" : 2151 dev->name, (dev->flags & IFF_PROMISC) ? "entered" :
2122 "left"); 2152 "left");
2153 audit_log(current->audit_context, GFP_ATOMIC,
2154 AUDIT_ANOM_PROMISCUOUS,
2155 "dev=%s prom=%d old_prom=%d auid=%u",
2156 dev->name, (dev->flags & IFF_PROMISC),
2157 (old_flags & IFF_PROMISC),
2158 audit_get_loginuid(current->audit_context));
2123 } 2159 }
2124} 2160}
2125 2161
@@ -2152,12 +2188,20 @@ unsigned dev_get_flags(const struct net_device *dev)
2152 2188
2153 flags = (dev->flags & ~(IFF_PROMISC | 2189 flags = (dev->flags & ~(IFF_PROMISC |
2154 IFF_ALLMULTI | 2190 IFF_ALLMULTI |
2155 IFF_RUNNING)) | 2191 IFF_RUNNING |
2192 IFF_LOWER_UP |
2193 IFF_DORMANT)) |
2156 (dev->gflags & (IFF_PROMISC | 2194 (dev->gflags & (IFF_PROMISC |
2157 IFF_ALLMULTI)); 2195 IFF_ALLMULTI));
2158 2196
2159 if (netif_running(dev) && netif_carrier_ok(dev)) 2197 if (netif_running(dev)) {
2160 flags |= IFF_RUNNING; 2198 if (netif_oper_up(dev))
2199 flags |= IFF_RUNNING;
2200 if (netif_carrier_ok(dev))
2201 flags |= IFF_LOWER_UP;
2202 if (netif_dormant(dev))
2203 flags |= IFF_DORMANT;
2204 }
2161 2205
2162 return flags; 2206 return flags;
2163} 2207}
@@ -2200,7 +2244,8 @@ int dev_change_flags(struct net_device *dev, unsigned flags)
2200 if (dev->flags & IFF_UP && 2244 if (dev->flags & IFF_UP &&
2201 ((old_flags ^ dev->flags) &~ (IFF_UP | IFF_PROMISC | IFF_ALLMULTI | 2245 ((old_flags ^ dev->flags) &~ (IFF_UP | IFF_PROMISC | IFF_ALLMULTI |
2202 IFF_VOLATILE))) 2246 IFF_VOLATILE)))
2203 notifier_call_chain(&netdev_chain, NETDEV_CHANGE, dev); 2247 blocking_notifier_call_chain(&netdev_chain,
2248 NETDEV_CHANGE, dev);
2204 2249
2205 if ((flags ^ dev->gflags) & IFF_PROMISC) { 2250 if ((flags ^ dev->gflags) & IFF_PROMISC) {
2206 int inc = (flags & IFF_PROMISC) ? +1 : -1; 2251 int inc = (flags & IFF_PROMISC) ? +1 : -1;
@@ -2244,8 +2289,8 @@ int dev_set_mtu(struct net_device *dev, int new_mtu)
2244 else 2289 else
2245 dev->mtu = new_mtu; 2290 dev->mtu = new_mtu;
2246 if (!err && dev->flags & IFF_UP) 2291 if (!err && dev->flags & IFF_UP)
2247 notifier_call_chain(&netdev_chain, 2292 blocking_notifier_call_chain(&netdev_chain,
2248 NETDEV_CHANGEMTU, dev); 2293 NETDEV_CHANGEMTU, dev);
2249 return err; 2294 return err;
2250} 2295}
2251 2296
@@ -2261,7 +2306,8 @@ int dev_set_mac_address(struct net_device *dev, struct sockaddr *sa)
2261 return -ENODEV; 2306 return -ENODEV;
2262 err = dev->set_mac_address(dev, sa); 2307 err = dev->set_mac_address(dev, sa);
2263 if (!err) 2308 if (!err)
2264 notifier_call_chain(&netdev_chain, NETDEV_CHANGEADDR, dev); 2309 blocking_notifier_call_chain(&netdev_chain,
2310 NETDEV_CHANGEADDR, dev);
2265 return err; 2311 return err;
2266} 2312}
2267 2313
@@ -2317,7 +2363,7 @@ static int dev_ifsioc(struct ifreq *ifr, unsigned int cmd)
2317 return -EINVAL; 2363 return -EINVAL;
2318 memcpy(dev->broadcast, ifr->ifr_hwaddr.sa_data, 2364 memcpy(dev->broadcast, ifr->ifr_hwaddr.sa_data,
2319 min(sizeof ifr->ifr_hwaddr.sa_data, (size_t) dev->addr_len)); 2365 min(sizeof ifr->ifr_hwaddr.sa_data, (size_t) dev->addr_len));
2320 notifier_call_chain(&netdev_chain, 2366 blocking_notifier_call_chain(&netdev_chain,
2321 NETDEV_CHANGEADDR, dev); 2367 NETDEV_CHANGEADDR, dev);
2322 return 0; 2368 return 0;
2323 2369
@@ -2436,9 +2482,9 @@ int dev_ioctl(unsigned int cmd, void __user *arg)
2436 */ 2482 */
2437 2483
2438 if (cmd == SIOCGIFCONF) { 2484 if (cmd == SIOCGIFCONF) {
2439 rtnl_shlock(); 2485 rtnl_lock();
2440 ret = dev_ifconf((char __user *) arg); 2486 ret = dev_ifconf((char __user *) arg);
2441 rtnl_shunlock(); 2487 rtnl_unlock();
2442 return ret; 2488 return ret;
2443 } 2489 }
2444 if (cmd == SIOCGIFNAME) 2490 if (cmd == SIOCGIFNAME)
@@ -2582,7 +2628,7 @@ int dev_ioctl(unsigned int cmd, void __user *arg)
2582 ret = -EFAULT; 2628 ret = -EFAULT;
2583 return ret; 2629 return ret;
2584 } 2630 }
2585#ifdef WIRELESS_EXT 2631#ifdef CONFIG_WIRELESS_EXT
2586 /* Take care of Wireless Extensions */ 2632 /* Take care of Wireless Extensions */
2587 if (cmd >= SIOCIWFIRST && cmd <= SIOCIWLAST) { 2633 if (cmd >= SIOCIWFIRST && cmd <= SIOCIWLAST) {
2588 /* If command is `set a parameter', or 2634 /* If command is `set a parameter', or
@@ -2603,7 +2649,7 @@ int dev_ioctl(unsigned int cmd, void __user *arg)
2603 ret = -EFAULT; 2649 ret = -EFAULT;
2604 return ret; 2650 return ret;
2605 } 2651 }
2606#endif /* WIRELESS_EXT */ 2652#endif /* CONFIG_WIRELESS_EXT */
2607 return -EINVAL; 2653 return -EINVAL;
2608 } 2654 }
2609} 2655}
@@ -2771,7 +2817,7 @@ int register_netdevice(struct net_device *dev)
2771 write_unlock_bh(&dev_base_lock); 2817 write_unlock_bh(&dev_base_lock);
2772 2818
2773 /* Notify protocols, that a new device appeared. */ 2819 /* Notify protocols, that a new device appeared. */
2774 notifier_call_chain(&netdev_chain, NETDEV_REGISTER, dev); 2820 blocking_notifier_call_chain(&netdev_chain, NETDEV_REGISTER, dev);
2775 2821
2776 /* Finish registration after unlock */ 2822 /* Finish registration after unlock */
2777 net_set_todo(dev); 2823 net_set_todo(dev);
@@ -2847,10 +2893,10 @@ static void netdev_wait_allrefs(struct net_device *dev)
2847 rebroadcast_time = warning_time = jiffies; 2893 rebroadcast_time = warning_time = jiffies;
2848 while (atomic_read(&dev->refcnt) != 0) { 2894 while (atomic_read(&dev->refcnt) != 0) {
2849 if (time_after(jiffies, rebroadcast_time + 1 * HZ)) { 2895 if (time_after(jiffies, rebroadcast_time + 1 * HZ)) {
2850 rtnl_shlock(); 2896 rtnl_lock();
2851 2897
2852 /* Rebroadcast unregister notification */ 2898 /* Rebroadcast unregister notification */
2853 notifier_call_chain(&netdev_chain, 2899 blocking_notifier_call_chain(&netdev_chain,
2854 NETDEV_UNREGISTER, dev); 2900 NETDEV_UNREGISTER, dev);
2855 2901
2856 if (test_bit(__LINK_STATE_LINKWATCH_PENDING, 2902 if (test_bit(__LINK_STATE_LINKWATCH_PENDING,
@@ -2864,7 +2910,7 @@ static void netdev_wait_allrefs(struct net_device *dev)
2864 linkwatch_run_queue(); 2910 linkwatch_run_queue();
2865 } 2911 }
2866 2912
2867 rtnl_shunlock(); 2913 __rtnl_unlock();
2868 2914
2869 rebroadcast_time = jiffies; 2915 rebroadcast_time = jiffies;
2870 } 2916 }
@@ -2902,7 +2948,7 @@ static void netdev_wait_allrefs(struct net_device *dev)
2902 * 2) Since we run with the RTNL semaphore not held, we can sleep 2948 * 2) Since we run with the RTNL semaphore not held, we can sleep
2903 * safely in order to wait for the netdev refcnt to drop to zero. 2949 * safely in order to wait for the netdev refcnt to drop to zero.
2904 */ 2950 */
2905static DECLARE_MUTEX(net_todo_run_mutex); 2951static DEFINE_MUTEX(net_todo_run_mutex);
2906void netdev_run_todo(void) 2952void netdev_run_todo(void)
2907{ 2953{
2908 struct list_head list = LIST_HEAD_INIT(list); 2954 struct list_head list = LIST_HEAD_INIT(list);
@@ -2910,7 +2956,7 @@ void netdev_run_todo(void)
2910 2956
2911 2957
2912 /* Need to guard against multiple cpu's getting out of order. */ 2958 /* Need to guard against multiple cpu's getting out of order. */
2913 down(&net_todo_run_mutex); 2959 mutex_lock(&net_todo_run_mutex);
2914 2960
2915 /* Not safe to do outside the semaphore. We must not return 2961 /* Not safe to do outside the semaphore. We must not return
2916 * until all unregister events invoked by the local processor 2962 * until all unregister events invoked by the local processor
@@ -2967,7 +3013,7 @@ void netdev_run_todo(void)
2967 } 3013 }
2968 3014
2969out: 3015out:
2970 up(&net_todo_run_mutex); 3016 mutex_unlock(&net_todo_run_mutex);
2971} 3017}
2972 3018
2973/** 3019/**
@@ -3106,7 +3152,7 @@ int unregister_netdevice(struct net_device *dev)
3106 /* Notify protocols, that we are about to destroy 3152 /* Notify protocols, that we are about to destroy
3107 this device. They should clean all the things. 3153 this device. They should clean all the things.
3108 */ 3154 */
3109 notifier_call_chain(&netdev_chain, NETDEV_UNREGISTER, dev); 3155 blocking_notifier_call_chain(&netdev_chain, NETDEV_UNREGISTER, dev);
3110 3156
3111 /* 3157 /*
3112 * Flush the multicast chain 3158 * Flush the multicast chain