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