| 1 | /* ar-skbuff.c: socket buffer destruction handling |
| 2 | * |
| 3 | * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved. |
| 4 | * Written by David Howells (dhowells@redhat.com) |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
| 10 | */ |
| 11 | |
| 12 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 13 | |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/net.h> |
| 16 | #include <linux/skbuff.h> |
| 17 | #include <net/sock.h> |
| 18 | #include <net/af_rxrpc.h> |
| 19 | #include "ar-internal.h" |
| 20 | |
| 21 | /* |
| 22 | * Note the existence of a new-to-us socket buffer (allocated or dequeued). |
| 23 | */ |
| 24 | void rxrpc_new_skb(struct sk_buff *skb) |
| 25 | { |
| 26 | const void *here = __builtin_return_address(0); |
| 27 | int n = atomic_inc_return(&rxrpc_n_skbs); |
| 28 | trace_rxrpc_skb(skb, 0, atomic_read(&skb->users), n, here); |
| 29 | } |
| 30 | |
| 31 | /* |
| 32 | * Note the re-emergence of a socket buffer from a queue or buffer. |
| 33 | */ |
| 34 | void rxrpc_see_skb(struct sk_buff *skb) |
| 35 | { |
| 36 | const void *here = __builtin_return_address(0); |
| 37 | if (skb) { |
| 38 | int n = atomic_read(&rxrpc_n_skbs); |
| 39 | trace_rxrpc_skb(skb, 1, atomic_read(&skb->users), n, here); |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | /* |
| 44 | * Note the addition of a ref on a socket buffer. |
| 45 | */ |
| 46 | void rxrpc_get_skb(struct sk_buff *skb) |
| 47 | { |
| 48 | const void *here = __builtin_return_address(0); |
| 49 | int n = atomic_inc_return(&rxrpc_n_skbs); |
| 50 | trace_rxrpc_skb(skb, 2, atomic_read(&skb->users), n, here); |
| 51 | skb_get(skb); |
| 52 | } |
| 53 | |
| 54 | /* |
| 55 | * Note the destruction of a socket buffer. |
| 56 | */ |
| 57 | void rxrpc_free_skb(struct sk_buff *skb) |
| 58 | { |
| 59 | const void *here = __builtin_return_address(0); |
| 60 | if (skb) { |
| 61 | int n; |
| 62 | CHECK_SLAB_OKAY(&skb->users); |
| 63 | n = atomic_dec_return(&rxrpc_n_skbs); |
| 64 | trace_rxrpc_skb(skb, 3, atomic_read(&skb->users), n, here); |
| 65 | kfree_skb(skb); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | /* |
| 70 | * Clear a queue of socket buffers. |
| 71 | */ |
| 72 | void rxrpc_purge_queue(struct sk_buff_head *list) |
| 73 | { |
| 74 | const void *here = __builtin_return_address(0); |
| 75 | struct sk_buff *skb; |
| 76 | while ((skb = skb_dequeue((list))) != NULL) { |
| 77 | int n = atomic_dec_return(&rxrpc_n_skbs); |
| 78 | trace_rxrpc_skb(skb, 4, atomic_read(&skb->users), n, here); |
| 79 | kfree_skb(skb); |
| 80 | } |
| 81 | } |