packet_history.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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/module.h>
  38. #include <linux/string.h>
  39. #include "packet_history.h"
  40. struct dccp_rx_hist *dccp_rx_hist_new(const char *name)
  41. {
  42. struct dccp_rx_hist *hist = kmalloc(sizeof(*hist), GFP_ATOMIC);
  43. static const char dccp_rx_hist_mask[] = "rx_hist_%s";
  44. char *slab_name;
  45. if (hist == NULL)
  46. goto out;
  47. slab_name = kmalloc(strlen(name) + sizeof(dccp_rx_hist_mask) - 1,
  48. GFP_ATOMIC);
  49. if (slab_name == NULL)
  50. goto out_free_hist;
  51. sprintf(slab_name, dccp_rx_hist_mask, name);
  52. hist->dccprxh_slab = kmem_cache_create(slab_name,
  53. sizeof(struct dccp_rx_hist_entry),
  54. 0, SLAB_HWCACHE_ALIGN,
  55. NULL, NULL);
  56. if (hist->dccprxh_slab == NULL)
  57. goto out_free_slab_name;
  58. out:
  59. return hist;
  60. out_free_slab_name:
  61. kfree(slab_name);
  62. out_free_hist:
  63. kfree(hist);
  64. hist = NULL;
  65. goto out;
  66. }
  67. EXPORT_SYMBOL_GPL(dccp_rx_hist_new);
  68. void dccp_rx_hist_delete(struct dccp_rx_hist *hist)
  69. {
  70. const char* name = kmem_cache_name(hist->dccprxh_slab);
  71. kmem_cache_destroy(hist->dccprxh_slab);
  72. kfree(name);
  73. kfree(hist);
  74. }
  75. EXPORT_SYMBOL_GPL(dccp_rx_hist_delete);
  76. void dccp_rx_hist_purge(struct dccp_rx_hist *hist, struct list_head *list)
  77. {
  78. struct dccp_rx_hist_entry *entry, *next;
  79. list_for_each_entry_safe(entry, next, list, dccphrx_node) {
  80. list_del_init(&entry->dccphrx_node);
  81. kmem_cache_free(hist->dccprxh_slab, entry);
  82. }
  83. }
  84. EXPORT_SYMBOL_GPL(dccp_rx_hist_purge);
  85. struct dccp_rx_hist_entry *
  86. dccp_rx_hist_find_data_packet(const struct list_head *list)
  87. {
  88. struct dccp_rx_hist_entry *entry, *packet = NULL;
  89. list_for_each_entry(entry, list, dccphrx_node)
  90. if (entry->dccphrx_type == DCCP_PKT_DATA ||
  91. entry->dccphrx_type == DCCP_PKT_DATAACK) {
  92. packet = entry;
  93. break;
  94. }
  95. return packet;
  96. }
  97. EXPORT_SYMBOL_GPL(dccp_rx_hist_find_data_packet);
  98. struct dccp_tx_hist *dccp_tx_hist_new(const char *name)
  99. {
  100. struct dccp_tx_hist *hist = kmalloc(sizeof(*hist), GFP_ATOMIC);
  101. static const char dccp_tx_hist_mask[] = "tx_hist_%s";
  102. char *slab_name;
  103. if (hist == NULL)
  104. goto out;
  105. slab_name = kmalloc(strlen(name) + sizeof(dccp_tx_hist_mask) - 1,
  106. GFP_ATOMIC);
  107. if (slab_name == NULL)
  108. goto out_free_hist;
  109. sprintf(slab_name, dccp_tx_hist_mask, name);
  110. hist->dccptxh_slab = kmem_cache_create(slab_name,
  111. sizeof(struct dccp_tx_hist_entry),
  112. 0, SLAB_HWCACHE_ALIGN,
  113. NULL, NULL);
  114. if (hist->dccptxh_slab == NULL)
  115. goto out_free_slab_name;
  116. out:
  117. return hist;
  118. out_free_slab_name:
  119. kfree(slab_name);
  120. out_free_hist:
  121. kfree(hist);
  122. hist = NULL;
  123. goto out;
  124. }
  125. EXPORT_SYMBOL_GPL(dccp_tx_hist_new);
  126. void dccp_tx_hist_delete(struct dccp_tx_hist *hist)
  127. {
  128. const char* name = kmem_cache_name(hist->dccptxh_slab);
  129. kmem_cache_destroy(hist->dccptxh_slab);
  130. kfree(name);
  131. kfree(hist);
  132. }
  133. EXPORT_SYMBOL_GPL(dccp_tx_hist_delete);
  134. struct dccp_tx_hist_entry *
  135. dccp_tx_hist_find_entry(const struct list_head *list, const u64 seq)
  136. {
  137. struct dccp_tx_hist_entry *packet = NULL, *entry;
  138. list_for_each_entry(entry, list, dccphtx_node)
  139. if (entry->dccphtx_seqno == seq) {
  140. packet = entry;
  141. break;
  142. }
  143. return packet;
  144. }
  145. EXPORT_SYMBOL_GPL(dccp_tx_hist_find_entry);
  146. void dccp_tx_hist_purge_older(struct dccp_tx_hist *hist,
  147. struct list_head *list,
  148. struct dccp_tx_hist_entry *packet)
  149. {
  150. struct dccp_tx_hist_entry *next;
  151. list_for_each_entry_safe_continue(packet, next, list, dccphtx_node) {
  152. list_del_init(&packet->dccphtx_node);
  153. dccp_tx_hist_entry_delete(hist, packet);
  154. }
  155. }
  156. EXPORT_SYMBOL_GPL(dccp_tx_hist_purge_older);
  157. void dccp_tx_hist_purge(struct dccp_tx_hist *hist, struct list_head *list)
  158. {
  159. struct dccp_tx_hist_entry *entry, *next;
  160. list_for_each_entry_safe(entry, next, list, dccphtx_node) {
  161. list_del_init(&entry->dccphtx_node);
  162. dccp_tx_hist_entry_delete(hist, entry);
  163. }
  164. }
  165. EXPORT_SYMBOL_GPL(dccp_tx_hist_purge);
  166. MODULE_AUTHOR("Ian McDonald <iam4@cs.waikato.ac.nz>, "
  167. "Arnaldo Carvalho de Melo <acme@ghostprotocols.net>");
  168. MODULE_DESCRIPTION("DCCP TFRC library");
  169. MODULE_LICENSE("GPL");