2011-01-23 19:36:28 +00:00
|
|
|
/*-
|
2017-11-24 19:38:59 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
2017-11-24 11:25:53 +00:00
|
|
|
*
|
2012-05-23 11:26:28 +00:00
|
|
|
* Copyright (c) 2010-2012, by Michael Tuexen. All rights reserved.
|
|
|
|
* Copyright (c) 2010-2012, by Randall Stewart. All rights reserved.
|
|
|
|
* Copyright (c) 2010-2012, by Robin Seggelmann. All rights reserved.
|
2011-01-23 19:36:28 +00:00
|
|
|
*
|
|
|
|
* 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,
|
2011-12-17 19:21:40 +00:00
|
|
|
* this list of conditions and the following disclaimer.
|
2011-01-23 19:36:28 +00:00
|
|
|
*
|
|
|
|
* b) Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
2011-12-17 19:21:40 +00:00
|
|
|
* the documentation and/or other materials provided with the distribution.
|
2011-01-23 19:36:28 +00:00
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
|
|
|
#include <netinet/sctp_pcb.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Default simple round-robin algorithm.
|
|
|
|
* Just interates the streams in the order they appear.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
|
|
|
sctp_ss_default_add(struct sctp_tcb *, struct sctp_association *,
|
|
|
|
struct sctp_stream_out *,
|
|
|
|
struct sctp_stream_queue_pending *, int);
|
|
|
|
|
|
|
|
static void
|
|
|
|
sctp_ss_default_remove(struct sctp_tcb *, struct sctp_association *,
|
|
|
|
struct sctp_stream_out *,
|
|
|
|
struct sctp_stream_queue_pending *, int);
|
|
|
|
|
|
|
|
static void
|
|
|
|
sctp_ss_default_init(struct sctp_tcb *stcb, struct sctp_association *asoc,
|
|
|
|
int holds_lock)
|
|
|
|
{
|
|
|
|
uint16_t i;
|
|
|
|
|
2019-03-08 18:16:19 +00:00
|
|
|
if (holds_lock == 0) {
|
|
|
|
SCTP_TCB_SEND_LOCK(stcb);
|
|
|
|
}
|
2016-08-06 12:33:15 +00:00
|
|
|
asoc->ss_data.locked_on_sending = NULL;
|
|
|
|
asoc->ss_data.last_out_stream = NULL;
|
|
|
|
TAILQ_INIT(&asoc->ss_data.out.wheel);
|
2011-02-03 20:44:49 +00:00
|
|
|
/*
|
|
|
|
* If there is data in the stream queues already, the scheduler of
|
|
|
|
* an existing association has been changed. We need to add all
|
|
|
|
* stream queues to the wheel.
|
|
|
|
*/
|
2011-01-23 19:36:28 +00:00
|
|
|
for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
|
2011-02-13 13:53:28 +00:00
|
|
|
stcb->asoc.ss_functions.sctp_ss_add_to_stream(stcb, &stcb->asoc,
|
|
|
|
&stcb->asoc.strmout[i],
|
2019-03-08 18:16:19 +00:00
|
|
|
NULL, 1);
|
|
|
|
}
|
|
|
|
if (holds_lock == 0) {
|
|
|
|
SCTP_TCB_SEND_UNLOCK(stcb);
|
2011-01-23 19:36:28 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sctp_ss_default_clear(struct sctp_tcb *stcb, struct sctp_association *asoc,
|
2011-12-17 19:21:40 +00:00
|
|
|
int clear_values SCTP_UNUSED, int holds_lock)
|
2011-01-23 19:36:28 +00:00
|
|
|
{
|
2011-02-13 13:53:28 +00:00
|
|
|
if (holds_lock == 0) {
|
|
|
|
SCTP_TCB_SEND_LOCK(stcb);
|
|
|
|
}
|
2016-08-06 12:33:15 +00:00
|
|
|
while (!TAILQ_EMPTY(&asoc->ss_data.out.wheel)) {
|
2019-03-07 08:43:20 +00:00
|
|
|
struct sctp_stream_out *strq;
|
2011-01-23 19:36:28 +00:00
|
|
|
|
2019-03-07 08:43:20 +00:00
|
|
|
strq = TAILQ_FIRST(&asoc->ss_data.out.wheel);
|
|
|
|
TAILQ_REMOVE(&asoc->ss_data.out.wheel, strq, ss_params.rr.next_spoke);
|
2011-02-13 13:53:28 +00:00
|
|
|
strq->ss_params.rr.next_spoke.tqe_next = NULL;
|
|
|
|
strq->ss_params.rr.next_spoke.tqe_prev = NULL;
|
|
|
|
}
|
2016-08-06 12:33:15 +00:00
|
|
|
asoc->ss_data.last_out_stream = NULL;
|
2011-02-13 13:53:28 +00:00
|
|
|
if (holds_lock == 0) {
|
|
|
|
SCTP_TCB_SEND_UNLOCK(stcb);
|
2011-01-23 19:36:28 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-08-06 12:33:15 +00:00
|
|
|
sctp_ss_default_init_stream(struct sctp_tcb *stcb, struct sctp_stream_out *strq, struct sctp_stream_out *with_strq)
|
2011-01-23 19:36:28 +00:00
|
|
|
{
|
2016-08-06 12:33:15 +00:00
|
|
|
if (with_strq != NULL) {
|
|
|
|
if (stcb->asoc.ss_data.locked_on_sending == with_strq) {
|
|
|
|
stcb->asoc.ss_data.locked_on_sending = strq;
|
|
|
|
}
|
|
|
|
if (stcb->asoc.ss_data.last_out_stream == with_strq) {
|
|
|
|
stcb->asoc.ss_data.last_out_stream = strq;
|
|
|
|
}
|
|
|
|
}
|
2011-01-23 19:36:28 +00:00
|
|
|
strq->ss_params.rr.next_spoke.tqe_next = NULL;
|
|
|
|
strq->ss_params.rr.next_spoke.tqe_prev = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sctp_ss_default_add(struct sctp_tcb *stcb, struct sctp_association *asoc,
|
|
|
|
struct sctp_stream_out *strq,
|
2011-12-17 19:21:40 +00:00
|
|
|
struct sctp_stream_queue_pending *sp SCTP_UNUSED, int holds_lock)
|
2011-01-23 19:36:28 +00:00
|
|
|
{
|
|
|
|
if (holds_lock == 0) {
|
|
|
|
SCTP_TCB_SEND_LOCK(stcb);
|
|
|
|
}
|
2011-02-13 13:53:28 +00:00
|
|
|
/* Add to wheel if not already on it and stream queue not empty */
|
|
|
|
if (!TAILQ_EMPTY(&strq->outqueue) &&
|
|
|
|
(strq->ss_params.rr.next_spoke.tqe_next == NULL) &&
|
2011-01-23 19:36:28 +00:00
|
|
|
(strq->ss_params.rr.next_spoke.tqe_prev == NULL)) {
|
2016-08-06 12:33:15 +00:00
|
|
|
TAILQ_INSERT_TAIL(&asoc->ss_data.out.wheel,
|
2011-01-23 19:36:28 +00:00
|
|
|
strq, ss_params.rr.next_spoke);
|
|
|
|
}
|
|
|
|
if (holds_lock == 0) {
|
|
|
|
SCTP_TCB_SEND_UNLOCK(stcb);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2011-12-17 19:21:40 +00:00
|
|
|
sctp_ss_default_is_empty(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_association *asoc)
|
2011-01-23 19:36:28 +00:00
|
|
|
{
|
2016-08-06 12:33:15 +00:00
|
|
|
if (TAILQ_EMPTY(&asoc->ss_data.out.wheel)) {
|
2011-01-23 19:36:28 +00:00
|
|
|
return (1);
|
|
|
|
} else {
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sctp_ss_default_remove(struct sctp_tcb *stcb, struct sctp_association *asoc,
|
|
|
|
struct sctp_stream_out *strq,
|
2011-12-17 19:21:40 +00:00
|
|
|
struct sctp_stream_queue_pending *sp SCTP_UNUSED, int holds_lock)
|
2011-01-23 19:36:28 +00:00
|
|
|
{
|
|
|
|
if (holds_lock == 0) {
|
|
|
|
SCTP_TCB_SEND_LOCK(stcb);
|
|
|
|
}
|
2016-12-26 11:06:41 +00:00
|
|
|
/*
|
|
|
|
* Remove from wheel if stream queue is empty and actually is on the
|
|
|
|
* wheel
|
|
|
|
*/
|
2011-02-13 13:53:28 +00:00
|
|
|
if (TAILQ_EMPTY(&strq->outqueue) &&
|
|
|
|
(strq->ss_params.rr.next_spoke.tqe_next != NULL ||
|
|
|
|
strq->ss_params.rr.next_spoke.tqe_prev != NULL)) {
|
2016-08-06 12:33:15 +00:00
|
|
|
if (asoc->ss_data.last_out_stream == strq) {
|
|
|
|
asoc->ss_data.last_out_stream = TAILQ_PREV(asoc->ss_data.last_out_stream,
|
2011-01-23 19:36:28 +00:00
|
|
|
sctpwheel_listhead,
|
|
|
|
ss_params.rr.next_spoke);
|
2016-08-06 12:33:15 +00:00
|
|
|
if (asoc->ss_data.last_out_stream == NULL) {
|
|
|
|
asoc->ss_data.last_out_stream = TAILQ_LAST(&asoc->ss_data.out.wheel,
|
2011-01-23 19:36:28 +00:00
|
|
|
sctpwheel_listhead);
|
|
|
|
}
|
2016-08-06 12:33:15 +00:00
|
|
|
if (asoc->ss_data.last_out_stream == strq) {
|
|
|
|
asoc->ss_data.last_out_stream = NULL;
|
2011-01-23 19:36:28 +00:00
|
|
|
}
|
|
|
|
}
|
2016-08-06 12:33:15 +00:00
|
|
|
TAILQ_REMOVE(&asoc->ss_data.out.wheel, strq, ss_params.rr.next_spoke);
|
2011-01-23 19:36:28 +00:00
|
|
|
strq->ss_params.rr.next_spoke.tqe_next = NULL;
|
|
|
|
strq->ss_params.rr.next_spoke.tqe_prev = NULL;
|
|
|
|
}
|
|
|
|
if (holds_lock == 0) {
|
|
|
|
SCTP_TCB_SEND_UNLOCK(stcb);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct sctp_stream_out *
|
2011-12-17 19:21:40 +00:00
|
|
|
sctp_ss_default_select(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net,
|
2011-01-23 19:36:28 +00:00
|
|
|
struct sctp_association *asoc)
|
|
|
|
{
|
|
|
|
struct sctp_stream_out *strq, *strqt;
|
|
|
|
|
2016-08-06 12:33:15 +00:00
|
|
|
if (asoc->ss_data.locked_on_sending) {
|
|
|
|
return (asoc->ss_data.locked_on_sending);
|
|
|
|
}
|
|
|
|
strqt = asoc->ss_data.last_out_stream;
|
2011-01-23 19:36:28 +00:00
|
|
|
default_again:
|
|
|
|
/* Find the next stream to use */
|
|
|
|
if (strqt == NULL) {
|
2016-08-06 12:33:15 +00:00
|
|
|
strq = TAILQ_FIRST(&asoc->ss_data.out.wheel);
|
2011-01-23 19:36:28 +00:00
|
|
|
} else {
|
|
|
|
strq = TAILQ_NEXT(strqt, ss_params.rr.next_spoke);
|
|
|
|
if (strq == NULL) {
|
2016-08-06 12:33:15 +00:00
|
|
|
strq = TAILQ_FIRST(&asoc->ss_data.out.wheel);
|
2011-01-23 19:36:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If CMT is off, we must validate that the stream in question has
|
2011-02-05 12:12:51 +00:00
|
|
|
* the first item pointed towards are network destination requested
|
2011-01-23 19:36:28 +00:00
|
|
|
* by the caller. Note that if we turn out to be locked to a stream
|
|
|
|
* (assigning TSN's then we must stop, since we cannot look for
|
|
|
|
* another stream with data to send to that destination). In CMT's
|
|
|
|
* case, by skipping this check, we will send one data packet
|
|
|
|
* towards the requested net.
|
|
|
|
*/
|
|
|
|
if (net != NULL && strq != NULL &&
|
|
|
|
SCTP_BASE_SYSCTL(sctp_cmt_on_off) == 0) {
|
|
|
|
if (TAILQ_FIRST(&strq->outqueue) &&
|
|
|
|
TAILQ_FIRST(&strq->outqueue)->net != NULL &&
|
|
|
|
TAILQ_FIRST(&strq->outqueue)->net != net) {
|
2016-08-06 12:33:15 +00:00
|
|
|
if (strq == asoc->ss_data.last_out_stream) {
|
2011-01-23 19:36:28 +00:00
|
|
|
return (NULL);
|
|
|
|
} else {
|
|
|
|
strqt = strq;
|
|
|
|
goto default_again;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (strq);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-08-06 12:51:07 +00:00
|
|
|
sctp_ss_default_scheduled(struct sctp_tcb *stcb,
|
|
|
|
struct sctp_nets *net SCTP_UNUSED,
|
2016-08-06 12:33:15 +00:00
|
|
|
struct sctp_association *asoc,
|
2016-08-06 12:51:07 +00:00
|
|
|
struct sctp_stream_out *strq,
|
|
|
|
int moved_how_much SCTP_UNUSED)
|
2011-01-23 19:36:28 +00:00
|
|
|
{
|
2016-08-06 12:33:15 +00:00
|
|
|
struct sctp_stream_queue_pending *sp;
|
|
|
|
|
|
|
|
asoc->ss_data.last_out_stream = strq;
|
|
|
|
if (stcb->asoc.idata_supported == 0) {
|
|
|
|
sp = TAILQ_FIRST(&strq->outqueue);
|
|
|
|
if ((sp != NULL) && (sp->some_taken == 1)) {
|
|
|
|
stcb->asoc.ss_data.locked_on_sending = strq;
|
|
|
|
} else {
|
|
|
|
stcb->asoc.ss_data.locked_on_sending = NULL;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
stcb->asoc.ss_data.locked_on_sending = NULL;
|
|
|
|
}
|
2011-01-23 19:36:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-12-17 19:21:40 +00:00
|
|
|
sctp_ss_default_packet_done(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net SCTP_UNUSED,
|
|
|
|
struct sctp_association *asoc SCTP_UNUSED)
|
2011-01-23 19:36:28 +00:00
|
|
|
{
|
|
|
|
/* Nothing to be done here */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2011-12-17 19:21:40 +00:00
|
|
|
sctp_ss_default_get_value(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_association *asoc SCTP_UNUSED,
|
2018-07-19 20:11:14 +00:00
|
|
|
struct sctp_stream_out *strq SCTP_UNUSED, uint16_t *value SCTP_UNUSED)
|
2011-01-23 19:36:28 +00:00
|
|
|
{
|
|
|
|
/* Nothing to be done here */
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2011-12-17 19:21:40 +00:00
|
|
|
sctp_ss_default_set_value(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_association *asoc SCTP_UNUSED,
|
|
|
|
struct sctp_stream_out *strq SCTP_UNUSED, uint16_t value SCTP_UNUSED)
|
2011-01-23 19:36:28 +00:00
|
|
|
{
|
|
|
|
/* Nothing to be done here */
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
2016-08-06 12:33:15 +00:00
|
|
|
static int
|
2017-07-20 11:09:33 +00:00
|
|
|
sctp_ss_default_is_user_msgs_incomplete(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_association *asoc)
|
2016-08-06 12:33:15 +00:00
|
|
|
{
|
2017-07-20 11:09:33 +00:00
|
|
|
struct sctp_stream_out *strq;
|
|
|
|
struct sctp_stream_queue_pending *sp;
|
|
|
|
|
|
|
|
if (asoc->stream_queue_cnt != 1) {
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
strq = asoc->ss_data.locked_on_sending;
|
|
|
|
if (strq == NULL) {
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
sp = TAILQ_FIRST(&strq->outqueue);
|
|
|
|
if (sp == NULL) {
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
return (!sp->msg_is_complete);
|
2016-08-06 12:33:15 +00:00
|
|
|
}
|
|
|
|
|
2011-01-23 19:36:28 +00:00
|
|
|
/*
|
|
|
|
* Real round-robin algorithm.
|
|
|
|
* Always interates the streams in ascending order.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
sctp_ss_rr_add(struct sctp_tcb *stcb, struct sctp_association *asoc,
|
|
|
|
struct sctp_stream_out *strq,
|
2011-12-17 19:21:40 +00:00
|
|
|
struct sctp_stream_queue_pending *sp SCTP_UNUSED, int holds_lock)
|
2011-01-23 19:36:28 +00:00
|
|
|
{
|
|
|
|
struct sctp_stream_out *strqt;
|
|
|
|
|
|
|
|
if (holds_lock == 0) {
|
|
|
|
SCTP_TCB_SEND_LOCK(stcb);
|
|
|
|
}
|
2011-02-13 13:53:28 +00:00
|
|
|
if (!TAILQ_EMPTY(&strq->outqueue) &&
|
|
|
|
(strq->ss_params.rr.next_spoke.tqe_next == NULL) &&
|
2011-01-23 19:36:28 +00:00
|
|
|
(strq->ss_params.rr.next_spoke.tqe_prev == NULL)) {
|
2016-08-06 12:33:15 +00:00
|
|
|
if (TAILQ_EMPTY(&asoc->ss_data.out.wheel)) {
|
|
|
|
TAILQ_INSERT_HEAD(&asoc->ss_data.out.wheel, strq, ss_params.rr.next_spoke);
|
2011-01-23 19:36:28 +00:00
|
|
|
} else {
|
2016-08-06 12:33:15 +00:00
|
|
|
strqt = TAILQ_FIRST(&asoc->ss_data.out.wheel);
|
2016-12-07 19:30:59 +00:00
|
|
|
while (strqt != NULL && (strqt->sid < strq->sid)) {
|
2011-01-23 19:36:28 +00:00
|
|
|
strqt = TAILQ_NEXT(strqt, ss_params.rr.next_spoke);
|
|
|
|
}
|
|
|
|
if (strqt != NULL) {
|
|
|
|
TAILQ_INSERT_BEFORE(strqt, strq, ss_params.rr.next_spoke);
|
|
|
|
} else {
|
2016-08-06 12:33:15 +00:00
|
|
|
TAILQ_INSERT_TAIL(&asoc->ss_data.out.wheel, strq, ss_params.rr.next_spoke);
|
2011-01-23 19:36:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (holds_lock == 0) {
|
|
|
|
SCTP_TCB_SEND_UNLOCK(stcb);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Real round-robin per packet algorithm.
|
|
|
|
* Always interates the streams in ascending order and
|
|
|
|
* only fills messages of the same stream in a packet.
|
|
|
|
*/
|
2011-02-13 13:53:28 +00:00
|
|
|
static struct sctp_stream_out *
|
2011-12-17 19:21:40 +00:00
|
|
|
sctp_ss_rrp_select(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net SCTP_UNUSED,
|
2011-02-13 13:53:28 +00:00
|
|
|
struct sctp_association *asoc)
|
2011-01-23 19:36:28 +00:00
|
|
|
{
|
2016-08-06 12:33:15 +00:00
|
|
|
return (asoc->ss_data.last_out_stream);
|
2011-01-23 19:36:28 +00:00
|
|
|
}
|
|
|
|
|
2011-02-13 13:53:28 +00:00
|
|
|
static void
|
2011-12-17 19:21:40 +00:00
|
|
|
sctp_ss_rrp_packet_done(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net,
|
2011-01-23 19:36:28 +00:00
|
|
|
struct sctp_association *asoc)
|
|
|
|
{
|
|
|
|
struct sctp_stream_out *strq, *strqt;
|
|
|
|
|
2016-08-06 12:33:15 +00:00
|
|
|
strqt = asoc->ss_data.last_out_stream;
|
2011-01-23 19:36:28 +00:00
|
|
|
rrp_again:
|
|
|
|
/* Find the next stream to use */
|
|
|
|
if (strqt == NULL) {
|
2016-08-06 12:33:15 +00:00
|
|
|
strq = TAILQ_FIRST(&asoc->ss_data.out.wheel);
|
2011-01-23 19:36:28 +00:00
|
|
|
} else {
|
|
|
|
strq = TAILQ_NEXT(strqt, ss_params.rr.next_spoke);
|
|
|
|
if (strq == NULL) {
|
2016-08-06 12:33:15 +00:00
|
|
|
strq = TAILQ_FIRST(&asoc->ss_data.out.wheel);
|
2011-01-23 19:36:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If CMT is off, we must validate that the stream in question has
|
2011-02-05 12:12:51 +00:00
|
|
|
* the first item pointed towards are network destination requested
|
2011-01-23 19:36:28 +00:00
|
|
|
* by the caller. Note that if we turn out to be locked to a stream
|
|
|
|
* (assigning TSN's then we must stop, since we cannot look for
|
|
|
|
* another stream with data to send to that destination). In CMT's
|
|
|
|
* case, by skipping this check, we will send one data packet
|
|
|
|
* towards the requested net.
|
|
|
|
*/
|
|
|
|
if (net != NULL && strq != NULL &&
|
|
|
|
SCTP_BASE_SYSCTL(sctp_cmt_on_off) == 0) {
|
|
|
|
if (TAILQ_FIRST(&strq->outqueue) &&
|
|
|
|
TAILQ_FIRST(&strq->outqueue)->net != NULL &&
|
|
|
|
TAILQ_FIRST(&strq->outqueue)->net != net) {
|
2016-08-06 12:33:15 +00:00
|
|
|
if (strq == asoc->ss_data.last_out_stream) {
|
2011-02-13 13:53:28 +00:00
|
|
|
strq = NULL;
|
2011-01-23 19:36:28 +00:00
|
|
|
} else {
|
|
|
|
strqt = strq;
|
|
|
|
goto rrp_again;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-08-06 12:33:15 +00:00
|
|
|
asoc->ss_data.last_out_stream = strq;
|
2011-01-23 19:36:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Priority algorithm.
|
|
|
|
* Always prefers streams based on their priority id.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
sctp_ss_prio_clear(struct sctp_tcb *stcb, struct sctp_association *asoc,
|
|
|
|
int clear_values, int holds_lock)
|
|
|
|
{
|
2011-02-13 13:53:28 +00:00
|
|
|
if (holds_lock == 0) {
|
|
|
|
SCTP_TCB_SEND_LOCK(stcb);
|
|
|
|
}
|
2016-08-06 12:33:15 +00:00
|
|
|
while (!TAILQ_EMPTY(&asoc->ss_data.out.wheel)) {
|
2019-03-08 18:16:19 +00:00
|
|
|
struct sctp_stream_out *strq;
|
2011-01-23 19:36:28 +00:00
|
|
|
|
2019-03-08 18:16:19 +00:00
|
|
|
strq = TAILQ_FIRST(&asoc->ss_data.out.wheel);
|
2011-02-13 13:53:28 +00:00
|
|
|
if (clear_values) {
|
|
|
|
strq->ss_params.prio.priority = 0;
|
2011-01-23 19:36:28 +00:00
|
|
|
}
|
2019-03-08 18:16:19 +00:00
|
|
|
TAILQ_REMOVE(&asoc->ss_data.out.wheel, strq, ss_params.prio.next_spoke);
|
2011-02-13 13:53:28 +00:00
|
|
|
strq->ss_params.prio.next_spoke.tqe_next = NULL;
|
|
|
|
strq->ss_params.prio.next_spoke.tqe_prev = NULL;
|
|
|
|
}
|
2016-08-06 12:33:15 +00:00
|
|
|
asoc->ss_data.last_out_stream = NULL;
|
2011-02-13 13:53:28 +00:00
|
|
|
if (holds_lock == 0) {
|
|
|
|
SCTP_TCB_SEND_UNLOCK(stcb);
|
2011-01-23 19:36:28 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-08-06 12:33:15 +00:00
|
|
|
sctp_ss_prio_init_stream(struct sctp_tcb *stcb, struct sctp_stream_out *strq, struct sctp_stream_out *with_strq)
|
2011-01-23 19:36:28 +00:00
|
|
|
{
|
2016-08-06 12:33:15 +00:00
|
|
|
if (with_strq != NULL) {
|
|
|
|
if (stcb->asoc.ss_data.locked_on_sending == with_strq) {
|
|
|
|
stcb->asoc.ss_data.locked_on_sending = strq;
|
|
|
|
}
|
|
|
|
if (stcb->asoc.ss_data.last_out_stream == with_strq) {
|
|
|
|
stcb->asoc.ss_data.last_out_stream = strq;
|
|
|
|
}
|
|
|
|
}
|
2011-01-23 19:36:28 +00:00
|
|
|
strq->ss_params.prio.next_spoke.tqe_next = NULL;
|
|
|
|
strq->ss_params.prio.next_spoke.tqe_prev = NULL;
|
2011-02-03 20:44:49 +00:00
|
|
|
if (with_strq != NULL) {
|
|
|
|
strq->ss_params.prio.priority = with_strq->ss_params.prio.priority;
|
|
|
|
} else {
|
|
|
|
strq->ss_params.prio.priority = 0;
|
|
|
|
}
|
2011-01-23 19:36:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sctp_ss_prio_add(struct sctp_tcb *stcb, struct sctp_association *asoc,
|
2011-12-17 19:21:40 +00:00
|
|
|
struct sctp_stream_out *strq, struct sctp_stream_queue_pending *sp SCTP_UNUSED,
|
2011-01-23 19:36:28 +00:00
|
|
|
int holds_lock)
|
|
|
|
{
|
|
|
|
struct sctp_stream_out *strqt;
|
|
|
|
|
|
|
|
if (holds_lock == 0) {
|
|
|
|
SCTP_TCB_SEND_LOCK(stcb);
|
|
|
|
}
|
2011-02-13 13:53:28 +00:00
|
|
|
/* Add to wheel if not already on it and stream queue not empty */
|
|
|
|
if (!TAILQ_EMPTY(&strq->outqueue) &&
|
|
|
|
(strq->ss_params.prio.next_spoke.tqe_next == NULL) &&
|
2011-01-23 19:36:28 +00:00
|
|
|
(strq->ss_params.prio.next_spoke.tqe_prev == NULL)) {
|
2016-08-06 12:33:15 +00:00
|
|
|
if (TAILQ_EMPTY(&asoc->ss_data.out.wheel)) {
|
|
|
|
TAILQ_INSERT_HEAD(&asoc->ss_data.out.wheel, strq, ss_params.prio.next_spoke);
|
2011-01-23 19:36:28 +00:00
|
|
|
} else {
|
2016-08-06 12:33:15 +00:00
|
|
|
strqt = TAILQ_FIRST(&asoc->ss_data.out.wheel);
|
2011-01-23 19:36:28 +00:00
|
|
|
while (strqt != NULL && strqt->ss_params.prio.priority < strq->ss_params.prio.priority) {
|
|
|
|
strqt = TAILQ_NEXT(strqt, ss_params.prio.next_spoke);
|
|
|
|
}
|
|
|
|
if (strqt != NULL) {
|
|
|
|
TAILQ_INSERT_BEFORE(strqt, strq, ss_params.prio.next_spoke);
|
|
|
|
} else {
|
2016-08-06 12:33:15 +00:00
|
|
|
TAILQ_INSERT_TAIL(&asoc->ss_data.out.wheel, strq, ss_params.prio.next_spoke);
|
2011-01-23 19:36:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (holds_lock == 0) {
|
|
|
|
SCTP_TCB_SEND_UNLOCK(stcb);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sctp_ss_prio_remove(struct sctp_tcb *stcb, struct sctp_association *asoc,
|
2011-12-17 19:21:40 +00:00
|
|
|
struct sctp_stream_out *strq, struct sctp_stream_queue_pending *sp SCTP_UNUSED,
|
2011-01-23 19:36:28 +00:00
|
|
|
int holds_lock)
|
|
|
|
{
|
|
|
|
if (holds_lock == 0) {
|
|
|
|
SCTP_TCB_SEND_LOCK(stcb);
|
|
|
|
}
|
2016-12-26 11:06:41 +00:00
|
|
|
/*
|
|
|
|
* Remove from wheel if stream queue is empty and actually is on the
|
|
|
|
* wheel
|
|
|
|
*/
|
2011-02-13 13:53:28 +00:00
|
|
|
if (TAILQ_EMPTY(&strq->outqueue) &&
|
|
|
|
(strq->ss_params.prio.next_spoke.tqe_next != NULL ||
|
|
|
|
strq->ss_params.prio.next_spoke.tqe_prev != NULL)) {
|
2016-08-06 12:33:15 +00:00
|
|
|
if (asoc->ss_data.last_out_stream == strq) {
|
|
|
|
asoc->ss_data.last_out_stream = TAILQ_PREV(asoc->ss_data.last_out_stream, sctpwheel_listhead,
|
2011-01-23 19:36:28 +00:00
|
|
|
ss_params.prio.next_spoke);
|
2016-08-06 12:33:15 +00:00
|
|
|
if (asoc->ss_data.last_out_stream == NULL) {
|
|
|
|
asoc->ss_data.last_out_stream = TAILQ_LAST(&asoc->ss_data.out.wheel,
|
2011-01-23 19:36:28 +00:00
|
|
|
sctpwheel_listhead);
|
|
|
|
}
|
2016-08-06 12:33:15 +00:00
|
|
|
if (asoc->ss_data.last_out_stream == strq) {
|
|
|
|
asoc->ss_data.last_out_stream = NULL;
|
2011-01-23 19:36:28 +00:00
|
|
|
}
|
|
|
|
}
|
2016-08-06 12:33:15 +00:00
|
|
|
TAILQ_REMOVE(&asoc->ss_data.out.wheel, strq, ss_params.prio.next_spoke);
|
2011-01-23 19:36:28 +00:00
|
|
|
strq->ss_params.prio.next_spoke.tqe_next = NULL;
|
|
|
|
strq->ss_params.prio.next_spoke.tqe_prev = NULL;
|
|
|
|
}
|
|
|
|
if (holds_lock == 0) {
|
|
|
|
SCTP_TCB_SEND_UNLOCK(stcb);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct sctp_stream_out *
|
2011-12-17 19:21:40 +00:00
|
|
|
sctp_ss_prio_select(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net,
|
2011-01-23 19:36:28 +00:00
|
|
|
struct sctp_association *asoc)
|
|
|
|
{
|
|
|
|
struct sctp_stream_out *strq, *strqt, *strqn;
|
|
|
|
|
2020-02-17 18:05:03 +00:00
|
|
|
if (asoc->ss_data.locked_on_sending) {
|
|
|
|
return (asoc->ss_data.locked_on_sending);
|
|
|
|
}
|
2016-08-06 12:33:15 +00:00
|
|
|
strqt = asoc->ss_data.last_out_stream;
|
2011-01-23 19:36:28 +00:00
|
|
|
prio_again:
|
|
|
|
/* Find the next stream to use */
|
|
|
|
if (strqt == NULL) {
|
2016-08-06 12:33:15 +00:00
|
|
|
strq = TAILQ_FIRST(&asoc->ss_data.out.wheel);
|
2011-01-23 19:36:28 +00:00
|
|
|
} else {
|
|
|
|
strqn = TAILQ_NEXT(strqt, ss_params.prio.next_spoke);
|
|
|
|
if (strqn != NULL &&
|
|
|
|
strqn->ss_params.prio.priority == strqt->ss_params.prio.priority) {
|
2011-02-13 13:53:28 +00:00
|
|
|
strq = strqn;
|
2011-01-23 19:36:28 +00:00
|
|
|
} else {
|
2016-08-06 12:33:15 +00:00
|
|
|
strq = TAILQ_FIRST(&asoc->ss_data.out.wheel);
|
2011-01-23 19:36:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If CMT is off, we must validate that the stream in question has
|
2011-02-05 12:12:51 +00:00
|
|
|
* the first item pointed towards are network destination requested
|
2011-01-23 19:36:28 +00:00
|
|
|
* by the caller. Note that if we turn out to be locked to a stream
|
|
|
|
* (assigning TSN's then we must stop, since we cannot look for
|
|
|
|
* another stream with data to send to that destination). In CMT's
|
|
|
|
* case, by skipping this check, we will send one data packet
|
|
|
|
* towards the requested net.
|
|
|
|
*/
|
|
|
|
if (net != NULL && strq != NULL &&
|
|
|
|
SCTP_BASE_SYSCTL(sctp_cmt_on_off) == 0) {
|
|
|
|
if (TAILQ_FIRST(&strq->outqueue) &&
|
|
|
|
TAILQ_FIRST(&strq->outqueue)->net != NULL &&
|
|
|
|
TAILQ_FIRST(&strq->outqueue)->net != net) {
|
2016-08-06 12:33:15 +00:00
|
|
|
if (strq == asoc->ss_data.last_out_stream) {
|
2011-01-23 19:36:28 +00:00
|
|
|
return (NULL);
|
|
|
|
} else {
|
|
|
|
strqt = strq;
|
|
|
|
goto prio_again;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (strq);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2011-12-17 19:21:40 +00:00
|
|
|
sctp_ss_prio_get_value(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_association *asoc SCTP_UNUSED,
|
2018-07-19 20:11:14 +00:00
|
|
|
struct sctp_stream_out *strq, uint16_t *value)
|
2011-01-23 19:36:28 +00:00
|
|
|
{
|
|
|
|
if (strq == NULL) {
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
*value = strq->ss_params.prio.priority;
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
sctp_ss_prio_set_value(struct sctp_tcb *stcb, struct sctp_association *asoc,
|
|
|
|
struct sctp_stream_out *strq, uint16_t value)
|
|
|
|
{
|
|
|
|
if (strq == NULL) {
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
strq->ss_params.prio.priority = value;
|
|
|
|
sctp_ss_prio_remove(stcb, asoc, strq, NULL, 1);
|
|
|
|
sctp_ss_prio_add(stcb, asoc, strq, NULL, 1);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fair bandwidth algorithm.
|
2021-03-13 15:37:28 +00:00
|
|
|
* Maintains an equal throughput per stream.
|
2011-01-23 19:36:28 +00:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
sctp_ss_fb_clear(struct sctp_tcb *stcb, struct sctp_association *asoc,
|
|
|
|
int clear_values, int holds_lock)
|
|
|
|
{
|
2011-02-13 13:53:28 +00:00
|
|
|
if (holds_lock == 0) {
|
|
|
|
SCTP_TCB_SEND_LOCK(stcb);
|
|
|
|
}
|
2016-08-06 12:33:15 +00:00
|
|
|
while (!TAILQ_EMPTY(&asoc->ss_data.out.wheel)) {
|
2019-03-08 18:16:19 +00:00
|
|
|
struct sctp_stream_out *strq;
|
2011-01-23 19:36:28 +00:00
|
|
|
|
2019-03-08 18:16:19 +00:00
|
|
|
strq = TAILQ_FIRST(&asoc->ss_data.out.wheel);
|
2011-02-13 13:53:28 +00:00
|
|
|
if (clear_values) {
|
|
|
|
strq->ss_params.fb.rounds = -1;
|
2011-01-23 19:36:28 +00:00
|
|
|
}
|
2019-03-08 18:16:19 +00:00
|
|
|
TAILQ_REMOVE(&asoc->ss_data.out.wheel, strq, ss_params.fb.next_spoke);
|
2011-02-13 13:53:28 +00:00
|
|
|
strq->ss_params.fb.next_spoke.tqe_next = NULL;
|
|
|
|
strq->ss_params.fb.next_spoke.tqe_prev = NULL;
|
|
|
|
}
|
2016-08-06 12:33:15 +00:00
|
|
|
asoc->ss_data.last_out_stream = NULL;
|
2011-02-13 13:53:28 +00:00
|
|
|
if (holds_lock == 0) {
|
|
|
|
SCTP_TCB_SEND_UNLOCK(stcb);
|
2011-01-23 19:36:28 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-08-06 12:33:15 +00:00
|
|
|
sctp_ss_fb_init_stream(struct sctp_tcb *stcb, struct sctp_stream_out *strq, struct sctp_stream_out *with_strq)
|
2011-01-23 19:36:28 +00:00
|
|
|
{
|
2016-08-06 12:33:15 +00:00
|
|
|
if (with_strq != NULL) {
|
|
|
|
if (stcb->asoc.ss_data.locked_on_sending == with_strq) {
|
|
|
|
stcb->asoc.ss_data.locked_on_sending = strq;
|
|
|
|
}
|
|
|
|
if (stcb->asoc.ss_data.last_out_stream == with_strq) {
|
|
|
|
stcb->asoc.ss_data.last_out_stream = strq;
|
|
|
|
}
|
|
|
|
}
|
2011-01-23 19:36:28 +00:00
|
|
|
strq->ss_params.fb.next_spoke.tqe_next = NULL;
|
|
|
|
strq->ss_params.fb.next_spoke.tqe_prev = NULL;
|
2011-02-03 20:44:49 +00:00
|
|
|
if (with_strq != NULL) {
|
|
|
|
strq->ss_params.fb.rounds = with_strq->ss_params.fb.rounds;
|
|
|
|
} else {
|
|
|
|
strq->ss_params.fb.rounds = -1;
|
|
|
|
}
|
2011-01-23 19:36:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sctp_ss_fb_add(struct sctp_tcb *stcb, struct sctp_association *asoc,
|
2011-12-17 19:21:40 +00:00
|
|
|
struct sctp_stream_out *strq, struct sctp_stream_queue_pending *sp SCTP_UNUSED,
|
2011-01-23 19:36:28 +00:00
|
|
|
int holds_lock)
|
|
|
|
{
|
|
|
|
if (holds_lock == 0) {
|
|
|
|
SCTP_TCB_SEND_LOCK(stcb);
|
|
|
|
}
|
2011-02-13 13:53:28 +00:00
|
|
|
if (!TAILQ_EMPTY(&strq->outqueue) &&
|
|
|
|
(strq->ss_params.fb.next_spoke.tqe_next == NULL) &&
|
|
|
|
(strq->ss_params.fb.next_spoke.tqe_prev == NULL)) {
|
|
|
|
if (strq->ss_params.fb.rounds < 0)
|
2011-01-23 19:36:28 +00:00
|
|
|
strq->ss_params.fb.rounds = TAILQ_FIRST(&strq->outqueue)->length;
|
2016-08-06 12:33:15 +00:00
|
|
|
TAILQ_INSERT_TAIL(&asoc->ss_data.out.wheel, strq, ss_params.fb.next_spoke);
|
2011-01-23 19:36:28 +00:00
|
|
|
}
|
|
|
|
if (holds_lock == 0) {
|
|
|
|
SCTP_TCB_SEND_UNLOCK(stcb);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sctp_ss_fb_remove(struct sctp_tcb *stcb, struct sctp_association *asoc,
|
2011-12-17 19:21:40 +00:00
|
|
|
struct sctp_stream_out *strq, struct sctp_stream_queue_pending *sp SCTP_UNUSED,
|
2011-01-23 19:36:28 +00:00
|
|
|
int holds_lock)
|
|
|
|
{
|
|
|
|
if (holds_lock == 0) {
|
|
|
|
SCTP_TCB_SEND_LOCK(stcb);
|
|
|
|
}
|
2016-12-26 11:06:41 +00:00
|
|
|
/*
|
|
|
|
* Remove from wheel if stream queue is empty and actually is on the
|
|
|
|
* wheel
|
|
|
|
*/
|
2011-02-13 13:53:28 +00:00
|
|
|
if (TAILQ_EMPTY(&strq->outqueue) &&
|
|
|
|
(strq->ss_params.fb.next_spoke.tqe_next != NULL ||
|
|
|
|
strq->ss_params.fb.next_spoke.tqe_prev != NULL)) {
|
2016-08-06 12:33:15 +00:00
|
|
|
if (asoc->ss_data.last_out_stream == strq) {
|
|
|
|
asoc->ss_data.last_out_stream = TAILQ_PREV(asoc->ss_data.last_out_stream, sctpwheel_listhead,
|
2011-01-23 19:36:28 +00:00
|
|
|
ss_params.fb.next_spoke);
|
2016-08-06 12:33:15 +00:00
|
|
|
if (asoc->ss_data.last_out_stream == NULL) {
|
|
|
|
asoc->ss_data.last_out_stream = TAILQ_LAST(&asoc->ss_data.out.wheel,
|
2011-01-23 19:36:28 +00:00
|
|
|
sctpwheel_listhead);
|
|
|
|
}
|
2016-08-06 12:33:15 +00:00
|
|
|
if (asoc->ss_data.last_out_stream == strq) {
|
|
|
|
asoc->ss_data.last_out_stream = NULL;
|
2011-01-23 19:36:28 +00:00
|
|
|
}
|
|
|
|
}
|
2016-08-06 12:33:15 +00:00
|
|
|
TAILQ_REMOVE(&asoc->ss_data.out.wheel, strq, ss_params.fb.next_spoke);
|
2011-01-23 19:36:28 +00:00
|
|
|
strq->ss_params.fb.next_spoke.tqe_next = NULL;
|
|
|
|
strq->ss_params.fb.next_spoke.tqe_prev = NULL;
|
|
|
|
}
|
|
|
|
if (holds_lock == 0) {
|
|
|
|
SCTP_TCB_SEND_UNLOCK(stcb);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct sctp_stream_out *
|
2011-12-17 19:21:40 +00:00
|
|
|
sctp_ss_fb_select(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net,
|
2011-01-23 19:36:28 +00:00
|
|
|
struct sctp_association *asoc)
|
|
|
|
{
|
|
|
|
struct sctp_stream_out *strq = NULL, *strqt;
|
|
|
|
|
2020-02-17 18:05:03 +00:00
|
|
|
if (asoc->ss_data.locked_on_sending) {
|
|
|
|
return (asoc->ss_data.locked_on_sending);
|
|
|
|
}
|
2016-08-06 12:33:15 +00:00
|
|
|
if (asoc->ss_data.last_out_stream == NULL ||
|
|
|
|
TAILQ_FIRST(&asoc->ss_data.out.wheel) == TAILQ_LAST(&asoc->ss_data.out.wheel, sctpwheel_listhead)) {
|
|
|
|
strqt = TAILQ_FIRST(&asoc->ss_data.out.wheel);
|
2011-01-23 19:36:28 +00:00
|
|
|
} else {
|
2016-08-06 12:33:15 +00:00
|
|
|
strqt = TAILQ_NEXT(asoc->ss_data.last_out_stream, ss_params.fb.next_spoke);
|
2011-01-23 19:36:28 +00:00
|
|
|
}
|
|
|
|
do {
|
2011-02-13 13:53:28 +00:00
|
|
|
if ((strqt != NULL) &&
|
|
|
|
((SCTP_BASE_SYSCTL(sctp_cmt_on_off) > 0) ||
|
|
|
|
(SCTP_BASE_SYSCTL(sctp_cmt_on_off) == 0 &&
|
|
|
|
(net == NULL || (TAILQ_FIRST(&strqt->outqueue) && TAILQ_FIRST(&strqt->outqueue)->net == NULL) ||
|
|
|
|
(net != NULL && TAILQ_FIRST(&strqt->outqueue) && TAILQ_FIRST(&strqt->outqueue)->net != NULL &&
|
|
|
|
TAILQ_FIRST(&strqt->outqueue)->net == net))))) {
|
2011-01-23 19:36:28 +00:00
|
|
|
if ((strqt->ss_params.fb.rounds >= 0) && (strq == NULL ||
|
|
|
|
strqt->ss_params.fb.rounds < strq->ss_params.fb.rounds)) {
|
|
|
|
strq = strqt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (strqt != NULL) {
|
|
|
|
strqt = TAILQ_NEXT(strqt, ss_params.fb.next_spoke);
|
|
|
|
} else {
|
2016-08-06 12:33:15 +00:00
|
|
|
strqt = TAILQ_FIRST(&asoc->ss_data.out.wheel);
|
2011-01-23 19:36:28 +00:00
|
|
|
}
|
|
|
|
} while (strqt != strq);
|
|
|
|
return (strq);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-08-06 12:33:15 +00:00
|
|
|
sctp_ss_fb_scheduled(struct sctp_tcb *stcb, struct sctp_nets *net SCTP_UNUSED,
|
2011-01-23 19:36:28 +00:00
|
|
|
struct sctp_association *asoc, struct sctp_stream_out *strq,
|
2011-12-17 19:21:40 +00:00
|
|
|
int moved_how_much SCTP_UNUSED)
|
2011-01-23 19:36:28 +00:00
|
|
|
{
|
2016-08-06 12:33:15 +00:00
|
|
|
struct sctp_stream_queue_pending *sp;
|
2011-01-23 19:36:28 +00:00
|
|
|
struct sctp_stream_out *strqt;
|
|
|
|
int subtract;
|
|
|
|
|
2016-08-06 12:33:15 +00:00
|
|
|
if (stcb->asoc.idata_supported == 0) {
|
|
|
|
sp = TAILQ_FIRST(&strq->outqueue);
|
|
|
|
if ((sp != NULL) && (sp->some_taken == 1)) {
|
|
|
|
stcb->asoc.ss_data.locked_on_sending = strq;
|
|
|
|
} else {
|
|
|
|
stcb->asoc.ss_data.locked_on_sending = NULL;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
stcb->asoc.ss_data.locked_on_sending = NULL;
|
|
|
|
}
|
2011-01-23 19:36:28 +00:00
|
|
|
subtract = strq->ss_params.fb.rounds;
|
2016-08-06 12:33:15 +00:00
|
|
|
TAILQ_FOREACH(strqt, &asoc->ss_data.out.wheel, ss_params.fb.next_spoke) {
|
2011-01-23 19:36:28 +00:00
|
|
|
strqt->ss_params.fb.rounds -= subtract;
|
|
|
|
if (strqt->ss_params.fb.rounds < 0)
|
|
|
|
strqt->ss_params.fb.rounds = 0;
|
|
|
|
}
|
|
|
|
if (TAILQ_FIRST(&strq->outqueue)) {
|
|
|
|
strq->ss_params.fb.rounds = TAILQ_FIRST(&strq->outqueue)->length;
|
|
|
|
} else {
|
|
|
|
strq->ss_params.fb.rounds = -1;
|
|
|
|
}
|
2016-08-06 12:33:15 +00:00
|
|
|
asoc->ss_data.last_out_stream = strq;
|
2011-01-23 19:36:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* First-come, first-serve algorithm.
|
|
|
|
* Maintains the order provided by the application.
|
|
|
|
*/
|
|
|
|
static void
|
2011-02-03 20:44:49 +00:00
|
|
|
sctp_ss_fcfs_add(struct sctp_tcb *stcb, struct sctp_association *asoc,
|
2020-06-14 09:50:00 +00:00
|
|
|
struct sctp_stream_out *strq SCTP_UNUSED,
|
|
|
|
struct sctp_stream_queue_pending *sp, int holds_lock);
|
2011-02-03 20:44:49 +00:00
|
|
|
|
|
|
|
static void
|
2011-01-23 19:36:28 +00:00
|
|
|
sctp_ss_fcfs_init(struct sctp_tcb *stcb, struct sctp_association *asoc,
|
|
|
|
int holds_lock)
|
|
|
|
{
|
2011-02-03 20:44:49 +00:00
|
|
|
uint32_t x, n = 0, add_more = 1;
|
2011-01-23 19:36:28 +00:00
|
|
|
struct sctp_stream_queue_pending *sp;
|
|
|
|
uint16_t i;
|
|
|
|
|
2019-03-08 18:16:19 +00:00
|
|
|
if (holds_lock == 0) {
|
|
|
|
SCTP_TCB_SEND_LOCK(stcb);
|
|
|
|
}
|
2016-08-06 12:33:15 +00:00
|
|
|
TAILQ_INIT(&asoc->ss_data.out.list);
|
2011-02-03 20:44:49 +00:00
|
|
|
/*
|
|
|
|
* If there is data in the stream queues already, the scheduler of
|
|
|
|
* an existing association has been changed. We can only cycle
|
|
|
|
* through the stream queues and add everything to the FCFS queue.
|
|
|
|
*/
|
2011-01-23 19:36:28 +00:00
|
|
|
while (add_more) {
|
|
|
|
add_more = 0;
|
|
|
|
for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
|
2011-02-03 20:44:49 +00:00
|
|
|
sp = TAILQ_FIRST(&stcb->asoc.strmout[i].outqueue);
|
|
|
|
x = 0;
|
|
|
|
/* Find n. message in current stream queue */
|
|
|
|
while (sp != NULL && x < n) {
|
2011-01-23 19:36:28 +00:00
|
|
|
sp = TAILQ_NEXT(sp, next);
|
2011-02-03 20:44:49 +00:00
|
|
|
x++;
|
2011-01-23 19:36:28 +00:00
|
|
|
}
|
|
|
|
if (sp != NULL) {
|
2019-03-08 18:16:19 +00:00
|
|
|
sctp_ss_fcfs_add(stcb, &stcb->asoc, &stcb->asoc.strmout[i], sp, 1);
|
2011-01-23 19:36:28 +00:00
|
|
|
add_more = 1;
|
|
|
|
}
|
|
|
|
}
|
2011-02-03 20:44:49 +00:00
|
|
|
n++;
|
2011-01-23 19:36:28 +00:00
|
|
|
}
|
2019-03-08 18:16:19 +00:00
|
|
|
if (holds_lock == 0) {
|
|
|
|
SCTP_TCB_SEND_UNLOCK(stcb);
|
|
|
|
}
|
2011-01-23 19:36:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sctp_ss_fcfs_clear(struct sctp_tcb *stcb, struct sctp_association *asoc,
|
|
|
|
int clear_values, int holds_lock)
|
|
|
|
{
|
2019-03-07 08:43:20 +00:00
|
|
|
struct sctp_stream_queue_pending *sp;
|
|
|
|
|
2011-01-23 19:36:28 +00:00
|
|
|
if (clear_values) {
|
2011-02-13 13:53:28 +00:00
|
|
|
if (holds_lock == 0) {
|
|
|
|
SCTP_TCB_SEND_LOCK(stcb);
|
|
|
|
}
|
2016-08-06 12:33:15 +00:00
|
|
|
while (!TAILQ_EMPTY(&asoc->ss_data.out.list)) {
|
2019-03-07 08:43:20 +00:00
|
|
|
sp = TAILQ_FIRST(&asoc->ss_data.out.list);
|
|
|
|
TAILQ_REMOVE(&asoc->ss_data.out.list, sp, ss_next);
|
|
|
|
sp->ss_next.tqe_next = NULL;
|
|
|
|
sp->ss_next.tqe_prev = NULL;
|
2011-01-23 19:36:28 +00:00
|
|
|
}
|
2011-02-13 13:53:28 +00:00
|
|
|
if (holds_lock == 0) {
|
|
|
|
SCTP_TCB_SEND_UNLOCK(stcb);
|
|
|
|
}
|
2011-01-23 19:36:28 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-08-06 12:33:15 +00:00
|
|
|
sctp_ss_fcfs_init_stream(struct sctp_tcb *stcb, struct sctp_stream_out *strq, struct sctp_stream_out *with_strq)
|
2011-01-23 19:36:28 +00:00
|
|
|
{
|
2016-08-06 12:33:15 +00:00
|
|
|
if (with_strq != NULL) {
|
|
|
|
if (stcb->asoc.ss_data.locked_on_sending == with_strq) {
|
|
|
|
stcb->asoc.ss_data.locked_on_sending = strq;
|
|
|
|
}
|
|
|
|
if (stcb->asoc.ss_data.last_out_stream == with_strq) {
|
|
|
|
stcb->asoc.ss_data.last_out_stream = strq;
|
|
|
|
}
|
|
|
|
}
|
2019-03-25 16:40:54 +00:00
|
|
|
strq->ss_params.fb.next_spoke.tqe_next = NULL;
|
|
|
|
strq->ss_params.fb.next_spoke.tqe_prev = NULL;
|
2011-01-23 19:36:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sctp_ss_fcfs_add(struct sctp_tcb *stcb, struct sctp_association *asoc,
|
2011-12-17 19:21:40 +00:00
|
|
|
struct sctp_stream_out *strq SCTP_UNUSED, struct sctp_stream_queue_pending *sp,
|
2011-01-23 19:36:28 +00:00
|
|
|
int holds_lock)
|
|
|
|
{
|
|
|
|
if (holds_lock == 0) {
|
|
|
|
SCTP_TCB_SEND_LOCK(stcb);
|
|
|
|
}
|
2011-02-03 20:44:49 +00:00
|
|
|
if (sp && (sp->ss_next.tqe_next == NULL) &&
|
|
|
|
(sp->ss_next.tqe_prev == NULL)) {
|
2016-08-06 12:33:15 +00:00
|
|
|
TAILQ_INSERT_TAIL(&asoc->ss_data.out.list, sp, ss_next);
|
2011-01-23 19:36:28 +00:00
|
|
|
}
|
|
|
|
if (holds_lock == 0) {
|
|
|
|
SCTP_TCB_SEND_UNLOCK(stcb);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2011-12-17 19:21:40 +00:00
|
|
|
sctp_ss_fcfs_is_empty(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_association *asoc)
|
2011-01-23 19:36:28 +00:00
|
|
|
{
|
2016-08-06 12:33:15 +00:00
|
|
|
if (TAILQ_EMPTY(&asoc->ss_data.out.list)) {
|
2011-01-23 19:36:28 +00:00
|
|
|
return (1);
|
|
|
|
} else {
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sctp_ss_fcfs_remove(struct sctp_tcb *stcb, struct sctp_association *asoc,
|
2011-12-17 19:21:40 +00:00
|
|
|
struct sctp_stream_out *strq SCTP_UNUSED, struct sctp_stream_queue_pending *sp,
|
2011-01-23 19:36:28 +00:00
|
|
|
int holds_lock)
|
|
|
|
{
|
|
|
|
if (holds_lock == 0) {
|
|
|
|
SCTP_TCB_SEND_LOCK(stcb);
|
|
|
|
}
|
|
|
|
if (sp &&
|
2011-02-03 20:44:49 +00:00
|
|
|
((sp->ss_next.tqe_next != NULL) ||
|
|
|
|
(sp->ss_next.tqe_prev != NULL))) {
|
2016-08-06 12:33:15 +00:00
|
|
|
TAILQ_REMOVE(&asoc->ss_data.out.list, sp, ss_next);
|
2019-03-07 08:43:20 +00:00
|
|
|
sp->ss_next.tqe_next = NULL;
|
|
|
|
sp->ss_next.tqe_prev = NULL;
|
2011-01-23 19:36:28 +00:00
|
|
|
}
|
|
|
|
if (holds_lock == 0) {
|
|
|
|
SCTP_TCB_SEND_UNLOCK(stcb);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct sctp_stream_out *
|
2011-12-17 19:21:40 +00:00
|
|
|
sctp_ss_fcfs_select(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net,
|
2011-01-23 19:36:28 +00:00
|
|
|
struct sctp_association *asoc)
|
|
|
|
{
|
|
|
|
struct sctp_stream_out *strq;
|
|
|
|
struct sctp_stream_queue_pending *sp;
|
|
|
|
|
2020-02-17 18:05:03 +00:00
|
|
|
if (asoc->ss_data.locked_on_sending) {
|
|
|
|
return (asoc->ss_data.locked_on_sending);
|
|
|
|
}
|
2016-08-06 12:33:15 +00:00
|
|
|
sp = TAILQ_FIRST(&asoc->ss_data.out.list);
|
2011-01-23 19:36:28 +00:00
|
|
|
default_again:
|
|
|
|
if (sp != NULL) {
|
2016-12-07 19:30:59 +00:00
|
|
|
strq = &asoc->strmout[sp->sid];
|
2011-01-23 19:36:28 +00:00
|
|
|
} else {
|
|
|
|
strq = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If CMT is off, we must validate that the stream in question has
|
2011-02-05 12:12:51 +00:00
|
|
|
* the first item pointed towards are network destination requested
|
2011-01-23 19:36:28 +00:00
|
|
|
* by the caller. Note that if we turn out to be locked to a stream
|
|
|
|
* (assigning TSN's then we must stop, since we cannot look for
|
|
|
|
* another stream with data to send to that destination). In CMT's
|
|
|
|
* case, by skipping this check, we will send one data packet
|
|
|
|
* towards the requested net.
|
|
|
|
*/
|
|
|
|
if (net != NULL && strq != NULL &&
|
|
|
|
SCTP_BASE_SYSCTL(sctp_cmt_on_off) == 0) {
|
|
|
|
if (TAILQ_FIRST(&strq->outqueue) &&
|
|
|
|
TAILQ_FIRST(&strq->outqueue)->net != NULL &&
|
|
|
|
TAILQ_FIRST(&strq->outqueue)->net != net) {
|
2011-02-03 20:44:49 +00:00
|
|
|
sp = TAILQ_NEXT(sp, ss_next);
|
2011-01-23 19:36:28 +00:00
|
|
|
goto default_again;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (strq);
|
|
|
|
}
|
|
|
|
|
2016-03-23 13:28:04 +00:00
|
|
|
const struct sctp_ss_functions sctp_ss_functions[] = {
|
2011-01-23 19:36:28 +00:00
|
|
|
/* SCTP_SS_DEFAULT */
|
|
|
|
{
|
|
|
|
.sctp_ss_init = sctp_ss_default_init,
|
|
|
|
.sctp_ss_clear = sctp_ss_default_clear,
|
|
|
|
.sctp_ss_init_stream = sctp_ss_default_init_stream,
|
|
|
|
.sctp_ss_add_to_stream = sctp_ss_default_add,
|
|
|
|
.sctp_ss_is_empty = sctp_ss_default_is_empty,
|
|
|
|
.sctp_ss_remove_from_stream = sctp_ss_default_remove,
|
|
|
|
.sctp_ss_select_stream = sctp_ss_default_select,
|
|
|
|
.sctp_ss_scheduled = sctp_ss_default_scheduled,
|
|
|
|
.sctp_ss_packet_done = sctp_ss_default_packet_done,
|
|
|
|
.sctp_ss_get_value = sctp_ss_default_get_value,
|
2016-08-06 12:33:15 +00:00
|
|
|
.sctp_ss_set_value = sctp_ss_default_set_value,
|
|
|
|
.sctp_ss_is_user_msgs_incomplete = sctp_ss_default_is_user_msgs_incomplete
|
2011-01-23 19:36:28 +00:00
|
|
|
},
|
|
|
|
/* SCTP_SS_ROUND_ROBIN */
|
|
|
|
{
|
|
|
|
.sctp_ss_init = sctp_ss_default_init,
|
|
|
|
.sctp_ss_clear = sctp_ss_default_clear,
|
|
|
|
.sctp_ss_init_stream = sctp_ss_default_init_stream,
|
|
|
|
.sctp_ss_add_to_stream = sctp_ss_rr_add,
|
|
|
|
.sctp_ss_is_empty = sctp_ss_default_is_empty,
|
|
|
|
.sctp_ss_remove_from_stream = sctp_ss_default_remove,
|
|
|
|
.sctp_ss_select_stream = sctp_ss_default_select,
|
|
|
|
.sctp_ss_scheduled = sctp_ss_default_scheduled,
|
|
|
|
.sctp_ss_packet_done = sctp_ss_default_packet_done,
|
|
|
|
.sctp_ss_get_value = sctp_ss_default_get_value,
|
2016-08-06 12:33:15 +00:00
|
|
|
.sctp_ss_set_value = sctp_ss_default_set_value,
|
|
|
|
.sctp_ss_is_user_msgs_incomplete = sctp_ss_default_is_user_msgs_incomplete
|
2011-01-23 19:36:28 +00:00
|
|
|
},
|
|
|
|
/* SCTP_SS_ROUND_ROBIN_PACKET */
|
|
|
|
{
|
|
|
|
.sctp_ss_init = sctp_ss_default_init,
|
|
|
|
.sctp_ss_clear = sctp_ss_default_clear,
|
|
|
|
.sctp_ss_init_stream = sctp_ss_default_init_stream,
|
2011-02-13 13:53:28 +00:00
|
|
|
.sctp_ss_add_to_stream = sctp_ss_rr_add,
|
2011-01-23 19:36:28 +00:00
|
|
|
.sctp_ss_is_empty = sctp_ss_default_is_empty,
|
|
|
|
.sctp_ss_remove_from_stream = sctp_ss_default_remove,
|
|
|
|
.sctp_ss_select_stream = sctp_ss_rrp_select,
|
|
|
|
.sctp_ss_scheduled = sctp_ss_default_scheduled,
|
|
|
|
.sctp_ss_packet_done = sctp_ss_rrp_packet_done,
|
|
|
|
.sctp_ss_get_value = sctp_ss_default_get_value,
|
2016-08-06 12:33:15 +00:00
|
|
|
.sctp_ss_set_value = sctp_ss_default_set_value,
|
|
|
|
.sctp_ss_is_user_msgs_incomplete = sctp_ss_default_is_user_msgs_incomplete
|
2011-01-23 19:36:28 +00:00
|
|
|
},
|
|
|
|
/* SCTP_SS_PRIORITY */
|
|
|
|
{
|
|
|
|
.sctp_ss_init = sctp_ss_default_init,
|
|
|
|
.sctp_ss_clear = sctp_ss_prio_clear,
|
|
|
|
.sctp_ss_init_stream = sctp_ss_prio_init_stream,
|
|
|
|
.sctp_ss_add_to_stream = sctp_ss_prio_add,
|
|
|
|
.sctp_ss_is_empty = sctp_ss_default_is_empty,
|
|
|
|
.sctp_ss_remove_from_stream = sctp_ss_prio_remove,
|
|
|
|
.sctp_ss_select_stream = sctp_ss_prio_select,
|
|
|
|
.sctp_ss_scheduled = sctp_ss_default_scheduled,
|
|
|
|
.sctp_ss_packet_done = sctp_ss_default_packet_done,
|
|
|
|
.sctp_ss_get_value = sctp_ss_prio_get_value,
|
2016-08-06 12:33:15 +00:00
|
|
|
.sctp_ss_set_value = sctp_ss_prio_set_value,
|
|
|
|
.sctp_ss_is_user_msgs_incomplete = sctp_ss_default_is_user_msgs_incomplete
|
2011-01-23 19:36:28 +00:00
|
|
|
},
|
|
|
|
/* SCTP_SS_FAIR_BANDWITH */
|
|
|
|
{
|
|
|
|
.sctp_ss_init = sctp_ss_default_init,
|
|
|
|
.sctp_ss_clear = sctp_ss_fb_clear,
|
|
|
|
.sctp_ss_init_stream = sctp_ss_fb_init_stream,
|
|
|
|
.sctp_ss_add_to_stream = sctp_ss_fb_add,
|
|
|
|
.sctp_ss_is_empty = sctp_ss_default_is_empty,
|
|
|
|
.sctp_ss_remove_from_stream = sctp_ss_fb_remove,
|
|
|
|
.sctp_ss_select_stream = sctp_ss_fb_select,
|
|
|
|
.sctp_ss_scheduled = sctp_ss_fb_scheduled,
|
|
|
|
.sctp_ss_packet_done = sctp_ss_default_packet_done,
|
|
|
|
.sctp_ss_get_value = sctp_ss_default_get_value,
|
2016-08-06 12:33:15 +00:00
|
|
|
.sctp_ss_set_value = sctp_ss_default_set_value,
|
|
|
|
.sctp_ss_is_user_msgs_incomplete = sctp_ss_default_is_user_msgs_incomplete
|
2011-01-23 19:36:28 +00:00
|
|
|
},
|
|
|
|
/* SCTP_SS_FIRST_COME */
|
|
|
|
{
|
|
|
|
.sctp_ss_init = sctp_ss_fcfs_init,
|
|
|
|
.sctp_ss_clear = sctp_ss_fcfs_clear,
|
|
|
|
.sctp_ss_init_stream = sctp_ss_fcfs_init_stream,
|
|
|
|
.sctp_ss_add_to_stream = sctp_ss_fcfs_add,
|
|
|
|
.sctp_ss_is_empty = sctp_ss_fcfs_is_empty,
|
|
|
|
.sctp_ss_remove_from_stream = sctp_ss_fcfs_remove,
|
|
|
|
.sctp_ss_select_stream = sctp_ss_fcfs_select,
|
|
|
|
.sctp_ss_scheduled = sctp_ss_default_scheduled,
|
|
|
|
.sctp_ss_packet_done = sctp_ss_default_packet_done,
|
|
|
|
.sctp_ss_get_value = sctp_ss_default_get_value,
|
2016-08-06 12:33:15 +00:00
|
|
|
.sctp_ss_set_value = sctp_ss_default_set_value,
|
|
|
|
.sctp_ss_is_user_msgs_incomplete = sctp_ss_default_is_user_msgs_incomplete
|
2011-01-23 19:36:28 +00:00
|
|
|
}
|
|
|
|
};
|