skbuff.c 2.0 KB

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