Merge branch 'drm-nouveau-fixes-3.8' of git://anongit.freedesktop.org/git/nouveau...
[deliverable/linux.git] / net / core / skbuff.c
CommitLineData
1da177e4
LT
1/*
2 * Routines having to do with the 'struct sk_buff' memory handlers.
3 *
113aa838 4 * Authors: Alan Cox <alan@lxorguk.ukuu.org.uk>
1da177e4
LT
5 * Florian La Roche <rzsfl@rz.uni-sb.de>
6 *
1da177e4
LT
7 * Fixes:
8 * Alan Cox : Fixed the worst of the load
9 * balancer bugs.
10 * Dave Platt : Interrupt stacking fix.
11 * Richard Kooijman : Timestamp fixes.
12 * Alan Cox : Changed buffer format.
13 * Alan Cox : destructor hook for AF_UNIX etc.
14 * Linus Torvalds : Better skb_clone.
15 * Alan Cox : Added skb_copy.
16 * Alan Cox : Added all the changed routines Linus
17 * only put in the headers
18 * Ray VanTassle : Fixed --skb->lock in free
19 * Alan Cox : skb_copy copy arp field
20 * Andi Kleen : slabified it.
21 * Robert Olsson : Removed skb_head_pool
22 *
23 * NOTE:
24 * The __skb_ routines should be called with interrupts
25 * disabled, or you better be *real* sure that the operation is atomic
26 * with respect to whatever list is being frobbed (e.g. via lock_sock()
27 * or via disabling bottom half handlers, etc).
28 *
29 * This program is free software; you can redistribute it and/or
30 * modify it under the terms of the GNU General Public License
31 * as published by the Free Software Foundation; either version
32 * 2 of the License, or (at your option) any later version.
33 */
34
35/*
36 * The functions in this file will not compile correctly with gcc 2.4.x
37 */
38
e005d193
JP
39#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
40
1da177e4
LT
41#include <linux/module.h>
42#include <linux/types.h>
43#include <linux/kernel.h>
fe55f6d5 44#include <linux/kmemcheck.h>
1da177e4
LT
45#include <linux/mm.h>
46#include <linux/interrupt.h>
47#include <linux/in.h>
48#include <linux/inet.h>
49#include <linux/slab.h>
50#include <linux/netdevice.h>
51#ifdef CONFIG_NET_CLS_ACT
52#include <net/pkt_sched.h>
53#endif
54#include <linux/string.h>
55#include <linux/skbuff.h>
9c55e01c 56#include <linux/splice.h>
1da177e4
LT
57#include <linux/cache.h>
58#include <linux/rtnetlink.h>
59#include <linux/init.h>
716ea3a7 60#include <linux/scatterlist.h>
ac45f602 61#include <linux/errqueue.h>
268bb0ce 62#include <linux/prefetch.h>
1da177e4
LT
63
64#include <net/protocol.h>
65#include <net/dst.h>
66#include <net/sock.h>
67#include <net/checksum.h>
68#include <net/xfrm.h>
69
70#include <asm/uaccess.h>
ad8d75ff 71#include <trace/events/skb.h>
51c56b00 72#include <linux/highmem.h>
a1f8e7f7 73
d7e8883c 74struct kmem_cache *skbuff_head_cache __read_mostly;
e18b890b 75static struct kmem_cache *skbuff_fclone_cache __read_mostly;
1da177e4 76
9c55e01c
JA
77static void sock_pipe_buf_release(struct pipe_inode_info *pipe,
78 struct pipe_buffer *buf)
79{
8b9d3728 80 put_page(buf->page);
9c55e01c
JA
81}
82
83static void sock_pipe_buf_get(struct pipe_inode_info *pipe,
84 struct pipe_buffer *buf)
85{
8b9d3728 86 get_page(buf->page);
9c55e01c
JA
87}
88
89static int sock_pipe_buf_steal(struct pipe_inode_info *pipe,
90 struct pipe_buffer *buf)
91{
92 return 1;
93}
94
95
96/* Pipe buffer operations for a socket. */
28dfef8f 97static const struct pipe_buf_operations sock_pipe_buf_ops = {
9c55e01c
JA
98 .can_merge = 0,
99 .map = generic_pipe_buf_map,
100 .unmap = generic_pipe_buf_unmap,
101 .confirm = generic_pipe_buf_confirm,
102 .release = sock_pipe_buf_release,
103 .steal = sock_pipe_buf_steal,
104 .get = sock_pipe_buf_get,
105};
106
1da177e4
LT
107/*
108 * Keep out-of-line to prevent kernel bloat.
109 * __builtin_return_address is not used because it is not always
110 * reliable.
111 */
112
113/**
114 * skb_over_panic - private function
115 * @skb: buffer
116 * @sz: size
117 * @here: address
118 *
119 * Out of line support code for skb_put(). Not user callable.
120 */
ccb7c773 121static void skb_over_panic(struct sk_buff *skb, int sz, void *here)
1da177e4 122{
e005d193
JP
123 pr_emerg("%s: text:%p len:%d put:%d head:%p data:%p tail:%#lx end:%#lx dev:%s\n",
124 __func__, here, skb->len, sz, skb->head, skb->data,
125 (unsigned long)skb->tail, (unsigned long)skb->end,
126 skb->dev ? skb->dev->name : "<NULL>");
1da177e4
LT
127 BUG();
128}
129
130/**
131 * skb_under_panic - private function
132 * @skb: buffer
133 * @sz: size
134 * @here: address
135 *
136 * Out of line support code for skb_push(). Not user callable.
137 */
138
ccb7c773 139static void skb_under_panic(struct sk_buff *skb, int sz, void *here)
1da177e4 140{
e005d193
JP
141 pr_emerg("%s: text:%p len:%d put:%d head:%p data:%p tail:%#lx end:%#lx dev:%s\n",
142 __func__, here, skb->len, sz, skb->head, skb->data,
143 (unsigned long)skb->tail, (unsigned long)skb->end,
144 skb->dev ? skb->dev->name : "<NULL>");
1da177e4
LT
145 BUG();
146}
147
c93bdd0e
MG
148
149/*
150 * kmalloc_reserve is a wrapper around kmalloc_node_track_caller that tells
151 * the caller if emergency pfmemalloc reserves are being used. If it is and
152 * the socket is later found to be SOCK_MEMALLOC then PFMEMALLOC reserves
153 * may be used. Otherwise, the packet data may be discarded until enough
154 * memory is free
155 */
156#define kmalloc_reserve(size, gfp, node, pfmemalloc) \
157 __kmalloc_reserve(size, gfp, node, _RET_IP_, pfmemalloc)
158void *__kmalloc_reserve(size_t size, gfp_t flags, int node, unsigned long ip,
159 bool *pfmemalloc)
160{
161 void *obj;
162 bool ret_pfmemalloc = false;
163
164 /*
165 * Try a regular allocation, when that fails and we're not entitled
166 * to the reserves, fail.
167 */
168 obj = kmalloc_node_track_caller(size,
169 flags | __GFP_NOMEMALLOC | __GFP_NOWARN,
170 node);
171 if (obj || !(gfp_pfmemalloc_allowed(flags)))
172 goto out;
173
174 /* Try again but now we are using pfmemalloc reserves */
175 ret_pfmemalloc = true;
176 obj = kmalloc_node_track_caller(size, flags, node);
177
178out:
179 if (pfmemalloc)
180 *pfmemalloc = ret_pfmemalloc;
181
182 return obj;
183}
184
1da177e4
LT
185/* Allocate a new skbuff. We do this ourselves so we can fill in a few
186 * 'private' fields and also do memory statistics to find all the
187 * [BEEP] leaks.
188 *
189 */
190
191/**
d179cd12 192 * __alloc_skb - allocate a network buffer
1da177e4
LT
193 * @size: size to allocate
194 * @gfp_mask: allocation mask
c93bdd0e
MG
195 * @flags: If SKB_ALLOC_FCLONE is set, allocate from fclone cache
196 * instead of head cache and allocate a cloned (child) skb.
197 * If SKB_ALLOC_RX is set, __GFP_MEMALLOC will be used for
198 * allocations in case the data is required for writeback
b30973f8 199 * @node: numa node to allocate memory on
1da177e4
LT
200 *
201 * Allocate a new &sk_buff. The returned buffer has no headroom and a
94b6042c
BH
202 * tail room of at least size bytes. The object has a reference count
203 * of one. The return is the buffer. On a failure the return is %NULL.
1da177e4
LT
204 *
205 * Buffers may only be allocated from interrupts using a @gfp_mask of
206 * %GFP_ATOMIC.
207 */
dd0fc66f 208struct sk_buff *__alloc_skb(unsigned int size, gfp_t gfp_mask,
c93bdd0e 209 int flags, int node)
1da177e4 210{
e18b890b 211 struct kmem_cache *cache;
4947d3ef 212 struct skb_shared_info *shinfo;
1da177e4
LT
213 struct sk_buff *skb;
214 u8 *data;
c93bdd0e 215 bool pfmemalloc;
1da177e4 216
c93bdd0e
MG
217 cache = (flags & SKB_ALLOC_FCLONE)
218 ? skbuff_fclone_cache : skbuff_head_cache;
219
220 if (sk_memalloc_socks() && (flags & SKB_ALLOC_RX))
221 gfp_mask |= __GFP_MEMALLOC;
8798b3fb 222
1da177e4 223 /* Get the HEAD */
b30973f8 224 skb = kmem_cache_alloc_node(cache, gfp_mask & ~__GFP_DMA, node);
1da177e4
LT
225 if (!skb)
226 goto out;
ec7d2f2c 227 prefetchw(skb);
1da177e4 228
87fb4b7b
ED
229 /* We do our best to align skb_shared_info on a separate cache
230 * line. It usually works because kmalloc(X > SMP_CACHE_BYTES) gives
231 * aligned memory blocks, unless SLUB/SLAB debug is enabled.
232 * Both skb->head and skb_shared_info are cache line aligned.
233 */
bc417e30 234 size = SKB_DATA_ALIGN(size);
87fb4b7b 235 size += SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
c93bdd0e 236 data = kmalloc_reserve(size, gfp_mask, node, &pfmemalloc);
1da177e4
LT
237 if (!data)
238 goto nodata;
87fb4b7b
ED
239 /* kmalloc(size) might give us more room than requested.
240 * Put skb_shared_info exactly at the end of allocated zone,
241 * to allow max possible filling before reallocation.
242 */
243 size = SKB_WITH_OVERHEAD(ksize(data));
ec7d2f2c 244 prefetchw(data + size);
1da177e4 245
ca0605a7 246 /*
c8005785
JB
247 * Only clear those fields we need to clear, not those that we will
248 * actually initialise below. Hence, don't put any more fields after
249 * the tail pointer in struct sk_buff!
ca0605a7
ACM
250 */
251 memset(skb, 0, offsetof(struct sk_buff, tail));
87fb4b7b
ED
252 /* Account for allocated memory : skb + skb->head */
253 skb->truesize = SKB_TRUESIZE(size);
c93bdd0e 254 skb->pfmemalloc = pfmemalloc;
1da177e4
LT
255 atomic_set(&skb->users, 1);
256 skb->head = data;
257 skb->data = data;
27a884dc 258 skb_reset_tail_pointer(skb);
4305b541 259 skb->end = skb->tail + size;
19633e12
SH
260#ifdef NET_SKBUFF_DATA_USES_OFFSET
261 skb->mac_header = ~0U;
262#endif
263
4947d3ef
BL
264 /* make sure we initialize shinfo sequentially */
265 shinfo = skb_shinfo(skb);
ec7d2f2c 266 memset(shinfo, 0, offsetof(struct skb_shared_info, dataref));
4947d3ef 267 atomic_set(&shinfo->dataref, 1);
c2aa3665 268 kmemcheck_annotate_variable(shinfo->destructor_arg);
4947d3ef 269
c93bdd0e 270 if (flags & SKB_ALLOC_FCLONE) {
d179cd12
DM
271 struct sk_buff *child = skb + 1;
272 atomic_t *fclone_ref = (atomic_t *) (child + 1);
1da177e4 273
fe55f6d5
VN
274 kmemcheck_annotate_bitfield(child, flags1);
275 kmemcheck_annotate_bitfield(child, flags2);
d179cd12
DM
276 skb->fclone = SKB_FCLONE_ORIG;
277 atomic_set(fclone_ref, 1);
278
279 child->fclone = SKB_FCLONE_UNAVAILABLE;
c93bdd0e 280 child->pfmemalloc = pfmemalloc;
d179cd12 281 }
1da177e4
LT
282out:
283 return skb;
284nodata:
8798b3fb 285 kmem_cache_free(cache, skb);
1da177e4
LT
286 skb = NULL;
287 goto out;
1da177e4 288}
b4ac530f 289EXPORT_SYMBOL(__alloc_skb);
1da177e4 290
b2b5ce9d
ED
291/**
292 * build_skb - build a network buffer
293 * @data: data buffer provided by caller
d3836f21 294 * @frag_size: size of fragment, or 0 if head was kmalloced
b2b5ce9d
ED
295 *
296 * Allocate a new &sk_buff. Caller provides space holding head and
297 * skb_shared_info. @data must have been allocated by kmalloc()
298 * The return is the new skb buffer.
299 * On a failure the return is %NULL, and @data is not freed.
300 * Notes :
301 * Before IO, driver allocates only data buffer where NIC put incoming frame
302 * Driver should add room at head (NET_SKB_PAD) and
303 * MUST add room at tail (SKB_DATA_ALIGN(skb_shared_info))
304 * After IO, driver calls build_skb(), to allocate sk_buff and populate it
305 * before giving packet to stack.
306 * RX rings only contains data buffers, not full skbs.
307 */
d3836f21 308struct sk_buff *build_skb(void *data, unsigned int frag_size)
b2b5ce9d
ED
309{
310 struct skb_shared_info *shinfo;
311 struct sk_buff *skb;
d3836f21 312 unsigned int size = frag_size ? : ksize(data);
b2b5ce9d
ED
313
314 skb = kmem_cache_alloc(skbuff_head_cache, GFP_ATOMIC);
315 if (!skb)
316 return NULL;
317
d3836f21 318 size -= SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
b2b5ce9d
ED
319
320 memset(skb, 0, offsetof(struct sk_buff, tail));
321 skb->truesize = SKB_TRUESIZE(size);
d3836f21 322 skb->head_frag = frag_size != 0;
b2b5ce9d
ED
323 atomic_set(&skb->users, 1);
324 skb->head = data;
325 skb->data = data;
326 skb_reset_tail_pointer(skb);
327 skb->end = skb->tail + size;
328#ifdef NET_SKBUFF_DATA_USES_OFFSET
329 skb->mac_header = ~0U;
330#endif
331
332 /* make sure we initialize shinfo sequentially */
333 shinfo = skb_shinfo(skb);
334 memset(shinfo, 0, offsetof(struct skb_shared_info, dataref));
335 atomic_set(&shinfo->dataref, 1);
336 kmemcheck_annotate_variable(shinfo->destructor_arg);
337
338 return skb;
339}
340EXPORT_SYMBOL(build_skb);
341
a1c7fff7 342struct netdev_alloc_cache {
69b08f62
ED
343 struct page_frag frag;
344 /* we maintain a pagecount bias, so that we dont dirty cache line
345 * containing page->_count every time we allocate a fragment.
346 */
347 unsigned int pagecnt_bias;
a1c7fff7
ED
348};
349static DEFINE_PER_CPU(struct netdev_alloc_cache, netdev_alloc_cache);
350
69b08f62
ED
351#define NETDEV_FRAG_PAGE_MAX_ORDER get_order(32768)
352#define NETDEV_FRAG_PAGE_MAX_SIZE (PAGE_SIZE << NETDEV_FRAG_PAGE_MAX_ORDER)
353#define NETDEV_PAGECNT_MAX_BIAS NETDEV_FRAG_PAGE_MAX_SIZE
540eb7bf 354
c93bdd0e 355static void *__netdev_alloc_frag(unsigned int fragsz, gfp_t gfp_mask)
6f532612
ED
356{
357 struct netdev_alloc_cache *nc;
358 void *data = NULL;
69b08f62 359 int order;
6f532612
ED
360 unsigned long flags;
361
362 local_irq_save(flags);
363 nc = &__get_cpu_var(netdev_alloc_cache);
69b08f62 364 if (unlikely(!nc->frag.page)) {
6f532612 365refill:
69b08f62
ED
366 for (order = NETDEV_FRAG_PAGE_MAX_ORDER; ;) {
367 gfp_t gfp = gfp_mask;
368
369 if (order)
370 gfp |= __GFP_COMP | __GFP_NOWARN;
371 nc->frag.page = alloc_pages(gfp, order);
372 if (likely(nc->frag.page))
373 break;
374 if (--order < 0)
375 goto end;
376 }
377 nc->frag.size = PAGE_SIZE << order;
540eb7bf 378recycle:
69b08f62
ED
379 atomic_set(&nc->frag.page->_count, NETDEV_PAGECNT_MAX_BIAS);
380 nc->pagecnt_bias = NETDEV_PAGECNT_MAX_BIAS;
381 nc->frag.offset = 0;
6f532612 382 }
540eb7bf 383
69b08f62 384 if (nc->frag.offset + fragsz > nc->frag.size) {
540eb7bf 385 /* avoid unnecessary locked operations if possible */
69b08f62
ED
386 if ((atomic_read(&nc->frag.page->_count) == nc->pagecnt_bias) ||
387 atomic_sub_and_test(nc->pagecnt_bias, &nc->frag.page->_count))
540eb7bf
AD
388 goto recycle;
389 goto refill;
6f532612 390 }
540eb7bf 391
69b08f62
ED
392 data = page_address(nc->frag.page) + nc->frag.offset;
393 nc->frag.offset += fragsz;
540eb7bf
AD
394 nc->pagecnt_bias--;
395end:
6f532612
ED
396 local_irq_restore(flags);
397 return data;
398}
c93bdd0e
MG
399
400/**
401 * netdev_alloc_frag - allocate a page fragment
402 * @fragsz: fragment size
403 *
404 * Allocates a frag from a page for receive buffer.
405 * Uses GFP_ATOMIC allocations.
406 */
407void *netdev_alloc_frag(unsigned int fragsz)
408{
409 return __netdev_alloc_frag(fragsz, GFP_ATOMIC | __GFP_COLD);
410}
6f532612
ED
411EXPORT_SYMBOL(netdev_alloc_frag);
412
8af27456
CH
413/**
414 * __netdev_alloc_skb - allocate an skbuff for rx on a specific device
415 * @dev: network device to receive on
416 * @length: length to allocate
417 * @gfp_mask: get_free_pages mask, passed to alloc_skb
418 *
419 * Allocate a new &sk_buff and assign it a usage count of one. The
420 * buffer has unspecified headroom built in. Users should allocate
421 * the headroom they think they need without accounting for the
422 * built in space. The built in space is used for optimisations.
423 *
424 * %NULL is returned if there is no free memory.
425 */
426struct sk_buff *__netdev_alloc_skb(struct net_device *dev,
6f532612 427 unsigned int length, gfp_t gfp_mask)
8af27456 428{
6f532612 429 struct sk_buff *skb = NULL;
a1c7fff7
ED
430 unsigned int fragsz = SKB_DATA_ALIGN(length + NET_SKB_PAD) +
431 SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
432
310e158c 433 if (fragsz <= PAGE_SIZE && !(gfp_mask & (__GFP_WAIT | GFP_DMA))) {
c93bdd0e
MG
434 void *data;
435
436 if (sk_memalloc_socks())
437 gfp_mask |= __GFP_MEMALLOC;
438
439 data = __netdev_alloc_frag(fragsz, gfp_mask);
a1c7fff7 440
6f532612
ED
441 if (likely(data)) {
442 skb = build_skb(data, fragsz);
443 if (unlikely(!skb))
444 put_page(virt_to_head_page(data));
a1c7fff7 445 }
a1c7fff7 446 } else {
c93bdd0e
MG
447 skb = __alloc_skb(length + NET_SKB_PAD, gfp_mask,
448 SKB_ALLOC_RX, NUMA_NO_NODE);
a1c7fff7 449 }
7b2e497a 450 if (likely(skb)) {
8af27456 451 skb_reserve(skb, NET_SKB_PAD);
7b2e497a
CH
452 skb->dev = dev;
453 }
8af27456
CH
454 return skb;
455}
b4ac530f 456EXPORT_SYMBOL(__netdev_alloc_skb);
1da177e4 457
654bed16 458void skb_add_rx_frag(struct sk_buff *skb, int i, struct page *page, int off,
50269e19 459 int size, unsigned int truesize)
654bed16
PZ
460{
461 skb_fill_page_desc(skb, i, page, off, size);
462 skb->len += size;
463 skb->data_len += size;
50269e19 464 skb->truesize += truesize;
654bed16
PZ
465}
466EXPORT_SYMBOL(skb_add_rx_frag);
467
27b437c8 468static void skb_drop_list(struct sk_buff **listp)
1da177e4 469{
27b437c8 470 struct sk_buff *list = *listp;
1da177e4 471
27b437c8 472 *listp = NULL;
1da177e4
LT
473
474 do {
475 struct sk_buff *this = list;
476 list = list->next;
477 kfree_skb(this);
478 } while (list);
479}
480
27b437c8
HX
481static inline void skb_drop_fraglist(struct sk_buff *skb)
482{
483 skb_drop_list(&skb_shinfo(skb)->frag_list);
484}
485
1da177e4
LT
486static void skb_clone_fraglist(struct sk_buff *skb)
487{
488 struct sk_buff *list;
489
fbb398a8 490 skb_walk_frags(skb, list)
1da177e4
LT
491 skb_get(list);
492}
493
d3836f21
ED
494static void skb_free_head(struct sk_buff *skb)
495{
496 if (skb->head_frag)
497 put_page(virt_to_head_page(skb->head));
498 else
499 kfree(skb->head);
500}
501
5bba1712 502static void skb_release_data(struct sk_buff *skb)
1da177e4
LT
503{
504 if (!skb->cloned ||
505 !atomic_sub_return(skb->nohdr ? (1 << SKB_DATAREF_SHIFT) + 1 : 1,
506 &skb_shinfo(skb)->dataref)) {
507 if (skb_shinfo(skb)->nr_frags) {
508 int i;
509 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++)
ea2ab693 510 skb_frag_unref(skb, i);
1da177e4
LT
511 }
512
a6686f2f
SM
513 /*
514 * If skb buf is from userspace, we need to notify the caller
515 * the lower device DMA has done;
516 */
517 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
518 struct ubuf_info *uarg;
519
520 uarg = skb_shinfo(skb)->destructor_arg;
521 if (uarg->callback)
e19d6763 522 uarg->callback(uarg, true);
a6686f2f
SM
523 }
524
21dc3301 525 if (skb_has_frag_list(skb))
1da177e4
LT
526 skb_drop_fraglist(skb);
527
d3836f21 528 skb_free_head(skb);
1da177e4
LT
529 }
530}
531
532/*
533 * Free an skbuff by memory without cleaning the state.
534 */
2d4baff8 535static void kfree_skbmem(struct sk_buff *skb)
1da177e4 536{
d179cd12
DM
537 struct sk_buff *other;
538 atomic_t *fclone_ref;
539
d179cd12
DM
540 switch (skb->fclone) {
541 case SKB_FCLONE_UNAVAILABLE:
542 kmem_cache_free(skbuff_head_cache, skb);
543 break;
544
545 case SKB_FCLONE_ORIG:
546 fclone_ref = (atomic_t *) (skb + 2);
547 if (atomic_dec_and_test(fclone_ref))
548 kmem_cache_free(skbuff_fclone_cache, skb);
549 break;
550
551 case SKB_FCLONE_CLONE:
552 fclone_ref = (atomic_t *) (skb + 1);
553 other = skb - 1;
554
555 /* The clone portion is available for
556 * fast-cloning again.
557 */
558 skb->fclone = SKB_FCLONE_UNAVAILABLE;
559
560 if (atomic_dec_and_test(fclone_ref))
561 kmem_cache_free(skbuff_fclone_cache, other);
562 break;
3ff50b79 563 }
1da177e4
LT
564}
565
04a4bb55 566static void skb_release_head_state(struct sk_buff *skb)
1da177e4 567{
adf30907 568 skb_dst_drop(skb);
1da177e4
LT
569#ifdef CONFIG_XFRM
570 secpath_put(skb->sp);
571#endif
9c2b3328
SH
572 if (skb->destructor) {
573 WARN_ON(in_irq());
1da177e4
LT
574 skb->destructor(skb);
575 }
a3bf7ae9 576#if IS_ENABLED(CONFIG_NF_CONNTRACK)
5f79e0f9 577 nf_conntrack_put(skb->nfct);
2fc72c7b
KK
578#endif
579#ifdef NET_SKBUFF_NF_DEFRAG_NEEDED
9fb9cbb1
YK
580 nf_conntrack_put_reasm(skb->nfct_reasm);
581#endif
1da177e4
LT
582#ifdef CONFIG_BRIDGE_NETFILTER
583 nf_bridge_put(skb->nf_bridge);
584#endif
1da177e4
LT
585/* XXX: IS this still necessary? - JHS */
586#ifdef CONFIG_NET_SCHED
587 skb->tc_index = 0;
588#ifdef CONFIG_NET_CLS_ACT
589 skb->tc_verd = 0;
1da177e4
LT
590#endif
591#endif
04a4bb55
LB
592}
593
594/* Free everything but the sk_buff shell. */
595static void skb_release_all(struct sk_buff *skb)
596{
597 skb_release_head_state(skb);
2d4baff8
HX
598 skb_release_data(skb);
599}
600
601/**
602 * __kfree_skb - private function
603 * @skb: buffer
604 *
605 * Free an sk_buff. Release anything attached to the buffer.
606 * Clean the state. This is an internal helper function. Users should
607 * always call kfree_skb
608 */
1da177e4 609
2d4baff8
HX
610void __kfree_skb(struct sk_buff *skb)
611{
612 skb_release_all(skb);
1da177e4
LT
613 kfree_skbmem(skb);
614}
b4ac530f 615EXPORT_SYMBOL(__kfree_skb);
1da177e4 616