2 * Routines having to do with the 'struct sk_buff' memory handlers.
4 * Authors: Alan Cox <iiitac@pyr.swan.ac.uk>
5 * Florian La Roche <rzsfl@rz.uni-sb.de>
7 * Version: $Id: skbuff.c,v 1.90 2001/11/07 05:56:19 davem Exp $
10 * Alan Cox : Fixed the worst of the load
12 * Dave Platt : Interrupt stacking fix.
13 * Richard Kooijman : Timestamp fixes.
14 * Alan Cox : Changed buffer format.
15 * Alan Cox : destructor hook for AF_UNIX etc.
16 * Linus Torvalds : Better skb_clone.
17 * Alan Cox : Added skb_copy.
18 * Alan Cox : Added all the changed routines Linus
19 * only put in the headers
20 * Ray VanTassle : Fixed --skb->lock in free
21 * Alan Cox : skb_copy copy arp field
22 * Andi Kleen : slabified it.
23 * Robert Olsson : Removed skb_head_pool
26 * The __skb_ routines should be called with interrupts
27 * disabled, or you better be *real* sure that the operation is atomic
28 * with respect to whatever list is being frobbed (e.g. via lock_sock()
29 * or via disabling bottom half handlers, etc).
31 * This program is free software; you can redistribute it and/or
32 * modify it under the terms of the GNU General Public License
33 * as published by the Free Software Foundation; either version
34 * 2 of the License, or (at your option) any later version.
38 * The functions in this file will not compile correctly with gcc 2.4.x
41 #include <linux/config.h>
42 #include <linux/module.h>
43 #include <linux/types.h>
44 #include <linux/kernel.h>
45 #include <linux/sched.h>
47 #include <linux/interrupt.h>
49 #include <linux/inet.h>
50 #include <linux/slab.h>
51 #include <linux/netdevice.h>
52 #ifdef CONFIG_NET_CLS_ACT
53 #include <net/pkt_sched.h>
55 #include <linux/string.h>
56 #include <linux/skbuff.h>
57 #include <linux/cache.h>
58 #include <linux/rtnetlink.h>
59 #include <linux/init.h>
60 #include <linux/highmem.h>
62 #include <net/protocol.h>
65 #include <net/checksum.h>
68 #include <asm/uaccess.h>
69 #include <asm/system.h>
71 static kmem_cache_t
*skbuff_head_cache __read_mostly
;
72 static kmem_cache_t
*skbuff_fclone_cache __read_mostly
;
75 * Keep out-of-line to prevent kernel bloat.
76 * __builtin_return_address is not used because it is not always
81 * skb_over_panic - private function
86 * Out of line support code for skb_put(). Not user callable.
88 void skb_over_panic(struct sk_buff
*skb
, int sz
, void *here
)
90 printk(KERN_EMERG
"skb_over_panic: text:%p len:%d put:%d head:%p "
91 "data:%p tail:%p end:%p dev:%s\n",
92 here
, skb
->len
, sz
, skb
->head
, skb
->data
, skb
->tail
, skb
->end
,
93 skb
->dev
? skb
->dev
->name
: "<NULL>");
98 * skb_under_panic - private function
103 * Out of line support code for skb_push(). Not user callable.
106 void skb_under_panic(struct sk_buff
*skb
, int sz
, void *here
)
108 printk(KERN_EMERG
"skb_under_panic: text:%p len:%d put:%d head:%p "
109 "data:%p tail:%p end:%p dev:%s\n",
110 here
, skb
->len
, sz
, skb
->head
, skb
->data
, skb
->tail
, skb
->end
,
111 skb
->dev
? skb
->dev
->name
: "<NULL>");
115 /* Allocate a new skbuff. We do this ourselves so we can fill in a few
116 * 'private' fields and also do memory statistics to find all the
122 * __alloc_skb - allocate a network buffer
123 * @size: size to allocate
124 * @gfp_mask: allocation mask
125 * @fclone: allocate from fclone cache instead of head cache
126 * and allocate a cloned (child) skb
128 * Allocate a new &sk_buff. The returned buffer has no headroom and a
129 * tail room of size bytes. The object has a reference count of one.
130 * The return is the buffer. On a failure the return is %NULL.
132 * Buffers may only be allocated from interrupts using a @gfp_mask of
135 struct sk_buff
*__alloc_skb(unsigned int size
, gfp_t gfp_mask
,
139 struct skb_shared_info
*shinfo
;
143 cache
= fclone
? skbuff_fclone_cache
: skbuff_head_cache
;
146 skb
= kmem_cache_alloc(cache
, gfp_mask
& ~__GFP_DMA
);
150 /* Get the DATA. Size must match skb_add_mtu(). */
151 size
= SKB_DATA_ALIGN(size
);
152 data
= kmalloc(size
+ sizeof(struct skb_shared_info
), gfp_mask
);
156 memset(skb
, 0, offsetof(struct sk_buff
, truesize
));
157 skb
->truesize
= size
+ sizeof(struct sk_buff
);
158 atomic_set(&skb
->users
, 1);
162 skb
->end
= data
+ size
;
163 /* make sure we initialize shinfo sequentially */
164 shinfo
= skb_shinfo(skb
);
165 atomic_set(&shinfo
->dataref
, 1);
166 shinfo
->nr_frags
= 0;
167 shinfo
->tso_size
= 0;
168 shinfo
->tso_segs
= 0;
169 shinfo
->ufo_size
= 0;
170 shinfo
->ip6_frag_id
= 0;
171 shinfo
->frag_list
= NULL
;
174 struct sk_buff
*child
= skb
+ 1;
175 atomic_t
*fclone_ref
= (atomic_t
*) (child
+ 1);
177 skb
->fclone
= SKB_FCLONE_ORIG
;
178 atomic_set(fclone_ref
, 1);
180 child
->fclone
= SKB_FCLONE_UNAVAILABLE
;
185 kmem_cache_free(cache
, skb
);
191 * alloc_skb_from_cache - allocate a network buffer
192 * @cp: kmem_cache from which to allocate the data area
193 * (object size must be big enough for @size bytes + skb overheads)
194 * @size: size to allocate
195 * @gfp_mask: allocation mask
197 * Allocate a new &sk_buff. The returned buffer has no headroom and
198 * tail room of size bytes. The object has a reference count of one.
199 * The return is the buffer. On a failure the return is %NULL.
201 * Buffers may only be allocated from interrupts using a @gfp_mask of
204 struct sk_buff
*alloc_skb_from_cache(kmem_cache_t
*cp
,
212 skb
= kmem_cache_alloc(skbuff_head_cache
,
213 gfp_mask
& ~__GFP_DMA
);
218 size
= SKB_DATA_ALIGN(size
);
219 data
= kmem_cache_alloc(cp
, gfp_mask
);
223 memset(skb
, 0, offsetof(struct sk_buff
, truesize
));
224 skb
->truesize
= size
+ sizeof(struct sk_buff
);
225 atomic_set(&skb
->users
, 1);
229 skb
->end
= data
+ size
;
231 atomic_set(&(skb_shinfo(skb
)->dataref
), 1);
232 skb_shinfo(skb
)->nr_frags
= 0;
233 skb_shinfo(skb
)->tso_size
= 0;
234 skb_shinfo(skb
)->tso_segs
= 0;
235 skb_shinfo(skb
)->frag_list
= NULL
;
239 kmem_cache_free(skbuff_head_cache
, skb
);
245 static void skb_drop_fraglist(struct sk_buff
*skb
)
247 struct sk_buff
*list
= skb_shinfo(skb
)->frag_list
;
249 skb_shinfo(skb
)->frag_list
= NULL
;
252 struct sk_buff
*this = list
;
258 static void skb_clone_fraglist(struct sk_buff
*skb
)
260 struct sk_buff
*list
;
262 for (list
= skb_shinfo(skb
)->frag_list
; list
; list
= list
->next
)
266 void skb_release_data(struct sk_buff
*skb
)
269 !atomic_sub_return(skb
->nohdr
? (1 << SKB_DATAREF_SHIFT
) + 1 : 1,
270 &skb_shinfo(skb
)->dataref
)) {
271 if (skb_shinfo(skb
)->nr_frags
) {
273 for (i
= 0; i
< skb_shinfo(skb
)->nr_frags
; i
++)
274 put_page(skb_shinfo(skb
)->frags
[i
].page
);
277 if (skb_shinfo(skb
)->frag_list
)
278 skb_drop_fraglist(skb
);
285 * Free an skbuff by memory without cleaning the state.
287 void kfree_skbmem(struct sk_buff
*skb
)
289 struct sk_buff
*other
;
290 atomic_t
*fclone_ref
;
292 skb_release_data(skb
);
293 switch (skb
->fclone
) {
294 case SKB_FCLONE_UNAVAILABLE
:
295 kmem_cache_free(skbuff_head_cache
, skb
);
298 case SKB_FCLONE_ORIG
:
299 fclone_ref
= (atomic_t
*) (skb
+ 2);
300 if (atomic_dec_and_test(fclone_ref
))
301 kmem_cache_free(skbuff_fclone_cache
, skb
);
304 case SKB_FCLONE_CLONE
:
305 fclone_ref
= (atomic_t
*) (skb
+ 1);
308 /* The clone portion is available for
309 * fast-cloning again.
311 skb
->fclone
= SKB_FCLONE_UNAVAILABLE
;
313 if (atomic_dec_and_test(fclone_ref
))
314 kmem_cache_free(skbuff_fclone_cache
, other
);
320 * __kfree_skb - private function
323 * Free an sk_buff. Release anything attached to the buffer.
324 * Clean the state. This is an internal helper function. Users should
325 * always call kfree_skb
328 void __kfree_skb(struct sk_buff
*skb
)
330 dst_release(skb
->dst
);
332 secpath_put(skb
->sp
);
334 if (skb
->destructor
) {
336 skb
->destructor(skb
);
338 #ifdef CONFIG_NETFILTER
339 nf_conntrack_put(skb
->nfct
);
340 #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
341 nf_conntrack_put_reasm(skb
->nfct_reasm
);
343 #ifdef CONFIG_BRIDGE_NETFILTER
344 nf_bridge_put(skb
->nf_bridge
);
347 /* XXX: IS this still necessary? - JHS */
348 #ifdef CONFIG_NET_SCHED
350 #ifdef CONFIG_NET_CLS_ACT
359 * kfree_skb - free an sk_buff
360 * @skb: buffer to free
362 * Drop a reference to the buffer and free it if the usage count has
365 void kfree_skb(struct sk_buff
*skb
)
369 if (likely(atomic_read(&skb
->users
) == 1))
371 else if (likely(!atomic_dec_and_test(&skb
->users
)))
377 * skb_clone - duplicate an sk_buff
378 * @skb: buffer to clone
379 * @gfp_mask: allocation priority
381 * Duplicate an &sk_buff. The new one is not owned by a socket. Both
382 * copies share the same packet data but not structure. The new
383 * buffer has a reference count of 1. If the allocation fails the
384 * function returns %NULL otherwise the new buffer is returned.
386 * If this function is called from an interrupt gfp_mask() must be
390 struct sk_buff
*skb_clone(struct sk_buff
*skb
, gfp_t gfp_mask
)
395 if (skb
->fclone
== SKB_FCLONE_ORIG
&&
396 n
->fclone
== SKB_FCLONE_UNAVAILABLE
) {
397 atomic_t
*fclone_ref
= (atomic_t
*) (n
+ 1);
398 n
->fclone
= SKB_FCLONE_CLONE
;
399 atomic_inc(fclone_ref
);
401 n
= kmem_cache_alloc(skbuff_head_cache
, gfp_mask
);
404 n
->fclone
= SKB_FCLONE_UNAVAILABLE
;
407 #define C(x) n->x = skb->x
409 n
->next
= n
->prev
= NULL
;
420 secpath_get(skb
->sp
);
422 memcpy(n
->cb
, skb
->cb
, sizeof(skb
->cb
));
432 #if defined(CONFIG_IP_VS) || defined(CONFIG_IP_VS_MODULE)
436 n
->destructor
= NULL
;
437 #ifdef CONFIG_NETFILTER
440 nf_conntrack_get(skb
->nfct
);
442 #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
444 nf_conntrack_get_reasm(skb
->nfct_reasm
);
446 #ifdef CONFIG_BRIDGE_NETFILTER
448 nf_bridge_get(skb
->nf_bridge
);
450 #endif /*CONFIG_NETFILTER*/
451 #ifdef CONFIG_NET_SCHED
453 #ifdef CONFIG_NET_CLS_ACT
454 n
->tc_verd
= SET_TC_VERD(skb
->tc_verd
,0);
455 n
->tc_verd
= CLR_TC_OK2MUNGE(n
->tc_verd
);
456 n
->tc_verd
= CLR_TC_MUNGED(n
->tc_verd
);
462 atomic_set(&n
->users
, 1);
468 atomic_inc(&(skb_shinfo(skb
)->dataref
));
474 static void copy_skb_header(struct sk_buff
*new, const struct sk_buff
*old
)
477 * Shift between the two data areas in bytes
479 unsigned long offset
= new->data
- old
->data
;
483 new->priority
= old
->priority
;
484 new->protocol
= old
->protocol
;
485 new->dst
= dst_clone(old
->dst
);
487 new->sp
= secpath_get(old
->sp
);
489 new->h
.raw
= old
->h
.raw
+ offset
;
490 new->nh
.raw
= old
->nh
.raw
+ offset
;
491 new->mac
.raw
= old
->mac
.raw
+ offset
;
492 memcpy(new->cb
, old
->cb
, sizeof(old
->cb
));
493 new->local_df
= old
->local_df
;
494 new->fclone
= SKB_FCLONE_UNAVAILABLE
;
495 new->pkt_type
= old
->pkt_type
;
496 new->tstamp
= old
->tstamp
;
497 new->destructor
= NULL
;
498 #ifdef CONFIG_NETFILTER
499 new->nfmark
= old
->nfmark
;
500 new->nfct
= old
->nfct
;
501 nf_conntrack_get(old
->nfct
);
502 new->nfctinfo
= old
->nfctinfo
;
503 #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
504 new->nfct_reasm
= old
->nfct_reasm
;
505 nf_conntrack_get_reasm(old
->nfct_reasm
);
507 #if defined(CONFIG_IP_VS) || defined(CONFIG_IP_VS_MODULE)
508 new->ipvs_property
= old
->ipvs_property
;
510 #ifdef CONFIG_BRIDGE_NETFILTER
511 new->nf_bridge
= old
->nf_bridge
;
512 nf_bridge_get(old
->nf_bridge
);
515 #ifdef CONFIG_NET_SCHED
516 #ifdef CONFIG_NET_CLS_ACT
517 new->tc_verd
= old
->tc_verd
;
519 new->tc_index
= old
->tc_index
;
521 atomic_set(&new->users
, 1);
522 skb_shinfo(new)->tso_size
= skb_shinfo(old
)->tso_size
;
523 skb_shinfo(new)->tso_segs
= skb_shinfo(old
)->tso_segs
;
527 * skb_copy - create private copy of an sk_buff
528 * @skb: buffer to copy
529 * @gfp_mask: allocation priority
531 * Make a copy of both an &sk_buff and its data. This is used when the
532 * caller wishes to modify the data and needs a private copy of the
533 * data to alter. Returns %NULL on failure or the pointer to the buffer
534 * on success. The returned buffer has a reference count of 1.
536 * As by-product this function converts non-linear &sk_buff to linear
537 * one, so that &sk_buff becomes completely private and caller is allowed
538 * to modify all the data of returned buffer. This means that this
539 * function is not recommended for use in circumstances when only
540 * header is going to be modified. Use pskb_copy() instead.
543 struct sk_buff
*skb_copy(const struct sk_buff
*skb
, gfp_t gfp_mask
)
545 int headerlen
= skb
->data
- skb
->head
;
547 * Allocate the copy buffer
549 struct sk_buff
*n
= alloc_skb(skb
->end
- skb
->head
+ skb
->data_len
,
554 /* Set the data pointer */
555 skb_reserve(n
, headerlen
);
556 /* Set the tail pointer and length */
557 skb_put(n
, skb
->len
);
559 n
->ip_summed
= skb
->ip_summed
;
561 if (skb_copy_bits(skb
, -headerlen
, n
->head
, headerlen
+ skb
->len
))
564 copy_skb_header(n
, skb
);
570 * pskb_copy - create copy of an sk_buff with private head.
571 * @skb: buffer to copy
572 * @gfp_mask: allocation priority
574 * Make a copy of both an &sk_buff and part of its data, located
575 * in header. Fragmented data remain shared. This is used when
576 * the caller wishes to modify only header of &sk_buff and needs
577 * private copy of the header to alter. Returns %NULL on failure
578 * or the pointer to the buffer on success.
579 * The returned buffer has a reference count of 1.
582 struct sk_buff
*pskb_copy(struct sk_buff
*skb
, gfp_t gfp_mask
)
585 * Allocate the copy buffer
587 struct sk_buff
*n
= alloc_skb(skb
->end
- skb
->head
, gfp_mask
);
592 /* Set the data pointer */
593 skb_reserve(n
, skb
->data
- skb
->head
);
594 /* Set the tail pointer and length */
595 skb_put(n
, skb_headlen(skb
));
597 memcpy(n
->data
, skb
->data
, n
->len
);
599 n
->ip_summed
= skb
->ip_summed
;
601 n
->data_len
= skb
->data_len
;
604 if (skb_shinfo(skb
)->nr_frags
) {
607 for (i
= 0; i
< skb_shinfo(skb
)->nr_frags
; i
++) {
608 skb_shinfo(n
)->frags
[i
] = skb_shinfo(skb
)->frags
[i
];
609 get_page(skb_shinfo(n
)->frags
[i
].page
);
611 skb_shinfo(n
)->nr_frags
= i
;
614 if (skb_shinfo(skb
)->frag_list
) {
615 skb_shinfo(n
)->frag_list
= skb_shinfo(skb
)->frag_list
;
616 skb_clone_fraglist(n
);
619 copy_skb_header(n
, skb
);
625 * pskb_expand_head - reallocate header of &sk_buff
626 * @skb: buffer to reallocate
627 * @nhead: room to add at head
628 * @ntail: room to add at tail
629 * @gfp_mask: allocation priority
631 * Expands (or creates identical copy, if &nhead and &ntail are zero)
632 * header of skb. &sk_buff itself is not changed. &sk_buff MUST have
633 * reference count of 1. Returns zero in the case of success or error,
634 * if expansion failed. In the last case, &sk_buff is not changed.
636 * All the pointers pointing into skb header may change and must be
637 * reloaded after call to this function.
640 int pskb_expand_head(struct sk_buff
*skb
, int nhead
, int ntail
,
645 int size
= nhead
+ (skb
->end
- skb
->head
) + ntail
;
651 size
= SKB_DATA_ALIGN(size
);
653 data
= kmalloc(size
+ sizeof(struct skb_shared_info
), gfp_mask
);
657 /* Copy only real data... and, alas, header. This should be
658 * optimized for the cases when header is void. */
659 memcpy(data
+ nhead
, skb
->head
, skb
->tail
- skb
->head
);
660 memcpy(data
+ size
, skb
->end
, sizeof(struct skb_shared_info
));
662 for (i
= 0; i
< skb_shinfo(skb
)->nr_frags
; i
++)
663 get_page(skb_shinfo(skb
)->frags
[i
].page
);
665 if (skb_shinfo(skb
)->frag_list
)
666 skb_clone_fraglist(skb
);
668 skb_release_data(skb
);
670 off
= (data
+ nhead
) - skb
->head
;
673 skb
->end
= data
+ size
;
681 atomic_set(&skb_shinfo(skb
)->dataref
, 1);
688 /* Make private copy of skb with writable head and some headroom */
690 struct sk_buff
*skb_realloc_headroom(struct sk_buff
*skb
, unsigned int headroom
)
692 struct sk_buff
*skb2
;
693 int delta
= headroom
- skb_headroom(skb
);
696 skb2
= pskb_copy(skb
, GFP_ATOMIC
);
698 skb2
= skb_clone(skb
, GFP_ATOMIC
);
699 if (skb2
&& pskb_expand_head(skb2
, SKB_DATA_ALIGN(delta
), 0,
710 * skb_copy_expand - copy and expand sk_buff
711 * @skb: buffer to copy
712 * @newheadroom: new free bytes at head
713 * @newtailroom: new free bytes at tail
714 * @gfp_mask: allocation priority
716 * Make a copy of both an &sk_buff and its data and while doing so
717 * allocate additional space.
719 * This is used when the caller wishes to modify the data and needs a
720 * private copy of the data to alter as well as more space for new fields.
721 * Returns %NULL on failure or the pointer to the buffer
722 * on success. The returned buffer has a reference count of 1.
724 * You must pass %GFP_ATOMIC as the allocation priority if this function
725 * is called from an interrupt.
727 * BUG ALERT: ip_summed is not copied. Why does this work? Is it used
728 * only by netfilter in the cases when checksum is recalculated? --ANK
730 struct sk_buff
*skb_copy_expand(const struct sk_buff
*skb
,
731 int newheadroom
, int newtailroom
,
735 * Allocate the copy buffer
737 struct sk_buff
*n
= alloc_skb(newheadroom
+ skb
->len
+ newtailroom
,
739 int head_copy_len
, head_copy_off
;
744 skb_reserve(n
, newheadroom
);
746 /* Set the tail pointer and length */
747 skb_put(n
, skb
->len
);
749 head_copy_len
= skb_headroom(skb
);
751 if (newheadroom
<= head_copy_len
)
752 head_copy_len
= newheadroom
;
754 head_copy_off
= newheadroom
- head_copy_len
;
756 /* Copy the linear header and data. */
757 if (skb_copy_bits(skb
, -head_copy_len
, n
->head
+ head_copy_off
,
758 skb
->len
+ head_copy_len
))
761 copy_skb_header(n
, skb
);
767 * skb_pad - zero pad the tail of an skb
768 * @skb: buffer to pad
771 * Ensure that a buffer is followed by a padding area that is zero
772 * filled. Used by network drivers which may DMA or transfer data
773 * beyond the buffer end onto the wire.
775 * May return NULL in out of memory cases.
778 struct sk_buff
*skb_pad(struct sk_buff
*skb
, int pad
)
780 struct sk_buff
*nskb
;
782 /* If the skbuff is non linear tailroom is always zero.. */
783 if (skb_tailroom(skb
) >= pad
) {
784 memset(skb
->data
+skb
->len
, 0, pad
);
788 nskb
= skb_copy_expand(skb
, skb_headroom(skb
), skb_tailroom(skb
) + pad
, GFP_ATOMIC
);
791 memset(nskb
->data
+nskb
->len
, 0, pad
);
795 /* Trims skb to length len. It can change skb pointers, if "realloc" is 1.
796 * If realloc==0 and trimming is impossible without change of data,
800 int ___pskb_trim(struct sk_buff
*skb
, unsigned int len
, int realloc
)
802 int offset
= skb_headlen(skb
);
803 int nfrags
= skb_shinfo(skb
)->nr_frags
;
806 for (i
= 0; i
< nfrags
; i
++) {
807 int end
= offset
+ skb_shinfo(skb
)->frags
[i
].size
;
809 if (skb_cloned(skb
)) {
811 if (pskb_expand_head(skb
, 0, 0, GFP_ATOMIC
))
815 put_page(skb_shinfo(skb
)->frags
[i
].page
);
816 skb_shinfo(skb
)->nr_frags
--;
818 skb_shinfo(skb
)->frags
[i
].size
= len
- offset
;
825 skb
->data_len
-= skb
->len
- len
;
828 if (len
<= skb_headlen(skb
)) {
831 skb
->tail
= skb
->data
+ len
;
832 if (skb_shinfo(skb
)->frag_list
&& !skb_cloned(skb
))
833 skb_drop_fraglist(skb
);
835 skb
->data_len
-= skb
->len
- len
;
844 * __pskb_pull_tail - advance tail of skb header
845 * @skb: buffer to reallocate
846 * @delta: number of bytes to advance tail
848 * The function makes a sense only on a fragmented &sk_buff,
849 * it expands header moving its tail forward and copying necessary
850 * data from fragmented part.
852 * &sk_buff MUST have reference count of 1.
854 * Returns %NULL (and &sk_buff does not change) if pull failed
855 * or value of new tail of skb in the case of success.
857 * All the pointers pointing into skb header may change and must be
858 * reloaded after call to this function.
861 /* Moves tail of skb head forward, copying data from fragmented part,
862 * when it is necessary.
863 * 1. It may fail due to malloc failure.
864 * 2. It may change skb pointers.
866 * It is pretty complicated. Luckily, it is called only in exceptional cases.
868 unsigned char *__pskb_pull_tail(struct sk_buff
*skb
, int delta
)
870 /* If skb has not enough free space at tail, get new one
871 * plus 128 bytes for future expansions. If we have enough
872 * room at tail, reallocate without expansion only if skb is cloned.
874 int i
, k
, eat
= (skb
->tail
+ delta
) - skb
->end
;
876 if (eat
> 0 || skb_cloned(skb
)) {
877 if (pskb_expand_head(skb
, 0, eat
> 0 ? eat
+ 128 : 0,
882 if (skb_copy_bits(skb
, skb_headlen(skb
), skb
->tail
, delta
))
885 /* Optimization: no fragments, no reasons to preestimate
886 * size of pulled pages. Superb.
888 if (!skb_shinfo(skb
)->frag_list
)
891 /* Estimate size of pulled pages. */
893 for (i
= 0; i
< skb_shinfo(skb
)->nr_frags
; i
++) {
894 if (skb_shinfo(skb
)->frags
[i
].size
>= eat
)
896 eat
-= skb_shinfo(skb
)->frags
[i
].size
;
899 /* If we need update frag list, we are in troubles.
900 * Certainly, it possible to add an offset to skb data,
901 * but taking into account that pulling is expected to
902 * be very rare operation, it is worth to fight against
903 * further bloating skb head and crucify ourselves here instead.
904 * Pure masohism, indeed. 8)8)
907 struct sk_buff
*list
= skb_shinfo(skb
)->frag_list
;
908 struct sk_buff
*clone
= NULL
;
909 struct sk_buff
*insp
= NULL
;
914 if (list
->len
<= eat
) {
915 /* Eaten as whole. */
920 /* Eaten partially. */
922 if (skb_shared(list
)) {
923 /* Sucks! We need to fork list. :-( */
924 clone
= skb_clone(list
, GFP_ATOMIC
);
930 /* This may be pulled without
934 if (!pskb_pull(list
, eat
)) {
943 /* Free pulled out fragments. */
944 while ((list
= skb_shinfo(skb
)->frag_list
) != insp
) {
945 skb_shinfo(skb
)->frag_list
= list
->next
;
948 /* And insert new clone at head. */
951 skb_shinfo(skb
)->frag_list
= clone
;
954 /* Success! Now we may commit changes to skb data. */
959 for (i
= 0; i
< skb_shinfo(skb
)->nr_frags
; i
++) {
960 if (skb_shinfo(skb
)->frags
[i
].size
<= eat
) {
961 put_page(skb_shinfo(skb
)->frags
[i
].page
);
962 eat
-= skb_shinfo(skb
)->frags
[i
].size
;
964 skb_shinfo(skb
)->frags
[k
] = skb_shinfo(skb
)->frags
[i
];
966 skb_shinfo(skb
)->frags
[k
].page_offset
+= eat
;
967 skb_shinfo(skb
)->frags
[k
].size
-= eat
;
973 skb_shinfo(skb
)->nr_frags
= k
;
976 skb
->data_len
-= delta
;
981 /* Copy some data bits from skb to kernel buffer. */
983 int skb_copy_bits(const struct sk_buff
*skb
, int offset
, void *to
, int len
)
986 int start
= skb_headlen(skb
);
988 if (offset
> (int)skb
->len
- len
)
992 if ((copy
= start
- offset
) > 0) {
995 memcpy(to
, skb
->data
+ offset
, copy
);
996 if ((len
-= copy
) == 0)
1002 for (i
= 0; i
< skb_shinfo(skb
)->nr_frags
; i
++) {
1005 BUG_TRAP(start
<= offset
+ len
);
1007 end
= start
+ skb_shinfo(skb
)->frags
[i
].size
;
1008 if ((copy
= end
- offset
) > 0) {
1014 vaddr
= kmap_skb_frag(&skb_shinfo(skb
)->frags
[i
]);
1016 vaddr
+ skb_shinfo(skb
)->frags
[i
].page_offset
+
1017 offset
- start
, copy
);
1018 kunmap_skb_frag(vaddr
);
1020 if ((len
-= copy
) == 0)
1028 if (skb_shinfo(skb
)->frag_list
) {
1029 struct sk_buff
*list
= skb_shinfo(skb
)->frag_list
;
1031 for (; list
; list
= list
->next
) {
1034 BUG_TRAP(start
<= offset
+ len
);
1036 end
= start
+ list
->len
;
1037 if ((copy
= end
- offset
) > 0) {
1040 if (skb_copy_bits(list
, offset
- start
,
1043 if ((len
-= copy
) == 0)
1059 * skb_store_bits - store bits from kernel buffer to skb
1060 * @skb: destination buffer
1061 * @offset: offset in destination
1062 * @from: source buffer
1063 * @len: number of bytes to copy
1065 * Copy the specified number of bytes from the source buffer to the
1066 * destination skb. This function handles all the messy bits of
1067 * traversing fragment lists and such.
1070 int skb_store_bits(const struct sk_buff
*skb
, int offset
, void *from
, int len
)
1073 int start
= skb_headlen(skb
);
1075 if (offset
> (int)skb
->len
- len
)
1078 if ((copy
= start
- offset
) > 0) {
1081 memcpy(skb
->data
+ offset
, from
, copy
);
1082 if ((len
-= copy
) == 0)
1088 for (i
= 0; i
< skb_shinfo(skb
)->nr_frags
; i
++) {
1089 skb_frag_t
*frag
= &skb_shinfo(skb
)->frags
[i
];
1092 BUG_TRAP(start
<= offset
+ len
);
1094 end
= start
+ frag
->size
;
1095 if ((copy
= end
- offset
) > 0) {
1101 vaddr
= kmap_skb_frag(frag
);
1102 memcpy(vaddr
+ frag
->page_offset
+ offset
- start
,
1104 kunmap_skb_frag(vaddr
);
1106 if ((len
-= copy
) == 0)
1114 if (skb_shinfo(skb
)->frag_list
) {
1115 struct sk_buff
*list
= skb_shinfo(skb
)->frag_list
;
1117 for (; list
; list
= list
->next
) {
1120 BUG_TRAP(start
<= offset
+ len
);
1122 end
= start
+ list
->len
;
1123 if ((copy
= end
- offset
) > 0) {
1126 if (skb_store_bits(list
, offset
- start
,
1129 if ((len
-= copy
) == 0)
1144 EXPORT_SYMBOL(skb_store_bits
);
1146 /* Checksum skb data. */
1148 unsigned int skb_checksum(const struct sk_buff
*skb
, int offset
,
1149 int len
, unsigned int csum
)
1151 int start
= skb_headlen(skb
);
1152 int i
, copy
= start
- offset
;
1155 /* Checksum header. */
1159 csum
= csum_partial(skb
->data
+ offset
, copy
, csum
);
1160 if ((len
-= copy
) == 0)
1166 for (i
= 0; i
< skb_shinfo(skb
)->nr_frags
; i
++) {
1169 BUG_TRAP(start
<= offset
+ len
);
1171 end
= start
+ skb_shinfo(skb
)->frags
[i
].size
;
1172 if ((copy
= end
- offset
) > 0) {
1175 skb_frag_t
*frag
= &skb_shinfo(skb
)->frags
[i
];
1179 vaddr
= kmap_skb_frag(frag
);
1180 csum2
= csum_partial(vaddr
+ frag
->page_offset
+
1181 offset
- start
, copy
, 0);
1182 kunmap_skb_frag(vaddr
);
1183 csum
= csum_block_add(csum
, csum2
, pos
);
1192 if (skb_shinfo(skb
)->frag_list
) {
1193 struct sk_buff
*list
= skb_shinfo(skb
)->frag_list
;
1195 for (; list
; list
= list
->next
) {
1198 BUG_TRAP(start
<= offset
+ len
);
1200 end
= start
+ list
->len
;
1201 if ((copy
= end
- offset
) > 0) {
1205 csum2
= skb_checksum(list
, offset
- start
,
1207 csum
= csum_block_add(csum
, csum2
, pos
);
1208 if ((len
-= copy
) == 0)
1221 /* Both of above in one bottle. */
1223 unsigned int skb_copy_and_csum_bits(const struct sk_buff
*skb
, int offset
,
1224 u8
*to
, int len
, unsigned int csum
)
1226 int start
= skb_headlen(skb
);
1227 int i
, copy
= start
- offset
;
1234 csum
= csum_partial_copy_nocheck(skb
->data
+ offset
, to
,
1236 if ((len
-= copy
) == 0)
1243 for (i
= 0; i
< skb_shinfo(skb
)->nr_frags
; i
++) {
1246 BUG_TRAP(start
<= offset
+ len
);
1248 end
= start
+ skb_shinfo(skb
)->frags
[i
].size
;
1249 if ((copy
= end
- offset
) > 0) {
1252 skb_frag_t
*frag
= &skb_shinfo(skb
)->frags
[i
];
1256 vaddr
= kmap_skb_frag(frag
);
1257 csum2
= csum_partial_copy_nocheck(vaddr
+
1261 kunmap_skb_frag(vaddr
);
1262 csum
= csum_block_add(csum
, csum2
, pos
);
1272 if (skb_shinfo(skb
)->frag_list
) {
1273 struct sk_buff
*list
= skb_shinfo(skb
)->frag_list
;
1275 for (; list
; list
= list
->next
) {
1279 BUG_TRAP(start
<= offset
+ len
);
1281 end
= start
+ list
->len
;
1282 if ((copy
= end
- offset
) > 0) {
1285 csum2
= skb_copy_and_csum_bits(list
,
1288 csum
= csum_block_add(csum
, csum2
, pos
);
1289 if ((len
-= copy
) == 0)
1302 void skb_copy_and_csum_dev(const struct sk_buff
*skb
, u8
*to
)
1307 if (skb
->ip_summed
== CHECKSUM_HW
)
1308 csstart
= skb
->h
.raw
- skb
->data
;
1310 csstart
= skb_headlen(skb
);
1312 BUG_ON(csstart
> skb_headlen(skb
));
1314 memcpy(to
, skb
->data
, csstart
);
1317 if (csstart
!= skb
->len
)
1318 csum
= skb_copy_and_csum_bits(skb
, csstart
, to
+ csstart
,
1319 skb
->len
- csstart
, 0);
1321 if (skb
->ip_summed
== CHECKSUM_HW
) {
1322 long csstuff
= csstart
+ skb
->csum
;
1324 *((unsigned short *)(to
+ csstuff
)) = csum_fold(csum
);
1329 * skb_dequeue - remove from the head of the queue
1330 * @list: list to dequeue from
1332 * Remove the head of the list. The list lock is taken so the function
1333 * may be used safely with other locking list functions. The head item is
1334 * returned or %NULL if the list is empty.
1337 struct sk_buff
*skb_dequeue(struct sk_buff_head
*list
)
1339 unsigned long flags
;
1340 struct sk_buff
*result
;
1342 spin_lock_irqsave(&list
->lock
, flags
);
1343 result
= __skb_dequeue(list
);
1344 spin_unlock_irqrestore(&list
->lock
, flags
);
1349 * skb_dequeue_tail - remove from the tail of the queue
1350 * @list: list to dequeue from
1352 * Remove the tail of the list. The list lock is taken so the function
1353 * may be used safely with other locking list functions. The tail item is
1354 * returned or %NULL if the list is empty.
1356 struct sk_buff
*skb_dequeue_tail(struct sk_buff_head
*list
)
1358 unsigned long flags
;
1359 struct sk_buff
*result
;
1361 spin_lock_irqsave(&list
->lock
, flags
);
1362 result
= __skb_dequeue_tail(list
);
1363 spin_unlock_irqrestore(&list
->lock
, flags
);
1368 * skb_queue_purge - empty a list
1369 * @list: list to empty
1371 * Delete all buffers on an &sk_buff list. Each buffer is removed from
1372 * the list and one reference dropped. This function takes the list
1373 * lock and is atomic with respect to other list locking functions.
1375 void skb_queue_purge(struct sk_buff_head
*list
)
1377 struct sk_buff
*skb
;
1378 while ((skb
= skb_dequeue(list
)) != NULL
)
1383 * skb_queue_head - queue a buffer at the list head
1384 * @list: list to use
1385 * @newsk: buffer to queue
1387 * Queue a buffer at the start of the list. This function takes the
1388 * list lock and can be used safely with other locking &sk_buff functions
1391 * A buffer cannot be placed on two lists at the same time.
1393 void skb_queue_head(struct sk_buff_head
*list
, struct sk_buff
*newsk
)
1395 unsigned long flags
;
1397 spin_lock_irqsave(&list
->lock
, flags
);
1398 __skb_queue_head(list
, newsk
);
1399 spin_unlock_irqrestore(&list
->lock
, flags
);
1403 * skb_queue_tail - queue a buffer at the list tail
1404 * @list: list to use
1405 * @newsk: buffer to queue
1407 * Queue a buffer at the tail of the list. This function takes the
1408 * list lock and can be used safely with other locking &sk_buff functions
1411 * A buffer cannot be placed on two lists at the same time.
1413 void skb_queue_tail(struct sk_buff_head
*list
, struct sk_buff
*newsk
)
1415 unsigned long flags
;
1417 spin_lock_irqsave(&list
->lock
, flags
);
1418 __skb_queue_tail(list
, newsk
);
1419 spin_unlock_irqrestore(&list
->lock
, flags
);
1423 * skb_unlink - remove a buffer from a list
1424 * @skb: buffer to remove
1425 * @list: list to use
1427 * Remove a packet from a list. The list locks are taken and this
1428 * function is atomic with respect to other list locked calls
1430 * You must know what list the SKB is on.
1432 void skb_unlink(struct sk_buff
*skb
, struct sk_buff_head
*list
)
1434 unsigned long flags
;
1436 spin_lock_irqsave(&list
->lock
, flags
);
1437 __skb_unlink(skb
, list
);
1438 spin_unlock_irqrestore(&list
->lock
, flags
);
1442 * skb_append - append a buffer
1443 * @old: buffer to insert after
1444 * @newsk: buffer to insert
1445 * @list: list to use
1447 * Place a packet after a given packet in a list. The list locks are taken
1448 * and this function is atomic with respect to other list locked calls.
1449 * A buffer cannot be placed on two lists at the same time.
1451 void skb_append(struct sk_buff
*old
, struct sk_buff
*newsk
, struct sk_buff_head
*list
)
1453 unsigned long flags
;
1455 spin_lock_irqsave(&list
->lock
, flags
);
1456 __skb_append(old
, newsk
, list
);
1457 spin_unlock_irqrestore(&list
->lock
, flags
);
1462 * skb_insert - insert a buffer
1463 * @old: buffer to insert before
1464 * @newsk: buffer to insert
1465 * @list: list to use
1467 * Place a packet before a given packet in a list. The list locks are
1468 * taken and this function is atomic with respect to other list locked
1471 * A buffer cannot be placed on two lists at the same time.
1473 void skb_insert(struct sk_buff
*old
, struct sk_buff
*newsk
, struct sk_buff_head
*list
)
1475 unsigned long flags
;
1477 spin_lock_irqsave(&list
->lock
, flags
);
1478 __skb_insert(newsk
, old
->prev
, old
, list
);
1479 spin_unlock_irqrestore(&list
->lock
, flags
);
1484 * Tune the memory allocator for a new MTU size.
1486 void skb_add_mtu(int mtu
)
1488 /* Must match allocation in alloc_skb */
1489 mtu
= SKB_DATA_ALIGN(mtu
) + sizeof(struct skb_shared_info
);
1491 kmem_add_cache_size(mtu
);
1495 static inline void skb_split_inside_header(struct sk_buff
*skb
,
1496 struct sk_buff
* skb1
,
1497 const u32 len
, const int pos
)
1501 memcpy(skb_put(skb1
, pos
- len
), skb
->data
+ len
, pos
- len
);
1503 /* And move data appendix as is. */
1504 for (i
= 0; i
< skb_shinfo(skb
)->nr_frags
; i
++)
1505 skb_shinfo(skb1
)->frags
[i
] = skb_shinfo(skb
)->frags
[i
];
1507 skb_shinfo(skb1
)->nr_frags
= skb_shinfo(skb
)->nr_frags
;
1508 skb_shinfo(skb
)->nr_frags
= 0;
1509 skb1
->data_len
= skb
->data_len
;
1510 skb1
->len
+= skb1
->data_len
;
1513 skb
->tail
= skb
->data
+ len
;
1516 static inline void skb_split_no_header(struct sk_buff
*skb
,
1517 struct sk_buff
* skb1
,
1518 const u32 len
, int pos
)
1521 const int nfrags
= skb_shinfo(skb
)->nr_frags
;
1523 skb_shinfo(skb
)->nr_frags
= 0;
1524 skb1
->len
= skb1
->data_len
= skb
->len
- len
;
1526 skb
->data_len
= len
- pos
;
1528 for (i
= 0; i
< nfrags
; i
++) {
1529 int size
= skb_shinfo(skb
)->frags
[i
].size
;
1531 if (pos
+ size
> len
) {
1532 skb_shinfo(skb1
)->frags
[k
] = skb_shinfo(skb
)->frags
[i
];
1536 * We have two variants in this case:
1537 * 1. Move all the frag to the second
1538 * part, if it is possible. F.e.
1539 * this approach is mandatory for TUX,
1540 * where splitting is expensive.
1541 * 2. Split is accurately. We make this.
1543 get_page(skb_shinfo(skb
)->frags
[i
].page
);
1544 skb_shinfo(skb1
)->frags
[0].page_offset
+= len
- pos
;
1545 skb_shinfo(skb1
)->frags
[0].size
-= len
- pos
;
1546 skb_shinfo(skb
)->frags
[i
].size
= len
- pos
;
1547 skb_shinfo(skb
)->nr_frags
++;
1551 skb_shinfo(skb
)->nr_frags
++;
1554 skb_shinfo(skb1
)->nr_frags
= k
;
1558 * skb_split - Split fragmented skb to two parts at length len.
1559 * @skb: the buffer to split
1560 * @skb1: the buffer to receive the second part
1561 * @len: new length for skb
1563 void skb_split(struct sk_buff
*skb
, struct sk_buff
*skb1
, const u32 len
)
1565 int pos
= skb_headlen(skb
);
1567 if (len
< pos
) /* Split line is inside header. */
1568 skb_split_inside_header(skb
, skb1
, len
, pos
);
1569 else /* Second chunk has no header, nothing to copy. */
1570 skb_split_no_header(skb
, skb1
, len
, pos
);
1574 * skb_prepare_seq_read - Prepare a sequential read of skb data
1575 * @skb: the buffer to read
1576 * @from: lower offset of data to be read
1577 * @to: upper offset of data to be read
1578 * @st: state variable
1580 * Initializes the specified state variable. Must be called before
1581 * invoking skb_seq_read() for the first time.
1583 void skb_prepare_seq_read(struct sk_buff
*skb
, unsigned int from
,
1584 unsigned int to
, struct skb_seq_state
*st
)
1586 st
->lower_offset
= from
;
1587 st
->upper_offset
= to
;
1588 st
->root_skb
= st
->cur_skb
= skb
;
1589 st
->frag_idx
= st
->stepped_offset
= 0;
1590 st
->frag_data
= NULL
;
1594 * skb_seq_read - Sequentially read skb data
1595 * @consumed: number of bytes consumed by the caller so far
1596 * @data: destination pointer for data to be returned
1597 * @st: state variable
1599 * Reads a block of skb data at &consumed relative to the
1600 * lower offset specified to skb_prepare_seq_read(). Assigns
1601 * the head of the data block to &data and returns the length
1602 * of the block or 0 if the end of the skb data or the upper
1603 * offset has been reached.
1605 * The caller is not required to consume all of the data
1606 * returned, i.e. &consumed is typically set to the number
1607 * of bytes already consumed and the next call to
1608 * skb_seq_read() will return the remaining part of the block.
1610 * Note: The size of each block of data returned can be arbitary,
1611 * this limitation is the cost for zerocopy seqeuental
1612 * reads of potentially non linear data.
1614 * Note: Fragment lists within fragments are not implemented
1615 * at the moment, state->root_skb could be replaced with
1616 * a stack for this purpose.
1618 unsigned int skb_seq_read(unsigned int consumed
, const u8
**data
,
1619 struct skb_seq_state
*st
)
1621 unsigned int block_limit
, abs_offset
= consumed
+ st
->lower_offset
;
1624 if (unlikely(abs_offset
>= st
->upper_offset
))
1628 block_limit
= skb_headlen(st
->cur_skb
);
1630 if (abs_offset
< block_limit
) {
1631 *data
= st
->cur_skb
->data
+ abs_offset
;
1632 return block_limit
- abs_offset
;
1635 if (st
->frag_idx
== 0 && !st
->frag_data
)
1636 st
->stepped_offset
+= skb_headlen(st
->cur_skb
);
1638 while (st
->frag_idx
< skb_shinfo(st
->cur_skb
)->nr_frags
) {
1639 frag
= &skb_shinfo(st
->cur_skb
)->frags
[st
->frag_idx
];
1640 block_limit
= frag
->size
+ st
->stepped_offset
;
1642 if (abs_offset
< block_limit
) {
1644 st
->frag_data
= kmap_skb_frag(frag
);
1646 *data
= (u8
*) st
->frag_data
+ frag
->page_offset
+
1647 (abs_offset
- st
->stepped_offset
);
1649 return block_limit
- abs_offset
;
1652 if (st
->frag_data
) {
1653 kunmap_skb_frag(st
->frag_data
);
1654 st
->frag_data
= NULL
;
1658 st
->stepped_offset
+= frag
->size
;
1661 if (st
->cur_skb
->next
) {
1662 st
->cur_skb
= st
->cur_skb
->next
;
1665 } else if (st
->root_skb
== st
->cur_skb
&&
1666 skb_shinfo(st
->root_skb
)->frag_list
) {
1667 st
->cur_skb
= skb_shinfo(st
->root_skb
)->frag_list
;
1675 * skb_abort_seq_read - Abort a sequential read of skb data
1676 * @st: state variable
1678 * Must be called if skb_seq_read() was not called until it
1681 void skb_abort_seq_read(struct skb_seq_state
*st
)
1684 kunmap_skb_frag(st
->frag_data
);
1687 #define TS_SKB_CB(state) ((struct skb_seq_state *) &((state)->cb))
1689 static unsigned int skb_ts_get_next_block(unsigned int offset
, const u8
**text
,
1690 struct ts_config
*conf
,
1691 struct ts_state
*state
)
1693 return skb_seq_read(offset
, text
, TS_SKB_CB(state
));
1696 static void skb_ts_finish(struct ts_config
*conf
, struct ts_state
*state
)
1698 skb_abort_seq_read(TS_SKB_CB(state
));
1702 * skb_find_text - Find a text pattern in skb data
1703 * @skb: the buffer to look in
1704 * @from: search offset
1706 * @config: textsearch configuration
1707 * @state: uninitialized textsearch state variable
1709 * Finds a pattern in the skb data according to the specified
1710 * textsearch configuration. Use textsearch_next() to retrieve
1711 * subsequent occurrences of the pattern. Returns the offset
1712 * to the first occurrence or UINT_MAX if no match was found.
1714 unsigned int skb_find_text(struct sk_buff
*skb
, unsigned int from
,
1715 unsigned int to
, struct ts_config
*config
,
1716 struct ts_state
*state
)
1718 config
->get_next_block
= skb_ts_get_next_block
;
1719 config
->finish
= skb_ts_finish
;
1721 skb_prepare_seq_read(skb
, from
, to
, TS_SKB_CB(state
));
1723 return textsearch_find(config
, state
);
1727 * skb_append_datato_frags: - append the user data to a skb
1728 * @sk: sock structure
1729 * @skb: skb structure to be appened with user data.
1730 * @getfrag: call back function to be used for getting the user data
1731 * @from: pointer to user message iov
1732 * @length: length of the iov message
1734 * Description: This procedure append the user data in the fragment part
1735 * of the skb if any page alloc fails user this procedure returns -ENOMEM
1737 int skb_append_datato_frags(struct sock
*sk
, struct sk_buff
*skb
,
1738 int (*getfrag
)(void *from
, char *to
, int offset
,
1739 int len
, int odd
, struct sk_buff
*skb
),
1740 void *from
, int length
)
1743 skb_frag_t
*frag
= NULL
;
1744 struct page
*page
= NULL
;
1750 /* Return error if we don't have space for new frag */
1751 frg_cnt
= skb_shinfo(skb
)->nr_frags
;
1752 if (frg_cnt
>= MAX_SKB_FRAGS
)
1755 /* allocate a new page for next frag */
1756 page
= alloc_pages(sk
->sk_allocation
, 0);
1758 /* If alloc_page fails just return failure and caller will
1759 * free previous allocated pages by doing kfree_skb()
1764 /* initialize the next frag */
1765 sk
->sk_sndmsg_page
= page
;
1766 sk
->sk_sndmsg_off
= 0;
1767 skb_fill_page_desc(skb
, frg_cnt
, page
, 0, 0);
1768 skb
->truesize
+= PAGE_SIZE
;
1769 atomic_add(PAGE_SIZE
, &sk
->sk_wmem_alloc
);
1771 /* get the new initialized frag */
1772 frg_cnt
= skb_shinfo(skb
)->nr_frags
;
1773 frag
= &skb_shinfo(skb
)->frags
[frg_cnt
- 1];
1775 /* copy the user data to page */
1776 left
= PAGE_SIZE
- frag
->page_offset
;
1777 copy
= (length
> left
)? left
: length
;
1779 ret
= getfrag(from
, (page_address(frag
->page
) +
1780 frag
->page_offset
+ frag
->size
),
1781 offset
, copy
, 0, skb
);
1785 /* copy was successful so update the size parameters */
1786 sk
->sk_sndmsg_off
+= copy
;
1789 skb
->data_len
+= copy
;
1793 } while (length
> 0);
1798 void __init
skb_init(void)
1800 skbuff_head_cache
= kmem_cache_create("skbuff_head_cache",
1801 sizeof(struct sk_buff
),
1805 if (!skbuff_head_cache
)
1806 panic("cannot create skbuff cache");
1808 skbuff_fclone_cache
= kmem_cache_create("skbuff_fclone_cache",
1809 (2*sizeof(struct sk_buff
)) +
1814 if (!skbuff_fclone_cache
)
1815 panic("cannot create skbuff cache");
1818 EXPORT_SYMBOL(___pskb_trim
);
1819 EXPORT_SYMBOL(__kfree_skb
);
1820 EXPORT_SYMBOL(kfree_skb
);
1821 EXPORT_SYMBOL(__pskb_pull_tail
);
1822 EXPORT_SYMBOL(__alloc_skb
);
1823 EXPORT_SYMBOL(pskb_copy
);
1824 EXPORT_SYMBOL(pskb_expand_head
);
1825 EXPORT_SYMBOL(skb_checksum
);
1826 EXPORT_SYMBOL(skb_clone
);
1827 EXPORT_SYMBOL(skb_clone_fraglist
);
1828 EXPORT_SYMBOL(skb_copy
);
1829 EXPORT_SYMBOL(skb_copy_and_csum_bits
);
1830 EXPORT_SYMBOL(skb_copy_and_csum_dev
);
1831 EXPORT_SYMBOL(skb_copy_bits
);
1832 EXPORT_SYMBOL(skb_copy_expand
);
1833 EXPORT_SYMBOL(skb_over_panic
);
1834 EXPORT_SYMBOL(skb_pad
);
1835 EXPORT_SYMBOL(skb_realloc_headroom
);
1836 EXPORT_SYMBOL(skb_under_panic
);
1837 EXPORT_SYMBOL(skb_dequeue
);
1838 EXPORT_SYMBOL(skb_dequeue_tail
);
1839 EXPORT_SYMBOL(skb_insert
);
1840 EXPORT_SYMBOL(skb_queue_purge
);
1841 EXPORT_SYMBOL(skb_queue_head
);
1842 EXPORT_SYMBOL(skb_queue_tail
);
1843 EXPORT_SYMBOL(skb_unlink
);
1844 EXPORT_SYMBOL(skb_append
);
1845 EXPORT_SYMBOL(skb_split
);
1846 EXPORT_SYMBOL(skb_prepare_seq_read
);
1847 EXPORT_SYMBOL(skb_seq_read
);
1848 EXPORT_SYMBOL(skb_abort_seq_read
);
1849 EXPORT_SYMBOL(skb_find_text
);
1850 EXPORT_SYMBOL(skb_append_datato_frags
);