skbuff.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  12. #include <linux/module.h>
  13. #include <linux/net.h>
  14. #include <linux/skbuff.h>
  15. #include <net/sock.h>
  16. #include <net/af_rxrpc.h>
  17. #include "ar-internal.h"
  18. #define select_skb_count(op) (op >= rxrpc_skb_tx_cleaned ? &rxrpc_n_tx_skbs : &rxrpc_n_rx_skbs)
  19. /*
  20. * Note the allocation or reception of a socket buffer.
  21. */
  22. void rxrpc_new_skb(struct sk_buff *skb, enum rxrpc_skb_trace op)
  23. {
  24. const void *here = __builtin_return_address(0);
  25. int n = atomic_inc_return(select_skb_count(op));
  26. trace_rxrpc_skb(skb, op, atomic_read(&skb->users), n, here);
  27. }
  28. /*
  29. * Note the re-emergence of a socket buffer from a queue or buffer.
  30. */
  31. void rxrpc_see_skb(struct sk_buff *skb, enum rxrpc_skb_trace op)
  32. {
  33. const void *here = __builtin_return_address(0);
  34. if (skb) {
  35. int n = atomic_read(select_skb_count(op));
  36. trace_rxrpc_skb(skb, op, atomic_read(&skb->users), n, here);
  37. }
  38. }
  39. /*
  40. * Note the addition of a ref on a socket buffer.
  41. */
  42. void rxrpc_get_skb(struct sk_buff *skb, enum rxrpc_skb_trace op)
  43. {
  44. const void *here = __builtin_return_address(0);
  45. int n = atomic_inc_return(select_skb_count(op));
  46. trace_rxrpc_skb(skb, op, atomic_read(&skb->users), n, here);
  47. skb_get(skb);
  48. }
  49. /*
  50. * Note the destruction of a socket buffer.
  51. */
  52. void rxrpc_free_skb(struct sk_buff *skb, enum rxrpc_skb_trace op)
  53. {
  54. const void *here = __builtin_return_address(0);
  55. if (skb) {
  56. int n;
  57. CHECK_SLAB_OKAY(&skb->users);
  58. n = atomic_dec_return(select_skb_count(op));
  59. trace_rxrpc_skb(skb, op, atomic_read(&skb->users), n, here);
  60. kfree_skb(skb);
  61. }
  62. }
  63. /*
  64. * Note the injected loss of a socket buffer.
  65. */
  66. void rxrpc_lose_skb(struct sk_buff *skb, enum rxrpc_skb_trace op)
  67. {
  68. const void *here = __builtin_return_address(0);
  69. if (skb) {
  70. int n;
  71. CHECK_SLAB_OKAY(&skb->users);
  72. n = atomic_dec_return(select_skb_count(op));
  73. trace_rxrpc_skb(skb, op, atomic_read(&skb->users), n, here);
  74. kfree_skb(skb);
  75. }
  76. }
  77. /*
  78. * Clear a queue of socket buffers.
  79. */
  80. void rxrpc_purge_queue(struct sk_buff_head *list)
  81. {
  82. const void *here = __builtin_return_address(0);
  83. struct sk_buff *skb;
  84. while ((skb = skb_dequeue((list))) != NULL) {
  85. int n = atomic_dec_return(select_skb_count(rxrpc_skb_rx_purged));
  86. trace_rxrpc_skb(skb, rxrpc_skb_rx_purged,
  87. atomic_read(&skb->users), n, here);
  88. kfree_skb(skb);
  89. }
  90. }