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.c516
1 files changed, 388 insertions, 128 deletions
diff --git a/net/core/dev.c b/net/core/dev.c
index d334446a8eaf..8d13a9b9f1df 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -90,6 +90,7 @@
90#include <linux/if_ether.h> 90#include <linux/if_ether.h>
91#include <linux/netdevice.h> 91#include <linux/netdevice.h>
92#include <linux/etherdevice.h> 92#include <linux/etherdevice.h>
93#include <linux/ethtool.h>
93#include <linux/notifier.h> 94#include <linux/notifier.h>
94#include <linux/skbuff.h> 95#include <linux/skbuff.h>
95#include <net/net_namespace.h> 96#include <net/net_namespace.h>
@@ -119,6 +120,12 @@
119#include <linux/err.h> 120#include <linux/err.h>
120#include <linux/ctype.h> 121#include <linux/ctype.h>
121#include <linux/if_arp.h> 122#include <linux/if_arp.h>
123#include <linux/if_vlan.h>
124#include <linux/ip.h>
125#include <linux/ipv6.h>
126#include <linux/in.h>
127#include <linux/jhash.h>
128#include <linux/random.h>
122 129
123#include "net-sysfs.h" 130#include "net-sysfs.h"
124 131
@@ -254,9 +261,9 @@ static RAW_NOTIFIER_HEAD(netdev_chain);
254 261
255DEFINE_PER_CPU(struct softnet_data, softnet_data); 262DEFINE_PER_CPU(struct softnet_data, softnet_data);
256 263
257#ifdef CONFIG_DEBUG_LOCK_ALLOC 264#ifdef CONFIG_LOCKDEP
258/* 265/*
259 * register_netdevice() inits dev->_xmit_lock and sets lockdep class 266 * register_netdevice() inits txq->_xmit_lock and sets lockdep class
260 * according to dev->type 267 * according to dev->type
261 */ 268 */
262static const unsigned short netdev_lock_type[] = 269static const unsigned short netdev_lock_type[] =
@@ -294,6 +301,7 @@ static const char *netdev_lock_name[] =
294 "_xmit_NONE"}; 301 "_xmit_NONE"};
295 302
296static struct lock_class_key netdev_xmit_lock_key[ARRAY_SIZE(netdev_lock_type)]; 303static struct lock_class_key netdev_xmit_lock_key[ARRAY_SIZE(netdev_lock_type)];
304static struct lock_class_key netdev_addr_lock_key[ARRAY_SIZE(netdev_lock_type)];
297 305
298static inline unsigned short netdev_lock_pos(unsigned short dev_type) 306static inline unsigned short netdev_lock_pos(unsigned short dev_type)
299{ 307{
@@ -306,8 +314,8 @@ static inline unsigned short netdev_lock_pos(unsigned short dev_type)
306 return ARRAY_SIZE(netdev_lock_type) - 1; 314 return ARRAY_SIZE(netdev_lock_type) - 1;
307} 315}
308 316
309static inline void netdev_set_lockdep_class(spinlock_t *lock, 317static inline void netdev_set_xmit_lockdep_class(spinlock_t *lock,
310 unsigned short dev_type) 318 unsigned short dev_type)
311{ 319{
312 int i; 320 int i;
313 321
@@ -315,9 +323,22 @@ static inline void netdev_set_lockdep_class(spinlock_t *lock,
315 lockdep_set_class_and_name(lock, &netdev_xmit_lock_key[i], 323 lockdep_set_class_and_name(lock, &netdev_xmit_lock_key[i],
316 netdev_lock_name[i]); 324 netdev_lock_name[i]);
317} 325}
326
327static inline void netdev_set_addr_lockdep_class(struct net_device *dev)
328{
329 int i;
330
331 i = netdev_lock_pos(dev->type);
332 lockdep_set_class_and_name(&dev->addr_list_lock,
333 &netdev_addr_lock_key[i],
334 netdev_lock_name[i]);
335}
318#else 336#else
319static inline void netdev_set_lockdep_class(spinlock_t *lock, 337static inline void netdev_set_xmit_lockdep_class(spinlock_t *lock,
320 unsigned short dev_type) 338 unsigned short dev_type)
339{
340}
341static inline void netdev_set_addr_lockdep_class(struct net_device *dev)
321{ 342{
322} 343}
323#endif 344#endif
@@ -453,7 +474,7 @@ static int netdev_boot_setup_add(char *name, struct ifmap *map)
453 for (i = 0; i < NETDEV_BOOT_SETUP_MAX; i++) { 474 for (i = 0; i < NETDEV_BOOT_SETUP_MAX; i++) {
454 if (s[i].name[0] == '\0' || s[i].name[0] == ' ') { 475 if (s[i].name[0] == '\0' || s[i].name[0] == ' ') {
455 memset(s[i].name, 0, sizeof(s[i].name)); 476 memset(s[i].name, 0, sizeof(s[i].name));
456 strcpy(s[i].name, name); 477 strlcpy(s[i].name, name, IFNAMSIZ);
457 memcpy(&s[i].map, map, sizeof(s[i].map)); 478 memcpy(&s[i].map, map, sizeof(s[i].map));
458 break; 479 break;
459 } 480 }
@@ -478,7 +499,7 @@ int netdev_boot_setup_check(struct net_device *dev)
478 499
479 for (i = 0; i < NETDEV_BOOT_SETUP_MAX; i++) { 500 for (i = 0; i < NETDEV_BOOT_SETUP_MAX; i++) {
480 if (s[i].name[0] != '\0' && s[i].name[0] != ' ' && 501 if (s[i].name[0] != '\0' && s[i].name[0] != ' ' &&
481 !strncmp(dev->name, s[i].name, strlen(s[i].name))) { 502 !strcmp(dev->name, s[i].name)) {
482 dev->irq = s[i].map.irq; 503 dev->irq = s[i].map.irq;
483 dev->base_addr = s[i].map.base_addr; 504 dev->base_addr = s[i].map.base_addr;
484 dev->mem_start = s[i].map.mem_start; 505 dev->mem_start = s[i].map.mem_start;
@@ -903,7 +924,11 @@ int dev_change_name(struct net_device *dev, char *newname)
903 strlcpy(dev->name, newname, IFNAMSIZ); 924 strlcpy(dev->name, newname, IFNAMSIZ);
904 925
905rollback: 926rollback:
906 device_rename(&dev->dev, dev->name); 927 err = device_rename(&dev->dev, dev->name);
928 if (err) {
929 memcpy(dev->name, oldname, IFNAMSIZ);
930 return err;
931 }
907 932
908 write_lock_bh(&dev_base_lock); 933 write_lock_bh(&dev_base_lock);
909 hlist_del(&dev->name_hlist); 934 hlist_del(&dev->name_hlist);
@@ -956,6 +981,12 @@ void netdev_state_change(struct net_device *dev)
956 } 981 }
957} 982}
958 983
984void netdev_bonding_change(struct net_device *dev)
985{
986 call_netdevice_notifiers(NETDEV_BONDING_FAILOVER, dev);
987}
988EXPORT_SYMBOL(netdev_bonding_change);
989
959/** 990/**
960 * dev_load - load a network module 991 * dev_load - load a network module
961 * @net: the applicable net namespace 992 * @net: the applicable net namespace
@@ -994,6 +1025,8 @@ int dev_open(struct net_device *dev)
994{ 1025{
995 int ret = 0; 1026 int ret = 0;
996 1027
1028 ASSERT_RTNL();
1029
997 /* 1030 /*
998 * Is it already up? 1031 * Is it already up?
999 */ 1032 */
@@ -1060,6 +1093,8 @@ int dev_open(struct net_device *dev)
1060 */ 1093 */
1061int dev_close(struct net_device *dev) 1094int dev_close(struct net_device *dev)
1062{ 1095{
1096 ASSERT_RTNL();
1097
1063 might_sleep(); 1098 might_sleep();
1064 1099
1065 if (!(dev->flags & IFF_UP)) 1100 if (!(dev->flags & IFF_UP))
@@ -1108,6 +1143,29 @@ int dev_close(struct net_device *dev)
1108} 1143}
1109 1144
1110 1145
1146/**
1147 * dev_disable_lro - disable Large Receive Offload on a device
1148 * @dev: device
1149 *
1150 * Disable Large Receive Offload (LRO) on a net device. Must be
1151 * called under RTNL. This is needed if received packets may be
1152 * forwarded to another interface.
1153 */
1154void dev_disable_lro(struct net_device *dev)
1155{
1156 if (dev->ethtool_ops && dev->ethtool_ops->get_flags &&
1157 dev->ethtool_ops->set_flags) {
1158 u32 flags = dev->ethtool_ops->get_flags(dev);
1159 if (flags & ETH_FLAG_LRO) {
1160 flags &= ~ETH_FLAG_LRO;
1161 dev->ethtool_ops->set_flags(dev, flags);
1162 }
1163 }
1164 WARN_ON(dev->features & NETIF_F_LRO);
1165}
1166EXPORT_SYMBOL(dev_disable_lro);
1167
1168
1111static int dev_boot_phase = 1; 1169static int dev_boot_phase = 1;
1112 1170
1113/* 1171/*
@@ -1281,16 +1339,16 @@ static void dev_queue_xmit_nit(struct sk_buff *skb, struct net_device *dev)
1281} 1339}
1282 1340
1283 1341
1284void __netif_schedule(struct net_device *dev) 1342void __netif_schedule(struct Qdisc *q)
1285{ 1343{
1286 if (!test_and_set_bit(__LINK_STATE_SCHED, &dev->state)) { 1344 if (!test_and_set_bit(__QDISC_STATE_SCHED, &q->state)) {
1287 unsigned long flags;
1288 struct softnet_data *sd; 1345 struct softnet_data *sd;
1346 unsigned long flags;
1289 1347
1290 local_irq_save(flags); 1348 local_irq_save(flags);
1291 sd = &__get_cpu_var(softnet_data); 1349 sd = &__get_cpu_var(softnet_data);
1292 dev->next_sched = sd->output_queue; 1350 q->next_sched = sd->output_queue;
1293 sd->output_queue = dev; 1351 sd->output_queue = q;
1294 raise_softirq_irqoff(NET_TX_SOFTIRQ); 1352 raise_softirq_irqoff(NET_TX_SOFTIRQ);
1295 local_irq_restore(flags); 1353 local_irq_restore(flags);
1296 } 1354 }
@@ -1354,6 +1412,29 @@ void netif_device_attach(struct net_device *dev)
1354} 1412}
1355EXPORT_SYMBOL(netif_device_attach); 1413EXPORT_SYMBOL(netif_device_attach);
1356 1414
1415static bool can_checksum_protocol(unsigned long features, __be16 protocol)
1416{
1417 return ((features & NETIF_F_GEN_CSUM) ||
1418 ((features & NETIF_F_IP_CSUM) &&
1419 protocol == htons(ETH_P_IP)) ||
1420 ((features & NETIF_F_IPV6_CSUM) &&
1421 protocol == htons(ETH_P_IPV6)));
1422}
1423
1424static bool dev_can_checksum(struct net_device *dev, struct sk_buff *skb)
1425{
1426 if (can_checksum_protocol(dev->features, skb->protocol))
1427 return true;
1428
1429 if (skb->protocol == htons(ETH_P_8021Q)) {
1430 struct vlan_ethhdr *veh = (struct vlan_ethhdr *)skb->data;
1431 if (can_checksum_protocol(dev->features & dev->vlan_features,
1432 veh->h_vlan_encapsulated_proto))
1433 return true;
1434 }
1435
1436 return false;
1437}
1357 1438
1358/* 1439/*
1359 * Invalidate hardware checksum when packet is to be mangled, and 1440 * Invalidate hardware checksum when packet is to be mangled, and
@@ -1534,7 +1615,8 @@ static int dev_gso_segment(struct sk_buff *skb)
1534 return 0; 1615 return 0;
1535} 1616}
1536 1617
1537int dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev) 1618int dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev,
1619 struct netdev_queue *txq)
1538{ 1620{
1539 if (likely(!skb->next)) { 1621 if (likely(!skb->next)) {
1540 if (!list_empty(&ptype_all)) 1622 if (!list_empty(&ptype_all))
@@ -1563,9 +1645,7 @@ gso:
1563 skb->next = nskb; 1645 skb->next = nskb;
1564 return rc; 1646 return rc;
1565 } 1647 }
1566 if (unlikely((netif_queue_stopped(dev) || 1648 if (unlikely(netif_tx_queue_stopped(txq) && skb->next))
1567 netif_subqueue_stopped(dev, skb)) &&
1568 skb->next))
1569 return NETDEV_TX_BUSY; 1649 return NETDEV_TX_BUSY;
1570 } while (skb->next); 1650 } while (skb->next);
1571 1651
@@ -1576,6 +1656,73 @@ out_kfree_skb:
1576 return 0; 1656 return 0;
1577} 1657}
1578 1658
1659static u32 simple_tx_hashrnd;
1660static int simple_tx_hashrnd_initialized = 0;
1661
1662static u16 simple_tx_hash(struct net_device *dev, struct sk_buff *skb)
1663{
1664 u32 addr1, addr2, ports;
1665 u32 hash, ihl;
1666 u8 ip_proto;
1667
1668 if (unlikely(!simple_tx_hashrnd_initialized)) {
1669 get_random_bytes(&simple_tx_hashrnd, 4);
1670 simple_tx_hashrnd_initialized = 1;
1671 }
1672
1673 switch (skb->protocol) {
1674 case __constant_htons(ETH_P_IP):
1675 ip_proto = ip_hdr(skb)->protocol;
1676 addr1 = ip_hdr(skb)->saddr;
1677 addr2 = ip_hdr(skb)->daddr;
1678 ihl = ip_hdr(skb)->ihl;
1679 break;
1680 case __constant_htons(ETH_P_IPV6):
1681 ip_proto = ipv6_hdr(skb)->nexthdr;
1682 addr1 = ipv6_hdr(skb)->saddr.s6_addr32[3];
1683 addr2 = ipv6_hdr(skb)->daddr.s6_addr32[3];
1684 ihl = (40 >> 2);
1685 break;
1686 default:
1687 return 0;
1688 }
1689
1690
1691 switch (ip_proto) {
1692 case IPPROTO_TCP:
1693 case IPPROTO_UDP:
1694 case IPPROTO_DCCP:
1695 case IPPROTO_ESP:
1696 case IPPROTO_AH:
1697 case IPPROTO_SCTP:
1698 case IPPROTO_UDPLITE:
1699 ports = *((u32 *) (skb_network_header(skb) + (ihl * 4)));
1700 break;
1701
1702 default:
1703 ports = 0;
1704 break;
1705 }
1706
1707 hash = jhash_3words(addr1, addr2, ports, simple_tx_hashrnd);
1708
1709 return (u16) (((u64) hash * dev->real_num_tx_queues) >> 32);
1710}
1711
1712static struct netdev_queue *dev_pick_tx(struct net_device *dev,
1713 struct sk_buff *skb)
1714{
1715 u16 queue_index = 0;
1716
1717 if (dev->select_queue)
1718 queue_index = dev->select_queue(dev, skb);
1719 else if (dev->real_num_tx_queues > 1)
1720 queue_index = simple_tx_hash(dev, skb);
1721
1722 skb_set_queue_mapping(skb, queue_index);
1723 return netdev_get_tx_queue(dev, queue_index);
1724}
1725
1579/** 1726/**
1580 * dev_queue_xmit - transmit a buffer 1727 * dev_queue_xmit - transmit a buffer
1581 * @skb: buffer to transmit 1728 * @skb: buffer to transmit
@@ -1601,10 +1748,10 @@ out_kfree_skb:
1601 * the BH enable code must have IRQs enabled so that it will not deadlock. 1748 * the BH enable code must have IRQs enabled so that it will not deadlock.
1602 * --BLG 1749 * --BLG
1603 */ 1750 */
1604
1605int dev_queue_xmit(struct sk_buff *skb) 1751int dev_queue_xmit(struct sk_buff *skb)
1606{ 1752{
1607 struct net_device *dev = skb->dev; 1753 struct net_device *dev = skb->dev;
1754 struct netdev_queue *txq;
1608 struct Qdisc *q; 1755 struct Qdisc *q;
1609 int rc = -ENOMEM; 1756 int rc = -ENOMEM;
1610 1757
@@ -1632,55 +1779,34 @@ int dev_queue_xmit(struct sk_buff *skb)
1632 if (skb->ip_summed == CHECKSUM_PARTIAL) { 1779 if (skb->ip_summed == CHECKSUM_PARTIAL) {
1633 skb_set_transport_header(skb, skb->csum_start - 1780 skb_set_transport_header(skb, skb->csum_start -
1634 skb_headroom(skb)); 1781 skb_headroom(skb));
1635 1782 if (!dev_can_checksum(dev, skb) && skb_checksum_help(skb))
1636 if (!(dev->features & NETIF_F_GEN_CSUM) && 1783 goto out_kfree_skb;
1637 !((dev->features & NETIF_F_IP_CSUM) &&
1638 skb->protocol == htons(ETH_P_IP)) &&
1639 !((dev->features & NETIF_F_IPV6_CSUM) &&
1640 skb->protocol == htons(ETH_P_IPV6)))
1641 if (skb_checksum_help(skb))
1642 goto out_kfree_skb;
1643 } 1784 }
1644 1785
1645gso: 1786gso:
1646 spin_lock_prefetch(&dev->queue_lock);
1647
1648 /* Disable soft irqs for various locks below. Also 1787 /* Disable soft irqs for various locks below. Also
1649 * stops preemption for RCU. 1788 * stops preemption for RCU.
1650 */ 1789 */
1651 rcu_read_lock_bh(); 1790 rcu_read_lock_bh();
1652 1791
1653 /* Updates of qdisc are serialized by queue_lock. 1792 txq = dev_pick_tx(dev, skb);
1654 * The struct Qdisc which is pointed to by qdisc is now a 1793 q = rcu_dereference(txq->qdisc);
1655 * rcu structure - it may be accessed without acquiring
1656 * a lock (but the structure may be stale.) The freeing of the
1657 * qdisc will be deferred until it's known that there are no
1658 * more references to it.
1659 *
1660 * If the qdisc has an enqueue function, we still need to
1661 * hold the queue_lock before calling it, since queue_lock
1662 * also serializes access to the device queue.
1663 */
1664 1794
1665 q = rcu_dereference(dev->qdisc);
1666#ifdef CONFIG_NET_CLS_ACT 1795#ifdef CONFIG_NET_CLS_ACT
1667 skb->tc_verd = SET_TC_AT(skb->tc_verd,AT_EGRESS); 1796 skb->tc_verd = SET_TC_AT(skb->tc_verd,AT_EGRESS);
1668#endif 1797#endif
1669 if (q->enqueue) { 1798 if (q->enqueue) {
1670 /* Grab device queue */ 1799 spinlock_t *root_lock = qdisc_root_lock(q);
1671 spin_lock(&dev->queue_lock); 1800
1672 q = dev->qdisc; 1801 spin_lock(root_lock);
1673 if (q->enqueue) { 1802
1674 /* reset queue_mapping to zero */ 1803 rc = qdisc_enqueue_root(skb, q);
1675 skb_set_queue_mapping(skb, 0); 1804 qdisc_run(q);
1676 rc = q->enqueue(skb, q); 1805
1677 qdisc_run(dev); 1806 spin_unlock(root_lock);
1678 spin_unlock(&dev->queue_lock); 1807
1679 1808 rc = rc == NET_XMIT_BYPASS ? NET_XMIT_SUCCESS : rc;
1680 rc = rc == NET_XMIT_BYPASS ? NET_XMIT_SUCCESS : rc; 1809 goto out;
1681 goto out;
1682 }
1683 spin_unlock(&dev->queue_lock);
1684 } 1810 }
1685 1811
1686 /* The device has no queue. Common case for software devices: 1812 /* The device has no queue. Common case for software devices:
@@ -1698,19 +1824,18 @@ gso:
1698 if (dev->flags & IFF_UP) { 1824 if (dev->flags & IFF_UP) {
1699 int cpu = smp_processor_id(); /* ok because BHs are off */ 1825 int cpu = smp_processor_id(); /* ok because BHs are off */
1700 1826
1701 if (dev->xmit_lock_owner != cpu) { 1827 if (txq->xmit_lock_owner != cpu) {
1702 1828
1703 HARD_TX_LOCK(dev, cpu); 1829 HARD_TX_LOCK(dev, txq, cpu);
1704 1830
1705 if (!netif_queue_stopped(dev) && 1831 if (!netif_tx_queue_stopped(txq)) {
1706 !netif_subqueue_stopped(dev, skb)) {
1707 rc = 0; 1832 rc = 0;
1708 if (!dev_hard_start_xmit(skb, dev)) { 1833 if (!dev_hard_start_xmit(skb, dev, txq)) {
1709 HARD_TX_UNLOCK(dev); 1834 HARD_TX_UNLOCK(dev, txq);
1710 goto out; 1835 goto out;
1711 } 1836 }
1712 } 1837 }
1713 HARD_TX_UNLOCK(dev); 1838 HARD_TX_UNLOCK(dev, txq);
1714 if (net_ratelimit()) 1839 if (net_ratelimit())
1715 printk(KERN_CRIT "Virtual device %s asks to " 1840 printk(KERN_CRIT "Virtual device %s asks to "
1716 "queue packet!\n", dev->name); 1841 "queue packet!\n", dev->name);
@@ -1848,13 +1973,13 @@ static void net_tx_action(struct softirq_action *h)
1848 struct sk_buff *skb = clist; 1973 struct sk_buff *skb = clist;
1849 clist = clist->next; 1974 clist = clist->next;
1850 1975
1851 BUG_TRAP(!atomic_read(&skb->users)); 1976 WARN_ON(atomic_read(&skb->users));
1852 __kfree_skb(skb); 1977 __kfree_skb(skb);
1853 } 1978 }
1854 } 1979 }
1855 1980
1856 if (sd->output_queue) { 1981 if (sd->output_queue) {
1857 struct net_device *head; 1982 struct Qdisc *head;
1858 1983
1859 local_irq_disable(); 1984 local_irq_disable();
1860 head = sd->output_queue; 1985 head = sd->output_queue;
@@ -1862,17 +1987,20 @@ static void net_tx_action(struct softirq_action *h)
1862 local_irq_enable(); 1987 local_irq_enable();
1863 1988
1864 while (head) { 1989 while (head) {
1865 struct net_device *dev = head; 1990 struct Qdisc *q = head;
1991 spinlock_t *root_lock;
1992
1866 head = head->next_sched; 1993 head = head->next_sched;
1867 1994
1868 smp_mb__before_clear_bit(); 1995 smp_mb__before_clear_bit();
1869 clear_bit(__LINK_STATE_SCHED, &dev->state); 1996 clear_bit(__QDISC_STATE_SCHED, &q->state);
1870 1997
1871 if (spin_trylock(&dev->queue_lock)) { 1998 root_lock = qdisc_root_lock(q);
1872 qdisc_run(dev); 1999 if (spin_trylock(root_lock)) {
1873 spin_unlock(&dev->queue_lock); 2000 qdisc_run(q);
2001 spin_unlock(root_lock);
1874 } else { 2002 } else {
1875 netif_schedule(dev); 2003 __netif_schedule(q);
1876 } 2004 }
1877 } 2005 }
1878 } 2006 }
@@ -1953,10 +2081,11 @@ static inline struct sk_buff *handle_macvlan(struct sk_buff *skb,
1953 */ 2081 */
1954static int ing_filter(struct sk_buff *skb) 2082static int ing_filter(struct sk_buff *skb)
1955{ 2083{
1956 struct Qdisc *q;
1957 struct net_device *dev = skb->dev; 2084 struct net_device *dev = skb->dev;
1958 int result = TC_ACT_OK;
1959 u32 ttl = G_TC_RTTL(skb->tc_verd); 2085 u32 ttl = G_TC_RTTL(skb->tc_verd);
2086 struct netdev_queue *rxq;
2087 int result = TC_ACT_OK;
2088 struct Qdisc *q;
1960 2089
1961 if (MAX_RED_LOOP < ttl++) { 2090 if (MAX_RED_LOOP < ttl++) {
1962 printk(KERN_WARNING 2091 printk(KERN_WARNING
@@ -1968,10 +2097,14 @@ static int ing_filter(struct sk_buff *skb)
1968 skb->tc_verd = SET_TC_RTTL(skb->tc_verd, ttl); 2097 skb->tc_verd = SET_TC_RTTL(skb->tc_verd, ttl);
1969 skb->tc_verd = SET_TC_AT(skb->tc_verd, AT_INGRESS); 2098 skb->tc_verd = SET_TC_AT(skb->tc_verd, AT_INGRESS);
1970 2099
1971 spin_lock(&dev->ingress_lock); 2100 rxq = &dev->rx_queue;
1972 if ((q = dev->qdisc_ingress) != NULL) 2101
1973 result = q->enqueue(skb, q); 2102 q = rxq->qdisc;
1974 spin_unlock(&dev->ingress_lock); 2103 if (q) {
2104 spin_lock(qdisc_lock(q));
2105 result = qdisc_enqueue_root(skb, q);
2106 spin_unlock(qdisc_lock(q));
2107 }
1975 2108
1976 return result; 2109 return result;
1977} 2110}
@@ -1980,7 +2113,7 @@ static inline struct sk_buff *handle_ing(struct sk_buff *skb,
1980 struct packet_type **pt_prev, 2113 struct packet_type **pt_prev,
1981 int *ret, struct net_device *orig_dev) 2114 int *ret, struct net_device *orig_dev)
1982{ 2115{
1983 if (!skb->dev->qdisc_ingress) 2116 if (!skb->dev->rx_queue.qdisc)
1984 goto out; 2117 goto out;
1985 2118
1986 if (*pt_prev) { 2119 if (*pt_prev) {
@@ -2004,6 +2137,33 @@ out:
2004} 2137}
2005#endif 2138#endif
2006 2139
2140/*
2141 * netif_nit_deliver - deliver received packets to network taps
2142 * @skb: buffer
2143 *
2144 * This function is used to deliver incoming packets to network
2145 * taps. It should be used when the normal netif_receive_skb path
2146 * is bypassed, for example because of VLAN acceleration.
2147 */
2148void netif_nit_deliver(struct sk_buff *skb)
2149{
2150 struct packet_type *ptype;
2151
2152 if (list_empty(&ptype_all))
2153 return;
2154
2155 skb_reset_network_header(skb);
2156 skb_reset_transport_header(skb);
2157 skb->mac_len = skb->network_header - skb->mac_header;
2158
2159 rcu_read_lock();
2160 list_for_each_entry_rcu(ptype, &ptype_all, list) {
2161 if (!ptype->dev || ptype->dev == skb->dev)
2162 deliver_skb(skb, ptype, skb->dev);
2163 }
2164 rcu_read_unlock();
2165}
2166
2007/** 2167/**
2008 * netif_receive_skb - process receive buffer from network 2168 * netif_receive_skb - process receive buffer from network
2009 * @skb: buffer to process 2169 * @skb: buffer to process
@@ -2051,6 +2211,10 @@ int netif_receive_skb(struct sk_buff *skb)
2051 2211
2052 rcu_read_lock(); 2212 rcu_read_lock();
2053 2213
2214 /* Don't receive packets in an exiting network namespace */
2215 if (!net_alive(dev_net(skb->dev)))
2216 goto out;
2217
2054#ifdef CONFIG_NET_CLS_ACT 2218#ifdef CONFIG_NET_CLS_ACT
2055 if (skb->tc_verd & TC_NCLS) { 2219 if (skb->tc_verd & TC_NCLS) {
2056 skb->tc_verd = CLR_TC_NCLS(skb->tc_verd); 2220 skb->tc_verd = CLR_TC_NCLS(skb->tc_verd);
@@ -2231,7 +2395,7 @@ out:
2231 */ 2395 */
2232 if (!cpus_empty(net_dma.channel_mask)) { 2396 if (!cpus_empty(net_dma.channel_mask)) {
2233 int chan_idx; 2397 int chan_idx;
2234 for_each_cpu_mask(chan_idx, net_dma.channel_mask) { 2398 for_each_cpu_mask_nr(chan_idx, net_dma.channel_mask) {
2235 struct dma_chan *chan = net_dma.channels[chan_idx]; 2399 struct dma_chan *chan = net_dma.channels[chan_idx];
2236 if (chan) 2400 if (chan)
2237 dma_async_memcpy_issue_pending(chan); 2401 dma_async_memcpy_issue_pending(chan);
@@ -2739,16 +2903,29 @@ int netdev_set_master(struct net_device *slave, struct net_device *master)
2739 return 0; 2903 return 0;
2740} 2904}
2741 2905
2742static void __dev_set_promiscuity(struct net_device *dev, int inc) 2906static int __dev_set_promiscuity(struct net_device *dev, int inc)
2743{ 2907{
2744 unsigned short old_flags = dev->flags; 2908 unsigned short old_flags = dev->flags;
2745 2909
2746 ASSERT_RTNL(); 2910 ASSERT_RTNL();
2747 2911
2748 if ((dev->promiscuity += inc) == 0) 2912 dev->flags |= IFF_PROMISC;
2749 dev->flags &= ~IFF_PROMISC; 2913 dev->promiscuity += inc;
2750 else 2914 if (dev->promiscuity == 0) {
2751 dev->flags |= IFF_PROMISC; 2915 /*
2916 * Avoid overflow.
2917 * If inc causes overflow, untouch promisc and return error.
2918 */
2919 if (inc < 0)
2920 dev->flags &= ~IFF_PROMISC;
2921 else {
2922 dev->promiscuity -= inc;
2923 printk(KERN_WARNING "%s: promiscuity touches roof, "
2924 "set promiscuity failed, promiscuity feature "
2925 "of device might be broken.\n", dev->name);
2926 return -EOVERFLOW;
2927 }
2928 }
2752 if (dev->flags != old_flags) { 2929 if (dev->flags != old_flags) {
2753 printk(KERN_INFO "device %s %s promiscuous mode\n", 2930 printk(KERN_INFO "device %s %s promiscuous mode\n",
2754 dev->name, (dev->flags & IFF_PROMISC) ? "entered" : 2931 dev->name, (dev->flags & IFF_PROMISC) ? "entered" :
@@ -2766,6 +2943,7 @@ static void __dev_set_promiscuity(struct net_device *dev, int inc)
2766 if (dev->change_rx_flags) 2943 if (dev->change_rx_flags)
2767 dev->change_rx_flags(dev, IFF_PROMISC); 2944 dev->change_rx_flags(dev, IFF_PROMISC);
2768 } 2945 }
2946 return 0;
2769} 2947}
2770 2948
2771/** 2949/**
@@ -2777,14 +2955,19 @@ static void __dev_set_promiscuity(struct net_device *dev, int inc)
2777 * remains above zero the interface remains promiscuous. Once it hits zero 2955 * remains above zero the interface remains promiscuous. Once it hits zero
2778 * the device reverts back to normal filtering operation. A negative inc 2956 * the device reverts back to normal filtering operation. A negative inc
2779 * value is used to drop promiscuity on the device. 2957 * value is used to drop promiscuity on the device.
2958 * Return 0 if successful or a negative errno code on error.
2780 */ 2959 */
2781void dev_set_promiscuity(struct net_device *dev, int inc) 2960int dev_set_promiscuity(struct net_device *dev, int inc)
2782{ 2961{
2783 unsigned short old_flags = dev->flags; 2962 unsigned short old_flags = dev->flags;
2963 int err;
2784 2964
2785 __dev_set_promiscuity(dev, inc); 2965 err = __dev_set_promiscuity(dev, inc);
2966 if (err < 0)
2967 return err;
2786 if (dev->flags != old_flags) 2968 if (dev->flags != old_flags)
2787 dev_set_rx_mode(dev); 2969 dev_set_rx_mode(dev);
2970 return err;
2788} 2971}
2789 2972
2790/** 2973/**
@@ -2797,22 +2980,38 @@ void dev_set_promiscuity(struct net_device *dev, int inc)
2797 * to all interfaces. Once it hits zero the device reverts back to normal 2980 * to all interfaces. Once it hits zero the device reverts back to normal
2798 * filtering operation. A negative @inc value is used to drop the counter 2981 * filtering operation. A negative @inc value is used to drop the counter
2799 * when releasing a resource needing all multicasts. 2982 * when releasing a resource needing all multicasts.
2983 * Return 0 if successful or a negative errno code on error.
2800 */ 2984 */
2801 2985
2802void dev_set_allmulti(struct net_device *dev, int inc) 2986int dev_set_allmulti(struct net_device *dev, int inc)
2803{ 2987{
2804 unsigned short old_flags = dev->flags; 2988 unsigned short old_flags = dev->flags;
2805 2989
2806 ASSERT_RTNL(); 2990 ASSERT_RTNL();
2807 2991
2808 dev->flags |= IFF_ALLMULTI; 2992 dev->flags |= IFF_ALLMULTI;
2809 if ((dev->allmulti += inc) == 0) 2993 dev->allmulti += inc;
2810 dev->flags &= ~IFF_ALLMULTI; 2994 if (dev->allmulti == 0) {
2995 /*
2996 * Avoid overflow.
2997 * If inc causes overflow, untouch allmulti and return error.
2998 */
2999 if (inc < 0)
3000 dev->flags &= ~IFF_ALLMULTI;
3001 else {
3002 dev->allmulti -= inc;
3003 printk(KERN_WARNING "%s: allmulti touches roof, "
3004 "set allmulti failed, allmulti feature of "
3005 "device might be broken.\n", dev->name);
3006 return -EOVERFLOW;
3007 }
3008 }
2811 if (dev->flags ^ old_flags) { 3009 if (dev->flags ^ old_flags) {
2812 if (dev->change_rx_flags) 3010 if (dev->change_rx_flags)
2813 dev->change_rx_flags(dev, IFF_ALLMULTI); 3011 dev->change_rx_flags(dev, IFF_ALLMULTI);
2814 dev_set_rx_mode(dev); 3012 dev_set_rx_mode(dev);
2815 } 3013 }
3014 return 0;
2816} 3015}
2817 3016
2818/* 3017/*
@@ -2851,9 +3050,9 @@ void __dev_set_rx_mode(struct net_device *dev)
2851 3050
2852void dev_set_rx_mode(struct net_device *dev) 3051void dev_set_rx_mode(struct net_device *dev)
2853{ 3052{
2854 netif_tx_lock_bh(dev); 3053 netif_addr_lock_bh(dev);
2855 __dev_set_rx_mode(dev); 3054 __dev_set_rx_mode(dev);
2856 netif_tx_unlock_bh(dev); 3055 netif_addr_unlock_bh(dev);
2857} 3056}
2858 3057
2859int __dev_addr_delete(struct dev_addr_list **list, int *count, 3058int __dev_addr_delete(struct dev_addr_list **list, int *count,
@@ -2931,11 +3130,11 @@ int dev_unicast_delete(struct net_device *dev, void *addr, int alen)
2931 3130
2932 ASSERT_RTNL(); 3131 ASSERT_RTNL();
2933 3132
2934 netif_tx_lock_bh(dev); 3133 netif_addr_lock_bh(dev);
2935 err = __dev_addr_delete(&dev->uc_list, &dev->uc_count, addr, alen, 0); 3134 err = __dev_addr_delete(&dev->uc_list, &dev->uc_count, addr, alen, 0);
2936 if (!err) 3135 if (!err)
2937 __dev_set_rx_mode(dev); 3136 __dev_set_rx_mode(dev);
2938 netif_tx_unlock_bh(dev); 3137 netif_addr_unlock_bh(dev);
2939 return err; 3138 return err;
2940} 3139}
2941EXPORT_SYMBOL(dev_unicast_delete); 3140EXPORT_SYMBOL(dev_unicast_delete);
@@ -2943,7 +3142,7 @@ EXPORT_SYMBOL(dev_unicast_delete);
2943/** 3142/**
2944 * dev_unicast_add - add a secondary unicast address 3143 * dev_unicast_add - add a secondary unicast address
2945 * @dev: device 3144 * @dev: device
2946 * @addr: address to delete 3145 * @addr: address to add
2947 * @alen: length of @addr 3146 * @alen: length of @addr
2948 * 3147 *
2949 * Add a secondary unicast address to the device or increase 3148 * Add a secondary unicast address to the device or increase
@@ -2957,11 +3156,11 @@ int dev_unicast_add(struct net_device *dev, void *addr, int alen)
2957 3156
2958 ASSERT_RTNL(); 3157 ASSERT_RTNL();
2959 3158
2960 netif_tx_lock_bh(dev); 3159 netif_addr_lock_bh(dev);
2961 err = __dev_addr_add(&dev->uc_list, &dev->uc_count, addr, alen, 0); 3160 err = __dev_addr_add(&dev->uc_list, &dev->uc_count, addr, alen, 0);
2962 if (!err) 3161 if (!err)
2963 __dev_set_rx_mode(dev); 3162 __dev_set_rx_mode(dev);
2964 netif_tx_unlock_bh(dev); 3163 netif_addr_unlock_bh(dev);
2965 return err; 3164 return err;
2966} 3165}
2967EXPORT_SYMBOL(dev_unicast_add); 3166EXPORT_SYMBOL(dev_unicast_add);
@@ -3028,12 +3227,12 @@ int dev_unicast_sync(struct net_device *to, struct net_device *from)
3028{ 3227{
3029 int err = 0; 3228 int err = 0;
3030 3229
3031 netif_tx_lock_bh(to); 3230 netif_addr_lock_bh(to);
3032 err = __dev_addr_sync(&to->uc_list, &to->uc_count, 3231 err = __dev_addr_sync(&to->uc_list, &to->uc_count,
3033 &from->uc_list, &from->uc_count); 3232 &from->uc_list, &from->uc_count);
3034 if (!err) 3233 if (!err)
3035 __dev_set_rx_mode(to); 3234 __dev_set_rx_mode(to);
3036 netif_tx_unlock_bh(to); 3235 netif_addr_unlock_bh(to);
3037 return err; 3236 return err;
3038} 3237}
3039EXPORT_SYMBOL(dev_unicast_sync); 3238EXPORT_SYMBOL(dev_unicast_sync);
@@ -3049,15 +3248,15 @@ EXPORT_SYMBOL(dev_unicast_sync);
3049 */ 3248 */
3050void dev_unicast_unsync(struct net_device *to, struct net_device *from) 3249void dev_unicast_unsync(struct net_device *to, struct net_device *from)
3051{ 3250{
3052 netif_tx_lock_bh(from); 3251 netif_addr_lock_bh(from);
3053 netif_tx_lock_bh(to); 3252 netif_addr_lock(to);
3054 3253
3055 __dev_addr_unsync(&to->uc_list, &to->uc_count, 3254 __dev_addr_unsync(&to->uc_list, &to->uc_count,
3056 &from->uc_list, &from->uc_count); 3255 &from->uc_list, &from->uc_count);
3057 __dev_set_rx_mode(to); 3256 __dev_set_rx_mode(to);
3058 3257
3059 netif_tx_unlock_bh(to); 3258 netif_addr_unlock(to);
3060 netif_tx_unlock_bh(from); 3259 netif_addr_unlock_bh(from);
3061} 3260}
3062EXPORT_SYMBOL(dev_unicast_unsync); 3261EXPORT_SYMBOL(dev_unicast_unsync);
3063 3262
@@ -3077,7 +3276,7 @@ static void __dev_addr_discard(struct dev_addr_list **list)
3077 3276
3078static void dev_addr_discard(struct net_device *dev) 3277static void dev_addr_discard(struct net_device *dev)
3079{ 3278{
3080 netif_tx_lock_bh(dev); 3279 netif_addr_lock_bh(dev);
3081 3280
3082 __dev_addr_discard(&dev->uc_list); 3281 __dev_addr_discard(&dev->uc_list);
3083 dev->uc_count = 0; 3282 dev->uc_count = 0;
@@ -3085,7 +3284,7 @@ static void dev_addr_discard(struct net_device *dev)
3085 __dev_addr_discard(&dev->mc_list); 3284 __dev_addr_discard(&dev->mc_list);
3086 dev->mc_count = 0; 3285 dev->mc_count = 0;
3087 3286
3088 netif_tx_unlock_bh(dev); 3287 netif_addr_unlock_bh(dev);
3089} 3288}
3090 3289
3091unsigned dev_get_flags(const struct net_device *dev) 3290unsigned dev_get_flags(const struct net_device *dev)
@@ -3133,7 +3332,7 @@ int dev_change_flags(struct net_device *dev, unsigned flags)
3133 * Load in the correct multicast list now the flags have changed. 3332 * Load in the correct multicast list now the flags have changed.
3134 */ 3333 */
3135 3334
3136 if (dev->change_rx_flags && (dev->flags ^ flags) & IFF_MULTICAST) 3335 if (dev->change_rx_flags && (old_flags ^ flags) & IFF_MULTICAST)
3137 dev->change_rx_flags(dev, IFF_MULTICAST); 3336 dev->change_rx_flags(dev, IFF_MULTICAST);
3138 3337
3139 dev_set_rx_mode(dev); 3338 dev_set_rx_mode(dev);
@@ -3648,7 +3847,7 @@ static void rollback_registered(struct net_device *dev)
3648 dev->uninit(dev); 3847 dev->uninit(dev);
3649 3848
3650 /* Notifier chain MUST detach us from master device. */ 3849 /* Notifier chain MUST detach us from master device. */
3651 BUG_TRAP(!dev->master); 3850 WARN_ON(dev->master);
3652 3851
3653 /* Remove entries from kobject tree */ 3852 /* Remove entries from kobject tree */
3654 netdev_unregister_kobject(dev); 3853 netdev_unregister_kobject(dev);
@@ -3658,6 +3857,21 @@ static void rollback_registered(struct net_device *dev)
3658 dev_put(dev); 3857 dev_put(dev);
3659} 3858}
3660 3859
3860static void __netdev_init_queue_locks_one(struct net_device *dev,
3861 struct netdev_queue *dev_queue,
3862 void *_unused)
3863{
3864 spin_lock_init(&dev_queue->_xmit_lock);
3865 netdev_set_xmit_lockdep_class(&dev_queue->_xmit_lock, dev->type);
3866 dev_queue->xmit_lock_owner = -1;
3867}
3868
3869static void netdev_init_queue_locks(struct net_device *dev)
3870{
3871 netdev_for_each_tx_queue(dev, __netdev_init_queue_locks_one, NULL);
3872 __netdev_init_queue_locks_one(dev, &dev->rx_queue, NULL);
3873}
3874
3661/** 3875/**
3662 * register_netdevice - register a network device 3876 * register_netdevice - register a network device
3663 * @dev: device to register 3877 * @dev: device to register
@@ -3692,11 +3906,9 @@ int register_netdevice(struct net_device *dev)
3692 BUG_ON(!dev_net(dev)); 3906 BUG_ON(!dev_net(dev));
3693 net = dev_net(dev); 3907 net = dev_net(dev);
3694 3908
3695 spin_lock_init(&dev->queue_lock); 3909 spin_lock_init(&dev->addr_list_lock);
3696 spin_lock_init(&dev->_xmit_lock); 3910 netdev_set_addr_lockdep_class(dev);
3697 netdev_set_lockdep_class(&dev->_xmit_lock, dev->type); 3911 netdev_init_queue_locks(dev);
3698 dev->xmit_lock_owner = -1;
3699 spin_lock_init(&dev->ingress_lock);
3700 3912
3701 dev->iflink = -1; 3913 dev->iflink = -1;
3702 3914
@@ -3957,9 +4169,9 @@ void netdev_run_todo(void)
3957 4169
3958 /* paranoia */ 4170 /* paranoia */
3959 BUG_ON(atomic_read(&dev->refcnt)); 4171 BUG_ON(atomic_read(&dev->refcnt));
3960 BUG_TRAP(!dev->ip_ptr); 4172 WARN_ON(dev->ip_ptr);
3961 BUG_TRAP(!dev->ip6_ptr); 4173 WARN_ON(dev->ip6_ptr);
3962 BUG_TRAP(!dev->dn_ptr); 4174 WARN_ON(dev->dn_ptr);
3963 4175
3964 if (dev->destructor) 4176 if (dev->destructor)
3965 dev->destructor(dev); 4177 dev->destructor(dev);
@@ -3977,6 +4189,19 @@ static struct net_device_stats *internal_stats(struct net_device *dev)
3977 return &dev->stats; 4189 return &dev->stats;
3978} 4190}
3979 4191
4192static void netdev_init_one_queue(struct net_device *dev,
4193 struct netdev_queue *queue,
4194 void *_unused)
4195{
4196 queue->dev = dev;
4197}
4198
4199static void netdev_init_queues(struct net_device *dev)
4200{
4201 netdev_init_one_queue(dev, &dev->rx_queue, NULL);
4202 netdev_for_each_tx_queue(dev, netdev_init_one_queue, NULL);
4203}
4204
3980/** 4205/**
3981 * alloc_netdev_mq - allocate network device 4206 * alloc_netdev_mq - allocate network device
3982 * @sizeof_priv: size of private data to allocate space for 4207 * @sizeof_priv: size of private data to allocate space for
@@ -3991,14 +4216,14 @@ static struct net_device_stats *internal_stats(struct net_device *dev)
3991struct net_device *alloc_netdev_mq(int sizeof_priv, const char *name, 4216struct net_device *alloc_netdev_mq(int sizeof_priv, const char *name,
3992 void (*setup)(struct net_device *), unsigned int queue_count) 4217 void (*setup)(struct net_device *), unsigned int queue_count)
3993{ 4218{
3994 void *p; 4219 struct netdev_queue *tx;
3995 struct net_device *dev; 4220 struct net_device *dev;
3996 int alloc_size; 4221 size_t alloc_size;
4222 void *p;
3997 4223
3998 BUG_ON(strlen(name) >= sizeof(dev->name)); 4224 BUG_ON(strlen(name) >= sizeof(dev->name));
3999 4225
4000 alloc_size = sizeof(struct net_device) + 4226 alloc_size = sizeof(struct net_device);
4001 sizeof(struct net_device_subqueue) * (queue_count - 1);
4002 if (sizeof_priv) { 4227 if (sizeof_priv) {
4003 /* ensure 32-byte alignment of private area */ 4228 /* ensure 32-byte alignment of private area */
4004 alloc_size = (alloc_size + NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST; 4229 alloc_size = (alloc_size + NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST;
@@ -4013,22 +4238,33 @@ struct net_device *alloc_netdev_mq(int sizeof_priv, const char *name,
4013 return NULL; 4238 return NULL;
4014 } 4239 }
4015 4240
4241 tx = kcalloc(queue_count, sizeof(struct netdev_queue), GFP_KERNEL);
4242 if (!tx) {
4243 printk(KERN_ERR "alloc_netdev: Unable to allocate "
4244 "tx qdiscs.\n");
4245 kfree(p);
4246 return NULL;
4247 }
4248
4016 dev = (struct net_device *) 4249 dev = (struct net_device *)
4017 (((long)p + NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST); 4250 (((long)p + NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST);
4018 dev->padded = (char *)dev - (char *)p; 4251 dev->padded = (char *)dev - (char *)p;
4019 dev_net_set(dev, &init_net); 4252 dev_net_set(dev, &init_net);
4020 4253
4254 dev->_tx = tx;
4255 dev->num_tx_queues = queue_count;
4256 dev->real_num_tx_queues = queue_count;
4257
4021 if (sizeof_priv) { 4258 if (sizeof_priv) {
4022 dev->priv = ((char *)dev + 4259 dev->priv = ((char *)dev +
4023 ((sizeof(struct net_device) + 4260 ((sizeof(struct net_device) + NETDEV_ALIGN_CONST)
4024 (sizeof(struct net_device_subqueue) *
4025 (queue_count - 1)) + NETDEV_ALIGN_CONST)
4026 & ~NETDEV_ALIGN_CONST)); 4261 & ~NETDEV_ALIGN_CONST));
4027 } 4262 }
4028 4263
4029 dev->egress_subqueue_count = queue_count;
4030 dev->gso_max_size = GSO_MAX_SIZE; 4264 dev->gso_max_size = GSO_MAX_SIZE;
4031 4265
4266 netdev_init_queues(dev);
4267
4032 dev->get_stats = internal_stats; 4268 dev->get_stats = internal_stats;
4033 netpoll_netdev_init(dev); 4269 netpoll_netdev_init(dev);
4034 setup(dev); 4270 setup(dev);
@@ -4049,6 +4285,8 @@ void free_netdev(struct net_device *dev)
4049{ 4285{
4050 release_net(dev_net(dev)); 4286 release_net(dev_net(dev));
4051 4287
4288 kfree(dev->_tx);
4289
4052 /* Compatibility with error handling in drivers */ 4290 /* Compatibility with error handling in drivers */
4053 if (dev->reg_state == NETREG_UNINITIALIZED) { 4291 if (dev->reg_state == NETREG_UNINITIALIZED) {
4054 kfree((char *)dev - dev->padded); 4292 kfree((char *)dev - dev->padded);
@@ -4230,7 +4468,7 @@ static int dev_cpu_callback(struct notifier_block *nfb,
4230 void *ocpu) 4468 void *ocpu)
4231{ 4469{
4232 struct sk_buff **list_skb; 4470 struct sk_buff **list_skb;
4233 struct net_device **list_net; 4471 struct Qdisc **list_net;
4234 struct sk_buff *skb; 4472 struct sk_buff *skb;
4235 unsigned int cpu, oldcpu = (unsigned long)ocpu; 4473 unsigned int cpu, oldcpu = (unsigned long)ocpu;
4236 struct softnet_data *sd, *oldsd; 4474 struct softnet_data *sd, *oldsd;
@@ -4292,7 +4530,7 @@ static void net_dma_rebalance(struct net_dma *net_dma)
4292 i = 0; 4530 i = 0;
4293 cpu = first_cpu(cpu_online_map); 4531 cpu = first_cpu(cpu_online_map);
4294 4532
4295 for_each_cpu_mask(chan_idx, net_dma->channel_mask) { 4533 for_each_cpu_mask_nr(chan_idx, net_dma->channel_mask) {
4296 chan = net_dma->channels[chan_idx]; 4534 chan = net_dma->channels[chan_idx];
4297 4535
4298 n = ((num_online_cpus() / cpus_weight(net_dma->channel_mask)) 4536 n = ((num_online_cpus() / cpus_weight(net_dma->channel_mask))
@@ -4459,6 +4697,26 @@ err_name:
4459 return -ENOMEM; 4697 return -ENOMEM;
4460} 4698}
4461 4699
4700char *netdev_drivername(struct net_device *dev, char *buffer, int len)
4701{
4702 struct device_driver *driver;
4703 struct device *parent;
4704
4705 if (len <= 0 || !buffer)
4706 return buffer;
4707 buffer[0] = 0;
4708
4709 parent = dev->dev.parent;
4710
4711 if (!parent)
4712 return buffer;
4713
4714 driver = parent->driver;
4715 if (driver && driver->name)
4716 strlcpy(buffer, driver->name, len);
4717 return buffer;
4718}
4719
4462static void __net_exit netdev_exit(struct net *net) 4720static void __net_exit netdev_exit(struct net *net)
4463{ 4721{
4464 kfree(net->dev_name_head); 4722 kfree(net->dev_name_head);
@@ -4480,17 +4738,19 @@ static void __net_exit default_device_exit(struct net *net)
4480 rtnl_lock(); 4738 rtnl_lock();
4481 for_each_netdev_safe(net, dev, next) { 4739 for_each_netdev_safe(net, dev, next) {
4482 int err; 4740 int err;
4741 char fb_name[IFNAMSIZ];
4483 4742
4484 /* Ignore unmoveable devices (i.e. loopback) */ 4743 /* Ignore unmoveable devices (i.e. loopback) */
4485 if (dev->features & NETIF_F_NETNS_LOCAL) 4744 if (dev->features & NETIF_F_NETNS_LOCAL)
4486 continue; 4745 continue;
4487 4746
4488 /* Push remaing network devices to init_net */ 4747 /* Push remaing network devices to init_net */
4489 err = dev_change_net_namespace(dev, &init_net, "dev%d"); 4748 snprintf(fb_name, IFNAMSIZ, "dev%d", dev->ifindex);
4749 err = dev_change_net_namespace(dev, &init_net, fb_name);
4490 if (err) { 4750 if (err) {
4491 printk(KERN_WARNING "%s: failed to move %s to init_net: %d\n", 4751 printk(KERN_EMERG "%s: failed to move %s to init_net: %d\n",
4492 __func__, dev->name, err); 4752 __func__, dev->name, err);
4493 unregister_netdevice(dev); 4753 BUG();
4494 } 4754 }
4495 } 4755 }
4496 rtnl_unlock(); 4756 rtnl_unlock();
@@ -4553,8 +4813,8 @@ static int __init net_dev_init(void)
4553 4813
4554 dev_boot_phase = 0; 4814 dev_boot_phase = 0;
4555 4815
4556 open_softirq(NET_TX_SOFTIRQ, net_tx_action, NULL); 4816 open_softirq(NET_TX_SOFTIRQ, net_tx_action);
4557 open_softirq(NET_RX_SOFTIRQ, net_rx_action, NULL); 4817 open_softirq(NET_RX_SOFTIRQ, net_rx_action);
4558 4818
4559 hotcpu_notifier(dev_cpu_callback, 0); 4819 hotcpu_notifier(dev_cpu_callback, 0);
4560 dst_init(); 4820 dst_init();