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