tsnmap.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /* SCTP kernel implementation
  3. * (C) Copyright IBM Corp. 2001, 2004
  4. * Copyright (c) 1999-2000 Cisco, Inc.
  5. * Copyright (c) 1999-2001 Motorola, Inc.
  6. * Copyright (c) 2001 Intel Corp.
  7. *
  8. * This file is part of the SCTP kernel implementation
  9. *
  10. * These are the definitions needed for the tsnmap type. The tsnmap is used
  11. * to track out of order TSNs received.
  12. *
  13. * Please send any bug reports or fixes you make to the
  14. * email address(es):
  15. * lksctp developers <[email protected]>
  16. *
  17. * Written or modified by:
  18. * Jon Grimm <[email protected]>
  19. * La Monte H.P. Yarroll <[email protected]>
  20. * Karl Knutson <[email protected]>
  21. * Sridhar Samudrala <[email protected]>
  22. */
  23. #include <net/sctp/constants.h>
  24. #ifndef __sctp_tsnmap_h__
  25. #define __sctp_tsnmap_h__
  26. /* RFC 2960 12.2 Parameters necessary per association (i.e. the TCB)
  27. * Mapping An array of bits or bytes indicating which out of
  28. * Array order TSN's have been received (relative to the
  29. * Last Rcvd TSN). If no gaps exist, i.e. no out of
  30. * order packets have been received, this array
  31. * will be set to all zero. This structure may be
  32. * in the form of a circular buffer or bit array.
  33. */
  34. struct sctp_tsnmap {
  35. /* This array counts the number of chunks with each TSN.
  36. * It points at one of the two buffers with which we will
  37. * ping-pong between.
  38. */
  39. unsigned long *tsn_map;
  40. /* This is the TSN at tsn_map[0]. */
  41. __u32 base_tsn;
  42. /* Last Rcvd : This is the last TSN received in
  43. * TSN : sequence. This value is set initially by
  44. * : taking the peer's Initial TSN, received in
  45. * : the INIT or INIT ACK chunk, and subtracting
  46. * : one from it.
  47. *
  48. * Throughout most of the specification this is called the
  49. * "Cumulative TSN ACK Point". In this case, we
  50. * ignore the advice in 12.2 in favour of the term
  51. * used in the bulk of the text.
  52. */
  53. __u32 cumulative_tsn_ack_point;
  54. /* This is the highest TSN we've marked. */
  55. __u32 max_tsn_seen;
  56. /* This is the minimum number of TSNs we can track. This corresponds
  57. * to the size of tsn_map. Note: the overflow_map allows us to
  58. * potentially track more than this quantity.
  59. */
  60. __u16 len;
  61. /* Data chunks pending receipt. used by SCTP_STATUS sockopt */
  62. __u16 pending_data;
  63. /* Record duplicate TSNs here. We clear this after
  64. * every SACK. Store up to SCTP_MAX_DUP_TSNS worth of
  65. * information.
  66. */
  67. __u16 num_dup_tsns;
  68. __be32 dup_tsns[SCTP_MAX_DUP_TSNS];
  69. };
  70. struct sctp_tsnmap_iter {
  71. __u32 start;
  72. };
  73. /* Initialize a block of memory as a tsnmap. */
  74. struct sctp_tsnmap *sctp_tsnmap_init(struct sctp_tsnmap *, __u16 len,
  75. __u32 initial_tsn, gfp_t gfp);
  76. void sctp_tsnmap_free(struct sctp_tsnmap *map);
  77. /* Test the tracking state of this TSN.
  78. * Returns:
  79. * 0 if the TSN has not yet been seen
  80. * >0 if the TSN has been seen (duplicate)
  81. * <0 if the TSN is invalid (too large to track)
  82. */
  83. int sctp_tsnmap_check(const struct sctp_tsnmap *, __u32 tsn);
  84. /* Mark this TSN as seen. */
  85. int sctp_tsnmap_mark(struct sctp_tsnmap *, __u32 tsn,
  86. struct sctp_transport *trans);
  87. /* Mark this TSN and all lower as seen. */
  88. void sctp_tsnmap_skip(struct sctp_tsnmap *map, __u32 tsn);
  89. /* Retrieve the Cumulative TSN ACK Point. */
  90. static inline __u32 sctp_tsnmap_get_ctsn(const struct sctp_tsnmap *map)
  91. {
  92. return map->cumulative_tsn_ack_point;
  93. }
  94. /* Retrieve the highest TSN we've seen. */
  95. static inline __u32 sctp_tsnmap_get_max_tsn_seen(const struct sctp_tsnmap *map)
  96. {
  97. return map->max_tsn_seen;
  98. }
  99. /* How many duplicate TSNs are stored? */
  100. static inline __u16 sctp_tsnmap_num_dups(struct sctp_tsnmap *map)
  101. {
  102. return map->num_dup_tsns;
  103. }
  104. /* Return pointer to duplicate tsn array as needed by SACK. */
  105. static inline __be32 *sctp_tsnmap_get_dups(struct sctp_tsnmap *map)
  106. {
  107. map->num_dup_tsns = 0;
  108. return map->dup_tsns;
  109. }
  110. /* How many gap ack blocks do we have recorded? */
  111. __u16 sctp_tsnmap_num_gabs(struct sctp_tsnmap *map,
  112. struct sctp_gap_ack_block *gabs);
  113. /* Refresh the count on pending data. */
  114. __u16 sctp_tsnmap_pending(struct sctp_tsnmap *map);
  115. /* Is there a gap in the TSN map? */
  116. static inline int sctp_tsnmap_has_gap(const struct sctp_tsnmap *map)
  117. {
  118. return map->cumulative_tsn_ack_point != map->max_tsn_seen;
  119. }
  120. /* Mark a duplicate TSN. Note: limit the storage of duplicate TSN
  121. * information.
  122. */
  123. static inline void sctp_tsnmap_mark_dup(struct sctp_tsnmap *map, __u32 tsn)
  124. {
  125. if (map->num_dup_tsns < SCTP_MAX_DUP_TSNS)
  126. map->dup_tsns[map->num_dup_tsns++] = htonl(tsn);
  127. }
  128. /* Renege a TSN that was seen. */
  129. void sctp_tsnmap_renege(struct sctp_tsnmap *, __u32 tsn);
  130. /* Is there a gap in the TSN map? */
  131. int sctp_tsnmap_has_gap(const struct sctp_tsnmap *);
  132. #endif /* __sctp_tsnmap_h__ */