aboutsummaryrefslogtreecommitdiffstats
path: root/net/core/skbuff.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/core/skbuff.c')
-rw-r--r--net/core/skbuff.c96
1 files changed, 95 insertions, 1 deletions
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 608701339620..4fe605fa6f8a 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -263,6 +263,28 @@ struct sk_buff *__netdev_alloc_skb(struct net_device *dev,
263 return skb; 263 return skb;
264} 264}
265 265
266/**
267 * dev_alloc_skb - allocate an skbuff for receiving
268 * @length: length to allocate
269 *
270 * Allocate a new &sk_buff and assign it a usage count of one. The
271 * buffer has unspecified headroom built in. Users should allocate
272 * the headroom they think they need without accounting for the
273 * built in space. The built in space is used for optimisations.
274 *
275 * %NULL is returned if there is no free memory. Although this function
276 * allocates memory it can be called from an interrupt.
277 */
278struct sk_buff *dev_alloc_skb(unsigned int length)
279{
280 /*
281 * There is more code here than it seems:
282 * __dev_alloc_skb is an inline
283 */
284 return __dev_alloc_skb(length, GFP_ATOMIC);
285}
286EXPORT_SYMBOL(dev_alloc_skb);
287
266static void skb_drop_list(struct sk_buff **listp) 288static void skb_drop_list(struct sk_buff **listp)
267{ 289{
268 struct sk_buff *list = *listp; 290 struct sk_buff *list = *listp;
@@ -857,6 +879,78 @@ free_skb:
857 return err; 879 return err;
858} 880}
859 881
882/**
883 * skb_put - add data to a buffer
884 * @skb: buffer to use
885 * @len: amount of data to add
886 *
887 * This function extends the used data area of the buffer. If this would
888 * exceed the total buffer size the kernel will panic. A pointer to the
889 * first byte of the extra data is returned.
890 */
891unsigned char *skb_put(struct sk_buff *skb, unsigned int len)
892{
893 unsigned char *tmp = skb_tail_pointer(skb);
894 SKB_LINEAR_ASSERT(skb);
895 skb->tail += len;
896 skb->len += len;
897 if (unlikely(skb->tail > skb->end))
898 skb_over_panic(skb, len, __builtin_return_address(0));
899 return tmp;
900}
901EXPORT_SYMBOL(skb_put);
902
903/**
904 * skb_push - add data to the start of a buffer
905 * @skb: buffer to use
906 * @len: amount of data to add
907 *
908 * This function extends the used data area of the buffer at the buffer
909 * start. If this would exceed the total buffer headroom the kernel will
910 * panic. A pointer to the first byte of the extra data is returned.
911 */
912unsigned char *skb_push(struct sk_buff *skb, unsigned int len)
913{
914 skb->data -= len;
915 skb->len += len;
916 if (unlikely(skb->data<skb->head))
917 skb_under_panic(skb, len, __builtin_return_address(0));
918 return skb->data;
919}
920EXPORT_SYMBOL(skb_push);
921
922/**
923 * skb_pull - remove data from the start of a buffer
924 * @skb: buffer to use
925 * @len: amount of data to remove
926 *
927 * This function removes data from the start of a buffer, returning
928 * the memory to the headroom. A pointer to the next data in the buffer
929 * is returned. Once the data has been pulled future pushes will overwrite
930 * the old data.
931 */
932unsigned char *skb_pull(struct sk_buff *skb, unsigned int len)
933{
934 return unlikely(len > skb->len) ? NULL : __skb_pull(skb, len);
935}
936EXPORT_SYMBOL(skb_pull);
937
938/**
939 * skb_trim - remove end from a buffer
940 * @skb: buffer to alter
941 * @len: new length
942 *
943 * Cut the length of a buffer down by removing data from the tail. If
944 * the buffer is already under the length specified it is not modified.
945 * The skb must be linear.
946 */
947void skb_trim(struct sk_buff *skb, unsigned int len)
948{
949 if (skb->len > len)
950 __skb_trim(skb, len);
951}
952EXPORT_SYMBOL(skb_trim);
953
860/* Trims skb to length len. It can change skb pointers. 954/* Trims skb to length len. It can change skb pointers.
861 */ 955 */
862 956
@@ -1766,7 +1860,7 @@ void skb_append(struct sk_buff *old, struct sk_buff *newsk, struct sk_buff_head
1766 unsigned long flags; 1860 unsigned long flags;
1767 1861
1768 spin_lock_irqsave(&list->lock, flags); 1862 spin_lock_irqsave(&list->lock, flags);
1769 __skb_append(old, newsk, list); 1863 __skb_queue_after(list, old, newsk);
1770 spin_unlock_irqrestore(&list->lock, flags); 1864 spin_unlock_irqrestore(&list->lock, flags);
1771} 1865}
1772 1866