ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / include / net / sctp / tsnmap.h
1 /* SCTP kernel reference Implementation
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  *
7  * This file is part of the SCTP kernel reference Implementation
8  *
9  * These are the definitions needed for the tsnmap type.  The tsnmap is used
10  * to track out of order TSNs received.
11  *
12  * The SCTP reference implementation is free software;
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  *
18  * The SCTP reference implementation is distributed in the hope that it
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
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  */
58 struct 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          */
63         __u8 *tsn_map;
64
65         /* This marks the tsn which overflows the tsn_map, when the
66          * cumulative ack point reaches this point we know we can switch
67          * maps (tsn_map and overflow_map swap).
68          */
69         __u32 overflow_tsn;
70
71         /* This is the overflow array for tsn_map.
72          * It points at one of the other ping-pong buffers.
73          */
74         __u8 *overflow_map;
75
76         /* This is the TSN at tsn_map[0].  */
77         __u32 base_tsn;
78
79         /* Last Rcvd   : This is the last TSN received in
80          * TSN         : sequence. This value is set initially by
81          *             : taking the peer's Initial TSN, received in
82          *             : the INIT or INIT ACK chunk, and subtracting
83          *             : one from it.
84          *
85          * Throughout most of the specification this is called the
86          * "Cumulative TSN ACK Point".  In this case, we
87          * ignore the advice in 12.2 in favour of the term
88          * used in the bulk of the text.
89          */
90         __u32 cumulative_tsn_ack_point;
91
92         /* This is the minimum number of TSNs we can track.  This corresponds
93          * to the size of tsn_map.   Note: the overflow_map allows us to
94          * potentially track more than this quantity.
95          */
96         __u16 len;
97
98         /* This is the highest TSN we've marked.  */
99         __u32 max_tsn_seen;
100
101         /* Data chunks pending receipt. used by SCTP_STATUS sockopt */
102         __u16 pending_data;
103
104         /* Record duplicate TSNs here.  We clear this after
105          * every SACK.  Store up to SCTP_MAX_DUP_TSNS worth of
106          * information.
107          */
108         __u32 dup_tsns[SCTP_MAX_DUP_TSNS];
109         __u16 num_dup_tsns;
110
111         /* Record gap ack block information here.  */
112         struct sctp_gap_ack_block gabs[SCTP_MAX_GABS];
113
114         int malloced;
115
116         __u8 raw_map[0];
117 };
118
119 struct sctp_tsnmap_iter {
120         __u32 start;
121 };
122
123 /* Create a new tsnmap.  */
124 struct sctp_tsnmap *sctp_tsnmap_new(__u16 len, __u32 init_tsn, int gfp);
125
126 /* Dispose of a tsnmap.  */
127 void sctp_tsnmap_free(struct sctp_tsnmap *);
128
129 /* This macro assists in creation of external storage for variable length
130  * internal buffers.  We double allocate so the overflow map works.
131  */
132 #define sctp_tsnmap_storage_size(count) (sizeof(__u8) * (count) * 2)
133
134 /* Initialize a block of memory as a tsnmap.  */
135 struct sctp_tsnmap *sctp_tsnmap_init(struct sctp_tsnmap *, __u16 len,
136                                      __u32 initial_tsn);
137
138 /* Test the tracking state of this TSN.
139  * Returns:
140  *   0 if the TSN has not yet been seen
141  *  >0 if the TSN has been seen (duplicate)
142  *  <0 if the TSN is invalid (too large to track)
143  */
144 int sctp_tsnmap_check(const struct sctp_tsnmap *, __u32 tsn);
145
146 /* Mark this TSN as seen.  */
147 void sctp_tsnmap_mark(struct sctp_tsnmap *, __u32 tsn);
148
149 /* Mark this TSN and all lower as seen. */
150 void sctp_tsnmap_skip(struct sctp_tsnmap *map, __u32 tsn);
151
152 /* Retrieve the Cumulative TSN ACK Point.  */
153 static inline __u32 sctp_tsnmap_get_ctsn(const struct sctp_tsnmap *map)
154 {
155         return map->cumulative_tsn_ack_point;
156 }
157
158 /* Retrieve the highest TSN we've seen.  */
159 static inline __u32 sctp_tsnmap_get_max_tsn_seen(const struct sctp_tsnmap *map)
160 {
161         return map->max_tsn_seen;
162 }
163
164 /* How many duplicate TSNs are stored? */
165 static inline __u16 sctp_tsnmap_num_dups(struct sctp_tsnmap *map)
166 {
167         return map->num_dup_tsns;
168 }
169
170 /* Return pointer to duplicate tsn array as needed by SACK. */
171 static inline __u32 *sctp_tsnmap_get_dups(struct sctp_tsnmap *map)
172 {
173         map->num_dup_tsns = 0;
174         return map->dup_tsns;
175 }
176
177 /* How many gap ack blocks do we have recorded? */
178 __u16 sctp_tsnmap_num_gabs(struct sctp_tsnmap *map);
179
180 /* Refresh the count on pending data. */
181 __u16 sctp_tsnmap_pending(struct sctp_tsnmap *map);
182
183 /* Return pointer to gap ack blocks as needed by SACK. */
184 static inline struct sctp_gap_ack_block *sctp_tsnmap_get_gabs(struct sctp_tsnmap *map)
185 {
186         return map->gabs;
187 }
188
189 /* Is there a gap in the TSN map?  */
190 static inline int sctp_tsnmap_has_gap(const struct sctp_tsnmap *map)
191 {
192         int has_gap;
193
194         has_gap = (map->cumulative_tsn_ack_point != map->max_tsn_seen);
195         return has_gap;
196 }
197
198 /* Mark a duplicate TSN.  Note:  limit the storage of duplicate TSN
199  * information.
200  */
201 static inline void sctp_tsnmap_mark_dup(struct sctp_tsnmap *map, __u32 tsn)
202 {
203         if (map->num_dup_tsns < SCTP_MAX_DUP_TSNS)
204                 map->dup_tsns[map->num_dup_tsns++] = htonl(tsn);
205 }
206
207 /* Renege a TSN that was seen.  */
208 void sctp_tsnmap_renege(struct sctp_tsnmap *, __u32 tsn);
209
210 /* Is there a gap in the TSN map? */
211 int sctp_tsnmap_has_gap(const struct sctp_tsnmap *);
212
213 /* Initialize a gap ack block interator from user-provided memory.  */
214 void sctp_tsnmap_iter_init(const struct sctp_tsnmap *,
215                            struct sctp_tsnmap_iter *);
216
217 /* Get the next gap ack blocks.  We return 0 if there are no more
218  * gap ack blocks.
219  */
220 int sctp_tsnmap_next_gap_ack(const struct sctp_tsnmap *,
221         struct sctp_tsnmap_iter *,__u16 *start, __u16 *end);
222
223 #endif /* __sctp_tsnmap_h__ */