Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /* SCTP kernel implementation
0003  * (C) Copyright IBM Corp. 2001, 2004
0004  * Copyright (c) 1999-2000 Cisco, Inc.
0005  * Copyright (c) 1999-2001 Motorola, Inc.
0006  * Copyright (c) 2001 Intel Corp.
0007  *
0008  * This file is part of the SCTP kernel implementation
0009  *
0010  * These are the definitions needed for the tsnmap type.  The tsnmap is used
0011  * to track out of order TSNs received.
0012  *
0013  * Please send any bug reports or fixes you make to the
0014  * email address(es):
0015  *    lksctp developers <linux-sctp@vger.kernel.org>
0016  *
0017  * Written or modified by:
0018  *   Jon Grimm             <jgrimm@us.ibm.com>
0019  *   La Monte H.P. Yarroll <piggy@acm.org>
0020  *   Karl Knutson          <karl@athena.chicago.il.us>
0021  *   Sridhar Samudrala     <sri@us.ibm.com>
0022  */
0023 #include <net/sctp/constants.h>
0024 
0025 #ifndef __sctp_tsnmap_h__
0026 #define __sctp_tsnmap_h__
0027 
0028 /* RFC 2960 12.2 Parameters necessary per association (i.e. the TCB)
0029  * Mapping  An array of bits or bytes indicating which out of
0030  * Array    order TSN's have been received (relative to the
0031  *          Last Rcvd TSN). If no gaps exist, i.e. no out of
0032  *          order packets have been received, this array
0033  *          will be set to all zero. This structure may be
0034  *          in the form of a circular buffer or bit array.
0035  */
0036 struct sctp_tsnmap {
0037     /* This array counts the number of chunks with each TSN.
0038      * It points at one of the two buffers with which we will
0039      * ping-pong between.
0040      */
0041     unsigned long *tsn_map;
0042 
0043     /* This is the TSN at tsn_map[0].  */
0044     __u32 base_tsn;
0045 
0046     /* Last Rcvd   : This is the last TSN received in
0047      * TSN         : sequence. This value is set initially by
0048      *             : taking the peer's Initial TSN, received in
0049      *             : the INIT or INIT ACK chunk, and subtracting
0050      *             : one from it.
0051      *
0052      * Throughout most of the specification this is called the
0053      * "Cumulative TSN ACK Point".  In this case, we
0054      * ignore the advice in 12.2 in favour of the term
0055      * used in the bulk of the text.
0056      */
0057     __u32 cumulative_tsn_ack_point;
0058 
0059     /* This is the highest TSN we've marked.  */
0060     __u32 max_tsn_seen;
0061 
0062     /* This is the minimum number of TSNs we can track.  This corresponds
0063      * to the size of tsn_map.   Note: the overflow_map allows us to
0064      * potentially track more than this quantity.
0065      */
0066     __u16 len;
0067 
0068     /* Data chunks pending receipt. used by SCTP_STATUS sockopt */
0069     __u16 pending_data;
0070 
0071     /* Record duplicate TSNs here.  We clear this after
0072      * every SACK.  Store up to SCTP_MAX_DUP_TSNS worth of
0073      * information.
0074      */
0075     __u16 num_dup_tsns;
0076     __be32 dup_tsns[SCTP_MAX_DUP_TSNS];
0077 };
0078 
0079 struct sctp_tsnmap_iter {
0080     __u32 start;
0081 };
0082 
0083 /* Initialize a block of memory as a tsnmap.  */
0084 struct sctp_tsnmap *sctp_tsnmap_init(struct sctp_tsnmap *, __u16 len,
0085                      __u32 initial_tsn, gfp_t gfp);
0086 
0087 void sctp_tsnmap_free(struct sctp_tsnmap *map);
0088 
0089 /* Test the tracking state of this TSN.
0090  * Returns:
0091  *   0 if the TSN has not yet been seen
0092  *  >0 if the TSN has been seen (duplicate)
0093  *  <0 if the TSN is invalid (too large to track)
0094  */
0095 int sctp_tsnmap_check(const struct sctp_tsnmap *, __u32 tsn);
0096 
0097 /* Mark this TSN as seen.  */
0098 int sctp_tsnmap_mark(struct sctp_tsnmap *, __u32 tsn,
0099              struct sctp_transport *trans);
0100 
0101 /* Mark this TSN and all lower as seen. */
0102 void sctp_tsnmap_skip(struct sctp_tsnmap *map, __u32 tsn);
0103 
0104 /* Retrieve the Cumulative TSN ACK Point.  */
0105 static inline __u32 sctp_tsnmap_get_ctsn(const struct sctp_tsnmap *map)
0106 {
0107     return map->cumulative_tsn_ack_point;
0108 }
0109 
0110 /* Retrieve the highest TSN we've seen.  */
0111 static inline __u32 sctp_tsnmap_get_max_tsn_seen(const struct sctp_tsnmap *map)
0112 {
0113     return map->max_tsn_seen;
0114 }
0115 
0116 /* How many duplicate TSNs are stored? */
0117 static inline __u16 sctp_tsnmap_num_dups(struct sctp_tsnmap *map)
0118 {
0119     return map->num_dup_tsns;
0120 }
0121 
0122 /* Return pointer to duplicate tsn array as needed by SACK. */
0123 static inline __be32 *sctp_tsnmap_get_dups(struct sctp_tsnmap *map)
0124 {
0125     map->num_dup_tsns = 0;
0126     return map->dup_tsns;
0127 }
0128 
0129 /* How many gap ack blocks do we have recorded? */
0130 __u16 sctp_tsnmap_num_gabs(struct sctp_tsnmap *map,
0131                struct sctp_gap_ack_block *gabs);
0132 
0133 /* Refresh the count on pending data. */
0134 __u16 sctp_tsnmap_pending(struct sctp_tsnmap *map);
0135 
0136 /* Is there a gap in the TSN map?  */
0137 static inline int sctp_tsnmap_has_gap(const struct sctp_tsnmap *map)
0138 {
0139     return map->cumulative_tsn_ack_point != map->max_tsn_seen;
0140 }
0141 
0142 /* Mark a duplicate TSN.  Note:  limit the storage of duplicate TSN
0143  * information.
0144  */
0145 static inline void sctp_tsnmap_mark_dup(struct sctp_tsnmap *map, __u32 tsn)
0146 {
0147     if (map->num_dup_tsns < SCTP_MAX_DUP_TSNS)
0148         map->dup_tsns[map->num_dup_tsns++] = htonl(tsn);
0149 }
0150 
0151 /* Renege a TSN that was seen.  */
0152 void sctp_tsnmap_renege(struct sctp_tsnmap *, __u32 tsn);
0153 
0154 /* Is there a gap in the TSN map? */
0155 int sctp_tsnmap_has_gap(const struct sctp_tsnmap *);
0156 
0157 #endif /* __sctp_tsnmap_h__ */