blob: 4aabc5a96cf675f150a7b6823e8a4c787765cf7e [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):
31 * lksctp developers <lksctp-developers@lists.sourceforge.net>
32 *
33 * Or submit a bug report through the following website:
34 * http://www.sf.net/projects/lksctp
35 *
36 * Written or modified by:
37 * Jon Grimm <jgrimm@us.ibm.com>
38 * La Monte H.P. Yarroll <piggy@acm.org>
39 * Karl Knutson <karl@athena.chicago.il.us>
40 * Sridhar Samudrala <sri@us.ibm.com>
41 *
42 * Any bugs reported given to us we will try to fix... any fixes shared will
43 * be incorporated into the next SCTP release.
44 */
45#include <net/sctp/constants.h>
46
47#ifndef __sctp_tsnmap_h__
48#define __sctp_tsnmap_h__
49
50/* RFC 2960 12.2 Parameters necessary per association (i.e. the TCB)
51 * Mapping An array of bits or bytes indicating which out of
52 * Array order TSN's have been received (relative to the
53 * Last Rcvd TSN). If no gaps exist, i.e. no out of
54 * order packets have been received, this array
55 * will be set to all zero. This structure may be
56 * in the form of a circular buffer or bit array.
57 */
58struct sctp_tsnmap {
59 /* This array counts the number of chunks with each TSN.
60 * It points at one of the two buffers with which we will
61 * ping-pong between.
62 */
Vlad Yasevich8e1ee182008-10-08 14:18:39 -070063 unsigned long *tsn_map;
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
65 /* This is the TSN at tsn_map[0]. */
66 __u32 base_tsn;
67
68 /* Last Rcvd : This is the last TSN received in
69 * TSN : sequence. This value is set initially by
70 * : taking the peer's Initial TSN, received in
71 * : the INIT or INIT ACK chunk, and subtracting
72 * : one from it.
73 *
74 * Throughout most of the specification this is called the
75 * "Cumulative TSN ACK Point". In this case, we
76 * ignore the advice in 12.2 in favour of the term
77 * used in the bulk of the text.
78 */
79 __u32 cumulative_tsn_ack_point;
80
Vlad Yasevich8e1ee182008-10-08 14:18:39 -070081 /* This is the highest TSN we've marked. */
82 __u32 max_tsn_seen;
83
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 /* This is the minimum number of TSNs we can track. This corresponds
85 * to the size of tsn_map. Note: the overflow_map allows us to
86 * potentially track more than this quantity.
87 */
88 __u16 len;
89
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 /* Data chunks pending receipt. used by SCTP_STATUS sockopt */
91 __u16 pending_data;
92
93 /* Record duplicate TSNs here. We clear this after
94 * every SACK. Store up to SCTP_MAX_DUP_TSNS worth of
95 * information.
96 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 __u16 num_dup_tsns;
Vlad Yasevich02015182008-10-08 14:19:01 -070098 __be32 dup_tsns[SCTP_MAX_DUP_TSNS];
Linus Torvalds1da177e2005-04-16 15:20:36 -070099};
100
101struct sctp_tsnmap_iter {
102 __u32 start;
103};
104
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105/* Initialize a block of memory as a tsnmap. */
106struct sctp_tsnmap *sctp_tsnmap_init(struct sctp_tsnmap *, __u16 len,
Vlad Yasevich8e1ee182008-10-08 14:18:39 -0700107 __u32 initial_tsn, gfp_t gfp);
108
109void sctp_tsnmap_free(struct sctp_tsnmap *map);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
111/* Test the tracking state of this TSN.
112 * Returns:
113 * 0 if the TSN has not yet been seen
114 * >0 if the TSN has been seen (duplicate)
115 * <0 if the TSN is invalid (too large to track)
116 */
117int sctp_tsnmap_check(const struct sctp_tsnmap *, __u32 tsn);
118
119/* Mark this TSN as seen. */
Vlad Yasevich8e1ee182008-10-08 14:18:39 -0700120int sctp_tsnmap_mark(struct sctp_tsnmap *, __u32 tsn);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
122/* Mark this TSN and all lower as seen. */
123void sctp_tsnmap_skip(struct sctp_tsnmap *map, __u32 tsn);
124
125/* Retrieve the Cumulative TSN ACK Point. */
126static inline __u32 sctp_tsnmap_get_ctsn(const struct sctp_tsnmap *map)
127{
128 return map->cumulative_tsn_ack_point;
129}
130
131/* Retrieve the highest TSN we've seen. */
132static inline __u32 sctp_tsnmap_get_max_tsn_seen(const struct sctp_tsnmap *map)
133{
134 return map->max_tsn_seen;
135}
136
137/* How many duplicate TSNs are stored? */
138static inline __u16 sctp_tsnmap_num_dups(struct sctp_tsnmap *map)
139{
140 return map->num_dup_tsns;
141}
142
143/* Return pointer to duplicate tsn array as needed by SACK. */
Al Viro72f17e12006-11-20 17:01:23 -0800144static inline __be32 *sctp_tsnmap_get_dups(struct sctp_tsnmap *map)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145{
146 map->num_dup_tsns = 0;
147 return map->dup_tsns;
148}
149
150/* How many gap ack blocks do we have recorded? */
Vlad Yasevich02015182008-10-08 14:19:01 -0700151__u16 sctp_tsnmap_num_gabs(struct sctp_tsnmap *map,
152 struct sctp_gap_ack_block *gabs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
154/* Refresh the count on pending data. */
155__u16 sctp_tsnmap_pending(struct sctp_tsnmap *map);
156
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157/* Is there a gap in the TSN map? */
158static inline int sctp_tsnmap_has_gap(const struct sctp_tsnmap *map)
159{
Vlad Yasevich8e1ee182008-10-08 14:18:39 -0700160 return (map->cumulative_tsn_ack_point != map->max_tsn_seen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161}
162
163/* Mark a duplicate TSN. Note: limit the storage of duplicate TSN
164 * information.
165 */
166static inline void sctp_tsnmap_mark_dup(struct sctp_tsnmap *map, __u32 tsn)
167{
168 if (map->num_dup_tsns < SCTP_MAX_DUP_TSNS)
169 map->dup_tsns[map->num_dup_tsns++] = htonl(tsn);
170}
171
172/* Renege a TSN that was seen. */
173void sctp_tsnmap_renege(struct sctp_tsnmap *, __u32 tsn);
174
175/* Is there a gap in the TSN map? */
176int sctp_tsnmap_has_gap(const struct sctp_tsnmap *);
177
178#endif /* __sctp_tsnmap_h__ */