blob: 913dca65cc6573d646f54a9583b9dbc5d7f6f017 [file] [log] [blame]
David Howells17926a72007-04-26 15:48:28 -07001/* 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
Joe Perches9b6d5392016-06-02 12:08:52 -070012#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13
David Howells17926a72007-04-26 15:48:28 -070014#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
David Howells71f3ca42016-09-17 10:49:14 +010021#define select_skb_count(op) (op >= rxrpc_skb_tx_cleaned ? &rxrpc_n_tx_skbs : &rxrpc_n_rx_skbs)
22
David Howells17926a72007-04-26 15:48:28 -070023/*
David Howells71f3ca42016-09-17 10:49:14 +010024 * Note the allocation or reception of a socket buffer.
David Howellsdf844fd2016-08-23 15:27:24 +010025 */
David Howells71f3ca42016-09-17 10:49:14 +010026void rxrpc_new_skb(struct sk_buff *skb, enum rxrpc_skb_trace op)
David Howellsdf844fd2016-08-23 15:27:24 +010027{
28 const void *here = __builtin_return_address(0);
David Howells71f3ca42016-09-17 10:49:14 +010029 int n = atomic_inc_return(select_skb_count(op));
Reshetova, Elena63354792017-06-30 13:07:58 +030030 trace_rxrpc_skb(skb, op, refcount_read(&skb->users), n, here);
David Howellsdf844fd2016-08-23 15:27:24 +010031}
32
33/*
34 * Note the re-emergence of a socket buffer from a queue or buffer.
35 */
David Howells71f3ca42016-09-17 10:49:14 +010036void rxrpc_see_skb(struct sk_buff *skb, enum rxrpc_skb_trace op)
David Howellsdf844fd2016-08-23 15:27:24 +010037{
38 const void *here = __builtin_return_address(0);
39 if (skb) {
David Howells71f3ca42016-09-17 10:49:14 +010040 int n = atomic_read(select_skb_count(op));
Reshetova, Elena63354792017-06-30 13:07:58 +030041 trace_rxrpc_skb(skb, op, refcount_read(&skb->users), n, here);
David Howellsdf844fd2016-08-23 15:27:24 +010042 }
43}
44
45/*
46 * Note the addition of a ref on a socket buffer.
47 */
David Howells71f3ca42016-09-17 10:49:14 +010048void rxrpc_get_skb(struct sk_buff *skb, enum rxrpc_skb_trace op)
David Howellsdf844fd2016-08-23 15:27:24 +010049{
50 const void *here = __builtin_return_address(0);
David Howells71f3ca42016-09-17 10:49:14 +010051 int n = atomic_inc_return(select_skb_count(op));
Reshetova, Elena63354792017-06-30 13:07:58 +030052 trace_rxrpc_skb(skb, op, refcount_read(&skb->users), n, here);
David Howellsdf844fd2016-08-23 15:27:24 +010053 skb_get(skb);
54}
55
56/*
57 * Note the destruction of a socket buffer.
58 */
David Howells71f3ca42016-09-17 10:49:14 +010059void rxrpc_free_skb(struct sk_buff *skb, enum rxrpc_skb_trace op)
David Howellsdf844fd2016-08-23 15:27:24 +010060{
61 const void *here = __builtin_return_address(0);
62 if (skb) {
63 int n;
64 CHECK_SLAB_OKAY(&skb->users);
David Howells71f3ca42016-09-17 10:49:14 +010065 n = atomic_dec_return(select_skb_count(op));
Reshetova, Elena63354792017-06-30 13:07:58 +030066 trace_rxrpc_skb(skb, op, refcount_read(&skb->users), n, here);
David Howellsdf844fd2016-08-23 15:27:24 +010067 kfree_skb(skb);
68 }
69}
70
71/*
72 * Clear a queue of socket buffers.
73 */
74void rxrpc_purge_queue(struct sk_buff_head *list)
75{
76 const void *here = __builtin_return_address(0);
77 struct sk_buff *skb;
78 while ((skb = skb_dequeue((list))) != NULL) {
David Howells71f3ca42016-09-17 10:49:14 +010079 int n = atomic_dec_return(select_skb_count(rxrpc_skb_rx_purged));
80 trace_rxrpc_skb(skb, rxrpc_skb_rx_purged,
Reshetova, Elena63354792017-06-30 13:07:58 +030081 refcount_read(&skb->users), n, here);
David Howellsdf844fd2016-08-23 15:27:24 +010082 kfree_skb(skb);
83 }
84}