http://lxr.free-electrons.com/source/net/core/dev.c#L18051780 /** 1781 * dev_queue_xmit - transmit a buffer 1782 * @skb: buffer to transmit 1783 * 1784 * Queue a buffer for transmission to a network device. The caller must 1785 * have set the device and priority and built the buffer before calling 1786 * this function. The function can be called from an interrupt. 1787 * 1788 * A negative errno code is returned on a failure. A success does not 1789 * guarantee the frame will be transmitted as it may be dropped due 1790 * to congestion or traffic shaping. 1791 * 1792 * ----------------------------------------------------------------------------------- 1793 * I notice this method can also return errors from the queue disciplines, 1794 * including NET_XMIT_DROP, which is a positive value. So, errors can also 1795 * be positive. 1796 * 1797 * Regardless of the return value, the skb is consumed, so it is currently 1798 * difficult to retry a send to this method. (You can bump the ref count 1799 * before sending to hold a reference for retry if you are careful.) 1800 * 1801 * When calling this method, interrupts MUST be enabled. This is because 1802 * the BH enable code must have IRQs enabled so that it will not deadlock. 1803 * --BLG 1804 */ 1805 int dev_queue_xmit(struct sk_buff *skb) 1806 { 1807 struct net_device *dev = skb->dev; 1808 struct netdev_queue *txq; 1809 struct Qdisc *q; 1810 int rc = -ENOMEM; 1811 1812 /* GSO will handle the following emulations directly. */ 1813 if (netif_needs_gso(dev, skb)) 1814 goto gso; 1815 1816 if (skb_shinfo(skb)->frag_list && 1817 !(dev->features & NETIF_F_FRAGLIST) && 1818 __skb_linearize(skb)) 1819 goto out_kfree_skb; 1820 1821 /* Fragmented skb is linearized if device does not support SG, 1822 * or if at least one of fragments is in highmem and device 1823 * does not support DMA from it. 1824 */ 1825 if (skb_shinfo(skb)->nr_frags && 1826 (!(dev->features & NETIF_F_SG) || illegal_highdma(dev, skb)) && 1827 __skb_linearize(skb)) 1828 goto out_kfree_skb; 1829 1830 /* If packet is not checksummed and device does not support 1831 * checksumming for this protocol, complete checksumming here. 1832 */ 1833 if (skb->ip_summed == CHECKSUM_PARTIAL) { 1834 skb_set_transport_header(skb, skb->csum_start - 1835 skb_headroom(skb)); 1836 if (!dev_can_checksum(dev, skb) && skb_checksum_help(skb)) 1837 goto out_kfree_skb; 1838 } 1839 1840 gso: 1841 /* Disable soft irqs for various locks below. Also 1842 * stops preemption for RCU. 1843 */ 1844 rcu_read_lock_bh(); 1845 1846 txq = dev_pick_tx(dev, skb); 1847 q = rcu_dereference(txq->qdisc); 1848 1849 #ifdef CONFIG_NET_CLS_ACT 1850 skb->tc_verd = SET_TC_AT(skb->tc_verd,AT_EGRESS); 1851 #endif 1852 if (q->enqueue) { 1853 spinlock_t *root_lock = qdisc_lock(q); 1854 1855 spin_lock(root_lock); 1856 1857 if (unlikely(test_bit(__QDISC_STATE_DEACTIVATED, &q->state))) { 1858 kfree_skb(skb); 1859 rc = NET_XMIT_DROP; 1860 } else { 1861 rc = qdisc_enqueue_root(skb, q); 1862 qdisc_run(q); 1863 } 1864 spin_unlock(root_lock); 1865 1866 goto out; 1867 } 1868 1869 /* The device has no queue. Common case for software devices: 1870 loopback, all the sorts of tunnels... 1871 1872 Really, it is unlikely that netif_tx_lock protection is necessary 1873 here. (f.e. loopback and IP tunnels are clean ignoring statistics 1874 counters.) 1875 However, it is possible, that they rely on protection 1876 made by us here. 1877 1878 Check this and shot the lock. It is not prone from deadlocks. 1879 Either shot noqueue qdisc, it is even simpler 8) 1880 */ 1881 if (dev->flags & IFF_UP) { 1882 int cpu = smp_processor_id(); /* ok because BHs are off */ 1883 1884 if (txq->xmit_lock_owner != cpu) { 1885 1886 HARD_TX_LOCK(dev, txq, cpu); 1887 1888 if (!netif_tx_queue_stopped(txq)) { 1889 rc = 0; 1890 if (!dev_hard_start_xmit(skb, dev, txq)) { 1891 HARD_TX_UNLOCK(dev, txq); 1892 goto out; 1893 } 1894 } 1895 HARD_TX_UNLOCK(dev, txq); 1896 if (net_ratelimit()) 1897 printk(KERN_CRIT "Virtual device %s asks to " 1898 "queue packet!\n", dev->name); 1899 } else { 1900 /* Recursion is detected! It is possible, 1901 * unfortunately */ 1902 if (net_ratelimit()) 1903 printk(KERN_CRIT "Dead loop on virtual device " 1904 "%s, fix it urgently!\n", dev->name); 1905 } 1906 } 1907 1908 rc = -ENETDOWN; 1909 rcu_read_unlock_bh(); 1910 1911 out_kfree_skb: 1912 kfree_skb(skb); 1913 return rc; 1914 out: 1915 rcu_read_unlock_bh(); 1916 return rc; 1917 } 1918 |