packet_history.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*
  2. * net/dccp/packet_history.h
  3. *
  4. * Copyright (c) 2005 The University of Waikato, Hamilton, New Zealand.
  5. *
  6. * An implementation of the DCCP protocol
  7. *
  8. * This code has been developed by the University of Waikato WAND
  9. * research group. For further information please see http://www.wand.net.nz/
  10. * or e-mail Ian McDonald - iam4@cs.waikato.ac.nz
  11. *
  12. * This code also uses code from Lulea University, rereleased as GPL by its
  13. * authors:
  14. * Copyright (c) 2003 Nils-Erik Mattsson, Joacim Haggmark, Magnus Erixzon
  15. *
  16. * Changes to meet Linux coding standards, to make it meet latest ccid3 draft
  17. * and to make it work as a loadable module in the DCCP stack written by
  18. * Arnaldo Carvalho de Melo <acme@conectiva.com.br>.
  19. *
  20. * Copyright (c) 2005 Arnaldo Carvalho de Melo <acme@conectiva.com.br>
  21. *
  22. * This program is free software; you can redistribute it and/or modify
  23. * it under the terms of the GNU General Public License as published by
  24. * the Free Software Foundation; either version 2 of the License, or
  25. * (at your option) any later version.
  26. *
  27. * This program is distributed in the hope that it will be useful,
  28. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  29. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  30. * GNU General Public License for more details.
  31. *
  32. * You should have received a copy of the GNU General Public License
  33. * along with this program; if not, write to the Free Software
  34. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  35. */
  36. #include <linux/config.h>
  37. #include <linux/string.h>
  38. #include "packet_history.h"
  39. struct dccp_rx_hist *dccp_rx_hist_new(const char *name)
  40. {
  41. struct dccp_rx_hist *hist = kmalloc(sizeof(*hist), GFP_ATOMIC);
  42. static const char dccp_rx_hist_mask[] = "rx_hist_%s";
  43. char *slab_name;
  44. if (hist == NULL)
  45. goto out;
  46. slab_name = kmalloc(strlen(name) + sizeof(dccp_rx_hist_mask) - 1,
  47. GFP_ATOMIC);
  48. if (slab_name == NULL)
  49. goto out_free_hist;
  50. sprintf(slab_name, dccp_rx_hist_mask, name);
  51. hist->dccprxh_slab = kmem_cache_create(slab_name,
  52. sizeof(struct dccp_rx_hist_entry),
  53. 0, SLAB_HWCACHE_ALIGN,
  54. NULL, NULL);
  55. if (hist->dccprxh_slab == NULL)
  56. goto out_free_slab_name;
  57. out:
  58. return hist;
  59. out_free_slab_name:
  60. kfree(slab_name);
  61. out_free_hist:
  62. kfree(hist);
  63. hist = NULL;
  64. goto out;
  65. }
  66. EXPORT_SYMBOL_GPL(dccp_rx_hist_new);
  67. void dccp_rx_hist_delete(struct dccp_rx_hist *hist)
  68. {
  69. const char* name = kmem_cache_name(hist->dccprxh_slab);
  70. kmem_cache_destroy(hist->dccprxh_slab);
  71. kfree(name);
  72. kfree(hist);
  73. }
  74. EXPORT_SYMBOL_GPL(dccp_rx_hist_delete);
  75. void dccp_rx_hist_purge(struct dccp_rx_hist *hist, struct list_head *list)
  76. {
  77. struct dccp_rx_hist_entry *entry, *next;
  78. list_for_each_entry_safe(entry, next, list, dccphrx_node) {
  79. list_del_init(&entry->dccphrx_node);
  80. kmem_cache_free(hist->dccprxh_slab, entry);
  81. }
  82. }
  83. EXPORT_SYMBOL_GPL(dccp_rx_hist_purge);
  84. struct dccp_rx_hist_entry *
  85. dccp_rx_hist_find_data_packet(const struct list_head *list)
  86. {
  87. struct dccp_rx_hist_entry *entry, *packet = NULL;
  88. list_for_each_entry(entry, list, dccphrx_node)
  89. if (entry->dccphrx_type == DCCP_PKT_DATA ||
  90. entry->dccphrx_type == DCCP_PKT_DATAACK) {
  91. packet = entry;
  92. break;
  93. }
  94. return packet;
  95. }
  96. EXPORT_SYMBOL_GPL(dccp_rx_hist_find_data_packet);
  97. struct dccp_tx_hist *dccp_tx_hist_new(const char *name)
  98. {
  99. struct dccp_tx_hist *hist = kmalloc(sizeof(*hist), GFP_ATOMIC);
  100. static const char dccp_tx_hist_mask[] = "tx_hist_%s";
  101. char *slab_name;
  102. if (hist == NULL)
  103. goto out;
  104. slab_name = kmalloc(strlen(name) + sizeof(dccp_tx_hist_mask) - 1,
  105. GFP_ATOMIC);
  106. if (slab_name == NULL)
  107. goto out_free_hist;
  108. sprintf(slab_name, dccp_tx_hist_mask, name);
  109. hist->dccptxh_slab = kmem_cache_create(slab_name,
  110. sizeof(struct dccp_tx_hist_entry),
  111. 0, SLAB_HWCACHE_ALIGN,
  112. NULL, NULL);
  113. if (hist->dccptxh_slab == NULL)
  114. goto out_free_slab_name;
  115. out:
  116. return hist;
  117. out_free_slab_name:
  118. kfree(slab_name);
  119. out_free_hist:
  120. kfree(hist);
  121. hist = NULL;
  122. goto out;
  123. }
  124. EXPORT_SYMBOL_GPL(dccp_tx_hist_new);
  125. void dccp_tx_hist_delete(struct dccp_tx_hist *hist)
  126. {
  127. const char* name = kmem_cache_name(hist->dccptxh_slab);
  128. kmem_cache_destroy(hist->dccptxh_slab);
  129. kfree(name);
  130. kfree(hist);
  131. }
  132. EXPORT_SYMBOL_GPL(dccp_tx_hist_delete);
  133. struct dccp_tx_hist_entry *
  134. dccp_tx_hist_find_entry(const struct list_head *list, const u64 seq)
  135. {
  136. struct dccp_tx_hist_entry *packet = NULL, *entry;
  137. list_for_each_entry(entry, list, dccphtx_node)
  138. if (entry->dccphtx_seqno == seq) {
  139. packet = entry;
  140. break;
  141. }
  142. return packet;
  143. }
  144. EXPORT_SYMBOL_GPL(dccp_tx_hist_find_entry);
  145. void dccp_tx_hist_purge_older(struct dccp_tx_hist *hist,
  146. struct list_head *list,
  147. struct dccp_tx_hist_entry *packet)
  148. {
  149. struct dccp_tx_hist_entry *next;
  150. list_for_each_entry_safe_continue(packet, next, list, dccphtx_node) {
  151. list_del_init(&packet->dccphtx_node);
  152. dccp_tx_hist_entry_delete(hist, packet);
  153. }
  154. }
  155. EXPORT_SYMBOL_GPL(dccp_tx_hist_purge_older);
  156. void dccp_tx_hist_purge(struct dccp_tx_hist *hist, struct list_head *list)
  157. {
  158. struct dccp_tx_hist_entry *entry, *next;
  159. list_for_each_entry_safe(entry, next, list, dccphtx_node) {
  160. list_del_init(&entry->dccphtx_node);
  161. dccp_tx_hist_entry_delete(hist, entry);
  162. }
  163. }
  164. EXPORT_SYMBOL_GPL(dccp_tx_hist_purge);