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