Commit | Line | Data |
---|---|---|
17926a79 DH |
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 | ||
9b6d5398 JP |
12 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
13 | ||
17926a79 DH |
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 | ||
71f3ca40 DH |
21 | #define select_skb_count(op) (op >= rxrpc_skb_tx_cleaned ? &rxrpc_n_tx_skbs : &rxrpc_n_rx_skbs) |
22 | ||
df844fd4 | 23 | /* |
71f3ca40 | 24 | * Note the allocation or reception of a socket buffer. |
df844fd4 | 25 | */ |
71f3ca40 | 26 | void rxrpc_new_skb(struct sk_buff *skb, enum rxrpc_skb_trace op) |
df844fd4 DH |
27 | { |
28 | const void *here = __builtin_return_address(0); | |
71f3ca40 DH |
29 | int n = atomic_inc_return(select_skb_count(op)); |
30 | trace_rxrpc_skb(skb, op, atomic_read(&skb->users), n, here); | |
df844fd4 DH |
31 | } |
32 | ||
33 | /* | |
34 | * Note the re-emergence of a socket buffer from a queue or buffer. | |
35 | */ | |
71f3ca40 | 36 | void rxrpc_see_skb(struct sk_buff *skb, enum rxrpc_skb_trace op) |
df844fd4 DH |
37 | { |
38 | const void *here = __builtin_return_address(0); | |
39 | if (skb) { | |
71f3ca40 DH |
40 | int n = atomic_read(select_skb_count(op)); |
41 | trace_rxrpc_skb(skb, op, atomic_read(&skb->users), n, here); | |
df844fd4 DH |
42 | } |
43 | } | |
44 | ||
45 | /* | |
46 | * Note the addition of a ref on a socket buffer. | |
47 | */ | |
71f3ca40 | 48 | void rxrpc_get_skb(struct sk_buff *skb, enum rxrpc_skb_trace op) |
df844fd4 DH |
49 | { |
50 | const void *here = __builtin_return_address(0); | |
71f3ca40 DH |
51 | int n = atomic_inc_return(select_skb_count(op)); |
52 | trace_rxrpc_skb(skb, op, atomic_read(&skb->users), n, here); | |
df844fd4 DH |
53 | skb_get(skb); |
54 | } | |
55 | ||
56 | /* | |
57 | * Note the destruction of a socket buffer. | |
58 | */ | |
71f3ca40 | 59 | void rxrpc_free_skb(struct sk_buff *skb, enum rxrpc_skb_trace op) |
df844fd4 DH |
60 | { |
61 | const void *here = __builtin_return_address(0); | |
62 | if (skb) { | |
63 | int n; | |
64 | CHECK_SLAB_OKAY(&skb->users); | |
71f3ca40 DH |
65 | n = atomic_dec_return(select_skb_count(op)); |
66 | trace_rxrpc_skb(skb, op, atomic_read(&skb->users), n, here); | |
df844fd4 DH |
67 | kfree_skb(skb); |
68 | } | |
69 | } | |
70 | ||
71f3ca40 DH |
71 | /* |
72 | * Note the injected loss of a socket buffer. | |
73 | */ | |
74 | void rxrpc_lose_skb(struct sk_buff *skb, enum rxrpc_skb_trace op) | |
75 | { | |
76 | const void *here = __builtin_return_address(0); | |
77 | if (skb) { | |
78 | int n; | |
79 | CHECK_SLAB_OKAY(&skb->users); | |
80 | if (op == rxrpc_skb_tx_lost) { | |
81 | n = atomic_read(select_skb_count(op)); | |
82 | trace_rxrpc_skb(skb, op, atomic_read(&skb->users), n, here); | |
83 | } else { | |
84 | n = atomic_dec_return(select_skb_count(op)); | |
85 | trace_rxrpc_skb(skb, op, atomic_read(&skb->users), n, here); | |
86 | kfree_skb(skb); | |
87 | } | |
88 | } | |
89 | } | |
90 | ||
df844fd4 DH |
91 | /* |
92 | * Clear a queue of socket buffers. | |
93 | */ | |
94 | void rxrpc_purge_queue(struct sk_buff_head *list) | |
95 | { | |
96 | const void *here = __builtin_return_address(0); | |
97 | struct sk_buff *skb; | |
98 | while ((skb = skb_dequeue((list))) != NULL) { | |
71f3ca40 DH |
99 | int n = atomic_dec_return(select_skb_count(rxrpc_skb_rx_purged)); |
100 | trace_rxrpc_skb(skb, rxrpc_skb_rx_purged, | |
101 | atomic_read(&skb->users), n, here); | |
df844fd4 DH |
102 | kfree_skb(skb); |
103 | } | |
104 | } |