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