--- a/netwerk/sctp/src/netinet/sctp_cc_functions.c
+++ b/netwerk/sctp/src/netinet/sctp_cc_functions.c
@@ -1,11 +1,9 @@
/*-
- * SPDX-License-Identifier: BSD-3-Clause
- *
* Copyright (c) 2001-2007, by Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2008-2012, by Randall Stewart. All rights reserved.
* Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* a) Redistributions of source code must retain the above copyright notice,
@@ -29,17 +27,17 @@
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/netinet/sctp_cc_functions.c 310590 2016-12-26 11:06:41Z tuexen $");
+__FBSDID("$FreeBSD: head/sys/netinet/sctp_cc_functions.c 279859 2015-03-10 19:49:25Z tuexen $");
#endif
#include <netinet/sctp_os.h>
#include <netinet/sctp_var.h>
#include <netinet/sctp_sysctl.h>
#include <netinet/sctp_pcb.h>
#include <netinet/sctp_header.h>
#include <netinet/sctputil.h>
@@ -97,17 +95,17 @@ sctp_set_initial_cc_param(struct sctp_tc
net->cwnd /= assoc->numnets;
if (net->cwnd < (net->mtu - sizeof(struct sctphdr))) {
net->cwnd = net->mtu - sizeof(struct sctphdr);
}
}
sctp_enforce_cwnd_limit(assoc, net);
net->ssthresh = assoc->peers_rwnd;
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
- SDT_PROBE5(sctp, cwnd, net, init,
+ SDT_PROBE(sctp, cwnd, net, init,
stcb->asoc.my_vtag, ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), net,
0, net->cwnd);
#endif
if (SCTP_BASE_SYSCTL(sctp_logging_level) &
(SCTP_CWND_MONITOR_ENABLE|SCTP_CWND_LOGGING_ENABLE)) {
sctp_log_cwnd(stcb, net, 0, SCTP_CWND_INITIALIZATION);
}
}
@@ -192,67 +190,66 @@ sctp_cwnd_update_after_fr(struct sctp_tc
net->ssthresh = net->cwnd / 2;
if (net->ssthresh < (net->mtu * 2)) {
net->ssthresh = 2 * net->mtu;
}
}
net->cwnd = net->ssthresh;
sctp_enforce_cwnd_limit(asoc, net);
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
- SDT_PROBE5(sctp, cwnd, net, fr,
+ SDT_PROBE(sctp, cwnd, net, fr,
stcb->asoc.my_vtag, ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), net,
old_cwnd, net->cwnd);
#endif
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd),
SCTP_CWND_LOG_FROM_FR);
}
lchk = TAILQ_FIRST(&asoc->send_queue);
net->partial_bytes_acked = 0;
/* Turn on fast recovery window */
asoc->fast_retran_loss_recovery = 1;
if (lchk == NULL) {
/* Mark end of the window */
asoc->fast_recovery_tsn = asoc->sending_seq - 1;
} else {
- asoc->fast_recovery_tsn = lchk->rec.data.tsn - 1;
+ asoc->fast_recovery_tsn = lchk->rec.data.TSN_seq - 1;
}
/*
* CMT fast recovery -- per destination
* recovery variable.
*/
net->fast_retran_loss_recovery = 1;
if (lchk == NULL) {
/* Mark end of the window */
net->fast_recovery_tsn = asoc->sending_seq - 1;
} else {
- net->fast_recovery_tsn = lchk->rec.data.tsn - 1;
+ net->fast_recovery_tsn = lchk->rec.data.TSN_seq - 1;
}
sctp_timer_stop(SCTP_TIMER_TYPE_SEND,
- stcb->sctp_ep, stcb, net,
- SCTP_FROM_SCTP_CC_FUNCTIONS + SCTP_LOC_1);
+ stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_INDATA+SCTP_LOC_32 );
sctp_timer_start(SCTP_TIMER_TYPE_SEND,
stcb->sctp_ep, stcb, net);
}
} else if (net->net_ack > 0) {
/*
* Mark a peg that we WOULD have done a cwnd
* reduction but RFC2582 prevented this action.
*/
SCTP_STAT_INCR(sctps_fastretransinrtt);
}
}
}
/* Defines for instantaneous bw decisions */
-#define SCTP_INST_LOOSING 1 /* Losing to other flows */
+#define SCTP_INST_LOOSING 1 /* Loosing to other flows */
#define SCTP_INST_NEUTRAL 2 /* Neutral, no indication */
#define SCTP_INST_GAINING 3 /* Gaining, step down possible */
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
static int
cc_bw_same(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw,
uint64_t rtt_offset, uint64_t vtag, uint8_t inst_ind)
@@ -273,17 +270,17 @@ cc_bw_same(struct sctp_tcb *stcb SCTP_UN
/*
* rtt increased
* we don't update bw.. so we don't
* update the rtt either.
*/
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
/* Probe point 5 */
probepoint |= ((5 << 16) | 1);
- SDT_PROBE5(sctp, cwnd, net, rttvar,
+ SDT_PROBE(sctp, cwnd, net, rttvar,
vtag,
((net->cc_mod.rtcc.lbw << 32) | nbw),
((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
net->flight_size,
probepoint);
#endif
if ((net->cc_mod.rtcc.steady_step) && (inst_ind != SCTP_INST_LOOSING)) {
if (net->cc_mod.rtcc.last_step_state == 5)
@@ -296,17 +293,17 @@ cc_bw_same(struct sctp_tcb *stcb SCTP_UN
((net->cc_mod.rtcc.step_cnt % net->cc_mod.rtcc.steady_step) == 0))) {
/* Try a step down */
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
oth = net->cc_mod.rtcc.vol_reduce;
oth <<= 16;
oth |= net->cc_mod.rtcc.step_cnt;
oth <<= 16;
oth |= net->cc_mod.rtcc.last_step_state;
- SDT_PROBE5(sctp, cwnd, net, rttstep,
+ SDT_PROBE(sctp, cwnd, net, rttstep,
vtag,
((net->cc_mod.rtcc.lbw << 32) | nbw),
((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
oth,
probepoint);
#endif
if (net->cwnd > (4 * net->mtu)) {
net->cwnd -= net->mtu;
@@ -322,31 +319,31 @@ cc_bw_same(struct sctp_tcb *stcb SCTP_UN
/*
* rtt decreased, there could be more room.
* we update both the bw and the rtt here to
* lock this in as a good step down.
*/
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
/* Probe point 6 */
probepoint |= ((6 << 16) | 0);
- SDT_PROBE5(sctp, cwnd, net, rttvar,
+ SDT_PROBE(sctp, cwnd, net, rttvar,
vtag,
((net->cc_mod.rtcc.lbw << 32) | nbw),
((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
net->flight_size,
probepoint);
#endif
if (net->cc_mod.rtcc.steady_step) {
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
oth = net->cc_mod.rtcc.vol_reduce;
oth <<= 16;
oth |= net->cc_mod.rtcc.step_cnt;
oth <<= 16;
oth |= net->cc_mod.rtcc.last_step_state;
- SDT_PROBE5(sctp, cwnd, net, rttstep,
+ SDT_PROBE(sctp, cwnd, net, rttstep,
vtag,
((net->cc_mod.rtcc.lbw << 32) | nbw),
((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
oth,
probepoint);
#endif
if ((net->cc_mod.rtcc.last_step_state == 5) &&
(net->cc_mod.rtcc.step_cnt > net->cc_mod.rtcc.steady_step)) {
@@ -368,17 +365,17 @@ cc_bw_same(struct sctp_tcb *stcb SCTP_UN
else
return (0);
}
/* Ok bw and rtt remained the same .. no update to any
*/
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
/* Probe point 7 */
probepoint |= ((7 << 16) | net->cc_mod.rtcc.ret_from_eq);
- SDT_PROBE5(sctp, cwnd, net, rttvar,
+ SDT_PROBE(sctp, cwnd, net, rttvar,
vtag,
((net->cc_mod.rtcc.lbw << 32) | nbw),
((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
net->flight_size,
probepoint);
#endif
if ((net->cc_mod.rtcc.steady_step) && (inst_ind != SCTP_INST_LOOSING)) {
if (net->cc_mod.rtcc.last_step_state == 5)
@@ -429,49 +426,49 @@ cc_bw_decrease(struct sctp_tcb *stcb SCT
/* rtt increased */
/* Did we add more */
if ((net->cwnd > net->cc_mod.rtcc.cwnd_at_bw_set) &&
(inst_ind != SCTP_INST_LOOSING)) {
/* We caused it maybe.. back off? */
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
/* PROBE POINT 1 */
probepoint |= ((1 << 16) | 1);
- SDT_PROBE5(sctp, cwnd, net, rttvar,
+ SDT_PROBE(sctp, cwnd, net, rttvar,
vtag,
((net->cc_mod.rtcc.lbw << 32) | nbw),
((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
net->flight_size,
probepoint);
#endif
if (net->cc_mod.rtcc.ret_from_eq) {
/* Switch over to CA if we are less aggressive */
net->ssthresh = net->cwnd-1;
net->partial_bytes_acked = 0;
}
return (1);
}
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
/* Probe point 2 */
probepoint |= ((2 << 16) | 0);
- SDT_PROBE5(sctp, cwnd, net, rttvar,
+ SDT_PROBE(sctp, cwnd, net, rttvar,
vtag,
((net->cc_mod.rtcc.lbw << 32) | nbw),
((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
net->flight_size,
probepoint);
#endif
/* Someone else - fight for more? */
if (net->cc_mod.rtcc.steady_step) {
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
oth = net->cc_mod.rtcc.vol_reduce;
oth <<= 16;
oth |= net->cc_mod.rtcc.step_cnt;
oth <<= 16;
oth |= net->cc_mod.rtcc.last_step_state;
- SDT_PROBE5(sctp, cwnd, net, rttstep,
+ SDT_PROBE(sctp, cwnd, net, rttstep,
vtag,
((net->cc_mod.rtcc.lbw << 32) | nbw),
((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
oth,
probepoint);
#endif
/* Did we voluntarily give up some? if so take
* one back please
@@ -486,31 +483,31 @@ cc_bw_decrease(struct sctp_tcb *stcb SCT
net->cc_mod.rtcc.step_cnt = 0;
}
goto out_decision;
} else if (net->rtt < net->cc_mod.rtcc.lbw_rtt-rtt_offset) {
/* bw & rtt decreased */
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
/* Probe point 3 */
probepoint |= ((3 << 16) | 0);
- SDT_PROBE5(sctp, cwnd, net, rttvar,
+ SDT_PROBE(sctp, cwnd, net, rttvar,
vtag,
((net->cc_mod.rtcc.lbw << 32) | nbw),
((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
net->flight_size,
probepoint);
#endif
if (net->cc_mod.rtcc.steady_step) {
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
oth = net->cc_mod.rtcc.vol_reduce;
oth <<= 16;
oth |= net->cc_mod.rtcc.step_cnt;
oth <<= 16;
oth |= net->cc_mod.rtcc.last_step_state;
- SDT_PROBE5(sctp, cwnd, net, rttstep,
+ SDT_PROBE(sctp, cwnd, net, rttstep,
vtag,
((net->cc_mod.rtcc.lbw << 32) | nbw),
((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
oth,
probepoint);
#endif
if ((net->cc_mod.rtcc.vol_reduce) &&
(inst_ind != SCTP_INST_GAINING)) {
@@ -522,31 +519,31 @@ cc_bw_decrease(struct sctp_tcb *stcb SCT
net->cc_mod.rtcc.step_cnt = 0;
}
goto out_decision;
}
/* The bw decreased but rtt stayed the same */
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
/* Probe point 4 */
probepoint |= ((4 << 16) | 0);
- SDT_PROBE5(sctp, cwnd, net, rttvar,
+ SDT_PROBE(sctp, cwnd, net, rttvar,
vtag,
((net->cc_mod.rtcc.lbw << 32) | nbw),
((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
net->flight_size,
probepoint);
#endif
if (net->cc_mod.rtcc.steady_step) {
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
oth = net->cc_mod.rtcc.vol_reduce;
oth <<= 16;
oth |= net->cc_mod.rtcc.step_cnt;
oth <<= 16;
oth |= net->cc_mod.rtcc.last_step_state;
- SDT_PROBE5(sctp, cwnd, net, rttstep,
+ SDT_PROBE(sctp, cwnd, net, rttstep,
vtag,
((net->cc_mod.rtcc.lbw << 32) | nbw),
((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
oth,
probepoint);
#endif
if ((net->cc_mod.rtcc.vol_reduce) &&
(inst_ind != SCTP_INST_GAINING)) {
@@ -584,48 +581,48 @@ cc_bw_increase(struct sctp_tcb *stcb SCT
* return 0, since all actions in
* our table say to do the normal CC
* update. Note that we pay no attention to
* the inst_ind since our overall sum is increasing.
*/
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
/* PROBE POINT 0 */
probepoint = (((uint64_t)net->cwnd) << 32);
- SDT_PROBE5(sctp, cwnd, net, rttvar,
+ SDT_PROBE(sctp, cwnd, net, rttvar,
vtag,
((net->cc_mod.rtcc.lbw << 32) | nbw),
((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
net->flight_size,
probepoint);
#endif
if (net->cc_mod.rtcc.steady_step) {
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
oth = net->cc_mod.rtcc.vol_reduce;
oth <<= 16;
oth |= net->cc_mod.rtcc.step_cnt;
oth <<= 16;
oth |= net->cc_mod.rtcc.last_step_state;
- SDT_PROBE5(sctp, cwnd, net, rttstep,
+ SDT_PROBE(sctp, cwnd, net, rttstep,
vtag,
((net->cc_mod.rtcc.lbw << 32) | nbw),
((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
oth,
probepoint);
#endif
net->cc_mod.rtcc.last_step_state = 0;
net->cc_mod.rtcc.step_cnt = 0;
net->cc_mod.rtcc.vol_reduce = 0;
}
net->cc_mod.rtcc.lbw = nbw;
net->cc_mod.rtcc.lbw_rtt = net->rtt;
net->cc_mod.rtcc.cwnd_at_bw_set = net->cwnd;
return (0);
}
-/* RTCC Algorithm to limit growth of cwnd, return
+/* RTCC Algoritm to limit growth of cwnd, return
* true if you want to NOT allow cwnd growth
*/
static int
cc_bw_limit(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw)
{
uint64_t bw_offset, rtt_offset;
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
uint64_t probepoint, rtt, vtag;
@@ -709,17 +706,17 @@ cc_bw_limit(struct sctp_tcb *stcb, struc
inst_ind = net->cc_mod.rtcc.last_inst_ind;
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
inst_bw = bytes_for_this_rtt;
/* Can't determine do not change */
probepoint |= ((0xd << 16) | inst_ind);
#endif
}
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
- SDT_PROBE5(sctp, cwnd, net, rttvar,
+ SDT_PROBE(sctp, cwnd, net, rttvar,
vtag,
((nbw << 32) | inst_bw),
((net->cc_mod.rtcc.lbw_rtt << 32) | rtt),
net->flight_size,
probepoint);
#endif
} else {
/* No rtt measurement, use last one */
@@ -883,17 +880,17 @@ sctp_cwnd_update_after_sack_common(struc
uint64_t vtag, probepoint;
probepoint = (((uint64_t)net->cwnd) << 32);
probepoint |= ((0xa << 16) | 0);
vtag = (net->rtt << 32) |
(((uint32_t)(stcb->sctp_ep->sctp_lport)) << 16) |
(stcb->rport);
- SDT_PROBE5(sctp, cwnd, net, rttvar,
+ SDT_PROBE(sctp, cwnd, net, rttvar,
vtag,
nbw,
((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
net->flight_size,
probepoint);
#endif
net->cc_mod.rtcc.lbw = nbw;
net->cc_mod.rtcc.lbw_rtt = net->rtt;
@@ -983,17 +980,17 @@ sctp_cwnd_update_after_sack_common(struc
}
net->cwnd += incr;
sctp_enforce_cwnd_limit(asoc, net);
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
sctp_log_cwnd(stcb, net, incr,
SCTP_CWND_LOG_FROM_SS);
}
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
- SDT_PROBE5(sctp, cwnd, net, ack,
+ SDT_PROBE(sctp, cwnd, net, ack,
stcb->asoc.my_vtag,
((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
net,
old_cwnd, net->cwnd);
#endif
} else {
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
sctp_log_cwnd(stcb, net, net->net_ack,
@@ -1047,17 +1044,17 @@ sctp_cwnd_update_after_sack_common(struc
break;
default:
incr = net->mtu;
break;
}
net->cwnd += incr;
sctp_enforce_cwnd_limit(asoc, net);
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
- SDT_PROBE5(sctp, cwnd, net, ack,
+ SDT_PROBE(sctp, cwnd, net, ack,
stcb->asoc.my_vtag,
((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
net,
old_cwnd, net->cwnd);
#endif
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
sctp_log_cwnd(stcb, net, net->mtu,
SCTP_CWND_LOG_FROM_CA);
@@ -1088,17 +1085,17 @@ sctp_cwnd_update_exit_pf_common(struct s
{
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
int old_cwnd;
old_cwnd = net->cwnd;
#endif
net->cwnd = net->mtu;
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
- SDT_PROBE5(sctp, cwnd, net, ack,
+ SDT_PROBE(sctp, cwnd, net, ack,
stcb->asoc.my_vtag, ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), net,
old_cwnd, net->cwnd);
#endif
SCTPDBG(SCTP_DEBUG_INDATA1, "Destination %p moved from PF to reachable with cwnd %d.\n",
(void *)net, net->cwnd);
}
@@ -1161,17 +1158,17 @@ sctp_cwnd_update_after_timeout(struct sc
net->ssthresh = net->mtu;
}
} else {
net->ssthresh = max(net->cwnd / 2, 4 * net->mtu);
}
net->cwnd = net->mtu;
net->partial_bytes_acked = 0;
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
- SDT_PROBE5(sctp, cwnd, net, to,
+ SDT_PROBE(sctp, cwnd, net, to,
stcb->asoc.my_vtag,
((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
net,
old_cwnd, net->cwnd);
#endif
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
sctp_log_cwnd(stcb, net, net->cwnd - old_cwnd, SCTP_CWND_LOG_FROM_RTX);
}
@@ -1196,17 +1193,17 @@ sctp_cwnd_update_after_ecn_echo_common(s
net->cwnd /= 2;
}
/* Drop to CA */
net->ssthresh = net->cwnd - (num_pkt_lost * net->mtu);
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_SAT);
}
} else {
- /* Further tuning down required over the drastic original cut */
+ /* Further tuning down required over the drastic orginal cut */
net->ssthresh -= (net->mtu * num_pkt_lost);
net->cwnd -= (net->mtu * num_pkt_lost);
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_SAT);
}
}
SCTP_STAT_INCR(sctps_ecnereducedcwnd);
@@ -1216,17 +1213,17 @@ sctp_cwnd_update_after_ecn_echo_common(s
net->ssthresh = net->cwnd / 2;
if (net->ssthresh < net->mtu) {
net->ssthresh = net->mtu;
/* here back off the timer as well, to slow us down */
net->RTO <<= 1;
}
net->cwnd = net->ssthresh;
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
- SDT_PROBE5(sctp, cwnd, net, ecn,
+ SDT_PROBE(sctp, cwnd, net, ecn,
stcb->asoc.my_vtag,
((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
net,
old_cwnd, net->cwnd);
#endif
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_SAT);
}
@@ -1337,17 +1334,17 @@ sctp_cwnd_update_after_packet_dropped(st
if (net->cwnd < net->mtu) {
/* We always have 1 MTU */
net->cwnd = net->mtu;
}
sctp_enforce_cwnd_limit(&stcb->asoc, net);
if (net->cwnd - old_cwnd != 0) {
/* log only changes */
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
- SDT_PROBE5(sctp, cwnd, net, pd,
+ SDT_PROBE(sctp, cwnd, net, pd,
stcb->asoc.my_vtag,
((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
net,
old_cwnd, net->cwnd);
#endif
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd),
SCTP_CWND_LOG_FROM_SAT);
@@ -1362,48 +1359,48 @@ sctp_cwnd_update_after_output(struct sct
int old_cwnd = net->cwnd;
if (net->ssthresh < net->cwnd)
net->ssthresh = net->cwnd;
if (burst_limit) {
net->cwnd = (net->flight_size + (burst_limit * net->mtu));
sctp_enforce_cwnd_limit(&stcb->asoc, net);
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
- SDT_PROBE5(sctp, cwnd, net, bl,
+ SDT_PROBE(sctp, cwnd, net, bl,
stcb->asoc.my_vtag,
((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
net,
old_cwnd, net->cwnd);
#endif
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_BRST);
}
}
}
static void
sctp_cwnd_update_after_sack(struct sctp_tcb *stcb,
struct sctp_association *asoc,
int accum_moved, int reneged_all, int will_exit)
{
- /* Passing a zero argument in last disables the rtcc algorithm */
+ /* Passing a zero argument in last disables the rtcc algoritm */
sctp_cwnd_update_after_sack_common(stcb, asoc, accum_moved, reneged_all, will_exit, 0);
}
static void
sctp_cwnd_update_after_ecn_echo(struct sctp_tcb *stcb, struct sctp_nets *net,
int in_window, int num_pkt_lost)
{
- /* Passing a zero argument in last disables the rtcc algorithm */
+ /* Passing a zero argument in last disables the rtcc algoritm */
sctp_cwnd_update_after_ecn_echo_common(stcb, net, in_window, num_pkt_lost, 0);
}
/* Here starts the RTCCVAR type CC invented by RRS which
* is a slight mod to RFC2581. We reuse a common routine or
- * two since these algorithms are so close and need to
+ * two since these algoritms are so close and need to
* remain the same.
*/
static void
sctp_cwnd_update_rtcc_after_ecn_echo(struct sctp_tcb *stcb, struct sctp_nets *net,
int in_window, int num_pkt_lost)
{
sctp_cwnd_update_after_ecn_echo_common(stcb, net, in_window, num_pkt_lost, 1);
}
@@ -1440,17 +1437,17 @@ sctp_cwnd_new_rtcc_transmission_begins(s
if (net->cc_mod.rtcc.lbw) {
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
/* Clear the old bw.. we went to 0 in-flight */
vtag = (net->rtt << 32) | (((uint32_t)(stcb->sctp_ep->sctp_lport)) << 16) |
(stcb->rport);
probepoint = (((uint64_t)net->cwnd) << 32);
/* Probe point 8 */
probepoint |= ((8 << 16) | 0);
- SDT_PROBE5(sctp, cwnd, net, rttvar,
+ SDT_PROBE(sctp, cwnd, net, rttvar,
vtag,
((net->cc_mod.rtcc.lbw << 32) | 0),
((net->cc_mod.rtcc.lbw_rtt << 32) | net->rtt),
net->flight_size,
probepoint);
#endif
net->cc_mod.rtcc.lbw_rtt = 0;
net->cc_mod.rtcc.cwnd_at_bw_set = 0;
@@ -1501,17 +1498,17 @@ sctp_set_rtcc_initial_cc_param(struct sc
sctp_set_initial_cc_param(stcb, net);
stcb->asoc.use_precise_time = 1;
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
probepoint = (((uint64_t)net->cwnd) << 32);
probepoint |= ((9 << 16) | 0);
vtag = (net->rtt << 32) |
(((uint32_t)(stcb->sctp_ep->sctp_lport)) << 16) |
(stcb->rport);
- SDT_PROBE5(sctp, cwnd, net, rttvar,
+ SDT_PROBE(sctp, cwnd, net, rttvar,
vtag,
0,
0,
0,
probepoint);
#endif
net->cc_mod.rtcc.lbw_rtt = 0;
net->cc_mod.rtcc.cwnd_at_bw_set = 0;
@@ -1598,39 +1595,39 @@ sctp_cwnd_update_rtcc_packet_transmitted
}
}
static void
sctp_cwnd_update_rtcc_after_sack(struct sctp_tcb *stcb,
struct sctp_association *asoc,
int accum_moved, int reneged_all, int will_exit)
{
- /* Passing a one argument at the last enables the rtcc algorithm */
+ /* Passing a one argument at the last enables the rtcc algoritm */
sctp_cwnd_update_after_sack_common(stcb, asoc, accum_moved, reneged_all, will_exit, 1);
}
static void
sctp_rtt_rtcc_calculated(struct sctp_tcb *stcb SCTP_UNUSED,
struct sctp_nets *net,
struct timeval *now SCTP_UNUSED)
{
net->cc_mod.rtcc.rtt_set_this_sack = 1;
}
/* Here starts Sally Floyds HS-TCP */
struct sctp_hs_raise_drop {
int32_t cwnd;
- int8_t increase;
- int8_t drop_percent;
+ int32_t increase;
+ int32_t drop_percent;
};
#define SCTP_HS_TABLE_SIZE 73
-static const struct sctp_hs_raise_drop sctp_cwnd_adjust[SCTP_HS_TABLE_SIZE] = {
+struct sctp_hs_raise_drop sctp_cwnd_adjust[SCTP_HS_TABLE_SIZE] = {
{38, 1, 50}, /* 0 */
{118, 2, 44}, /* 1 */
{221, 3, 41}, /* 2 */
{347, 4, 38}, /* 3 */
{495, 5, 37}, /* 4 */
{663, 6, 35}, /* 5 */
{851, 7, 34}, /* 6 */
{1058, 8, 33}, /* 7 */
@@ -1720,17 +1717,17 @@ sctp_hs_cwnd_increase(struct sctp_tcb *s
} else {
for (i = net->last_hs_used; i < SCTP_HS_TABLE_SIZE; i++) {
if (cur_val < sctp_cwnd_adjust[i].cwnd) {
indx = i;
break;
}
}
net->last_hs_used = indx;
- incr = (((int32_t)sctp_cwnd_adjust[indx].increase) << 10);
+ incr = ((sctp_cwnd_adjust[indx].increase) << 10);
net->cwnd += incr;
}
sctp_enforce_cwnd_limit(&stcb->asoc, net);
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_SS);
}
}
@@ -1746,17 +1743,17 @@ sctp_hs_cwnd_decrease(struct sctp_tcb *s
net->ssthresh = net->cwnd / 2;
if (net->ssthresh < (net->mtu * 2)) {
net->ssthresh = 2 * net->mtu;
}
net->cwnd = net->ssthresh;
} else {
/* drop by the proper amount */
net->ssthresh = net->cwnd - (int)((net->cwnd / 100) *
- (int32_t)sctp_cwnd_adjust[net->last_hs_used].drop_percent);
+ sctp_cwnd_adjust[net->last_hs_used].drop_percent);
net->cwnd = net->ssthresh;
/* now where are we */
indx = net->last_hs_used;
cur_val = net->cwnd >> 10;
/* reset where we are in the table */
if (cur_val < sctp_cwnd_adjust[0].cwnd) {
/* feel out of hs */
net->last_hs_used = 0;
@@ -1803,35 +1800,34 @@ sctp_hs_cwnd_update_after_fr(struct sctp
net->partial_bytes_acked = 0;
/* Turn on fast recovery window */
asoc->fast_retran_loss_recovery = 1;
if (lchk == NULL) {
/* Mark end of the window */
asoc->fast_recovery_tsn = asoc->sending_seq - 1;
} else {
- asoc->fast_recovery_tsn = lchk->rec.data.tsn - 1;
+ asoc->fast_recovery_tsn = lchk->rec.data.TSN_seq - 1;
}
/*
* CMT fast recovery -- per destination
* recovery variable.
*/
net->fast_retran_loss_recovery = 1;
if (lchk == NULL) {
/* Mark end of the window */
net->fast_recovery_tsn = asoc->sending_seq - 1;
} else {
- net->fast_recovery_tsn = lchk->rec.data.tsn - 1;
+ net->fast_recovery_tsn = lchk->rec.data.TSN_seq - 1;
}
sctp_timer_stop(SCTP_TIMER_TYPE_SEND,
- stcb->sctp_ep, stcb, net,
- SCTP_FROM_SCTP_CC_FUNCTIONS + SCTP_LOC_2);
+ stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_INDATA+SCTP_LOC_32);
sctp_timer_start(SCTP_TIMER_TYPE_SEND,
stcb->sctp_ep, stcb, net);
}
} else if (net->net_ack > 0) {
/*
* Mark a peg that we WOULD have done a cwnd
* reduction but RFC2582 prevented this action.
*/
@@ -2330,35 +2326,34 @@ sctp_htcp_cwnd_update_after_fr(struct sc
net->partial_bytes_acked = 0;
/* Turn on fast recovery window */
asoc->fast_retran_loss_recovery = 1;
if (lchk == NULL) {
/* Mark end of the window */
asoc->fast_recovery_tsn = asoc->sending_seq - 1;
} else {
- asoc->fast_recovery_tsn = lchk->rec.data.tsn - 1;
+ asoc->fast_recovery_tsn = lchk->rec.data.TSN_seq - 1;
}
/*
* CMT fast recovery -- per destination
* recovery variable.
*/
net->fast_retran_loss_recovery = 1;
if (lchk == NULL) {
/* Mark end of the window */
net->fast_recovery_tsn = asoc->sending_seq - 1;
} else {
- net->fast_recovery_tsn = lchk->rec.data.tsn - 1;
+ net->fast_recovery_tsn = lchk->rec.data.TSN_seq - 1;
}
sctp_timer_stop(SCTP_TIMER_TYPE_SEND,
- stcb->sctp_ep, stcb, net,
- SCTP_FROM_SCTP_CC_FUNCTIONS + SCTP_LOC_3);
+ stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_INDATA+SCTP_LOC_32);
sctp_timer_start(SCTP_TIMER_TYPE_SEND,
stcb->sctp_ep, stcb, net);
}
} else if (net->net_ack > 0) {
/*
* Mark a peg that we WOULD have done a cwnd
* reduction but RFC2582 prevented this action.
*/
@@ -2403,17 +2398,17 @@ sctp_htcp_cwnd_update_after_ecn_echo(str
net->cwnd = net->ssthresh;
sctp_enforce_cwnd_limit(&stcb->asoc, net);
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_MONITOR_ENABLE) {
sctp_log_cwnd(stcb, net, (net->cwnd - old_cwnd), SCTP_CWND_LOG_FROM_SAT);
}
}
}
-const struct sctp_cc_functions sctp_cc_functions[] = {
+struct sctp_cc_functions sctp_cc_functions[] = {
{
#if defined(__Windows__) || defined(__Userspace_os_Windows)
sctp_set_initial_cc_param,
sctp_cwnd_update_after_sack,
sctp_cwnd_update_exit_pf_common,
sctp_cwnd_update_after_fr,
sctp_cwnd_update_after_timeout,
sctp_cwnd_update_after_ecn_echo,
--- a/netwerk/sctp/src/netinet/sctp_crc32.c
+++ b/netwerk/sctp/src/netinet/sctp_crc32.c
@@ -1,11 +1,9 @@
/*-
- * SPDX-License-Identifier: BSD-3-Clause
- *
* Copyright (c) 2001-2007, by Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2008-2012, by Randall Stewart. All rights reserved.
* Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* a) Redistributions of source code must retain the above copyright notice,
@@ -29,17 +27,17 @@
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/netinet/sctp_crc32.c 310590 2016-12-26 11:06:41Z tuexen $");
+__FBSDID("$FreeBSD: head/sys/netinet/sctp_crc32.c 235828 2012-05-23 11:26:28Z tuexen $");
#endif
#include <netinet/sctp_os.h>
#include <netinet/sctp.h>
#include <netinet/sctp_crc32.h>
#include <netinet/sctp_pcb.h>
@@ -91,17 +89,17 @@
* Reflected Bits = ....................... TRUE
* Table Generation Offset = .............. 32 bits
* Number of Slices = ..................... 8 slices
* Slice Lengths = ........................ 8 8 8 8 8 8 8 8
* Directory Name = ....................... .\
* File Name = ............................ 8x256_tables.c
*/
-static const uint32_t sctp_crc_tableil8_o32[256] =
+static uint32_t sctp_crc_tableil8_o32[256] =
{
0x00000000, 0xF26B8303, 0xE13B70F7, 0x1350F3F4, 0xC79A971F, 0x35F1141C, 0x26A1E7E8, 0xD4CA64EB,
0x8AD958CF, 0x78B2DBCC, 0x6BE22838, 0x9989AB3B, 0x4D43CFD0, 0xBF284CD3, 0xAC78BF27, 0x5E133C24,
0x105EC76F, 0xE235446C, 0xF165B798, 0x030E349B, 0xD7C45070, 0x25AFD373, 0x36FF2087, 0xC494A384,
0x9A879FA0, 0x68EC1CA3, 0x7BBCEF57, 0x89D76C54, 0x5D1D08BF, 0xAF768BBC, 0xBC267848, 0x4E4DFB4B,
0x20BD8EDE, 0xD2D60DDD, 0xC186FE29, 0x33ED7D2A, 0xE72719C1, 0x154C9AC2, 0x061C6936, 0xF477EA35,
0xAA64D611, 0x580F5512, 0x4B5FA6E6, 0xB93425E5, 0x6DFE410E, 0x9F95C20D, 0x8CC531F9, 0x7EAEB2FA,
0x30E349B1, 0xC288CAB2, 0xD1D83946, 0x23B3BA45, 0xF779DEAE, 0x05125DAD, 0x1642AE59, 0xE4292D5A,
@@ -147,17 +145,17 @@ static const uint32_t sctp_crc_tableil8_
* Reflected Bits = ....................... TRUE
* Table Generation Offset = .............. 32 bits
* Number of Slices = ..................... 8 slices
* Slice Lengths = ........................ 8 8 8 8 8 8 8 8
* Directory Name = ....................... .\
* File Name = ............................ 8x256_tables.c
*/
-static const uint32_t sctp_crc_tableil8_o40[256] =
+static uint32_t sctp_crc_tableil8_o40[256] =
{
0x00000000, 0x13A29877, 0x274530EE, 0x34E7A899, 0x4E8A61DC, 0x5D28F9AB, 0x69CF5132, 0x7A6DC945,
0x9D14C3B8, 0x8EB65BCF, 0xBA51F356, 0xA9F36B21, 0xD39EA264, 0xC03C3A13, 0xF4DB928A, 0xE7790AFD,
0x3FC5F181, 0x2C6769F6, 0x1880C16F, 0x0B225918, 0x714F905D, 0x62ED082A, 0x560AA0B3, 0x45A838C4,
0xA2D13239, 0xB173AA4E, 0x859402D7, 0x96369AA0, 0xEC5B53E5, 0xFFF9CB92, 0xCB1E630B, 0xD8BCFB7C,
0x7F8BE302, 0x6C297B75, 0x58CED3EC, 0x4B6C4B9B, 0x310182DE, 0x22A31AA9, 0x1644B230, 0x05E62A47,
0xE29F20BA, 0xF13DB8CD, 0xC5DA1054, 0xD6788823, 0xAC154166, 0xBFB7D911, 0x8B507188, 0x98F2E9FF,
0x404E1283, 0x53EC8AF4, 0x670B226D, 0x74A9BA1A, 0x0EC4735F, 0x1D66EB28, 0x298143B1, 0x3A23DBC6,
@@ -203,17 +201,17 @@ static const uint32_t sctp_crc_tableil8_
* Reflected Bits = ....................... TRUE
* Table Generation Offset = .............. 32 bits
* Number of Slices = ..................... 8 slices
* Slice Lengths = ........................ 8 8 8 8 8 8 8 8
* Directory Name = ....................... .\
* File Name = ............................ 8x256_tables.c
*/
-static const uint32_t sctp_crc_tableil8_o48[256] =
+static uint32_t sctp_crc_tableil8_o48[256] =
{
0x00000000, 0xA541927E, 0x4F6F520D, 0xEA2EC073, 0x9EDEA41A, 0x3B9F3664, 0xD1B1F617, 0x74F06469,
0x38513EC5, 0x9D10ACBB, 0x773E6CC8, 0xD27FFEB6, 0xA68F9ADF, 0x03CE08A1, 0xE9E0C8D2, 0x4CA15AAC,
0x70A27D8A, 0xD5E3EFF4, 0x3FCD2F87, 0x9A8CBDF9, 0xEE7CD990, 0x4B3D4BEE, 0xA1138B9D, 0x045219E3,
0x48F3434F, 0xEDB2D131, 0x079C1142, 0xA2DD833C, 0xD62DE755, 0x736C752B, 0x9942B558, 0x3C032726,
0xE144FB14, 0x4405696A, 0xAE2BA919, 0x0B6A3B67, 0x7F9A5F0E, 0xDADBCD70, 0x30F50D03, 0x95B49F7D,
0xD915C5D1, 0x7C5457AF, 0x967A97DC, 0x333B05A2, 0x47CB61CB, 0xE28AF3B5, 0x08A433C6, 0xADE5A1B8,
0x91E6869E, 0x34A714E0, 0xDE89D493, 0x7BC846ED, 0x0F382284, 0xAA79B0FA, 0x40577089, 0xE516E2F7,
@@ -259,17 +257,17 @@ static const uint32_t sctp_crc_tableil8_
* Reflected Bits = ....................... TRUE
* Table Generation Offset = .............. 32 bits
* Number of Slices = ..................... 8 slices
* Slice Lengths = ........................ 8 8 8 8 8 8 8 8
* Directory Name = ....................... .\
* File Name = ............................ 8x256_tables.c
*/
-static const uint32_t sctp_crc_tableil8_o56[256] =
+static uint32_t sctp_crc_tableil8_o56[256] =
{
0x00000000, 0xDD45AAB8, 0xBF672381, 0x62228939, 0x7B2231F3, 0xA6679B4B, 0xC4451272, 0x1900B8CA,
0xF64463E6, 0x2B01C95E, 0x49234067, 0x9466EADF, 0x8D665215, 0x5023F8AD, 0x32017194, 0xEF44DB2C,
0xE964B13D, 0x34211B85, 0x560392BC, 0x8B463804, 0x924680CE, 0x4F032A76, 0x2D21A34F, 0xF06409F7,
0x1F20D2DB, 0xC2657863, 0xA047F15A, 0x7D025BE2, 0x6402E328, 0xB9474990, 0xDB65C0A9, 0x06206A11,
0xD725148B, 0x0A60BE33, 0x6842370A, 0xB5079DB2, 0xAC072578, 0x71428FC0, 0x136006F9, 0xCE25AC41,
0x2161776D, 0xFC24DDD5, 0x9E0654EC, 0x4343FE54, 0x5A43469E, 0x8706EC26, 0xE524651F, 0x3861CFA7,
0x3E41A5B6, 0xE3040F0E, 0x81268637, 0x5C632C8F, 0x45639445, 0x98263EFD, 0xFA04B7C4, 0x27411D7C,
@@ -315,17 +313,17 @@ static const uint32_t sctp_crc_tableil8_
* Reflected Bits = ....................... TRUE
* Table Generation Offset = .............. 32 bits
* Number of Slices = ..................... 8 slices
* Slice Lengths = ........................ 8 8 8 8 8 8 8 8
* Directory Name = ....................... .\
* File Name = ............................ 8x256_tables.c
*/
-static const uint32_t sctp_crc_tableil8_o64[256] =
+static uint32_t sctp_crc_tableil8_o64[256] =
{
0x00000000, 0x38116FAC, 0x7022DF58, 0x4833B0F4, 0xE045BEB0, 0xD854D11C, 0x906761E8, 0xA8760E44,
0xC5670B91, 0xFD76643D, 0xB545D4C9, 0x8D54BB65, 0x2522B521, 0x1D33DA8D, 0x55006A79, 0x6D1105D5,
0x8F2261D3, 0xB7330E7F, 0xFF00BE8B, 0xC711D127, 0x6F67DF63, 0x5776B0CF, 0x1F45003B, 0x27546F97,
0x4A456A42, 0x725405EE, 0x3A67B51A, 0x0276DAB6, 0xAA00D4F2, 0x9211BB5E, 0xDA220BAA, 0xE2336406,
0x1BA8B557, 0x23B9DAFB, 0x6B8A6A0F, 0x539B05A3, 0xFBED0BE7, 0xC3FC644B, 0x8BCFD4BF, 0xB3DEBB13,
0xDECFBEC6, 0xE6DED16A, 0xAEED619E, 0x96FC0E32, 0x3E8A0076, 0x069B6FDA, 0x4EA8DF2E, 0x76B9B082,
0x948AD484, 0xAC9BBB28, 0xE4A80BDC, 0xDCB96470, 0x74CF6A34, 0x4CDE0598, 0x04EDB56C, 0x3CFCDAC0,
@@ -371,17 +369,17 @@ static const uint32_t sctp_crc_tableil8_
* Reflected Bits = ....................... TRUE
* Table Generation Offset = .............. 32 bits
* Number of Slices = ..................... 8 slices
* Slice Lengths = ........................ 8 8 8 8 8 8 8 8
* Directory Name = ....................... .\
* File Name = ............................ 8x256_tables.c
*/
-static const uint32_t sctp_crc_tableil8_o72[256] =
+uint32_t sctp_crc_tableil8_o72[256] =
{
0x00000000, 0xEF306B19, 0xDB8CA0C3, 0x34BCCBDA, 0xB2F53777, 0x5DC55C6E, 0x697997B4, 0x8649FCAD,
0x6006181F, 0x8F367306, 0xBB8AB8DC, 0x54BAD3C5, 0xD2F32F68, 0x3DC34471, 0x097F8FAB, 0xE64FE4B2,
0xC00C303E, 0x2F3C5B27, 0x1B8090FD, 0xF4B0FBE4, 0x72F90749, 0x9DC96C50, 0xA975A78A, 0x4645CC93,
0xA00A2821, 0x4F3A4338, 0x7B8688E2, 0x94B6E3FB, 0x12FF1F56, 0xFDCF744F, 0xC973BF95, 0x2643D48C,
0x85F4168D, 0x6AC47D94, 0x5E78B64E, 0xB148DD57, 0x370121FA, 0xD8314AE3, 0xEC8D8139, 0x03BDEA20,
0xE5F20E92, 0x0AC2658B, 0x3E7EAE51, 0xD14EC548, 0x570739E5, 0xB83752FC, 0x8C8B9926, 0x63BBF23F,
0x45F826B3, 0xAAC84DAA, 0x9E748670, 0x7144ED69, 0xF70D11C4, 0x183D7ADD, 0x2C81B107, 0xC3B1DA1E,
@@ -427,17 +425,17 @@ static const uint32_t sctp_crc_tableil8_
* Reflected Bits = ....................... TRUE
* Table Generation Offset = .............. 32 bits
* Number of Slices = ..................... 8 slices
* Slice Lengths = ........................ 8 8 8 8 8 8 8 8
* Directory Name = ....................... .\
* File Name = ............................ 8x256_tables.c
*/
-static const uint32_t sctp_crc_tableil8_o80[256] =
+static uint32_t sctp_crc_tableil8_o80[256] =
{
0x00000000, 0x68032CC8, 0xD0065990, 0xB8057558, 0xA5E0C5D1, 0xCDE3E919, 0x75E69C41, 0x1DE5B089,
0x4E2DFD53, 0x262ED19B, 0x9E2BA4C3, 0xF628880B, 0xEBCD3882, 0x83CE144A, 0x3BCB6112, 0x53C84DDA,
0x9C5BFAA6, 0xF458D66E, 0x4C5DA336, 0x245E8FFE, 0x39BB3F77, 0x51B813BF, 0xE9BD66E7, 0x81BE4A2F,
0xD27607F5, 0xBA752B3D, 0x02705E65, 0x6A7372AD, 0x7796C224, 0x1F95EEEC, 0xA7909BB4, 0xCF93B77C,
0x3D5B83BD, 0x5558AF75, 0xED5DDA2D, 0x855EF6E5, 0x98BB466C, 0xF0B86AA4, 0x48BD1FFC, 0x20BE3334,
0x73767EEE, 0x1B755226, 0xA370277E, 0xCB730BB6, 0xD696BB3F, 0xBE9597F7, 0x0690E2AF, 0x6E93CE67,
0xA100791B, 0xC90355D3, 0x7106208B, 0x19050C43, 0x04E0BCCA, 0x6CE39002, 0xD4E6E55A, 0xBCE5C992,
@@ -483,17 +481,17 @@ static const uint32_t sctp_crc_tableil8_
* Reflected Bits = ....................... TRUE
* Table Generation Offset = .............. 32 bits
* Number of Slices = ..................... 8 slices
* Slice Lengths = ........................ 8 8 8 8 8 8 8 8
* Directory Name = ....................... .\
* File Name = ............................ 8x256_tables.c
*/
-static const uint32_t sctp_crc_tableil8_o88[256] =
+static uint32_t sctp_crc_tableil8_o88[256] =
{
0x00000000, 0x493C7D27, 0x9278FA4E, 0xDB448769, 0x211D826D, 0x6821FF4A, 0xB3657823, 0xFA590504,
0x423B04DA, 0x0B0779FD, 0xD043FE94, 0x997F83B3, 0x632686B7, 0x2A1AFB90, 0xF15E7CF9, 0xB86201DE,
0x847609B4, 0xCD4A7493, 0x160EF3FA, 0x5F328EDD, 0xA56B8BD9, 0xEC57F6FE, 0x37137197, 0x7E2F0CB0,
0xC64D0D6E, 0x8F717049, 0x5435F720, 0x1D098A07, 0xE7508F03, 0xAE6CF224, 0x7528754D, 0x3C14086A,
0x0D006599, 0x443C18BE, 0x9F789FD7, 0xD644E2F0, 0x2C1DE7F4, 0x65219AD3, 0xBE651DBA, 0xF759609D,
0x4F3B6143, 0x06071C64, 0xDD439B0D, 0x947FE62A, 0x6E26E32E, 0x271A9E09, 0xFC5E1960, 0xB5626447,
0x89766C2D, 0xC04A110A, 0x1B0E9663, 0x5232EB44, 0xA86BEE40, 0xE1579367, 0x3A13140E, 0x732F6929,
@@ -610,17 +608,17 @@ multitable_crc32c(uint32_t crc32c,
if (length == 0) {
return (crc32c);
}
to_even_word = (4 - (((uintptr_t) buffer) & 0x3));
return (sctp_crc32c_sb8_64_bit(crc32c, buffer, length, to_even_word));
}
-static const uint32_t sctp_crc_c[256] = {
+static uint32_t sctp_crc_c[256] = {
0x00000000, 0xF26B8303, 0xE13B70F7, 0x1350F3F4,
0xC79A971F, 0x35F1141C, 0x26A1E7E8, 0xD4CA64EB,
0x8AD958CF, 0x78B2DBCC, 0x6BE22838, 0x9989AB3B,
0x4D43CFD0, 0xBF284CD3, 0xAC78BF27, 0x5E133C24,
0x105EC76F, 0xE235446C, 0xF165B798, 0x030E349B,
0xD7C45070, 0x25AFD373, 0x36FF2087, 0xC494A384,
0x9A879FA0, 0x68EC1CA3, 0x7BBCEF57, 0x89D76C54,
0x5D1D08BF, 0xAF768BBC, 0xBC267848, 0x4E4DFB4B,
@@ -693,38 +691,31 @@ singletable_crc32c(uint32_t crc32c,
unsigned int i;
for (i = 0; i < length; i++) {
SCTP_CRC32C(crc32c, buffer[i]);
}
return (crc32c);
}
-#if defined(__Userspace__)
-uint32_t
-#else
+
static uint32_t
-#endif
calculate_crc32c(uint32_t crc32c,
const unsigned char *buffer,
unsigned int length)
{
if (length < 4) {
return (singletable_crc32c(crc32c, buffer, length));
} else {
return (multitable_crc32c(crc32c, buffer, length));
}
}
#endif /* FreeBSD < 80000 || other OS */
-#if defined(__Userspace__)
-uint32_t
-#else
static uint32_t
-#endif
sctp_finalize_crc32c(uint32_t crc32c)
{
uint32_t result;
#if BYTE_ORDER == BIG_ENDIAN
uint8_t byte0, byte1, byte2, byte3;
#endif
--- a/netwerk/sctp/src/netinet/sctp_indata.c
+++ b/netwerk/sctp/src/netinet/sctp_indata.c
@@ -1,11 +1,9 @@
/*-
- * SPDX-License-Identifier: BSD-3-Clause
- *
* Copyright (c) 2001-2007, by Cisco Systems, Inc. All rights reserved.
* Copyright (c) 2008-2012, by Randall Stewart. All rights reserved.
* Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* a) Redistributions of source code must retain the above copyright notice,
@@ -29,56 +27,41 @@
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: head/sys/netinet/sctp_indata.c 325434 2017-11-05 11:59:33Z tuexen $");
+__FBSDID("$FreeBSD: head/sys/netinet/sctp_indata.c 280440 2015-03-24 15:05:36Z tuexen $");
#endif
#include <netinet/sctp_os.h>
-#ifdef __FreeBSD__
-#include <sys/proc.h>
-#endif
#include <netinet/sctp_var.h>
#include <netinet/sctp_sysctl.h>
+#include <netinet/sctp_pcb.h>
#include <netinet/sctp_header.h>
-#include <netinet/sctp_pcb.h>
#include <netinet/sctputil.h>
#include <netinet/sctp_output.h>
-#include <netinet/sctp_uio.h>
-#include <netinet/sctp_auth.h>
-#include <netinet/sctp_timer.h>
-#include <netinet/sctp_asconf.h>
+#include <netinet/sctp_input.h>
#include <netinet/sctp_indata.h>
-#include <netinet/sctp_bsd_addr.h>
-#include <netinet/sctp_input.h>
-#include <netinet/sctp_crc32.h>
-#ifdef __FreeBSD__
-#include <netinet/sctp_lock_bsd.h>
-#endif
+#include <netinet/sctp_uio.h>
+#include <netinet/sctp_timer.h>
+
+
/*
* NOTES: On the outbound side of things I need to check the sack timer to
* see if I should generate a sack into the chunk queue (if I have data to
* send that is and will be sending it .. for bundling.
*
* The callback in sctp_usrreq.c will get called when the socket is read from.
* This will cause sctp_service_queues() to get called on the top entry in
* the list.
*/
-static uint32_t
-sctp_add_chk_to_control(struct sctp_queued_to_read *control,
- struct sctp_stream_in *strm,
- struct sctp_tcb *stcb,
- struct sctp_association *asoc,
- struct sctp_tmit_chunk *chk, int lock_held);
-
void
sctp_set_rwnd(struct sctp_tcb *stcb, struct sctp_association *asoc)
{
asoc->my_rwnd = sctp_calc_rwnd(stcb, asoc);
}
/* Calculate what the rwnd would be */
@@ -88,41 +71,38 @@ sctp_calc_rwnd(struct sctp_tcb *stcb, st
uint32_t calc = 0;
/*
* This is really set wrong with respect to a 1-2-m socket. Since
* the sb_cc is the count that everyone as put up. When we re-write
* sctp_soreceive then we will fix this so that ONLY this
* associations data is taken into account.
*/
- if (stcb->sctp_socket == NULL) {
+ if (stcb->sctp_socket == NULL)
return (calc);
- }
-
- KASSERT(asoc->cnt_on_reasm_queue > 0 || asoc->size_on_reasm_queue == 0,
- ("size_on_reasm_queue is %u", asoc->size_on_reasm_queue));
- KASSERT(asoc->cnt_on_all_streams > 0 || asoc->size_on_all_streams == 0,
- ("size_on_all_streams is %u", asoc->size_on_all_streams));
+
if (stcb->asoc.sb_cc == 0 &&
- asoc->cnt_on_reasm_queue == 0 &&
- asoc->cnt_on_all_streams == 0) {
+ asoc->size_on_reasm_queue == 0 &&
+ asoc->size_on_all_streams == 0) {
/* Full rwnd granted */
calc = max(SCTP_SB_LIMIT_RCV(stcb->sctp_socket), SCTP_MINIMAL_RWND);
return (calc);
}
/* get actual space */
calc = (uint32_t) sctp_sbspace(&stcb->asoc, &stcb->sctp_socket->so_rcv);
+
/*
* take out what has NOT been put on socket queue and we yet hold
* for putting up.
*/
calc = sctp_sbspace_sub(calc, (uint32_t)(asoc->size_on_reasm_queue +
asoc->cnt_on_reasm_queue * MSIZE));
calc = sctp_sbspace_sub(calc, (uint32_t)(asoc->size_on_all_streams +
asoc->cnt_on_all_streams * MSIZE));
+
if (calc == 0) {
/* out of space */
return (calc);
}
/* what is the overhead of all these rwnd's */
calc = sctp_sbspace_sub(calc, stcb->asoc.my_rwnd_control_len);
/* If the window gets too small due to ctrl-stuff, reduce it
@@ -138,46 +118,93 @@ sctp_calc_rwnd(struct sctp_tcb *stcb, st
/*
* Build out our readq entry based on the incoming packet.
*/
struct sctp_queued_to_read *
sctp_build_readq_entry(struct sctp_tcb *stcb,
struct sctp_nets *net,
uint32_t tsn, uint32_t ppid,
- uint32_t context, uint16_t sid,
- uint32_t mid, uint8_t flags,
+ uint32_t context, uint16_t stream_no,
+ uint16_t stream_seq, uint8_t flags,
struct mbuf *dm)
{
struct sctp_queued_to_read *read_queue_e = NULL;
sctp_alloc_a_readq(stcb, read_queue_e);
if (read_queue_e == NULL) {
goto failed_build;
}
- memset(read_queue_e, 0, sizeof(struct sctp_queued_to_read));
- read_queue_e->sinfo_stream = sid;
+ read_queue_e->sinfo_stream = stream_no;
+ read_queue_e->sinfo_ssn = stream_seq;
read_queue_e->sinfo_flags = (flags << 8);
read_queue_e->sinfo_ppid = ppid;
read_queue_e->sinfo_context = context;
+ read_queue_e->sinfo_timetolive = 0;
read_queue_e->sinfo_tsn = tsn;
read_queue_e->sinfo_cumtsn = tsn;
read_queue_e->sinfo_assoc_id = sctp_get_associd(stcb);
- read_queue_e->mid = mid;
- read_queue_e->top_fsn = read_queue_e->fsn_included = 0xffffffff;
- TAILQ_INIT(&read_queue_e->reasm);
read_queue_e->whoFrom = net;
+ read_queue_e->length = 0;
atomic_add_int(&net->ref_count, 1);
read_queue_e->data = dm;
+ read_queue_e->spec_flags = 0;
+ read_queue_e->tail_mbuf = NULL;
+ read_queue_e->aux_data = NULL;
read_queue_e->stcb = stcb;
read_queue_e->port_from = stcb->rport;
+ read_queue_e->do_not_ref_stcb = 0;
+ read_queue_e->end_added = 0;
+ read_queue_e->some_taken = 0;
+ read_queue_e->pdapi_aborted = 0;
failed_build:
return (read_queue_e);
}
+
+/*
+ * Build out our readq entry based on the incoming packet.
+ */
+static struct sctp_queued_to_read *
+sctp_build_readq_entry_chk(struct sctp_tcb *stcb,
+ struct sctp_tmit_chunk *chk)
+{
+ struct sctp_queued_to_read *read_queue_e = NULL;
+
+ sctp_alloc_a_readq(stcb, read_queue_e);
+ if (read_queue_e == NULL) {
+ goto failed_build;
+ }
+ read_queue_e->sinfo_stream = chk->rec.data.stream_number;
+ read_queue_e->sinfo_ssn = chk->rec.data.stream_seq;
+ read_queue_e->sinfo_flags = (chk->rec.data.rcv_flags << 8);
+ read_queue_e->sinfo_ppid = chk->rec.data.payloadtype;
+ read_queue_e->sinfo_context = stcb->asoc.context;
+ read_queue_e->sinfo_timetolive = 0;
+ read_queue_e->sinfo_tsn = chk->rec.data.TSN_seq;
+ read_queue_e->sinfo_cumtsn = chk->rec.data.TSN_seq;
+ read_queue_e->sinfo_assoc_id = sctp_get_associd(stcb);
+ read_queue_e->whoFrom = chk->whoTo;
+ read_queue_e->aux_data = NULL;
+ read_queue_e->length = 0;
+ atomic_add_int(&chk->whoTo->ref_count, 1);
+ read_queue_e->data = chk->data;
+ read_queue_e->tail_mbuf = NULL;
+ read_queue_e->stcb = stcb;
+ read_queue_e->port_from = stcb->rport;
+ read_queue_e->spec_flags = 0;
+ read_queue_e->do_not_ref_stcb = 0;
+ read_queue_e->end_added = 0;
+ read_queue_e->some_taken = 0;
+ read_queue_e->pdapi_aborted = 0;
+failed_build:
+ return (read_queue_e);
+}
+
+
struct mbuf *
sctp_build_ctl_nchunk(struct sctp_inpcb *inp, struct sctp_sndrcvinfo *sinfo)
{
struct sctp_extrcvinfo *seinfo;
struct sctp_sndrcvinfo *outinfo;
struct sctp_rcvinfo *rcvinfo;
struct sctp_nxtinfo *nxtinfo;
#if defined(__Userspace_os_Windows)
@@ -198,19 +225,19 @@ sctp_build_ctl_nchunk(struct sctp_inpcb
}
len = 0;
if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVRCVINFO)) {
len += CMSG_SPACE(sizeof(struct sctp_rcvinfo));
}
seinfo = (struct sctp_extrcvinfo *)sinfo;
if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO) &&
- (seinfo->serinfo_next_flags & SCTP_NEXT_MSG_AVAIL)) {
+ (seinfo->sreinfo_next_flags & SCTP_NEXT_MSG_AVAIL)) {
provide_nxt = 1;
- len += CMSG_SPACE(sizeof(struct sctp_nxtinfo));
+ len += CMSG_SPACE(sizeof(struct sctp_rcvinfo));
} else {
provide_nxt = 0;
}
if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT)) {
if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO)) {
use_extended = 1;
len += CMSG_SPACE(sizeof(struct sctp_extrcvinfo));
} else {
@@ -259,30 +286,30 @@ sctp_build_ctl_nchunk(struct sctp_inpcb
#endif
SCTP_BUF_LEN(ret) += CMSG_SPACE(sizeof(struct sctp_rcvinfo));
}
if (provide_nxt) {
cmh->cmsg_level = IPPROTO_SCTP;
cmh->cmsg_len = CMSG_LEN(sizeof(struct sctp_nxtinfo));
cmh->cmsg_type = SCTP_NXTINFO;
nxtinfo = (struct sctp_nxtinfo *)CMSG_DATA(cmh);
- nxtinfo->nxt_sid = seinfo->serinfo_next_stream;
+ nxtinfo->nxt_sid = seinfo->sreinfo_next_stream;
nxtinfo->nxt_flags = 0;
- if (seinfo->serinfo_next_flags & SCTP_NEXT_MSG_IS_UNORDERED) {
+ if (seinfo->sreinfo_next_flags & SCTP_NEXT_MSG_IS_UNORDERED) {
nxtinfo->nxt_flags |= SCTP_UNORDERED;
}
- if (seinfo->serinfo_next_flags & SCTP_NEXT_MSG_IS_NOTIFICATION) {
+ if (seinfo->sreinfo_next_flags & SCTP_NEXT_MSG_IS_NOTIFICATION) {
nxtinfo->nxt_flags |= SCTP_NOTIFICATION;
}
- if (seinfo->serinfo_next_flags & SCTP_NEXT_MSG_ISCOMPLETE) {
+ if (seinfo->sreinfo_next_flags & SCTP_NEXT_MSG_ISCOMPLETE) {
nxtinfo->nxt_flags |= SCTP_COMPLETE;
}
- nxtinfo->nxt_ppid = seinfo->serinfo_next_ppid;
- nxtinfo->nxt_length = seinfo->serinfo_next_length;
- nxtinfo->nxt_assoc_id = seinfo->serinfo_next_aid;
+ nxtinfo->nxt_ppid = seinfo->sreinfo_next_ppid;
+ nxtinfo->nxt_length = seinfo->sreinfo_next_length;
+ nxtinfo->nxt_assoc_id = seinfo->sreinfo_next_aid;
#if defined(__Userspace_os_Windows)
cmh = (WSACMSGHDR *)((caddr_t)cmh + CMSG_SPACE(sizeof(struct sctp_nxtinfo)));
#else
cmh = (struct cmsghdr *)((caddr_t)cmh + CMSG_SPACE(sizeof(struct sctp_nxtinfo)));
#endif
SCTP_BUF_LEN(ret) += CMSG_SPACE(sizeof(struct sctp_nxtinfo));
}
if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT)) {
@@ -304,42 +331,37 @@ sctp_build_ctl_nchunk(struct sctp_inpcb
}
static void
sctp_mark_non_revokable(struct sctp_association *asoc, uint32_t tsn)
{
uint32_t gap, i, cumackp1;
int fnd = 0;
- int in_r=0, in_nr=0;
+
if (SCTP_BASE_SYSCTL(sctp_do_drain) == 0) {
return;
}
cumackp1 = asoc->cumulative_tsn + 1;
if (SCTP_TSN_GT(cumackp1, tsn)) {
/* this tsn is behind the cum ack and thus we don't
* need to worry about it being moved from one to the other.
*/
return;
}
SCTP_CALC_TSN_TO_GAP(gap, tsn, asoc->mapping_array_base_tsn);
- in_r = SCTP_IS_TSN_PRESENT(asoc->mapping_array, gap);
- in_nr = SCTP_IS_TSN_PRESENT(asoc->nr_mapping_array, gap);
- if ((in_r == 0) && (in_nr == 0)) {
-#ifdef INVARIANTS
- panic("Things are really messed up now");
-#else
+ if (!SCTP_IS_TSN_PRESENT(asoc->mapping_array, gap)) {
SCTP_PRINTF("gap:%x tsn:%x\n", gap, tsn);
sctp_print_mapping_array(asoc);
+#ifdef INVARIANTS
+ panic("Things are really messed up now!!");
#endif
}
- if (in_nr == 0)
- SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, gap);
- if (in_r)
- SCTP_UNSET_TSN_PRESENT(asoc->mapping_array, gap);
+ SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, gap);
+ SCTP_UNSET_TSN_PRESENT(asoc->mapping_array, gap);
if (SCTP_TSN_GT(tsn, asoc->highest_tsn_inside_nr_map)) {
asoc->highest_tsn_inside_nr_map = tsn;
}
if (tsn == asoc->highest_tsn_inside_map) {
/* We must back down to see what the new highest is */
for (i = tsn - 1; SCTP_TSN_GE(i, asoc->mapping_array_base_tsn); i--) {
SCTP_CALC_TSN_TO_GAP(gap, i, asoc->mapping_array_base_tsn);
if (SCTP_IS_TSN_PRESENT(asoc->mapping_array, gap)) {
@@ -349,1393 +371,949 @@ sctp_mark_non_revokable(struct sctp_asso
}
}
if (!fnd) {
asoc->highest_tsn_inside_map = asoc->mapping_array_base_tsn - 1;
}
}
}
-static int
-sctp_place_control_in_stream(struct sctp_stream_in *strm,
- struct sctp_association *asoc,
- struct sctp_queued_to_read *control)
+
+/*
+ * We are delivering currently from the reassembly queue. We must continue to
+ * deliver until we either: 1) run out of space. 2) run out of sequential
+ * TSN's 3) hit the SCTP_DATA_LAST_FRAG flag.
+ */
+static void
+sctp_service_reassembly(struct sctp_tcb *stcb, struct sctp_association *asoc)
{
- struct sctp_queued_to_read *at;
- struct sctp_readhead *q;
- uint8_t flags, unordered;
-
- flags = (control->sinfo_flags >> 8);
- unordered = flags & SCTP_DATA_UNORDERED;
- if (unordered) {
- q = &strm->uno_inqueue;
- if (asoc->idata_supported == 0) {
- if (!TAILQ_EMPTY(q)) {
- /* Only one stream can be here in old style -- abort */
- return (-1);
+ struct sctp_tmit_chunk *chk, *nchk;
+ uint16_t nxt_todel;
+ uint16_t stream_no;
+ int end = 0;
+ int cntDel;
+ struct sctp_queued_to_read *control, *ctl, *nctl;
+
+ if (stcb == NULL)
+ return;
+
+ cntDel = stream_no = 0;
+ if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) ||
+ (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) ||
+ (stcb->asoc.state & SCTP_STATE_CLOSED_SOCKET)) {
+ /* socket above is long gone or going.. */
+ abandon:
+ asoc->fragmented_delivery_inprogress = 0;
+ TAILQ_FOREACH_SAFE(chk, &asoc->reasmqueue, sctp_next, nchk) {
+ TAILQ_REMOVE(&asoc->reasmqueue, chk, sctp_next);
+ asoc->size_on_reasm_queue -= chk->send_size;
+ sctp_ucount_decr(asoc->cnt_on_reasm_queue);
+ /*
+ * Lose the data pointer, since its in the socket
+ * buffer
+ */
+ if (chk->data) {
+ sctp_m_freem(chk->data);
+ chk->data = NULL;
}
- TAILQ_INSERT_TAIL(q, control, next_instrm);
- control->on_strm_q = SCTP_ON_UNORDERED;
- return (0);
+ /* Now free the address and data */
+ sctp_free_a_chunk(stcb, chk, SCTP_SO_NOT_LOCKED);
+ /*sa_ignore FREED_MEMORY*/
}
- } else {
- q = &strm->inqueue;
+ return;
}
- if ((flags & SCTP_DATA_NOT_FRAG) == SCTP_DATA_NOT_FRAG) {
- control->end_added = 1;
- control->first_frag_seen = 1;
- control->last_frag_seen = 1;
- }
- if (TAILQ_EMPTY(q)) {
- /* Empty queue */
- TAILQ_INSERT_HEAD(q, control, next_instrm);
- if (unordered) {
- control->on_strm_q = SCTP_ON_UNORDERED;
- } else {
- control->on_strm_q = SCTP_ON_ORDERED;
+ SCTP_TCB_LOCK_ASSERT(stcb);
+ TAILQ_FOREACH_SAFE(chk, &asoc->reasmqueue, sctp_next, nchk) {
+ if (chk->rec.data.TSN_seq != (asoc->tsn_last_delivered + 1)) {
+ /* Can't deliver more :< */
+ return;
+ }
+ stream_no = chk->rec.data.stream_number;
+ nxt_todel = asoc->strmin[stream_no].last_sequence_delivered + 1;
+ if (nxt_todel != chk->rec.data.stream_seq &&
+ (chk->rec.data.rcv_flags & SCTP_DATA_UNORDERED) == 0) {
+ /*
+ * Not the next sequence to deliver in its stream OR
+ * unordered
+ */
+ return;
}
- return (0);
- } else {
- TAILQ_FOREACH(at, q, next_instrm) {
- if (SCTP_MID_GT(asoc->idata_supported, at->mid, control->mid)) {
- /*
- * one in queue is bigger than the
- * new one, insert before this one
- */
- TAILQ_INSERT_BEFORE(at, control, next_instrm);
- if (unordered) {
- control->on_strm_q = SCTP_ON_UNORDERED;
- } else {
- control->on_strm_q = SCTP_ON_ORDERED ;
- }
- break;
- } else if (SCTP_MID_EQ(asoc->idata_supported, at->mid, control->mid)) {
+ if (chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) {
+
+ control = sctp_build_readq_entry_chk(stcb, chk);
+ if (control == NULL) {
+ /* out of memory? */
+ return;
+ }
+ /* save it off for our future deliveries */
+ stcb->asoc.control_pdapi = control;
+ if (chk->rec.data.rcv_flags & SCTP_DATA_LAST_FRAG)
+ end = 1;
+ else
+ end = 0;
+ sctp_mark_non_revokable(asoc, chk->rec.data.TSN_seq);
+ sctp_add_to_readq(stcb->sctp_ep,
+ stcb, control, &stcb->sctp_socket->so_rcv, end,
+ SCTP_READ_LOCK_NOT_HELD, SCTP_SO_NOT_LOCKED);
+ cntDel++;
+ } else {
+ if (chk->rec.data.rcv_flags & SCTP_DATA_LAST_FRAG)
+ end = 1;
+ else
+ end = 0;
+ sctp_mark_non_revokable(asoc, chk->rec.data.TSN_seq);
+ if (sctp_append_to_readq(stcb->sctp_ep, stcb,
+ stcb->asoc.control_pdapi,
+ chk->data, end, chk->rec.data.TSN_seq,
+ &stcb->sctp_socket->so_rcv)) {
/*
- * Gak, He sent me a duplicate msg
- * id number?? return -1 to abort.
+ * something is very wrong, either
+ * control_pdapi is NULL, or the tail_mbuf
+ * is corrupt, or there is a EOM already on
+ * the mbuf chain.
*/
- return (-1);
- } else {
- if (TAILQ_NEXT(at, next_instrm) == NULL) {
- /*
- * We are at the end, insert
- * it after this one
- */
- if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_STR_LOGGING_ENABLE) {
- sctp_log_strm_del(control, at,
- SCTP_STR_LOG_FROM_INSERT_TL);
+ if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
+ goto abandon;
+ } else {
+#ifdef INVARIANTS
+ if ((stcb->asoc.control_pdapi == NULL) || (stcb->asoc.control_pdapi->tail_mbuf == NULL)) {
+ panic("This should not happen control_pdapi NULL?");
+ }
+ /* if we did not panic, it was a EOM */
+ panic("Bad chunking ??");
+#else
+ if ((stcb->asoc.control_pdapi == NULL) || (stcb->asoc.control_pdapi->tail_mbuf == NULL)) {
+ SCTP_PRINTF("This should not happen control_pdapi NULL?\n");
}
- TAILQ_INSERT_AFTER(q, at, control, next_instrm);
- if (unordered) {
- control->on_strm_q = SCTP_ON_UNORDERED ;
- } else {
- control->on_strm_q = SCTP_ON_ORDERED ;
- }
+ SCTP_PRINTF("Bad chunking ??\n");
+ SCTP_PRINTF("Dumping re-assembly queue this will probably hose the association\n");
+
+#endif
+ goto abandon;
+ }
+ }
+ cntDel++;
+ }
+ /* pull it we did it */
+ TAILQ_REMOVE(&asoc->reasmqueue, chk, sctp_next);
+ if (chk->rec.data.rcv_flags & SCTP_DATA_LAST_FRAG) {
+ asoc->fragmented_delivery_inprogress = 0;
+ if ((chk->rec.data.rcv_flags & SCTP_DATA_UNORDERED) == 0) {
+ asoc->strmin[stream_no].last_sequence_delivered++;
+ }
+ if ((chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) == 0) {
+ SCTP_STAT_INCR_COUNTER64(sctps_reasmusrmsgs);
+ }
+ } else if (chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) {
+ /*
+ * turn the flag back on since we just delivered
+ * yet another one.
+ */
+ asoc->fragmented_delivery_inprogress = 1;
+ }
+ asoc->tsn_of_pdapi_last_delivered = chk->rec.data.TSN_seq;
+ asoc->last_flags_delivered = chk->rec.data.rcv_flags;
+ asoc->last_strm_seq_delivered = chk->rec.data.stream_seq;
+ asoc->last_strm_no_delivered = chk->rec.data.stream_number;
+
+ asoc->tsn_last_delivered = chk->rec.data.TSN_seq;
+ asoc->size_on_reasm_queue -= chk->send_size;
+ sctp_ucount_decr(asoc->cnt_on_reasm_queue);
+ /* free up the chk */
+ chk->data = NULL;
+ sctp_free_a_chunk(stcb, chk, SCTP_SO_NOT_LOCKED);
+
+ if (asoc->fragmented_delivery_inprogress == 0) {
+ /*
+ * Now lets see if we can deliver the next one on
+ * the stream
+ */
+ struct sctp_stream_in *strm;
+
+ strm = &asoc->strmin[stream_no];
+ nxt_todel = strm->last_sequence_delivered + 1;
+ TAILQ_FOREACH_SAFE(ctl, &strm->inqueue, next, nctl) {
+ /* Deliver more if we can. */
+ if (nxt_todel == ctl->sinfo_ssn) {
+ TAILQ_REMOVE(&strm->inqueue, ctl, next);
+ asoc->size_on_all_streams -= ctl->length;
+ sctp_ucount_decr(asoc->cnt_on_all_streams);
+ strm->last_sequence_delivered++;
+ sctp_mark_non_revokable(asoc, ctl->sinfo_tsn);
+ sctp_add_to_readq(stcb->sctp_ep, stcb,
+ ctl,
+ &stcb->sctp_socket->so_rcv, 1,
+ SCTP_READ_LOCK_NOT_HELD, SCTP_SO_NOT_LOCKED);
+ } else {
break;
}
+ nxt_todel = strm->last_sequence_delivered + 1;
}
+ break;
}
}
- return (0);
-}
-
-static void
-sctp_abort_in_reasm(struct sctp_tcb *stcb,
- struct sctp_queued_to_read *control,
- struct sctp_tmit_chunk *chk,
- int *abort_flag, int opspot)
-{
- char msg[SCTP_DIAG_INFO_LEN];
- struct mbuf *oper;
-
- if (stcb->asoc.idata_supported) {
- snprintf(msg, sizeof(msg),
- "Reass %x,CF:%x,TSN=%8.8x,SID=%4.4x,FSN=%8.8x,MID:%8.8x",
- opspot,
- control->fsn_included,
- chk->rec.data.tsn,
- chk->rec.data.sid,
- chk->rec.data.fsn, chk->rec.data.mid);
- } else {
- snprintf(msg, sizeof(msg),
- "Reass %x,CI:%x,TSN=%8.8x,SID=%4.4x,FSN=%4.4x,SSN:%4.4x",
- opspot,
- control->fsn_included,
- chk->rec.data.tsn,
- chk->rec.data.sid,
- chk->rec.data.fsn,
- (uint16_t)chk->rec.data.mid);
- }
- oper = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg);
- sctp_m_freem(chk->data);
- chk->data = NULL;
- sctp_free_a_chunk(stcb, chk, SCTP_SO_NOT_LOCKED);
- stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_1;
- sctp_abort_an_association(stcb->sctp_ep, stcb, oper, SCTP_SO_NOT_LOCKED);
- *abort_flag = 1;
-}
-
-static void
-sctp_clean_up_control(struct sctp_tcb *stcb, struct sctp_queued_to_read *control)
-{
- /*
- * The control could not be placed and must be cleaned.
- */
- struct sctp_tmit_chunk *chk, *nchk;
- TAILQ_FOREACH_SAFE(chk, &control->reasm, sctp_next, nchk) {
- TAILQ_REMOVE(&control->reasm, chk, sctp_next);
- if (chk->data)
- sctp_m_freem(chk->data);
- chk->data = NULL;
- sctp_free_a_chunk(stcb, chk, SCTP_SO_NOT_LOCKED);
- }
- sctp_free_a_readq(stcb, control);
}
/*
* Queue the chunk either right into the socket buffer if it is the next one
* to go OR put it in the correct place in the delivery queue. If we do
- * append to the so_buf, keep doing so until we are out of order as
- * long as the control's entered are non-fragmented.
+ * append to the so_buf, keep doing so until we are out of order. One big
+ * question still remains, what to do when the socket buffer is FULL??
*/
static void
-sctp_queue_data_to_stream(struct sctp_tcb *stcb,
- struct sctp_association *asoc,
- struct sctp_queued_to_read *control, int *abort_flag, int *need_reasm)
+sctp_queue_data_to_stream(struct sctp_tcb *stcb, struct sctp_association *asoc,
+ struct sctp_queued_to_read *control, int *abort_flag)
{
/*
* FIX-ME maybe? What happens when the ssn wraps? If we are getting
* all the data in one stream this could happen quite rapidly. One
* could use the TSN to keep track of things, but this scheme breaks
- * down in the other type of stream usage that could occur. Send a
+ * down in the other type of stream useage that could occur. Send a
* single msg to stream 0, send 4Billion messages to stream 1, now
* send a message to stream 0. You have a situation where the TSN
* has wrapped but not in the stream. Is this worth worrying about
* or should we just change our queue sort at the bottom to be by
* TSN.
*
* Could it also be legal for a peer to send ssn 1 with TSN 2 and ssn 2
* with TSN 1? If the peer is doing some sort of funky TSN/SSN
* assignment this could happen... and I don't see how this would be
* a violation. So for now I am undecided an will leave the sort by
* SSN alone. Maybe a hybred approach is the answer
*
*/
+ struct sctp_stream_in *strm;
struct sctp_queued_to_read *at;
int queue_needed;
- uint32_t nxt_todel;
+ uint16_t nxt_todel;
struct mbuf *op_err;
- struct sctp_stream_in *strm;
char msg[SCTP_DIAG_INFO_LEN];
+ queue_needed = 1;
+ asoc->size_on_all_streams += control->length;
+ sctp_ucount_incr(asoc->cnt_on_all_streams);
strm = &asoc->strmin[control->sinfo_stream];
+ nxt_todel = strm->last_sequence_delivered + 1;
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_STR_LOGGING_ENABLE) {
sctp_log_strm_del(control, NULL, SCTP_STR_LOG_FROM_INTO_STRD);
}
- if (SCTP_MID_GT((asoc->idata_supported), strm->last_mid_delivered, control->mid)) {
+ SCTPDBG(SCTP_DEBUG_INDATA1,
+ "queue to stream called for ssn:%u lastdel:%u nxt:%u\n",
+ (uint32_t) control->sinfo_stream,
+ (uint32_t) strm->last_sequence_delivered,
+ (uint32_t) nxt_todel);
+ if (SCTP_SSN_GE(strm->last_sequence_delivered, control->sinfo_ssn)) {
/* The incoming sseq is behind where we last delivered? */
- SCTPDBG(SCTP_DEBUG_INDATA1, "Duplicate S-SEQ: %u delivered: %u from peer, Abort association\n",
- strm->last_mid_delivered, control->mid);
+ SCTPDBG(SCTP_DEBUG_INDATA1, "Duplicate S-SEQ:%d delivered:%d from peer, Abort association\n",
+ control->sinfo_ssn, strm->last_sequence_delivered);
+ protocol_error:
/*
* throw it in the stream so it gets cleaned up in
* association destruction
*/
- TAILQ_INSERT_HEAD(&strm->inqueue, control, next_instrm);
- if (asoc->idata_supported) {
- snprintf(msg, sizeof(msg), "Delivered MID=%8.8x, got TSN=%8.8x, SID=%4.4x, MID=%8.8x",
- strm->last_mid_delivered, control->sinfo_tsn,
- control->sinfo_stream, control->mid);
- } else {
- snprintf(msg, sizeof(msg), "Delivered SSN=%4.4x, got TSN=%8.8x, SID=%4.4x, SSN=%4.4x",
- (uint16_t)strm->last_mid_delivered,
- control->sinfo_tsn,
- control->sinfo_stream,
- (uint16_t)control->mid);
- }
+ TAILQ_INSERT_HEAD(&strm->inqueue, control, next);
+ snprintf(msg, sizeof(msg), "Delivered SSN=%4.4x, got TSN=%8.8x, SID=%4.4x, SSN=%4.4x",
+ strm->last_sequence_delivered, control->sinfo_tsn,
+ control->sinfo_stream, control->sinfo_ssn);
op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg);
- stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_2;
+ stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA+SCTP_LOC_1;
sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED);
*abort_flag = 1;
return;
}
- queue_needed = 1;
- asoc->size_on_all_streams += control->length;
- sctp_ucount_incr(asoc->cnt_on_all_streams);
- nxt_todel = strm->last_mid_delivered + 1;
- if (SCTP_MID_EQ(asoc->idata_supported, nxt_todel, control->mid)) {
-#if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
- struct socket *so;
-
- so = SCTP_INP_SO(stcb->sctp_ep);
- atomic_add_int(&stcb->asoc.refcnt, 1);
- SCTP_TCB_UNLOCK(stcb);
- SCTP_SOCKET_LOCK(so, 1);
- SCTP_TCB_LOCK(stcb);
- atomic_subtract_int(&stcb->asoc.refcnt, 1);
- if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) {
- SCTP_SOCKET_UNLOCK(so, 1);
- return;
- }
-#endif
+ if (nxt_todel == control->sinfo_ssn) {
/* can be delivered right away? */
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_STR_LOGGING_ENABLE) {
sctp_log_strm_del(control, NULL, SCTP_STR_LOG_FROM_IMMED_DEL);
}
- /* EY it wont be queued if it could be delivered directly */
+ /* EY it wont be queued if it could be delivered directly*/
queue_needed = 0;
- if (asoc->size_on_all_streams >= control->length) {
- asoc->size_on_all_streams -= control->length;
- } else {
-#ifdef INVARIANTS
- panic("size_on_all_streams = %u smaller than control length %u", asoc->size_on_all_streams, control->length);
-#else
- asoc->size_on_all_streams = 0;
-#endif
- }
+ asoc->size_on_all_streams -= control->length;
sctp_ucount_decr(asoc->cnt_on_all_streams);
- strm->last_mid_delivered++;
+ strm->last_sequence_delivered++;
+
sctp_mark_non_revokable(asoc, control->sinfo_tsn);
sctp_add_to_readq(stcb->sctp_ep, stcb,
control,
&stcb->sctp_socket->so_rcv, 1,
- SCTP_READ_LOCK_NOT_HELD, SCTP_SO_LOCKED);
- TAILQ_FOREACH_SAFE(control, &strm->inqueue, next_instrm, at) {
+ SCTP_READ_LOCK_NOT_HELD, SCTP_SO_NOT_LOCKED);
+ TAILQ_FOREACH_SAFE(control, &strm->inqueue, next, at) {
/* all delivered */
- nxt_todel = strm->last_mid_delivered + 1;
- if (SCTP_MID_EQ(asoc->idata_supported, nxt_todel, control->mid) &&
- (((control->sinfo_flags >> 8) & SCTP_DATA_NOT_FRAG) == SCTP_DATA_NOT_FRAG)) {
- if (control->on_strm_q == SCTP_ON_ORDERED) {
- TAILQ_REMOVE(&strm->inqueue, control, next_instrm);
- if (asoc->size_on_all_streams >= control->length) {
- asoc->size_on_all_streams -= control->length;
- } else {
-#ifdef INVARIANTS
- panic("size_on_all_streams = %u smaller than control length %u", asoc->size_on_all_streams, control->length);
-#else
- asoc->size_on_all_streams = 0;
-#endif
- }
- sctp_ucount_decr(asoc->cnt_on_all_streams);
-#ifdef INVARIANTS
- } else {
- panic("Huh control: %p is on_strm_q: %d",
- control, control->on_strm_q);
-#endif
- }
- control->on_strm_q = 0;
- strm->last_mid_delivered++;
+ nxt_todel = strm->last_sequence_delivered + 1;
+ if (nxt_todel == control->sinfo_ssn) {
+ TAILQ_REMOVE(&strm->inqueue, control, next);
+ asoc->size_on_all_streams -= control->length;
+ sctp_ucount_decr(asoc->cnt_on_all_streams);
+ strm->last_sequence_delivered++;
/*
* We ignore the return of deliver_data here
* since we always can hold the chunk on the
* d-queue. And we have a finite number that
* can be delivered from the strq.
*/
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_STR_LOGGING_ENABLE) {
sctp_log_strm_del(control, NULL,
SCTP_STR_LOG_FROM_IMMED_DEL);
}
sctp_mark_non_revokable(asoc, control->sinfo_tsn);
sctp_add_to_readq(stcb->sctp_ep, stcb,
control,
&stcb->sctp_socket->so_rcv, 1,
SCTP_READ_LOCK_NOT_HELD,
- SCTP_SO_LOCKED);
+ SCTP_SO_NOT_LOCKED);
continue;
- } else if (SCTP_MID_EQ(asoc->idata_supported, nxt_todel, control->mid)) {
- *need_reasm = 1;
}
break;
}
-#if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
- SCTP_SOCKET_UNLOCK(so, 1);
-#endif
}
if (queue_needed) {
/*
* Ok, we did not deliver this guy, find the correct place
* to put it on the queue.
*/
- if (sctp_place_control_in_stream(strm, asoc, control)) {
- snprintf(msg, sizeof(msg),
- "Queue to str MID: %u duplicate",
- control->mid);
- sctp_clean_up_control(stcb, control);
- op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg);
- stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_3;
- sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED);
- *abort_flag = 1;
+ if (SCTP_TSN_GE(asoc->cumulative_tsn, control->sinfo_tsn)) {
+ goto protocol_error;
+ }
+ if (TAILQ_EMPTY(&strm->inqueue)) {
+ /* Empty queue */
+ if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_STR_LOGGING_ENABLE) {
+ sctp_log_strm_del(control, NULL, SCTP_STR_LOG_FROM_INSERT_HD);
+ }
+ TAILQ_INSERT_HEAD(&strm->inqueue, control, next);
+ } else {
+ TAILQ_FOREACH(at, &strm->inqueue, next) {
+ if (SCTP_SSN_GT(at->sinfo_ssn, control->sinfo_ssn)) {
+ /*
+ * one in queue is bigger than the
+ * new one, insert before this one
+ */
+ if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_STR_LOGGING_ENABLE) {
+ sctp_log_strm_del(control, at,
+ SCTP_STR_LOG_FROM_INSERT_MD);
+ }
+ TAILQ_INSERT_BEFORE(at, control, next);
+ break;
+ } else if (at->sinfo_ssn == control->sinfo_ssn) {
+ /*
+ * Gak, He sent me a duplicate str
+ * seq number
+ */
+ /*
+ * foo bar, I guess I will just free
+ * this new guy, should we abort
+ * too? FIX ME MAYBE? Or it COULD be
+ * that the SSN's have wrapped.
+ * Maybe I should compare to TSN
+ * somehow... sigh for now just blow
+ * away the chunk!
+ */
+
+ if (control->data)
+ sctp_m_freem(control->data);
+ control->data = NULL;
+ asoc->size_on_all_streams -= control->length;
+ sctp_ucount_decr(asoc->cnt_on_all_streams);
+ if (control->whoFrom) {
+ sctp_free_remote_addr(control->whoFrom);
+ control->whoFrom = NULL;
+ }
+ sctp_free_a_readq(stcb, control);
+ return;
+ } else {
+ if (TAILQ_NEXT(at, next) == NULL) {
+ /*
+ * We are at the end, insert
+ * it after this one
+ */
+ if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_STR_LOGGING_ENABLE) {
+ sctp_log_strm_del(control, at,
+ SCTP_STR_LOG_FROM_INSERT_TL);
+ }
+ TAILQ_INSERT_AFTER(&strm->inqueue,
+ at, control, next);
+ break;
+ }
+ }
+ }
}
}
}
-
-static void
-sctp_setup_tail_pointer(struct sctp_queued_to_read *control)
-{
- struct mbuf *m, *prev = NULL;
- struct sctp_tcb *stcb;
-
- stcb = control->stcb;
- control->held_length = 0;
- control->length = 0;
- m = control->data;
- while (m) {
- if (SCTP_BUF_LEN(m) == 0) {
- /* Skip mbufs with NO length */
- if (prev == NULL) {
- /* First one */
- control->data = sctp_m_free(m);
- m = control->data;
- } else {
- SCTP_BUF_NEXT(prev) = sctp_m_free(m);
- m = SCTP_BUF_NEXT(prev);
- }
- if (m == NULL) {
- control->tail_mbuf = prev;
- }
- continue;
- }
- prev = m;
- atomic_add_int(&control->length, SCTP_BUF_LEN(m));
- if (control->on_read_q) {
- /*
- * On read queue so we must increment the
- * SB stuff, we assume caller has done any locks of SB.
- */
- sctp_sballoc(stcb, &stcb->sctp_socket->so_rcv, m);
- }
- m = SCTP_BUF_NEXT(m);
- }
- if (prev) {
- control->tail_mbuf = prev;
- }
-}
-
-static void
-sctp_add_to_tail_pointer(struct sctp_queued_to_read *control, struct mbuf *m, uint32_t *added)
-{
- struct mbuf *prev=NULL;
- struct sctp_tcb *stcb;
-
- stcb = control->stcb;
- if (stcb == NULL) {
-#ifdef INVARIANTS
- panic("Control broken");
-#else
- return;
-#endif
- }
- if (control->tail_mbuf == NULL) {
- /* TSNH */
- control->data = m;
- sctp_setup_tail_pointer(control);
- return;
- }
- control->tail_mbuf->m_next = m;
- while (m) {
- if (SCTP_BUF_LEN(m) == 0) {
- /* Skip mbufs with NO length */
- if (prev == NULL) {
- /* First one */
- control->tail_mbuf->m_next = sctp_m_free(m);
- m = control->tail_mbuf->m_next;
- } else {
- SCTP_BUF_NEXT(prev) = sctp_m_free(m);
- m = SCTP_BUF_NEXT(prev);
- }
- if (m == NULL) {
- control->tail_mbuf = prev;
- }
- continue;
- }
- prev = m;
- if (control->on_read_q) {
- /*
- * On read queue so we must increment the
- * SB stuff, we assume caller has done any locks of SB.
- */
- sctp_sballoc(stcb, &stcb->sctp_socket->so_rcv, m);
- }
- *added += SCTP_BUF_LEN(m);
- atomic_add_int(&control->length, SCTP_BUF_LEN(m));
- m = SCTP_BUF_NEXT(m);
- }
- if (prev) {
- control->tail_mbuf = prev;
- }
-}
-
-static void
-sctp_build_readq_entry_from_ctl(struct sctp_queued_to_read *nc, struct sctp_queued_to_read *control)
-{
- memset(nc, 0, sizeof(struct sctp_queued_to_read));
- nc->sinfo_stream = control->sinfo_stream;
- nc->mid = control->mid;
- TAILQ_INIT(&nc->reasm);
- nc->top_fsn = control->top_fsn;
- nc->mid = control->mid;
- nc->sinfo_flags = control->sinfo_flags;
- nc->sinfo_ppid = control->sinfo_ppid;
- nc->sinfo_context = control->sinfo_context;
- nc->fsn_included = 0xffffffff;
- nc->sinfo_tsn = control->sinfo_tsn;
- nc->sinfo_cumtsn = control->sinfo_cumtsn;
- nc->sinfo_assoc_id = control->sinfo_assoc_id;
- nc->whoFrom = control->whoFrom;
- atomic_add_int(&nc->whoFrom->ref_count, 1);
- nc->stcb = control->stcb;
- nc->port_from = control->port_from;
-}
-
-static void
-sctp_reset_a_control(struct sctp_queued_to_read *control,
- struct sctp_inpcb *inp, uint32_t tsn)
-{
- control->fsn_included = tsn;
- if (control->on_read_q) {
- /*
- * We have to purge it from there,
- * hopefully this will work :-)
- */
- TAILQ_REMOVE(&inp->read_queue, control, next);
- control->on_read_q = 0;
- }
-}
-
+/*
+ * Returns two things: You get the total size of the deliverable parts of the
+ * first fragmented message on the reassembly queue. And you get a 1 back if
+ * all of the message is ready or a 0 back if the message is still incomplete
+ */
static int
-sctp_handle_old_unordered_data(struct sctp_tcb *stcb,
- struct sctp_association *asoc,
- struct sctp_stream_in *strm,
- struct sctp_queued_to_read *control,
- uint32_t pd_point,
- int inp_read_lock_held)
+sctp_is_all_msg_on_reasm(struct sctp_association *asoc, uint32_t *t_size)
{
- /* Special handling for the old un-ordered data chunk.
- * All the chunks/TSN's go to mid 0. So
- * we have to do the old style watching to see
- * if we have it all. If you return one, no other
- * control entries on the un-ordered queue will
- * be looked at. In theory there should be no others
- * entries in reality, unless the guy is sending both
- * unordered NDATA and unordered DATA...
- */
- struct sctp_tmit_chunk *chk, *lchk, *tchk;
- uint32_t fsn;
- struct sctp_queued_to_read *nc;
- int cnt_added;
-
- if (control->first_frag_seen == 0) {
- /* Nothing we can do, we have not seen the first piece yet */
- return (1);
+ struct sctp_tmit_chunk *chk;
+ uint32_t tsn;
+
+ *t_size = 0;
+ chk = TAILQ_FIRST(&asoc->reasmqueue);
+ if (chk == NULL) {
+ /* nothing on the queue */
+ return (0);
}
- /* Collapse any we can */
- cnt_added = 0;
-restart:
- fsn = control->fsn_included + 1;
- /* Now what can we add? */
- TAILQ_FOREACH_SAFE(chk, &control->reasm, sctp_next, lchk) {
- if (chk->rec.data.fsn == fsn) {
- /* Ok lets add it */
- sctp_alloc_a_readq(stcb, nc);
- if (nc == NULL) {
- break;
- }
- memset(nc, 0, sizeof(struct sctp_queued_to_read));
- TAILQ_REMOVE(&control->reasm, chk, sctp_next);
- sctp_add_chk_to_control(control, strm, stcb, asoc, chk, SCTP_READ_LOCK_NOT_HELD);
- fsn++;
- cnt_added++;
- chk = NULL;
- if (control->end_added) {
- /* We are done */
- if (!TAILQ_EMPTY(&control->reasm)) {
- /*
- * Ok we have to move anything left on
- * the control queue to a new control.
- */
- sctp_build_readq_entry_from_ctl(nc, control);
- tchk = TAILQ_FIRST(&control->reasm);
- if (tchk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) {
- TAILQ_REMOVE(&control->reasm, tchk, sctp_next);
- if (asoc->size_on_reasm_queue >= tchk->send_size) {
- asoc->size_on_reasm_queue -= tchk->send_size;
- } else {
-#ifdef INVARIANTS
- panic("size_on_reasm_queue = %u smaller than chunk length %u", asoc->size_on_reasm_queue, tchk->send_size);
-#else
- asoc->size_on_reasm_queue = 0;
-#endif
- }
- sctp_ucount_decr(asoc->cnt_on_reasm_queue);
- nc->first_frag_seen = 1;
- nc->fsn_included = tchk->rec.data.fsn;
- nc->data = tchk->data;
- nc->sinfo_ppid = tchk->rec.data.ppid;
- nc->sinfo_tsn = tchk->rec.data.tsn;
- sctp_mark_non_revokable(asoc, tchk->rec.data.tsn);
- tchk->data = NULL;
- sctp_free_a_chunk(stcb, tchk, SCTP_SO_NOT_LOCKED);
- sctp_setup_tail_pointer(nc);
- tchk = TAILQ_FIRST(&control->reasm);
- }
- /* Spin the rest onto the queue */
- while (tchk) {
- TAILQ_REMOVE(&control->reasm, tchk, sctp_next);
- TAILQ_INSERT_TAIL(&nc->reasm, tchk, sctp_next);
- tchk = TAILQ_FIRST(&control->reasm);
- }
- /* Now lets add it to the queue after removing control */
- TAILQ_INSERT_TAIL(&strm->uno_inqueue, nc, next_instrm);
- nc->on_strm_q = SCTP_ON_UNORDERED;
- if (control->on_strm_q) {
- TAILQ_REMOVE(&strm->uno_inqueue, control, next_instrm);
- control->on_strm_q = 0;
- }
- }
- if (control->pdapi_started) {
- strm->pd_api_started = 0;
- control->pdapi_started = 0;
- }
- if (control->on_strm_q) {
- TAILQ_REMOVE(&strm->uno_inqueue, control, next_instrm);
- control->on_strm_q = 0;
- SCTP_STAT_INCR_COUNTER64(sctps_reasmusrmsgs);
- }
- if (control->on_read_q == 0) {
- sctp_add_to_readq(stcb->sctp_ep, stcb, control,
- &stcb->sctp_socket->so_rcv, control->end_added,
- inp_read_lock_held, SCTP_SO_NOT_LOCKED);
-#if defined(__Userspace__)
- } else {
- sctp_invoke_recv_callback(stcb->sctp_ep, stcb, control, inp_read_lock_held);
-#endif
- }
- sctp_wakeup_the_read_socket(stcb->sctp_ep, stcb, SCTP_SO_NOT_LOCKED);
- if ((nc->first_frag_seen) && !TAILQ_EMPTY(&nc->reasm)) {
- /* Switch to the new guy and continue */
- control = nc;
- goto restart;
- } else {
- if (nc->on_strm_q == 0) {
- sctp_free_a_readq(stcb, nc);
- }
- }
- return (1);
- } else {
- sctp_free_a_readq(stcb, nc);
- }
- } else {
- /* Can't add more */
- break;
+ if ((chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) == 0) {
+ /* Not a first on the queue */
+ return (0);
+ }
+ tsn = chk->rec.data.TSN_seq;
+ TAILQ_FOREACH(chk, &asoc->reasmqueue, sctp_next) {
+ if (tsn != chk->rec.data.TSN_seq) {
+ return (0);
}
+ *t_size += chk->send_size;
+ if (chk->rec.data.rcv_flags & SCTP_DATA_LAST_FRAG) {
+ return (1);
+ }
+ tsn++;
}
- if ((control->length > pd_point) && (strm->pd_api_started == 0)) {
- strm->pd_api_started = 1;
- control->pdapi_started = 1;
- sctp_add_to_readq(stcb->sctp_ep, stcb, control,
- &stcb->sctp_socket->so_rcv, control->end_added,
- inp_read_lock_held, SCTP_SO_NOT_LOCKED);
- sctp_wakeup_the_read_socket(stcb->sctp_ep, stcb, SCTP_SO_NOT_LOCKED);
- return (0);
- } else {
- return (1);
- }
+ return (0);
}
static void
-sctp_inject_old_unordered_data(struct sctp_tcb *stcb,
- struct sctp_association *asoc,
- struct sctp_queued_to_read *control,
- struct sctp_tmit_chunk *chk,
- int *abort_flag)
+sctp_deliver_reasm_check(struct sctp_tcb *stcb, struct sctp_association *asoc)
{
- struct sctp_tmit_chunk *at;
- int inserted;
- /*
- * Here we need to place the chunk into the control structure
- * sorted in the correct order.
- */
- if (chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) {
- /* Its the very first one. */
- SCTPDBG(SCTP_DEBUG_XXX,
- "chunk is a first fsn: %u becomes fsn_included\n",
- chk->rec.data.fsn);
- if (control->first_frag_seen) {
- /*
- * In old un-ordered we can reassembly on
- * one control multiple messages. As long
- * as the next FIRST is greater then the old
- * first (TSN i.e. FSN wise)
- */
- struct mbuf *tdata;
- uint32_t tmp;
-
- if (SCTP_TSN_GT(chk->rec.data.fsn, control->fsn_included)) {
- /* Easy way the start of a new guy beyond the lowest */
- goto place_chunk;
- }
- if ((chk->rec.data.fsn == control->fsn_included) ||
- (control->pdapi_started)) {
- /*
- * Ok this should not happen, if it does
- * we started the pd-api on the higher TSN (since
- * the equals part is a TSN failure it must be that).
- *
- * We are completly hosed in that case since I have
- * no way to recover. This really will only happen
- * if we can get more TSN's higher before the pd-api-point.
- */
- sctp_abort_in_reasm(stcb, control, chk,
- abort_flag,
- SCTP_FROM_SCTP_INDATA + SCTP_LOC_4);
-
- return;
- }
- /*
- * Ok we have two firsts and the one we just got
- * is smaller than the one we previously placed.. yuck!
- * We must swap them out.
- */
- /* swap the mbufs */
- tdata = control->data;
- control->data = chk->data;
- chk->data = tdata;
- /* Save the lengths */
- chk->send_size = control->length;
- /* Recompute length of control and tail pointer */
- sctp_setup_tail_pointer(control);
- /* Fix the FSN included */
- tmp = control->fsn_included;
- control->fsn_included = chk->rec.data.fsn;
- chk->rec.data.fsn = tmp;
- /* Fix the TSN included */
- tmp = control->sinfo_tsn;
- control->sinfo_tsn = chk->rec.data.tsn;
- chk->rec.data.tsn = tmp;
- /* Fix the PPID included */
- tmp = control->sinfo_ppid;
- control->sinfo_ppid = chk->rec.data.ppid;
- chk->rec.data.ppid = tmp;
- /* Fix tail pointer */
- goto place_chunk;
- }
- control->first_frag_seen = 1;
- control->fsn_included = chk->rec.data.fsn;
- control->top_fsn = chk->rec.data.fsn;
- control->sinfo_tsn = chk->rec.data.tsn;
- control->sinfo_ppid = chk->rec.data.ppid;
- control->data = chk->data;
- sctp_mark_non_revokable(asoc, chk->rec.data.tsn);
- chk->data = NULL;
- sctp_free_a_chunk(stcb, chk, SCTP_SO_NOT_LOCKED);
- sctp_setup_tail_pointer(control);
+ struct sctp_tmit_chunk *chk;
+ uint16_t nxt_todel;
+ uint32_t tsize, pd_point;
+
+ doit_again:
+ chk = TAILQ_FIRST(&asoc->reasmqueue);
+ if (chk == NULL) {
+ /* Huh? */
+ asoc->size_on_reasm_queue = 0;
+ asoc->cnt_on_reasm_queue = 0;
return;
}
-place_chunk:
- inserted = 0;
- TAILQ_FOREACH(at, &control->reasm, sctp_next) {
- if (SCTP_TSN_GT(at->rec.data.fsn, chk->rec.data.fsn)) {
+ if (asoc->fragmented_delivery_inprogress == 0) {
+ nxt_todel =
+ asoc->strmin[chk->rec.data.stream_number].last_sequence_delivered + 1;
+ if ((chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) &&
+ (nxt_todel == chk->rec.data.stream_seq ||
+ (chk->rec.data.rcv_flags & SCTP_DATA_UNORDERED))) {
/*
- * This one in queue is bigger than the new one, insert
- * the new one before at.
- */
- asoc->size_on_reasm_queue += chk->send_size;
- sctp_ucount_incr(asoc->cnt_on_reasm_queue);
- inserted = 1;
- TAILQ_INSERT_BEFORE(at, chk, sctp_next);
- break;
- } else if (at->rec.data.fsn == chk->rec.data.fsn) {
- /*
- * They sent a duplicate fsn number. This
- * really should not happen since the FSN is
- * a TSN and it should have been dropped earlier.
+ * Yep the first one is here and its ok to deliver
+ * but should we?
*/
- sctp_abort_in_reasm(stcb, control, chk,
- abort_flag,
- SCTP_FROM_SCTP_INDATA + SCTP_LOC_5);
- return;
- }
-
- }
- if (inserted == 0) {
- /* Its at the end */
- asoc->size_on_reasm_queue += chk->send_size;
- sctp_ucount_incr(asoc->cnt_on_reasm_queue);
- control->top_fsn = chk->rec.data.fsn;
- TAILQ_INSERT_TAIL(&control->reasm, chk, sctp_next);
- }
-}
-
-static int
-sctp_deliver_reasm_check(struct sctp_tcb *stcb, struct sctp_association *asoc,
- struct sctp_stream_in *strm, int inp_read_lock_held)
-{
- /*
- * Given a stream, strm, see if any of
- * the SSN's on it that are fragmented
- * are ready to deliver. If so go ahead
- * and place them on the read queue. In
- * so placing if we have hit the end, then
- * we need to remove them from the stream's queue.
- */
- struct sctp_queued_to_read *control, *nctl = NULL;
- uint32_t next_to_del;
- uint32_t pd_point;
- int ret = 0;
-
- if (stcb->sctp_socket) {
- pd_point = min(SCTP_SB_LIMIT_RCV(stcb->sctp_socket) >> SCTP_PARTIAL_DELIVERY_SHIFT,
- stcb->sctp_ep->partial_delivery_point);
- } else {
- pd_point = stcb->sctp_ep->partial_delivery_point;
- }
- control = TAILQ_FIRST(&strm->uno_inqueue);
-
- if ((control != NULL) &&
- (asoc->idata_supported == 0)) {
- /* Special handling needed for "old" data format */
- if (sctp_handle_old_unordered_data(stcb, asoc, strm, control, pd_point, inp_read_lock_held)) {
- goto done_un;
- }
- }
- if (strm->pd_api_started) {
- /* Can't add more */
- return (0);
- }
- while (control) {
- SCTPDBG(SCTP_DEBUG_XXX, "Looking at control: %p e(%d) ssn: %u top_fsn: %u inc_fsn: %u -uo\n",
- control, control->end_added, control->mid, control->top_fsn, control->fsn_included);
- nctl = TAILQ_NEXT(control, next_instrm);
- if (control->end_added) {
- /* We just put the last bit on */
- if (control->on_strm_q) {
-#ifdef INVARIANTS
- if (control->on_strm_q != SCTP_ON_UNORDERED ) {
- panic("Huh control: %p on_q: %d -- not unordered?",
- control, control->on_strm_q);
- }
-#endif
- SCTP_STAT_INCR_COUNTER64(sctps_reasmusrmsgs);
- TAILQ_REMOVE(&strm->uno_inqueue, control, next_instrm);
- control->on_strm_q = 0;
+ if (stcb->sctp_socket) {
+ pd_point = min(SCTP_SB_LIMIT_RCV(stcb->sctp_socket) >> SCTP_PARTIAL_DELIVERY_SHIFT,
+ stcb->sctp_ep->partial_delivery_point);
+ } else {
+ pd_point = stcb->sctp_ep->partial_delivery_point;
}
- if (control->on_read_q == 0) {
- sctp_add_to_readq(stcb->sctp_ep, stcb,
- control,
- &stcb->sctp_socket->so_rcv, control->end_added,
- inp_read_lock_held, SCTP_SO_NOT_LOCKED);
- }
- } else {
- /* Can we do a PD-API for this un-ordered guy? */
- if ((control->length >= pd_point) && (strm->pd_api_started == 0)) {
- strm->pd_api_started = 1;
- control->pdapi_started = 1;
- sctp_add_to_readq(stcb->sctp_ep, stcb,
- control,
- &stcb->sctp_socket->so_rcv, control->end_added,
- inp_read_lock_held, SCTP_SO_NOT_LOCKED);
-
- break;
+ if (sctp_is_all_msg_on_reasm(asoc, &tsize) || (tsize >= pd_point)) {
+ /*
+ * Yes, we setup to start reception, by
+ * backing down the TSN just in case we
+ * can't deliver. If we
+ */
+ asoc->fragmented_delivery_inprogress = 1;
+ asoc->tsn_last_delivered =
+ chk->rec.data.TSN_seq - 1;
+ asoc->str_of_pdapi =
+ chk->rec.data.stream_number;
+ asoc->ssn_of_pdapi = chk->rec.data.stream_seq;
+ asoc->pdapi_ppid = chk->rec.data.payloadtype;
+ asoc->fragment_flags = chk->rec.data.rcv_flags;
+ sctp_service_reassembly(stcb, asoc);
}
}
- control = nctl;
- }
-done_un:
- control = TAILQ_FIRST(&strm->inqueue);
- if (strm->pd_api_started) {
- /* Can't add more */
- return (0);
- }
- if (control == NULL) {
- return (ret);
- }
- if (SCTP_MID_EQ(asoc->idata_supported, strm->last_mid_delivered, control->mid)) {
- /* Ok the guy at the top was being partially delivered
- * completed, so we remove it. Note
- * the pd_api flag was taken off when the
- * chunk was merged on in sctp_queue_data_for_reasm below.
+ } else {
+ /* Service re-assembly will deliver stream data queued
+ * at the end of fragmented delivery.. but it wont know
+ * to go back and call itself again... we do that here
+ * with the got doit_again
*/
- nctl = TAILQ_NEXT(control, next_instrm);
- SCTPDBG(SCTP_DEBUG_XXX,
- "Looking at control: %p e(%d) ssn: %u top_fsn: %u inc_fsn: %u (lastdel: %u)- o\n",
- control, control->end_added, control->mid,
- control->top_fsn, control->fsn_included,
- strm->last_mid_delivered);
- if (control->end_added) {
- if (control->on_strm_q) {
-#ifdef INVARIANTS
- if (control->on_strm_q != SCTP_ON_ORDERED ) {
- panic("Huh control: %p on_q: %d -- not ordered?",
- control, control->on_strm_q);
- }
-#endif
- SCTP_STAT_INCR_COUNTER64(sctps_reasmusrmsgs);
- TAILQ_REMOVE(&strm->inqueue, control, next_instrm);
- if (asoc->size_on_all_streams >= control->length) {
- asoc->size_on_all_streams -= control->length;
- } else {
-#ifdef INVARIANTS
- panic("size_on_all_streams = %u smaller than control length %u", asoc->size_on_all_streams, control->length);
-#else
- asoc->size_on_all_streams = 0;
-#endif
- }
- sctp_ucount_decr(asoc->cnt_on_all_streams);
- control->on_strm_q = 0;
- }
- if (strm->pd_api_started && control->pdapi_started) {
- control->pdapi_started = 0;
- strm->pd_api_started = 0;
- }
- if (control->on_read_q == 0) {
- sctp_add_to_readq(stcb->sctp_ep, stcb,
- control,
- &stcb->sctp_socket->so_rcv, control->end_added,
- inp_read_lock_held, SCTP_SO_NOT_LOCKED);
- }
- control = nctl;
+ sctp_service_reassembly(stcb, asoc);
+ if (asoc->fragmented_delivery_inprogress == 0) {
+ /* finished our Fragmented delivery, could be
+ * more waiting?
+ */
+ goto doit_again;
}
}
- if (strm->pd_api_started) {
- /* Can't add more must have gotten an un-ordered above being partially delivered. */
- return (0);
- }
-deliver_more:
- next_to_del = strm->last_mid_delivered + 1;
- if (control) {
- SCTPDBG(SCTP_DEBUG_XXX,
- "Looking at control: %p e(%d) ssn: %u top_fsn: %u inc_fsn: %u (nxtdel: %u)- o\n",
- control, control->end_added, control->mid, control->top_fsn, control->fsn_included,
- next_to_del);
- nctl = TAILQ_NEXT(control, next_instrm);
- if (SCTP_MID_EQ(asoc->idata_supported, control->mid, next_to_del) &&
- (control->first_frag_seen)) {
- int done;
-
- /* Ok we can deliver it onto the stream. */
- if (control->end_added) {
- /* We are done with it afterwards */
- if (control->on_strm_q) {
-#ifdef INVARIANTS
- if (control->on_strm_q != SCTP_ON_ORDERED ) {
- panic("Huh control: %p on_q: %d -- not ordered?",
- control, control->on_strm_q);
- }
-#endif
- SCTP_STAT_INCR_COUNTER64(sctps_reasmusrmsgs);
- TAILQ_REMOVE(&strm->inqueue, control, next_instrm);
- if (asoc->size_on_all_streams >= control->length) {
- asoc->size_on_all_streams -= control->length;
- } else {
-#ifdef INVARIANTS
- panic("size_on_all_streams = %u smaller than control length %u", asoc->size_on_all_streams, control->length);
-#else
- asoc->size_on_all_streams = 0;
-#endif
- }
- sctp_ucount_decr(asoc->cnt_on_all_streams);
- control->on_strm_q = 0;
- }
- ret++;
- }
- if (((control->sinfo_flags >> 8) & SCTP_DATA_NOT_FRAG) == SCTP_DATA_NOT_FRAG) {
- /* A singleton now slipping through - mark it non-revokable too */
- sctp_mark_non_revokable(asoc, control->sinfo_tsn);
- } else if (control->end_added == 0) {
- /* Check if we can defer adding until its all there */
- if ((control->length < pd_point) || (strm->pd_api_started)) {
- /* Don't need it or cannot add more (one being delivered that way) */
- goto out;
- }
- }
- done = (control->end_added) && (control->last_frag_seen);
- if (control->on_read_q == 0) {
- if (!done) {
- if (asoc->size_on_all_streams >= control->length) {
- asoc->size_on_all_streams -= control->length;
- } else {
-#ifdef INVARIANTS
- panic("size_on_all_streams = %u smaller than control length %u", asoc->size_on_all_streams, control->length);
-#else
- asoc->size_on_all_streams = 0;
-#endif
- }
- strm->pd_api_started = 1;
- control->pdapi_started = 1;
- }
- sctp_add_to_readq(stcb->sctp_ep, stcb,
- control,
- &stcb->sctp_socket->so_rcv, control->end_added,
- inp_read_lock_held, SCTP_SO_NOT_LOCKED);
- }
- strm->last_mid_delivered = next_to_del;
- if (done) {
- control = nctl;
- goto deliver_more;
- }
- }
- }
-out:
- return (ret);
-}
-
-
-uint32_t
-sctp_add_chk_to_control(struct sctp_queued_to_read *control,
- struct sctp_stream_in *strm,
- struct sctp_tcb *stcb, struct sctp_association *asoc,
- struct sctp_tmit_chunk *chk, int hold_rlock)
-{
- /*
- * Given a control and a chunk, merge the
- * data from the chk onto the control and free
- * up the chunk resources.
- */
- uint32_t added=0;
- int i_locked = 0;
-
- if (control->on_read_q && (hold_rlock == 0)) {
- /*
- * Its being pd-api'd so we must
- * do some locks.
- */
- SCTP_INP_READ_LOCK(stcb->sctp_ep);
- i_locked = 1;
- }
- if (control->data == NULL) {
- control->data = chk->data;
- sctp_setup_tail_pointer(control);
- } else {
- sctp_add_to_tail_pointer(control, chk->data, &added);
- }
- control->fsn_included = chk->rec.data.fsn;
- asoc->size_on_reasm_queue -= chk->send_size;
- sctp_ucount_decr(asoc->cnt_on_reasm_queue);
- sctp_mark_non_revokable(asoc, chk->rec.data.tsn);
- chk->data = NULL;
- if (chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) {
- control->first_frag_seen = 1;
- control->sinfo_tsn = chk->rec.data.tsn;
- control->sinfo_ppid = chk->rec.data.ppid;
- }
- if (chk->rec.data.rcv_flags & SCTP_DATA_LAST_FRAG) {
- /* Its complete */
- if ((control->on_strm_q) && (control->on_read_q)) {
- if (control->pdapi_started) {
- control->pdapi_started = 0;
- strm->pd_api_started = 0;
- }
- if (control->on_strm_q == SCTP_ON_UNORDERED) {
- /* Unordered */
- TAILQ_REMOVE(&strm->uno_inqueue, control, next_instrm);
- control->on_strm_q = 0;
- } else if (control->on_strm_q == SCTP_ON_ORDERED) {
- /* Ordered */
- TAILQ_REMOVE(&strm->inqueue, control, next_instrm);
- /*
- * Don't need to decrement size_on_all_streams,
- * since control is on the read queue.
- */
- sctp_ucount_decr(asoc->cnt_on_all_streams);
- control->on_strm_q = 0;
-#ifdef INVARIANTS
- } else if (control->on_strm_q) {
- panic("Unknown state on ctrl: %p on_strm_q: %d", control,
- control->on_strm_q);
-#endif
- }
- }
- control->end_added = 1;
- control->last_frag_seen = 1;
- }
- if (i_locked) {
- SCTP_INP_READ_UNLOCK(stcb->sctp_ep);
- }
- sctp_free_a_chunk(stcb, chk, SCTP_SO_NOT_LOCKED);
- return (added);
}
/*
* Dump onto the re-assembly queue, in its proper place. After dumping on the
* queue, see if anthing can be delivered. If so pull it off (or as much as
* we can. If we run out of space then we must dump what we can and set the
* appropriate flag to say we queued what we could.
*/
static void
sctp_queue_data_for_reasm(struct sctp_tcb *stcb, struct sctp_association *asoc,
- struct sctp_queued_to_read *control,
- struct sctp_tmit_chunk *chk,
- int created_control,
- int *abort_flag, uint32_t tsn)
+ struct sctp_tmit_chunk *chk, int *abort_flag)
{
- uint32_t next_fsn;
- struct sctp_tmit_chunk *at, *nat;
- struct sctp_stream_in *strm;
- int do_wakeup, unordered;
- uint32_t lenadded;
-
- strm = &asoc->strmin[control->sinfo_stream];
- /*
- * For old un-ordered data chunks.
- */
- if ((control->sinfo_flags >> 8) & SCTP_DATA_UNORDERED) {
- unordered = 1;
- } else {
- unordered = 0;
- }
- /* Must be added to the stream-in queue */
- if (created_control) {
- if (unordered == 0) {
- sctp_ucount_incr(asoc->cnt_on_all_streams);
- }
- if (sctp_place_control_in_stream(strm, asoc, control)) {
- /* Duplicate SSN? */
- sctp_abort_in_reasm(stcb, control, chk,
- abort_flag,
- SCTP_FROM_SCTP_INDATA + SCTP_LOC_6);
- sctp_clean_up_control(stcb, control);
- return;
- }
- if ((tsn == (asoc->cumulative_tsn + 1) && (asoc->idata_supported == 0))) {
- /* Ok we created this control and now
- * lets validate that its legal i.e. there
- * is a B bit set, if not and we have
- * up to the cum-ack then its invalid.
- */
- if ((chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) == 0) {
- sctp_abort_in_reasm(stcb, control, chk,
- abort_flag,
- SCTP_FROM_SCTP_INDATA + SCTP_LOC_7);
- return;
- }
- }
- }
- if ((asoc->idata_supported == 0) && (unordered == 1)) {
- sctp_inject_old_unordered_data(stcb, asoc, control, chk, abort_flag);
- return;
- }
- /*
- * Ok we must queue the chunk into the reasembly portion:
- * o if its the first it goes to the control mbuf.
- * o if its not first but the next in sequence it goes to the control,
- * and each succeeding one in order also goes.
- * o if its not in order we place it on the list in its place.
- */
- if (chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) {
- /* Its the very first one. */
- SCTPDBG(SCTP_DEBUG_XXX,
- "chunk is a first fsn: %u becomes fsn_included\n",
- chk->rec.data.fsn);
- if (control->first_frag_seen) {
- /*
- * Error on senders part, they either
- * sent us two data chunks with FIRST,
- * or they sent two un-ordered chunks that
- * were fragmented at the same time in the same stream.
- */
- sctp_abort_in_reasm(stcb, control, chk,
- abort_flag,
- SCTP_FROM_SCTP_INDATA + SCTP_LOC_8);
- return;
- }
- control->first_frag_seen = 1;
- control->sinfo_ppid = chk->rec.data.ppid;
- control->sinfo_tsn = chk->rec.data.tsn;
- control->fsn_included = chk->rec.data.fsn;
- control->data = chk->data;
- sctp_mark_non_revokable(asoc, chk->rec.data.tsn);
- chk->data = NULL;
- sctp_free_a_chunk(stcb, chk, SCTP_SO_NOT_LOCKED);
- sctp_setup_tail_pointer(control);
- asoc->size_on_all_streams += control->length;
- } else {
- /* Place the chunk in our list */
- int inserted=0;
- if (control->last_frag_seen == 0) {
- /* Still willing to raise highest FSN seen */
- if (SCTP_TSN_GT(chk->rec.data.fsn, control->top_fsn)) {
- SCTPDBG(SCTP_DEBUG_XXX,
- "We have a new top_fsn: %u\n",
- chk->rec.data.fsn);
- control->top_fsn = chk->rec.data.fsn;
- }
- if (chk->rec.data.rcv_flags & SCTP_DATA_LAST_FRAG) {
- SCTPDBG(SCTP_DEBUG_XXX,
- "The last fsn is now in place fsn: %u\n",
- chk->rec.data.fsn);
- control->last_frag_seen = 1;
- }
- if (asoc->idata_supported || control->first_frag_seen) {
- /*
- * For IDATA we always check since we know that
- * the first fragment is 0. For old DATA we have
- * to receive the first before we know the first FSN
- * (which is the TSN).
+ struct mbuf *op_err;
+ char msg[SCTP_DIAG_INFO_LEN];
+ uint32_t cum_ackp1, prev_tsn, post_tsn;
+ struct sctp_tmit_chunk *at, *prev, *next;
+
+ prev = next = NULL;
+ cum_ackp1 = asoc->tsn_last_delivered + 1;
+ if (TAILQ_EMPTY(&asoc->reasmqueue)) {
+ /* This is the first one on the queue */
+ TAILQ_INSERT_HEAD(&asoc->reasmqueue, chk, sctp_next);
+ /*
+ * we do not check for delivery of anything when only one
+ * fragment is here
+ */
+ asoc->size_on_reasm_queue = chk->send_size;
+ sctp_ucount_incr(asoc->cnt_on_reasm_queue);
+ if (chk->rec.data.TSN_seq == cum_ackp1) {
+ if (asoc->fragmented_delivery_inprogress == 0 &&
+ (chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) !=
+ SCTP_DATA_FIRST_FRAG) {
+ /*
+ * An empty queue, no delivery inprogress,
+ * we hit the next one and it does NOT have
+ * a FIRST fragment mark.
+ */
+ SCTPDBG(SCTP_DEBUG_INDATA1, "Gak, Evil plot, its not first, no fragmented delivery in progress\n");
+ snprintf(msg, sizeof(msg),
+ "Expected B-bit for TSN=%8.8x, SID=%4.4x, SSN=%4.4x",
+ chk->rec.data.TSN_seq,
+ chk->rec.data.stream_number,
+ chk->rec.data.stream_seq);
+ op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg);
+ stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA+SCTP_LOC_2;
+ sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED);
+ *abort_flag = 1;
+ } else if (asoc->fragmented_delivery_inprogress &&
+ (chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) == SCTP_DATA_FIRST_FRAG) {
+ /*
+ * We are doing a partial delivery and the
+ * NEXT chunk MUST be either the LAST or
+ * MIDDLE fragment NOT a FIRST
*/
- if (SCTP_TSN_GE(control->fsn_included, chk->rec.data.fsn)) {
- /* We have already delivered up to this so its a dup */
- sctp_abort_in_reasm(stcb, control, chk,
- abort_flag,
- SCTP_FROM_SCTP_INDATA + SCTP_LOC_9);
- return;
+ SCTPDBG(SCTP_DEBUG_INDATA1, "Gak, Evil plot, it IS a first and fragmented delivery in progress\n");
+ snprintf(msg, sizeof(msg),
+ "Didn't expect B-bit for TSN=%8.8x, SID=%4.4x, SSN=%4.4x",
+ chk->rec.data.TSN_seq,
+ chk->rec.data.stream_number,
+ chk->rec.data.stream_seq);
+ op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg);
+ stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA+SCTP_LOC_3;
+ sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED);
+ *abort_flag = 1;
+ } else if (asoc->fragmented_delivery_inprogress) {
+ /*
+ * Here we are ok with a MIDDLE or LAST
+ * piece
+ */
+ if (chk->rec.data.stream_number !=
+ asoc->str_of_pdapi) {
+ /* Got to be the right STR No */
+ SCTPDBG(SCTP_DEBUG_INDATA1, "Gak, Evil plot, it IS not same stream number %d vs %d\n",
+ chk->rec.data.stream_number,
+ asoc->str_of_pdapi);
+ snprintf(msg, sizeof(msg),
+ "Expected SID=%4.4x, got TSN=%8.8x, SID=%4.4x, SSN=%4.4x",
+ asoc->str_of_pdapi,
+ chk->rec.data.TSN_seq,
+ chk->rec.data.stream_number,
+ chk->rec.data.stream_seq);
+ op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg);
+ stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA+SCTP_LOC_4;
+ sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED);
+ *abort_flag = 1;
+ } else if ((asoc->fragment_flags & SCTP_DATA_UNORDERED) !=
+ SCTP_DATA_UNORDERED &&
+ chk->rec.data.stream_seq != asoc->ssn_of_pdapi) {
+ /* Got to be the right STR Seq */
+ SCTPDBG(SCTP_DEBUG_INDATA1, "Gak, Evil plot, it IS not same stream seq %d vs %d\n",
+ chk->rec.data.stream_seq,
+ asoc->ssn_of_pdapi);
+ snprintf(msg, sizeof(msg),
+ "Expected SSN=%4.4x, got TSN=%8.8x, SID=%4.4x, SSN=%4.4x",
+ asoc->ssn_of_pdapi,
+ chk->rec.data.TSN_seq,
+ chk->rec.data.stream_number,
+ chk->rec.data.stream_seq);
+ op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg);
+ stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA+SCTP_LOC_5;
+ sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED);
+ *abort_flag = 1;
}
}
- } else {
- if (chk->rec.data.rcv_flags & SCTP_DATA_LAST_FRAG) {
- /* Second last? huh? */
- SCTPDBG(SCTP_DEBUG_XXX,
- "Duplicate last fsn: %u (top: %u) -- abort\n",
- chk->rec.data.fsn, control->top_fsn);
- sctp_abort_in_reasm(stcb, control,
- chk, abort_flag,
- SCTP_FROM_SCTP_INDATA + SCTP_LOC_10);
- return;
- }
- if (asoc->idata_supported || control->first_frag_seen) {
- /*
- * For IDATA we always check since we know that
- * the first fragment is 0. For old DATA we have
- * to receive the first before we know the first FSN
- * (which is the TSN).
- */
-
- if (SCTP_TSN_GE(control->fsn_included, chk->rec.data.fsn)) {
- /* We have already delivered up to this so its a dup */
- SCTPDBG(SCTP_DEBUG_XXX,
- "New fsn: %u is already seen in included_fsn: %u -- abort\n",
- chk->rec.data.fsn, control->fsn_included);
- sctp_abort_in_reasm(stcb, control, chk,
- abort_flag,
- SCTP_FROM_SCTP_INDATA + SCTP_LOC_11);
- return;
- }
+ }
+ return;
+ }
+ /* Find its place */
+ TAILQ_FOREACH(at, &asoc->reasmqueue, sctp_next) {
+ if (SCTP_TSN_GT(at->rec.data.TSN_seq, chk->rec.data.TSN_seq)) {
+ /*
+ * one in queue is bigger than the new one, insert
+ * before this one
+ */
+ /* A check */
+ asoc->size_on_reasm_queue += chk->send_size;
+ sctp_ucount_incr(asoc->cnt_on_reasm_queue);
+ next = at;
+ TAILQ_INSERT_BEFORE(at, chk, sctp_next);
+ break;
+ } else if (at->rec.data.TSN_seq == chk->rec.data.TSN_seq) {
+ /* Gak, He sent me a duplicate str seq number */
+ /*
+ * foo bar, I guess I will just free this new guy,
+ * should we abort too? FIX ME MAYBE? Or it COULD be
+ * that the SSN's have wrapped. Maybe I should
+ * compare to TSN somehow... sigh for now just blow
+ * away the chunk!
+ */
+ if (chk->data) {
+ sctp_m_freem(chk->data);
+ chk->data = NULL;
}
- /* validate not beyond top FSN if we have seen last one */
- if (SCTP_TSN_GT(chk->rec.data.fsn, control->top_fsn)) {
- SCTPDBG(SCTP_DEBUG_XXX,
- "New fsn: %u is beyond or at top_fsn: %u -- abort\n",
- chk->rec.data.fsn,
- control->top_fsn);
- sctp_abort_in_reasm(stcb, control, chk,
- abort_flag,
- SCTP_FROM_SCTP_INDATA + SCTP_LOC_12);
- return;
- }
- }
- /*
- * If we reach here, we need to place the
- * new chunk in the reassembly for this
- * control.
- */
- SCTPDBG(SCTP_DEBUG_XXX,
- "chunk is a not first fsn: %u needs to be inserted\n",
- chk->rec.data.fsn);
- TAILQ_FOREACH(at, &control->reasm, sctp_next) {
- if (SCTP_TSN_GT(at->rec.data.fsn, chk->rec.data.fsn)) {
+ sctp_free_a_chunk(stcb, chk, SCTP_SO_NOT_LOCKED);
+ return;
+ } else {
+ prev = at;
+ if (TAILQ_NEXT(at, sctp_next) == NULL) {
/*
- * This one in queue is bigger than the new one, insert
- * the new one before at.
+ * We are at the end, insert it after this
+ * one
*/
- SCTPDBG(SCTP_DEBUG_XXX,
- "Insert it before fsn: %u\n",
- at->rec.data.fsn);
+ /* check it first */
asoc->size_on_reasm_queue += chk->send_size;
sctp_ucount_incr(asoc->cnt_on_reasm_queue);
- TAILQ_INSERT_BEFORE(at, chk, sctp_next);
- inserted = 1;
- break;
- } else if (at->rec.data.fsn == chk->rec.data.fsn) {
- /* Gak, He sent me a duplicate str seq number */
- /*
- * foo bar, I guess I will just free this new guy,
- * should we abort too? FIX ME MAYBE? Or it COULD be
- * that the SSN's have wrapped. Maybe I should
- * compare to TSN somehow... sigh for now just blow
- * away the chunk!
- */
- SCTPDBG(SCTP_DEBUG_XXX,
- "Duplicate to fsn: %u -- abort\n",
- at->rec.data.fsn);
- sctp_abort_in_reasm(stcb, control,
- chk, abort_flag,
- SCTP_FROM_SCTP_INDATA + SCTP_LOC_13);
- return;
- }
- }
- if (inserted == 0) {
- /* Goes on the end */
- SCTPDBG(SCTP_DEBUG_XXX, "Inserting at tail of list fsn: %u\n",
- chk->rec.data.fsn);
- asoc->size_on_reasm_queue += chk->send_size;
- sctp_ucount_incr(asoc->cnt_on_reasm_queue);
- TAILQ_INSERT_TAIL(&control->reasm, chk, sctp_next);
- }
- }
- /*
- * Ok lets see if we can suck any up into the control
- * structure that are in seq if it makes sense.
- */
- do_wakeup = 0;
- /*
- * If the first fragment has not been
- * seen there is no sense in looking.
- */
- if (control->first_frag_seen) {
- next_fsn = control->fsn_included + 1;
- TAILQ_FOREACH_SAFE(at, &control->reasm, sctp_next, nat) {
- if (at->rec.data.fsn == next_fsn) {
- /* We can add this one now to the control */
- SCTPDBG(SCTP_DEBUG_XXX,
- "Adding more to control: %p at: %p fsn: %u next_fsn: %u included: %u\n",
- control, at,
- at->rec.data.fsn,
- next_fsn, control->fsn_included);
- TAILQ_REMOVE(&control->reasm, at, sctp_next);
- lenadded = sctp_add_chk_to_control(control, strm, stcb, asoc, at, SCTP_READ_LOCK_NOT_HELD);
- if (control->on_read_q) {
- do_wakeup = 1;
- } else {
- /*
- * We only add to the size-on-all-streams
- * if its not on the read q. The read q
- * flag will cause a sballoc so its accounted
- * for there.
- */
- asoc->size_on_all_streams += lenadded;
- }
- next_fsn++;
- if (control->end_added && control->pdapi_started) {
- if (strm->pd_api_started) {
- strm->pd_api_started = 0;
- control->pdapi_started = 0;
- }
- if (control->on_read_q == 0) {
- sctp_add_to_readq(stcb->sctp_ep, stcb,
- control,
- &stcb->sctp_socket->so_rcv, control->end_added,
- SCTP_READ_LOCK_NOT_HELD, SCTP_SO_NOT_LOCKED);
- }
- break;
- }
- } else {
+ TAILQ_INSERT_AFTER(&asoc->reasmqueue, at, chk, sctp_next);
break;
}
}
}
- if (do_wakeup) {
-#if defined(__Userspace__)
- sctp_invoke_recv_callback(stcb->sctp_ep, stcb, control, SCTP_READ_LOCK_NOT_HELD);
-#endif
- /* Need to wakeup the reader */
- sctp_wakeup_the_read_socket(stcb->sctp_ep, stcb, SCTP_SO_NOT_LOCKED);
- }
-}
-
-static struct sctp_queued_to_read *
-sctp_find_reasm_entry(struct sctp_stream_in *strm, uint32_t mid, int ordered, int idata_supported)
-{
- struct sctp_queued_to_read *control;
-
- if (ordered) {
- TAILQ_FOREACH(control, &strm->inqueue, next_instrm) {
- if (SCTP_MID_EQ(idata_supported, control->mid, mid)) {
- break;
+ /* Now the audits */
+ if (prev) {
+ prev_tsn = chk->rec.data.TSN_seq - 1;
+ if (prev_tsn == prev->rec.data.TSN_seq) {
+ /*
+ * Ok the one I am dropping onto the end is the
+ * NEXT. A bit of valdiation here.
+ */
+ if ((prev->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) ==
+ SCTP_DATA_FIRST_FRAG ||
+ (prev->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) ==
+ SCTP_DATA_MIDDLE_FRAG) {
+ /*
+ * Insert chk MUST be a MIDDLE or LAST
+ * fragment
+ */
+ if ((chk->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) ==
+ SCTP_DATA_FIRST_FRAG) {
+ SCTPDBG(SCTP_DEBUG_INDATA1, "Prev check - It can be a midlle or last but not a first\n");
+ SCTPDBG(SCTP_DEBUG_INDATA1, "Gak, Evil plot, it's a FIRST!\n");
+ snprintf(msg, sizeof(msg),
+ "Can't handle B-bit, got TSN=%8.8x, SID=%4.4x, SSN=%4.4x",
+ chk->rec.data.TSN_seq,
+ chk->rec.data.stream_number,
+ chk->rec.data.stream_seq);
+ op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg);
+ stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA+SCTP_LOC_6;
+ sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED);
+ *abort_flag = 1;
+ return;
+ }
+ if (chk->rec.data.stream_number !=
+ prev->rec.data.stream_number) {
+ /*
+ * Huh, need the correct STR here,
+ * they must be the same.
+ */
+ SCTPDBG(SCTP_DEBUG_INDATA1, "Prev check - Gak, Evil plot, sid:%d not the same as at:%d\n",
+ chk->rec.data.stream_number,
+ prev->rec.data.stream_number);
+ snprintf(msg, sizeof(msg),
+ "Expect SID=%4.4x, got TSN=%8.8x, SID=%4.4x, SSN=%4.4x",
+ prev->rec.data.stream_number,
+ chk->rec.data.TSN_seq,
+ chk->rec.data.stream_number,
+ chk->rec.data.stream_seq);
+ op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg);
+ stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA+SCTP_LOC_7;
+ sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED);
+ *abort_flag = 1;
+ return;
+ }
+ if ((chk->rec.data.rcv_flags & SCTP_DATA_UNORDERED) !=
+ (prev->rec.data.rcv_flags & SCTP_DATA_UNORDERED)) {
+ /*
+ * Huh, need the same ordering here,
+ * they must be the same.
+ */
+ SCTPDBG(SCTP_DEBUG_INDATA1, "Prev check - Gak, Evil plot, U-bit not constant\n");
+ snprintf(msg, sizeof(msg),
+ "Expect U-bit=%d for TSN=%8.8x, got U-bit=%d",
+ (prev->rec.data.rcv_flags & SCTP_DATA_UNORDERED) ? 1 : 0,
+ chk->rec.data.TSN_seq,
+ (chk->rec.data.rcv_flags & SCTP_DATA_UNORDERED) ? 1 : 0);
+ op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg);
+ stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA+SCTP_LOC_7;
+ sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED);
+ *abort_flag = 1;
+ return;
+ }
+ if ((prev->rec.data.rcv_flags & SCTP_DATA_UNORDERED) == 0 &&
+ chk->rec.data.stream_seq !=
+ prev->rec.data.stream_seq) {
+ /*
+ * Huh, need the correct STR here,
+ * they must be the same.
+ */
+ SCTPDBG(SCTP_DEBUG_INDATA1, "Prev check - Gak, Evil plot, sseq:%d not the same as at:%d\n",
+ chk->rec.data.stream_seq,
+ prev->rec.data.stream_seq);
+ snprintf(msg, sizeof(msg),
+ "Expect SSN=%4.4x, got TSN=%8.8x, SID=%4.4x, SSN=%4.4x",
+ prev->rec.data.stream_seq,
+ chk->rec.data.TSN_seq,
+ chk->rec.data.stream_number,
+ chk->rec.data.stream_seq);
+ op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg);
+ stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA+SCTP_LOC_8;
+ sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED);
+ *abort_flag = 1;
+ return;
+ }
+ } else if ((prev->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) ==
+ SCTP_DATA_LAST_FRAG) {
+ /* Insert chk MUST be a FIRST */
+ if ((chk->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) !=
+ SCTP_DATA_FIRST_FRAG) {
+ SCTPDBG(SCTP_DEBUG_INDATA1, "Prev check - Gak, evil plot, its not FIRST and it must be!\n");
+ snprintf(msg, sizeof(msg),
+ "Expect B-bit, got TSN=%8.8x, SID=%4.4x, SSN=%4.4x",
+ chk->rec.data.TSN_seq,
+ chk->rec.data.stream_number,
+ chk->rec.data.stream_seq);
+ op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg);
+ stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA+SCTP_LOC_9;
+ sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED);
+ *abort_flag = 1;
+ return;
+ }
}
}
- } else {
- if (idata_supported) {
- TAILQ_FOREACH(control, &strm->uno_inqueue, next_instrm) {
- if (SCTP_MID_EQ(idata_supported, control->mid, mid)) {
- break;
+ }
+ if (next) {
+ post_tsn = chk->rec.data.TSN_seq + 1;
+ if (post_tsn == next->rec.data.TSN_seq) {
+ /*
+ * Ok the one I am inserting ahead of is my NEXT
+ * one. A bit of valdiation here.
+ */
+ if (next->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) {
+ /* Insert chk MUST be a last fragment */
+ if ((chk->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK)
+ != SCTP_DATA_LAST_FRAG) {
+ SCTPDBG(SCTP_DEBUG_INDATA1, "Next chk - Next is FIRST, we must be LAST\n");
+ SCTPDBG(SCTP_DEBUG_INDATA1, "Gak, Evil plot, its not a last!\n");
+ snprintf(msg, sizeof(msg),
+ "Expect only E-bit, got TSN=%8.8x, SID=%4.4x, SSN=%4.4x",
+ chk->rec.data.TSN_seq,
+ chk->rec.data.stream_number,
+ chk->rec.data.stream_seq);
+ op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg);
+ stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA+SCTP_LOC_10;
+ sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED);
+ *abort_flag = 1;
+ return;
+ }
+ } else if ((next->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) ==
+ SCTP_DATA_MIDDLE_FRAG ||
+ (next->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) ==
+ SCTP_DATA_LAST_FRAG) {
+ /*
+ * Insert chk CAN be MIDDLE or FIRST NOT
+ * LAST
+ */
+ if ((chk->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) ==
+ SCTP_DATA_LAST_FRAG) {
+ SCTPDBG(SCTP_DEBUG_INDATA1, "Next chk - Next is a MIDDLE/LAST\n");
+ SCTPDBG(SCTP_DEBUG_INDATA1, "Gak, Evil plot, new prev chunk is a LAST\n");
+ snprintf(msg, sizeof(msg),
+ "Didn't expect E-bit, got TSN=%8.8x, SID=%4.4x, SSN=%4.4x",
+ chk->rec.data.TSN_seq,
+ chk->rec.data.stream_number,
+ chk->rec.data.stream_seq);
+ op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg);
+ stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA+SCTP_LOC_11;
+ sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED);
+ *abort_flag = 1;
+ return;
+ }
+ if (chk->rec.data.stream_number !=
+ next->rec.data.stream_number) {
+ /*
+ * Huh, need the correct STR here,
+ * they must be the same.
+ */
+ SCTPDBG(SCTP_DEBUG_INDATA1, "Next chk - Gak, Evil plot, ssn:%d not the same as at:%d\n",
+ chk->rec.data.stream_number,
+ next->rec.data.stream_number);
+ snprintf(msg, sizeof(msg),
+ "Required SID %4.4x, got TSN=%8.8x, SID=%4.4x, SSN=%4.4x",
+ next->rec.data.stream_number,
+ chk->rec.data.TSN_seq,
+ chk->rec.data.stream_number,
+ chk->rec.data.stream_seq);
+ op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg);
+ stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA+SCTP_LOC_12;
+ sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED);
+ *abort_flag = 1;
+ return;
+ }
+ if ((chk->rec.data.rcv_flags & SCTP_DATA_UNORDERED) !=
+ (next->rec.data.rcv_flags & SCTP_DATA_UNORDERED)) {
+ /*
+ * Huh, need the same ordering here,
+ * they must be the same.
+ */
+ SCTPDBG(SCTP_DEBUG_INDATA1, "Next check - Gak, Evil plot, U-bit not constant\n");
+ snprintf(msg, sizeof(msg),
+ "Expect U-bit=%d for TSN=%8.8x, got U-bit=%d",
+ (next->rec.data.rcv_flags & SCTP_DATA_UNORDERED) ? 1 : 0,
+ chk->rec.data.TSN_seq,
+ (chk->rec.data.rcv_flags & SCTP_DATA_UNORDERED) ? 1 : 0);
+ op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg);
+ stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA+SCTP_LOC_12;
+ sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED);
+ *abort_flag = 1;
+ return;
+ }
+ if ((next->rec.data.rcv_flags & SCTP_DATA_UNORDERED) == 0 &&
+ chk->rec.data.stream_seq !=
+ next->rec.data.stream_seq) {
+ /*
+ * Huh, need the correct STR here,
+ * they must be the same.
+ */
+ SCTPDBG(SCTP_DEBUG_INDATA1, "Next chk - Gak, Evil plot, sseq:%d not the same as at:%d\n",
+ chk->rec.data.stream_seq,
+ next->rec.data.stream_seq);
+ snprintf(msg, sizeof(msg),
+ "Required SSN %4.4x, got TSN=%8.8x, SID=%4.4x, SSN=%4.4x",
+ next->rec.data.stream_seq,
+ chk->rec.data.TSN_seq,
+ chk->rec.data.stream_number,
+ chk->rec.data.stream_seq);
+ op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg);
+ stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA+SCTP_LOC_13;
+ sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED);
+ *abort_flag = 1;
+ return;
}
}
- } else {
- control = TAILQ_FIRST(&strm->uno_inqueue);
}
}
- return (control);
+ /* Do we need to do some delivery? check */
+ sctp_deliver_reasm_check(stcb, asoc);
+}
+
+/*
+ * This is an unfortunate routine. It checks to make sure a evil guy is not
+ * stuffing us full of bad packet fragments. A broken peer could also do this
+ * but this is doubtful. It is to bad I must worry about evil crackers sigh
+ * :< more cycles.
+ */
+static int
+sctp_does_tsn_belong_to_reasm(struct sctp_association *asoc,
+ uint32_t TSN_seq)
+{
+ struct sctp_tmit_chunk *at;
+ uint32_t tsn_est;
+
+ TAILQ_FOREACH(at, &asoc->reasmqueue, sctp_next) {
+ if (SCTP_TSN_GT(TSN_seq, at->rec.data.TSN_seq)) {
+ /* is it one bigger? */
+ tsn_est = at->rec.data.TSN_seq + 1;
+ if (tsn_est == TSN_seq) {
+ /* yep. It better be a last then */
+ if ((at->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) !=
+ SCTP_DATA_LAST_FRAG) {
+ /*
+ * Ok this guy belongs next to a guy
+ * that is NOT last, it should be a
+ * middle/last, not a complete
+ * chunk.
+ */
+ return (1);
+ } else {
+ /*
+ * This guy is ok since its a LAST
+ * and the new chunk is a fully
+ * self- contained one.
+ */
+ return (0);
+ }
+ }
+ } else if (TSN_seq == at->rec.data.TSN_seq) {
+ /* Software error since I have a dup? */
+ return (1);
+ } else {
+ /*
+ * Ok, 'at' is larger than new chunk but does it
+ * need to be right before it.
+ */
+ tsn_est = TSN_seq + 1;
+ if (tsn_est == at->rec.data.TSN_seq) {
+ /* Yep, It better be a first */
+ if ((at->rec.data.rcv_flags & SCTP_DATA_FRAG_MASK) !=
+ SCTP_DATA_FIRST_FRAG) {
+ return (1);
+ } else {
+ return (0);
+ }
+ }
+ }
+ }
+ return (0);
}
static int
sctp_process_a_data_chunk(struct sctp_tcb *stcb, struct sctp_association *asoc,
- struct mbuf **m, int offset, int chk_length,
- struct sctp_nets *net, uint32_t *high_tsn, int *abort_flag,
- int *break_flag, int last_chunk, uint8_t chk_type)
+ struct mbuf **m, int offset, struct sctp_data_chunk *ch, int chk_length,
+ struct sctp_nets *net, uint32_t *high_tsn, int *abort_flag,
+ int *break_flag, int last_chunk)
{
/* Process a data chunk */
/* struct sctp_tmit_chunk *chk; */
struct sctp_tmit_chunk *chk;
- uint32_t tsn, fsn, gap, mid;
+ uint32_t tsn, gap;
struct mbuf *dmbuf;
int the_len;
int need_reasm_check = 0;
- uint16_t sid;
+ uint16_t strmno, strmseq;
struct mbuf *op_err;
char msg[SCTP_DIAG_INFO_LEN];
- struct sctp_queued_to_read *control, *ncontrol;
- uint32_t ppid;
- uint8_t chk_flags;
- struct sctp_stream_reset_list *liste;
+ struct sctp_queued_to_read *control;
int ordered;
- size_t clen;
- int created_control = 0;
-
- if (chk_type == SCTP_IDATA) {
- struct sctp_idata_chunk *chunk, chunk_buf;
-
- chunk = (struct sctp_idata_chunk *)sctp_m_getptr(*m, offset,
- sizeof(struct sctp_idata_chunk), (uint8_t *)&chunk_buf);
- chk_flags = chunk->ch.chunk_flags;
- clen = sizeof(struct sctp_idata_chunk);
- tsn = ntohl(chunk->dp.tsn);
- sid = ntohs(chunk->dp.sid);
- mid = ntohl(chunk->dp.mid);
- if (chk_flags & SCTP_DATA_FIRST_FRAG) {
- fsn = 0;
- ppid = chunk->dp.ppid_fsn.ppid;
- } else {
- fsn = ntohl(chunk->dp.ppid_fsn.fsn);
- ppid = 0xffffffff; /* Use as an invalid value. */
- }
- } else {
- struct sctp_data_chunk *chunk, chunk_buf;
-
- chunk = (struct sctp_data_chunk *)sctp_m_getptr(*m, offset,
- sizeof(struct sctp_data_chunk), (uint8_t *)&chunk_buf);
- chk_flags = chunk->ch.chunk_flags;
- clen = sizeof(struct sctp_data_chunk);
- tsn = ntohl(chunk->dp.tsn);
- sid = ntohs(chunk->dp.sid);
- mid = (uint32_t)(ntohs(chunk->dp.ssn));
- fsn = tsn;
- ppid = chunk->dp.ppid;
- }
- if ((size_t)chk_length == clen) {
- /*
- * Need to send an abort since we had a
- * empty data chunk.
- */
- op_err = sctp_generate_no_user_data_cause(tsn);
- stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_14;
- sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED);
- *abort_flag = 1;
- return (0);
- }
- if ((chk_flags & SCTP_DATA_SACK_IMMEDIATELY) == SCTP_DATA_SACK_IMMEDIATELY) {
+ uint32_t protocol_id;
+ uint8_t chunk_flags;
+ struct sctp_stream_reset_list *liste;
+
+ chk = NULL;
+ tsn = ntohl(ch->dp.tsn);
+ chunk_flags = ch->ch.chunk_flags;
+ if ((chunk_flags & SCTP_DATA_SACK_IMMEDIATELY) == SCTP_DATA_SACK_IMMEDIATELY) {
asoc->send_sack = 1;
}
- ordered = ((chk_flags & SCTP_DATA_UNORDERED) == 0);
+ protocol_id = ch->dp.protocol_id;
+ ordered = ((chunk_flags & SCTP_DATA_UNORDERED) == 0);
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) {
sctp_log_map(tsn, asoc->cumulative_tsn, asoc->highest_tsn_inside_map, SCTP_MAP_TSN_ENTERS);
}
if (stcb == NULL) {
return (0);
}
- SCTP_LTRACE_CHK(stcb->sctp_ep, stcb, chk_type, tsn);
+ SCTP_LTRACE_CHK(stcb->sctp_ep, stcb, ch->ch.chunk_type, tsn);
if (SCTP_TSN_GE(asoc->cumulative_tsn, tsn)) {
/* It is a duplicate */
SCTP_STAT_INCR(sctps_recvdupdata);
if (asoc->numduptsns < SCTP_MAX_DUP_TSNS) {
/* Record a dup for the next outbound sack */
asoc->dup_tsns[asoc->numduptsns] = tsn;
asoc->numduptsns++;
}
@@ -1787,119 +1365,16 @@ sctp_process_a_data_chunk(struct sctp_tc
return (0);
}
/*
* Now before going further we see if there is room. If NOT then we
* MAY let one through only IF this TSN is the one we are waiting
* for on a partial delivery API.
*/
- /* Is the stream valid? */
- if (sid >= asoc->streamincnt) {
- struct sctp_error_invalid_stream *cause;
-
- op_err = sctp_get_mbuf_for_msg(sizeof(struct sctp_error_invalid_stream),
- 0, M_NOWAIT, 1, MT_DATA);
- if (op_err != NULL) {
- /* add some space up front so prepend will work well */
- SCTP_BUF_RESV_UF(op_err, sizeof(struct sctp_chunkhdr));
- cause = mtod(op_err, struct sctp_error_invalid_stream *);
- /*
- * Error causes are just param's and this one has
- * two back to back phdr, one with the error type
- * and size, the other with the streamid and a rsvd
- */
- SCTP_BUF_LEN(op_err) = sizeof(struct sctp_error_invalid_stream);
- cause->cause.code = htons(SCTP_CAUSE_INVALID_STREAM);
- cause->cause.length = htons(sizeof(struct sctp_error_invalid_stream));
- cause->stream_id = htons(sid);
- cause->reserved = htons(0);
- sctp_queue_op_err(stcb, op_err);
- }
- SCTP_STAT_INCR(sctps_badsid);
- SCTP_TCB_LOCK_ASSERT(stcb);
- SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, gap);
- if (SCTP_TSN_GT(tsn, asoc->highest_tsn_inside_nr_map)) {
- asoc->highest_tsn_inside_nr_map = tsn;
- }
- if (tsn == (asoc->cumulative_tsn + 1)) {
- /* Update cum-ack */
- asoc->cumulative_tsn = tsn;
- }
- return (0);
- }
- /*
- * If its a fragmented message, lets see if we can
- * find the control on the reassembly queues.
- */
- if ((chk_type == SCTP_IDATA) &&
- ((chk_flags & SCTP_DATA_FIRST_FRAG) == 0) &&
- (fsn == 0)) {
- /*
- * The first *must* be fsn 0, and other
- * (middle/end) pieces can *not* be fsn 0.
- * XXX: This can happen in case of a wrap around.
- * Ignore is for now.
- */
- snprintf(msg, sizeof(msg), "FSN zero for MID=%8.8x, but flags=%2.2x",
- mid, chk_flags);
- goto err_out;
- }
- control = sctp_find_reasm_entry(&asoc->strmin[sid], mid, ordered, asoc->idata_supported);
- SCTPDBG(SCTP_DEBUG_XXX, "chunk_flags:0x%x look for control on queues %p\n",
- chk_flags, control);
- if ((chk_flags & SCTP_DATA_NOT_FRAG) != SCTP_DATA_NOT_FRAG) {
- /* See if we can find the re-assembly entity */
- if (control != NULL) {
- /* We found something, does it belong? */
- if (ordered && (mid != control->mid)) {
- snprintf(msg, sizeof(msg), "Reassembly problem (MID=%8.8x)", mid);
- err_out:
- op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg);
- stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_15;
- sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED);
- *abort_flag = 1;
- return (0);
- }
- if (ordered && ((control->sinfo_flags >> 8) & SCTP_DATA_UNORDERED)) {
- /* We can't have a switched order with an unordered chunk */
- snprintf(msg, sizeof(msg), "All fragments of a user message must be ordered or unordered (TSN=%8.8x)",
- tsn);
- goto err_out;
- }
- if (!ordered && (((control->sinfo_flags >> 8) & SCTP_DATA_UNORDERED) == 0)) {
- /* We can't have a switched unordered with a ordered chunk */
- snprintf(msg, sizeof(msg), "All fragments of a user message must be ordered or unordered (TSN=%8.8x)",
- tsn);
- goto err_out;
- }
- }
- } else {
- /* Its a complete segment. Lets validate we
- * don't have a re-assembly going on with
- * the same Stream/Seq (for ordered) or in
- * the same Stream for unordered.
- */
- if (control != NULL) {
- if (ordered || asoc->idata_supported) {
- SCTPDBG(SCTP_DEBUG_XXX, "chunk_flags: 0x%x dup detected on MID: %u\n",
- chk_flags, mid);
- snprintf(msg, sizeof(msg), "Duplicate MID=%8.8x detected.", mid);
- goto err_out;
- } else {
- if ((tsn == control->fsn_included + 1) &&
- (control->end_added == 0)) {
- snprintf(msg, sizeof(msg), "Illegal message sequence, missing end for MID: %8.8x", control->fsn_included);
- goto err_out;
- } else {
- control = NULL;
- }
- }
- }
- }
/* now do the tests */
if (((asoc->cnt_on_all_streams +
asoc->cnt_on_reasm_queue +
asoc->cnt_msg_on_sb) >= SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue)) ||
(((int)asoc->my_rwnd) <= 0)) {
/*
* When we have NO room in the rwnd we check to make sure
* the reader is doing its job...
@@ -1922,121 +1397,132 @@ sctp_process_a_data_chunk(struct sctp_tc
}
#endif
sctp_sorwakeup(stcb->sctp_ep, stcb->sctp_socket);
#if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
SCTP_SOCKET_UNLOCK(so, 1);
#endif
}
/* now is it in the mapping array of what we have accepted? */
- if (chk_type == SCTP_DATA) {
- if (SCTP_TSN_GT(tsn, asoc->highest_tsn_inside_map) &&
- SCTP_TSN_GT(tsn, asoc->highest_tsn_inside_nr_map)) {
- /* Nope not in the valid range dump it */
- dump_packet:
- sctp_set_rwnd(stcb, asoc);
- if ((asoc->cnt_on_all_streams +
- asoc->cnt_on_reasm_queue +
- asoc->cnt_msg_on_sb) >= SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue)) {
- SCTP_STAT_INCR(sctps_datadropchklmt);
- } else {
- SCTP_STAT_INCR(sctps_datadroprwnd);
- }
- *break_flag = 1;
- return (0);
+ if (SCTP_TSN_GT(tsn, asoc->highest_tsn_inside_map) &&
+ SCTP_TSN_GT(tsn, asoc->highest_tsn_inside_nr_map)) {
+ /* Nope not in the valid range dump it */
+ sctp_set_rwnd(stcb, asoc);
+ if ((asoc->cnt_on_all_streams +
+ asoc->cnt_on_reasm_queue +
+ asoc->cnt_msg_on_sb) >= SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue)) {
+ SCTP_STAT_INCR(sctps_datadropchklmt);
+ } else {
+ SCTP_STAT_INCR(sctps_datadroprwnd);
}
- } else {
- if (control == NULL) {
- goto dump_packet;
- }
- if (SCTP_TSN_GT(fsn, control->top_fsn)) {
- goto dump_packet;
- }
+ *break_flag = 1;
+ return (0);
}
}
+ strmno = ntohs(ch->dp.stream_id);
+ if (strmno >= asoc->streamincnt) {
+ struct sctp_paramhdr *phdr;
+ struct mbuf *mb;
+
+ mb = sctp_get_mbuf_for_msg((sizeof(struct sctp_paramhdr) * 2),
+ 0, M_NOWAIT, 1, MT_DATA);
+ if (mb != NULL) {
+ /* add some space up front so prepend will work well */
+ SCTP_BUF_RESV_UF(mb, sizeof(struct sctp_chunkhdr));
+ phdr = mtod(mb, struct sctp_paramhdr *);
+ /*
+ * Error causes are just param's and this one has
+ * two back to back phdr, one with the error type
+ * and size, the other with the streamid and a rsvd
+ */
+ SCTP_BUF_LEN(mb) = (sizeof(struct sctp_paramhdr) * 2);
+ phdr->param_type = htons(SCTP_CAUSE_INVALID_STREAM);
+ phdr->param_length =
+ htons(sizeof(struct sctp_paramhdr) * 2);
+ phdr++;
+ /* We insert the stream in the type field */
+ phdr->param_type = ch->dp.stream_id;
+ /* And set the length to 0 for the rsvd field */
+ phdr->param_length = 0;
+ sctp_queue_op_err(stcb, mb);
+ }
+ SCTP_STAT_INCR(sctps_badsid);
+ SCTP_TCB_LOCK_ASSERT(stcb);
+ SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, gap);
+ if (SCTP_TSN_GT(tsn, asoc->highest_tsn_inside_nr_map)) {
+ asoc->highest_tsn_inside_nr_map = tsn;
+ }
+ if (tsn == (asoc->cumulative_tsn + 1)) {
+ /* Update cum-ack */
+ asoc->cumulative_tsn = tsn;
+ }
+ return (0);
+ }
+ /*
+ * Before we continue lets validate that we are not being fooled by
+ * an evil attacker. We can only have 4k chunks based on our TSN
+ * spread allowed by the mapping array 512 * 8 bits, so there is no
+ * way our stream sequence numbers could have wrapped. We of course
+ * only validate the FIRST fragment so the bit must be set.
+ */
+ strmseq = ntohs(ch->dp.stream_sequence);
#ifdef SCTP_ASOCLOG_OF_TSNS
SCTP_TCB_LOCK_ASSERT(stcb);
if (asoc->tsn_in_at >= SCTP_TSN_LOG_SIZE) {
asoc->tsn_in_at = 0;
asoc->tsn_in_wrapped = 1;
}
asoc->in_tsnlog[asoc->tsn_in_at].tsn = tsn;
- asoc->in_tsnlog[asoc->tsn_in_at].strm = sid;
- asoc->in_tsnlog[asoc->tsn_in_at].seq = mid;
+ asoc->in_tsnlog[asoc->tsn_in_at].strm = strmno;
+ asoc->in_tsnlog[asoc->tsn_in_at].seq = strmseq;
asoc->in_tsnlog[asoc->tsn_in_at].sz = chk_length;
asoc->in_tsnlog[asoc->tsn_in_at].flgs = chunk_flags;
asoc->in_tsnlog[asoc->tsn_in_at].stcb = (void *)stcb;
asoc->in_tsnlog[asoc->tsn_in_at].in_pos = asoc->tsn_in_at;
asoc->in_tsnlog[asoc->tsn_in_at].in_out = 1;
asoc->tsn_in_at++;
#endif
- /*
- * Before we continue lets validate that we are not being fooled by
- * an evil attacker. We can only have Nk chunks based on our TSN
- * spread allowed by the mapping array N * 8 bits, so there is no
- * way our stream sequence numbers could have wrapped. We of course
- * only validate the FIRST fragment so the bit must be set.
- */
- if ((chk_flags & SCTP_DATA_FIRST_FRAG) &&
+ if ((chunk_flags & SCTP_DATA_FIRST_FRAG) &&
(TAILQ_EMPTY(&asoc->resetHead)) &&
- (chk_flags & SCTP_DATA_UNORDERED) == 0 &&
- SCTP_MID_GE(asoc->idata_supported, asoc->strmin[sid].last_mid_delivered, mid)) {
+ (chunk_flags & SCTP_DATA_UNORDERED) == 0 &&
+ SCTP_SSN_GE(asoc->strmin[strmno].last_sequence_delivered, strmseq)) {
/* The incoming sseq is behind where we last delivered? */
- SCTPDBG(SCTP_DEBUG_INDATA1, "EVIL/Broken-Dup S-SEQ: %u delivered: %u from peer, Abort!\n",
- mid, asoc->strmin[sid].last_mid_delivered);
-
- if (asoc->idata_supported) {
- snprintf(msg, sizeof(msg), "Delivered MID=%8.8x, got TSN=%8.8x, SID=%4.4x, MID=%8.8x",
- asoc->strmin[sid].last_mid_delivered,
- tsn,
- sid,
- mid);
- } else {
- snprintf(msg, sizeof(msg), "Delivered SSN=%4.4x, got TSN=%8.8x, SID=%4.4x, SSN=%4.4x",
- (uint16_t)asoc->strmin[sid].last_mid_delivered,
- tsn,
- sid,
- (uint16_t)mid);
- }
+ SCTPDBG(SCTP_DEBUG_INDATA1, "EVIL/Broken-Dup S-SEQ:%d delivered:%d from peer, Abort!\n",
+ strmseq, asoc->strmin[strmno].last_sequence_delivered);
+
+ snprintf(msg, sizeof(msg), "Delivered SSN=%4.4x, got TSN=%8.8x, SID=%4.4x, SSN=%4.4x",
+ asoc->strmin[strmno].last_sequence_delivered,
+ tsn, strmno, strmseq);
op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg);
- stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_16;
+ stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA+SCTP_LOC_14;
sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED);
*abort_flag = 1;
return (0);
}
- if (chk_type == SCTP_IDATA) {
- the_len = (chk_length - sizeof(struct sctp_idata_chunk));
- } else {
- the_len = (chk_length - sizeof(struct sctp_data_chunk));
- }
+ /************************************
+ * From here down we may find ch-> invalid
+ * so its a good idea NOT to use it.
+ *************************************/
+
+ the_len = (chk_length - sizeof(struct sctp_data_chunk));
if (last_chunk == 0) {
- if (chk_type == SCTP_IDATA) {
- dmbuf = SCTP_M_COPYM(*m,
- (offset + sizeof(struct sctp_idata_chunk)),
- the_len, M_NOWAIT);
- } else {
- dmbuf = SCTP_M_COPYM(*m,
- (offset + sizeof(struct sctp_data_chunk)),
- the_len, M_NOWAIT);
- }
+ dmbuf = SCTP_M_COPYM(*m,
+ (offset + sizeof(struct sctp_data_chunk)),
+ the_len, M_NOWAIT);
#ifdef SCTP_MBUF_LOGGING
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MBUF_LOGGING_ENABLE) {
sctp_log_mbc(dmbuf, SCTP_MBUF_ICOPY);
}
#endif
} else {
/* We can steal the last chunk */
int l_len;
dmbuf = *m;
/* lop off the top part */
- if (chk_type == SCTP_IDATA) {
- m_adj(dmbuf, (offset + sizeof(struct sctp_idata_chunk)));
- } else {
- m_adj(dmbuf, (offset + sizeof(struct sctp_data_chunk)));
- }
+ m_adj(dmbuf, (offset + sizeof(struct sctp_data_chunk)));
if (SCTP_BUF_NEXT(dmbuf) == NULL) {
l_len = SCTP_BUF_LEN(dmbuf);
} else {
/* need to count up the size hopefully
* does not hit this to often :-0
*/
struct mbuf *lat;
@@ -2049,293 +1535,418 @@ sctp_process_a_data_chunk(struct sctp_tc
/* Trim the end round bytes off too */
m_adj(dmbuf, -(l_len - the_len));
}
}
if (dmbuf == NULL) {
SCTP_STAT_INCR(sctps_nomem);
return (0);
}
- /*
- * Now no matter what, we need a control, get one
- * if we don't have one (we may have gotten it
- * above when we found the message was fragmented
- */
- if (control == NULL) {
- sctp_alloc_a_readq(stcb, control);
- sctp_build_readq_entry_mac(control, stcb, asoc->context, net, tsn,
- ppid,
- sid,
- chk_flags,
- NULL, fsn, mid);
- if (control == NULL) {
- SCTP_STAT_INCR(sctps_nomem);
- return (0);
- }
- if ((chk_flags & SCTP_DATA_NOT_FRAG) == SCTP_DATA_NOT_FRAG) {
- struct mbuf *mm;
-
- control->data = dmbuf;
- for (mm = control->data; mm; mm = mm->m_next) {
- control->length += SCTP_BUF_LEN(mm);
- }
- control->tail_mbuf = NULL;
- control->end_added = 1;
- control->last_frag_seen = 1;
- control->first_frag_seen = 1;
- control->fsn_included = fsn;
- control->top_fsn = fsn;
- }
- created_control = 1;
- }
- SCTPDBG(SCTP_DEBUG_XXX, "chunk_flags: 0x%x ordered: %d MID: %u control: %p\n",
- chk_flags, ordered, mid, control);
- if ((chk_flags & SCTP_DATA_NOT_FRAG) == SCTP_DATA_NOT_FRAG &&
+ if ((chunk_flags & SCTP_DATA_NOT_FRAG) == SCTP_DATA_NOT_FRAG &&
+ asoc->fragmented_delivery_inprogress == 0 &&
TAILQ_EMPTY(&asoc->resetHead) &&
((ordered == 0) ||
- (SCTP_MID_EQ(asoc->idata_supported, asoc->strmin[sid].last_mid_delivered + 1, mid) &&
- TAILQ_EMPTY(&asoc->strmin[sid].inqueue)))) {
+ ((uint16_t)(asoc->strmin[strmno].last_sequence_delivered + 1) == strmseq &&
+ TAILQ_EMPTY(&asoc->strmin[strmno].inqueue)))) {
/* Candidate for express delivery */
/*
* Its not fragmented, No PD-API is up, Nothing in the
* delivery queue, Its un-ordered OR ordered and the next to
* deliver AND nothing else is stuck on the stream queue,
* And there is room for it in the socket buffer. Lets just
* stuff it up the buffer....
*/
+
+ /* It would be nice to avoid this copy if we could :< */
+ sctp_alloc_a_readq(stcb, control);
+ sctp_build_readq_entry_mac(control, stcb, asoc->context, net, tsn,
+ protocol_id,
+ strmno, strmseq,
+ chunk_flags,
+ dmbuf);
+ if (control == NULL) {
+ goto failed_express_del;
+ }
SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, gap);
if (SCTP_TSN_GT(tsn, asoc->highest_tsn_inside_nr_map)) {
asoc->highest_tsn_inside_nr_map = tsn;
}
- SCTPDBG(SCTP_DEBUG_XXX, "Injecting control: %p to be read (MID: %u)\n",
- control, mid);
-
sctp_add_to_readq(stcb->sctp_ep, stcb,
control, &stcb->sctp_socket->so_rcv,
1, SCTP_READ_LOCK_NOT_HELD, SCTP_SO_NOT_LOCKED);
- if ((chk_flags & SCTP_DATA_UNORDERED) == 0) {
+ if ((chunk_flags & SCTP_DATA_UNORDERED) == 0) {
/* for ordered, bump what we delivered */
- asoc->strmin[sid].last_mid_delivered++;
+ asoc->strmin[strmno].last_sequence_delivered++;
}
SCTP_STAT_INCR(sctps_recvexpress);
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_STR_LOGGING_ENABLE) {
- sctp_log_strm_del_alt(stcb, tsn, mid, sid,
+ sctp_log_strm_del_alt(stcb, tsn, strmseq, strmno,
SCTP_STR_LOG_FROM_EXPRS_DEL);
}
control = NULL;
+
goto finish_express_del;
}
-
- /* Now will we need a chunk too? */
- if ((chk_flags & SCTP_DATA_NOT_FRAG) != SCTP_DATA_NOT_FRAG) {
- sctp_alloc_a_chunk(stcb, chk);
- if (chk == NULL) {
- /* No memory so we drop the chunk */
- SCTP_STAT_INCR(sctps_nomem);
- if (last_chunk == 0) {
- /* we copied it, free the copy */
- sctp_m_freem(dmbuf);
- }
- return (0);
+failed_express_del:
+ /* If we reach here this is a new chunk */
+ chk = NULL;
+ control = NULL;
+ /* Express for fragmented delivery? */
+ if ((asoc->fragmented_delivery_inprogress) &&
+ (stcb->asoc.control_pdapi) &&
+ (asoc->str_of_pdapi == strmno) &&
+ (asoc->ssn_of_pdapi == strmseq)
+ ) {
+ control = stcb->asoc.control_pdapi;
+ if ((chunk_flags & SCTP_DATA_FIRST_FRAG) == SCTP_DATA_FIRST_FRAG) {
+ /* Can't be another first? */
+ goto failed_pdapi_express_del;
}
- chk->rec.data.tsn = tsn;
- chk->no_fr_allowed = 0;
- chk->rec.data.fsn = fsn;
- chk->rec.data.mid = mid;
- chk->rec.data.sid = sid;
- chk->rec.data.ppid = ppid;
- chk->rec.data.context = stcb->asoc.context;
- chk->rec.data.doing_fast_retransmit = 0;
- chk->rec.data.rcv_flags = chk_flags;
- chk->asoc = asoc;
- chk->send_size = the_len;
- chk->whoTo = net;
- SCTPDBG(SCTP_DEBUG_XXX, "Building ck: %p for control: %p to be read (MID: %u)\n",
- chk,
- control, mid);
- atomic_add_int(&net->ref_count, 1);
- chk->data = dmbuf;
+ if (tsn == (control->sinfo_tsn + 1)) {
+ /* Yep, we can add it on */
+ int end = 0;
+
+ if (chunk_flags & SCTP_DATA_LAST_FRAG) {
+ end = 1;
+ }
+ if (sctp_append_to_readq(stcb->sctp_ep, stcb, control, dmbuf, end,
+ tsn,
+ &stcb->sctp_socket->so_rcv)) {
+ SCTP_PRINTF("Append fails end:%d\n", end);
+ goto failed_pdapi_express_del;
+ }
+
+ SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, gap);
+ if (SCTP_TSN_GT(tsn, asoc->highest_tsn_inside_nr_map)) {
+ asoc->highest_tsn_inside_nr_map = tsn;
+ }
+ SCTP_STAT_INCR(sctps_recvexpressm);
+ asoc->tsn_last_delivered = tsn;
+ asoc->fragment_flags = chunk_flags;
+ asoc->tsn_of_pdapi_last_delivered = tsn;
+ asoc->last_flags_delivered = chunk_flags;
+ asoc->last_strm_seq_delivered = strmseq;
+ asoc->last_strm_no_delivered = strmno;
+ if (end) {
+ /* clean up the flags and such */
+ asoc->fragmented_delivery_inprogress = 0;
+ if ((chunk_flags & SCTP_DATA_UNORDERED) == 0) {
+ asoc->strmin[strmno].last_sequence_delivered++;
+ }
+ stcb->asoc.control_pdapi = NULL;
+ if (TAILQ_EMPTY(&asoc->reasmqueue) == 0) {
+ /* There could be another message ready */
+ need_reasm_check = 1;
+ }
+ }
+ control = NULL;
+ goto finish_express_del;
+ }
}
- /* Set the appropriate TSN mark */
+ failed_pdapi_express_del:
+ control = NULL;
if (SCTP_BASE_SYSCTL(sctp_do_drain) == 0) {
SCTP_SET_TSN_PRESENT(asoc->nr_mapping_array, gap);
if (SCTP_TSN_GT(tsn, asoc->highest_tsn_inside_nr_map)) {
asoc->highest_tsn_inside_nr_map = tsn;
}
} else {
SCTP_SET_TSN_PRESENT(asoc->mapping_array, gap);
if (SCTP_TSN_GT(tsn, asoc->highest_tsn_inside_map)) {
asoc->highest_tsn_inside_map = tsn;
}
}
- /* Now is it complete (i.e. not fragmented)? */
- if ((chk_flags & SCTP_DATA_NOT_FRAG) == SCTP_DATA_NOT_FRAG) {
- /*
- * Special check for when streams are resetting. We
- * could be more smart about this and check the
- * actual stream to see if it is not being reset..
- * that way we would not create a HOLB when amongst
- * streams being reset and those not being reset.
- *
- */
- if (((liste = TAILQ_FIRST(&asoc->resetHead)) != NULL) &&
- SCTP_TSN_GT(tsn, liste->tsn)) {
+ if ((chunk_flags & SCTP_DATA_NOT_FRAG) != SCTP_DATA_NOT_FRAG) {
+ sctp_alloc_a_chunk(stcb, chk);
+ if (chk == NULL) {
+ /* No memory so we drop the chunk */
+ SCTP_STAT_INCR(sctps_nomem);
+ if (last_chunk == 0) {
+ /* we copied it, free the copy */
+ sctp_m_freem(dmbuf);
+ }
+ return (0);
+ }
+ chk->rec.data.TSN_seq = tsn;
+ chk->no_fr_allowed = 0;
+ chk->rec.data.stream_seq = strmseq;
+ chk->rec.data.stream_number = strmno;
+ chk->rec.data.payloadtype = protocol_id;
+ chk->rec.data.context = stcb->asoc.context;
+ chk->rec.data.doing_fast_retransmit = 0;
+ chk->rec.data.rcv_flags = chunk_flags;
+ chk->asoc = asoc;
+ chk->send_size = the_len;
+ chk->whoTo = net;
+ atomic_add_int(&net->ref_count, 1);
+ chk->data = dmbuf;
+ } else {
+ sctp_alloc_a_readq(stcb, control);
+ sctp_build_readq_entry_mac(control, stcb, asoc->context, net, tsn,
+ protocol_id,
+ strmno, strmseq,
+ chunk_flags,
+ dmbuf);
+ if (control == NULL) {
+ /* No memory so we drop the chunk */
+ SCTP_STAT_INCR(sctps_nomem);
+ if (last_chunk == 0) {
+ /* we copied it, free the copy */
+ sctp_m_freem(dmbuf);
+ }
+ return (0);
+ }
+ control->length = the_len;
+ }
+
+ /* Mark it as received */
+ /* Now queue it where it belongs */
+ if (control != NULL) {
+ /* First a sanity check */
+ if (asoc->fragmented_delivery_inprogress) {
/*
- * yep its past where we need to reset... go
- * ahead and queue it.
+ * Ok, we have a fragmented delivery in progress if
+ * this chunk is next to deliver OR belongs in our
+ * view to the reassembly, the peer is evil or
+ * broken.
*/
- if (TAILQ_EMPTY(&asoc->pending_reply_queue)) {
- /* first one on */
- TAILQ_INSERT_TAIL(&asoc->pending_reply_queue, control, next);
- } else {
- struct sctp_queued_to_read *lcontrol, *nlcontrol;
- unsigned char inserted = 0;
- TAILQ_FOREACH_SAFE(lcontrol, &asoc->pending_reply_queue, next, nlcontrol) {
- if (SCTP_TSN_GT(control->sinfo_tsn, lcontrol->sinfo_tsn)) {
-
- continue;
- } else {
- /* found it */
- TAILQ_INSERT_BEFORE(lcontrol, control, next);
- inserted = 1;
- break;
- }
+ uint32_t estimate_tsn;
+
+ estimate_tsn = asoc->tsn_last_delivered + 1;
+ if (TAILQ_EMPTY(&asoc->reasmqueue) &&
+ (estimate_tsn == control->sinfo_tsn)) {
+ /* Evil/Broke peer */
+ sctp_m_freem(control->data);
+ control->data = NULL;
+ if (control->whoFrom) {
+ sctp_free_remote_addr(control->whoFrom);
+ control->whoFrom = NULL;
}
- if (inserted == 0) {
- /*
- * must be put at end, use
- * prevP (all setup from
- * loop) to setup nextP.
- */
- TAILQ_INSERT_TAIL(&asoc->pending_reply_queue, control, next);
- }
- }
- goto finish_express_del;
- }
- if (chk_flags & SCTP_DATA_UNORDERED) {
- /* queue directly into socket buffer */
- SCTPDBG(SCTP_DEBUG_XXX, "Unordered data to be read control: %p MID: %u\n",
- control, mid);
- sctp_mark_non_revokable(asoc, control->sinfo_tsn);
- sctp_add_to_readq(stcb->sctp_ep, stcb,
- control,
- &stcb->sctp_socket->so_rcv, 1,
- SCTP_READ_LOCK_NOT_HELD, SCTP_SO_NOT_LOCKED);
-
- } else {
- SCTPDBG(SCTP_DEBUG_XXX, "Queue control: %p for reordering MID: %u\n", control,
- mid);
- sctp_queue_data_to_stream(stcb, asoc, control, abort_flag, &need_reasm_check);
- if (*abort_flag) {
+ sctp_free_a_readq(stcb, control);
+ snprintf(msg, sizeof(msg), "Reas. queue emtpy, got TSN=%8.8x, SID=%4.4x, SSN=%4.4x",
+ tsn, strmno, strmseq);
+ op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg);
+ stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA+SCTP_LOC_15;
+ sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED);
+ *abort_flag = 1;
if (last_chunk) {
*m = NULL;
}
return (0);
+ } else {
+ if (sctp_does_tsn_belong_to_reasm(asoc, control->sinfo_tsn)) {
+ sctp_m_freem(control->data);
+ control->data = NULL;
+ if (control->whoFrom) {
+ sctp_free_remote_addr(control->whoFrom);
+ control->whoFrom = NULL;
+ }
+ sctp_free_a_readq(stcb, control);
+ snprintf(msg, sizeof(msg), "PD ongoing, got TSN=%8.8x, SID=%4.4x, SSN=%4.4x",
+ tsn, strmno, strmseq);
+ op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg);
+ stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA+SCTP_LOC_16;
+ sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED);
+ *abort_flag = 1;
+ if (last_chunk) {
+ *m = NULL;
+ }
+ return (0);
+ }
+ }
+ } else {
+ /* No PDAPI running */
+ if (!TAILQ_EMPTY(&asoc->reasmqueue)) {
+ /*
+ * Reassembly queue is NOT empty validate
+ * that this tsn does not need to be in
+ * reasembly queue. If it does then our peer
+ * is broken or evil.
+ */
+ if (sctp_does_tsn_belong_to_reasm(asoc, control->sinfo_tsn)) {
+ sctp_m_freem(control->data);
+ control->data = NULL;
+ if (control->whoFrom) {
+ sctp_free_remote_addr(control->whoFrom);
+ control->whoFrom = NULL;
+ }
+ sctp_free_a_readq(stcb, control);
+ snprintf(msg, sizeof(msg), "No PD ongoing, got TSN=%8.8x, SID=%4.4x, SSN=%4.4x",
+ tsn, strmno, strmseq);
+ op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg);
+ stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA+SCTP_LOC_17;
+ sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED);
+ *abort_flag = 1;
+ if (last_chunk) {
+ *m = NULL;
+ }
+ return (0);
+ }
}
}
- goto finish_express_del;
- }
- /* If we reach here its a reassembly */
- need_reasm_check = 1;
- SCTPDBG(SCTP_DEBUG_XXX,
- "Queue data to stream for reasm control: %p MID: %u\n",
- control, mid);
- sctp_queue_data_for_reasm(stcb, asoc, control, chk, created_control, abort_flag, tsn);
- if (*abort_flag) {
- /*
- * the assoc is now gone and chk was put onto the
- * reasm queue, which has all been freed.
- */
- if (last_chunk) {
- *m = NULL;
+ /* ok, if we reach here we have passed the sanity checks */
+ if (chunk_flags & SCTP_DATA_UNORDERED) {
+ /* queue directly into socket buffer */
+ sctp_mark_non_revokable(asoc, control->sinfo_tsn);
+ sctp_add_to_readq(stcb->sctp_ep, stcb,
+ control,
+ &stcb->sctp_socket->so_rcv, 1, SCTP_READ_LOCK_NOT_HELD, SCTP_SO_NOT_LOCKED);
+ } else {
+ /*
+ * Special check for when streams are resetting. We
+ * could be more smart about this and check the
+ * actual stream to see if it is not being reset..
+ * that way we would not create a HOLB when amongst
+ * streams being reset and those not being reset.
+ *
+ * We take complete messages that have a stream reset
+ * intervening (aka the TSN is after where our
+ * cum-ack needs to be) off and put them on a
+ * pending_reply_queue. The reassembly ones we do
+ * not have to worry about since they are all sorted
+ * and proceessed by TSN order. It is only the
+ * singletons I must worry about.
+ */
+ if (((liste = TAILQ_FIRST(&asoc->resetHead)) != NULL) &&
+ SCTP_TSN_GT(tsn, liste->tsn)) {
+ /*
+ * yep its past where we need to reset... go
+ * ahead and queue it.
+ */
+ if (TAILQ_EMPTY(&asoc->pending_reply_queue)) {
+ /* first one on */
+ TAILQ_INSERT_TAIL(&asoc->pending_reply_queue, control, next);
+ } else {
+ struct sctp_queued_to_read *ctlOn, *nctlOn;
+ unsigned char inserted = 0;
+
+ TAILQ_FOREACH_SAFE(ctlOn, &asoc->pending_reply_queue, next, nctlOn) {
+ if (SCTP_TSN_GT(control->sinfo_tsn, ctlOn->sinfo_tsn)) {
+ continue;
+ } else {
+ /* found it */
+ TAILQ_INSERT_BEFORE(ctlOn, control, next);
+ inserted = 1;
+ break;
+ }
+ }
+ if (inserted == 0) {
+ /*
+ * must be put at end, use
+ * prevP (all setup from
+ * loop) to setup nextP.
+ */
+ TAILQ_INSERT_TAIL(&asoc->pending_reply_queue, control, next);
+ }
+ }
+ } else {
+ sctp_queue_data_to_stream(stcb, asoc, control, abort_flag);
+ if (*abort_flag) {
+ if (last_chunk) {
+ *m = NULL;
+ }
+ return (0);
+ }
+ }
}
- return (0);
+ } else {
+ /* Into the re-assembly queue */
+ sctp_queue_data_for_reasm(stcb, asoc, chk, abort_flag);
+ if (*abort_flag) {
+ /*
+ * the assoc is now gone and chk was put onto the
+ * reasm queue, which has all been freed.
+ */
+ if (last_chunk) {
+ *m = NULL;
+ }
+ return (0);
+ }
}
finish_express_del:
- /* Here we tidy up things */
if (tsn == (asoc->cumulative_tsn + 1)) {
/* Update cum-ack */
asoc->cumulative_tsn = tsn;
}
if (last_chunk) {
*m = NULL;
}
if (ordered) {
SCTP_STAT_INCR_COUNTER64(sctps_inorderchunks);
} else {
SCTP_STAT_INCR_COUNTER64(sctps_inunorderchunks);
}
SCTP_STAT_INCR(sctps_recvdata);
/* Set it present please */
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_STR_LOGGING_ENABLE) {
- sctp_log_strm_del_alt(stcb, tsn, mid, sid, SCTP_STR_LOG_FROM_MARK_TSN);
+ sctp_log_strm_del_alt(stcb, tsn, strmseq, strmno, SCTP_STR_LOG_FROM_MARK_TSN);
}
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) {
sctp_log_map(asoc->mapping_array_base_tsn, asoc->cumulative_tsn,
asoc->highest_tsn_inside_map, SCTP_MAP_PREPARE_SLIDE);
}
- if (need_reasm_check) {
- (void)sctp_deliver_reasm_check(stcb, asoc, &asoc->strmin[sid], SCTP_READ_LOCK_NOT_HELD);
- need_reasm_check = 0;
- }
/* check the special flag for stream resets */
if (((liste = TAILQ_FIRST(&asoc->resetHead)) != NULL) &&
SCTP_TSN_GE(asoc->cumulative_tsn, liste->tsn)) {
/*
* we have finished working through the backlogged TSN's now
* time to reset streams. 1: call reset function. 2: free
* pending_reply space 3: distribute any chunks in
* pending_reply_queue.
*/
+ struct sctp_queued_to_read *ctl, *nctl;
+
sctp_reset_in_stream(stcb, liste->number_entries, liste->list_of_streams);
TAILQ_REMOVE(&asoc->resetHead, liste, next_resp);
- sctp_send_deferred_reset_response(stcb, liste, SCTP_STREAM_RESET_RESULT_PERFORMED);
SCTP_FREE(liste, SCTP_M_STRESET);
/*sa_ignore FREED_MEMORY*/
liste = TAILQ_FIRST(&asoc->resetHead);
if (TAILQ_EMPTY(&asoc->resetHead)) {
/* All can be removed */
- TAILQ_FOREACH_SAFE(control, &asoc->pending_reply_queue, next, ncontrol) {
- TAILQ_REMOVE(&asoc->pending_reply_queue, control, next);
- sctp_queue_data_to_stream(stcb, asoc, control, abort_flag, &need_reasm_check);
+ TAILQ_FOREACH_SAFE(ctl, &asoc->pending_reply_queue, next, nctl) {
+ TAILQ_REMOVE(&asoc->pending_reply_queue, ctl, next);
+ sctp_queue_data_to_stream(stcb, asoc, ctl, abort_flag);
if (*abort_flag) {
return (0);
}
- if (need_reasm_check) {
- (void)sctp_deliver_reasm_check(stcb, asoc, &asoc->strmin[control->sinfo_stream], SCTP_READ_LOCK_NOT_HELD);
- need_reasm_check = 0;
- }
}
} else {
- TAILQ_FOREACH_SAFE(control, &asoc->pending_reply_queue, next, ncontrol) {
- if (SCTP_TSN_GT(control->sinfo_tsn, liste->tsn)) {
+ TAILQ_FOREACH_SAFE(ctl, &asoc->pending_reply_queue, next, nctl) {
+ if (SCTP_TSN_GT(ctl->sinfo_tsn, liste->tsn)) {
break;
}
/*
- * if control->sinfo_tsn is <= liste->tsn we can
+ * if ctl->sinfo_tsn is <= liste->tsn we can
* process it which is the NOT of
- * control->sinfo_tsn > liste->tsn
+ * ctl->sinfo_tsn > liste->tsn
*/
- TAILQ_REMOVE(&asoc->pending_reply_queue, control, next);
- sctp_queue_data_to_stream(stcb, asoc, control, abort_flag, &need_reasm_check);
+ TAILQ_REMOVE(&asoc->pending_reply_queue, ctl, next);
+ sctp_queue_data_to_stream(stcb, asoc, ctl, abort_flag);
if (*abort_flag) {
return (0);
}
- if (need_reasm_check) {
- (void)sctp_deliver_reasm_check(stcb, asoc, &asoc->strmin[control->sinfo_stream], SCTP_READ_LOCK_NOT_HELD);
- need_reasm_check = 0;
- }
}
}
+ /*
+ * Now service re-assembly to pick up anything that has been
+ * held on reassembly queue?
+ */
+ sctp_deliver_reasm_check(stcb, asoc);
+ need_reasm_check = 0;
+ }
+
+ if (need_reasm_check) {
+ /* Another one waits ? */
+ sctp_deliver_reasm_check(stcb, asoc);
}
return (1);
}
-static const int8_t sctp_map_lookup_tab[256] = {
+int8_t sctp_map_lookup_tab[256] = {
0, 1, 0, 2, 0, 1, 0, 3,
0, 1, 0, 2, 0, 1, 0, 4,
0, 1, 0, 2, 0, 1, 0, 3,
0, 1, 0, 2, 0, 1, 0, 5,
0, 1, 0, 2, 0, 1, 0, 3,
0, 1, 0, 2, 0, 1, 0, 4,
0, 1, 0, 2, 0, 1, 0, 3,
0, 1, 0, 2, 0, 1, 0, 6,
@@ -2369,17 +1980,17 @@ static const int8_t sctp_map_lookup_tab[
void
sctp_slide_mapping_arrays(struct sctp_tcb *stcb)
{
/*
* Now we also need to check the mapping array in a couple of ways.
* 1) Did we move the cum-ack point?
*
* When you first glance at this you might think
- * that all entries that make up the position
+ * that all entries that make up the postion
* of the cum-ack would be in the nr-mapping array
* only.. i.e. things up to the cum-ack are always
* deliverable. Thats true with one exception, when
* its a fragmented message we may not deliver the data
* until some threshold (or all of it) is in place. So
* we must OR the nr_mapping_array and mapping_array to
* get a true picture of the cum-ack.
*/
@@ -2467,26 +2078,26 @@ sctp_slide_mapping_arrays(struct sctp_tc
*/
SCTP_CALC_TSN_TO_GAP(lgap, highest_tsn, asoc->mapping_array_base_tsn);
slide_end = (lgap >> 3);
if (slide_end < slide_from) {
sctp_print_mapping_array(asoc);
#ifdef INVARIANTS
panic("impossible slide");
#else
- SCTP_PRINTF("impossible slide lgap: %x slide_end: %x slide_from: %x? at: %d\n",
+ SCTP_PRINTF("impossible slide lgap:%x slide_end:%x slide_from:%x? at:%d\n",
lgap, slide_end, slide_from, at);
return;
#endif
}
if (slide_end > asoc->mapping_array_size) {
#ifdef INVARIANTS
panic("would overrun buffer");
#else
- SCTP_PRINTF("Gak, would have overrun map end: %d slide_end: %d\n",
+ SCTP_PRINTF("Gak, would have overrun map end:%d slide_end:%d\n",
asoc->mapping_array_size, slide_end);
slide_end = asoc->mapping_array_size;
#endif
}
distance = (slide_end - slide_from) + 1;
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MAP_LOGGING_ENABLE) {
sctp_log_map(old_base, old_cumack, old_highest,
SCTP_MAP_PREPARE_SLIDE);
@@ -2535,49 +2146,47 @@ sctp_slide_mapping_arrays(struct sctp_tc
}
}
void
sctp_sack_check(struct sctp_tcb *stcb, int was_a_gap)
{
struct sctp_association *asoc;
uint32_t highest_tsn;
- int is_a_gap;
-
- sctp_slide_mapping_arrays(stcb);
+
asoc = &stcb->asoc;
if (SCTP_TSN_GT(asoc->highest_tsn_inside_nr_map, asoc->highest_tsn_inside_map)) {
highest_tsn = asoc->highest_tsn_inside_nr_map;
} else {
highest_tsn = asoc->highest_tsn_inside_map;
}
- /* Is there a gap now? */
- is_a_gap = SCTP_TSN_GT(highest_tsn, stcb->asoc.cumulative_tsn);
/*
* Now we need to see if we need to queue a sack or just start the
* timer (if allowed).
*/
if (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_SENT) {
/*
* Ok special case, in SHUTDOWN-SENT case. here we
* maker sure SACK timer is off and instead send a
* SHUTDOWN and a SACK
*/
if (SCTP_OS_TIMER_PENDING(&stcb->asoc.dack_timer.timer)) {
sctp_timer_stop(SCTP_TIMER_TYPE_RECV,
- stcb->sctp_ep, stcb, NULL,
- SCTP_FROM_SCTP_INDATA + SCTP_LOC_17);
+ stcb->sctp_ep, stcb, NULL, SCTP_FROM_SCTP_INDATA+SCTP_LOC_18);
}
sctp_send_shutdown(stcb,
- ((stcb->asoc.alternate) ? stcb->asoc.alternate : stcb->asoc.primary_destination));
- if (is_a_gap) {
- sctp_send_sack(stcb, SCTP_SO_NOT_LOCKED);
- }
+ ((stcb->asoc.alternate) ? stcb->asoc.alternate : stcb->asoc.primary_destination));
+ sctp_send_sack(stcb, SCTP_SO_NOT_LOCKED);
} else {
+ int is_a_gap;
+
+ /* is there a gap now ? */
+ is_a_gap = SCTP_TSN_GT(highest_tsn, stcb->asoc.cumulative_tsn);
+
/*
* CMT DAC algorithm: increase number of packets
* received since last ack
*/
stcb->asoc.cmt_dac_pkts_rcvd++;
if ((stcb->asoc.send_sack == 1) || /* We need to send a SACK */
((was_a_gap) && (is_a_gap == 0)) || /* was a gap, but no
@@ -2623,30 +2232,95 @@ sctp_sack_check(struct sctp_tcb *stcb, i
if (!SCTP_OS_TIMER_PENDING(&stcb->asoc.dack_timer.timer)) {
sctp_timer_start(SCTP_TIMER_TYPE_RECV,
stcb->sctp_ep, stcb, NULL);
}
}
}
}
+void
+sctp_service_queues(struct sctp_tcb *stcb, struct sctp_association *asoc)
+{
+ struct sctp_tmit_chunk *chk;
+ uint32_t tsize, pd_point;
+ uint16_t nxt_todel;
+
+ if (asoc->fragmented_delivery_inprogress) {
+ sctp_service_reassembly(stcb, asoc);
+ }
+ /* Can we proceed further, i.e. the PD-API is complete */
+ if (asoc->fragmented_delivery_inprogress) {
+ /* no */
+ return;
+ }
+ /*
+ * Now is there some other chunk I can deliver from the reassembly
+ * queue.
+ */
+ doit_again:
+ chk = TAILQ_FIRST(&asoc->reasmqueue);
+ if (chk == NULL) {
+ asoc->size_on_reasm_queue = 0;
+ asoc->cnt_on_reasm_queue = 0;
+ return;
+ }
+ nxt_todel = asoc->strmin[chk->rec.data.stream_number].last_sequence_delivered + 1;
+ if ((chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) &&
+ ((nxt_todel == chk->rec.data.stream_seq) ||
+ (chk->rec.data.rcv_flags & SCTP_DATA_UNORDERED))) {
+ /*
+ * Yep the first one is here. We setup to start reception,
+ * by backing down the TSN just in case we can't deliver.
+ */
+
+ /*
+ * Before we start though either all of the message should
+ * be here or the socket buffer max or nothing on the
+ * delivery queue and something can be delivered.
+ */
+ if (stcb->sctp_socket) {
+ pd_point = min(SCTP_SB_LIMIT_RCV(stcb->sctp_socket) >> SCTP_PARTIAL_DELIVERY_SHIFT,
+ stcb->sctp_ep->partial_delivery_point);
+ } else {
+ pd_point = stcb->sctp_ep->partial_delivery_point;
+ }
+ if (sctp_is_all_msg_on_reasm(asoc, &tsize) || (tsize >= pd_point)) {
+ asoc->fragmented_delivery_inprogress = 1;
+ asoc->tsn_last_delivered = chk->rec.data.TSN_seq - 1;
+ asoc->str_of_pdapi = chk->rec.data.stream_number;
+ asoc->ssn_of_pdapi = chk->rec.data.stream_seq;
+ asoc->pdapi_ppid = chk->rec.data.payloadtype;
+ asoc->fragment_flags = chk->rec.data.rcv_flags;
+ sctp_service_reassembly(stcb, asoc);
+ if (asoc->fragmented_delivery_inprogress == 0) {
+ goto doit_again;
+ }
+ }
+ }
+}
+
int
sctp_process_data(struct mbuf **mm, int iphlen, int *offset, int length,
- struct sctp_inpcb *inp, struct sctp_tcb *stcb,
- struct sctp_nets *net, uint32_t *high_tsn)
+ struct sockaddr *src, struct sockaddr *dst,
+ struct sctphdr *sh, struct sctp_inpcb *inp,
+ struct sctp_tcb *stcb, struct sctp_nets *net, uint32_t *high_tsn,
+#if defined(__FreeBSD__)
+ uint8_t mflowtype, uint32_t mflowid,
+#endif
+ uint32_t vrf_id, uint16_t port)
{
- struct sctp_chunkhdr *ch, chunk_buf;
+ struct sctp_data_chunk *ch, chunk_buf;
struct sctp_association *asoc;
int num_chunks = 0; /* number of control chunks processed */
int stop_proc = 0;
- int break_flag, last_chunk;
+ int chk_length, break_flag, last_chunk;
int abort_flag = 0, was_a_gap;
struct mbuf *m;
uint32_t highest_tsn;
- uint16_t chk_length;
/* set the rwnd */
sctp_set_rwnd(stcb, &stcb->asoc);
m = *mm;
SCTP_TCB_LOCK_ASSERT(stcb);
asoc = &stcb->asoc;
if (SCTP_TSN_GT(asoc->highest_tsn_inside_nr_map, asoc->highest_tsn_inside_map)) {
@@ -2679,119 +2353,109 @@ sctp_process_data(struct mbuf **mm, int
caddr_t *from, *to;
/* get the pointers and copy */
to = mtod(m, caddr_t *);
from = mtod((*mm), caddr_t *);
memcpy(to, from, SCTP_BUF_LEN((*mm)));
/* copy the length and free up the old */
SCTP_BUF_LEN(m) = SCTP_BUF_LEN((*mm));
sctp_m_freem(*mm);
- /* success, back copy */
+ /* sucess, back copy */
*mm = m;
} else {
/* We are in trouble in the mbuf world .. yikes */
m = *mm;
}
}
#endif
/* get pointer to the first chunk header */
- ch = (struct sctp_chunkhdr *)sctp_m_getptr(m, *offset,
- sizeof(struct sctp_chunkhdr),
- (uint8_t *)&chunk_buf);
+ ch = (struct sctp_data_chunk *)sctp_m_getptr(m, *offset,
+ sizeof(struct sctp_data_chunk), (uint8_t *) & chunk_buf);
if (ch == NULL) {
return (1);
}
/*
* process all DATA chunks...
*/
*high_tsn = asoc->cumulative_tsn;
break_flag = 0;
asoc->data_pkts_seen++;
while (stop_proc == 0) {
/* validate chunk length */
- chk_length = ntohs(ch->chunk_length);
+ chk_length = ntohs(ch->ch.chunk_length);
if (length - *offset < chk_length) {
/* all done, mutulated chunk */
stop_proc = 1;
continue;
}
- if ((asoc->idata_supported == 1) &&
- (ch->chunk_type == SCTP_DATA)) {
- struct mbuf *op_err;
- char msg[SCTP_DIAG_INFO_LEN];
-
- snprintf(msg, sizeof(msg), "%s", "I-DATA chunk received when DATA was negotiated");
- op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg);
- stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_18;
- sctp_abort_an_association(inp, stcb, op_err, SCTP_SO_NOT_LOCKED);
- return (2);
- }
- if ((asoc->idata_supported == 0) &&
- (ch->chunk_type == SCTP_IDATA)) {
- struct mbuf *op_err;
- char msg[SCTP_DIAG_INFO_LEN];
-
- snprintf(msg, sizeof(msg), "%s", "DATA chunk received when I-DATA was negotiated");
- op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg);
- stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_19;
- sctp_abort_an_association(inp, stcb, op_err, SCTP_SO_NOT_LOCKED);
- return (2);
- }
- if ((ch->chunk_type == SCTP_DATA) ||
- (ch->chunk_type == SCTP_IDATA)) {
- uint16_t clen;
-
- if (ch->chunk_type == SCTP_DATA) {
- clen = sizeof(struct sctp_data_chunk);
- } else {
- clen = sizeof(struct sctp_idata_chunk);
- }
- if (chk_length < clen) {
+ if (ch->ch.chunk_type == SCTP_DATA) {
+ if ((size_t)chk_length < sizeof(struct sctp_data_chunk)) {
/*
* Need to send an abort since we had a
* invalid data chunk.
*/
struct mbuf *op_err;
char msg[SCTP_DIAG_INFO_LEN];
- snprintf(msg, sizeof(msg), "%s chunk of length %u",
- ch->chunk_type == SCTP_DATA ? "DATA" : "I-DATA",
+ snprintf(msg, sizeof(msg), "DATA chunk of length %d",
chk_length);
op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg);
- stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_20;
- sctp_abort_an_association(inp, stcb, op_err, SCTP_SO_NOT_LOCKED);
+ stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA+SCTP_LOC_19;
+ sctp_abort_association(inp, stcb, m, iphlen,
+ src, dst, sh, op_err,
+#if defined(__FreeBSD__)
+ mflowtype, mflowid,
+#endif
+ vrf_id, port);
+ return (2);
+ }
+ if ((size_t)chk_length == sizeof(struct sctp_data_chunk)) {
+ /*
+ * Need to send an abort since we had an
+ * empty data chunk.
+ */
+ struct mbuf *op_err;
+
+ op_err = sctp_generate_no_user_data_cause(ch->dp.tsn);
+ stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA+SCTP_LOC_19;
+ sctp_abort_association(inp, stcb, m, iphlen,
+ src, dst, sh, op_err,
+#if defined(__FreeBSD__)
+ mflowtype, mflowid,
+#endif
+ vrf_id, port);
return (2);
}
#ifdef SCTP_AUDITING_ENABLED
sctp_audit_log(0xB1, 0);
#endif
if (SCTP_SIZE32(chk_length) == (length - *offset)) {
last_chunk = 1;
} else {
last_chunk = 0;
}
- if (sctp_process_a_data_chunk(stcb, asoc, mm, *offset,
+ if (sctp_process_a_data_chunk(stcb, asoc, mm, *offset, ch,
chk_length, net, high_tsn, &abort_flag, &break_flag,
- last_chunk, ch->chunk_type)) {
+ last_chunk)) {
num_chunks++;
}
if (abort_flag)
return (2);
if (break_flag) {
/*
* Set because of out of rwnd space and no
* drop rep space left.
*/
stop_proc = 1;
continue;
}
} else {
/* not a data chunk in the data region */
- switch (ch->chunk_type) {
+ switch (ch->ch.chunk_type) {
case SCTP_INITIATION:
case SCTP_INITIATION_ACK:
case SCTP_SELECTIVE_ACK:
case SCTP_NR_SELECTIVE_ACK:
case SCTP_HEARTBEAT_REQUEST:
case SCTP_HEARTBEAT_ACK:
case SCTP_ABORT_ASSOCIATION:
case SCTP_SHUTDOWN:
@@ -2803,92 +2467,91 @@ sctp_process_data(struct mbuf **mm, int
case SCTP_ECN_CWR:
case SCTP_SHUTDOWN_COMPLETE:
case SCTP_AUTHENTICATION:
case SCTP_ASCONF_ACK:
case SCTP_PACKET_DROPPED:
case SCTP_STREAM_RESET:
case SCTP_FORWARD_CUM_TSN:
case SCTP_ASCONF:
- {
/*
* Now, what do we do with KNOWN chunks that
* are NOT in the right place?
*
* For now, I do nothing but ignore them. We
* may later want to add sysctl stuff to
* switch out and do either an ABORT() or
* possibly process them.
*/
- struct mbuf *op_err;
- char msg[SCTP_DIAG_INFO_LEN];
-
- snprintf(msg, sizeof(msg), "DATA chunk followed by chunk of type %2.2x",
- ch->chunk_type);
- op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg);
- sctp_abort_an_association(inp, stcb, op_err, SCTP_SO_NOT_LOCKED);
- return (2);
- }
- default:
- /*
- * Unknown chunk type: use bit rules after
- * checking length
- */
- if (chk_length < sizeof(struct sctp_chunkhdr)) {
- /*
- * Need to send an abort since we had a
- * invalid chunk.
- */
+ if (SCTP_BASE_SYSCTL(sctp_strict_data_order)) {
struct mbuf *op_err;
- char msg[SCTP_DIAG_INFO_LEN];
-
- snprintf(msg, sizeof(msg), "Chunk of length %u",
- chk_length);
- op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg);
- stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_20;
- sctp_abort_an_association(inp, stcb, op_err, SCTP_SO_NOT_LOCKED);
+
+ op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, "");
+ sctp_abort_association(inp, stcb,
+ m, iphlen,
+ src, dst,
+ sh, op_err,
+#if defined(__FreeBSD__)
+ mflowtype, mflowid,
+#endif
+ vrf_id, port);
return (2);
}
- if (ch->chunk_type & 0x40) {
+ break;
+ default:
+ /* unknown chunk type, use bit rules */
+ if (ch->ch.chunk_type & 0x40) {
/* Add a error report to the queue */
- struct mbuf *op_err;
- struct sctp_gen_error_cause *cause;
-
- op_err = sctp_get_mbuf_for_msg(sizeof(struct sctp_gen_error_cause),
- 0, M_NOWAIT, 1, MT_DATA);
- if (op_err != NULL) {
- cause = mtod(op_err, struct sctp_gen_error_cause *);
- cause->code = htons(SCTP_CAUSE_UNRECOG_CHUNK);
- cause->length = htons((uint16_t)(chk_length + sizeof(struct sctp_gen_error_cause)));
- SCTP_BUF_LEN(op_err) = sizeof(struct sctp_gen_error_cause);
- SCTP_BUF_NEXT(op_err) = SCTP_M_COPYM(m, *offset, chk_length, M_NOWAIT);
- if (SCTP_BUF_NEXT(op_err) != NULL) {
- sctp_queue_op_err(stcb, op_err);
+ struct mbuf *merr;
+ struct sctp_paramhdr *phd;
+
+ merr = sctp_get_mbuf_for_msg(sizeof(*phd), 0, M_NOWAIT, 1, MT_DATA);
+ if (merr) {
+ phd = mtod(merr, struct sctp_paramhdr *);
+ /*
+ * We cheat and use param
+ * type since we did not
+ * bother to define a error
+ * cause struct. They are
+ * the same basic format
+ * with different names.
+ */
+ phd->param_type =
+ htons(SCTP_CAUSE_UNRECOG_CHUNK);
+ phd->param_length =
+ htons(chk_length + sizeof(*phd));
+ SCTP_BUF_LEN(merr) = sizeof(*phd);
+ SCTP_BUF_NEXT(merr) = SCTP_M_COPYM(m, *offset, chk_length, M_NOWAIT);
+ if (SCTP_BUF_NEXT(merr)) {
+ if (sctp_pad_lastmbuf(SCTP_BUF_NEXT(merr), SCTP_SIZE32(chk_length) - chk_length, NULL) == NULL) {
+ sctp_m_freem(merr);
+ } else {
+ sctp_queue_op_err(stcb, merr);
+ }
} else {
- sctp_m_freem(op_err);
+ sctp_m_freem(merr);
}
}
}
- if ((ch->chunk_type & 0x80) == 0) {
+ if ((ch->ch.chunk_type & 0x80) == 0) {
/* discard the rest of this packet */
stop_proc = 1;
} /* else skip this bad chunk and
* continue... */
break;
} /* switch of chunk type */
}
*offset += SCTP_SIZE32(chk_length);
if ((*offset >= length) || stop_proc) {
/* no more data left in the mbuf chain */
stop_proc = 1;
continue;
}
- ch = (struct sctp_chunkhdr *)sctp_m_getptr(m, *offset,
- sizeof(struct sctp_chunkhdr),
- (uint8_t *)&chunk_buf);
+ ch = (struct sctp_data_chunk *)sctp_m_getptr(m, *offset,
+ sizeof(struct sctp_data_chunk), (uint8_t *) & chunk_buf);
if (ch == NULL) {
*offset = length;
stop_proc = 1;
continue;
}
}
if (break_flag) {
/*
@@ -2908,16 +2571,19 @@ sctp_process_data(struct mbuf **mm, int
0,
SCTP_FROM_SCTP_INDATA,
__LINE__);
}
stcb->asoc.overall_error_count = 0;
(void)SCTP_GETTIME_TIMEVAL(&stcb->asoc.time_last_rcvd);
}
/* now service all of the reassm queue if needed */
+ if (!(TAILQ_EMPTY(&asoc->reasmqueue)))
+ sctp_service_queues(stcb, asoc);
+
if (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_SENT) {
/* Assure that we ack right away */
stcb->asoc.send_sack = 1;
}
/* Start a sack timer or QUEUE a SACK for sending */
sctp_sack_check(stcb, was_a_gap);
return (0);
}
@@ -2951,110 +2617,110 @@ sctp_process_segment_range(struct sctp_t
* next expected pseudo-cumack, or
* rtx_pseudo_cumack, if required. Separate
* cumack trackers for first transmissions,
* and retransmissions.
*/
if ((tp1->sent < SCTP_DATAGRAM_RESEND) &&
(tp1->whoTo->find_pseudo_cumack == 1) &&
(tp1->snd_count == 1)) {
- tp1->whoTo->pseudo_cumack = tp1->rec.data.tsn;
+ tp1->whoTo->pseudo_cumack = tp1->rec.data.TSN_seq;
tp1->whoTo->find_pseudo_cumack = 0;
}
if ((tp1->sent < SCTP_DATAGRAM_RESEND) &&
(tp1->whoTo->find_rtx_pseudo_cumack == 1) &&
(tp1->snd_count > 1)) {
- tp1->whoTo->rtx_pseudo_cumack = tp1->rec.data.tsn;
+ tp1->whoTo->rtx_pseudo_cumack = tp1->rec.data.TSN_seq;
tp1->whoTo->find_rtx_pseudo_cumack = 0;
}
- if (tp1->rec.data.tsn == theTSN) {
+ if (tp1->rec.data.TSN_seq == theTSN) {
if (tp1->sent != SCTP_DATAGRAM_UNSENT) {
/*-
* must be held until
* cum-ack passes
*/
if (tp1->sent < SCTP_DATAGRAM_RESEND) {
/*-
* If it is less than RESEND, it is
* now no-longer in flight.
* Higher values may already be set
* via previous Gap Ack Blocks...
* i.e. ACKED or RESEND.
*/
- if (SCTP_TSN_GT(tp1->rec.data.tsn,
+ if (SCTP_TSN_GT(tp1->rec.data.TSN_seq,
*biggest_newly_acked_tsn)) {
- *biggest_newly_acked_tsn = tp1->rec.data.tsn;
+ *biggest_newly_acked_tsn = tp1->rec.data.TSN_seq;
}
/*-
* CMT: SFR algo (and HTNA) - set
* saw_newack to 1 for dest being
* newly acked. update
* this_sack_highest_newack if
* appropriate.
*/
if (tp1->rec.data.chunk_was_revoked == 0)
tp1->whoTo->saw_newack = 1;
- if (SCTP_TSN_GT(tp1->rec.data.tsn,
+ if (SCTP_TSN_GT(tp1->rec.data.TSN_seq,
tp1->whoTo->this_sack_highest_newack)) {
tp1->whoTo->this_sack_highest_newack =
- tp1->rec.data.tsn;
+ tp1->rec.data.TSN_seq;
}
/*-
* CMT DAC algo: also update
* this_sack_lowest_newack
*/
if (*this_sack_lowest_newack == 0) {
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_LOGGING_ENABLE) {
sctp_log_sack(*this_sack_lowest_newack,
last_tsn,
- tp1->rec.data.tsn,
+ tp1->rec.data.TSN_seq,
0,
0,
SCTP_LOG_TSN_ACKED);
}
- *this_sack_lowest_newack = tp1->rec.data.tsn;
+ *this_sack_lowest_newack = tp1->rec.data.TSN_seq;
}
/*-
* CMT: CUCv2 algorithm. If (rtx-)pseudo-cumack for corresp
* dest is being acked, then we have a new (rtx-)pseudo-cumack. Set
* new_(rtx_)pseudo_cumack to TRUE so that the cwnd for this dest can be
* updated. Also trigger search for the next expected (rtx-)pseudo-cumack.
* Separate pseudo_cumack trackers for first transmissions and
* retransmissions.
*/
- if (tp1->rec.data.tsn == tp1->whoTo->pseudo_cumack) {
+ if (tp1->rec.data.TSN_seq == tp1->whoTo->pseudo_cumack) {
if (tp1->rec.data.chunk_was_revoked == 0) {
tp1->whoTo->new_pseudo_cumack = 1;
}
tp1->whoTo->find_pseudo_cumack = 1;
}
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
- sctp_log_cwnd(stcb, tp1->whoTo, tp1->rec.data.tsn, SCTP_CWND_LOG_FROM_SACK);
+ sctp_log_cwnd(stcb, tp1->whoTo, tp1->rec.data.TSN_seq, SCTP_CWND_LOG_FROM_SACK);
}
- if (tp1->rec.data.tsn == tp1->whoTo->rtx_pseudo_cumack) {
+ if (tp1->rec.data.TSN_seq == tp1->whoTo->rtx_pseudo_cumack) {
if (tp1->rec.data.chunk_was_revoked == 0) {
tp1->whoTo->new_pseudo_cumack = 1;
}
tp1->whoTo->find_rtx_pseudo_cumack = 1;
}
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_LOGGING_ENABLE) {
sctp_log_sack(*biggest_newly_acked_tsn,
last_tsn,
- tp1->rec.data.tsn,
+ tp1->rec.data.TSN_seq,
frag_strt,
frag_end,
SCTP_LOG_TSN_ACKED);
}
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) {
sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_GAP,
tp1->whoTo->flight_size,
tp1->book_size,
- (uint32_t)(uintptr_t)tp1->whoTo,
- tp1->rec.data.tsn);
+ (uintptr_t)tp1->whoTo,
+ tp1->rec.data.TSN_seq);
}
sctp_flight_size_decrease(tp1);
if (stcb->asoc.cc_functions.sctp_cwnd_update_tsn_acknowledged) {
(*stcb->asoc.cc_functions.sctp_cwnd_update_tsn_acknowledged)(tp1->whoTo,
tp1);
}
sctp_total_flight_decrease(stcb, tp1);
@@ -3070,32 +2736,33 @@ sctp_process_segment_range(struct sctp_t
*/
if (tp1->do_rtt) {
if (*rto_ok) {
tp1->whoTo->RTO =
sctp_calculate_rto(stcb,
&stcb->asoc,
tp1->whoTo,
&tp1->sent_rcv_time,
+ sctp_align_safe_nocopy,
SCTP_RTT_FROM_DATA);
*rto_ok = 0;
}
if (tp1->whoTo->rto_needed == 0) {
tp1->whoTo->rto_needed = 1;
}
tp1->do_rtt = 0;
}
}
}
if (tp1->sent <= SCTP_DATAGRAM_RESEND) {
- if (SCTP_TSN_GT(tp1->rec.data.tsn,
+ if (SCTP_TSN_GT(tp1->rec.data.TSN_seq,
stcb->asoc.this_sack_highest_gap)) {
stcb->asoc.this_sack_highest_gap =
- tp1->rec.data.tsn;
+ tp1->rec.data.TSN_seq;
}
if (tp1->sent == SCTP_DATAGRAM_RESEND) {
sctp_ucount_decr(stcb->asoc.sent_queue_retran_cnt);
#ifdef SCTP_AUDITING_ENABLED
sctp_audit_log(0xB2,
(stcb->asoc.sent_queue_retran_cnt & 0x000000ff));
#endif
}
@@ -3111,41 +2778,36 @@ sctp_process_segment_range(struct sctp_t
if (tp1->rec.data.chunk_was_revoked) {
/* deflate the cwnd */
tp1->whoTo->cwnd -= tp1->book_size;
tp1->rec.data.chunk_was_revoked = 0;
}
/* NR Sack code here */
if (nr_sacking &&
(tp1->sent != SCTP_DATAGRAM_NR_ACKED)) {
- if (stcb->asoc.strmout[tp1->rec.data.sid].chunks_on_queues > 0) {
- stcb->asoc.strmout[tp1->rec.data.sid].chunks_on_queues--;
+ if (stcb->asoc.strmout[tp1->rec.data.stream_number].chunks_on_queues > 0) {
+ stcb->asoc.strmout[tp1->rec.data.stream_number].chunks_on_queues--;
#ifdef INVARIANTS
} else {
- panic("No chunks on the queues for sid %u.", tp1->rec.data.sid);
+ panic("No chunks on the queues for sid %u.", tp1->rec.data.stream_number);
#endif
}
- if ((stcb->asoc.strmout[tp1->rec.data.sid].chunks_on_queues == 0) &&
- (stcb->asoc.strmout[tp1->rec.data.sid].state == SCTP_STREAM_RESET_PENDING) &&
- TAILQ_EMPTY(&stcb->asoc.strmout[tp1->rec.data.sid].outqueue)) {
- stcb->asoc.trigger_reset = 1;
- }
tp1->sent = SCTP_DATAGRAM_NR_ACKED;
if (tp1->data) {
/* sa_ignore NO_NULL_CHK */
sctp_free_bufspace(stcb, &stcb->asoc, tp1, 1);
sctp_m_freem(tp1->data);
tp1->data = NULL;
}
wake_him++;
}
}
break;
- } /* if (tp1->tsn == theTSN) */
- if (SCTP_TSN_GT(tp1->rec.data.tsn, theTSN)) {
+ } /* if (tp1->TSN_seq == theTSN) */
+ if (SCTP_TSN_GT(tp1->rec.data.TSN_seq, theTSN)) {
break;
}
tp1 = TAILQ_NEXT(tp1, sctp_next);
if ((tp1 == NULL) && (circled == 0)) {
circled++;
tp1 = TAILQ_FIRST(&stcb->asoc.sent_queue);
}
} /* end while (tp1) */
@@ -3227,50 +2889,50 @@ sctp_handle_segments(struct mbuf *m, int
static void
sctp_check_for_revoked(struct sctp_tcb *stcb,
struct sctp_association *asoc, uint32_t cumack,
uint32_t biggest_tsn_acked)
{
struct sctp_tmit_chunk *tp1;
TAILQ_FOREACH(tp1, &asoc->sent_queue, sctp_next) {
- if (SCTP_TSN_GT(tp1->rec.data.tsn, cumack)) {
+ if (SCTP_TSN_GT(tp1->rec.data.TSN_seq, cumack)) {
/*
* ok this guy is either ACK or MARKED. If it is
* ACKED it has been previously acked but not this
* time i.e. revoked. If it is MARKED it was ACK'ed
* again.
*/
- if (SCTP_TSN_GT(tp1->rec.data.tsn, biggest_tsn_acked)) {
+ if (SCTP_TSN_GT(tp1->rec.data.TSN_seq, biggest_tsn_acked)) {
break;
}
if (tp1->sent == SCTP_DATAGRAM_ACKED) {
/* it has been revoked */
tp1->sent = SCTP_DATAGRAM_SENT;
tp1->rec.data.chunk_was_revoked = 1;
/* We must add this stuff back in to
* assure timers and such get started.
*/
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) {
sctp_misc_ints(SCTP_FLIGHT_LOG_UP_REVOKE,
tp1->whoTo->flight_size,
tp1->book_size,
- (uint32_t)(uintptr_t)tp1->whoTo,
- tp1->rec.data.tsn);
+ (uintptr_t)tp1->whoTo,
+ tp1->rec.data.TSN_seq);
}
sctp_flight_size_increase(tp1);
sctp_total_flight_increase(stcb, tp1);
/* We inflate the cwnd to compensate for our
* artificial inflation of the flight_size.
*/
tp1->whoTo->cwnd += tp1->book_size;
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_LOGGING_ENABLE) {
sctp_log_sack(asoc->last_acked_seq,
cumack,
- tp1->rec.data.tsn,
+ tp1->rec.data.TSN_seq,
0,
0,
SCTP_LOG_TSN_REVOKED);
}
} else if (tp1->sent == SCTP_DATAGRAM_MARKED) {
/* it has been re-acked in this SACK */
tp1->sent = SCTP_DATAGRAM_ACKED;
}
@@ -3296,17 +2958,17 @@ sctp_strike_gap_ack_chunks(struct sctp_t
/*
* select the sending_seq, this is either the next thing ready to be
* sent but not transmitted, OR, the next seq we assign.
*/
tp1 = TAILQ_FIRST(&stcb->asoc.send_queue);
if (tp1 == NULL) {
sending_seq = asoc->sending_seq;
} else {
- sending_seq = tp1->rec.data.tsn;
+ sending_seq = tp1->rec.data.TSN_seq;
}
/* CMT DAC algo: finding out if SACK is a mixed SACK */
if ((asoc->sctp_cmt_on_off > 0) &&
SCTP_BASE_SYSCTL(sctp_cmt_use_dac)) {
TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
if (net->saw_newack)
num_dests_sacked++;
@@ -3319,21 +2981,21 @@ sctp_strike_gap_ack_chunks(struct sctp_t
strike_flag = 0;
if (tp1->no_fr_allowed) {
/* this one had a timeout or something */
continue;
}
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) {
if (tp1->sent < SCTP_DATAGRAM_RESEND)
sctp_log_fr(biggest_tsn_newly_acked,
- tp1->rec.data.tsn,
+ tp1->rec.data.TSN_seq,
tp1->sent,
SCTP_FR_LOG_CHECK_STRIKE);
}
- if (SCTP_TSN_GT(tp1->rec.data.tsn, biggest_tsn_acked) ||
+ if (SCTP_TSN_GT(tp1->rec.data.TSN_seq, biggest_tsn_acked) ||
tp1->sent == SCTP_DATAGRAM_UNSENT) {
/* done */
break;
}
if (stcb->asoc.prsctp_supported) {
if ((PR_SCTP_TTL_ENABLED(tp1->flags)) && tp1->sent < SCTP_DATAGRAM_ACKED) {
/* Is it expired? */
#ifndef __FreeBSD__
@@ -3346,17 +3008,17 @@ sctp_strike_gap_ack_chunks(struct sctp_t
(void)sctp_release_pr_sctp_chunk(stcb, tp1, 1,
SCTP_SO_NOT_LOCKED);
}
continue;
}
}
}
- if (SCTP_TSN_GT(tp1->rec.data.tsn, asoc->this_sack_highest_gap)) {
+ if (SCTP_TSN_GT(tp1->rec.data.TSN_seq, asoc->this_sack_highest_gap)) {
/* we are beyond the tsn in the sack */
break;
}
if (tp1->sent >= SCTP_DATAGRAM_RESEND) {
/* either a RESEND, ACKED, or MARKED */
/* skip */
if (tp1->sent == SCTP_FORWARD_TSN_SKIP) {
/* Continue strikin FWD-TSN chunks */
@@ -3370,17 +3032,17 @@ sctp_strike_gap_ack_chunks(struct sctp_t
if (tp1->whoTo && tp1->whoTo->saw_newack == 0) {
/*
* No new acks were receieved for data sent to this
* dest. Therefore, according to the SFR algo for
* CMT, no data sent to this dest can be marked for
* FR using this SACK.
*/
continue;
- } else if (tp1->whoTo && SCTP_TSN_GT(tp1->rec.data.tsn,
+ } else if (tp1->whoTo && SCTP_TSN_GT(tp1->rec.data.TSN_seq,
tp1->whoTo->this_sack_highest_newack)) {
/*
* CMT: New acks were receieved for data sent to
* this dest. But no new acks were seen for data
* sent after tp1. Therefore, according to the SFR
* algo for CMT, tp1 cannot be marked for FR using
* this SACK. This step covers part of the DAC algo
* and the HTNA algo as well.
@@ -3399,17 +3061,17 @@ sctp_strike_gap_ack_chunks(struct sctp_t
*/
if (accum_moved && asoc->fast_retran_loss_recovery) {
/*
* Strike the TSN if in fast-recovery and cum-ack
* moved.
*/
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) {
sctp_log_fr(biggest_tsn_newly_acked,
- tp1->rec.data.tsn,
+ tp1->rec.data.TSN_seq,
tp1->sent,
SCTP_FR_LOG_STRIKE_CHUNK);
}
if (tp1->sent < SCTP_DATAGRAM_RESEND) {
tp1->sent++;
}
if ((asoc->sctp_cmt_on_off > 0) &&
SCTP_BASE_SYSCTL(sctp_cmt_use_dac)) {
@@ -3420,20 +3082,20 @@ sctp_strike_gap_ack_chunks(struct sctp_t
* cumack earlier. If not already to be
* rtx'd, If not a mixed sack and if tp1 is
* not between two sacked TSNs, then mark by
* one more.
* NOTE that we are marking by one additional time since the SACK DAC flag indicates that
* two packets have been received after this missing TSN.
*/
if ((tp1->sent < SCTP_DATAGRAM_RESEND) && (num_dests_sacked == 1) &&
- SCTP_TSN_GT(this_sack_lowest_newack, tp1->rec.data.tsn)) {
+ SCTP_TSN_GT(this_sack_lowest_newack, tp1->rec.data.TSN_seq)) {
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) {
sctp_log_fr(16 + num_dests_sacked,
- tp1->rec.data.tsn,
+ tp1->rec.data.TSN_seq,
tp1->sent,
SCTP_FR_LOG_STRIKE_CHUNK);
}
tp1->sent++;
}
}
} else if ((tp1->rec.data.doing_fast_retransmit) &&
(asoc->sctp_cmt_on_off == 0)) {
@@ -3461,17 +3123,17 @@ sctp_strike_gap_ack_chunks(struct sctp_t
tp1->rec.data.fast_retran_tsn)) {
/*
* Strike the TSN, since this ack is
* beyond where things were when we
* did a FR.
*/
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) {
sctp_log_fr(biggest_tsn_newly_acked,
- tp1->rec.data.tsn,
+ tp1->rec.data.TSN_seq,
tp1->sent,
SCTP_FR_LOG_STRIKE_CHUNK);
}
if (tp1->sent < SCTP_DATAGRAM_RESEND) {
tp1->sent++;
}
strike_flag = 1;
if ((asoc->sctp_cmt_on_off > 0) &&
@@ -3489,47 +3151,47 @@ sctp_strike_gap_ack_chunks(struct sctp_t
* sacked TSNs, then mark by
* one more.
* NOTE that we are marking by one additional time since the SACK DAC flag indicates that
* two packets have been received after this missing TSN.
*/
if ((tp1->sent < SCTP_DATAGRAM_RESEND) &&
(num_dests_sacked == 1) &&
SCTP_TSN_GT(this_sack_lowest_newack,
- tp1->rec.data.tsn)) {
+ tp1->rec.data.TSN_seq)) {
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) {
sctp_log_fr(32 + num_dests_sacked,
- tp1->rec.data.tsn,
+ tp1->rec.data.TSN_seq,
tp1->sent,
SCTP_FR_LOG_STRIKE_CHUNK);
}
if (tp1->sent < SCTP_DATAGRAM_RESEND) {
tp1->sent++;
}
}
}
}
}
/*
* JRI: TODO: remove code for HTNA algo. CMT's
* SFR algo covers HTNA.
*/
- } else if (SCTP_TSN_GT(tp1->rec.data.tsn,
+ } else if (SCTP_TSN_GT(tp1->rec.data.TSN_seq,
biggest_tsn_newly_acked)) {
/*
* We don't strike these: This is the HTNA
* algorithm i.e. we don't strike If our TSN is
* larger than the Highest TSN Newly Acked.
*/
;
} else {
/* Strike the TSN */
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) {
sctp_log_fr(biggest_tsn_newly_acked,
- tp1->rec.data.tsn,
+ tp1->rec.data.TSN_seq,
tp1->sent,
SCTP_FR_LOG_STRIKE_CHUNK);
}
if (tp1->sent < SCTP_DATAGRAM_RESEND) {
tp1->sent++;
}
if ((asoc->sctp_cmt_on_off > 0) &&
SCTP_BASE_SYSCTL(sctp_cmt_use_dac)) {
@@ -3540,37 +3202,37 @@ sctp_strike_gap_ack_chunks(struct sctp_t
* cumack earlier. If not already to be
* rtx'd, If not a mixed sack and if tp1 is
* not between two sacked TSNs, then mark by
* one more.
* NOTE that we are marking by one additional time since the SACK DAC flag indicates that
* two packets have been received after this missing TSN.
*/
if ((tp1->sent < SCTP_DATAGRAM_RESEND) && (num_dests_sacked == 1) &&
- SCTP_TSN_GT(this_sack_lowest_newack, tp1->rec.data.tsn)) {
+ SCTP_TSN_GT(this_sack_lowest_newack, tp1->rec.data.TSN_seq)) {
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) {
sctp_log_fr(48 + num_dests_sacked,
- tp1->rec.data.tsn,
+ tp1->rec.data.TSN_seq,
tp1->sent,
SCTP_FR_LOG_STRIKE_CHUNK);
}
tp1->sent++;
}
}
}
if (tp1->sent == SCTP_DATAGRAM_RESEND) {
struct sctp_nets *alt;
/* fix counts and things */
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) {
sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_RSND,
(tp1->whoTo ? (tp1->whoTo->flight_size) : 0),
tp1->book_size,
- (uint32_t)(uintptr_t)tp1->whoTo,
- tp1->rec.data.tsn);
+ (uintptr_t)tp1->whoTo,
+ tp1->rec.data.TSN_seq);
}
if (tp1->whoTo) {
tp1->whoTo->net_ack++;
sctp_flight_size_decrease(tp1);
if (stcb->asoc.cc_functions.sctp_cwnd_update_tsn_acknowledged) {
(*stcb->asoc.cc_functions.sctp_cwnd_update_tsn_acknowledged)(tp1->whoTo,
tp1);
}
@@ -3597,17 +3259,17 @@ sctp_strike_gap_ack_chunks(struct sctp_t
}
/* Make sure to flag we had a FR */
tp1->whoTo->net_ack++;
continue;
}
}
/* SCTP_PRINTF("OK, we are now ready to FR this guy\n"); */
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FR_LOGGING_ENABLE) {
- sctp_log_fr(tp1->rec.data.tsn, tp1->snd_count,
+ sctp_log_fr(tp1->rec.data.TSN_seq, tp1->snd_count,
0, SCTP_FR_MARKED);
}
if (strike_flag) {
/* This is a subsequent FR */
SCTP_STAT_INCR(sctps_sendmultfastretrans);
}
sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt);
if (asoc->sctp_cmt_on_off > 0) {
@@ -3657,17 +3319,17 @@ sctp_strike_gap_ack_chunks(struct sctp_t
#endif
}
tp1->rec.data.doing_fast_retransmit = 1;
tot_retrans++;
/* mark the sending seq for possible subsequent FR's */
/*
* SCTP_PRINTF("Marking TSN for FR new value %x\n",
- * (uint32_t)tpi->rec.data.tsn);
+ * (uint32_t)tpi->rec.data.TSN_seq);
*/
if (TAILQ_EMPTY(&asoc->send_queue)) {
/*
* If the queue of send is empty then its
* the next sequence number that will be
* assigned so we subtract one from this to
* get the one we last sent.
*/
@@ -3680,17 +3342,17 @@ sctp_strike_gap_ack_chunks(struct sctp_t
* take the first one (which will have the
* lowest TSN) and subtract one to get the
* one we last sent.
*/
struct sctp_tmit_chunk *ttt;
ttt = TAILQ_FIRST(&asoc->send_queue);
tp1->rec.data.fast_retran_tsn =
- ttt->rec.data.tsn;
+ ttt->rec.data.TSN_seq;
}
if (tp1->do_rtt) {
/*
* this guy had a RTO calculation pending on
* it, cancel it
*/
if ((tp1->whoTo != NULL) &&
@@ -3728,17 +3390,17 @@ sctp_try_advance_peer_ack_point(struct s
/* no chance to advance, out of here */
break;
}
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_TRY_ADVANCE) {
if ((tp1->sent == SCTP_FORWARD_TSN_SKIP) ||
(tp1->sent == SCTP_DATAGRAM_NR_ACKED)) {
sctp_misc_ints(SCTP_FWD_TSN_CHECK,
asoc->advanced_peer_ack_point,
- tp1->rec.data.tsn, 0, 0);
+ tp1->rec.data.TSN_seq, 0, 0);
}
}
if (!PR_SCTP_ENABLED(tp1->flags)) {
/*
* We can't fwd-tsn past any that are reliable aka
* retransmitted until the asoc fails.
*/
break;
@@ -3780,20 +3442,20 @@ sctp_try_advance_peer_ack_point(struct s
/*
* Ok now if this chunk is marked to drop it we can clean up
* the chunk, advance our peer ack point and we can check
* the next chunk.
*/
if ((tp1->sent == SCTP_FORWARD_TSN_SKIP) ||
(tp1->sent == SCTP_DATAGRAM_NR_ACKED)) {
/* advance PeerAckPoint goes forward */
- if (SCTP_TSN_GT(tp1->rec.data.tsn, asoc->advanced_peer_ack_point)) {
- asoc->advanced_peer_ack_point = tp1->rec.data.tsn;
+ if (SCTP_TSN_GT(tp1->rec.data.TSN_seq, asoc->advanced_peer_ack_point)) {
+ asoc->advanced_peer_ack_point = tp1->rec.data.TSN_seq;
a_adv = tp1;
- } else if (tp1->rec.data.tsn == asoc->advanced_peer_ack_point) {
+ } else if (tp1->rec.data.TSN_seq == asoc->advanced_peer_ack_point) {
/* No update but we do save the chk */
a_adv = tp1;
}
} else {
/*
* If it is still in RESEND we can advance no
* further
*/
@@ -3803,33 +3465,29 @@ sctp_try_advance_peer_ack_point(struct s
return (a_adv);
}
static int
sctp_fs_audit(struct sctp_association *asoc)
{
struct sctp_tmit_chunk *chk;
int inflight = 0, resend = 0, inbetween = 0, acked = 0, above = 0;
- int ret;
-#ifndef INVARIANTS
- int entry_flight, entry_cnt;
-#endif
-
- ret = 0;
-#ifndef INVARIANTS
+ int entry_flight, entry_cnt, ret;
+
entry_flight = asoc->total_flight;
entry_cnt = asoc->total_flight_count;
-#endif
+ ret = 0;
+
if (asoc->pr_sctp_cnt >= asoc->sent_queue_cnt)
return (0);
TAILQ_FOREACH(chk, &asoc->sent_queue, sctp_next) {
if (chk->sent < SCTP_DATAGRAM_RESEND) {
- SCTP_PRINTF("Chk TSN: %u size: %d inflight cnt: %d\n",
- chk->rec.data.tsn,
+ SCTP_PRINTF("Chk TSN:%u size:%d inflight cnt:%d\n",
+ chk->rec.data.TSN_seq,
chk->send_size,
chk->snd_count);
inflight++;
} else if (chk->sent == SCTP_DATAGRAM_RESEND) {
resend++;
} else if (chk->sent < SCTP_DATAGRAM_ACKED) {
inbetween++;
} else if (chk->sent > SCTP_DATAGRAM_ACKED) {
@@ -3838,20 +3496,20 @@ sctp_fs_audit(struct sctp_association *a
acked++;
}
}
if ((inflight > 0) || (inbetween > 0)) {
#ifdef INVARIANTS
panic("Flight size-express incorrect? \n");
#else
- SCTP_PRINTF("asoc->total_flight: %d cnt: %d\n",
+ SCTP_PRINTF("asoc->total_flight:%d cnt:%d\n",
entry_flight, entry_cnt);
- SCTP_PRINTF("Flight size-express incorrect F: %d I: %d R: %d Ab: %d ACK: %d\n",
+ SCTP_PRINTF("Flight size-express incorrect F:%d I:%d R:%d Ab:%d ACK:%d\n",
inflight, inbetween, resend, above, acked);
ret = 1;
#endif
}
return (ret);
}
@@ -3861,18 +3519,18 @@ sctp_window_probe_recovery(struct sctp_t
struct sctp_tmit_chunk *tp1)
{
tp1->window_probe = 0;
if ((tp1->sent >= SCTP_DATAGRAM_ACKED) || (tp1->data == NULL)) {
/* TSN's skipped we do NOT move back. */
sctp_misc_ints(SCTP_FLIGHT_LOG_DWN_WP_FWD,
tp1->whoTo ? tp1->whoTo->flight_size : 0,
tp1->book_size,
- (uint32_t)(uintptr_t)tp1->whoTo,
- tp1->rec.data.tsn);
+ (uintptr_t)tp1->whoTo,
+ tp1->rec.data.TSN_seq);
return;
}
/* First setup this by shrinking flight */
if (stcb->asoc.cc_functions.sctp_cwnd_update_tsn_acknowledged) {
(*stcb->asoc.cc_functions.sctp_cwnd_update_tsn_acknowledged)(tp1->whoTo,
tp1);
}
sctp_flight_size_decrease(tp1);
@@ -3880,34 +3538,33 @@ sctp_window_probe_recovery(struct sctp_t
/* Now mark for resend */
tp1->sent = SCTP_DATAGRAM_RESEND;
sctp_ucount_incr(asoc->sent_queue_retran_cnt);
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) {
sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_WP,
tp1->whoTo->flight_size,
tp1->book_size,
- (uint32_t)(uintptr_t)tp1->whoTo,
- tp1->rec.data.tsn);
+ (uintptr_t)tp1->whoTo,
+ tp1->rec.data.TSN_seq);
}
}
void
sctp_express_handle_sack(struct sctp_tcb *stcb, uint32_t cumack,
uint32_t rwnd, int *abort_now, int ecne_seen)
{
struct sctp_nets *net;
struct sctp_association *asoc;
struct sctp_tmit_chunk *tp1, *tp2;
uint32_t old_rwnd;
int win_probe_recovery = 0;
int win_probe_recovered = 0;
int j, done_once = 0;
int rto_ok = 1;
- uint32_t send_s;
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOG_SACK_ARRIVALS_ENABLE) {
sctp_misc_ints(SCTP_SACK_LOG_EXPRESS, cumack,
rwnd, stcb->asoc.last_acked_seq, stcb->asoc.peers_rwnd);
}
SCTP_TCB_LOCK_ASSERT(stcb);
#ifdef SCTP_ASOCLOG_OF_TSNS
stcb->asoc.cumack_log[stcb->asoc.cumack_log_at] = cumack;
@@ -3950,65 +3607,76 @@ sctp_express_handle_sack(struct sctp_tcb
* SACK processing
*/
net->new_pseudo_cumack = 0;
net->will_exit_fast_recovery = 0;
if (stcb->asoc.cc_functions.sctp_cwnd_prepare_net_for_sack) {
(*stcb->asoc.cc_functions.sctp_cwnd_prepare_net_for_sack)(stcb, net);
}
}
- if (!TAILQ_EMPTY(&asoc->sent_queue)) {
- tp1 = TAILQ_LAST(&asoc->sent_queue,
- sctpchunk_listhead);
- send_s = tp1->rec.data.tsn + 1;
- } else {
- send_s = asoc->sending_seq;
- }
- if (SCTP_TSN_GE(cumack, send_s)) {
- struct mbuf *op_err;
- char msg[SCTP_DIAG_INFO_LEN];
-
- *abort_now = 1;
- /* XXX */
- snprintf(msg, sizeof(msg), "Cum ack %8.8x greater or equal than TSN %8.8x",
- cumack, send_s);
- op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg);
- stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_21;
- sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED);
- return;
+ if (SCTP_BASE_SYSCTL(sctp_strict_sacks)) {
+ uint32_t send_s;
+
+ if (!TAILQ_EMPTY(&asoc->sent_queue)) {
+ tp1 = TAILQ_LAST(&asoc->sent_queue,
+ sctpchunk_listhead);
+ send_s = tp1->rec.data.TSN_seq + 1;
+ } else {
+ send_s = asoc->sending_seq;
+ }
+ if (SCTP_TSN_GE(cumack, send_s)) {
+#ifndef INVARIANTS
+ struct mbuf *op_err;
+ char msg[SCTP_DIAG_INFO_LEN];
+
+#endif
+#ifdef INVARIANTS
+ panic("Impossible sack 1");
+#else
+
+ *abort_now = 1;
+ /* XXX */
+ snprintf(msg, sizeof(msg), "Cum ack %8.8x greater or equal then TSN %8.8x",
+ cumack, send_s);
+ op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg);
+ stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_25;
+ sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED);
+ return;
+#endif
+ }
}
asoc->this_sack_highest_gap = cumack;
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_THRESHOLD_LOGGING) {
sctp_misc_ints(SCTP_THRESHOLD_CLEAR,
stcb->asoc.overall_error_count,
0,
SCTP_FROM_SCTP_INDATA,
__LINE__);
}
stcb->asoc.overall_error_count = 0;
if (SCTP_TSN_GT(cumack, asoc->last_acked_seq)) {
/* process the new consecutive TSN first */
TAILQ_FOREACH_SAFE(tp1, &asoc->sent_queue, sctp_next, tp2) {
- if (SCTP_TSN_GE(cumack, tp1->rec.data.tsn)) {
+ if (SCTP_TSN_GE(cumack, tp1->rec.data.TSN_seq)) {
if (tp1->sent == SCTP_DATAGRAM_UNSENT) {
SCTP_PRINTF("Warning, an unsent is now acked?\n");
}
if (tp1->sent < SCTP_DATAGRAM_ACKED) {
/*
* If it is less than ACKED, it is
* now no-longer in flight. Higher
* values may occur during marking
*/
if (tp1->sent < SCTP_DATAGRAM_RESEND) {
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) {
sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_CA,
tp1->whoTo->flight_size,
tp1->book_size,
- (uint32_t)(uintptr_t)tp1->whoTo,
- tp1->rec.data.tsn);
+ (uintptr_t)tp1->whoTo,
+ tp1->rec.data.TSN_seq);
}
sctp_flight_size_decrease(tp1);
if (stcb->asoc.cc_functions.sctp_cwnd_update_tsn_acknowledged) {
(*stcb->asoc.cc_functions.sctp_cwnd_update_tsn_acknowledged)(tp1->whoTo,
tp1);
}
/* sa_ignore NO_NULL_CHK */
sctp_total_flight_decrease(stcb, tp1);
@@ -4028,16 +3696,17 @@ sctp_express_handle_sack(struct sctp_tcb
tp1->whoTo->RTO =
/*
* sa_ignore
* NO_NULL_CHK
*/
sctp_calculate_rto(stcb,
asoc, tp1->whoTo,
&tp1->sent_rcv_time,
+ sctp_align_safe_nocopy,
SCTP_RTT_FROM_DATA);
rto_ok = 0;
}
if (tp1->whoTo->rto_needed == 0) {
tp1->whoTo->rto_needed = 1;
}
tp1->do_rtt = 0;
}
@@ -4055,52 +3724,47 @@ sctp_express_handle_sack(struct sctp_tcb
* expected (rtx-)pseudo-cumack.
*/
tp1->whoTo->new_pseudo_cumack = 1;
tp1->whoTo->find_pseudo_cumack = 1;
tp1->whoTo->find_rtx_pseudo_cumack = 1;
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
/* sa_ignore NO_NULL_CHK */
- sctp_log_cwnd(stcb, tp1->whoTo, tp1->rec.data.tsn, SCTP_CWND_LOG_FROM_SACK);
+ sctp_log_cwnd(stcb, tp1->whoTo, tp1->rec.data.TSN_seq, SCTP_CWND_LOG_FROM_SACK);
}
}
if (tp1->sent == SCTP_DATAGRAM_RESEND) {
sctp_ucount_decr(asoc->sent_queue_retran_cnt);
}
if (tp1->rec.data.chunk_was_revoked) {
/* deflate the cwnd */
tp1->whoTo->cwnd -= tp1->book_size;
tp1->rec.data.chunk_was_revoked = 0;
}
if (tp1->sent != SCTP_DATAGRAM_NR_ACKED) {
- if (asoc->strmout[tp1->rec.data.sid].chunks_on_queues > 0) {
- asoc->strmout[tp1->rec.data.sid].chunks_on_queues--;
+ if (asoc->strmout[tp1->rec.data.stream_number].chunks_on_queues > 0) {
+ asoc->strmout[tp1->rec.data.stream_number].chunks_on_queues--;
#ifdef INVARIANTS
} else {
- panic("No chunks on the queues for sid %u.", tp1->rec.data.sid);
+ panic("No chunks on the queues for sid %u.", tp1->rec.data.stream_number);
#endif
}
}
- if ((asoc->strmout[tp1->rec.data.sid].chunks_on_queues == 0) &&
- (asoc->strmout[tp1->rec.data.sid].state == SCTP_STREAM_RESET_PENDING) &&
- TAILQ_EMPTY(&asoc->strmout[tp1->rec.data.sid].outqueue)) {
- asoc->trigger_reset = 1;
- }
TAILQ_REMOVE(&asoc->sent_queue, tp1, sctp_next);
if (tp1->data) {
/* sa_ignore NO_NULL_CHK */
sctp_free_bufspace(stcb, asoc, tp1, 1);
sctp_m_freem(tp1->data);
tp1->data = NULL;
}
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_LOGGING_ENABLE) {
sctp_log_sack(asoc->last_acked_seq,
cumack,
- tp1->rec.data.tsn,
+ tp1->rec.data.TSN_seq,
0,
0,
SCTP_LOG_FREE_SENT);
}
asoc->sent_queue_cnt--;
sctp_free_a_chunk(stcb, tp1, SCTP_SO_NOT_LOCKED);
} else {
break;
@@ -4187,19 +3851,17 @@ sctp_express_handle_sack(struct sctp_tcb
if (stcb->asoc.alternate) {
/* release the alternate, primary is good */
sctp_free_remote_addr(stcb->asoc.alternate);
stcb->asoc.alternate = NULL;
}
}
if (net->dest_state & SCTP_ADDR_PF) {
net->dest_state &= ~SCTP_ADDR_PF;
- sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
- stcb->sctp_ep, stcb, net,
- SCTP_FROM_SCTP_INDATA + SCTP_LOC_22);
+ sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_INPUT + SCTP_LOC_3);
sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
asoc->cc_functions.sctp_cwnd_update_exit_pf(stcb, net);
/* Done with this net */
net->net_ack = 0;
}
/* restore any doubled timers */
net->RTO = (net->lastsa >> SCTP_RTT_SHIFT) + net->lastsv;
if (net->RTO < stcb->asoc.minrto) {
@@ -4233,48 +3895,56 @@ sctp_express_handle_sack(struct sctp_tcb
}
if (asoc->peers_rwnd > old_rwnd) {
win_probe_recovery = 1;
}
/* Now assure a timer where data is queued at */
again:
j = 0;
TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
+ int to_ticks;
if (win_probe_recovery && (net->window_probe)) {
win_probe_recovered = 1;
/*
* Find first chunk that was used with window probe
* and clear the sent
*/
/* sa_ignore FREED_MEMORY */
TAILQ_FOREACH(tp1, &asoc->sent_queue, sctp_next) {
if (tp1->window_probe) {
/* move back to data send queue */
sctp_window_probe_recovery(stcb, asoc, tp1);
break;
}
}
}
+ if (net->RTO == 0) {
+ to_ticks = MSEC_TO_TICKS(stcb->asoc.initial_rto);
+ } else {
+ to_ticks = MSEC_TO_TICKS(net->RTO);
+ }
if (net->flight_size) {
j++;
- sctp_timer_start(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, stcb, net);
+ (void)SCTP_OS_TIMER_START(&net->rxt_timer.timer, to_ticks,
+ sctp_timeout_handler, &net->rxt_timer);
if (net->window_probe) {
net->window_probe = 0;
}
} else {
if (net->window_probe) {
/* In window probes we must assure a timer is still running there */
net->window_probe = 0;
if (!SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer)) {
- sctp_timer_start(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, stcb, net);
+ SCTP_OS_TIMER_START(&net->rxt_timer.timer, to_ticks,
+ sctp_timeout_handler, &net->rxt_timer);
}
} else if (SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer)) {
sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep,
stcb, net,
- SCTP_FROM_SCTP_INDATA + SCTP_LOC_23);
+ SCTP_FROM_SCTP_INDATA + SCTP_LOC_22);
}
}
}
if ((j == 0) &&
(!TAILQ_EMPTY(&asoc->sent_queue)) &&
(asoc->sent_queue_retran_cnt == 0) &&
(win_probe_recovered == 0) &&
(done_once == 0)) {
@@ -4304,57 +3974,78 @@ again:
/* Now what about shutdown issues */
/**********************************/
if (TAILQ_EMPTY(&asoc->send_queue) && TAILQ_EMPTY(&asoc->sent_queue)) {
/* nothing left on sendqueue.. consider done */
/* clean up */
if ((asoc->stream_queue_cnt == 1) &&
((asoc->state & SCTP_STATE_SHUTDOWN_PENDING) ||
(asoc->state & SCTP_STATE_SHUTDOWN_RECEIVED)) &&
- ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete)(stcb, asoc))) {
- asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
- }
- if (((asoc->state & SCTP_STATE_SHUTDOWN_PENDING) ||
- (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) &&
- (asoc->stream_queue_cnt == 1) &&
- (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
- struct mbuf *op_err;
-
- *abort_now = 1;
- /* XXX */
- op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
- stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_24;
- sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED);
- return;
+ (asoc->locked_on_sending)
+ ) {
+ struct sctp_stream_queue_pending *sp;
+ /* I may be in a state where we got
+ * all across.. but cannot write more due
+ * to a shutdown... we abort since the
+ * user did not indicate EOR in this case. The
+ * sp will be cleaned during free of the asoc.
+ */
+ sp = TAILQ_LAST(&((asoc->locked_on_sending)->outqueue),
+ sctp_streamhead);
+ if ((sp) && (sp->length == 0)) {
+ /* Let cleanup code purge it */
+ if (sp->msg_is_complete) {
+ asoc->stream_queue_cnt--;
+ } else {
+ asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
+ asoc->locked_on_sending = NULL;
+ asoc->stream_queue_cnt--;
+ }
+ }
}
if ((asoc->state & SCTP_STATE_SHUTDOWN_PENDING) &&
(asoc->stream_queue_cnt == 0)) {
- struct sctp_nets *netp;
-
- if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
- (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
- SCTP_STAT_DECR_GAUGE32(sctps_currestab);
+ if (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT) {
+ /* Need to abort here */
+ struct mbuf *op_err;
+
+ abort_out_now:
+ *abort_now = 1;
+ /* XXX */
+ op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
+ stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_24;
+ sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED);
+ } else {
+ struct sctp_nets *netp;
+
+ if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
+ (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
+ SCTP_STAT_DECR_GAUGE32(sctps_currestab);
+ }
+ SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
+ SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
+ sctp_stop_timers_for_shutdown(stcb);
+ if (asoc->alternate) {
+ netp = asoc->alternate;
+ } else {
+ netp = asoc->primary_destination;
+ }
+ sctp_send_shutdown(stcb, netp);
+ sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
+ stcb->sctp_ep, stcb, netp);
+ sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
+ stcb->sctp_ep, stcb, netp);
}
- SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
- SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
- sctp_stop_timers_for_shutdown(stcb);
- if (asoc->alternate) {
- netp = asoc->alternate;
- } else {
- netp = asoc->primary_destination;
- }
- sctp_send_shutdown(stcb, netp);
- sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
- stcb->sctp_ep, stcb, netp);
- sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
- stcb->sctp_ep, stcb, netp);
} else if ((SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED) &&
(asoc->stream_queue_cnt == 0)) {
struct sctp_nets *netp;
+ if (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT) {
+ goto abort_out_now;
+ }
SCTP_STAT_DECR_GAUGE32(sctps_currestab);
SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_ACK_SENT);
SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
sctp_stop_timers_for_shutdown(stcb);
if (asoc->alternate) {
netp = asoc->alternate;
} else {
netp = asoc->primary_destination;
@@ -4498,48 +4189,50 @@ sctp_handle_sack(struct mbuf *m, int off
dupdata = (uint32_t *)sctp_m_getptr(m, offset_dup + i * sizeof(uint32_t),
sizeof(uint32_t), (uint8_t *)&dblock);
if (dupdata == NULL) {
break;
}
sctp_log_fr(*dupdata, 0, 0, SCTP_FR_DUPED);
}
}
- /* reality check */
- if (!TAILQ_EMPTY(&asoc->sent_queue)) {
- tp1 = TAILQ_LAST(&asoc->sent_queue,
- sctpchunk_listhead);
- send_s = tp1->rec.data.tsn + 1;
- } else {
- tp1 = NULL;
- send_s = asoc->sending_seq;
- }
- if (SCTP_TSN_GE(cum_ack, send_s)) {
- struct mbuf *op_err;
- char msg[SCTP_DIAG_INFO_LEN];
-
- /*
- * no way, we have not even sent this TSN out yet.
- * Peer is hopelessly messed up with us.
- */
- SCTP_PRINTF("NEW cum_ack:%x send_s:%x is smaller or equal\n",
- cum_ack, send_s);
- if (tp1) {
- SCTP_PRINTF("Got send_s from tsn:%x + 1 of tp1: %p\n",
- tp1->rec.data.tsn, (void *)tp1);
+ if (SCTP_BASE_SYSCTL(sctp_strict_sacks)) {
+ /* reality check */
+ if (!TAILQ_EMPTY(&asoc->sent_queue)) {
+ tp1 = TAILQ_LAST(&asoc->sent_queue,
+ sctpchunk_listhead);
+ send_s = tp1->rec.data.TSN_seq + 1;
+ } else {
+ tp1 = NULL;
+ send_s = asoc->sending_seq;
}
- hopeless_peer:
- *abort_now = 1;
- /* XXX */
- snprintf(msg, sizeof(msg), "Cum ack %8.8x greater or equal than TSN %8.8x",
- cum_ack, send_s);
- op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg);
- stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_25;
- sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED);
- return;
+ if (SCTP_TSN_GE(cum_ack, send_s)) {
+ struct mbuf *op_err;
+ char msg[SCTP_DIAG_INFO_LEN];
+
+ /*
+ * no way, we have not even sent this TSN out yet.
+ * Peer is hopelessly messed up with us.
+ */
+ SCTP_PRINTF("NEW cum_ack:%x send_s:%x is smaller or equal\n",
+ cum_ack, send_s);
+ if (tp1) {
+ SCTP_PRINTF("Got send_s from tsn:%x + 1 of tp1:%p\n",
+ tp1->rec.data.TSN_seq, (void *)tp1);
+ }
+ hopeless_peer:
+ *abort_now = 1;
+ /* XXX */
+ snprintf(msg, sizeof(msg), "Cum ack %8.8x greater or equal then TSN %8.8x",
+ cum_ack, send_s);
+ op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg);
+ stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_25;
+ sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED);
+ return;
+ }
}
/**********************/
/* 1) check the range */
/**********************/
if (SCTP_TSN_GT(asoc->last_acked_seq, last_tsn)) {
/* acking something behind */
return;
}
@@ -4595,17 +4288,17 @@ sctp_handle_sack(struct mbuf *m, int off
net->new_pseudo_cumack = 0;
net->will_exit_fast_recovery = 0;
if (stcb->asoc.cc_functions.sctp_cwnd_prepare_net_for_sack) {
(*stcb->asoc.cc_functions.sctp_cwnd_prepare_net_for_sack)(stcb, net);
}
}
/* process the new consecutive TSN first */
TAILQ_FOREACH(tp1, &asoc->sent_queue, sctp_next) {
- if (SCTP_TSN_GE(last_tsn, tp1->rec.data.tsn)) {
+ if (SCTP_TSN_GE(last_tsn, tp1->rec.data.TSN_seq)) {
if (tp1->sent != SCTP_DATAGRAM_UNSENT) {
accum_moved = 1;
if (tp1->sent < SCTP_DATAGRAM_ACKED) {
/*
* If it is less than ACKED, it is
* now no-longer in flight. Higher
* values may occur during marking
*/
@@ -4623,30 +4316,30 @@ sctp_handle_sack(struct mbuf *m, int off
tp1->whoTo->dest_state &=
~SCTP_ADDR_UNCONFIRMED;
}
if (tp1->sent < SCTP_DATAGRAM_RESEND) {
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) {
sctp_misc_ints(SCTP_FLIGHT_LOG_DOWN_CA,
tp1->whoTo->flight_size,
tp1->book_size,
- (uint32_t)(uintptr_t)tp1->whoTo,
- tp1->rec.data.tsn);
+ (uintptr_t)tp1->whoTo,
+ tp1->rec.data.TSN_seq);
}
sctp_flight_size_decrease(tp1);
sctp_total_flight_decrease(stcb, tp1);
if (stcb->asoc.cc_functions.sctp_cwnd_update_tsn_acknowledged) {
(*stcb->asoc.cc_functions.sctp_cwnd_update_tsn_acknowledged)(tp1->whoTo,
tp1);
}
}
tp1->whoTo->net_ack += tp1->send_size;
/* CMT SFR and DAC algos */
- this_sack_lowest_newack = tp1->rec.data.tsn;
+ this_sack_lowest_newack = tp1->rec.data.TSN_seq;
tp1->whoTo->saw_newack = 1;
if (tp1->snd_count < 2) {
/*
* True non-retransmited
* chunk
*/
tp1->whoTo->net_ack2 +=
@@ -4654,16 +4347,17 @@ sctp_handle_sack(struct mbuf *m, int off
/* update RTO too? */
if (tp1->do_rtt) {
if (rto_ok) {
tp1->whoTo->RTO =
sctp_calculate_rto(stcb,
asoc, tp1->whoTo,
&tp1->sent_rcv_time,
+ sctp_align_safe_nocopy,
SCTP_RTT_FROM_DATA);
rto_ok = 0;
}
if (tp1->whoTo->rto_needed == 0) {
tp1->whoTo->rto_needed = 1;
}
tp1->do_rtt = 0;
}
@@ -4683,23 +4377,23 @@ sctp_handle_sack(struct mbuf *m, int off
tp1->whoTo->new_pseudo_cumack = 1;
tp1->whoTo->find_pseudo_cumack = 1;
tp1->whoTo->find_rtx_pseudo_cumack = 1;
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_LOGGING_ENABLE) {
sctp_log_sack(asoc->last_acked_seq,
cum_ack,
- tp1->rec.data.tsn,
+ tp1->rec.data.TSN_seq,
0,
0,
SCTP_LOG_TSN_ACKED);
}
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_CWND_LOGGING_ENABLE) {
- sctp_log_cwnd(stcb, tp1->whoTo, tp1->rec.data.tsn, SCTP_CWND_LOG_FROM_SACK);
+ sctp_log_cwnd(stcb, tp1->whoTo, tp1->rec.data.TSN_seq, SCTP_CWND_LOG_FROM_SACK);
}
}
if (tp1->sent == SCTP_DATAGRAM_RESEND) {
sctp_ucount_decr(asoc->sent_queue_retran_cnt);
#ifdef SCTP_AUDITING_ENABLED
sctp_audit_log(0xB3,
(asoc->sent_queue_retran_cnt & 0x000000ff));
#endif
@@ -4739,28 +4433,30 @@ sctp_handle_sack(struct mbuf *m, int off
* handling NEWLY ACKED chunks. this_sack_lowest_newack is
* used for CMT DAC algo. saw_newack will also change.
*/
if (sctp_handle_segments(m, &offset_seg, stcb, asoc, last_tsn, &biggest_tsn_acked,
&biggest_tsn_newly_acked, &this_sack_lowest_newack,
num_seg, num_nr_seg, &rto_ok)) {
wake_him++;
}
- /*
- * validate the biggest_tsn_acked in the gap acks if
- * strict adherence is wanted.
- */
- if (SCTP_TSN_GE(biggest_tsn_acked, send_s)) {
+ if (SCTP_BASE_SYSCTL(sctp_strict_sacks)) {
/*
- * peer is either confused or we are under
- * attack. We must abort.
+ * validate the biggest_tsn_acked in the gap acks if
+ * strict adherence is wanted.
*/
- SCTP_PRINTF("Hopeless peer! biggest_tsn_acked:%x largest seq:%x\n",
- biggest_tsn_acked, send_s);
- goto hopeless_peer;
+ if (SCTP_TSN_GE(biggest_tsn_acked, send_s)) {
+ /*
+ * peer is either confused or we are under
+ * attack. We must abort.
+ */
+ SCTP_PRINTF("Hopeless peer! biggest_tsn_acked:%x largest seq:%x\n",
+ biggest_tsn_acked, send_s);
+ goto hopeless_peer;
+ }
}
}
/*******************************************/
/* cancel ALL T3-send timer if accum moved */
/*******************************************/
if (asoc->sctp_cmt_on_off > 0) {
TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
if (net->new_pseudo_cumack)
@@ -4778,33 +4474,28 @@ sctp_handle_sack(struct mbuf *m, int off
}
}
/********************************************/
/* drop the acked chunks from the sentqueue */
/********************************************/
asoc->last_acked_seq = cum_ack;
TAILQ_FOREACH_SAFE(tp1, &asoc->sent_queue, sctp_next, tp2) {
- if (SCTP_TSN_GT(tp1->rec.data.tsn, cum_ack)) {
+ if (SCTP_TSN_GT(tp1->rec.data.TSN_seq, cum_ack)) {
break;
}
if (tp1->sent != SCTP_DATAGRAM_NR_ACKED) {
- if (asoc->strmout[tp1->rec.data.sid].chunks_on_queues > 0) {
- asoc->strmout[tp1->rec.data.sid].chunks_on_queues--;
+ if (asoc->strmout[tp1->rec.data.stream_number].chunks_on_queues > 0) {
+ asoc->strmout[tp1->rec.data.stream_number].chunks_on_queues--;
#ifdef INVARIANTS
} else {
- panic("No chunks on the queues for sid %u.", tp1->rec.data.sid);
+ panic("No chunks on the queues for sid %u.", tp1->rec.data.stream_number);
#endif
}
}
- if ((asoc->strmout[tp1->rec.data.sid].chunks_on_queues == 0) &&
- (asoc->strmout[tp1->rec.data.sid].state == SCTP_STREAM_RESET_PENDING) &&
- TAILQ_EMPTY(&asoc->strmout[tp1->rec.data.sid].outqueue)) {
- asoc->trigger_reset = 1;
- }
TAILQ_REMOVE(&asoc->sent_queue, tp1, sctp_next);
if (PR_SCTP_ENABLED(tp1->flags)) {
if (asoc->pr_sctp_cnt != 0)
asoc->pr_sctp_cnt--;
}
asoc->sent_queue_cnt--;
if (tp1->data) {
/* sa_ignore NO_NULL_CHK */
@@ -4813,27 +4504,27 @@ sctp_handle_sack(struct mbuf *m, int off
tp1->data = NULL;
if (asoc->prsctp_supported && PR_SCTP_BUF_ENABLED(tp1->flags)) {
asoc->sent_queue_cnt_removeable--;
}
}
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SACK_LOGGING_ENABLE) {
sctp_log_sack(asoc->last_acked_seq,
cum_ack,
- tp1->rec.data.tsn,
+ tp1->rec.data.TSN_seq,
0,
0,
SCTP_LOG_FREE_SENT);
}
sctp_free_a_chunk(stcb, tp1, SCTP_SO_NOT_LOCKED);
wake_him++;
}
if (TAILQ_EMPTY(&asoc->sent_queue) && (asoc->total_flight > 0)) {
#ifdef INVARIANTS
- panic("Warning flight size is positive and should be 0");
+ panic("Warning flight size is postive and should be 0");
#else
SCTP_PRINTF("Warning flight size incorrect should be 0 is %d\n",
asoc->total_flight);
#endif
asoc->total_flight = 0;
}
#if defined(__Userspace__)
@@ -4918,18 +4609,18 @@ sctp_handle_sack(struct mbuf *m, int off
/* Peer revoked all dg's marked or acked */
TAILQ_FOREACH(tp1, &asoc->sent_queue, sctp_next) {
if (tp1->sent == SCTP_DATAGRAM_ACKED) {
tp1->sent = SCTP_DATAGRAM_SENT;
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_FLIGHT_LOGGING_ENABLE) {
sctp_misc_ints(SCTP_FLIGHT_LOG_UP_REVOKE,
tp1->whoTo->flight_size,
tp1->book_size,
- (uint32_t)(uintptr_t)tp1->whoTo,
- tp1->rec.data.tsn);
+ (uintptr_t)tp1->whoTo,
+ tp1->rec.data.TSN_seq);
}
sctp_flight_size_increase(tp1);
sctp_total_flight_increase(stcb, tp1);
tp1->rec.data.chunk_was_revoked = 1;
/*
* To ensure that this increase in
* flightsize, which is artificial,
* does not throttle the sender, we
@@ -4971,19 +4662,17 @@ sctp_handle_sack(struct mbuf *m, int off
/* release the alternate, primary is good */
sctp_free_remote_addr(stcb->asoc.alternate);
stcb->asoc.alternate = NULL;
}
}
if (net->dest_state & SCTP_ADDR_PF) {
net->dest_state &= ~SCTP_ADDR_PF;
- sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT,
- stcb->sctp_ep, stcb, net,
- SCTP_FROM_SCTP_INDATA + SCTP_LOC_29);
+ sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net, SCTP_FROM_SCTP_INPUT + SCTP_LOC_3);
sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep, stcb, net);
asoc->cc_functions.sctp_cwnd_update_exit_pf(stcb, net);
/* Done with this net */
net->net_ack = 0;
}
/* restore any doubled timers */
net->RTO = (net->lastsa >> SCTP_RTT_SHIFT) + net->lastsv;
if (net->RTO < stcb->asoc.minrto) {
@@ -4997,18 +4686,17 @@ sctp_handle_sack(struct mbuf *m, int off
asoc->cc_functions.sctp_cwnd_update_after_sack(stcb, asoc, accum_moved, reneged_all, will_exit_fast_recovery);
}
if (TAILQ_EMPTY(&asoc->sent_queue)) {
/* nothing left in-flight */
TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
/* stop all timers */
sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep,
- stcb, net,
- SCTP_FROM_SCTP_INDATA + SCTP_LOC_30);
+ stcb, net, SCTP_FROM_SCTP_INDATA + SCTP_LOC_30);
net->flight_size = 0;
net->partial_bytes_acked = 0;
}
asoc->total_flight = 0;
asoc->total_flight_count = 0;
}
/**********************************/
@@ -5024,58 +4712,78 @@ sctp_handle_sack(struct mbuf *m, int off
if (asoc->peers_rwnd < stcb->sctp_ep->sctp_ep.sctp_sws_sender) {
/* SWS sender side engages */
asoc->peers_rwnd = 0;
}
/* clean up */
if ((asoc->stream_queue_cnt == 1) &&
((asoc->state & SCTP_STATE_SHUTDOWN_PENDING) ||
(asoc->state & SCTP_STATE_SHUTDOWN_RECEIVED)) &&
- ((*asoc->ss_functions.sctp_ss_is_user_msgs_incomplete)(stcb, asoc))) {
- asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
- }
- if (((asoc->state & SCTP_STATE_SHUTDOWN_PENDING) ||
- (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) &&
- (asoc->stream_queue_cnt == 1) &&
- (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT)) {
- struct mbuf *op_err;
-
- *abort_now = 1;
- /* XXX */
- op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
- stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_24;
- sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED);
- return;
+ (asoc->locked_on_sending)
+ ) {
+ struct sctp_stream_queue_pending *sp;
+ /* I may be in a state where we got
+ * all across.. but cannot write more due
+ * to a shutdown... we abort since the
+ * user did not indicate EOR in this case.
+ */
+ sp = TAILQ_LAST(&((asoc->locked_on_sending)->outqueue),
+ sctp_streamhead);
+ if ((sp) && (sp->length == 0)) {
+ asoc->locked_on_sending = NULL;
+ if (sp->msg_is_complete) {
+ asoc->stream_queue_cnt--;
+ } else {
+ asoc->state |= SCTP_STATE_PARTIAL_MSG_LEFT;
+ asoc->stream_queue_cnt--;
+ }
+ }
}
if ((asoc->state & SCTP_STATE_SHUTDOWN_PENDING) &&
(asoc->stream_queue_cnt == 0)) {
- struct sctp_nets *netp;
-
- if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
- (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
- SCTP_STAT_DECR_GAUGE32(sctps_currestab);
+ if (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT) {
+ /* Need to abort here */
+ struct mbuf *op_err;
+
+ abort_out_now:
+ *abort_now = 1;
+ /* XXX */
+ op_err = sctp_generate_cause(SCTP_CAUSE_USER_INITIATED_ABT, "");
+ stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_31;
+ sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED);
+ return;
+ } else {
+ struct sctp_nets *netp;
+
+ if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
+ (SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
+ SCTP_STAT_DECR_GAUGE32(sctps_currestab);
+ }
+ SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
+ SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
+ sctp_stop_timers_for_shutdown(stcb);
+ if (asoc->alternate) {
+ netp = asoc->alternate;
+ } else {
+ netp = asoc->primary_destination;
+ }
+ sctp_send_shutdown(stcb, netp);
+ sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
+ stcb->sctp_ep, stcb, netp);
+ sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
+ stcb->sctp_ep, stcb, netp);
}
- SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
- SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
- sctp_stop_timers_for_shutdown(stcb);
- if (asoc->alternate) {
- netp = asoc->alternate;
- } else {
- netp = asoc->primary_destination;
- }
- sctp_send_shutdown(stcb, netp);
- sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
- stcb->sctp_ep, stcb, netp);
- sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
- stcb->sctp_ep, stcb, netp);
return;
} else if ((SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED) &&
(asoc->stream_queue_cnt == 0)) {
struct sctp_nets *netp;
+ if (asoc->state & SCTP_STATE_PARTIAL_MSG_LEFT) {
+ goto abort_out_now;
+ }
SCTP_STAT_DECR_GAUGE32(sctps_currestab);
SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_ACK_SENT);
SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
sctp_stop_timers_for_shutdown(stcb);
if (asoc->alternate) {
netp = asoc->alternate;
} else {
netp = asoc->primary_destination;
@@ -5184,17 +4892,17 @@ again:
if (!SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer)) {
sctp_timer_start(SCTP_TIMER_TYPE_SEND,
stcb->sctp_ep, stcb, net);
}
} else if (SCTP_OS_TIMER_PENDING(&net->rxt_timer.timer)) {
sctp_timer_stop(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep,
stcb, net,
- SCTP_FROM_SCTP_INDATA + SCTP_LOC_32);
+ SCTP_FROM_SCTP_INDATA + SCTP_LOC_22);
}
}
}
if ((j == 0) &&
(!TAILQ_EMPTY(&asoc->sent_queue)) &&
(asoc->sent_queue_retran_cnt == 0) &&
(win_probe_recovered == 0) &&
(done_once == 0)) {
@@ -5280,282 +4988,171 @@ sctp_update_acked(struct sctp_tcb *stcb,
a_rwnd = stcb->asoc.peers_rwnd + stcb->asoc.total_flight;
/* Now call the express sack handling */
sctp_express_handle_sack(stcb, cum_ack, a_rwnd, abort_flag, 0);
}
static void
sctp_kick_prsctp_reorder_queue(struct sctp_tcb *stcb,
- struct sctp_stream_in *strmin)
+ struct sctp_stream_in *strmin)
{
- struct sctp_queued_to_read *control, *ncontrol;
+ struct sctp_queued_to_read *ctl, *nctl;
struct sctp_association *asoc;
- uint32_t mid;
- int need_reasm_check = 0;
+ uint16_t tt;
asoc = &stcb->asoc;
- mid = strmin->last_mid_delivered;
+ tt = strmin->last_sequence_delivered;
/*
* First deliver anything prior to and including the stream no that
- * came in.
+ * came in
*/
- TAILQ_FOREACH_SAFE(control, &strmin->inqueue, next_instrm, ncontrol) {
- if (SCTP_MID_GE(asoc->idata_supported, mid, control->mid)) {
+ TAILQ_FOREACH_SAFE(ctl, &strmin->inqueue, next, nctl) {
+ if (SCTP_SSN_GE(tt, ctl->sinfo_ssn)) {
/* this is deliverable now */
- if (((control->sinfo_flags >> 8) & SCTP_DATA_NOT_FRAG) == SCTP_DATA_NOT_FRAG) {
- if (control->on_strm_q) {
- if (control->on_strm_q == SCTP_ON_ORDERED) {
- TAILQ_REMOVE(&strmin->inqueue, control, next_instrm);
- } else if (control->on_strm_q == SCTP_ON_UNORDERED) {
- TAILQ_REMOVE(&strmin->uno_inqueue, control, next_instrm);
-#ifdef INVARIANTS
- } else {
- panic("strmin: %p ctl: %p unknown %d",
- strmin, control, control->on_strm_q);
-#endif
- }
- control->on_strm_q = 0;
- }
- /* subtract pending on streams */
- if (asoc->size_on_all_streams >= control->length) {
- asoc->size_on_all_streams -= control->length;
- } else {
-#ifdef INVARIANTS
- panic("size_on_all_streams = %u smaller than control length %u", asoc->size_on_all_streams, control->length);
-#else
- asoc->size_on_all_streams = 0;
-#endif
- }
- sctp_ucount_decr(asoc->cnt_on_all_streams);
- /* deliver it to at least the delivery-q */
- if (stcb->sctp_socket) {
- sctp_mark_non_revokable(asoc, control->sinfo_tsn);
- sctp_add_to_readq(stcb->sctp_ep, stcb,
- control,
- &stcb->sctp_socket->so_rcv,
- 1, SCTP_READ_LOCK_HELD,
- SCTP_SO_NOT_LOCKED);
- }
- } else {
- /* Its a fragmented message */
- if (control->first_frag_seen) {
- /* Make it so this is next to deliver, we restore later */
- strmin->last_mid_delivered = control->mid - 1;
- need_reasm_check = 1;
- break;
- }
+ TAILQ_REMOVE(&strmin->inqueue, ctl, next);
+ /* subtract pending on streams */
+ asoc->size_on_all_streams -= ctl->length;
+ sctp_ucount_decr(asoc->cnt_on_all_streams);
+ /* deliver it to at least the delivery-q */
+ if (stcb->sctp_socket) {
+ sctp_mark_non_revokable(asoc, ctl->sinfo_tsn);
+ sctp_add_to_readq(stcb->sctp_ep, stcb,
+ ctl,
+ &stcb->sctp_socket->so_rcv, 1, SCTP_READ_LOCK_HELD, SCTP_SO_NOT_LOCKED);
}
} else {
/* no more delivery now. */
break;
}
}
- if (need_reasm_check) {
- int ret;
- ret = sctp_deliver_reasm_check(stcb, &stcb->asoc, strmin, SCTP_READ_LOCK_HELD);
- if (SCTP_MID_GT(asoc->idata_supported, mid, strmin->last_mid_delivered)) {
- /* Restore the next to deliver unless we are ahead */
- strmin->last_mid_delivered = mid;
- }
- if (ret == 0) {
- /* Left the front Partial one on */
- return;
- }
- need_reasm_check = 0;
- }
/*
* now we must deliver things in queue the normal way if any are
* now ready.
*/
- mid = strmin->last_mid_delivered + 1;
- TAILQ_FOREACH_SAFE(control, &strmin->inqueue, next_instrm, ncontrol) {
- if (SCTP_MID_EQ(asoc->idata_supported, mid, control->mid)) {
- if (((control->sinfo_flags >> 8) & SCTP_DATA_NOT_FRAG) == SCTP_DATA_NOT_FRAG) {
- /* this is deliverable now */
- if (control->on_strm_q) {
- if (control->on_strm_q == SCTP_ON_ORDERED) {
- TAILQ_REMOVE(&strmin->inqueue, control, next_instrm);
- } else if (control->on_strm_q == SCTP_ON_UNORDERED) {
- TAILQ_REMOVE(&strmin->uno_inqueue, control, next_instrm);
-#ifdef INVARIANTS
- } else {
- panic("strmin: %p ctl: %p unknown %d",
- strmin, control, control->on_strm_q);
-#endif
- }
- control->on_strm_q = 0;
- }
- /* subtract pending on streams */
- if (asoc->size_on_all_streams >= control->length) {
- asoc->size_on_all_streams -= control->length;
- } else {
-#ifdef INVARIANTS
- panic("size_on_all_streams = %u smaller than control length %u", asoc->size_on_all_streams, control->length);
-#else
- asoc->size_on_all_streams = 0;
-#endif
- }
- sctp_ucount_decr(asoc->cnt_on_all_streams);
- /* deliver it to at least the delivery-q */
- strmin->last_mid_delivered = control->mid;
- if (stcb->sctp_socket) {
- sctp_mark_non_revokable(asoc, control->sinfo_tsn);
- sctp_add_to_readq(stcb->sctp_ep, stcb,
- control,
- &stcb->sctp_socket->so_rcv, 1,
- SCTP_READ_LOCK_HELD, SCTP_SO_NOT_LOCKED);
-
- }
- mid = strmin->last_mid_delivered + 1;
- } else {
- /* Its a fragmented message */
- if (control->first_frag_seen) {
- /* Make it so this is next to deliver */
- strmin->last_mid_delivered = control->mid - 1;
- need_reasm_check = 1;
- break;
- }
+ tt = strmin->last_sequence_delivered + 1;
+ TAILQ_FOREACH_SAFE(ctl, &strmin->inqueue, next, nctl) {
+ if (tt == ctl->sinfo_ssn) {
+ /* this is deliverable now */
+ TAILQ_REMOVE(&strmin->inqueue, ctl, next);
+ /* subtract pending on streams */
+ asoc->size_on_all_streams -= ctl->length;
+ sctp_ucount_decr(asoc->cnt_on_all_streams);
+ /* deliver it to at least the delivery-q */
+ strmin->last_sequence_delivered = ctl->sinfo_ssn;
+ if (stcb->sctp_socket) {
+ sctp_mark_non_revokable(asoc, ctl->sinfo_tsn);
+ sctp_add_to_readq(stcb->sctp_ep, stcb,
+ ctl,
+ &stcb->sctp_socket->so_rcv, 1, SCTP_READ_LOCK_HELD, SCTP_SO_NOT_LOCKED);
+
}
+ tt = strmin->last_sequence_delivered + 1;
} else {
break;
}
}
- if (need_reasm_check) {
- (void)sctp_deliver_reasm_check(stcb, &stcb->asoc, strmin, SCTP_READ_LOCK_HELD);
- }
}
-
-
static void
sctp_flush_reassm_for_str_seq(struct sctp_tcb *stcb,
struct sctp_association *asoc,
- uint16_t stream, uint32_t mid, int ordered, uint32_t cumtsn)
+ uint16_t stream, uint16_t seq)
{
- struct sctp_queued_to_read *control;
- struct sctp_stream_in *strm;
struct sctp_tmit_chunk *chk, *nchk;
- int cnt_removed=0;
-
+
+ /* For each one on here see if we need to toss it */
/*
- * For now large messages held on the stream reasm that are
+ * For now large messages held on the reasmqueue that are
* complete will be tossed too. We could in theory do more
* work to spin through and stop after dumping one msg aka
* seeing the start of a new msg at the head, and call the
* delivery function... to see if it can be delivered... But
* for now we just dump everything on the queue.
*/
- strm = &asoc->strmin[stream];
- control = sctp_find_reasm_entry(strm, mid, ordered, asoc->idata_supported);
- if (control == NULL) {
- /* Not found */
- return;
- }
- if (!asoc->idata_supported && !ordered && SCTP_TSN_GT(control->fsn_included, cumtsn)) {
- return;
- }
- TAILQ_FOREACH_SAFE(chk, &control->reasm, sctp_next, nchk) {
- /* Purge hanging chunks */
- if (!asoc->idata_supported && (ordered == 0)) {
- if (SCTP_TSN_GT(chk->rec.data.tsn, cumtsn)) {
- break;
- }
- }
- cnt_removed++;
- TAILQ_REMOVE(&control->reasm, chk, sctp_next);
- if (asoc->size_on_reasm_queue >= chk->send_size) {
- asoc->size_on_reasm_queue -= chk->send_size;
- } else {
-#ifdef INVARIANTS
- panic("size_on_reasm_queue = %u smaller than chunk length %u", asoc->size_on_reasm_queue, chk->send_size);
-#else
- asoc->size_on_reasm_queue = 0;
-#endif
- }
- sctp_ucount_decr(asoc->cnt_on_reasm_queue);
- if (chk->data) {
- sctp_m_freem(chk->data);
- chk->data = NULL;
- }
- sctp_free_a_chunk(stcb, chk, SCTP_SO_NOT_LOCKED);
- }
- if (!TAILQ_EMPTY(&control->reasm)) {
- /* This has to be old data, unordered */
- if (control->data) {
- sctp_m_freem(control->data);
- control->data = NULL;
+ TAILQ_FOREACH_SAFE(chk, &asoc->reasmqueue, sctp_next, nchk) {
+ /* Do not toss it if on a different stream or
+ * marked for unordered delivery in which case
+ * the stream sequence number has no meaning.
+ */
+ if ((chk->rec.data.stream_number != stream) ||
+ ((chk->rec.data.rcv_flags & SCTP_DATA_UNORDERED) == SCTP_DATA_UNORDERED)) {
+ continue;
}
- sctp_reset_a_control(control, stcb->sctp_ep, cumtsn);
- chk = TAILQ_FIRST(&control->reasm);
- if (chk->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG) {
- TAILQ_REMOVE(&control->reasm, chk, sctp_next);
- sctp_add_chk_to_control(control, strm, stcb, asoc,
- chk, SCTP_READ_LOCK_HELD);
+ if (chk->rec.data.stream_seq == seq) {
+ /* It needs to be tossed */
+ TAILQ_REMOVE(&asoc->reasmqueue, chk, sctp_next);
+ if (SCTP_TSN_GT(chk->rec.data.TSN_seq, asoc->tsn_last_delivered)) {
+ asoc->tsn_last_delivered = chk->rec.data.TSN_seq;
+ asoc->str_of_pdapi = chk->rec.data.stream_number;
+ asoc->ssn_of_pdapi = chk->rec.data.stream_seq;
+ asoc->fragment_flags = chk->rec.data.rcv_flags;
+ }
+ asoc->size_on_reasm_queue -= chk->send_size;
+ sctp_ucount_decr(asoc->cnt_on_reasm_queue);
+
+ /* Clear up any stream problem */
+ if ((chk->rec.data.rcv_flags & SCTP_DATA_UNORDERED) != SCTP_DATA_UNORDERED &&
+ SCTP_SSN_GT(chk->rec.data.stream_seq, asoc->strmin[chk->rec.data.stream_number].last_sequence_delivered)) {
+ /*
+ * We must dump forward this streams
+ * sequence number if the chunk is
+ * not unordered that is being
+ * skipped. There is a chance that
+ * if the peer does not include the
+ * last fragment in its FWD-TSN we
+ * WILL have a problem here since
+ * you would have a partial chunk in
+ * queue that may not be
+ * deliverable. Also if a Partial
+ * delivery API as started the user
+ * may get a partial chunk. The next
+ * read returning a new chunk...
+ * really ugly but I see no way
+ * around it! Maybe a notify??
+ */
+ asoc->strmin[chk->rec.data.stream_number].last_sequence_delivered = chk->rec.data.stream_seq;
+ }
+ if (chk->data) {
+ sctp_m_freem(chk->data);
+ chk->data = NULL;
+ }
+ sctp_free_a_chunk(stcb, chk, SCTP_SO_NOT_LOCKED);
+ } else if (SCTP_SSN_GT(chk->rec.data.stream_seq, seq)) {
+ /* If the stream_seq is > than the purging one, we are done */
+ break;
}
- sctp_deliver_reasm_check(stcb, asoc, strm, SCTP_READ_LOCK_HELD);
- return;
- }
- if (control->on_strm_q == SCTP_ON_ORDERED) {
- TAILQ_REMOVE(&strm->inqueue, control, next_instrm);
- if (asoc->size_on_all_streams >= control->length) {
- asoc->size_on_all_streams -= control->length;
- } else {
-#ifdef INVARIANTS
- panic("size_on_all_streams = %u smaller than control length %u", asoc->size_on_all_streams, control->length);
-#else
- asoc->size_on_all_streams = 0;
-#endif
- }
- sctp_ucount_decr(asoc->cnt_on_all_streams);
- control->on_strm_q = 0;
- } else if (control->on_strm_q == SCTP_ON_UNORDERED) {
- TAILQ_REMOVE(&strm->uno_inqueue, control, next_instrm);
- control->on_strm_q = 0;
-#ifdef INVARIANTS
- } else if (control->on_strm_q) {
- panic("strm: %p ctl: %p unknown %d",
- strm, control, control->on_strm_q);
-#endif
- }
- control->on_strm_q = 0;
- if (control->on_read_q == 0) {
- sctp_free_remote_addr(control->whoFrom);
- if (control->data) {
- sctp_m_freem(control->data);
- control->data = NULL;
- }
- sctp_free_a_readq(stcb, control);
}
}
+
void
sctp_handle_forward_tsn(struct sctp_tcb *stcb,
struct sctp_forward_tsn_chunk *fwd,
- int *abort_flag, struct mbuf *m , int offset)
+ int *abort_flag, struct mbuf *m ,int offset)
{
/* The pr-sctp fwd tsn */
/*
* here we will perform all the data receiver side steps for
* processing FwdTSN, as required in by pr-sctp draft:
*
* Assume we get FwdTSN(x):
*
- * 1) update local cumTSN to x
- * 2) try to further advance cumTSN to x + others we have
- * 3) examine and update re-ordering queue on pr-in-streams
- * 4) clean up re-assembly queue
- * 5) Send a sack to report where we are.
+ * 1) update local cumTSN to x 2) try to further advance cumTSN to x +
+ * others we have 3) examine and update re-ordering queue on
+ * pr-in-streams 4) clean up re-assembly queue 5) Send a sack to
+ * report where we are.
*/
struct sctp_association *asoc;
uint32_t new_cum_tsn, gap;
unsigned int i, fwd_sz, m_size;
uint32_t str_seq;
struct sctp_stream_in *strm;
- struct sctp_queued_to_read *control, *sv;
+ struct sctp_tmit_chunk *chk, *nchk;
+ struct sctp_queued_to_read *ctl, *sv;
asoc = &stcb->asoc;
if ((fwd_sz = ntohs(fwd->ch.chunk_length)) < sizeof(struct sctp_forward_tsn_chunk)) {
SCTPDBG(SCTP_DEBUG_INDATA1,
"Bad size too small/big fwd-tsn\n");
return;
}
m_size = (stcb->asoc.mapping_array_size << 3);
@@ -5583,17 +5180,17 @@ sctp_handle_forward_tsn(struct sctp_tcb
* out of range (of single byte chunks in the rwnd I
* give out). This must be an attacker.
*/
*abort_flag = 1;
snprintf(msg, sizeof(msg),
"New cum ack %8.8x too high, highest TSN %8.8x",
new_cum_tsn, asoc->highest_tsn_inside_map);
op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg);
- stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA + SCTP_LOC_33;
+ stcb->sctp_ep->last_abort_code = SCTP_FROM_SCTP_INDATA+SCTP_LOC_33;
sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED);
return;
}
SCTP_STAT_INCR(sctps_fwdtsn_map_over);
memset(stcb->asoc.mapping_array, 0, stcb->asoc.mapping_array_size);
asoc->mapping_array_base_tsn = new_cum_tsn + 1;
asoc->highest_tsn_inside_map = new_cum_tsn;
@@ -5614,151 +5211,163 @@ sctp_handle_forward_tsn(struct sctp_tcb
asoc->highest_tsn_inside_nr_map = asoc->mapping_array_base_tsn + i;
}
}
}
}
/*************************************************************/
/* 2. Clear up re-assembly queue */
/*************************************************************/
-
- /* This is now done as part of clearing up the stream/seq */
- if (asoc->idata_supported == 0) {
- uint16_t sid;
- /* Flush all the un-ordered data based on cum-tsn */
- SCTP_INP_READ_LOCK(stcb->sctp_ep);
- for (sid = 0 ; sid < asoc->streamincnt; sid++) {
- sctp_flush_reassm_for_str_seq(stcb, asoc, sid, 0, 0, new_cum_tsn);
+ /*
+ * First service it if pd-api is up, just in case we can progress it
+ * forward
+ */
+ if (asoc->fragmented_delivery_inprogress) {
+ sctp_service_reassembly(stcb, asoc);
+ }
+ /* For each one on here see if we need to toss it */
+ /*
+ * For now large messages held on the reasmqueue that are
+ * complete will be tossed too. We could in theory do more
+ * work to spin through and stop after dumping one msg aka
+ * seeing the start of a new msg at the head, and call the
+ * delivery function... to see if it can be delivered... But
+ * for now we just dump everything on the queue.
+ */
+ TAILQ_FOREACH_SAFE(chk, &asoc->reasmqueue, sctp_next, nchk) {
+ if (SCTP_TSN_GE(new_cum_tsn, chk->rec.data.TSN_seq)) {
+ /* It needs to be tossed */
+ TAILQ_REMOVE(&asoc->reasmqueue, chk, sctp_next);
+ if (SCTP_TSN_GT(chk->rec.data.TSN_seq, asoc->tsn_last_delivered)) {
+ asoc->tsn_last_delivered = chk->rec.data.TSN_seq;
+ asoc->str_of_pdapi = chk->rec.data.stream_number;
+ asoc->ssn_of_pdapi = chk->rec.data.stream_seq;
+ asoc->fragment_flags = chk->rec.data.rcv_flags;
+ }
+ asoc->size_on_reasm_queue -= chk->send_size;
+ sctp_ucount_decr(asoc->cnt_on_reasm_queue);
+
+ /* Clear up any stream problem */
+ if ((chk->rec.data.rcv_flags & SCTP_DATA_UNORDERED) != SCTP_DATA_UNORDERED &&
+ SCTP_SSN_GT(chk->rec.data.stream_seq, asoc->strmin[chk->rec.data.stream_number].last_sequence_delivered)) {
+ /*
+ * We must dump forward this streams
+ * sequence number if the chunk is
+ * not unordered that is being
+ * skipped. There is a chance that
+ * if the peer does not include the
+ * last fragment in its FWD-TSN we
+ * WILL have a problem here since
+ * you would have a partial chunk in
+ * queue that may not be
+ * deliverable. Also if a Partial
+ * delivery API as started the user
+ * may get a partial chunk. The next
+ * read returning a new chunk...
+ * really ugly but I see no way
+ * around it! Maybe a notify??
+ */
+ asoc->strmin[chk->rec.data.stream_number].last_sequence_delivered = chk->rec.data.stream_seq;
+ }
+ if (chk->data) {
+ sctp_m_freem(chk->data);
+ chk->data = NULL;
+ }
+ sctp_free_a_chunk(stcb, chk, SCTP_SO_NOT_LOCKED);
+ } else {
+ /*
+ * Ok we have gone beyond the end of the
+ * fwd-tsn's mark.
+ */
+ break;
}
- SCTP_INP_READ_UNLOCK(stcb->sctp_ep);
}
/*******************************************************/
/* 3. Update the PR-stream re-ordering queues and fix */
/* delivery issues as needed. */
/*******************************************************/
fwd_sz -= sizeof(*fwd);
if (m && fwd_sz) {
/* New method. */
unsigned int num_str;
- uint32_t mid, cur_mid;
- uint16_t sid;
- uint16_t ordered, flags;
struct sctp_strseq *stseq, strseqbuf;
- struct sctp_strseq_mid *stseq_m, strseqbuf_m;
offset += sizeof(*fwd);
SCTP_INP_READ_LOCK(stcb->sctp_ep);
- if (asoc->idata_supported) {
- num_str = fwd_sz / sizeof(struct sctp_strseq_mid);
- } else {
- num_str = fwd_sz / sizeof(struct sctp_strseq);
- }
+ num_str = fwd_sz / sizeof(struct sctp_strseq);
for (i = 0; i < num_str; i++) {
- if (asoc->idata_supported) {
- stseq_m = (struct sctp_strseq_mid *)sctp_m_getptr(m, offset,
- sizeof(struct sctp_strseq_mid),
- (uint8_t *)&strseqbuf_m);
- offset += sizeof(struct sctp_strseq_mid);
- if (stseq_m == NULL) {
- break;
- }
- sid = ntohs(stseq_m->sid);
- mid = ntohl(stseq_m->mid);
- flags = ntohs(stseq_m->flags);
- if (flags & PR_SCTP_UNORDERED_FLAG) {
- ordered = 0;
- } else {
- ordered = 1;
- }
- } else {
- stseq = (struct sctp_strseq *)sctp_m_getptr(m, offset,
- sizeof(struct sctp_strseq),
- (uint8_t *)&strseqbuf);
- offset += sizeof(struct sctp_strseq);
- if (stseq == NULL) {
- break;
- }
- sid = ntohs(stseq->sid);
- mid = (uint32_t)ntohs(stseq->ssn);
- ordered = 1;
+ uint16_t st;
+ stseq = (struct sctp_strseq *)sctp_m_getptr(m, offset,
+ sizeof(struct sctp_strseq),
+ (uint8_t *)&strseqbuf);
+ offset += sizeof(struct sctp_strseq);
+ if (stseq == NULL) {
+ break;
}
/* Convert */
+ st = ntohs(stseq->stream);
+ stseq->stream = st;
+ st = ntohs(stseq->sequence);
+ stseq->sequence = st;
/* now process */
/*
* Ok we now look for the stream/seq on the read queue
* where its not all delivered. If we find it we transmute the
* read entry into a PDI_ABORTED.
*/
- if (sid >= asoc->streamincnt) {
+ if (stseq->stream >= asoc->streamincnt) {
/* screwed up streams, stop! */
break;
}
- if ((asoc->str_of_pdapi == sid) &&
- (asoc->ssn_of_pdapi == mid)) {
+ if ((asoc->str_of_pdapi == stseq->stream) &&
+ (asoc->ssn_of_pdapi == stseq->sequence)) {
/* If this is the one we were partially delivering
* now then we no longer are. Note this will change
* with the reassembly re-write.
*/
asoc->fragmented_delivery_inprogress = 0;
}
- strm = &asoc->strmin[sid];
- for (cur_mid = strm->last_mid_delivered; SCTP_MID_GE(asoc->idata_supported, mid, cur_mid); cur_mid++) {
- sctp_flush_reassm_for_str_seq(stcb, asoc, sid, cur_mid, ordered, new_cum_tsn);
- }
- TAILQ_FOREACH(control, &stcb->sctp_ep->read_queue, next) {
- if ((control->sinfo_stream == sid) &&
- (SCTP_MID_EQ(asoc->idata_supported, control->mid, mid))) {
- str_seq = (sid << 16) | (0x0000ffff & mid);
- control->pdapi_aborted = 1;
+ sctp_flush_reassm_for_str_seq(stcb, asoc, stseq->stream, stseq->sequence);
+ TAILQ_FOREACH(ctl, &stcb->sctp_ep->read_queue, next) {
+ if ((ctl->sinfo_stream == stseq->stream) &&
+ (ctl->sinfo_ssn == stseq->sequence)) {
+ str_seq = (stseq->stream << 16) | stseq->sequence;
+ ctl->end_added = 1;
+ ctl->pdapi_aborted = 1;
sv = stcb->asoc.control_pdapi;
- control->end_added = 1;
- if (control->on_strm_q == SCTP_ON_ORDERED) {
- TAILQ_REMOVE(&strm->inqueue, control, next_instrm);
- if (asoc->size_on_all_streams >= control->length) {
- asoc->size_on_all_streams -= control->length;
- } else {
-#ifdef INVARIANTS
- panic("size_on_all_streams = %u smaller than control length %u", asoc->size_on_all_streams, control->length);
-#else
- asoc->size_on_all_streams = 0;
-#endif
- }
- sctp_ucount_decr(asoc->cnt_on_all_streams);
- } else if (control->on_strm_q == SCTP_ON_UNORDERED) {
- TAILQ_REMOVE(&strm->uno_inqueue, control, next_instrm);
-#ifdef INVARIANTS
- } else if (control->on_strm_q) {
- panic("strm: %p ctl: %p unknown %d",
- strm, control, control->on_strm_q);
-#endif
- }
- control->on_strm_q = 0;
- stcb->asoc.control_pdapi = control;
+ stcb->asoc.control_pdapi = ctl;
sctp_ulp_notify(SCTP_NOTIFY_PARTIAL_DELVIERY_INDICATION,
stcb,
SCTP_PARTIAL_DELIVERY_ABORTED,
(void *)&str_seq,
SCTP_SO_NOT_LOCKED);
stcb->asoc.control_pdapi = sv;
break;
- } else if ((control->sinfo_stream == sid) &&
- SCTP_MID_GT(asoc->idata_supported, control->mid, mid)) {
+ } else if ((ctl->sinfo_stream == stseq->stream) &&
+ SCTP_SSN_GT(ctl->sinfo_ssn, stseq->sequence)) {
/* We are past our victim SSN */
break;
}
}
- if (SCTP_MID_GT(asoc->idata_supported, mid, strm->last_mid_delivered)) {
+ strm = &asoc->strmin[stseq->stream];
+ if (SCTP_SSN_GT(stseq->sequence, strm->last_sequence_delivered)) {
/* Update the sequence number */
- strm->last_mid_delivered = mid;
+ strm->last_sequence_delivered = stseq->sequence;
}
/* now kick the stream the new way */
- /*sa_ignore NO_NULL_CHK*/
+ /*sa_ignore NO_NULL_CHK*/
sctp_kick_prsctp_reorder_queue(stcb, strm);
}
SCTP_INP_READ_UNLOCK(stcb->sctp_ep);
}
/*
* Now slide thing forward.
*/
sctp_slide_mapping_arrays(stcb);
+
+ if (!TAILQ_EMPTY(&asoc->reasmqueue)) {
+ /* now lets kick out and check for more fragmented delivery */
+ /*sa_ignore NO_NULL_CHK*/
+ sctp_deliver_reasm_check(stcb, &stcb->asoc);
+ }
}