tsnmap.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /* SCTP kernel reference Implementation
  2. * (C) Copyright IBM Corp. 2001, 2004
  3. * Copyright (c) 1999-2000 Cisco, Inc.
  4. * Copyright (c) 1999-2001 Motorola, Inc.
  5. * Copyright (c) 2001 Intel Corp.
  6. *
  7. * This file is part of the SCTP kernel reference Implementation
  8. *
  9. * These are the definitions needed for the tsnmap type. The tsnmap is used
  10. * to track out of order TSNs received.
  11. *
  12. * The SCTP reference implementation is free software;
  13. * you can redistribute it and/or modify it under the terms of
  14. * the GNU General Public License as published by
  15. * the Free Software Foundation; either version 2, or (at your option)
  16. * any later version.
  17. *
  18. * The SCTP reference implementation is distributed in the hope that it
  19. * will be useful, but WITHOUT ANY WARRANTY; without even the implied
  20. * ************************
  21. * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  22. * See the GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with GNU CC; see the file COPYING. If not, write to
  26. * the Free Software Foundation, 59 Temple Place - Suite 330,
  27. * Boston, MA 02111-1307, USA.
  28. *
  29. * Please send any bug reports or fixes you make to the
  30. * email address(es):
  31. * lksctp developers <lksctp-developers@lists.sourceforge.net>
  32. *
  33. * Or submit a bug report through the following website:
  34. * http://www.sf.net/projects/lksctp
  35. *
  36. * Written or modified by:
  37. * Jon Grimm <jgrimm@us.ibm.com>
  38. * La Monte H.P. Yarroll <piggy@acm.org>
  39. * Karl Knutson <karl@athena.chicago.il.us>
  40. * Sridhar Samudrala <sri@us.ibm.com>
  41. *
  42. * Any bugs reported given to us we will try to fix... any fixes shared will
  43. * be incorporated into the next SCTP release.
  44. */
  45. #include <net/sctp/constants.h>
  46. #ifndef __sctp_tsnmap_h__
  47. #define __sctp_tsnmap_h__
  48. /* RFC 2960 12.2 Parameters necessary per association (i.e. the TCB)
  49. * Mapping An array of bits or bytes indicating which out of
  50. * Array order TSN's have been received (relative to the
  51. * Last Rcvd TSN). If no gaps exist, i.e. no out of
  52. * order packets have been received, this array
  53. * will be set to all zero. This structure may be
  54. * in the form of a circular buffer or bit array.
  55. */
  56. struct sctp_tsnmap {
  57. /* This array counts the number of chunks with each TSN.
  58. * It points at one of the two buffers with which we will
  59. * ping-pong between.
  60. */
  61. __u8 *tsn_map;
  62. /* This marks the tsn which overflows the tsn_map, when the
  63. * cumulative ack point reaches this point we know we can switch
  64. * maps (tsn_map and overflow_map swap).
  65. */
  66. __u32 overflow_tsn;
  67. /* This is the overflow array for tsn_map.
  68. * It points at one of the other ping-pong buffers.
  69. */
  70. __u8 *overflow_map;
  71. /* This is the TSN at tsn_map[0]. */
  72. __u32 base_tsn;
  73. /* Last Rcvd : This is the last TSN received in
  74. * TSN : sequence. This value is set initially by
  75. * : taking the peer's Initial TSN, received in
  76. * : the INIT or INIT ACK chunk, and subtracting
  77. * : one from it.
  78. *
  79. * Throughout most of the specification this is called the
  80. * "Cumulative TSN ACK Point". In this case, we
  81. * ignore the advice in 12.2 in favour of the term
  82. * used in the bulk of the text.
  83. */
  84. __u32 cumulative_tsn_ack_point;
  85. /* This is the minimum number of TSNs we can track. This corresponds
  86. * to the size of tsn_map. Note: the overflow_map allows us to
  87. * potentially track more than this quantity.
  88. */
  89. __u16 len;
  90. /* This is the highest TSN we've marked. */
  91. __u32 max_tsn_seen;
  92. /* Data chunks pending receipt. used by SCTP_STATUS sockopt */
  93. __u16 pending_data;
  94. /* Record duplicate TSNs here. We clear this after
  95. * every SACK. Store up to SCTP_MAX_DUP_TSNS worth of
  96. * information.
  97. */
  98. __be32 dup_tsns[SCTP_MAX_DUP_TSNS];
  99. __u16 num_dup_tsns;
  100. /* Record gap ack block information here. */
  101. struct sctp_gap_ack_block gabs[SCTP_MAX_GABS];
  102. int malloced;
  103. __u8 raw_map[0];
  104. };
  105. struct sctp_tsnmap_iter {
  106. __u32 start;
  107. };
  108. /* This macro assists in creation of external storage for variable length
  109. * internal buffers. We double allocate so the overflow map works.
  110. */
  111. #define sctp_tsnmap_storage_size(count) (sizeof(__u8) * (count) * 2)
  112. /* Initialize a block of memory as a tsnmap. */
  113. struct sctp_tsnmap *sctp_tsnmap_init(struct sctp_tsnmap *, __u16 len,
  114. __u32 initial_tsn);
  115. /* Test the tracking state of this TSN.
  116. * Returns:
  117. * 0 if the TSN has not yet been seen
  118. * >0 if the TSN has been seen (duplicate)
  119. * <0 if the TSN is invalid (too large to track)
  120. */
  121. int sctp_tsnmap_check(const struct sctp_tsnmap *, __u32 tsn);
  122. /* Mark this TSN as seen. */
  123. void sctp_tsnmap_mark(struct sctp_tsnmap *, __u32 tsn);
  124. /* Mark this TSN and all lower as seen. */
  125. void sctp_tsnmap_skip(struct sctp_tsnmap *map, __u32 tsn);
  126. /* Retrieve the Cumulative TSN ACK Point. */
  127. static inline __u32 sctp_tsnmap_get_ctsn(const struct sctp_tsnmap *map)
  128. {
  129. return map->cumulative_tsn_ack_point;
  130. }
  131. /* Retrieve the highest TSN we've seen. */
  132. static inline __u32 sctp_tsnmap_get_max_tsn_seen(const struct sctp_tsnmap *map)
  133. {
  134. return map->max_tsn_seen;
  135. }
  136. /* How many duplicate TSNs are stored? */
  137. static inline __u16 sctp_tsnmap_num_dups(struct sctp_tsnmap *map)
  138. {
  139. return map->num_dup_tsns;
  140. }
  141. /* Return pointer to duplicate tsn array as needed by SACK. */
  142. static inline __be32 *sctp_tsnmap_get_dups(struct sctp_tsnmap *map)
  143. {
  144. map->num_dup_tsns = 0;
  145. return map->dup_tsns;
  146. }
  147. /* How many gap ack blocks do we have recorded? */
  148. __u16 sctp_tsnmap_num_gabs(struct sctp_tsnmap *map);
  149. /* Refresh the count on pending data. */
  150. __u16 sctp_tsnmap_pending(struct sctp_tsnmap *map);
  151. /* Return pointer to gap ack blocks as needed by SACK. */
  152. static inline struct sctp_gap_ack_block *sctp_tsnmap_get_gabs(struct sctp_tsnmap *map)
  153. {
  154. return map->gabs;
  155. }
  156. /* Is there a gap in the TSN map? */
  157. static inline int sctp_tsnmap_has_gap(const struct sctp_tsnmap *map)
  158. {
  159. int has_gap;
  160. has_gap = (map->cumulative_tsn_ack_point != map->max_tsn_seen);
  161. return has_gap;
  162. }
  163. /* Mark a duplicate TSN. Note: limit the storage of duplicate TSN
  164. * information.
  165. */
  166. static inline void sctp_tsnmap_mark_dup(struct sctp_tsnmap *map, __u32 tsn)
  167. {
  168. if (map->num_dup_tsns < SCTP_MAX_DUP_TSNS)
  169. map->dup_tsns[map->num_dup_tsns++] = htonl(tsn);
  170. }
  171. /* Renege a TSN that was seen. */
  172. void sctp_tsnmap_renege(struct sctp_tsnmap *, __u32 tsn);
  173. /* Is there a gap in the TSN map? */
  174. int sctp_tsnmap_has_gap(const struct sctp_tsnmap *);
  175. #endif /* __sctp_tsnmap_h__ */