aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/skbuff.h
diff options
context:
space:
mode:
authorEric Dumazet <edumazet@google.com>2012-05-18 01:12:12 -0400
committerDavid S. Miller <davem@davemloft.net>2012-05-18 13:31:25 -0400
commit6f532612cc2410a5079ea0f83e7a5011adfbf70d (patch)
tree0459fada6287120f5c47ed56c440c4d1c3e3eaa2 /include/linux/skbuff.h
parent56138f50d1900b0c3d8647376e37b488b23ba53d (diff)
net: introduce netdev_alloc_frag()
Fix two issues introduced in commit a1c7fff7e18f5 ( net: netdev_alloc_skb() use build_skb() ) - Must be IRQ safe (non NAPI drivers can use it) - Must not leak the frag if build_skb() fails to allocate sk_buff This patch introduces netdev_alloc_frag() for drivers willing to use build_skb() instead of __netdev_alloc_skb() variants. Factorize code so that : __dev_alloc_skb() is a wrapper around __netdev_alloc_skb(), and dev_alloc_skb() a wrapper around netdev_alloc_skb() Use __GFP_COLD flag. Almost all network drivers now benefit from skb->head_frag infrastructure. Signed-off-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/linux/skbuff.h')
-rw-r--r--include/linux/skbuff.h42
1 files changed, 18 insertions, 24 deletions
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index bb47314c7179..fe37c21d3a60 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -1680,31 +1680,11 @@ static inline void __skb_queue_purge(struct sk_buff_head *list)
1680 kfree_skb(skb); 1680 kfree_skb(skb);
1681} 1681}
1682 1682
1683/** 1683extern void *netdev_alloc_frag(unsigned int fragsz);
1684 * __dev_alloc_skb - allocate an skbuff for receiving
1685 * @length: length to allocate
1686 * @gfp_mask: get_free_pages mask, passed to alloc_skb
1687 *
1688 * Allocate a new &sk_buff and assign it a usage count of one. The
1689 * buffer has unspecified headroom built in. Users should allocate
1690 * the headroom they think they need without accounting for the
1691 * built in space. The built in space is used for optimisations.
1692 *
1693 * %NULL is returned if there is no free memory.
1694 */
1695static inline struct sk_buff *__dev_alloc_skb(unsigned int length,
1696 gfp_t gfp_mask)
1697{
1698 struct sk_buff *skb = alloc_skb(length + NET_SKB_PAD, gfp_mask);
1699 if (likely(skb))
1700 skb_reserve(skb, NET_SKB_PAD);
1701 return skb;
1702}
1703
1704extern struct sk_buff *dev_alloc_skb(unsigned int length);
1705 1684
1706extern struct sk_buff *__netdev_alloc_skb(struct net_device *dev, 1685extern struct sk_buff *__netdev_alloc_skb(struct net_device *dev,
1707 unsigned int length, gfp_t gfp_mask); 1686 unsigned int length,
1687 gfp_t gfp_mask);
1708 1688
1709/** 1689/**
1710 * netdev_alloc_skb - allocate an skbuff for rx on a specific device 1690 * netdev_alloc_skb - allocate an skbuff for rx on a specific device
@@ -1720,11 +1700,25 @@ extern struct sk_buff *__netdev_alloc_skb(struct net_device *dev,
1720 * allocates memory it can be called from an interrupt. 1700 * allocates memory it can be called from an interrupt.
1721 */ 1701 */
1722static inline struct sk_buff *netdev_alloc_skb(struct net_device *dev, 1702static inline struct sk_buff *netdev_alloc_skb(struct net_device *dev,
1723 unsigned int length) 1703 unsigned int length)
1724{ 1704{
1725 return __netdev_alloc_skb(dev, length, GFP_ATOMIC); 1705 return __netdev_alloc_skb(dev, length, GFP_ATOMIC);
1726} 1706}
1727 1707
1708/* legacy helper around __netdev_alloc_skb() */
1709static inline struct sk_buff *__dev_alloc_skb(unsigned int length,
1710 gfp_t gfp_mask)
1711{
1712 return __netdev_alloc_skb(NULL, length, gfp_mask);
1713}
1714
1715/* legacy helper around netdev_alloc_skb() */
1716static inline struct sk_buff *dev_alloc_skb(unsigned int length)
1717{
1718 return netdev_alloc_skb(NULL, length);
1719}
1720
1721
1728static inline struct sk_buff *__netdev_alloc_skb_ip_align(struct net_device *dev, 1722static inline struct sk_buff *__netdev_alloc_skb_ip_align(struct net_device *dev,
1729 unsigned int length, gfp_t gfp) 1723 unsigned int length, gfp_t gfp)
1730{ 1724{