blob: 54bbbe547303cc8d37c88d736e9e95894e054a69 [file] [log] [blame]
Vlad Yasevich60c778b2008-01-11 09:57:09 -05001/* SCTP kernel implementation
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * (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 Yasevich60c778b2008-01-11 09:57:09 -05007 * This file is part of the SCTP kernel implementation
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 *
9 * These are the definitions needed for the tsnmap type. The tsnmap is used
10 * to track out of order TSNs received.
11 *
Vlad Yasevich60c778b2008-01-11 09:57:09 -050012 * This SCTP implementation is free software;
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 * 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 Yasevich60c778b2008-01-11 09:57:09 -050018 * This SCTP implementation is distributed in the hope that it
Linus Torvalds1da177e2005-04-16 15:20:36 -070019 * 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):
Daniel Borkmann91705c62013-07-23 14:51:47 +020031 * lksctp developers <linux-sctp@vger.kernel.org>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 * Written or modified by:
34 * Jon Grimm <jgrimm@us.ibm.com>
35 * La Monte H.P. Yarroll <piggy@acm.org>
36 * Karl Knutson <karl@athena.chicago.il.us>
37 * Sridhar Samudrala <sri@us.ibm.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 */
39#include <net/sctp/constants.h>
40
41#ifndef __sctp_tsnmap_h__
42#define __sctp_tsnmap_h__
43
44/* RFC 2960 12.2 Parameters necessary per association (i.e. the TCB)
45 * Mapping An array of bits or bytes indicating which out of
46 * Array order TSN's have been received (relative to the
47 * Last Rcvd TSN). If no gaps exist, i.e. no out of
48 * order packets have been received, this array
49 * will be set to all zero. This structure may be
50 * in the form of a circular buffer or bit array.
51 */
52struct sctp_tsnmap {
53 /* This array counts the number of chunks with each TSN.
54 * It points at one of the two buffers with which we will
55 * ping-pong between.
56 */
Vlad Yasevich8e1ee182008-10-08 14:18:39 -070057 unsigned long *tsn_map;
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
59 /* This is the TSN at tsn_map[0]. */
60 __u32 base_tsn;
61
62 /* Last Rcvd : This is the last TSN received in
63 * TSN : sequence. This value is set initially by
64 * : taking the peer's Initial TSN, received in
65 * : the INIT or INIT ACK chunk, and subtracting
66 * : one from it.
67 *
68 * Throughout most of the specification this is called the
69 * "Cumulative TSN ACK Point". In this case, we
70 * ignore the advice in 12.2 in favour of the term
71 * used in the bulk of the text.
72 */
73 __u32 cumulative_tsn_ack_point;
74
Vlad Yasevich8e1ee182008-10-08 14:18:39 -070075 /* This is the highest TSN we've marked. */
76 __u32 max_tsn_seen;
77
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 /* This is the minimum number of TSNs we can track. This corresponds
79 * to the size of tsn_map. Note: the overflow_map allows us to
80 * potentially track more than this quantity.
81 */
82 __u16 len;
83
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 /* Data chunks pending receipt. used by SCTP_STATUS sockopt */
85 __u16 pending_data;
86
87 /* Record duplicate TSNs here. We clear this after
88 * every SACK. Store up to SCTP_MAX_DUP_TSNS worth of
89 * information.
90 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 __u16 num_dup_tsns;
Vlad Yasevich02015182008-10-08 14:19:01 -070092 __be32 dup_tsns[SCTP_MAX_DUP_TSNS];
Linus Torvalds1da177e2005-04-16 15:20:36 -070093};
94
95struct sctp_tsnmap_iter {
96 __u32 start;
97};
98
Linus Torvalds1da177e2005-04-16 15:20:36 -070099/* Initialize a block of memory as a tsnmap. */
100struct sctp_tsnmap *sctp_tsnmap_init(struct sctp_tsnmap *, __u16 len,
Vlad Yasevich8e1ee182008-10-08 14:18:39 -0700101 __u32 initial_tsn, gfp_t gfp);
102
103void sctp_tsnmap_free(struct sctp_tsnmap *map);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
105/* Test the tracking state of this TSN.
106 * Returns:
107 * 0 if the TSN has not yet been seen
108 * >0 if the TSN has been seen (duplicate)
109 * <0 if the TSN is invalid (too large to track)
110 */
111int sctp_tsnmap_check(const struct sctp_tsnmap *, __u32 tsn);
112
113/* Mark this TSN as seen. */
Neil Horman42448542012-06-30 03:04:26 +0000114int sctp_tsnmap_mark(struct sctp_tsnmap *, __u32 tsn,
115 struct sctp_transport *trans);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
117/* Mark this TSN and all lower as seen. */
118void sctp_tsnmap_skip(struct sctp_tsnmap *map, __u32 tsn);
119
120/* Retrieve the Cumulative TSN ACK Point. */
121static inline __u32 sctp_tsnmap_get_ctsn(const struct sctp_tsnmap *map)
122{
123 return map->cumulative_tsn_ack_point;
124}
125
126/* Retrieve the highest TSN we've seen. */
127static inline __u32 sctp_tsnmap_get_max_tsn_seen(const struct sctp_tsnmap *map)
128{
129 return map->max_tsn_seen;
130}
131
132/* How many duplicate TSNs are stored? */
133static inline __u16 sctp_tsnmap_num_dups(struct sctp_tsnmap *map)
134{
135 return map->num_dup_tsns;
136}
137
138/* Return pointer to duplicate tsn array as needed by SACK. */
Al Viro72f17e12006-11-20 17:01:23 -0800139static inline __be32 *sctp_tsnmap_get_dups(struct sctp_tsnmap *map)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140{
141 map->num_dup_tsns = 0;
142 return map->dup_tsns;
143}
144
145/* How many gap ack blocks do we have recorded? */
Vlad Yasevich02015182008-10-08 14:19:01 -0700146__u16 sctp_tsnmap_num_gabs(struct sctp_tsnmap *map,
147 struct sctp_gap_ack_block *gabs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
149/* Refresh the count on pending data. */
150__u16 sctp_tsnmap_pending(struct sctp_tsnmap *map);
151
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152/* Is there a gap in the TSN map? */
153static inline int sctp_tsnmap_has_gap(const struct sctp_tsnmap *map)
154{
Eric Dumazeta02cec22010-09-22 20:43:57 +0000155 return map->cumulative_tsn_ack_point != map->max_tsn_seen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156}
157
158/* Mark a duplicate TSN. Note: limit the storage of duplicate TSN
159 * information.
160 */
161static inline void sctp_tsnmap_mark_dup(struct sctp_tsnmap *map, __u32 tsn)
162{
163 if (map->num_dup_tsns < SCTP_MAX_DUP_TSNS)
164 map->dup_tsns[map->num_dup_tsns++] = htonl(tsn);
165}
166
167/* Renege a TSN that was seen. */
168void sctp_tsnmap_renege(struct sctp_tsnmap *, __u32 tsn);
169
170/* Is there a gap in the TSN map? */
171int sctp_tsnmap_has_gap(const struct sctp_tsnmap *);
172
173#endif /* __sctp_tsnmap_h__ */