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