Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /* SCTP kernel implementation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  * (C) Copyright IBM Corp. 2001, 2004
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  * Copyright (c) 1999-2000 Cisco, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  * Copyright (c) 1999-2001 Motorola, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  * Copyright (c) 2001-2003 Intel Corp.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  * This file is part of the SCTP kernel implementation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)  * These functions implement the sctp_outq class.   The outqueue handles
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11)  * bundling and queueing of outgoing SCTP chunks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13)  * Please send any bug reports or fixes you make to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14)  * email address(es):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15)  *    lksctp developers <linux-sctp@vger.kernel.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17)  * Written or modified by:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18)  *    La Monte H.P. Yarroll <piggy@acm.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19)  *    Karl Knutson          <karl@athena.chicago.il.us>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20)  *    Perry Melange         <pmelange@null.cc.uic.edu>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21)  *    Xingang Guo           <xingang.guo@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22)  *    Hui Huang 	    <hui.huang@nokia.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23)  *    Sridhar Samudrala     <sri@us.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24)  *    Jon Grimm             <jgrimm@us.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) #include <linux/list.h>   /* For struct list_head */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) #include <linux/socket.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) #include <linux/ip.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) #include <net/sock.h>	  /* For skb_set_owner_w */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) #include <net/sctp/sctp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) #include <net/sctp/sm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) #include <net/sctp/stream_sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) #include <trace/events/sctp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) /* Declare internal functions here.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) static int sctp_acked(struct sctp_sackhdr *sack, __u32 tsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) static void sctp_check_transmitted(struct sctp_outq *q,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) 				   struct list_head *transmitted_queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) 				   struct sctp_transport *transport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) 				   union sctp_addr *saddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) 				   struct sctp_sackhdr *sack,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) 				   __u32 *highest_new_tsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) static void sctp_mark_missing(struct sctp_outq *q,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) 			      struct list_head *transmitted_queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) 			      struct sctp_transport *transport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) 			      __u32 highest_new_tsn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) 			      int count_of_newacks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) static void sctp_outq_flush(struct sctp_outq *q, int rtx_timeout, gfp_t gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) /* Add data to the front of the queue. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) static inline void sctp_outq_head_data(struct sctp_outq *q,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) 				       struct sctp_chunk *ch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) 	struct sctp_stream_out_ext *oute;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) 	__u16 stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) 	list_add(&ch->list, &q->out_chunk_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) 	q->out_qlen += ch->skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) 	stream = sctp_chunk_stream_no(ch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) 	oute = SCTP_SO(&q->asoc->stream, stream)->ext;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) 	list_add(&ch->stream_list, &oute->outq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) /* Take data from the front of the queue. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) static inline struct sctp_chunk *sctp_outq_dequeue_data(struct sctp_outq *q)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) 	return q->sched->dequeue(q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) /* Add data chunk to the end of the queue. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) static inline void sctp_outq_tail_data(struct sctp_outq *q,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) 				       struct sctp_chunk *ch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) 	struct sctp_stream_out_ext *oute;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) 	__u16 stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) 	list_add_tail(&ch->list, &q->out_chunk_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 	q->out_qlen += ch->skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 	stream = sctp_chunk_stream_no(ch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) 	oute = SCTP_SO(&q->asoc->stream, stream)->ext;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) 	list_add_tail(&ch->stream_list, &oute->outq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95)  * SFR-CACC algorithm:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96)  * D) If count_of_newacks is greater than or equal to 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97)  * and t was not sent to the current primary then the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98)  * sender MUST NOT increment missing report count for t.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) static inline int sctp_cacc_skip_3_1_d(struct sctp_transport *primary,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) 				       struct sctp_transport *transport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) 				       int count_of_newacks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) 	if (count_of_newacks >= 2 && transport != primary)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110)  * SFR-CACC algorithm:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111)  * F) If count_of_newacks is less than 2, let d be the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112)  * destination to which t was sent. If cacc_saw_newack
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113)  * is 0 for destination d, then the sender MUST NOT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114)  * increment missing report count for t.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) static inline int sctp_cacc_skip_3_1_f(struct sctp_transport *transport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 				       int count_of_newacks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 	if (count_of_newacks < 2 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 			(transport && !transport->cacc.cacc_saw_newack))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126)  * SFR-CACC algorithm:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127)  * 3.1) If CYCLING_CHANGEOVER is 0, the sender SHOULD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128)  * execute steps C, D, F.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130)  * C has been implemented in sctp_outq_sack
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) static inline int sctp_cacc_skip_3_1(struct sctp_transport *primary,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 				     struct sctp_transport *transport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 				     int count_of_newacks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 	if (!primary->cacc.cycling_changeover) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 		if (sctp_cacc_skip_3_1_d(primary, transport, count_of_newacks))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 			return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 		if (sctp_cacc_skip_3_1_f(transport, count_of_newacks))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 			return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147)  * SFR-CACC algorithm:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148)  * 3.2) Else if CYCLING_CHANGEOVER is 1, and t is less
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149)  * than next_tsn_at_change of the current primary, then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150)  * the sender MUST NOT increment missing report count
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151)  * for t.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) static inline int sctp_cacc_skip_3_2(struct sctp_transport *primary, __u32 tsn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 	if (primary->cacc.cycling_changeover &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 	    TSN_lt(tsn, primary->cacc.next_tsn_at_change))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162)  * SFR-CACC algorithm:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163)  * 3) If the missing report count for TSN t is to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164)  * incremented according to [RFC2960] and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165)  * [SCTP_STEWART-2002], and CHANGEOVER_ACTIVE is set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166)  * then the sender MUST further execute steps 3.1 and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167)  * 3.2 to determine if the missing report count for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168)  * TSN t SHOULD NOT be incremented.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170)  * 3.3) If 3.1 and 3.2 do not dictate that the missing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171)  * report count for t should not be incremented, then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172)  * the sender SHOULD increment missing report count for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173)  * t (according to [RFC2960] and [SCTP_STEWART_2002]).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) static inline int sctp_cacc_skip(struct sctp_transport *primary,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 				 struct sctp_transport *transport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 				 int count_of_newacks,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 				 __u32 tsn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 	if (primary->cacc.changeover_active &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 	    (sctp_cacc_skip_3_1(primary, transport, count_of_newacks) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 	     sctp_cacc_skip_3_2(primary, tsn)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) /* Initialize an existing sctp_outq.  This does the boring stuff.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188)  * You still need to define handlers if you really want to DO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189)  * something with this structure...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) void sctp_outq_init(struct sctp_association *asoc, struct sctp_outq *q)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 	memset(q, 0, sizeof(struct sctp_outq));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 	q->asoc = asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 	INIT_LIST_HEAD(&q->out_chunk_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 	INIT_LIST_HEAD(&q->control_chunk_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 	INIT_LIST_HEAD(&q->retransmit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 	INIT_LIST_HEAD(&q->sacked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 	INIT_LIST_HEAD(&q->abandoned);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 	sctp_sched_set_sched(asoc, sctp_sk(asoc->base.sk)->default_ss);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) /* Free the outqueue structure and any related pending chunks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) static void __sctp_outq_teardown(struct sctp_outq *q)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 	struct sctp_transport *transport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 	struct list_head *lchunk, *temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 	struct sctp_chunk *chunk, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 	/* Throw away unacknowledged chunks. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 	list_for_each_entry(transport, &q->asoc->peer.transport_addr_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 			transports) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 		while ((lchunk = sctp_list_dequeue(&transport->transmitted)) != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 			chunk = list_entry(lchunk, struct sctp_chunk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 					   transmitted_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 			/* Mark as part of a failed message. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 			sctp_chunk_fail(chunk, q->error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 			sctp_chunk_free(chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 	/* Throw away chunks that have been gap ACKed.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 	list_for_each_safe(lchunk, temp, &q->sacked) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 		list_del_init(lchunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 		chunk = list_entry(lchunk, struct sctp_chunk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 				   transmitted_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 		sctp_chunk_fail(chunk, q->error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 		sctp_chunk_free(chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 	/* Throw away any chunks in the retransmit queue. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 	list_for_each_safe(lchunk, temp, &q->retransmit) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 		list_del_init(lchunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 		chunk = list_entry(lchunk, struct sctp_chunk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 				   transmitted_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 		sctp_chunk_fail(chunk, q->error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 		sctp_chunk_free(chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 	/* Throw away any chunks that are in the abandoned queue. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 	list_for_each_safe(lchunk, temp, &q->abandoned) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 		list_del_init(lchunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 		chunk = list_entry(lchunk, struct sctp_chunk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 				   transmitted_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 		sctp_chunk_fail(chunk, q->error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 		sctp_chunk_free(chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 	/* Throw away any leftover data chunks. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 	while ((chunk = sctp_outq_dequeue_data(q)) != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 		sctp_sched_dequeue_done(q, chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 		/* Mark as send failure. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 		sctp_chunk_fail(chunk, q->error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 		sctp_chunk_free(chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 	/* Throw away any leftover control chunks. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 	list_for_each_entry_safe(chunk, tmp, &q->control_chunk_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 		list_del_init(&chunk->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 		sctp_chunk_free(chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) void sctp_outq_teardown(struct sctp_outq *q)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 	__sctp_outq_teardown(q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 	sctp_outq_init(q->asoc, q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) /* Free the outqueue structure and any related pending chunks.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) void sctp_outq_free(struct sctp_outq *q)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 	/* Throw away leftover chunks. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 	__sctp_outq_teardown(q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) /* Put a new chunk in an sctp_outq.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) void sctp_outq_tail(struct sctp_outq *q, struct sctp_chunk *chunk, gfp_t gfp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 	struct net *net = q->asoc->base.net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 	pr_debug("%s: outq:%p, chunk:%p[%s]\n", __func__, q, chunk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 		 chunk && chunk->chunk_hdr ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 		 sctp_cname(SCTP_ST_CHUNK(chunk->chunk_hdr->type)) :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 		 "illegal chunk");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 	/* If it is data, queue it up, otherwise, send it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 	 * immediately.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 	if (sctp_chunk_is_data(chunk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 		pr_debug("%s: outqueueing: outq:%p, chunk:%p[%s])\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 			 __func__, q, chunk, chunk && chunk->chunk_hdr ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 			 sctp_cname(SCTP_ST_CHUNK(chunk->chunk_hdr->type)) :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 			 "illegal chunk");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 		sctp_outq_tail_data(q, chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 		if (chunk->asoc->peer.prsctp_capable &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 		    SCTP_PR_PRIO_ENABLED(chunk->sinfo.sinfo_flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 			chunk->asoc->sent_cnt_removable++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 		if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 			SCTP_INC_STATS(net, SCTP_MIB_OUTUNORDERCHUNKS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 			SCTP_INC_STATS(net, SCTP_MIB_OUTORDERCHUNKS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 		list_add_tail(&chunk->list, &q->control_chunk_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 		SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 	if (!q->cork)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 		sctp_outq_flush(q, 0, gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) /* Insert a chunk into the sorted list based on the TSNs.  The retransmit list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317)  * and the abandoned list are in ascending order.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) static void sctp_insert_list(struct list_head *head, struct list_head *new)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 	struct list_head *pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 	struct sctp_chunk *nchunk, *lchunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 	__u32 ntsn, ltsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 	int done = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 	nchunk = list_entry(new, struct sctp_chunk, transmitted_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 	ntsn = ntohl(nchunk->subh.data_hdr->tsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 	list_for_each(pos, head) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 		lchunk = list_entry(pos, struct sctp_chunk, transmitted_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 		ltsn = ntohl(lchunk->subh.data_hdr->tsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 		if (TSN_lt(ntsn, ltsn)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 			list_add(new, pos->prev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 			done = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 	if (!done)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 		list_add_tail(new, head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) static int sctp_prsctp_prune_sent(struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 				  struct sctp_sndrcvinfo *sinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 				  struct list_head *queue, int msg_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 	struct sctp_chunk *chk, *temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 	list_for_each_entry_safe(chk, temp, queue, transmitted_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 		struct sctp_stream_out *streamout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 		if (!chk->msg->abandoned &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 		    (!SCTP_PR_PRIO_ENABLED(chk->sinfo.sinfo_flags) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 		     chk->sinfo.sinfo_timetolive <= sinfo->sinfo_timetolive))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 		chk->msg->abandoned = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 		list_del_init(&chk->transmitted_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 		sctp_insert_list(&asoc->outqueue.abandoned,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 				 &chk->transmitted_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 		streamout = SCTP_SO(&asoc->stream, chk->sinfo.sinfo_stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 		asoc->sent_cnt_removable--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 		asoc->abandoned_sent[SCTP_PR_INDEX(PRIO)]++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 		streamout->ext->abandoned_sent[SCTP_PR_INDEX(PRIO)]++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 		if (queue != &asoc->outqueue.retransmit &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 		    !chk->tsn_gap_acked) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 			if (chk->transport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 				chk->transport->flight_size -=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 						sctp_data_size(chk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 			asoc->outqueue.outstanding_bytes -= sctp_data_size(chk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 		msg_len -= chk->skb->truesize + sizeof(struct sctp_chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 		if (msg_len <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 	return msg_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) static int sctp_prsctp_prune_unsent(struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 				    struct sctp_sndrcvinfo *sinfo, int msg_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 	struct sctp_outq *q = &asoc->outqueue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 	struct sctp_chunk *chk, *temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 	q->sched->unsched_all(&asoc->stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 	list_for_each_entry_safe(chk, temp, &q->out_chunk_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 		if (!chk->msg->abandoned &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 		    (!(chk->chunk_hdr->flags & SCTP_DATA_FIRST_FRAG) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 		     !SCTP_PR_PRIO_ENABLED(chk->sinfo.sinfo_flags) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 		     chk->sinfo.sinfo_timetolive <= sinfo->sinfo_timetolive))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 		chk->msg->abandoned = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 		sctp_sched_dequeue_common(q, chk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 		asoc->sent_cnt_removable--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 		asoc->abandoned_unsent[SCTP_PR_INDEX(PRIO)]++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 		if (chk->sinfo.sinfo_stream < asoc->stream.outcnt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 			struct sctp_stream_out *streamout =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 				SCTP_SO(&asoc->stream, chk->sinfo.sinfo_stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 			streamout->ext->abandoned_unsent[SCTP_PR_INDEX(PRIO)]++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 		msg_len -= chk->skb->truesize + sizeof(struct sctp_chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 		sctp_chunk_free(chk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 		if (msg_len <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 	q->sched->sched_all(&asoc->stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 	return msg_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) /* Abandon the chunks according their priorities */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) void sctp_prsctp_prune(struct sctp_association *asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 		       struct sctp_sndrcvinfo *sinfo, int msg_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 	struct sctp_transport *transport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 	if (!asoc->peer.prsctp_capable || !asoc->sent_cnt_removable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 	msg_len = sctp_prsctp_prune_sent(asoc, sinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 					 &asoc->outqueue.retransmit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 					 msg_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 	if (msg_len <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 	list_for_each_entry(transport, &asoc->peer.transport_addr_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 			    transports) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 		msg_len = sctp_prsctp_prune_sent(asoc, sinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 						 &transport->transmitted,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 						 msg_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 		if (msg_len <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 	sctp_prsctp_prune_unsent(asoc, sinfo, msg_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) /* Mark all the eligible packets on a transport for retransmission.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) void sctp_retransmit_mark(struct sctp_outq *q,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 			  struct sctp_transport *transport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 			  __u8 reason)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 	struct list_head *lchunk, *ltemp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 	struct sctp_chunk *chunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 	/* Walk through the specified transmitted queue.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 	list_for_each_safe(lchunk, ltemp, &transport->transmitted) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 		chunk = list_entry(lchunk, struct sctp_chunk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 				   transmitted_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 		/* If the chunk is abandoned, move it to abandoned list. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 		if (sctp_chunk_abandoned(chunk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 			list_del_init(lchunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 			sctp_insert_list(&q->abandoned, lchunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 			/* If this chunk has not been previousely acked,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 			 * stop considering it 'outstanding'.  Our peer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 			 * will most likely never see it since it will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 			 * not be retransmitted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 			if (!chunk->tsn_gap_acked) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 				if (chunk->transport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 					chunk->transport->flight_size -=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 							sctp_data_size(chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 				q->outstanding_bytes -= sctp_data_size(chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 				q->asoc->peer.rwnd += sctp_data_size(chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 		/* If we are doing  retransmission due to a timeout or pmtu
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 		 * discovery, only the  chunks that are not yet acked should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 		 * be added to the retransmit queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 		if ((reason == SCTP_RTXR_FAST_RTX  &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 			    (chunk->fast_retransmit == SCTP_NEED_FRTX)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 		    (reason != SCTP_RTXR_FAST_RTX  && !chunk->tsn_gap_acked)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 			/* RFC 2960 6.2.1 Processing a Received SACK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 			 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 			 * C) Any time a DATA chunk is marked for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 			 * retransmission (via either T3-rtx timer expiration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 			 * (Section 6.3.3) or via fast retransmit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 			 * (Section 7.2.4)), add the data size of those
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 			 * chunks to the rwnd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 			q->asoc->peer.rwnd += sctp_data_size(chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 			q->outstanding_bytes -= sctp_data_size(chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 			if (chunk->transport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 				transport->flight_size -= sctp_data_size(chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 			/* sctpimpguide-05 Section 2.8.2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 			 * M5) If a T3-rtx timer expires, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 			 * 'TSN.Missing.Report' of all affected TSNs is set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 			 * to 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 			chunk->tsn_missing_report = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 			/* If a chunk that is being used for RTT measurement
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 			 * has to be retransmitted, we cannot use this chunk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 			 * anymore for RTT measurements. Reset rto_pending so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 			 * that a new RTT measurement is started when a new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 			 * data chunk is sent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 			if (chunk->rtt_in_progress) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 				chunk->rtt_in_progress = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 				transport->rto_pending = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 			/* Move the chunk to the retransmit queue. The chunks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 			 * on the retransmit queue are always kept in order.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 			list_del_init(lchunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 			sctp_insert_list(&q->retransmit, lchunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 	pr_debug("%s: transport:%p, reason:%d, cwnd:%d, ssthresh:%d, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 		 "flight_size:%d, pba:%d\n", __func__, transport, reason,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 		 transport->cwnd, transport->ssthresh, transport->flight_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 		 transport->partial_bytes_acked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) /* Mark all the eligible packets on a transport for retransmission and force
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532)  * one packet out.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) void sctp_retransmit(struct sctp_outq *q, struct sctp_transport *transport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 		     enum sctp_retransmit_reason reason)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 	struct net *net = q->asoc->base.net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 	switch (reason) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 	case SCTP_RTXR_T3_RTX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 		SCTP_INC_STATS(net, SCTP_MIB_T3_RETRANSMITS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 		sctp_transport_lower_cwnd(transport, SCTP_LOWER_CWND_T3_RTX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 		/* Update the retran path if the T3-rtx timer has expired for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 		 * the current retran path.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 		if (transport == transport->asoc->peer.retran_path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 			sctp_assoc_update_retran_path(transport->asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 		transport->asoc->rtx_data_chunks +=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 			transport->asoc->unack_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 	case SCTP_RTXR_FAST_RTX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 		SCTP_INC_STATS(net, SCTP_MIB_FAST_RETRANSMITS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 		sctp_transport_lower_cwnd(transport, SCTP_LOWER_CWND_FAST_RTX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 		q->fast_rtx = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 	case SCTP_RTXR_PMTUD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 		SCTP_INC_STATS(net, SCTP_MIB_PMTUD_RETRANSMITS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 	case SCTP_RTXR_T1_RTX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 		SCTP_INC_STATS(net, SCTP_MIB_T1_RETRANSMITS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 		transport->asoc->init_retries++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 		BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 	sctp_retransmit_mark(q, transport, reason);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 	/* PR-SCTP A5) Any time the T3-rtx timer expires, on any destination,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 	 * the sender SHOULD try to advance the "Advanced.Peer.Ack.Point" by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 	 * following the procedures outlined in C1 - C5.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 	if (reason == SCTP_RTXR_T3_RTX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 		q->asoc->stream.si->generate_ftsn(q, q->asoc->ctsn_ack_point);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 	/* Flush the queues only on timeout, since fast_rtx is only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 	 * triggered during sack processing and the queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 	 * will be flushed at the end.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 	if (reason != SCTP_RTXR_FAST_RTX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 		sctp_outq_flush(q, /* rtx_timeout */ 1, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585)  * Transmit DATA chunks on the retransmit queue.  Upon return from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586)  * __sctp_outq_flush_rtx() the packet 'pkt' may contain chunks which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587)  * need to be transmitted by the caller.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588)  * We assume that pkt->transport has already been set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590)  * The return value is a normal kernel error return value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) static int __sctp_outq_flush_rtx(struct sctp_outq *q, struct sctp_packet *pkt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 				 int rtx_timeout, int *start_timer, gfp_t gfp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 	struct sctp_transport *transport = pkt->transport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 	struct sctp_chunk *chunk, *chunk1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 	struct list_head *lqueue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 	enum sctp_xmit status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 	int error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 	int timer = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 	int done = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 	int fast_rtx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 	lqueue = &q->retransmit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 	fast_rtx = q->fast_rtx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 	/* This loop handles time-out retransmissions, fast retransmissions,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 	 * and retransmissions due to opening of whindow.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 	 * RFC 2960 6.3.3 Handle T3-rtx Expiration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 	 * E3) Determine how many of the earliest (i.e., lowest TSN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 	 * outstanding DATA chunks for the address for which the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 	 * T3-rtx has expired will fit into a single packet, subject
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 	 * to the MTU constraint for the path corresponding to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 	 * destination transport address to which the retransmission
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 	 * is being sent (this may be different from the address for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 	 * which the timer expires [see Section 6.4]). Call this value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 	 * K. Bundle and retransmit those K DATA chunks in a single
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 	 * packet to the destination endpoint.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 	 * [Just to be painfully clear, if we are retransmitting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 	 * because a timeout just happened, we should send only ONE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 	 * packet of retransmitted data.]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 	 * For fast retransmissions we also send only ONE packet.  However,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 	 * if we are just flushing the queue due to open window, we'll
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 	 * try to send as much as possible.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 	list_for_each_entry_safe(chunk, chunk1, lqueue, transmitted_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 		/* If the chunk is abandoned, move it to abandoned list. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 		if (sctp_chunk_abandoned(chunk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 			list_del_init(&chunk->transmitted_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 			sctp_insert_list(&q->abandoned,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 					 &chunk->transmitted_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 		/* Make sure that Gap Acked TSNs are not retransmitted.  A
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 		 * simple approach is just to move such TSNs out of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 		 * way and into a 'transmitted' queue and skip to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 		 * next chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 		if (chunk->tsn_gap_acked) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 			list_move_tail(&chunk->transmitted_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 				       &transport->transmitted);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 		/* If we are doing fast retransmit, ignore non-fast_rtransmit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 		 * chunks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 		if (fast_rtx && !chunk->fast_retransmit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) redo:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 		/* Attempt to append this chunk to the packet. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 		status = sctp_packet_append_chunk(pkt, chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 		switch (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 		case SCTP_XMIT_PMTU_FULL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 			if (!pkt->has_data && !pkt->has_cookie_echo) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 				/* If this packet did not contain DATA then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 				 * retransmission did not happen, so do it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 				 * again.  We'll ignore the error here since
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 				 * control chunks are already freed so there
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 				 * is nothing we can do.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 				sctp_packet_transmit(pkt, gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 				goto redo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 			/* Send this packet.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 			error = sctp_packet_transmit(pkt, gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 			/* If we are retransmitting, we should only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 			 * send a single packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 			 * Otherwise, try appending this chunk again.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 			if (rtx_timeout || fast_rtx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 				done = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 				goto redo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 			/* Bundle next chunk in the next round.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 		case SCTP_XMIT_RWND_FULL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 			/* Send this packet. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 			error = sctp_packet_transmit(pkt, gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 			/* Stop sending DATA as there is no more room
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 			 * at the receiver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 			done = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 		case SCTP_XMIT_DELAY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 			/* Send this packet. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 			error = sctp_packet_transmit(pkt, gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 			/* Stop sending DATA because of nagle delay. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 			done = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 			/* The append was successful, so add this chunk to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 			 * the transmitted list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 			list_move_tail(&chunk->transmitted_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 				       &transport->transmitted);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 			/* Mark the chunk as ineligible for fast retransmit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 			 * after it is retransmitted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 			if (chunk->fast_retransmit == SCTP_NEED_FRTX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 				chunk->fast_retransmit = SCTP_DONT_FRTX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 			q->asoc->stats.rtxchunks++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 		/* Set the timer if there were no errors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 		if (!error && !timer)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 			timer = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 		if (done)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 	/* If we are here due to a retransmit timeout or a fast
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 	 * retransmit and if there are any chunks left in the retransmit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 	 * queue that could not fit in the PMTU sized packet, they need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 	 * to be marked as ineligible for a subsequent fast retransmit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 	if (rtx_timeout || fast_rtx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 		list_for_each_entry(chunk1, lqueue, transmitted_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 			if (chunk1->fast_retransmit == SCTP_NEED_FRTX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 				chunk1->fast_retransmit = SCTP_DONT_FRTX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 	*start_timer = timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 	/* Clear fast retransmit hint */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 	if (fast_rtx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 		q->fast_rtx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) /* Cork the outqueue so queued chunks are really queued. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) void sctp_outq_uncork(struct sctp_outq *q, gfp_t gfp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 	if (q->cork)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 		q->cork = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 	sctp_outq_flush(q, 0, gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) static int sctp_packet_singleton(struct sctp_transport *transport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 				 struct sctp_chunk *chunk, gfp_t gfp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 	const struct sctp_association *asoc = transport->asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 	const __u16 sport = asoc->base.bind_addr.port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 	const __u16 dport = asoc->peer.port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 	const __u32 vtag = asoc->peer.i.init_tag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 	struct sctp_packet singleton;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 	sctp_packet_init(&singleton, transport, sport, dport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 	sctp_packet_config(&singleton, vtag, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 	sctp_packet_append_chunk(&singleton, chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 	return sctp_packet_transmit(&singleton, gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) /* Struct to hold the context during sctp outq flush */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) struct sctp_flush_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 	struct sctp_outq *q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 	/* Current transport being used. It's NOT the same as curr active one */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 	struct sctp_transport *transport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 	/* These transports have chunks to send. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 	struct list_head transport_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 	struct sctp_association *asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 	/* Packet on the current transport above */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 	struct sctp_packet *packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 	gfp_t gfp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) /* transport: current transport */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) static void sctp_outq_select_transport(struct sctp_flush_ctx *ctx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 				       struct sctp_chunk *chunk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 	struct sctp_transport *new_transport = chunk->transport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 	if (!new_transport) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 		if (!sctp_chunk_is_data(chunk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 			/* If we have a prior transport pointer, see if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 			 * the destination address of the chunk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 			 * matches the destination address of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 			 * current transport.  If not a match, then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 			 * try to look up the transport with a given
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 			 * destination address.  We do this because
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 			 * after processing ASCONFs, we may have new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 			 * transports created.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 			if (ctx->transport && sctp_cmp_addr_exact(&chunk->dest,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 							&ctx->transport->ipaddr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 				new_transport = ctx->transport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 				new_transport = sctp_assoc_lookup_paddr(ctx->asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 								  &chunk->dest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 		/* if we still don't have a new transport, then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 		 * use the current active path.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 		if (!new_transport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 			new_transport = ctx->asoc->peer.active_path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 		__u8 type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 		switch (new_transport->state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 		case SCTP_INACTIVE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 		case SCTP_UNCONFIRMED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 		case SCTP_PF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 			/* If the chunk is Heartbeat or Heartbeat Ack,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 			 * send it to chunk->transport, even if it's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 			 * inactive.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 			 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 			 * 3.3.6 Heartbeat Acknowledgement:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 			 * ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 			 * A HEARTBEAT ACK is always sent to the source IP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 			 * address of the IP datagram containing the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 			 * HEARTBEAT chunk to which this ack is responding.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 			 * ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 			 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 			 * ASCONF_ACKs also must be sent to the source.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 			type = chunk->chunk_hdr->type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 			if (type != SCTP_CID_HEARTBEAT &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 			    type != SCTP_CID_HEARTBEAT_ACK &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 			    type != SCTP_CID_ASCONF_ACK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 				new_transport = ctx->asoc->peer.active_path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 	/* Are we switching transports? Take care of transport locks. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 	if (new_transport != ctx->transport) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 		ctx->transport = new_transport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 		ctx->packet = &ctx->transport->packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 		if (list_empty(&ctx->transport->send_ready))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 			list_add_tail(&ctx->transport->send_ready,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 				      &ctx->transport_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 		sctp_packet_config(ctx->packet,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 				   ctx->asoc->peer.i.init_tag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 				   ctx->asoc->peer.ecn_capable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 		/* We've switched transports, so apply the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 		 * Burst limit to the new transport.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 		sctp_transport_burst_limited(ctx->transport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) static void sctp_outq_flush_ctrl(struct sctp_flush_ctx *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 	struct sctp_chunk *chunk, *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 	enum sctp_xmit status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 	int one_packet, error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 	list_for_each_entry_safe(chunk, tmp, &ctx->q->control_chunk_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 		one_packet = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 		/* RFC 5061, 5.3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 		 * F1) This means that until such time as the ASCONF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 		 * containing the add is acknowledged, the sender MUST
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 		 * NOT use the new IP address as a source for ANY SCTP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 		 * packet except on carrying an ASCONF Chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 		if (ctx->asoc->src_out_of_asoc_ok &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 		    chunk->chunk_hdr->type != SCTP_CID_ASCONF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 		list_del_init(&chunk->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 		/* Pick the right transport to use. Should always be true for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 		 * the first chunk as we don't have a transport by then.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 		sctp_outq_select_transport(ctx, chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 		switch (chunk->chunk_hdr->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 		/* 6.10 Bundling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 		 *   ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 		 *   An endpoint MUST NOT bundle INIT, INIT ACK or SHUTDOWN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 		 *   COMPLETE with any other chunks.  [Send them immediately.]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 		case SCTP_CID_INIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 		case SCTP_CID_INIT_ACK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 		case SCTP_CID_SHUTDOWN_COMPLETE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 			error = sctp_packet_singleton(ctx->transport, chunk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 						      ctx->gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 			if (error < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 				ctx->asoc->base.sk->sk_err = -error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 				return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 		case SCTP_CID_ABORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 			if (sctp_test_T_bit(chunk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 				ctx->packet->vtag = ctx->asoc->c.my_vtag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 			fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 		/* The following chunks are "response" chunks, i.e.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 		 * they are generated in response to something we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 		 * received.  If we are sending these, then we can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 		 * send only 1 packet containing these chunks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 		case SCTP_CID_HEARTBEAT_ACK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 		case SCTP_CID_SHUTDOWN_ACK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 		case SCTP_CID_COOKIE_ACK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 		case SCTP_CID_COOKIE_ECHO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 		case SCTP_CID_ERROR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 		case SCTP_CID_ECN_CWR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 		case SCTP_CID_ASCONF_ACK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 			one_packet = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 			fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 		case SCTP_CID_SACK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 		case SCTP_CID_HEARTBEAT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 		case SCTP_CID_SHUTDOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 		case SCTP_CID_ECN_ECNE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 		case SCTP_CID_ASCONF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 		case SCTP_CID_FWD_TSN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 		case SCTP_CID_I_FWD_TSN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 		case SCTP_CID_RECONF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 			status = sctp_packet_transmit_chunk(ctx->packet, chunk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 							    one_packet, ctx->gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 			if (status != SCTP_XMIT_OK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 				/* put the chunk back */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 				list_add(&chunk->list, &ctx->q->control_chunk_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 			ctx->asoc->stats.octrlchunks++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 			/* PR-SCTP C5) If a FORWARD TSN is sent, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 			 * sender MUST assure that at least one T3-rtx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 			 * timer is running.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 			if (chunk->chunk_hdr->type == SCTP_CID_FWD_TSN ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 			    chunk->chunk_hdr->type == SCTP_CID_I_FWD_TSN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 				sctp_transport_reset_t3_rtx(ctx->transport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 				ctx->transport->last_time_sent = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 			if (chunk == ctx->asoc->strreset_chunk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 				sctp_transport_reset_reconf_timer(ctx->transport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 			/* We built a chunk with an illegal type! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 			BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) /* Returns false if new data shouldn't be sent */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) static bool sctp_outq_flush_rtx(struct sctp_flush_ctx *ctx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 				int rtx_timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 	int error, start_timer = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 	if (ctx->asoc->peer.retran_path->state == SCTP_UNCONFIRMED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 	if (ctx->transport != ctx->asoc->peer.retran_path) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 		/* Switch transports & prepare the packet.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 		ctx->transport = ctx->asoc->peer.retran_path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 		ctx->packet = &ctx->transport->packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 		if (list_empty(&ctx->transport->send_ready))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 			list_add_tail(&ctx->transport->send_ready,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 				      &ctx->transport_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 		sctp_packet_config(ctx->packet, ctx->asoc->peer.i.init_tag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 				   ctx->asoc->peer.ecn_capable);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 	error = __sctp_outq_flush_rtx(ctx->q, ctx->packet, rtx_timeout,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 				      &start_timer, ctx->gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 	if (error < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 		ctx->asoc->base.sk->sk_err = -error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 	if (start_timer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 		sctp_transport_reset_t3_rtx(ctx->transport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 		ctx->transport->last_time_sent = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 	/* This can happen on COOKIE-ECHO resend.  Only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 	 * one chunk can get bundled with a COOKIE-ECHO.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 	if (ctx->packet->has_cookie_echo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 	/* Don't send new data if there is still data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 	 * waiting to retransmit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 	if (!list_empty(&ctx->q->retransmit))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) static void sctp_outq_flush_data(struct sctp_flush_ctx *ctx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 				 int rtx_timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 	struct sctp_chunk *chunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 	enum sctp_xmit status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 	/* Is it OK to send data chunks?  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 	switch (ctx->asoc->state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 	case SCTP_STATE_COOKIE_ECHOED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 		/* Only allow bundling when this packet has a COOKIE-ECHO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 		 * chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 		if (!ctx->packet || !ctx->packet->has_cookie_echo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 	case SCTP_STATE_ESTABLISHED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 	case SCTP_STATE_SHUTDOWN_PENDING:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 	case SCTP_STATE_SHUTDOWN_RECEIVED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 		/* Do nothing. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 	/* RFC 2960 6.1  Transmission of DATA Chunks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 	 * C) When the time comes for the sender to transmit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 	 * before sending new DATA chunks, the sender MUST
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 	 * first transmit any outstanding DATA chunks which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 	 * are marked for retransmission (limited by the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 	 * current cwnd).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 	if (!list_empty(&ctx->q->retransmit) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 	    !sctp_outq_flush_rtx(ctx, rtx_timeout))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 	/* Apply Max.Burst limitation to the current transport in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 	 * case it will be used for new data.  We are going to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 	 * rest it before we return, but we want to apply the limit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 	 * to the currently queued data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 	if (ctx->transport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 		sctp_transport_burst_limited(ctx->transport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 	/* Finally, transmit new packets.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 	while ((chunk = sctp_outq_dequeue_data(ctx->q)) != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 		__u32 sid = ntohs(chunk->subh.data_hdr->stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 		__u8 stream_state = SCTP_SO(&ctx->asoc->stream, sid)->state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 		/* Has this chunk expired? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 		if (sctp_chunk_abandoned(chunk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 			sctp_sched_dequeue_done(ctx->q, chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 			sctp_chunk_fail(chunk, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 			sctp_chunk_free(chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 		if (stream_state == SCTP_STREAM_CLOSED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 			sctp_outq_head_data(ctx->q, chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 		sctp_outq_select_transport(ctx, chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 		pr_debug("%s: outq:%p, chunk:%p[%s], tx-tsn:0x%x skb->head:%p skb->users:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 			 __func__, ctx->q, chunk, chunk && chunk->chunk_hdr ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 			 sctp_cname(SCTP_ST_CHUNK(chunk->chunk_hdr->type)) :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 			 "illegal chunk", ntohl(chunk->subh.data_hdr->tsn),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 			 chunk->skb ? chunk->skb->head : NULL, chunk->skb ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 			 refcount_read(&chunk->skb->users) : -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 		/* Add the chunk to the packet.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 		status = sctp_packet_transmit_chunk(ctx->packet, chunk, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 						    ctx->gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 		if (status != SCTP_XMIT_OK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 			/* We could not append this chunk, so put
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 			 * the chunk back on the output queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 			pr_debug("%s: could not transmit tsn:0x%x, status:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 				 __func__, ntohl(chunk->subh.data_hdr->tsn),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 				 status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 			sctp_outq_head_data(ctx->q, chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 		/* The sender is in the SHUTDOWN-PENDING state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 		 * The sender MAY set the I-bit in the DATA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 		 * chunk header.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 		if (ctx->asoc->state == SCTP_STATE_SHUTDOWN_PENDING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 			chunk->chunk_hdr->flags |= SCTP_DATA_SACK_IMM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 		if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 			ctx->asoc->stats.ouodchunks++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 			ctx->asoc->stats.oodchunks++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 		/* Only now it's safe to consider this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 		 * chunk as sent, sched-wise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 		sctp_sched_dequeue_done(ctx->q, chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 		list_add_tail(&chunk->transmitted_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 			      &ctx->transport->transmitted);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 		sctp_transport_reset_t3_rtx(ctx->transport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 		ctx->transport->last_time_sent = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 		/* Only let one DATA chunk get bundled with a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 		 * COOKIE-ECHO chunk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 		if (ctx->packet->has_cookie_echo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) static void sctp_outq_flush_transports(struct sctp_flush_ctx *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 	struct list_head *ltransport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 	struct sctp_packet *packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 	struct sctp_transport *t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 	int error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 	while ((ltransport = sctp_list_dequeue(&ctx->transport_list)) != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 		t = list_entry(ltransport, struct sctp_transport, send_ready);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 		packet = &t->packet;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 		if (!sctp_packet_empty(packet)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 			error = sctp_packet_transmit(packet, ctx->gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 			if (error < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 				ctx->q->asoc->base.sk->sk_err = -error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 		/* Clear the burst limited state, if any */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 		sctp_transport_burst_reset(t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) /* Try to flush an outqueue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159)  * Description: Send everything in q which we legally can, subject to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160)  * congestion limitations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161)  * * Note: This function can be called from multiple contexts so appropriate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162)  * locking concerns must be made.  Today we use the sock lock to protect
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163)  * this function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) static void sctp_outq_flush(struct sctp_outq *q, int rtx_timeout, gfp_t gfp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 	struct sctp_flush_ctx ctx = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 		.q = q,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 		.transport = NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 		.transport_list = LIST_HEAD_INIT(ctx.transport_list),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 		.asoc = q->asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 		.packet = NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 		.gfp = gfp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 	/* 6.10 Bundling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 	 *   ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 	 *   When bundling control chunks with DATA chunks, an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 	 *   endpoint MUST place control chunks first in the outbound
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 	 *   SCTP packet.  The transmitter MUST transmit DATA chunks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 	 *   within a SCTP packet in increasing order of TSN.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 	 *   ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 	sctp_outq_flush_ctrl(&ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 	if (q->asoc->src_out_of_asoc_ok)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 		goto sctp_flush_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) 	sctp_outq_flush_data(&ctx, rtx_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) sctp_flush_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) 	sctp_outq_flush_transports(&ctx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) /* Update unack_data based on the incoming SACK chunk */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) static void sctp_sack_update_unack_data(struct sctp_association *assoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) 					struct sctp_sackhdr *sack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) 	union sctp_sack_variable *frags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) 	__u16 unack_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 	unack_data = assoc->next_tsn - assoc->ctsn_ack_point - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) 	frags = sack->variable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) 	for (i = 0; i < ntohs(sack->num_gap_ack_blocks); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) 		unack_data -= ((ntohs(frags[i].gab.end) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) 				ntohs(frags[i].gab.start) + 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) 	assoc->unack_data = unack_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) /* This is where we REALLY process a SACK.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219)  * Process the SACK against the outqueue.  Mostly, this just frees
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220)  * things off the transmitted queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) int sctp_outq_sack(struct sctp_outq *q, struct sctp_chunk *chunk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) 	struct sctp_association *asoc = q->asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 	struct sctp_sackhdr *sack = chunk->subh.sack_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) 	struct sctp_transport *transport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 	struct sctp_chunk *tchunk = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) 	struct list_head *lchunk, *transport_list, *temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) 	union sctp_sack_variable *frags = sack->variable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 	__u32 sack_ctsn, ctsn, tsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) 	__u32 highest_tsn, highest_new_tsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) 	__u32 sack_a_rwnd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) 	unsigned int outstanding;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) 	struct sctp_transport *primary = asoc->peer.primary_path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) 	int count_of_newacks = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) 	int gap_ack_blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) 	u8 accum_moved = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) 	/* Grab the association's destination address list. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 	transport_list = &asoc->peer.transport_addr_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) 	/* SCTP path tracepoint for congestion control debugging. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) 	if (trace_sctp_probe_path_enabled()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) 		list_for_each_entry(transport, transport_list, transports)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) 			trace_sctp_probe_path(transport, asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) 	sack_ctsn = ntohl(sack->cum_tsn_ack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) 	gap_ack_blocks = ntohs(sack->num_gap_ack_blocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) 	asoc->stats.gapcnt += gap_ack_blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) 	 * SFR-CACC algorithm:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) 	 * On receipt of a SACK the sender SHOULD execute the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) 	 * following statements.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) 	 * 1) If the cumulative ack in the SACK passes next tsn_at_change
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) 	 * on the current primary, the CHANGEOVER_ACTIVE flag SHOULD be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) 	 * cleared. The CYCLING_CHANGEOVER flag SHOULD also be cleared for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) 	 * all destinations.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) 	 * 2) If the SACK contains gap acks and the flag CHANGEOVER_ACTIVE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) 	 * is set the receiver of the SACK MUST take the following actions:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) 	 * A) Initialize the cacc_saw_newack to 0 for all destination
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) 	 * addresses.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) 	 * Only bother if changeover_active is set. Otherwise, this is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) 	 * totally suboptimal to do on every SACK.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) 	if (primary->cacc.changeover_active) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) 		u8 clear_cycling = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) 		if (TSN_lte(primary->cacc.next_tsn_at_change, sack_ctsn)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) 			primary->cacc.changeover_active = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) 			clear_cycling = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) 		if (clear_cycling || gap_ack_blocks) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) 			list_for_each_entry(transport, transport_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) 					transports) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) 				if (clear_cycling)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) 					transport->cacc.cycling_changeover = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) 				if (gap_ack_blocks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) 					transport->cacc.cacc_saw_newack = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) 	/* Get the highest TSN in the sack. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) 	highest_tsn = sack_ctsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) 	if (gap_ack_blocks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) 		highest_tsn += ntohs(frags[gap_ack_blocks - 1].gab.end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) 	if (TSN_lt(asoc->highest_sacked, highest_tsn))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) 		asoc->highest_sacked = highest_tsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) 	highest_new_tsn = sack_ctsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) 	/* Run through the retransmit queue.  Credit bytes received
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 	 * and free those chunks that we can.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) 	sctp_check_transmitted(q, &q->retransmit, NULL, NULL, sack, &highest_new_tsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) 	/* Run through the transmitted queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 	 * Credit bytes received and free those chunks which we can.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 	 * This is a MASSIVE candidate for optimization.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) 	list_for_each_entry(transport, transport_list, transports) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) 		sctp_check_transmitted(q, &transport->transmitted,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) 				       transport, &chunk->source, sack,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) 				       &highest_new_tsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) 		 * SFR-CACC algorithm:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) 		 * C) Let count_of_newacks be the number of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) 		 * destinations for which cacc_saw_newack is set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) 		if (transport->cacc.cacc_saw_newack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) 			count_of_newacks++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) 	/* Move the Cumulative TSN Ack Point if appropriate.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) 	if (TSN_lt(asoc->ctsn_ack_point, sack_ctsn)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) 		asoc->ctsn_ack_point = sack_ctsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) 		accum_moved = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) 	if (gap_ack_blocks) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) 		if (asoc->fast_recovery && accum_moved)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) 			highest_new_tsn = highest_tsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) 		list_for_each_entry(transport, transport_list, transports)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) 			sctp_mark_missing(q, &transport->transmitted, transport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) 					  highest_new_tsn, count_of_newacks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) 	/* Update unack_data field in the assoc. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) 	sctp_sack_update_unack_data(asoc, sack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) 	ctsn = asoc->ctsn_ack_point;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) 	/* Throw away stuff rotting on the sack queue.  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) 	list_for_each_safe(lchunk, temp, &q->sacked) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) 		tchunk = list_entry(lchunk, struct sctp_chunk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) 				    transmitted_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) 		tsn = ntohl(tchunk->subh.data_hdr->tsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) 		if (TSN_lte(tsn, ctsn)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) 			list_del_init(&tchunk->transmitted_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) 			if (asoc->peer.prsctp_capable &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) 			    SCTP_PR_PRIO_ENABLED(chunk->sinfo.sinfo_flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) 				asoc->sent_cnt_removable--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) 			sctp_chunk_free(tchunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) 	/* ii) Set rwnd equal to the newly received a_rwnd minus the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) 	 *     number of bytes still outstanding after processing the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) 	 *     Cumulative TSN Ack and the Gap Ack Blocks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) 	sack_a_rwnd = ntohl(sack->a_rwnd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) 	asoc->peer.zero_window_announced = !sack_a_rwnd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) 	outstanding = q->outstanding_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) 	if (outstanding < sack_a_rwnd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) 		sack_a_rwnd -= outstanding;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) 		sack_a_rwnd = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) 	asoc->peer.rwnd = sack_a_rwnd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) 	asoc->stream.si->generate_ftsn(q, sack_ctsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) 	pr_debug("%s: sack cumulative tsn ack:0x%x\n", __func__, sack_ctsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) 	pr_debug("%s: cumulative tsn ack of assoc:%p is 0x%x, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) 		 "advertised peer ack point:0x%x\n", __func__, asoc, ctsn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) 		 asoc->adv_peer_ack_point);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) 	return sctp_outq_is_empty(q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) /* Is the outqueue empty?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383)  * The queue is empty when we have not pending data, no in-flight data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384)  * and nothing pending retransmissions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) int sctp_outq_is_empty(const struct sctp_outq *q)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) 	return q->out_qlen == 0 && q->outstanding_bytes == 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) 	       list_empty(&q->retransmit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) /********************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393)  * 2nd Level Abstractions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394)  ********************************************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) /* Go through a transport's transmitted list or the association's retransmit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397)  * list and move chunks that are acked by the Cumulative TSN Ack to q->sacked.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398)  * The retransmit list will not have an associated transport.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400)  * I added coherent debug information output.	--xguo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402)  * Instead of printing 'sacked' or 'kept' for each TSN on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403)  * transmitted_queue, we print a range: SACKED: TSN1-TSN2, TSN3, TSN4-TSN5.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404)  * KEPT TSN6-TSN7, etc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) static void sctp_check_transmitted(struct sctp_outq *q,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) 				   struct list_head *transmitted_queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) 				   struct sctp_transport *transport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) 				   union sctp_addr *saddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) 				   struct sctp_sackhdr *sack,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) 				   __u32 *highest_new_tsn_in_sack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) 	struct list_head *lchunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) 	struct sctp_chunk *tchunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) 	struct list_head tlist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) 	__u32 tsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) 	__u32 sack_ctsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) 	__u32 rtt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) 	__u8 restart_timer = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) 	int bytes_acked = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) 	int migrate_bytes = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) 	bool forward_progress = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) 	sack_ctsn = ntohl(sack->cum_tsn_ack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) 	INIT_LIST_HEAD(&tlist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) 	/* The while loop will skip empty transmitted queues. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) 	while (NULL != (lchunk = sctp_list_dequeue(transmitted_queue))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) 		tchunk = list_entry(lchunk, struct sctp_chunk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) 				    transmitted_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) 		if (sctp_chunk_abandoned(tchunk)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) 			/* Move the chunk to abandoned list. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) 			sctp_insert_list(&q->abandoned, lchunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) 			/* If this chunk has not been acked, stop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) 			 * considering it as 'outstanding'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) 			if (transmitted_queue != &q->retransmit &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) 			    !tchunk->tsn_gap_acked) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) 				if (tchunk->transport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) 					tchunk->transport->flight_size -=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) 							sctp_data_size(tchunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) 				q->outstanding_bytes -= sctp_data_size(tchunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) 		tsn = ntohl(tchunk->subh.data_hdr->tsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) 		if (sctp_acked(sack, tsn)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) 			/* If this queue is the retransmit queue, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) 			 * retransmit timer has already reclaimed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) 			 * the outstanding bytes for this chunk, so only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) 			 * count bytes associated with a transport.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) 			if (transport && !tchunk->tsn_gap_acked) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) 				/* If this chunk is being used for RTT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) 				 * measurement, calculate the RTT and update
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) 				 * the RTO using this value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) 				 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) 				 * 6.3.1 C5) Karn's algorithm: RTT measurements
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) 				 * MUST NOT be made using packets that were
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) 				 * retransmitted (and thus for which it is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) 				 * ambiguous whether the reply was for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) 				 * first instance of the packet or a later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) 				 * instance).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) 				if (!sctp_chunk_retransmitted(tchunk) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) 				    tchunk->rtt_in_progress) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) 					tchunk->rtt_in_progress = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) 					rtt = jiffies - tchunk->sent_at;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) 					sctp_transport_update_rto(transport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) 								  rtt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) 				if (TSN_lte(tsn, sack_ctsn)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) 					/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) 					 * SFR-CACC algorithm:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) 					 * 2) If the SACK contains gap acks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) 					 * and the flag CHANGEOVER_ACTIVE is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) 					 * set the receiver of the SACK MUST
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) 					 * take the following action:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) 					 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) 					 * B) For each TSN t being acked that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) 					 * has not been acked in any SACK so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) 					 * far, set cacc_saw_newack to 1 for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) 					 * the destination that the TSN was
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) 					 * sent to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) 					 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) 					if (sack->num_gap_ack_blocks &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) 					    q->asoc->peer.primary_path->cacc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) 					    changeover_active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) 						transport->cacc.cacc_saw_newack
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) 							= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) 			/* If the chunk hasn't been marked as ACKED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) 			 * mark it and account bytes_acked if the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) 			 * chunk had a valid transport (it will not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) 			 * have a transport if ASCONF had deleted it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) 			 * while DATA was outstanding).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) 			if (!tchunk->tsn_gap_acked) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) 				tchunk->tsn_gap_acked = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) 				if (TSN_lt(*highest_new_tsn_in_sack, tsn))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) 					*highest_new_tsn_in_sack = tsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) 				bytes_acked += sctp_data_size(tchunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) 				if (!tchunk->transport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) 					migrate_bytes += sctp_data_size(tchunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) 				forward_progress = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) 			if (TSN_lte(tsn, sack_ctsn)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) 				/* RFC 2960  6.3.2 Retransmission Timer Rules
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) 				 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) 				 * R3) Whenever a SACK is received
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) 				 * that acknowledges the DATA chunk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) 				 * with the earliest outstanding TSN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) 				 * for that address, restart T3-rtx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) 				 * timer for that address with its
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) 				 * current RTO.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) 				restart_timer = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) 				forward_progress = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) 				list_add_tail(&tchunk->transmitted_list,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) 					      &q->sacked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) 				/* RFC2960 7.2.4, sctpimpguide-05 2.8.2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) 				 * M2) Each time a SACK arrives reporting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) 				 * 'Stray DATA chunk(s)' record the highest TSN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) 				 * reported as newly acknowledged, call this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) 				 * value 'HighestTSNinSack'. A newly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) 				 * acknowledged DATA chunk is one not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) 				 * previously acknowledged in a SACK.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) 				 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) 				 * When the SCTP sender of data receives a SACK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) 				 * chunk that acknowledges, for the first time,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) 				 * the receipt of a DATA chunk, all the still
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) 				 * unacknowledged DATA chunks whose TSN is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) 				 * older than that newly acknowledged DATA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) 				 * chunk, are qualified as 'Stray DATA chunks'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) 				list_add_tail(lchunk, &tlist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) 			if (tchunk->tsn_gap_acked) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) 				pr_debug("%s: receiver reneged on data TSN:0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) 					 __func__, tsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) 				tchunk->tsn_gap_acked = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) 				if (tchunk->transport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) 					bytes_acked -= sctp_data_size(tchunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) 				/* RFC 2960 6.3.2 Retransmission Timer Rules
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) 				 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) 				 * R4) Whenever a SACK is received missing a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) 				 * TSN that was previously acknowledged via a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) 				 * Gap Ack Block, start T3-rtx for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) 				 * destination address to which the DATA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) 				 * chunk was originally
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) 				 * transmitted if it is not already running.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) 				restart_timer = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) 			list_add_tail(lchunk, &tlist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) 	if (transport) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) 		if (bytes_acked) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) 			struct sctp_association *asoc = transport->asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) 			/* We may have counted DATA that was migrated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) 			 * to this transport due to DEL-IP operation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) 			 * Subtract those bytes, since the were never
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) 			 * send on this transport and shouldn't be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) 			 * credited to this transport.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) 			bytes_acked -= migrate_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) 			/* 8.2. When an outstanding TSN is acknowledged,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) 			 * the endpoint shall clear the error counter of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) 			 * the destination transport address to which the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) 			 * DATA chunk was last sent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) 			 * The association's overall error counter is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) 			 * also cleared.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) 			transport->error_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) 			transport->asoc->overall_error_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) 			forward_progress = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) 			 * While in SHUTDOWN PENDING, we may have started
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) 			 * the T5 shutdown guard timer after reaching the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) 			 * retransmission limit. Stop that timer as soon
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) 			 * as the receiver acknowledged any data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) 			if (asoc->state == SCTP_STATE_SHUTDOWN_PENDING &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) 			    del_timer(&asoc->timers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) 				[SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) 					sctp_association_put(asoc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) 			/* Mark the destination transport address as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) 			 * active if it is not so marked.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) 			if ((transport->state == SCTP_INACTIVE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) 			     transport->state == SCTP_UNCONFIRMED) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) 			    sctp_cmp_addr_exact(&transport->ipaddr, saddr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) 				sctp_assoc_control_transport(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) 					transport->asoc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) 					transport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) 					SCTP_TRANSPORT_UP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) 					SCTP_RECEIVED_SACK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) 			sctp_transport_raise_cwnd(transport, sack_ctsn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) 						  bytes_acked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) 			transport->flight_size -= bytes_acked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) 			if (transport->flight_size == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) 				transport->partial_bytes_acked = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) 			q->outstanding_bytes -= bytes_acked + migrate_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) 			/* RFC 2960 6.1, sctpimpguide-06 2.15.2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) 			 * When a sender is doing zero window probing, it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) 			 * should not timeout the association if it continues
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) 			 * to receive new packets from the receiver. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) 			 * reason is that the receiver MAY keep its window
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) 			 * closed for an indefinite time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) 			 * A sender is doing zero window probing when the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) 			 * receiver's advertised window is zero, and there is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) 			 * only one data chunk in flight to the receiver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) 			 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) 			 * Allow the association to timeout while in SHUTDOWN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) 			 * PENDING or SHUTDOWN RECEIVED in case the receiver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) 			 * stays in zero window mode forever.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) 			if (!q->asoc->peer.rwnd &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) 			    !list_empty(&tlist) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) 			    (sack_ctsn+2 == q->asoc->next_tsn) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) 			    q->asoc->state < SCTP_STATE_SHUTDOWN_PENDING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) 				pr_debug("%s: sack received for zero window "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) 					 "probe:%u\n", __func__, sack_ctsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) 				q->asoc->overall_error_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) 				transport->error_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) 		/* RFC 2960 6.3.2 Retransmission Timer Rules
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) 		 * R2) Whenever all outstanding data sent to an address have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) 		 * been acknowledged, turn off the T3-rtx timer of that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) 		 * address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) 		if (!transport->flight_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) 			if (del_timer(&transport->T3_rtx_timer))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) 				sctp_transport_put(transport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) 		} else if (restart_timer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) 			if (!mod_timer(&transport->T3_rtx_timer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) 				       jiffies + transport->rto))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) 				sctp_transport_hold(transport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) 		if (forward_progress) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) 			if (transport->dst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) 				sctp_transport_dst_confirm(transport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) 	list_splice(&tlist, transmitted_queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) /* Mark chunks as missing and consequently may get retransmitted. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) static void sctp_mark_missing(struct sctp_outq *q,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) 			      struct list_head *transmitted_queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) 			      struct sctp_transport *transport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) 			      __u32 highest_new_tsn_in_sack,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) 			      int count_of_newacks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) 	struct sctp_chunk *chunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) 	__u32 tsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) 	char do_fast_retransmit = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) 	struct sctp_association *asoc = q->asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) 	struct sctp_transport *primary = asoc->peer.primary_path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) 	list_for_each_entry(chunk, transmitted_queue, transmitted_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) 		tsn = ntohl(chunk->subh.data_hdr->tsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) 		/* RFC 2960 7.2.4, sctpimpguide-05 2.8.2 M3) Examine all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) 		 * 'Unacknowledged TSN's', if the TSN number of an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) 		 * 'Unacknowledged TSN' is smaller than the 'HighestTSNinSack'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) 		 * value, increment the 'TSN.Missing.Report' count on that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) 		 * chunk if it has NOT been fast retransmitted or marked for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) 		 * fast retransmit already.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) 		if (chunk->fast_retransmit == SCTP_CAN_FRTX &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) 		    !chunk->tsn_gap_acked &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) 		    TSN_lt(tsn, highest_new_tsn_in_sack)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) 			/* SFR-CACC may require us to skip marking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) 			 * this chunk as missing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) 			if (!transport || !sctp_cacc_skip(primary,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) 						chunk->transport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) 						count_of_newacks, tsn)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) 				chunk->tsn_missing_report++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) 				pr_debug("%s: tsn:0x%x missing counter:%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) 					 __func__, tsn, chunk->tsn_missing_report);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) 		 * M4) If any DATA chunk is found to have a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) 		 * 'TSN.Missing.Report'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) 		 * value larger than or equal to 3, mark that chunk for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) 		 * retransmission and start the fast retransmit procedure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) 		if (chunk->tsn_missing_report >= 3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) 			chunk->fast_retransmit = SCTP_NEED_FRTX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) 			do_fast_retransmit = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) 	if (transport) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) 		if (do_fast_retransmit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) 			sctp_retransmit(q, transport, SCTP_RTXR_FAST_RTX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) 		pr_debug("%s: transport:%p, cwnd:%d, ssthresh:%d, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) 			 "flight_size:%d, pba:%d\n",  __func__, transport,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) 			 transport->cwnd, transport->ssthresh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) 			 transport->flight_size, transport->partial_bytes_acked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) /* Is the given TSN acked by this packet?  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) static int sctp_acked(struct sctp_sackhdr *sack, __u32 tsn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) 	__u32 ctsn = ntohl(sack->cum_tsn_ack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) 	union sctp_sack_variable *frags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) 	__u16 tsn_offset, blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) 	if (TSN_lte(tsn, ctsn))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) 		goto pass;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) 	/* 3.3.4 Selective Acknowledgment (SACK) (3):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) 	 * Gap Ack Blocks:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) 	 *  These fields contain the Gap Ack Blocks. They are repeated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) 	 *  for each Gap Ack Block up to the number of Gap Ack Blocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) 	 *  defined in the Number of Gap Ack Blocks field. All DATA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) 	 *  chunks with TSNs greater than or equal to (Cumulative TSN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) 	 *  Ack + Gap Ack Block Start) and less than or equal to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) 	 *  (Cumulative TSN Ack + Gap Ack Block End) of each Gap Ack
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) 	 *  Block are assumed to have been received correctly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) 	frags = sack->variable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) 	blocks = ntohs(sack->num_gap_ack_blocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) 	tsn_offset = tsn - ctsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) 	for (i = 0; i < blocks; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) 		if (tsn_offset >= ntohs(frags[i].gab.start) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) 		    tsn_offset <= ntohs(frags[i].gab.end))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) 			goto pass;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) pass:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) static inline int sctp_get_skip_pos(struct sctp_fwdtsn_skip *skiplist,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) 				    int nskips, __be16 stream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) 	for (i = 0; i < nskips; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) 		if (skiplist[i].stream == stream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) 			return i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) 	return i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) /* Create and add a fwdtsn chunk to the outq's control queue if needed. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) void sctp_generate_fwdtsn(struct sctp_outq *q, __u32 ctsn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) 	struct sctp_association *asoc = q->asoc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) 	struct sctp_chunk *ftsn_chunk = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) 	struct sctp_fwdtsn_skip ftsn_skip_arr[10];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) 	int nskips = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) 	int skip_pos = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) 	__u32 tsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) 	struct sctp_chunk *chunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) 	struct list_head *lchunk, *temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) 	if (!asoc->peer.prsctp_capable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) 	/* PR-SCTP C1) Let SackCumAck be the Cumulative TSN ACK carried in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) 	 * received SACK.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) 	 * If (Advanced.Peer.Ack.Point < SackCumAck), then update
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) 	 * Advanced.Peer.Ack.Point to be equal to SackCumAck.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) 	if (TSN_lt(asoc->adv_peer_ack_point, ctsn))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) 		asoc->adv_peer_ack_point = ctsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) 	/* PR-SCTP C2) Try to further advance the "Advanced.Peer.Ack.Point"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) 	 * locally, that is, to move "Advanced.Peer.Ack.Point" up as long as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) 	 * the chunk next in the out-queue space is marked as "abandoned" as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) 	 * shown in the following example:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) 	 * Assuming that a SACK arrived with the Cumulative TSN ACK 102
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) 	 * and the Advanced.Peer.Ack.Point is updated to this value:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) 	 *   out-queue at the end of  ==>   out-queue after Adv.Ack.Point
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) 	 *   normal SACK processing           local advancement
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) 	 *                ...                           ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) 	 *   Adv.Ack.Pt-> 102 acked                     102 acked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) 	 *                103 abandoned                 103 abandoned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) 	 *                104 abandoned     Adv.Ack.P-> 104 abandoned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) 	 *                105                           105
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) 	 *                106 acked                     106 acked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) 	 *                ...                           ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) 	 * In this example, the data sender successfully advanced the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) 	 * "Advanced.Peer.Ack.Point" from 102 to 104 locally.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) 	list_for_each_safe(lchunk, temp, &q->abandoned) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) 		chunk = list_entry(lchunk, struct sctp_chunk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) 					transmitted_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) 		tsn = ntohl(chunk->subh.data_hdr->tsn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) 		/* Remove any chunks in the abandoned queue that are acked by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) 		 * the ctsn.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) 		if (TSN_lte(tsn, ctsn)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) 			list_del_init(lchunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) 			sctp_chunk_free(chunk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) 			if (TSN_lte(tsn, asoc->adv_peer_ack_point+1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) 				asoc->adv_peer_ack_point = tsn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) 				if (chunk->chunk_hdr->flags &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) 					 SCTP_DATA_UNORDERED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) 					continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) 				skip_pos = sctp_get_skip_pos(&ftsn_skip_arr[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) 						nskips,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) 						chunk->subh.data_hdr->stream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) 				ftsn_skip_arr[skip_pos].stream =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) 					chunk->subh.data_hdr->stream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) 				ftsn_skip_arr[skip_pos].ssn =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) 					 chunk->subh.data_hdr->ssn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) 				if (skip_pos == nskips)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) 					nskips++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) 				if (nskips == 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) 					break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) 			} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) 	/* PR-SCTP C3) If, after step C1 and C2, the "Advanced.Peer.Ack.Point"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) 	 * is greater than the Cumulative TSN ACK carried in the received
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) 	 * SACK, the data sender MUST send the data receiver a FORWARD TSN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) 	 * chunk containing the latest value of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) 	 * "Advanced.Peer.Ack.Point".
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) 	 * C4) For each "abandoned" TSN the sender of the FORWARD TSN SHOULD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) 	 * list each stream and sequence number in the forwarded TSN. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) 	 * information will enable the receiver to easily find any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) 	 * stranded TSN's waiting on stream reorder queues. Each stream
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) 	 * SHOULD only be reported once; this means that if multiple
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) 	 * abandoned messages occur in the same stream then only the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) 	 * highest abandoned stream sequence number is reported. If the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) 	 * total size of the FORWARD TSN does NOT fit in a single MTU then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) 	 * the sender of the FORWARD TSN SHOULD lower the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) 	 * Advanced.Peer.Ack.Point to the last TSN that will fit in a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) 	 * single MTU.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) 	if (asoc->adv_peer_ack_point > ctsn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) 		ftsn_chunk = sctp_make_fwdtsn(asoc, asoc->adv_peer_ack_point,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) 					      nskips, &ftsn_skip_arr[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) 	if (ftsn_chunk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) 		list_add_tail(&ftsn_chunk->list, &q->control_chunk_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) 		SCTP_INC_STATS(asoc->base.net, SCTP_MIB_OUTCTRLCHUNKS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) }