1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* ar-skbuff.c: socket buffer destruction handling
4 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
5 * Written by David Howells (dhowells@redhat.com)
8 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
10 #include <linux/module.h>
11 #include <linux/net.h>
12 #include <linux/skbuff.h>
14 #include <net/af_rxrpc.h>
15 #include "ar-internal.h"
17 #define select_skb_count(op) (op >= rxrpc_skb_tx_cleaned ? &rxrpc_n_tx_skbs : &rxrpc_n_rx_skbs)
20 * Note the allocation or reception of a socket buffer.
22 void rxrpc_new_skb(struct sk_buff
*skb
, enum rxrpc_skb_trace op
)
24 const void *here
= __builtin_return_address(0);
25 int n
= atomic_inc_return(select_skb_count(op
));
26 trace_rxrpc_skb(skb
, op
, refcount_read(&skb
->users
), n
, here
);
30 * Note the re-emergence of a socket buffer from a queue or buffer.
32 void rxrpc_see_skb(struct sk_buff
*skb
, enum rxrpc_skb_trace op
)
34 const void *here
= __builtin_return_address(0);
36 int n
= atomic_read(select_skb_count(op
));
37 trace_rxrpc_skb(skb
, op
, refcount_read(&skb
->users
), n
, here
);
42 * Note the addition of a ref on a socket buffer.
44 void rxrpc_get_skb(struct sk_buff
*skb
, enum rxrpc_skb_trace op
)
46 const void *here
= __builtin_return_address(0);
47 int n
= atomic_inc_return(select_skb_count(op
));
48 trace_rxrpc_skb(skb
, op
, refcount_read(&skb
->users
), n
, here
);
53 * Note the destruction of a socket buffer.
55 void rxrpc_free_skb(struct sk_buff
*skb
, enum rxrpc_skb_trace op
)
57 const void *here
= __builtin_return_address(0);
60 CHECK_SLAB_OKAY(&skb
->users
);
61 n
= atomic_dec_return(select_skb_count(op
));
62 trace_rxrpc_skb(skb
, op
, refcount_read(&skb
->users
), n
, here
);
68 * Clear a queue of socket buffers.
70 void rxrpc_purge_queue(struct sk_buff_head
*list
)
72 const void *here
= __builtin_return_address(0);
74 while ((skb
= skb_dequeue((list
))) != NULL
) {
75 int n
= atomic_dec_return(select_skb_count(rxrpc_skb_rx_purged
));
76 trace_rxrpc_skb(skb
, rxrpc_skb_rx_purged
,
77 refcount_read(&skb
->users
), n
, here
);