1 // SPDX-License-Identifier: GPL-2.0-or-later 1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* Socket buffer accounting 2 /* Socket buffer accounting 3 * 3 * 4 * Copyright (C) 2007 Red Hat, Inc. All Rights 4 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved. 5 * Written by David Howells (dhowells@redhat.c 5 * Written by David Howells (dhowells@redhat.com) 6 */ 6 */ 7 7 8 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 8 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 9 9 10 #include <linux/module.h> 10 #include <linux/module.h> 11 #include <linux/net.h> 11 #include <linux/net.h> 12 #include <linux/skbuff.h> 12 #include <linux/skbuff.h> 13 #include <net/sock.h> 13 #include <net/sock.h> 14 #include <net/af_rxrpc.h> 14 #include <net/af_rxrpc.h> 15 #include "ar-internal.h" 15 #include "ar-internal.h" 16 16 17 #define select_skb_count(skb) (&rxrpc_n_rx_skb 17 #define select_skb_count(skb) (&rxrpc_n_rx_skbs) 18 18 19 /* 19 /* 20 * Note the allocation or reception of a socke 20 * Note the allocation or reception of a socket buffer. 21 */ 21 */ 22 void rxrpc_new_skb(struct sk_buff *skb, enum r 22 void rxrpc_new_skb(struct sk_buff *skb, enum rxrpc_skb_trace why) 23 { 23 { 24 int n = atomic_inc_return(select_skb_c 24 int n = atomic_inc_return(select_skb_count(skb)); 25 trace_rxrpc_skb(skb, refcount_read(&sk 25 trace_rxrpc_skb(skb, refcount_read(&skb->users), n, why); 26 } 26 } 27 27 28 /* 28 /* 29 * Note the re-emergence of a socket buffer fr 29 * Note the re-emergence of a socket buffer from a queue or buffer. 30 */ 30 */ 31 void rxrpc_see_skb(struct sk_buff *skb, enum r 31 void rxrpc_see_skb(struct sk_buff *skb, enum rxrpc_skb_trace why) 32 { 32 { 33 if (skb) { 33 if (skb) { 34 int n = atomic_read(select_skb 34 int n = atomic_read(select_skb_count(skb)); 35 trace_rxrpc_skb(skb, refcount_ 35 trace_rxrpc_skb(skb, refcount_read(&skb->users), n, why); 36 } 36 } 37 } 37 } 38 38 39 /* 39 /* 40 * Note the addition of a ref on a socket buff 40 * Note the addition of a ref on a socket buffer. 41 */ 41 */ 42 void rxrpc_get_skb(struct sk_buff *skb, enum r 42 void rxrpc_get_skb(struct sk_buff *skb, enum rxrpc_skb_trace why) 43 { 43 { 44 int n = atomic_inc_return(select_skb_c 44 int n = atomic_inc_return(select_skb_count(skb)); 45 trace_rxrpc_skb(skb, refcount_read(&sk 45 trace_rxrpc_skb(skb, refcount_read(&skb->users), n, why); 46 skb_get(skb); 46 skb_get(skb); 47 } 47 } 48 48 49 /* 49 /* 50 * Note the dropping of a ref on a socket buff 50 * Note the dropping of a ref on a socket buffer by the core. 51 */ 51 */ 52 void rxrpc_eaten_skb(struct sk_buff *skb, enum 52 void rxrpc_eaten_skb(struct sk_buff *skb, enum rxrpc_skb_trace why) 53 { 53 { 54 int n = atomic_inc_return(&rxrpc_n_rx_ 54 int n = atomic_inc_return(&rxrpc_n_rx_skbs); 55 trace_rxrpc_skb(skb, 0, n, why); 55 trace_rxrpc_skb(skb, 0, n, why); 56 } 56 } 57 57 58 /* 58 /* 59 * Note the destruction of a socket buffer. 59 * Note the destruction of a socket buffer. 60 */ 60 */ 61 void rxrpc_free_skb(struct sk_buff *skb, enum 61 void rxrpc_free_skb(struct sk_buff *skb, enum rxrpc_skb_trace why) 62 { 62 { 63 if (skb) { 63 if (skb) { 64 int n = atomic_dec_return(sele 64 int n = atomic_dec_return(select_skb_count(skb)); 65 trace_rxrpc_skb(skb, refcount_ 65 trace_rxrpc_skb(skb, refcount_read(&skb->users), n, why); 66 consume_skb(skb); !! 66 kfree_skb(skb); 67 } 67 } 68 } 68 } 69 69 70 /* 70 /* 71 * Clear a queue of socket buffers. 71 * Clear a queue of socket buffers. 72 */ 72 */ 73 void rxrpc_purge_queue(struct sk_buff_head *li 73 void rxrpc_purge_queue(struct sk_buff_head *list) 74 { 74 { 75 struct sk_buff *skb; 75 struct sk_buff *skb; 76 76 77 while ((skb = skb_dequeue((list))) != 77 while ((skb = skb_dequeue((list))) != NULL) { 78 int n = atomic_dec_return(sele 78 int n = atomic_dec_return(select_skb_count(skb)); 79 trace_rxrpc_skb(skb, refcount_ 79 trace_rxrpc_skb(skb, refcount_read(&skb->users), n, 80 rxrpc_skb_put_ 80 rxrpc_skb_put_purge); 81 consume_skb(skb); !! 81 kfree_skb(skb); 82 } 82 } 83 } 83 } 84 84
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.