2006-11-03 15:23:16 +00:00
|
|
|
/*-
|
2017-11-20 19:43:44 +00:00
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
*
|
2008-12-06 13:19:54 +00:00
|
|
|
* Copyright (c) 2001-2008, by Cisco Systems, Inc. All rights reserved.
|
2012-05-23 11:26:28 +00:00
|
|
|
* Copyright (c) 2008-2012, by Randall Stewart. All rights reserved.
|
|
|
|
* Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved.
|
2006-11-03 15:23:16 +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.
|
2006-11-03 15:23:16 +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.
|
2006-11-03 15:23:16 +00:00
|
|
|
*
|
|
|
|
* c) Neither the name of Cisco Systems, Inc. nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* 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_os.h>
|
|
|
|
#include <netinet/sctp_pcb.h>
|
|
|
|
#include <netinet/sctputil.h>
|
|
|
|
#include <netinet/sctp_var.h>
|
2007-03-15 11:27:14 +00:00
|
|
|
#include <netinet/sctp_sysctl.h>
|
2006-11-03 15:23:16 +00:00
|
|
|
#ifdef INET6
|
2012-11-17 20:04:04 +00:00
|
|
|
#include <netinet6/sctp6_var.h>
|
2006-11-03 15:23:16 +00:00
|
|
|
#endif
|
|
|
|
#include <netinet/sctp_header.h>
|
|
|
|
#include <netinet/sctp_output.h>
|
|
|
|
#include <netinet/sctp_uio.h>
|
|
|
|
#include <netinet/sctp_timer.h>
|
2018-01-15 21:59:20 +00:00
|
|
|
#include <netinet/sctp_indata.h>
|
2006-11-03 15:23:16 +00:00
|
|
|
#include <netinet/sctp_auth.h>
|
|
|
|
#include <netinet/sctp_asconf.h>
|
2010-05-16 17:03:56 +00:00
|
|
|
#include <netinet/sctp_bsd_addr.h>
|
2017-04-29 19:20:50 +00:00
|
|
|
#if defined(INET6) || defined(INET)
|
|
|
|
#include <netinet/tcp_var.h>
|
|
|
|
#endif
|
2012-11-17 20:04:04 +00:00
|
|
|
#include <netinet/udp.h>
|
|
|
|
#include <netinet/udp_var.h>
|
2018-08-22 21:23:32 +00:00
|
|
|
#include <netinet/in_kdtrace.h>
|
2012-11-17 20:04:04 +00:00
|
|
|
#include <sys/proc.h>
|
2016-04-29 20:22:01 +00:00
|
|
|
#ifdef INET6
|
|
|
|
#include <netinet/icmp6.h>
|
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
|
2007-06-15 20:54:12 +00:00
|
|
|
#ifndef KTR_SCTP
|
|
|
|
#define KTR_SCTP KTR_SUBSYS
|
2007-06-14 22:59:04 +00:00
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2016-03-23 13:28:04 +00:00
|
|
|
extern const struct sctp_cc_functions sctp_cc_functions[];
|
|
|
|
extern const struct sctp_ss_functions sctp_ss_functions[];
|
2011-01-19 22:10:35 +00:00
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
void
|
2012-09-14 18:32:20 +00:00
|
|
|
sctp_sblog(struct sockbuf *sb, struct sctp_tcb *stcb, int from, int incr)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
2018-05-21 14:53:22 +00:00
|
|
|
#if defined(SCTP_LOCAL_TRACE_BUF)
|
|
|
|
struct sctp_cwnd_log sctp_clog;
|
2007-06-14 22:59:04 +00:00
|
|
|
|
|
|
|
sctp_clog.x.sb.stcb = stcb;
|
2014-12-02 20:29:29 +00:00
|
|
|
sctp_clog.x.sb.so_sbcc = sb->sb_cc;
|
2006-11-03 15:23:16 +00:00
|
|
|
if (stcb)
|
2014-12-02 20:29:29 +00:00
|
|
|
sctp_clog.x.sb.stcb_sbcc = stcb->asoc.sb_cc;
|
2006-11-03 15:23:16 +00:00
|
|
|
else
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_clog.x.sb.stcb_sbcc = 0;
|
|
|
|
sctp_clog.x.sb.incr = incr;
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_CTR6(KTR_SCTP, "SCTP:%d[%d]:%x-%x-%x-%x",
|
2007-06-14 22:59:04 +00:00
|
|
|
SCTP_LOG_EVENT_SB,
|
|
|
|
from,
|
|
|
|
sctp_clog.x.misc.log1,
|
|
|
|
sctp_clog.x.misc.log2,
|
|
|
|
sctp_clog.x.misc.log3,
|
|
|
|
sctp_clog.x.misc.log4);
|
2018-05-21 14:53:22 +00:00
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sctp_log_closing(struct sctp_inpcb *inp, struct sctp_tcb *stcb, int16_t loc)
|
|
|
|
{
|
2018-05-21 14:53:22 +00:00
|
|
|
#if defined(SCTP_LOCAL_TRACE_BUF)
|
|
|
|
struct sctp_cwnd_log sctp_clog;
|
2007-06-14 22:59:04 +00:00
|
|
|
|
|
|
|
sctp_clog.x.close.inp = (void *)inp;
|
|
|
|
sctp_clog.x.close.sctp_flags = inp->sctp_flags;
|
2006-11-03 15:23:16 +00:00
|
|
|
if (stcb) {
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_clog.x.close.stcb = (void *)stcb;
|
2018-07-19 20:11:14 +00:00
|
|
|
sctp_clog.x.close.state = (uint16_t)stcb->asoc.state;
|
2006-11-03 15:23:16 +00:00
|
|
|
} else {
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_clog.x.close.stcb = 0;
|
|
|
|
sctp_clog.x.close.state = 0;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_clog.x.close.loc = loc;
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_CTR6(KTR_SCTP, "SCTP:%d[%d]:%x-%x-%x-%x",
|
2007-06-14 22:59:04 +00:00
|
|
|
SCTP_LOG_EVENT_CLOSE,
|
|
|
|
0,
|
|
|
|
sctp_clog.x.misc.log1,
|
|
|
|
sctp_clog.x.misc.log2,
|
|
|
|
sctp_clog.x.misc.log3,
|
|
|
|
sctp_clog.x.misc.log4);
|
2018-05-21 14:53:22 +00:00
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
rto_logging(struct sctp_nets *net, int from)
|
|
|
|
{
|
2018-05-21 14:53:22 +00:00
|
|
|
#if defined(SCTP_LOCAL_TRACE_BUF)
|
|
|
|
struct sctp_cwnd_log sctp_clog;
|
2007-06-14 22:59:04 +00:00
|
|
|
|
2008-05-20 09:51:36 +00:00
|
|
|
memset(&sctp_clog, 0, sizeof(sctp_clog));
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_clog.x.rto.net = (void *)net;
|
2011-02-24 22:36:40 +00:00
|
|
|
sctp_clog.x.rto.rtt = net->rtt / 1000;
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_CTR6(KTR_SCTP, "SCTP:%d[%d]:%x-%x-%x-%x",
|
2007-06-14 22:59:04 +00:00
|
|
|
SCTP_LOG_EVENT_RTT,
|
|
|
|
from,
|
|
|
|
sctp_clog.x.misc.log1,
|
|
|
|
sctp_clog.x.misc.log2,
|
|
|
|
sctp_clog.x.misc.log3,
|
|
|
|
sctp_clog.x.misc.log4);
|
2018-05-21 14:53:22 +00:00
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-11-11 15:59:01 +00:00
|
|
|
sctp_log_strm_del_alt(struct sctp_tcb *stcb, uint32_t tsn, uint16_t sseq, uint16_t stream, int from)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
2018-05-21 14:53:22 +00:00
|
|
|
#if defined(SCTP_LOCAL_TRACE_BUF)
|
|
|
|
struct sctp_cwnd_log sctp_clog;
|
2007-06-14 22:59:04 +00:00
|
|
|
|
|
|
|
sctp_clog.x.strlog.stcb = stcb;
|
|
|
|
sctp_clog.x.strlog.n_tsn = tsn;
|
|
|
|
sctp_clog.x.strlog.n_sseq = sseq;
|
|
|
|
sctp_clog.x.strlog.e_tsn = 0;
|
|
|
|
sctp_clog.x.strlog.e_sseq = 0;
|
|
|
|
sctp_clog.x.strlog.strm = stream;
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_CTR6(KTR_SCTP, "SCTP:%d[%d]:%x-%x-%x-%x",
|
2007-06-14 22:59:04 +00:00
|
|
|
SCTP_LOG_EVENT_STRM,
|
|
|
|
from,
|
|
|
|
sctp_clog.x.misc.log1,
|
|
|
|
sctp_clog.x.misc.log2,
|
|
|
|
sctp_clog.x.misc.log3,
|
|
|
|
sctp_clog.x.misc.log4);
|
2018-05-21 14:53:22 +00:00
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sctp_log_nagle_event(struct sctp_tcb *stcb, int action)
|
|
|
|
{
|
2018-05-21 14:53:22 +00:00
|
|
|
#if defined(SCTP_LOCAL_TRACE_BUF)
|
|
|
|
struct sctp_cwnd_log sctp_clog;
|
2007-06-14 22:59:04 +00:00
|
|
|
|
|
|
|
sctp_clog.x.nagle.stcb = (void *)stcb;
|
|
|
|
sctp_clog.x.nagle.total_flight = stcb->asoc.total_flight;
|
|
|
|
sctp_clog.x.nagle.total_in_queue = stcb->asoc.total_output_queue_size;
|
|
|
|
sctp_clog.x.nagle.count_in_queue = stcb->asoc.chunks_on_out_queue;
|
|
|
|
sctp_clog.x.nagle.count_in_flight = stcb->asoc.total_flight_count;
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_CTR6(KTR_SCTP, "SCTP:%d[%d]:%x-%x-%x-%x",
|
2007-06-14 22:59:04 +00:00
|
|
|
SCTP_LOG_EVENT_NAGLE,
|
|
|
|
action,
|
|
|
|
sctp_clog.x.misc.log1,
|
|
|
|
sctp_clog.x.misc.log2,
|
|
|
|
sctp_clog.x.misc.log3,
|
|
|
|
sctp_clog.x.misc.log4);
|
2018-05-21 14:53:22 +00:00
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sctp_log_sack(uint32_t old_cumack, uint32_t cumack, uint32_t tsn, uint16_t gaps, uint16_t dups, int from)
|
|
|
|
{
|
2018-05-21 14:53:22 +00:00
|
|
|
#if defined(SCTP_LOCAL_TRACE_BUF)
|
|
|
|
struct sctp_cwnd_log sctp_clog;
|
2007-06-14 22:59:04 +00:00
|
|
|
|
|
|
|
sctp_clog.x.sack.cumack = cumack;
|
|
|
|
sctp_clog.x.sack.oldcumack = old_cumack;
|
|
|
|
sctp_clog.x.sack.tsn = tsn;
|
|
|
|
sctp_clog.x.sack.numGaps = gaps;
|
|
|
|
sctp_clog.x.sack.numDups = dups;
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_CTR6(KTR_SCTP, "SCTP:%d[%d]:%x-%x-%x-%x",
|
2007-06-14 22:59:04 +00:00
|
|
|
SCTP_LOG_EVENT_SACK,
|
|
|
|
from,
|
|
|
|
sctp_clog.x.misc.log1,
|
|
|
|
sctp_clog.x.misc.log2,
|
|
|
|
sctp_clog.x.misc.log3,
|
|
|
|
sctp_clog.x.misc.log4);
|
2018-05-21 14:53:22 +00:00
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sctp_log_map(uint32_t map, uint32_t cum, uint32_t high, int from)
|
|
|
|
{
|
2018-05-21 14:53:22 +00:00
|
|
|
#if defined(SCTP_LOCAL_TRACE_BUF)
|
|
|
|
struct sctp_cwnd_log sctp_clog;
|
2007-06-14 22:59:04 +00:00
|
|
|
|
2008-05-20 09:51:36 +00:00
|
|
|
memset(&sctp_clog, 0, sizeof(sctp_clog));
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_clog.x.map.base = map;
|
|
|
|
sctp_clog.x.map.cum = cum;
|
|
|
|
sctp_clog.x.map.high = high;
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_CTR6(KTR_SCTP, "SCTP:%d[%d]:%x-%x-%x-%x",
|
2007-06-14 22:59:04 +00:00
|
|
|
SCTP_LOG_EVENT_MAP,
|
|
|
|
from,
|
|
|
|
sctp_clog.x.misc.log1,
|
|
|
|
sctp_clog.x.misc.log2,
|
|
|
|
sctp_clog.x.misc.log3,
|
|
|
|
sctp_clog.x.misc.log4);
|
2018-05-21 14:53:22 +00:00
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-09-14 18:32:20 +00:00
|
|
|
sctp_log_fr(uint32_t biggest_tsn, uint32_t biggest_new_tsn, uint32_t tsn, int from)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
2018-05-21 14:53:22 +00:00
|
|
|
#if defined(SCTP_LOCAL_TRACE_BUF)
|
|
|
|
struct sctp_cwnd_log sctp_clog;
|
2007-06-14 22:59:04 +00:00
|
|
|
|
2008-05-20 09:51:36 +00:00
|
|
|
memset(&sctp_clog, 0, sizeof(sctp_clog));
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_clog.x.fr.largest_tsn = biggest_tsn;
|
|
|
|
sctp_clog.x.fr.largest_new_tsn = biggest_new_tsn;
|
|
|
|
sctp_clog.x.fr.tsn = tsn;
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_CTR6(KTR_SCTP, "SCTP:%d[%d]:%x-%x-%x-%x",
|
2007-06-14 22:59:04 +00:00
|
|
|
SCTP_LOG_EVENT_FR,
|
|
|
|
from,
|
|
|
|
sctp_clog.x.misc.log1,
|
|
|
|
sctp_clog.x.misc.log2,
|
|
|
|
sctp_clog.x.misc.log3,
|
|
|
|
sctp_clog.x.misc.log4);
|
2018-05-21 14:53:22 +00:00
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
2015-01-10 20:49:57 +00:00
|
|
|
#ifdef SCTP_MBUF_LOGGING
|
2006-11-03 15:23:16 +00:00
|
|
|
void
|
|
|
|
sctp_log_mb(struct mbuf *m, int from)
|
|
|
|
{
|
2018-05-21 14:53:22 +00:00
|
|
|
#if defined(SCTP_LOCAL_TRACE_BUF)
|
|
|
|
struct sctp_cwnd_log sctp_clog;
|
2007-06-14 22:59:04 +00:00
|
|
|
|
|
|
|
sctp_clog.x.mb.mp = m;
|
2018-07-19 20:11:14 +00:00
|
|
|
sctp_clog.x.mb.mbuf_flags = (uint8_t)(SCTP_BUF_GET_FLAGS(m));
|
|
|
|
sctp_clog.x.mb.size = (uint16_t)(SCTP_BUF_LEN(m));
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_clog.x.mb.data = SCTP_BUF_AT(m, 0);
|
2006-12-29 20:21:42 +00:00
|
|
|
if (SCTP_BUF_IS_EXTENDED(m)) {
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_clog.x.mb.ext = SCTP_BUF_EXTEND_BASE(m);
|
2018-07-19 20:11:14 +00:00
|
|
|
sctp_clog.x.mb.refcnt = (uint8_t)(SCTP_BUF_EXTEND_REFCNT(m));
|
2006-11-03 15:23:16 +00:00
|
|
|
} else {
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_clog.x.mb.ext = 0;
|
|
|
|
sctp_clog.x.mb.refcnt = 0;
|
|
|
|
}
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_CTR6(KTR_SCTP, "SCTP:%d[%d]:%x-%x-%x-%x",
|
2007-06-14 22:59:04 +00:00
|
|
|
SCTP_LOG_EVENT_MBUF,
|
|
|
|
from,
|
|
|
|
sctp_clog.x.misc.log1,
|
|
|
|
sctp_clog.x.misc.log2,
|
|
|
|
sctp_clog.x.misc.log3,
|
|
|
|
sctp_clog.x.misc.log4);
|
2018-05-21 14:53:22 +00:00
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
2015-01-10 20:49:57 +00:00
|
|
|
void
|
|
|
|
sctp_log_mbc(struct mbuf *m, int from)
|
|
|
|
{
|
|
|
|
struct mbuf *mat;
|
|
|
|
|
|
|
|
for (mat = m; mat; mat = SCTP_BUF_NEXT(mat)) {
|
|
|
|
sctp_log_mb(mat, from);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
void
|
2012-09-14 18:32:20 +00:00
|
|
|
sctp_log_strm_del(struct sctp_queued_to_read *control, struct sctp_queued_to_read *poschk, int from)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
2018-05-21 14:53:22 +00:00
|
|
|
#if defined(SCTP_LOCAL_TRACE_BUF)
|
|
|
|
struct sctp_cwnd_log sctp_clog;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
if (control == NULL) {
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTP_PRINTF("Gak log of NULL?\n");
|
2006-11-03 15:23:16 +00:00
|
|
|
return;
|
|
|
|
}
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_clog.x.strlog.stcb = control->stcb;
|
|
|
|
sctp_clog.x.strlog.n_tsn = control->sinfo_tsn;
|
2018-07-19 20:11:14 +00:00
|
|
|
sctp_clog.x.strlog.n_sseq = (uint16_t)control->mid;
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_clog.x.strlog.strm = control->sinfo_stream;
|
2006-11-03 15:23:16 +00:00
|
|
|
if (poschk != NULL) {
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_clog.x.strlog.e_tsn = poschk->sinfo_tsn;
|
2018-07-19 20:11:14 +00:00
|
|
|
sctp_clog.x.strlog.e_sseq = (uint16_t)poschk->mid;
|
2006-11-03 15:23:16 +00:00
|
|
|
} else {
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_clog.x.strlog.e_tsn = 0;
|
|
|
|
sctp_clog.x.strlog.e_sseq = 0;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_CTR6(KTR_SCTP, "SCTP:%d[%d]:%x-%x-%x-%x",
|
2007-06-14 22:59:04 +00:00
|
|
|
SCTP_LOG_EVENT_STRM,
|
|
|
|
from,
|
|
|
|
sctp_clog.x.misc.log1,
|
|
|
|
sctp_clog.x.misc.log2,
|
|
|
|
sctp_clog.x.misc.log3,
|
|
|
|
sctp_clog.x.misc.log4);
|
2018-05-21 14:53:22 +00:00
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sctp_log_cwnd(struct sctp_tcb *stcb, struct sctp_nets *net, int augment, uint8_t from)
|
|
|
|
{
|
2018-05-21 14:53:22 +00:00
|
|
|
#if defined(SCTP_LOCAL_TRACE_BUF)
|
|
|
|
struct sctp_cwnd_log sctp_clog;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_clog.x.cwnd.net = net;
|
2006-11-03 15:23:16 +00:00
|
|
|
if (stcb->asoc.send_queue_cnt > 255)
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_clog.x.cwnd.cnt_in_send = 255;
|
2006-11-03 15:23:16 +00:00
|
|
|
else
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_clog.x.cwnd.cnt_in_send = stcb->asoc.send_queue_cnt;
|
2006-11-03 15:23:16 +00:00
|
|
|
if (stcb->asoc.stream_queue_cnt > 255)
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_clog.x.cwnd.cnt_in_str = 255;
|
2006-11-03 15:23:16 +00:00
|
|
|
else
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_clog.x.cwnd.cnt_in_str = stcb->asoc.stream_queue_cnt;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
if (net) {
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_clog.x.cwnd.cwnd_new_value = net->cwnd;
|
|
|
|
sctp_clog.x.cwnd.inflight = net->flight_size;
|
|
|
|
sctp_clog.x.cwnd.pseudo_cumack = net->pseudo_cumack;
|
|
|
|
sctp_clog.x.cwnd.meets_pseudo_cumack = net->new_pseudo_cumack;
|
|
|
|
sctp_clog.x.cwnd.need_new_pseudo_cumack = net->find_pseudo_cumack;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
if (SCTP_CWNDLOG_PRESEND == from) {
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_clog.x.cwnd.meets_pseudo_cumack = stcb->asoc.peers_rwnd;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_clog.x.cwnd.cwnd_augment = augment;
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_CTR6(KTR_SCTP, "SCTP:%d[%d]:%x-%x-%x-%x",
|
2007-06-14 22:59:04 +00:00
|
|
|
SCTP_LOG_EVENT_CWND,
|
|
|
|
from,
|
|
|
|
sctp_clog.x.misc.log1,
|
|
|
|
sctp_clog.x.misc.log2,
|
|
|
|
sctp_clog.x.misc.log3,
|
|
|
|
sctp_clog.x.misc.log4);
|
2018-05-21 14:53:22 +00:00
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sctp_log_lock(struct sctp_inpcb *inp, struct sctp_tcb *stcb, uint8_t from)
|
|
|
|
{
|
2018-05-21 14:53:22 +00:00
|
|
|
#if defined(SCTP_LOCAL_TRACE_BUF)
|
|
|
|
struct sctp_cwnd_log sctp_clog;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2008-05-20 09:51:36 +00:00
|
|
|
memset(&sctp_clog, 0, sizeof(sctp_clog));
|
2006-11-08 00:21:13 +00:00
|
|
|
if (inp) {
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_clog.x.lock.sock = (void *)inp->sctp_socket;
|
2006-11-08 00:21:13 +00:00
|
|
|
|
|
|
|
} else {
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_clog.x.lock.sock = (void *)NULL;
|
2006-11-08 00:21:13 +00:00
|
|
|
}
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_clog.x.lock.inp = (void *)inp;
|
2006-11-03 15:23:16 +00:00
|
|
|
if (stcb) {
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_clog.x.lock.tcb_lock = mtx_owned(&stcb->tcb_mtx);
|
2006-11-03 15:23:16 +00:00
|
|
|
} else {
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_clog.x.lock.tcb_lock = SCTP_LOCK_UNKNOWN;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
if (inp) {
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_clog.x.lock.inp_lock = mtx_owned(&inp->inp_mtx);
|
|
|
|
sctp_clog.x.lock.create_lock = mtx_owned(&inp->inp_create_mtx);
|
2006-11-03 15:23:16 +00:00
|
|
|
} else {
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_clog.x.lock.inp_lock = SCTP_LOCK_UNKNOWN;
|
|
|
|
sctp_clog.x.lock.create_lock = SCTP_LOCK_UNKNOWN;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2008-06-14 07:58:05 +00:00
|
|
|
sctp_clog.x.lock.info_lock = rw_wowned(&SCTP_BASE_INFO(ipi_ep_mtx));
|
2010-09-05 13:41:45 +00:00
|
|
|
if (inp && (inp->sctp_socket)) {
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_clog.x.lock.sock_lock = mtx_owned(&(inp->sctp_socket->so_rcv.sb_mtx));
|
|
|
|
sctp_clog.x.lock.sockrcvbuf_lock = mtx_owned(&(inp->sctp_socket->so_rcv.sb_mtx));
|
|
|
|
sctp_clog.x.lock.socksndbuf_lock = mtx_owned(&(inp->sctp_socket->so_snd.sb_mtx));
|
2006-11-03 15:23:16 +00:00
|
|
|
} else {
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_clog.x.lock.sock_lock = SCTP_LOCK_UNKNOWN;
|
|
|
|
sctp_clog.x.lock.sockrcvbuf_lock = SCTP_LOCK_UNKNOWN;
|
|
|
|
sctp_clog.x.lock.socksndbuf_lock = SCTP_LOCK_UNKNOWN;
|
|
|
|
}
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_CTR6(KTR_SCTP, "SCTP:%d[%d]:%x-%x-%x-%x",
|
2007-06-14 22:59:04 +00:00
|
|
|
SCTP_LOG_LOCK_EVENT,
|
|
|
|
from,
|
|
|
|
sctp_clog.x.misc.log1,
|
|
|
|
sctp_clog.x.misc.log2,
|
|
|
|
sctp_clog.x.misc.log3,
|
|
|
|
sctp_clog.x.misc.log4);
|
2018-05-21 14:53:22 +00:00
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sctp_log_maxburst(struct sctp_tcb *stcb, struct sctp_nets *net, int error, int burst, uint8_t from)
|
|
|
|
{
|
2018-05-21 14:53:22 +00:00
|
|
|
#if defined(SCTP_LOCAL_TRACE_BUF)
|
|
|
|
struct sctp_cwnd_log sctp_clog;
|
2007-06-14 22:59:04 +00:00
|
|
|
|
2008-05-20 09:51:36 +00:00
|
|
|
memset(&sctp_clog, 0, sizeof(sctp_clog));
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_clog.x.cwnd.net = net;
|
|
|
|
sctp_clog.x.cwnd.cwnd_new_value = error;
|
|
|
|
sctp_clog.x.cwnd.inflight = net->flight_size;
|
|
|
|
sctp_clog.x.cwnd.cwnd_augment = burst;
|
2006-11-03 15:23:16 +00:00
|
|
|
if (stcb->asoc.send_queue_cnt > 255)
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_clog.x.cwnd.cnt_in_send = 255;
|
2006-11-03 15:23:16 +00:00
|
|
|
else
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_clog.x.cwnd.cnt_in_send = stcb->asoc.send_queue_cnt;
|
2006-11-03 15:23:16 +00:00
|
|
|
if (stcb->asoc.stream_queue_cnt > 255)
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_clog.x.cwnd.cnt_in_str = 255;
|
2006-11-03 15:23:16 +00:00
|
|
|
else
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_clog.x.cwnd.cnt_in_str = stcb->asoc.stream_queue_cnt;
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_CTR6(KTR_SCTP, "SCTP:%d[%d]:%x-%x-%x-%x",
|
2007-06-14 22:59:04 +00:00
|
|
|
SCTP_LOG_EVENT_MAXBURST,
|
|
|
|
from,
|
|
|
|
sctp_clog.x.misc.log1,
|
|
|
|
sctp_clog.x.misc.log2,
|
|
|
|
sctp_clog.x.misc.log3,
|
|
|
|
sctp_clog.x.misc.log4);
|
2018-05-21 14:53:22 +00:00
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sctp_log_rwnd(uint8_t from, uint32_t peers_rwnd, uint32_t snd_size, uint32_t overhead)
|
|
|
|
{
|
2018-05-21 14:53:22 +00:00
|
|
|
#if defined(SCTP_LOCAL_TRACE_BUF)
|
|
|
|
struct sctp_cwnd_log sctp_clog;
|
2007-06-14 22:59:04 +00:00
|
|
|
|
|
|
|
sctp_clog.x.rwnd.rwnd = peers_rwnd;
|
|
|
|
sctp_clog.x.rwnd.send_size = snd_size;
|
|
|
|
sctp_clog.x.rwnd.overhead = overhead;
|
|
|
|
sctp_clog.x.rwnd.new_rwnd = 0;
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_CTR6(KTR_SCTP, "SCTP:%d[%d]:%x-%x-%x-%x",
|
2007-06-14 22:59:04 +00:00
|
|
|
SCTP_LOG_EVENT_RWND,
|
|
|
|
from,
|
|
|
|
sctp_clog.x.misc.log1,
|
|
|
|
sctp_clog.x.misc.log2,
|
|
|
|
sctp_clog.x.misc.log3,
|
|
|
|
sctp_clog.x.misc.log4);
|
2018-05-21 14:53:22 +00:00
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sctp_log_rwnd_set(uint8_t from, uint32_t peers_rwnd, uint32_t flight_size, uint32_t overhead, uint32_t a_rwndval)
|
|
|
|
{
|
2018-05-21 14:53:22 +00:00
|
|
|
#if defined(SCTP_LOCAL_TRACE_BUF)
|
|
|
|
struct sctp_cwnd_log sctp_clog;
|
2007-06-14 22:59:04 +00:00
|
|
|
|
|
|
|
sctp_clog.x.rwnd.rwnd = peers_rwnd;
|
|
|
|
sctp_clog.x.rwnd.send_size = flight_size;
|
|
|
|
sctp_clog.x.rwnd.overhead = overhead;
|
|
|
|
sctp_clog.x.rwnd.new_rwnd = a_rwndval;
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_CTR6(KTR_SCTP, "SCTP:%d[%d]:%x-%x-%x-%x",
|
2007-06-14 22:59:04 +00:00
|
|
|
SCTP_LOG_EVENT_RWND,
|
|
|
|
from,
|
|
|
|
sctp_clog.x.misc.log1,
|
|
|
|
sctp_clog.x.misc.log2,
|
|
|
|
sctp_clog.x.misc.log3,
|
|
|
|
sctp_clog.x.misc.log4);
|
2018-05-21 14:53:22 +00:00
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
2015-01-10 20:49:57 +00:00
|
|
|
#ifdef SCTP_MBCNT_LOGGING
|
|
|
|
static void
|
2006-11-03 15:23:16 +00:00
|
|
|
sctp_log_mbcnt(uint8_t from, uint32_t total_oq, uint32_t book, uint32_t total_mbcnt_q, uint32_t mbcnt)
|
|
|
|
{
|
2018-05-21 14:53:22 +00:00
|
|
|
#if defined(SCTP_LOCAL_TRACE_BUF)
|
|
|
|
struct sctp_cwnd_log sctp_clog;
|
2007-06-14 22:59:04 +00:00
|
|
|
|
|
|
|
sctp_clog.x.mbcnt.total_queue_size = total_oq;
|
|
|
|
sctp_clog.x.mbcnt.size_change = book;
|
|
|
|
sctp_clog.x.mbcnt.total_queue_mb_size = total_mbcnt_q;
|
|
|
|
sctp_clog.x.mbcnt.mbcnt_change = mbcnt;
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_CTR6(KTR_SCTP, "SCTP:%d[%d]:%x-%x-%x-%x",
|
2007-06-14 22:59:04 +00:00
|
|
|
SCTP_LOG_EVENT_MBCNT,
|
|
|
|
from,
|
|
|
|
sctp_clog.x.misc.log1,
|
|
|
|
sctp_clog.x.misc.log2,
|
|
|
|
sctp_clog.x.misc.log3,
|
|
|
|
sctp_clog.x.misc.log4);
|
2018-05-21 14:53:22 +00:00
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2015-01-10 20:49:57 +00:00
|
|
|
#endif
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
void
|
|
|
|
sctp_misc_ints(uint8_t from, uint32_t a, uint32_t b, uint32_t c, uint32_t d)
|
|
|
|
{
|
2018-05-21 14:53:22 +00:00
|
|
|
#if defined(SCTP_LOCAL_TRACE_BUF)
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_CTR6(KTR_SCTP, "SCTP:%d[%d]:%x-%x-%x-%x",
|
2007-06-14 22:59:04 +00:00
|
|
|
SCTP_LOG_MISC_EVENT,
|
|
|
|
from,
|
|
|
|
a, b, c, d);
|
2018-05-21 14:53:22 +00:00
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-12-17 19:21:40 +00:00
|
|
|
sctp_wakeup_log(struct sctp_tcb *stcb, uint32_t wake_cnt, int from)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
2018-05-21 14:53:22 +00:00
|
|
|
#if defined(SCTP_LOCAL_TRACE_BUF)
|
|
|
|
struct sctp_cwnd_log sctp_clog;
|
2007-06-14 22:59:04 +00:00
|
|
|
|
|
|
|
sctp_clog.x.wake.stcb = (void *)stcb;
|
|
|
|
sctp_clog.x.wake.wake_cnt = wake_cnt;
|
|
|
|
sctp_clog.x.wake.flight = stcb->asoc.total_flight_count;
|
|
|
|
sctp_clog.x.wake.send_q = stcb->asoc.send_queue_cnt;
|
|
|
|
sctp_clog.x.wake.sent_q = stcb->asoc.sent_queue_cnt;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
if (stcb->asoc.stream_queue_cnt < 0xff)
|
2018-07-19 20:11:14 +00:00
|
|
|
sctp_clog.x.wake.stream_qcnt = (uint8_t)stcb->asoc.stream_queue_cnt;
|
2006-11-03 15:23:16 +00:00
|
|
|
else
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_clog.x.wake.stream_qcnt = 0xff;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
if (stcb->asoc.chunks_on_out_queue < 0xff)
|
2018-07-19 20:11:14 +00:00
|
|
|
sctp_clog.x.wake.chunks_on_oque = (uint8_t)stcb->asoc.chunks_on_out_queue;
|
2006-11-03 15:23:16 +00:00
|
|
|
else
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_clog.x.wake.chunks_on_oque = 0xff;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_clog.x.wake.sctpflags = 0;
|
2006-11-03 15:23:16 +00:00
|
|
|
/* set in the defered mode stuff */
|
|
|
|
if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE)
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_clog.x.wake.sctpflags |= 1;
|
2006-11-03 15:23:16 +00:00
|
|
|
if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_WAKEOUTPUT)
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_clog.x.wake.sctpflags |= 2;
|
2006-11-03 15:23:16 +00:00
|
|
|
if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_WAKEINPUT)
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_clog.x.wake.sctpflags |= 4;
|
2006-11-03 15:23:16 +00:00
|
|
|
/* what about the sb */
|
|
|
|
if (stcb->sctp_socket) {
|
|
|
|
struct socket *so = stcb->sctp_socket;
|
|
|
|
|
2018-07-19 20:11:14 +00:00
|
|
|
sctp_clog.x.wake.sbflags = (uint8_t)((so->so_snd.sb_flags & 0x00ff));
|
2006-11-03 15:23:16 +00:00
|
|
|
} else {
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_clog.x.wake.sbflags = 0xff;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_CTR6(KTR_SCTP, "SCTP:%d[%d]:%x-%x-%x-%x",
|
2007-06-14 22:59:04 +00:00
|
|
|
SCTP_LOG_EVENT_WAKE,
|
|
|
|
from,
|
|
|
|
sctp_clog.x.misc.log1,
|
|
|
|
sctp_clog.x.misc.log2,
|
|
|
|
sctp_clog.x.misc.log3,
|
|
|
|
sctp_clog.x.misc.log4);
|
2018-05-21 14:53:22 +00:00
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-03-27 10:04:25 +00:00
|
|
|
sctp_log_block(uint8_t from, struct sctp_association *asoc, size_t sendlen)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
2018-05-21 14:53:22 +00:00
|
|
|
#if defined(SCTP_LOCAL_TRACE_BUF)
|
|
|
|
struct sctp_cwnd_log sctp_clog;
|
2007-06-14 22:59:04 +00:00
|
|
|
|
|
|
|
sctp_clog.x.blk.onsb = asoc->total_output_queue_size;
|
2018-07-19 20:11:14 +00:00
|
|
|
sctp_clog.x.blk.send_sent_qcnt = (uint16_t)(asoc->send_queue_cnt + asoc->sent_queue_cnt);
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_clog.x.blk.peer_rwnd = asoc->peers_rwnd;
|
2018-07-19 20:11:14 +00:00
|
|
|
sctp_clog.x.blk.stream_qcnt = (uint16_t)asoc->stream_queue_cnt;
|
|
|
|
sctp_clog.x.blk.chunks_on_oque = (uint16_t)asoc->chunks_on_out_queue;
|
|
|
|
sctp_clog.x.blk.flight_size = (uint16_t)(asoc->total_flight / 1024);
|
|
|
|
sctp_clog.x.blk.sndlen = (uint32_t)sendlen;
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_CTR6(KTR_SCTP, "SCTP:%d[%d]:%x-%x-%x-%x",
|
2007-06-14 22:59:04 +00:00
|
|
|
SCTP_LOG_EVENT_BLOCK,
|
|
|
|
from,
|
|
|
|
sctp_clog.x.misc.log1,
|
|
|
|
sctp_clog.x.misc.log2,
|
|
|
|
sctp_clog.x.misc.log3,
|
|
|
|
sctp_clog.x.misc.log4);
|
2018-05-21 14:53:22 +00:00
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2011-12-17 19:21:40 +00:00
|
|
|
sctp_fill_stat_log(void *optval SCTP_UNUSED, size_t *optsize SCTP_UNUSED)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
2007-06-14 22:59:04 +00:00
|
|
|
/* May need to fix this if ktrdump does not work */
|
2006-11-03 15:23:16 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef SCTP_AUDITING_ENABLED
|
|
|
|
uint8_t sctp_audit_data[SCTP_AUDIT_SIZE][2];
|
|
|
|
static int sctp_audit_indx = 0;
|
|
|
|
|
|
|
|
static
|
|
|
|
void
|
|
|
|
sctp_print_audit_report(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int cnt;
|
|
|
|
|
|
|
|
cnt = 0;
|
|
|
|
for (i = sctp_audit_indx; i < SCTP_AUDIT_SIZE; i++) {
|
|
|
|
if ((sctp_audit_data[i][0] == 0xe0) &&
|
|
|
|
(sctp_audit_data[i][1] == 0x01)) {
|
|
|
|
cnt = 0;
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTP_PRINTF("\n");
|
2006-11-03 15:23:16 +00:00
|
|
|
} else if (sctp_audit_data[i][0] == 0xf0) {
|
|
|
|
cnt = 0;
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTP_PRINTF("\n");
|
2006-11-03 15:23:16 +00:00
|
|
|
} else if ((sctp_audit_data[i][0] == 0xc0) &&
|
|
|
|
(sctp_audit_data[i][1] == 0x01)) {
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTP_PRINTF("\n");
|
2006-11-03 15:23:16 +00:00
|
|
|
cnt = 0;
|
|
|
|
}
|
2018-07-19 20:11:14 +00:00
|
|
|
SCTP_PRINTF("%2.2x%2.2x ", (uint32_t)sctp_audit_data[i][0],
|
|
|
|
(uint32_t)sctp_audit_data[i][1]);
|
2006-11-03 15:23:16 +00:00
|
|
|
cnt++;
|
|
|
|
if ((cnt % 14) == 0)
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTP_PRINTF("\n");
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
for (i = 0; i < sctp_audit_indx; i++) {
|
|
|
|
if ((sctp_audit_data[i][0] == 0xe0) &&
|
|
|
|
(sctp_audit_data[i][1] == 0x01)) {
|
|
|
|
cnt = 0;
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTP_PRINTF("\n");
|
2006-11-03 15:23:16 +00:00
|
|
|
} else if (sctp_audit_data[i][0] == 0xf0) {
|
|
|
|
cnt = 0;
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTP_PRINTF("\n");
|
2006-11-03 15:23:16 +00:00
|
|
|
} else if ((sctp_audit_data[i][0] == 0xc0) &&
|
|
|
|
(sctp_audit_data[i][1] == 0x01)) {
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTP_PRINTF("\n");
|
2006-11-03 15:23:16 +00:00
|
|
|
cnt = 0;
|
|
|
|
}
|
2018-07-19 20:11:14 +00:00
|
|
|
SCTP_PRINTF("%2.2x%2.2x ", (uint32_t)sctp_audit_data[i][0],
|
|
|
|
(uint32_t)sctp_audit_data[i][1]);
|
2006-11-03 15:23:16 +00:00
|
|
|
cnt++;
|
|
|
|
if ((cnt % 14) == 0)
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTP_PRINTF("\n");
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTP_PRINTF("\n");
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sctp_auditing(int from, struct sctp_inpcb *inp, struct sctp_tcb *stcb,
|
|
|
|
struct sctp_nets *net)
|
|
|
|
{
|
|
|
|
int resend_cnt, tot_out, rep, tot_book_cnt;
|
|
|
|
struct sctp_nets *lnet;
|
|
|
|
struct sctp_tmit_chunk *chk;
|
|
|
|
|
|
|
|
sctp_audit_data[sctp_audit_indx][0] = 0xAA;
|
|
|
|
sctp_audit_data[sctp_audit_indx][1] = 0x000000ff & from;
|
|
|
|
sctp_audit_indx++;
|
|
|
|
if (sctp_audit_indx >= SCTP_AUDIT_SIZE) {
|
|
|
|
sctp_audit_indx = 0;
|
|
|
|
}
|
|
|
|
if (inp == NULL) {
|
|
|
|
sctp_audit_data[sctp_audit_indx][0] = 0xAF;
|
|
|
|
sctp_audit_data[sctp_audit_indx][1] = 0x01;
|
|
|
|
sctp_audit_indx++;
|
|
|
|
if (sctp_audit_indx >= SCTP_AUDIT_SIZE) {
|
|
|
|
sctp_audit_indx = 0;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (stcb == NULL) {
|
|
|
|
sctp_audit_data[sctp_audit_indx][0] = 0xAF;
|
|
|
|
sctp_audit_data[sctp_audit_indx][1] = 0x02;
|
|
|
|
sctp_audit_indx++;
|
|
|
|
if (sctp_audit_indx >= SCTP_AUDIT_SIZE) {
|
|
|
|
sctp_audit_indx = 0;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sctp_audit_data[sctp_audit_indx][0] = 0xA1;
|
|
|
|
sctp_audit_data[sctp_audit_indx][1] =
|
|
|
|
(0x000000ff & stcb->asoc.sent_queue_retran_cnt);
|
|
|
|
sctp_audit_indx++;
|
|
|
|
if (sctp_audit_indx >= SCTP_AUDIT_SIZE) {
|
|
|
|
sctp_audit_indx = 0;
|
|
|
|
}
|
|
|
|
rep = 0;
|
|
|
|
tot_book_cnt = 0;
|
|
|
|
resend_cnt = tot_out = 0;
|
|
|
|
TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) {
|
|
|
|
if (chk->sent == SCTP_DATAGRAM_RESEND) {
|
|
|
|
resend_cnt++;
|
|
|
|
} else if (chk->sent < SCTP_DATAGRAM_RESEND) {
|
|
|
|
tot_out += chk->book_size;
|
|
|
|
tot_book_cnt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (resend_cnt != stcb->asoc.sent_queue_retran_cnt) {
|
|
|
|
sctp_audit_data[sctp_audit_indx][0] = 0xAF;
|
|
|
|
sctp_audit_data[sctp_audit_indx][1] = 0xA1;
|
|
|
|
sctp_audit_indx++;
|
|
|
|
if (sctp_audit_indx >= SCTP_AUDIT_SIZE) {
|
|
|
|
sctp_audit_indx = 0;
|
|
|
|
}
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTP_PRINTF("resend_cnt:%d asoc-tot:%d\n",
|
2006-11-03 15:23:16 +00:00
|
|
|
resend_cnt, stcb->asoc.sent_queue_retran_cnt);
|
|
|
|
rep = 1;
|
|
|
|
stcb->asoc.sent_queue_retran_cnt = resend_cnt;
|
|
|
|
sctp_audit_data[sctp_audit_indx][0] = 0xA2;
|
|
|
|
sctp_audit_data[sctp_audit_indx][1] =
|
|
|
|
(0x000000ff & stcb->asoc.sent_queue_retran_cnt);
|
|
|
|
sctp_audit_indx++;
|
|
|
|
if (sctp_audit_indx >= SCTP_AUDIT_SIZE) {
|
|
|
|
sctp_audit_indx = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (tot_out != stcb->asoc.total_flight) {
|
|
|
|
sctp_audit_data[sctp_audit_indx][0] = 0xAF;
|
|
|
|
sctp_audit_data[sctp_audit_indx][1] = 0xA2;
|
|
|
|
sctp_audit_indx++;
|
|
|
|
if (sctp_audit_indx >= SCTP_AUDIT_SIZE) {
|
|
|
|
sctp_audit_indx = 0;
|
|
|
|
}
|
|
|
|
rep = 1;
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTP_PRINTF("tot_flt:%d asoc_tot:%d\n", tot_out,
|
2006-11-03 15:23:16 +00:00
|
|
|
(int)stcb->asoc.total_flight);
|
|
|
|
stcb->asoc.total_flight = tot_out;
|
|
|
|
}
|
|
|
|
if (tot_book_cnt != stcb->asoc.total_flight_count) {
|
|
|
|
sctp_audit_data[sctp_audit_indx][0] = 0xAF;
|
|
|
|
sctp_audit_data[sctp_audit_indx][1] = 0xA5;
|
|
|
|
sctp_audit_indx++;
|
|
|
|
if (sctp_audit_indx >= SCTP_AUDIT_SIZE) {
|
|
|
|
sctp_audit_indx = 0;
|
|
|
|
}
|
|
|
|
rep = 1;
|
2010-04-23 08:19:47 +00:00
|
|
|
SCTP_PRINTF("tot_flt_book:%d\n", tot_book_cnt);
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
stcb->asoc.total_flight_count = tot_book_cnt;
|
|
|
|
}
|
|
|
|
tot_out = 0;
|
|
|
|
TAILQ_FOREACH(lnet, &stcb->asoc.nets, sctp_next) {
|
|
|
|
tot_out += lnet->flight_size;
|
|
|
|
}
|
|
|
|
if (tot_out != stcb->asoc.total_flight) {
|
|
|
|
sctp_audit_data[sctp_audit_indx][0] = 0xAF;
|
|
|
|
sctp_audit_data[sctp_audit_indx][1] = 0xA3;
|
|
|
|
sctp_audit_indx++;
|
|
|
|
if (sctp_audit_indx >= SCTP_AUDIT_SIZE) {
|
|
|
|
sctp_audit_indx = 0;
|
|
|
|
}
|
|
|
|
rep = 1;
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTP_PRINTF("real flight:%d net total was %d\n",
|
2006-11-03 15:23:16 +00:00
|
|
|
stcb->asoc.total_flight, tot_out);
|
|
|
|
/* now corrective action */
|
|
|
|
TAILQ_FOREACH(lnet, &stcb->asoc.nets, sctp_next) {
|
|
|
|
|
|
|
|
tot_out = 0;
|
|
|
|
TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) {
|
|
|
|
if ((chk->whoTo == lnet) &&
|
|
|
|
(chk->sent < SCTP_DATAGRAM_RESEND)) {
|
|
|
|
tot_out += chk->book_size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (lnet->flight_size != tot_out) {
|
2010-04-23 08:19:47 +00:00
|
|
|
SCTP_PRINTF("net:%p flight was %d corrected to %d\n",
|
2012-09-05 18:52:01 +00:00
|
|
|
(void *)lnet, lnet->flight_size,
|
2007-05-09 13:30:06 +00:00
|
|
|
tot_out);
|
2006-11-03 15:23:16 +00:00
|
|
|
lnet->flight_size = tot_out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (rep) {
|
|
|
|
sctp_print_audit_report();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sctp_audit_log(uint8_t ev, uint8_t fd)
|
|
|
|
{
|
|
|
|
|
|
|
|
sctp_audit_data[sctp_audit_indx][0] = ev;
|
|
|
|
sctp_audit_data[sctp_audit_indx][1] = fd;
|
|
|
|
sctp_audit_indx++;
|
|
|
|
if (sctp_audit_indx >= SCTP_AUDIT_SIZE) {
|
|
|
|
sctp_audit_indx = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2010-11-07 14:39:40 +00:00
|
|
|
/*
|
|
|
|
* sctp_stop_timers_for_shutdown() should be called
|
|
|
|
* when entering the SHUTDOWN_SENT or SHUTDOWN_ACK_SENT
|
|
|
|
* state to make sure that all timers are stopped.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
sctp_stop_timers_for_shutdown(struct sctp_tcb *stcb)
|
|
|
|
{
|
|
|
|
struct sctp_association *asoc;
|
|
|
|
struct sctp_nets *net;
|
|
|
|
|
|
|
|
asoc = &stcb->asoc;
|
|
|
|
|
|
|
|
(void)SCTP_OS_TIMER_STOP(&asoc->dack_timer.timer);
|
|
|
|
(void)SCTP_OS_TIMER_STOP(&asoc->strreset_timer.timer);
|
|
|
|
(void)SCTP_OS_TIMER_STOP(&asoc->asconf_timer.timer);
|
|
|
|
(void)SCTP_OS_TIMER_STOP(&asoc->autoclose_timer.timer);
|
|
|
|
(void)SCTP_OS_TIMER_STOP(&asoc->delayed_event_timer.timer);
|
|
|
|
TAILQ_FOREACH(net, &asoc->nets, sctp_next) {
|
|
|
|
(void)SCTP_OS_TIMER_STOP(&net->pmtu_timer.timer);
|
2011-08-03 20:21:00 +00:00
|
|
|
(void)SCTP_OS_TIMER_STOP(&net->hb_timer.timer);
|
2010-11-07 14:39:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
/*
|
2018-05-14 13:50:17 +00:00
|
|
|
* A list of sizes based on typical mtu's, used only if next hop size not
|
|
|
|
* returned. These values MUST be multiples of 4 and MUST be ordered.
|
2006-11-03 15:23:16 +00:00
|
|
|
*/
|
2010-11-07 18:50:35 +00:00
|
|
|
static uint32_t sctp_mtu_sizes[] = {
|
2006-11-03 15:23:16 +00:00
|
|
|
68,
|
2018-07-19 20:11:14 +00:00
|
|
|
296,
|
|
|
|
508,
|
|
|
|
512,
|
|
|
|
544,
|
|
|
|
576,
|
|
|
|
1004,
|
|
|
|
1492,
|
|
|
|
1500,
|
|
|
|
1536,
|
|
|
|
2000,
|
|
|
|
2048,
|
|
|
|
4352,
|
|
|
|
4464,
|
|
|
|
8166,
|
|
|
|
17912,
|
|
|
|
32000,
|
|
|
|
65532
|
2006-11-03 15:23:16 +00:00
|
|
|
};
|
|
|
|
|
2010-11-07 18:50:35 +00:00
|
|
|
/*
|
2018-05-14 13:50:17 +00:00
|
|
|
* Return the largest MTU in sctp_mtu_sizes smaller than val.
|
|
|
|
* If val is smaller than the minimum, just return the largest
|
|
|
|
* multiple of 4 smaller or equal to val.
|
|
|
|
* Ensure that the result is a multiple of 4.
|
2010-11-07 18:50:35 +00:00
|
|
|
*/
|
|
|
|
uint32_t
|
2018-07-19 20:11:14 +00:00
|
|
|
sctp_get_prev_mtu(uint32_t val)
|
|
|
|
{
|
2010-11-07 18:50:35 +00:00
|
|
|
uint32_t i;
|
|
|
|
|
2018-05-28 13:31:47 +00:00
|
|
|
val &= 0xfffffffc;
|
2010-11-07 18:50:35 +00:00
|
|
|
if (val <= sctp_mtu_sizes[0]) {
|
|
|
|
return (val);
|
|
|
|
}
|
|
|
|
for (i = 1; i < (sizeof(sctp_mtu_sizes) / sizeof(uint32_t)); i++) {
|
|
|
|
if (val <= sctp_mtu_sizes[i]) {
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-05-14 13:50:17 +00:00
|
|
|
KASSERT((sctp_mtu_sizes[i - 1] & 0x00000003) == 0,
|
|
|
|
("sctp_mtu_sizes[%u] not a multiple of 4", i - 1));
|
2010-11-07 18:50:35 +00:00
|
|
|
return (sctp_mtu_sizes[i - 1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2018-05-14 13:50:17 +00:00
|
|
|
* Return the smallest MTU in sctp_mtu_sizes larger than val.
|
|
|
|
* If val is larger than the maximum, just return the largest multiple of 4 smaller
|
|
|
|
* or equal to val.
|
|
|
|
* Ensure that the result is a multiple of 4.
|
2010-11-07 18:50:35 +00:00
|
|
|
*/
|
|
|
|
uint32_t
|
2018-07-19 20:11:14 +00:00
|
|
|
sctp_get_next_mtu(uint32_t val)
|
|
|
|
{
|
2010-11-07 18:50:35 +00:00
|
|
|
/* select another MTU that is just bigger than this one */
|
|
|
|
uint32_t i;
|
|
|
|
|
2018-05-28 13:31:47 +00:00
|
|
|
val &= 0xfffffffc;
|
2010-11-07 18:50:35 +00:00
|
|
|
for (i = 0; i < (sizeof(sctp_mtu_sizes) / sizeof(uint32_t)); i++) {
|
|
|
|
if (val < sctp_mtu_sizes[i]) {
|
2018-05-14 13:50:17 +00:00
|
|
|
KASSERT((sctp_mtu_sizes[i] & 0x00000003) == 0,
|
|
|
|
("sctp_mtu_sizes[%u] not a multiple of 4", i));
|
2010-11-07 18:50:35 +00:00
|
|
|
return (sctp_mtu_sizes[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (val);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sctp_fill_random_store(struct sctp_pcb *m)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Here we use the MD5/SHA-1 to hash with our good randomNumbers and
|
|
|
|
* our counter. The result becomes our good random numbers and we
|
|
|
|
* then setup to give these out. Note that we do no locking to
|
|
|
|
* protect this. This is ok, since if competing folks call this we
|
2007-05-08 00:21:05 +00:00
|
|
|
* will get more gobbled gook in the random store which is what we
|
2006-11-03 15:23:16 +00:00
|
|
|
* want. There is a danger that two guys will use the same random
|
|
|
|
* numbers, but thats ok too since that is random as well :->
|
|
|
|
*/
|
|
|
|
m->store_at = 0;
|
2018-07-19 20:11:14 +00:00
|
|
|
(void)sctp_hmac(SCTP_HMAC, (uint8_t *)m->random_numbers,
|
|
|
|
sizeof(m->random_numbers), (uint8_t *)&m->random_counter,
|
|
|
|
sizeof(m->random_counter), (uint8_t *)m->random_store);
|
2006-11-03 15:23:16 +00:00
|
|
|
m->random_counter++;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
2018-07-19 20:11:14 +00:00
|
|
|
sctp_select_initial_TSN(struct sctp_pcb *inp)
|
|
|
|
{
|
2006-11-03 15:23:16 +00:00
|
|
|
/*
|
|
|
|
* A true implementation should use random selection process to get
|
|
|
|
* the initial stream sequence number, using RFC1750 as a good
|
|
|
|
* guideline
|
|
|
|
*/
|
2006-12-29 20:21:42 +00:00
|
|
|
uint32_t x, *xp;
|
2006-11-03 15:23:16 +00:00
|
|
|
uint8_t *p;
|
2007-09-08 17:48:46 +00:00
|
|
|
int store_at, new_store;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2007-09-08 17:48:46 +00:00
|
|
|
if (inp->initial_sequence_debug != 0) {
|
2006-11-03 15:23:16 +00:00
|
|
|
uint32_t ret;
|
|
|
|
|
2007-09-08 17:48:46 +00:00
|
|
|
ret = inp->initial_sequence_debug;
|
|
|
|
inp->initial_sequence_debug++;
|
2006-11-03 15:23:16 +00:00
|
|
|
return (ret);
|
|
|
|
}
|
2007-09-08 17:48:46 +00:00
|
|
|
retry:
|
|
|
|
store_at = inp->store_at;
|
|
|
|
new_store = store_at + sizeof(uint32_t);
|
|
|
|
if (new_store >= (SCTP_SIGNATURE_SIZE - 3)) {
|
|
|
|
new_store = 0;
|
|
|
|
}
|
|
|
|
if (!atomic_cmpset_int(&inp->store_at, store_at, new_store)) {
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
if (new_store == 0) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/* Refill the random store */
|
2007-09-08 17:48:46 +00:00
|
|
|
sctp_fill_random_store(inp);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2007-09-08 17:48:46 +00:00
|
|
|
p = &inp->random_store[store_at];
|
2018-07-19 20:11:14 +00:00
|
|
|
xp = (uint32_t *)p;
|
2006-11-03 15:23:16 +00:00
|
|
|
x = *xp;
|
|
|
|
return (x);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
2018-07-19 20:11:14 +00:00
|
|
|
sctp_select_a_tag(struct sctp_inpcb *inp, uint16_t lport, uint16_t rport, int check)
|
|
|
|
{
|
2011-12-17 19:21:40 +00:00
|
|
|
uint32_t x;
|
2006-11-03 15:23:16 +00:00
|
|
|
struct timeval now;
|
|
|
|
|
2011-12-17 19:21:40 +00:00
|
|
|
if (check) {
|
|
|
|
(void)SCTP_GETTIME_TIMEVAL(&now);
|
|
|
|
}
|
|
|
|
for (;;) {
|
2007-09-08 17:48:46 +00:00
|
|
|
x = sctp_select_initial_TSN(&inp->sctp_ep);
|
2006-11-03 15:23:16 +00:00
|
|
|
if (x == 0) {
|
|
|
|
/* we never use 0 */
|
|
|
|
continue;
|
|
|
|
}
|
2011-12-17 19:21:40 +00:00
|
|
|
if (!check || sctp_is_vtag_good(x, lport, rport, &now)) {
|
|
|
|
break;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return (x);
|
|
|
|
}
|
|
|
|
|
2015-08-29 09:14:32 +00:00
|
|
|
int32_t
|
2018-07-19 20:11:14 +00:00
|
|
|
sctp_map_assoc_state(int kernel_state)
|
|
|
|
{
|
2015-08-29 09:14:32 +00:00
|
|
|
int32_t user_state;
|
|
|
|
|
|
|
|
if (kernel_state & SCTP_STATE_WAS_ABORTED) {
|
|
|
|
user_state = SCTP_CLOSED;
|
|
|
|
} else if (kernel_state & SCTP_STATE_SHUTDOWN_PENDING) {
|
|
|
|
user_state = SCTP_SHUTDOWN_PENDING;
|
|
|
|
} else {
|
|
|
|
switch (kernel_state & SCTP_STATE_MASK) {
|
|
|
|
case SCTP_STATE_EMPTY:
|
|
|
|
user_state = SCTP_CLOSED;
|
|
|
|
break;
|
|
|
|
case SCTP_STATE_INUSE:
|
|
|
|
user_state = SCTP_CLOSED;
|
|
|
|
break;
|
|
|
|
case SCTP_STATE_COOKIE_WAIT:
|
|
|
|
user_state = SCTP_COOKIE_WAIT;
|
|
|
|
break;
|
|
|
|
case SCTP_STATE_COOKIE_ECHOED:
|
|
|
|
user_state = SCTP_COOKIE_ECHOED;
|
|
|
|
break;
|
|
|
|
case SCTP_STATE_OPEN:
|
|
|
|
user_state = SCTP_ESTABLISHED;
|
|
|
|
break;
|
|
|
|
case SCTP_STATE_SHUTDOWN_SENT:
|
|
|
|
user_state = SCTP_SHUTDOWN_SENT;
|
|
|
|
break;
|
|
|
|
case SCTP_STATE_SHUTDOWN_RECEIVED:
|
|
|
|
user_state = SCTP_SHUTDOWN_RECEIVED;
|
|
|
|
break;
|
|
|
|
case SCTP_STATE_SHUTDOWN_ACK_SENT:
|
|
|
|
user_state = SCTP_SHUTDOWN_ACK_SENT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
user_state = SCTP_CLOSED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (user_state);
|
|
|
|
}
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
int
|
2013-02-09 17:26:14 +00:00
|
|
|
sctp_init_asoc(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
|
2015-12-06 16:17:57 +00:00
|
|
|
uint32_t override_tag, uint32_t vrf_id, uint16_t o_strms)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
2007-05-30 17:39:45 +00:00
|
|
|
struct sctp_association *asoc;
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
/*
|
|
|
|
* Anything set to zero is taken care of by the allocation routine's
|
|
|
|
* bzero
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Up front select what scoping to apply on addresses I tell my peer
|
|
|
|
* Not sure what to do with these right now, we will need to come up
|
|
|
|
* with a way to set them. We may need to pass them through from the
|
|
|
|
* caller in the sctp_aloc_assoc() function.
|
|
|
|
*/
|
|
|
|
int i;
|
2014-08-13 15:50:16 +00:00
|
|
|
#if defined(SCTP_DETAILED_STR_STATS)
|
|
|
|
int j;
|
|
|
|
#endif
|
|
|
|
|
2007-05-30 17:39:45 +00:00
|
|
|
asoc = &stcb->asoc;
|
2006-11-03 15:23:16 +00:00
|
|
|
/* init all variables to a known value. */
|
2018-08-13 13:58:45 +00:00
|
|
|
SCTP_SET_STATE(stcb, SCTP_STATE_INUSE);
|
2013-02-09 17:26:14 +00:00
|
|
|
asoc->max_burst = inp->sctp_ep.max_burst;
|
|
|
|
asoc->fr_max_burst = inp->sctp_ep.fr_max_burst;
|
|
|
|
asoc->heart_beat_delay = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_HEARTBEAT]);
|
|
|
|
asoc->cookie_life = inp->sctp_ep.def_cookie_life;
|
|
|
|
asoc->sctp_cmt_on_off = inp->sctp_cmt_on_off;
|
2014-08-02 17:35:13 +00:00
|
|
|
asoc->ecn_supported = inp->ecn_supported;
|
2014-08-02 21:36:40 +00:00
|
|
|
asoc->prsctp_supported = inp->prsctp_supported;
|
2016-04-07 09:10:34 +00:00
|
|
|
asoc->idata_supported = inp->idata_supported;
|
2014-08-12 11:30:16 +00:00
|
|
|
asoc->auth_supported = inp->auth_supported;
|
|
|
|
asoc->asconf_supported = inp->asconf_supported;
|
2014-08-04 20:07:35 +00:00
|
|
|
asoc->reconfig_supported = inp->reconfig_supported;
|
2014-08-03 14:10:10 +00:00
|
|
|
asoc->nrsack_supported = inp->nrsack_supported;
|
2014-08-03 18:12:55 +00:00
|
|
|
asoc->pktdrop_supported = inp->pktdrop_supported;
|
2016-04-07 09:10:34 +00:00
|
|
|
asoc->idata_supported = inp->idata_supported;
|
2018-07-19 20:11:14 +00:00
|
|
|
asoc->sctp_cmt_pf = (uint8_t)0;
|
2013-02-09 17:26:14 +00:00
|
|
|
asoc->sctp_frag_point = inp->sctp_frag_point;
|
|
|
|
asoc->sctp_features = inp->sctp_features;
|
|
|
|
asoc->default_dscp = inp->sctp_ep.default_dscp;
|
2015-03-10 19:49:25 +00:00
|
|
|
asoc->max_cwnd = inp->max_cwnd;
|
2007-03-15 11:27:14 +00:00
|
|
|
#ifdef INET6
|
2013-02-09 17:26:14 +00:00
|
|
|
if (inp->sctp_ep.default_flowlabel) {
|
|
|
|
asoc->default_flowlabel = inp->sctp_ep.default_flowlabel;
|
2011-09-14 08:15:21 +00:00
|
|
|
} else {
|
2013-02-09 17:26:14 +00:00
|
|
|
if (inp->ip_inp.inp.inp_flags & IN6P_AUTOFLOWLABEL) {
|
|
|
|
asoc->default_flowlabel = sctp_select_initial_TSN(&inp->sctp_ep);
|
2011-09-14 08:15:21 +00:00
|
|
|
asoc->default_flowlabel &= 0x000fffff;
|
|
|
|
asoc->default_flowlabel |= 0x80000000;
|
|
|
|
} else {
|
|
|
|
asoc->default_flowlabel = 0;
|
|
|
|
}
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
#endif
|
2007-12-04 14:41:48 +00:00
|
|
|
asoc->sb_send_resv = 0;
|
2006-11-03 15:23:16 +00:00
|
|
|
if (override_tag) {
|
2008-12-06 13:19:54 +00:00
|
|
|
asoc->my_vtag = override_tag;
|
2006-11-03 15:23:16 +00:00
|
|
|
} else {
|
2013-02-09 17:26:14 +00:00
|
|
|
asoc->my_vtag = sctp_select_a_tag(inp, stcb->sctp_ep->sctp_lport, stcb->rport, 1);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2006-11-10 13:34:55 +00:00
|
|
|
/* Get the nonce tags */
|
2013-02-09 17:26:14 +00:00
|
|
|
asoc->my_vtag_nonce = sctp_select_a_tag(inp, stcb->sctp_ep->sctp_lport, stcb->rport, 0);
|
|
|
|
asoc->peer_vtag_nonce = sctp_select_a_tag(inp, stcb->sctp_ep->sctp_lport, stcb->rport, 0);
|
2007-03-15 11:27:14 +00:00
|
|
|
asoc->vrf_id = vrf_id;
|
2006-11-10 13:34:55 +00:00
|
|
|
|
2007-07-17 20:58:26 +00:00
|
|
|
#ifdef SCTP_ASOCLOG_OF_TSNS
|
|
|
|
asoc->tsn_in_at = 0;
|
|
|
|
asoc->tsn_out_at = 0;
|
|
|
|
asoc->tsn_in_wrapped = 0;
|
|
|
|
asoc->tsn_out_wrapped = 0;
|
|
|
|
asoc->cumack_log_at = 0;
|
2007-10-16 14:05:51 +00:00
|
|
|
asoc->cumack_log_atsnt = 0;
|
2007-07-17 20:58:26 +00:00
|
|
|
#endif
|
|
|
|
#ifdef SCTP_FS_SPEC_LOG
|
|
|
|
asoc->fs_index = 0;
|
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
asoc->refcnt = 0;
|
|
|
|
asoc->assoc_up_sent = 0;
|
|
|
|
asoc->asconf_seq_out = asoc->str_reset_seq_out = asoc->init_seq_number = asoc->sending_seq =
|
2013-02-09 17:26:14 +00:00
|
|
|
sctp_select_initial_TSN(&inp->sctp_ep);
|
2008-05-20 13:47:46 +00:00
|
|
|
asoc->asconf_seq_out_acked = asoc->asconf_seq_out - 1;
|
2006-11-03 15:23:16 +00:00
|
|
|
/* we are optimisitic here */
|
2008-12-06 13:19:54 +00:00
|
|
|
asoc->peer_supports_nat = 0;
|
2006-11-03 15:23:16 +00:00
|
|
|
asoc->sent_queue_retran_cnt = 0;
|
|
|
|
|
|
|
|
/* for CMT */
|
2009-04-04 11:43:32 +00:00
|
|
|
asoc->last_net_cmt_send_started = NULL;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
/* This will need to be adjusted */
|
|
|
|
asoc->last_acked_seq = asoc->init_seq_number - 1;
|
|
|
|
asoc->advanced_peer_ack_point = asoc->last_acked_seq;
|
|
|
|
asoc->asconf_seq_in = asoc->last_acked_seq;
|
|
|
|
|
|
|
|
/* here we are different, we hold the next one we expect */
|
|
|
|
asoc->str_reset_seq_in = asoc->last_acked_seq + 1;
|
|
|
|
|
2013-02-09 17:26:14 +00:00
|
|
|
asoc->initial_init_rto_max = inp->sctp_ep.initial_init_rto_max;
|
|
|
|
asoc->initial_rto = inp->sctp_ep.initial_rto;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2017-11-03 20:46:12 +00:00
|
|
|
asoc->default_mtu = inp->sctp_ep.default_mtu;
|
2013-02-09 17:26:14 +00:00
|
|
|
asoc->max_init_times = inp->sctp_ep.max_init_times;
|
|
|
|
asoc->max_send_times = inp->sctp_ep.max_send_times;
|
|
|
|
asoc->def_net_failure = inp->sctp_ep.def_net_failure;
|
|
|
|
asoc->def_net_pf_threshold = inp->sctp_ep.def_net_pf_threshold;
|
2006-11-03 15:23:16 +00:00
|
|
|
asoc->free_chunk_cnt = 0;
|
|
|
|
|
|
|
|
asoc->iam_blocking = 0;
|
2013-02-09 17:26:14 +00:00
|
|
|
asoc->context = inp->sctp_context;
|
|
|
|
asoc->local_strreset_support = inp->local_strreset_support;
|
|
|
|
asoc->def_send = inp->def_send;
|
|
|
|
asoc->delayed_ack = TICKS_TO_MSEC(inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_RECV]);
|
|
|
|
asoc->sack_freq = inp->sctp_ep.sctp_sack_freq;
|
2006-11-03 15:23:16 +00:00
|
|
|
asoc->pr_sctp_cnt = 0;
|
|
|
|
asoc->total_output_queue_size = 0;
|
|
|
|
|
2013-02-09 17:26:14 +00:00
|
|
|
if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
|
|
|
|
asoc->scope.ipv6_addr_legal = 1;
|
|
|
|
if (SCTP_IPV6_V6ONLY(inp) == 0) {
|
|
|
|
asoc->scope.ipv4_addr_legal = 1;
|
2006-11-03 15:23:16 +00:00
|
|
|
} else {
|
2013-02-09 17:26:14 +00:00
|
|
|
asoc->scope.ipv4_addr_legal = 0;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
} else {
|
2013-02-09 17:26:14 +00:00
|
|
|
asoc->scope.ipv6_addr_legal = 0;
|
|
|
|
asoc->scope.ipv4_addr_legal = 1;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
2013-02-09 17:26:14 +00:00
|
|
|
asoc->my_rwnd = max(SCTP_SB_LIMIT_RCV(inp->sctp_socket), SCTP_MINIMAL_RWND);
|
|
|
|
asoc->peers_rwnd = SCTP_SB_LIMIT_RCV(inp->sctp_socket);
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2013-02-09 17:26:14 +00:00
|
|
|
asoc->smallest_mtu = inp->sctp_frag_point;
|
|
|
|
asoc->minrto = inp->sctp_ep.sctp_minrto;
|
|
|
|
asoc->maxrto = inp->sctp_ep.sctp_maxrto;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
asoc->stream_locked_on = 0;
|
|
|
|
asoc->ecn_echo_cnt_onq = 0;
|
|
|
|
asoc->stream_locked = 0;
|
|
|
|
|
2007-03-15 11:27:14 +00:00
|
|
|
asoc->send_sack = 1;
|
|
|
|
|
|
|
|
LIST_INIT(&asoc->sctp_restricted_addrs);
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
TAILQ_INIT(&asoc->nets);
|
|
|
|
TAILQ_INIT(&asoc->pending_reply_queue);
|
2007-08-27 05:19:48 +00:00
|
|
|
TAILQ_INIT(&asoc->asconf_ack_sent);
|
2006-11-03 15:23:16 +00:00
|
|
|
/* Setup to fill the hb random cache at first HB */
|
|
|
|
asoc->hb_random_idx = 4;
|
|
|
|
|
2013-02-09 17:26:14 +00:00
|
|
|
asoc->sctp_autoclose_ticks = inp->sctp_ep.auto_close_time;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2013-02-09 17:26:14 +00:00
|
|
|
stcb->asoc.congestion_control_module = inp->sctp_ep.sctp_default_cc_module;
|
|
|
|
stcb->asoc.cc_functions = sctp_cc_functions[inp->sctp_ep.sctp_default_cc_module];
|
2007-07-14 09:36:28 +00:00
|
|
|
|
2013-02-09 17:26:14 +00:00
|
|
|
stcb->asoc.stream_scheduling_module = inp->sctp_ep.sctp_default_ss_module;
|
|
|
|
stcb->asoc.ss_functions = sctp_ss_functions[inp->sctp_ep.sctp_default_ss_module];
|
2011-01-23 19:36:28 +00:00
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
/*
|
|
|
|
* Now the stream parameters, here we allocate space for all streams
|
|
|
|
* that we request by default.
|
|
|
|
*/
|
2009-02-20 15:03:54 +00:00
|
|
|
asoc->strm_realoutsize = asoc->streamoutcnt = asoc->pre_open_streams =
|
2015-12-06 16:17:57 +00:00
|
|
|
o_strms;
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_MALLOC(asoc->strmout, struct sctp_stream_out *,
|
|
|
|
asoc->streamoutcnt * sizeof(struct sctp_stream_out),
|
2007-05-29 09:29:03 +00:00
|
|
|
SCTP_M_STRMO);
|
2006-11-03 15:23:16 +00:00
|
|
|
if (asoc->strmout == NULL) {
|
|
|
|
/* big trouble no memory */
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(NULL, stcb, NULL, SCTP_FROM_SCTPUTIL, ENOMEM);
|
2006-11-03 15:23:16 +00:00
|
|
|
return (ENOMEM);
|
|
|
|
}
|
|
|
|
for (i = 0; i < asoc->streamoutcnt; i++) {
|
|
|
|
/*
|
|
|
|
* inbound side must be set to 0xffff, also NOTE when we get
|
|
|
|
* the INIT-ACK back (for INIT sender) we MUST reduce the
|
|
|
|
* count (streamoutcnt) but first check if we sent to any of
|
|
|
|
* the upper streams that were dropped (if some were). Those
|
|
|
|
* that were dropped must be notified to the upper layer as
|
|
|
|
* failed to send.
|
|
|
|
*/
|
2016-06-08 17:57:42 +00:00
|
|
|
asoc->strmout[i].next_mid_ordered = 0;
|
|
|
|
asoc->strmout[i].next_mid_unordered = 0;
|
2006-11-03 15:23:16 +00:00
|
|
|
TAILQ_INIT(&asoc->strmout[i].outqueue);
|
2012-11-16 19:39:10 +00:00
|
|
|
asoc->strmout[i].chunks_on_queues = 0;
|
2014-08-13 15:50:16 +00:00
|
|
|
#if defined(SCTP_DETAILED_STR_STATS)
|
|
|
|
for (j = 0; j < SCTP_PR_SCTP_MAX + 1; j++) {
|
|
|
|
asoc->strmout[i].abandoned_sent[j] = 0;
|
|
|
|
asoc->strmout[i].abandoned_unsent[j] = 0;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
asoc->strmout[i].abandoned_sent[0] = 0;
|
|
|
|
asoc->strmout[i].abandoned_unsent[0] = 0;
|
|
|
|
#endif
|
2016-12-07 19:30:59 +00:00
|
|
|
asoc->strmout[i].sid = i;
|
2006-11-03 15:23:16 +00:00
|
|
|
asoc->strmout[i].last_msg_incomplete = 0;
|
2015-07-22 11:30:37 +00:00
|
|
|
asoc->strmout[i].state = SCTP_STREAM_OPENING;
|
2016-08-06 12:33:15 +00:00
|
|
|
asoc->ss_functions.sctp_ss_init_stream(stcb, &asoc->strmout[i], NULL);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2011-01-23 19:36:28 +00:00
|
|
|
asoc->ss_functions.sctp_ss_init(stcb, asoc, 0);
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
/* Now the mapping array */
|
|
|
|
asoc->mapping_array_size = SCTP_INITIAL_MAPPING_ARRAY;
|
|
|
|
SCTP_MALLOC(asoc->mapping_array, uint8_t *, asoc->mapping_array_size,
|
2007-05-29 09:29:03 +00:00
|
|
|
SCTP_M_MAP);
|
2006-11-03 15:23:16 +00:00
|
|
|
if (asoc->mapping_array == NULL) {
|
2007-05-29 09:29:03 +00:00
|
|
|
SCTP_FREE(asoc->strmout, SCTP_M_STRMO);
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(NULL, stcb, NULL, SCTP_FROM_SCTPUTIL, ENOMEM);
|
2006-11-03 15:23:16 +00:00
|
|
|
return (ENOMEM);
|
|
|
|
}
|
|
|
|
memset(asoc->mapping_array, 0, asoc->mapping_array_size);
|
2010-04-03 15:40:14 +00:00
|
|
|
SCTP_MALLOC(asoc->nr_mapping_array, uint8_t *, asoc->mapping_array_size,
|
2008-12-06 13:19:54 +00:00
|
|
|
SCTP_M_MAP);
|
2009-05-30 10:56:27 +00:00
|
|
|
if (asoc->nr_mapping_array == NULL) {
|
|
|
|
SCTP_FREE(asoc->strmout, SCTP_M_STRMO);
|
|
|
|
SCTP_FREE(asoc->mapping_array, SCTP_M_MAP);
|
|
|
|
SCTP_LTRACE_ERR_RET(NULL, stcb, NULL, SCTP_FROM_SCTPUTIL, ENOMEM);
|
|
|
|
return (ENOMEM);
|
|
|
|
}
|
2010-04-03 15:40:14 +00:00
|
|
|
memset(asoc->nr_mapping_array, 0, asoc->mapping_array_size);
|
2008-12-06 13:19:54 +00:00
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
/* Now the init of the other outqueues */
|
|
|
|
TAILQ_INIT(&asoc->free_chunks);
|
|
|
|
TAILQ_INIT(&asoc->control_send_queue);
|
2008-05-20 13:47:46 +00:00
|
|
|
TAILQ_INIT(&asoc->asconf_send_queue);
|
2006-11-03 15:23:16 +00:00
|
|
|
TAILQ_INIT(&asoc->send_queue);
|
|
|
|
TAILQ_INIT(&asoc->sent_queue);
|
|
|
|
TAILQ_INIT(&asoc->resetHead);
|
2013-02-09 17:26:14 +00:00
|
|
|
asoc->max_inbound_streams = inp->sctp_ep.max_open_streams_intome;
|
2006-11-03 15:23:16 +00:00
|
|
|
TAILQ_INIT(&asoc->asconf_queue);
|
|
|
|
/* authentication fields */
|
|
|
|
asoc->authinfo.random = NULL;
|
2008-12-06 13:19:54 +00:00
|
|
|
asoc->authinfo.active_keyid = 0;
|
2006-11-03 15:23:16 +00:00
|
|
|
asoc->authinfo.assoc_key = NULL;
|
|
|
|
asoc->authinfo.assoc_keyid = 0;
|
|
|
|
asoc->authinfo.recv_key = NULL;
|
|
|
|
asoc->authinfo.recv_keyid = 0;
|
|
|
|
LIST_INIT(&asoc->shared_keys);
|
2007-02-12 23:24:31 +00:00
|
|
|
asoc->marked_retrans = 0;
|
2013-02-09 17:26:14 +00:00
|
|
|
asoc->port = inp->sctp_ep.port;
|
2007-02-12 23:24:31 +00:00
|
|
|
asoc->timoinit = 0;
|
|
|
|
asoc->timodata = 0;
|
|
|
|
asoc->timosack = 0;
|
|
|
|
asoc->timoshutdown = 0;
|
|
|
|
asoc->timoheartbeat = 0;
|
|
|
|
asoc->timocookie = 0;
|
|
|
|
asoc->timoshutdownack = 0;
|
2007-05-08 14:32:53 +00:00
|
|
|
(void)SCTP_GETTIME_TIMEVAL(&asoc->start_time);
|
|
|
|
asoc->discontinuity_time = asoc->start_time;
|
2014-08-13 15:50:16 +00:00
|
|
|
for (i = 0; i < SCTP_PR_SCTP_MAX + 1; i++) {
|
|
|
|
asoc->abandoned_unsent[i] = 0;
|
|
|
|
asoc->abandoned_sent[i] = 0;
|
|
|
|
}
|
2007-06-18 21:59:15 +00:00
|
|
|
/*
|
|
|
|
* sa_ignore MEMLEAK {memory is put in the assoc mapping array and
|
2010-03-24 19:45:36 +00:00
|
|
|
* freed later when the association is freed.
|
2007-06-18 21:59:15 +00:00
|
|
|
*/
|
2006-11-03 15:23:16 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2010-03-23 01:36:50 +00:00
|
|
|
void
|
|
|
|
sctp_print_mapping_array(struct sctp_association *asoc)
|
|
|
|
{
|
2010-04-06 18:57:50 +00:00
|
|
|
unsigned int i, limit;
|
2010-03-23 01:36:50 +00:00
|
|
|
|
2012-05-04 09:27:00 +00:00
|
|
|
SCTP_PRINTF("Mapping array size: %d, baseTSN: %8.8x, cumAck: %8.8x, highestTSN: (%8.8x, %8.8x).\n",
|
2010-03-23 01:36:50 +00:00
|
|
|
asoc->mapping_array_size,
|
|
|
|
asoc->mapping_array_base_tsn,
|
|
|
|
asoc->cumulative_tsn,
|
2010-04-06 18:57:50 +00:00
|
|
|
asoc->highest_tsn_inside_map,
|
|
|
|
asoc->highest_tsn_inside_nr_map);
|
|
|
|
for (limit = asoc->mapping_array_size; limit > 1; limit--) {
|
2011-12-27 10:16:24 +00:00
|
|
|
if (asoc->mapping_array[limit - 1] != 0) {
|
2010-03-24 19:45:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-05-04 09:27:00 +00:00
|
|
|
SCTP_PRINTF("Renegable mapping array (last %d entries are zero):\n", asoc->mapping_array_size - limit);
|
2010-03-24 19:45:36 +00:00
|
|
|
for (i = 0; i < limit; i++) {
|
2012-05-04 09:27:00 +00:00
|
|
|
SCTP_PRINTF("%2.2x%c", asoc->mapping_array[i], ((i + 1) % 16) ? ' ' : '\n');
|
2010-03-24 19:45:36 +00:00
|
|
|
}
|
2010-04-06 18:57:50 +00:00
|
|
|
if (limit % 16)
|
2012-05-04 09:27:00 +00:00
|
|
|
SCTP_PRINTF("\n");
|
2010-04-06 18:57:50 +00:00
|
|
|
for (limit = asoc->mapping_array_size; limit > 1; limit--) {
|
|
|
|
if (asoc->nr_mapping_array[limit - 1]) {
|
2010-03-24 19:45:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-05-04 09:27:00 +00:00
|
|
|
SCTP_PRINTF("Non renegable mapping array (last %d entries are zero):\n", asoc->mapping_array_size - limit);
|
2010-03-24 19:45:36 +00:00
|
|
|
for (i = 0; i < limit; i++) {
|
2012-05-04 09:27:00 +00:00
|
|
|
SCTP_PRINTF("%2.2x%c", asoc->nr_mapping_array[i], ((i + 1) % 16) ? ' ' : '\n');
|
2010-03-23 01:36:50 +00:00
|
|
|
}
|
2010-04-06 18:57:50 +00:00
|
|
|
if (limit % 16)
|
2012-05-04 09:27:00 +00:00
|
|
|
SCTP_PRINTF("\n");
|
2010-03-23 01:36:50 +00:00
|
|
|
}
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
int
|
2007-05-30 17:39:45 +00:00
|
|
|
sctp_expand_mapping_array(struct sctp_association *asoc, uint32_t needed)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
|
|
|
/* mapping array needs to grow */
|
2010-04-03 15:40:14 +00:00
|
|
|
uint8_t *new_array1, *new_array2;
|
2007-05-30 17:39:45 +00:00
|
|
|
uint32_t new_size;
|
|
|
|
|
|
|
|
new_size = asoc->mapping_array_size + ((needed + 7) / 8 + SCTP_MAPPING_ARRAY_INCR);
|
2010-04-03 15:40:14 +00:00
|
|
|
SCTP_MALLOC(new_array1, uint8_t *, new_size, SCTP_M_MAP);
|
|
|
|
SCTP_MALLOC(new_array2, uint8_t *, new_size, SCTP_M_MAP);
|
|
|
|
if ((new_array1 == NULL) || (new_array2 == NULL)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/* can't get more, forget it */
|
2010-04-03 15:40:14 +00:00
|
|
|
SCTP_PRINTF("No memory for expansion of SCTP mapping array %d\n", new_size);
|
|
|
|
if (new_array1) {
|
|
|
|
SCTP_FREE(new_array1, SCTP_M_MAP);
|
|
|
|
}
|
|
|
|
if (new_array2) {
|
|
|
|
SCTP_FREE(new_array2, SCTP_M_MAP);
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
return (-1);
|
|
|
|
}
|
2010-04-03 15:40:14 +00:00
|
|
|
memset(new_array1, 0, new_size);
|
|
|
|
memset(new_array2, 0, new_size);
|
|
|
|
memcpy(new_array1, asoc->mapping_array, asoc->mapping_array_size);
|
|
|
|
memcpy(new_array2, asoc->nr_mapping_array, asoc->mapping_array_size);
|
2007-05-29 09:29:03 +00:00
|
|
|
SCTP_FREE(asoc->mapping_array, SCTP_M_MAP);
|
2010-03-23 01:36:50 +00:00
|
|
|
SCTP_FREE(asoc->nr_mapping_array, SCTP_M_MAP);
|
2010-04-03 15:40:14 +00:00
|
|
|
asoc->mapping_array = new_array1;
|
|
|
|
asoc->nr_mapping_array = new_array2;
|
|
|
|
asoc->mapping_array_size = new_size;
|
2008-12-06 13:19:54 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2009-04-04 11:43:32 +00:00
|
|
|
|
2007-03-15 11:27:14 +00:00
|
|
|
static void
|
|
|
|
sctp_iterator_work(struct sctp_iterator *it)
|
|
|
|
{
|
|
|
|
int iteration_count = 0;
|
|
|
|
int inp_skip = 0;
|
2010-06-11 03:54:00 +00:00
|
|
|
int first_in = 1;
|
|
|
|
struct sctp_inpcb *tinp;
|
2007-03-15 11:27:14 +00:00
|
|
|
|
2010-06-11 03:54:00 +00:00
|
|
|
SCTP_INP_INFO_RLOCK();
|
2007-03-15 11:27:14 +00:00
|
|
|
SCTP_ITERATOR_LOCK();
|
2016-08-15 10:16:08 +00:00
|
|
|
sctp_it_ctl.cur_it = it;
|
2007-05-09 13:30:06 +00:00
|
|
|
if (it->inp) {
|
2010-06-11 03:54:00 +00:00
|
|
|
SCTP_INP_RLOCK(it->inp);
|
2007-03-15 11:27:14 +00:00
|
|
|
SCTP_INP_DECR_REF(it->inp);
|
2007-05-09 13:30:06 +00:00
|
|
|
}
|
2007-03-15 11:27:14 +00:00
|
|
|
if (it->inp == NULL) {
|
|
|
|
/* iterator is complete */
|
|
|
|
done_with_iterator:
|
2016-08-15 10:16:08 +00:00
|
|
|
sctp_it_ctl.cur_it = NULL;
|
2007-03-15 11:27:14 +00:00
|
|
|
SCTP_ITERATOR_UNLOCK();
|
2010-06-11 03:54:00 +00:00
|
|
|
SCTP_INP_INFO_RUNLOCK();
|
2007-03-15 11:27:14 +00:00
|
|
|
if (it->function_atend != NULL) {
|
|
|
|
(*it->function_atend) (it->pointer, it->val);
|
|
|
|
}
|
2007-05-29 09:29:03 +00:00
|
|
|
SCTP_FREE(it, SCTP_M_ITER);
|
2007-03-15 11:27:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
select_a_new_ep:
|
2010-06-11 03:54:00 +00:00
|
|
|
if (first_in) {
|
|
|
|
first_in = 0;
|
|
|
|
} else {
|
|
|
|
SCTP_INP_RLOCK(it->inp);
|
|
|
|
}
|
2007-03-15 11:27:14 +00:00
|
|
|
while (((it->pcb_flags) &&
|
|
|
|
((it->inp->sctp_flags & it->pcb_flags) != it->pcb_flags)) ||
|
|
|
|
((it->pcb_features) &&
|
|
|
|
((it->inp->sctp_features & it->pcb_features) != it->pcb_features))) {
|
|
|
|
/* endpoint flags or features don't match, so keep looking */
|
|
|
|
if (it->iterator_flags & SCTP_ITERATOR_DO_SINGLE_INP) {
|
2010-05-16 17:03:56 +00:00
|
|
|
SCTP_INP_RUNLOCK(it->inp);
|
2007-03-15 11:27:14 +00:00
|
|
|
goto done_with_iterator;
|
|
|
|
}
|
2010-06-11 03:54:00 +00:00
|
|
|
tinp = it->inp;
|
2007-03-15 11:27:14 +00:00
|
|
|
it->inp = LIST_NEXT(it->inp, sctp_list);
|
2010-06-11 03:54:00 +00:00
|
|
|
SCTP_INP_RUNLOCK(tinp);
|
2007-03-15 11:27:14 +00:00
|
|
|
if (it->inp == NULL) {
|
|
|
|
goto done_with_iterator;
|
|
|
|
}
|
2010-05-16 17:03:56 +00:00
|
|
|
SCTP_INP_RLOCK(it->inp);
|
2007-03-15 11:27:14 +00:00
|
|
|
}
|
|
|
|
/* now go through each assoc which is in the desired state */
|
|
|
|
if (it->done_current_ep == 0) {
|
|
|
|
if (it->function_inp != NULL)
|
|
|
|
inp_skip = (*it->function_inp) (it->inp, it->pointer, it->val);
|
|
|
|
it->done_current_ep = 1;
|
|
|
|
}
|
|
|
|
if (it->stcb == NULL) {
|
|
|
|
/* run the per instance function */
|
|
|
|
it->stcb = LIST_FIRST(&it->inp->sctp_asoc_list);
|
|
|
|
}
|
|
|
|
if ((inp_skip) || it->stcb == NULL) {
|
|
|
|
if (it->function_inp_end != NULL) {
|
|
|
|
inp_skip = (*it->function_inp_end) (it->inp,
|
|
|
|
it->pointer,
|
|
|
|
it->val);
|
|
|
|
}
|
|
|
|
SCTP_INP_RUNLOCK(it->inp);
|
|
|
|
goto no_stcb;
|
|
|
|
}
|
|
|
|
while (it->stcb) {
|
|
|
|
SCTP_TCB_LOCK(it->stcb);
|
|
|
|
if (it->asoc_state && ((it->stcb->asoc.state & it->asoc_state) != it->asoc_state)) {
|
|
|
|
/* not in the right state... keep looking */
|
|
|
|
SCTP_TCB_UNLOCK(it->stcb);
|
|
|
|
goto next_assoc;
|
|
|
|
}
|
|
|
|
/* see if we have limited out the iterator loop */
|
|
|
|
iteration_count++;
|
|
|
|
if (iteration_count > SCTP_ITERATOR_MAX_AT_ONCE) {
|
|
|
|
/* Pause to let others grab the lock */
|
|
|
|
atomic_add_int(&it->stcb->asoc.refcnt, 1);
|
|
|
|
SCTP_TCB_UNLOCK(it->stcb);
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_INP_INCR_REF(it->inp);
|
2007-03-15 11:27:14 +00:00
|
|
|
SCTP_INP_RUNLOCK(it->inp);
|
|
|
|
SCTP_ITERATOR_UNLOCK();
|
2010-06-11 03:54:00 +00:00
|
|
|
SCTP_INP_INFO_RUNLOCK();
|
|
|
|
SCTP_INP_INFO_RLOCK();
|
2007-03-15 11:27:14 +00:00
|
|
|
SCTP_ITERATOR_LOCK();
|
2010-05-16 17:03:56 +00:00
|
|
|
if (sctp_it_ctl.iterator_flags) {
|
|
|
|
/* We won't be staying here */
|
|
|
|
SCTP_INP_DECR_REF(it->inp);
|
|
|
|
atomic_add_int(&it->stcb->asoc.refcnt, -1);
|
|
|
|
if (sctp_it_ctl.iterator_flags &
|
|
|
|
SCTP_ITERATOR_STOP_CUR_IT) {
|
|
|
|
sctp_it_ctl.iterator_flags &= ~SCTP_ITERATOR_STOP_CUR_IT;
|
|
|
|
goto done_with_iterator;
|
|
|
|
}
|
|
|
|
if (sctp_it_ctl.iterator_flags &
|
|
|
|
SCTP_ITERATOR_STOP_CUR_INP) {
|
|
|
|
sctp_it_ctl.iterator_flags &= ~SCTP_ITERATOR_STOP_CUR_INP;
|
|
|
|
goto no_stcb;
|
|
|
|
}
|
|
|
|
/* If we reach here huh? */
|
2012-05-04 09:27:00 +00:00
|
|
|
SCTP_PRINTF("Unknown it ctl flag %x\n",
|
2010-05-16 17:03:56 +00:00
|
|
|
sctp_it_ctl.iterator_flags);
|
|
|
|
sctp_it_ctl.iterator_flags = 0;
|
|
|
|
}
|
2007-03-15 11:27:14 +00:00
|
|
|
SCTP_INP_RLOCK(it->inp);
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_INP_DECR_REF(it->inp);
|
2007-03-15 11:27:14 +00:00
|
|
|
SCTP_TCB_LOCK(it->stcb);
|
|
|
|
atomic_add_int(&it->stcb->asoc.refcnt, -1);
|
|
|
|
iteration_count = 0;
|
|
|
|
}
|
2018-07-19 20:16:33 +00:00
|
|
|
|
2007-03-15 11:27:14 +00:00
|
|
|
/* run function on this one */
|
|
|
|
(*it->function_assoc) (it->inp, it->stcb, it->pointer, it->val);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* we lie here, it really needs to have its own type but
|
|
|
|
* first I must verify that this won't effect things :-0
|
|
|
|
*/
|
|
|
|
if (it->no_chunk_output == 0)
|
2007-09-08 11:35:11 +00:00
|
|
|
sctp_chunk_output(it->inp, it->stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_NOT_LOCKED);
|
2007-03-15 11:27:14 +00:00
|
|
|
|
|
|
|
SCTP_TCB_UNLOCK(it->stcb);
|
|
|
|
next_assoc:
|
|
|
|
it->stcb = LIST_NEXT(it->stcb, sctp_tcblist);
|
|
|
|
if (it->stcb == NULL) {
|
|
|
|
/* Run last function */
|
|
|
|
if (it->function_inp_end != NULL) {
|
|
|
|
inp_skip = (*it->function_inp_end) (it->inp,
|
|
|
|
it->pointer,
|
|
|
|
it->val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SCTP_INP_RUNLOCK(it->inp);
|
|
|
|
no_stcb:
|
|
|
|
/* done with all assocs on this endpoint, move on to next endpoint */
|
|
|
|
it->done_current_ep = 0;
|
|
|
|
if (it->iterator_flags & SCTP_ITERATOR_DO_SINGLE_INP) {
|
|
|
|
it->inp = NULL;
|
|
|
|
} else {
|
|
|
|
it->inp = LIST_NEXT(it->inp, sctp_list);
|
|
|
|
}
|
|
|
|
if (it->inp == NULL) {
|
|
|
|
goto done_with_iterator;
|
|
|
|
}
|
|
|
|
goto select_a_new_ep;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sctp_iterator_worker(void)
|
|
|
|
{
|
2010-12-30 16:56:20 +00:00
|
|
|
struct sctp_iterator *it, *nit;
|
2007-03-15 11:27:14 +00:00
|
|
|
|
|
|
|
/* This function is called with the WQ lock in place */
|
|
|
|
|
2010-05-16 17:03:56 +00:00
|
|
|
sctp_it_ctl.iterator_running = 1;
|
2010-12-30 16:56:20 +00:00
|
|
|
TAILQ_FOREACH_SAFE(it, &sctp_it_ctl.iteratorhead, sctp_nxt_itr, nit) {
|
2007-03-15 11:27:14 +00:00
|
|
|
/* now lets work on this one */
|
2010-05-16 17:03:56 +00:00
|
|
|
TAILQ_REMOVE(&sctp_it_ctl.iteratorhead, it, sctp_nxt_itr);
|
2007-03-15 11:27:14 +00:00
|
|
|
SCTP_IPI_ITERATOR_WQ_UNLOCK();
|
2010-05-16 17:03:56 +00:00
|
|
|
CURVNET_SET(it->vn);
|
2007-03-15 11:27:14 +00:00
|
|
|
sctp_iterator_work(it);
|
2010-05-16 17:03:56 +00:00
|
|
|
CURVNET_RESTORE();
|
2007-03-15 11:27:14 +00:00
|
|
|
SCTP_IPI_ITERATOR_WQ_LOCK();
|
2007-05-17 12:16:24 +00:00
|
|
|
/* sa_ignore FREED_MEMORY */
|
2007-03-15 11:27:14 +00:00
|
|
|
}
|
2010-05-16 17:03:56 +00:00
|
|
|
sctp_it_ctl.iterator_running = 0;
|
2007-03-15 11:27:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
sctp_handle_addr_wq(void)
|
|
|
|
{
|
|
|
|
/* deal with the ADDR wq from the rtsock calls */
|
2010-12-30 16:56:20 +00:00
|
|
|
struct sctp_laddr *wi, *nwi;
|
2007-03-15 11:27:14 +00:00
|
|
|
struct sctp_asconf_iterator *asc;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2007-03-15 11:27:14 +00:00
|
|
|
SCTP_MALLOC(asc, struct sctp_asconf_iterator *,
|
2007-05-29 09:29:03 +00:00
|
|
|
sizeof(struct sctp_asconf_iterator), SCTP_M_ASC_IT);
|
2007-03-15 11:27:14 +00:00
|
|
|
if (asc == NULL) {
|
|
|
|
/* Try later, no memory */
|
2006-11-03 15:23:16 +00:00
|
|
|
sctp_timer_start(SCTP_TIMER_TYPE_ADDR_WQ,
|
|
|
|
(struct sctp_inpcb *)NULL,
|
|
|
|
(struct sctp_tcb *)NULL,
|
|
|
|
(struct sctp_nets *)NULL);
|
2007-03-15 11:27:14 +00:00
|
|
|
return;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2007-03-15 11:27:14 +00:00
|
|
|
LIST_INIT(&asc->list_of_work);
|
|
|
|
asc->cnt = 0;
|
2010-05-16 17:03:56 +00:00
|
|
|
|
2010-12-30 16:56:20 +00:00
|
|
|
LIST_FOREACH_SAFE(wi, &SCTP_BASE_INFO(addr_wq), sctp_nxt_addr, nwi) {
|
2007-03-15 11:27:14 +00:00
|
|
|
LIST_REMOVE(wi, sctp_nxt_addr);
|
|
|
|
LIST_INSERT_HEAD(&asc->list_of_work, wi, sctp_nxt_addr);
|
|
|
|
asc->cnt++;
|
|
|
|
}
|
2010-05-16 17:03:56 +00:00
|
|
|
|
2007-03-15 11:27:14 +00:00
|
|
|
if (asc->cnt == 0) {
|
2007-05-29 09:29:03 +00:00
|
|
|
SCTP_FREE(asc, SCTP_M_ASC_IT);
|
2007-03-15 11:27:14 +00:00
|
|
|
} else {
|
2016-02-16 19:36:25 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = sctp_initiate_iterator(sctp_asconf_iterator_ep,
|
2007-07-24 20:06:02 +00:00
|
|
|
sctp_asconf_iterator_stcb,
|
2007-03-15 11:27:14 +00:00
|
|
|
NULL, /* No ep end for boundall */
|
|
|
|
SCTP_PCB_FLAGS_BOUNDALL,
|
|
|
|
SCTP_PCB_ANY_FEATURES,
|
2007-07-24 20:06:02 +00:00
|
|
|
SCTP_ASOC_ANY_STATE,
|
|
|
|
(void *)asc, 0,
|
|
|
|
sctp_asconf_iterator_end, NULL, 0);
|
2016-02-16 19:36:25 +00:00
|
|
|
if (ret) {
|
|
|
|
SCTP_PRINTF("Failed to initiate iterator for handle_addr_wq\n");
|
2016-12-26 11:06:41 +00:00
|
|
|
/*
|
|
|
|
* Freeing if we are stopping or put back on the
|
|
|
|
* addr_wq.
|
|
|
|
*/
|
2016-02-16 19:36:25 +00:00
|
|
|
if (SCTP_BASE_VAR(sctp_pcb_initialized) == 0) {
|
|
|
|
sctp_asconf_iterator_end(asc, 0);
|
|
|
|
} else {
|
|
|
|
LIST_FOREACH(wi, &asc->list_of_work, sctp_nxt_addr) {
|
|
|
|
LIST_INSERT_HEAD(&SCTP_BASE_INFO(addr_wq), wi, sctp_nxt_addr);
|
|
|
|
}
|
|
|
|
SCTP_FREE(asc, SCTP_M_ASC_IT);
|
|
|
|
}
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sctp_timeout_handler(void *t)
|
|
|
|
{
|
|
|
|
struct sctp_inpcb *inp;
|
|
|
|
struct sctp_tcb *stcb;
|
|
|
|
struct sctp_nets *net;
|
|
|
|
struct sctp_timer *tmr;
|
2015-07-27 22:35:54 +00:00
|
|
|
struct mbuf *op_err;
|
2012-06-25 17:15:09 +00:00
|
|
|
#if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
|
2007-09-08 11:35:11 +00:00
|
|
|
struct socket *so;
|
|
|
|
#endif
|
2015-05-28 14:24:21 +00:00
|
|
|
int did_output;
|
2016-01-13 14:28:12 +00:00
|
|
|
int type;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
tmr = (struct sctp_timer *)t;
|
|
|
|
inp = (struct sctp_inpcb *)tmr->ep;
|
|
|
|
stcb = (struct sctp_tcb *)tmr->tcb;
|
|
|
|
net = (struct sctp_nets *)tmr->net;
|
2009-09-19 14:02:16 +00:00
|
|
|
CURVNET_SET((struct vnet *)tmr->vnet);
|
2006-11-03 15:23:16 +00:00
|
|
|
did_output = 1;
|
|
|
|
|
|
|
|
#ifdef SCTP_AUDITING_ENABLED
|
2018-07-19 20:11:14 +00:00
|
|
|
sctp_audit_log(0xF0, (uint8_t)tmr->type);
|
2006-11-03 15:23:16 +00:00
|
|
|
sctp_auditing(3, inp, stcb, net);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* sanity checks... */
|
|
|
|
if (tmr->self != (void *)tmr) {
|
|
|
|
/*
|
2007-05-09 13:30:06 +00:00
|
|
|
* SCTP_PRINTF("Stale SCTP timer fired (%p), ignoring...\n",
|
2012-09-05 18:52:01 +00:00
|
|
|
* (void *)tmr);
|
2006-11-03 15:23:16 +00:00
|
|
|
*/
|
2009-09-19 14:02:16 +00:00
|
|
|
CURVNET_RESTORE();
|
2006-11-03 15:23:16 +00:00
|
|
|
return;
|
|
|
|
}
|
2006-12-14 17:02:55 +00:00
|
|
|
tmr->stopped_from = 0xa001;
|
2006-11-03 15:23:16 +00:00
|
|
|
if (!SCTP_IS_TIMER_TYPE_VALID(tmr->type)) {
|
|
|
|
/*
|
2007-05-09 13:30:06 +00:00
|
|
|
* SCTP_PRINTF("SCTP timer fired with invalid type: 0x%x\n",
|
2006-11-03 15:23:16 +00:00
|
|
|
* tmr->type);
|
|
|
|
*/
|
2009-09-19 14:02:16 +00:00
|
|
|
CURVNET_RESTORE();
|
2006-11-03 15:23:16 +00:00
|
|
|
return;
|
|
|
|
}
|
2006-12-14 17:02:55 +00:00
|
|
|
tmr->stopped_from = 0xa002;
|
2006-11-03 15:23:16 +00:00
|
|
|
if ((tmr->type != SCTP_TIMER_TYPE_ADDR_WQ) && (inp == NULL)) {
|
2009-09-19 14:02:16 +00:00
|
|
|
CURVNET_RESTORE();
|
2006-11-03 15:23:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* if this is an iterator timeout, get the struct and clear inp */
|
2006-12-14 17:02:55 +00:00
|
|
|
tmr->stopped_from = 0xa003;
|
2006-11-03 15:23:16 +00:00
|
|
|
if (inp) {
|
|
|
|
SCTP_INP_INCR_REF(inp);
|
2012-01-06 20:20:59 +00:00
|
|
|
if ((inp->sctp_socket == NULL) &&
|
2006-11-03 15:23:16 +00:00
|
|
|
((tmr->type != SCTP_TIMER_TYPE_INPKILL) &&
|
2009-08-15 21:10:52 +00:00
|
|
|
(tmr->type != SCTP_TIMER_TYPE_INIT) &&
|
2008-11-12 14:16:39 +00:00
|
|
|
(tmr->type != SCTP_TIMER_TYPE_SEND) &&
|
|
|
|
(tmr->type != SCTP_TIMER_TYPE_RECV) &&
|
|
|
|
(tmr->type != SCTP_TIMER_TYPE_HEARTBEAT) &&
|
2006-11-03 15:23:16 +00:00
|
|
|
(tmr->type != SCTP_TIMER_TYPE_SHUTDOWN) &&
|
|
|
|
(tmr->type != SCTP_TIMER_TYPE_SHUTDOWNACK) &&
|
|
|
|
(tmr->type != SCTP_TIMER_TYPE_SHUTDOWNGUARD) &&
|
2017-09-20 21:29:54 +00:00
|
|
|
(tmr->type != SCTP_TIMER_TYPE_ASOCKILL))) {
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_DECR_REF(inp);
|
2009-09-19 14:02:16 +00:00
|
|
|
CURVNET_RESTORE();
|
2006-11-03 15:23:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2006-12-14 17:02:55 +00:00
|
|
|
tmr->stopped_from = 0xa004;
|
2006-11-03 15:23:16 +00:00
|
|
|
if (stcb) {
|
2007-04-14 09:44:09 +00:00
|
|
|
atomic_add_int(&stcb->asoc.refcnt, 1);
|
2006-11-03 15:23:16 +00:00
|
|
|
if (stcb->asoc.state == 0) {
|
2007-04-14 09:44:09 +00:00
|
|
|
atomic_add_int(&stcb->asoc.refcnt, -1);
|
2006-11-03 15:23:16 +00:00
|
|
|
if (inp) {
|
|
|
|
SCTP_INP_DECR_REF(inp);
|
|
|
|
}
|
2009-09-19 14:02:16 +00:00
|
|
|
CURVNET_RESTORE();
|
2006-11-03 15:23:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2016-01-13 14:28:12 +00:00
|
|
|
type = tmr->type;
|
2006-12-14 17:02:55 +00:00
|
|
|
tmr->stopped_from = 0xa005;
|
2016-01-13 14:28:12 +00:00
|
|
|
SCTPDBG(SCTP_DEBUG_TIMER1, "Timer type %d goes off\n", type);
|
2006-12-29 20:21:42 +00:00
|
|
|
if (!SCTP_OS_TIMER_ACTIVE(&tmr->timer)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
if (inp) {
|
|
|
|
SCTP_INP_DECR_REF(inp);
|
|
|
|
}
|
2007-05-29 09:29:03 +00:00
|
|
|
if (stcb) {
|
|
|
|
atomic_add_int(&stcb->asoc.refcnt, -1);
|
|
|
|
}
|
2009-09-19 14:02:16 +00:00
|
|
|
CURVNET_RESTORE();
|
2006-11-03 15:23:16 +00:00
|
|
|
return;
|
|
|
|
}
|
2006-12-14 17:02:55 +00:00
|
|
|
tmr->stopped_from = 0xa006;
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
if (stcb) {
|
|
|
|
SCTP_TCB_LOCK(stcb);
|
2006-11-05 13:25:18 +00:00
|
|
|
atomic_add_int(&stcb->asoc.refcnt, -1);
|
2016-01-13 14:28:12 +00:00
|
|
|
if ((type != SCTP_TIMER_TYPE_ASOCKILL) &&
|
2007-07-14 09:36:28 +00:00
|
|
|
((stcb->asoc.state == 0) ||
|
|
|
|
(stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED))) {
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
if (inp) {
|
|
|
|
SCTP_INP_DECR_REF(inp);
|
|
|
|
}
|
2009-09-19 14:02:16 +00:00
|
|
|
CURVNET_RESTORE();
|
2007-07-14 09:36:28 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-09-20 21:29:54 +00:00
|
|
|
} else if (inp != NULL) {
|
|
|
|
if (type != SCTP_TIMER_TYPE_INPKILL) {
|
|
|
|
SCTP_INP_WLOCK(inp);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
SCTP_WQ_ADDR_LOCK();
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2016-05-02 20:56:11 +00:00
|
|
|
/* record in stopped what t-o occurred */
|
2016-01-13 14:28:12 +00:00
|
|
|
tmr->stopped_from = type;
|
2007-01-15 15:12:10 +00:00
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
/* mark as being serviced now */
|
2007-01-15 15:12:10 +00:00
|
|
|
if (SCTP_OS_TIMER_PENDING(&tmr->timer)) {
|
|
|
|
/*
|
|
|
|
* Callout has been rescheduled.
|
|
|
|
*/
|
|
|
|
goto get_out;
|
|
|
|
}
|
|
|
|
if (!SCTP_OS_TIMER_ACTIVE(&tmr->timer)) {
|
|
|
|
/*
|
|
|
|
* Not active, so no action.
|
|
|
|
*/
|
|
|
|
goto get_out;
|
|
|
|
}
|
2006-12-29 20:21:42 +00:00
|
|
|
SCTP_OS_TIMER_DEACTIVATE(&tmr->timer);
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
/* call the handler for the appropriate timer type */
|
2016-01-13 14:28:12 +00:00
|
|
|
switch (type) {
|
2006-11-03 15:23:16 +00:00
|
|
|
case SCTP_TIMER_TYPE_ADDR_WQ:
|
|
|
|
sctp_handle_addr_wq();
|
|
|
|
break;
|
|
|
|
case SCTP_TIMER_TYPE_SEND:
|
2007-05-09 13:30:06 +00:00
|
|
|
if ((stcb == NULL) || (inp == NULL)) {
|
|
|
|
break;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_STAT_INCR(sctps_timodata);
|
2007-02-12 23:24:31 +00:00
|
|
|
stcb->asoc.timodata++;
|
2006-11-03 15:23:16 +00:00
|
|
|
stcb->asoc.num_send_timers_up--;
|
|
|
|
if (stcb->asoc.num_send_timers_up < 0) {
|
|
|
|
stcb->asoc.num_send_timers_up = 0;
|
|
|
|
}
|
2007-07-14 09:36:28 +00:00
|
|
|
SCTP_TCB_LOCK_ASSERT(stcb);
|
2011-12-27 10:16:24 +00:00
|
|
|
if (sctp_t3rxt_timer(inp, stcb, net)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/* no need to unlock on tcb its gone */
|
|
|
|
|
|
|
|
goto out_decr;
|
|
|
|
}
|
2007-07-14 09:36:28 +00:00
|
|
|
SCTP_TCB_LOCK_ASSERT(stcb);
|
2006-11-03 15:23:16 +00:00
|
|
|
#ifdef SCTP_AUDITING_ENABLED
|
|
|
|
sctp_auditing(4, inp, stcb, net);
|
|
|
|
#endif
|
2007-09-08 11:35:11 +00:00
|
|
|
sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_NOT_LOCKED);
|
2006-11-03 15:23:16 +00:00
|
|
|
if ((stcb->asoc.num_send_timers_up == 0) &&
|
2010-12-30 16:56:20 +00:00
|
|
|
(stcb->asoc.sent_queue_cnt > 0)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
struct sctp_tmit_chunk *chk;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* safeguard. If there on some on the sent queue
|
|
|
|
* somewhere but no timers running something is
|
|
|
|
* wrong... so we start a timer on the first chunk
|
|
|
|
* on the send queue on whatever net it is sent to.
|
|
|
|
*/
|
|
|
|
chk = TAILQ_FIRST(&stcb->asoc.sent_queue);
|
|
|
|
sctp_timer_start(SCTP_TIMER_TYPE_SEND, inp, stcb,
|
|
|
|
chk->whoTo);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCTP_TIMER_TYPE_INIT:
|
2007-05-09 13:30:06 +00:00
|
|
|
if ((stcb == NULL) || (inp == NULL)) {
|
|
|
|
break;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_STAT_INCR(sctps_timoinit);
|
2007-02-12 23:24:31 +00:00
|
|
|
stcb->asoc.timoinit++;
|
2006-11-03 15:23:16 +00:00
|
|
|
if (sctp_t1init_timer(inp, stcb, net)) {
|
|
|
|
/* no need to unlock on tcb its gone */
|
|
|
|
goto out_decr;
|
|
|
|
}
|
|
|
|
/* We do output but not here */
|
|
|
|
did_output = 0;
|
|
|
|
break;
|
|
|
|
case SCTP_TIMER_TYPE_RECV:
|
2007-05-09 13:30:06 +00:00
|
|
|
if ((stcb == NULL) || (inp == NULL)) {
|
|
|
|
break;
|
|
|
|
}
|
2011-08-03 20:21:00 +00:00
|
|
|
SCTP_STAT_INCR(sctps_timosack);
|
|
|
|
stcb->asoc.timosack++;
|
|
|
|
sctp_send_sack(stcb, SCTP_SO_NOT_LOCKED);
|
2006-11-03 15:23:16 +00:00
|
|
|
#ifdef SCTP_AUDITING_ENABLED
|
|
|
|
sctp_auditing(4, inp, stcb, net);
|
|
|
|
#endif
|
2007-09-08 11:35:11 +00:00
|
|
|
sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SACK_TMR, SCTP_SO_NOT_LOCKED);
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
|
|
|
case SCTP_TIMER_TYPE_SHUTDOWN:
|
2007-05-09 13:30:06 +00:00
|
|
|
if ((stcb == NULL) || (inp == NULL)) {
|
|
|
|
break;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
if (sctp_shutdown_timer(inp, stcb, net)) {
|
|
|
|
/* no need to unlock on tcb its gone */
|
|
|
|
goto out_decr;
|
|
|
|
}
|
|
|
|
SCTP_STAT_INCR(sctps_timoshutdown);
|
2007-02-12 23:24:31 +00:00
|
|
|
stcb->asoc.timoshutdown++;
|
2006-11-03 15:23:16 +00:00
|
|
|
#ifdef SCTP_AUDITING_ENABLED
|
|
|
|
sctp_auditing(4, inp, stcb, net);
|
|
|
|
#endif
|
2007-09-08 11:35:11 +00:00
|
|
|
sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SHUT_TMR, SCTP_SO_NOT_LOCKED);
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
|
|
|
case SCTP_TIMER_TYPE_HEARTBEAT:
|
2011-08-03 20:21:00 +00:00
|
|
|
if ((stcb == NULL) || (inp == NULL) || (net == NULL)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
SCTP_STAT_INCR(sctps_timoheartbeat);
|
|
|
|
stcb->asoc.timoheartbeat++;
|
|
|
|
if (sctp_heartbeat_timer(inp, stcb, net)) {
|
|
|
|
/* no need to unlock on tcb its gone */
|
|
|
|
goto out_decr;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
#ifdef SCTP_AUDITING_ENABLED
|
2011-08-03 20:21:00 +00:00
|
|
|
sctp_auditing(4, inp, stcb, net);
|
2006-11-03 15:23:16 +00:00
|
|
|
#endif
|
2011-08-03 20:21:00 +00:00
|
|
|
if (!(net->dest_state & SCTP_ADDR_NOHB)) {
|
2011-10-09 14:12:17 +00:00
|
|
|
sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net);
|
2007-09-08 11:35:11 +00:00
|
|
|
sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_HB_TMR, SCTP_SO_NOT_LOCKED);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCTP_TIMER_TYPE_COOKIE:
|
2007-05-09 13:30:06 +00:00
|
|
|
if ((stcb == NULL) || (inp == NULL)) {
|
|
|
|
break;
|
|
|
|
}
|
2018-07-19 20:16:33 +00:00
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
if (sctp_cookie_timer(inp, stcb, net)) {
|
|
|
|
/* no need to unlock on tcb its gone */
|
|
|
|
goto out_decr;
|
|
|
|
}
|
|
|
|
SCTP_STAT_INCR(sctps_timocookie);
|
2007-02-12 23:24:31 +00:00
|
|
|
stcb->asoc.timocookie++;
|
2006-11-03 15:23:16 +00:00
|
|
|
#ifdef SCTP_AUDITING_ENABLED
|
|
|
|
sctp_auditing(4, inp, stcb, net);
|
|
|
|
#endif
|
|
|
|
/*
|
|
|
|
* We consider T3 and Cookie timer pretty much the same with
|
|
|
|
* respect to where from in chunk_output.
|
|
|
|
*/
|
2007-09-08 11:35:11 +00:00
|
|
|
sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_T3, SCTP_SO_NOT_LOCKED);
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
|
|
|
case SCTP_TIMER_TYPE_NEWCOOKIE:
|
|
|
|
{
|
|
|
|
struct timeval tv;
|
|
|
|
int i, secret;
|
|
|
|
|
2007-05-09 13:30:06 +00:00
|
|
|
if (inp == NULL) {
|
|
|
|
break;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_STAT_INCR(sctps_timosecret);
|
2007-05-08 14:32:53 +00:00
|
|
|
(void)SCTP_GETTIME_TIMEVAL(&tv);
|
2006-11-03 15:23:16 +00:00
|
|
|
inp->sctp_ep.time_of_secret_change = tv.tv_sec;
|
|
|
|
inp->sctp_ep.last_secret_number =
|
|
|
|
inp->sctp_ep.current_secret_number;
|
|
|
|
inp->sctp_ep.current_secret_number++;
|
|
|
|
if (inp->sctp_ep.current_secret_number >=
|
|
|
|
SCTP_HOW_MANY_SECRETS) {
|
|
|
|
inp->sctp_ep.current_secret_number = 0;
|
|
|
|
}
|
|
|
|
secret = (int)inp->sctp_ep.current_secret_number;
|
|
|
|
for (i = 0; i < SCTP_NUMBER_OF_SECRETS; i++) {
|
|
|
|
inp->sctp_ep.secret_key[secret][i] =
|
|
|
|
sctp_select_initial_TSN(&inp->sctp_ep);
|
|
|
|
}
|
|
|
|
sctp_timer_start(SCTP_TIMER_TYPE_NEWCOOKIE, inp, stcb, net);
|
|
|
|
}
|
|
|
|
did_output = 0;
|
|
|
|
break;
|
|
|
|
case SCTP_TIMER_TYPE_PATHMTURAISE:
|
2007-05-09 13:30:06 +00:00
|
|
|
if ((stcb == NULL) || (inp == NULL)) {
|
|
|
|
break;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_STAT_INCR(sctps_timopathmtu);
|
|
|
|
sctp_pathmtu_timer(inp, stcb, net);
|
|
|
|
did_output = 0;
|
|
|
|
break;
|
|
|
|
case SCTP_TIMER_TYPE_SHUTDOWNACK:
|
2007-05-09 13:30:06 +00:00
|
|
|
if ((stcb == NULL) || (inp == NULL)) {
|
|
|
|
break;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
if (sctp_shutdownack_timer(inp, stcb, net)) {
|
|
|
|
/* no need to unlock on tcb its gone */
|
|
|
|
goto out_decr;
|
|
|
|
}
|
|
|
|
SCTP_STAT_INCR(sctps_timoshutdownack);
|
2007-02-12 23:24:31 +00:00
|
|
|
stcb->asoc.timoshutdownack++;
|
2006-11-03 15:23:16 +00:00
|
|
|
#ifdef SCTP_AUDITING_ENABLED
|
|
|
|
sctp_auditing(4, inp, stcb, net);
|
|
|
|
#endif
|
2007-09-08 11:35:11 +00:00
|
|
|
sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_SHUT_ACK_TMR, SCTP_SO_NOT_LOCKED);
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
|
|
|
case SCTP_TIMER_TYPE_SHUTDOWNGUARD:
|
2007-05-09 13:30:06 +00:00
|
|
|
if ((stcb == NULL) || (inp == NULL)) {
|
|
|
|
break;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_STAT_INCR(sctps_timoshutdownguard);
|
2015-07-27 22:35:54 +00:00
|
|
|
op_err = sctp_generate_cause(SCTP_BASE_SYSCTL(sctp_diag_info_code),
|
|
|
|
"Shutdown guard timer expired");
|
|
|
|
sctp_abort_an_association(inp, stcb, op_err, SCTP_SO_NOT_LOCKED);
|
2006-11-03 15:23:16 +00:00
|
|
|
/* no need to unlock on tcb its gone */
|
|
|
|
goto out_decr;
|
|
|
|
|
|
|
|
case SCTP_TIMER_TYPE_STRRESET:
|
2007-05-09 13:30:06 +00:00
|
|
|
if ((stcb == NULL) || (inp == NULL)) {
|
|
|
|
break;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
if (sctp_strreset_timer(inp, stcb, net)) {
|
|
|
|
/* no need to unlock on tcb its gone */
|
|
|
|
goto out_decr;
|
|
|
|
}
|
|
|
|
SCTP_STAT_INCR(sctps_timostrmrst);
|
2007-09-08 11:35:11 +00:00
|
|
|
sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_STRRST_TMR, SCTP_SO_NOT_LOCKED);
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
|
|
|
case SCTP_TIMER_TYPE_ASCONF:
|
2007-05-09 13:30:06 +00:00
|
|
|
if ((stcb == NULL) || (inp == NULL)) {
|
|
|
|
break;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
if (sctp_asconf_timer(inp, stcb, net)) {
|
|
|
|
/* no need to unlock on tcb its gone */
|
|
|
|
goto out_decr;
|
|
|
|
}
|
|
|
|
SCTP_STAT_INCR(sctps_timoasconf);
|
|
|
|
#ifdef SCTP_AUDITING_ENABLED
|
|
|
|
sctp_auditing(4, inp, stcb, net);
|
|
|
|
#endif
|
2007-09-08 11:35:11 +00:00
|
|
|
sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_ASCONF_TMR, SCTP_SO_NOT_LOCKED);
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
2007-09-08 17:48:46 +00:00
|
|
|
case SCTP_TIMER_TYPE_PRIM_DELETED:
|
|
|
|
if ((stcb == NULL) || (inp == NULL)) {
|
|
|
|
break;
|
|
|
|
}
|
2007-09-13 10:36:43 +00:00
|
|
|
sctp_delete_prim_timer(inp, stcb, net);
|
2007-09-08 17:48:46 +00:00
|
|
|
SCTP_STAT_INCR(sctps_timodelprim);
|
|
|
|
break;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
case SCTP_TIMER_TYPE_AUTOCLOSE:
|
2007-05-09 13:30:06 +00:00
|
|
|
if ((stcb == NULL) || (inp == NULL)) {
|
|
|
|
break;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_STAT_INCR(sctps_timoautoclose);
|
|
|
|
sctp_autoclose_timer(inp, stcb, net);
|
2007-09-08 11:35:11 +00:00
|
|
|
sctp_chunk_output(inp, stcb, SCTP_OUTPUT_FROM_AUTOCLOSE_TMR, SCTP_SO_NOT_LOCKED);
|
2006-11-03 15:23:16 +00:00
|
|
|
did_output = 0;
|
|
|
|
break;
|
|
|
|
case SCTP_TIMER_TYPE_ASOCKILL:
|
2007-05-09 13:30:06 +00:00
|
|
|
if ((stcb == NULL) || (inp == NULL)) {
|
|
|
|
break;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_STAT_INCR(sctps_timoassockill);
|
|
|
|
/* Can we free it yet? */
|
|
|
|
SCTP_INP_DECR_REF(inp);
|
2015-05-28 16:39:22 +00:00
|
|
|
sctp_timer_stop(SCTP_TIMER_TYPE_ASOCKILL, inp, stcb, NULL,
|
|
|
|
SCTP_FROM_SCTPUTIL + SCTP_LOC_1);
|
2012-06-25 17:15:09 +00:00
|
|
|
#if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
|
2007-09-08 11:35:11 +00:00
|
|
|
so = SCTP_INP_SO(inp);
|
|
|
|
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);
|
|
|
|
#endif
|
2015-05-28 16:39:22 +00:00
|
|
|
(void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
|
|
|
|
SCTP_FROM_SCTPUTIL + SCTP_LOC_2);
|
2012-06-25 17:15:09 +00:00
|
|
|
#if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
|
2007-09-08 11:35:11 +00:00
|
|
|
SCTP_SOCKET_UNLOCK(so, 1);
|
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
/*
|
|
|
|
* free asoc, always unlocks (or destroy's) so prevent
|
|
|
|
* duplicate unlock or unlock of a free mtx :-0
|
|
|
|
*/
|
|
|
|
stcb = NULL;
|
|
|
|
goto out_no_decr;
|
|
|
|
case SCTP_TIMER_TYPE_INPKILL:
|
|
|
|
SCTP_STAT_INCR(sctps_timoinpkill);
|
2007-05-09 13:30:06 +00:00
|
|
|
if (inp == NULL) {
|
|
|
|
break;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
/*
|
|
|
|
* special case, take away our increment since WE are the
|
|
|
|
* killer
|
|
|
|
*/
|
|
|
|
SCTP_INP_DECR_REF(inp);
|
2015-05-28 16:39:22 +00:00
|
|
|
sctp_timer_stop(SCTP_TIMER_TYPE_INPKILL, inp, NULL, NULL,
|
|
|
|
SCTP_FROM_SCTPUTIL + SCTP_LOC_3);
|
2007-05-08 15:53:03 +00:00
|
|
|
sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
|
2010-06-06 19:24:32 +00:00
|
|
|
SCTP_CALLED_FROM_INPKILL_TIMER);
|
2008-05-21 16:51:21 +00:00
|
|
|
inp = NULL;
|
2006-11-03 15:23:16 +00:00
|
|
|
goto out_no_decr;
|
|
|
|
default:
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTPDBG(SCTP_DEBUG_TIMER1, "sctp_timeout_handler:unknown timer %d\n",
|
2016-01-13 14:28:12 +00:00
|
|
|
type);
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
2011-12-27 10:16:24 +00:00
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
#ifdef SCTP_AUDITING_ENABLED
|
2018-07-19 20:11:14 +00:00
|
|
|
sctp_audit_log(0xF1, (uint8_t)type);
|
2006-11-03 15:23:16 +00:00
|
|
|
if (inp)
|
|
|
|
sctp_auditing(5, inp, stcb, net);
|
|
|
|
#endif
|
|
|
|
if ((did_output) && stcb) {
|
|
|
|
/*
|
|
|
|
* Now we need to clean up the control chunk chain if an
|
|
|
|
* ECNE is on it. It must be marked as UNSENT again so next
|
|
|
|
* call will continue to send it until such time that we get
|
|
|
|
* a CWR, to remove it. It is, however, less likely that we
|
|
|
|
* will find a ecn echo on the chain though.
|
|
|
|
*/
|
|
|
|
sctp_fix_ecn_echo(&stcb->asoc);
|
|
|
|
}
|
2007-01-15 15:12:10 +00:00
|
|
|
get_out:
|
2006-11-03 15:23:16 +00:00
|
|
|
if (stcb) {
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
2017-09-20 21:29:54 +00:00
|
|
|
} else if (inp != NULL) {
|
|
|
|
SCTP_INP_WUNLOCK(inp);
|
|
|
|
} else {
|
|
|
|
SCTP_WQ_ADDR_UNLOCK();
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2017-09-20 21:29:54 +00:00
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
out_decr:
|
|
|
|
if (inp) {
|
|
|
|
SCTP_INP_DECR_REF(inp);
|
|
|
|
}
|
2018-07-19 20:16:33 +00:00
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
out_no_decr:
|
2016-01-13 14:28:12 +00:00
|
|
|
SCTPDBG(SCTP_DEBUG_TIMER1, "Timer now complete (type = %d)\n", type);
|
2009-09-19 14:02:16 +00:00
|
|
|
CURVNET_RESTORE();
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
2007-05-09 13:30:06 +00:00
|
|
|
void
|
2006-11-03 15:23:16 +00:00
|
|
|
sctp_timer_start(int t_type, struct sctp_inpcb *inp, struct sctp_tcb *stcb,
|
|
|
|
struct sctp_nets *net)
|
|
|
|
{
|
2011-08-03 20:21:00 +00:00
|
|
|
uint32_t to_ticks;
|
2006-11-03 15:23:16 +00:00
|
|
|
struct sctp_timer *tmr;
|
|
|
|
|
2006-12-29 20:21:42 +00:00
|
|
|
if ((t_type != SCTP_TIMER_TYPE_ADDR_WQ) && (inp == NULL))
|
2007-05-09 13:30:06 +00:00
|
|
|
return;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
tmr = NULL;
|
|
|
|
if (stcb) {
|
|
|
|
SCTP_TCB_LOCK_ASSERT(stcb);
|
|
|
|
}
|
|
|
|
switch (t_type) {
|
|
|
|
case SCTP_TIMER_TYPE_ADDR_WQ:
|
|
|
|
/* Only 1 tick away :-) */
|
2008-06-14 07:58:05 +00:00
|
|
|
tmr = &SCTP_BASE_INFO(addr_wq_timer);
|
2007-03-15 11:27:14 +00:00
|
|
|
to_ticks = SCTP_ADDRESS_TICK_DELAY;
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
|
|
|
case SCTP_TIMER_TYPE_SEND:
|
|
|
|
/* Here we use the RTO timer */
|
|
|
|
{
|
|
|
|
int rto_val;
|
|
|
|
|
|
|
|
if ((stcb == NULL) || (net == NULL)) {
|
2007-05-09 13:30:06 +00:00
|
|
|
return;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
tmr = &net->rxt_timer;
|
|
|
|
if (net->RTO == 0) {
|
|
|
|
rto_val = stcb->asoc.initial_rto;
|
|
|
|
} else {
|
|
|
|
rto_val = net->RTO;
|
|
|
|
}
|
|
|
|
to_ticks = MSEC_TO_TICKS(rto_val);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCTP_TIMER_TYPE_INIT:
|
|
|
|
/*
|
|
|
|
* Here we use the INIT timer default usually about 1
|
|
|
|
* minute.
|
|
|
|
*/
|
|
|
|
if ((stcb == NULL) || (net == NULL)) {
|
2007-05-09 13:30:06 +00:00
|
|
|
return;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
tmr = &net->rxt_timer;
|
|
|
|
if (net->RTO == 0) {
|
|
|
|
to_ticks = MSEC_TO_TICKS(stcb->asoc.initial_rto);
|
|
|
|
} else {
|
|
|
|
to_ticks = MSEC_TO_TICKS(net->RTO);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCTP_TIMER_TYPE_RECV:
|
|
|
|
/*
|
|
|
|
* Here we use the Delayed-Ack timer value from the inp
|
|
|
|
* ususually about 200ms.
|
|
|
|
*/
|
|
|
|
if (stcb == NULL) {
|
2007-05-09 13:30:06 +00:00
|
|
|
return;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
tmr = &stcb->asoc.dack_timer;
|
|
|
|
to_ticks = MSEC_TO_TICKS(stcb->asoc.delayed_ack);
|
|
|
|
break;
|
|
|
|
case SCTP_TIMER_TYPE_SHUTDOWN:
|
|
|
|
/* Here we use the RTO of the destination. */
|
|
|
|
if ((stcb == NULL) || (net == NULL)) {
|
2007-05-09 13:30:06 +00:00
|
|
|
return;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
if (net->RTO == 0) {
|
|
|
|
to_ticks = MSEC_TO_TICKS(stcb->asoc.initial_rto);
|
|
|
|
} else {
|
|
|
|
to_ticks = MSEC_TO_TICKS(net->RTO);
|
|
|
|
}
|
|
|
|
tmr = &net->rxt_timer;
|
|
|
|
break;
|
|
|
|
case SCTP_TIMER_TYPE_HEARTBEAT:
|
|
|
|
/*
|
|
|
|
* the net is used here so that we can add in the RTO. Even
|
|
|
|
* though we use a different timer. We also add the HB timer
|
|
|
|
* PLUS a random jitter.
|
|
|
|
*/
|
2014-12-21 13:58:53 +00:00
|
|
|
if ((stcb == NULL) || (net == NULL)) {
|
2007-05-09 13:30:06 +00:00
|
|
|
return;
|
|
|
|
} else {
|
2006-11-03 15:23:16 +00:00
|
|
|
uint32_t rndval;
|
2011-08-03 20:21:00 +00:00
|
|
|
uint32_t jitter;
|
|
|
|
|
|
|
|
if ((net->dest_state & SCTP_ADDR_NOHB) &&
|
|
|
|
!(net->dest_state & SCTP_ADDR_UNCONFIRMED)) {
|
2007-05-09 13:30:06 +00:00
|
|
|
return;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2011-08-03 20:21:00 +00:00
|
|
|
if (net->RTO == 0) {
|
|
|
|
to_ticks = stcb->asoc.initial_rto;
|
2006-11-03 15:23:16 +00:00
|
|
|
} else {
|
2011-08-03 20:21:00 +00:00
|
|
|
to_ticks = net->RTO;
|
|
|
|
}
|
|
|
|
rndval = sctp_select_initial_TSN(&inp->sctp_ep);
|
|
|
|
jitter = rndval % to_ticks;
|
|
|
|
if (jitter >= (to_ticks >> 1)) {
|
|
|
|
to_ticks = to_ticks + (jitter - (to_ticks >> 1));
|
|
|
|
} else {
|
|
|
|
to_ticks = to_ticks - jitter;
|
|
|
|
}
|
|
|
|
if (!(net->dest_state & SCTP_ADDR_UNCONFIRMED) &&
|
|
|
|
!(net->dest_state & SCTP_ADDR_PF)) {
|
|
|
|
to_ticks += net->heart_beat_delay;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Now we must convert the to_ticks that are now in
|
|
|
|
* ms to ticks.
|
|
|
|
*/
|
|
|
|
to_ticks = MSEC_TO_TICKS(to_ticks);
|
2011-08-03 20:21:00 +00:00
|
|
|
tmr = &net->hb_timer;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCTP_TIMER_TYPE_COOKIE:
|
|
|
|
/*
|
|
|
|
* Here we can use the RTO timer from the network since one
|
|
|
|
* RTT was compelete. If a retran happened then we will be
|
|
|
|
* using the RTO initial value.
|
|
|
|
*/
|
|
|
|
if ((stcb == NULL) || (net == NULL)) {
|
2007-05-09 13:30:06 +00:00
|
|
|
return;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
if (net->RTO == 0) {
|
|
|
|
to_ticks = MSEC_TO_TICKS(stcb->asoc.initial_rto);
|
|
|
|
} else {
|
|
|
|
to_ticks = MSEC_TO_TICKS(net->RTO);
|
|
|
|
}
|
|
|
|
tmr = &net->rxt_timer;
|
|
|
|
break;
|
|
|
|
case SCTP_TIMER_TYPE_NEWCOOKIE:
|
|
|
|
/*
|
|
|
|
* nothing needed but the endpoint here ususually about 60
|
|
|
|
* minutes.
|
|
|
|
*/
|
|
|
|
tmr = &inp->sctp_ep.signature_change;
|
|
|
|
to_ticks = inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_SIGNATURE];
|
|
|
|
break;
|
|
|
|
case SCTP_TIMER_TYPE_ASOCKILL:
|
|
|
|
if (stcb == NULL) {
|
2007-05-09 13:30:06 +00:00
|
|
|
return;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
tmr = &stcb->asoc.strreset_timer;
|
|
|
|
to_ticks = MSEC_TO_TICKS(SCTP_ASOC_KILL_TIMEOUT);
|
|
|
|
break;
|
|
|
|
case SCTP_TIMER_TYPE_INPKILL:
|
|
|
|
/*
|
|
|
|
* The inp is setup to die. We re-use the signature_chage
|
|
|
|
* timer since that has stopped and we are in the GONE
|
|
|
|
* state.
|
|
|
|
*/
|
|
|
|
tmr = &inp->sctp_ep.signature_change;
|
|
|
|
to_ticks = MSEC_TO_TICKS(SCTP_INP_KILL_TIMEOUT);
|
|
|
|
break;
|
|
|
|
case SCTP_TIMER_TYPE_PATHMTURAISE:
|
|
|
|
/*
|
|
|
|
* Here we use the value found in the EP for PMTU ususually
|
|
|
|
* about 10 minutes.
|
|
|
|
*/
|
2014-12-21 13:58:53 +00:00
|
|
|
if ((stcb == NULL) || (net == NULL)) {
|
2007-05-09 13:30:06 +00:00
|
|
|
return;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2011-09-17 08:50:29 +00:00
|
|
|
if (net->dest_state & SCTP_ADDR_NO_PMTUD) {
|
|
|
|
return;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
to_ticks = inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_PMTU];
|
|
|
|
tmr = &net->pmtu_timer;
|
|
|
|
break;
|
|
|
|
case SCTP_TIMER_TYPE_SHUTDOWNACK:
|
|
|
|
/* Here we use the RTO of the destination */
|
|
|
|
if ((stcb == NULL) || (net == NULL)) {
|
2007-05-09 13:30:06 +00:00
|
|
|
return;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
if (net->RTO == 0) {
|
|
|
|
to_ticks = MSEC_TO_TICKS(stcb->asoc.initial_rto);
|
|
|
|
} else {
|
|
|
|
to_ticks = MSEC_TO_TICKS(net->RTO);
|
|
|
|
}
|
|
|
|
tmr = &net->rxt_timer;
|
|
|
|
break;
|
|
|
|
case SCTP_TIMER_TYPE_SHUTDOWNGUARD:
|
|
|
|
/*
|
|
|
|
* Here we use the endpoints shutdown guard timer usually
|
|
|
|
* about 3 minutes.
|
|
|
|
*/
|
2014-12-21 13:58:53 +00:00
|
|
|
if (stcb == NULL) {
|
2007-05-09 13:30:06 +00:00
|
|
|
return;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2015-08-29 17:26:29 +00:00
|
|
|
if (inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_MAXSHUTDOWN] == 0) {
|
|
|
|
to_ticks = 5 * MSEC_TO_TICKS(stcb->asoc.maxrto);
|
|
|
|
} else {
|
|
|
|
to_ticks = inp->sctp_ep.sctp_timeoutticks[SCTP_TIMER_MAXSHUTDOWN];
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
tmr = &stcb->asoc.shut_guard_timer;
|
|
|
|
break;
|
|
|
|
case SCTP_TIMER_TYPE_STRRESET:
|
|
|
|
/*
|
2007-07-24 20:06:02 +00:00
|
|
|
* Here the timer comes from the stcb but its value is from
|
|
|
|
* the net's RTO.
|
2006-11-03 15:23:16 +00:00
|
|
|
*/
|
|
|
|
if ((stcb == NULL) || (net == NULL)) {
|
2007-05-09 13:30:06 +00:00
|
|
|
return;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
if (net->RTO == 0) {
|
|
|
|
to_ticks = MSEC_TO_TICKS(stcb->asoc.initial_rto);
|
|
|
|
} else {
|
|
|
|
to_ticks = MSEC_TO_TICKS(net->RTO);
|
|
|
|
}
|
|
|
|
tmr = &stcb->asoc.strreset_timer;
|
|
|
|
break;
|
|
|
|
case SCTP_TIMER_TYPE_ASCONF:
|
|
|
|
/*
|
2007-07-24 20:06:02 +00:00
|
|
|
* Here the timer comes from the stcb but its value is from
|
|
|
|
* the net's RTO.
|
2006-11-03 15:23:16 +00:00
|
|
|
*/
|
|
|
|
if ((stcb == NULL) || (net == NULL)) {
|
2007-05-09 13:30:06 +00:00
|
|
|
return;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
if (net->RTO == 0) {
|
|
|
|
to_ticks = MSEC_TO_TICKS(stcb->asoc.initial_rto);
|
|
|
|
} else {
|
|
|
|
to_ticks = MSEC_TO_TICKS(net->RTO);
|
|
|
|
}
|
|
|
|
tmr = &stcb->asoc.asconf_timer;
|
|
|
|
break;
|
2007-09-08 17:48:46 +00:00
|
|
|
case SCTP_TIMER_TYPE_PRIM_DELETED:
|
|
|
|
if ((stcb == NULL) || (net != NULL)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
to_ticks = MSEC_TO_TICKS(stcb->asoc.initial_rto);
|
|
|
|
tmr = &stcb->asoc.delete_prim_timer;
|
|
|
|
break;
|
2006-11-03 15:23:16 +00:00
|
|
|
case SCTP_TIMER_TYPE_AUTOCLOSE:
|
|
|
|
if (stcb == NULL) {
|
2007-05-09 13:30:06 +00:00
|
|
|
return;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
if (stcb->asoc.sctp_autoclose_ticks == 0) {
|
|
|
|
/*
|
|
|
|
* Really an error since stcb is NOT set to
|
|
|
|
* autoclose
|
|
|
|
*/
|
2007-05-09 13:30:06 +00:00
|
|
|
return;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
to_ticks = stcb->asoc.sctp_autoclose_ticks;
|
|
|
|
tmr = &stcb->asoc.autoclose_timer;
|
|
|
|
break;
|
|
|
|
default:
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTPDBG(SCTP_DEBUG_TIMER1, "%s: Unknown timer type %d\n",
|
2015-10-19 11:17:54 +00:00
|
|
|
__func__, t_type);
|
2007-05-09 13:30:06 +00:00
|
|
|
return;
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
2011-12-27 10:16:24 +00:00
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
if ((to_ticks <= 0) || (tmr == NULL)) {
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTPDBG(SCTP_DEBUG_TIMER1, "%s: %d:software error to_ticks:%d tmr:%p not set ??\n",
|
2015-10-19 11:17:54 +00:00
|
|
|
__func__, t_type, to_ticks, (void *)tmr);
|
2007-05-09 13:30:06 +00:00
|
|
|
return;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2006-12-29 20:21:42 +00:00
|
|
|
if (SCTP_OS_TIMER_PENDING(&tmr->timer)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/*
|
|
|
|
* we do NOT allow you to have it already running. if it is
|
|
|
|
* we leave the current one up unchanged
|
|
|
|
*/
|
2007-05-09 13:30:06 +00:00
|
|
|
return;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
/* At this point we can proceed */
|
|
|
|
if (t_type == SCTP_TIMER_TYPE_SEND) {
|
|
|
|
stcb->asoc.num_send_timers_up++;
|
|
|
|
}
|
2006-12-14 17:02:55 +00:00
|
|
|
tmr->stopped_from = 0;
|
2006-11-03 15:23:16 +00:00
|
|
|
tmr->type = t_type;
|
|
|
|
tmr->ep = (void *)inp;
|
|
|
|
tmr->tcb = (void *)stcb;
|
|
|
|
tmr->net = (void *)net;
|
|
|
|
tmr->self = (void *)tmr;
|
2009-09-19 14:02:16 +00:00
|
|
|
tmr->vnet = (void *)curvnet;
|
2007-08-24 00:53:53 +00:00
|
|
|
tmr->ticks = sctp_get_tick_count();
|
2007-05-09 13:30:06 +00:00
|
|
|
(void)SCTP_OS_TIMER_START(&tmr->timer, to_ticks, sctp_timeout_handler, tmr);
|
|
|
|
return;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
2007-05-08 14:32:53 +00:00
|
|
|
void
|
2006-11-03 15:23:16 +00:00
|
|
|
sctp_timer_stop(int t_type, struct sctp_inpcb *inp, struct sctp_tcb *stcb,
|
2006-12-14 17:02:55 +00:00
|
|
|
struct sctp_nets *net, uint32_t from)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
|
|
|
struct sctp_timer *tmr;
|
|
|
|
|
|
|
|
if ((t_type != SCTP_TIMER_TYPE_ADDR_WQ) &&
|
|
|
|
(inp == NULL))
|
2007-05-08 14:32:53 +00:00
|
|
|
return;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
tmr = NULL;
|
|
|
|
if (stcb) {
|
|
|
|
SCTP_TCB_LOCK_ASSERT(stcb);
|
|
|
|
}
|
|
|
|
switch (t_type) {
|
|
|
|
case SCTP_TIMER_TYPE_ADDR_WQ:
|
2008-06-14 07:58:05 +00:00
|
|
|
tmr = &SCTP_BASE_INFO(addr_wq_timer);
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
|
|
|
case SCTP_TIMER_TYPE_SEND:
|
|
|
|
if ((stcb == NULL) || (net == NULL)) {
|
2007-05-08 14:32:53 +00:00
|
|
|
return;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
tmr = &net->rxt_timer;
|
|
|
|
break;
|
|
|
|
case SCTP_TIMER_TYPE_INIT:
|
|
|
|
if ((stcb == NULL) || (net == NULL)) {
|
2007-05-08 14:32:53 +00:00
|
|
|
return;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
tmr = &net->rxt_timer;
|
|
|
|
break;
|
|
|
|
case SCTP_TIMER_TYPE_RECV:
|
|
|
|
if (stcb == NULL) {
|
2007-05-08 14:32:53 +00:00
|
|
|
return;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
tmr = &stcb->asoc.dack_timer;
|
|
|
|
break;
|
|
|
|
case SCTP_TIMER_TYPE_SHUTDOWN:
|
|
|
|
if ((stcb == NULL) || (net == NULL)) {
|
2007-05-08 14:32:53 +00:00
|
|
|
return;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
tmr = &net->rxt_timer;
|
|
|
|
break;
|
|
|
|
case SCTP_TIMER_TYPE_HEARTBEAT:
|
2011-08-03 20:21:00 +00:00
|
|
|
if ((stcb == NULL) || (net == NULL)) {
|
2007-05-08 14:32:53 +00:00
|
|
|
return;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2011-08-03 20:21:00 +00:00
|
|
|
tmr = &net->hb_timer;
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
|
|
|
case SCTP_TIMER_TYPE_COOKIE:
|
|
|
|
if ((stcb == NULL) || (net == NULL)) {
|
2007-05-08 14:32:53 +00:00
|
|
|
return;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
tmr = &net->rxt_timer;
|
|
|
|
break;
|
|
|
|
case SCTP_TIMER_TYPE_NEWCOOKIE:
|
|
|
|
/* nothing needed but the endpoint here */
|
|
|
|
tmr = &inp->sctp_ep.signature_change;
|
|
|
|
/*
|
|
|
|
* We re-use the newcookie timer for the INP kill timer. We
|
|
|
|
* must assure that we do not kill it by accident.
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
case SCTP_TIMER_TYPE_ASOCKILL:
|
|
|
|
/*
|
|
|
|
* Stop the asoc kill timer.
|
|
|
|
*/
|
|
|
|
if (stcb == NULL) {
|
2007-05-08 14:32:53 +00:00
|
|
|
return;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
tmr = &stcb->asoc.strreset_timer;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCTP_TIMER_TYPE_INPKILL:
|
|
|
|
/*
|
|
|
|
* The inp is setup to die. We re-use the signature_chage
|
|
|
|
* timer since that has stopped and we are in the GONE
|
|
|
|
* state.
|
|
|
|
*/
|
|
|
|
tmr = &inp->sctp_ep.signature_change;
|
|
|
|
break;
|
|
|
|
case SCTP_TIMER_TYPE_PATHMTURAISE:
|
|
|
|
if ((stcb == NULL) || (net == NULL)) {
|
2007-05-08 14:32:53 +00:00
|
|
|
return;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
tmr = &net->pmtu_timer;
|
|
|
|
break;
|
|
|
|
case SCTP_TIMER_TYPE_SHUTDOWNACK:
|
|
|
|
if ((stcb == NULL) || (net == NULL)) {
|
2007-05-08 14:32:53 +00:00
|
|
|
return;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
tmr = &net->rxt_timer;
|
|
|
|
break;
|
|
|
|
case SCTP_TIMER_TYPE_SHUTDOWNGUARD:
|
|
|
|
if (stcb == NULL) {
|
2007-05-08 14:32:53 +00:00
|
|
|
return;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
tmr = &stcb->asoc.shut_guard_timer;
|
|
|
|
break;
|
|
|
|
case SCTP_TIMER_TYPE_STRRESET:
|
|
|
|
if (stcb == NULL) {
|
2007-05-08 14:32:53 +00:00
|
|
|
return;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
tmr = &stcb->asoc.strreset_timer;
|
|
|
|
break;
|
|
|
|
case SCTP_TIMER_TYPE_ASCONF:
|
|
|
|
if (stcb == NULL) {
|
2007-05-08 14:32:53 +00:00
|
|
|
return;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
tmr = &stcb->asoc.asconf_timer;
|
|
|
|
break;
|
2007-09-08 17:48:46 +00:00
|
|
|
case SCTP_TIMER_TYPE_PRIM_DELETED:
|
|
|
|
if (stcb == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
tmr = &stcb->asoc.delete_prim_timer;
|
|
|
|
break;
|
2006-11-03 15:23:16 +00:00
|
|
|
case SCTP_TIMER_TYPE_AUTOCLOSE:
|
|
|
|
if (stcb == NULL) {
|
2007-05-08 14:32:53 +00:00
|
|
|
return;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
tmr = &stcb->asoc.autoclose_timer;
|
|
|
|
break;
|
|
|
|
default:
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTPDBG(SCTP_DEBUG_TIMER1, "%s: Unknown timer type %d\n",
|
2015-10-19 11:17:54 +00:00
|
|
|
__func__, t_type);
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
2011-12-27 10:16:24 +00:00
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
if (tmr == NULL) {
|
2007-05-08 14:32:53 +00:00
|
|
|
return;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
if ((tmr->type != t_type) && tmr->type) {
|
|
|
|
/*
|
|
|
|
* Ok we have a timer that is under joint use. Cookie timer
|
|
|
|
* per chance with the SEND timer. We therefore are NOT
|
|
|
|
* running the timer that the caller wants stopped. So just
|
|
|
|
* return.
|
|
|
|
*/
|
2007-05-08 14:32:53 +00:00
|
|
|
return;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2007-05-09 13:30:06 +00:00
|
|
|
if ((t_type == SCTP_TIMER_TYPE_SEND) && (stcb != NULL)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
stcb->asoc.num_send_timers_up--;
|
|
|
|
if (stcb->asoc.num_send_timers_up < 0) {
|
|
|
|
stcb->asoc.num_send_timers_up = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tmr->self = NULL;
|
2006-12-14 17:02:55 +00:00
|
|
|
tmr->stopped_from = from;
|
2007-05-08 14:32:53 +00:00
|
|
|
(void)SCTP_OS_TIMER_STOP(&tmr->timer);
|
|
|
|
return;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
2018-07-19 20:11:14 +00:00
|
|
|
sctp_calculate_len(struct mbuf *m)
|
|
|
|
{
|
2006-11-03 15:23:16 +00:00
|
|
|
uint32_t tlen = 0;
|
|
|
|
struct mbuf *at;
|
|
|
|
|
|
|
|
at = m;
|
|
|
|
while (at) {
|
2006-12-29 20:21:42 +00:00
|
|
|
tlen += SCTP_BUF_LEN(at);
|
|
|
|
at = SCTP_BUF_NEXT(at);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
return (tlen);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sctp_mtu_size_reset(struct sctp_inpcb *inp,
|
2007-01-15 15:12:10 +00:00
|
|
|
struct sctp_association *asoc, uint32_t mtu)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Reset the P-MTU size on this association, this involves changing
|
|
|
|
* the asoc MTU, going through ANY chunk+overhead larger than mtu to
|
|
|
|
* allow the DF flag to be cleared.
|
|
|
|
*/
|
|
|
|
struct sctp_tmit_chunk *chk;
|
|
|
|
unsigned int eff_mtu, ovh;
|
|
|
|
|
|
|
|
asoc->smallest_mtu = mtu;
|
|
|
|
if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) {
|
|
|
|
ovh = SCTP_MIN_OVERHEAD;
|
|
|
|
} else {
|
|
|
|
ovh = SCTP_MIN_V4_OVERHEAD;
|
|
|
|
}
|
|
|
|
eff_mtu = mtu - ovh;
|
|
|
|
TAILQ_FOREACH(chk, &asoc->send_queue, sctp_next) {
|
|
|
|
if (chk->send_size > eff_mtu) {
|
|
|
|
chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TAILQ_FOREACH(chk, &asoc->sent_queue, sctp_next) {
|
|
|
|
if (chk->send_size > eff_mtu) {
|
|
|
|
chk->flags |= CHUNK_FLAGS_FRAGMENT_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* given an association and starting time of the current RTT period return
|
2007-02-12 23:24:31 +00:00
|
|
|
* RTO in number of msecs net should point to the current network
|
2006-11-03 15:23:16 +00:00
|
|
|
*/
|
2011-02-02 11:13:23 +00:00
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
uint32_t
|
|
|
|
sctp_calculate_rto(struct sctp_tcb *stcb,
|
|
|
|
struct sctp_association *asoc,
|
|
|
|
struct sctp_nets *net,
|
2017-10-14 10:02:59 +00:00
|
|
|
struct timeval *old,
|
2018-07-19 20:11:14 +00:00
|
|
|
int rtt_from_sack)
|
|
|
|
{
|
2007-07-17 20:58:26 +00:00
|
|
|
/*-
|
2006-11-03 15:23:16 +00:00
|
|
|
* given an association and the starting time of the current RTT
|
2007-02-12 23:24:31 +00:00
|
|
|
* period (in value1/value2) return RTO in number of msecs.
|
2006-11-03 15:23:16 +00:00
|
|
|
*/
|
2011-02-24 22:36:40 +00:00
|
|
|
int32_t rtt; /* RTT in ms */
|
|
|
|
uint32_t new_rto;
|
2006-11-03 15:23:16 +00:00
|
|
|
int first_measure = 0;
|
2017-10-14 10:02:59 +00:00
|
|
|
struct timeval now;
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
/************************/
|
|
|
|
/* 1. calculate new RTT */
|
|
|
|
/************************/
|
|
|
|
/* get the current time */
|
2011-02-26 15:23:46 +00:00
|
|
|
if (stcb->asoc.use_precise_time) {
|
|
|
|
(void)SCTP_GETPTIME_TIMEVAL(&now);
|
|
|
|
} else {
|
|
|
|
(void)SCTP_GETTIME_TIMEVAL(&now);
|
|
|
|
}
|
2011-02-24 22:36:40 +00:00
|
|
|
timevalsub(&now, old);
|
|
|
|
/* store the current RTT in us */
|
2018-07-19 20:16:33 +00:00
|
|
|
net->rtt = (uint64_t)1000000 * (uint64_t)now.tv_sec +
|
|
|
|
(uint64_t)now.tv_usec;
|
2014-09-16 14:39:24 +00:00
|
|
|
/* compute rtt in ms */
|
2018-07-19 20:11:14 +00:00
|
|
|
rtt = (int32_t)(net->rtt / 1000);
|
2011-03-08 11:58:25 +00:00
|
|
|
if ((asoc->cc_functions.sctp_rtt_calculated) && (rtt_from_sack == SCTP_RTT_FROM_DATA)) {
|
2016-12-26 11:06:41 +00:00
|
|
|
/*
|
|
|
|
* Tell the CC module that a new update has just occurred
|
|
|
|
* from a sack
|
|
|
|
*/
|
2011-03-08 11:58:25 +00:00
|
|
|
(*asoc->cc_functions.sctp_rtt_calculated) (stcb, net, &now);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Do we need to determine the lan? We do this only on sacks i.e.
|
|
|
|
* RTT being determined from data not non-data (HB/INIT->INITACK).
|
|
|
|
*/
|
|
|
|
if ((rtt_from_sack == SCTP_RTT_FROM_DATA) &&
|
2011-02-24 22:36:40 +00:00
|
|
|
(net->lan_type == SCTP_LAN_UNKNOWN)) {
|
|
|
|
if (net->rtt > SCTP_LOCAL_LAN_RTT) {
|
2011-02-02 11:13:23 +00:00
|
|
|
net->lan_type = SCTP_LAN_INTERNET;
|
|
|
|
} else {
|
|
|
|
net->lan_type = SCTP_LAN_LOCAL;
|
|
|
|
}
|
|
|
|
}
|
2018-07-19 20:16:33 +00:00
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
/***************************/
|
|
|
|
/* 2. update RTTVAR & SRTT */
|
|
|
|
/***************************/
|
2011-02-24 22:36:40 +00:00
|
|
|
/*-
|
|
|
|
* Compute the scaled average lastsa and the
|
|
|
|
* scaled variance lastsv as described in van Jacobson
|
|
|
|
* Paper "Congestion Avoidance and Control", Annex A.
|
|
|
|
*
|
|
|
|
* (net->lastsa >> SCTP_RTT_SHIFT) is the srtt
|
|
|
|
* (net->lastsa >> SCTP_RTT_VAR_SHIFT) is the rttvar
|
|
|
|
*/
|
2007-06-13 01:31:53 +00:00
|
|
|
if (net->RTO_measured) {
|
2011-02-24 22:36:40 +00:00
|
|
|
rtt -= (net->lastsa >> SCTP_RTT_SHIFT);
|
|
|
|
net->lastsa += rtt;
|
|
|
|
if (rtt < 0) {
|
|
|
|
rtt = -rtt;
|
|
|
|
}
|
|
|
|
rtt -= (net->lastsv >> SCTP_RTT_VAR_SHIFT);
|
|
|
|
net->lastsv += rtt;
|
2008-06-14 07:58:05 +00:00
|
|
|
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_RTTVAR_LOGGING_ENABLE) {
|
2007-06-14 22:59:04 +00:00
|
|
|
rto_logging(net, SCTP_LOG_RTTVAR);
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
} else {
|
|
|
|
/* First RTO measurment */
|
2007-06-13 01:31:53 +00:00
|
|
|
net->RTO_measured = 1;
|
2006-11-03 15:23:16 +00:00
|
|
|
first_measure = 1;
|
2011-02-24 22:36:40 +00:00
|
|
|
net->lastsa = rtt << SCTP_RTT_SHIFT;
|
|
|
|
net->lastsv = (rtt / 2) << SCTP_RTT_VAR_SHIFT;
|
2008-06-14 07:58:05 +00:00
|
|
|
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_RTTVAR_LOGGING_ENABLE) {
|
2007-06-14 22:59:04 +00:00
|
|
|
rto_logging(net, SCTP_LOG_INITIAL_RTT);
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2011-02-24 22:36:40 +00:00
|
|
|
if (net->lastsv == 0) {
|
|
|
|
net->lastsv = SCTP_CLOCK_GRANULARITY;
|
|
|
|
}
|
2007-06-08 10:57:11 +00:00
|
|
|
new_rto = (net->lastsa >> SCTP_RTT_SHIFT) + net->lastsv;
|
2006-11-03 15:23:16 +00:00
|
|
|
if ((new_rto > SCTP_SAT_NETWORK_MIN) &&
|
|
|
|
(stcb->asoc.sat_network_lockout == 0)) {
|
|
|
|
stcb->asoc.sat_network = 1;
|
|
|
|
} else if ((!first_measure) && stcb->asoc.sat_network) {
|
|
|
|
stcb->asoc.sat_network = 0;
|
|
|
|
stcb->asoc.sat_network_lockout = 1;
|
|
|
|
}
|
|
|
|
/* bound it, per C6/C7 in Section 5.3.1 */
|
|
|
|
if (new_rto < stcb->asoc.minrto) {
|
|
|
|
new_rto = stcb->asoc.minrto;
|
|
|
|
}
|
|
|
|
if (new_rto > stcb->asoc.maxrto) {
|
|
|
|
new_rto = stcb->asoc.maxrto;
|
|
|
|
}
|
2007-03-31 11:47:30 +00:00
|
|
|
/* we are now returning the RTO */
|
|
|
|
return (new_rto);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* return a pointer to a contiguous piece of data from the given mbuf chain
|
|
|
|
* starting at 'off' for 'len' bytes. If the desired piece spans more than
|
|
|
|
* one mbuf, a copy is made at 'ptr'. caller must ensure that the buffer size
|
|
|
|
* is >= 'len' returns NULL if there there isn't 'len' bytes in the chain.
|
|
|
|
*/
|
2007-06-16 00:33:47 +00:00
|
|
|
caddr_t
|
2018-07-19 20:11:14 +00:00
|
|
|
sctp_m_getptr(struct mbuf *m, int off, int len, uint8_t *in_ptr)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
|
|
|
uint32_t count;
|
|
|
|
uint8_t *ptr;
|
|
|
|
|
|
|
|
ptr = in_ptr;
|
|
|
|
if ((off < 0) || (len <= 0))
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
/* find the desired start location */
|
|
|
|
while ((m != NULL) && (off > 0)) {
|
2006-12-29 20:21:42 +00:00
|
|
|
if (off < SCTP_BUF_LEN(m))
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
2006-12-29 20:21:42 +00:00
|
|
|
off -= SCTP_BUF_LEN(m);
|
|
|
|
m = SCTP_BUF_NEXT(m);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
if (m == NULL)
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
/* is the current mbuf large enough (eg. contiguous)? */
|
2006-12-29 20:21:42 +00:00
|
|
|
if ((SCTP_BUF_LEN(m) - off) >= len) {
|
2006-11-03 15:23:16 +00:00
|
|
|
return (mtod(m, caddr_t)+off);
|
|
|
|
} else {
|
|
|
|
/* else, it spans more than one mbuf, so save a temp copy... */
|
|
|
|
while ((m != NULL) && (len > 0)) {
|
2006-12-29 20:21:42 +00:00
|
|
|
count = min(SCTP_BUF_LEN(m) - off, len);
|
2017-07-19 14:28:58 +00:00
|
|
|
memcpy(ptr, mtod(m, caddr_t)+off, count);
|
2006-11-03 15:23:16 +00:00
|
|
|
len -= count;
|
|
|
|
ptr += count;
|
|
|
|
off = 0;
|
2006-12-29 20:21:42 +00:00
|
|
|
m = SCTP_BUF_NEXT(m);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
if ((m == NULL) && (len > 0))
|
|
|
|
return (NULL);
|
|
|
|
else
|
|
|
|
return ((caddr_t)in_ptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-15 15:12:10 +00:00
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
struct sctp_paramhdr *
|
|
|
|
sctp_get_next_param(struct mbuf *m,
|
|
|
|
int offset,
|
|
|
|
struct sctp_paramhdr *pull,
|
|
|
|
int pull_limit)
|
|
|
|
{
|
|
|
|
/* This just provides a typed signature to Peter's Pull routine */
|
|
|
|
return ((struct sctp_paramhdr *)sctp_m_getptr(m, offset, pull_limit,
|
2018-07-19 20:11:14 +00:00
|
|
|
(uint8_t *)pull));
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-01 12:42:37 +00:00
|
|
|
struct mbuf *
|
2006-11-03 15:23:16 +00:00
|
|
|
sctp_add_pad_tombuf(struct mbuf *m, int padlen)
|
|
|
|
{
|
2014-08-01 12:42:37 +00:00
|
|
|
struct mbuf *m_last;
|
|
|
|
caddr_t dp;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
if (padlen > 3) {
|
2014-08-01 12:42:37 +00:00
|
|
|
return (NULL);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2007-12-07 01:32:14 +00:00
|
|
|
if (padlen <= M_TRAILINGSPACE(m)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/*
|
|
|
|
* The easy way. We hope the majority of the time we hit
|
|
|
|
* here :)
|
|
|
|
*/
|
2014-08-01 12:42:37 +00:00
|
|
|
m_last = m;
|
2006-11-03 15:23:16 +00:00
|
|
|
} else {
|
2014-08-01 12:42:37 +00:00
|
|
|
/* Hard way we must grow the mbuf chain */
|
|
|
|
m_last = sctp_get_mbuf_for_msg(padlen, 0, M_NOWAIT, 1, MT_DATA);
|
|
|
|
if (m_last == NULL) {
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
SCTP_BUF_LEN(m_last) = 0;
|
|
|
|
SCTP_BUF_NEXT(m_last) = NULL;
|
|
|
|
SCTP_BUF_NEXT(m) = m_last;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2014-08-01 12:42:37 +00:00
|
|
|
dp = mtod(m_last, caddr_t)+SCTP_BUF_LEN(m_last);
|
|
|
|
SCTP_BUF_LEN(m_last) += padlen;
|
|
|
|
memset(dp, 0, padlen);
|
|
|
|
return (m_last);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
2014-08-01 12:42:37 +00:00
|
|
|
struct mbuf *
|
2006-11-03 15:23:16 +00:00
|
|
|
sctp_pad_lastmbuf(struct mbuf *m, int padval, struct mbuf *last_mbuf)
|
|
|
|
{
|
|
|
|
/* find the last mbuf in chain and pad it */
|
|
|
|
struct mbuf *m_at;
|
|
|
|
|
2014-08-01 12:42:37 +00:00
|
|
|
if (last_mbuf != NULL) {
|
2006-11-03 15:23:16 +00:00
|
|
|
return (sctp_add_pad_tombuf(last_mbuf, padval));
|
|
|
|
} else {
|
2012-06-12 09:18:28 +00:00
|
|
|
for (m_at = m; m_at; m_at = SCTP_BUF_NEXT(m_at)) {
|
2006-12-29 20:21:42 +00:00
|
|
|
if (SCTP_BUF_NEXT(m_at) == NULL) {
|
2006-11-03 15:23:16 +00:00
|
|
|
return (sctp_add_pad_tombuf(m_at, padval));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-08-01 12:42:37 +00:00
|
|
|
return (NULL);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-05-11 18:07:36 +00:00
|
|
|
sctp_notify_assoc_change(uint16_t state, struct sctp_tcb *stcb,
|
2012-05-13 16:56:16 +00:00
|
|
|
uint16_t error, struct sctp_abort_chunk *abort, uint8_t from_peer, int so_locked
|
2007-09-08 11:35:11 +00:00
|
|
|
#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
|
|
|
|
SCTP_UNUSED
|
|
|
|
#endif
|
|
|
|
)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
|
|
|
struct mbuf *m_notify;
|
|
|
|
struct sctp_assoc_change *sac;
|
|
|
|
struct sctp_queued_to_read *control;
|
2016-03-27 10:04:25 +00:00
|
|
|
unsigned int notif_len;
|
|
|
|
uint16_t abort_len;
|
2012-05-06 13:09:13 +00:00
|
|
|
unsigned int i;
|
2012-06-25 17:15:09 +00:00
|
|
|
#if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
|
2007-09-08 11:35:11 +00:00
|
|
|
struct socket *so;
|
|
|
|
#endif
|
|
|
|
|
2015-09-04 09:22:16 +00:00
|
|
|
if (stcb == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
2012-05-13 16:07:53 +00:00
|
|
|
if (sctp_stcb_is_feature_on(stcb->sctp_ep, stcb, SCTP_PCB_FLAGS_RECVASSOCEVNT)) {
|
2016-03-27 10:04:25 +00:00
|
|
|
notif_len = (unsigned int)sizeof(struct sctp_assoc_change);
|
2012-05-13 16:07:53 +00:00
|
|
|
if (abort != NULL) {
|
2013-11-07 16:37:12 +00:00
|
|
|
abort_len = ntohs(abort->ch.chunk_length);
|
2018-05-08 18:48:51 +00:00
|
|
|
/*
|
|
|
|
* Only SCTP_CHUNK_BUFFER_SIZE are guaranteed to be
|
2018-05-08 20:39:35 +00:00
|
|
|
* contiguous.
|
2018-05-08 18:48:51 +00:00
|
|
|
*/
|
|
|
|
if (abort_len > SCTP_CHUNK_BUFFER_SIZE) {
|
|
|
|
abort_len = SCTP_CHUNK_BUFFER_SIZE;
|
|
|
|
}
|
2012-05-13 16:07:53 +00:00
|
|
|
} else {
|
|
|
|
abort_len = 0;
|
|
|
|
}
|
|
|
|
if ((state == SCTP_COMM_UP) || (state == SCTP_RESTART)) {
|
|
|
|
notif_len += SCTP_ASSOC_SUPPORTS_MAX;
|
|
|
|
} else if ((state == SCTP_COMM_LOST) || (state == SCTP_CANT_STR_ASSOC)) {
|
|
|
|
notif_len += abort_len;
|
|
|
|
}
|
2012-12-05 08:04:20 +00:00
|
|
|
m_notify = sctp_get_mbuf_for_msg(notif_len, 0, M_NOWAIT, 1, MT_DATA);
|
2012-05-13 16:07:53 +00:00
|
|
|
if (m_notify == NULL) {
|
|
|
|
/* Retry with smaller value. */
|
2016-03-27 10:04:25 +00:00
|
|
|
notif_len = (unsigned int)sizeof(struct sctp_assoc_change);
|
2012-12-05 08:04:20 +00:00
|
|
|
m_notify = sctp_get_mbuf_for_msg(notif_len, 0, M_NOWAIT, 1, MT_DATA);
|
2012-05-13 16:07:53 +00:00
|
|
|
if (m_notify == NULL) {
|
|
|
|
goto set_error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SCTP_BUF_NEXT(m_notify) = NULL;
|
|
|
|
sac = mtod(m_notify, struct sctp_assoc_change *);
|
2014-07-08 21:54:27 +00:00
|
|
|
memset(sac, 0, notif_len);
|
2012-05-13 16:07:53 +00:00
|
|
|
sac->sac_type = SCTP_ASSOC_CHANGE;
|
|
|
|
sac->sac_flags = 0;
|
|
|
|
sac->sac_length = sizeof(struct sctp_assoc_change);
|
|
|
|
sac->sac_state = state;
|
|
|
|
sac->sac_error = error;
|
|
|
|
/* XXX verify these stream counts */
|
|
|
|
sac->sac_outbound_streams = stcb->asoc.streamoutcnt;
|
|
|
|
sac->sac_inbound_streams = stcb->asoc.streamincnt;
|
|
|
|
sac->sac_assoc_id = sctp_get_associd(stcb);
|
|
|
|
if (notif_len > sizeof(struct sctp_assoc_change)) {
|
|
|
|
if ((state == SCTP_COMM_UP) || (state == SCTP_RESTART)) {
|
|
|
|
i = 0;
|
2014-08-12 11:30:16 +00:00
|
|
|
if (stcb->asoc.prsctp_supported == 1) {
|
2012-05-13 16:07:53 +00:00
|
|
|
sac->sac_info[i++] = SCTP_ASSOC_SUPPORTS_PR;
|
|
|
|
}
|
2014-08-12 11:30:16 +00:00
|
|
|
if (stcb->asoc.auth_supported == 1) {
|
2012-05-13 16:07:53 +00:00
|
|
|
sac->sac_info[i++] = SCTP_ASSOC_SUPPORTS_AUTH;
|
|
|
|
}
|
2014-08-12 11:30:16 +00:00
|
|
|
if (stcb->asoc.asconf_supported == 1) {
|
2012-05-13 16:07:53 +00:00
|
|
|
sac->sac_info[i++] = SCTP_ASSOC_SUPPORTS_ASCONF;
|
|
|
|
}
|
2016-04-07 09:10:34 +00:00
|
|
|
if (stcb->asoc.idata_supported == 1) {
|
|
|
|
sac->sac_info[i++] = SCTP_ASSOC_SUPPORTS_INTERLEAVING;
|
|
|
|
}
|
2012-05-13 16:07:53 +00:00
|
|
|
sac->sac_info[i++] = SCTP_ASSOC_SUPPORTS_MULTIBUF;
|
2014-08-12 11:30:16 +00:00
|
|
|
if (stcb->asoc.reconfig_supported == 1) {
|
2012-05-13 16:07:53 +00:00
|
|
|
sac->sac_info[i++] = SCTP_ASSOC_SUPPORTS_RE_CONFIG;
|
|
|
|
}
|
|
|
|
sac->sac_length += i;
|
|
|
|
} else if ((state == SCTP_COMM_LOST) || (state == SCTP_CANT_STR_ASSOC)) {
|
|
|
|
memcpy(sac->sac_info, abort, abort_len);
|
|
|
|
sac->sac_length += abort_len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SCTP_BUF_LEN(m_notify) = sac->sac_length;
|
|
|
|
control = sctp_build_readq_entry(stcb, stcb->asoc.primary_destination,
|
|
|
|
0, 0, stcb->asoc.context, 0, 0, 0,
|
|
|
|
m_notify);
|
|
|
|
if (control != NULL) {
|
|
|
|
control->length = SCTP_BUF_LEN(m_notify);
|
2017-07-19 12:27:40 +00:00
|
|
|
control->spec_flags = M_NOTIFICATION;
|
2012-05-13 16:07:53 +00:00
|
|
|
/* not that we need this */
|
|
|
|
control->tail_mbuf = m_notify;
|
|
|
|
sctp_add_to_readq(stcb->sctp_ep, stcb,
|
|
|
|
control,
|
|
|
|
&stcb->sctp_socket->so_rcv, 1, SCTP_READ_LOCK_NOT_HELD,
|
|
|
|
so_locked);
|
|
|
|
} else {
|
|
|
|
sctp_m_freem(m_notify);
|
|
|
|
}
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
/*
|
2012-05-13 16:07:53 +00:00
|
|
|
* For 1-to-1 style sockets, we send up and error when an ABORT
|
|
|
|
* comes in.
|
2006-11-03 15:23:16 +00:00
|
|
|
*/
|
2012-05-13 16:07:53 +00:00
|
|
|
set_error:
|
2006-11-03 15:23:16 +00:00
|
|
|
if (((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
|
|
|
|
(stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) &&
|
2012-05-11 18:07:36 +00:00
|
|
|
((state == SCTP_COMM_LOST) || (state == SCTP_CANT_STR_ASSOC))) {
|
2013-02-27 19:51:47 +00:00
|
|
|
SOCK_LOCK(stcb->sctp_socket);
|
2012-05-13 16:56:16 +00:00
|
|
|
if (from_peer) {
|
2018-08-13 13:58:45 +00:00
|
|
|
if (SCTP_GET_STATE(stcb) == SCTP_STATE_COOKIE_WAIT) {
|
2012-05-13 16:56:16 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(NULL, stcb, NULL, SCTP_FROM_SCTPUTIL, ECONNREFUSED);
|
|
|
|
stcb->sctp_socket->so_error = ECONNREFUSED;
|
|
|
|
} else {
|
|
|
|
SCTP_LTRACE_ERR_RET(NULL, stcb, NULL, SCTP_FROM_SCTPUTIL, ECONNRESET);
|
|
|
|
stcb->sctp_socket->so_error = ECONNRESET;
|
|
|
|
}
|
2007-08-24 00:53:53 +00:00
|
|
|
} else {
|
2018-08-13 13:58:45 +00:00
|
|
|
if ((SCTP_GET_STATE(stcb) == SCTP_STATE_COOKIE_WAIT) ||
|
|
|
|
(SCTP_GET_STATE(stcb) == SCTP_STATE_COOKIE_ECHOED)) {
|
2013-05-17 22:26:05 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(NULL, stcb, NULL, SCTP_FROM_SCTPUTIL, ETIMEDOUT);
|
|
|
|
stcb->sctp_socket->so_error = ETIMEDOUT;
|
|
|
|
} else {
|
|
|
|
SCTP_LTRACE_ERR_RET(NULL, stcb, NULL, SCTP_FROM_SCTPUTIL, ECONNABORTED);
|
|
|
|
stcb->sctp_socket->so_error = ECONNABORTED;
|
|
|
|
}
|
2007-08-24 00:53:53 +00:00
|
|
|
}
|
2017-06-08 06:37:11 +00:00
|
|
|
SOCK_UNLOCK(stcb->sctp_socket);
|
2012-05-13 16:07:53 +00:00
|
|
|
}
|
|
|
|
/* Wake ANY sleepers */
|
2012-06-25 17:15:09 +00:00
|
|
|
#if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
|
2012-05-13 16:07:53 +00:00
|
|
|
so = SCTP_INP_SO(stcb->sctp_ep);
|
|
|
|
if (!so_locked) {
|
|
|
|
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->asoc.state & SCTP_STATE_CLOSED_SOCKET) {
|
2007-09-08 11:35:11 +00:00
|
|
|
SCTP_SOCKET_UNLOCK(so, 1);
|
2012-05-12 20:11:35 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2007-09-08 11:35:11 +00:00
|
|
|
#endif
|
2012-05-13 16:07:53 +00:00
|
|
|
if (((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
|
|
|
|
(stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) &&
|
|
|
|
((state == SCTP_COMM_LOST) || (state == SCTP_CANT_STR_ASSOC))) {
|
2017-06-08 06:37:11 +00:00
|
|
|
socantrcvmore(stcb->sctp_socket);
|
2012-05-13 16:07:53 +00:00
|
|
|
}
|
|
|
|
sorwakeup(stcb->sctp_socket);
|
|
|
|
sowwakeup(stcb->sctp_socket);
|
2012-06-25 17:15:09 +00:00
|
|
|
#if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
|
2012-05-13 16:07:53 +00:00
|
|
|
if (!so_locked) {
|
|
|
|
SCTP_SOCKET_UNLOCK(so, 1);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2012-05-13 16:07:53 +00:00
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sctp_notify_peer_addr_change(struct sctp_tcb *stcb, uint32_t state,
|
2015-03-10 22:38:10 +00:00
|
|
|
struct sockaddr *sa, uint32_t error, int so_locked
|
|
|
|
#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
|
|
|
|
SCTP_UNUSED
|
|
|
|
#endif
|
|
|
|
)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
|
|
|
struct mbuf *m_notify;
|
|
|
|
struct sctp_paddr_change *spc;
|
|
|
|
struct sctp_queued_to_read *control;
|
|
|
|
|
2011-12-27 10:16:24 +00:00
|
|
|
if ((stcb == NULL) ||
|
|
|
|
sctp_stcb_is_feature_off(stcb->sctp_ep, stcb, SCTP_PCB_FLAGS_RECVPADDREVNT)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/* event not enabled */
|
|
|
|
return;
|
2008-12-06 13:19:54 +00:00
|
|
|
}
|
2012-12-05 08:04:20 +00:00
|
|
|
m_notify = sctp_get_mbuf_for_msg(sizeof(struct sctp_paddr_change), 0, M_NOWAIT, 1, MT_DATA);
|
2006-11-03 15:23:16 +00:00
|
|
|
if (m_notify == NULL)
|
|
|
|
return;
|
2006-12-29 20:21:42 +00:00
|
|
|
SCTP_BUF_LEN(m_notify) = 0;
|
2006-11-03 15:23:16 +00:00
|
|
|
spc = mtod(m_notify, struct sctp_paddr_change *);
|
2014-07-24 18:06:18 +00:00
|
|
|
memset(spc, 0, sizeof(struct sctp_paddr_change));
|
2006-11-03 15:23:16 +00:00
|
|
|
spc->spc_type = SCTP_PEER_ADDR_CHANGE;
|
|
|
|
spc->spc_flags = 0;
|
|
|
|
spc->spc_length = sizeof(struct sctp_paddr_change);
|
2008-04-16 17:24:18 +00:00
|
|
|
switch (sa->sa_family) {
|
2011-05-02 15:53:00 +00:00
|
|
|
#ifdef INET
|
2008-04-16 17:24:18 +00:00
|
|
|
case AF_INET:
|
2014-12-06 20:00:08 +00:00
|
|
|
#ifdef INET6
|
|
|
|
if (sctp_is_feature_on(stcb->sctp_ep, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
|
|
|
|
in6_sin_2_v4mapsin6((struct sockaddr_in *)sa,
|
|
|
|
(struct sockaddr_in6 *)&spc->spc_aaddr);
|
|
|
|
} else {
|
|
|
|
memcpy(&spc->spc_aaddr, sa, sizeof(struct sockaddr_in));
|
|
|
|
}
|
|
|
|
#else
|
2006-11-03 15:23:16 +00:00
|
|
|
memcpy(&spc->spc_aaddr, sa, sizeof(struct sockaddr_in));
|
2014-12-06 20:00:08 +00:00
|
|
|
#endif
|
2008-04-16 17:24:18 +00:00
|
|
|
break;
|
2011-05-02 15:53:00 +00:00
|
|
|
#endif
|
2008-04-16 17:24:18 +00:00
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6:
|
|
|
|
{
|
|
|
|
struct sockaddr_in6 *sin6;
|
2007-02-12 23:24:31 +00:00
|
|
|
|
2008-04-16 17:24:18 +00:00
|
|
|
memcpy(&spc->spc_aaddr, sa, sizeof(struct sockaddr_in6));
|
2007-02-12 23:24:31 +00:00
|
|
|
|
2008-04-16 17:24:18 +00:00
|
|
|
sin6 = (struct sockaddr_in6 *)&spc->spc_aaddr;
|
|
|
|
if (IN6_IS_SCOPE_LINKLOCAL(&sin6->sin6_addr)) {
|
|
|
|
if (sin6->sin6_scope_id == 0) {
|
|
|
|
/* recover scope_id for user */
|
|
|
|
(void)sa6_recoverscope(sin6);
|
|
|
|
} else {
|
|
|
|
/* clear embedded scope_id for user */
|
|
|
|
in6_clearscope(&sin6->sin6_addr);
|
|
|
|
}
|
2007-03-15 11:27:14 +00:00
|
|
|
}
|
2008-04-16 17:24:18 +00:00
|
|
|
break;
|
2007-02-12 23:24:31 +00:00
|
|
|
}
|
2008-04-16 17:24:18 +00:00
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
/* TSNH */
|
|
|
|
break;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
spc->spc_state = state;
|
|
|
|
spc->spc_error = error;
|
|
|
|
spc->spc_assoc_id = sctp_get_associd(stcb);
|
|
|
|
|
2006-12-29 20:21:42 +00:00
|
|
|
SCTP_BUF_LEN(m_notify) = sizeof(struct sctp_paddr_change);
|
|
|
|
SCTP_BUF_NEXT(m_notify) = NULL;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
/* append to socket */
|
|
|
|
control = sctp_build_readq_entry(stcb, stcb->asoc.primary_destination,
|
2011-12-17 19:21:40 +00:00
|
|
|
0, 0, stcb->asoc.context, 0, 0, 0,
|
2006-11-03 15:23:16 +00:00
|
|
|
m_notify);
|
|
|
|
if (control == NULL) {
|
|
|
|
/* no memory */
|
|
|
|
sctp_m_freem(m_notify);
|
|
|
|
return;
|
|
|
|
}
|
2006-12-29 20:21:42 +00:00
|
|
|
control->length = SCTP_BUF_LEN(m_notify);
|
|
|
|
control->spec_flags = M_NOTIFICATION;
|
2006-11-03 15:23:16 +00:00
|
|
|
/* not that we need this */
|
|
|
|
control->tail_mbuf = m_notify;
|
|
|
|
sctp_add_to_readq(stcb->sctp_ep, stcb,
|
|
|
|
control,
|
2009-07-28 14:09:06 +00:00
|
|
|
&stcb->sctp_socket->so_rcv, 1,
|
|
|
|
SCTP_READ_LOCK_NOT_HELD,
|
2015-03-10 22:38:10 +00:00
|
|
|
so_locked);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2012-05-13 19:32:49 +00:00
|
|
|
sctp_notify_send_failed(struct sctp_tcb *stcb, uint8_t sent, uint32_t error,
|
2007-09-08 11:35:11 +00:00
|
|
|
struct sctp_tmit_chunk *chk, int so_locked
|
|
|
|
#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
|
|
|
|
SCTP_UNUSED
|
|
|
|
#endif
|
|
|
|
)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
2008-12-06 13:19:54 +00:00
|
|
|
struct mbuf *m_notify;
|
2006-11-03 15:23:16 +00:00
|
|
|
struct sctp_send_failed *ssf;
|
2012-05-06 11:02:53 +00:00
|
|
|
struct sctp_send_failed_event *ssfe;
|
2006-11-03 15:23:16 +00:00
|
|
|
struct sctp_queued_to_read *control;
|
2016-06-26 16:38:42 +00:00
|
|
|
struct sctp_chunkhdr *chkhdr;
|
|
|
|
int notifhdr_len, chk_len, chkhdr_len, padding_len, payload_len;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2011-12-27 10:16:24 +00:00
|
|
|
if ((stcb == NULL) ||
|
2012-05-06 11:02:53 +00:00
|
|
|
(sctp_stcb_is_feature_off(stcb->sctp_ep, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT) &&
|
|
|
|
sctp_stcb_is_feature_off(stcb->sctp_ep, stcb, SCTP_PCB_FLAGS_RECVNSENDFAILEVNT))) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/* event not enabled */
|
|
|
|
return;
|
2008-12-06 13:19:54 +00:00
|
|
|
}
|
2018-07-19 20:16:33 +00:00
|
|
|
|
2012-05-06 11:02:53 +00:00
|
|
|
if (sctp_stcb_is_feature_on(stcb->sctp_ep, stcb, SCTP_PCB_FLAGS_RECVNSENDFAILEVNT)) {
|
2016-06-26 16:38:42 +00:00
|
|
|
notifhdr_len = sizeof(struct sctp_send_failed_event);
|
2012-05-06 11:02:53 +00:00
|
|
|
} else {
|
2016-06-26 16:38:42 +00:00
|
|
|
notifhdr_len = sizeof(struct sctp_send_failed);
|
2012-05-06 11:02:53 +00:00
|
|
|
}
|
2016-06-26 16:38:42 +00:00
|
|
|
m_notify = sctp_get_mbuf_for_msg(notifhdr_len, 0, M_NOWAIT, 1, MT_DATA);
|
2006-11-03 15:23:16 +00:00
|
|
|
if (m_notify == NULL)
|
|
|
|
/* no space left */
|
|
|
|
return;
|
2016-06-26 16:38:42 +00:00
|
|
|
SCTP_BUF_LEN(m_notify) = notifhdr_len;
|
|
|
|
if (stcb->asoc.idata_supported) {
|
|
|
|
chkhdr_len = sizeof(struct sctp_idata_chunk);
|
|
|
|
} else {
|
|
|
|
chkhdr_len = sizeof(struct sctp_data_chunk);
|
|
|
|
}
|
|
|
|
/* Use some defaults in case we can't access the chunk header */
|
|
|
|
if (chk->send_size >= chkhdr_len) {
|
|
|
|
payload_len = chk->send_size - chkhdr_len;
|
|
|
|
} else {
|
|
|
|
payload_len = 0;
|
|
|
|
}
|
|
|
|
padding_len = 0;
|
|
|
|
if (chk->data != NULL) {
|
|
|
|
chkhdr = mtod(chk->data, struct sctp_chunkhdr *);
|
|
|
|
if (chkhdr != NULL) {
|
|
|
|
chk_len = ntohs(chkhdr->chunk_length);
|
|
|
|
if ((chk_len >= chkhdr_len) &&
|
|
|
|
(chk->send_size >= chk_len) &&
|
|
|
|
(chk->send_size - chk_len < 4)) {
|
|
|
|
padding_len = chk->send_size - chk_len;
|
|
|
|
payload_len = chk->send_size - chkhdr_len - padding_len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-05-06 11:02:53 +00:00
|
|
|
if (sctp_stcb_is_feature_on(stcb->sctp_ep, stcb, SCTP_PCB_FLAGS_RECVNSENDFAILEVNT)) {
|
|
|
|
ssfe = mtod(m_notify, struct sctp_send_failed_event *);
|
2016-06-26 16:38:42 +00:00
|
|
|
memset(ssfe, 0, notifhdr_len);
|
2012-05-06 11:02:53 +00:00
|
|
|
ssfe->ssfe_type = SCTP_SEND_FAILED_EVENT;
|
2012-05-13 19:32:49 +00:00
|
|
|
if (sent) {
|
2012-05-06 11:02:53 +00:00
|
|
|
ssfe->ssfe_flags = SCTP_DATA_SENT;
|
2012-05-13 19:32:49 +00:00
|
|
|
} else {
|
|
|
|
ssfe->ssfe_flags = SCTP_DATA_UNSENT;
|
|
|
|
}
|
2018-07-19 20:11:14 +00:00
|
|
|
ssfe->ssfe_length = (uint32_t)(notifhdr_len + payload_len);
|
2012-05-06 11:02:53 +00:00
|
|
|
ssfe->ssfe_error = error;
|
|
|
|
/* not exactly what the user sent in, but should be close :) */
|
2016-12-07 19:30:59 +00:00
|
|
|
ssfe->ssfe_info.snd_sid = chk->rec.data.sid;
|
2012-05-06 11:02:53 +00:00
|
|
|
ssfe->ssfe_info.snd_flags = chk->rec.data.rcv_flags;
|
2016-12-07 19:30:59 +00:00
|
|
|
ssfe->ssfe_info.snd_ppid = chk->rec.data.ppid;
|
2012-05-06 11:02:53 +00:00
|
|
|
ssfe->ssfe_info.snd_context = chk->rec.data.context;
|
|
|
|
ssfe->ssfe_info.snd_assoc_id = sctp_get_associd(stcb);
|
|
|
|
ssfe->ssfe_assoc_id = sctp_get_associd(stcb);
|
|
|
|
} else {
|
|
|
|
ssf = mtod(m_notify, struct sctp_send_failed *);
|
2016-06-26 16:38:42 +00:00
|
|
|
memset(ssf, 0, notifhdr_len);
|
2012-05-06 11:02:53 +00:00
|
|
|
ssf->ssf_type = SCTP_SEND_FAILED;
|
2012-05-13 19:32:49 +00:00
|
|
|
if (sent) {
|
2012-05-06 11:02:53 +00:00
|
|
|
ssf->ssf_flags = SCTP_DATA_SENT;
|
2012-05-13 19:32:49 +00:00
|
|
|
} else {
|
|
|
|
ssf->ssf_flags = SCTP_DATA_UNSENT;
|
|
|
|
}
|
2018-07-19 20:11:14 +00:00
|
|
|
ssf->ssf_length = (uint32_t)(notifhdr_len + payload_len);
|
2012-05-06 11:02:53 +00:00
|
|
|
ssf->ssf_error = error;
|
|
|
|
/* not exactly what the user sent in, but should be close :) */
|
2016-12-07 19:30:59 +00:00
|
|
|
ssf->ssf_info.sinfo_stream = chk->rec.data.sid;
|
2018-07-19 20:11:14 +00:00
|
|
|
ssf->ssf_info.sinfo_ssn = (uint16_t)chk->rec.data.mid;
|
2012-05-06 11:02:53 +00:00
|
|
|
ssf->ssf_info.sinfo_flags = chk->rec.data.rcv_flags;
|
2016-12-07 19:30:59 +00:00
|
|
|
ssf->ssf_info.sinfo_ppid = chk->rec.data.ppid;
|
2012-05-06 11:02:53 +00:00
|
|
|
ssf->ssf_info.sinfo_context = chk->rec.data.context;
|
|
|
|
ssf->ssf_info.sinfo_assoc_id = sctp_get_associd(stcb);
|
|
|
|
ssf->ssf_assoc_id = sctp_get_associd(stcb);
|
|
|
|
}
|
2016-06-26 16:38:42 +00:00
|
|
|
if (chk->data != NULL) {
|
|
|
|
/* Trim off the sctp chunk header (it should be there) */
|
|
|
|
if (chk->send_size == chkhdr_len + payload_len + padding_len) {
|
|
|
|
m_adj(chk->data, chkhdr_len);
|
|
|
|
m_adj(chk->data, -padding_len);
|
2008-12-06 13:19:54 +00:00
|
|
|
sctp_mbuf_crush(chk->data);
|
2016-06-26 16:38:42 +00:00
|
|
|
chk->send_size -= (chkhdr_len + padding_len);
|
2008-12-06 13:19:54 +00:00
|
|
|
}
|
|
|
|
}
|
2009-08-15 21:10:52 +00:00
|
|
|
SCTP_BUF_NEXT(m_notify) = chk->data;
|
2006-11-03 15:23:16 +00:00
|
|
|
/* Steal off the mbuf */
|
|
|
|
chk->data = NULL;
|
|
|
|
/*
|
|
|
|
* For this case, we check the actual socket buffer, since the assoc
|
|
|
|
* is going away we don't want to overfill the socket buffer for a
|
|
|
|
* non-reader
|
|
|
|
*/
|
2006-12-29 20:21:42 +00:00
|
|
|
if (sctp_sbspace_failedmsgs(&stcb->sctp_socket->so_rcv) < SCTP_BUF_LEN(m_notify)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
sctp_m_freem(m_notify);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* append to socket */
|
|
|
|
control = sctp_build_readq_entry(stcb, stcb->asoc.primary_destination,
|
2011-12-17 19:21:40 +00:00
|
|
|
0, 0, stcb->asoc.context, 0, 0, 0,
|
2006-11-03 15:23:16 +00:00
|
|
|
m_notify);
|
|
|
|
if (control == NULL) {
|
|
|
|
/* no memory */
|
|
|
|
sctp_m_freem(m_notify);
|
|
|
|
return;
|
|
|
|
}
|
2017-07-19 12:27:40 +00:00
|
|
|
control->length = SCTP_BUF_LEN(m_notify);
|
2006-12-29 20:21:42 +00:00
|
|
|
control->spec_flags = M_NOTIFICATION;
|
2017-07-19 12:27:40 +00:00
|
|
|
/* not that we need this */
|
|
|
|
control->tail_mbuf = m_notify;
|
2006-11-03 15:23:16 +00:00
|
|
|
sctp_add_to_readq(stcb->sctp_ep, stcb,
|
|
|
|
control,
|
2009-07-28 14:09:06 +00:00
|
|
|
&stcb->sctp_socket->so_rcv, 1,
|
|
|
|
SCTP_READ_LOCK_NOT_HELD,
|
|
|
|
so_locked);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
sctp_notify_send_failed2(struct sctp_tcb *stcb, uint32_t error,
|
2007-09-08 11:35:11 +00:00
|
|
|
struct sctp_stream_queue_pending *sp, int so_locked
|
|
|
|
#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
|
|
|
|
SCTP_UNUSED
|
|
|
|
#endif
|
|
|
|
)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
|
|
|
struct mbuf *m_notify;
|
|
|
|
struct sctp_send_failed *ssf;
|
2012-05-06 11:02:53 +00:00
|
|
|
struct sctp_send_failed_event *ssfe;
|
2006-11-03 15:23:16 +00:00
|
|
|
struct sctp_queued_to_read *control;
|
2016-06-26 16:38:42 +00:00
|
|
|
int notifhdr_len;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2011-12-27 10:16:24 +00:00
|
|
|
if ((stcb == NULL) ||
|
2012-05-06 11:02:53 +00:00
|
|
|
(sctp_stcb_is_feature_off(stcb->sctp_ep, stcb, SCTP_PCB_FLAGS_RECVSENDFAILEVNT) &&
|
|
|
|
sctp_stcb_is_feature_off(stcb->sctp_ep, stcb, SCTP_PCB_FLAGS_RECVNSENDFAILEVNT))) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/* event not enabled */
|
|
|
|
return;
|
2008-12-06 13:19:54 +00:00
|
|
|
}
|
2012-05-06 11:02:53 +00:00
|
|
|
if (sctp_stcb_is_feature_on(stcb->sctp_ep, stcb, SCTP_PCB_FLAGS_RECVNSENDFAILEVNT)) {
|
2016-06-26 16:38:42 +00:00
|
|
|
notifhdr_len = sizeof(struct sctp_send_failed_event);
|
2012-05-06 11:02:53 +00:00
|
|
|
} else {
|
2016-06-26 16:38:42 +00:00
|
|
|
notifhdr_len = sizeof(struct sctp_send_failed);
|
2012-05-06 11:02:53 +00:00
|
|
|
}
|
2016-06-26 16:38:42 +00:00
|
|
|
m_notify = sctp_get_mbuf_for_msg(notifhdr_len, 0, M_NOWAIT, 1, MT_DATA);
|
2012-05-06 11:02:53 +00:00
|
|
|
if (m_notify == NULL) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/* no space left */
|
|
|
|
return;
|
2012-05-06 11:02:53 +00:00
|
|
|
}
|
2016-06-26 16:38:42 +00:00
|
|
|
SCTP_BUF_LEN(m_notify) = notifhdr_len;
|
2012-05-06 11:02:53 +00:00
|
|
|
if (sctp_stcb_is_feature_on(stcb->sctp_ep, stcb, SCTP_PCB_FLAGS_RECVNSENDFAILEVNT)) {
|
|
|
|
ssfe = mtod(m_notify, struct sctp_send_failed_event *);
|
2016-06-26 16:38:42 +00:00
|
|
|
memset(ssfe, 0, notifhdr_len);
|
2012-07-14 21:25:14 +00:00
|
|
|
ssfe->ssfe_type = SCTP_SEND_FAILED_EVENT;
|
2012-05-13 19:32:49 +00:00
|
|
|
ssfe->ssfe_flags = SCTP_DATA_UNSENT;
|
2018-07-19 20:11:14 +00:00
|
|
|
ssfe->ssfe_length = (uint32_t)(notifhdr_len + sp->length);
|
2012-05-06 11:02:53 +00:00
|
|
|
ssfe->ssfe_error = error;
|
|
|
|
/* not exactly what the user sent in, but should be close :) */
|
2016-12-07 19:30:59 +00:00
|
|
|
ssfe->ssfe_info.snd_sid = sp->sid;
|
2012-05-06 11:02:53 +00:00
|
|
|
if (sp->some_taken) {
|
|
|
|
ssfe->ssfe_info.snd_flags = SCTP_DATA_LAST_FRAG;
|
|
|
|
} else {
|
|
|
|
ssfe->ssfe_info.snd_flags = SCTP_DATA_NOT_FRAG;
|
|
|
|
}
|
|
|
|
ssfe->ssfe_info.snd_ppid = sp->ppid;
|
|
|
|
ssfe->ssfe_info.snd_context = sp->context;
|
|
|
|
ssfe->ssfe_info.snd_assoc_id = sctp_get_associd(stcb);
|
|
|
|
ssfe->ssfe_assoc_id = sctp_get_associd(stcb);
|
2008-07-09 16:45:30 +00:00
|
|
|
} else {
|
2012-05-06 11:02:53 +00:00
|
|
|
ssf = mtod(m_notify, struct sctp_send_failed *);
|
2016-06-26 16:38:42 +00:00
|
|
|
memset(ssf, 0, notifhdr_len);
|
2012-05-06 11:02:53 +00:00
|
|
|
ssf->ssf_type = SCTP_SEND_FAILED;
|
2012-05-13 19:32:49 +00:00
|
|
|
ssf->ssf_flags = SCTP_DATA_UNSENT;
|
2018-07-19 20:11:14 +00:00
|
|
|
ssf->ssf_length = (uint32_t)(notifhdr_len + sp->length);
|
2012-05-06 11:02:53 +00:00
|
|
|
ssf->ssf_error = error;
|
|
|
|
/* not exactly what the user sent in, but should be close :) */
|
2016-12-07 19:30:59 +00:00
|
|
|
ssf->ssf_info.sinfo_stream = sp->sid;
|
2012-11-05 20:55:17 +00:00
|
|
|
ssf->ssf_info.sinfo_ssn = 0;
|
2012-05-06 11:02:53 +00:00
|
|
|
if (sp->some_taken) {
|
|
|
|
ssf->ssf_info.sinfo_flags = SCTP_DATA_LAST_FRAG;
|
|
|
|
} else {
|
|
|
|
ssf->ssf_info.sinfo_flags = SCTP_DATA_NOT_FRAG;
|
|
|
|
}
|
|
|
|
ssf->ssf_info.sinfo_ppid = sp->ppid;
|
|
|
|
ssf->ssf_info.sinfo_context = sp->context;
|
|
|
|
ssf->ssf_info.sinfo_assoc_id = sctp_get_associd(stcb);
|
|
|
|
ssf->ssf_assoc_id = sctp_get_associd(stcb);
|
2008-07-09 16:45:30 +00:00
|
|
|
}
|
2006-12-29 20:21:42 +00:00
|
|
|
SCTP_BUF_NEXT(m_notify) = sp->data;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
/* Steal off the mbuf */
|
|
|
|
sp->data = NULL;
|
|
|
|
/*
|
|
|
|
* For this case, we check the actual socket buffer, since the assoc
|
|
|
|
* is going away we don't want to overfill the socket buffer for a
|
|
|
|
* non-reader
|
|
|
|
*/
|
2006-12-29 20:21:42 +00:00
|
|
|
if (sctp_sbspace_failedmsgs(&stcb->sctp_socket->so_rcv) < SCTP_BUF_LEN(m_notify)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
sctp_m_freem(m_notify);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* append to socket */
|
|
|
|
control = sctp_build_readq_entry(stcb, stcb->asoc.primary_destination,
|
2011-12-17 19:21:40 +00:00
|
|
|
0, 0, stcb->asoc.context, 0, 0, 0,
|
2006-11-03 15:23:16 +00:00
|
|
|
m_notify);
|
|
|
|
if (control == NULL) {
|
|
|
|
/* no memory */
|
|
|
|
sctp_m_freem(m_notify);
|
|
|
|
return;
|
|
|
|
}
|
2017-07-19 12:27:40 +00:00
|
|
|
control->length = SCTP_BUF_LEN(m_notify);
|
2006-12-29 20:21:42 +00:00
|
|
|
control->spec_flags = M_NOTIFICATION;
|
2017-07-19 12:27:40 +00:00
|
|
|
/* not that we need this */
|
|
|
|
control->tail_mbuf = m_notify;
|
2006-11-03 15:23:16 +00:00
|
|
|
sctp_add_to_readq(stcb->sctp_ep, stcb,
|
|
|
|
control,
|
2009-07-28 14:09:06 +00:00
|
|
|
&stcb->sctp_socket->so_rcv, 1, SCTP_READ_LOCK_NOT_HELD, so_locked);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2011-12-17 19:21:40 +00:00
|
|
|
sctp_notify_adaptation_layer(struct sctp_tcb *stcb)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
|
|
|
struct mbuf *m_notify;
|
|
|
|
struct sctp_adaptation_event *sai;
|
|
|
|
struct sctp_queued_to_read *control;
|
|
|
|
|
2011-12-27 10:16:24 +00:00
|
|
|
if ((stcb == NULL) ||
|
|
|
|
sctp_stcb_is_feature_off(stcb->sctp_ep, stcb, SCTP_PCB_FLAGS_ADAPTATIONEVNT)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/* event not enabled */
|
|
|
|
return;
|
2008-12-06 13:19:54 +00:00
|
|
|
}
|
2018-07-19 20:16:33 +00:00
|
|
|
|
2012-12-05 08:04:20 +00:00
|
|
|
m_notify = sctp_get_mbuf_for_msg(sizeof(struct sctp_adaption_event), 0, M_NOWAIT, 1, MT_DATA);
|
2006-11-03 15:23:16 +00:00
|
|
|
if (m_notify == NULL)
|
|
|
|
/* no space left */
|
|
|
|
return;
|
2006-12-29 20:21:42 +00:00
|
|
|
SCTP_BUF_LEN(m_notify) = 0;
|
2006-11-03 15:23:16 +00:00
|
|
|
sai = mtod(m_notify, struct sctp_adaptation_event *);
|
2014-07-08 21:54:27 +00:00
|
|
|
memset(sai, 0, sizeof(struct sctp_adaptation_event));
|
2006-11-03 15:23:16 +00:00
|
|
|
sai->sai_type = SCTP_ADAPTATION_INDICATION;
|
|
|
|
sai->sai_flags = 0;
|
|
|
|
sai->sai_length = sizeof(struct sctp_adaptation_event);
|
2007-08-27 05:19:48 +00:00
|
|
|
sai->sai_adaptation_ind = stcb->asoc.peers_adaptation;
|
2006-11-03 15:23:16 +00:00
|
|
|
sai->sai_assoc_id = sctp_get_associd(stcb);
|
|
|
|
|
2006-12-29 20:21:42 +00:00
|
|
|
SCTP_BUF_LEN(m_notify) = sizeof(struct sctp_adaptation_event);
|
|
|
|
SCTP_BUF_NEXT(m_notify) = NULL;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
/* append to socket */
|
|
|
|
control = sctp_build_readq_entry(stcb, stcb->asoc.primary_destination,
|
2011-12-17 19:21:40 +00:00
|
|
|
0, 0, stcb->asoc.context, 0, 0, 0,
|
2006-11-03 15:23:16 +00:00
|
|
|
m_notify);
|
|
|
|
if (control == NULL) {
|
|
|
|
/* no memory */
|
|
|
|
sctp_m_freem(m_notify);
|
|
|
|
return;
|
|
|
|
}
|
2006-12-29 20:21:42 +00:00
|
|
|
control->length = SCTP_BUF_LEN(m_notify);
|
|
|
|
control->spec_flags = M_NOTIFICATION;
|
2006-11-03 15:23:16 +00:00
|
|
|
/* not that we need this */
|
|
|
|
control->tail_mbuf = m_notify;
|
|
|
|
sctp_add_to_readq(stcb->sctp_ep, stcb,
|
|
|
|
control,
|
2009-07-28 14:09:06 +00:00
|
|
|
&stcb->sctp_socket->so_rcv, 1, SCTP_READ_LOCK_NOT_HELD, SCTP_SO_NOT_LOCKED);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
2006-11-08 00:21:13 +00:00
|
|
|
/* This always must be called with the read-queue LOCKED in the INP */
|
2009-08-15 21:10:52 +00:00
|
|
|
static void
|
2007-08-16 01:51:22 +00:00
|
|
|
sctp_notify_partial_delivery_indication(struct sctp_tcb *stcb, uint32_t error,
|
2009-08-15 21:10:52 +00:00
|
|
|
uint32_t val, int so_locked
|
|
|
|
#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
|
|
|
|
SCTP_UNUSED
|
|
|
|
#endif
|
|
|
|
)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
|
|
|
struct mbuf *m_notify;
|
|
|
|
struct sctp_pdapi_event *pdapi;
|
|
|
|
struct sctp_queued_to_read *control;
|
2006-11-08 00:21:13 +00:00
|
|
|
struct sockbuf *sb;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2011-12-27 10:16:24 +00:00
|
|
|
if ((stcb == NULL) ||
|
|
|
|
sctp_stcb_is_feature_off(stcb->sctp_ep, stcb, SCTP_PCB_FLAGS_PDAPIEVNT)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/* event not enabled */
|
|
|
|
return;
|
2008-12-06 13:19:54 +00:00
|
|
|
}
|
2010-06-18 09:01:44 +00:00
|
|
|
if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_CANT_READ) {
|
|
|
|
return;
|
|
|
|
}
|
2018-07-19 20:16:33 +00:00
|
|
|
|
2012-12-05 08:04:20 +00:00
|
|
|
m_notify = sctp_get_mbuf_for_msg(sizeof(struct sctp_pdapi_event), 0, M_NOWAIT, 1, MT_DATA);
|
2006-11-03 15:23:16 +00:00
|
|
|
if (m_notify == NULL)
|
|
|
|
/* no space left */
|
|
|
|
return;
|
2006-12-29 20:21:42 +00:00
|
|
|
SCTP_BUF_LEN(m_notify) = 0;
|
2006-11-03 15:23:16 +00:00
|
|
|
pdapi = mtod(m_notify, struct sctp_pdapi_event *);
|
2014-07-08 21:54:27 +00:00
|
|
|
memset(pdapi, 0, sizeof(struct sctp_pdapi_event));
|
2006-11-03 15:23:16 +00:00
|
|
|
pdapi->pdapi_type = SCTP_PARTIAL_DELIVERY_EVENT;
|
|
|
|
pdapi->pdapi_flags = 0;
|
|
|
|
pdapi->pdapi_length = sizeof(struct sctp_pdapi_event);
|
|
|
|
pdapi->pdapi_indication = error;
|
2007-04-22 11:06:27 +00:00
|
|
|
pdapi->pdapi_stream = (val >> 16);
|
|
|
|
pdapi->pdapi_seq = (val & 0x0000ffff);
|
2006-11-03 15:23:16 +00:00
|
|
|
pdapi->pdapi_assoc_id = sctp_get_associd(stcb);
|
|
|
|
|
2006-12-29 20:21:42 +00:00
|
|
|
SCTP_BUF_LEN(m_notify) = sizeof(struct sctp_pdapi_event);
|
|
|
|
SCTP_BUF_NEXT(m_notify) = NULL;
|
2006-11-08 00:21:13 +00:00
|
|
|
control = sctp_build_readq_entry(stcb, stcb->asoc.primary_destination,
|
2011-12-17 19:21:40 +00:00
|
|
|
0, 0, stcb->asoc.context, 0, 0, 0,
|
2006-11-08 00:21:13 +00:00
|
|
|
m_notify);
|
|
|
|
if (control == NULL) {
|
|
|
|
/* no memory */
|
|
|
|
sctp_m_freem(m_notify);
|
|
|
|
return;
|
|
|
|
}
|
2006-12-29 20:21:42 +00:00
|
|
|
control->length = SCTP_BUF_LEN(m_notify);
|
2017-07-19 12:27:40 +00:00
|
|
|
control->spec_flags = M_NOTIFICATION;
|
2006-11-08 00:21:13 +00:00
|
|
|
/* not that we need this */
|
|
|
|
control->tail_mbuf = m_notify;
|
|
|
|
sb = &stcb->sctp_socket->so_rcv;
|
2008-06-14 07:58:05 +00:00
|
|
|
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SB_LOGGING_ENABLE) {
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_sblog(sb, control->do_not_ref_stcb ? NULL : stcb, SCTP_LOG_SBALLOC, SCTP_BUF_LEN(m_notify));
|
|
|
|
}
|
2006-11-08 00:21:13 +00:00
|
|
|
sctp_sballoc(stcb, sb, m_notify);
|
2008-06-14 07:58:05 +00:00
|
|
|
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SB_LOGGING_ENABLE) {
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_sblog(sb, control->do_not_ref_stcb ? NULL : stcb, SCTP_LOG_SBRESULT, 0);
|
|
|
|
}
|
2006-11-08 00:21:13 +00:00
|
|
|
control->end_added = 1;
|
|
|
|
if (stcb->asoc.control_pdapi)
|
|
|
|
TAILQ_INSERT_AFTER(&stcb->sctp_ep->read_queue, stcb->asoc.control_pdapi, control, next);
|
|
|
|
else {
|
|
|
|
/* we really should not see this case */
|
|
|
|
TAILQ_INSERT_TAIL(&stcb->sctp_ep->read_queue, control, next);
|
|
|
|
}
|
|
|
|
if (stcb->sctp_ep && stcb->sctp_socket) {
|
|
|
|
/* This should always be the case */
|
2012-06-25 17:15:09 +00:00
|
|
|
#if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
|
2009-08-15 21:10:52 +00:00
|
|
|
struct socket *so;
|
|
|
|
|
|
|
|
so = SCTP_INP_SO(stcb->sctp_ep);
|
|
|
|
if (!so_locked) {
|
|
|
|
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
|
2006-11-05 13:25:18 +00:00
|
|
|
sctp_sorwakeup(stcb->sctp_ep, stcb->sctp_socket);
|
2012-06-25 17:15:09 +00:00
|
|
|
#if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
|
2009-08-15 21:10:52 +00:00
|
|
|
if (!so_locked) {
|
|
|
|
SCTP_SOCKET_UNLOCK(so, 1);
|
|
|
|
}
|
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sctp_notify_shutdown_event(struct sctp_tcb *stcb)
|
|
|
|
{
|
|
|
|
struct mbuf *m_notify;
|
|
|
|
struct sctp_shutdown_event *sse;
|
|
|
|
struct sctp_queued_to_read *control;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For TCP model AND UDP connected sockets we will send an error up
|
|
|
|
* when an SHUTDOWN completes
|
|
|
|
*/
|
|
|
|
if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
|
|
|
|
(stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) {
|
|
|
|
/* mark socket closed for read/write and wakeup! */
|
2012-06-25 17:15:09 +00:00
|
|
|
#if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
|
2007-09-08 11:35:11 +00:00
|
|
|
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->asoc.state & SCTP_STATE_CLOSED_SOCKET) {
|
|
|
|
SCTP_SOCKET_UNLOCK(so, 1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
socantsendmore(stcb->sctp_socket);
|
2012-06-25 17:15:09 +00:00
|
|
|
#if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
|
2007-09-08 11:35:11 +00:00
|
|
|
SCTP_SOCKET_UNLOCK(so, 1);
|
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2011-06-15 23:50:27 +00:00
|
|
|
if (sctp_stcb_is_feature_off(stcb->sctp_ep, stcb, SCTP_PCB_FLAGS_RECVSHUTDOWNEVNT)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/* event not enabled */
|
|
|
|
return;
|
2008-12-06 13:19:54 +00:00
|
|
|
}
|
2018-07-19 20:16:33 +00:00
|
|
|
|
2012-12-05 08:04:20 +00:00
|
|
|
m_notify = sctp_get_mbuf_for_msg(sizeof(struct sctp_shutdown_event), 0, M_NOWAIT, 1, MT_DATA);
|
2006-11-03 15:23:16 +00:00
|
|
|
if (m_notify == NULL)
|
|
|
|
/* no space left */
|
|
|
|
return;
|
|
|
|
sse = mtod(m_notify, struct sctp_shutdown_event *);
|
2014-07-08 21:54:27 +00:00
|
|
|
memset(sse, 0, sizeof(struct sctp_shutdown_event));
|
2006-11-03 15:23:16 +00:00
|
|
|
sse->sse_type = SCTP_SHUTDOWN_EVENT;
|
|
|
|
sse->sse_flags = 0;
|
|
|
|
sse->sse_length = sizeof(struct sctp_shutdown_event);
|
|
|
|
sse->sse_assoc_id = sctp_get_associd(stcb);
|
|
|
|
|
2006-12-29 20:21:42 +00:00
|
|
|
SCTP_BUF_LEN(m_notify) = sizeof(struct sctp_shutdown_event);
|
|
|
|
SCTP_BUF_NEXT(m_notify) = NULL;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
/* append to socket */
|
|
|
|
control = sctp_build_readq_entry(stcb, stcb->asoc.primary_destination,
|
2011-12-17 19:21:40 +00:00
|
|
|
0, 0, stcb->asoc.context, 0, 0, 0,
|
2006-11-03 15:23:16 +00:00
|
|
|
m_notify);
|
|
|
|
if (control == NULL) {
|
|
|
|
/* no memory */
|
|
|
|
sctp_m_freem(m_notify);
|
|
|
|
return;
|
|
|
|
}
|
2006-12-29 20:21:42 +00:00
|
|
|
control->length = SCTP_BUF_LEN(m_notify);
|
2017-07-19 12:27:40 +00:00
|
|
|
control->spec_flags = M_NOTIFICATION;
|
2006-11-03 15:23:16 +00:00
|
|
|
/* not that we need this */
|
|
|
|
control->tail_mbuf = m_notify;
|
|
|
|
sctp_add_to_readq(stcb->sctp_ep, stcb,
|
|
|
|
control,
|
2009-07-28 14:09:06 +00:00
|
|
|
&stcb->sctp_socket->so_rcv, 1, SCTP_READ_LOCK_NOT_HELD, SCTP_SO_NOT_LOCKED);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
2008-12-06 13:19:54 +00:00
|
|
|
static void
|
|
|
|
sctp_notify_sender_dry_event(struct sctp_tcb *stcb,
|
|
|
|
int so_locked
|
|
|
|
#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
|
|
|
|
SCTP_UNUSED
|
|
|
|
#endif
|
|
|
|
)
|
|
|
|
{
|
|
|
|
struct mbuf *m_notify;
|
|
|
|
struct sctp_sender_dry_event *event;
|
|
|
|
struct sctp_queued_to_read *control;
|
|
|
|
|
2011-12-27 10:16:24 +00:00
|
|
|
if ((stcb == NULL) ||
|
|
|
|
sctp_stcb_is_feature_off(stcb->sctp_ep, stcb, SCTP_PCB_FLAGS_DRYEVNT)) {
|
2008-12-06 13:19:54 +00:00
|
|
|
/* event not enabled */
|
|
|
|
return;
|
|
|
|
}
|
2018-07-19 20:16:33 +00:00
|
|
|
|
2012-12-05 08:04:20 +00:00
|
|
|
m_notify = sctp_get_mbuf_for_msg(sizeof(struct sctp_sender_dry_event), 0, M_NOWAIT, 1, MT_DATA);
|
2008-12-06 13:19:54 +00:00
|
|
|
if (m_notify == NULL) {
|
|
|
|
/* no space left */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SCTP_BUF_LEN(m_notify) = 0;
|
|
|
|
event = mtod(m_notify, struct sctp_sender_dry_event *);
|
2014-07-08 21:54:27 +00:00
|
|
|
memset(event, 0, sizeof(struct sctp_sender_dry_event));
|
2008-12-06 13:19:54 +00:00
|
|
|
event->sender_dry_type = SCTP_SENDER_DRY_EVENT;
|
|
|
|
event->sender_dry_flags = 0;
|
|
|
|
event->sender_dry_length = sizeof(struct sctp_sender_dry_event);
|
|
|
|
event->sender_dry_assoc_id = sctp_get_associd(stcb);
|
|
|
|
|
|
|
|
SCTP_BUF_LEN(m_notify) = sizeof(struct sctp_sender_dry_event);
|
|
|
|
SCTP_BUF_NEXT(m_notify) = NULL;
|
|
|
|
|
|
|
|
/* append to socket */
|
|
|
|
control = sctp_build_readq_entry(stcb, stcb->asoc.primary_destination,
|
2011-12-17 19:21:40 +00:00
|
|
|
0, 0, stcb->asoc.context, 0, 0, 0,
|
|
|
|
m_notify);
|
2008-12-06 13:19:54 +00:00
|
|
|
if (control == NULL) {
|
|
|
|
/* no memory */
|
|
|
|
sctp_m_freem(m_notify);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
control->length = SCTP_BUF_LEN(m_notify);
|
|
|
|
control->spec_flags = M_NOTIFICATION;
|
|
|
|
/* not that we need this */
|
|
|
|
control->tail_mbuf = m_notify;
|
|
|
|
sctp_add_to_readq(stcb->sctp_ep, stcb, control,
|
2009-07-28 14:09:06 +00:00
|
|
|
&stcb->sctp_socket->so_rcv, 1, SCTP_READ_LOCK_NOT_HELD, so_locked);
|
2008-12-06 13:19:54 +00:00
|
|
|
}
|
|
|
|
|
2009-02-20 15:03:54 +00:00
|
|
|
|
2012-03-29 13:36:53 +00:00
|
|
|
void
|
|
|
|
sctp_notify_stream_reset_add(struct sctp_tcb *stcb, uint16_t numberin, uint16_t numberout, int flag)
|
2009-02-20 15:03:54 +00:00
|
|
|
{
|
|
|
|
struct mbuf *m_notify;
|
|
|
|
struct sctp_queued_to_read *control;
|
2012-03-29 13:36:53 +00:00
|
|
|
struct sctp_stream_change_event *stradd;
|
2009-02-20 15:03:54 +00:00
|
|
|
|
2012-05-06 14:50:54 +00:00
|
|
|
if ((stcb == NULL) ||
|
|
|
|
(sctp_stcb_is_feature_off(stcb->sctp_ep, stcb, SCTP_PCB_FLAGS_STREAM_CHANGEEVNT))) {
|
2009-02-20 15:03:54 +00:00
|
|
|
/* event not enabled */
|
|
|
|
return;
|
|
|
|
}
|
2012-03-29 13:36:53 +00:00
|
|
|
if ((stcb->asoc.peer_req_out) && flag) {
|
|
|
|
/* Peer made the request, don't tell the local user */
|
|
|
|
stcb->asoc.peer_req_out = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
stcb->asoc.peer_req_out = 0;
|
2014-07-08 21:54:27 +00:00
|
|
|
m_notify = sctp_get_mbuf_for_msg(sizeof(struct sctp_stream_change_event), 0, M_NOWAIT, 1, MT_DATA);
|
2009-02-20 15:03:54 +00:00
|
|
|
if (m_notify == NULL)
|
|
|
|
/* no space left */
|
|
|
|
return;
|
|
|
|
SCTP_BUF_LEN(m_notify) = 0;
|
2012-03-29 13:36:53 +00:00
|
|
|
stradd = mtod(m_notify, struct sctp_stream_change_event *);
|
2014-07-08 21:54:27 +00:00
|
|
|
memset(stradd, 0, sizeof(struct sctp_stream_change_event));
|
2012-03-29 13:36:53 +00:00
|
|
|
stradd->strchange_type = SCTP_STREAM_CHANGE_EVENT;
|
|
|
|
stradd->strchange_flags = flag;
|
2014-07-08 21:54:27 +00:00
|
|
|
stradd->strchange_length = sizeof(struct sctp_stream_change_event);
|
2012-03-29 13:36:53 +00:00
|
|
|
stradd->strchange_assoc_id = sctp_get_associd(stcb);
|
|
|
|
stradd->strchange_instrms = numberin;
|
|
|
|
stradd->strchange_outstrms = numberout;
|
2014-07-08 21:54:27 +00:00
|
|
|
SCTP_BUF_LEN(m_notify) = sizeof(struct sctp_stream_change_event);
|
2012-03-29 13:36:53 +00:00
|
|
|
SCTP_BUF_NEXT(m_notify) = NULL;
|
|
|
|
if (sctp_sbspace(&stcb->asoc, &stcb->sctp_socket->so_rcv) < SCTP_BUF_LEN(m_notify)) {
|
|
|
|
/* no space */
|
|
|
|
sctp_m_freem(m_notify);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* append to socket */
|
|
|
|
control = sctp_build_readq_entry(stcb, stcb->asoc.primary_destination,
|
|
|
|
0, 0, stcb->asoc.context, 0, 0, 0,
|
|
|
|
m_notify);
|
|
|
|
if (control == NULL) {
|
|
|
|
/* no memory */
|
|
|
|
sctp_m_freem(m_notify);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
control->length = SCTP_BUF_LEN(m_notify);
|
2017-07-19 12:27:40 +00:00
|
|
|
control->spec_flags = M_NOTIFICATION;
|
2012-03-29 13:36:53 +00:00
|
|
|
/* not that we need this */
|
|
|
|
control->tail_mbuf = m_notify;
|
|
|
|
sctp_add_to_readq(stcb->sctp_ep, stcb,
|
|
|
|
control,
|
|
|
|
&stcb->sctp_socket->so_rcv, 1, SCTP_READ_LOCK_NOT_HELD, SCTP_SO_NOT_LOCKED);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sctp_notify_stream_reset_tsn(struct sctp_tcb *stcb, uint32_t sending_tsn, uint32_t recv_tsn, int flag)
|
|
|
|
{
|
|
|
|
struct mbuf *m_notify;
|
|
|
|
struct sctp_queued_to_read *control;
|
|
|
|
struct sctp_assoc_reset_event *strasoc;
|
2009-02-20 15:03:54 +00:00
|
|
|
|
2012-05-06 14:50:54 +00:00
|
|
|
if ((stcb == NULL) ||
|
|
|
|
(sctp_stcb_is_feature_off(stcb->sctp_ep, stcb, SCTP_PCB_FLAGS_ASSOC_RESETEVNT))) {
|
2012-03-29 13:36:53 +00:00
|
|
|
/* event not enabled */
|
|
|
|
return;
|
|
|
|
}
|
2014-07-08 21:54:27 +00:00
|
|
|
m_notify = sctp_get_mbuf_for_msg(sizeof(struct sctp_assoc_reset_event), 0, M_NOWAIT, 1, MT_DATA);
|
2012-03-29 13:36:53 +00:00
|
|
|
if (m_notify == NULL)
|
|
|
|
/* no space left */
|
|
|
|
return;
|
|
|
|
SCTP_BUF_LEN(m_notify) = 0;
|
|
|
|
strasoc = mtod(m_notify, struct sctp_assoc_reset_event *);
|
2014-07-08 21:54:27 +00:00
|
|
|
memset(strasoc, 0, sizeof(struct sctp_assoc_reset_event));
|
2012-03-29 13:36:53 +00:00
|
|
|
strasoc->assocreset_type = SCTP_ASSOC_RESET_EVENT;
|
|
|
|
strasoc->assocreset_flags = flag;
|
2014-07-08 21:54:27 +00:00
|
|
|
strasoc->assocreset_length = sizeof(struct sctp_assoc_reset_event);
|
2012-03-29 13:36:53 +00:00
|
|
|
strasoc->assocreset_assoc_id = sctp_get_associd(stcb);
|
|
|
|
strasoc->assocreset_local_tsn = sending_tsn;
|
|
|
|
strasoc->assocreset_remote_tsn = recv_tsn;
|
2014-07-08 21:54:27 +00:00
|
|
|
SCTP_BUF_LEN(m_notify) = sizeof(struct sctp_assoc_reset_event);
|
2009-02-20 15:03:54 +00:00
|
|
|
SCTP_BUF_NEXT(m_notify) = NULL;
|
|
|
|
if (sctp_sbspace(&stcb->asoc, &stcb->sctp_socket->so_rcv) < SCTP_BUF_LEN(m_notify)) {
|
|
|
|
/* no space */
|
|
|
|
sctp_m_freem(m_notify);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* append to socket */
|
|
|
|
control = sctp_build_readq_entry(stcb, stcb->asoc.primary_destination,
|
2011-12-17 19:21:40 +00:00
|
|
|
0, 0, stcb->asoc.context, 0, 0, 0,
|
2009-02-20 15:03:54 +00:00
|
|
|
m_notify);
|
|
|
|
if (control == NULL) {
|
|
|
|
/* no memory */
|
|
|
|
sctp_m_freem(m_notify);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
control->length = SCTP_BUF_LEN(m_notify);
|
2017-07-19 12:27:40 +00:00
|
|
|
control->spec_flags = M_NOTIFICATION;
|
2009-02-20 15:03:54 +00:00
|
|
|
/* not that we need this */
|
|
|
|
control->tail_mbuf = m_notify;
|
|
|
|
sctp_add_to_readq(stcb->sctp_ep, stcb,
|
|
|
|
control,
|
2009-07-28 14:09:06 +00:00
|
|
|
&stcb->sctp_socket->so_rcv, 1, SCTP_READ_LOCK_NOT_HELD, SCTP_SO_NOT_LOCKED);
|
2009-02-20 15:03:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-29 13:36:53 +00:00
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
static void
|
|
|
|
sctp_notify_stream_reset(struct sctp_tcb *stcb,
|
2018-07-19 20:11:14 +00:00
|
|
|
int number_entries, uint16_t *list, int flag)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
|
|
|
struct mbuf *m_notify;
|
|
|
|
struct sctp_queued_to_read *control;
|
|
|
|
struct sctp_stream_reset_event *strreset;
|
|
|
|
int len;
|
|
|
|
|
2012-05-06 14:50:54 +00:00
|
|
|
if ((stcb == NULL) ||
|
|
|
|
(sctp_stcb_is_feature_off(stcb->sctp_ep, stcb, SCTP_PCB_FLAGS_STREAM_RESETEVNT))) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/* event not enabled */
|
|
|
|
return;
|
2008-12-06 13:19:54 +00:00
|
|
|
}
|
2018-07-19 20:16:33 +00:00
|
|
|
|
2012-12-05 08:04:20 +00:00
|
|
|
m_notify = sctp_get_mbuf_for_msg(MCLBYTES, 0, M_NOWAIT, 1, MT_DATA);
|
2006-11-03 15:23:16 +00:00
|
|
|
if (m_notify == NULL)
|
|
|
|
/* no space left */
|
|
|
|
return;
|
2006-12-29 20:21:42 +00:00
|
|
|
SCTP_BUF_LEN(m_notify) = 0;
|
2006-11-03 15:23:16 +00:00
|
|
|
len = sizeof(struct sctp_stream_reset_event) + (number_entries * sizeof(uint16_t));
|
|
|
|
if (len > M_TRAILINGSPACE(m_notify)) {
|
|
|
|
/* never enough room */
|
|
|
|
sctp_m_freem(m_notify);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
strreset = mtod(m_notify, struct sctp_stream_reset_event *);
|
2014-07-08 21:54:27 +00:00
|
|
|
memset(strreset, 0, len);
|
2006-11-03 15:23:16 +00:00
|
|
|
strreset->strreset_type = SCTP_STREAM_RESET_EVENT;
|
2012-03-29 13:36:53 +00:00
|
|
|
strreset->strreset_flags = flag;
|
2006-11-03 15:23:16 +00:00
|
|
|
strreset->strreset_length = len;
|
|
|
|
strreset->strreset_assoc_id = sctp_get_associd(stcb);
|
|
|
|
if (number_entries) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < number_entries; i++) {
|
2012-03-29 13:36:53 +00:00
|
|
|
strreset->strreset_stream_list[i] = ntohs(list[i]);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
2006-12-29 20:21:42 +00:00
|
|
|
SCTP_BUF_LEN(m_notify) = len;
|
|
|
|
SCTP_BUF_NEXT(m_notify) = NULL;
|
|
|
|
if (sctp_sbspace(&stcb->asoc, &stcb->sctp_socket->so_rcv) < SCTP_BUF_LEN(m_notify)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/* no space */
|
|
|
|
sctp_m_freem(m_notify);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* append to socket */
|
|
|
|
control = sctp_build_readq_entry(stcb, stcb->asoc.primary_destination,
|
2011-12-17 19:21:40 +00:00
|
|
|
0, 0, stcb->asoc.context, 0, 0, 0,
|
2006-11-03 15:23:16 +00:00
|
|
|
m_notify);
|
|
|
|
if (control == NULL) {
|
|
|
|
/* no memory */
|
|
|
|
sctp_m_freem(m_notify);
|
|
|
|
return;
|
|
|
|
}
|
2006-12-29 20:21:42 +00:00
|
|
|
control->length = SCTP_BUF_LEN(m_notify);
|
2017-07-19 12:27:40 +00:00
|
|
|
control->spec_flags = M_NOTIFICATION;
|
2006-11-03 15:23:16 +00:00
|
|
|
/* not that we need this */
|
|
|
|
control->tail_mbuf = m_notify;
|
|
|
|
sctp_add_to_readq(stcb->sctp_ep, stcb,
|
|
|
|
control,
|
2009-07-28 14:09:06 +00:00
|
|
|
&stcb->sctp_socket->so_rcv, 1, SCTP_READ_LOCK_NOT_HELD, SCTP_SO_NOT_LOCKED);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-13 22:27:54 +00:00
|
|
|
static void
|
|
|
|
sctp_notify_remote_error(struct sctp_tcb *stcb, uint16_t error, struct sctp_error_chunk *chunk)
|
|
|
|
{
|
|
|
|
struct mbuf *m_notify;
|
|
|
|
struct sctp_remote_error *sre;
|
|
|
|
struct sctp_queued_to_read *control;
|
2016-03-27 10:04:25 +00:00
|
|
|
unsigned int notif_len;
|
|
|
|
uint16_t chunk_len;
|
2012-05-13 22:27:54 +00:00
|
|
|
|
|
|
|
if ((stcb == NULL) ||
|
|
|
|
sctp_stcb_is_feature_off(stcb->sctp_ep, stcb, SCTP_PCB_FLAGS_RECVPEERERR)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (chunk != NULL) {
|
2013-11-07 16:37:12 +00:00
|
|
|
chunk_len = ntohs(chunk->ch.chunk_length);
|
2018-05-08 18:48:51 +00:00
|
|
|
/*
|
|
|
|
* Only SCTP_CHUNK_BUFFER_SIZE are guaranteed to be
|
2018-05-08 20:39:35 +00:00
|
|
|
* contiguous.
|
2018-05-08 18:48:51 +00:00
|
|
|
*/
|
|
|
|
if (chunk_len > SCTP_CHUNK_BUFFER_SIZE) {
|
|
|
|
chunk_len = SCTP_CHUNK_BUFFER_SIZE;
|
|
|
|
}
|
2012-05-13 22:27:54 +00:00
|
|
|
} else {
|
|
|
|
chunk_len = 0;
|
|
|
|
}
|
2016-03-27 10:04:25 +00:00
|
|
|
notif_len = (unsigned int)(sizeof(struct sctp_remote_error) + chunk_len);
|
2012-12-05 08:04:20 +00:00
|
|
|
m_notify = sctp_get_mbuf_for_msg(notif_len, 0, M_NOWAIT, 1, MT_DATA);
|
2012-05-13 22:27:54 +00:00
|
|
|
if (m_notify == NULL) {
|
|
|
|
/* Retry with smaller value. */
|
2016-03-27 10:04:25 +00:00
|
|
|
notif_len = (unsigned int)sizeof(struct sctp_remote_error);
|
2012-12-05 08:04:20 +00:00
|
|
|
m_notify = sctp_get_mbuf_for_msg(notif_len, 0, M_NOWAIT, 1, MT_DATA);
|
2012-05-13 22:27:54 +00:00
|
|
|
if (m_notify == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SCTP_BUF_NEXT(m_notify) = NULL;
|
|
|
|
sre = mtod(m_notify, struct sctp_remote_error *);
|
2014-07-24 18:06:18 +00:00
|
|
|
memset(sre, 0, notif_len);
|
2012-05-13 22:27:54 +00:00
|
|
|
sre->sre_type = SCTP_REMOTE_ERROR;
|
|
|
|
sre->sre_flags = 0;
|
|
|
|
sre->sre_length = sizeof(struct sctp_remote_error);
|
|
|
|
sre->sre_error = error;
|
|
|
|
sre->sre_assoc_id = sctp_get_associd(stcb);
|
|
|
|
if (notif_len > sizeof(struct sctp_remote_error)) {
|
|
|
|
memcpy(sre->sre_data, chunk, chunk_len);
|
|
|
|
sre->sre_length += chunk_len;
|
|
|
|
}
|
|
|
|
SCTP_BUF_LEN(m_notify) = sre->sre_length;
|
|
|
|
control = sctp_build_readq_entry(stcb, stcb->asoc.primary_destination,
|
|
|
|
0, 0, stcb->asoc.context, 0, 0, 0,
|
|
|
|
m_notify);
|
|
|
|
if (control != NULL) {
|
|
|
|
control->length = SCTP_BUF_LEN(m_notify);
|
2017-07-19 12:27:40 +00:00
|
|
|
control->spec_flags = M_NOTIFICATION;
|
2012-05-13 22:27:54 +00:00
|
|
|
/* not that we need this */
|
|
|
|
control->tail_mbuf = m_notify;
|
|
|
|
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 {
|
|
|
|
sctp_m_freem(m_notify);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
void
|
|
|
|
sctp_ulp_notify(uint32_t notification, struct sctp_tcb *stcb,
|
2007-09-08 11:35:11 +00:00
|
|
|
uint32_t error, void *data, int so_locked
|
|
|
|
#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
|
|
|
|
SCTP_UNUSED
|
|
|
|
#endif
|
|
|
|
)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
2008-12-06 13:19:54 +00:00
|
|
|
if ((stcb == NULL) ||
|
|
|
|
(stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) ||
|
2006-11-03 15:23:16 +00:00
|
|
|
(stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
|
2008-12-06 13:19:54 +00:00
|
|
|
(stcb->asoc.state & SCTP_STATE_CLOSED_SOCKET)) {
|
|
|
|
/* If the socket is gone we are out of here */
|
2006-11-03 15:23:16 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-02-03 11:04:03 +00:00
|
|
|
if (stcb->sctp_socket->so_rcv.sb_state & SBS_CANTRCVMORE) {
|
|
|
|
return;
|
|
|
|
}
|
2018-08-13 13:58:45 +00:00
|
|
|
if ((SCTP_GET_STATE(stcb) == SCTP_STATE_COOKIE_WAIT) ||
|
2018-09-26 10:24:50 +00:00
|
|
|
(SCTP_GET_STATE(stcb) == SCTP_STATE_COOKIE_ECHOED)) {
|
2007-05-08 00:21:05 +00:00
|
|
|
if ((notification == SCTP_NOTIFY_INTERFACE_DOWN) ||
|
|
|
|
(notification == SCTP_NOTIFY_INTERFACE_UP) ||
|
|
|
|
(notification == SCTP_NOTIFY_INTERFACE_CONFIRMED)) {
|
|
|
|
/* Don't report these in front states */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
switch (notification) {
|
|
|
|
case SCTP_NOTIFY_ASSOC_UP:
|
|
|
|
if (stcb->asoc.assoc_up_sent == 0) {
|
2012-05-13 16:56:16 +00:00
|
|
|
sctp_notify_assoc_change(SCTP_COMM_UP, stcb, error, NULL, 0, so_locked);
|
2006-11-03 15:23:16 +00:00
|
|
|
stcb->asoc.assoc_up_sent = 1;
|
|
|
|
}
|
2007-08-27 05:19:48 +00:00
|
|
|
if (stcb->asoc.adaptation_needed && (stcb->asoc.adaptation_sent == 0)) {
|
2011-12-17 19:21:40 +00:00
|
|
|
sctp_notify_adaptation_layer(stcb);
|
2007-08-27 05:19:48 +00:00
|
|
|
}
|
2014-08-12 11:30:16 +00:00
|
|
|
if (stcb->asoc.auth_supported == 0) {
|
2008-12-06 13:19:54 +00:00
|
|
|
sctp_ulp_notify(SCTP_NOTIFY_NO_PEER_AUTH, stcb, 0,
|
|
|
|
NULL, so_locked);
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
|
|
|
case SCTP_NOTIFY_ASSOC_DOWN:
|
2012-05-13 16:56:16 +00:00
|
|
|
sctp_notify_assoc_change(SCTP_SHUTDOWN_COMP, stcb, error, NULL, 0, so_locked);
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
|
|
|
case SCTP_NOTIFY_INTERFACE_DOWN:
|
|
|
|
{
|
|
|
|
struct sctp_nets *net;
|
|
|
|
|
|
|
|
net = (struct sctp_nets *)data;
|
|
|
|
sctp_notify_peer_addr_change(stcb, SCTP_ADDR_UNREACHABLE,
|
2015-03-10 22:38:10 +00:00
|
|
|
(struct sockaddr *)&net->ro._l_addr, error, so_locked);
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SCTP_NOTIFY_INTERFACE_UP:
|
|
|
|
{
|
|
|
|
struct sctp_nets *net;
|
|
|
|
|
|
|
|
net = (struct sctp_nets *)data;
|
|
|
|
sctp_notify_peer_addr_change(stcb, SCTP_ADDR_AVAILABLE,
|
2015-03-10 22:38:10 +00:00
|
|
|
(struct sockaddr *)&net->ro._l_addr, error, so_locked);
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SCTP_NOTIFY_INTERFACE_CONFIRMED:
|
|
|
|
{
|
|
|
|
struct sctp_nets *net;
|
|
|
|
|
|
|
|
net = (struct sctp_nets *)data;
|
|
|
|
sctp_notify_peer_addr_change(stcb, SCTP_ADDR_CONFIRMED,
|
2015-03-10 22:38:10 +00:00
|
|
|
(struct sockaddr *)&net->ro._l_addr, error, so_locked);
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SCTP_NOTIFY_SPECIAL_SP_FAIL:
|
|
|
|
sctp_notify_send_failed2(stcb, error,
|
2007-09-08 11:35:11 +00:00
|
|
|
(struct sctp_stream_queue_pending *)data, so_locked);
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
2012-05-13 19:32:49 +00:00
|
|
|
case SCTP_NOTIFY_SENT_DG_FAIL:
|
|
|
|
sctp_notify_send_failed(stcb, 1, error,
|
|
|
|
(struct sctp_tmit_chunk *)data, so_locked);
|
|
|
|
break;
|
|
|
|
case SCTP_NOTIFY_UNSENT_DG_FAIL:
|
|
|
|
sctp_notify_send_failed(stcb, 0, error,
|
2007-09-08 11:35:11 +00:00
|
|
|
(struct sctp_tmit_chunk *)data, so_locked);
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
|
|
|
case SCTP_NOTIFY_PARTIAL_DELVIERY_INDICATION:
|
2007-04-22 11:06:27 +00:00
|
|
|
{
|
|
|
|
uint32_t val;
|
|
|
|
|
2018-07-19 20:11:14 +00:00
|
|
|
val = *((uint32_t *)data);
|
2007-04-22 11:06:27 +00:00
|
|
|
|
2009-08-15 21:10:52 +00:00
|
|
|
sctp_notify_partial_delivery_indication(stcb, error, val, so_locked);
|
|
|
|
break;
|
2007-04-22 11:06:27 +00:00
|
|
|
}
|
2012-05-13 16:56:16 +00:00
|
|
|
case SCTP_NOTIFY_ASSOC_LOC_ABORTED:
|
2018-08-13 13:58:45 +00:00
|
|
|
if ((SCTP_GET_STATE(stcb) == SCTP_STATE_COOKIE_WAIT) ||
|
|
|
|
(SCTP_GET_STATE(stcb) == SCTP_STATE_COOKIE_ECHOED)) {
|
2012-05-13 16:56:16 +00:00
|
|
|
sctp_notify_assoc_change(SCTP_CANT_STR_ASSOC, stcb, error, data, 0, so_locked);
|
2007-04-14 09:44:09 +00:00
|
|
|
} else {
|
2012-05-13 16:56:16 +00:00
|
|
|
sctp_notify_assoc_change(SCTP_COMM_LOST, stcb, error, data, 0, so_locked);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCTP_NOTIFY_ASSOC_REM_ABORTED:
|
2018-08-13 13:58:45 +00:00
|
|
|
if ((SCTP_GET_STATE(stcb) == SCTP_STATE_COOKIE_WAIT) ||
|
|
|
|
(SCTP_GET_STATE(stcb) == SCTP_STATE_COOKIE_ECHOED)) {
|
2012-05-13 16:56:16 +00:00
|
|
|
sctp_notify_assoc_change(SCTP_CANT_STR_ASSOC, stcb, error, data, 1, so_locked);
|
|
|
|
} else {
|
|
|
|
sctp_notify_assoc_change(SCTP_COMM_LOST, stcb, error, data, 1, so_locked);
|
2007-04-14 09:44:09 +00:00
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
|
|
|
case SCTP_NOTIFY_ASSOC_RESTART:
|
2012-05-13 16:56:16 +00:00
|
|
|
sctp_notify_assoc_change(SCTP_RESTART, stcb, error, NULL, 0, so_locked);
|
2014-08-12 11:30:16 +00:00
|
|
|
if (stcb->asoc.auth_supported == 0) {
|
2008-12-06 13:19:54 +00:00
|
|
|
sctp_ulp_notify(SCTP_NOTIFY_NO_PEER_AUTH, stcb, 0,
|
|
|
|
NULL, so_locked);
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
|
|
|
case SCTP_NOTIFY_STR_RESET_SEND:
|
2018-07-19 20:11:14 +00:00
|
|
|
sctp_notify_stream_reset(stcb, error, ((uint16_t *)data), SCTP_STREAM_RESET_OUTGOING_SSN);
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
|
|
|
case SCTP_NOTIFY_STR_RESET_RECV:
|
2018-07-19 20:11:14 +00:00
|
|
|
sctp_notify_stream_reset(stcb, error, ((uint16_t *)data), SCTP_STREAM_RESET_INCOMING);
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
|
|
|
case SCTP_NOTIFY_STR_RESET_FAILED_OUT:
|
2018-07-19 20:11:14 +00:00
|
|
|
sctp_notify_stream_reset(stcb, error, ((uint16_t *)data),
|
2012-04-23 20:45:31 +00:00
|
|
|
(SCTP_STREAM_RESET_OUTGOING_SSN | SCTP_STREAM_RESET_FAILED));
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
2012-05-05 21:41:16 +00:00
|
|
|
case SCTP_NOTIFY_STR_RESET_DENIED_OUT:
|
2018-07-19 20:11:14 +00:00
|
|
|
sctp_notify_stream_reset(stcb, error, ((uint16_t *)data),
|
2012-05-05 21:41:16 +00:00
|
|
|
(SCTP_STREAM_RESET_OUTGOING_SSN | SCTP_STREAM_RESET_DENIED));
|
|
|
|
break;
|
2006-11-03 15:23:16 +00:00
|
|
|
case SCTP_NOTIFY_STR_RESET_FAILED_IN:
|
2018-07-19 20:11:14 +00:00
|
|
|
sctp_notify_stream_reset(stcb, error, ((uint16_t *)data),
|
2012-04-23 20:45:31 +00:00
|
|
|
(SCTP_STREAM_RESET_INCOMING | SCTP_STREAM_RESET_FAILED));
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
2012-05-05 21:41:16 +00:00
|
|
|
case SCTP_NOTIFY_STR_RESET_DENIED_IN:
|
2018-07-19 20:11:14 +00:00
|
|
|
sctp_notify_stream_reset(stcb, error, ((uint16_t *)data),
|
2012-05-05 21:41:16 +00:00
|
|
|
(SCTP_STREAM_RESET_INCOMING | SCTP_STREAM_RESET_DENIED));
|
|
|
|
break;
|
2006-11-03 15:23:16 +00:00
|
|
|
case SCTP_NOTIFY_ASCONF_ADD_IP:
|
|
|
|
sctp_notify_peer_addr_change(stcb, SCTP_ADDR_ADDED, data,
|
2015-03-10 22:38:10 +00:00
|
|
|
error, so_locked);
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
|
|
|
case SCTP_NOTIFY_ASCONF_DELETE_IP:
|
|
|
|
sctp_notify_peer_addr_change(stcb, SCTP_ADDR_REMOVED, data,
|
2015-03-10 22:38:10 +00:00
|
|
|
error, so_locked);
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
|
|
|
case SCTP_NOTIFY_ASCONF_SET_PRIMARY:
|
|
|
|
sctp_notify_peer_addr_change(stcb, SCTP_ADDR_MADE_PRIM, data,
|
2015-03-10 22:38:10 +00:00
|
|
|
error, so_locked);
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
|
|
|
case SCTP_NOTIFY_PEER_SHUTDOWN:
|
|
|
|
sctp_notify_shutdown_event(stcb);
|
|
|
|
break;
|
|
|
|
case SCTP_NOTIFY_AUTH_NEW_KEY:
|
2012-04-26 11:07:15 +00:00
|
|
|
sctp_notify_authentication(stcb, SCTP_AUTH_NEW_KEY, error,
|
2018-07-19 20:11:14 +00:00
|
|
|
(uint16_t)(uintptr_t)data,
|
2008-12-06 13:19:54 +00:00
|
|
|
so_locked);
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
2008-12-06 13:19:54 +00:00
|
|
|
case SCTP_NOTIFY_AUTH_FREE_KEY:
|
|
|
|
sctp_notify_authentication(stcb, SCTP_AUTH_FREE_KEY, error,
|
2018-07-19 20:11:14 +00:00
|
|
|
(uint16_t)(uintptr_t)data,
|
2008-12-06 13:19:54 +00:00
|
|
|
so_locked);
|
|
|
|
break;
|
|
|
|
case SCTP_NOTIFY_NO_PEER_AUTH:
|
|
|
|
sctp_notify_authentication(stcb, SCTP_AUTH_NO_AUTH, error,
|
2018-07-19 20:11:14 +00:00
|
|
|
(uint16_t)(uintptr_t)data,
|
2008-12-06 13:19:54 +00:00
|
|
|
so_locked);
|
|
|
|
break;
|
|
|
|
case SCTP_NOTIFY_SENDER_DRY:
|
|
|
|
sctp_notify_sender_dry_event(stcb, so_locked);
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
2012-05-13 22:27:54 +00:00
|
|
|
case SCTP_NOTIFY_REMOTE_ERROR:
|
|
|
|
sctp_notify_remote_error(stcb, error, data);
|
|
|
|
break;
|
2006-11-03 15:23:16 +00:00
|
|
|
default:
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTPDBG(SCTP_DEBUG_UTIL1, "%s: unknown notification %xh (%u)\n",
|
2015-10-19 11:17:54 +00:00
|
|
|
__func__, notification, notification);
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
|
|
|
} /* end switch */
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-05-13 19:32:49 +00:00
|
|
|
sctp_report_all_outbound(struct sctp_tcb *stcb, uint16_t error, int holds_lock, int so_locked
|
2007-09-08 11:35:11 +00:00
|
|
|
#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
|
|
|
|
SCTP_UNUSED
|
|
|
|
#endif
|
|
|
|
)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
|
|
|
struct sctp_association *asoc;
|
|
|
|
struct sctp_stream_out *outs;
|
2010-12-30 16:56:20 +00:00
|
|
|
struct sctp_tmit_chunk *chk, *nchk;
|
|
|
|
struct sctp_stream_queue_pending *sp, *nsp;
|
2006-11-11 22:44:12 +00:00
|
|
|
int i;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2007-05-09 13:30:06 +00:00
|
|
|
if (stcb == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
2010-12-30 16:56:20 +00:00
|
|
|
asoc = &stcb->asoc;
|
|
|
|
if (asoc->state & SCTP_STATE_ABOUT_TO_BE_FREED) {
|
2010-07-03 14:03:31 +00:00
|
|
|
/* already being freed */
|
|
|
|
return;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) ||
|
|
|
|
(stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
|
2010-12-30 16:56:20 +00:00
|
|
|
(asoc->state & SCTP_STATE_CLOSED_SOCKET)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* now through all the gunk freeing chunks */
|
2007-05-09 13:30:06 +00:00
|
|
|
if (holds_lock == 0) {
|
2006-11-11 22:44:12 +00:00
|
|
|
SCTP_TCB_SEND_LOCK(stcb);
|
2007-05-09 13:30:06 +00:00
|
|
|
}
|
2007-06-09 13:46:57 +00:00
|
|
|
/* sent queue SHOULD be empty */
|
2010-12-30 16:56:20 +00:00
|
|
|
TAILQ_FOREACH_SAFE(chk, &asoc->sent_queue, sctp_next, nchk) {
|
|
|
|
TAILQ_REMOVE(&asoc->sent_queue, chk, sctp_next);
|
|
|
|
asoc->sent_queue_cnt--;
|
2012-11-16 19:39:10 +00:00
|
|
|
if (chk->sent != SCTP_DATAGRAM_NR_ACKED) {
|
2016-12-07 19:30:59 +00:00
|
|
|
if (asoc->strmout[chk->rec.data.sid].chunks_on_queues > 0) {
|
|
|
|
asoc->strmout[chk->rec.data.sid].chunks_on_queues--;
|
2012-11-07 22:11:38 +00:00
|
|
|
#ifdef INVARIANTS
|
|
|
|
} else {
|
2016-12-07 19:30:59 +00:00
|
|
|
panic("No chunks on the queues for sid %u.", chk->rec.data.sid);
|
2012-11-07 22:11:38 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
2010-12-30 16:56:20 +00:00
|
|
|
if (chk->data != NULL) {
|
|
|
|
sctp_free_bufspace(stcb, asoc, chk, 1);
|
2012-05-13 19:32:49 +00:00
|
|
|
sctp_ulp_notify(SCTP_NOTIFY_SENT_DG_FAIL, stcb,
|
|
|
|
error, chk, so_locked);
|
2010-12-30 16:56:20 +00:00
|
|
|
if (chk->data) {
|
|
|
|
sctp_m_freem(chk->data);
|
|
|
|
chk->data = NULL;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
2011-05-08 09:11:59 +00:00
|
|
|
sctp_free_a_chunk(stcb, chk, so_locked);
|
2010-12-30 16:56:20 +00:00
|
|
|
/* sa_ignore FREED_MEMORY */
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2007-06-09 13:46:57 +00:00
|
|
|
/* pending send queue SHOULD be empty */
|
2010-12-30 16:56:20 +00:00
|
|
|
TAILQ_FOREACH_SAFE(chk, &asoc->send_queue, sctp_next, nchk) {
|
|
|
|
TAILQ_REMOVE(&asoc->send_queue, chk, sctp_next);
|
|
|
|
asoc->send_queue_cnt--;
|
2016-12-07 19:30:59 +00:00
|
|
|
if (asoc->strmout[chk->rec.data.sid].chunks_on_queues > 0) {
|
|
|
|
asoc->strmout[chk->rec.data.sid].chunks_on_queues--;
|
2012-11-07 22:11:38 +00:00
|
|
|
#ifdef INVARIANTS
|
|
|
|
} else {
|
2016-12-07 19:30:59 +00:00
|
|
|
panic("No chunks on the queues for sid %u.", chk->rec.data.sid);
|
2012-11-07 22:11:38 +00:00
|
|
|
#endif
|
|
|
|
}
|
2010-12-30 16:56:20 +00:00
|
|
|
if (chk->data != NULL) {
|
|
|
|
sctp_free_bufspace(stcb, asoc, chk, 1);
|
2012-05-13 19:32:49 +00:00
|
|
|
sctp_ulp_notify(SCTP_NOTIFY_UNSENT_DG_FAIL, stcb,
|
|
|
|
error, chk, so_locked);
|
2010-12-30 16:56:20 +00:00
|
|
|
if (chk->data) {
|
|
|
|
sctp_m_freem(chk->data);
|
|
|
|
chk->data = NULL;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2007-06-09 13:46:57 +00:00
|
|
|
}
|
2011-05-08 09:11:59 +00:00
|
|
|
sctp_free_a_chunk(stcb, chk, so_locked);
|
2010-12-30 16:56:20 +00:00
|
|
|
/* sa_ignore FREED_MEMORY */
|
2007-06-09 13:46:57 +00:00
|
|
|
}
|
2010-12-30 16:56:20 +00:00
|
|
|
for (i = 0; i < asoc->streamoutcnt; i++) {
|
2007-06-09 13:46:57 +00:00
|
|
|
/* For each stream */
|
2010-12-30 16:56:20 +00:00
|
|
|
outs = &asoc->strmout[i];
|
2007-06-09 13:46:57 +00:00
|
|
|
/* clean up any sends there */
|
2010-12-30 16:56:20 +00:00
|
|
|
TAILQ_FOREACH_SAFE(sp, &outs->outqueue, next, nsp) {
|
2016-08-07 12:51:13 +00:00
|
|
|
atomic_subtract_int(&asoc->stream_queue_cnt, 1);
|
2007-06-09 13:46:57 +00:00
|
|
|
TAILQ_REMOVE(&outs->outqueue, sp, next);
|
2016-08-07 12:51:13 +00:00
|
|
|
stcb->asoc.ss_functions.sctp_ss_remove_from_stream(stcb, asoc, outs, sp, holds_lock);
|
2007-06-09 13:46:57 +00:00
|
|
|
sctp_free_spbufspace(stcb, asoc, sp);
|
|
|
|
if (sp->data) {
|
2010-07-03 14:03:31 +00:00
|
|
|
sctp_ulp_notify(SCTP_NOTIFY_SPECIAL_SP_FAIL, stcb,
|
2012-05-13 19:32:49 +00:00
|
|
|
error, (void *)sp, so_locked);
|
2010-07-03 14:03:31 +00:00
|
|
|
if (sp->data) {
|
|
|
|
sctp_m_freem(sp->data);
|
|
|
|
sp->data = NULL;
|
2012-07-17 13:03:47 +00:00
|
|
|
sp->tail_mbuf = NULL;
|
|
|
|
sp->length = 0;
|
2010-07-03 14:03:31 +00:00
|
|
|
}
|
2007-06-09 13:46:57 +00:00
|
|
|
}
|
2010-09-15 23:10:45 +00:00
|
|
|
if (sp->net) {
|
2007-06-09 13:46:57 +00:00
|
|
|
sctp_free_remote_addr(sp->net);
|
2010-09-15 23:10:45 +00:00
|
|
|
sp->net = NULL;
|
|
|
|
}
|
2007-06-09 13:46:57 +00:00
|
|
|
/* Free the chunk */
|
2011-05-08 09:11:59 +00:00
|
|
|
sctp_free_a_strmoq(stcb, sp, so_locked);
|
2007-06-09 13:46:57 +00:00
|
|
|
/* sa_ignore FREED_MEMORY */
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
2007-06-09 13:46:57 +00:00
|
|
|
|
2007-05-09 13:30:06 +00:00
|
|
|
if (holds_lock == 0) {
|
2006-11-11 22:44:12 +00:00
|
|
|
SCTP_TCB_SEND_UNLOCK(stcb);
|
2007-05-09 13:30:06 +00:00
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-05-13 16:56:16 +00:00
|
|
|
sctp_abort_notification(struct sctp_tcb *stcb, uint8_t from_peer, uint16_t error,
|
2012-05-12 20:11:35 +00:00
|
|
|
struct sctp_abort_chunk *abort, int so_locked
|
2007-09-08 11:35:11 +00:00
|
|
|
#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
|
|
|
|
SCTP_UNUSED
|
|
|
|
#endif
|
|
|
|
)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
2007-05-09 13:30:06 +00:00
|
|
|
if (stcb == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
2011-09-14 19:10:13 +00:00
|
|
|
if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL) ||
|
|
|
|
((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) &&
|
|
|
|
(stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_CONNECTED))) {
|
|
|
|
stcb->sctp_ep->sctp_flags |= SCTP_PCB_FLAGS_WAS_ABORTED;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) ||
|
|
|
|
(stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) ||
|
|
|
|
(stcb->asoc.state & SCTP_STATE_CLOSED_SOCKET)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* Tell them we lost the asoc */
|
2012-05-13 19:32:49 +00:00
|
|
|
sctp_report_all_outbound(stcb, error, 1, so_locked);
|
2012-05-13 16:56:16 +00:00
|
|
|
if (from_peer) {
|
|
|
|
sctp_ulp_notify(SCTP_NOTIFY_ASSOC_REM_ABORTED, stcb, error, abort, so_locked);
|
|
|
|
} else {
|
|
|
|
sctp_ulp_notify(SCTP_NOTIFY_ASSOC_LOC_ABORTED, stcb, error, abort, so_locked);
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sctp_abort_association(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
|
2012-06-28 16:01:08 +00:00
|
|
|
struct mbuf *m, int iphlen,
|
|
|
|
struct sockaddr *src, struct sockaddr *dst,
|
|
|
|
struct sctphdr *sh, struct mbuf *op_err,
|
2014-12-04 21:17:50 +00:00
|
|
|
uint8_t mflowtype, uint32_t mflowid,
|
2008-05-20 13:47:46 +00:00
|
|
|
uint32_t vrf_id, uint16_t port)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
|
|
|
uint32_t vtag;
|
2012-06-25 17:15:09 +00:00
|
|
|
#if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
|
2007-09-08 11:35:11 +00:00
|
|
|
struct socket *so;
|
|
|
|
#endif
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
vtag = 0;
|
|
|
|
if (stcb != NULL) {
|
|
|
|
vtag = stcb->asoc.peer_vtag;
|
2007-05-08 00:21:05 +00:00
|
|
|
vrf_id = stcb->asoc.vrf_id;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2012-06-28 16:01:08 +00:00
|
|
|
sctp_send_abort(m, iphlen, src, dst, sh, vtag, op_err,
|
2015-06-17 15:20:14 +00:00
|
|
|
mflowtype, mflowid, inp->fibnum,
|
2012-06-14 06:54:48 +00:00
|
|
|
vrf_id, port);
|
2006-11-03 15:23:16 +00:00
|
|
|
if (stcb != NULL) {
|
2016-08-24 06:22:53 +00:00
|
|
|
/* We have a TCB to abort, send notification too */
|
|
|
|
sctp_abort_notification(stcb, 0, 0, NULL, SCTP_SO_NOT_LOCKED);
|
2018-08-13 13:58:45 +00:00
|
|
|
SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_WAS_ABORTED);
|
2006-11-03 15:23:16 +00:00
|
|
|
/* Ok, now lets free it */
|
2012-06-25 17:15:09 +00:00
|
|
|
#if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
|
2007-09-08 11:35:11 +00:00
|
|
|
so = SCTP_INP_SO(inp);
|
|
|
|
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);
|
|
|
|
#endif
|
2010-12-12 20:50:44 +00:00
|
|
|
SCTP_STAT_INCR_COUNTER32(sctps_aborted);
|
2018-08-13 13:58:45 +00:00
|
|
|
if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
|
|
|
|
(SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
|
2010-12-12 20:50:44 +00:00
|
|
|
SCTP_STAT_DECR_GAUGE32(sctps_currestab);
|
|
|
|
}
|
2015-05-28 16:39:22 +00:00
|
|
|
(void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
|
|
|
|
SCTP_FROM_SCTPUTIL + SCTP_LOC_4);
|
2012-06-25 17:15:09 +00:00
|
|
|
#if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
|
2007-09-08 11:35:11 +00:00
|
|
|
SCTP_SOCKET_UNLOCK(so, 1);
|
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
2007-04-19 11:28:43 +00:00
|
|
|
#ifdef SCTP_ASOCLOG_OF_TSNS
|
|
|
|
void
|
|
|
|
sctp_print_out_track_log(struct sctp_tcb *stcb)
|
|
|
|
{
|
2007-07-17 20:58:26 +00:00
|
|
|
#ifdef NOSIY_PRINTS
|
2007-04-19 11:28:43 +00:00
|
|
|
int i;
|
|
|
|
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTP_PRINTF("Last ep reason:%x\n", stcb->sctp_ep->last_abort_code);
|
|
|
|
SCTP_PRINTF("IN bound TSN log-aaa\n");
|
2007-04-19 11:28:43 +00:00
|
|
|
if ((stcb->asoc.tsn_in_at == 0) && (stcb->asoc.tsn_in_wrapped == 0)) {
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTP_PRINTF("None rcvd\n");
|
2007-04-19 11:28:43 +00:00
|
|
|
goto none_in;
|
|
|
|
}
|
|
|
|
if (stcb->asoc.tsn_in_wrapped) {
|
|
|
|
for (i = stcb->asoc.tsn_in_at; i < SCTP_TSN_LOG_SIZE; i++) {
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTP_PRINTF("TSN:%x strm:%d seq:%d flags:%x sz:%d\n",
|
2007-04-19 11:28:43 +00:00
|
|
|
stcb->asoc.in_tsnlog[i].tsn,
|
|
|
|
stcb->asoc.in_tsnlog[i].strm,
|
|
|
|
stcb->asoc.in_tsnlog[i].seq,
|
|
|
|
stcb->asoc.in_tsnlog[i].flgs,
|
|
|
|
stcb->asoc.in_tsnlog[i].sz);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (stcb->asoc.tsn_in_at) {
|
|
|
|
for (i = 0; i < stcb->asoc.tsn_in_at; i++) {
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTP_PRINTF("TSN:%x strm:%d seq:%d flags:%x sz:%d\n",
|
2007-04-19 11:28:43 +00:00
|
|
|
stcb->asoc.in_tsnlog[i].tsn,
|
|
|
|
stcb->asoc.in_tsnlog[i].strm,
|
|
|
|
stcb->asoc.in_tsnlog[i].seq,
|
|
|
|
stcb->asoc.in_tsnlog[i].flgs,
|
|
|
|
stcb->asoc.in_tsnlog[i].sz);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
none_in:
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTP_PRINTF("OUT bound TSN log-aaa\n");
|
|
|
|
if ((stcb->asoc.tsn_out_at == 0) &&
|
|
|
|
(stcb->asoc.tsn_out_wrapped == 0)) {
|
|
|
|
SCTP_PRINTF("None sent\n");
|
2007-04-19 11:28:43 +00:00
|
|
|
}
|
|
|
|
if (stcb->asoc.tsn_out_wrapped) {
|
|
|
|
for (i = stcb->asoc.tsn_out_at; i < SCTP_TSN_LOG_SIZE; i++) {
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTP_PRINTF("TSN:%x strm:%d seq:%d flags:%x sz:%d\n",
|
2007-04-19 11:28:43 +00:00
|
|
|
stcb->asoc.out_tsnlog[i].tsn,
|
|
|
|
stcb->asoc.out_tsnlog[i].strm,
|
|
|
|
stcb->asoc.out_tsnlog[i].seq,
|
|
|
|
stcb->asoc.out_tsnlog[i].flgs,
|
|
|
|
stcb->asoc.out_tsnlog[i].sz);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (stcb->asoc.tsn_out_at) {
|
|
|
|
for (i = 0; i < stcb->asoc.tsn_out_at; i++) {
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTP_PRINTF("TSN:%x strm:%d seq:%d flags:%x sz:%d\n",
|
2007-04-19 11:28:43 +00:00
|
|
|
stcb->asoc.out_tsnlog[i].tsn,
|
|
|
|
stcb->asoc.out_tsnlog[i].strm,
|
|
|
|
stcb->asoc.out_tsnlog[i].seq,
|
|
|
|
stcb->asoc.out_tsnlog[i].flgs,
|
|
|
|
stcb->asoc.out_tsnlog[i].sz);
|
|
|
|
}
|
|
|
|
}
|
2007-07-17 20:58:26 +00:00
|
|
|
#endif
|
2007-04-19 11:28:43 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
void
|
|
|
|
sctp_abort_an_association(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
|
2012-05-12 20:11:35 +00:00
|
|
|
struct mbuf *op_err,
|
2007-09-08 11:35:11 +00:00
|
|
|
int so_locked
|
|
|
|
#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
|
|
|
|
SCTP_UNUSED
|
|
|
|
#endif
|
|
|
|
)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
2012-06-25 17:15:09 +00:00
|
|
|
#if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
|
2007-09-08 11:35:11 +00:00
|
|
|
struct socket *so;
|
|
|
|
#endif
|
|
|
|
|
2012-06-25 17:15:09 +00:00
|
|
|
#if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
|
2007-09-08 11:35:11 +00:00
|
|
|
so = SCTP_INP_SO(inp);
|
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
if (stcb == NULL) {
|
|
|
|
/* Got to have a TCB */
|
|
|
|
if (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) {
|
2013-06-02 10:35:08 +00:00
|
|
|
if (LIST_EMPTY(&inp->sctp_asoc_list)) {
|
2007-05-08 15:53:03 +00:00
|
|
|
sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
|
|
|
|
SCTP_CALLED_DIRECTLY_NOCMPSET);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
2007-08-06 15:46:46 +00:00
|
|
|
} else {
|
2018-08-13 13:58:45 +00:00
|
|
|
SCTP_ADD_SUBSTATE(stcb, SCTP_STATE_WAS_ABORTED);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
/* notify the peer */
|
2007-09-08 11:35:11 +00:00
|
|
|
sctp_send_abort_tcb(stcb, op_err, so_locked);
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_STAT_INCR_COUNTER32(sctps_aborted);
|
2018-08-13 13:58:45 +00:00
|
|
|
if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
|
|
|
|
(SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_STAT_DECR_GAUGE32(sctps_currestab);
|
|
|
|
}
|
2016-08-24 06:22:53 +00:00
|
|
|
/* notify the ulp */
|
|
|
|
if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) {
|
|
|
|
sctp_abort_notification(stcb, 0, 0, NULL, so_locked);
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
/* now free the asoc */
|
2007-04-19 11:28:43 +00:00
|
|
|
#ifdef SCTP_ASOCLOG_OF_TSNS
|
|
|
|
sctp_print_out_track_log(stcb);
|
2007-09-08 11:35:11 +00:00
|
|
|
#endif
|
2012-06-25 17:15:09 +00:00
|
|
|
#if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
|
2007-09-08 11:35:11 +00:00
|
|
|
if (!so_locked) {
|
|
|
|
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);
|
|
|
|
}
|
2007-04-19 11:28:43 +00:00
|
|
|
#endif
|
2015-05-28 16:39:22 +00:00
|
|
|
(void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
|
|
|
|
SCTP_FROM_SCTPUTIL + SCTP_LOC_5);
|
2012-06-25 17:15:09 +00:00
|
|
|
#if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
|
2007-09-08 11:35:11 +00:00
|
|
|
if (!so_locked) {
|
|
|
|
SCTP_SOCKET_UNLOCK(so, 1);
|
|
|
|
}
|
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-06-28 16:01:08 +00:00
|
|
|
sctp_handle_ootb(struct mbuf *m, int iphlen, int offset,
|
|
|
|
struct sockaddr *src, struct sockaddr *dst,
|
|
|
|
struct sctphdr *sh, struct sctp_inpcb *inp,
|
2014-03-16 12:32:16 +00:00
|
|
|
struct mbuf *cause,
|
2015-06-17 15:20:14 +00:00
|
|
|
uint8_t mflowtype, uint32_t mflowid, uint16_t fibnum,
|
2012-06-14 06:54:48 +00:00
|
|
|
uint32_t vrf_id, uint16_t port)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
|
|
|
struct sctp_chunkhdr *ch, chunk_buf;
|
|
|
|
unsigned int chk_length;
|
2012-01-08 09:56:24 +00:00
|
|
|
int contains_init_chunk;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
SCTP_STAT_INCR_COUNTER32(sctps_outoftheblue);
|
|
|
|
/* Generate a TO address for future reference */
|
|
|
|
if (inp && (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)) {
|
2013-06-02 10:35:08 +00:00
|
|
|
if (LIST_EMPTY(&inp->sctp_asoc_list)) {
|
2007-05-08 15:53:03 +00:00
|
|
|
sctp_inpcb_free(inp, SCTP_FREE_SHOULD_USE_ABORT,
|
|
|
|
SCTP_CALLED_DIRECTLY_NOCMPSET);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
2012-01-08 09:56:24 +00:00
|
|
|
contains_init_chunk = 0;
|
2006-11-03 15:23:16 +00:00
|
|
|
ch = (struct sctp_chunkhdr *)sctp_m_getptr(m, offset,
|
2018-07-19 20:11:14 +00:00
|
|
|
sizeof(*ch), (uint8_t *)&chunk_buf);
|
2006-11-03 15:23:16 +00:00
|
|
|
while (ch != NULL) {
|
|
|
|
chk_length = ntohs(ch->chunk_length);
|
|
|
|
if (chk_length < sizeof(*ch)) {
|
|
|
|
/* break to abort land */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
switch (ch->chunk_type) {
|
2012-01-08 09:56:24 +00:00
|
|
|
case SCTP_INIT:
|
|
|
|
contains_init_chunk = 1;
|
|
|
|
break;
|
2006-11-03 15:23:16 +00:00
|
|
|
case SCTP_PACKET_DROPPED:
|
|
|
|
/* we don't respond to pkt-dropped */
|
|
|
|
return;
|
|
|
|
case SCTP_ABORT_ASSOCIATION:
|
|
|
|
/* we don't respond with an ABORT to an ABORT */
|
|
|
|
return;
|
|
|
|
case SCTP_SHUTDOWN_COMPLETE:
|
|
|
|
/*
|
|
|
|
* we ignore it since we are not waiting for it and
|
|
|
|
* peer is gone
|
|
|
|
*/
|
|
|
|
return;
|
|
|
|
case SCTP_SHUTDOWN_ACK:
|
2012-06-28 16:01:08 +00:00
|
|
|
sctp_send_shutdown_complete2(src, dst, sh,
|
2015-06-17 15:20:14 +00:00
|
|
|
mflowtype, mflowid, fibnum,
|
2012-06-14 06:54:48 +00:00
|
|
|
vrf_id, port);
|
2006-11-03 15:23:16 +00:00
|
|
|
return;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
offset += SCTP_SIZE32(chk_length);
|
|
|
|
ch = (struct sctp_chunkhdr *)sctp_m_getptr(m, offset,
|
2018-07-19 20:11:14 +00:00
|
|
|
sizeof(*ch), (uint8_t *)&chunk_buf);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2012-01-08 09:56:24 +00:00
|
|
|
if ((SCTP_BASE_SYSCTL(sctp_blackhole) == 0) ||
|
|
|
|
((SCTP_BASE_SYSCTL(sctp_blackhole) == 1) &&
|
|
|
|
(contains_init_chunk == 0))) {
|
2014-03-16 12:32:16 +00:00
|
|
|
sctp_send_abort(m, iphlen, src, dst, sh, 0, cause,
|
2015-06-17 15:20:14 +00:00
|
|
|
mflowtype, mflowid, fibnum,
|
2012-06-14 06:54:48 +00:00
|
|
|
vrf_id, port);
|
2012-01-08 09:56:24 +00:00
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* check the inbound datagram to make sure there is not an abort inside it,
|
|
|
|
* if there is return 1, else return 0.
|
|
|
|
*/
|
|
|
|
int
|
2018-07-19 20:11:14 +00:00
|
|
|
sctp_is_there_an_abort_here(struct mbuf *m, int iphlen, uint32_t *vtagfill)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
|
|
|
struct sctp_chunkhdr *ch;
|
|
|
|
struct sctp_init_chunk *init_chk, chunk_buf;
|
|
|
|
int offset;
|
|
|
|
unsigned int chk_length;
|
|
|
|
|
|
|
|
offset = iphlen + sizeof(struct sctphdr);
|
|
|
|
ch = (struct sctp_chunkhdr *)sctp_m_getptr(m, offset, sizeof(*ch),
|
2018-07-19 20:11:14 +00:00
|
|
|
(uint8_t *)&chunk_buf);
|
2006-11-03 15:23:16 +00:00
|
|
|
while (ch != NULL) {
|
|
|
|
chk_length = ntohs(ch->chunk_length);
|
|
|
|
if (chk_length < sizeof(*ch)) {
|
|
|
|
/* packet is probably corrupt */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* we seem to be ok, is it an abort? */
|
|
|
|
if (ch->chunk_type == SCTP_ABORT_ASSOCIATION) {
|
|
|
|
/* yep, tell them */
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
if (ch->chunk_type == SCTP_INITIATION) {
|
|
|
|
/* need to update the Vtag */
|
|
|
|
init_chk = (struct sctp_init_chunk *)sctp_m_getptr(m,
|
2018-07-19 20:11:14 +00:00
|
|
|
offset, sizeof(*init_chk), (uint8_t *)&chunk_buf);
|
2006-11-03 15:23:16 +00:00
|
|
|
if (init_chk != NULL) {
|
|
|
|
*vtagfill = ntohl(init_chk->init.initiate_tag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Nope, move to the next chunk */
|
|
|
|
offset += SCTP_SIZE32(chk_length);
|
|
|
|
ch = (struct sctp_chunkhdr *)sctp_m_getptr(m, offset,
|
2018-07-19 20:11:14 +00:00
|
|
|
sizeof(*ch), (uint8_t *)&chunk_buf);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* currently (2/02), ifa_addr embeds scope_id's and don't have sin6_scope_id
|
|
|
|
* set (i.e. it's 0) so, create this function to compare link local scopes
|
|
|
|
*/
|
2008-04-16 17:24:18 +00:00
|
|
|
#ifdef INET6
|
2006-11-03 15:23:16 +00:00
|
|
|
uint32_t
|
2018-07-19 20:11:14 +00:00
|
|
|
sctp_is_same_scope(struct sockaddr_in6 *addr1, struct sockaddr_in6 *addr2)
|
|
|
|
{
|
2006-11-03 15:23:16 +00:00
|
|
|
struct sockaddr_in6 a, b;
|
|
|
|
|
|
|
|
/* save copies */
|
|
|
|
a = *addr1;
|
|
|
|
b = *addr2;
|
|
|
|
|
|
|
|
if (a.sin6_scope_id == 0)
|
|
|
|
if (sa6_recoverscope(&a)) {
|
|
|
|
/* can't get scope, so can't match */
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
if (b.sin6_scope_id == 0)
|
|
|
|
if (sa6_recoverscope(&b)) {
|
|
|
|
/* can't get scope, so can't match */
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
if (a.sin6_scope_id != b.sin6_scope_id)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* returns a sockaddr_in6 with embedded scope recovered and removed
|
|
|
|
*/
|
|
|
|
struct sockaddr_in6 *
|
|
|
|
sctp_recover_scope(struct sockaddr_in6 *addr, struct sockaddr_in6 *store)
|
|
|
|
{
|
|
|
|
/* check and strip embedded scope junk */
|
|
|
|
if (addr->sin6_family == AF_INET6) {
|
|
|
|
if (IN6_IS_SCOPE_LINKLOCAL(&addr->sin6_addr)) {
|
|
|
|
if (addr->sin6_scope_id == 0) {
|
|
|
|
*store = *addr;
|
|
|
|
if (!sa6_recoverscope(store)) {
|
|
|
|
/* use the recovered scope */
|
|
|
|
addr = store;
|
|
|
|
}
|
2007-02-12 23:24:31 +00:00
|
|
|
} else {
|
2006-11-03 15:23:16 +00:00
|
|
|
/* else, return the original "to" addr */
|
2007-02-12 23:24:31 +00:00
|
|
|
in6_clearscope(&addr->sin6_addr);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (addr);
|
|
|
|
}
|
2008-04-16 17:24:18 +00:00
|
|
|
#endif
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
/*
|
|
|
|
* are the two addresses the same? currently a "scopeless" check returns: 1
|
|
|
|
* if same, 0 if not
|
|
|
|
*/
|
2007-06-16 00:33:47 +00:00
|
|
|
int
|
2006-11-03 15:23:16 +00:00
|
|
|
sctp_cmpaddr(struct sockaddr *sa1, struct sockaddr *sa2)
|
|
|
|
{
|
|
|
|
|
|
|
|
/* must be valid */
|
|
|
|
if (sa1 == NULL || sa2 == NULL)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
/* must be the same family */
|
|
|
|
if (sa1->sa_family != sa2->sa_family)
|
|
|
|
return (0);
|
|
|
|
|
2008-04-16 17:24:18 +00:00
|
|
|
switch (sa1->sa_family) {
|
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6:
|
|
|
|
{
|
|
|
|
/* IPv6 addresses */
|
|
|
|
struct sockaddr_in6 *sin6_1, *sin6_2;
|
|
|
|
|
|
|
|
sin6_1 = (struct sockaddr_in6 *)sa1;
|
|
|
|
sin6_2 = (struct sockaddr_in6 *)sa2;
|
2008-05-20 13:47:46 +00:00
|
|
|
return (SCTP6_ARE_ADDR_EQUAL(sin6_1,
|
|
|
|
sin6_2));
|
2008-04-16 17:24:18 +00:00
|
|
|
}
|
|
|
|
#endif
|
2011-05-02 15:53:00 +00:00
|
|
|
#ifdef INET
|
2008-04-16 17:24:18 +00:00
|
|
|
case AF_INET:
|
|
|
|
{
|
|
|
|
/* IPv4 addresses */
|
|
|
|
struct sockaddr_in *sin_1, *sin_2;
|
|
|
|
|
|
|
|
sin_1 = (struct sockaddr_in *)sa1;
|
|
|
|
sin_2 = (struct sockaddr_in *)sa2;
|
|
|
|
return (sin_1->sin_addr.s_addr == sin_2->sin_addr.s_addr);
|
|
|
|
}
|
2011-05-02 15:53:00 +00:00
|
|
|
#endif
|
2008-04-16 17:24:18 +00:00
|
|
|
default:
|
2006-11-03 15:23:16 +00:00
|
|
|
/* we don't do these... */
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sctp_print_address(struct sockaddr *sa)
|
|
|
|
{
|
2008-04-16 17:24:18 +00:00
|
|
|
#ifdef INET6
|
2007-05-09 13:30:06 +00:00
|
|
|
char ip6buf[INET6_ADDRSTRLEN];
|
2008-04-16 17:24:18 +00:00
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2008-04-16 17:24:18 +00:00
|
|
|
switch (sa->sa_family) {
|
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6:
|
|
|
|
{
|
|
|
|
struct sockaddr_in6 *sin6;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2008-04-16 17:24:18 +00:00
|
|
|
sin6 = (struct sockaddr_in6 *)sa;
|
|
|
|
SCTP_PRINTF("IPv6 address: %s:port:%d scope:%u\n",
|
|
|
|
ip6_sprintf(ip6buf, &sin6->sin6_addr),
|
|
|
|
ntohs(sin6->sin6_port),
|
|
|
|
sin6->sin6_scope_id);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
2011-05-02 15:53:00 +00:00
|
|
|
#ifdef INET
|
2008-04-16 17:24:18 +00:00
|
|
|
case AF_INET:
|
|
|
|
{
|
|
|
|
struct sockaddr_in *sin;
|
|
|
|
unsigned char *p;
|
|
|
|
|
|
|
|
sin = (struct sockaddr_in *)sa;
|
|
|
|
p = (unsigned char *)&sin->sin_addr;
|
|
|
|
SCTP_PRINTF("IPv4 address: %u.%u.%u.%u:%d\n",
|
|
|
|
p[0], p[1], p[2], p[3], ntohs(sin->sin_port));
|
|
|
|
break;
|
|
|
|
}
|
2011-05-02 15:53:00 +00:00
|
|
|
#endif
|
2008-04-16 17:24:18 +00:00
|
|
|
default:
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTP_PRINTF("?\n");
|
2008-04-16 17:24:18 +00:00
|
|
|
break;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sctp_pull_off_control_to_new_inp(struct sctp_inpcb *old_inp,
|
|
|
|
struct sctp_inpcb *new_inp,
|
2007-05-02 12:50:13 +00:00
|
|
|
struct sctp_tcb *stcb,
|
|
|
|
int waitflags)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* go through our old INP and pull off any control structures that
|
|
|
|
* belong to stcb and move then to the new inp.
|
|
|
|
*/
|
|
|
|
struct socket *old_so, *new_so;
|
|
|
|
struct sctp_queued_to_read *control, *nctl;
|
|
|
|
struct sctp_readhead tmp_queue;
|
|
|
|
struct mbuf *m;
|
2007-04-03 11:15:32 +00:00
|
|
|
int error = 0;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
old_so = old_inp->sctp_socket;
|
|
|
|
new_so = new_inp->sctp_socket;
|
|
|
|
TAILQ_INIT(&tmp_queue);
|
2007-05-02 12:50:13 +00:00
|
|
|
error = sblock(&old_so->so_rcv, waitflags);
|
2006-11-03 15:23:16 +00:00
|
|
|
if (error) {
|
|
|
|
/*
|
|
|
|
* Gak, can't get sblock, we have a problem. data will be
|
|
|
|
* left stranded.. and we don't dare look at it since the
|
|
|
|
* other thread may be reading something. Oh well, its a
|
|
|
|
* screwed up app that does a peeloff OR a accept while
|
|
|
|
* reading from the main socket... actually its only the
|
|
|
|
* peeloff() case, since I think read will fail on a
|
|
|
|
* listening socket..
|
|
|
|
*/
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* lock the socket buffers */
|
|
|
|
SCTP_INP_READ_LOCK(old_inp);
|
2010-12-30 16:56:20 +00:00
|
|
|
TAILQ_FOREACH_SAFE(control, &old_inp->read_queue, next, nctl) {
|
|
|
|
/* Pull off all for out target stcb */
|
2006-11-03 15:23:16 +00:00
|
|
|
if (control->stcb == stcb) {
|
|
|
|
/* remove it we want it */
|
|
|
|
TAILQ_REMOVE(&old_inp->read_queue, control, next);
|
|
|
|
TAILQ_INSERT_TAIL(&tmp_queue, control, next);
|
|
|
|
m = control->data;
|
|
|
|
while (m) {
|
2008-06-14 07:58:05 +00:00
|
|
|
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SB_LOGGING_ENABLE) {
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_sblog(&old_so->so_rcv, control->do_not_ref_stcb ? NULL : stcb, SCTP_LOG_SBFREE, SCTP_BUF_LEN(m));
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
sctp_sbfree(control, stcb, &old_so->so_rcv, m);
|
2008-06-14 07:58:05 +00:00
|
|
|
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SB_LOGGING_ENABLE) {
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_sblog(&old_so->so_rcv, control->do_not_ref_stcb ? NULL : stcb, SCTP_LOG_SBRESULT, 0);
|
|
|
|
}
|
2006-12-29 20:21:42 +00:00
|
|
|
m = SCTP_BUF_NEXT(m);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SCTP_INP_READ_UNLOCK(old_inp);
|
|
|
|
/* Remove the sb-lock on the old socket */
|
|
|
|
|
|
|
|
sbunlock(&old_so->so_rcv);
|
|
|
|
/* Now we move them over to the new socket buffer */
|
|
|
|
SCTP_INP_READ_LOCK(new_inp);
|
2010-12-30 16:56:20 +00:00
|
|
|
TAILQ_FOREACH_SAFE(control, &tmp_queue, next, nctl) {
|
2006-11-03 15:23:16 +00:00
|
|
|
TAILQ_INSERT_TAIL(&new_inp->read_queue, control, next);
|
|
|
|
m = control->data;
|
|
|
|
while (m) {
|
2008-06-14 07:58:05 +00:00
|
|
|
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SB_LOGGING_ENABLE) {
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_sblog(&new_so->so_rcv, control->do_not_ref_stcb ? NULL : stcb, SCTP_LOG_SBALLOC, SCTP_BUF_LEN(m));
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
sctp_sballoc(stcb, &new_so->so_rcv, m);
|
2008-06-14 07:58:05 +00:00
|
|
|
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SB_LOGGING_ENABLE) {
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_sblog(&new_so->so_rcv, control->do_not_ref_stcb ? NULL : stcb, SCTP_LOG_SBRESULT, 0);
|
|
|
|
}
|
2006-12-29 20:21:42 +00:00
|
|
|
m = SCTP_BUF_NEXT(m);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
SCTP_INP_READ_UNLOCK(new_inp);
|
|
|
|
}
|
|
|
|
|
2016-04-07 09:10:34 +00:00
|
|
|
void
|
2016-04-18 20:16:41 +00:00
|
|
|
sctp_wakeup_the_read_socket(struct sctp_inpcb *inp,
|
|
|
|
struct sctp_tcb *stcb,
|
|
|
|
int so_locked
|
|
|
|
#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
|
|
|
|
SCTP_UNUSED
|
|
|
|
#endif
|
|
|
|
)
|
2016-04-07 09:10:34 +00:00
|
|
|
{
|
2016-04-18 20:16:41 +00:00
|
|
|
if ((inp != NULL) && (inp->sctp_socket != NULL)) {
|
2016-04-07 09:10:34 +00:00
|
|
|
#if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
|
2017-09-16 21:26:06 +00:00
|
|
|
struct socket *so;
|
2016-04-07 09:10:34 +00:00
|
|
|
|
2017-09-16 21:26:06 +00:00
|
|
|
so = SCTP_INP_SO(inp);
|
|
|
|
if (!so_locked) {
|
|
|
|
if (stcb) {
|
|
|
|
atomic_add_int(&stcb->asoc.refcnt, 1);
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
2016-04-07 09:10:34 +00:00
|
|
|
}
|
2017-09-16 21:26:06 +00:00
|
|
|
SCTP_SOCKET_LOCK(so, 1);
|
|
|
|
if (stcb) {
|
|
|
|
SCTP_TCB_LOCK(stcb);
|
|
|
|
atomic_subtract_int(&stcb->asoc.refcnt, 1);
|
|
|
|
}
|
|
|
|
if (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) {
|
2016-04-07 09:10:34 +00:00
|
|
|
SCTP_SOCKET_UNLOCK(so, 1);
|
2017-09-16 21:26:06 +00:00
|
|
|
return;
|
2016-04-07 09:10:34 +00:00
|
|
|
}
|
2017-09-16 21:26:06 +00:00
|
|
|
}
|
2016-04-07 09:10:34 +00:00
|
|
|
#endif
|
2017-09-16 21:26:06 +00:00
|
|
|
sctp_sorwakeup(inp, inp->sctp_socket);
|
|
|
|
#if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
|
|
|
|
if (!so_locked) {
|
|
|
|
SCTP_SOCKET_UNLOCK(so, 1);
|
2016-04-07 09:10:34 +00:00
|
|
|
}
|
2017-09-16 21:26:06 +00:00
|
|
|
#endif
|
2016-04-07 09:10:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
void
|
|
|
|
sctp_add_to_readq(struct sctp_inpcb *inp,
|
|
|
|
struct sctp_tcb *stcb,
|
|
|
|
struct sctp_queued_to_read *control,
|
|
|
|
struct sockbuf *sb,
|
2007-09-08 11:35:11 +00:00
|
|
|
int end,
|
2009-07-28 14:09:06 +00:00
|
|
|
int inp_read_lock_held,
|
2007-09-08 11:35:11 +00:00
|
|
|
int so_locked
|
|
|
|
#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
|
|
|
|
SCTP_UNUSED
|
|
|
|
#endif
|
|
|
|
)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Here we must place the control on the end of the socket read
|
2014-12-02 20:29:29 +00:00
|
|
|
* queue AND increment sb_cc so that select will work properly on
|
2006-11-03 15:23:16 +00:00
|
|
|
* read.
|
|
|
|
*/
|
|
|
|
struct mbuf *m, *prev = NULL;
|
|
|
|
|
2006-11-08 00:21:13 +00:00
|
|
|
if (inp == NULL) {
|
|
|
|
/* Gak, TSNH!! */
|
2006-12-14 17:02:55 +00:00
|
|
|
#ifdef INVARIANTS
|
2006-11-08 00:21:13 +00:00
|
|
|
panic("Gak, inp NULL on add_to_readq");
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
2009-07-28 14:09:06 +00:00
|
|
|
if (inp_read_lock_held == 0)
|
|
|
|
SCTP_INP_READ_LOCK(inp);
|
2010-06-18 09:01:44 +00:00
|
|
|
if (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_CANT_READ) {
|
|
|
|
sctp_free_remote_addr(control->whoFrom);
|
|
|
|
if (control->data) {
|
|
|
|
sctp_m_freem(control->data);
|
|
|
|
control->data = NULL;
|
|
|
|
}
|
2016-04-07 09:10:34 +00:00
|
|
|
sctp_free_a_readq(stcb, control);
|
2010-06-18 09:01:44 +00:00
|
|
|
if (inp_read_lock_held == 0)
|
|
|
|
SCTP_INP_READ_UNLOCK(inp);
|
|
|
|
return;
|
|
|
|
}
|
2007-03-15 11:27:14 +00:00
|
|
|
if (!(control->spec_flags & M_NOTIFICATION)) {
|
|
|
|
atomic_add_int(&inp->total_recvs, 1);
|
|
|
|
if (!control->do_not_ref_stcb) {
|
|
|
|
atomic_add_int(&stcb->total_recvs, 1);
|
|
|
|
}
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
m = control->data;
|
|
|
|
control->held_length = 0;
|
|
|
|
control->length = 0;
|
|
|
|
while (m) {
|
2006-12-29 20:21:42 +00:00
|
|
|
if (SCTP_BUF_LEN(m) == 0) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/* Skip mbufs with NO length */
|
|
|
|
if (prev == NULL) {
|
|
|
|
/* First one */
|
|
|
|
control->data = sctp_m_free(m);
|
|
|
|
m = control->data;
|
|
|
|
} else {
|
2006-12-29 20:21:42 +00:00
|
|
|
SCTP_BUF_NEXT(prev) = sctp_m_free(m);
|
|
|
|
m = SCTP_BUF_NEXT(prev);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
if (m == NULL) {
|
2010-01-07 21:01:37 +00:00
|
|
|
control->tail_mbuf = prev;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
prev = m;
|
2008-06-14 07:58:05 +00:00
|
|
|
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SB_LOGGING_ENABLE) {
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_sblog(sb, control->do_not_ref_stcb ? NULL : stcb, SCTP_LOG_SBALLOC, SCTP_BUF_LEN(m));
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
sctp_sballoc(stcb, sb, m);
|
2008-06-14 07:58:05 +00:00
|
|
|
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SB_LOGGING_ENABLE) {
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_sblog(sb, control->do_not_ref_stcb ? NULL : stcb, SCTP_LOG_SBRESULT, 0);
|
|
|
|
}
|
2006-12-29 20:21:42 +00:00
|
|
|
atomic_add_int(&control->length, SCTP_BUF_LEN(m));
|
|
|
|
m = SCTP_BUF_NEXT(m);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
if (prev != NULL) {
|
|
|
|
control->tail_mbuf = prev;
|
|
|
|
} else {
|
2006-12-29 20:21:42 +00:00
|
|
|
/* Everything got collapsed out?? */
|
2010-06-18 09:01:44 +00:00
|
|
|
sctp_free_remote_addr(control->whoFrom);
|
2016-04-07 09:10:34 +00:00
|
|
|
sctp_free_a_readq(stcb, control);
|
2009-07-28 14:09:06 +00:00
|
|
|
if (inp_read_lock_held == 0)
|
|
|
|
SCTP_INP_READ_UNLOCK(inp);
|
2006-11-03 15:23:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (end) {
|
|
|
|
control->end_added = 1;
|
|
|
|
}
|
|
|
|
TAILQ_INSERT_TAIL(&inp->read_queue, control, next);
|
2016-04-07 09:10:34 +00:00
|
|
|
control->on_read_q = 1;
|
2009-07-28 14:09:06 +00:00
|
|
|
if (inp_read_lock_held == 0)
|
|
|
|
SCTP_INP_READ_UNLOCK(inp);
|
2006-11-03 15:23:16 +00:00
|
|
|
if (inp && inp->sctp_socket) {
|
2016-04-18 20:16:41 +00:00
|
|
|
sctp_wakeup_the_read_socket(inp, stcb, so_locked);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************HOLD THIS COMMENT FOR PATCH FILE OF
|
|
|
|
*************ALTERNATE ROUTING CODE
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*************HOLD THIS COMMENT FOR END OF PATCH FILE OF
|
|
|
|
*************ALTERNATE ROUTING CODE
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct mbuf *
|
2014-03-16 12:32:16 +00:00
|
|
|
sctp_generate_cause(uint16_t code, char *info)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
|
|
|
struct mbuf *m;
|
2014-03-16 12:32:16 +00:00
|
|
|
struct sctp_gen_error_cause *cause;
|
2016-03-27 10:04:25 +00:00
|
|
|
size_t info_len;
|
|
|
|
uint16_t len;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2014-03-16 12:32:16 +00:00
|
|
|
if ((code == 0) || (info == NULL)) {
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
info_len = strlen(info);
|
2016-03-27 10:04:25 +00:00
|
|
|
if (info_len > (SCTP_MAX_CAUSE_LENGTH - sizeof(struct sctp_paramhdr))) {
|
|
|
|
return (NULL);
|
|
|
|
}
|
2018-07-19 20:11:14 +00:00
|
|
|
len = (uint16_t)(sizeof(struct sctp_paramhdr) + info_len);
|
2014-03-16 12:32:16 +00:00
|
|
|
m = sctp_get_mbuf_for_msg(len, 0, M_NOWAIT, 1, MT_DATA);
|
|
|
|
if (m != NULL) {
|
|
|
|
SCTP_BUF_LEN(m) = len;
|
|
|
|
cause = mtod(m, struct sctp_gen_error_cause *);
|
|
|
|
cause->code = htons(code);
|
2016-03-27 10:04:25 +00:00
|
|
|
cause->length = htons(len);
|
2014-03-16 12:32:16 +00:00
|
|
|
memcpy(cause->info, info, info_len);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
return (m);
|
|
|
|
}
|
|
|
|
|
2014-04-19 19:21:06 +00:00
|
|
|
struct mbuf *
|
|
|
|
sctp_generate_no_user_data_cause(uint32_t tsn)
|
|
|
|
{
|
|
|
|
struct mbuf *m;
|
|
|
|
struct sctp_error_no_user_data *no_user_data_cause;
|
2016-03-27 10:04:25 +00:00
|
|
|
uint16_t len;
|
2014-04-19 19:21:06 +00:00
|
|
|
|
2018-07-19 20:11:14 +00:00
|
|
|
len = (uint16_t)sizeof(struct sctp_error_no_user_data);
|
2014-04-19 19:21:06 +00:00
|
|
|
m = sctp_get_mbuf_for_msg(len, 0, M_NOWAIT, 1, MT_DATA);
|
|
|
|
if (m != NULL) {
|
|
|
|
SCTP_BUF_LEN(m) = len;
|
|
|
|
no_user_data_cause = mtod(m, struct sctp_error_no_user_data *);
|
|
|
|
no_user_data_cause->cause.code = htons(SCTP_CAUSE_NO_USER_DATA);
|
2016-03-27 10:04:25 +00:00
|
|
|
no_user_data_cause->cause.length = htons(len);
|
2016-12-11 13:26:35 +00:00
|
|
|
no_user_data_cause->tsn = htonl(tsn);
|
2014-04-19 19:21:06 +00:00
|
|
|
}
|
|
|
|
return (m);
|
|
|
|
}
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
#ifdef SCTP_MBCNT_LOGGING
|
|
|
|
void
|
|
|
|
sctp_free_bufspace(struct sctp_tcb *stcb, struct sctp_association *asoc,
|
|
|
|
struct sctp_tmit_chunk *tp1, int chk_cnt)
|
|
|
|
{
|
|
|
|
if (tp1->data == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
asoc->chunks_on_out_queue -= chk_cnt;
|
2008-06-14 07:58:05 +00:00
|
|
|
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MBCNT_LOGGING_ENABLE) {
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_log_mbcnt(SCTP_LOG_MBCNT_DECREASE,
|
|
|
|
asoc->total_output_queue_size,
|
|
|
|
tp1->book_size,
|
|
|
|
0,
|
|
|
|
tp1->mbcnt);
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
if (asoc->total_output_queue_size >= tp1->book_size) {
|
2007-01-15 15:12:10 +00:00
|
|
|
atomic_add_int(&asoc->total_output_queue_size, -tp1->book_size);
|
2006-11-03 15:23:16 +00:00
|
|
|
} else {
|
|
|
|
asoc->total_output_queue_size = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stcb->sctp_socket && (((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL)) ||
|
|
|
|
((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE)))) {
|
2014-12-02 20:29:29 +00:00
|
|
|
if (stcb->sctp_socket->so_snd.sb_cc >= tp1->book_size) {
|
|
|
|
stcb->sctp_socket->so_snd.sb_cc -= tp1->book_size;
|
2006-11-03 15:23:16 +00:00
|
|
|
} else {
|
2014-12-02 20:29:29 +00:00
|
|
|
stcb->sctp_socket->so_snd.sb_cc = 0;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int
|
|
|
|
sctp_release_pr_sctp_chunk(struct sctp_tcb *stcb, struct sctp_tmit_chunk *tp1,
|
2012-05-13 19:32:49 +00:00
|
|
|
uint8_t sent, int so_locked
|
2007-09-08 11:35:11 +00:00
|
|
|
#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
|
|
|
|
SCTP_UNUSED
|
|
|
|
#endif
|
|
|
|
)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
2009-03-14 13:42:13 +00:00
|
|
|
struct sctp_stream_out *strq;
|
2010-12-30 16:56:20 +00:00
|
|
|
struct sctp_tmit_chunk *chk = NULL, *tp2;
|
2009-03-14 13:42:13 +00:00
|
|
|
struct sctp_stream_queue_pending *sp;
|
2016-12-07 19:30:59 +00:00
|
|
|
uint32_t mid;
|
|
|
|
uint16_t sid;
|
2009-03-14 13:42:13 +00:00
|
|
|
uint8_t foundeom = 0;
|
2006-11-03 15:23:16 +00:00
|
|
|
int ret_sz = 0;
|
|
|
|
int notdone;
|
2009-03-14 13:42:13 +00:00
|
|
|
int do_wakeup_routine = 0;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2016-12-07 19:30:59 +00:00
|
|
|
sid = tp1->rec.data.sid;
|
|
|
|
mid = tp1->rec.data.mid;
|
2014-08-13 15:50:16 +00:00
|
|
|
if (sent || !(tp1->rec.data.rcv_flags & SCTP_DATA_FIRST_FRAG)) {
|
|
|
|
stcb->asoc.abandoned_sent[0]++;
|
|
|
|
stcb->asoc.abandoned_sent[PR_SCTP_POLICY(tp1->flags)]++;
|
2016-12-07 19:30:59 +00:00
|
|
|
stcb->asoc.strmout[sid].abandoned_sent[0]++;
|
2014-08-13 15:50:16 +00:00
|
|
|
#if defined(SCTP_DETAILED_STR_STATS)
|
2017-11-24 12:18:48 +00:00
|
|
|
stcb->asoc.strmout[sid].abandoned_sent[PR_SCTP_POLICY(tp1->flags)]++;
|
2014-08-13 15:50:16 +00:00
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
stcb->asoc.abandoned_unsent[0]++;
|
|
|
|
stcb->asoc.abandoned_unsent[PR_SCTP_POLICY(tp1->flags)]++;
|
2016-12-07 19:30:59 +00:00
|
|
|
stcb->asoc.strmout[sid].abandoned_unsent[0]++;
|
2014-08-13 15:50:16 +00:00
|
|
|
#if defined(SCTP_DETAILED_STR_STATS)
|
2017-11-24 12:18:48 +00:00
|
|
|
stcb->asoc.strmout[sid].abandoned_unsent[PR_SCTP_POLICY(tp1->flags)]++;
|
2014-08-13 15:50:16 +00:00
|
|
|
#endif
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
do {
|
|
|
|
ret_sz += tp1->book_size;
|
2009-03-14 13:42:13 +00:00
|
|
|
if (tp1->data != NULL) {
|
2009-04-04 11:43:32 +00:00
|
|
|
if (tp1->sent < SCTP_DATAGRAM_RESEND) {
|
|
|
|
sctp_flight_size_decrease(tp1);
|
|
|
|
sctp_total_flight_decrease(stcb, tp1);
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
sctp_free_bufspace(stcb, &stcb->asoc, tp1, 1);
|
2009-03-14 13:42:13 +00:00
|
|
|
stcb->asoc.peers_rwnd += tp1->send_size;
|
|
|
|
stcb->asoc.peers_rwnd += SCTP_BASE_SYSCTL(sctp_peer_chunk_oh);
|
2012-05-13 19:32:49 +00:00
|
|
|
if (sent) {
|
|
|
|
sctp_ulp_notify(SCTP_NOTIFY_SENT_DG_FAIL, stcb, 0, tp1, so_locked);
|
|
|
|
} else {
|
|
|
|
sctp_ulp_notify(SCTP_NOTIFY_UNSENT_DG_FAIL, stcb, 0, tp1, so_locked);
|
|
|
|
}
|
2009-08-19 12:02:28 +00:00
|
|
|
if (tp1->data) {
|
|
|
|
sctp_m_freem(tp1->data);
|
|
|
|
tp1->data = NULL;
|
|
|
|
}
|
2009-03-14 13:42:13 +00:00
|
|
|
do_wakeup_routine = 1;
|
|
|
|
if (PR_SCTP_BUF_ENABLED(tp1->flags)) {
|
|
|
|
stcb->asoc.sent_queue_cnt_removeable--;
|
2007-09-08 11:35:11 +00:00
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2009-04-04 11:43:32 +00:00
|
|
|
tp1->sent = SCTP_FORWARD_TSN_SKIP;
|
2006-11-03 15:23:16 +00:00
|
|
|
if ((tp1->rec.data.rcv_flags & SCTP_DATA_NOT_FRAG) ==
|
|
|
|
SCTP_DATA_NOT_FRAG) {
|
|
|
|
/* not frag'ed we ae done */
|
|
|
|
notdone = 0;
|
|
|
|
foundeom = 1;
|
|
|
|
} else if (tp1->rec.data.rcv_flags & SCTP_DATA_LAST_FRAG) {
|
|
|
|
/* end of frag, we are done */
|
|
|
|
notdone = 0;
|
|
|
|
foundeom = 1;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Its a begin or middle piece, we must mark all of
|
|
|
|
* it
|
|
|
|
*/
|
|
|
|
notdone = 1;
|
|
|
|
tp1 = TAILQ_NEXT(tp1, sctp_next);
|
|
|
|
}
|
|
|
|
} while (tp1 && notdone);
|
2009-03-14 13:42:13 +00:00
|
|
|
if (foundeom == 0) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/*
|
|
|
|
* The multi-part message was scattered across the send and
|
|
|
|
* sent queue.
|
|
|
|
*/
|
2010-12-30 16:56:20 +00:00
|
|
|
TAILQ_FOREACH_SAFE(tp1, &stcb->asoc.send_queue, sctp_next, tp2) {
|
2016-12-07 19:30:59 +00:00
|
|
|
if ((tp1->rec.data.sid != sid) ||
|
|
|
|
(!SCTP_MID_EQ(stcb->asoc.idata_supported, tp1->rec.data.mid, mid))) {
|
2010-12-30 16:56:20 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-03-14 13:42:13 +00:00
|
|
|
/*
|
|
|
|
* save to chk in case we have some on stream out
|
|
|
|
* queue. If so and we have an un-transmitted one we
|
|
|
|
* don't have to fudge the TSN.
|
|
|
|
*/
|
|
|
|
chk = tp1;
|
|
|
|
ret_sz += tp1->book_size;
|
|
|
|
sctp_free_bufspace(stcb, &stcb->asoc, tp1, 1);
|
2012-05-13 19:32:49 +00:00
|
|
|
if (sent) {
|
|
|
|
sctp_ulp_notify(SCTP_NOTIFY_SENT_DG_FAIL, stcb, 0, tp1, so_locked);
|
|
|
|
} else {
|
|
|
|
sctp_ulp_notify(SCTP_NOTIFY_UNSENT_DG_FAIL, stcb, 0, tp1, so_locked);
|
|
|
|
}
|
2009-08-19 12:02:28 +00:00
|
|
|
if (tp1->data) {
|
|
|
|
sctp_m_freem(tp1->data);
|
|
|
|
tp1->data = NULL;
|
|
|
|
}
|
2009-04-04 11:43:32 +00:00
|
|
|
/* No flight involved here book the size to 0 */
|
|
|
|
tp1->book_size = 0;
|
2009-03-14 13:42:13 +00:00
|
|
|
if (tp1->rec.data.rcv_flags & SCTP_DATA_LAST_FRAG) {
|
|
|
|
foundeom = 1;
|
|
|
|
}
|
|
|
|
do_wakeup_routine = 1;
|
|
|
|
tp1->sent = SCTP_FORWARD_TSN_SKIP;
|
|
|
|
TAILQ_REMOVE(&stcb->asoc.send_queue, tp1, sctp_next);
|
2016-12-26 11:06:41 +00:00
|
|
|
/*
|
|
|
|
* on to the sent queue so we can wait for it to be
|
|
|
|
* passed by.
|
|
|
|
*/
|
2009-03-14 13:42:13 +00:00
|
|
|
TAILQ_INSERT_TAIL(&stcb->asoc.sent_queue, tp1,
|
|
|
|
sctp_next);
|
|
|
|
stcb->asoc.send_queue_cnt--;
|
|
|
|
stcb->asoc.sent_queue_cnt++;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
2009-03-14 13:42:13 +00:00
|
|
|
if (foundeom == 0) {
|
|
|
|
/*
|
|
|
|
* Still no eom found. That means there is stuff left on the
|
|
|
|
* stream out queue.. yuck.
|
|
|
|
*/
|
|
|
|
SCTP_TCB_SEND_LOCK(stcb);
|
2016-12-07 19:30:59 +00:00
|
|
|
strq = &stcb->asoc.strmout[sid];
|
2012-11-05 20:55:17 +00:00
|
|
|
sp = TAILQ_FIRST(&strq->outqueue);
|
|
|
|
if (sp != NULL) {
|
|
|
|
sp->discard_rest = 1;
|
|
|
|
/*
|
|
|
|
* We may need to put a chunk on the queue that
|
|
|
|
* holds the TSN that would have been sent with the
|
|
|
|
* LAST bit.
|
|
|
|
*/
|
|
|
|
if (chk == NULL) {
|
|
|
|
/* Yep, we have to */
|
|
|
|
sctp_alloc_a_chunk(stcb, chk);
|
2009-03-14 13:42:13 +00:00
|
|
|
if (chk == NULL) {
|
|
|
|
/*
|
2012-11-05 20:55:17 +00:00
|
|
|
* we are hosed. All we can do is
|
|
|
|
* nothing.. which will cause an
|
|
|
|
* abort if the peer is paying
|
|
|
|
* attention.
|
2009-03-14 13:42:13 +00:00
|
|
|
*/
|
2012-11-05 20:55:17 +00:00
|
|
|
goto oh_well;
|
2009-03-14 13:42:13 +00:00
|
|
|
}
|
2012-11-05 20:55:17 +00:00
|
|
|
memset(chk, 0, sizeof(*chk));
|
2016-06-08 17:57:42 +00:00
|
|
|
chk->rec.data.rcv_flags = 0;
|
2012-11-05 20:55:17 +00:00
|
|
|
chk->sent = SCTP_FORWARD_TSN_SKIP;
|
|
|
|
chk->asoc = &stcb->asoc;
|
2016-06-08 17:57:42 +00:00
|
|
|
if (stcb->asoc.idata_supported == 0) {
|
|
|
|
if (sp->sinfo_flags & SCTP_UNORDERED) {
|
2016-12-07 19:30:59 +00:00
|
|
|
chk->rec.data.mid = 0;
|
2016-06-08 17:57:42 +00:00
|
|
|
} else {
|
2016-12-07 19:30:59 +00:00
|
|
|
chk->rec.data.mid = strq->next_mid_ordered;
|
2016-06-08 17:57:42 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (sp->sinfo_flags & SCTP_UNORDERED) {
|
2016-12-07 19:30:59 +00:00
|
|
|
chk->rec.data.mid = strq->next_mid_unordered;
|
2016-06-08 17:57:42 +00:00
|
|
|
} else {
|
2016-12-07 19:30:59 +00:00
|
|
|
chk->rec.data.mid = strq->next_mid_ordered;
|
2016-06-08 17:57:42 +00:00
|
|
|
}
|
|
|
|
}
|
2016-12-07 19:30:59 +00:00
|
|
|
chk->rec.data.sid = sp->sid;
|
|
|
|
chk->rec.data.ppid = sp->ppid;
|
2012-11-05 20:55:17 +00:00
|
|
|
chk->rec.data.context = sp->context;
|
|
|
|
chk->flags = sp->act_flags;
|
2015-03-24 14:51:46 +00:00
|
|
|
chk->whoTo = NULL;
|
2016-12-07 19:30:59 +00:00
|
|
|
chk->rec.data.tsn = atomic_fetchadd_int(&stcb->asoc.sending_seq, 1);
|
2015-03-24 14:51:46 +00:00
|
|
|
strq->chunks_on_queues++;
|
2012-11-05 20:55:17 +00:00
|
|
|
TAILQ_INSERT_TAIL(&stcb->asoc.sent_queue, chk, sctp_next);
|
|
|
|
stcb->asoc.sent_queue_cnt++;
|
|
|
|
stcb->asoc.pr_sctp_cnt++;
|
2016-06-08 17:57:42 +00:00
|
|
|
}
|
|
|
|
chk->rec.data.rcv_flags |= SCTP_DATA_LAST_FRAG;
|
2016-08-06 12:33:15 +00:00
|
|
|
if (sp->sinfo_flags & SCTP_UNORDERED) {
|
|
|
|
chk->rec.data.rcv_flags |= SCTP_DATA_UNORDERED;
|
|
|
|
}
|
2016-06-08 17:57:42 +00:00
|
|
|
if (stcb->asoc.idata_supported == 0) {
|
|
|
|
if ((sp->sinfo_flags & SCTP_UNORDERED) == 0) {
|
|
|
|
strq->next_mid_ordered++;
|
|
|
|
}
|
2012-11-05 20:55:17 +00:00
|
|
|
} else {
|
2016-06-08 17:57:42 +00:00
|
|
|
if (sp->sinfo_flags & SCTP_UNORDERED) {
|
|
|
|
strq->next_mid_unordered++;
|
|
|
|
} else {
|
|
|
|
strq->next_mid_ordered++;
|
|
|
|
}
|
2009-03-14 13:42:13 +00:00
|
|
|
}
|
2012-11-05 20:55:17 +00:00
|
|
|
oh_well:
|
|
|
|
if (sp->data) {
|
|
|
|
/*
|
|
|
|
* Pull any data to free up the SB and allow
|
|
|
|
* sender to "add more" while we will throw
|
|
|
|
* away :-)
|
|
|
|
*/
|
|
|
|
sctp_free_spbufspace(stcb, &stcb->asoc, sp);
|
|
|
|
ret_sz += sp->length;
|
|
|
|
do_wakeup_routine = 1;
|
|
|
|
sp->some_taken = 1;
|
|
|
|
sctp_m_freem(sp->data);
|
|
|
|
sp->data = NULL;
|
|
|
|
sp->tail_mbuf = NULL;
|
|
|
|
sp->length = 0;
|
|
|
|
}
|
|
|
|
}
|
2009-03-14 13:42:13 +00:00
|
|
|
SCTP_TCB_SEND_UNLOCK(stcb);
|
|
|
|
}
|
|
|
|
if (do_wakeup_routine) {
|
2012-06-25 17:15:09 +00:00
|
|
|
#if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
|
2009-04-04 11:43:32 +00:00
|
|
|
struct socket *so;
|
|
|
|
|
2009-03-14 13:42:13 +00:00
|
|
|
so = SCTP_INP_SO(stcb->sctp_ep);
|
|
|
|
if (!so_locked) {
|
|
|
|
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->asoc.state & SCTP_STATE_CLOSED_SOCKET) {
|
|
|
|
/* assoc was freed while we were unlocked */
|
|
|
|
SCTP_SOCKET_UNLOCK(so, 1);
|
|
|
|
return (ret_sz);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
sctp_sowwakeup(stcb->sctp_ep, stcb->sctp_socket);
|
2012-06-25 17:15:09 +00:00
|
|
|
#if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
|
2009-03-14 13:42:13 +00:00
|
|
|
if (!so_locked) {
|
|
|
|
SCTP_SOCKET_UNLOCK(so, 1);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
return (ret_sz);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* checks to see if the given address, sa, is one that is currently known by
|
|
|
|
* the kernel note: can't distinguish the same address on multiple interfaces
|
|
|
|
* and doesn't handle multiple addresses with different zone/scope id's note:
|
|
|
|
* ifa_ifwithaddr() compares the entire sockaddr struct
|
|
|
|
*/
|
2007-03-15 11:27:14 +00:00
|
|
|
struct sctp_ifa *
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_find_ifa_in_ep(struct sctp_inpcb *inp, struct sockaddr *addr,
|
|
|
|
int holds_lock)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
2007-03-15 11:27:14 +00:00
|
|
|
struct sctp_laddr *laddr;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2007-05-09 13:30:06 +00:00
|
|
|
if (holds_lock == 0) {
|
2007-03-15 11:27:14 +00:00
|
|
|
SCTP_INP_RLOCK(inp);
|
2007-05-09 13:30:06 +00:00
|
|
|
}
|
2018-07-19 20:16:33 +00:00
|
|
|
|
2007-03-15 11:27:14 +00:00
|
|
|
LIST_FOREACH(laddr, &inp->sctp_addr_list, sctp_nxt_addr) {
|
|
|
|
if (laddr->ifa == NULL)
|
|
|
|
continue;
|
|
|
|
if (addr->sa_family != laddr->ifa->address.sa.sa_family)
|
|
|
|
continue;
|
2011-04-30 11:18:16 +00:00
|
|
|
#ifdef INET
|
2007-03-15 11:27:14 +00:00
|
|
|
if (addr->sa_family == AF_INET) {
|
|
|
|
if (((struct sockaddr_in *)addr)->sin_addr.s_addr ==
|
|
|
|
laddr->ifa->address.sin.sin_addr.s_addr) {
|
|
|
|
/* found him. */
|
2007-05-09 13:30:06 +00:00
|
|
|
if (holds_lock == 0) {
|
2007-03-15 11:27:14 +00:00
|
|
|
SCTP_INP_RUNLOCK(inp);
|
2007-05-09 13:30:06 +00:00
|
|
|
}
|
2007-03-15 11:27:14 +00:00
|
|
|
return (laddr->ifa);
|
|
|
|
break;
|
|
|
|
}
|
2008-04-16 17:24:18 +00:00
|
|
|
}
|
2011-04-30 11:18:16 +00:00
|
|
|
#endif
|
2008-04-16 17:24:18 +00:00
|
|
|
#ifdef INET6
|
|
|
|
if (addr->sa_family == AF_INET6) {
|
2008-05-20 13:47:46 +00:00
|
|
|
if (SCTP6_ARE_ADDR_EQUAL((struct sockaddr_in6 *)addr,
|
|
|
|
&laddr->ifa->address.sin6)) {
|
2007-03-15 11:27:14 +00:00
|
|
|
/* found him. */
|
2007-05-09 13:30:06 +00:00
|
|
|
if (holds_lock == 0) {
|
2007-03-15 11:27:14 +00:00
|
|
|
SCTP_INP_RUNLOCK(inp);
|
2007-05-09 13:30:06 +00:00
|
|
|
}
|
2007-03-15 11:27:14 +00:00
|
|
|
return (laddr->ifa);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-04-16 17:24:18 +00:00
|
|
|
#endif
|
2007-03-15 11:27:14 +00:00
|
|
|
}
|
2007-05-09 13:30:06 +00:00
|
|
|
if (holds_lock == 0) {
|
2007-03-15 11:27:14 +00:00
|
|
|
SCTP_INP_RUNLOCK(inp);
|
2007-05-09 13:30:06 +00:00
|
|
|
}
|
2007-03-15 11:27:14 +00:00
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
2007-03-19 11:11:16 +00:00
|
|
|
uint32_t
|
2018-07-19 20:11:14 +00:00
|
|
|
sctp_get_ifa_hash_val(struct sockaddr *addr)
|
|
|
|
{
|
2011-05-02 15:53:00 +00:00
|
|
|
switch (addr->sa_family) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
|
|
|
{
|
|
|
|
struct sockaddr_in *sin;
|
2007-03-19 11:11:16 +00:00
|
|
|
|
2011-05-02 15:53:00 +00:00
|
|
|
sin = (struct sockaddr_in *)addr;
|
|
|
|
return (sin->sin_addr.s_addr ^ (sin->sin_addr.s_addr >> 16));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
2012-12-27 08:02:58 +00:00
|
|
|
case AF_INET6:
|
2011-05-02 15:53:00 +00:00
|
|
|
{
|
|
|
|
struct sockaddr_in6 *sin6;
|
|
|
|
uint32_t hash_of_addr;
|
2007-03-19 11:11:16 +00:00
|
|
|
|
2011-05-02 15:53:00 +00:00
|
|
|
sin6 = (struct sockaddr_in6 *)addr;
|
|
|
|
hash_of_addr = (sin6->sin6_addr.s6_addr32[0] +
|
|
|
|
sin6->sin6_addr.s6_addr32[1] +
|
|
|
|
sin6->sin6_addr.s6_addr32[2] +
|
|
|
|
sin6->sin6_addr.s6_addr32[3]);
|
|
|
|
hash_of_addr = (hash_of_addr ^ (hash_of_addr >> 16));
|
|
|
|
return (hash_of_addr);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
break;
|
2007-03-19 11:11:16 +00:00
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2007-03-15 11:27:14 +00:00
|
|
|
struct sctp_ifa *
|
|
|
|
sctp_find_ifa_by_addr(struct sockaddr *addr, uint32_t vrf_id, int holds_lock)
|
|
|
|
{
|
|
|
|
struct sctp_ifa *sctp_ifap;
|
|
|
|
struct sctp_vrf *vrf;
|
2007-03-19 11:11:16 +00:00
|
|
|
struct sctp_ifalist *hash_head;
|
|
|
|
uint32_t hash_of_addr;
|
2007-03-15 11:27:14 +00:00
|
|
|
|
2007-04-03 11:15:32 +00:00
|
|
|
if (holds_lock == 0)
|
2007-09-18 15:16:39 +00:00
|
|
|
SCTP_IPI_ADDR_RLOCK();
|
2007-04-03 11:15:32 +00:00
|
|
|
|
2007-03-15 11:27:14 +00:00
|
|
|
vrf = sctp_find_vrf(vrf_id);
|
2007-04-03 11:15:32 +00:00
|
|
|
if (vrf == NULL) {
|
|
|
|
if (holds_lock == 0)
|
2007-09-18 15:16:39 +00:00
|
|
|
SCTP_IPI_ADDR_RUNLOCK();
|
2007-03-15 11:27:14 +00:00
|
|
|
return (NULL);
|
2007-04-03 11:15:32 +00:00
|
|
|
}
|
2018-07-19 20:16:33 +00:00
|
|
|
|
2007-03-19 11:11:16 +00:00
|
|
|
hash_of_addr = sctp_get_ifa_hash_val(addr);
|
2007-03-15 11:27:14 +00:00
|
|
|
|
2007-05-08 00:21:05 +00:00
|
|
|
hash_head = &vrf->vrf_addr_hash[(hash_of_addr & vrf->vrf_addr_hashmark)];
|
2007-04-03 11:15:32 +00:00
|
|
|
if (hash_head == NULL) {
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTP_PRINTF("hash_of_addr:%x mask:%x table:%x - ",
|
2018-07-19 20:11:14 +00:00
|
|
|
hash_of_addr, (uint32_t)vrf->vrf_addr_hashmark,
|
|
|
|
(uint32_t)(hash_of_addr & vrf->vrf_addr_hashmark));
|
2007-04-03 11:15:32 +00:00
|
|
|
sctp_print_address(addr);
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTP_PRINTF("No such bucket for address\n");
|
2007-04-03 11:15:32 +00:00
|
|
|
if (holds_lock == 0)
|
2007-09-18 15:16:39 +00:00
|
|
|
SCTP_IPI_ADDR_RUNLOCK();
|
2007-04-03 11:15:32 +00:00
|
|
|
|
|
|
|
return (NULL);
|
|
|
|
}
|
2007-03-19 11:11:16 +00:00
|
|
|
LIST_FOREACH(sctp_ifap, hash_head, next_bucket) {
|
|
|
|
if (addr->sa_family != sctp_ifap->address.sa.sa_family)
|
|
|
|
continue;
|
2011-04-30 11:18:16 +00:00
|
|
|
#ifdef INET
|
2007-03-19 11:11:16 +00:00
|
|
|
if (addr->sa_family == AF_INET) {
|
|
|
|
if (((struct sockaddr_in *)addr)->sin_addr.s_addr ==
|
|
|
|
sctp_ifap->address.sin.sin_addr.s_addr) {
|
|
|
|
/* found him. */
|
|
|
|
if (holds_lock == 0)
|
2007-09-18 15:16:39 +00:00
|
|
|
SCTP_IPI_ADDR_RUNLOCK();
|
2007-03-19 11:11:16 +00:00
|
|
|
return (sctp_ifap);
|
|
|
|
break;
|
|
|
|
}
|
2008-04-16 17:24:18 +00:00
|
|
|
}
|
2011-04-30 11:18:16 +00:00
|
|
|
#endif
|
2008-04-16 17:24:18 +00:00
|
|
|
#ifdef INET6
|
|
|
|
if (addr->sa_family == AF_INET6) {
|
2008-05-20 13:47:46 +00:00
|
|
|
if (SCTP6_ARE_ADDR_EQUAL((struct sockaddr_in6 *)addr,
|
|
|
|
&sctp_ifap->address.sin6)) {
|
2007-03-19 11:11:16 +00:00
|
|
|
/* found him. */
|
|
|
|
if (holds_lock == 0)
|
2007-09-18 15:16:39 +00:00
|
|
|
SCTP_IPI_ADDR_RUNLOCK();
|
2007-03-19 11:11:16 +00:00
|
|
|
return (sctp_ifap);
|
|
|
|
break;
|
|
|
|
}
|
2007-03-15 11:27:14 +00:00
|
|
|
}
|
2008-04-16 17:24:18 +00:00
|
|
|
#endif
|
2007-03-15 11:27:14 +00:00
|
|
|
}
|
|
|
|
if (holds_lock == 0)
|
2007-09-18 15:16:39 +00:00
|
|
|
SCTP_IPI_ADDR_RUNLOCK();
|
2006-11-03 15:23:16 +00:00
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-07-19 20:11:14 +00:00
|
|
|
sctp_user_rcvd(struct sctp_tcb *stcb, uint32_t *freed_so_far, int hold_rlock,
|
2006-11-03 15:23:16 +00:00
|
|
|
uint32_t rwnd_req)
|
|
|
|
{
|
|
|
|
/* User pulled some data, do we need a rwnd update? */
|
|
|
|
int r_unlocked = 0;
|
|
|
|
uint32_t dif, rwnd;
|
|
|
|
struct socket *so = NULL;
|
|
|
|
|
|
|
|
if (stcb == NULL)
|
|
|
|
return;
|
|
|
|
|
2006-11-05 13:25:18 +00:00
|
|
|
atomic_add_int(&stcb->asoc.refcnt, 1);
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2018-08-13 13:58:45 +00:00
|
|
|
if ((SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_ACK_SENT) ||
|
2018-08-13 11:56:21 +00:00
|
|
|
(stcb->asoc.state & (SCTP_STATE_ABOUT_TO_BE_FREED | SCTP_STATE_SHUTDOWN_RECEIVED))) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/* Pre-check If we are freeing no update */
|
|
|
|
goto no_lock;
|
|
|
|
}
|
|
|
|
SCTP_INP_INCR_REF(stcb->sctp_ep);
|
|
|
|
if ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) ||
|
|
|
|
(stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE)) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
so = stcb->sctp_socket;
|
|
|
|
if (so == NULL) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
atomic_add_int(&stcb->freed_by_sorcv_sincelast, *freed_so_far);
|
|
|
|
/* Have you have freed enough to look */
|
|
|
|
*freed_so_far = 0;
|
|
|
|
/* Yep, its worth a look and the lock overhead */
|
|
|
|
|
|
|
|
/* Figure out what the rwnd would be */
|
|
|
|
rwnd = sctp_calc_rwnd(stcb, &stcb->asoc);
|
|
|
|
if (rwnd >= stcb->asoc.my_last_reported_rwnd) {
|
|
|
|
dif = rwnd - stcb->asoc.my_last_reported_rwnd;
|
|
|
|
} else {
|
|
|
|
dif = 0;
|
|
|
|
}
|
|
|
|
if (dif >= rwnd_req) {
|
|
|
|
if (hold_rlock) {
|
|
|
|
SCTP_INP_READ_UNLOCK(stcb->sctp_ep);
|
|
|
|
r_unlocked = 1;
|
|
|
|
}
|
|
|
|
if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
|
|
|
|
/*
|
|
|
|
* One last check before we allow the guy possibly
|
|
|
|
* to get in. There is a race, where the guy has not
|
|
|
|
* reached the gate. In that case
|
|
|
|
*/
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
SCTP_TCB_LOCK(stcb);
|
|
|
|
if (stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
|
|
|
|
/* No reports here */
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
SCTP_STAT_INCR(sctps_wu_sacks_sent);
|
2011-05-08 09:11:59 +00:00
|
|
|
sctp_send_sack(stcb, SCTP_SO_LOCKED);
|
2008-12-06 13:19:54 +00:00
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
sctp_chunk_output(stcb->sctp_ep, stcb,
|
2007-09-08 11:35:11 +00:00
|
|
|
SCTP_OUTPUT_FROM_USR_RCVD, SCTP_SO_LOCKED);
|
2006-11-03 15:23:16 +00:00
|
|
|
/* make sure no timer is running */
|
2015-05-28 16:39:22 +00:00
|
|
|
sctp_timer_stop(SCTP_TIMER_TYPE_RECV, stcb->sctp_ep, stcb, NULL,
|
|
|
|
SCTP_FROM_SCTPUTIL + SCTP_LOC_6);
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
} else {
|
|
|
|
/* Update how much we have pending */
|
|
|
|
stcb->freed_by_sorcv_sincelast = dif;
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
if (so && r_unlocked && hold_rlock) {
|
|
|
|
SCTP_INP_READ_LOCK(stcb->sctp_ep);
|
|
|
|
}
|
2018-07-19 20:16:33 +00:00
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
SCTP_INP_DECR_REF(stcb->sctp_ep);
|
|
|
|
no_lock:
|
2006-11-05 13:25:18 +00:00
|
|
|
atomic_add_int(&stcb->asoc.refcnt, -1);
|
2006-11-03 15:23:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
sctp_sorecvmsg(struct socket *so,
|
|
|
|
struct uio *uio,
|
|
|
|
struct mbuf **mp,
|
|
|
|
struct sockaddr *from,
|
|
|
|
int fromlen,
|
|
|
|
int *msg_flags,
|
|
|
|
struct sctp_sndrcvinfo *sinfo,
|
|
|
|
int filling_sinfo)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* MSG flags we will look at MSG_DONTWAIT - non-blocking IO.
|
|
|
|
* MSG_PEEK - Look don't touch :-D (only valid with OUT mbuf copy
|
|
|
|
* mp=NULL thus uio is the copy method to userland) MSG_WAITALL - ??
|
|
|
|
* On the way out we may send out any combination of:
|
|
|
|
* MSG_NOTIFICATION MSG_EOR
|
2016-12-06 10:21:25 +00:00
|
|
|
*
|
2006-11-03 15:23:16 +00:00
|
|
|
*/
|
|
|
|
struct sctp_inpcb *inp = NULL;
|
|
|
|
int my_len = 0;
|
|
|
|
int cp_len = 0, error = 0;
|
|
|
|
struct sctp_queued_to_read *control = NULL, *ctl = NULL, *nxt = NULL;
|
2010-09-15 23:40:36 +00:00
|
|
|
struct mbuf *m = NULL;
|
2006-11-03 15:23:16 +00:00
|
|
|
struct sctp_tcb *stcb = NULL;
|
|
|
|
int wakeup_read_socket = 0;
|
|
|
|
int freecnt_applied = 0;
|
|
|
|
int out_flags = 0, in_flags = 0;
|
|
|
|
int block_allowed = 1;
|
2007-05-30 22:34:21 +00:00
|
|
|
uint32_t freed_so_far = 0;
|
2007-11-10 00:47:14 +00:00
|
|
|
uint32_t copied_so_far = 0;
|
2007-01-18 09:58:43 +00:00
|
|
|
int in_eeor_mode = 0;
|
2006-11-03 15:23:16 +00:00
|
|
|
int no_rcv_needed = 0;
|
|
|
|
uint32_t rwnd_req = 0;
|
|
|
|
int hold_sblock = 0;
|
|
|
|
int hold_rlock = 0;
|
2016-03-27 10:04:25 +00:00
|
|
|
ssize_t slen = 0;
|
2007-05-30 22:34:21 +00:00
|
|
|
uint32_t held_length = 0;
|
2007-05-03 14:42:42 +00:00
|
|
|
int sockbuf_lock = 0;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2007-05-08 00:21:05 +00:00
|
|
|
if (uio == NULL) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTPUTIL, EINVAL);
|
2007-05-08 00:21:05 +00:00
|
|
|
return (EINVAL);
|
|
|
|
}
|
2018-07-19 20:16:33 +00:00
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
if (msg_flags) {
|
|
|
|
in_flags = *msg_flags;
|
2007-04-14 09:44:09 +00:00
|
|
|
if (in_flags & MSG_PEEK)
|
|
|
|
SCTP_STAT_INCR(sctps_read_peeks);
|
2006-11-03 15:23:16 +00:00
|
|
|
} else {
|
|
|
|
in_flags = 0;
|
|
|
|
}
|
2007-05-08 00:21:05 +00:00
|
|
|
slen = uio->uio_resid;
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
/* Pull in and set up our int flags */
|
|
|
|
if (in_flags & MSG_OOB) {
|
|
|
|
/* Out of band's NOT supported */
|
|
|
|
return (EOPNOTSUPP);
|
|
|
|
}
|
|
|
|
if ((in_flags & MSG_PEEK) && (mp != NULL)) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTPUTIL, EINVAL);
|
2006-11-03 15:23:16 +00:00
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
if ((in_flags & (MSG_DONTWAIT
|
|
|
|
| MSG_NBIO
|
|
|
|
)) ||
|
2007-03-15 11:27:14 +00:00
|
|
|
SCTP_SO_IS_NBIO(so)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
block_allowed = 0;
|
|
|
|
}
|
|
|
|
/* setup the endpoint */
|
|
|
|
inp = (struct sctp_inpcb *)so->so_pcb;
|
|
|
|
if (inp == NULL) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(NULL, NULL, NULL, SCTP_FROM_SCTPUTIL, EFAULT);
|
2006-11-03 15:23:16 +00:00
|
|
|
return (EFAULT);
|
|
|
|
}
|
2007-03-20 10:23:11 +00:00
|
|
|
rwnd_req = (SCTP_SB_LIMIT_RCV(so) >> SCTP_RWND_HIWAT_SHIFT);
|
2006-11-03 15:23:16 +00:00
|
|
|
/* Must be at least a MTU's worth */
|
|
|
|
if (rwnd_req < SCTP_MIN_RWND)
|
|
|
|
rwnd_req = SCTP_MIN_RWND;
|
|
|
|
in_eeor_mode = sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXPLICIT_EOR);
|
2008-06-14 07:58:05 +00:00
|
|
|
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_RECV_RWND_LOGGING_ENABLE) {
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_misc_ints(SCTP_SORECV_ENTER,
|
2018-07-19 20:11:14 +00:00
|
|
|
rwnd_req, in_eeor_mode, so->so_rcv.sb_cc, (uint32_t)uio->uio_resid);
|
2007-06-14 22:59:04 +00:00
|
|
|
}
|
2008-06-14 07:58:05 +00:00
|
|
|
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_RECV_RWND_LOGGING_ENABLE) {
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_misc_ints(SCTP_SORECV_ENTERPL,
|
2018-07-19 20:11:14 +00:00
|
|
|
rwnd_req, block_allowed, so->so_rcv.sb_cc, (uint32_t)uio->uio_resid);
|
2007-06-14 22:59:04 +00:00
|
|
|
}
|
2018-07-19 20:16:33 +00:00
|
|
|
|
|
|
|
|
Correct two problems relating to sorflush(), which is called to flush
read socket buffers in shutdown() and close():
- Call socantrcvmore() before sblock() to dislodge any threads that
might be sleeping (potentially indefinitely) while holding sblock(),
such as a thread blocked in recv().
- Flag the sblock() call as non-interruptible so that a signal
delivered to the thread calling sorflush() doesn't cause sblock() to
fail. The sblock() is required to ensure that all other socket
consumer threads have, in fact, left, and do not enter, the socket
buffer until we're done flushin it.
To implement the latter, change the 'flags' argument to sblock() to
accept two flags, SBL_WAIT and SBL_NOINTR, rather than one M_WAITOK
flag. When SBL_NOINTR is set, it forces a non-interruptible sx
acquisition, regardless of the setting of the disposition of SB_NOINTR
on the socket buffer; without this change it would be possible for
another thread to clear SB_NOINTR between when the socket buffer mutex
is released and sblock() is invoked.
Reviewed by: bz, kmacy
Reported by: Jos Backus <jos at catnook dot com>
2008-01-31 08:22:24 +00:00
|
|
|
error = sblock(&so->so_rcv, (block_allowed ? SBL_WAIT : 0));
|
2006-11-03 15:23:16 +00:00
|
|
|
if (error) {
|
|
|
|
goto release_unlocked;
|
|
|
|
}
|
2012-11-06 23:04:23 +00:00
|
|
|
sockbuf_lock = 1;
|
2006-11-03 15:23:16 +00:00
|
|
|
restart:
|
2007-05-03 14:42:42 +00:00
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
restart_nosblocks:
|
|
|
|
if (hold_sblock == 0) {
|
|
|
|
SOCKBUF_LOCK(&so->so_rcv);
|
|
|
|
hold_sblock = 1;
|
|
|
|
}
|
|
|
|
if ((inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) ||
|
|
|
|
(inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE)) {
|
|
|
|
goto out;
|
|
|
|
}
|
2014-12-02 20:29:29 +00:00
|
|
|
if ((so->so_rcv.sb_state & SBS_CANTRCVMORE) && (so->so_rcv.sb_cc == 0)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
if (so->so_error) {
|
|
|
|
error = so->so_error;
|
2007-01-15 15:12:10 +00:00
|
|
|
if ((in_flags & MSG_PEEK) == 0)
|
|
|
|
so->so_error = 0;
|
2007-12-04 14:41:48 +00:00
|
|
|
goto out;
|
2006-11-03 15:23:16 +00:00
|
|
|
} else {
|
2014-12-02 20:29:29 +00:00
|
|
|
if (so->so_rcv.sb_cc == 0) {
|
2007-12-04 14:41:48 +00:00
|
|
|
/* indicate EOF */
|
|
|
|
error = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
2016-06-23 19:27:29 +00:00
|
|
|
if (so->so_rcv.sb_cc <= held_length) {
|
|
|
|
if (so->so_error) {
|
|
|
|
error = so->so_error;
|
|
|
|
if ((in_flags & MSG_PEEK) == 0) {
|
|
|
|
so->so_error = 0;
|
|
|
|
}
|
|
|
|
goto out;
|
|
|
|
}
|
2014-12-02 20:29:29 +00:00
|
|
|
if ((so->so_rcv.sb_cc == 0) &&
|
2006-11-03 15:23:16 +00:00
|
|
|
((inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE) ||
|
|
|
|
(inp->sctp_flags & SCTP_PCB_FLAGS_IN_TCPPOOL))) {
|
|
|
|
if ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) == 0) {
|
|
|
|
/*
|
|
|
|
* For active open side clear flags for
|
|
|
|
* re-use passive open is blocked by
|
|
|
|
* connect.
|
|
|
|
*/
|
|
|
|
if (inp->sctp_flags & SCTP_PCB_FLAGS_WAS_ABORTED) {
|
2016-12-26 11:06:41 +00:00
|
|
|
/*
|
|
|
|
* You were aborted, passive side
|
|
|
|
* always hits here
|
|
|
|
*/
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTPUTIL, ECONNRESET);
|
2006-11-03 15:23:16 +00:00
|
|
|
error = ECONNRESET;
|
|
|
|
}
|
|
|
|
so->so_state &= ~(SS_ISCONNECTING |
|
|
|
|
SS_ISDISCONNECTING |
|
|
|
|
SS_ISCONFIRMING |
|
|
|
|
SS_ISCONNECTED);
|
|
|
|
if (error == 0) {
|
|
|
|
if ((inp->sctp_flags & SCTP_PCB_FLAGS_WAS_CONNECTED) == 0) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTPUTIL, ENOTCONN);
|
2006-11-03 15:23:16 +00:00
|
|
|
error = ENOTCONN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
2016-06-23 19:27:29 +00:00
|
|
|
if (block_allowed) {
|
|
|
|
error = sbwait(&so->so_rcv);
|
|
|
|
if (error) {
|
|
|
|
goto out;
|
2007-01-15 15:12:10 +00:00
|
|
|
}
|
2016-06-23 19:27:29 +00:00
|
|
|
held_length = 0;
|
|
|
|
goto restart_nosblocks;
|
|
|
|
} else {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTPUTIL, EWOULDBLOCK);
|
2007-01-15 15:12:10 +00:00
|
|
|
error = EWOULDBLOCK;
|
2016-06-23 19:27:29 +00:00
|
|
|
goto out;
|
2007-01-15 15:12:10 +00:00
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2007-05-02 12:50:13 +00:00
|
|
|
if (hold_sblock == 1) {
|
|
|
|
SOCKBUF_UNLOCK(&so->so_rcv);
|
|
|
|
hold_sblock = 0;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
/* we possibly have data we can read */
|
2007-05-17 12:16:24 +00:00
|
|
|
/* sa_ignore FREED_MEMORY */
|
2006-11-03 15:23:16 +00:00
|
|
|
control = TAILQ_FIRST(&inp->read_queue);
|
|
|
|
if (control == NULL) {
|
|
|
|
/*
|
|
|
|
* This could be happening since the appender did the
|
|
|
|
* increment but as not yet did the tailq insert onto the
|
|
|
|
* read_queue
|
|
|
|
*/
|
|
|
|
if (hold_rlock == 0) {
|
|
|
|
SCTP_INP_READ_LOCK(inp);
|
|
|
|
}
|
|
|
|
control = TAILQ_FIRST(&inp->read_queue);
|
2014-12-02 20:29:29 +00:00
|
|
|
if ((control == NULL) && (so->so_rcv.sb_cc != 0)) {
|
2006-12-14 17:02:55 +00:00
|
|
|
#ifdef INVARIANTS
|
2006-11-03 15:23:16 +00:00
|
|
|
panic("Huh, its non zero and nothing on control?");
|
|
|
|
#endif
|
2014-12-02 20:29:29 +00:00
|
|
|
so->so_rcv.sb_cc = 0;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
SCTP_INP_READ_UNLOCK(inp);
|
|
|
|
hold_rlock = 0;
|
|
|
|
goto restart;
|
|
|
|
}
|
2018-07-19 20:16:33 +00:00
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
if ((control->length == 0) &&
|
|
|
|
(control->do_not_ref_stcb)) {
|
|
|
|
/*
|
|
|
|
* Clean up code for freeing assoc that left behind a
|
|
|
|
* pdapi.. maybe a peer in EEOR that just closed after
|
|
|
|
* sending and never indicated a EOR.
|
|
|
|
*/
|
|
|
|
if (hold_rlock == 0) {
|
|
|
|
hold_rlock = 1;
|
|
|
|
SCTP_INP_READ_LOCK(inp);
|
|
|
|
}
|
|
|
|
control->held_length = 0;
|
|
|
|
if (control->data) {
|
|
|
|
/* Hmm there is data here .. fix */
|
2007-05-30 22:34:21 +00:00
|
|
|
struct mbuf *m_tmp;
|
2006-11-03 15:23:16 +00:00
|
|
|
int cnt = 0;
|
|
|
|
|
2007-05-30 22:34:21 +00:00
|
|
|
m_tmp = control->data;
|
|
|
|
while (m_tmp) {
|
|
|
|
cnt += SCTP_BUF_LEN(m_tmp);
|
|
|
|
if (SCTP_BUF_NEXT(m_tmp) == NULL) {
|
|
|
|
control->tail_mbuf = m_tmp;
|
2006-11-03 15:23:16 +00:00
|
|
|
control->end_added = 1;
|
|
|
|
}
|
2007-05-30 22:34:21 +00:00
|
|
|
m_tmp = SCTP_BUF_NEXT(m_tmp);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
control->length = cnt;
|
|
|
|
} else {
|
|
|
|
/* remove it */
|
|
|
|
TAILQ_REMOVE(&inp->read_queue, control, next);
|
|
|
|
/* Add back any hiddend data */
|
|
|
|
sctp_free_remote_addr(control->whoFrom);
|
|
|
|
sctp_free_a_readq(stcb, control);
|
|
|
|
}
|
|
|
|
if (hold_rlock) {
|
|
|
|
hold_rlock = 0;
|
|
|
|
SCTP_INP_READ_UNLOCK(inp);
|
|
|
|
}
|
|
|
|
goto restart;
|
|
|
|
}
|
2009-08-15 21:10:52 +00:00
|
|
|
if ((control->length == 0) &&
|
|
|
|
(control->end_added == 1)) {
|
2016-12-26 11:06:41 +00:00
|
|
|
/*
|
|
|
|
* Do we also need to check for (control->pdapi_aborted ==
|
|
|
|
* 1)?
|
|
|
|
*/
|
2009-08-15 21:10:52 +00:00
|
|
|
if (hold_rlock == 0) {
|
|
|
|
hold_rlock = 1;
|
|
|
|
SCTP_INP_READ_LOCK(inp);
|
|
|
|
}
|
|
|
|
TAILQ_REMOVE(&inp->read_queue, control, next);
|
|
|
|
if (control->data) {
|
|
|
|
#ifdef INVARIANTS
|
|
|
|
panic("control->data not null but control->length == 0");
|
|
|
|
#else
|
|
|
|
SCTP_PRINTF("Strange, data left in the control buffer. Cleaning up.\n");
|
|
|
|
sctp_m_freem(control->data);
|
|
|
|
control->data = NULL;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
if (control->aux_data) {
|
|
|
|
sctp_m_free(control->aux_data);
|
|
|
|
control->aux_data = NULL;
|
|
|
|
}
|
2016-04-18 09:29:14 +00:00
|
|
|
#ifdef INVARIANTS
|
2016-04-07 09:10:34 +00:00
|
|
|
if (control->on_strm_q) {
|
|
|
|
panic("About to free ctl:%p so:%p and its in %d",
|
|
|
|
control, so, control->on_strm_q);
|
|
|
|
}
|
2016-04-18 09:29:14 +00:00
|
|
|
#endif
|
2009-08-15 21:10:52 +00:00
|
|
|
sctp_free_remote_addr(control->whoFrom);
|
|
|
|
sctp_free_a_readq(stcb, control);
|
|
|
|
if (hold_rlock) {
|
|
|
|
hold_rlock = 0;
|
|
|
|
SCTP_INP_READ_UNLOCK(inp);
|
|
|
|
}
|
|
|
|
goto restart;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
if (control->length == 0) {
|
|
|
|
if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE)) &&
|
|
|
|
(filling_sinfo)) {
|
|
|
|
/* find a more suitable one then this */
|
|
|
|
ctl = TAILQ_NEXT(control, next);
|
|
|
|
while (ctl) {
|
2007-04-22 11:06:27 +00:00
|
|
|
if ((ctl->stcb != control->stcb) && (ctl->length) &&
|
|
|
|
(ctl->some_taken ||
|
2007-05-08 00:21:05 +00:00
|
|
|
(ctl->spec_flags & M_NOTIFICATION) ||
|
2007-04-22 11:06:27 +00:00
|
|
|
((ctl->do_not_ref_stcb == 0) &&
|
|
|
|
(ctl->stcb->asoc.strmin[ctl->sinfo_stream].delivery_started == 0)))
|
|
|
|
) {
|
|
|
|
/*-
|
|
|
|
* If we have a different TCB next, and there is data
|
|
|
|
* present. If we have already taken some (pdapi), OR we can
|
|
|
|
* ref the tcb and no delivery as started on this stream, we
|
2007-05-08 00:21:05 +00:00
|
|
|
* take it. Note we allow a notification on a different
|
|
|
|
* assoc to be delivered..
|
2007-04-22 11:06:27 +00:00
|
|
|
*/
|
|
|
|
control = ctl;
|
|
|
|
goto found_one;
|
|
|
|
} else if ((sctp_is_feature_on(inp, SCTP_PCB_FLAGS_INTERLEAVE_STRMS)) &&
|
|
|
|
(ctl->length) &&
|
|
|
|
((ctl->some_taken) ||
|
|
|
|
((ctl->do_not_ref_stcb == 0) &&
|
2007-05-08 00:21:05 +00:00
|
|
|
((ctl->spec_flags & M_NOTIFICATION) == 0) &&
|
2010-04-03 15:40:14 +00:00
|
|
|
(ctl->stcb->asoc.strmin[ctl->sinfo_stream].delivery_started == 0)))) {
|
2007-04-22 11:06:27 +00:00
|
|
|
/*-
|
|
|
|
* If we have the same tcb, and there is data present, and we
|
|
|
|
* have the strm interleave feature present. Then if we have
|
|
|
|
* taken some (pdapi) or we can refer to tht tcb AND we have
|
|
|
|
* not started a delivery for this stream, we can take it.
|
2007-05-08 00:21:05 +00:00
|
|
|
* Note we do NOT allow a notificaiton on the same assoc to
|
|
|
|
* be delivered.
|
2007-04-22 11:06:27 +00:00
|
|
|
*/
|
2006-11-03 15:23:16 +00:00
|
|
|
control = ctl;
|
|
|
|
goto found_one;
|
|
|
|
}
|
|
|
|
ctl = TAILQ_NEXT(ctl, next);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* if we reach here, not suitable replacement is available
|
2014-12-02 20:29:29 +00:00
|
|
|
* <or> fragment interleave is NOT on. So stuff the sb_cc
|
2006-11-03 15:23:16 +00:00
|
|
|
* into the our held count, and its time to sleep again.
|
|
|
|
*/
|
2014-12-02 20:29:29 +00:00
|
|
|
held_length = so->so_rcv.sb_cc;
|
|
|
|
control->held_length = so->so_rcv.sb_cc;
|
2006-11-03 15:23:16 +00:00
|
|
|
goto restart;
|
|
|
|
}
|
|
|
|
/* Clear the held length since there is something to read */
|
|
|
|
control->held_length = 0;
|
|
|
|
found_one:
|
|
|
|
/*
|
|
|
|
* If we reach here, control has a some data for us to read off.
|
|
|
|
* Note that stcb COULD be NULL.
|
|
|
|
*/
|
2016-08-08 08:20:10 +00:00
|
|
|
if (hold_rlock == 0) {
|
|
|
|
hold_rlock = 1;
|
|
|
|
SCTP_INP_READ_LOCK(inp);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2016-08-08 08:20:10 +00:00
|
|
|
control->some_taken++;
|
2006-11-03 15:23:16 +00:00
|
|
|
stcb = control->stcb;
|
|
|
|
if (stcb) {
|
2007-05-30 17:39:45 +00:00
|
|
|
if ((control->do_not_ref_stcb == 0) &&
|
|
|
|
(stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED)) {
|
2006-11-05 13:25:18 +00:00
|
|
|
if (freecnt_applied == 0)
|
|
|
|
stcb = NULL;
|
2006-11-03 15:23:16 +00:00
|
|
|
} else if (control->do_not_ref_stcb == 0) {
|
|
|
|
/* you can't free it on me please */
|
|
|
|
/*
|
|
|
|
* The lock on the socket buffer protects us so the
|
|
|
|
* free code will stop. But since we used the
|
|
|
|
* socketbuf lock and the sender uses the tcb_lock
|
|
|
|
* to increment, we need to use the atomic add to
|
|
|
|
* the refcnt
|
|
|
|
*/
|
2007-10-01 03:22:29 +00:00
|
|
|
if (freecnt_applied) {
|
|
|
|
#ifdef INVARIANTS
|
2007-05-29 09:29:03 +00:00
|
|
|
panic("refcnt already incremented");
|
2007-10-01 03:22:29 +00:00
|
|
|
#else
|
2012-05-04 09:27:00 +00:00
|
|
|
SCTP_PRINTF("refcnt already incremented?\n");
|
2007-10-01 03:22:29 +00:00
|
|
|
#endif
|
|
|
|
} else {
|
|
|
|
atomic_add_int(&stcb->asoc.refcnt, 1);
|
|
|
|
freecnt_applied = 1;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
/*
|
|
|
|
* Setup to remember how much we have not yet told
|
|
|
|
* the peer our rwnd has opened up. Note we grab the
|
|
|
|
* value from the tcb from last time. Note too that
|
2007-05-30 17:39:45 +00:00
|
|
|
* sack sending clears this when a sack is sent,
|
2006-11-03 15:23:16 +00:00
|
|
|
* which is fine. Once we hit the rwnd_req, we then
|
|
|
|
* will go to the sctp_user_rcvd() that will not
|
|
|
|
* lock until it KNOWs it MUST send a WUP-SACK.
|
|
|
|
*/
|
|
|
|
freed_so_far = stcb->freed_by_sorcv_sincelast;
|
|
|
|
stcb->freed_by_sorcv_sincelast = 0;
|
|
|
|
}
|
|
|
|
}
|
2007-05-08 00:21:05 +00:00
|
|
|
if (stcb &&
|
|
|
|
((control->spec_flags & M_NOTIFICATION) == 0) &&
|
2007-05-06 00:01:17 +00:00
|
|
|
control->do_not_ref_stcb == 0) {
|
2007-05-02 12:50:13 +00:00
|
|
|
stcb->asoc.strmin[control->sinfo_stream].delivery_started = 1;
|
|
|
|
}
|
2018-07-19 20:16:33 +00:00
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
/* First lets get off the sinfo and sockaddr info */
|
2016-05-13 09:11:41 +00:00
|
|
|
if ((sinfo != NULL) && (filling_sinfo != 0)) {
|
|
|
|
sinfo->sinfo_stream = control->sinfo_stream;
|
2018-07-19 20:11:14 +00:00
|
|
|
sinfo->sinfo_ssn = (uint16_t)control->mid;
|
2016-05-13 09:11:41 +00:00
|
|
|
sinfo->sinfo_flags = control->sinfo_flags;
|
|
|
|
sinfo->sinfo_ppid = control->sinfo_ppid;
|
|
|
|
sinfo->sinfo_context = control->sinfo_context;
|
|
|
|
sinfo->sinfo_timetolive = control->sinfo_timetolive;
|
|
|
|
sinfo->sinfo_tsn = control->sinfo_tsn;
|
|
|
|
sinfo->sinfo_cumtsn = control->sinfo_cumtsn;
|
|
|
|
sinfo->sinfo_assoc_id = control->sinfo_assoc_id;
|
2006-11-03 15:23:16 +00:00
|
|
|
nxt = TAILQ_NEXT(control, next);
|
2011-06-15 23:50:27 +00:00
|
|
|
if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO) ||
|
|
|
|
sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
struct sctp_extrcvinfo *s_extra;
|
|
|
|
|
|
|
|
s_extra = (struct sctp_extrcvinfo *)sinfo;
|
2007-04-22 11:06:27 +00:00
|
|
|
if ((nxt) &&
|
|
|
|
(nxt->length)) {
|
2015-11-06 13:08:16 +00:00
|
|
|
s_extra->serinfo_next_flags = SCTP_NEXT_MSG_AVAIL;
|
2006-11-03 15:23:16 +00:00
|
|
|
if (nxt->sinfo_flags & SCTP_UNORDERED) {
|
2015-11-06 13:08:16 +00:00
|
|
|
s_extra->serinfo_next_flags |= SCTP_NEXT_MSG_IS_UNORDERED;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2007-02-12 23:24:31 +00:00
|
|
|
if (nxt->spec_flags & M_NOTIFICATION) {
|
2015-11-06 13:08:16 +00:00
|
|
|
s_extra->serinfo_next_flags |= SCTP_NEXT_MSG_IS_NOTIFICATION;
|
2007-02-12 23:24:31 +00:00
|
|
|
}
|
2015-11-06 13:08:16 +00:00
|
|
|
s_extra->serinfo_next_aid = nxt->sinfo_assoc_id;
|
|
|
|
s_extra->serinfo_next_length = nxt->length;
|
|
|
|
s_extra->serinfo_next_ppid = nxt->sinfo_ppid;
|
|
|
|
s_extra->serinfo_next_stream = nxt->sinfo_stream;
|
2006-11-03 15:23:16 +00:00
|
|
|
if (nxt->tail_mbuf != NULL) {
|
2006-12-29 20:21:42 +00:00
|
|
|
if (nxt->end_added) {
|
2015-11-06 13:08:16 +00:00
|
|
|
s_extra->serinfo_next_flags |= SCTP_NEXT_MSG_ISCOMPLETE;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* we explicitly 0 this, since the memcpy
|
|
|
|
* got some other things beyond the older
|
|
|
|
* sinfo_ that is on the control's structure
|
|
|
|
* :-D
|
|
|
|
*/
|
2007-04-22 11:06:27 +00:00
|
|
|
nxt = NULL;
|
2015-11-06 13:08:16 +00:00
|
|
|
s_extra->serinfo_next_flags = SCTP_NO_NEXT_MSG;
|
|
|
|
s_extra->serinfo_next_aid = 0;
|
|
|
|
s_extra->serinfo_next_length = 0;
|
|
|
|
s_extra->serinfo_next_ppid = 0;
|
|
|
|
s_extra->serinfo_next_stream = 0;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* update off the real current cum-ack, if we have an stcb.
|
|
|
|
*/
|
2007-05-30 17:39:45 +00:00
|
|
|
if ((control->do_not_ref_stcb == 0) && stcb)
|
2006-11-03 15:23:16 +00:00
|
|
|
sinfo->sinfo_cumtsn = stcb->asoc.cumulative_tsn;
|
|
|
|
/*
|
|
|
|
* mask off the high bits, we keep the actual chunk bits in
|
|
|
|
* there.
|
|
|
|
*/
|
|
|
|
sinfo->sinfo_flags &= 0x00ff;
|
2007-06-06 00:40:41 +00:00
|
|
|
if ((control->sinfo_flags >> 8) & SCTP_DATA_UNORDERED) {
|
|
|
|
sinfo->sinfo_flags |= SCTP_UNORDERED;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2007-07-17 20:58:26 +00:00
|
|
|
#ifdef SCTP_ASOCLOG_OF_TSNS
|
|
|
|
{
|
|
|
|
int index, newindex;
|
|
|
|
struct sctp_pcbtsn_rlog *entry;
|
|
|
|
|
|
|
|
do {
|
|
|
|
index = inp->readlog_index;
|
|
|
|
newindex = index + 1;
|
|
|
|
if (newindex >= SCTP_READ_LOG_SIZE) {
|
|
|
|
newindex = 0;
|
|
|
|
}
|
|
|
|
} while (atomic_cmpset_int(&inp->readlog_index, index, newindex) == 0);
|
|
|
|
entry = &inp->readlog[index];
|
|
|
|
entry->vtag = control->sinfo_assoc_id;
|
|
|
|
entry->strm = control->sinfo_stream;
|
2018-07-19 20:11:14 +00:00
|
|
|
entry->seq = (uint16_t)control->mid;
|
2007-07-17 20:58:26 +00:00
|
|
|
entry->sz = control->length;
|
|
|
|
entry->flgs = control->sinfo_flags;
|
|
|
|
}
|
|
|
|
#endif
|
2014-12-06 20:00:08 +00:00
|
|
|
if ((fromlen > 0) && (from != NULL)) {
|
|
|
|
union sctp_sockstore store;
|
|
|
|
size_t len;
|
|
|
|
|
2012-03-22 16:22:16 +00:00
|
|
|
switch (control->whoFrom->ro._l_addr.sa.sa_family) {
|
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6:
|
2014-12-06 20:00:08 +00:00
|
|
|
len = sizeof(struct sockaddr_in6);
|
|
|
|
store.sin6 = control->whoFrom->ro._l_addr.sin6;
|
|
|
|
store.sin6.sin6_port = control->port_from;
|
2012-03-22 16:22:16 +00:00
|
|
|
break;
|
|
|
|
#endif
|
2007-03-15 11:27:14 +00:00
|
|
|
#ifdef INET
|
2012-03-22 16:22:16 +00:00
|
|
|
case AF_INET:
|
2014-12-06 20:00:08 +00:00
|
|
|
#ifdef INET6
|
|
|
|
if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_NEEDS_MAPPED_V4)) {
|
|
|
|
len = sizeof(struct sockaddr_in6);
|
|
|
|
in6_sin_2_v4mapsin6(&control->whoFrom->ro._l_addr.sin,
|
|
|
|
&store.sin6);
|
|
|
|
store.sin6.sin6_port = control->port_from;
|
|
|
|
} else {
|
|
|
|
len = sizeof(struct sockaddr_in);
|
|
|
|
store.sin = control->whoFrom->ro._l_addr.sin;
|
|
|
|
store.sin.sin_port = control->port_from;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
len = sizeof(struct sockaddr_in);
|
|
|
|
store.sin = control->whoFrom->ro._l_addr.sin;
|
|
|
|
store.sin.sin_port = control->port_from;
|
|
|
|
#endif
|
2012-03-22 16:22:16 +00:00
|
|
|
break;
|
2006-11-03 15:23:16 +00:00
|
|
|
#endif
|
2012-03-22 16:22:16 +00:00
|
|
|
default:
|
2014-12-06 20:00:08 +00:00
|
|
|
len = 0;
|
2012-03-22 16:22:16 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-12-06 20:00:08 +00:00
|
|
|
memcpy(from, &store, min((size_t)fromlen, len));
|
2012-07-15 11:04:49 +00:00
|
|
|
#ifdef INET6
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
2012-03-22 16:22:16 +00:00
|
|
|
struct sockaddr_in6 lsa6, *from6;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
2012-03-22 16:22:16 +00:00
|
|
|
from6 = (struct sockaddr_in6 *)from;
|
|
|
|
sctp_recover_scope_mac(from6, (&lsa6));
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2016-08-08 08:20:10 +00:00
|
|
|
if (hold_rlock) {
|
|
|
|
SCTP_INP_READ_UNLOCK(inp);
|
|
|
|
hold_rlock = 0;
|
|
|
|
}
|
|
|
|
if (hold_sblock) {
|
|
|
|
SOCKBUF_UNLOCK(&so->so_rcv);
|
|
|
|
hold_sblock = 0;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
/* now copy out what data we can */
|
|
|
|
if (mp == NULL) {
|
|
|
|
/* copy out each mbuf in the chain up to length */
|
|
|
|
get_more_data:
|
|
|
|
m = control->data;
|
|
|
|
while (m) {
|
|
|
|
/* Move out all we can */
|
|
|
|
cp_len = (int)uio->uio_resid;
|
2006-12-29 20:21:42 +00:00
|
|
|
my_len = (int)SCTP_BUF_LEN(m);
|
2006-11-03 15:23:16 +00:00
|
|
|
if (cp_len > my_len) {
|
|
|
|
/* not enough in this buf */
|
|
|
|
cp_len = my_len;
|
|
|
|
}
|
|
|
|
if (hold_rlock) {
|
|
|
|
SCTP_INP_READ_UNLOCK(inp);
|
|
|
|
hold_rlock = 0;
|
|
|
|
}
|
|
|
|
if (cp_len > 0)
|
|
|
|
error = uiomove(mtod(m, char *), cp_len, uio);
|
|
|
|
/* re-read */
|
|
|
|
if (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) {
|
|
|
|
goto release;
|
|
|
|
}
|
2018-07-19 20:16:33 +00:00
|
|
|
|
2007-05-30 17:39:45 +00:00
|
|
|
if ((control->do_not_ref_stcb == 0) && stcb &&
|
2006-11-03 15:23:16 +00:00
|
|
|
stcb->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) {
|
|
|
|
no_rcv_needed = 1;
|
|
|
|
}
|
|
|
|
if (error) {
|
|
|
|
/* error we are out of here */
|
|
|
|
goto release;
|
|
|
|
}
|
2016-04-07 09:10:34 +00:00
|
|
|
SCTP_INP_READ_LOCK(inp);
|
|
|
|
hold_rlock = 1;
|
2006-12-29 20:21:42 +00:00
|
|
|
if (cp_len == SCTP_BUF_LEN(m)) {
|
|
|
|
if ((SCTP_BUF_NEXT(m) == NULL) &&
|
|
|
|
(control->end_added)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
out_flags |= MSG_EOR;
|
2010-09-05 13:41:45 +00:00
|
|
|
if ((control->do_not_ref_stcb == 0) &&
|
|
|
|
(control->stcb != NULL) &&
|
|
|
|
((control->spec_flags & M_NOTIFICATION) == 0))
|
2007-04-23 00:51:49 +00:00
|
|
|
control->stcb->asoc.strmin[control->sinfo_stream].delivery_started = 0;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2006-12-29 20:21:42 +00:00
|
|
|
if (control->spec_flags & M_NOTIFICATION) {
|
2006-11-03 15:23:16 +00:00
|
|
|
out_flags |= MSG_NOTIFICATION;
|
|
|
|
}
|
|
|
|
/* we ate up the mbuf */
|
|
|
|
if (in_flags & MSG_PEEK) {
|
|
|
|
/* just looking */
|
2006-12-29 20:21:42 +00:00
|
|
|
m = SCTP_BUF_NEXT(m);
|
2006-11-03 15:23:16 +00:00
|
|
|
copied_so_far += cp_len;
|
|
|
|
} else {
|
|
|
|
/* dispose of the mbuf */
|
2008-06-14 07:58:05 +00:00
|
|
|
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SB_LOGGING_ENABLE) {
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_sblog(&so->so_rcv,
|
|
|
|
control->do_not_ref_stcb ? NULL : stcb, SCTP_LOG_SBFREE, SCTP_BUF_LEN(m));
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
sctp_sbfree(control, stcb, &so->so_rcv, m);
|
2008-06-14 07:58:05 +00:00
|
|
|
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SB_LOGGING_ENABLE) {
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_sblog(&so->so_rcv,
|
|
|
|
control->do_not_ref_stcb ? NULL : stcb, SCTP_LOG_SBRESULT, 0);
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
copied_so_far += cp_len;
|
|
|
|
freed_so_far += cp_len;
|
2007-08-24 00:53:53 +00:00
|
|
|
freed_so_far += MSIZE;
|
2007-07-17 20:58:26 +00:00
|
|
|
atomic_subtract_int(&control->length, cp_len);
|
2006-11-03 15:23:16 +00:00
|
|
|
control->data = sctp_m_free(m);
|
|
|
|
m = control->data;
|
2016-12-26 11:06:41 +00:00
|
|
|
/*
|
|
|
|
* been through it all, must hold sb
|
|
|
|
* lock ok to null tail
|
|
|
|
*/
|
2006-11-03 15:23:16 +00:00
|
|
|
if (control->data == NULL) {
|
2006-12-14 17:02:55 +00:00
|
|
|
#ifdef INVARIANTS
|
2006-11-03 15:23:16 +00:00
|
|
|
if ((control->end_added == 0) ||
|
|
|
|
(TAILQ_NEXT(control, next) == NULL)) {
|
|
|
|
/*
|
|
|
|
* If the end is not
|
|
|
|
* added, OR the
|
|
|
|
* next is NOT null
|
|
|
|
* we MUST have the
|
|
|
|
* lock.
|
|
|
|
*/
|
|
|
|
if (mtx_owned(&inp->inp_rdata_mtx) == 0) {
|
|
|
|
panic("Hmm we don't own the lock?");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
control->tail_mbuf = NULL;
|
2006-12-14 17:02:55 +00:00
|
|
|
#ifdef INVARIANTS
|
2006-11-03 15:23:16 +00:00
|
|
|
if ((control->end_added) && ((out_flags & MSG_EOR) == 0)) {
|
|
|
|
panic("end_added, nothing left and no MSG_EOR");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Do we need to trim the mbuf? */
|
2006-12-29 20:21:42 +00:00
|
|
|
if (control->spec_flags & M_NOTIFICATION) {
|
2006-11-03 15:23:16 +00:00
|
|
|
out_flags |= MSG_NOTIFICATION;
|
|
|
|
}
|
|
|
|
if ((in_flags & MSG_PEEK) == 0) {
|
2006-12-29 20:21:42 +00:00
|
|
|
SCTP_BUF_RESV_UF(m, cp_len);
|
|
|
|
SCTP_BUF_LEN(m) -= cp_len;
|
2008-06-14 07:58:05 +00:00
|
|
|
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SB_LOGGING_ENABLE) {
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_sblog(&so->so_rcv, control->do_not_ref_stcb ? NULL : stcb, SCTP_LOG_SBFREE, cp_len);
|
|
|
|
}
|
2014-12-02 20:29:29 +00:00
|
|
|
atomic_subtract_int(&so->so_rcv.sb_cc, cp_len);
|
2007-05-30 17:39:45 +00:00
|
|
|
if ((control->do_not_ref_stcb == 0) &&
|
|
|
|
stcb) {
|
2014-12-02 20:29:29 +00:00
|
|
|
atomic_subtract_int(&stcb->asoc.sb_cc, cp_len);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
copied_so_far += cp_len;
|
|
|
|
freed_so_far += cp_len;
|
2007-08-24 00:53:53 +00:00
|
|
|
freed_so_far += MSIZE;
|
2008-06-14 07:58:05 +00:00
|
|
|
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SB_LOGGING_ENABLE) {
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_sblog(&so->so_rcv, control->do_not_ref_stcb ? NULL : stcb,
|
|
|
|
SCTP_LOG_SBRESULT, 0);
|
|
|
|
}
|
2007-07-17 20:58:26 +00:00
|
|
|
atomic_subtract_int(&control->length, cp_len);
|
2006-11-03 15:23:16 +00:00
|
|
|
} else {
|
|
|
|
copied_so_far += cp_len;
|
|
|
|
}
|
|
|
|
}
|
2007-05-28 11:17:24 +00:00
|
|
|
if ((out_flags & MSG_EOR) || (uio->uio_resid == 0)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (((stcb) && (in_flags & MSG_PEEK) == 0) &&
|
|
|
|
(control->do_not_ref_stcb == 0) &&
|
|
|
|
(freed_so_far >= rwnd_req)) {
|
|
|
|
sctp_user_rcvd(stcb, &freed_so_far, hold_rlock, rwnd_req);
|
|
|
|
}
|
|
|
|
} /* end while(m) */
|
|
|
|
/*
|
|
|
|
* At this point we have looked at it all and we either have
|
|
|
|
* a MSG_EOR/or read all the user wants... <OR>
|
|
|
|
* control->length == 0.
|
|
|
|
*/
|
2007-05-28 11:17:24 +00:00
|
|
|
if ((out_flags & MSG_EOR) && ((in_flags & MSG_PEEK) == 0)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/* we are done with this control */
|
|
|
|
if (control->length == 0) {
|
|
|
|
if (control->data) {
|
2006-12-14 17:02:55 +00:00
|
|
|
#ifdef INVARIANTS
|
2006-11-03 15:23:16 +00:00
|
|
|
panic("control->data not null at read eor?");
|
|
|
|
#else
|
2007-05-09 13:30:06 +00:00
|
|
|
SCTP_PRINTF("Strange, data left in the control buffer .. invarients would panic?\n");
|
2006-11-03 15:23:16 +00:00
|
|
|
sctp_m_freem(control->data);
|
|
|
|
control->data = NULL;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
done_with_control:
|
2016-04-07 09:10:34 +00:00
|
|
|
if (hold_rlock == 0) {
|
|
|
|
SCTP_INP_READ_LOCK(inp);
|
|
|
|
hold_rlock = 1;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
TAILQ_REMOVE(&inp->read_queue, control, next);
|
|
|
|
/* Add back any hiddend data */
|
|
|
|
if (control->held_length) {
|
|
|
|
held_length = 0;
|
|
|
|
control->held_length = 0;
|
|
|
|
wakeup_read_socket = 1;
|
|
|
|
}
|
2007-05-08 00:21:05 +00:00
|
|
|
if (control->aux_data) {
|
|
|
|
sctp_m_free(control->aux_data);
|
|
|
|
control->aux_data = NULL;
|
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
no_rcv_needed = control->do_not_ref_stcb;
|
|
|
|
sctp_free_remote_addr(control->whoFrom);
|
|
|
|
control->data = NULL;
|
2016-04-18 09:29:14 +00:00
|
|
|
#ifdef INVARIANTS
|
2016-04-07 09:10:34 +00:00
|
|
|
if (control->on_strm_q) {
|
|
|
|
panic("About to free ctl:%p so:%p and its in %d",
|
|
|
|
control, so, control->on_strm_q);
|
|
|
|
}
|
2016-04-18 09:29:14 +00:00
|
|
|
#endif
|
2006-11-03 15:23:16 +00:00
|
|
|
sctp_free_a_readq(stcb, control);
|
|
|
|
control = NULL;
|
2007-05-30 17:39:45 +00:00
|
|
|
if ((freed_so_far >= rwnd_req) &&
|
|
|
|
(no_rcv_needed == 0))
|
2006-11-03 15:23:16 +00:00
|
|
|
sctp_user_rcvd(stcb, &freed_so_far, hold_rlock, rwnd_req);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* The user did not read all of this
|
|
|
|
* message, turn off the returned MSG_EOR
|
|
|
|
* since we are leaving more behind on the
|
|
|
|
* control to read.
|
|
|
|
*/
|
2006-12-14 17:02:55 +00:00
|
|
|
#ifdef INVARIANTS
|
2007-05-30 17:39:45 +00:00
|
|
|
if (control->end_added &&
|
|
|
|
(control->data == NULL) &&
|
2006-11-03 15:23:16 +00:00
|
|
|
(control->tail_mbuf == NULL)) {
|
|
|
|
panic("Gak, control->length is corrupt?");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
no_rcv_needed = control->do_not_ref_stcb;
|
|
|
|
out_flags &= ~MSG_EOR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (out_flags & MSG_EOR) {
|
|
|
|
goto release;
|
|
|
|
}
|
|
|
|
if ((uio->uio_resid == 0) ||
|
2013-12-27 13:07:00 +00:00
|
|
|
((in_eeor_mode) &&
|
2018-07-19 20:11:14 +00:00
|
|
|
(copied_so_far >= (uint32_t)max(so->so_rcv.sb_lowat, 1)))) {
|
2006-11-03 15:23:16 +00:00
|
|
|
goto release;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* If I hit here the receiver wants more and this message is
|
|
|
|
* NOT done (pd-api). So two questions. Can we block? if not
|
|
|
|
* we are done. Did the user NOT set MSG_WAITALL?
|
|
|
|
*/
|
|
|
|
if (block_allowed == 0) {
|
|
|
|
goto release;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* We need to wait for more data a few things: - We don't
|
|
|
|
* sbunlock() so we don't get someone else reading. - We
|
|
|
|
* must be sure to account for the case where what is added
|
|
|
|
* is NOT to our control when we wakeup.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do we need to tell the transport a rwnd update might be
|
|
|
|
* needed before we go to sleep?
|
|
|
|
*/
|
|
|
|
if (((stcb) && (in_flags & MSG_PEEK) == 0) &&
|
|
|
|
((freed_so_far >= rwnd_req) &&
|
|
|
|
(control->do_not_ref_stcb == 0) &&
|
|
|
|
(no_rcv_needed == 0))) {
|
|
|
|
sctp_user_rcvd(stcb, &freed_so_far, hold_rlock, rwnd_req);
|
|
|
|
}
|
|
|
|
wait_some_more:
|
2007-01-15 15:12:10 +00:00
|
|
|
if (so->so_rcv.sb_state & SBS_CANTRCVMORE) {
|
2006-11-03 15:23:16 +00:00
|
|
|
goto release;
|
|
|
|
}
|
2018-07-19 20:16:33 +00:00
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
if (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE)
|
|
|
|
goto release;
|
|
|
|
|
|
|
|
if (hold_rlock == 1) {
|
|
|
|
SCTP_INP_READ_UNLOCK(inp);
|
|
|
|
hold_rlock = 0;
|
|
|
|
}
|
|
|
|
if (hold_sblock == 0) {
|
|
|
|
SOCKBUF_LOCK(&so->so_rcv);
|
|
|
|
hold_sblock = 1;
|
|
|
|
}
|
2007-09-08 17:48:46 +00:00
|
|
|
if ((copied_so_far) && (control->length == 0) &&
|
2010-04-03 15:40:14 +00:00
|
|
|
(sctp_is_feature_on(inp, SCTP_PCB_FLAGS_FRAG_INTERLEAVE))) {
|
2007-09-08 17:48:46 +00:00
|
|
|
goto release;
|
|
|
|
}
|
2014-12-02 20:29:29 +00:00
|
|
|
if (so->so_rcv.sb_cc <= control->held_length) {
|
2006-11-03 15:23:16 +00:00
|
|
|
error = sbwait(&so->so_rcv);
|
|
|
|
if (error) {
|
|
|
|
goto release;
|
|
|
|
}
|
|
|
|
control->held_length = 0;
|
|
|
|
}
|
|
|
|
if (hold_sblock) {
|
|
|
|
SOCKBUF_UNLOCK(&so->so_rcv);
|
|
|
|
hold_sblock = 0;
|
|
|
|
}
|
|
|
|
if (control->length == 0) {
|
|
|
|
/* still nothing here */
|
|
|
|
if (control->end_added == 1) {
|
|
|
|
/* he aborted, or is done i.e.did a shutdown */
|
|
|
|
out_flags |= MSG_EOR;
|
2007-04-22 11:06:27 +00:00
|
|
|
if (control->pdapi_aborted) {
|
2007-05-06 00:01:17 +00:00
|
|
|
if ((control->do_not_ref_stcb == 0) && ((control->spec_flags & M_NOTIFICATION) == 0))
|
2007-04-23 00:51:49 +00:00
|
|
|
control->stcb->asoc.strmin[control->sinfo_stream].delivery_started = 0;
|
2007-04-22 11:06:27 +00:00
|
|
|
|
2006-11-08 00:21:13 +00:00
|
|
|
out_flags |= MSG_TRUNC;
|
2007-04-22 11:06:27 +00:00
|
|
|
} else {
|
2007-05-06 00:01:17 +00:00
|
|
|
if ((control->do_not_ref_stcb == 0) && ((control->spec_flags & M_NOTIFICATION) == 0))
|
2007-04-23 00:51:49 +00:00
|
|
|
control->stcb->asoc.strmin[control->sinfo_stream].delivery_started = 0;
|
2007-04-22 11:06:27 +00:00
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
goto done_with_control;
|
|
|
|
}
|
2014-12-02 20:29:29 +00:00
|
|
|
if (so->so_rcv.sb_cc > held_length) {
|
|
|
|
control->held_length = so->so_rcv.sb_cc;
|
2006-11-03 15:23:16 +00:00
|
|
|
held_length = 0;
|
|
|
|
}
|
|
|
|
goto wait_some_more;
|
|
|
|
} else if (control->data == NULL) {
|
2006-11-05 13:25:18 +00:00
|
|
|
/*
|
|
|
|
* we must re-sync since data is probably being
|
|
|
|
* added
|
|
|
|
*/
|
|
|
|
SCTP_INP_READ_LOCK(inp);
|
|
|
|
if ((control->length > 0) && (control->data == NULL)) {
|
2016-12-26 11:06:41 +00:00
|
|
|
/*
|
|
|
|
* big trouble.. we have the lock and its
|
|
|
|
* corrupt?
|
|
|
|
*/
|
2007-12-06 00:22:55 +00:00
|
|
|
#ifdef INVARIANTS
|
2016-04-07 09:34:41 +00:00
|
|
|
panic("Impossible data==NULL length !=0");
|
2007-12-06 00:22:55 +00:00
|
|
|
#endif
|
|
|
|
out_flags |= MSG_EOR;
|
|
|
|
out_flags |= MSG_TRUNC;
|
|
|
|
control->length = 0;
|
|
|
|
SCTP_INP_READ_UNLOCK(inp);
|
|
|
|
goto done_with_control;
|
2006-11-05 13:25:18 +00:00
|
|
|
}
|
|
|
|
SCTP_INP_READ_UNLOCK(inp);
|
|
|
|
/* We will fall around to get more data */
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
goto get_more_data;
|
|
|
|
} else {
|
2007-05-08 00:21:05 +00:00
|
|
|
/*-
|
|
|
|
* Give caller back the mbuf chain,
|
|
|
|
* store in uio_resid the length
|
2006-11-03 15:23:16 +00:00
|
|
|
*/
|
2007-05-08 00:21:05 +00:00
|
|
|
wakeup_read_socket = 0;
|
|
|
|
if ((control->end_added == 0) ||
|
|
|
|
(TAILQ_NEXT(control, next) == NULL)) {
|
|
|
|
/* Need to get rlock */
|
|
|
|
if (hold_rlock == 0) {
|
|
|
|
SCTP_INP_READ_LOCK(inp);
|
|
|
|
hold_rlock = 1;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2007-05-08 00:21:05 +00:00
|
|
|
}
|
|
|
|
if (control->end_added) {
|
|
|
|
out_flags |= MSG_EOR;
|
2011-12-27 10:16:24 +00:00
|
|
|
if ((control->do_not_ref_stcb == 0) &&
|
|
|
|
(control->stcb != NULL) &&
|
|
|
|
((control->spec_flags & M_NOTIFICATION) == 0))
|
2007-05-08 00:21:05 +00:00
|
|
|
control->stcb->asoc.strmin[control->sinfo_stream].delivery_started = 0;
|
|
|
|
}
|
|
|
|
if (control->spec_flags & M_NOTIFICATION) {
|
|
|
|
out_flags |= MSG_NOTIFICATION;
|
|
|
|
}
|
|
|
|
uio->uio_resid = control->length;
|
|
|
|
*mp = control->data;
|
|
|
|
m = control->data;
|
|
|
|
while (m) {
|
2008-06-14 07:58:05 +00:00
|
|
|
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SB_LOGGING_ENABLE) {
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_sblog(&so->so_rcv,
|
|
|
|
control->do_not_ref_stcb ? NULL : stcb, SCTP_LOG_SBFREE, SCTP_BUF_LEN(m));
|
|
|
|
}
|
2007-05-08 00:21:05 +00:00
|
|
|
sctp_sbfree(control, stcb, &so->so_rcv, m);
|
|
|
|
freed_so_far += SCTP_BUF_LEN(m);
|
2007-08-24 00:53:53 +00:00
|
|
|
freed_so_far += MSIZE;
|
2008-06-14 07:58:05 +00:00
|
|
|
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_SB_LOGGING_ENABLE) {
|
2007-06-14 22:59:04 +00:00
|
|
|
sctp_sblog(&so->so_rcv,
|
|
|
|
control->do_not_ref_stcb ? NULL : stcb, SCTP_LOG_SBRESULT, 0);
|
|
|
|
}
|
2007-05-08 00:21:05 +00:00
|
|
|
m = SCTP_BUF_NEXT(m);
|
|
|
|
}
|
|
|
|
control->data = control->tail_mbuf = NULL;
|
|
|
|
control->length = 0;
|
|
|
|
if (out_flags & MSG_EOR) {
|
|
|
|
/* Done with this control */
|
|
|
|
goto done_with_control;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
release:
|
|
|
|
if (hold_rlock == 1) {
|
|
|
|
SCTP_INP_READ_UNLOCK(inp);
|
|
|
|
hold_rlock = 0;
|
|
|
|
}
|
2007-05-03 14:42:42 +00:00
|
|
|
if (hold_sblock == 1) {
|
|
|
|
SOCKBUF_UNLOCK(&so->so_rcv);
|
|
|
|
hold_sblock = 0;
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2018-07-19 20:16:33 +00:00
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
sbunlock(&so->so_rcv);
|
2007-05-03 14:42:42 +00:00
|
|
|
sockbuf_lock = 0;
|
2006-11-03 15:23:16 +00:00
|
|
|
|
|
|
|
release_unlocked:
|
|
|
|
if (hold_sblock) {
|
|
|
|
SOCKBUF_UNLOCK(&so->so_rcv);
|
|
|
|
hold_sblock = 0;
|
|
|
|
}
|
|
|
|
if ((stcb) && (in_flags & MSG_PEEK) == 0) {
|
|
|
|
if ((freed_so_far >= rwnd_req) &&
|
|
|
|
(control && (control->do_not_ref_stcb == 0)) &&
|
|
|
|
(no_rcv_needed == 0))
|
|
|
|
sctp_user_rcvd(stcb, &freed_so_far, hold_rlock, rwnd_req);
|
|
|
|
}
|
|
|
|
out:
|
2008-10-18 15:56:52 +00:00
|
|
|
if (msg_flags) {
|
|
|
|
*msg_flags = out_flags;
|
|
|
|
}
|
2007-04-22 11:06:27 +00:00
|
|
|
if (((out_flags & MSG_EOR) == 0) &&
|
|
|
|
((in_flags & MSG_PEEK) == 0) &&
|
|
|
|
(sinfo) &&
|
2011-06-15 23:50:27 +00:00
|
|
|
(sctp_is_feature_on(inp, SCTP_PCB_FLAGS_EXT_RCVINFO) ||
|
|
|
|
sctp_is_feature_on(inp, SCTP_PCB_FLAGS_RECVNXTINFO))) {
|
2007-04-22 11:06:27 +00:00
|
|
|
struct sctp_extrcvinfo *s_extra;
|
|
|
|
|
|
|
|
s_extra = (struct sctp_extrcvinfo *)sinfo;
|
2015-11-06 13:08:16 +00:00
|
|
|
s_extra->serinfo_next_flags = SCTP_NO_NEXT_MSG;
|
2007-04-22 11:06:27 +00:00
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
if (hold_rlock == 1) {
|
|
|
|
SCTP_INP_READ_UNLOCK(inp);
|
|
|
|
}
|
|
|
|
if (hold_sblock) {
|
|
|
|
SOCKBUF_UNLOCK(&so->so_rcv);
|
|
|
|
}
|
2007-05-03 14:42:42 +00:00
|
|
|
if (sockbuf_lock) {
|
|
|
|
sbunlock(&so->so_rcv);
|
|
|
|
}
|
2018-07-19 20:16:33 +00:00
|
|
|
|
2006-11-05 13:25:18 +00:00
|
|
|
if (freecnt_applied) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/*
|
|
|
|
* The lock on the socket buffer protects us so the free
|
|
|
|
* code will stop. But since we used the socketbuf lock and
|
|
|
|
* the sender uses the tcb_lock to increment, we need to use
|
|
|
|
* the atomic add to the refcnt.
|
|
|
|
*/
|
2006-11-05 13:25:18 +00:00
|
|
|
if (stcb == NULL) {
|
2008-08-28 09:44:07 +00:00
|
|
|
#ifdef INVARIANTS
|
2006-11-05 13:25:18 +00:00
|
|
|
panic("stcb for refcnt has gone NULL?");
|
2008-08-28 09:44:07 +00:00
|
|
|
goto stage_left;
|
|
|
|
#else
|
|
|
|
goto stage_left;
|
|
|
|
#endif
|
2006-11-05 13:25:18 +00:00
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
/* Save the value back for next time */
|
|
|
|
stcb->freed_by_sorcv_sincelast = freed_so_far;
|
2016-08-06 15:29:46 +00:00
|
|
|
atomic_add_int(&stcb->asoc.refcnt, -1);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2008-06-14 07:58:05 +00:00
|
|
|
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_RECV_RWND_LOGGING_ENABLE) {
|
2007-06-14 22:59:04 +00:00
|
|
|
if (stcb) {
|
|
|
|
sctp_misc_ints(SCTP_SORECV_DONE,
|
|
|
|
freed_so_far,
|
2018-07-19 20:11:14 +00:00
|
|
|
(uint32_t)((uio) ? (slen - uio->uio_resid) : slen),
|
2007-06-14 22:59:04 +00:00
|
|
|
stcb->asoc.my_rwnd,
|
2014-12-02 20:29:29 +00:00
|
|
|
so->so_rcv.sb_cc);
|
2007-06-14 22:59:04 +00:00
|
|
|
} else {
|
|
|
|
sctp_misc_ints(SCTP_SORECV_DONE,
|
|
|
|
freed_so_far,
|
2018-07-19 20:11:14 +00:00
|
|
|
(uint32_t)((uio) ? (slen - uio->uio_resid) : slen),
|
2007-06-14 22:59:04 +00:00
|
|
|
0,
|
2014-12-02 20:29:29 +00:00
|
|
|
so->so_rcv.sb_cc);
|
2007-06-14 22:59:04 +00:00
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
2008-08-28 09:44:07 +00:00
|
|
|
stage_left:
|
2006-11-03 15:23:16 +00:00
|
|
|
if (wakeup_read_socket) {
|
|
|
|
sctp_sorwakeup(inp, so);
|
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef SCTP_MBUF_LOGGING
|
|
|
|
struct mbuf *
|
|
|
|
sctp_m_free(struct mbuf *m)
|
|
|
|
{
|
2008-06-14 07:58:05 +00:00
|
|
|
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MBUF_LOGGING_ENABLE) {
|
2015-01-10 20:49:57 +00:00
|
|
|
sctp_log_mb(m, SCTP_MBUF_IFREE);
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
return (m_free(m));
|
|
|
|
}
|
|
|
|
|
2018-01-15 21:59:20 +00:00
|
|
|
void
|
2006-11-03 15:23:16 +00:00
|
|
|
sctp_m_freem(struct mbuf *mb)
|
|
|
|
{
|
|
|
|
while (mb != NULL)
|
|
|
|
mb = sctp_m_free(mb);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2007-03-15 11:27:14 +00:00
|
|
|
int
|
|
|
|
sctp_dynamic_set_primary(struct sockaddr *sa, uint32_t vrf_id)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Given a local address. For all associations that holds the
|
|
|
|
* address, request a peer-set-primary.
|
|
|
|
*/
|
|
|
|
struct sctp_ifa *ifa;
|
|
|
|
struct sctp_laddr *wi;
|
|
|
|
|
|
|
|
ifa = sctp_find_ifa_by_addr(sa, vrf_id, 0);
|
|
|
|
if (ifa == NULL) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(NULL, NULL, NULL, SCTP_FROM_SCTPUTIL, EADDRNOTAVAIL);
|
2007-03-15 11:27:14 +00:00
|
|
|
return (EADDRNOTAVAIL);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Now that we have the ifa we must awaken the iterator with this
|
|
|
|
* message.
|
|
|
|
*/
|
2008-06-14 07:58:05 +00:00
|
|
|
wi = SCTP_ZONE_GET(SCTP_BASE_INFO(ipi_zone_laddr), struct sctp_laddr);
|
2007-03-15 11:27:14 +00:00
|
|
|
if (wi == NULL) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(NULL, NULL, NULL, SCTP_FROM_SCTPUTIL, ENOMEM);
|
2007-03-15 11:27:14 +00:00
|
|
|
return (ENOMEM);
|
|
|
|
}
|
|
|
|
/* Now incr the count and int wi structure */
|
|
|
|
SCTP_INCR_LADDR_COUNT();
|
2017-07-19 14:28:58 +00:00
|
|
|
memset(wi, 0, sizeof(*wi));
|
2007-05-28 11:17:24 +00:00
|
|
|
(void)SCTP_GETTIME_TIMEVAL(&wi->start_time);
|
2007-03-15 11:27:14 +00:00
|
|
|
wi->ifa = ifa;
|
|
|
|
wi->action = SCTP_SET_PRIM_ADDR;
|
|
|
|
atomic_add_int(&ifa->refcount, 1);
|
|
|
|
|
|
|
|
/* Now add it to the work queue */
|
2010-05-16 17:03:56 +00:00
|
|
|
SCTP_WQ_ADDR_LOCK();
|
2007-03-15 11:27:14 +00:00
|
|
|
/*
|
|
|
|
* Should this really be a tailq? As it is we will process the
|
|
|
|
* newest first :-0
|
|
|
|
*/
|
2008-06-14 07:58:05 +00:00
|
|
|
LIST_INSERT_HEAD(&SCTP_BASE_INFO(addr_wq), wi, sctp_nxt_addr);
|
2007-03-15 11:27:14 +00:00
|
|
|
sctp_timer_start(SCTP_TIMER_TYPE_ADDR_WQ,
|
|
|
|
(struct sctp_inpcb *)NULL,
|
|
|
|
(struct sctp_tcb *)NULL,
|
|
|
|
(struct sctp_nets *)NULL);
|
2017-09-20 21:29:54 +00:00
|
|
|
SCTP_WQ_ADDR_UNLOCK();
|
2007-03-15 11:27:14 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-03 15:23:16 +00:00
|
|
|
int
|
2007-05-08 00:21:05 +00:00
|
|
|
sctp_soreceive(struct socket *so,
|
|
|
|
struct sockaddr **psa,
|
|
|
|
struct uio *uio,
|
|
|
|
struct mbuf **mp0,
|
|
|
|
struct mbuf **controlp,
|
|
|
|
int *flagsp)
|
2006-11-03 15:23:16 +00:00
|
|
|
{
|
|
|
|
int error, fromlen;
|
|
|
|
uint8_t sockbuf[256];
|
|
|
|
struct sockaddr *from;
|
|
|
|
struct sctp_extrcvinfo sinfo;
|
|
|
|
int filling_sinfo = 1;
|
2018-01-15 21:59:20 +00:00
|
|
|
int flags;
|
2006-11-03 15:23:16 +00:00
|
|
|
struct sctp_inpcb *inp;
|
|
|
|
|
|
|
|
inp = (struct sctp_inpcb *)so->so_pcb;
|
|
|
|
/* pickup the assoc we are reading from */
|
|
|
|
if (inp == NULL) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTPUTIL, EINVAL);
|
2006-11-03 15:23:16 +00:00
|
|
|
return (EINVAL);
|
|
|
|
}
|
2011-06-15 23:50:27 +00:00
|
|
|
if ((sctp_is_feature_off(inp, SCTP_PCB_FLAGS_RECVDATAIOEVNT) &&
|
|
|
|
sctp_is_feature_off(inp, SCTP_PCB_FLAGS_RECVRCVINFO) &&
|
|
|
|
sctp_is_feature_off(inp, SCTP_PCB_FLAGS_RECVNXTINFO)) ||
|
2006-11-03 15:23:16 +00:00
|
|
|
(controlp == NULL)) {
|
|
|
|
/* user does not want the sndrcv ctl */
|
|
|
|
filling_sinfo = 0;
|
|
|
|
}
|
|
|
|
if (psa) {
|
|
|
|
from = (struct sockaddr *)sockbuf;
|
|
|
|
fromlen = sizeof(sockbuf);
|
|
|
|
from->sa_len = 0;
|
|
|
|
} else {
|
|
|
|
from = NULL;
|
|
|
|
fromlen = 0;
|
|
|
|
}
|
|
|
|
|
2014-07-08 21:54:27 +00:00
|
|
|
if (filling_sinfo) {
|
|
|
|
memset(&sinfo, 0, sizeof(struct sctp_extrcvinfo));
|
|
|
|
}
|
2018-01-15 21:59:20 +00:00
|
|
|
if (flagsp != NULL) {
|
|
|
|
flags = *flagsp;
|
|
|
|
} else {
|
|
|
|
flags = 0;
|
|
|
|
}
|
|
|
|
error = sctp_sorecvmsg(so, uio, mp0, from, fromlen, &flags,
|
2006-11-03 15:23:16 +00:00
|
|
|
(struct sctp_sndrcvinfo *)&sinfo, filling_sinfo);
|
2018-01-15 21:59:20 +00:00
|
|
|
if (flagsp != NULL) {
|
|
|
|
*flagsp = flags;
|
|
|
|
}
|
2014-07-08 21:54:27 +00:00
|
|
|
if (controlp != NULL) {
|
2006-11-03 15:23:16 +00:00
|
|
|
/* copy back the sinfo in a CMSG format */
|
2018-01-15 21:59:20 +00:00
|
|
|
if (filling_sinfo && ((flags & MSG_NOTIFICATION) == 0)) {
|
2006-11-03 15:23:16 +00:00
|
|
|
*controlp = sctp_build_ctl_nchunk(inp,
|
|
|
|
(struct sctp_sndrcvinfo *)&sinfo);
|
2018-01-15 21:59:20 +00:00
|
|
|
} else {
|
2006-11-03 15:23:16 +00:00
|
|
|
*controlp = NULL;
|
2018-01-15 21:59:20 +00:00
|
|
|
}
|
2006-11-03 15:23:16 +00:00
|
|
|
}
|
|
|
|
if (psa) {
|
|
|
|
/* copy back the address info */
|
|
|
|
if (from && from->sa_len) {
|
|
|
|
*psa = sodupsockaddr(from, M_NOWAIT);
|
|
|
|
} else {
|
|
|
|
*psa = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
2007-05-08 00:21:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
2007-05-28 11:17:24 +00:00
|
|
|
sctp_connectx_helper_add(struct sctp_tcb *stcb, struct sockaddr *addr,
|
|
|
|
int totaddr, int *error)
|
2007-05-08 00:21:05 +00:00
|
|
|
{
|
|
|
|
int added = 0;
|
|
|
|
int i;
|
|
|
|
struct sctp_inpcb *inp;
|
|
|
|
struct sockaddr *sa;
|
|
|
|
size_t incr = 0;
|
2011-09-15 08:49:54 +00:00
|
|
|
#ifdef INET
|
|
|
|
struct sockaddr_in *sin;
|
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
|
|
|
struct sockaddr_in6 *sin6;
|
|
|
|
#endif
|
|
|
|
|
2007-05-08 00:21:05 +00:00
|
|
|
sa = addr;
|
|
|
|
inp = stcb->sctp_ep;
|
|
|
|
*error = 0;
|
|
|
|
for (i = 0; i < totaddr; i++) {
|
2011-05-02 15:53:00 +00:00
|
|
|
switch (sa->sa_family) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
2007-05-08 00:21:05 +00:00
|
|
|
incr = sizeof(struct sockaddr_in);
|
2011-09-15 08:49:54 +00:00
|
|
|
sin = (struct sockaddr_in *)sa;
|
|
|
|
if ((sin->sin_addr.s_addr == INADDR_ANY) ||
|
|
|
|
(sin->sin_addr.s_addr == INADDR_BROADCAST) ||
|
|
|
|
IN_MULTICAST(ntohl(sin->sin_addr.s_addr))) {
|
|
|
|
SCTP_LTRACE_ERR_RET(NULL, stcb, NULL, SCTP_FROM_SCTPUTIL, EINVAL);
|
2015-05-28 16:39:22 +00:00
|
|
|
(void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
|
|
|
|
SCTP_FROM_SCTPUTIL + SCTP_LOC_7);
|
2011-09-15 08:49:54 +00:00
|
|
|
*error = EINVAL;
|
|
|
|
goto out_now;
|
|
|
|
}
|
2016-04-30 14:25:00 +00:00
|
|
|
if (sctp_add_remote_addr(stcb, sa, NULL, stcb->asoc.port,
|
|
|
|
SCTP_DONOT_SETSCOPE,
|
|
|
|
SCTP_ADDR_IS_CONFIRMED)) {
|
2007-05-08 00:21:05 +00:00
|
|
|
/* assoc gone no un-lock */
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(NULL, stcb, NULL, SCTP_FROM_SCTPUTIL, ENOBUFS);
|
2015-05-28 16:39:22 +00:00
|
|
|
(void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
|
|
|
|
SCTP_FROM_SCTPUTIL + SCTP_LOC_8);
|
2007-05-08 00:21:05 +00:00
|
|
|
*error = ENOBUFS;
|
|
|
|
goto out_now;
|
|
|
|
}
|
|
|
|
added++;
|
2011-05-02 15:53:00 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6:
|
2007-05-08 00:21:05 +00:00
|
|
|
incr = sizeof(struct sockaddr_in6);
|
2011-09-15 08:49:54 +00:00
|
|
|
sin6 = (struct sockaddr_in6 *)sa;
|
|
|
|
if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr) ||
|
|
|
|
IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr)) {
|
|
|
|
SCTP_LTRACE_ERR_RET(NULL, stcb, NULL, SCTP_FROM_SCTPUTIL, EINVAL);
|
2015-05-28 16:39:22 +00:00
|
|
|
(void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
|
|
|
|
SCTP_FROM_SCTPUTIL + SCTP_LOC_9);
|
2011-09-15 08:49:54 +00:00
|
|
|
*error = EINVAL;
|
|
|
|
goto out_now;
|
|
|
|
}
|
2016-04-30 14:25:00 +00:00
|
|
|
if (sctp_add_remote_addr(stcb, sa, NULL, stcb->asoc.port,
|
|
|
|
SCTP_DONOT_SETSCOPE,
|
|
|
|
SCTP_ADDR_IS_CONFIRMED)) {
|
2007-05-08 00:21:05 +00:00
|
|
|
/* assoc gone no un-lock */
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(NULL, stcb, NULL, SCTP_FROM_SCTPUTIL, ENOBUFS);
|
2015-05-28 16:39:22 +00:00
|
|
|
(void)sctp_free_assoc(inp, stcb, SCTP_NORMAL_PROC,
|
|
|
|
SCTP_FROM_SCTPUTIL + SCTP_LOC_10);
|
2007-05-08 00:21:05 +00:00
|
|
|
*error = ENOBUFS;
|
|
|
|
goto out_now;
|
|
|
|
}
|
|
|
|
added++;
|
2011-05-02 15:53:00 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
break;
|
2007-05-08 00:21:05 +00:00
|
|
|
}
|
|
|
|
sa = (struct sockaddr *)((caddr_t)sa + incr);
|
|
|
|
}
|
|
|
|
out_now:
|
|
|
|
return (added);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct sctp_tcb *
|
2007-05-28 11:17:24 +00:00
|
|
|
sctp_connectx_helper_find(struct sctp_inpcb *inp, struct sockaddr *addr,
|
2016-03-27 10:04:25 +00:00
|
|
|
unsigned int *totaddr,
|
|
|
|
unsigned int *num_v4, unsigned int *num_v6, int *error,
|
|
|
|
unsigned int limit, int *bad_addr)
|
2007-05-08 00:21:05 +00:00
|
|
|
{
|
|
|
|
struct sockaddr *sa;
|
|
|
|
struct sctp_tcb *stcb = NULL;
|
2016-03-27 10:04:25 +00:00
|
|
|
unsigned int incr, at, i;
|
2007-05-08 00:21:05 +00:00
|
|
|
|
2016-08-20 20:15:36 +00:00
|
|
|
at = 0;
|
2007-05-08 00:21:05 +00:00
|
|
|
sa = addr;
|
|
|
|
*error = *num_v6 = *num_v4 = 0;
|
|
|
|
/* account and validate addresses */
|
2016-03-27 10:04:25 +00:00
|
|
|
for (i = 0; i < *totaddr; i++) {
|
2011-05-02 15:53:00 +00:00
|
|
|
switch (sa->sa_family) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
2016-08-20 20:15:36 +00:00
|
|
|
incr = (unsigned int)sizeof(struct sockaddr_in);
|
2007-05-28 11:17:24 +00:00
|
|
|
if (sa->sa_len != incr) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTPUTIL, EINVAL);
|
2007-05-28 11:17:24 +00:00
|
|
|
*error = EINVAL;
|
|
|
|
*bad_addr = 1;
|
|
|
|
return (NULL);
|
|
|
|
}
|
2016-03-27 10:04:25 +00:00
|
|
|
(*num_v4) += 1;
|
2011-05-02 15:53:00 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6:
|
|
|
|
{
|
|
|
|
struct sockaddr_in6 *sin6;
|
|
|
|
|
|
|
|
sin6 = (struct sockaddr_in6 *)sa;
|
|
|
|
if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
|
|
|
|
/* Must be non-mapped for connectx */
|
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTPUTIL, EINVAL);
|
|
|
|
*error = EINVAL;
|
|
|
|
*bad_addr = 1;
|
|
|
|
return (NULL);
|
|
|
|
}
|
2016-08-20 20:15:36 +00:00
|
|
|
incr = (unsigned int)sizeof(struct sockaddr_in6);
|
2011-05-02 15:53:00 +00:00
|
|
|
if (sa->sa_len != incr) {
|
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTPUTIL, EINVAL);
|
|
|
|
*error = EINVAL;
|
|
|
|
*bad_addr = 1;
|
|
|
|
return (NULL);
|
|
|
|
}
|
2016-03-27 10:04:25 +00:00
|
|
|
(*num_v6) += 1;
|
2011-05-02 15:53:00 +00:00
|
|
|
break;
|
2007-05-28 11:17:24 +00:00
|
|
|
}
|
2011-05-02 15:53:00 +00:00
|
|
|
#endif
|
|
|
|
default:
|
2007-05-08 00:21:05 +00:00
|
|
|
*totaddr = i;
|
2016-08-24 06:22:53 +00:00
|
|
|
incr = 0;
|
2007-05-08 00:21:05 +00:00
|
|
|
/* we are done */
|
|
|
|
break;
|
|
|
|
}
|
2016-03-27 10:04:25 +00:00
|
|
|
if (i == *totaddr) {
|
2011-05-02 15:53:00 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-05-28 11:17:24 +00:00
|
|
|
SCTP_INP_INCR_REF(inp);
|
2007-05-08 00:21:05 +00:00
|
|
|
stcb = sctp_findassociation_ep_addr(&inp, sa, NULL, NULL, NULL);
|
|
|
|
if (stcb != NULL) {
|
|
|
|
/* Already have or am bring up an association */
|
|
|
|
return (stcb);
|
2007-05-28 11:17:24 +00:00
|
|
|
} else {
|
|
|
|
SCTP_INP_DECR_REF(inp);
|
2007-05-08 00:21:05 +00:00
|
|
|
}
|
2016-03-27 10:04:25 +00:00
|
|
|
if ((at + incr) > limit) {
|
2007-05-08 00:21:05 +00:00
|
|
|
*totaddr = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
sa = (struct sockaddr *)((caddr_t)sa + incr);
|
|
|
|
}
|
|
|
|
return ((struct sctp_tcb *)NULL);
|
|
|
|
}
|
2007-06-12 11:21:00 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* sctp_bindx(ADD) for one address.
|
|
|
|
* assumes all arguments are valid/checked by caller.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
sctp_bindx_add_address(struct socket *so, struct sctp_inpcb *inp,
|
|
|
|
struct sockaddr *sa, sctp_assoc_t assoc_id,
|
|
|
|
uint32_t vrf_id, int *error, void *p)
|
|
|
|
{
|
|
|
|
struct sockaddr *addr_touse;
|
2014-12-06 20:00:08 +00:00
|
|
|
#if defined(INET) && defined(INET6)
|
2007-06-12 11:21:00 +00:00
|
|
|
struct sockaddr_in sin;
|
2008-04-16 17:24:18 +00:00
|
|
|
#endif
|
|
|
|
|
2007-06-12 11:21:00 +00:00
|
|
|
/* see if we're bound all already! */
|
|
|
|
if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTPUTIL, EINVAL);
|
2007-06-12 11:21:00 +00:00
|
|
|
*error = EINVAL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
addr_touse = sa;
|
2011-05-02 15:53:00 +00:00
|
|
|
#ifdef INET6
|
2007-06-12 11:21:00 +00:00
|
|
|
if (sa->sa_family == AF_INET6) {
|
2014-12-06 20:00:08 +00:00
|
|
|
#ifdef INET
|
2007-06-12 11:21:00 +00:00
|
|
|
struct sockaddr_in6 *sin6;
|
|
|
|
|
2014-12-06 20:00:08 +00:00
|
|
|
#endif
|
2007-06-12 11:21:00 +00:00
|
|
|
if (sa->sa_len != sizeof(struct sockaddr_in6)) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTPUTIL, EINVAL);
|
2007-06-12 11:21:00 +00:00
|
|
|
*error = EINVAL;
|
|
|
|
return;
|
|
|
|
}
|
2007-06-13 14:39:41 +00:00
|
|
|
if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
|
|
|
|
/* can only bind v6 on PF_INET6 sockets */
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTPUTIL, EINVAL);
|
2007-06-13 14:39:41 +00:00
|
|
|
*error = EINVAL;
|
|
|
|
return;
|
|
|
|
}
|
2014-12-06 20:00:08 +00:00
|
|
|
#ifdef INET
|
2007-06-12 11:21:00 +00:00
|
|
|
sin6 = (struct sockaddr_in6 *)addr_touse;
|
|
|
|
if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
|
2007-06-13 14:39:41 +00:00
|
|
|
if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
|
|
|
|
SCTP_IPV6_V6ONLY(inp)) {
|
|
|
|
/* can't bind v4-mapped on PF_INET sockets */
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTPUTIL, EINVAL);
|
2007-06-13 14:39:41 +00:00
|
|
|
*error = EINVAL;
|
|
|
|
return;
|
|
|
|
}
|
2007-06-12 11:21:00 +00:00
|
|
|
in6_sin6_2_sin(&sin, sin6);
|
|
|
|
addr_touse = (struct sockaddr *)&sin;
|
|
|
|
}
|
2014-12-06 20:00:08 +00:00
|
|
|
#endif
|
2007-06-12 11:21:00 +00:00
|
|
|
}
|
|
|
|
#endif
|
2011-05-02 15:53:00 +00:00
|
|
|
#ifdef INET
|
2007-06-12 11:21:00 +00:00
|
|
|
if (sa->sa_family == AF_INET) {
|
|
|
|
if (sa->sa_len != sizeof(struct sockaddr_in)) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTPUTIL, EINVAL);
|
2007-06-12 11:21:00 +00:00
|
|
|
*error = EINVAL;
|
|
|
|
return;
|
|
|
|
}
|
2007-06-13 14:39:41 +00:00
|
|
|
if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
|
|
|
|
SCTP_IPV6_V6ONLY(inp)) {
|
|
|
|
/* can't bind v4 on PF_INET sockets */
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTPUTIL, EINVAL);
|
2007-06-13 14:39:41 +00:00
|
|
|
*error = EINVAL;
|
|
|
|
return;
|
|
|
|
}
|
2007-06-12 11:21:00 +00:00
|
|
|
}
|
2011-05-02 15:53:00 +00:00
|
|
|
#endif
|
2007-06-12 11:21:00 +00:00
|
|
|
if (inp->sctp_flags & SCTP_PCB_FLAGS_UNBOUND) {
|
|
|
|
if (p == NULL) {
|
|
|
|
/* Can't get proc for Net/Open BSD */
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTPUTIL, EINVAL);
|
2007-06-12 11:21:00 +00:00
|
|
|
*error = EINVAL;
|
|
|
|
return;
|
|
|
|
}
|
2007-07-24 20:06:02 +00:00
|
|
|
*error = sctp_inpcb_bind(so, addr_touse, NULL, p);
|
2007-06-12 11:21:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* No locks required here since bind and mgmt_ep_sa all do their own
|
|
|
|
* locking. If we do something for the FIX: below we may need to
|
|
|
|
* lock in that case.
|
|
|
|
*/
|
|
|
|
if (assoc_id == 0) {
|
|
|
|
/* add the address */
|
|
|
|
struct sctp_inpcb *lep;
|
2007-06-25 19:05:26 +00:00
|
|
|
struct sockaddr_in *lsin = (struct sockaddr_in *)addr_touse;
|
|
|
|
|
|
|
|
/* validate the incoming port */
|
|
|
|
if ((lsin->sin_port != 0) &&
|
|
|
|
(lsin->sin_port != inp->sctp_lport)) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTPUTIL, EINVAL);
|
2007-06-25 19:05:26 +00:00
|
|
|
*error = EINVAL;
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
/* user specified 0 port, set it to existing port */
|
|
|
|
lsin->sin_port = inp->sctp_lport;
|
|
|
|
}
|
2007-06-12 11:21:00 +00:00
|
|
|
|
|
|
|
lep = sctp_pcb_findep(addr_touse, 1, 0, vrf_id);
|
|
|
|
if (lep != NULL) {
|
|
|
|
/*
|
|
|
|
* We must decrement the refcount since we have the
|
|
|
|
* ep already and are binding. No remove going on
|
|
|
|
* here.
|
|
|
|
*/
|
2008-07-31 11:08:30 +00:00
|
|
|
SCTP_INP_DECR_REF(lep);
|
2007-06-12 11:21:00 +00:00
|
|
|
}
|
|
|
|
if (lep == inp) {
|
|
|
|
/* already bound to it.. ok */
|
|
|
|
return;
|
|
|
|
} else if (lep == NULL) {
|
|
|
|
((struct sockaddr_in *)addr_touse)->sin_port = 0;
|
|
|
|
*error = sctp_addr_mgmt_ep_sa(inp, addr_touse,
|
|
|
|
SCTP_ADD_IP_ADDRESS,
|
2007-06-14 22:59:04 +00:00
|
|
|
vrf_id, NULL);
|
2007-06-12 11:21:00 +00:00
|
|
|
} else {
|
|
|
|
*error = EADDRINUSE;
|
|
|
|
}
|
|
|
|
if (*error)
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* FIX: decide whether we allow assoc based bindx
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* sctp_bindx(DELETE) for one address.
|
|
|
|
* assumes all arguments are valid/checked by caller.
|
|
|
|
*/
|
|
|
|
void
|
2011-12-17 19:21:40 +00:00
|
|
|
sctp_bindx_delete_address(struct sctp_inpcb *inp,
|
2007-06-12 11:21:00 +00:00
|
|
|
struct sockaddr *sa, sctp_assoc_t assoc_id,
|
|
|
|
uint32_t vrf_id, int *error)
|
|
|
|
{
|
|
|
|
struct sockaddr *addr_touse;
|
2014-12-06 20:00:08 +00:00
|
|
|
#if defined(INET) && defined(INET6)
|
2007-06-12 11:21:00 +00:00
|
|
|
struct sockaddr_in sin;
|
2008-04-16 17:24:18 +00:00
|
|
|
#endif
|
|
|
|
|
2007-06-12 11:21:00 +00:00
|
|
|
/* see if we're bound all already! */
|
|
|
|
if (inp->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTPUTIL, EINVAL);
|
2007-06-12 11:21:00 +00:00
|
|
|
*error = EINVAL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
addr_touse = sa;
|
2012-07-15 11:04:49 +00:00
|
|
|
#ifdef INET6
|
2007-06-12 11:21:00 +00:00
|
|
|
if (sa->sa_family == AF_INET6) {
|
2014-12-06 20:00:08 +00:00
|
|
|
#ifdef INET
|
2007-06-12 11:21:00 +00:00
|
|
|
struct sockaddr_in6 *sin6;
|
2014-12-06 20:00:08 +00:00
|
|
|
#endif
|
|
|
|
|
2007-06-12 11:21:00 +00:00
|
|
|
if (sa->sa_len != sizeof(struct sockaddr_in6)) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTPUTIL, EINVAL);
|
2007-06-12 11:21:00 +00:00
|
|
|
*error = EINVAL;
|
|
|
|
return;
|
|
|
|
}
|
2007-06-13 14:39:41 +00:00
|
|
|
if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) == 0) {
|
|
|
|
/* can only bind v6 on PF_INET6 sockets */
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTPUTIL, EINVAL);
|
2007-06-13 14:39:41 +00:00
|
|
|
*error = EINVAL;
|
|
|
|
return;
|
|
|
|
}
|
2014-12-06 20:00:08 +00:00
|
|
|
#ifdef INET
|
2007-06-12 11:21:00 +00:00
|
|
|
sin6 = (struct sockaddr_in6 *)addr_touse;
|
|
|
|
if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
|
2007-06-13 14:39:41 +00:00
|
|
|
if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
|
|
|
|
SCTP_IPV6_V6ONLY(inp)) {
|
|
|
|
/* can't bind mapped-v4 on PF_INET sockets */
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTPUTIL, EINVAL);
|
2007-06-13 14:39:41 +00:00
|
|
|
*error = EINVAL;
|
|
|
|
return;
|
|
|
|
}
|
2007-06-12 11:21:00 +00:00
|
|
|
in6_sin6_2_sin(&sin, sin6);
|
|
|
|
addr_touse = (struct sockaddr *)&sin;
|
|
|
|
}
|
2014-12-06 20:00:08 +00:00
|
|
|
#endif
|
2007-06-12 11:21:00 +00:00
|
|
|
}
|
|
|
|
#endif
|
2011-05-02 15:53:00 +00:00
|
|
|
#ifdef INET
|
2007-06-12 11:21:00 +00:00
|
|
|
if (sa->sa_family == AF_INET) {
|
|
|
|
if (sa->sa_len != sizeof(struct sockaddr_in)) {
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTPUTIL, EINVAL);
|
2007-06-12 11:21:00 +00:00
|
|
|
*error = EINVAL;
|
|
|
|
return;
|
|
|
|
}
|
2007-06-13 14:39:41 +00:00
|
|
|
if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
|
|
|
|
SCTP_IPV6_V6ONLY(inp)) {
|
|
|
|
/* can't bind v4 on PF_INET sockets */
|
2007-08-24 00:53:53 +00:00
|
|
|
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTPUTIL, EINVAL);
|
2007-06-13 14:39:41 +00:00
|
|
|
*error = EINVAL;
|
|
|
|
return;
|
|
|
|
}
|
2007-06-12 11:21:00 +00:00
|
|
|
}
|
2011-05-02 15:53:00 +00:00
|
|
|
#endif
|
2007-06-12 11:21:00 +00:00
|
|
|
/*
|
|
|
|
* No lock required mgmt_ep_sa does its own locking. If the FIX:
|
|
|
|
* below is ever changed we may need to lock before calling
|
|
|
|
* association level binding.
|
|
|
|
*/
|
|
|
|
if (assoc_id == 0) {
|
|
|
|
/* delete the address */
|
|
|
|
*error = sctp_addr_mgmt_ep_sa(inp, addr_touse,
|
|
|
|
SCTP_DEL_IP_ADDRESS,
|
2007-06-14 22:59:04 +00:00
|
|
|
vrf_id, NULL);
|
2007-06-12 11:21:00 +00:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* FIX: decide whether we allow assoc based bindx
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
}
|
2007-07-24 20:06:02 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* returns the valid local address count for an assoc, taking into account
|
|
|
|
* all scoping rules
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
sctp_local_addr_count(struct sctp_tcb *stcb)
|
|
|
|
{
|
2013-11-02 20:12:19 +00:00
|
|
|
int loopback_scope;
|
|
|
|
#if defined(INET)
|
|
|
|
int ipv4_local_scope, ipv4_addr_legal;
|
|
|
|
#endif
|
|
|
|
#if defined (INET6)
|
|
|
|
int local_scope, site_scope, ipv6_addr_legal;
|
|
|
|
#endif
|
2007-07-24 20:06:02 +00:00
|
|
|
struct sctp_vrf *vrf;
|
|
|
|
struct sctp_ifn *sctp_ifn;
|
|
|
|
struct sctp_ifa *sctp_ifa;
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
/* Turn on all the appropriate scopes */
|
2013-02-09 17:26:14 +00:00
|
|
|
loopback_scope = stcb->asoc.scope.loopback_scope;
|
2013-11-02 20:12:19 +00:00
|
|
|
#if defined(INET)
|
2013-02-09 17:26:14 +00:00
|
|
|
ipv4_local_scope = stcb->asoc.scope.ipv4_local_scope;
|
2013-11-02 20:12:19 +00:00
|
|
|
ipv4_addr_legal = stcb->asoc.scope.ipv4_addr_legal;
|
|
|
|
#endif
|
|
|
|
#if defined(INET6)
|
2013-02-09 17:26:14 +00:00
|
|
|
local_scope = stcb->asoc.scope.local_scope;
|
|
|
|
site_scope = stcb->asoc.scope.site_scope;
|
|
|
|
ipv6_addr_legal = stcb->asoc.scope.ipv6_addr_legal;
|
2013-11-02 20:12:19 +00:00
|
|
|
#endif
|
2007-09-18 15:16:39 +00:00
|
|
|
SCTP_IPI_ADDR_RLOCK();
|
2007-07-24 20:06:02 +00:00
|
|
|
vrf = sctp_find_vrf(stcb->asoc.vrf_id);
|
|
|
|
if (vrf == NULL) {
|
|
|
|
/* no vrf, no addresses */
|
2007-09-18 15:16:39 +00:00
|
|
|
SCTP_IPI_ADDR_RUNLOCK();
|
2007-07-24 20:06:02 +00:00
|
|
|
return (0);
|
|
|
|
}
|
2018-07-19 20:16:33 +00:00
|
|
|
|
2007-07-24 20:06:02 +00:00
|
|
|
if (stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_BOUNDALL) {
|
|
|
|
/*
|
|
|
|
* bound all case: go through all ifns on the vrf
|
|
|
|
*/
|
|
|
|
LIST_FOREACH(sctp_ifn, &vrf->ifnlist, next_ifn) {
|
|
|
|
if ((loopback_scope == 0) &&
|
|
|
|
SCTP_IFN_IS_IFT_LOOP(sctp_ifn)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
LIST_FOREACH(sctp_ifa, &sctp_ifn->ifalist, next_ifa) {
|
|
|
|
if (sctp_is_addr_restricted(stcb, sctp_ifa))
|
|
|
|
continue;
|
2008-04-16 17:24:18 +00:00
|
|
|
switch (sctp_ifa->address.sa.sa_family) {
|
2011-05-02 15:53:00 +00:00
|
|
|
#ifdef INET
|
2008-04-16 17:24:18 +00:00
|
|
|
case AF_INET:
|
|
|
|
if (ipv4_addr_legal) {
|
|
|
|
struct sockaddr_in *sin;
|
2007-07-24 20:06:02 +00:00
|
|
|
|
2014-09-07 09:06:26 +00:00
|
|
|
sin = &sctp_ifa->address.sin;
|
2008-04-16 17:24:18 +00:00
|
|
|
if (sin->sin_addr.s_addr == 0) {
|
2016-12-26 11:06:41 +00:00
|
|
|
/*
|
|
|
|
* skip unspecified
|
|
|
|
* addrs
|
|
|
|
*/
|
2008-04-16 17:24:18 +00:00
|
|
|
continue;
|
|
|
|
}
|
2014-06-20 13:26:49 +00:00
|
|
|
if (prison_check_ip4(stcb->sctp_ep->ip_inp.inp.inp_cred,
|
|
|
|
&sin->sin_addr) != 0) {
|
|
|
|
continue;
|
|
|
|
}
|
2008-04-16 17:24:18 +00:00
|
|
|
if ((ipv4_local_scope == 0) &&
|
|
|
|
(IN4_ISPRIVATE_ADDRESS(&sin->sin_addr))) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* count this one */
|
|
|
|
count++;
|
|
|
|
} else {
|
2007-07-24 20:06:02 +00:00
|
|
|
continue;
|
|
|
|
}
|
2008-04-16 17:24:18 +00:00
|
|
|
break;
|
2011-05-02 15:53:00 +00:00
|
|
|
#endif
|
2008-04-16 17:24:18 +00:00
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6:
|
|
|
|
if (ipv6_addr_legal) {
|
|
|
|
struct sockaddr_in6 *sin6;
|
|
|
|
|
2014-09-07 09:06:26 +00:00
|
|
|
sin6 = &sctp_ifa->address.sin6;
|
2008-04-16 17:24:18 +00:00
|
|
|
if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
|
2007-07-24 20:06:02 +00:00
|
|
|
continue;
|
2008-04-16 17:24:18 +00:00
|
|
|
}
|
2014-06-20 13:26:49 +00:00
|
|
|
if (prison_check_ip6(stcb->sctp_ep->ip_inp.inp.inp_cred,
|
|
|
|
&sin6->sin6_addr) != 0) {
|
|
|
|
continue;
|
|
|
|
}
|
2008-04-16 17:24:18 +00:00
|
|
|
if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
|
|
|
|
if (local_scope == 0)
|
2007-07-24 20:06:02 +00:00
|
|
|
continue;
|
2008-04-16 17:24:18 +00:00
|
|
|
if (sin6->sin6_scope_id == 0) {
|
|
|
|
if (sa6_recoverscope(sin6) != 0)
|
|
|
|
/*
|
2016-12-06 10:21:25 +00:00
|
|
|
*
|
2008-04-16 17:24:18 +00:00
|
|
|
* bad
|
2016-12-06 10:21:25 +00:00
|
|
|
* link
|
|
|
|
*
|
|
|
|
* local
|
|
|
|
*
|
|
|
|
* address
|
|
|
|
*/
|
2008-04-16 17:24:18 +00:00
|
|
|
continue;
|
|
|
|
}
|
2007-07-24 20:06:02 +00:00
|
|
|
}
|
2008-04-16 17:24:18 +00:00
|
|
|
if ((site_scope == 0) &&
|
|
|
|
(IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr))) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* count this one */
|
|
|
|
count++;
|
2007-07-24 20:06:02 +00:00
|
|
|
}
|
2008-04-16 17:24:18 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
/* TSNH */
|
|
|
|
break;
|
2007-07-24 20:06:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* subset bound case
|
|
|
|
*/
|
|
|
|
struct sctp_laddr *laddr;
|
|
|
|
|
|
|
|
LIST_FOREACH(laddr, &stcb->sctp_ep->sctp_addr_list,
|
|
|
|
sctp_nxt_addr) {
|
|
|
|
if (sctp_is_addr_restricted(stcb, laddr->ifa)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* count this one */
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
2007-09-18 15:16:39 +00:00
|
|
|
SCTP_IPI_ADDR_RUNLOCK();
|
2007-07-24 20:06:02 +00:00
|
|
|
return (count);
|
|
|
|
}
|
2007-08-24 00:53:53 +00:00
|
|
|
|
|
|
|
#if defined(SCTP_LOCAL_TRACE_BUF)
|
|
|
|
|
|
|
|
void
|
2007-09-13 14:43:54 +00:00
|
|
|
sctp_log_trace(uint32_t subsys, const char *str SCTP_UNUSED, uint32_t a, uint32_t b, uint32_t c, uint32_t d, uint32_t e, uint32_t f)
|
2007-08-24 00:53:53 +00:00
|
|
|
{
|
2007-09-13 14:43:54 +00:00
|
|
|
uint32_t saveindex, newindex;
|
2007-08-24 00:53:53 +00:00
|
|
|
|
|
|
|
do {
|
2008-06-14 07:58:05 +00:00
|
|
|
saveindex = SCTP_BASE_SYSCTL(sctp_log).index;
|
2007-08-24 00:53:53 +00:00
|
|
|
if (saveindex >= SCTP_MAX_LOGGING_SIZE) {
|
|
|
|
newindex = 1;
|
|
|
|
} else {
|
|
|
|
newindex = saveindex + 1;
|
|
|
|
}
|
2008-06-14 07:58:05 +00:00
|
|
|
} while (atomic_cmpset_int(&SCTP_BASE_SYSCTL(sctp_log).index, saveindex, newindex) == 0);
|
2007-08-24 00:53:53 +00:00
|
|
|
if (saveindex >= SCTP_MAX_LOGGING_SIZE) {
|
|
|
|
saveindex = 0;
|
|
|
|
}
|
2008-06-14 07:58:05 +00:00
|
|
|
SCTP_BASE_SYSCTL(sctp_log).entry[saveindex].timestamp = SCTP_GET_CYCLECOUNT;
|
|
|
|
SCTP_BASE_SYSCTL(sctp_log).entry[saveindex].subsys = subsys;
|
|
|
|
SCTP_BASE_SYSCTL(sctp_log).entry[saveindex].params[0] = a;
|
|
|
|
SCTP_BASE_SYSCTL(sctp_log).entry[saveindex].params[1] = b;
|
|
|
|
SCTP_BASE_SYSCTL(sctp_log).entry[saveindex].params[2] = c;
|
|
|
|
SCTP_BASE_SYSCTL(sctp_log).entry[saveindex].params[3] = d;
|
|
|
|
SCTP_BASE_SYSCTL(sctp_log).entry[saveindex].params[4] = e;
|
|
|
|
SCTP_BASE_SYSCTL(sctp_log).entry[saveindex].params[5] = f;
|
2007-08-24 00:53:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2009-02-03 11:04:03 +00:00
|
|
|
static void
|
2015-07-22 11:30:37 +00:00
|
|
|
sctp_recv_udp_tunneled_packet(struct mbuf *m, int off, struct inpcb *inp,
|
2014-10-10 06:08:59 +00:00
|
|
|
const struct sockaddr *sa SCTP_UNUSED, void *ctx SCTP_UNUSED)
|
2009-02-03 11:04:03 +00:00
|
|
|
{
|
|
|
|
struct ip *iph;
|
2012-11-17 20:04:04 +00:00
|
|
|
#ifdef INET6
|
|
|
|
struct ip6_hdr *ip6;
|
|
|
|
#endif
|
2009-02-03 11:04:03 +00:00
|
|
|
struct mbuf *sp, *last;
|
|
|
|
struct udphdr *uhdr;
|
2012-06-18 17:09:39 +00:00
|
|
|
uint16_t port;
|
2009-02-03 11:04:03 +00:00
|
|
|
|
|
|
|
if ((m->m_flags & M_PKTHDR) == 0) {
|
|
|
|
/* Can't handle one that is not a pkt hdr */
|
|
|
|
goto out;
|
|
|
|
}
|
2012-06-18 17:09:39 +00:00
|
|
|
/* Pull the src port */
|
2009-02-03 11:04:03 +00:00
|
|
|
iph = mtod(m, struct ip *);
|
|
|
|
uhdr = (struct udphdr *)((caddr_t)iph + off);
|
|
|
|
port = uhdr->uh_sport;
|
2012-06-18 17:09:39 +00:00
|
|
|
/*
|
|
|
|
* Split out the mbuf chain. Leave the IP header in m, place the
|
|
|
|
* rest in the sp.
|
|
|
|
*/
|
2012-12-05 08:04:20 +00:00
|
|
|
sp = m_split(m, off, M_NOWAIT);
|
2009-02-03 11:04:03 +00:00
|
|
|
if (sp == NULL) {
|
|
|
|
/* Gak, drop packet, we can't do a split */
|
|
|
|
goto out;
|
|
|
|
}
|
2012-06-18 17:09:39 +00:00
|
|
|
if (sp->m_pkthdr.len < sizeof(struct udphdr) + sizeof(struct sctphdr)) {
|
|
|
|
/* Gak, packet can't have an SCTP header in it - too small */
|
2009-02-03 11:04:03 +00:00
|
|
|
m_freem(sp);
|
|
|
|
goto out;
|
|
|
|
}
|
2012-06-18 17:09:39 +00:00
|
|
|
/* Now pull up the UDP header and SCTP header together */
|
|
|
|
sp = m_pullup(sp, sizeof(struct udphdr) + sizeof(struct sctphdr));
|
2009-02-03 11:04:03 +00:00
|
|
|
if (sp == NULL) {
|
|
|
|
/* Gak pullup failed */
|
|
|
|
goto out;
|
|
|
|
}
|
2012-06-18 17:09:39 +00:00
|
|
|
/* Trim out the UDP header */
|
2009-02-03 11:04:03 +00:00
|
|
|
m_adj(sp, sizeof(struct udphdr));
|
|
|
|
|
|
|
|
/* Now reconstruct the mbuf chain */
|
2012-06-18 17:09:39 +00:00
|
|
|
for (last = m; last->m_next; last = last->m_next);
|
2009-02-03 11:04:03 +00:00
|
|
|
last->m_next = sp;
|
|
|
|
m->m_pkthdr.len += sp->m_pkthdr.len;
|
2015-11-26 09:25:20 +00:00
|
|
|
/*
|
|
|
|
* The CSUM_DATA_VALID flags indicates that the HW checked the UDP
|
|
|
|
* checksum and it was valid. Since CSUM_DATA_VALID ==
|
|
|
|
* CSUM_SCTP_VALID this would imply that the HW also verified the
|
|
|
|
* SCTP checksum. Therefore, clear the bit.
|
|
|
|
*/
|
|
|
|
SCTPDBG(SCTP_DEBUG_CRCOFFLOAD,
|
|
|
|
"sctp_recv_udp_tunneled_packet(): Packet of length %d received on %s with csum_flags 0x%b.\n",
|
|
|
|
m->m_pkthdr.len,
|
|
|
|
if_name(m->m_pkthdr.rcvif),
|
|
|
|
(int)m->m_pkthdr.csum_flags, CSUM_BITS);
|
|
|
|
m->m_pkthdr.csum_flags &= ~CSUM_DATA_VALID;
|
2009-02-03 11:04:03 +00:00
|
|
|
iph = mtod(m, struct ip *);
|
|
|
|
switch (iph->ip_v) {
|
2011-04-30 11:18:16 +00:00
|
|
|
#ifdef INET
|
2009-02-03 11:04:03 +00:00
|
|
|
case IPVERSION:
|
2012-10-29 20:42:48 +00:00
|
|
|
iph->ip_len = htons(ntohs(iph->ip_len) - sizeof(struct udphdr));
|
2012-06-18 17:09:39 +00:00
|
|
|
sctp_input_with_port(m, off, port);
|
|
|
|
break;
|
2011-04-30 11:18:16 +00:00
|
|
|
#endif
|
2009-02-03 11:04:03 +00:00
|
|
|
#ifdef INET6
|
|
|
|
case IPV6_VERSION >> 4:
|
2012-11-17 20:04:04 +00:00
|
|
|
ip6 = mtod(m, struct ip6_hdr *);
|
|
|
|
ip6->ip6_plen = htons(ntohs(ip6->ip6_plen) - sizeof(struct udphdr));
|
|
|
|
sctp6_input_with_port(&m, &off, port);
|
2012-06-18 17:09:39 +00:00
|
|
|
break;
|
2009-02-03 11:04:03 +00:00
|
|
|
#endif
|
|
|
|
default:
|
2012-06-18 17:09:39 +00:00
|
|
|
goto out;
|
|
|
|
break;
|
2009-02-03 11:04:03 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
out:
|
|
|
|
m_freem(m);
|
|
|
|
}
|
2008-05-20 13:47:46 +00:00
|
|
|
|
2016-04-29 20:22:01 +00:00
|
|
|
#ifdef INET
|
|
|
|
static void
|
|
|
|
sctp_recv_icmp_tunneled_packet(int cmd, struct sockaddr *sa, void *vip, void *ctx SCTP_UNUSED)
|
|
|
|
{
|
|
|
|
struct ip *outer_ip, *inner_ip;
|
|
|
|
struct sctphdr *sh;
|
|
|
|
struct icmp *icmp;
|
|
|
|
struct udphdr *udp;
|
|
|
|
struct sctp_inpcb *inp;
|
|
|
|
struct sctp_tcb *stcb;
|
|
|
|
struct sctp_nets *net;
|
|
|
|
struct sctp_init_chunk *ch;
|
|
|
|
struct sockaddr_in src, dst;
|
|
|
|
uint8_t type, code;
|
|
|
|
|
|
|
|
inner_ip = (struct ip *)vip;
|
|
|
|
icmp = (struct icmp *)((caddr_t)inner_ip -
|
|
|
|
(sizeof(struct icmp) - sizeof(struct ip)));
|
|
|
|
outer_ip = (struct ip *)((caddr_t)icmp - sizeof(struct ip));
|
|
|
|
if (ntohs(outer_ip->ip_len) <
|
|
|
|
sizeof(struct ip) + 8 + (inner_ip->ip_hl << 2) + sizeof(struct udphdr) + 8) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
udp = (struct udphdr *)((caddr_t)inner_ip + (inner_ip->ip_hl << 2));
|
|
|
|
sh = (struct sctphdr *)(udp + 1);
|
|
|
|
memset(&src, 0, sizeof(struct sockaddr_in));
|
|
|
|
src.sin_family = AF_INET;
|
|
|
|
src.sin_len = sizeof(struct sockaddr_in);
|
|
|
|
src.sin_port = sh->src_port;
|
|
|
|
src.sin_addr = inner_ip->ip_src;
|
|
|
|
memset(&dst, 0, sizeof(struct sockaddr_in));
|
|
|
|
dst.sin_family = AF_INET;
|
|
|
|
dst.sin_len = sizeof(struct sockaddr_in);
|
|
|
|
dst.sin_port = sh->dest_port;
|
|
|
|
dst.sin_addr = inner_ip->ip_dst;
|
|
|
|
/*
|
|
|
|
* 'dst' holds the dest of the packet that failed to be sent. 'src'
|
|
|
|
* holds our local endpoint address. Thus we reverse the dst and the
|
|
|
|
* src in the lookup.
|
|
|
|
*/
|
|
|
|
inp = NULL;
|
|
|
|
net = NULL;
|
|
|
|
stcb = sctp_findassociation_addr_sa((struct sockaddr *)&dst,
|
|
|
|
(struct sockaddr *)&src,
|
|
|
|
&inp, &net, 1,
|
|
|
|
SCTP_DEFAULT_VRFID);
|
|
|
|
if ((stcb != NULL) &&
|
|
|
|
(net != NULL) &&
|
2016-06-23 09:13:15 +00:00
|
|
|
(inp != NULL)) {
|
2016-04-29 20:22:01 +00:00
|
|
|
/* Check the UDP port numbers */
|
|
|
|
if ((udp->uh_dport != net->port) ||
|
|
|
|
(udp->uh_sport != htons(SCTP_BASE_SYSCTL(sctp_udp_tunneling_port)))) {
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* Check the verification tag */
|
|
|
|
if (ntohl(sh->v_tag) != 0) {
|
|
|
|
/*
|
|
|
|
* This must be the verification tag used for
|
|
|
|
* sending out packets. We don't consider packets
|
|
|
|
* reflecting the verification tag.
|
|
|
|
*/
|
|
|
|
if (ntohl(sh->v_tag) != stcb->asoc.peer_vtag) {
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (ntohs(outer_ip->ip_len) >=
|
|
|
|
sizeof(struct ip) +
|
|
|
|
8 + (inner_ip->ip_hl << 2) + 8 + 20) {
|
|
|
|
/*
|
|
|
|
* In this case we can check if we got an
|
|
|
|
* INIT chunk and if the initiate tag
|
|
|
|
* matches.
|
|
|
|
*/
|
|
|
|
ch = (struct sctp_init_chunk *)(sh + 1);
|
|
|
|
if ((ch->ch.chunk_type != SCTP_INITIATION) ||
|
|
|
|
(ntohl(ch->init.initiate_tag) != stcb->asoc.my_vtag)) {
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
type = icmp->icmp_type;
|
|
|
|
code = icmp->icmp_code;
|
2016-04-29 20:33:20 +00:00
|
|
|
if ((type == ICMP_UNREACH) &&
|
|
|
|
(code == ICMP_UNREACH_PORT)) {
|
2016-04-29 20:22:01 +00:00
|
|
|
code = ICMP_UNREACH_PROTOCOL;
|
|
|
|
}
|
|
|
|
sctp_notify(inp, stcb, net, type, code,
|
|
|
|
ntohs(inner_ip->ip_len),
|
2018-07-19 20:11:14 +00:00
|
|
|
(uint32_t)ntohs(icmp->icmp_nextmtu));
|
2016-04-29 20:22:01 +00:00
|
|
|
} else {
|
|
|
|
if ((stcb == NULL) && (inp != NULL)) {
|
|
|
|
/* reduce ref-count */
|
|
|
|
SCTP_INP_WLOCK(inp);
|
|
|
|
SCTP_INP_DECR_REF(inp);
|
|
|
|
SCTP_INP_WUNLOCK(inp);
|
|
|
|
}
|
|
|
|
if (stcb) {
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef INET6
|
|
|
|
static void
|
|
|
|
sctp_recv_icmp6_tunneled_packet(int cmd, struct sockaddr *sa, void *d, void *ctx SCTP_UNUSED)
|
|
|
|
{
|
|
|
|
struct ip6ctlparam *ip6cp;
|
|
|
|
struct sctp_inpcb *inp;
|
|
|
|
struct sctp_tcb *stcb;
|
|
|
|
struct sctp_nets *net;
|
|
|
|
struct sctphdr sh;
|
|
|
|
struct udphdr udp;
|
|
|
|
struct sockaddr_in6 src, dst;
|
|
|
|
uint8_t type, code;
|
|
|
|
|
|
|
|
ip6cp = (struct ip6ctlparam *)d;
|
|
|
|
/*
|
|
|
|
* XXX: We assume that when IPV6 is non NULL, M and OFF are valid.
|
|
|
|
*/
|
|
|
|
if (ip6cp->ip6c_m == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Check if we can safely examine the ports and the verification tag
|
|
|
|
* of the SCTP common header.
|
|
|
|
*/
|
|
|
|
if (ip6cp->ip6c_m->m_pkthdr.len <
|
|
|
|
ip6cp->ip6c_off + sizeof(struct udphdr) + offsetof(struct sctphdr, checksum)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* Copy out the UDP header. */
|
|
|
|
memset(&udp, 0, sizeof(struct udphdr));
|
|
|
|
m_copydata(ip6cp->ip6c_m,
|
|
|
|
ip6cp->ip6c_off,
|
|
|
|
sizeof(struct udphdr),
|
|
|
|
(caddr_t)&udp);
|
|
|
|
/* Copy out the port numbers and the verification tag. */
|
|
|
|
memset(&sh, 0, sizeof(struct sctphdr));
|
|
|
|
m_copydata(ip6cp->ip6c_m,
|
|
|
|
ip6cp->ip6c_off + sizeof(struct udphdr),
|
|
|
|
sizeof(uint16_t) + sizeof(uint16_t) + sizeof(uint32_t),
|
|
|
|
(caddr_t)&sh);
|
|
|
|
memset(&src, 0, sizeof(struct sockaddr_in6));
|
|
|
|
src.sin6_family = AF_INET6;
|
|
|
|
src.sin6_len = sizeof(struct sockaddr_in6);
|
|
|
|
src.sin6_port = sh.src_port;
|
|
|
|
src.sin6_addr = ip6cp->ip6c_ip6->ip6_src;
|
|
|
|
if (in6_setscope(&src.sin6_addr, ip6cp->ip6c_m->m_pkthdr.rcvif, NULL) != 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
memset(&dst, 0, sizeof(struct sockaddr_in6));
|
|
|
|
dst.sin6_family = AF_INET6;
|
|
|
|
dst.sin6_len = sizeof(struct sockaddr_in6);
|
|
|
|
dst.sin6_port = sh.dest_port;
|
|
|
|
dst.sin6_addr = ip6cp->ip6c_ip6->ip6_dst;
|
|
|
|
if (in6_setscope(&dst.sin6_addr, ip6cp->ip6c_m->m_pkthdr.rcvif, NULL) != 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
inp = NULL;
|
|
|
|
net = NULL;
|
|
|
|
stcb = sctp_findassociation_addr_sa((struct sockaddr *)&dst,
|
|
|
|
(struct sockaddr *)&src,
|
|
|
|
&inp, &net, 1, SCTP_DEFAULT_VRFID);
|
|
|
|
if ((stcb != NULL) &&
|
|
|
|
(net != NULL) &&
|
2016-06-23 09:13:15 +00:00
|
|
|
(inp != NULL)) {
|
2016-04-29 20:22:01 +00:00
|
|
|
/* Check the UDP port numbers */
|
|
|
|
if ((udp.uh_dport != net->port) ||
|
|
|
|
(udp.uh_sport != htons(SCTP_BASE_SYSCTL(sctp_udp_tunneling_port)))) {
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* Check the verification tag */
|
|
|
|
if (ntohl(sh.v_tag) != 0) {
|
|
|
|
/*
|
|
|
|
* This must be the verification tag used for
|
|
|
|
* sending out packets. We don't consider packets
|
|
|
|
* reflecting the verification tag.
|
|
|
|
*/
|
|
|
|
if (ntohl(sh.v_tag) != stcb->asoc.peer_vtag) {
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (ip6cp->ip6c_m->m_pkthdr.len >=
|
|
|
|
ip6cp->ip6c_off + sizeof(struct udphdr) +
|
|
|
|
sizeof(struct sctphdr) +
|
|
|
|
sizeof(struct sctp_chunkhdr) +
|
|
|
|
offsetof(struct sctp_init, a_rwnd)) {
|
|
|
|
/*
|
|
|
|
* In this case we can check if we got an
|
|
|
|
* INIT chunk and if the initiate tag
|
|
|
|
* matches.
|
|
|
|
*/
|
|
|
|
uint32_t initiate_tag;
|
|
|
|
uint8_t chunk_type;
|
|
|
|
|
|
|
|
m_copydata(ip6cp->ip6c_m,
|
|
|
|
ip6cp->ip6c_off +
|
|
|
|
sizeof(struct udphdr) +
|
|
|
|
sizeof(struct sctphdr),
|
|
|
|
sizeof(uint8_t),
|
|
|
|
(caddr_t)&chunk_type);
|
|
|
|
m_copydata(ip6cp->ip6c_m,
|
|
|
|
ip6cp->ip6c_off +
|
|
|
|
sizeof(struct udphdr) +
|
|
|
|
sizeof(struct sctphdr) +
|
|
|
|
sizeof(struct sctp_chunkhdr),
|
|
|
|
sizeof(uint32_t),
|
|
|
|
(caddr_t)&initiate_tag);
|
|
|
|
if ((chunk_type != SCTP_INITIATION) ||
|
|
|
|
(ntohl(initiate_tag) != stcb->asoc.my_vtag)) {
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
type = ip6cp->ip6c_icmp6->icmp6_type;
|
|
|
|
code = ip6cp->ip6c_icmp6->icmp6_code;
|
|
|
|
if ((type == ICMP6_DST_UNREACH) &&
|
|
|
|
(code == ICMP6_DST_UNREACH_NOPORT)) {
|
|
|
|
type = ICMP6_PARAM_PROB;
|
|
|
|
code = ICMP6_PARAMPROB_NEXTHEADER;
|
|
|
|
}
|
|
|
|
sctp6_notify(inp, stcb, net, type, code,
|
2017-04-26 19:26:40 +00:00
|
|
|
ntohl(ip6cp->ip6c_icmp6->icmp6_mtu));
|
2016-04-29 20:22:01 +00:00
|
|
|
} else {
|
|
|
|
if ((stcb == NULL) && (inp != NULL)) {
|
|
|
|
/* reduce inp's ref-count */
|
|
|
|
SCTP_INP_WLOCK(inp);
|
|
|
|
SCTP_INP_DECR_REF(inp);
|
|
|
|
SCTP_INP_WUNLOCK(inp);
|
|
|
|
}
|
|
|
|
if (stcb) {
|
|
|
|
SCTP_TCB_UNLOCK(stcb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-05-02 15:53:00 +00:00
|
|
|
void
|
2008-05-20 13:47:46 +00:00
|
|
|
sctp_over_udp_stop(void)
|
|
|
|
{
|
2009-02-03 11:04:03 +00:00
|
|
|
/*
|
|
|
|
* This function assumes sysctl caller holds sctp_sysctl_info_lock()
|
|
|
|
* for writting!
|
|
|
|
*/
|
2012-11-17 20:04:04 +00:00
|
|
|
#ifdef INET
|
|
|
|
if (SCTP_BASE_INFO(udp4_tun_socket) != NULL) {
|
|
|
|
soclose(SCTP_BASE_INFO(udp4_tun_socket));
|
|
|
|
SCTP_BASE_INFO(udp4_tun_socket) = NULL;
|
2009-02-03 11:04:03 +00:00
|
|
|
}
|
2012-11-17 20:04:04 +00:00
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
|
|
|
if (SCTP_BASE_INFO(udp6_tun_socket) != NULL) {
|
|
|
|
soclose(SCTP_BASE_INFO(udp6_tun_socket));
|
|
|
|
SCTP_BASE_INFO(udp6_tun_socket) = NULL;
|
|
|
|
}
|
|
|
|
#endif
|
2008-05-20 13:47:46 +00:00
|
|
|
}
|
2011-05-02 15:53:00 +00:00
|
|
|
|
|
|
|
int
|
2008-05-20 13:47:46 +00:00
|
|
|
sctp_over_udp_start(void)
|
|
|
|
{
|
2009-02-03 11:04:03 +00:00
|
|
|
uint16_t port;
|
|
|
|
int ret;
|
2012-11-17 20:04:04 +00:00
|
|
|
#ifdef INET
|
2009-02-03 11:04:03 +00:00
|
|
|
struct sockaddr_in sin;
|
2012-11-17 20:04:04 +00:00
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
|
|
|
struct sockaddr_in6 sin6;
|
|
|
|
#endif
|
2009-02-03 11:04:03 +00:00
|
|
|
/*
|
|
|
|
* This function assumes sysctl caller holds sctp_sysctl_info_lock()
|
|
|
|
* for writting!
|
|
|
|
*/
|
|
|
|
port = SCTP_BASE_SYSCTL(sctp_udp_tunneling_port);
|
2012-11-17 20:04:04 +00:00
|
|
|
if (ntohs(port) == 0) {
|
2009-02-03 11:04:03 +00:00
|
|
|
/* Must have a port set */
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
2012-11-17 20:04:04 +00:00
|
|
|
#ifdef INET
|
|
|
|
if (SCTP_BASE_INFO(udp4_tun_socket) != NULL) {
|
|
|
|
/* Already running -- must stop first */
|
|
|
|
return (EALREADY);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
|
|
|
if (SCTP_BASE_INFO(udp6_tun_socket) != NULL) {
|
2009-02-03 11:04:03 +00:00
|
|
|
/* Already running -- must stop first */
|
|
|
|
return (EALREADY);
|
|
|
|
}
|
2012-11-17 20:04:04 +00:00
|
|
|
#endif
|
|
|
|
#ifdef INET
|
|
|
|
if ((ret = socreate(PF_INET, &SCTP_BASE_INFO(udp4_tun_socket),
|
|
|
|
SOCK_DGRAM, IPPROTO_UDP,
|
|
|
|
curthread->td_ucred, curthread))) {
|
|
|
|
sctp_over_udp_stop();
|
2009-02-03 11:04:03 +00:00
|
|
|
return (ret);
|
|
|
|
}
|
2012-11-17 20:04:04 +00:00
|
|
|
/* Call the special UDP hook. */
|
|
|
|
if ((ret = udp_set_kernel_tunneling(SCTP_BASE_INFO(udp4_tun_socket),
|
2016-04-29 20:22:01 +00:00
|
|
|
sctp_recv_udp_tunneled_packet,
|
|
|
|
sctp_recv_icmp_tunneled_packet,
|
|
|
|
NULL))) {
|
2012-11-17 20:04:04 +00:00
|
|
|
sctp_over_udp_stop();
|
|
|
|
return (ret);
|
2009-02-03 11:04:03 +00:00
|
|
|
}
|
2012-11-17 20:04:04 +00:00
|
|
|
/* Ok, we have a socket, bind it to the port. */
|
|
|
|
memset(&sin, 0, sizeof(struct sockaddr_in));
|
|
|
|
sin.sin_len = sizeof(struct sockaddr_in);
|
2009-02-03 11:04:03 +00:00
|
|
|
sin.sin_family = AF_INET;
|
|
|
|
sin.sin_port = htons(port);
|
2012-11-17 20:04:04 +00:00
|
|
|
if ((ret = sobind(SCTP_BASE_INFO(udp4_tun_socket),
|
|
|
|
(struct sockaddr *)&sin, curthread))) {
|
2009-02-03 11:04:03 +00:00
|
|
|
sctp_over_udp_stop();
|
|
|
|
return (ret);
|
|
|
|
}
|
2012-11-17 20:04:04 +00:00
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
|
|
|
if ((ret = socreate(PF_INET6, &SCTP_BASE_INFO(udp6_tun_socket),
|
|
|
|
SOCK_DGRAM, IPPROTO_UDP,
|
|
|
|
curthread->td_ucred, curthread))) {
|
|
|
|
sctp_over_udp_stop();
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
/* Call the special UDP hook. */
|
|
|
|
if ((ret = udp_set_kernel_tunneling(SCTP_BASE_INFO(udp6_tun_socket),
|
2016-04-29 20:22:01 +00:00
|
|
|
sctp_recv_udp_tunneled_packet,
|
|
|
|
sctp_recv_icmp6_tunneled_packet,
|
|
|
|
NULL))) {
|
2012-11-17 20:04:04 +00:00
|
|
|
sctp_over_udp_stop();
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
/* Ok, we have a socket, bind it to the port. */
|
|
|
|
memset(&sin6, 0, sizeof(struct sockaddr_in6));
|
|
|
|
sin6.sin6_len = sizeof(struct sockaddr_in6);
|
|
|
|
sin6.sin6_family = AF_INET6;
|
|
|
|
sin6.sin6_port = htons(port);
|
|
|
|
if ((ret = sobind(SCTP_BASE_INFO(udp6_tun_socket),
|
|
|
|
(struct sockaddr *)&sin6, curthread))) {
|
|
|
|
sctp_over_udp_stop();
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
#endif
|
2009-02-03 11:04:03 +00:00
|
|
|
return (0);
|
2008-05-20 13:47:46 +00:00
|
|
|
}
|
2017-04-29 19:20:50 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* sctp_min_mtu ()returns the minimum of all non-zero arguments.
|
|
|
|
* If all arguments are zero, zero is returned.
|
|
|
|
*/
|
|
|
|
uint32_t
|
2018-07-19 20:11:14 +00:00
|
|
|
sctp_min_mtu(uint32_t mtu1, uint32_t mtu2, uint32_t mtu3)
|
|
|
|
{
|
2017-04-29 19:20:50 +00:00
|
|
|
if (mtu1 > 0) {
|
|
|
|
if (mtu2 > 0) {
|
|
|
|
if (mtu3 > 0) {
|
|
|
|
return (min(mtu1, min(mtu2, mtu3)));
|
|
|
|
} else {
|
|
|
|
return (min(mtu1, mtu2));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (mtu3 > 0) {
|
|
|
|
return (min(mtu1, mtu3));
|
|
|
|
} else {
|
|
|
|
return (mtu1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (mtu2 > 0) {
|
|
|
|
if (mtu3 > 0) {
|
|
|
|
return (min(mtu2, mtu3));
|
|
|
|
} else {
|
|
|
|
return (mtu2);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return (mtu3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sctp_hc_set_mtu(union sctp_sockstore *addr, uint16_t fibnum, uint32_t mtu)
|
|
|
|
{
|
|
|
|
struct in_conninfo inc;
|
|
|
|
|
|
|
|
memset(&inc, 0, sizeof(struct in_conninfo));
|
|
|
|
inc.inc_fibnum = fibnum;
|
|
|
|
switch (addr->sa.sa_family) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
|
|
|
inc.inc_faddr = addr->sin.sin_addr;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6:
|
|
|
|
inc.inc_flags |= INC_ISIPV6;
|
|
|
|
inc.inc6_faddr = addr->sin6.sin6_addr;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
tcp_hc_updatemtu(&inc, (u_long)mtu);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
2018-07-19 20:11:14 +00:00
|
|
|
sctp_hc_get_mtu(union sctp_sockstore *addr, uint16_t fibnum)
|
|
|
|
{
|
2017-04-29 19:20:50 +00:00
|
|
|
struct in_conninfo inc;
|
|
|
|
|
|
|
|
memset(&inc, 0, sizeof(struct in_conninfo));
|
|
|
|
inc.inc_fibnum = fibnum;
|
|
|
|
switch (addr->sa.sa_family) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
|
|
|
inc.inc_faddr = addr->sin.sin_addr;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6:
|
|
|
|
inc.inc_flags |= INC_ISIPV6;
|
|
|
|
inc.inc6_faddr = addr->sin6.sin6_addr;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
return (0);
|
|
|
|
}
|
2018-07-19 20:11:14 +00:00
|
|
|
return ((uint32_t)tcp_hc_getmtu(&inc));
|
2017-04-29 19:20:50 +00:00
|
|
|
}
|
2018-08-21 13:37:06 +00:00
|
|
|
|
2018-08-21 13:25:32 +00:00
|
|
|
void
|
|
|
|
sctp_set_state(struct sctp_tcb *stcb, int new_state)
|
|
|
|
{
|
2018-08-22 21:23:32 +00:00
|
|
|
#if defined(KDTRACE_HOOKS)
|
|
|
|
int old_state = stcb->asoc.state;
|
|
|
|
#endif
|
|
|
|
|
2018-08-21 13:25:32 +00:00
|
|
|
KASSERT((new_state & ~SCTP_STATE_MASK) == 0,
|
2018-09-26 10:24:50 +00:00
|
|
|
("sctp_set_state: Can't set substate (new_state = %x)",
|
|
|
|
new_state));
|
2018-08-21 13:25:32 +00:00
|
|
|
stcb->asoc.state = (stcb->asoc.state & ~SCTP_STATE_MASK) | new_state;
|
|
|
|
if ((new_state == SCTP_STATE_SHUTDOWN_RECEIVED) ||
|
|
|
|
(new_state == SCTP_STATE_SHUTDOWN_SENT) ||
|
|
|
|
(new_state == SCTP_STATE_SHUTDOWN_ACK_SENT)) {
|
|
|
|
SCTP_CLEAR_SUBSTATE(stcb, SCTP_STATE_SHUTDOWN_PENDING);
|
|
|
|
}
|
2018-08-22 21:23:32 +00:00
|
|
|
#if defined(KDTRACE_HOOKS)
|
|
|
|
if (((old_state & SCTP_STATE_MASK) != new_state) &&
|
|
|
|
!(((old_state & SCTP_STATE_MASK) == SCTP_STATE_EMPTY) &&
|
2018-09-26 10:24:50 +00:00
|
|
|
(new_state == SCTP_STATE_INUSE))) {
|
2018-08-22 21:23:32 +00:00
|
|
|
SCTP_PROBE6(state__change, NULL, stcb, NULL, stcb, NULL, old_state);
|
|
|
|
}
|
|
|
|
#endif
|
2018-08-21 13:25:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sctp_add_substate(struct sctp_tcb *stcb, int substate)
|
|
|
|
{
|
2018-08-22 21:23:32 +00:00
|
|
|
#if defined(KDTRACE_HOOKS)
|
|
|
|
int old_state = stcb->asoc.state;
|
|
|
|
#endif
|
|
|
|
|
2018-08-21 13:25:32 +00:00
|
|
|
KASSERT((substate & SCTP_STATE_MASK) == 0,
|
2018-09-26 10:24:50 +00:00
|
|
|
("sctp_add_substate: Can't set state (substate = %x)",
|
|
|
|
substate));
|
2018-08-21 13:25:32 +00:00
|
|
|
stcb->asoc.state |= substate;
|
2018-08-22 21:23:32 +00:00
|
|
|
#if defined(KDTRACE_HOOKS)
|
|
|
|
if (((substate & SCTP_STATE_ABOUT_TO_BE_FREED) &&
|
2018-09-26 10:24:50 +00:00
|
|
|
((old_state & SCTP_STATE_ABOUT_TO_BE_FREED) == 0)) ||
|
2018-08-22 21:23:32 +00:00
|
|
|
((substate & SCTP_STATE_SHUTDOWN_PENDING) &&
|
2018-09-26 10:24:50 +00:00
|
|
|
((old_state & SCTP_STATE_SHUTDOWN_PENDING) == 0))) {
|
2018-08-22 21:23:32 +00:00
|
|
|
SCTP_PROBE6(state__change, NULL, stcb, NULL, stcb, NULL, old_state);
|
|
|
|
}
|
|
|
|
#endif
|
2018-08-21 13:25:32 +00:00
|
|
|
}
|