Bug 1646715 - Bump usrsctp version to ea345b6d0c8a0f8701cf49445dba5ec8d34e2305 r=bwc

Differential Revision: https://phabricator.services.mozilla.com/D81713
This commit is contained in:
Lennart Grahl 2020-07-09 13:24:23 +00:00
parent 6fd4323032
commit c1c91eceec
60 changed files with 6016 additions and 6663 deletions

View File

@ -17,3 +17,4 @@ sctp updated to version 8815 from SVN on Tue Mar 4 08:50:51 EST 2014
sctp updated to version 9168 from SVN on Tue Mar 3 12:11:40 EST 2015
sctp updated to version 9209 from SVN on Tue Mar 24 18:11:59 EDT 2015
sctp updated to version 0e076261b832121cf120ddc04aaff87ac3a34d30 from git on Tue Nov 28 15:20:51 EST 2017
sctp updated to version ea345b6d0c8a0f8701cf49445dba5ec8d34e2305 from git on Tue 30 Jun 14:01:18 CEST 2020

View File

@ -1,4 +1,3 @@
/*-
* SPDX-License-Identifier: BSD-3-Clause
*
@ -33,22 +32,22 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp.h 356270 2020-01-02 13:55:10Z tuexen $");
__FBSDID("$FreeBSD: head/sys/netinet/sctp.h 356357 2020-01-04 20:33:12Z tuexen $");
#endif
#ifndef _NETINET_SCTP_H_
#define _NETINET_SCTP_H_
#if (defined(__APPLE__) || defined(__Userspace_os_Linux) || defined(__Userspace_os_Darwin))
#if defined(__APPLE__) || defined(__linux__)
#include <stdint.h>
#endif
#include <sys/types.h>
#if !defined(__Userspace_os_Windows)
#if !defined(_WIN32)
#define SCTP_PACKED __attribute__((packed))
#else
#pragma pack (push, 1)
@ -287,11 +286,11 @@ struct sctp_paramhdr {
#define SCTP_PEELOFF 0x0000800a
/* the real worker for sctp_getaddrlen() */
#define SCTP_GET_ADDR_LEN 0x0000800b
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
/* temporary workaround for Apple listen() issue, no args used */
#define SCTP_LISTEN_FIX 0x0000800c
#endif
#if defined(__Windows__)
#if defined(_WIN32) && !defined(__Userspace__)
/* workaround for Cygwin on Windows: returns the SOCKET handle */
#define SCTP_GET_HANDLE 0x0000800d
#endif
@ -531,6 +530,7 @@ struct sctp_error_auth_invalid_hmac {
#define SCTP_PCB_FLAGS_BOUNDALL 0x00000004
#define SCTP_PCB_FLAGS_ACCEPTING 0x00000008
#define SCTP_PCB_FLAGS_UNBOUND 0x00000010
#define SCTP_PCB_FLAGS_SND_ITERATOR_UP 0x00000020
#define SCTP_PCB_FLAGS_CLOSE_IP 0x00040000
#define SCTP_PCB_FLAGS_WAS_CONNECTED 0x00080000
#define SCTP_PCB_FLAGS_WAS_ABORTED 0x00100000
@ -613,7 +613,7 @@ struct sctp_error_auth_invalid_hmac {
/* Largest PMTU allowed when disabling PMTU discovery */
#define SCTP_LARGEST_PMTU 65536
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
#pragma pack(pop)
#endif
#undef SCTP_PACKED

View File

@ -32,9 +32,9 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_asconf.c 324056 2017-09-27 13:05:23Z tuexen $");
__FBSDID("$FreeBSD: head/sys/netinet/sctp_asconf.c 362377 2020-06-19 12:35:29Z tuexen $");
#endif
#include <netinet/sctp_os.h>
@ -53,10 +53,6 @@ __FBSDID("$FreeBSD: head/sys/netinet/sctp_asconf.c 324056 2017-09-27 13:05:23Z t
* SCTP_DEBUG_ASCONF2: detailed info
*/
#if defined(__APPLE__)
#define APPLE_FILE_NO 1
#endif
/*
* RFC 5061
*
@ -105,47 +101,52 @@ sctp_asconf_success_response(uint32_t id)
static struct mbuf *
sctp_asconf_error_response(uint32_t id, uint16_t cause, uint8_t *error_tlv,
uint16_t tlv_length)
uint16_t tlv_length)
{
struct mbuf *m_reply = NULL;
struct sctp_asconf_paramhdr *aph;
struct sctp_error_cause *error;
uint32_t buf_len;
uint16_t i, param_length, cause_length, padding_length;
uint8_t *tlv;
m_reply = sctp_get_mbuf_for_msg((sizeof(struct sctp_asconf_paramhdr) +
tlv_length +
sizeof(struct sctp_error_cause)),
0, M_NOWAIT, 1, MT_DATA);
if (error_tlv == NULL) {
tlv_length = 0;
}
cause_length = sizeof(struct sctp_error_cause) + tlv_length;
param_length = sizeof(struct sctp_asconf_paramhdr) + cause_length;
padding_length = tlv_length % 4;
if (padding_length != 0) {
padding_length = 4 - padding_length;
}
buf_len = param_length + padding_length;
if (buf_len > MLEN) {
SCTPDBG(SCTP_DEBUG_ASCONF1,
"asconf_error_response: tlv_length (%xh) too big\n",
tlv_length);
return (NULL);
}
m_reply = sctp_get_mbuf_for_msg(buf_len, 0, M_NOWAIT, 1, MT_DATA);
if (m_reply == NULL) {
SCTPDBG(SCTP_DEBUG_ASCONF1,
"asconf_error_response: couldn't get mbuf!\n");
return (NULL);
}
aph = mtod(m_reply, struct sctp_asconf_paramhdr *);
error = (struct sctp_error_cause *)(aph + 1);
aph->correlation_id = id;
aph->ph.param_type = htons(SCTP_ERROR_CAUSE_IND);
aph->ph.param_length = htons(param_length);
aph->correlation_id = id;
error = (struct sctp_error_cause *)(aph + 1);
error->code = htons(cause);
error->length = tlv_length + sizeof(struct sctp_error_cause);
aph->ph.param_length = error->length +
sizeof(struct sctp_asconf_paramhdr);
if (aph->ph.param_length > MLEN) {
SCTPDBG(SCTP_DEBUG_ASCONF1,
"asconf_error_response: tlv_length (%xh) too big\n",
tlv_length);
sctp_m_freem(m_reply); /* discard */
return (NULL);
}
error->length = htons(cause_length);
if (error_tlv != NULL) {
tlv = (uint8_t *) (error + 1);
memcpy(tlv, error_tlv, tlv_length);
for (i = 0; i < padding_length; i++) {
tlv[tlv_length + i] = 0;
}
}
SCTP_BUF_LEN(m_reply) = aph->ph.param_length;
error->length = htons(error->length);
aph->ph.param_length = htons(aph->ph.param_length);
SCTP_BUF_LEN(m_reply) = buf_len;
return (m_reply);
}
@ -174,10 +175,16 @@ sctp_process_asconf_add_ip(struct sockaddr *src, struct sctp_asconf_paramhdr *ap
#endif
aparam_length = ntohs(aph->ph.param_length);
if (aparam_length < sizeof(struct sctp_asconf_paramhdr) + sizeof(struct sctp_paramhdr)) {
return (NULL);
}
ph = (struct sctp_paramhdr *)(aph + 1);
param_type = ntohs(ph->param_type);
#if defined(INET) || defined(INET6)
param_length = ntohs(ph->param_length);
if (param_length + sizeof(struct sctp_asconf_paramhdr) != aparam_length) {
return (NULL);
}
#endif
sa = &store.sa;
switch (param_type) {
@ -245,6 +252,7 @@ sctp_process_asconf_add_ip(struct sockaddr *src, struct sctp_asconf_paramhdr *ap
"process_asconf_add_ip: using source addr ");
SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, src);
}
net = NULL;
/* add the address */
if (bad_address) {
m_reply = sctp_asconf_error_response(aph->correlation_id,
@ -259,17 +267,19 @@ sctp_process_asconf_add_ip(struct sockaddr *src, struct sctp_asconf_paramhdr *ap
SCTP_CAUSE_RESOURCE_SHORTAGE, (uint8_t *) aph,
aparam_length);
} else {
/* notify upper layer */
sctp_ulp_notify(SCTP_NOTIFY_ASCONF_ADD_IP, stcb, 0, sa, SCTP_SO_NOT_LOCKED);
if (response_required) {
m_reply =
sctp_asconf_success_response(aph->correlation_id);
}
sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, stcb->sctp_ep, stcb, net);
sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep,
stcb, net);
if (send_hb) {
sctp_send_hb(stcb, net, SCTP_SO_NOT_LOCKED);
if (net != NULL) {
/* notify upper layer */
sctp_ulp_notify(SCTP_NOTIFY_ASCONF_ADD_IP, stcb, 0, sa, SCTP_SO_NOT_LOCKED);
sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, stcb->sctp_ep, stcb, net);
sctp_timer_start(SCTP_TIMER_TYPE_HEARTBEAT, stcb->sctp_ep,
stcb, net);
if (send_hb) {
sctp_send_hb(stcb, net, SCTP_SO_NOT_LOCKED);
}
}
}
return (m_reply);
@ -278,7 +288,7 @@ sctp_process_asconf_add_ip(struct sockaddr *src, struct sctp_asconf_paramhdr *ap
static int
sctp_asconf_del_remote_addrs_except(struct sctp_tcb *stcb, struct sockaddr *src)
{
struct sctp_nets *src_net, *net;
struct sctp_nets *src_net, *net, *nnet;
/* make sure the source address exists as a destination net */
src_net = sctp_findnet(stcb, src);
@ -288,10 +298,9 @@ sctp_asconf_del_remote_addrs_except(struct sctp_tcb *stcb, struct sockaddr *src)
}
/* delete all destination addresses except the source */
TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
TAILQ_FOREACH_SAFE(net, &stcb->asoc.nets, sctp_next, nnet) {
if (net != src_net) {
/* delete this address */
sctp_remove_net(stcb, net);
SCTPDBG(SCTP_DEBUG_ASCONF1,
"asconf_del_remote_addrs_except: deleting ");
SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1,
@ -299,6 +308,7 @@ sctp_asconf_del_remote_addrs_except(struct sctp_tcb *stcb, struct sockaddr *src)
/* notify upper layer */
sctp_ulp_notify(SCTP_NOTIFY_ASCONF_DELETE_IP, stcb, 0,
(struct sockaddr *)&net->ro._l_addr, SCTP_SO_NOT_LOCKED);
sctp_remove_net(stcb, net);
}
}
return (0);
@ -329,10 +339,16 @@ sctp_process_asconf_delete_ip(struct sockaddr *src,
#endif
aparam_length = ntohs(aph->ph.param_length);
if (aparam_length < sizeof(struct sctp_asconf_paramhdr) + sizeof(struct sctp_paramhdr)) {
return (NULL);
}
ph = (struct sctp_paramhdr *)(aph + 1);
param_type = ntohs(ph->param_type);
#if defined(INET) || defined(INET6)
param_length = ntohs(ph->param_length);
if (param_length + sizeof(struct sctp_asconf_paramhdr) != aparam_length) {
return (NULL);
}
#endif
sa = &store.sa;
switch (param_type) {
@ -464,10 +480,16 @@ sctp_process_asconf_set_primary(struct sockaddr *src,
#endif
aparam_length = ntohs(aph->ph.param_length);
if (aparam_length < sizeof(struct sctp_asconf_paramhdr) + sizeof(struct sctp_paramhdr)) {
return (NULL);
}
ph = (struct sctp_paramhdr *)(aph + 1);
param_type = ntohs(ph->param_type);
#if defined(INET) || defined(INET6)
param_length = ntohs(ph->param_length);
if (param_length + sizeof(struct sctp_asconf_paramhdr) != aparam_length) {
return (NULL);
}
#endif
sa = &store.sa;
switch (param_type) {
@ -576,8 +598,7 @@ sctp_process_asconf_set_primary(struct sockaddr *src,
sctp_move_chunks_from_net(stcb,
stcb->asoc.deleted_primary);
}
sctp_delete_prim_timer(stcb->sctp_ep, stcb,
stcb->asoc.deleted_primary);
sctp_delete_prim_timer(stcb->sctp_ep, stcb);
}
} else {
/* couldn't set the requested primary address! */
@ -687,10 +708,11 @@ sctp_handle_asconf(struct mbuf *m, unsigned int offset,
SCTPDBG(SCTP_DEBUG_ASCONF1,
"handle_asconf: couldn't get lookup addr!\n");
/* respond with a missing/invalid mandatory parameter error */
sctp_m_freem(m_ack);
return;
}
/* param_length is already validated in process_control... */
offset += ntohs(p_addr->ph.param_length); /* skip lookup addr */
/* skip lookup addr */
offset += SCTP_SIZE32(ntohs(p_addr->ph.param_length));
/* get pointer to first asconf param in ASCONF */
aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, sizeof(struct sctp_asconf_paramhdr), (uint8_t *)&aparam_buf);
if (aph == NULL) {
@ -719,6 +741,7 @@ sctp_handle_asconf(struct mbuf *m, unsigned int offset,
if (param_length <= sizeof(struct sctp_paramhdr)) {
SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf: param length (%u) too short\n", param_length);
sctp_m_freem(m_ack);
return;
}
/* get the entire parameter */
aph = (struct sctp_asconf_paramhdr *)sctp_m_getptr(m, offset, param_length, aparam_buf);
@ -774,8 +797,6 @@ sctp_handle_asconf(struct mbuf *m, unsigned int offset,
if (m_result != NULL) {
SCTP_BUF_NEXT(m_tail) = m_result;
m_tail = m_result;
/* update lengths, make sure it's aligned too */
SCTP_BUF_LEN(m_result) = SCTP_SIZE32(SCTP_BUF_LEN(m_result));
ack_cp->ch.chunk_length += SCTP_BUF_LEN(m_result);
/* set flag to force success reports */
error = 1;
@ -929,12 +950,12 @@ sctp_addr_match(struct sctp_paramhdr *ph, struct sockaddr *sa)
* Cleanup for non-responded/OP ERR'd ASCONF
*/
void
sctp_asconf_cleanup(struct sctp_tcb *stcb, struct sctp_nets *net)
sctp_asconf_cleanup(struct sctp_tcb *stcb)
{
/*
* clear out any existing asconfs going out
*/
sctp_timer_stop(SCTP_TIMER_TYPE_ASCONF, stcb->sctp_ep, stcb, net,
sctp_timer_stop(SCTP_TIMER_TYPE_ASCONF, stcb->sctp_ep, stcb, NULL,
SCTP_FROM_SCTP_ASCONF + SCTP_LOC_2);
stcb->asoc.asconf_seq_out_acked = stcb->asoc.asconf_seq_out;
/* remove the old ASCONF on our outbound queue */
@ -971,8 +992,12 @@ sctp_asconf_nets_cleanup(struct sctp_tcb *stcb, struct sctp_ifn *ifn)
((ifn == NULL) ||
(SCTP_GET_IF_INDEX_FROM_ROUTE(&net->ro) != ifn->ifn_index))) {
/* clear any cached route */
#if defined(__FreeBSD__) && !defined(__Userspace__)
RO_NHFREE(&net->ro);
#else
RTFREE(net->ro.ro_rt);
net->ro.ro_rt = NULL;
#endif
}
/* clear any cached source address */
if (net->src_addr_selected) {
@ -1024,9 +1049,14 @@ sctp_assoc_immediate_retrans(struct sctp_tcb *stcb, struct sctp_nets *dstnet)
(stcb->asoc.sent_queue_cnt > 0)) {
struct sctp_tmit_chunk *chk;
chk = TAILQ_FIRST(&stcb->asoc.sent_queue);
sctp_timer_start(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep,
stcb, chk->whoTo);
TAILQ_FOREACH(chk, &stcb->asoc.sent_queue, sctp_next) {
if (chk->whoTo != NULL) {
break;
}
}
if (chk != NULL) {
sctp_timer_start(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, stcb, chk->whoTo);
}
}
}
return;
@ -1081,10 +1111,14 @@ sctp_path_check_and_react(struct sctp_tcb *stcb, struct sctp_ifa *newifa)
if (addrnum == 1) {
TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
/* clear any cached route and source address */
#if defined(__FreeBSD__) && !defined(__Userspace__)
RO_NHFREE(&net->ro);
#else
if (net->ro.ro_rt) {
RTFREE(net->ro.ro_rt);
net->ro.ro_rt = NULL;
}
#endif
if (net->src_addr_selected) {
sctp_free_ifa(net->ro._s_addr);
net->ro._s_addr = NULL;
@ -1103,10 +1137,14 @@ sctp_path_check_and_react(struct sctp_tcb *stcb, struct sctp_ifa *newifa)
/* Multiple local addresses exsist in the association. */
TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
/* clear any cached route and source address */
#if defined(__FreeBSD__) && !defined(__Userspace__)
RO_NHFREE(&net->ro);
#else
if (net->ro.ro_rt) {
RTFREE(net->ro.ro_rt);
net->ro.ro_rt = NULL;
}
#endif
if (net->src_addr_selected) {
sctp_free_ifa(net->ro._s_addr);
net->ro._s_addr = NULL;
@ -1121,7 +1159,11 @@ sctp_path_check_and_react(struct sctp_tcb *stcb, struct sctp_ifa *newifa)
SCTP_RTALLOC((sctp_route_t *)&net->ro,
stcb->sctp_ep->def_vrf_id,
stcb->sctp_ep->fibnum);
#if defined(__FreeBSD__) && !defined(__Userspace__)
if (net->ro.ro_nh == NULL)
#else
if (net->ro.ro_rt == NULL)
#endif
continue;
changed = 0;
@ -1161,7 +1203,7 @@ sctp_path_check_and_react(struct sctp_tcb *stcb, struct sctp_ifa *newifa)
}
}
}
#endif /* __FreeBSD__ __APPLE__ __Userspace__ */
#endif
/*
* process an ADD/DELETE IP ack from peer.
@ -1193,7 +1235,7 @@ sctp_asconf_addr_mgmt_ack(struct sctp_tcb *stcb, struct sctp_ifa *addr, uint32_t
sctp_path_check_and_react(stcb, addr);
return;
}
#endif /* __FreeBSD__ __APPLE__ __Userspace__ */
#endif
/* clear any cached/topologically incorrect source addresses */
sctp_asconf_nets_cleanup(stcb, addr->ifn_p);
}
@ -1380,7 +1422,7 @@ sctp_asconf_queue_add(struct sctp_tcb *stcb, struct sctp_ifa *ifa,
if (sctp_asconf_queue_mgmt(stcb,
stcb->asoc.asconf_addr_del_pending,
SCTP_DEL_IP_ADDRESS) == 0) {
SCTPDBG(SCTP_DEBUG_ASCONF2, "asconf_queue_add: queing pending delete\n");
SCTPDBG(SCTP_DEBUG_ASCONF2, "asconf_queue_add: queuing pending delete\n");
pending_delete_queued = 1;
/* clear out the pending delete info */
stcb->asoc.asconf_del_pending = 0;
@ -1697,8 +1739,7 @@ sctp_handle_asconf_ack(struct mbuf *m, int offset,
char msg[SCTP_DIAG_INFO_LEN];
SCTPDBG(SCTP_DEBUG_ASCONF1, "handle_asconf_ack: got unexpected next serial number! Aborting asoc!\n");
snprintf(msg, sizeof(msg), "Never sent serial number %8.8x",
serial_num);
SCTP_SNPRINTF(msg, sizeof(msg), "Never sent serial number %8.8x", serial_num);
op_err = sctp_generate_cause(SCTP_CAUSE_PROTOCOL_VIOLATION, msg);
sctp_abort_an_association(stcb->sctp_ep, stcb, op_err, SCTP_SO_NOT_LOCKED);
*abort_no_unlock = 1;
@ -1713,7 +1754,7 @@ sctp_handle_asconf_ack(struct mbuf *m, int offset,
if (serial_num == asoc->asconf_seq_out - 1) {
/* stop our timer */
sctp_timer_stop(SCTP_TIMER_TYPE_ASCONF, stcb->sctp_ep, stcb, net,
sctp_timer_stop(SCTP_TIMER_TYPE_ASCONF, stcb->sctp_ep, stcb, NULL,
SCTP_FROM_SCTP_ASCONF + SCTP_LOC_5);
}
@ -1787,9 +1828,9 @@ sctp_handle_asconf_ack(struct mbuf *m, int offset,
} /* switch */
/* update remaining ASCONF-ACK message length to process */
ack_length -= SCTP_SIZE32(param_length);
if (ack_length <= 0) {
/* no more data in the mbuf chain */
if (ack_length > SCTP_SIZE32(param_length)) {
ack_length -= SCTP_SIZE32(param_length);
} else {
break;
}
offset += SCTP_SIZE32(param_length);
@ -1900,7 +1941,7 @@ sctp_addr_mgmt_assoc(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
switch (ifa->address.sa.sa_family) {
#ifdef INET6
case AF_INET6:
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
&ifa->address.sin6.sin6_addr) != 0) {
return;
@ -1910,7 +1951,7 @@ sctp_addr_mgmt_assoc(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
#endif
#ifdef INET
case AF_INET:
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
&ifa->address.sin.sin_addr) != 0) {
return;
@ -1971,12 +2012,10 @@ sctp_addr_mgmt_assoc(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
case AF_INET:
{
struct sockaddr_in *sin;
struct in6pcb *inp6;
inp6 = (struct in6pcb *)&inp->ip_inp.inp;
/* invalid if we are a v6 only endpoint */
if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
SCTP_IPV6_V6ONLY(inp6))
SCTP_IPV6_V6ONLY(inp))
return;
sin = &ifa->address.sin;
@ -2009,8 +2048,8 @@ sctp_addr_mgmt_assoc(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
* sent when the state goes open.
*/
if (status == 0 &&
((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
(SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED))) {
((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
(SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED))) {
#ifdef SCTP_TIMER_BASED_ASCONF
sctp_timer_start(SCTP_TIMER_TYPE_ASCONF, inp,
stcb, stcb->asoc.primary_destination);
@ -2049,10 +2088,8 @@ sctp_asconf_iterator_ep(struct sctp_inpcb *inp, void *ptr, uint32_t val SCTP_UNU
case AF_INET:
{
/* invalid if we are a v6 only endpoint */
struct in6pcb *inp6;
inp6 = (struct in6pcb *)&inp->ip_inp.inp;
if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
SCTP_IPV6_V6ONLY(inp6)) {
SCTP_IPV6_V6ONLY(inp)) {
cnt_invalid++;
if (asc->cnt == cnt_invalid)
return (1);
@ -2143,7 +2180,7 @@ sctp_asconf_iterator_stcb(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
/* we skip unspecifed addresses */
continue;
}
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
&sin6->sin6_addr) != 0) {
continue;
@ -2165,13 +2202,11 @@ sctp_asconf_iterator_stcb(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
case AF_INET:
{
/* invalid if we are a v6 only endpoint */
struct in6pcb *inp6;
struct sockaddr_in *sin;
inp6 = (struct in6pcb *)&inp->ip_inp.inp;
/* invalid if we are a v6 only endpoint */
if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
SCTP_IPV6_V6ONLY(inp6))
SCTP_IPV6_V6ONLY(inp))
continue;
sin = &ifa->address.sin;
@ -2179,7 +2214,7 @@ sctp_asconf_iterator_stcb(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
/* we skip unspecifed addresses */
continue;
}
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
&sin->sin_addr) != 0) {
continue;
@ -2190,7 +2225,7 @@ sctp_asconf_iterator_stcb(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
continue;
}
if ((inp->sctp_flags & SCTP_PCB_FLAGS_BOUND_V6) &&
SCTP_IPV6_V6ONLY(inp6)) {
SCTP_IPV6_V6ONLY(inp)) {
cnt_invalid++;
if (asc->cnt == cnt_invalid)
return;
@ -2216,18 +2251,19 @@ sctp_asconf_iterator_stcb(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
} else if (type == SCTP_DEL_IP_ADDRESS) {
struct sctp_nets *net;
TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
sctp_rtentry_t *rt;
/* delete this address if cached */
if (net->ro._s_addr == ifa) {
sctp_free_ifa(net->ro._s_addr);
net->ro._s_addr = NULL;
net->src_addr_selected = 0;
rt = net->ro.ro_rt;
if (rt) {
RTFREE(rt);
#if defined(__FreeBSD__) && !defined(__Userspace__)
RO_NHFREE(&net->ro);
#else
if (net->ro.ro_rt) {
RTFREE(net->ro.ro_rt);
net->ro.ro_rt = NULL;
}
#endif
/*
* Now we deleted our src address,
* should we not also now reset the
@ -2262,8 +2298,8 @@ sctp_asconf_iterator_stcb(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
* count of queued params. If in the non-open state,
* these get sent when the assoc goes open.
*/
if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
(SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
(SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
if (status >= 0) {
num_queued++;
}
@ -2324,8 +2360,8 @@ sctp_set_primary_ip_address_sa(struct sctp_tcb *stcb, struct sockaddr *sa)
"set_primary_ip_address_sa: queued on tcb=%p, ",
(void *)stcb);
SCTPDBG_ADDR(SCTP_DEBUG_ASCONF1, sa);
if ((SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_OPEN) ||
(SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
(SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
#ifdef SCTP_TIMER_BASED_ASCONF
sctp_timer_start(SCTP_TIMER_TYPE_ASCONF,
stcb->sctp_ep, stcb,
@ -2468,7 +2504,7 @@ sctp_find_valid_localaddr(struct sctp_tcb *stcb, int addr_locked)
/* skip unspecifed addresses */
continue;
}
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
if (prison_check_ip4(stcb->sctp_ep->ip_inp.inp.inp_cred,
&sin->sin_addr) != 0) {
continue;
@ -2502,7 +2538,7 @@ sctp_find_valid_localaddr(struct sctp_tcb *stcb, int addr_locked)
/* we skip unspecifed addresses */
continue;
}
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
if (prison_check_ip6(stcb->sctp_ep->ip_inp.inp.inp_cred,
&sin6->sin6_addr) != 0) {
continue;
@ -2860,8 +2896,7 @@ sctp_process_initack_addresses(struct sctp_tcb *stcb, struct mbuf *m,
* out the ASCONF.
*/
if (status == 0 &&
SCTP_GET_STATE(&stcb->asoc) ==
SCTP_STATE_OPEN) {
SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) {
#ifdef SCTP_TIMER_BASED_ASCONF
sctp_timer_start(SCTP_TIMER_TYPE_ASCONF,
stcb->sctp_ep, stcb,
@ -3036,10 +3071,6 @@ sctp_check_address_list_ep(struct sctp_tcb *stcb, struct mbuf *m, int offset,
"check_addr_list_ep: laddr->ifa is NULL");
continue;
}
if (laddr->ifa == NULL) {
SCTPDBG(SCTP_DEBUG_ASCONF1, "check_addr_list_ep: laddr->ifa->ifa_addr is NULL");
continue;
}
/* do i have it implicitly? */
if (sctp_cmpaddr(&laddr->ifa->address.sa, init_addr)) {
continue;
@ -3101,7 +3132,7 @@ sctp_check_address_list_all(struct sctp_tcb *stcb, struct mbuf *m, int offset,
#ifdef INET
case AF_INET:
sin = &sctp_ifa->address.sin;
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
if (prison_check_ip4(stcb->sctp_ep->ip_inp.inp.inp_cred,
&sin->sin_addr) != 0) {
continue;
@ -3117,7 +3148,7 @@ sctp_check_address_list_all(struct sctp_tcb *stcb, struct mbuf *m, int offset,
#ifdef INET6
case AF_INET6:
sin6 = &sctp_ifa->address.sin6;
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
if (prison_check_ip6(stcb->sctp_ep->ip_inp.inp.inp_cred,
&sin6->sin6_addr) != 0) {
continue;
@ -3186,7 +3217,7 @@ sctp_check_address_list(struct sctp_tcb *stcb, struct mbuf *m, int offset,
*/
uint32_t
sctp_addr_mgmt_ep_sa(struct sctp_inpcb *inp, struct sockaddr *sa,
uint32_t type, uint32_t vrf_id, struct sctp_ifa *sctp_ifap)
uint32_t type, uint32_t vrf_id)
{
struct sctp_ifa *ifa;
struct sctp_laddr *laddr, *nladdr;
@ -3197,9 +3228,7 @@ sctp_addr_mgmt_ep_sa(struct sctp_inpcb *inp, struct sockaddr *sa,
return (EINVAL);
}
#endif
if (sctp_ifap) {
ifa = sctp_ifap;
} else if (type == SCTP_ADD_IP_ADDRESS) {
if (type == SCTP_ADD_IP_ADDRESS) {
/* For an add the address MUST be on the system */
ifa = sctp_find_ifa_by_addr(sa, vrf_id, SCTP_ADDR_NOT_LOCKED);
} else if (type == SCTP_DEL_IP_ADDRESS) {
@ -3427,7 +3456,7 @@ sctp_asconf_send_nat_state_update(struct sctp_tcb *stcb,
#ifdef INET
case AF_INET:
to = &sctp_ifap->address.sin;
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
if (prison_check_ip4(stcb->sctp_ep->ip_inp.inp.inp_cred,
&to->sin_addr) != 0) {
continue;
@ -3444,7 +3473,7 @@ sctp_asconf_send_nat_state_update(struct sctp_tcb *stcb,
#ifdef INET6
case AF_INET6:
to6 = &sctp_ifap->address.sin6;
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
if (prison_check_ip6(stcb->sctp_ep->ip_inp.inp.inp_cred,
&to6->sin6_addr) != 0) {
continue;

View File

@ -32,9 +32,9 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_asconf.h 324056 2017-09-27 13:05:23Z tuexen $");
__FBSDID("$FreeBSD: head/sys/netinet/sctp_asconf.h 362377 2020-06-19 12:35:29Z tuexen $");
#endif
#ifndef _NETINET_SCTP_ASCONF_H_
@ -45,7 +45,7 @@ __FBSDID("$FreeBSD: head/sys/netinet/sctp_asconf.h 324056 2017-09-27 13:05:23Z t
/*
* function prototypes
*/
extern void sctp_asconf_cleanup(struct sctp_tcb *, struct sctp_nets *);
extern void sctp_asconf_cleanup(struct sctp_tcb *);
extern struct mbuf *sctp_compose_asconf(struct sctp_tcb *, int *, int);
@ -58,8 +58,8 @@ sctp_handle_asconf_ack(struct mbuf *, int, struct sctp_asconf_ack_chunk *,
struct sctp_tcb *, struct sctp_nets *, int *);
extern uint32_t
sctp_addr_mgmt_ep_sa(struct sctp_inpcb *, struct sockaddr *,
uint32_t, uint32_t, struct sctp_ifa *);
sctp_addr_mgmt_ep_sa(struct sctp_inpcb *, struct sockaddr *, uint32_t,
uint32_t);
extern int sctp_asconf_iterator_ep(struct sctp_inpcb *inp, void *ptr,

View File

@ -32,9 +32,9 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_auth.c 355931 2019-12-20 15:25:08Z tuexen $");
__FBSDID("$FreeBSD: head/sys/netinet/sctp_auth.c 362054 2020-06-11 13:34:09Z tuexen $");
#endif
#include <netinet/sctp_os.h>
@ -525,7 +525,7 @@ sctp_insert_sharedkey(struct sctp_keyhead *shared_keys,
} else if (new_skey->keyid == skey->keyid) {
/* replace the existing key */
/* verify this key *can* be replaced */
if ((skey->deactivated) && (skey->refcount > 1)) {
if ((skey->deactivated) || (skey->refcount > 1)) {
SCTPDBG(SCTP_DEBUG_AUTH1,
"can't replace shared key id %u\n",
new_skey->keyid);
@ -567,11 +567,7 @@ sctp_auth_key_acquire(struct sctp_tcb *stcb, uint16_t key_id)
}
void
sctp_auth_key_release(struct sctp_tcb *stcb, uint16_t key_id, int so_locked
#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
SCTP_UNUSED
#endif
)
sctp_auth_key_release(struct sctp_tcb *stcb, uint16_t key_id, int so_locked)
{
sctp_sharedkey_t *skey;
@ -660,7 +656,6 @@ sctp_free_hmaclist(sctp_hmaclist_t *list)
{
if (list != NULL) {
SCTP_FREE(list,SCTP_M_AUTH_HL);
list = NULL;
}
}
@ -1084,40 +1079,6 @@ sctp_hmac_m(uint16_t hmac_algo, uint8_t *key, uint32_t keylen,
return (digestlen);
}
/*-
* verify the HMAC digest using the desired hash key, text, and HMAC
* algorithm.
* Returns -1 on error, 0 on success.
*/
int
sctp_verify_hmac(uint16_t hmac_algo, uint8_t *key, uint32_t keylen,
uint8_t *text, uint32_t textlen,
uint8_t *digest, uint32_t digestlen)
{
uint32_t len;
uint8_t temp[SCTP_AUTH_DIGEST_LEN_MAX];
/* sanity check the material and length */
if ((key == NULL) || (keylen == 0) ||
(text == NULL) || (textlen == 0) || (digest == NULL)) {
/* can't do HMAC with empty key or text or digest */
return (-1);
}
len = sctp_get_hmac_digest_len(hmac_algo);
if ((len == 0) || (digestlen != len))
return (-1);
/* compute the expected hash */
if (sctp_hmac(hmac_algo, key, keylen, text, textlen, temp) != len)
return (-1);
if (memcmp(digest, temp, digestlen) != 0)
return (-1);
else
return (0);
}
/*
* computes the requested HMAC using a key struct (which may be modified if
* the keylen exceeds the HMAC block len).
@ -1527,24 +1488,24 @@ sctp_auth_get_cookie_params(struct sctp_tcb *stcb, struct mbuf *m,
}
new_key = sctp_alloc_key(keylen);
if (new_key != NULL) {
/* copy in the RANDOM */
if (p_random != NULL) {
keylen = sizeof(*p_random) + random_len;
memcpy(new_key->key, p_random, keylen);
} else {
keylen = 0;
}
/* append in the AUTH chunks */
if (chunks != NULL) {
memcpy(new_key->key + keylen, chunks,
sizeof(*chunks) + num_chunks);
keylen += sizeof(*chunks) + num_chunks;
}
/* append in the HMACs */
if (hmacs != NULL) {
memcpy(new_key->key + keylen, hmacs,
sizeof(*hmacs) + hmacs_len);
}
/* copy in the RANDOM */
if (p_random != NULL) {
keylen = sizeof(*p_random) + random_len;
memcpy(new_key->key, p_random, keylen);
} else {
keylen = 0;
}
/* append in the AUTH chunks */
if (chunks != NULL) {
memcpy(new_key->key + keylen, chunks,
sizeof(*chunks) + num_chunks);
keylen += sizeof(*chunks) + num_chunks;
}
/* append in the HMACs */
if (hmacs != NULL) {
memcpy(new_key->key + keylen, hmacs,
sizeof(*hmacs) + hmacs_len);
}
}
if (stcb->asoc.authinfo.random != NULL)
sctp_free_key(stcb->asoc.authinfo.random);
@ -1684,6 +1645,11 @@ sctp_handle_auth(struct sctp_tcb *stcb, struct sctp_auth_chunk *auth,
"SCTP AUTH Chunk: shared key %u, HMAC id %u\n",
shared_key_id, hmac_id);
#if defined(__Userspace__)
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
return (0);
#endif
#endif
/* is the indicated HMAC supported? */
if (!sctp_auth_is_supported_hmac(stcb->asoc.local_hmacs, hmac_id)) {
struct mbuf *op_err;
@ -1765,7 +1731,7 @@ sctp_handle_auth(struct sctp_tcb *stcb, struct sctp_auth_chunk *auth,
m, offset, computed_digest);
/* compare the computed digest with the one in the AUTH chunk */
if (memcmp(digest, computed_digest, digestlen) != 0) {
if (timingsafe_bcmp(digest, computed_digest, digestlen) != 0) {
SCTP_STAT_INCR(sctps_recvauthfailed);
SCTPDBG(SCTP_DEBUG_AUTH1,
"SCTP Auth: HMAC digest check failed\n");
@ -1779,11 +1745,7 @@ sctp_handle_auth(struct sctp_tcb *stcb, struct sctp_auth_chunk *auth,
*/
void
sctp_notify_authentication(struct sctp_tcb *stcb, uint32_t indication,
uint16_t keyid, uint16_t alt_keyid, int so_locked
#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
SCTP_UNUSED
#endif
)
uint16_t keyid, uint16_t alt_keyid, int so_locked)
{
struct mbuf *m_notify;
struct sctp_authkey_event *auth;

View File

@ -32,9 +32,9 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_auth.h 310590 2016-12-26 11:06:41Z tuexen $");
__FBSDID("$FreeBSD: head/sys/netinet/sctp_auth.h 338749 2018-09-18 10:53:07Z tuexen $");
#endif
#ifndef _NETINET_SCTP_AUTH_H_
@ -170,8 +170,6 @@ extern uint32_t sctp_get_auth_chunk_len(uint16_t hmac_algo);
extern uint32_t sctp_get_hmac_digest_len(uint16_t hmac_algo);
extern uint32_t sctp_hmac(uint16_t hmac_algo, uint8_t *key, uint32_t keylen,
uint8_t *text, uint32_t textlen, uint8_t *digest);
extern int sctp_verify_hmac(uint16_t hmac_algo, uint8_t *key, uint32_t keylen,
uint8_t *text, uint32_t textlen, uint8_t *digest, uint32_t digestlen);
extern uint32_t sctp_compute_hmac(uint16_t hmac_algo, sctp_key_t *key,
uint8_t *text, uint32_t textlen, uint8_t *digest);
extern int sctp_auth_is_supported_hmac(sctp_hmaclist_t *list, uint16_t id);

View File

@ -32,9 +32,9 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_bsd_addr.c 310590 2016-12-26 11:06:41Z tuexen $");
__FBSDID("$FreeBSD: head/sys/netinet/sctp_bsd_addr.c 358080 2020-02-18 19:41:55Z tuexen $");
#endif
#include <netinet/sctp_os.h>
@ -50,17 +50,11 @@ __FBSDID("$FreeBSD: head/sys/netinet/sctp_bsd_addr.c 310590 2016-12-26 11:06:41Z
#include <netinet/sctp_asconf.h>
#include <netinet/sctp_sysctl.h>
#include <netinet/sctp_indata.h>
#if defined(ANDROID)
#include <unistd.h>
#include <ifaddrs-android-ext.h>
#else
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/unistd.h>
#endif
#endif
/* Declare all of our malloc named types */
#ifndef __Panda__
MALLOC_DEFINE(SCTP_M_MAP, "sctp_map", "sctp asoc map descriptor");
MALLOC_DEFINE(SCTP_M_STRMI, "sctp_stri", "sctp stream in array");
MALLOC_DEFINE(SCTP_M_STRMO, "sctp_stro", "sctp stream out array");
@ -81,12 +75,11 @@ MALLOC_DEFINE(SCTP_M_MVRF, "sctp_mvrf", "sctp mvrf pcb list");
MALLOC_DEFINE(SCTP_M_ITER, "sctp_iter", "sctp iterator control");
MALLOC_DEFINE(SCTP_M_SOCKOPT, "sctp_socko", "sctp socket option");
MALLOC_DEFINE(SCTP_M_MCORE, "sctp_mcore", "sctp mcore queue");
#endif
/* Global NON-VNET structure that controls the iterator */
struct iterator_control sctp_it_ctl;
#if !defined(__FreeBSD__)
#if !(defined(__FreeBSD__) && !defined(__Userspace__))
static void
sctp_cleanup_itqueue(void)
{
@ -114,7 +107,7 @@ void
sctp_wakeup_iterator(void)
{
#if defined(SCTP_PROCESS_LEVEL_LOCKS)
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
WakeAllConditionVariable(&sctp_it_ctl.iterator_wakeup);
#else
pthread_cond_broadcast(&sctp_it_ctl.iterator_wakeup);
@ -136,7 +129,7 @@ sctp_iterator_thread(void *v SCTP_UNUSED)
#endif
SCTP_IPI_ITERATOR_WQ_LOCK();
/* In FreeBSD this thread never terminates. */
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
for (;;) {
#else
while ((sctp_it_ctl.iterator_flags & SCTP_ITERATOR_MUST_EXIT) == 0) {
@ -145,25 +138,25 @@ sctp_iterator_thread(void *v SCTP_UNUSED)
msleep(&sctp_it_ctl.iterator_running,
#if defined(__FreeBSD__)
&sctp_it_ctl.ipi_iterator_wq_mtx,
#elif defined(__APPLE__) || defined(__Userspace_os_Darwin)
#elif defined(__APPLE__)
sctp_it_ctl.ipi_iterator_wq_mtx,
#endif
0, "waiting_for_work", 0);
#else
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
SleepConditionVariableCS(&sctp_it_ctl.iterator_wakeup, &sctp_it_ctl.ipi_iterator_wq_mtx, INFINITE);
#else
pthread_cond_wait(&sctp_it_ctl.iterator_wakeup, &sctp_it_ctl.ipi_iterator_wq_mtx);
#endif
#endif
#if !defined(__FreeBSD__)
#if !(defined(__FreeBSD__) && !defined(__Userspace__))
if (sctp_it_ctl.iterator_flags & SCTP_ITERATOR_MUST_EXIT) {
break;
}
#endif
sctp_iterator_worker();
}
#if !defined(__FreeBSD__)
#if !(defined(__FreeBSD__) && !defined(__Userspace__))
/* Now this thread needs to be terminated */
sctp_cleanup_itqueue();
sctp_it_ctl.iterator_flags |= SCTP_ITERATOR_EXITED;
@ -192,12 +185,14 @@ sctp_startup_iterator(void)
SCTP_ITERATOR_LOCK_INIT();
SCTP_IPI_ITERATOR_WQ_INIT();
TAILQ_INIT(&sctp_it_ctl.iteratorhead);
#if defined(__FreeBSD__)
#if __FreeBSD_version <= 701000
kthread_create(sctp_iterator_thread,
#else
#if defined(__Userspace__)
if (sctp_userspace_thread_create(&sctp_it_ctl.thread_proc, &sctp_iterator_thread)) {
SCTP_PRINTF("ERROR: Creating sctp_iterator_thread failed.\n");
} else {
SCTP_BASE_VAR(iterator_thread_started) = 1;
}
#elif defined(__FreeBSD__)
kproc_create(sctp_iterator_thread,
#endif
(void *)NULL,
&sctp_it_ctl.thread_proc,
RFPROC,
@ -205,10 +200,6 @@ sctp_startup_iterator(void)
SCTP_KTRHEAD_NAME);
#elif defined(__APPLE__)
kernel_thread_start((thread_continue_t)sctp_iterator_thread, NULL, &sctp_it_ctl.thread_proc);
#elif defined(__Userspace__)
if (sctp_userspace_thread_create(&sctp_it_ctl.thread_proc, &sctp_iterator_thread)) {
SCTP_PRINTF("ERROR: Creating sctp_iterator_thread failed.\n");
}
#endif
}
@ -261,7 +252,7 @@ sctp_is_desired_interface_type(struct ifnet *ifn)
int result;
/* check the interface type to see if it's one we care about */
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
switch(ifnet_type(ifn)) {
#else
switch (ifn->if_type) {
@ -287,7 +278,7 @@ sctp_is_desired_interface_type(struct ifnet *ifn)
case IFT_GIF:
case IFT_L2VLAN:
case IFT_STF:
#if !defined(__APPLE__)
#if !(defined(__APPLE__) && !defined(__Userspace__))
case IFT_IP:
case IFT_IPOVERCDLC:
case IFT_IPOVERCLAW:
@ -304,7 +295,7 @@ sctp_is_desired_interface_type(struct ifnet *ifn)
}
#endif
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
int
sctp_is_vmware_interface(struct ifnet *ifn)
{
@ -312,7 +303,7 @@ sctp_is_vmware_interface(struct ifnet *ifn)
}
#endif
#if defined(__Userspace_os_Windows)
#if defined(_WIN32) && defined(__Userspace__)
#ifdef MALLOC
#undef MALLOC
#define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x))
@ -486,7 +477,7 @@ sctp_init_ifns_for_vrf(int vrfid)
}
#endif
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
static void
sctp_init_ifns_for_vrf(int vrfid)
{
@ -545,7 +536,7 @@ sctp_init_ifns_for_vrf(int vrfid)
} else {
ifa_flags = 0;
}
snprintf(name, SCTP_IFNAMSIZ, "%s%d", ifnet_name(ifn), ifnet_unit(ifn));
SCTP_SNPRINTF(name, SCTP_IFNAMSIZ, "%s%d", ifnet_name(ifn), ifnet_unit(ifn));
sctp_ifa = sctp_add_addr_to_vrf(vrfid,
(void *)ifn, /* XXX */
ifnet_index(ifn),
@ -565,7 +556,7 @@ sctp_init_ifns_for_vrf(int vrfid)
}
#endif
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
static void
sctp_init_ifns_for_vrf(int vrfid)
{
@ -574,6 +565,7 @@ sctp_init_ifns_for_vrf(int vrfid)
* any IFA that exists as we float through the
* list of IFA's
*/
struct epoch_tracker et;
struct ifnet *ifn;
struct ifaddr *ifa;
struct sctp_ifa *sctp_ifa;
@ -583,17 +575,13 @@ sctp_init_ifns_for_vrf(int vrfid)
#endif
IFNET_RLOCK();
TAILQ_FOREACH(ifn, &MODULE_GLOBAL(ifnet), if_link) {
NET_EPOCH_ENTER(et);
CK_STAILQ_FOREACH(ifn, &MODULE_GLOBAL(ifnet), if_link) {
if (sctp_is_desired_interface_type(ifn) == 0) {
/* non desired type */
continue;
}
#if (__FreeBSD_version >= 803000 && __FreeBSD_version < 900000) || __FreeBSD_version > 900000
IF_ADDR_RLOCK(ifn);
#else
IF_ADDR_LOCK(ifn);
#endif
TAILQ_FOREACH(ifa, &ifn->if_addrhead, ifa_link) {
CK_STAILQ_FOREACH(ifa, &ifn->if_addrhead, ifa_link) {
if (ifa->ifa_addr == NULL) {
continue;
}
@ -645,12 +633,8 @@ sctp_init_ifns_for_vrf(int vrfid)
sctp_ifa->localifa_flags &= ~SCTP_ADDR_DEFER_USE;
}
}
#if (__FreeBSD_version >= 803000 && __FreeBSD_version < 900000) || __FreeBSD_version > 900000
IF_ADDR_RUNLOCK(ifn);
#else
IF_ADDR_UNLOCK(ifn);
#endif
}
NET_EPOCH_EXIT(et);
IFNET_RUNLOCK();
}
#endif
@ -728,7 +712,7 @@ sctp_addr_change(struct ifaddr *ifa, int cmd)
}
if (cmd == RTM_ADD) {
(void)sctp_add_addr_to_vrf(SCTP_DEFAULT_VRFID, (void *)ifa->ifa_ifp,
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
ifnet_index(ifa->ifa_ifp), ifnet_type(ifa->ifa_ifp), ifnet_name(ifa->ifa_ifp),
#else
ifa->ifa_ifp->if_index, ifa->ifa_ifp->if_type, ifa->ifa_ifp->if_xname,
@ -737,7 +721,7 @@ sctp_addr_change(struct ifaddr *ifa, int cmd)
} else {
sctp_del_addr_from_vrf(SCTP_DEFAULT_VRFID, ifa->ifa_addr,
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
ifnet_index(ifa->ifa_ifp),
ifnet_name(ifa->ifa_ifp));
#else
@ -752,26 +736,13 @@ sctp_addr_change(struct ifaddr *ifa, int cmd)
#endif
}
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
void
sctp_add_or_del_interfaces(int (*pred)(struct ifnet *), int add)
{
struct ifnet *ifn;
struct ifaddr *ifa;
IFNET_RLOCK();
TAILQ_FOREACH(ifn, &MODULE_GLOBAL(ifnet), if_link) {
if (!(*pred)(ifn)) {
continue;
}
TAILQ_FOREACH(ifa, &ifn->if_addrhead, ifa_link) {
sctp_addr_change(ifa, add ? RTM_ADD : RTM_DELETE);
}
}
IFNET_RUNLOCK();
sctp_addr_change_event_handler(void *arg __unused, struct ifaddr *ifa, int cmd) {
sctp_addr_change(ifa, cmd);
}
#endif
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
void
sctp_add_or_del_interfaces(int (*pred)(struct ifnet *), int add)
{
@ -803,145 +774,52 @@ struct mbuf *
sctp_get_mbuf_for_msg(unsigned int space_needed, int want_header,
int how, int allonebuf, int type)
{
struct mbuf *m = NULL;
struct mbuf *m = NULL;
#if defined(__FreeBSD__) || defined(__Userspace__)
#if defined(__Userspace__)
/*
* __Userspace__
* Using m_clget, which creates and mbuf and a cluster and
* hooks those together.
* TODO: This does not yet have functionality for jumbo packets.
*
*/
int mbuf_threshold;
if (want_header) {
MGETHDR(m, how, type);
} else {
MGET(m, how, type);
}
if (m == NULL) {
return (NULL);
}
if (allonebuf == 0)
mbuf_threshold = SCTP_BASE_SYSCTL(sctp_mbuf_threshold_count);
else
mbuf_threshold = 1;
if ((int)space_needed > (((mbuf_threshold - 1) * MLEN) + MHLEN)) {
MCLGET(m, how);
if (SCTP_BUF_IS_EXTENDED(m) == 0) {
sctp_m_freem(m);
return (NULL);
}
}
SCTP_BUF_LEN(m) = 0;
SCTP_BUF_NEXT(m) = SCTP_BUF_NEXT_PKT(m) = NULL;
/* __Userspace__
* Check if anything need to be done to ensure logging works
*/
#ifdef SCTP_MBUF_LOGGING
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MBUF_LOGGING_ENABLE) {
sctp_log_mb(m, SCTP_MBUF_IALLOC);
}
#endif
#elif defined(__FreeBSD__) && __FreeBSD_version > 1100052
m = m_getm2(NULL, space_needed, how, type, want_header ? M_PKTHDR : 0, allonebuf);
#else
m = m_getm2(NULL, space_needed, how, type, want_header ? M_PKTHDR : 0);
#endif
if (m == NULL) {
/* bad, no memory */
return (m);
}
#if !defined(__Userspace__)
if (allonebuf) {
if (SCTP_BUF_SIZE(m) < space_needed) {
m_freem(m);
return (NULL);
}
}
if (SCTP_BUF_NEXT(m)) {
sctp_m_freem(SCTP_BUF_NEXT(m));
SCTP_BUF_NEXT(m) = NULL;
}
#ifdef SCTP_MBUF_LOGGING
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MBUF_LOGGING_ENABLE) {
sctp_log_mb(m, SCTP_MBUF_IALLOC);
KASSERT(SCTP_BUF_NEXT(m) == NULL, ("%s: no chain allowed", __FUNCTION__));
}
#endif
#elif defined(__FreeBSD__) && __FreeBSD_version > 602000
m = m_getm2(NULL, space_needed, how, type, want_header ? M_PKTHDR : 0);
if (m == NULL) {
/* bad, no memory */
return (m);
}
if (allonebuf) {
int siz;
if (SCTP_BUF_IS_EXTENDED(m)) {
siz = SCTP_BUF_EXTEND_SIZE(m);
} else {
if (want_header)
siz = MHLEN;
else
siz = MLEN;
}
if (siz < space_needed) {
m_freem(m);
return (NULL);
}
}
if (SCTP_BUF_NEXT(m)) {
sctp_m_freem(SCTP_BUF_NEXT(m));
SCTP_BUF_NEXT(m) = NULL;
}
#ifdef SCTP_MBUF_LOGGING
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_MBUF_LOGGING_ENABLE) {
sctp_log_mb(m, SCTP_MBUF_IALLOC);
}
#endif
#else
#if defined(__FreeBSD__) && __FreeBSD_version >= 601000
int aloc_size;
int index = 0;
#endif
int mbuf_threshold;
unsigned int size;
if (want_header) {
MGETHDR(m, how, type);
size = MHLEN;
} else {
MGET(m, how, type);
size = MLEN;
}
if (m == NULL) {
return (NULL);
}
if (allonebuf == 0)
if (allonebuf == 0) {
mbuf_threshold = SCTP_BASE_SYSCTL(sctp_mbuf_threshold_count);
else
} else {
mbuf_threshold = 1;
}
if (space_needed > (((mbuf_threshold - 1) * MLEN) + MHLEN)) {
#if defined(__FreeBSD__) && __FreeBSD_version >= 601000
try_again:
index = 4;
if (space_needed <= MCLBYTES) {
aloc_size = MCLBYTES;
} else {
aloc_size = MJUMPAGESIZE;
index = 5;
}
m_cljget(m, how, aloc_size);
if (m == NULL) {
return (NULL);
}
if (SCTP_BUF_IS_EXTENDED(m) == 0) {
if ((aloc_size != MCLBYTES) &&
(allonebuf == 0)) {
aloc_size -= 10;
goto try_again;
}
sctp_m_freem(m);
return (NULL);
}
#else
if (space_needed > (unsigned int)(((mbuf_threshold - 1) * MLEN) + MHLEN)) {
MCLGET(m, how);
if (m == NULL) {
return (NULL);
@ -950,7 +828,11 @@ sctp_get_mbuf_for_msg(unsigned int space_needed, int want_header,
sctp_m_freem(m);
return (NULL);
}
#endif
size = SCTP_BUF_EXTEND_SIZE(m);
}
if (allonebuf != 0 && size < space_needed) {
m_freem(m);
return (NULL);
}
SCTP_BUF_LEN(m) = 0;
SCTP_BUF_NEXT(m) = SCTP_BUF_NEXT_PKT(m) = NULL;

View File

@ -32,9 +32,9 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_bsd_addr.h 310590 2016-12-26 11:06:41Z tuexen $");
__FBSDID("$FreeBSD: head/sys/netinet/sctp_bsd_addr.h 353480 2019-10-13 18:17:08Z tuexen $");
#endif
#ifndef _NETINET_SCTP_BSD_ADDR_H_
@ -61,8 +61,10 @@ int sctp_copy_out_packet_log(uint8_t *target, int length);
#endif
#if !defined(__Panda__)
void sctp_addr_change(struct ifaddr *ifa, int cmd);
#if defined(__FreeBSD__) && !defined(__Userspace__)
void sctp_addr_change_event_handler(void *, struct ifaddr *, int);
#endif
void sctp_add_or_del_interfaces(int (*pred)(struct ifnet *), int add);

View File

@ -34,18 +34,19 @@
#if defined(__Userspace__)
#include <sys/types.h>
#if !defined (__Userspace_os_Windows)
#if !defined(_WIN32)
#include <sys/wait.h>
#include <unistd.h>
#include <pthread.h>
#endif
#if defined(__Userspace_os_NaCl)
#if defined(__native_client__)
#include <sys/select.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <user_atomic.h>
#include <netinet/sctp_sysctl.h>
#include <netinet/sctp_pcb.h>
#else
@ -53,18 +54,19 @@
#include <netinet/sctp_callout.h>
#include <netinet/sctp_pcb.h>
#endif
#include <netinet/sctputil.h>
/*
* Callout/Timer routines for OS that doesn't have them
*/
#if defined(__APPLE__) || defined(__Userspace__)
static int ticks = 0;
static uint32_t ticks = 0;
#else
extern int ticks;
#endif
int sctp_get_tick_count(void) {
int ret;
uint32_t sctp_get_tick_count(void) {
uint32_t ret;
SCTP_TIMERQ_LOCK();
ret = ticks;
@ -76,27 +78,8 @@ int sctp_get_tick_count(void) {
* SCTP_TIMERQ_LOCK protects:
* - SCTP_BASE_INFO(callqueue)
* - sctp_os_timer_next: next timer to check
* - sctp_os_timer_current: current callout callback in progress
* - sctp_os_timer_current_tid: current callout thread id in progress
* - sctp_os_timer_waiting: some thread is waiting for callout to complete
* - sctp_os_timer_wait_ctr: incremented every time a thread wants to wait
* for a callout to complete.
*/
static sctp_os_timer_t *sctp_os_timer_next = NULL;
static sctp_os_timer_t *sctp_os_timer_current = NULL;
static int sctp_os_timer_waiting = 0;
static int sctp_os_timer_wait_ctr = 0;
static userland_thread_id_t sctp_os_timer_current_tid;
/*
* SCTP_TIMERWAIT_LOCK (sctp_os_timerwait_mtx) protects:
* - sctp_os_timer_wait_cond: waiting for callout to complete
* - sctp_os_timer_done_ctr: value of "wait_ctr" after triggering "waiting"
*/
userland_mutex_t sctp_os_timerwait_mtx;
static userland_cond_t sctp_os_timer_wait_cond;
static int sctp_os_timer_done_ctr = 0;
void
sctp_os_timer_init(sctp_os_timer_t *c)
@ -104,32 +87,20 @@ sctp_os_timer_init(sctp_os_timer_t *c)
memset(c, 0, sizeof(*c));
}
void
sctp_os_timer_start(sctp_os_timer_t *c, int to_ticks, void (*ftn) (void *),
int
sctp_os_timer_start(sctp_os_timer_t *c, uint32_t to_ticks, void (*ftn) (void *),
void *arg)
{
int ret = 0;
/* paranoia */
if ((c == NULL) || (ftn == NULL))
return;
return (ret);
SCTP_TIMERQ_LOCK();
/* check to see if we're rescheduling a timer */
if (c == sctp_os_timer_current) {
/*
* We're being asked to reschedule a callout which is
* currently in progress.
*/
if (sctp_os_timer_waiting) {
/*
* This callout is already being stopped.
* callout. Don't reschedule.
*/
SCTP_TIMERQ_UNLOCK();
return;
}
}
if (c->c_flags & SCTP_CALLOUT_PENDING) {
ret = 1;
if (c == sctp_os_timer_next) {
sctp_os_timer_next = TAILQ_NEXT(c, tqe);
}
@ -146,7 +117,7 @@ sctp_os_timer_start(sctp_os_timer_t *c, int to_ticks, void (*ftn) (void *),
* We could unlock/splx here and lock/spl at the TAILQ_INSERT_TAIL,
* but there's no point since doing this setup doesn't take much time.
*/
if (to_ticks <= 0)
if (to_ticks == 0)
to_ticks = 1;
c->c_arg = arg;
@ -155,56 +126,19 @@ sctp_os_timer_start(sctp_os_timer_t *c, int to_ticks, void (*ftn) (void *),
c->c_time = ticks + to_ticks;
TAILQ_INSERT_TAIL(&SCTP_BASE_INFO(callqueue), c, tqe);
SCTP_TIMERQ_UNLOCK();
return (ret);
}
int
sctp_os_timer_stop(sctp_os_timer_t *c)
{
int wakeup_cookie;
SCTP_TIMERQ_LOCK();
/*
* Don't attempt to delete a callout that's not on the queue.
*/
if (!(c->c_flags & SCTP_CALLOUT_PENDING)) {
c->c_flags &= ~SCTP_CALLOUT_ACTIVE;
if (sctp_os_timer_current != c) {
SCTP_TIMERQ_UNLOCK();
return (0);
} else {
/*
* Deleting the callout from the currently running
* callout from the same thread, so just return
*/
userland_thread_id_t tid;
sctp_userspace_thread_id(&tid);
if (sctp_userspace_thread_equal(tid,
sctp_os_timer_current_tid)) {
SCTP_TIMERQ_UNLOCK();
return (0);
}
/* need to wait until the callout is finished */
sctp_os_timer_waiting = 1;
wakeup_cookie = ++sctp_os_timer_wait_ctr;
SCTP_TIMERQ_UNLOCK();
SCTP_TIMERWAIT_LOCK();
/*
* wait only if sctp_handle_tick didn't do a wakeup
* in between the lock dance
*/
if (wakeup_cookie - sctp_os_timer_done_ctr > 0) {
#if defined (__Userspace_os_Windows)
SleepConditionVariableCS(&sctp_os_timer_wait_cond,
&sctp_os_timerwait_mtx,
INFINITE);
#else
pthread_cond_wait(&sctp_os_timer_wait_cond,
&sctp_os_timerwait_mtx);
#endif
}
SCTP_TIMERWAIT_UNLOCK();
}
SCTP_TIMERQ_UNLOCK();
return (0);
}
c->c_flags &= ~(SCTP_CALLOUT_ACTIVE | SCTP_CALLOUT_PENDING);
@ -216,45 +150,27 @@ sctp_os_timer_stop(sctp_os_timer_t *c)
return (1);
}
static void
sctp_handle_tick(int delta)
void
sctp_handle_tick(uint32_t elapsed_ticks)
{
sctp_os_timer_t *c;
void (*c_func)(void *);
void *c_arg;
int wakeup_cookie;
SCTP_TIMERQ_LOCK();
/* update our tick count */
ticks += delta;
ticks += elapsed_ticks;
c = TAILQ_FIRST(&SCTP_BASE_INFO(callqueue));
while (c) {
if (c->c_time <= ticks) {
if (SCTP_UINT32_GE(ticks, c->c_time)) {
sctp_os_timer_next = TAILQ_NEXT(c, tqe);
TAILQ_REMOVE(&SCTP_BASE_INFO(callqueue), c, tqe);
c_func = c->c_func;
c_arg = c->c_arg;
c->c_flags &= ~SCTP_CALLOUT_PENDING;
sctp_os_timer_current = c;
sctp_userspace_thread_id(&sctp_os_timer_current_tid);
SCTP_TIMERQ_UNLOCK();
c_func(c_arg);
SCTP_TIMERQ_LOCK();
sctp_os_timer_current = NULL;
if (sctp_os_timer_waiting) {
wakeup_cookie = sctp_os_timer_wait_ctr;
SCTP_TIMERQ_UNLOCK();
SCTP_TIMERWAIT_LOCK();
#if defined (__Userspace_os_Windows)
WakeAllConditionVariable(&sctp_os_timer_wait_cond);
#else
pthread_cond_broadcast(&sctp_os_timer_wait_cond);
#endif
sctp_os_timer_done_ctr = wakeup_cookie;
SCTP_TIMERWAIT_UNLOCK();
SCTP_TIMERQ_LOCK();
sctp_os_timer_waiting = 0;
}
c = sctp_os_timer_next;
} else {
c = TAILQ_NEXT(c, tqe);
@ -264,7 +180,7 @@ sctp_handle_tick(int delta)
SCTP_TIMERQ_UNLOCK();
}
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
void
sctp_timeout(void *arg SCTP_UNUSED)
{
@ -281,25 +197,27 @@ user_sctp_timer_iterate(void *arg)
{
sctp_userspace_set_threadname("SCTP timer");
for (;;) {
#if defined (__Userspace_os_Windows)
#if defined(_WIN32)
Sleep(TIMEOUT_INTERVAL);
#else
struct timeval timeout;
struct timespec amount, remaining;
timeout.tv_sec = 0;
timeout.tv_usec = 1000 * TIMEOUT_INTERVAL;
select(0, NULL, NULL, NULL, &timeout);
remaining.tv_sec = 0;
remaining.tv_nsec = TIMEOUT_INTERVAL * 1000 * 1000;
do {
amount = remaining;
} while (nanosleep(&amount, &remaining) == -1);
#endif
if (SCTP_BASE_VAR(timer_thread_should_exit)) {
if (atomic_cmpset_int(&SCTP_BASE_VAR(timer_thread_should_exit), 1, 1)) {
break;
}
sctp_handle_tick(MSEC_TO_TICKS(TIMEOUT_INTERVAL));
sctp_handle_tick(sctp_msecs_to_ticks(TIMEOUT_INTERVAL));
}
return (NULL);
}
void
sctp_start_timer(void)
sctp_start_timer_thread(void)
{
/*
* No need to do SCTP_TIMERQ_LOCK_INIT();
@ -307,18 +225,25 @@ sctp_start_timer(void)
*/
int rc;
#if defined(__Userspace_os_Windows)
InitializeConditionVariable(&sctp_os_timer_wait_cond);
#else
rc = pthread_cond_init(&sctp_os_timer_wait_cond, NULL);
if (rc)
SCTP_PRINTF("ERROR; return code from pthread_cond_init is %d\n", rc);
#endif
rc = sctp_userspace_thread_create(&SCTP_BASE_VAR(timer_thread), user_sctp_timer_iterate);
if (rc) {
SCTP_PRINTF("ERROR; return code from sctp_thread_create() is %d\n", rc);
} else {
SCTP_BASE_VAR(timer_thread_started) = 1;
}
}
void
sctp_stop_timer_thread(void)
{
atomic_cmpset_int(&SCTP_BASE_VAR(timer_thread_should_exit), 0, 1);
if (SCTP_BASE_VAR(timer_thread_started)) {
#if defined(_WIN32)
WaitForSingleObject(SCTP_BASE_VAR(timer_thread), INFINITE);
CloseHandle(SCTP_BASE_VAR(timer_thread));
#else
pthread_join(SCTP_BASE_VAR(timer_thread), NULL);
#endif
}
}
#endif

View File

@ -30,7 +30,7 @@
* SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#endif
@ -52,45 +52,32 @@ __FBSDID("$FreeBSD$");
#define SCTP_TICKS_PER_FASTTIMO 20 /* called about every 20ms */
extern userland_mutex_t sctp_os_timerwait_mtx;
#if defined(__Userspace__)
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
#define SCTP_TIMERQ_LOCK() EnterCriticalSection(&SCTP_BASE_VAR(timer_mtx))
#define SCTP_TIMERQ_UNLOCK() LeaveCriticalSection(&SCTP_BASE_VAR(timer_mtx))
#define SCTP_TIMERQ_LOCK_INIT() InitializeCriticalSection(&SCTP_BASE_VAR(timer_mtx))
#define SCTP_TIMERQ_LOCK_DESTROY() DeleteCriticalSection(&SCTP_BASE_VAR(timer_mtx))
#define SCTP_TIMERWAIT_LOCK() EnterCriticalSection(&sctp_os_timerwait_mtx)
#define SCTP_TIMERWAIT_UNLOCK() LeaveCriticalSection(&sctp_os_timerwait_mtx)
#define SCTP_TIMERWAIT_LOCK_INIT() InitializeCriticalSection(&sctp_os_timerwait_mtx)
#define SCTP_TIMERWAIT_LOCK_DESTROY() DeleteCriticalSection(&sctp_os_timerwait_mtx)
#else
#ifdef INVARIANTS
#define SCTP_TIMERQ_LOCK() KASSERT(pthread_mutex_lock(&SCTP_BASE_VAR(timer_mtx)) == 0, ("%s: timer_mtx already locked", __func__))
#define SCTP_TIMERQ_UNLOCK() KASSERT(pthread_mutex_unlock(&SCTP_BASE_VAR(timer_mtx)) == 0, ("%s: timer_mtx not locked", __func__))
#define SCTP_TIMERWAIT_LOCK() KASSERT(pthread_mutex_lock(&sctp_os_timerwait_mtx) == 0, ("%s: sctp_os_timerwait_mtx already locked", __func__))
#define SCTP_TIMERWAIT_UNLOCK() KASSERT(pthread_mutex_unlock(&sctp_os_timerwait_mtx) == 0, ("%s: sctp_os_timerwait_mtx not locked", __func__))
#else
#define SCTP_TIMERQ_LOCK() (void)pthread_mutex_lock(&SCTP_BASE_VAR(timer_mtx))
#define SCTP_TIMERQ_UNLOCK() (void)pthread_mutex_unlock(&SCTP_BASE_VAR(timer_mtx))
#define SCTP_TIMERWAIT_LOCK() (void)pthread_mutex_lock(&sctp_os_timerwait_mtx)
#define SCTP_TIMERWAIT_UNLOCK() (void)pthread_mutex_unlock(&sctp_os_timerwait_mtx)
#endif
#define SCTP_TIMERQ_LOCK_INIT() (void)pthread_mutex_init(&SCTP_BASE_VAR(timer_mtx), &SCTP_BASE_VAR(mtx_attr))
#define SCTP_TIMERQ_LOCK_DESTROY() (void)pthread_mutex_destroy(&SCTP_BASE_VAR(timer_mtx))
#define SCTP_TIMERWAIT_LOCK_INIT() (void)pthread_mutex_init(&sctp_os_timerwait_mtx, &SCTP_BASE_VAR(mtx_attr))
#define SCTP_TIMERWAIT_LOCK_DESTROY() (void)pthread_mutex_destroy(&sctp_os_timerwait_mtx)
#endif
#endif
int sctp_get_tick_count(void);
uint32_t sctp_get_tick_count(void);
TAILQ_HEAD(calloutlist, sctp_callout);
struct sctp_callout {
TAILQ_ENTRY(sctp_callout) tqe;
int c_time; /* ticks to the event */
uint32_t c_time; /* ticks to the event */
void *c_arg; /* function argument */
void (*c_func)(void *); /* function to call */
int c_flags; /* state of this entry */
@ -101,8 +88,11 @@ typedef struct sctp_callout sctp_os_timer_t;
#define SCTP_CALLOUT_PENDING 0x0004 /* callout is waiting for timeout */
void sctp_os_timer_init(sctp_os_timer_t *tmr);
void sctp_os_timer_start(sctp_os_timer_t *, int, void (*)(void *), void *);
/* Returns 1 if pending timer was rescheduled, 0 otherwise. */
int sctp_os_timer_start(sctp_os_timer_t *, uint32_t, void (*)(void *), void *);
/* Returns 1 if pending timer was stopped, 0 otherwise. */
int sctp_os_timer_stop(sctp_os_timer_t *);
void sctp_handle_tick(uint32_t);
#define SCTP_OS_TIMER_INIT sctp_os_timer_init
#define SCTP_OS_TIMER_START sctp_os_timer_start
@ -114,9 +104,10 @@ int sctp_os_timer_stop(sctp_os_timer_t *);
#define SCTP_OS_TIMER_DEACTIVATE(tmr) ((tmr)->c_flags &= ~SCTP_CALLOUT_ACTIVE)
#if defined(__Userspace__)
void sctp_start_timer(void);
void sctp_start_timer_thread(void);
void sctp_stop_timer_thread(void);
#endif
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
void sctp_timeout(void *);
#endif

View File

@ -32,9 +32,9 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_cc_functions.c 310590 2016-12-26 11:06:41Z tuexen $");
__FBSDID("$FreeBSD: head/sys/netinet/sctp_cc_functions.c 359405 2020-03-28 20:25:45Z tuexen $");
#endif
#include <netinet/sctp_os.h>
@ -50,8 +50,8 @@ __FBSDID("$FreeBSD: head/sys/netinet/sctp_cc_functions.c 310590 2016-12-26 11:06
#include <netinet/sctp_timer.h>
#include <netinet/sctp_auth.h>
#include <netinet/sctp_asconf.h>
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#include <netinet/sctp_dtrace_declare.h>
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <netinet/sctp_kdtrace.h>
#endif
#define SHIFT_MPTCP_MULTI_N 40
@ -101,7 +101,7 @@ sctp_set_initial_cc_param(struct sctp_tcb *stcb, struct sctp_nets *net)
}
sctp_enforce_cwnd_limit(assoc, net);
net->ssthresh = assoc->peers_rwnd;
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
SDT_PROBE5(sctp, cwnd, net, init,
stcb->asoc.my_vtag, ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), net,
0, net->cwnd);
@ -196,7 +196,7 @@ sctp_cwnd_update_after_fr(struct sctp_tcb *stcb,
}
net->cwnd = net->ssthresh;
sctp_enforce_cwnd_limit(asoc, net);
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
SDT_PROBE5(sctp, cwnd, net, fr,
stcb->asoc.my_vtag, ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), net,
old_cwnd, net->cwnd);
@ -252,7 +252,7 @@ sctp_cwnd_update_after_fr(struct sctp_tcb *stcb,
#define SCTP_INST_GAINING 3 /* Gaining, step down possible */
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
static int
cc_bw_same(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw,
uint64_t rtt_offset, uint64_t vtag, uint8_t inst_ind)
@ -262,11 +262,11 @@ cc_bw_same(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net, uint64_t nb
uint64_t rtt_offset, uint8_t inst_ind)
#endif
{
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
uint64_t oth, probepoint;
#endif
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
probepoint = (((uint64_t)net->cwnd) << 32);
#endif
if (net->rtt > net->cc_mod.rtcc.lbw_rtt + rtt_offset) {
@ -275,7 +275,7 @@ cc_bw_same(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net, uint64_t nb
* we don't update bw.. so we don't
* update the rtt either.
*/
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
/* Probe point 5 */
probepoint |= ((5 << 16) | 1);
SDT_PROBE5(sctp, cwnd, net, rttvar,
@ -295,7 +295,7 @@ cc_bw_same(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net, uint64_t nb
((net->cc_mod.rtcc.step_cnt > net->cc_mod.rtcc.steady_step) &&
((net->cc_mod.rtcc.step_cnt % net->cc_mod.rtcc.steady_step) == 0))) {
/* Try a step down */
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
oth = net->cc_mod.rtcc.vol_reduce;
oth <<= 16;
oth |= net->cc_mod.rtcc.step_cnt;
@ -324,7 +324,7 @@ cc_bw_same(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net, uint64_t nb
* we update both the bw and the rtt here to
* lock this in as a good step down.
*/
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
/* Probe point 6 */
probepoint |= ((6 << 16) | 0);
SDT_PROBE5(sctp, cwnd, net, rttvar,
@ -335,7 +335,7 @@ cc_bw_same(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net, uint64_t nb
probepoint);
#endif
if (net->cc_mod.rtcc.steady_step) {
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
oth = net->cc_mod.rtcc.vol_reduce;
oth <<= 16;
oth |= net->cc_mod.rtcc.step_cnt;
@ -370,7 +370,7 @@ cc_bw_same(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net, uint64_t nb
}
/* Ok bw and rtt remained the same .. no update to any
*/
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
/* Probe point 7 */
probepoint |= ((7 << 16) | net->cc_mod.rtcc.ret_from_eq);
SDT_PROBE5(sctp, cwnd, net, rttvar,
@ -407,7 +407,7 @@ cc_bw_same(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net, uint64_t nb
return ((int)net->cc_mod.rtcc.ret_from_eq);
}
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
static int
cc_bw_decrease(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw, uint64_t rtt_offset,
uint64_t vtag, uint8_t inst_ind)
@ -417,12 +417,12 @@ cc_bw_decrease(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net, uint64_
uint8_t inst_ind)
#endif
{
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
uint64_t oth, probepoint;
#endif
/* Bandwidth decreased.*/
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
probepoint = (((uint64_t)net->cwnd) << 32);
#endif
if (net->rtt > net->cc_mod.rtcc.lbw_rtt+rtt_offset) {
@ -431,7 +431,7 @@ cc_bw_decrease(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net, uint64_
if ((net->cwnd > net->cc_mod.rtcc.cwnd_at_bw_set) &&
(inst_ind != SCTP_INST_LOOSING)) {
/* We caused it maybe.. back off? */
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
/* PROBE POINT 1 */
probepoint |= ((1 << 16) | 1);
SDT_PROBE5(sctp, cwnd, net, rttvar,
@ -448,7 +448,7 @@ cc_bw_decrease(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net, uint64_
}
return (1);
}
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
/* Probe point 2 */
probepoint |= ((2 << 16) | 0);
SDT_PROBE5(sctp, cwnd, net, rttvar,
@ -460,7 +460,7 @@ cc_bw_decrease(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net, uint64_
#endif
/* Someone else - fight for more? */
if (net->cc_mod.rtcc.steady_step) {
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
oth = net->cc_mod.rtcc.vol_reduce;
oth <<= 16;
oth |= net->cc_mod.rtcc.step_cnt;
@ -488,7 +488,7 @@ cc_bw_decrease(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net, uint64_
goto out_decision;
} else if (net->rtt < net->cc_mod.rtcc.lbw_rtt-rtt_offset) {
/* bw & rtt decreased */
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
/* Probe point 3 */
probepoint |= ((3 << 16) | 0);
SDT_PROBE5(sctp, cwnd, net, rttvar,
@ -499,7 +499,7 @@ cc_bw_decrease(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net, uint64_
probepoint);
#endif
if (net->cc_mod.rtcc.steady_step) {
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
oth = net->cc_mod.rtcc.vol_reduce;
oth <<= 16;
oth |= net->cc_mod.rtcc.step_cnt;
@ -524,7 +524,7 @@ cc_bw_decrease(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net, uint64_
goto out_decision;
}
/* The bw decreased but rtt stayed the same */
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
/* Probe point 4 */
probepoint |= ((4 << 16) | 0);
SDT_PROBE5(sctp, cwnd, net, rttvar,
@ -535,7 +535,7 @@ cc_bw_decrease(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net, uint64_
probepoint);
#endif
if (net->cc_mod.rtcc.steady_step) {
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
oth = net->cc_mod.rtcc.vol_reduce;
oth <<= 16;
oth |= net->cc_mod.rtcc.step_cnt;
@ -568,7 +568,7 @@ out_decision:
}
}
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
static int
cc_bw_increase(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw, uint64_t vtag)
#else
@ -576,7 +576,7 @@ static int
cc_bw_increase(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net, uint64_t nbw)
#endif
{
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
uint64_t oth, probepoint;
#endif
@ -586,7 +586,7 @@ cc_bw_increase(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net, uint64_
* update. Note that we pay no attention to
* the inst_ind since our overall sum is increasing.
*/
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
/* PROBE POINT 0 */
probepoint = (((uint64_t)net->cwnd) << 32);
SDT_PROBE5(sctp, cwnd, net, rttvar,
@ -597,7 +597,7 @@ cc_bw_increase(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net, uint64_
probepoint);
#endif
if (net->cc_mod.rtcc.steady_step) {
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
oth = net->cc_mod.rtcc.vol_reduce;
oth <<= 16;
oth |= net->cc_mod.rtcc.step_cnt;
@ -627,7 +627,7 @@ static int
cc_bw_limit(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw)
{
uint64_t bw_offset, rtt_offset;
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
uint64_t probepoint, rtt, vtag;
#endif
uint64_t bytes_for_this_rtt, inst_bw;
@ -673,7 +673,7 @@ cc_bw_limit(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw)
* change within 1/32nd
*/
bw_shift = SCTP_BASE_SYSCTL(sctp_rttvar_bw);
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
rtt = stcb->asoc.my_vtag;
vtag = (rtt << 32) | (((uint32_t)(stcb->sctp_ep->sctp_lport)) << 16) | (stcb->rport);
probepoint = (((uint64_t)net->cwnd) << 32);
@ -694,12 +694,12 @@ cc_bw_limit(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw)
inst_ind = SCTP_INST_LOOSING;
else
inst_ind = SCTP_INST_NEUTRAL;
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
probepoint |= ((0xb << 16) | inst_ind);
#endif
} else {
inst_ind = net->cc_mod.rtcc.last_inst_ind;
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
inst_bw = bytes_for_this_rtt / (uint64_t)(net->rtt);
/* Can't determine do not change */
probepoint |= ((0xc << 16) | inst_ind);
@ -707,13 +707,13 @@ cc_bw_limit(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw)
}
} else {
inst_ind = net->cc_mod.rtcc.last_inst_ind;
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
inst_bw = bytes_for_this_rtt;
/* Can't determine do not change */
probepoint |= ((0xd << 16) | inst_ind);
#endif
}
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
SDT_PROBE5(sctp, cwnd, net, rttvar,
vtag,
((nbw << 32) | inst_bw),
@ -727,7 +727,7 @@ cc_bw_limit(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw)
}
bw_offset = net->cc_mod.rtcc.lbw >> bw_shift;
if (nbw > net->cc_mod.rtcc.lbw + bw_offset) {
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
ret = cc_bw_increase(stcb, net, nbw, vtag);
#else
ret = cc_bw_increase(stcb, net, nbw);
@ -736,7 +736,7 @@ cc_bw_limit(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw)
}
rtt_offset = net->cc_mod.rtcc.lbw_rtt >> SCTP_BASE_SYSCTL(sctp_rttvar_rtt);
if (nbw < net->cc_mod.rtcc.lbw - bw_offset) {
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
ret = cc_bw_decrease(stcb, net, nbw, rtt_offset, vtag, inst_ind);
#else
ret = cc_bw_decrease(stcb, net, nbw, rtt_offset, inst_ind);
@ -747,7 +747,7 @@ cc_bw_limit(struct sctp_tcb *stcb, struct sctp_nets *net, uint64_t nbw)
* we are in a situation where
* the bw stayed the same.
*/
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
ret = cc_bw_same(stcb, net, nbw, rtt_offset, vtag, inst_ind);
#else
ret = cc_bw_same(stcb, net, nbw, rtt_offset, inst_ind);
@ -763,7 +763,7 @@ sctp_cwnd_update_after_sack_common(struct sctp_tcb *stcb,
int accum_moved, int reneged_all SCTP_UNUSED, int will_exit, int use_rtcc)
{
struct sctp_nets *net;
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
int old_cwnd;
#endif
uint32_t t_ssthresh, t_cwnd, incr;
@ -879,7 +879,7 @@ sctp_cwnd_update_after_sack_common(struct sctp_tcb *stcb,
continue;
}
} else {
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
uint64_t vtag, probepoint;
probepoint = (((uint64_t)net->cwnd) << 32);
@ -915,7 +915,7 @@ sctp_cwnd_update_after_sack_common(struct sctp_tcb *stcb,
if (net->flight_size + net->net_ack >= net->cwnd) {
uint32_t limit;
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
old_cwnd = net->cwnd;
#endif
switch (asoc->sctp_cmt_on_off) {
@ -987,7 +987,7 @@ sctp_cwnd_update_after_sack_common(struct sctp_tcb *stcb,
sctp_log_cwnd(stcb, net, incr,
SCTP_CWND_LOG_FROM_SS);
}
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
SDT_PROBE5(sctp, cwnd, net, ack,
stcb->asoc.my_vtag,
((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
@ -1010,7 +1010,7 @@ sctp_cwnd_update_after_sack_common(struct sctp_tcb *stcb,
if ((net->flight_size + net->net_ack >= net->cwnd) &&
(net->partial_bytes_acked >= net->cwnd)) {
net->partial_bytes_acked -= net->cwnd;
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
old_cwnd = net->cwnd;
#endif
switch (asoc->sctp_cmt_on_off) {
@ -1051,7 +1051,7 @@ sctp_cwnd_update_after_sack_common(struct sctp_tcb *stcb,
}
net->cwnd += incr;
sctp_enforce_cwnd_limit(asoc, net);
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
SDT_PROBE5(sctp, cwnd, net, ack,
stcb->asoc.my_vtag,
((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
@ -1078,7 +1078,7 @@ sctp_cwnd_update_after_sack_common(struct sctp_tcb *stcb,
}
}
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
static void
sctp_cwnd_update_exit_pf_common(struct sctp_tcb *stcb, struct sctp_nets *net)
#else
@ -1086,13 +1086,13 @@ static void
sctp_cwnd_update_exit_pf_common(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net)
#endif
{
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
int old_cwnd;
old_cwnd = net->cwnd;
#endif
net->cwnd = net->mtu;
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
SDT_PROBE5(sctp, cwnd, net, ack,
stcb->asoc.my_vtag, ((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)), net,
old_cwnd, net->cwnd);
@ -1165,7 +1165,7 @@ sctp_cwnd_update_after_timeout(struct sctp_tcb *stcb, struct sctp_nets *net)
}
net->cwnd = net->mtu;
net->partial_bytes_acked = 0;
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
SDT_PROBE5(sctp, cwnd, net, to,
stcb->asoc.my_vtag,
((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
@ -1220,7 +1220,7 @@ sctp_cwnd_update_after_ecn_echo_common(struct sctp_tcb *stcb, struct sctp_nets *
net->RTO <<= 1;
}
net->cwnd = net->ssthresh;
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
SDT_PROBE5(sctp, cwnd, net, ecn,
stcb->asoc.my_vtag,
((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
@ -1341,7 +1341,7 @@ sctp_cwnd_update_after_packet_dropped(struct sctp_tcb *stcb,
sctp_enforce_cwnd_limit(&stcb->asoc, net);
if (net->cwnd - old_cwnd != 0) {
/* log only changes */
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
SDT_PROBE5(sctp, cwnd, net, pd,
stcb->asoc.my_vtag,
((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
@ -1366,7 +1366,7 @@ sctp_cwnd_update_after_output(struct sctp_tcb *stcb,
if (burst_limit) {
net->cwnd = (net->flight_size + (burst_limit * net->mtu));
sctp_enforce_cwnd_limit(&stcb->asoc, net);
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
SDT_PROBE5(sctp, cwnd, net, bl,
stcb->asoc.my_vtag,
((stcb->sctp_ep->sctp_lport << 16) | (stcb->rport)),
@ -1433,12 +1433,12 @@ static void
sctp_cwnd_new_rtcc_transmission_begins(struct sctp_tcb *stcb,
struct sctp_nets *net)
{
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
uint64_t vtag, probepoint;
#endif
if (net->cc_mod.rtcc.lbw) {
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
/* Clear the old bw.. we went to 0 in-flight */
vtag = (net->rtt << 32) | (((uint32_t)(stcb->sctp_ep->sctp_lport)) << 16) |
(stcb->rport);
@ -1494,13 +1494,13 @@ static void
sctp_set_rtcc_initial_cc_param(struct sctp_tcb *stcb,
struct sctp_nets *net)
{
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
uint64_t vtag, probepoint;
#endif
sctp_set_initial_cc_param(stcb, net);
stcb->asoc.use_precise_time = 1;
#if defined(__FreeBSD__) && __FreeBSD_version >= 803000
#if defined(__FreeBSD__) && !defined(__Userspace__)
probepoint = (((uint64_t)net->cwnd) << 32);
probepoint |= ((9 << 16) | 0);
vtag = (net->rtt << 32) |
@ -1962,7 +1962,7 @@ htcp_cong_time(struct htcp *ca)
static inline uint32_t
htcp_ccount(struct htcp *ca)
{
return (htcp_cong_time(ca)/ca->minRTT);
return (ca->minRTT == 0 ? htcp_cong_time(ca) : htcp_cong_time(ca)/ca->minRTT);
}
static inline void
@ -2000,7 +2000,7 @@ measure_rtt(struct sctp_nets *net)
if (net->fast_retran_ip == 0 && net->ssthresh < 0xFFFF && htcp_ccount(&net->cc_mod.htcp_ca) > 3) {
if (net->cc_mod.htcp_ca.maxRTT < net->cc_mod.htcp_ca.minRTT)
net->cc_mod.htcp_ca.maxRTT = net->cc_mod.htcp_ca.minRTT;
if (net->cc_mod.htcp_ca.maxRTT < srtt && srtt <= net->cc_mod.htcp_ca.maxRTT+MSEC_TO_TICKS(20))
if (net->cc_mod.htcp_ca.maxRTT < srtt && srtt <= net->cc_mod.htcp_ca.maxRTT+sctp_msecs_to_ticks(20))
net->cc_mod.htcp_ca.maxRTT = srtt;
}
}
@ -2060,7 +2060,7 @@ htcp_beta_update(struct htcp *ca, uint32_t minRTT, uint32_t maxRTT)
}
}
if (ca->modeswitch && minRTT > (uint32_t)MSEC_TO_TICKS(10) && maxRTT) {
if (ca->modeswitch && minRTT > sctp_msecs_to_ticks(10) && maxRTT) {
ca->beta = (minRTT<<7)/maxRTT;
if (ca->beta < BETA_MIN)
ca->beta = BETA_MIN;
@ -2410,7 +2410,7 @@ sctp_htcp_cwnd_update_after_ecn_echo(struct sctp_tcb *stcb,
const struct sctp_cc_functions sctp_cc_functions[] = {
{
#if defined(__Windows__) || defined(__Userspace_os_Windows)
#if defined(_WIN32) && !defined(__MINGW32__)
sctp_set_initial_cc_param,
sctp_cwnd_update_after_sack,
sctp_cwnd_update_exit_pf_common,
@ -2431,7 +2431,7 @@ const struct sctp_cc_functions sctp_cc_functions[] = {
#endif
},
{
#if defined(__Windows__) || defined(__Userspace_os_Windows)
#if defined(_WIN32) && !defined(__MINGW32__)
sctp_set_initial_cc_param,
sctp_hs_cwnd_update_after_sack,
sctp_cwnd_update_exit_pf_common,
@ -2452,7 +2452,7 @@ const struct sctp_cc_functions sctp_cc_functions[] = {
#endif
},
{
#if defined(__Windows__) || defined(__Userspace_os_Windows)
#if defined(_WIN32) && !defined(__MINGW32__)
sctp_htcp_set_initial_cc_param,
sctp_htcp_cwnd_update_after_sack,
sctp_cwnd_update_exit_pf_common,
@ -2473,7 +2473,7 @@ const struct sctp_cc_functions sctp_cc_functions[] = {
#endif
},
{
#if defined(__Windows__) || defined(__Userspace_os_Windows)
#if defined(_WIN32) && !defined(__MINGW32__)
sctp_set_rtcc_initial_cc_param,
sctp_cwnd_update_rtcc_after_sack,
sctp_cwnd_update_exit_pf_common,

View File

@ -32,15 +32,15 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_constants.h 324615 2017-10-14 10:02:59Z tuexen $");
__FBSDID("$FreeBSD: head/sys/netinet/sctp_constants.h 362107 2020-06-12 16:40:10Z tuexen $");
#endif
#ifndef _NETINET_SCTP_CONSTANTS_H_
#define _NETINET_SCTP_CONSTANTS_H_
#if defined(__Userspace_os_Windows)
#if defined(_WIN32) && defined(__Userspace__)
extern void getwintimeofday(struct timeval *tv);
#endif
@ -398,7 +398,7 @@ extern void getwintimeofday(struct timeval *tv);
/*************0x0000 series*************/
#define SCTP_HEARTBEAT_INFO 0x0001
#if defined(__Userspace__)
#define SCTP_CONN_ADDRESS 0x0004
#define SCTP_CONN_ADDRESS 0x0004
#endif
#define SCTP_IPV4_ADDRESS 0x0005
#define SCTP_IPV6_ADDRESS 0x0006
@ -408,43 +408,34 @@ extern void getwintimeofday(struct timeval *tv);
#define SCTP_HOSTNAME_ADDRESS 0x000b
#define SCTP_SUPPORTED_ADDRTYPE 0x000c
/* draft-ietf-stewart-tsvwg-strreset-xxx */
/* RFC 6525 */
#define SCTP_STR_RESET_OUT_REQUEST 0x000d
#define SCTP_STR_RESET_IN_REQUEST 0x000e
#define SCTP_STR_RESET_TSN_REQUEST 0x000f
#define SCTP_STR_RESET_RESPONSE 0x0010
#define SCTP_STR_RESET_ADD_OUT_STREAMS 0x0011
#define SCTP_STR_RESET_ADD_IN_STREAMS 0x0012
#define SCTP_STR_RESET_ADD_IN_STREAMS 0x0012
#define SCTP_MAX_RESET_PARAMS 2
#define SCTP_STREAM_RESET_TSN_DELTA 0x1000
#define SCTP_STREAM_RESET_TSN_DELTA 0x1000
/*************0x4000 series*************/
/*************0x8000 series*************/
#define SCTP_ECN_CAPABLE 0x8000
/* draft-ietf-tsvwg-auth-xxx */
/* RFC 4895 */
#define SCTP_RANDOM 0x8002
#define SCTP_CHUNK_LIST 0x8003
#define SCTP_HMAC_LIST 0x8004
/*
* draft-ietf-tsvwg-addip-sctp-xx param=0x8008 len=0xNNNN Byte | Byte | Byte
* | Byte Byte | Byte ...
*
* Where each byte is a chunk type extension supported. For example, to support
* all chunks one would have (in hex):
*
* 80 01 00 09 C0 C1 80 81 82 00 00 00
*
* Has the parameter. C0 = PR-SCTP (RFC3758) C1, 80 = ASCONF (addip draft) 81
* = Packet Drop 82 = Stream Reset 83 = Authentication
*/
#define SCTP_SUPPORTED_CHUNK_EXT 0x8008
/* RFC 4820 */
#define SCTP_PAD 0x8005
/* RFC 5061 */
#define SCTP_SUPPORTED_CHUNK_EXT 0x8008
/*************0xC000 series*************/
#define SCTP_PRSCTP_SUPPORTED 0xc000
/* draft-ietf-tsvwg-addip-sctp */
/* RFC 5061 */
#define SCTP_ADD_IP_ADDRESS 0xc001
#define SCTP_DEL_IP_ADDRESS 0xc002
#define SCTP_ERROR_CAUSE_IND 0xc003
@ -452,8 +443,8 @@ extern void getwintimeofday(struct timeval *tv);
#define SCTP_SUCCESS_REPORT 0xc005
#define SCTP_ULP_ADAPTATION 0xc006
/* behave-nat-draft */
#define SCTP_HAS_NAT_SUPPORT 0xc007
#define SCTP_NAT_VTAGS 0xc008
#define SCTP_HAS_NAT_SUPPORT 0xc007
#define SCTP_NAT_VTAGS 0xc008
/* bits for TOS field */
#define SCTP_ECT0_BIT 0x02
@ -487,10 +478,14 @@ extern void getwintimeofday(struct timeval *tv);
#define SCTP_STATE_IN_ACCEPT_QUEUE 0x1000
#define SCTP_STATE_MASK 0x007f
#define SCTP_GET_STATE(asoc) ((asoc)->state & SCTP_STATE_MASK)
#define SCTP_SET_STATE(asoc, newstate) ((asoc)->state = ((asoc)->state & ~SCTP_STATE_MASK) | newstate)
#define SCTP_CLEAR_SUBSTATE(asoc, substate) ((asoc)->state &= ~substate)
#define SCTP_ADD_SUBSTATE(asoc, substate) ((asoc)->state |= substate)
#define SCTP_GET_STATE(_stcb) \
((_stcb)->asoc.state & SCTP_STATE_MASK)
#define SCTP_SET_STATE(_stcb, _state) \
sctp_set_state(_stcb, _state)
#define SCTP_CLEAR_SUBSTATE(_stcb, _substate) \
(_stcb)->asoc.state &= ~(_substate)
#define SCTP_ADD_SUBSTATE(_stcb, _substate) \
sctp_add_substate(_stcb, _substate)
/* SCTP reachability state for each address */
#define SCTP_ADDR_REACHABLE 0x001
@ -556,20 +551,19 @@ extern void getwintimeofday(struct timeval *tv);
#define SCTP_TIMER_TYPE_ASCONF 10
#define SCTP_TIMER_TYPE_SHUTDOWNGUARD 11
#define SCTP_TIMER_TYPE_AUTOCLOSE 12
#define SCTP_TIMER_TYPE_EVENTWAKE 13
#define SCTP_TIMER_TYPE_STRRESET 14
#define SCTP_TIMER_TYPE_INPKILL 15
#define SCTP_TIMER_TYPE_ASOCKILL 16
#define SCTP_TIMER_TYPE_ADDR_WQ 17
#define SCTP_TIMER_TYPE_PRIM_DELETED 18
#define SCTP_TIMER_TYPE_STRRESET 13
#define SCTP_TIMER_TYPE_INPKILL 14
#define SCTP_TIMER_TYPE_ASOCKILL 15
#define SCTP_TIMER_TYPE_ADDR_WQ 16
#define SCTP_TIMER_TYPE_PRIM_DELETED 17
/* add new timers here - and increment LAST */
#define SCTP_TIMER_TYPE_LAST 19
#define SCTP_TIMER_TYPE_LAST 18
#define SCTP_IS_TIMER_TYPE_VALID(t) (((t) > SCTP_TIMER_TYPE_NONE) && \
((t) < SCTP_TIMER_TYPE_LAST))
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
/* Number of ticks to run the main timer at in msec */
#define SCTP_MAIN_TIMER_DEFAULT 10
#endif
@ -592,22 +586,7 @@ extern void getwintimeofday(struct timeval *tv);
* number of clusters as a base. This way high bandwidth environments will
* not get impacted by the lower bandwidth sending a bunch of 1 byte chunks
*/
#ifdef __Panda__
#define SCTP_ASOC_MAX_CHUNKS_ON_QUEUE 10240
#else
#define SCTP_ASOC_MAX_CHUNKS_ON_QUEUE 512
#endif
/* The conversion from time to ticks and vice versa is done by rounding
* upwards. This way we can test in the code the time to be positive and
* know that this corresponds to a positive number of ticks.
*/
#define MSEC_TO_TICKS(x) ((hz == 1000) ? x : ((((x) * hz) + 999) / 1000))
#define TICKS_TO_MSEC(x) ((hz == 1000) ? x : ((((x) * 1000) + (hz - 1)) / hz))
#define SEC_TO_TICKS(x) ((x) * hz)
#define TICKS_TO_SEC(x) (((x) + (hz - 1)) / hz)
/*
* Basically the minimum amount of time before I do a early FR. Making this
@ -792,9 +771,8 @@ extern void getwintimeofday(struct timeval *tv);
#define SCTP_FROM_SCTP_ASCONF 0x80000000
#define SCTP_FROM_SCTP_OUTPUT 0x90000000
#define SCTP_FROM_SCTP_PEELOFF 0xa0000000
#define SCTP_FROM_SCTP_PANDA 0xb0000000
#define SCTP_FROM_SCTP_SYSCTL 0xc0000000
#define SCTP_FROM_SCTP_CC_FUNCTIONS 0xd0000000
#define SCTP_FROM_SCTP_SYSCTL 0xb0000000
#define SCTP_FROM_SCTP_CC_FUNCTIONS 0xc0000000
/* Location ID's */
#define SCTP_LOC_1 0x00000001
@ -832,7 +810,7 @@ extern void getwintimeofday(struct timeval *tv);
#define SCTP_LOC_33 0x00000021
#define SCTP_LOC_34 0x00000022
#define SCTP_LOC_35 0x00000023
#define SCTP_LOC_36 0x00000024
/* Free assoc codes */
#define SCTP_NORMAL_PROC 0
@ -879,7 +857,7 @@ extern void getwintimeofday(struct timeval *tv);
#define SCTP_CHUNKQUEUE_SCALE 10
#endif
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
/* clock variance is 1 ms */
#define SCTP_CLOCK_GRANULARITY 1
#else
@ -986,7 +964,7 @@ extern void getwintimeofday(struct timeval *tv);
/*-
* defines for socket lock states.
* Used by __APPLE__ and SCTP_SO_LOCK_TESTING
* Used by __APPLE__
*/
#define SCTP_SO_LOCKED 1
#define SCTP_SO_NOT_LOCKED 0
@ -1013,8 +991,11 @@ extern void getwintimeofday(struct timeval *tv);
((((uint8_t *)&(a)->s_addr)[0] == 169) && \
(((uint8_t *)&(a)->s_addr)[1] == 254))
/* Maximum size of optval for IPPROTO_SCTP level socket options. */
#define SCTP_SOCKET_OPTION_LIMIT (64 * 1024)
#if defined(__Userspace__)
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
#define SCTP_GETTIME_TIMEVAL(x) getwintimeofday(x)
#define SCTP_GETPTIME_TIMEVAL(x) getwintimeofday(x) /* this doesn't seem to ever be used.. */
#else
@ -1038,11 +1019,11 @@ do { \
} \
} while (0)
#if defined(__FreeBSD__) || defined(__Windows__) || defined(__Userspace__)
#if defined(__FreeBSD__) || defined(_WIN32) || defined(__Userspace__)
#define sctp_sowwakeup_locked(inp, so) \
do { \
if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) { \
SOCKBUF_UNLOCK(&((so)->so_snd)); \
SOCKBUF_UNLOCK(&((so)->so_snd)); \
inp->sctp_flags |= SCTP_PCB_FLAGS_WAKEOUTPUT; \
} else { \
sowwakeup_locked(so); \
@ -1052,7 +1033,7 @@ do { \
#define sctp_sowwakeup_locked(inp, so) \
do { \
if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) { \
SOCKBUF_UNLOCK(&((so)->so_snd)); \
SOCKBUF_UNLOCK(&((so)->so_snd)); \
inp->sctp_flags |= SCTP_PCB_FLAGS_WAKEOUTPUT; \
} else { \
sowwakeup(so); \
@ -1069,12 +1050,12 @@ do { \
} \
} while (0)
#if defined(__FreeBSD__) || defined(__Windows__) || defined(__Userspace__)
#if defined(__FreeBSD__) || defined(_WIN32) || defined(__Userspace__)
#define sctp_sorwakeup_locked(inp, so) \
do { \
if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) { \
inp->sctp_flags |= SCTP_PCB_FLAGS_WAKEINPUT; \
SOCKBUF_UNLOCK(&((so)->so_rcv)); \
SOCKBUF_UNLOCK(&((so)->so_rcv)); \
} else { \
sorwakeup_locked(so); \
} \
@ -1085,7 +1066,7 @@ do { \
do { \
if (inp->sctp_flags & SCTP_PCB_FLAGS_DONT_WAKE) { \
inp->sctp_flags |= SCTP_PCB_FLAGS_WAKEINPUT; \
SOCKBUF_UNLOCK(&((so)->so_rcv)); \
SOCKBUF_UNLOCK(&((so)->so_rcv)); \
} else { \
sorwakeup(so); \
} \

View File

@ -32,20 +32,31 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_crc32.c 310590 2016-12-26 11:06:41Z tuexen $");
#endif
__FBSDID("$FreeBSD: head/sys/netinet/sctp_crc32.c 362498 2020-06-22 14:36:14Z tuexen $");
#include "opt_sctp.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/gsb_crc32.h>
#include <sys/mbuf.h>
#include <netinet/sctp.h>
#include <netinet/sctp_crc32.h>
#if defined(SCTP) || defined(SCTP_SUPPORT)
#include <netinet/sctp_os.h>
#include <netinet/sctp_pcb.h>
#endif
#else
#include <netinet/sctp_os.h>
#include <netinet/sctp.h>
#include <netinet/sctp_crc32.h>
#include <netinet/sctp_pcb.h>
#endif
#if !defined(SCTP_WITH_NO_CSUM)
#if defined(__FreeBSD__) && __FreeBSD_version >= 800000
#else
#if !(defined(__FreeBSD__) && !defined(__Userspace__))
/**
*
* Routine Description:
@ -60,7 +71,7 @@ __FBSDID("$FreeBSD: head/sys/netinet/sctp_crc32.c 310590 2016-12-26 11:06:41Z tu
* non-NULL if the mode argument is equal to CONT or END
* p_buf - the packet buffer where crc computations are being performed
* length - the length of p_buf in bytes
* init_bytes - the number of initial bytes that need to be processed before
* init_bytes - the number of initial bytes that need to be procesed before
* aligning p_buf to multiples of 4 bytes
* mode - can be any of the following: BEGIN, CONT, END, BODY, ALIGN
*
@ -713,8 +724,8 @@ calculate_crc32c(uint32_t crc32c,
return (multitable_crc32c(crc32c, buffer, length));
}
}
#endif /* FreeBSD < 80000 || other OS */
#endif
#if defined(__Userspace__)
uint32_t
#else
@ -723,18 +734,16 @@ static uint32_t
sctp_finalize_crc32c(uint32_t crc32c)
{
uint32_t result;
#if BYTE_ORDER == BIG_ENDIAN
uint8_t byte0, byte1, byte2, byte3;
#endif
/* Complement the result */
result = ~crc32c;
#if BYTE_ORDER == BIG_ENDIAN
/*
* For BIG-ENDIAN.. aka Motorola byte order the result is in
* little-endian form. So we must manually swap the bytes. Then we
* can call htonl() which does nothing...
* For BIG-ENDIAN platforms the result is in little-endian form. So we
* must swap the bytes to return the result in network byte order.
*/
byte0 = result & 0x000000ff;
byte1 = (result >> 8) & 0x000000ff;
@ -743,66 +752,61 @@ sctp_finalize_crc32c(uint32_t crc32c)
crc32c = ((byte0 << 24) | (byte1 << 16) | (byte2 << 8) | byte3);
#else
/*
* For INTEL platforms the result comes out in network order. No
* htonl is required or the swap above. So we optimize out both the
* htonl and the manual swap above.
* For LITTLE ENDIAN platforms the result is in already in network
* byte order.
*/
crc32c = result;
#endif
return (crc32c);
}
/*
* Compute the SCTP checksum in network byte order for a given mbuf chain m
* which contains an SCTP packet starting at offset.
* Since this function is also called by ipfw, don't assume that
* it is compiled on a kernel with SCTP support.
*/
uint32_t
sctp_calculate_cksum(struct mbuf *m, uint32_t offset)
{
/*
* given a mbuf chain with a packetheader offset by 'offset'
* pointing at a sctphdr (with csum set to 0) go through the chain
* of SCTP_BUF_NEXT()'s and calculate the SCTP checksum. This also
* has a side bonus as it will calculate the total length of the
* mbuf chain. Note: if offset is greater than the total mbuf
* length, checksum=1, pktlen=0 is returned (ie. no real error code)
*/
uint32_t base = 0xffffffff;
struct mbuf *at;
at = m;
/* find the correct mbuf and offset into mbuf */
while ((at != NULL) && (offset > (uint32_t) SCTP_BUF_LEN(at))) {
offset -= SCTP_BUF_LEN(at); /* update remaining offset
* left */
at = SCTP_BUF_NEXT(at);
while (offset > 0) {
KASSERT(m != NULL, ("sctp_calculate_cksum, offset > length of mbuf chain"));
if (offset < (uint32_t)m->m_len) {
break;
}
offset -= m->m_len;
m = m->m_next;
}
while (at != NULL) {
if ((SCTP_BUF_LEN(at) - offset) > 0) {
base = calculate_crc32c(base,
(unsigned char *)(SCTP_BUF_AT(at, offset)),
(unsigned int)(SCTP_BUF_LEN(at) - offset));
}
if (offset) {
/* we only offset once into the first mbuf */
if (offset < (uint32_t) SCTP_BUF_LEN(at))
offset = 0;
else
offset -= SCTP_BUF_LEN(at);
}
at = SCTP_BUF_NEXT(at);
if (offset > 0) {
base = calculate_crc32c(base,
(unsigned char *)(m->m_data + offset),
(unsigned int)(m->m_len - offset));
m = m->m_next;
}
while (m != NULL) {
base = calculate_crc32c(base,
(unsigned char *)m->m_data,
(unsigned int)m->m_len);
m = m->m_next;
}
base = sctp_finalize_crc32c(base);
return (base);
}
#endif /* !defined(SCTP_WITH_NO_CSUM) */
#if defined(__FreeBSD__) && !defined(__Userspace__)
#if defined(SCTP) || defined(SCTP_SUPPORT)
#if defined(__FreeBSD__)
VNET_DEFINE(struct sctp_base_info, system_base_info);
/*
* Compute and insert the SCTP checksum in network byte order for a given
* mbuf chain m which contains an SCTP packet starting at offset.
*/
void
sctp_delayed_cksum(struct mbuf *m, uint32_t offset)
{
#if defined(SCTP_WITH_NO_CSUM)
#ifdef INVARIANTS
panic("sctp_delayed_cksum() called when using no SCTP CRC.");
#endif
#else
uint32_t checksum;
checksum = sctp_calculate_cksum(m, offset);
@ -810,18 +814,18 @@ sctp_delayed_cksum(struct mbuf *m, uint32_t offset)
SCTP_STAT_INCR(sctps_sendswcrc);
offset += offsetof(struct sctphdr, checksum);
if (offset + sizeof(uint32_t) > (uint32_t) (m->m_len)) {
SCTP_PRINTF("sctp_delayed_cksum(): m->len: %d, off: %d.\n",
(uint32_t) m->m_len, offset);
/*
* XXX this shouldn't happen, but if it does, the correct
* behavior may be to insert the checksum in the appropriate
* next mbuf in the chain.
*/
if (offset + sizeof(uint32_t) > (uint32_t)(m->m_pkthdr.len)) {
#ifdef INVARIANTS
panic("sctp_delayed_cksum(): m->m_pkthdr.len: %d, offset: %u.",
m->m_pkthdr.len, offset);
#else
SCTP_PRINTF("sctp_delayed_cksum(): m->m_pkthdr.len: %d, offset: %u.\n",
m->m_pkthdr.len, offset);
#endif
return;
}
*(uint32_t *) (m->m_data + offset) = checksum;
#endif
m_copyback(m, (int)offset, (int)sizeof(uint32_t), (caddr_t)&checksum);
}
#endif
#endif

View File

@ -32,27 +32,25 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_crc32.h 309607 2016-12-06 10:21:25Z tuexen $");
__FBSDID("$FreeBSD: head/sys/netinet/sctp_crc32.h 362338 2020-06-18 19:32:34Z markj $");
#endif
#ifndef _NETINET_SCTP_CRC32_H_
#define _NETINET_SCTP_CRC32_H_
#if defined(_KERNEL)
#if !defined(SCTP_WITH_NO_CSUM)
uint32_t sctp_calculate_cksum(struct mbuf *, uint32_t);
#endif
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
#if defined(SCTP) || defined(SCTP_SUPPORT)
void sctp_delayed_cksum(struct mbuf *, uint32_t offset);
#endif
#endif
#endif /* _KERNEL */
#if defined(__Userspace__)
#if !defined(SCTP_WITH_NO_CSUM)
uint32_t calculate_crc32c(uint32_t, const unsigned char *, unsigned int);
uint32_t sctp_finalize_crc32c(uint32_t);
uint32_t sctp_calculate_cksum(struct mbuf *, uint32_t);
#endif
#endif
#endif /* __crc32c_h__ */

View File

@ -32,7 +32,7 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_header.h 309682 2016-12-07 19:30:59Z tuexen $");
#endif
@ -40,16 +40,16 @@ __FBSDID("$FreeBSD: head/sys/netinet/sctp_header.h 309682 2016-12-07 19:30:59Z t
#ifndef _NETINET_SCTP_HEADER_H_
#define _NETINET_SCTP_HEADER_H_
#if defined(__Windows__) && !defined(__Userspace_os_Windows)
#if defined(_WIN32) && !defined(__Userspace__)
#include <packon.h>
#endif
#if !defined(__Userspace_os_Windows)
#if !defined(_WIN32)
#include <sys/time.h>
#endif
#include <netinet/sctp.h>
#include <netinet/sctp_constants.h>
#if !defined(__Userspace_os_Windows)
#if !defined(_WIN32)
#define SCTP_PACKED __attribute__((packed))
#else
#pragma pack (push, 1)
@ -601,10 +601,10 @@ struct sctp_auth_chunk {
#define SCTP_MIN_V4_OVERHEAD (sizeof(struct ip) + \
sizeof(struct sctphdr))
#if defined(__Windows__)
#if defined(_WIN32) && !defined(__Userspace__)
#include <packoff.h>
#endif
#if defined(__Userspace_os_Windows)
#if defined(_WIN32) && defined(__Userspace__)
#pragma pack(pop)
#endif
#undef SCTP_PACKED

File diff suppressed because it is too large Load Diff

View File

@ -32,9 +32,9 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_indata.h 310590 2016-12-26 11:06:41Z tuexen $");
__FBSDID("$FreeBSD: head/sys/netinet/sctp_indata.h 361116 2020-05-16 19:26:39Z tuexen $");
#endif
#ifndef _NETINET_SCTP_INDATA_H_
@ -63,7 +63,6 @@ sctp_build_readq_entry(struct sctp_tcb *stcb,
(_ctl)->sinfo_ppid = ppid; \
(_ctl)->sinfo_context = context; \
(_ctl)->fsn_included = 0xffffffff; \
(_ctl)->top_fsn = 0xffffffff; \
(_ctl)->sinfo_tsn = tsn; \
(_ctl)->sinfo_cumtsn = tsn; \
(_ctl)->sinfo_assoc_id = sctp_get_associd((in_it)); \
@ -71,6 +70,9 @@ sctp_build_readq_entry(struct sctp_tcb *stcb,
(_ctl)->data = dm; \
(_ctl)->stcb = (in_it); \
(_ctl)->port_from = (in_it)->rport; \
if ((in_it)->asoc.state & SCTP_STATE_ABOUT_TO_BE_FREED) { \
(_ctl)->do_not_ref_stcb = 1; \
}\
} \
} while (0)

File diff suppressed because it is too large Load Diff

View File

@ -32,9 +32,9 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_input.h 310590 2016-12-26 11:06:41Z tuexen $");
__FBSDID("$FreeBSD: head/sys/netinet/sctp_input.h 326672 2017-12-07 22:19:08Z tuexen $");
#endif
#ifndef _NETINET_SCTP_INPUT_H_
@ -45,11 +45,9 @@ void
sctp_common_input_processing(struct mbuf **, int, int, int,
struct sockaddr *, struct sockaddr *,
struct sctphdr *, struct sctp_chunkhdr *,
#if !defined(SCTP_WITH_NO_CSUM)
uint8_t,
#endif
uint8_t,
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
uint8_t, uint32_t, uint16_t,
#endif
uint32_t, uint16_t);

View File

@ -33,7 +33,7 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#endif
@ -68,7 +68,7 @@ __FBSDID("$FreeBSD$");
#define SCTP_WQ_ADDR_DESTROY()
#define SCTP_WQ_ADDR_LOCK()
#define SCTP_WQ_ADDR_UNLOCK()
#define SCTP_WQ_ADDR_LOCK_ASSERT()
#define SCTP_IPI_ADDR_INIT()
#define SCTP_IPI_ADDR_DESTROY()
@ -82,14 +82,11 @@ __FBSDID("$FreeBSD$");
#define SCTP_IPI_ITERATOR_WQ_LOCK()
#define SCTP_IPI_ITERATOR_WQ_UNLOCK()
#define SCTP_IP_PKTLOG_INIT()
#define SCTP_IP_PKTLOG_LOCK()
#define SCTP_IP_PKTLOG_UNLOCK()
#define SCTP_IP_PKTLOG_DESTROY()
#define SCTP_INP_READ_INIT(_inp)
#define SCTP_INP_READ_DESTROY(_inp)
#define SCTP_INP_READ_LOCK(_inp)
@ -100,9 +97,10 @@ __FBSDID("$FreeBSD$");
#define SCTP_INP_LOCK_DESTROY(_inp)
#define SCTP_ASOC_CREATE_LOCK_DESTROY(_inp)
#define SCTP_INP_RLOCK(_inp)
#define SCTP_INP_WLOCK(_inp)
#define SCTP_INP_RLOCK_ASSERT(_inp)
#define SCTP_INP_WLOCK_ASSERT(_inp)
#define SCTP_INP_LOCK_CONTENDED(_inp) (0) /* Don't know if this is possible */
@ -214,14 +212,6 @@ __FBSDID("$FreeBSD$");
} while (0)
/* not sure if __Userspace__ needs these (but copied nonetheless...) */
#if defined(SCTP_SO_LOCK_TESTING)
#define SCTP_INP_SO(sctpinp) (sctpinp)->ip_inp.inp.inp_socket
#define SCTP_SOCKET_LOCK(so, refcnt)
#define SCTP_SOCKET_UNLOCK(so, refcnt)
#endif
/* these were in sctp_lock_empty.h but aren't in sctp_lock_bsd.h ... */
#if 0
#define SCTP_IPI_ADDR_LOCK()

View File

@ -32,9 +32,9 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_os.h 235828 2012-05-23 11:26:28Z tuexen $");
__FBSDID("$FreeBSD: head/sys/netinet/sctp_os.h 361872 2020-06-06 18:20:09Z tuexen $");
#endif
#ifndef _NETINET_SCTP_OS_H_
@ -64,7 +64,7 @@ __FBSDID("$FreeBSD: head/sys/netinet/sctp_os.h 235828 2012-05-23 11:26:28Z tuexe
* SCTP_ZONE_DESTROY(zone)
*/
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <netinet/sctp_os_bsd.h>
#else
#define MODULE_GLOBAL(_B) (_B)
@ -74,15 +74,11 @@ __FBSDID("$FreeBSD: head/sys/netinet/sctp_os.h 235828 2012-05-23 11:26:28Z tuexe
#include <netinet/sctp_os_userspace.h>
#endif
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
#include <netinet/sctp_os_macosx.h>
#endif
#if defined(__Panda__)
#include <ip/sctp/sctp_os_iox.h>
#endif
#if defined(__Windows__)
#if defined(_WIN32) && !defined(__Userspace__)
#include <netinet/sctp_os_windows.h>
#endif

View File

@ -43,7 +43,7 @@
#include <errno.h>
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
#include <winsock2.h>
#include <ws2tcpip.h>
#include <iphlpapi.h>
@ -76,38 +76,34 @@ void WakeAllXPConditionVariable(userland_cond_t *);
typedef CONDITION_VARIABLE userland_cond_t;
#endif
typedef HANDLE userland_thread_t;
typedef DWORD userland_thread_id_t;
#define ADDRESS_FAMILY unsigned __int8
#define IPVERSION 4
#define MAXTTL 255
/* VS2010 comes with stdint.h */
#if _MSC_VER >= 1600
#if !defined(_MSC_VER) || (_MSC_VER >= 1600)
#include <stdint.h>
#else
#define uint64_t unsigned __int64
#define uint32_t unsigned __int32
#define int32_t __int32
#define uint16_t unsigned __int16
#define int16_t __int16
#define uint8_t unsigned __int8
#define int8_t __int8
typedef unsigned __int64 uint64_t;
typedef unsigned __int32 uint32_t;
typedef __int32 int32_t;
typedef unsigned __int16 uint16_t;
typedef __int16 int16_t;
typedef unsigned __int8 uint8_t;
typedef __int8 int8_t;
#endif
#ifndef _SIZE_T_DEFINED
#define size_t __int32
#typedef __int32 size_t;
#endif
#define u_long unsigned __int64
#define u_int unsigned __int32
#define u_int32_t unsigned __int32
#define u_int16_t unsigned __int16
#define u_int8_t unsigned __int8
#define u_char unsigned char
#define n_short unsigned __int16
#define u_short unsigned __int16
#define n_time unsigned __int32
#define sa_family_t unsigned __int8
#define ssize_t __int64
typedef unsigned __int32 u_int;
typedef unsigned char u_char;
typedef unsigned __int16 u_short;
typedef unsigned __int8 sa_family_t;
#ifndef _SSIZE_T_DEFINED
typedef __int64 ssize_t;
#endif
#if !defined(__MINGW32__)
#define __func__ __FUNCTION__
#endif
#ifndef EWOULDBLOCK
#define EWOULDBLOCK WSAEWOULDBLOCK
#endif
@ -221,9 +217,19 @@ typedef char* caddr_t;
#define bzero(buf, len) memset(buf, 0, len)
#define bcopy(srcKey, dstKey, len) memcpy(dstKey, srcKey, len)
#if _MSC_VER < 1900
#define snprintf(data, size, format, ...) _snprintf_s(data, size, _TRUNCATE, format, __VA_ARGS__)
#if defined(_MSC_VER) && (_MSC_VER < 1900) && !defined(__MINGW32__)
#define SCTP_SNPRINTF(data, size, format, ...) \
if (_snprintf_s(data, size, _TRUNCATE, format, __VA_ARGS__) < 0) { \
data[0] = '\0'; \
}
#else
#define SCTP_SNPRINTF(data, ...) \
if (snprintf(data, __VA_ARGS__) < 0 ) { \
data[0] = '\0'; \
}
#endif
#define inline __inline
#define __inline__ __inline
#define MSG_EOR 0x8 /* data completes record */
@ -277,16 +283,15 @@ typedef char* caddr_t;
#else /* !defined(Userspace_os_Windows) */
#include <sys/socket.h>
#if defined(__Userspace_os_DragonFly) || defined(__Userspace_os_FreeBSD) || defined(__Userspace_os_Linux) || defined(__Userspace_os_NetBSD) || defined(__Userspace_os_OpenBSD) || defined(__Userspace_os_NaCl) || defined(__Userspace_os_Fuchsia)
#if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__linux__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__native_client__) || defined(__Fuchsia__)
#include <pthread.h>
#endif
typedef pthread_mutex_t userland_mutex_t;
typedef pthread_cond_t userland_cond_t;
typedef pthread_t userland_thread_t;
typedef pthread_t userland_thread_id_t;
#endif
#if defined(__Userspace_os_Windows) || defined(__Userspace_os_NaCl)
#if defined(_WIN32) || defined(__native_client__)
#define IFNAMSIZ 64
@ -380,43 +385,9 @@ struct ifkpi {
int ifk_value;
} ifk_data;
};
struct ifreq {
char ifr_name[16];
union {
struct sockaddr ifru_addr;
struct sockaddr ifru_dstaddr;
struct sockaddr ifru_broadaddr;
short ifru_flags;
int ifru_metric;
int ifru_mtu;
int ifru_phys;
int ifru_media;
int ifru_intval;
char* ifru_data;
struct ifdevmtu ifru_devmtu;
struct ifkpi ifru_kpi;
uint32_t ifru_wake_flags;
} ifr_ifru;
#define ifr_addr ifr_ifru.ifru_addr
#define ifr_dstaddr ifr_ifru.ifru_dstaddr
#define ifr_broadaddr ifr_ifru.ifru_broadaddr
#define ifr_flags ifr_ifru.ifru_flags[0]
#define ifr_prevflags ifr_ifru.ifru_flags[1]
#define ifr_metric ifr_ifru.ifru_metric
#define ifr_mtu ifr_ifru.ifru_mtu
#define ifr_phys ifr_ifru.ifru_phys
#define ifr_media ifr_ifru.ifru_media
#define ifr_data ifr_ifru.ifru_data
#define ifr_devmtu ifr_ifru.ifru_devmtu
#define ifr_intval ifr_ifru.ifru_intval
#define ifr_kpi ifr_ifru.ifru_kpi
#define ifr_wake_flags ifr_ifru.ifru_wake_flags
};
#endif
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
int Win_getifaddrs(struct ifaddrs**);
#define getifaddrs(interfaces) (int)Win_getifaddrs(interfaces)
int win_if_nametoindex(const char *);
@ -427,9 +398,9 @@ int win_if_nametoindex(const char *);
#define mtx_unlock(arg1)
#define mtx_assert(arg1,arg2)
#define MA_OWNED 7 /* sys/mutex.h typically on FreeBSD */
#if !defined(__Userspace_os_FreeBSD)
#if !defined(__FreeBSD__)
struct mtx {int dummy;};
#if !defined(__Userspace_os_NetBSD)
#if !defined(__NetBSD__)
struct selinfo {int dummy;};
#endif
struct sx {int dummy;};
@ -437,6 +408,7 @@ struct sx {int dummy;};
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
/* #include <sys/param.h> in FreeBSD defines MSIZE */
/* #include <sys/ktr.h> */
/* #include <sys/systm.h> */
@ -459,22 +431,22 @@ struct sx {int dummy;};
#include <user_mbuf.h>
/* #include <sys/uio.h> */
/* #include <sys/lock.h> */
#if defined(__FreeBSD__) && __FreeBSD_version > 602000
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/rwlock.h>
#endif
/* #include <sys/kthread.h> */
#if defined(__FreeBSD__) && __FreeBSD_version > 602000
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/priv.h>
#endif
/* #include <sys/random.h> */
#include <limits.h>
/* #include <machine/cpu.h> */
#if defined(__Userspace_os_Darwin)
#if defined(__APPLE__)
/* was a 0 byte file. needed for structs if_data(64) and net_event_data */
#include <net/if_var.h>
#endif
#if defined(__Userspace_os_FreeBSD)
#if defined(__FreeBSD__)
#include <net/if_types.h>
/* #include <net/if_var.h> was a 0 byte file. causes struct mtx redefinition */
#endif
@ -482,7 +454,7 @@ struct sx {int dummy;};
* userspace as well? */
/* on FreeBSD, this results in a redefintion of struct route */
/* #include <net/route.h> */
#if !defined(__Userspace_os_Windows) && !defined(__Userspace_os_NaCl)
#if !defined(_WIN32) && !defined(__native_client__)
#include <net/if.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
@ -498,8 +470,8 @@ struct sx {int dummy;};
/* for getifaddrs */
#include <sys/types.h>
#if !defined(__Userspace_os_Windows)
#if !defined(ANDROID) && (defined(INET) || defined(INET6))
#if !defined(_WIN32)
#if defined(INET) || defined(INET6)
#include <ifaddrs.h>
#endif
@ -508,6 +480,8 @@ struct sx {int dummy;};
/* for close, etc. */
#include <unistd.h>
/* for gettimeofday */
#include <sys/time.h>
#endif
/* lots of errno's used and needed in userspace */
@ -515,7 +489,7 @@ struct sx {int dummy;};
/* for offsetof */
#include <stddef.h>
#if defined(SCTP_PROCESS_LEVEL_LOCKS) && !defined(__Userspace_os_Windows)
#if defined(SCTP_PROCESS_LEVEL_LOCKS) && !defined(_WIN32)
/* for pthread_mutex_lock, pthread_mutex_unlock, etc. */
#include <pthread.h>
#endif
@ -526,21 +500,21 @@ struct sx {int dummy;};
#endif /* IPSEC */
#ifdef INET6
#if defined(__Userspace_os_FreeBSD)
#if defined(__FreeBSD__)
#include <sys/domain.h>
#endif
#ifdef IPSEC
#include <netipsec/ipsec6.h>
#endif
#if !defined(__Userspace_os_Windows)
#if !defined(_WIN32)
#include <netinet/ip6.h>
#endif
#if defined(__Userspace_os_Darwin) || defined(__Userspace_os_FreeBSD) || defined(__Userspace_os_Linux) || defined(__Userspace_os_NetBSD) || defined(__Userspace_os_OpenBSD) || defined(__Userspace_os_Windows)
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__linux__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(_WIN32)
#include "user_ip6_var.h"
#else
#include <netinet6/ip6_var.h>
#endif
#if defined(__Userspace_os_FreeBSD)
#if defined(__FreeBSD__)
#include <netinet6/in6_pcb.h>
#include <netinet6/ip6protosw.h>
/* #include <netinet6/nd6.h> was a 0 byte file */
@ -555,7 +529,7 @@ struct sx {int dummy;};
#include "netinet/sctp_sha1.h"
#if __FreeBSD_version >= 700000
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <netinet/ip_options.h>
#endif
@ -564,11 +538,6 @@ struct sx {int dummy;};
SCTP_BASE_VAR(debug_printf)(__VA_ARGS__); \
}
#if defined(__FreeBSD__)
#ifndef in6pcb
#define in6pcb inpcb
#endif
#endif
/* Declare all the malloc names for all the various mallocs */
MALLOC_DECLARE(SCTP_M_MAP);
MALLOC_DECLARE(SCTP_M_STRMI);
@ -613,12 +582,12 @@ MALLOC_DECLARE(SCTP_M_SOCKOPT);
/*
*
*/
#if !defined(__Userspace_os_Darwin)
#if !defined(__APPLE__)
#define USER_ADDR_NULL (NULL) /* FIX ME: temp */
#endif
#if defined(SCTP_DEBUG)
#include <netinet/sctp_constants.h>
#if defined(SCTP_DEBUG)
#define SCTPDBG(level, ...) \
{ \
do { \
@ -672,7 +641,7 @@ MALLOC_DECLARE(SCTP_M_SOCKOPT);
#define SCTP_VRF_IFN_HASH_SIZE 3
#define SCTP_INIT_VRF_TABLEID(vrf)
#if !defined(__Userspace_os_Windows)
#if !defined(_WIN32)
#define SCTP_IFN_IS_IFT_LOOP(ifn) (strncmp((ifn)->ifn_name, "lo", 2) == 0)
/* BSD definition */
/* #define SCTP_ROUTE_IS_REAL_LOOP(ro) ((ro)->ro_rt && (ro)->ro_rt->rt_ifa && (ro)->ro_rt->rt_ifa->ifa_ifp && (ro)->ro_rt->rt_ifa->ifa_ifp->if_type == IFT_LOOP) */
@ -806,7 +775,7 @@ sctp_hashfreedestroy(void *vhashtbl, struct malloc_type *type, u_long hashmask);
#define KTR_SUBSYS 1
/* The packed define for 64 bit platforms */
#if !defined(__Userspace_os_Windows)
#if !defined(_WIN32)
#define SCTP_PACKED __attribute__((packed))
#define SCTP_UNUSED __attribute__((unused))
#else
@ -835,6 +804,13 @@ sctp_hashfreedestroy(void *vhashtbl, struct malloc_type *type, u_long hashmask);
M_ALIGN(m, len); \
}
#if !defined(_WIN32)
#define SCTP_SNPRINTF(data, ...) \
if (snprintf(data, __VA_ARGS__) < 0) { \
data[0] = '\0'; \
}
#endif
/* We make it so if you have up to 4 threads
* writting based on the default size of
* the packet log 65 k, that would be
@ -893,7 +869,6 @@ static inline void sctp_userspace_rtfree(sctp_rtentry_t *rt)
return;
}
free(rt);
rt = NULL;
}
#define rtfree(arg1) sctp_userspace_rtfree(arg1)
@ -914,10 +889,6 @@ int sctp_userspace_get_mtu_from_ifn(uint32_t if_index, int af);
rt->rt_rmx.rmx_mtu = mtu; \
} while(0)
/* (de-)register interface event notifications */
#define SCTP_REGISTER_INTERFACE(ifhandle, af)
#define SCTP_DEREGISTER_INTERFACE(ifhandle, af)
/*************************/
/* These are for logging */
@ -967,11 +938,11 @@ int sctp_userspace_get_mtu_from_ifn(uint32_t if_index, int af);
*/
/* get the v6 hop limit */
#define SCTP_GET_HLIM(inp, ro) 128 /* As done for __Windows__ */
#define SCTP_GET_HLIM(inp, ro) 128
#define IPv6_HOP_LIMIT 128
/* is the endpoint v6only? */
#define SCTP_IPV6_V6ONLY(inp) (((struct inpcb *)inp)->inp_flags & IN6P_IPV6_V6ONLY)
#define SCTP_IPV6_V6ONLY(sctp_inpcb) ((sctp_inpcb)->ip_inp.inp.inp_flags & IN6P_IPV6_V6ONLY)
/* is the socket non-blocking? */
#define SCTP_SO_IS_NBIO(so) ((so)->so_state & SS_NBIO)
#define SCTP_SET_SO_NBIO(so) ((so)->so_state |= SS_NBIO)
@ -1006,7 +977,7 @@ int sctp_userspace_get_mtu_from_ifn(uint32_t if_index, int af);
/* sctp_pcb.h */
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
#define SHUT_RD 1
#define SHUT_WR 2
#define SHUT_RDWR 3
@ -1041,9 +1012,6 @@ sctp_userspace_thread_create(userland_thread_t *thread, start_routine_t start_ro
void
sctp_userspace_set_threadname(const char *name);
int sctp_userspace_thread_id(userland_thread_id_t *thread);
int sctp_userspace_thread_equal(userland_thread_id_t t1, userland_thread_id_t t2);
/*
* SCTP protocol specific mbuf flags.
*/
@ -1082,7 +1050,7 @@ extern void sctp_userspace_ip6_output(int *result, struct mbuf *o_pak,
{ \
if (stcb && stcb->sctp_ep) \
result = ip6_output(o_pak, \
((struct in6pcb *)(stcb->sctp_ep))->in6p_outputopts, \
((struct inpcb *)(stcb->sctp_ep))->in6p_outputopts, \
(ro), 0, 0, ifp, NULL); \
else \
result = ip6_output(o_pak, NULL, (ro), 0, 0, ifp, NULL); \
@ -1096,12 +1064,12 @@ sctp_get_mbuf_for_msg(unsigned int space_needed, int want_header, int how, int a
/* with the current included files, this is defined in Linux but
* in FreeBSD, it is behind a _KERNEL in sys/socket.h ...
*/
#if defined(__Userspace_os_DragonFly) || defined(__Userspace_os_FreeBSD) || defined(__Userspace_os_OpenBSD) || defined(__Userspace_os_NaCl)
#if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__native_client__)
/* stolen from /usr/include/sys/socket.h */
#define CMSG_ALIGN(n) _ALIGN(n)
#elif defined(__Userspace_os_NetBSD)
#elif defined(__NetBSD__)
#define CMSG_ALIGN(n) (((n) + __ALIGNBYTES) & ~__ALIGNBYTES)
#elif defined(__Userspace_os_Darwin)
#elif defined(__APPLE__)
#if !defined(__DARWIN_ALIGNBYTES)
#define __DARWIN_ALIGNBYTES (sizeof(__darwin_size_t) - 1)
#endif
@ -1136,7 +1104,7 @@ sctp_get_mbuf_for_msg(unsigned int space_needed, int want_header, int how, int a
} while (0)
#endif
#if defined(__Userspace_os_Linux)
#if defined(__linux__)
#if !defined(TAILQ_FOREACH_SAFE)
#define TAILQ_FOREACH_SAFE(var, head, field, tvar) \
for ((var) = ((head)->tqh_first); \
@ -1150,12 +1118,12 @@ sctp_get_mbuf_for_msg(unsigned int space_needed, int want_header, int how, int a
(var) = (tvar))
#endif
#endif
#if defined(__Userspace_os_DragonFly)
#if defined(__DragonFly__)
#define TAILQ_FOREACH_SAFE TAILQ_FOREACH_MUTABLE
#define LIST_FOREACH_SAFE LIST_FOREACH_MUTABLE
#endif
#if defined(__Userspace_os_NaCl)
#if defined(__native_client__)
#define timercmp(tvp, uvp, cmp) \
(((tvp)->tv_sec == (uvp)->tv_sec) ? \
((tvp)->tv_usec cmp (uvp)->tv_usec) : \
@ -1164,4 +1132,9 @@ sctp_get_mbuf_for_msg(unsigned int space_needed, int want_header, int how, int a
#define SCTP_IS_LISTENING(inp) ((inp->sctp_flags & SCTP_PCB_FLAGS_ACCEPTING) != 0)
#if defined(__APPLE__) || defined(__DragonFly__) || defined(__linux__) || defined(__native_client__) || defined(__NetBSD__) || defined(_WIN32) || defined(__Fuchsia__)
int
timingsafe_bcmp(const void *, const void *, size_t);
#endif
#endif

File diff suppressed because it is too large Load Diff

View File

@ -32,9 +32,9 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_output.h 323861 2017-09-21 11:56:31Z tuexen $");
__FBSDID("$FreeBSD: head/sys/netinet/sctp_output.h 362054 2020-06-11 13:34:09Z tuexen $");
#endif
#ifndef _NETINET_SCTP_OUTPUT_H_
@ -78,11 +78,7 @@ int
sctp_v4src_match_nexthop(struct sctp_ifa *sifa, sctp_route_t *ro);
#endif
void sctp_send_initiate(struct sctp_inpcb *, struct sctp_tcb *, int
#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
SCTP_UNUSED
#endif
);
void sctp_send_initiate(struct sctp_inpcb *, struct sctp_tcb *, int);
void
sctp_send_initiate_ack(struct sctp_inpcb *, struct sctp_tcb *,
@ -90,18 +86,18 @@ sctp_send_initiate_ack(struct sctp_inpcb *, struct sctp_tcb *,
int, int,
struct sockaddr *, struct sockaddr *,
struct sctphdr *, struct sctp_init_chunk *,
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
uint8_t, uint32_t,
#endif
uint32_t, uint16_t);
struct mbuf *
sctp_arethere_unrecognized_parameters(struct mbuf *, int, int *,
struct sctp_chunkhdr *, int *);
struct sctp_chunkhdr *, int *, int *);
void sctp_queue_op_err(struct sctp_tcb *, struct mbuf *);
int
sctp_send_cookie_echo(struct mbuf *, int, struct sctp_tcb *,
sctp_send_cookie_echo(struct mbuf *, int, int, struct sctp_tcb *,
struct sctp_nets *);
void sctp_send_cookie_ack(struct sctp_tcb *);
@ -124,7 +120,7 @@ void sctp_send_shutdown_complete(struct sctp_tcb *, struct sctp_nets *, int);
void sctp_send_shutdown_complete2(struct sockaddr *, struct sockaddr *,
struct sctphdr *,
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
uint8_t, uint32_t, uint16_t,
#endif
uint32_t, uint16_t);
@ -148,11 +144,11 @@ void sctp_move_chunks_from_net(struct sctp_tcb *stcb, struct sctp_nets *net);
sizeof(struct sctp_idata_chunk) : \
sizeof(struct sctp_data_chunk))
#if defined(__FreeBSD__) && __FreeBSD_version >= 500000
#if defined(__FreeBSD__) && !defined(__Userspace__)
int
sctp_output(struct sctp_inpcb *, struct mbuf *, struct sockaddr *,
struct mbuf *, struct thread *, int);
#elif defined(__Windows__)
#elif defined(_WIN32) && !defined(__Userspace__)
sctp_output(struct sctp_inpcb *, struct mbuf *, struct sockaddr *,
struct mbuf *, PKTHREAD, int);
#else
@ -161,30 +157,15 @@ sctp_output(struct sctp_inpcb *, struct mbuf *, struct sockaddr *,
#endif
int
sctp_output(struct sctp_inpcb *,
#if defined(__Panda__)
pakhandle_type,
#else
struct mbuf *,
#endif
struct sockaddr *,
#if defined(__Panda__)
pakhandle_type,
#else
struct mbuf *,
#endif
struct proc *, int);
#endif
void sctp_chunk_output(struct sctp_inpcb *, struct sctp_tcb *, int, int
#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
SCTP_UNUSED
#endif
);
void sctp_send_abort_tcb(struct sctp_tcb *, struct mbuf *, int
#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
SCTP_UNUSED
#endif
);
void sctp_chunk_output(struct sctp_inpcb *, struct sctp_tcb *, int, int);
void sctp_send_abort_tcb(struct sctp_tcb *, struct mbuf *, int);
void send_forward_tsn(struct sctp_tcb *, struct sctp_association *);
@ -194,7 +175,6 @@ void sctp_send_hb(struct sctp_tcb *, struct sctp_nets *, int);
void sctp_send_ecn_echo(struct sctp_tcb *, struct sctp_nets *, uint32_t);
void
sctp_send_packet_dropped(struct sctp_tcb *, struct sctp_nets *, struct mbuf *,
int, int, int);
@ -225,14 +205,14 @@ sctp_send_str_reset_req(struct sctp_tcb *, uint16_t , uint16_t *,
void
sctp_send_abort(struct mbuf *, int, struct sockaddr *, struct sockaddr *,
struct sctphdr *, uint32_t, struct mbuf *,
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
uint8_t, uint32_t, uint16_t,
#endif
uint32_t, uint16_t);
void sctp_send_operr_to(struct sockaddr *, struct sockaddr *,
struct sctphdr *, uint32_t, struct mbuf *,
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
uint8_t, uint32_t, uint16_t,
#endif
uint32_t, uint16_t);
@ -244,20 +224,15 @@ int
sctp_sosend(struct socket *so,
struct sockaddr *addr,
struct uio *uio,
#ifdef __Panda__
pakhandle_type top,
pakhandle_type control,
#else
struct mbuf *top,
struct mbuf *control,
#endif
#if defined(__APPLE__) || defined(__Panda__)
#if defined(__APPLE__) && !defined(__Userspace__)
int flags
#else
int flags,
#if defined(__FreeBSD__) && __FreeBSD_version >= 500000
#if defined(__FreeBSD__) && !defined(__Userspace__)
struct thread *p
#elif defined(__Windows__)
#elif defined(_WIN32) && !defined(__Userspace__)
PKTHREAD p
#else
#if defined(__Userspace__)

File diff suppressed because it is too large Load Diff

View File

@ -32,9 +32,9 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_pcb.h 325370 2017-11-03 20:46:12Z tuexen $");
__FBSDID("$FreeBSD: head/sys/netinet/sctp_pcb.h 362106 2020-06-12 16:31:13Z tuexen $");
#endif
#ifndef _NETINET_SCTP_PCB_H_
@ -149,7 +149,7 @@ struct sctp_tagblock {
struct sctp_epinfo {
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
#ifdef INET
struct socket *udp4_tun_socket;
#endif
@ -189,7 +189,7 @@ struct sctp_epinfo {
struct sctppcbhead listhead;
struct sctpladdr addr_wq;
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
struct inpcbhead inplisthead;
struct inpcbinfo sctbinfo;
#endif
@ -204,18 +204,10 @@ struct sctp_epinfo {
sctp_zone_t ipi_zone_asconf;
sctp_zone_t ipi_zone_asconf_ack;
#if defined(__FreeBSD__) && __FreeBSD_version >= 503000
#if __FreeBSD_version <= 602000
struct mtx ipi_ep_mtx;
#else
#if defined(__FreeBSD__) && !defined(__Userspace__)
struct rwlock ipi_ep_mtx;
#endif
struct mtx ipi_iterator_wq_mtx;
#if __FreeBSD_version <= 602000
struct mtx ipi_addr_mtx;
#else
struct rwlock ipi_addr_mtx;
#endif
struct mtx ipi_pktlog_mtx;
struct mtx wq_addr_mtx;
#elif defined(SCTP_PROCESS_LEVEL_LOCKS)
@ -224,7 +216,7 @@ struct sctp_epinfo {
userland_mutex_t ipi_count_mtx;
userland_mutex_t ipi_pktlog_mtx;
userland_mutex_t wq_addr_mtx;
#elif defined(__APPLE__)
#elif defined(__APPLE__) && !defined(__Userspace__)
#ifdef _KERN_LOCKS_H_
lck_mtx_t *ipi_addr_mtx;
lck_mtx_t *ipi_count_mtx;
@ -235,13 +227,12 @@ struct sctp_epinfo {
void *ipi_count_mtx;
void *logging_mtx;
#endif /* _KERN_LOCKS_H_ */
#elif defined(__Windows__)
#elif defined(_WIN32) && !defined(__Userspace__)
struct rwlock ipi_ep_lock;
struct rwlock ipi_addr_lock;
struct spinlock ipi_pktlog_mtx;
struct rwlock wq_addr_mtx;
#elif defined(__Userspace__)
/* TODO decide on __Userspace__ locks */
#endif
uint32_t ipi_count_ep;
@ -292,8 +283,12 @@ struct sctp_base_info {
* anchor the system must be here.
*/
struct sctp_epinfo sctppcbinfo;
#if defined(__FreeBSD__) && defined(SMP) && defined(SCTP_USE_PERCPU_STAT)
#if defined(__FreeBSD__) && !defined(__Userspace__)
#if defined(SMP) && defined(SCTP_USE_PERCPU_STAT)
struct sctpstat *sctpstat;
#else
struct sctpstat sctpstat;
#endif
#else
struct sctpstat sctpstat;
#endif
@ -305,14 +300,19 @@ struct sctp_base_info {
int packet_log_end;
uint8_t packet_log_buffer[SCTP_PACKET_LOG_SIZE];
#endif
#if defined(__APPLE__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
eventhandler_tag eh_tag;
#endif
#if defined(__APPLE__) && !defined(__Userspace__)
int sctp_main_timer_ticks;
#endif
#if defined(__Userspace__)
userland_mutex_t timer_mtx;
userland_thread_t timer_thread;
uint8_t timer_thread_should_exit;
#if !defined(__Userspace_os_Windows)
int timer_thread_should_exit;
int iterator_thread_started;
int timer_thread_started;
#if !defined(_WIN32)
pthread_mutexattr_t mtx_attr;
#if defined(INET) || defined(INET6)
int userspace_route;
@ -320,7 +320,7 @@ struct sctp_base_info {
#endif
#endif
#ifdef INET
#if defined(__Userspace_os_Windows)
#if defined(_WIN32) && !defined(__MINGW32__)
SOCKET userspace_rawsctp;
SOCKET userspace_udpsctp;
#else
@ -331,7 +331,7 @@ struct sctp_base_info {
userland_thread_t recvthreadudp;
#endif
#ifdef INET6
#if defined(__Userspace_os_Windows)
#if defined(_WIN32) && !defined(__MINGW32__)
SOCKET userspace_rawsctp6;
SOCKET userspace_udpsctp6;
#else
@ -358,11 +358,11 @@ struct sctp_pcb {
uint32_t secret_key[SCTP_HOW_MANY_SECRETS][SCTP_NUMBER_OF_SECRETS];
unsigned int size_of_a_cookie;
unsigned int sctp_timeoutticks[SCTP_NUM_TMRS];
unsigned int sctp_minrto;
unsigned int sctp_maxrto;
unsigned int initial_rto;
int initial_init_rto_max;
uint32_t sctp_timeoutticks[SCTP_NUM_TMRS];
uint32_t sctp_minrto;
uint32_t sctp_maxrto;
uint32_t initial_rto;
uint32_t initial_init_rto_max;
unsigned int sctp_sack_freq;
uint32_t sctp_sws_sender;
@ -405,7 +405,7 @@ struct sctp_pcb {
uint32_t def_cookie_life;
/* defaults to 0 */
int auto_close_time;
uint32_t auto_close_time;
uint32_t initial_sequence_debug;
uint32_t adaptation_layer_indicator;
uint8_t adaptation_layer_indicator_provided;
@ -448,11 +448,11 @@ struct sctp_inpcb {
*/
union {
struct inpcb inp;
char align[(sizeof(struct in6pcb) + SCTP_ALIGNM1) &
char align[(sizeof(struct inpcb) + SCTP_ALIGNM1) &
~SCTP_ALIGNM1];
} ip_inp;
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
/* leave some space in case i386 inpcb is bigger than ppc */
uint8_t padding[128];
#endif
@ -509,26 +509,9 @@ struct sctp_inpcb {
* they are candidates with sctp_sendm for
* de-supporting.
*/
#ifdef __Panda__
pakhandle_type pak_to_read;
pakhandle_type pak_to_read_sendq;
#endif
struct mbuf *pkt, *pkt_last;
struct mbuf *control;
#if !(defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__) || defined(__Userspace__))
#ifndef INP_IPV6
#define INP_IPV6 0x1
#endif
#ifndef INP_IPV4
#define INP_IPV4 0x2
#endif
uint8_t inp_vflag;
/* TODO __Userspace__ where is our inp_vlag going to be? */
uint8_t inp_ip_ttl;
uint8_t inp_ip_tos; /* defined as macro in user_inpcb.h */
uint8_t inp_ip_resv;
#endif
#if defined(__FreeBSD__) && __FreeBSD_version >= 503000
#if defined(__FreeBSD__) && !defined(__Userspace__)
struct mtx inp_mtx;
struct mtx inp_create_mtx;
struct mtx inp_rdata_mtx;
@ -538,7 +521,7 @@ struct sctp_inpcb {
userland_mutex_t inp_create_mtx;
userland_mutex_t inp_rdata_mtx;
int32_t refcount;
#elif defined(__APPLE__)
#elif defined(__APPLE__) && !defined(__Userspace__)
#if defined(SCTP_APPLE_RWLOCK)
lck_rw_t *inp_mtx;
#else
@ -546,16 +529,15 @@ struct sctp_inpcb {
#endif
lck_mtx_t *inp_create_mtx;
lck_mtx_t *inp_rdata_mtx;
#elif defined(__Windows__)
#elif defined(_WIN32) && !defined(__Userspace__)
struct rwlock inp_lock;
struct spinlock inp_create_lock;
struct spinlock inp_rdata_lock;
int32_t refcount;
#elif defined(__Userspace__)
/* TODO decide on __Userspace__ locks */
int32_t refcount;
#endif
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
int32_t refcount;
uint32_t lock_caller1;
@ -609,6 +591,7 @@ int register_recv_cb (struct socket *,
struct sctp_rcvinfo, int, void *));
int register_send_cb (struct socket *, uint32_t, int (*)(struct socket *, uint32_t));
int register_ulp_info (struct socket *, void *);
int retrieve_ulp_info (struct socket *, void **);
#endif
struct sctp_tcb {
@ -636,22 +619,21 @@ struct sctp_tcb {
int freed_from_where;
uint16_t rport; /* remote port in network format */
uint16_t resv;
#if defined(__FreeBSD__) && __FreeBSD_version >= 503000
#if defined(__FreeBSD__) && !defined(__Userspace__)
struct mtx tcb_mtx;
struct mtx tcb_send_mtx;
#elif defined(SCTP_PROCESS_LEVEL_LOCKS)
userland_mutex_t tcb_mtx;
userland_mutex_t tcb_send_mtx;
#elif defined(__APPLE__)
#elif defined(__APPLE__) && !defined(__Userspace__)
lck_mtx_t* tcb_mtx;
lck_mtx_t* tcb_send_mtx;
#elif defined(__Windows__)
#elif defined(_WIN32) && !defined(__Userspace__)
struct spinlock tcb_lock;
struct spinlock tcb_send_lock;
#elif defined(__Userspace__)
/* TODO decide on __Userspace__ locks */
#endif
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
uint32_t caller1;
uint32_t caller2;
uint32_t caller3;
@ -659,11 +641,11 @@ struct sctp_tcb {
};
#if defined(__FreeBSD__) && __FreeBSD_version >= 503000
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <netinet/sctp_lock_bsd.h>
#elif defined(__APPLE__)
#elif defined(__APPLE__) && !defined(__Userspace__)
/*
* Apple MacOS X 10.4 "Tiger"
*/
@ -674,7 +656,7 @@ struct sctp_tcb {
#include <netinet/sctp_process_lock.h>
#elif defined(__Windows__)
#elif defined(_WIN32) && !defined(__Userspace__)
#include <netinet/sctp_lock_windows.h>
@ -689,14 +671,13 @@ struct sctp_tcb {
#include <netinet/sctp_lock_empty.h>
#endif
/* TODO where to put non-_KERNEL things for __Userspace__? */
#if defined(_KERNEL) || defined(__Userspace__)
/* Attention Julian, this is the extern that
* goes with the base info. sctp_pcb.c has
* the real definition.
*/
#if defined(__FreeBSD__) && __FreeBSD_version >= 801000
#if defined(__FreeBSD__) && !defined(__Userspace__)
VNET_DECLARE(struct sctp_base_info, system_base_info) ;
#else
extern struct sctp_base_info system_base_info;
@ -749,10 +730,10 @@ struct sctp_nets *sctp_findnet(struct sctp_tcb *, struct sockaddr *);
struct sctp_inpcb *sctp_pcb_findep(struct sockaddr *, int, int, uint32_t);
#if defined(__FreeBSD__) && __FreeBSD_version >= 500000
#if defined(__FreeBSD__) && !defined(__Userspace__)
int sctp_inpcb_bind(struct socket *, struct sockaddr *,
struct sctp_ifa *,struct thread *);
#elif defined(__Windows__)
#elif defined(_WIN32) && !defined(__Userspace__)
int sctp_inpcb_bind(struct socket *, struct sockaddr *,
struct sctp_ifa *,PKTHREAD);
#else
@ -803,19 +784,24 @@ int sctp_is_address_on_local_host(struct sockaddr *addr, uint32_t vrf_id);
void sctp_inpcb_free(struct sctp_inpcb *, int, int);
#if defined(__FreeBSD__) && __FreeBSD_version >= 500000
#define SCTP_DONT_INITIALIZE_AUTH_PARAMS 0
#define SCTP_INITIALIZE_AUTH_PARAMS 1
#if defined(__FreeBSD__) && !defined(__Userspace__)
struct sctp_tcb *
sctp_aloc_assoc(struct sctp_inpcb *, struct sockaddr *,
int *, uint32_t, uint32_t, uint16_t, uint16_t, struct thread *);
#elif defined(__Windows__)
int *, uint32_t, uint32_t, uint16_t, uint16_t, struct thread *,
int);
#elif defined(_WIN32) && !defined(__Userspace__)
struct sctp_tcb *
sctp_aloc_assoc(struct sctp_inpcb *, struct sockaddr *,
int *, uint32_t, uint32_t, uint16_t, uint16_t, PKTHREAD);
int *, uint32_t, uint32_t, uint16_t, uint16_t, PKTHREAD, int);
#else
/* proc will be NULL for __Userspace__ */
struct sctp_tcb *
sctp_aloc_assoc(struct sctp_inpcb *, struct sockaddr *,
int *, uint32_t, uint32_t, uint16_t, uint16_t, struct proc *);
int *, uint32_t, uint32_t, uint16_t, uint16_t, struct proc *,
int);
#endif
int sctp_free_assoc(struct sctp_inpcb *, struct sctp_tcb *, int, int);
@ -838,7 +824,11 @@ void sctp_remove_net(struct sctp_tcb *, struct sctp_nets *);
int sctp_del_remote_addr(struct sctp_tcb *, struct sockaddr *);
#if defined(__Userspace__)
void sctp_pcb_init(int);
#else
void sctp_pcb_init(void);
#endif
void sctp_pcb_finish(void);
@ -877,10 +867,12 @@ sctp_initiate_iterator(inp_func inpf,
end_func ef,
struct sctp_inpcb *,
uint8_t co_off);
#if defined(__FreeBSD__) && defined(SCTP_MCORE_INPUT) && defined(SMP)
#if defined(__FreeBSD__) && !defined(__Userspace__)
#if defined(SCTP_MCORE_INPUT) && defined(SMP)
void
sctp_queue_to_mcore(struct mbuf *m, int off, int cpu_to_use);
#endif
#endif
#endif /* _KERNEL */

View File

@ -32,9 +32,9 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_peeloff.c 279859 2015-03-10 19:49:25Z tuexen $");
__FBSDID("$FreeBSD: head/sys/netinet/sctp_peeloff.c 362054 2020-06-11 13:34:09Z tuexen $");
#endif
#include <netinet/sctp_os.h>
@ -49,10 +49,6 @@ __FBSDID("$FreeBSD: head/sys/netinet/sctp_peeloff.c 279859 2015-03-10 19:49:25Z
#include <netinet/sctputil.h>
#include <netinet/sctp_auth.h>
#if defined(__APPLE__)
#define APPLE_FILE_NO 5
#endif
int
sctp_can_peel_off(struct socket *head, sctp_assoc_t assoc_id)
{
@ -79,7 +75,7 @@ sctp_can_peel_off(struct socket *head, sctp_assoc_t assoc_id)
SCTP_LTRACE_ERR_RET(inp, stcb, NULL, SCTP_FROM_SCTP_PEELOFF, ENOENT);
return (ENOENT);
}
state = SCTP_GET_STATE((&stcb->asoc));
state = SCTP_GET_STATE(stcb);
if ((state == SCTP_STATE_EMPTY) ||
(state == SCTP_STATE_INUSE)) {
SCTP_TCB_UNLOCK(stcb);
@ -109,7 +105,7 @@ sctp_do_peeloff(struct socket *head, struct socket *so, sctp_assoc_t assoc_id)
return (ENOTCONN);
}
state = SCTP_GET_STATE((&stcb->asoc));
state = SCTP_GET_STATE(stcb);
if ((state == SCTP_STATE_EMPTY) ||
(state == SCTP_STATE_INUSE)) {
SCTP_TCB_UNLOCK(stcb);
@ -164,7 +160,7 @@ sctp_do_peeloff(struct socket *head, struct socket *so, sctp_assoc_t assoc_id)
atomic_add_int(&stcb->asoc.refcnt, 1);
SCTP_TCB_UNLOCK(stcb);
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
sctp_pull_off_control_to_new_inp(inp, n_inp, stcb, SBL_WAIT);
#else
sctp_pull_off_control_to_new_inp(inp, n_inp, stcb, M_WAITOK);
@ -178,14 +174,6 @@ sctp_do_peeloff(struct socket *head, struct socket *so, sctp_assoc_t assoc_id)
struct socket *
sctp_get_peeloff(struct socket *head, sctp_assoc_t assoc_id, int *error)
{
#if defined(__Userspace__)
/* if __Userspace__ chooses to originally not support peeloff, put it here... */
#endif
#if defined(__Panda__)
SCTP_LTRACE_ERR_RET(NULL, NULL, NULL, SCTP_FROM_SCTP_PEELOFF, EINVAL);
*error = EINVAL;
return (NULL);
#else
struct socket *newso;
struct sctp_inpcb *inp, *n_inp;
struct sctp_tcb *stcb;
@ -205,18 +193,15 @@ sctp_get_peeloff(struct socket *head, sctp_assoc_t assoc_id, int *error)
}
atomic_add_int(&stcb->asoc.refcnt, 1);
SCTP_TCB_UNLOCK(stcb);
#if defined(__FreeBSD__) && __FreeBSD_version >= 801000
#if defined(__FreeBSD__) && !defined(__Userspace__)
CURVNET_SET(head->so_vnet);
#endif
newso = sonewconn(head, SS_ISCONNECTED
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
, NULL
#elif defined(__Panda__)
/* place this socket in the assoc's vrf id */
, NULL, stcb->asoc.vrf_id
#endif
);
#if defined(__FreeBSD__) && __FreeBSD_version >= 801000
#if defined(__FreeBSD__) && !defined(__Userspace__)
CURVNET_RESTORE();
#endif
if (newso == NULL) {
@ -227,7 +212,7 @@ sctp_get_peeloff(struct socket *head, sctp_assoc_t assoc_id, int *error)
return (NULL);
}
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
else {
SCTP_SOCKET_LOCK(newso, 1);
}
@ -288,7 +273,6 @@ sctp_get_peeloff(struct socket *head, sctp_assoc_t assoc_id, int *error)
SOCK_UNLOCK(newso);
/* We remove it right away */
#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__) || defined(__Userspace__)
#ifdef SCTP_LOCK_LOGGING
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) {
sctp_log_lock(inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_SOCK);
@ -297,16 +281,6 @@ sctp_get_peeloff(struct socket *head, sctp_assoc_t assoc_id, int *error)
TAILQ_REMOVE(&head->so_comp, newso, so_list);
head->so_qlen--;
SOCK_UNLOCK(head);
#else
newso = TAILQ_FIRST(&head->so_q);
if (soqremque(newso, 1) == 0) {
SCTP_PRINTF("soremque failed, peeloff-fails (invarients would panic)\n");
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP_PEELOFF, ENOTCONN);
*error = ENOTCONN;
return (NULL);
}
#endif
/*
* Now we must move it from one hash table to another and get the
* stcb in the right place.
@ -318,13 +292,12 @@ sctp_get_peeloff(struct socket *head, sctp_assoc_t assoc_id, int *error)
* And now the final hack. We move data in the pending side i.e.
* head to the new socket buffer. Let the GRUBBING begin :-0
*/
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
sctp_pull_off_control_to_new_inp(inp, n_inp, stcb, SBL_WAIT);
#else
sctp_pull_off_control_to_new_inp(inp, n_inp, stcb, M_WAITOK);
#endif
atomic_subtract_int(&stcb->asoc.refcnt, 1);
return (newso);
#endif
}
#endif

View File

@ -32,7 +32,7 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_peeloff.h 309607 2016-12-06 10:21:25Z tuexen $");
#endif
@ -42,13 +42,13 @@ __FBSDID("$FreeBSD: head/sys/netinet/sctp_peeloff.h 309607 2016-12-06 10:21:25Z
#if defined(HAVE_SCTP_PEELOFF_SOCKOPT)
/* socket option peeloff */
struct sctp_peeloff_opt {
#if !defined(__Windows__)
#if !(defined(_WIN32) && !defined(__Userspace__))
int s;
#else
HANDLE s;
#endif
sctp_assoc_t assoc_id;
#if !defined(__Windows__)
#if !(defined(_WIN32) && !defined(__Userspace__))
int new_sd;
#else
HANDLE new_sd;

View File

@ -53,7 +53,7 @@
* per socket level locking
*/
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
/* Lock for INFO stuff */
#define SCTP_INP_INFO_LOCK_INIT()
#define SCTP_INP_INFO_RLOCK()
@ -86,7 +86,9 @@
#define SCTP_INP_RLOCK(_inp)
#define SCTP_INP_RUNLOCK(_inp)
#define SCTP_INP_WLOCK(_inp)
#define SCTP_INP_WUNLOCK(_inep)
#define SCTP_INP_WUNLOCK(_inp)
#define SCTP_INP_RLOCK_ASSERT(_inp)
#define SCTP_INP_WLOCK_ASSERT(_inp)
#define SCTP_INP_INCR_REF(_inp)
#define SCTP_INP_DECR_REF(_inp)
@ -115,7 +117,7 @@
*/
#define SCTP_IPI_COUNT_INIT()
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
#define SCTP_WQ_ADDR_INIT() \
InitializeCriticalSection(&SCTP_BASE_INFO(wq_addr_mtx))
#define SCTP_WQ_ADDR_DESTROY() \
@ -124,7 +126,7 @@
EnterCriticalSection(&SCTP_BASE_INFO(wq_addr_mtx))
#define SCTP_WQ_ADDR_UNLOCK() \
LeaveCriticalSection(&SCTP_BASE_INFO(wq_addr_mtx))
#define SCTP_WQ_ADDR_LOCK_ASSERT()
#define SCTP_INP_INFO_LOCK_INIT() \
InitializeCriticalSection(&SCTP_BASE_INFO(ipi_ep_mtx))
@ -185,6 +187,8 @@
#define SCTP_INP_WLOCK(_inp) \
EnterCriticalSection(&(_inp)->inp_mtx)
#endif
#define SCTP_INP_RLOCK_ASSERT(_tcb)
#define SCTP_INP_WLOCK_ASSERT(_tcb)
#define SCTP_TCB_SEND_LOCK_INIT(_tcb) \
InitializeCriticalSection(&(_tcb)->tcb_send_mtx)
@ -263,6 +267,8 @@
#define SCTP_WQ_ADDR_UNLOCK() \
(void)pthread_mutex_unlock(&SCTP_BASE_INFO(wq_addr_mtx))
#endif
#define SCTP_WQ_ADDR_LOCK_ASSERT() \
KASSERT(pthread_mutex_trylock(&SCTP_BASE_INFO(wq_addr_mtx)) == EBUSY, ("%s: wq_addr_mtx not locked", __func__))
#define SCTP_INP_INFO_LOCK_INIT() \
(void)pthread_mutex_init(&SCTP_BASE_INFO(ipi_ep_mtx), &SCTP_BASE_VAR(mtx_attr))
@ -377,6 +383,10 @@
#define SCTP_INP_WUNLOCK(_inp) \
(void)pthread_mutex_unlock(&(_inp)->inp_mtx)
#endif
#define SCTP_INP_RLOCK_ASSERT(_inp) \
KASSERT(pthread_mutex_trylock(&(_inp)->inp_mtx) == EBUSY, ("%s: inp_mtx not locked", __func__))
#define SCTP_INP_WLOCK_ASSERT(_inp) \
KASSERT(pthread_mutex_trylock(&(_inp)->inp_mtx) == EBUSY, ("%s: inp_mtx not locked", __func__))
#define SCTP_INP_INCR_REF(_inp) atomic_add_int(&((_inp)->refcount), 1)
#define SCTP_INP_DECR_REF(_inp) atomic_add_int(&((_inp)->refcount), -1)
@ -484,7 +494,7 @@
/* socket locks */
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
#define SOCKBUF_LOCK_ASSERT(_so_buf)
#define SOCKBUF_LOCK(_so_buf) \
EnterCriticalSection(&(_so_buf)->sb_mtx)
@ -519,7 +529,7 @@
#define SCTP_STATLOG_UNLOCK()
#define SCTP_STATLOG_DESTROY()
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
/* address list locks */
#define SCTP_IPI_ADDR_INIT() \
InitializeCriticalSection(&SCTP_BASE_INFO(ipi_addr_mtx))
@ -554,7 +564,7 @@
#define SCTP_IPI_ITERATOR_WQ_UNLOCK() \
LeaveCriticalSection(&sctp_it_ctl.ipi_iterator_wq_mtx)
#else /* end of __Userspace_os_Windows */
#else
/* address list locks */
#define SCTP_IPI_ADDR_INIT() \
(void)pthread_mutex_init(&SCTP_BASE_INFO(ipi_addr_mtx), &SCTP_BASE_VAR(mtx_attr))

View File

@ -84,9 +84,9 @@ sctp_sha1_final(unsigned char *digest, struct sctp_sha1_context *ctx)
#else
#include <string.h>
#if defined(__Userspace_os_Windows)
#if defined(_WIN32) && defined(__Userspace__)
#include <winsock2.h>
#elif !defined(__Windows__)
#elif !(defined(_WIN32) && !defined(__Userspace__))
#include <arpa/inet.h>
#endif

View File

@ -32,7 +32,7 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#endif
@ -43,16 +43,7 @@ __FBSDID("$FreeBSD$");
#include <sys/types.h>
#if defined(SCTP_USE_NSS_SHA1)
#if defined(__Userspace_os_Darwin)
/* The NSS sources require __APPLE__ to be defined.
* XXX: Remove this ugly hack once the platform defines have been cleaned up.
*/
#define __APPLE__
#endif
#include <pk11pub.h>
#if defined(__Userspace_os_Darwin)
#undef __APPLE__
#endif
#elif defined(SCTP_USE_OPENSSL_SHA1)
#include <openssl/sha.h>
#endif
@ -83,7 +74,7 @@ struct sctp_sha1_context {
#endif
};
#if (defined(__APPLE__) && defined(KERNEL))
#if (defined(__APPLE__) && !defined(__Userspace__) && defined(KERNEL))
#ifndef _KERNEL
#define _KERNEL
#endif

View File

@ -28,9 +28,9 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_ss_functions.c 345505 2019-03-25 16:40:54Z tuexen $");
__FBSDID("$FreeBSD: head/sys/netinet/sctp_ss_functions.c 362173 2020-06-14 09:50:00Z tuexen $");
#endif
#include <netinet/sctp_pcb.h>
@ -59,6 +59,9 @@ sctp_ss_default_init(struct sctp_tcb *stcb, struct sctp_association *asoc,
{
uint16_t i;
if (holds_lock == 0) {
SCTP_TCB_SEND_LOCK(stcb);
}
asoc->ss_data.locked_on_sending = NULL;
asoc->ss_data.last_out_stream = NULL;
TAILQ_INIT(&asoc->ss_data.out.wheel);
@ -71,7 +74,10 @@ sctp_ss_default_init(struct sctp_tcb *stcb, struct sctp_association *asoc,
for (i = 0; i < stcb->asoc.streamoutcnt; i++) {
stcb->asoc.ss_functions.sctp_ss_add_to_stream(stcb, &stcb->asoc,
&stcb->asoc.strmout[i],
NULL, holds_lock);
NULL, 1);
}
if (holds_lock == 0) {
SCTP_TCB_SEND_UNLOCK(stcb);
}
return;
}
@ -84,8 +90,10 @@ sctp_ss_default_clear(struct sctp_tcb *stcb, struct sctp_association *asoc,
SCTP_TCB_SEND_LOCK(stcb);
}
while (!TAILQ_EMPTY(&asoc->ss_data.out.wheel)) {
struct sctp_stream_out *strq = TAILQ_FIRST(&asoc->ss_data.out.wheel);
TAILQ_REMOVE(&asoc->ss_data.out.wheel, TAILQ_FIRST(&asoc->ss_data.out.wheel), ss_params.rr.next_spoke);
struct sctp_stream_out *strq;
strq = TAILQ_FIRST(&asoc->ss_data.out.wheel);
TAILQ_REMOVE(&asoc->ss_data.out.wheel, strq, ss_params.rr.next_spoke);
strq->ss_params.rr.next_spoke.tqe_next = NULL;
strq->ss_params.rr.next_spoke.tqe_prev = NULL;
}
@ -401,11 +409,13 @@ sctp_ss_prio_clear(struct sctp_tcb *stcb, struct sctp_association *asoc,
SCTP_TCB_SEND_LOCK(stcb);
}
while (!TAILQ_EMPTY(&asoc->ss_data.out.wheel)) {
struct sctp_stream_out *strq = TAILQ_FIRST(&asoc->ss_data.out.wheel);
struct sctp_stream_out *strq;
strq = TAILQ_FIRST(&asoc->ss_data.out.wheel);
if (clear_values) {
strq->ss_params.prio.priority = 0;
}
TAILQ_REMOVE(&asoc->ss_data.out.wheel, TAILQ_FIRST(&asoc->ss_data.out.wheel), ss_params.prio.next_spoke);
TAILQ_REMOVE(&asoc->ss_data.out.wheel, strq, ss_params.prio.next_spoke);
strq->ss_params.prio.next_spoke.tqe_next = NULL;
strq->ss_params.prio.next_spoke.tqe_prev = NULL;
@ -511,6 +521,9 @@ sctp_ss_prio_select(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net,
{
struct sctp_stream_out *strq, *strqt, *strqn;
if (asoc->ss_data.locked_on_sending) {
return (asoc->ss_data.locked_on_sending);
}
strqt = asoc->ss_data.last_out_stream;
prio_again:
/* Find the next stream to use */
@ -589,11 +602,13 @@ sctp_ss_fb_clear(struct sctp_tcb *stcb, struct sctp_association *asoc,
SCTP_TCB_SEND_LOCK(stcb);
}
while (!TAILQ_EMPTY(&asoc->ss_data.out.wheel)) {
struct sctp_stream_out *strq = TAILQ_FIRST(&asoc->ss_data.out.wheel);
struct sctp_stream_out *strq;
strq = TAILQ_FIRST(&asoc->ss_data.out.wheel);
if (clear_values) {
strq->ss_params.fb.rounds = -1;
}
TAILQ_REMOVE(&asoc->ss_data.out.wheel, TAILQ_FIRST(&asoc->ss_data.out.wheel), ss_params.fb.next_spoke);
TAILQ_REMOVE(&asoc->ss_data.out.wheel, strq, ss_params.fb.next_spoke);
strq->ss_params.fb.next_spoke.tqe_next = NULL;
strq->ss_params.fb.next_spoke.tqe_prev = NULL;
}
@ -685,6 +700,9 @@ sctp_ss_fb_select(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net,
{
struct sctp_stream_out *strq = NULL, *strqt;
if (asoc->ss_data.locked_on_sending) {
return (asoc->ss_data.locked_on_sending);
}
if (asoc->ss_data.last_out_stream == NULL ||
TAILQ_FIRST(&asoc->ss_data.out.wheel) == TAILQ_LAST(&asoc->ss_data.out.wheel, sctpwheel_listhead)) {
strqt = TAILQ_FIRST(&asoc->ss_data.out.wheel);
@ -752,8 +770,8 @@ sctp_ss_fb_scheduled(struct sctp_tcb *stcb, struct sctp_nets *net SCTP_UNUSED,
*/
static void
sctp_ss_fcfs_add(struct sctp_tcb *stcb, struct sctp_association *asoc,
struct sctp_stream_out *strq, struct sctp_stream_queue_pending *sp,
int holds_lock);
struct sctp_stream_out *strq SCTP_UNUSED,
struct sctp_stream_queue_pending *sp, int holds_lock);
static void
sctp_ss_fcfs_init(struct sctp_tcb *stcb, struct sctp_association *asoc,
@ -763,6 +781,9 @@ sctp_ss_fcfs_init(struct sctp_tcb *stcb, struct sctp_association *asoc,
struct sctp_stream_queue_pending *sp;
uint16_t i;
if (holds_lock == 0) {
SCTP_TCB_SEND_LOCK(stcb);
}
TAILQ_INIT(&asoc->ss_data.out.list);
/*
* If there is data in the stream queues already,
@ -782,12 +803,15 @@ sctp_ss_fcfs_init(struct sctp_tcb *stcb, struct sctp_association *asoc,
x++;
}
if (sp != NULL) {
sctp_ss_fcfs_add(stcb, &stcb->asoc, &stcb->asoc.strmout[i], sp, holds_lock);
sctp_ss_fcfs_add(stcb, &stcb->asoc, &stcb->asoc.strmout[i], sp, 1);
add_more = 1;
}
}
n++;
}
if (holds_lock == 0) {
SCTP_TCB_SEND_UNLOCK(stcb);
}
return;
}
@ -795,12 +819,17 @@ static void
sctp_ss_fcfs_clear(struct sctp_tcb *stcb, struct sctp_association *asoc,
int clear_values, int holds_lock)
{
struct sctp_stream_queue_pending *sp;
if (clear_values) {
if (holds_lock == 0) {
SCTP_TCB_SEND_LOCK(stcb);
}
while (!TAILQ_EMPTY(&asoc->ss_data.out.list)) {
TAILQ_REMOVE(&asoc->ss_data.out.list, TAILQ_FIRST(&asoc->ss_data.out.list), ss_next);
sp = TAILQ_FIRST(&asoc->ss_data.out.list);
TAILQ_REMOVE(&asoc->ss_data.out.list, sp, ss_next);
sp->ss_next.tqe_next = NULL;
sp->ss_next.tqe_prev = NULL;
}
if (holds_lock == 0) {
SCTP_TCB_SEND_UNLOCK(stcb);
@ -865,6 +894,8 @@ sctp_ss_fcfs_remove(struct sctp_tcb *stcb, struct sctp_association *asoc,
((sp->ss_next.tqe_next != NULL) ||
(sp->ss_next.tqe_prev != NULL))) {
TAILQ_REMOVE(&asoc->ss_data.out.list, sp, ss_next);
sp->ss_next.tqe_next = NULL;
sp->ss_next.tqe_prev = NULL;
}
if (holds_lock == 0) {
SCTP_TCB_SEND_UNLOCK(stcb);
@ -880,6 +911,9 @@ sctp_ss_fcfs_select(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_nets *net,
struct sctp_stream_out *strq;
struct sctp_stream_queue_pending *sp;
if (asoc->ss_data.locked_on_sending) {
return (asoc->ss_data.locked_on_sending);
}
sp = TAILQ_FIRST(&asoc->ss_data.out.list);
default_again:
if (sp != NULL) {
@ -915,7 +949,7 @@ default_again:
const struct sctp_ss_functions sctp_ss_functions[] = {
/* SCTP_SS_DEFAULT */
{
#if defined(__Windows__) || defined(__Userspace_os_Windows)
#if defined(_WIN32)
sctp_ss_default_init,
sctp_ss_default_clear,
sctp_ss_default_init_stream,
@ -945,7 +979,7 @@ const struct sctp_ss_functions sctp_ss_functions[] = {
},
/* SCTP_SS_ROUND_ROBIN */
{
#if defined(__Windows__) || defined(__Userspace_os_Windows)
#if defined(_WIN32)
sctp_ss_default_init,
sctp_ss_default_clear,
sctp_ss_default_init_stream,
@ -975,7 +1009,7 @@ const struct sctp_ss_functions sctp_ss_functions[] = {
},
/* SCTP_SS_ROUND_ROBIN_PACKET */
{
#if defined(__Windows__) || defined(__Userspace_os_Windows)
#if defined(_WIN32)
sctp_ss_default_init,
sctp_ss_default_clear,
sctp_ss_default_init_stream,
@ -1005,7 +1039,7 @@ const struct sctp_ss_functions sctp_ss_functions[] = {
},
/* SCTP_SS_PRIORITY */
{
#if defined(__Windows__) || defined(__Userspace_os_Windows)
#if defined(_WIN32)
sctp_ss_default_init,
sctp_ss_prio_clear,
sctp_ss_prio_init_stream,
@ -1035,7 +1069,7 @@ const struct sctp_ss_functions sctp_ss_functions[] = {
},
/* SCTP_SS_FAIR_BANDWITH */
{
#if defined(__Windows__) || defined(__Userspace_os_Windows)
#if defined(_WIN32)
sctp_ss_default_init,
sctp_ss_fb_clear,
sctp_ss_fb_init_stream,
@ -1065,7 +1099,7 @@ const struct sctp_ss_functions sctp_ss_functions[] = {
},
/* SCTP_SS_FIRST_COME */
{
#if defined(__Windows__) || defined(__Userspace_os_Windows)
#if defined(_WIN32)
sctp_ss_fcfs_init,
sctp_ss_fcfs_clear,
sctp_ss_fcfs_init_stream,

View File

@ -32,9 +32,9 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_structs.h 325370 2017-11-03 20:46:12Z tuexen $");
__FBSDID("$FreeBSD: head/sys/netinet/sctp_structs.h 362106 2020-06-12 16:31:13Z tuexen $");
#endif
#ifndef _NETINET_SCTP_STRUCTS_H_
@ -55,7 +55,7 @@ struct sctp_timer {
void *ep;
void *tcb;
void *net;
#if defined(__FreeBSD__) && __FreeBSD_version >= 800000
#if defined(__FreeBSD__) && !defined(__Userspace__)
void *vnet;
#endif
@ -113,13 +113,12 @@ typedef void (*asoc_func) (struct sctp_inpcb *, struct sctp_tcb *, void *ptr,
typedef int (*inp_func) (struct sctp_inpcb *, void *ptr, uint32_t val);
typedef void (*end_func) (void *ptr, uint32_t val);
#if defined(__FreeBSD__) && defined(SCTP_MCORE_INPUT) && defined(SMP)
#if defined(__FreeBSD__) && !defined(__Userspace__)
#if defined(SCTP_MCORE_INPUT) && defined(SMP)
/* whats on the mcore control struct */
struct sctp_mcore_queue {
TAILQ_ENTRY(sctp_mcore_queue) next;
#if defined(__FreeBSD__) && __FreeBSD_version >= 801000
struct vnet *vn;
#endif
struct mbuf *m;
int off;
int v6;
@ -135,14 +134,12 @@ struct sctp_mcore_ctrl {
int running;
int cpuid;
};
#endif
#endif
struct sctp_iterator {
TAILQ_ENTRY(sctp_iterator) sctp_nxt_itr;
#if defined(__FreeBSD__) && __FreeBSD_version >= 801000
#if defined(__FreeBSD__) && !defined(__Userspace__)
struct vnet *vn;
#endif
struct sctp_timer tmr;
@ -173,7 +170,7 @@ struct sctp_copy_all {
struct sctp_inpcb *inp; /* ep */
struct mbuf *m;
struct sctp_sndrcvinfo sndrcv;
int sndlen;
ssize_t sndlen;
int cnt_sent;
int cnt_failed;
};
@ -184,10 +181,10 @@ struct sctp_asconf_iterator {
};
struct iterator_control {
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
struct mtx ipi_iterator_wq_mtx;
struct mtx it_mtx;
#elif defined(__APPLE__)
#elif defined(__APPLE__) && !defined(__Userspace__)
lck_mtx_t *ipi_iterator_wq_mtx;
lck_mtx_t *it_mtx;
#elif defined(SCTP_PROCESS_LEVEL_LOCKS)
@ -200,7 +197,7 @@ struct iterator_control {
pthread_mutex_t it_mtx;
pthread_cond_t iterator_wakeup;
#endif
#elif defined(__Windows__)
#elif defined(_WIN32) && !defined(__Userspace__)
struct spinlock it_lock;
struct spinlock ipi_iterator_wq_lock;
KEVENT iterator_wakeup[2];
@ -208,7 +205,7 @@ struct iterator_control {
#else
void *it_mtx;
#endif
#if !defined(__Windows__)
#if !(defined(_WIN32) && !defined(__Userspace__))
#if !defined(__Userspace__)
SCTP_PROCESS_STRUCT thread_proc;
#else
@ -220,7 +217,7 @@ struct iterator_control {
uint32_t iterator_running;
uint32_t iterator_flags;
};
#if !defined(__FreeBSD__)
#if !(defined(__FreeBSD__) && !defined(__Userspace__))
#define SCTP_ITERATOR_MUST_EXIT 0x00000001
#define SCTP_ITERATOR_EXITED 0x00000002
#endif
@ -228,28 +225,21 @@ struct iterator_control {
#define SCTP_ITERATOR_STOP_CUR_INP 0x00000008
struct sctp_net_route {
sctp_rtentry_t *ro_rt;
#if defined(__FreeBSD__)
#if __FreeBSD_version < 1100093
#if __FreeBSD_version >= 800000
void *ro_lle;
#endif
#if __FreeBSD_version >= 900000
void *ro_ia;
int ro_flags;
#endif
#else
#if __FreeBSD_version >= 1100116
#if defined(__FreeBSD__) && !defined(__Userspace__)
struct nhop_object *ro_nh;
struct llentry *ro_lle;
#endif
char *ro_prepend;
uint16_t ro_plen;
uint16_t ro_flags;
uint16_t ro_mtu;
uint16_t spare;
#else
sctp_rtentry_t *ro_rt;
#endif
#if defined(__APPLE__) && !defined(__Userspace__)
#if !defined(APPLE_LEOPARD) && !defined(APPLE_SNOWLEOPARD) && !defined(APPLE_LION) && !defined(APPLE_MOUNTAINLION) && !defined(APPLE_ELCAPITAN)
struct llentry *ro_lle;
#endif
#if defined(__APPLE__)
#if !defined(APPLE_LEOPARD) && !defined(APPLE_SNOWLEOPARD) && !defined(APPLE_LION) && !defined(APPLE_MOUNTAINLION)
struct ifaddr *ro_srcia;
#endif
@ -331,7 +321,7 @@ struct sctp_nets {
int lastsa;
int lastsv;
uint64_t rtt; /* last measured rtt value in us */
unsigned int RTO;
uint32_t RTO;
/* This is used for SHUTDOWN/SHUTDOWN-ACK/SEND or INIT timers */
struct sctp_timer rxt_timer;
@ -440,7 +430,7 @@ struct sctp_nets {
uint8_t last_hs_used; /* index into the last HS table entry we used */
uint8_t lan_type;
uint8_t rto_needed;
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
uint32_t flowid;
uint8_t flowtype;
#endif
@ -865,7 +855,6 @@ struct sctp_association {
struct sctp_timer strreset_timer; /* stream reset */
struct sctp_timer shut_guard_timer; /* shutdown guard */
struct sctp_timer autoclose_timer; /* automatic close timer */
struct sctp_timer delayed_event_timer; /* timer for delayed events */
struct sctp_timer delete_prim_timer; /* deleting primary dst */
/* list of restricted local addresses */
@ -1119,7 +1108,7 @@ struct sctp_association {
uint32_t heart_beat_delay;
/* autoclose */
unsigned int sctp_autoclose_ticks;
uint32_t sctp_autoclose_ticks;
/* how many preopen streams we have */
unsigned int pre_open_streams;
@ -1128,7 +1117,7 @@ struct sctp_association {
unsigned int max_inbound_streams;
/* the cookie life I award for any cookie, in seconds */
unsigned int cookie_life;
uint32_t cookie_life;
/* time to delay acks for */
unsigned int delayed_ack;
unsigned int old_delayed_ack;
@ -1137,10 +1126,10 @@ struct sctp_association {
unsigned int numduptsns;
int dup_tsns[SCTP_MAX_DUP_TSNS];
unsigned int initial_init_rto_max; /* initial RTO for INIT's */
unsigned int initial_rto; /* initial send RTO */
unsigned int minrto; /* per assoc RTO-MIN */
unsigned int maxrto; /* per assoc RTO-MAX */
uint32_t initial_init_rto_max; /* initial RTO for INIT's */
uint32_t initial_rto; /* initial send RTO */
uint32_t minrto; /* per assoc RTO-MIN */
uint32_t maxrto; /* per assoc RTO-MAX */
/* authentication fields */
sctp_auth_chklist_t *local_auth_chunks;

View File

@ -32,9 +32,9 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_sysctl.c 323505 2017-09-12 21:08:50Z tuexen $");
__FBSDID("$FreeBSD: head/sys/netinet/sctp_sysctl.c 361934 2020-06-08 20:23:20Z tuexen $");
#endif
#include <netinet/sctp_os.h>
@ -44,15 +44,15 @@ __FBSDID("$FreeBSD: head/sys/netinet/sctp_sysctl.c 323505 2017-09-12 21:08:50Z t
#include <netinet/sctp_pcb.h>
#include <netinet/sctputil.h>
#include <netinet/sctp_output.h>
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/smp.h>
#include <sys/sysctl.h>
#endif
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
#include <netinet/sctp_bsd_addr.h>
#endif
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
FEATURE(sctp, "Stream Control Transmission Protocol");
#endif
@ -74,19 +74,35 @@ sctp_init_sysctls()
SCTP_BASE_SYSCTL(sctp_reconfig_enable) = SCTPCTL_RECONFIG_ENABLE_DEFAULT;
SCTP_BASE_SYSCTL(sctp_nrsack_enable) = SCTPCTL_NRSACK_ENABLE_DEFAULT;
SCTP_BASE_SYSCTL(sctp_pktdrop_enable) = SCTPCTL_PKTDROP_ENABLE_DEFAULT;
#if !(defined(__FreeBSD__) && __FreeBSD_version >= 800000)
#if !defined(SCTP_WITH_NO_CSUM)
#if !(defined(__FreeBSD__) && !defined(__Userspace__))
SCTP_BASE_SYSCTL(sctp_no_csum_on_loopback) = SCTPCTL_LOOPBACK_NOCSUM_DEFAULT;
#endif
#endif
SCTP_BASE_SYSCTL(sctp_peer_chunk_oh) = SCTPCTL_PEER_CHKOH_DEFAULT;
SCTP_BASE_SYSCTL(sctp_max_burst_default) = SCTPCTL_MAXBURST_DEFAULT;
SCTP_BASE_SYSCTL(sctp_fr_max_burst_default) = SCTPCTL_FRMAXBURST_DEFAULT;
SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue) = SCTPCTL_MAXCHUNKS_DEFAULT;
#if defined(__Userspace__)
if (SCTP_BASE_SYSCTL(sctp_hashtblsize) == 0) {
SCTP_BASE_SYSCTL(sctp_hashtblsize) = SCTPCTL_TCBHASHSIZE_DEFAULT;
}
#else
SCTP_BASE_SYSCTL(sctp_hashtblsize) = SCTPCTL_TCBHASHSIZE_DEFAULT;
#endif
#if defined(__Userspace__)
if (SCTP_BASE_SYSCTL(sctp_pcbtblsize) == 0) {
SCTP_BASE_SYSCTL(sctp_pcbtblsize) = SCTPCTL_PCBHASHSIZE_DEFAULT;
}
#else
SCTP_BASE_SYSCTL(sctp_pcbtblsize) = SCTPCTL_PCBHASHSIZE_DEFAULT;
#endif
SCTP_BASE_SYSCTL(sctp_min_split_point) = SCTPCTL_MIN_SPLIT_POINT_DEFAULT;
#if defined(__Userspace__)
if (SCTP_BASE_SYSCTL(sctp_chunkscale) == 0) {
SCTP_BASE_SYSCTL(sctp_chunkscale) = SCTPCTL_CHUNKSCALE_DEFAULT;
}
#else
SCTP_BASE_SYSCTL(sctp_chunkscale) = SCTPCTL_CHUNKSCALE_DEFAULT;
#endif
SCTP_BASE_SYSCTL(sctp_delayed_sack_time_default) = SCTPCTL_DELAYED_SACK_TIME_DEFAULT;
SCTP_BASE_SYSCTL(sctp_sack_freq_default) = SCTPCTL_SACK_FREQ_DEFAULT;
SCTP_BASE_SYSCTL(sctp_system_free_resc_limit) = SCTPCTL_SYS_RESOURCE_DEFAULT;
@ -133,9 +149,10 @@ sctp_init_sysctls()
SCTP_BASE_SYSCTL(sctp_steady_step) = SCTPCTL_RTTVAR_STEADYS_DEFAULT;
SCTP_BASE_SYSCTL(sctp_use_dccc_ecn) = SCTPCTL_RTTVAR_DCCCECN_DEFAULT;
SCTP_BASE_SYSCTL(sctp_blackhole) = SCTPCTL_BLACKHOLE_DEFAULT;
SCTP_BASE_SYSCTL(sctp_sendall_limit) = SCTPCTL_SENDALL_LIMIT_DEFAULT;
SCTP_BASE_SYSCTL(sctp_diag_info_code) = SCTPCTL_DIAG_INFO_CODE_DEFAULT;
#if defined(SCTP_LOCAL_TRACE_BUF)
#if defined(__Windows__)
#if defined(_WIN32) && !defined(__Userspace__)
/* On Windows, the resource for global variables is limited. */
MALLOC(SCTP_BASE_SYSCTL(sctp_log), struct sctp_log *, sizeof(struct sctp_log), M_SYSCTL, M_ZERO);
#else
@ -148,18 +165,18 @@ sctp_init_sysctls()
#if defined(SCTP_DEBUG)
SCTP_BASE_SYSCTL(sctp_debug_on) = SCTPCTL_DEBUG_DEFAULT;
#endif
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
SCTP_BASE_SYSCTL(sctp_ignore_vmware_interfaces) = SCTPCTL_IGNORE_VMWARE_INTERFACES_DEFAULT;
SCTP_BASE_SYSCTL(sctp_main_timer) = SCTPCTL_MAIN_TIMER_DEFAULT;
SCTP_BASE_SYSCTL(sctp_addr_watchdog_limit) = SCTPCTL_ADDR_WATCHDOG_LIMIT_DEFAULT;
SCTP_BASE_SYSCTL(sctp_vtag_watchdog_limit) = SCTPCTL_VTAG_WATCHDOG_LIMIT_DEFAULT;
#endif
#if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
#if defined(__APPLE__) && !defined(__Userspace__)
SCTP_BASE_SYSCTL(sctp_output_unlocked) = SCTPCTL_OUTPUT_UNLOCKED_DEFAULT;
#endif
}
#if defined(__Windows__)
#if defined(_WIN32) && !defined(__Userspace__)
void
sctp_finish_sysctls()
{
@ -172,7 +189,7 @@ sctp_finish_sysctls()
}
#endif
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__Windows__)
#if !defined(__Userspace__)
/* It returns an upper limit. No filtering is done here */
static unsigned int
sctp_sysctl_number_of_addresses(struct sctp_inpcb *inp)
@ -312,7 +329,7 @@ sctp_sysctl_copy_out_local_addresses(struct sctp_inpcb *inp, struct sctp_tcb *st
sin = &sctp_ifa->address.sin;
if (sin->sin_addr.s_addr == 0)
continue;
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
if (prison_check_ip4(inp->ip_inp.inp.inp_cred,
&sin->sin_addr) != 0) {
continue;
@ -333,7 +350,7 @@ sctp_sysctl_copy_out_local_addresses(struct sctp_inpcb *inp, struct sctp_tcb *st
sin6 = &sctp_ifa->address.sin6;
if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr))
continue;
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
if (prison_check_ip6(inp->ip_inp.inp.inp_cred,
&sin6->sin6_addr) != 0) {
continue;
@ -411,7 +428,7 @@ sctp_sysctl_copy_out_local_addresses(struct sctp_inpcb *inp, struct sctp_tcb *st
/*
* sysctl functions
*/
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
static int
sctp_sysctl_handle_assoclist SYSCTL_HANDLER_ARGS
{
@ -441,7 +458,7 @@ sctp_sysctl_handle_assoclist(SYSCTL_HANDLER_ARGS)
number_of_remote_addresses = 0;
SCTP_INP_INFO_RLOCK();
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
if (req->oldptr == USER_ADDR_NULL) {
#else
if (req->oldptr == NULL) {
@ -466,14 +483,14 @@ sctp_sysctl_handle_assoclist(SYSCTL_HANDLER_ARGS)
(number_of_remote_addresses + number_of_associations) * sizeof(struct xsctp_raddr);
/* request some more memory than needed */
#if !defined(__Windows__)
#if !(defined(_WIN32) && !defined(__Userspace__))
req->oldidx = (n + n / 8);
#else
req->dataidx = (n + n / 8);
#endif
return (0);
}
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
if (req->newptr != USER_ADDR_NULL) {
#else
if (req->newptr != NULL) {
@ -482,6 +499,9 @@ sctp_sysctl_handle_assoclist(SYSCTL_HANDLER_ARGS)
SCTP_LTRACE_ERR_RET(NULL, NULL, NULL, SCTP_FROM_SCTP_SYSCTL, EPERM);
return (EPERM);
}
memset(&xinpcb, 0, sizeof(xinpcb));
memset(&xstcb, 0, sizeof(xstcb));
memset(&xraddr, 0, sizeof(xraddr));
LIST_FOREACH(inp, &SCTP_BASE_INFO(listhead), sctp_list) {
SCTP_INP_RLOCK(inp);
if (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_ALLGONE) {
@ -491,16 +511,14 @@ sctp_sysctl_handle_assoclist(SYSCTL_HANDLER_ARGS)
xinpcb.last = 0;
xinpcb.local_port = ntohs(inp->sctp_lport);
xinpcb.flags = inp->sctp_flags;
#if defined(__FreeBSD__) && __FreeBSD_version < 1000048
xinpcb.features = (uint32_t)inp->sctp_features;
#else
xinpcb.features = inp->sctp_features;
#endif
xinpcb.total_sends = inp->total_sends;
xinpcb.total_recvs = inp->total_recvs;
xinpcb.total_nospaces = inp->total_nospaces;
xinpcb.fragmentation_point = inp->sctp_frag_point;
#if !(defined(__FreeBSD__) && (__FreeBSD_version < 1001517))
#if defined(__FreeBSD__) && !defined(__Userspace__)
xinpcb.socket = (uintptr_t)inp->sctp_socket;
#else
xinpcb.socket = inp->sctp_socket;
#endif
so = inp->sctp_socket;
@ -510,33 +528,16 @@ sctp_sysctl_handle_assoclist(SYSCTL_HANDLER_ARGS)
xinpcb.qlen = 0;
xinpcb.maxqlen = 0;
} else {
#if defined(__FreeBSD__) && __FreeBSD_version >= 1200034
#if defined(__FreeBSD__) && !defined(__Userspace__)
xinpcb.qlen = so->sol_qlen;
#else
xinpcb.qlen = so->so_qlen;
#endif
#if defined(__FreeBSD__) && __FreeBSD_version > 1100096
#if __FreeBSD_version >= 1200034
xinpcb.qlen_old = so->sol_qlen > USHRT_MAX ?
USHRT_MAX : (uint16_t) so->sol_qlen;
#else
xinpcb.qlen_old = so->so_qlen > USHRT_MAX ?
USHRT_MAX : (uint16_t) so->so_qlen;
#endif
#endif
#if defined(__FreeBSD__) && __FreeBSD_version >= 1200034
xinpcb.maxqlen = so->sol_qlimit;
#else
xinpcb.maxqlen = so->so_qlimit;
#endif
#if defined(__FreeBSD__) && __FreeBSD_version > 1100096
#if __FreeBSD_version >= 1200034
xinpcb.maxqlen_old = so->sol_qlimit > USHRT_MAX ?
USHRT_MAX : (uint16_t) so->sol_qlimit;
#else
xinpcb.maxqlen_old = so->so_qlimit > USHRT_MAX ?
USHRT_MAX : (uint16_t) so->so_qlimit;
#endif
xinpcb.qlen = so->so_qlen;
xinpcb.maxqlen = so->so_qlimit;
#endif
}
SCTP_INP_INCR_REF(inp);
@ -565,16 +566,8 @@ sctp_sysctl_handle_assoclist(SYSCTL_HANDLER_ARGS)
xstcb.primary_addr = stcb->asoc.primary_destination->ro._l_addr;
xstcb.heartbeat_interval = stcb->asoc.heart_beat_delay;
xstcb.state = (uint32_t)sctp_map_assoc_state(stcb->asoc.state);
#if defined(__FreeBSD__)
#if __FreeBSD_version >= 800000
/* 7.0 does not support these */
xstcb.assoc_id = sctp_get_associd(stcb);
xstcb.peers_rwnd = stcb->asoc.peers_rwnd;
#endif
#else
xstcb.assoc_id = sctp_get_associd(stcb);
xstcb.peers_rwnd = stcb->asoc.peers_rwnd;
#endif
xstcb.in_streams = stcb->asoc.streamincnt;
xstcb.out_streams = stcb->asoc.streamoutcnt;
xstcb.max_nr_retrans = stcb->asoc.overall_error_count;
@ -626,8 +619,6 @@ sctp_sysctl_handle_assoclist(SYSCTL_HANDLER_ARGS)
xraddr.cwnd = net->cwnd;
xraddr.flight_size = net->flight_size;
xraddr.mtu = net->mtu;
#if defined(__FreeBSD__)
#if __FreeBSD_version >= 800000
xraddr.rtt = net->rtt / 1000;
xraddr.heartbeat_interval = net->heart_beat_delay;
xraddr.ssthresh = net->ssthresh;
@ -639,20 +630,6 @@ sctp_sysctl_handle_assoclist(SYSCTL_HANDLER_ARGS)
} else {
xraddr.state = SCTP_INACTIVE;
}
#endif
#else
xraddr.rtt = net->rtt / 1000;
xraddr.heartbeat_interval = net->heart_beat_delay;
xraddr.ssthresh = net->ssthresh;
xraddr.encaps_port = net->port;
if (net->dest_state & SCTP_ADDR_UNCONFIRMED) {
xraddr.state = SCTP_UNCONFIRMED;
} else if (net->dest_state & SCTP_ADDR_REACHABLE) {
xraddr.state = SCTP_ACTIVE;
} else {
xraddr.state = SCTP_INACTIVE;
}
#endif
xraddr.start_time.tv_sec = (uint32_t)net->start_time.tv_sec;
xraddr.start_time.tv_usec = (uint32_t)net->start_time.tv_usec;
SCTP_INP_RUNLOCK(inp);
@ -699,7 +676,7 @@ skip:
return (error);
}
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
static int
sctp_sysctl_handle_udp_tunneling SYSCTL_HANDLER_ARGS
{
@ -716,22 +693,14 @@ sctp_sysctl_handle_udp_tunneling(SYSCTL_HANDLER_ARGS)
old = SCTP_BASE_SYSCTL(sctp_udp_tunneling_port);
SCTP_INP_INFO_RUNLOCK();
new = old;
#if defined(__FreeBSD__) && __FreeBSD_version >= 800056 && __FreeBSD_version < 1000100
#ifdef VIMAGE
error = vnet_sysctl_handle_int(oidp, &new, 0, req);
#else
error = sysctl_handle_int(oidp, &new, 0, req);
#endif
#else
error = sysctl_handle_int(oidp, &new, 0, req);
#endif
if ((error == 0) &&
#if defined (__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
(req->newptr != USER_ADDR_NULL)) {
#else
(req->newptr != NULL)) {
#endif
#if defined(__Windows__)
#if defined(_WIN32) && !defined(__Userspace__)
SCTP_INP_INFO_WLOCK();
sctp_over_udp_restart();
SCTP_INP_INFO_WUNLOCK();
@ -759,7 +728,7 @@ sctp_sysctl_handle_udp_tunneling(SYSCTL_HANDLER_ARGS)
return (error);
}
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
int sctp_is_vmware_interface(struct ifnet *);
static int
@ -792,7 +761,7 @@ sctp_sysctl_handle_vmware_interfaces SYSCTL_HANDLER_ARGS
}
#endif
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
static int
sctp_sysctl_handle_auth SYSCTL_HANDLER_ARGS
{
@ -806,17 +775,9 @@ sctp_sysctl_handle_auth(SYSCTL_HANDLER_ARGS)
uint32_t new;
new = SCTP_BASE_SYSCTL(sctp_auth_enable);
#if defined(__FreeBSD__) && __FreeBSD_version >= 800056 && __FreeBSD_version < 1000100
#ifdef VIMAGE
error = vnet_sysctl_handle_int(oidp, &new, 0, req);
#else
error = sysctl_handle_int(oidp, &new, 0, req);
#endif
#else
error = sysctl_handle_int(oidp, &new, 0, req);
#endif
if ((error == 0) &&
#if defined (__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
(req->newptr != USER_ADDR_NULL)) {
#else
(req->newptr != NULL)) {
@ -837,7 +798,7 @@ sctp_sysctl_handle_auth(SYSCTL_HANDLER_ARGS)
return (error);
}
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
static int
sctp_sysctl_handle_asconf SYSCTL_HANDLER_ARGS
{
@ -851,17 +812,9 @@ sctp_sysctl_handle_asconf(SYSCTL_HANDLER_ARGS)
uint32_t new;
new = SCTP_BASE_SYSCTL(sctp_asconf_enable);
#if defined(__FreeBSD__) && __FreeBSD_version >= 800056 && __FreeBSD_version < 1000100
#ifdef VIMAGE
error = vnet_sysctl_handle_int(oidp, &new, 0, req);
#else
error = sysctl_handle_int(oidp, &new, 0, req);
#endif
#else
error = sysctl_handle_int(oidp, &new, 0, req);
#endif
if ((error == 0) &&
#if defined (__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
(req->newptr != USER_ADDR_NULL)) {
#else
(req->newptr != NULL)) {
@ -882,7 +835,7 @@ sctp_sysctl_handle_asconf(SYSCTL_HANDLER_ARGS)
return (error);
}
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
static int
sctp_sysctl_handle_stats SYSCTL_HANDLER_ARGS
{
@ -893,7 +846,7 @@ sctp_sysctl_handle_stats(SYSCTL_HANDLER_ARGS)
{
#endif
int error;
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
#if defined(SMP) && defined(SCTP_USE_PERCPU_STAT)
struct sctpstat *sarry;
struct sctpstat sb;
@ -902,7 +855,7 @@ sctp_sysctl_handle_stats(SYSCTL_HANDLER_ARGS)
struct sctpstat sb_temp;
#endif
#if defined (__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
if ((req->newptr != USER_ADDR_NULL) &&
#else
if ((req->newptr != NULL) &&
@ -910,7 +863,7 @@ sctp_sysctl_handle_stats(SYSCTL_HANDLER_ARGS)
(req->newlen != sizeof(struct sctpstat))) {
return (EINVAL);
}
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
memset(&sb_temp, 0, sizeof(struct sctpstat));
if (req->newptr != NULL) {
@ -962,7 +915,6 @@ sctp_sysctl_handle_stats(SYSCTL_HANDLER_ARGS)
sb.sctps_recvauthfailed += sarry->sctps_recvauthfailed;
sb.sctps_recvexpress += sarry->sctps_recvexpress;
sb.sctps_recvexpressm += sarry->sctps_recvexpressm;
sb.sctps_recvnocrc += sarry->sctps_recvnocrc;
sb.sctps_recvswcrc += sarry->sctps_recvswcrc;
sb.sctps_recvhwcrc += sarry->sctps_recvhwcrc;
sb.sctps_sendpackets += sarry->sctps_sendpackets;
@ -975,7 +927,6 @@ sctp_sysctl_handle_stats(SYSCTL_HANDLER_ARGS)
sb.sctps_sendecne += sarry->sctps_sendecne;
sb.sctps_sendauth += sarry->sctps_sendauth;
sb.sctps_senderrors += sarry->sctps_senderrors;
sb.sctps_sendnocrc += sarry->sctps_sendnocrc;
sb.sctps_sendswcrc += sarry->sctps_sendswcrc;
sb.sctps_sendhwcrc += sarry->sctps_sendhwcrc;
sb.sctps_pdrpfmbox += sarry->sctps_pdrpfmbox;
@ -1069,7 +1020,7 @@ sctp_sysctl_handle_stats(SYSCTL_HANDLER_ARGS)
}
#if defined(SCTP_LOCAL_TRACE_BUF)
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
static int
sctp_sysctl_handle_trace_log SYSCTL_HANDLER_ARGS
{
@ -1081,7 +1032,7 @@ sctp_sysctl_handle_trace_log(SYSCTL_HANDLER_ARGS)
#endif
int error;
#if defined(__Windows__)
#if defined(_WIN32) && !defined(__Userspace__)
error = SYSCTL_OUT(req, SCTP_BASE_SYSCTL(sctp_log), sizeof(struct sctp_log));
#else
error = SYSCTL_OUT(req, &SCTP_BASE_SYSCTL(sctp_log), sizeof(struct sctp_log));
@ -1089,7 +1040,7 @@ sctp_sysctl_handle_trace_log(SYSCTL_HANDLER_ARGS)
return (error);
}
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
static int
sctp_sysctl_handle_trace_log_clear SYSCTL_HANDLER_ARGS
{
@ -1100,7 +1051,7 @@ sctp_sysctl_handle_trace_log_clear(SYSCTL_HANDLER_ARGS)
{
#endif
int error = 0;
#if defined(__Windows__)
#if defined(_WIN32) && !defined(__Userspace__)
int value = 0;
if (req->new_data == NULL) {
@ -1118,33 +1069,8 @@ sctp_sysctl_handle_trace_log_clear(SYSCTL_HANDLER_ARGS)
}
#endif
#if defined(__APPLE__) || defined(__FreeBSD__)
#if (defined(__APPLE__) || defined(__FreeBSD__)) && !defined(__Userspace__)
#if defined(__FreeBSD__)
#if __FreeBSD_version >= 800056 && __FreeBSD_version < 1000100
#ifdef VIMAGE
#define SCTP_UINT_SYSCTL(name, var_name, prefix) \
static int \
sctp_sysctl_handle_##mib_name(SYSCTL_HANDLER_ARGS) \
{ \
int error; \
uint32_t new; \
\
new = SCTP_BASE_SYSCTL(var_name); \
error = vnet_sysctl_handle_int(oidp, &new, 0, req); \
if ((error == 0) && (req->newptr != NULL)) { \
if ((new < prefix##_MIN) || \
(new > prefix##_MAX)) { \
error = EINVAL; \
} else { \
SCTP_BASE_SYSCTL(var_name) = new; \
} \
} \
return (error); \
} \
SYSCTL_PROC(_net_inet_sctp, OID_AUTO, mib_name, \
CTLTYPE_UINT|CTLFLAG_RW, NULL, 0, \
sctp_sysctl_handle_##mib_name, "UI", prefix##_DESC);
#else
#define SCTP_UINT_SYSCTL(mib_name, var_name, prefix) \
static int \
sctp_sysctl_handle_##mib_name(SYSCTL_HANDLER_ARGS) \
@ -1167,31 +1093,6 @@ sctp_sysctl_handle_trace_log_clear(SYSCTL_HANDLER_ARGS)
SYSCTL_PROC(_net_inet_sctp, OID_AUTO, mib_name, \
CTLFLAG_VNET|CTLTYPE_UINT|CTLFLAG_RW, NULL, 0, \
sctp_sysctl_handle_##mib_name, "UI", prefix##_DESC);
#endif
#else
#define SCTP_UINT_SYSCTL(mib_name, var_name, prefix) \
static int \
sctp_sysctl_handle_##mib_name(SYSCTL_HANDLER_ARGS) \
{ \
int error; \
uint32_t new; \
\
new = SCTP_BASE_SYSCTL(var_name); \
error = sysctl_handle_int(oidp, &new, 0, req); \
if ((error == 0) && (req->newptr != NULL)) { \
if ((new < prefix##_MIN) || \
(new > prefix##_MAX)) { \
error = EINVAL; \
} else { \
SCTP_BASE_SYSCTL(var_name) = new; \
} \
} \
return (error); \
} \
SYSCTL_PROC(_net_inet_sctp, OID_AUTO, mib_name, \
CTLFLAG_VNET|CTLTYPE_UINT|CTLFLAG_RW, NULL, 0, \
sctp_sysctl_handle_##mib_name, "UI", prefix##_DESC);
#endif
#else
#define SCTP_UINT_SYSCTL(mib_name, var_name, prefix) \
static int \
@ -1238,11 +1139,9 @@ SYSCTL_PROC(_net_inet_sctp, OID_AUTO, asconf_enable, CTLFLAG_VNET|CTLTYPE_UINT|C
SCTP_UINT_SYSCTL(reconfig_enable, sctp_reconfig_enable, SCTPCTL_RECONFIG_ENABLE)
SCTP_UINT_SYSCTL(nrsack_enable, sctp_nrsack_enable, SCTPCTL_NRSACK_ENABLE)
SCTP_UINT_SYSCTL(pktdrop_enable, sctp_pktdrop_enable, SCTPCTL_PKTDROP_ENABLE)
#if defined(__APPLE__)
#if !defined(SCTP_WITH_NO_CSUM)
#if defined(__APPLE__) && !defined(__Userspace__)
SCTP_UINT_SYSCTL(loopback_nocsum, sctp_no_csum_on_loopback, SCTPCTL_LOOPBACK_NOCSUM)
#endif
#endif
SCTP_UINT_SYSCTL(peer_chkoh, sctp_peer_chunk_oh, SCTPCTL_PEER_CHKOH)
SCTP_UINT_SYSCTL(maxburst, sctp_max_burst_default, SCTPCTL_MAXBURST)
SCTP_UINT_SYSCTL(fr_maxburst, sctp_fr_max_burst_default, SCTPCTL_FRMAXBURST)
@ -1307,18 +1206,19 @@ SCTP_UINT_SYSCTL(rttvar_eqret, sctp_rttvar_eqret, SCTPCTL_RTTVAR_EQRET)
SCTP_UINT_SYSCTL(rttvar_steady_step, sctp_steady_step, SCTPCTL_RTTVAR_STEADYS)
SCTP_UINT_SYSCTL(use_dcccecn, sctp_use_dccc_ecn, SCTPCTL_RTTVAR_DCCCECN)
SCTP_UINT_SYSCTL(blackhole, sctp_blackhole, SCTPCTL_BLACKHOLE)
SCTP_UINT_SYSCTL(sendall_limit, sctp_sendall_limit, SCTPCTL_SENDALL_LIMIT)
SCTP_UINT_SYSCTL(diag_info_code, sctp_diag_info_code, SCTPCTL_DIAG_INFO_CODE)
#ifdef SCTP_DEBUG
SCTP_UINT_SYSCTL(debug, sctp_debug_on, SCTPCTL_DEBUG)
#endif
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
SCTP_UINT_SYSCTL(main_timer, sctp_main_timer, SCTPCTL_MAIN_TIMER)
SYSCTL_PROC(_net_inet_sctp, OID_AUTO, ignore_vmware_interfaces, CTLTYPE_UINT|CTLFLAG_RW,
NULL, 0, sctp_sysctl_handle_vmware_interfaces, "IU", SCTPCTL_IGNORE_VMWARE_INTERFACES_DESC);
SCTP_UINT_SYSCTL(addr_watchdog_limit, sctp_addr_watchdog_limit, SCTPCTL_ADDR_WATCHDOG_LIMIT)
SCTP_UINT_SYSCTL(vtag_watchdog_limit, sctp_vtag_watchdog_limit, SCTPCTL_VTAG_WATCHDOG_LIMIT)
#endif
#if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
#if defined(__APPLE__) && !defined(__Userspace__)
SCTP_UINT_SYSCTL(output_unlocked, sctp_output_unlocked, SCTPCTL_OUTPUT_UNLOCKED)
#endif
SYSCTL_PROC(_net_inet_sctp, OID_AUTO, stats, CTLFLAG_VNET|CTLTYPE_STRUCT|CTLFLAG_RW,
@ -1326,7 +1226,7 @@ SYSCTL_PROC(_net_inet_sctp, OID_AUTO, stats, CTLFLAG_VNET|CTLTYPE_STRUCT|CTLFLAG
SYSCTL_PROC(_net_inet_sctp, OID_AUTO, assoclist, CTLFLAG_VNET|CTLTYPE_OPAQUE|CTLFLAG_RD,
NULL, 0, sctp_sysctl_handle_assoclist, "S,xassoc", "List of active SCTP associations");
#elif defined(__Windows__)
#elif defined(_WIN32) && !defined(__Userspace__)
#define RANGECHK(var, min, max) \
if ((var) < (min)) { (var) = (min); } \
@ -1348,9 +1248,7 @@ sctp_sysctl_handle_int(SYSCTL_HANDLER_ARGS)
RANGECHK(SCTP_BASE_SYSCTL(sctp_reconfig_enable), SCTPCTL_RECONFIG_ENABLE_MIN, SCTPCTL_RECONFIG_ENABLE_MAX);
RANGECHK(SCTP_BASE_SYSCTL(sctp_nrsack_enable), SCTPCTL_NRSACK_ENABLE_MIN, SCTPCTL_NRSACK_ENABLE_MAX);
RANGECHK(SCTP_BASE_SYSCTL(sctp_pktdrop_enable), SCTPCTL_PKTDROP_ENABLE_MIN, SCTPCTL_PKTDROP_ENABLE_MAX);
#if !defined(SCTP_WITH_NO_CSUM)
RANGECHK(SCTP_BASE_SYSCTL(sctp_no_csum_on_loopback), SCTPCTL_LOOPBACK_NOCSUM_MIN, SCTPCTL_LOOPBACK_NOCSUM_MAX);
#endif
RANGECHK(SCTP_BASE_SYSCTL(sctp_peer_chunk_oh), SCTPCTL_PEER_CHKOH_MIN, SCTPCTL_PEER_CHKOH_MAX);
RANGECHK(SCTP_BASE_SYSCTL(sctp_max_burst_default), SCTPCTL_MAXBURST_MIN, SCTPCTL_MAXBURST_MAX);
RANGECHK(SCTP_BASE_SYSCTL(sctp_fr_max_burst_default), SCTPCTL_FRMAXBURST_MIN, SCTPCTL_FRMAXBURST_MAX);
@ -1407,6 +1305,7 @@ sctp_sysctl_handle_int(SYSCTL_HANDLER_ARGS)
RANGECHK(SCTP_BASE_SYSCTL(sctp_enable_sack_immediately), SCTPCTL_SACK_IMMEDIATELY_ENABLE_MIN, SCTPCTL_SACK_IMMEDIATELY_ENABLE_MAX);
RANGECHK(SCTP_BASE_SYSCTL(sctp_inits_include_nat_friendly), SCTPCTL_NAT_FRIENDLY_INITS_MIN, SCTPCTL_NAT_FRIENDLY_INITS_MAX);
RANGECHK(SCTP_BASE_SYSCTL(sctp_blackhole), SCTPCTL_BLACKHOLE_MIN, SCTPCTL_BLACKHOLE_MAX);
RANGECHK(SCTP_BASE_SYSCTL(sctp_sendall_limit), SCTPCTL_SENDALL_LIMIT_MIN, SCTPCTL_SENDALL_LIMIT_MAX);
RANGECHK(SCTP_BASE_SYSCTL(sctp_diag_info_code), SCTPCTL_DIAG_INFO_CODE_MIN, SCTPCTL_DIAG_INFO_CODE_MAX);
#ifdef SCTP_DEBUG
RANGECHK(SCTP_BASE_SYSCTL(sctp_debug_on), SCTPCTL_DEBUG_MIN, SCTPCTL_DEBUG_MAX);
@ -1419,145 +1318,143 @@ void
sysctl_setup_sctp(void)
{
sysctl_add_oid(&sysctl_oid_top, "sendspace", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_sendspace), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_sendspace), 0, sctp_sysctl_handle_int,
SCTPCTL_MAXDGRAM_DESC);
sysctl_add_oid(&sysctl_oid_top, "recvspace", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_recvspace), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_recvspace), 0, sctp_sysctl_handle_int,
SCTPCTL_RECVSPACE_DESC);
sysctl_add_oid(&sysctl_oid_top, "auto_asconf", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_auto_asconf), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_auto_asconf), 0, sctp_sysctl_handle_int,
SCTPCTL_AUTOASCONF_DESC);
sysctl_add_oid(&sysctl_oid_top, "ecn_enable", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_ecn_enable), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_ecn_enable), 0, sctp_sysctl_handle_int,
SCTPCTL_ECN_ENABLE_DESC);
sysctl_add_oid(&sysctl_oid_top, "pr_enable", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_pr_enable), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_pr_enable), 0, sctp_sysctl_handle_int,
SCTPCTL_PR_ENABLE_DESC);
sysctl_add_oid(&sysctl_oid_top, "auth_enable", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_auth_enable), 0, sctp_sysctl_handle_auth,
&SCTP_BASE_SYSCTL(sctp_auth_enable), 0, sctp_sysctl_handle_auth,
SCTPCTL_AUTH_ENABLE_DESC);
sysctl_add_oid(&sysctl_oid_top, "asconf_enable", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_asconf_enable), 0, sctp_sysctl_handle_asconf,
&SCTP_BASE_SYSCTL(sctp_asconf_enable), 0, sctp_sysctl_handle_asconf,
SCTPCTL_ASCONF_ENABLE_DESC);
sysctl_add_oid(&sysctl_oid_top, "reconfig_enable", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_reconfig_enable), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_reconfig_enable), 0, sctp_sysctl_handle_int,
SCTPCTL_RECONFIG_ENABLE_DESC);
sysctl_add_oid(&sysctl_oid_top, "nrsack_enable", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_nrsack_enable), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_nrsack_enable), 0, sctp_sysctl_handle_int,
SCTPCTL_NRSACK_ENABLE_DESC);
sysctl_add_oid(&sysctl_oid_top, "pktdrop_enable", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_pktdrop_enable), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_pktdrop_enable), 0, sctp_sysctl_handle_int,
SCTPCTL_PKTDROP_ENABLE_DESC);
#if !defined(SCTP_WITH_NO_CSUM)
sysctl_add_oid(&sysctl_oid_top, "loopback_nocsum", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_no_csum_on_loopback), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_no_csum_on_loopback), 0, sctp_sysctl_handle_int,
SCTPCTL_LOOPBACK_NOCSUM_DESC);
#endif
sysctl_add_oid(&sysctl_oid_top, "peer_chkoh", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_peer_chunk_oh), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_peer_chunk_oh), 0, sctp_sysctl_handle_int,
SCTPCTL_PEER_CHKOH_DESC);
sysctl_add_oid(&sysctl_oid_top, "maxburst", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_max_burst_default), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_max_burst_default), 0, sctp_sysctl_handle_int,
SCTPCTL_MAXBURST_DESC);
sysctl_add_oid(&sysctl_oid_top, "fr_maxburst", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_fr_max_burst_default), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_fr_max_burst_default), 0, sctp_sysctl_handle_int,
SCTPCTL_FRMAXBURST_DESC);
sysctl_add_oid(&sysctl_oid_top, "maxchunks", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_max_chunks_on_queue), 0, sctp_sysctl_handle_int,
SCTPCTL_MAXCHUNKS_DESC);
sysctl_add_oid(&sysctl_oid_top, "tcbhashsize", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_hashtblsize), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_hashtblsize), 0, sctp_sysctl_handle_int,
SCTPCTL_TCBHASHSIZE_DESC);
sysctl_add_oid(&sysctl_oid_top, "pcbhashsize", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_pcbtblsize), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_pcbtblsize), 0, sctp_sysctl_handle_int,
SCTPCTL_PCBHASHSIZE_DESC);
sysctl_add_oid(&sysctl_oid_top, "min_split_point", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_min_split_point), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_min_split_point), 0, sctp_sysctl_handle_int,
SCTPCTL_MIN_SPLIT_POINT_DESC);
sysctl_add_oid(&sysctl_oid_top, "chunkscale", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_chunkscale), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_chunkscale), 0, sctp_sysctl_handle_int,
SCTPCTL_CHUNKSCALE_DESC);
sysctl_add_oid(&sysctl_oid_top, "delayed_sack_time", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_delayed_sack_time_default), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_delayed_sack_time_default), 0, sctp_sysctl_handle_int,
SCTPCTL_DELAYED_SACK_TIME_DESC);
sysctl_add_oid(&sysctl_oid_top, "sack_freq", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_sack_freq_default), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_sack_freq_default), 0, sctp_sysctl_handle_int,
SCTPCTL_SACK_FREQ_DESC);
sysctl_add_oid(&sysctl_oid_top, "sys_resource", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_system_free_resc_limit), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_system_free_resc_limit), 0, sctp_sysctl_handle_int,
SCTPCTL_SYS_RESOURCE_DESC);
sysctl_add_oid(&sysctl_oid_top, "asoc_resource", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_asoc_free_resc_limit), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_asoc_free_resc_limit), 0, sctp_sysctl_handle_int,
SCTPCTL_ASOC_RESOURCE_DESC);
sysctl_add_oid(&sysctl_oid_top, "heartbeat_interval", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_heartbeat_interval_default), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_heartbeat_interval_default), 0, sctp_sysctl_handle_int,
SCTPCTL_HEARTBEAT_INTERVAL_DESC);
sysctl_add_oid(&sysctl_oid_top, "pmtu_raise_time", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_pmtu_raise_time_default), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_pmtu_raise_time_default), 0, sctp_sysctl_handle_int,
SCTPCTL_PMTU_RAISE_TIME_DESC);
sysctl_add_oid(&sysctl_oid_top, "shutdown_guard_time", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_shutdown_guard_time_default), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_shutdown_guard_time_default), 0, sctp_sysctl_handle_int,
SCTPCTL_SHUTDOWN_GUARD_TIME_DESC);
sysctl_add_oid(&sysctl_oid_top, "secret_lifetime", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_secret_lifetime_default), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_secret_lifetime_default), 0, sctp_sysctl_handle_int,
SCTPCTL_SECRET_LIFETIME_DESC);
sysctl_add_oid(&sysctl_oid_top, "rto_max", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_rto_max_default), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_rto_max_default), 0, sctp_sysctl_handle_int,
SCTPCTL_RTO_MAX_DESC);
sysctl_add_oid(&sysctl_oid_top, "rto_min", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_rto_min_default), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_rto_min_default), 0, sctp_sysctl_handle_int,
SCTPCTL_RTO_MIN_DESC);
sysctl_add_oid(&sysctl_oid_top, "rto_initial", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_rto_initial_default), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_rto_initial_default), 0, sctp_sysctl_handle_int,
SCTPCTL_RTO_INITIAL_DESC);
sysctl_add_oid(&sysctl_oid_top, "init_rto_max", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_init_rto_max_default), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_init_rto_max_default), 0, sctp_sysctl_handle_int,
SCTPCTL_INIT_RTO_MAX_DESC);
sysctl_add_oid(&sysctl_oid_top, "valid_cookie_life", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_valid_cookie_life_default), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_valid_cookie_life_default), 0, sctp_sysctl_handle_int,
SCTPCTL_VALID_COOKIE_LIFE_DESC);
sysctl_add_oid(&sysctl_oid_top, "init_rtx_max", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_init_rtx_max_default), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_init_rtx_max_default), 0, sctp_sysctl_handle_int,
SCTPCTL_INIT_RTX_MAX_DESC);
sysctl_add_oid(&sysctl_oid_top, "assoc_rtx_max", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_assoc_rtx_max_default), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_assoc_rtx_max_default), 0, sctp_sysctl_handle_int,
SCTPCTL_ASSOC_RTX_MAX_DESC);
sysctl_add_oid(&sysctl_oid_top, "path_rtx_max", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_path_rtx_max_default), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_path_rtx_max_default), 0, sctp_sysctl_handle_int,
SCTPCTL_PATH_RTX_MAX_DESC);
sysctl_add_oid(&sysctl_oid_top, "path_pf_threshold", CTLTYPE_INT|CTLFLAG_RW,
@ -1565,83 +1462,83 @@ sysctl_setup_sctp(void)
SCTPCTL_PATH_PF_THRESHOLD_DESC);
sysctl_add_oid(&sysctl_oid_top, "add_more_on_output", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_add_more_threshold), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_add_more_threshold), 0, sctp_sysctl_handle_int,
SCTPCTL_ADD_MORE_ON_OUTPUT_DESC);
sysctl_add_oid(&sysctl_oid_top, "incoming_streams", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_nr_incoming_streams_default), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_nr_incoming_streams_default), 0, sctp_sysctl_handle_int,
SCTPCTL_INCOMING_STREAMS_DESC);
sysctl_add_oid(&sysctl_oid_top, "outgoing_streams", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_nr_outgoing_streams_default), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_nr_outgoing_streams_default), 0, sctp_sysctl_handle_int,
SCTPCTL_OUTGOING_STREAMS_DESC);
sysctl_add_oid(&sysctl_oid_top, "cmt_on_off", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_cmt_on_off), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_cmt_on_off), 0, sctp_sysctl_handle_int,
SCTPCTL_CMT_ON_OFF_DESC);
sysctl_add_oid(&sysctl_oid_top, "cmt_use_dac", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_cmt_use_dac), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_cmt_use_dac), 0, sctp_sysctl_handle_int,
SCTPCTL_CMT_USE_DAC_DESC);
sysctl_add_oid(&sysctl_oid_top, "cwnd_maxburst", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_use_cwnd_based_maxburst), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_use_cwnd_based_maxburst), 0, sctp_sysctl_handle_int,
SCTPCTL_CWND_MAXBURST_DESC);
sysctl_add_oid(&sysctl_oid_top, "nat_friendly", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_nat_friendly), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_nat_friendly), 0, sctp_sysctl_handle_int,
SCTPCTL_NAT_FRIENDLY_DESC);
sysctl_add_oid(&sysctl_oid_top, "abc_l_var", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_L2_abc_variable), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_L2_abc_variable), 0, sctp_sysctl_handle_int,
SCTPCTL_ABC_L_VAR_DESC);
sysctl_add_oid(&sysctl_oid_top, "max_chained_mbufs", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_mbuf_threshold_count), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_mbuf_threshold_count), 0, sctp_sysctl_handle_int,
SCTPCTL_MAX_CHAINED_MBUFS_DESC);
sysctl_add_oid(&sysctl_oid_top, "do_sctp_drain", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_do_drain), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_do_drain), 0, sctp_sysctl_handle_int,
SCTPCTL_DO_SCTP_DRAIN_DESC);
sysctl_add_oid(&sysctl_oid_top, "hb_max_burst", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_hb_maxburst), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_hb_maxburst), 0, sctp_sysctl_handle_int,
SCTPCTL_HB_MAX_BURST_DESC);
sysctl_add_oid(&sysctl_oid_top, "abort_at_limit", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_abort_if_one_2_one_hits_limit), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_abort_if_one_2_one_hits_limit), 0, sctp_sysctl_handle_int,
SCTPCTL_ABORT_AT_LIMIT_DESC);
sysctl_add_oid(&sysctl_oid_top, "min_residual", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_min_residual), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_min_residual), 0, sctp_sysctl_handle_int,
SCTPCTL_MIN_RESIDUAL_DESC);
sysctl_add_oid(&sysctl_oid_top, "max_retran_chunk", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_max_retran_chunk), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_max_retran_chunk), 0, sctp_sysctl_handle_int,
SCTPCTL_MAX_RETRAN_CHUNK_DESC);
sysctl_add_oid(&sysctl_oid_top, "log_level", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_logging_level), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_logging_level), 0, sctp_sysctl_handle_int,
SCTPCTL_LOGGING_LEVEL_DESC);
sysctl_add_oid(&sysctl_oid_top, "default_cc_module", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_default_cc_module), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_default_cc_module), 0, sctp_sysctl_handle_int,
SCTPCTL_DEFAULT_CC_MODULE_DESC);
sysctl_add_oid(&sysctl_oid_top, "default_ss_module", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_default_ss_module), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_default_ss_module), 0, sctp_sysctl_handle_int,
SCTPCTL_DEFAULT_SS_MODULE_DESC);
sysctl_add_oid(&sysctl_oid_top, "default_frag_interleave", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_default_frag_interleave), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_default_frag_interleave), 0, sctp_sysctl_handle_int,
SCTPCTL_DEFAULT_FRAG_INTERLEAVE_DESC);
sysctl_add_oid(&sysctl_oid_top, "mobility_base", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_mobility_base), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_mobility_base), 0, sctp_sysctl_handle_int,
SCTPCTL_MOBILITY_BASE_DESC);
sysctl_add_oid(&sysctl_oid_top, "mobility_fasthandoff", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_mobility_fasthandoff), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_mobility_fasthandoff), 0, sctp_sysctl_handle_int,
SCTPCTL_MOBILITY_FASTHANDOFF_DESC);
#if defined(SCTP_LOCAL_TRACE_BUF)
@ -1659,52 +1556,56 @@ sysctl_setup_sctp(void)
SCTPCTL_UDP_TUNNELING_PORT_DESC);
sysctl_add_oid(&sysctl_oid_top, "enable_sack_immediately", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_enable_sack_immediately), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_enable_sack_immediately), 0, sctp_sysctl_handle_int,
SCTPCTL_SACK_IMMEDIATELY_ENABLE_DESC);
sysctl_add_oid(&sysctl_oid_top, "nat_friendly_init", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_inits_include_nat_friendly), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_inits_include_nat_friendly), 0, sctp_sysctl_handle_int,
SCTPCTL_NAT_FRIENDLY_DESC);
sysctl_add_oid(&sysctl_oid_top, "vtag_time_wait", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_vtag_time_wait), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_vtag_time_wait), 0, sctp_sysctl_handle_int,
SCTPCTL_TIME_WAIT_DESC);
sysctl_add_oid(&sysctl_oid_top, "buffer_splitting", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_buffer_splitting), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_buffer_splitting), 0, sctp_sysctl_handle_int,
SCTPCTL_BUFFER_SPLITTING_DESC);
sysctl_add_oid(&sysctl_oid_top, "initial_cwnd", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_initial_cwnd), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_initial_cwnd), 0, sctp_sysctl_handle_int,
SCTPCTL_INITIAL_CWND_DESC);
sysctl_add_oid(&sysctl_oid_top, "rttvar_bw", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_rttvar_bw), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_rttvar_bw), 0, sctp_sysctl_handle_int,
SCTPCTL_RTTVAR_BW_DESC);
sysctl_add_oid(&sysctl_oid_top, "rttvar_rtt", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_rttvar_rtt), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_rttvar_rtt), 0, sctp_sysctl_handle_int,
SCTPCTL_RTTVAR_RTT_DESC);
sysctl_add_oid(&sysctl_oid_top, "rttvar_eqret", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_rttvar_eqret), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_rttvar_eqret), 0, sctp_sysctl_handle_int,
SCTPCTL_RTTVAR_EQRET_DESC);
sysctl_add_oid(&sysctl_oid_top, "rttvar_steady_step", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_steady_step), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_steady_step), 0, sctp_sysctl_handle_int,
SCTPCTL_RTTVAR_STEADYS_DESC);
sysctl_add_oid(&sysctl_oid_top, "use_dcccecn", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_use_dccc_ecn), 0, sctp_sysctl_handle_int,
&SCTP_BASE_SYSCTL(sctp_use_dccc_ecn), 0, sctp_sysctl_handle_int,
SCTPCTL_RTTVAR_DCCCECN_DESC);
sysctl_add_oid(&sysctl_oid_top, "blackhole", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_blackhole), 0, sctp_sysctl_handle_int,
SCTPCTL_BLACKHOLE_DESC);
&SCTP_BASE_SYSCTL(sctp_blackhole), 0, sctp_sysctl_handle_int,
SCTPCTL_BLACKHOLE_DESC);
sysctl_add_oid(&sysctl_oid_top, "sendall_limit", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_sendall_limit), 0, sctp_sysctl_handle_int,
SCTPCTL_SENDALL_LIMIT_DESC);
sysctl_add_oid(&sysctl_oid_top, "diag_info_code", CTLTYPE_INT|CTLFLAG_RW,
&SCTP_BASE_SYSCTL(sctp_diag_info_code), 0, sctp_sysctl_handle_int,
SCTPCTL_DIAG_INFO_CODE_DESC);
&SCTP_BASE_SYSCTL(sctp_diag_info_code), 0, sctp_sysctl_handle_int,
SCTPCTL_DIAG_INFO_CODE_DESC);
#ifdef SCTP_DEBUG
sysctl_add_oid(&sysctl_oid_top, "debug", CTLTYPE_INT|CTLFLAG_RW,

View File

@ -32,9 +32,9 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_sysctl.h 299543 2016-05-12 16:34:59Z tuexen $");
__FBSDID("$FreeBSD: head/sys/netinet/sctp_sysctl.h 361895 2020-06-07 14:39:20Z tuexen $");
#endif
#ifndef _NETINET_SCTP_SYSCTL_H_
@ -56,10 +56,8 @@ struct sctp_sysctl {
uint32_t sctp_nrsack_enable;
uint32_t sctp_pktdrop_enable;
uint32_t sctp_fr_max_burst_default;
#if !(defined(__FreeBSD__) && __FreeBSD_version >= 800000)
#if !defined(SCTP_WITH_NO_CSUM)
#if !(defined(__FreeBSD__) && !defined(__Userspace__))
uint32_t sctp_no_csum_on_loopback;
#endif
#endif
uint32_t sctp_peer_chunk_oh;
uint32_t sctp_max_burst_default;
@ -115,7 +113,7 @@ struct sctp_sysctl {
uint32_t sctp_use_dccc_ecn;
uint32_t sctp_diag_info_code;
#if defined(SCTP_LOCAL_TRACE_BUF)
#if defined(__Windows__)
#if defined(_WIN32) && !defined(__Userspace__)
struct sctp_log *sctp_log;
#else
struct sctp_log sctp_log;
@ -127,16 +125,17 @@ struct sctp_sysctl {
uint32_t sctp_buffer_splitting;
uint32_t sctp_initial_cwnd;
uint32_t sctp_blackhole;
uint32_t sctp_sendall_limit;
#if defined(SCTP_DEBUG)
uint32_t sctp_debug_on;
#endif
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
uint32_t sctp_ignore_vmware_interfaces;
uint32_t sctp_main_timer;
uint32_t sctp_addr_watchdog_limit;
uint32_t sctp_vtag_watchdog_limit;
#endif
#if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
#if defined(__APPLE__) && !defined(__Userspace__)
uint32_t sctp_output_unlocked;
#endif
};
@ -237,7 +236,7 @@ struct sctp_sysctl {
#define SCTPCTL_MAXBURST_DEFAULT SCTP_DEF_MAX_BURST
/* fr_maxburst: Default max burst for sctp endpoints when fast retransmitting */
#define SCTPCTL_FRMAXBURST_DESC "Default fr max burst for sctp endpoints"
#define SCTPCTL_FRMAXBURST_DESC "Default max burst for SCTP endpoints when fast retransmitting"
#define SCTPCTL_FRMAXBURST_MIN 0
#define SCTPCTL_FRMAXBURST_MAX 0xFFFFFFFF
#define SCTPCTL_FRMAXBURST_DEFAULT SCTP_DEF_FRMAX_BURST
@ -268,7 +267,7 @@ struct sctp_sysctl {
#define SCTPCTL_MIN_SPLIT_POINT_DEFAULT SCTP_DEFAULT_SPLIT_POINT_MIN
/* chunkscale: Tunable for Scaling of number of chunks and messages */
#define SCTPCTL_CHUNKSCALE_DESC "Tunable for Scaling of number of chunks and messages"
#define SCTPCTL_CHUNKSCALE_DESC "Tunable for scaling of number of chunks and messages"
#define SCTPCTL_CHUNKSCALE_MIN 1
#define SCTPCTL_CHUNKSCALE_MAX 0xFFFFFFFF
#define SCTPCTL_CHUNKSCALE_DEFAULT SCTP_CHUNKQUEUE_SCALE
@ -352,7 +351,7 @@ struct sctp_sysctl {
#define SCTPCTL_VALID_COOKIE_LIFE_DEFAULT SCTP_DEFAULT_COOKIE_LIFE
/* init_rtx_max: Default maximum number of retransmission for INIT chunks */
#define SCTPCTL_INIT_RTX_MAX_DESC "Default maximum number of retransmission for INIT chunks"
#define SCTPCTL_INIT_RTX_MAX_DESC "Default maximum number of retransmissions for INIT chunks"
#define SCTPCTL_INIT_RTX_MAX_MIN 0
#define SCTPCTL_INIT_RTX_MAX_MAX 0xFFFFFFFF
#define SCTPCTL_INIT_RTX_MAX_DEFAULT SCTP_DEF_MAX_INIT
@ -405,8 +404,8 @@ struct sctp_sysctl {
#define SCTPCTL_CMT_USE_DAC_MAX 1
#define SCTPCTL_CMT_USE_DAC_DEFAULT 0
/* cwnd_maxburst: Use a CWND adjusting maxburst */
#define SCTPCTL_CWND_MAXBURST_DESC "Use a CWND adjusting maxburst"
/* cwnd_maxburst: Use a CWND adjusting to implement maxburst */
#define SCTPCTL_CWND_MAXBURST_DESC "Adjust congestion control window to limit maximum burst when sending"
#define SCTPCTL_CWND_MAXBURST_MIN 0
#define SCTPCTL_CWND_MAXBURST_MAX 1
#define SCTPCTL_CWND_MAXBURST_DEFAULT 1
@ -442,7 +441,7 @@ struct sctp_sysctl {
#define SCTPCTL_HB_MAX_BURST_DEFAULT SCTP_DEF_HBMAX_BURST
/* abort_at_limit: When one-2-one hits qlimit abort */
#define SCTPCTL_ABORT_AT_LIMIT_DESC "When one-2-one hits qlimit abort"
#define SCTPCTL_ABORT_AT_LIMIT_DESC "Abort when one-to-one hits qlimit"
#define SCTPCTL_ABORT_AT_LIMIT_MIN 0
#define SCTPCTL_ABORT_AT_LIMIT_MAX 1
#define SCTPCTL_ABORT_AT_LIMIT_DEFAULT 0
@ -454,7 +453,7 @@ struct sctp_sysctl {
#define SCTPCTL_MIN_RESIDUAL_DEFAULT 1452
/* max_retran_chunk: max chunk retransmissions */
#define SCTPCTL_MAX_RETRAN_CHUNK_DESC "Maximum times an unlucky chunk can be retran'd before assoc abort"
#define SCTPCTL_MAX_RETRAN_CHUNK_DESC "Maximum times an unlucky chunk can be retransmitted before assoc abort"
#define SCTPCTL_MAX_RETRAN_CHUNK_MIN 0
#define SCTPCTL_MAX_RETRAN_CHUNK_MAX 65535
#define SCTPCTL_MAX_RETRAN_CHUNK_DEFAULT 30
@ -499,74 +498,80 @@ struct sctp_sysctl {
#define SCTPCTL_UDP_TUNNELING_PORT_DESC "Set the SCTP/UDP tunneling port"
#define SCTPCTL_UDP_TUNNELING_PORT_MIN 0
#define SCTPCTL_UDP_TUNNELING_PORT_MAX 65535
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
#define SCTPCTL_UDP_TUNNELING_PORT_DEFAULT 0
#else
#define SCTPCTL_UDP_TUNNELING_PORT_DEFAULT SCTP_OVER_UDP_TUNNELING_PORT
#endif
/* Enable sending of the SACK-IMMEDIATELY bit */
#define SCTPCTL_SACK_IMMEDIATELY_ENABLE_DESC "Enable sending of the SACK-IMMEDIATELY-bit."
#define SCTPCTL_SACK_IMMEDIATELY_ENABLE_DESC "Enable sending of the SACK-IMMEDIATELY-bit"
#define SCTPCTL_SACK_IMMEDIATELY_ENABLE_MIN 0
#define SCTPCTL_SACK_IMMEDIATELY_ENABLE_MAX 1
#define SCTPCTL_SACK_IMMEDIATELY_ENABLE_DEFAULT SCTPCTL_SACK_IMMEDIATELY_ENABLE_MAX
/* Enable sending of the NAT-FRIENDLY message */
#define SCTPCTL_NAT_FRIENDLY_INITS_DESC "Enable sending of the nat-friendly SCTP option on INITs."
#define SCTPCTL_NAT_FRIENDLY_INITS_DESC "Enable sending of the nat-friendly SCTP option on INITs"
#define SCTPCTL_NAT_FRIENDLY_INITS_MIN 0
#define SCTPCTL_NAT_FRIENDLY_INITS_MAX 1
#define SCTPCTL_NAT_FRIENDLY_INITS_DEFAULT SCTPCTL_NAT_FRIENDLY_INITS_MIN
/* Vtag time wait in seconds */
#define SCTPCTL_TIME_WAIT_DESC "Vtag time wait time in seconds, 0 disables it."
#define SCTPCTL_TIME_WAIT_DESC "Vtag time wait time in seconds, 0 disables it"
#define SCTPCTL_TIME_WAIT_MIN 0
#define SCTPCTL_TIME_WAIT_MAX 0xffffffff
#define SCTPCTL_TIME_WAIT_DEFAULT SCTP_TIME_WAIT
/* Enable Send/Receive buffer splitting */
#define SCTPCTL_BUFFER_SPLITTING_DESC "Enable send/receive buffer splitting."
#define SCTPCTL_BUFFER_SPLITTING_DESC "Enable send/receive buffer splitting"
#define SCTPCTL_BUFFER_SPLITTING_MIN 0
#define SCTPCTL_BUFFER_SPLITTING_MAX 0x3
#define SCTPCTL_BUFFER_SPLITTING_DEFAULT SCTPCTL_BUFFER_SPLITTING_MIN
/* Initial congestion window in MTU */
#define SCTPCTL_INITIAL_CWND_DESC "Initial congestion window in MTUs"
/* Initial congestion window in MTUs */
#define SCTPCTL_INITIAL_CWND_DESC "Defines the initial congestion window size in MTUs"
#define SCTPCTL_INITIAL_CWND_MIN 0
#define SCTPCTL_INITIAL_CWND_MAX 0xffffffff
#define SCTPCTL_INITIAL_CWND_DEFAULT 3
/* rttvar smooth avg for bw calc */
#define SCTPCTL_RTTVAR_BW_DESC "Shift amount for bw smoothing on rtt calc"
#define SCTPCTL_RTTVAR_BW_DESC "Shift amount DCCC uses for bw smoothing on rtt calc"
#define SCTPCTL_RTTVAR_BW_MIN 0
#define SCTPCTL_RTTVAR_BW_MAX 32
#define SCTPCTL_RTTVAR_BW_DEFAULT 4
/* rttvar smooth avg for bw calc */
#define SCTPCTL_RTTVAR_RTT_DESC "Shift amount for rtt smoothing on rtt calc"
#define SCTPCTL_RTTVAR_RTT_DESC "Shift amount DCCC uses for rtt smoothing on rtt calc"
#define SCTPCTL_RTTVAR_RTT_MIN 0
#define SCTPCTL_RTTVAR_RTT_MAX 32
#define SCTPCTL_RTTVAR_RTT_DEFAULT 5
#define SCTPCTL_RTTVAR_EQRET_DESC "What to return when rtt and bw are unchanged"
#define SCTPCTL_RTTVAR_EQRET_DESC "Whether DCCC increases cwnd when the rtt and bw are unchanged"
#define SCTPCTL_RTTVAR_EQRET_MIN 0
#define SCTPCTL_RTTVAR_EQRET_MAX 1
#define SCTPCTL_RTTVAR_EQRET_DEFAULT 0
#define SCTPCTL_RTTVAR_STEADYS_DESC "How many the sames it takes to try step down of cwnd"
#define SCTPCTL_RTTVAR_STEADYS_DESC "Number of identical bw measurements DCCC takes to try step down of cwnd"
#define SCTPCTL_RTTVAR_STEADYS_MIN 0
#define SCTPCTL_RTTVAR_STEADYS_MAX 0xFFFF
#define SCTPCTL_RTTVAR_STEADYS_DEFAULT 20 /* 0 means disable feature */
#define SCTPCTL_RTTVAR_DCCCECN_DESC "Enable for RTCC CC datacenter ECN"
#define SCTPCTL_RTTVAR_DCCCECN_DESC "Enable ECN for DCCC."
#define SCTPCTL_RTTVAR_DCCCECN_MIN 0
#define SCTPCTL_RTTVAR_DCCCECN_MAX 1
#define SCTPCTL_RTTVAR_DCCCECN_DEFAULT 1 /* 0 means disable feature */
#define SCTPCTL_BLACKHOLE_DESC "Enable SCTP blackholing. See blackhole(4) for more details."
#define SCTPCTL_BLACKHOLE_DESC "Enable SCTP blackholing, see blackhole(4) for more details"
#define SCTPCTL_BLACKHOLE_MIN 0
#define SCTPCTL_BLACKHOLE_MAX 2
#define SCTPCTL_BLACKHOLE_DEFAULT SCTPCTL_BLACKHOLE_MIN
/* sendall_limit: Maximum message with SCTP_SENDALL */
#define SCTPCTL_SENDALL_LIMIT_DESC "Maximum size of a message send with SCTP_SENDALL"
#define SCTPCTL_SENDALL_LIMIT_MIN 0
#define SCTPCTL_SENDALL_LIMIT_MAX 0xFFFFFFFF
#define SCTPCTL_SENDALL_LIMIT_DEFAULT 1432
#define SCTPCTL_DIAG_INFO_CODE_DESC "Diagnostic information error cause code"
#define SCTPCTL_DIAG_INFO_CODE_MIN 0
#define SCTPCTL_DIAG_INFO_CODE_MAX 65535
@ -580,7 +585,7 @@ struct sctp_sysctl {
#define SCTPCTL_DEBUG_DEFAULT 0
#endif
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
#define SCTPCTL_MAIN_TIMER_DESC "Main timer interval in ms"
#define SCTPCTL_MAIN_TIMER_MIN 1
#define SCTPCTL_MAIN_TIMER_MAX 0xFFFFFFFF
@ -592,14 +597,14 @@ struct sctp_sysctl {
#define SCTPCTL_IGNORE_VMWARE_INTERFACES_DEFAULT SCTPCTL_IGNORE_VMWARE_INTERFACES_MAX
#endif
#if defined(__APPLE__) || defined(SCTP_SO_LOCK_TESTING)
#define SCTPCTL_OUTPUT_UNLOCKED_DESC "Unlock socket when sending packets down to IP."
#if defined(__APPLE__) && !defined(__Userspace__)
#define SCTPCTL_OUTPUT_UNLOCKED_DESC "Unlock socket when sending packets down to IP"
#define SCTPCTL_OUTPUT_UNLOCKED_MIN 0
#define SCTPCTL_OUTPUT_UNLOCKED_MAX 1
#define SCTPCTL_OUTPUT_UNLOCKED_DEFAULT SCTPCTL_OUTPUT_UNLOCKED_MIN
#endif
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
#define SCTPCTL_ADDR_WATCHDOG_LIMIT_DESC "Address watchdog limit"
#define SCTPCTL_ADDR_WATCHDOG_LIMIT_MIN 0
#define SCTPCTL_ADDR_WATCHDOG_LIMIT_MAX 0xFFFFFFFF
@ -619,7 +624,7 @@ SYSCTL_DECL(_net_inet_sctp);
#endif
void sctp_init_sysctls(void);
#if defined(__Windows__)
#if defined(_WIN32) && !defined(__Userspace__)
void sctp_finish_sysctls(void);
#endif

View File

@ -32,16 +32,16 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_timer.c 317592 2017-04-29 09:57:27Z tuexen $");
__FBSDID("$FreeBSD: head/sys/netinet/sctp_timer.c 362054 2020-06-11 13:34:09Z tuexen $");
#endif
#define _IP_VHL
#include <netinet/sctp_os.h>
#include <netinet/sctp_pcb.h>
#ifdef INET6
#if defined(__Userspace_os_FreeBSD)
#if defined(__FreeBSD__) && defined(__Userspace__)
#include <netinet6/sctp6_var.h>
#endif
#endif
@ -57,15 +57,11 @@ __FBSDID("$FreeBSD: head/sys/netinet/sctp_timer.c 317592 2017-04-29 09:57:27Z tu
#include <netinet/sctp.h>
#include <netinet/sctp_uio.h>
#if defined(INET) || defined(INET6)
#if !defined(__Userspace_os_Windows)
#if !(defined(_WIN32) && defined(__Userspace__))
#include <netinet/udp.h>
#endif
#endif
#if defined(__APPLE__)
#define APPLE_FILE_NO 6
#endif
void
sctp_audit_retranmission_queue(struct sctp_association *asoc)
{
@ -348,7 +344,11 @@ sctp_find_alternate_net(struct sctp_tcb *stcb,
return (NULL);
}
}
#if defined(__FreeBSD__) && !defined(__Userspace__)
if (alt->ro.ro_nh == NULL) {
#else
if (alt->ro.ro_rt == NULL) {
#endif
if (alt->ro._s_addr) {
sctp_free_ifa(alt->ro._s_addr);
alt->ro._s_addr = NULL;
@ -356,7 +356,11 @@ sctp_find_alternate_net(struct sctp_tcb *stcb,
alt->src_addr_selected = 0;
}
if (((alt->dest_state & SCTP_ADDR_REACHABLE) == SCTP_ADDR_REACHABLE) &&
#if defined(__FreeBSD__) && !defined(__Userspace__)
(alt->ro.ro_nh != NULL) &&
#else
(alt->ro.ro_rt != NULL) &&
#endif
(!(alt->dest_state & SCTP_ADDR_UNCONFIRMED))) {
/* Found a reachable address */
break;
@ -517,7 +521,7 @@ sctp_mark_all_for_resend(struct sctp_tcb *stcb,
}
tv.tv_sec = cur_rto / 1000000;
tv.tv_usec = cur_rto % 1000000;
#ifndef __FreeBSD__
#if !(defined(__FreeBSD__) && !defined(__Userspace__))
timersub(&now, &tv, &min_wait);
#else
min_wait = now;
@ -614,7 +618,7 @@ sctp_mark_all_for_resend(struct sctp_tcb *stcb,
}
if (stcb->asoc.prsctp_supported && PR_SCTP_TTL_ENABLED(chk->flags)) {
/* Is it expired? */
#ifndef __FreeBSD__
#if !(defined(__FreeBSD__) && !defined(__Userspace__))
if (timercmp(&now, &chk->rec.data.timetodrop, >)) {
#else
if (timevalcmp(&now, &chk->rec.data.timetodrop, >)) {
@ -942,10 +946,14 @@ sctp_t3rxt_timer(struct sctp_inpcb *inp,
net->src_addr_selected = 0;
/* Force a route allocation too */
#if defined(__FreeBSD__) && !defined(__Userspace__)
RO_NHFREE(&net->ro);
#else
if (net->ro.ro_rt) {
RTFREE(net->ro.ro_rt);
net->ro.ro_rt = NULL;
}
#endif
/* Was it our primary? */
if ((stcb->asoc.primary_destination == net) && (alt != net)) {
@ -967,7 +975,7 @@ sctp_t3rxt_timer(struct sctp_inpcb *inp,
* Special case for cookie-echo'ed case, we don't do output but must
* await the COOKIE-ACK before retransmission
*/
if (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_COOKIE_ECHOED) {
if (SCTP_GET_STATE(stcb) == SCTP_STATE_COOKIE_ECHOED) {
/*
* Here we just reset the timer and start again since we
* have not established the asoc
@ -982,7 +990,12 @@ sctp_t3rxt_timer(struct sctp_inpcb *inp,
/* C3. See if we need to send a Fwd-TSN */
if (SCTP_TSN_GT(stcb->asoc.advanced_peer_ack_point, stcb->asoc.last_acked_seq)) {
send_forward_tsn(stcb, &stcb->asoc);
if (lchk) {
for (; lchk != NULL; lchk = TAILQ_NEXT(lchk, sctp_next)) {
if (lchk->whoTo != NULL) {
break;
}
}
if (lchk != NULL) {
/* Assure a timer is up */
sctp_timer_start(SCTP_TIMER_TYPE_SEND, stcb->sctp_ep, stcb, lchk->whoTo);
}
@ -1009,7 +1022,7 @@ sctp_t1init_timer(struct sctp_inpcb *inp,
sctp_send_initiate(inp, stcb, SCTP_SO_NOT_LOCKED);
return (0);
}
if (SCTP_GET_STATE((&stcb->asoc)) != SCTP_STATE_COOKIE_WAIT) {
if (SCTP_GET_STATE(stcb) != SCTP_STATE_COOKIE_WAIT) {
return (0);
}
if (sctp_threshold_management(inp, stcb, net,
@ -1057,7 +1070,7 @@ sctp_cookie_timer(struct sctp_inpcb *inp,
}
}
if (cookie == NULL) {
if (SCTP_GET_STATE(&stcb->asoc) == SCTP_STATE_COOKIE_ECHOED) {
if (SCTP_GET_STATE(stcb) == SCTP_STATE_COOKIE_ECHOED) {
/* FOOBAR! */
struct mbuf *op_err;
@ -1069,7 +1082,7 @@ sctp_cookie_timer(struct sctp_inpcb *inp,
#ifdef INVARIANTS
panic("Cookie timer expires in wrong state?");
#else
SCTP_PRINTF("Strange in state %d not cookie-echoed yet c-e timer expires?\n", SCTP_GET_STATE(&stcb->asoc));
SCTP_PRINTF("Strange in state %d not cookie-echoed yet c-e timer expires?\n", SCTP_GET_STATE(stcb));
return (0);
#endif
}
@ -1108,10 +1121,9 @@ sctp_cookie_timer(struct sctp_inpcb *inp,
}
int
sctp_strreset_timer(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
struct sctp_nets *net)
sctp_strreset_timer(struct sctp_inpcb *inp, struct sctp_tcb *stcb)
{
struct sctp_nets *alt;
struct sctp_nets *alt, *net;
struct sctp_tmit_chunk *strrst = NULL, *chk = NULL;
if (stcb->asoc.stream_reset_outstanding == 0) {
@ -1122,9 +1134,9 @@ sctp_strreset_timer(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
if (strrst == NULL) {
return (0);
}
net = strrst->whoTo;
/* do threshold management */
if (sctp_threshold_management(inp, stcb, strrst->whoTo,
stcb->asoc.max_send_times)) {
if (sctp_threshold_management(inp, stcb, net, stcb->asoc.max_send_times)) {
/* Assoc is over */
return (1);
}
@ -1132,9 +1144,8 @@ sctp_strreset_timer(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
* Cleared threshold management, now lets backoff the address
* and select an alternate
*/
sctp_backoff_on_timeout(stcb, strrst->whoTo, 1, 0, 0);
alt = sctp_find_alternate_net(stcb, strrst->whoTo, 0);
sctp_free_remote_addr(strrst->whoTo);
sctp_backoff_on_timeout(stcb, net, 1, 0, 0);
alt = sctp_find_alternate_net(stcb, net, 0);
strrst->whoTo = alt;
atomic_add_int(&alt->ref_count, 1);
@ -1159,6 +1170,8 @@ sctp_strreset_timer(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
*/
sctp_move_chunks_from_net(stcb, net);
}
sctp_free_remote_addr(net);
/* mark the retran info */
if (strrst->sent != SCTP_DATAGRAM_RESEND)
sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt);
@ -1166,7 +1179,7 @@ sctp_strreset_timer(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
strrst->flags |= CHUNK_FLAGS_FRAGMENT_OK;
/* restart the timer */
sctp_timer_start(SCTP_TIMER_TYPE_STRRESET, inp, stcb, strrst->whoTo);
sctp_timer_start(SCTP_TIMER_TYPE_STRRESET, inp, stcb, alt);
return (0);
}
@ -1191,8 +1204,9 @@ sctp_asconf_timer(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
if (asconf == NULL) {
return (0);
}
net = asconf->whoTo;
/* do threshold management */
if (sctp_threshold_management(inp, stcb, asconf->whoTo,
if (sctp_threshold_management(inp, stcb, net,
stcb->asoc.max_send_times)) {
/* Assoc is over */
return (1);
@ -1205,17 +1219,16 @@ sctp_asconf_timer(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
* Mark this peer as ASCONF incapable and cleanup.
*/
SCTPDBG(SCTP_DEBUG_TIMER1, "asconf_timer: Peer has not responded to our repeated ASCONFs\n");
sctp_asconf_cleanup(stcb, net);
sctp_asconf_cleanup(stcb);
return (0);
}
/*
* cleared threshold management, so now backoff the net and
* select an alternate
*/
sctp_backoff_on_timeout(stcb, asconf->whoTo, 1, 0, 0);
alt = sctp_find_alternate_net(stcb, asconf->whoTo, 0);
sctp_backoff_on_timeout(stcb, net, 1, 0, 0);
alt = sctp_find_alternate_net(stcb, net, 0);
if (asconf->whoTo != alt) {
sctp_free_remote_addr(asconf->whoTo);
asconf->whoTo = alt;
atomic_add_int(&alt->ref_count, 1);
}
@ -1252,6 +1265,8 @@ sctp_asconf_timer(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
*/
sctp_move_chunks_from_net(stcb, net);
}
sctp_free_remote_addr(net);
/* mark the retran info */
if (asconf->sent != SCTP_DATAGRAM_RESEND)
sctp_ucount_incr(stcb->asoc.sent_queue_retran_cnt);
@ -1266,8 +1281,7 @@ sctp_asconf_timer(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
/* Mobility adaptation */
void
sctp_delete_prim_timer(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
struct sctp_nets *net SCTP_UNUSED)
sctp_delete_prim_timer(struct sctp_inpcb *inp, struct sctp_tcb *stcb)
{
if (stcb->asoc.deleted_primary == NULL) {
SCTPDBG(SCTP_DEBUG_ASCONF1, "delete_prim_timer: deleted_primary is not stored...\n");
@ -1441,7 +1455,7 @@ sctp_heartbeat_timer(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
if ((net->last_sent_time.tv_sec > 0) ||
(net->last_sent_time.tv_usec > 0)) {
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
struct timeval diff;
SCTP_GETTIME_TIMEVAL(&diff);
@ -1487,7 +1501,7 @@ sctp_pathmtu_timer(struct sctp_inpcb *inp,
if (net->ro._l_addr.sa.sa_family == AF_INET6) {
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&net->ro._l_addr;
/* KAME hack: embed scopeid */
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
#if defined(APPLE_LEOPARD) || defined(APPLE_SNOWLEOPARD)
(void)in6_embedscope(&sin6->sin6_addr, sin6, NULL, NULL);
#else
@ -1520,7 +1534,11 @@ sctp_pathmtu_timer(struct sctp_inpcb *inp,
net->src_addr_selected = 1;
}
if (net->ro._s_addr) {
#if defined(__FreeBSD__) && !defined(__Userspace__)
mtu = SCTP_GATHER_MTU_FROM_ROUTE(net->ro._s_addr, &net->ro._s_addr.sa, net->ro.ro_nh);
#else
mtu = SCTP_GATHER_MTU_FROM_ROUTE(net->ro._s_addr, &net->ro._s_addr.sa, net->ro.ro_rt);
#endif
#if defined(INET) || defined(INET6)
if (net->port) {
mtu -= sizeof(struct udphdr);
@ -1538,16 +1556,14 @@ sctp_pathmtu_timer(struct sctp_inpcb *inp,
}
void
sctp_autoclose_timer(struct sctp_inpcb *inp,
struct sctp_tcb *stcb,
struct sctp_nets *net)
sctp_autoclose_timer(struct sctp_inpcb *inp, struct sctp_tcb *stcb)
{
struct timeval tn, *tim_touse;
struct sctp_association *asoc;
int ticks_gone_by;
uint32_t ticks_gone_by;
(void)SCTP_GETTIME_TIMEVAL(&tn);
if (stcb->asoc.sctp_autoclose_ticks &&
if (stcb->asoc.sctp_autoclose_ticks > 0 &&
sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE)) {
/* Auto close is on */
asoc = &stcb->asoc;
@ -1559,9 +1575,8 @@ sctp_autoclose_timer(struct sctp_inpcb *inp,
tim_touse = &asoc->time_last_sent;
}
/* Now has long enough transpired to autoclose? */
ticks_gone_by = SEC_TO_TICKS(tn.tv_sec - tim_touse->tv_sec);
if ((ticks_gone_by > 0) &&
(ticks_gone_by >= (int)asoc->sctp_autoclose_ticks)) {
ticks_gone_by = sctp_secs_to_ticks((uint32_t)(tn.tv_sec - tim_touse->tv_sec));
if (ticks_gone_by >= asoc->sctp_autoclose_ticks) {
/*
* autoclose time has hit, call the output routine,
* which should do nothing just to be SURE we don't
@ -1577,29 +1592,26 @@ sctp_autoclose_timer(struct sctp_inpcb *inp,
* there is nothing queued to send, so I'm
* done...
*/
if (SCTP_GET_STATE(asoc) != SCTP_STATE_SHUTDOWN_SENT) {
if (SCTP_GET_STATE(stcb) != SCTP_STATE_SHUTDOWN_SENT) {
/* only send SHUTDOWN 1st time thru */
struct sctp_nets *netp;
struct sctp_nets *net;
if ((SCTP_GET_STATE(asoc) == SCTP_STATE_OPEN) ||
(SCTP_GET_STATE(asoc) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
if ((SCTP_GET_STATE(stcb) == SCTP_STATE_OPEN) ||
(SCTP_GET_STATE(stcb) == SCTP_STATE_SHUTDOWN_RECEIVED)) {
SCTP_STAT_DECR_GAUGE32(sctps_currestab);
}
SCTP_SET_STATE(asoc, SCTP_STATE_SHUTDOWN_SENT);
SCTP_CLEAR_SUBSTATE(asoc, SCTP_STATE_SHUTDOWN_PENDING);
SCTP_SET_STATE(stcb, SCTP_STATE_SHUTDOWN_SENT);
sctp_stop_timers_for_shutdown(stcb);
if (stcb->asoc.alternate) {
netp = stcb->asoc.alternate;
net = stcb->asoc.alternate;
} else {
netp = stcb->asoc.primary_destination;
net = stcb->asoc.primary_destination;
}
sctp_send_shutdown(stcb, netp);
sctp_send_shutdown(stcb, net);
sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWN,
stcb->sctp_ep, stcb,
netp);
stcb->sctp_ep, stcb, net);
sctp_timer_start(SCTP_TIMER_TYPE_SHUTDOWNGUARD,
stcb->sctp_ep, stcb,
netp);
stcb->sctp_ep, stcb, NULL);
}
}
} else {
@ -1607,13 +1619,12 @@ sctp_autoclose_timer(struct sctp_inpcb *inp,
* No auto close at this time, reset t-o to check
* later
*/
int tmp;
uint32_t tmp;
/* fool the timer startup to use the time left */
tmp = asoc->sctp_autoclose_ticks;
asoc->sctp_autoclose_ticks -= ticks_gone_by;
sctp_timer_start(SCTP_TIMER_TYPE_AUTOCLOSE, inp, stcb,
net);
sctp_timer_start(SCTP_TIMER_TYPE_AUTOCLOSE, inp, stcb, NULL);
/* restore the real tick value */
asoc->sctp_autoclose_ticks = tmp;
}

View File

@ -32,9 +32,9 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_timer.h 295709 2016-02-17 18:04:22Z tuexen $");
__FBSDID("$FreeBSD: head/sys/netinet/sctp_timer.h 359195 2020-03-21 16:12:19Z tuexen $");
#endif
#ifndef _NETINET_SCTP_TIMER_H_
@ -46,18 +46,20 @@ __FBSDID("$FreeBSD: head/sys/netinet/sctp_timer.h 295709 2016-02-17 18:04:22Z tu
#define SCTP_RTT_VAR_SHIFT 2
struct sctp_nets *
sctp_find_alternate_net(struct sctp_tcb *,
struct sctp_nets *, int mode);
sctp_find_alternate_net(struct sctp_tcb *, struct sctp_nets *, int);
int
sctp_t3rxt_timer(struct sctp_inpcb *, struct sctp_tcb *,
struct sctp_nets *);
int
sctp_t1init_timer(struct sctp_inpcb *, struct sctp_tcb *,
struct sctp_nets *);
int
sctp_shutdown_timer(struct sctp_inpcb *, struct sctp_tcb *,
struct sctp_nets *);
int
sctp_heartbeat_timer(struct sctp_inpcb *, struct sctp_tcb *,
struct sctp_nets *);
@ -74,26 +76,23 @@ int
sctp_shutdownack_timer(struct sctp_inpcb *, struct sctp_tcb *,
struct sctp_nets *);
int
sctp_strreset_timer(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
struct sctp_nets *net);
sctp_strreset_timer(struct sctp_inpcb *, struct sctp_tcb *);
int
sctp_asconf_timer(struct sctp_inpcb *, struct sctp_tcb *,
struct sctp_nets *);
void
sctp_delete_prim_timer(struct sctp_inpcb *, struct sctp_tcb *,
struct sctp_nets *);
sctp_delete_prim_timer(struct sctp_inpcb *, struct sctp_tcb *);
void
sctp_autoclose_timer(struct sctp_inpcb *, struct sctp_tcb *,
struct sctp_nets *net);
sctp_autoclose_timer(struct sctp_inpcb *, struct sctp_tcb *);
void sctp_audit_retranmission_queue(struct sctp_association *);
void sctp_iterator_timer(struct sctp_iterator *it);
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
#if defined(APPLE_LEOPARD) || defined(APPLE_SNOWLEOPARD) || defined(APPLE_LION) || defined(APPLE_MOUNTAINLION)
void sctp_slowtimo(void);
#else

View File

@ -32,29 +32,29 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_uio.h 323505 2017-09-12 21:08:50Z tuexen $");
__FBSDID("$FreeBSD: head/sys/netinet/sctp_uio.h 362473 2020-06-21 23:12:56Z tuexen $");
#endif
#ifndef _NETINET_SCTP_UIO_H_
#define _NETINET_SCTP_UIO_H_
#if (defined(__APPLE__) && defined(KERNEL))
#if (defined(__APPLE__) && !defined(__Userspace__) && defined(KERNEL))
#ifndef _KERNEL
#define _KERNEL
#endif
#endif
#if !(defined(__Windows__)) && !defined(__Userspace_os_Windows)
#if ! defined(_KERNEL)
#if !defined(_WIN32)
#if !defined(_KERNEL)
#include <stdint.h>
#endif
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#endif
#if defined(__Windows__)
#if defined(_WIN32) && !defined(__Userspace__)
#pragma warning(push)
#pragma warning(disable: 4200)
#if defined(_KERNEL)
@ -110,14 +110,8 @@ struct sctp_event_subscribe {
* ancillary data structures
*/
struct sctp_initmsg {
#if defined(__FreeBSD__) && __FreeBSD_version < 800000
/* This is a bug. Not fixed for ABI compatibility */
uint32_t sinit_num_ostreams;
uint32_t sinit_max_instreams;
#else
uint16_t sinit_num_ostreams;
uint16_t sinit_max_instreams;
#endif
uint16_t sinit_max_attempts;
uint16_t sinit_max_init_timeo;
};
@ -143,9 +137,6 @@ struct sctp_sndrcvinfo {
uint16_t sinfo_stream;
uint16_t sinfo_ssn;
uint16_t sinfo_flags;
#if defined(__FreeBSD__) && __FreeBSD_version < 800000
uint16_t sinfo_pr_policy;
#endif
uint32_t sinfo_ppid;
uint32_t sinfo_context;
uint32_t sinfo_timetolive;
@ -161,9 +152,6 @@ struct sctp_extrcvinfo {
uint16_t sinfo_stream;
uint16_t sinfo_ssn;
uint16_t sinfo_flags;
#if defined(__FreeBSD__) && __FreeBSD_version < 800000
uint16_t sinfo_pr_policy;
#endif
uint32_t sinfo_ppid;
uint32_t sinfo_context;
uint32_t sinfo_timetolive; /* should have been sinfo_pr_value */
@ -662,10 +650,18 @@ struct sctp_setpeerprim {
uint8_t sspp_padding[4];
};
union sctp_sockstore {
struct sockaddr_in sin;
struct sockaddr_in6 sin6;
#if defined(__Userspace__)
struct sockaddr_conn sconn;
#endif
struct sockaddr sa;
};
struct sctp_getaddresses {
sctp_assoc_t sget_assoc_id;
/* addr is filled in for N * sockaddr_storage */
struct sockaddr addr[1];
union sctp_sockstore addr[];
};
struct sctp_status {
@ -1012,7 +1008,7 @@ struct sctpstat {
uint32_t sctps_recvauthfailed; /* total number of auth failed */
uint32_t sctps_recvexpress; /* total fast path receives all one chunk */
uint32_t sctps_recvexpressm; /* total fast path multi-part data */
uint32_t sctps_recvnocrc;
uint32_t sctps_recv_spare; /* formerly sctps_recvnocrc */
uint32_t sctps_recvswcrc;
uint32_t sctps_recvhwcrc;
@ -1023,13 +1019,13 @@ struct sctpstat {
uint32_t sctps_sendretransdata; /* total output retransmitted DATA chunks */
uint32_t sctps_sendfastretrans; /* total output fast retransmitted DATA chunks */
uint32_t sctps_sendmultfastretrans; /* total FR's that happened more than once
* to same chunk (u-del multi-fr algo).
*/
* to same chunk (u-del multi-fr algo).
*/
uint32_t sctps_sendheartbeat; /* total output HB chunks */
uint32_t sctps_sendecne; /* total output ECNE chunks */
uint32_t sctps_sendauth; /* total output AUTH chunks FIXME */
uint32_t sctps_senderrors; /* ip_output error counter */
uint32_t sctps_sendnocrc;
uint32_t sctps_senderrors; /* ip_output error counter */
uint32_t sctps_send_spare; /* formerly sctps_sendnocrc */
uint32_t sctps_sendswcrc;
uint32_t sctps_sendhwcrc;
/* PCKDROPREP statistics: */
@ -1121,13 +1117,18 @@ struct sctpstat {
#define SCTP_STAT_INCR(_x) SCTP_STAT_INCR_BY(_x,1)
#define SCTP_STAT_DECR(_x) SCTP_STAT_DECR_BY(_x,1)
#if defined(__FreeBSD__) && defined(SMP) && defined(SCTP_USE_PERCPU_STAT)
#if defined(__FreeBSD__) && !defined(__Userspace__)
#if defined(SMP) && defined(SCTP_USE_PERCPU_STAT)
#define SCTP_STAT_INCR_BY(_x,_d) (SCTP_BASE_STATS[PCPU_GET(cpuid)]._x += _d)
#define SCTP_STAT_DECR_BY(_x,_d) (SCTP_BASE_STATS[PCPU_GET(cpuid)]._x -= _d)
#else
#define SCTP_STAT_INCR_BY(_x,_d) atomic_add_int(&SCTP_BASE_STAT(_x), _d)
#define SCTP_STAT_DECR_BY(_x,_d) atomic_subtract_int(&SCTP_BASE_STAT(_x), _d)
#endif
#else
#define SCTP_STAT_INCR_BY(_x,_d) atomic_add_int(&SCTP_BASE_STAT(_x), _d)
#define SCTP_STAT_DECR_BY(_x,_d) atomic_subtract_int(&SCTP_BASE_STAT(_x), _d)
#endif
/* The following macros are for handling MIB values, */
#define SCTP_STAT_INCR_COUNTER32(_x) SCTP_STAT_INCR(_x)
#define SCTP_STAT_INCR_COUNTER64(_x) SCTP_STAT_INCR(_x)
@ -1136,34 +1137,15 @@ struct sctpstat {
#define SCTP_STAT_DECR_COUNTER64(_x) SCTP_STAT_DECR(_x)
#define SCTP_STAT_DECR_GAUGE32(_x) SCTP_STAT_DECR(_x)
#if defined(__Userspace__)
union sctp_sockstore {
#if defined(INET)
struct sockaddr_in sin;
#endif
#if defined(INET6)
struct sockaddr_in6 sin6;
#endif
struct sockaddr_conn sconn;
struct sockaddr sa;
};
#else
union sctp_sockstore {
struct sockaddr_in sin;
struct sockaddr_in6 sin6;
struct sockaddr sa;
};
#endif
/***********************************/
/* And something for us old timers */
/***********************************/
#ifndef __APPLE__
#ifndef __Userspace__
#if !(defined(__APPLE__) && !defined(__Userspace__))
#if !defined(__Userspace__)
#ifndef ntohll
#if defined(__Userspace_os_Linux)
#if defined(__linux__)
#ifndef _BSD_SOURCE
#define _BSD_SOURCE
#endif
@ -1175,7 +1157,7 @@ union sctp_sockstore {
#endif
#ifndef htonll
#if defined(__Userspace_os_Linux)
#if defined(__linux__)
#ifndef _BSD_SOURCE
#define _BSD_SOURCE
#endif
@ -1193,52 +1175,30 @@ union sctp_sockstore {
struct xsctp_inpcb {
uint32_t last;
uint32_t flags;
#if defined(__FreeBSD__) && __FreeBSD_version < 1000048
uint32_t features;
#else
uint64_t features;
#endif
uint32_t total_sends;
uint32_t total_recvs;
uint32_t total_nospaces;
uint32_t fragmentation_point;
uint16_t local_port;
#if defined(__FreeBSD__) && __FreeBSD_version > 1100096
#if defined(__FreeBSD__) && !defined(__Userspace__)
uint16_t qlen_old;
uint16_t maxqlen_old;
#else
uint16_t qlen;
uint16_t maxqlen;
#endif
#if defined(__Windows__)
uint16_t padding;
#endif
#if !(defined(__FreeBSD__) && (__FreeBSD_version < 1001517))
uint16_t __spare16;
#if defined(__FreeBSD__) && !defined(__Userspace__)
kvaddr_t socket;
#else
void *socket;
#endif
#if defined(__FreeBSD__) && __FreeBSD_version > 1100096
#if defined(__FreeBSD__) && !defined(__Userspace__)
uint32_t qlen;
uint32_t maxqlen;
#endif
#if defined(__FreeBSD__) && __FreeBSD_version < 1000048
uint32_t extra_padding[32]; /* future */
#elif defined(__FreeBSD__) && (__FreeBSD_version < 1001517)
uint32_t extra_padding[31]; /* future */
#else
#if defined(__LP64__)
#if defined(__FreeBSD__) && __FreeBSD_version > 1100096
uint32_t extra_padding[27]; /* future */
#else
uint32_t extra_padding[29]; /* future */
#endif
#else
#if defined(__FreeBSD__) && __FreeBSD_version > 1100096
uint32_t extra_padding[28]; /* future */
#else
uint32_t extra_padding[30]; /* future */
#endif
#endif
#endif
uint32_t extra_padding[26]; /* future */
};
struct xsctp_tcb {
@ -1267,18 +1227,9 @@ struct xsctp_tcb {
uint16_t remote_port; /* sctpAssocEntry 4 */
struct sctp_timeval start_time; /* sctpAssocEntry 16 */
struct sctp_timeval discontinuity_time; /* sctpAssocEntry 17 */
#if defined(__FreeBSD__)
#if __FreeBSD_version >= 800000
uint32_t peers_rwnd;
sctp_assoc_t assoc_id; /* sctpAssocEntry 1 */
uint32_t extra_padding[32]; /* future */
#else
#endif
#else
uint32_t peers_rwnd;
sctp_assoc_t assoc_id; /* sctpAssocEntry 1 */
uint32_t extra_padding[32]; /* future */
#endif
};
struct xsctp_laddr {
@ -1303,23 +1254,12 @@ struct xsctp_raddr {
uint8_t heartbeat_enabled; /* sctpAssocLocalRemEntry 4 */
uint8_t potentially_failed;
struct sctp_timeval start_time; /* sctpAssocLocalRemEntry 8 */
#if defined(__FreeBSD__)
#if __FreeBSD_version >= 800000
uint32_t rtt;
uint32_t heartbeat_interval;
uint32_t ssthresh;
uint16_t encaps_port;
uint16_t state;
uint32_t extra_padding[29]; /* future */
#endif
#else
uint32_t rtt;
uint32_t heartbeat_interval;
uint32_t ssthresh;
uint16_t encaps_port;
uint16_t state;
uint32_t extra_padding[29]; /* future */
#endif
};
#define SCTP_MAX_LOGGING_SIZE 30000
@ -1346,19 +1286,14 @@ int
sctp_lower_sosend(struct socket *so,
struct sockaddr *addr,
struct uio *uio,
#if defined(__Panda__)
pakhandle_type i_pak,
pakhandle_type i_control,
#else
struct mbuf *i_pak,
struct mbuf *control,
#endif
int flags,
struct sctp_sndrcvinfo *srcv
#if !(defined(__Panda__) || defined(__Userspace__))
#if defined(__FreeBSD__) && __FreeBSD_version >= 500000
#if !defined(__Userspace__)
#if defined(__FreeBSD__)
,struct thread *p
#elif defined(__Windows__)
#elif defined(_WIN32)
, PKTHREAD p
#else
,struct proc *p
@ -1369,11 +1304,7 @@ sctp_lower_sosend(struct socket *so,
int
sctp_sorecvmsg(struct socket *so,
struct uio *uio,
#if defined(__Panda__)
particletype **mp,
#else
struct mbuf **mp,
#endif
struct sockaddr *from,
int fromlen,
int *msg_flags,
@ -1387,45 +1318,6 @@ sctp_sorecvmsg(struct socket *so,
#if !(defined(_KERNEL)) && !(defined(__Userspace__))
__BEGIN_DECLS
#if defined(__FreeBSD__) && __FreeBSD_version < 902000
int sctp_peeloff __P((int, sctp_assoc_t));
int sctp_bindx __P((int, struct sockaddr *, int, int));
int sctp_connectx __P((int, const struct sockaddr *, int, sctp_assoc_t *));
int sctp_getaddrlen __P((sa_family_t));
int sctp_getpaddrs __P((int, sctp_assoc_t, struct sockaddr **));
void sctp_freepaddrs __P((struct sockaddr *));
int sctp_getladdrs __P((int, sctp_assoc_t, struct sockaddr **));
void sctp_freeladdrs __P((struct sockaddr *));
int sctp_opt_info __P((int, sctp_assoc_t, int, void *, socklen_t *));
/* deprecated */
ssize_t sctp_sendmsg __P((int, const void *, size_t, const struct sockaddr *,
socklen_t, uint32_t, uint32_t, uint16_t, uint32_t, uint32_t));
/* deprecated */
ssize_t sctp_send __P((int, const void *, size_t,
const struct sctp_sndrcvinfo *, int));
/* deprecated */
ssize_t sctp_sendx __P((int, const void *, size_t, struct sockaddr *,
int, struct sctp_sndrcvinfo *, int));
/* deprecated */
ssize_t sctp_sendmsgx __P((int sd, const void *, size_t, struct sockaddr *,
int, uint32_t, uint32_t, uint16_t, uint32_t, uint32_t));
sctp_assoc_t sctp_getassocid __P((int, struct sockaddr *));
/* deprecated */
ssize_t sctp_recvmsg __P((int, void *, size_t, struct sockaddr *, socklen_t *,
struct sctp_sndrcvinfo *, int *));
ssize_t sctp_sendv __P((int, const struct iovec *, int, struct sockaddr *,
int, void *, socklen_t, unsigned int, int));
ssize_t sctp_recvv __P((int, const struct iovec *, int, struct sockaddr *,
socklen_t *, void *, socklen_t *, unsigned int *, int *));
#else
int sctp_peeloff(int, sctp_assoc_t);
int sctp_bindx(int, struct sockaddr *, int, int);
int sctp_connectx(int, const struct sockaddr *, int, sctp_assoc_t *);
@ -1463,7 +1355,6 @@ ssize_t sctp_sendv(int, const struct iovec *, int, struct sockaddr *,
ssize_t sctp_recvv(int, const struct iovec *, int, struct sockaddr *,
socklen_t *, void *, socklen_t *, unsigned int *, int *);
#endif
__END_DECLS
#endif /* !_KERNEL */

View File

@ -31,21 +31,27 @@
#include <netinet/sctp_pcb.h>
#include <sys/timeb.h>
#include <iphlpapi.h>
#if !defined(__MINGW32__)
#pragma comment(lib, "IPHLPAPI.lib")
#endif
#endif
#include <netinet/sctp_os_userspace.h>
#if defined(__Userspace_os_FreeBSD)
#if defined(__FreeBSD__)
#include <pthread_np.h>
#endif
#if defined(__Userspace_os_Linux)
#if defined(__linux__)
#include <sys/prctl.h>
#endif
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
/* Adapter to translate Unix thread start routines to Windows thread start
* routines.
*/
#if defined(__MINGW32__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpedantic"
#endif
static DWORD WINAPI
sctp_create_thread_adapter(void *arg) {
start_routine_t start_routine = (start_routine_t)arg;
@ -62,18 +68,9 @@ sctp_userspace_thread_create(userland_thread_t *thread, start_routine_t start_ro
return 0;
}
int
sctp_userspace_thread_id(userland_thread_id_t *thread)
{
*thread = GetCurrentThreadId();
return 0;
}
int
sctp_userspace_thread_equal(userland_thread_id_t t1, userland_thread_id_t t2)
{
return (t1 == t2);
}
#if defined(__MINGW32__)
#pragma GCC diagnostic pop
#endif
#else
int
@ -81,36 +78,23 @@ sctp_userspace_thread_create(userland_thread_t *thread, start_routine_t start_ro
{
return pthread_create(thread, NULL, start_routine, NULL);
}
int
sctp_userspace_thread_id(userland_thread_id_t *thread)
{
*thread = pthread_self();
return 0;
}
int
sctp_userspace_thread_equal(userland_thread_id_t t1, userland_thread_id_t t2)
{
return pthread_equal(t1, t2);
}
#endif
void
sctp_userspace_set_threadname(const char *name)
{
#if defined(__Userspace_os_Darwin)
#if defined(__APPLE__)
pthread_setname_np(name);
#endif
#if defined(__Userspace_os_Linux)
#if defined(__linux__)
prctl(PR_SET_NAME, name);
#endif
#if defined(__Userspace_os_FreeBSD)
#if defined(__FreeBSD__)
pthread_set_name_np(pthread_self(), name);
#endif
}
#if !defined(_WIN32) && !defined(__Userspace_os_NaCl)
#if !defined(_WIN32) && !defined(__native_client__)
int
sctp_userspace_get_mtu_from_ifn(uint32_t if_index, int af)
{
@ -134,7 +118,7 @@ sctp_userspace_get_mtu_from_ifn(uint32_t if_index, int af)
}
#endif
#if defined(__Userspace_os_NaCl)
#if defined(__native_client__)
int
sctp_userspace_get_mtu_from_ifn(uint32_t if_index, int af)
{
@ -142,6 +126,19 @@ sctp_userspace_get_mtu_from_ifn(uint32_t if_index, int af)
}
#endif
#if defined(__APPLE__) || defined(__DragonFly__) || defined(__linux__) || defined(__native_client__) || defined(__NetBSD__) || defined(_WIN32) || defined(__Fuchsia__)
int
timingsafe_bcmp(const void *b1, const void *b2, size_t n)
{
const unsigned char *p1 = b1, *p2 = b2;
int ret = 0;
for (; n > 0; n--)
ret |= *p1++ ^ *p2++;
return (ret != 0);
}
#endif
#ifdef _WIN32
int
sctp_userspace_get_mtu_from_ifn(uint32_t if_index, int af)
@ -186,11 +183,29 @@ cleanup:
void
getwintimeofday(struct timeval *tv)
{
struct timeb tb;
FILETIME filetime;
ULARGE_INTEGER ularge;
ftime(&tb);
tv->tv_sec = (long)tb.time;
tv->tv_usec = (long)(tb.millitm) * 1000L;
GetSystemTimeAsFileTime(&filetime);
ularge.LowPart = filetime.dwLowDateTime;
ularge.HighPart = filetime.dwHighDateTime;
/* Change base from Jan 1 1601 00:00:00 to Jan 1 1970 00:00:00 */
#if defined(__MINGW32__)
ularge.QuadPart -= 116444736000000000ULL;
#else
ularge.QuadPart -= 116444736000000000UI64;
#endif
/*
* ularge.QuadPart is now the number of 100-nanosecond intervals
* since Jan 1 1970 00:00:00.
*/
#if defined(__MINGW32__)
tv->tv_sec = (long)(ularge.QuadPart / 10000000ULL);
tv->tv_usec = (long)((ularge.QuadPart % 10000000ULL) / 10ULL);
#else
tv->tv_sec = (long)(ularge.QuadPart / 10000000UI64);
tv->tv_usec = (long)((ularge.QuadPart % 10000000UI64) / 10UI64);
#endif
}
int

File diff suppressed because it is too large Load Diff

View File

@ -32,9 +32,9 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_var.h 317457 2017-04-26 19:26:40Z tuexen $");
__FBSDID("$FreeBSD: head/sys/netinet/sctp_var.h 360292 2020-04-25 09:06:11Z melifaro $");
#endif
#ifndef _NETINET_SCTP_VAR_H_
@ -44,7 +44,7 @@ __FBSDID("$FreeBSD: head/sys/netinet/sctp_var.h 317457 2017-04-26 19:26:40Z tuex
#if defined(_KERNEL) || defined(__Userspace__)
#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__)
#if !defined(__Userspace__)
extern struct pr_usrreqs sctp_usrreqs;
#endif
@ -186,18 +186,13 @@ extern struct pr_usrreqs sctp_usrreqs;
} \
}
#if defined(__FreeBSD__) && __FreeBSD_version > 500000
#if defined(__FreeBSD__) && !defined(__Userspace__)
#define sctp_free_remote_addr(__net) { \
if ((__net)) { \
if (SCTP_DECREMENT_AND_CHECK_REFCOUNT(&(__net)->ref_count)) { \
(void)SCTP_OS_TIMER_STOP(&(__net)->rxt_timer.timer); \
(void)SCTP_OS_TIMER_STOP(&(__net)->pmtu_timer.timer); \
(void)SCTP_OS_TIMER_STOP(&(__net)->hb_timer.timer); \
if ((__net)->ro.ro_rt) { \
RTFREE((__net)->ro.ro_rt); \
(__net)->ro.ro_rt = NULL; \
} \
RO_NHFREE(&(__net)->ro); \
if ((__net)->src_addr_selected) { \
sctp_free_ifa((__net)->ro._s_addr); \
(__net)->ro._s_addr = NULL; \
@ -240,8 +235,6 @@ extern struct pr_usrreqs sctp_usrreqs;
if ((__net)) { \
if (SCTP_DECREMENT_AND_CHECK_REFCOUNT(&(__net)->ref_count)) { \
(void)SCTP_OS_TIMER_STOP(&(__net)->rxt_timer.timer); \
(void)SCTP_OS_TIMER_STOP(&(__net)->pmtu_timer.timer); \
(void)SCTP_OS_TIMER_STOP(&(__net)->hb_timer.timer); \
if ((__net)->ro.ro_rt) { \
RTFREE((__net)->ro.ro_rt); \
(__net)->ro.ro_rt = NULL; \
@ -258,31 +251,6 @@ extern struct pr_usrreqs sctp_usrreqs;
} \
}
#if defined(__Panda__)
#define sctp_sbfree(ctl, stcb, sb, m) { \
if ((sb)->sb_cc >= (uint32_t)SCTP_BUF_LEN((m))) { \
atomic_subtract_int(&(sb)->sb_cc, SCTP_BUF_LEN((m))); \
} else { \
(sb)->sb_cc = 0; \
} \
if (((ctl)->do_not_ref_stcb == 0) && stcb) { \
if ((stcb)->asoc.sb_cc >= (uint32_t)SCTP_BUF_LEN((m))) { \
atomic_subtract_int(&(stcb)->asoc.sb_cc, SCTP_BUF_LEN((m))); \
} else { \
(stcb)->asoc.sb_cc = 0; \
} \
} \
}
#define sctp_sballoc(stcb, sb, m) { \
atomic_add_int(&(sb)->sb_cc, SCTP_BUF_LEN((m))); \
if (stcb) { \
atomic_add_int(&(stcb)->asoc.sb_cc, SCTP_BUF_LEN((m))); \
} \
}
#else
#define sctp_sbfree(ctl, stcb, sb, m) { \
SCTP_SAVE_ATOMIC_DECREMENT(&(sb)->sb_cc, SCTP_BUF_LEN((m))); \
SCTP_SAVE_ATOMIC_DECREMENT(&(sb)->sb_mbcnt, MSIZE); \
@ -301,7 +269,6 @@ extern struct pr_usrreqs sctp_usrreqs;
} \
}
#endif
#endif
#define sctp_ucount_incr(val) { \
val++; \
@ -403,38 +370,30 @@ struct sctp_tcb;
struct sctphdr;
#if (defined(__FreeBSD__) && __FreeBSD_version > 690000) || defined(__Windows__) || defined(__Userspace__)
#if defined(__FreeBSD__) || defined(_WIN32) || defined(__Userspace__)
void sctp_close(struct socket *so);
#else
int sctp_detach(struct socket *so);
#endif
int sctp_disconnect(struct socket *so);
#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__)
#if defined(__FreeBSD__) && __FreeBSD_version < 902000
void sctp_ctlinput __P((int, struct sockaddr *, void *));
int sctp_ctloutput __P((struct socket *, struct sockopt *));
#ifdef INET
void sctp_input_with_port __P((struct mbuf *, int, uint16_t));
void sctp_input __P((struct mbuf *, int));
#endif
void sctp_pathmtu_adjustment __P((struct sctp_tcb *, uint16_t));
#if !defined(__Userspace__)
#if defined(__APPLE__) && !defined(APPLE_LEOPARD) && !defined(APPLE_SNOWLEOPARD) && !defined(APPLE_LION) && !defined(APPLE_MOUNTAINLION) && !defined(APPLE_ELCAPITAN)
void sctp_ctlinput(int, struct sockaddr *, void *, struct ifnet * SCTP_UNUSED);
#else
void sctp_ctlinput(int, struct sockaddr *, void *);
#endif
int sctp_ctloutput(struct socket *, struct sockopt *);
#ifdef INET
void sctp_input_with_port(struct mbuf *, int, uint16_t);
#if defined(__FreeBSD__) && __FreeBSD_version >= 1100020
#if defined(__FreeBSD__) && !defined(__Userspace__)
int sctp_input(struct mbuf **, int *, int);
#else
void sctp_input(struct mbuf *, int);
#endif
#endif
void sctp_pathmtu_adjustment(struct sctp_tcb *, uint16_t);
#endif
#else
#if defined(__Panda__)
void sctp_input(pakhandle_type i_pak);
#elif defined(__Userspace__)
#if defined(__Userspace__)
void sctp_pathmtu_adjustment(struct sctp_tcb *, uint16_t);
#else
void sctp_input(struct mbuf *,...);
@ -442,17 +401,11 @@ void sctp_input(struct mbuf *,...);
void *sctp_ctlinput(int, struct sockaddr *, void *);
int sctp_ctloutput(int, struct socket *, int, int, struct mbuf **);
#endif
#if defined(__FreeBSD__) && __FreeBSD_version < 902000
void sctp_drain __P((void));
#else
void sctp_drain(void);
#endif
#if defined(__Userspace__)
void sctp_init(uint16_t,
int (*)(void *addr, void *buffer, size_t length, uint8_t tos, uint8_t set_df),
void (*)(const char *, ...));
#elif defined(__FreeBSD__) && __FreeBSD_version < 902000
void sctp_init __P((void));
void (*)(const char *, ...), int start_threads);
#elif defined(__APPLE__) && (!defined(APPLE_LEOPARD) && !defined(APPLE_SNOWLEOPARD) &&!defined(APPLE_LION) && !defined(APPLE_MOUNTAINLION))
void sctp_init(struct protosw *pp, struct domain *dp);
#else
@ -460,55 +413,37 @@ void sctp_init(void);
void sctp_notify(struct sctp_inpcb *, struct sctp_tcb *, struct sctp_nets *,
uint8_t, uint8_t, uint16_t, uint32_t);
#endif
#if !defined(__FreeBSD__)
#if !defined(__FreeBSD__) && !defined(__Userspace__)
void sctp_finish(void);
#endif
#if defined(__FreeBSD__) || defined(__Windows__) || defined(__Userspace__)
#if defined(__FreeBSD__) || defined(_WIN32) || defined(__Userspace__)
int sctp_flush(struct socket *, int);
#endif
#if defined(__FreeBSD__) && __FreeBSD_version < 902000
int sctp_shutdown __P((struct socket *));
#else
int sctp_shutdown(struct socket *);
#endif
int sctp_bindx(struct socket *, int, struct sockaddr_storage *,
int, int, struct proc *);
/* can't use sctp_assoc_t here */
int sctp_peeloff(struct socket *, struct socket *, int, caddr_t, int *);
#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__)
#if !defined(__Userspace__)
int sctp_ingetaddr(struct socket *, struct sockaddr **);
#elif defined(__Panda__)
int sctp_ingetaddr(struct socket *, struct sockaddr *);
#else
int sctp_ingetaddr(struct socket *, struct mbuf *);
#endif
#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__)
#if !defined(__Userspace__)
int sctp_peeraddr(struct socket *, struct sockaddr **);
#elif defined(__Panda__)
int sctp_peeraddr(struct socket *, struct sockaddr *);
#else
int sctp_peeraddr(struct socket *, struct mbuf *);
#endif
#if defined(__FreeBSD__) && __FreeBSD_version >= 500000
#if __FreeBSD_version >= 700000
#if defined(__FreeBSD__) && !defined(__Userspace__)
int sctp_listen(struct socket *, int, struct thread *);
#else
int sctp_listen(struct socket *, struct thread *);
#endif
#elif defined(__Windows__)
#elif defined(_WIN32) && !defined(__Userspace__)
int sctp_listen(struct socket *, int, PKTHREAD);
#elif defined(__Userspace__)
int sctp_listen(struct socket *, int, struct proc *);
#else
int sctp_listen(struct socket *, struct proc *);
#endif
#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__Windows__) || defined(__Userspace__)
int sctp_accept(struct socket *, struct sockaddr **);
#elif defined(__Panda__)
int sctp_accept(struct socket *, struct sockaddr *, int *, void *, int *);
#else
int sctp_accept(struct socket *, struct mbuf *);
#endif
#endif /* _KERNEL */

File diff suppressed because it is too large Load Diff

View File

@ -32,9 +32,9 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctputil.h 324615 2017-10-14 10:02:59Z tuexen $");
__FBSDID("$FreeBSD: head/sys/netinet/sctputil.h 362448 2020-06-20 20:20:16Z tuexen $");
#endif
#ifndef _NETINET_SCTP_UTIL_H_
@ -57,7 +57,7 @@ void sctp_m_freem(struct mbuf *m);
#define sctp_m_freem m_freem
#endif
#if defined(SCTP_LOCAL_TRACE_BUF) || defined(__APPLE__)
#if defined(SCTP_LOCAL_TRACE_BUF)
void
sctp_log_trace(uint32_t fr, const char *str SCTP_UNUSED, uint32_t a, uint32_t b, uint32_t c, uint32_t d, uint32_t e, uint32_t f);
#endif
@ -111,7 +111,7 @@ sctp_mtu_size_reset(struct sctp_inpcb *, struct sctp_association *, uint32_t);
void
sctp_wakeup_the_read_socket(struct sctp_inpcb *inp, struct sctp_tcb *stcb,
int so_locked
#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
#if !(defined(__APPLE__) && !defined(__Userspace__))
SCTP_UNUSED
#endif
);
@ -130,11 +130,7 @@ sctp_add_to_readq(struct sctp_inpcb *inp,
struct sockbuf *sb,
int end,
int inpread_locked,
int so_locked
#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
SCTP_UNUSED
#endif
);
int so_locked);
void sctp_iterator_worker(void);
@ -144,7 +140,7 @@ uint32_t sctp_get_next_mtu(uint32_t);
void
sctp_timeout_handler(void *);
uint32_t
int
sctp_calculate_rto(struct sctp_tcb *, struct sctp_association *,
struct sctp_nets *, struct timeval *, int);
@ -162,11 +158,7 @@ sctp_add_pad_tombuf(struct mbuf *, int);
struct mbuf *
sctp_pad_lastmbuf(struct mbuf *, int, struct mbuf *);
void sctp_ulp_notify(uint32_t, struct sctp_tcb *, uint32_t, void *, int
#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
SCTP_UNUSED
#endif
);
void sctp_ulp_notify(uint32_t, struct sctp_tcb *, uint32_t, void *, int);
void
sctp_pull_off_control_to_new_inp(struct sctp_inpcb *old_inp,
@ -176,27 +168,22 @@ sctp_pull_off_control_to_new_inp(struct sctp_inpcb *old_inp,
void sctp_stop_timers_for_shutdown(struct sctp_tcb *);
void sctp_report_all_outbound(struct sctp_tcb *, uint16_t, int, int
#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
SCTP_UNUSED
#endif
);
/* Stop all timers for association and remote addresses. */
void sctp_stop_association_timers(struct sctp_tcb *, bool);
void sctp_report_all_outbound(struct sctp_tcb *, uint16_t, int, int);
int sctp_expand_mapping_array(struct sctp_association *, uint32_t);
void sctp_abort_notification(struct sctp_tcb *, uint8_t, uint16_t,
struct sctp_abort_chunk *, int
#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
SCTP_UNUSED
#endif
);
struct sctp_abort_chunk *, int);
/* We abort responding to an IP packet for some reason */
void
sctp_abort_association(struct sctp_inpcb *, struct sctp_tcb *, struct mbuf *,
int, struct sockaddr *, struct sockaddr *,
struct sctphdr *, struct mbuf *,
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
uint8_t, uint32_t,
#endif
uint32_t, uint16_t);
@ -205,17 +192,13 @@ sctp_abort_association(struct sctp_inpcb *, struct sctp_tcb *, struct mbuf *,
/* We choose to abort via user input */
void
sctp_abort_an_association(struct sctp_inpcb *, struct sctp_tcb *,
struct mbuf *, int
#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
SCTP_UNUSED
#endif
);
struct mbuf *, int);
void sctp_handle_ootb(struct mbuf *, int, int,
struct sockaddr *, struct sockaddr *,
struct sctphdr *, struct sctp_inpcb *,
struct mbuf *,
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
uint8_t, uint32_t, uint16_t,
#endif
uint32_t, uint16_t);
@ -223,10 +206,9 @@ void sctp_handle_ootb(struct mbuf *, int, int,
int sctp_connectx_helper_add(struct sctp_tcb *stcb, struct sockaddr *addr,
int totaddr, int *error);
struct sctp_tcb *
sctp_connectx_helper_find(struct sctp_inpcb *inp, struct sockaddr *addr,
unsigned int *totaddr, unsigned int *num_v4, unsigned int *num_v6,
int *error, unsigned int limit, int *bad_addr);
int
sctp_connectx_helper_find(struct sctp_inpcb *, struct sockaddr *,
unsigned int, unsigned int *, unsigned int *, unsigned int);
int sctp_is_there_an_abort_here(struct mbuf *, int, uint32_t *);
#ifdef INET6
@ -277,21 +259,16 @@ void sctp_print_address(struct sockaddr *);
int
sctp_release_pr_sctp_chunk(struct sctp_tcb *, struct sctp_tmit_chunk *,
uint8_t, int
#if !defined(__APPLE__) && !defined(SCTP_SO_LOCK_TESTING)
SCTP_UNUSED
#endif
);
uint8_t, int);
struct mbuf *sctp_generate_cause(uint16_t, char *);
struct mbuf *sctp_generate_no_user_data_cause(uint32_t);
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);
void sctp_bindx_delete_address(struct sctp_inpcb *inp,
struct sockaddr *sa, sctp_assoc_t assoc_id,
uint32_t vrf_id, int *error);
struct sockaddr *sa, uint32_t vrf_id, int *error,
void *p);
void sctp_bindx_delete_address(struct sctp_inpcb *inp, struct sockaddr *sa,
uint32_t vrf_id, int *error);
int sctp_local_addr_count(struct sctp_tcb *stcb);
@ -353,11 +330,11 @@ do { \
} while (0)
/* functions to start/stop udp tunneling */
#if defined(__APPLE__) || defined(__FreeBSD__)
#if (defined(__APPLE__) || defined(__FreeBSD__)) && !defined(__Userspace__)
void sctp_over_udp_stop(void);
int sctp_over_udp_start(void);
#endif
#if defined(__Windows__)
#if defined(_WIN32) && !defined(__Userspace__)
void sctp_over_udp_restart(void);
#endif
@ -403,7 +380,7 @@ void sctp_log_closing(struct sctp_inpcb *inp, struct sctp_tcb *stcb, int16_t loc
void sctp_log_lock(struct sctp_inpcb *inp, struct sctp_tcb *stcb, uint8_t from);
void sctp_log_maxburst(struct sctp_tcb *stcb, struct sctp_nets *, int, int, uint8_t);
void sctp_log_block(uint8_t, struct sctp_association *, size_t);
void sctp_log_block(uint8_t, struct sctp_association *, ssize_t);
void sctp_log_rwnd(uint8_t, uint32_t, uint32_t, uint32_t);
void sctp_log_rwnd_set(uint8_t, uint32_t, uint32_t, uint32_t, uint32_t);
int sctp_fill_stat_log(void *, size_t *);
@ -422,9 +399,16 @@ void sctp_audit_log(uint8_t, uint8_t);
#endif
uint32_t sctp_min_mtu(uint32_t, uint32_t, uint32_t);
#if defined(__FreeBSD__)
#if defined(__FreeBSD__) && !defined(__Userspace__)
void sctp_hc_set_mtu(union sctp_sockstore *, uint16_t, uint32_t);
uint32_t sctp_hc_get_mtu(union sctp_sockstore *, uint16_t);
#endif
void sctp_set_state(struct sctp_tcb *, int);
void sctp_add_substate(struct sctp_tcb *, int);
uint32_t sctp_ticks_to_msecs(uint32_t);
uint32_t sctp_msecs_to_ticks(uint32_t);
uint32_t sctp_ticks_to_secs(uint32_t);
uint32_t sctp_secs_to_ticks(uint32_t);
#endif /* _KERNEL */
#endif

File diff suppressed because it is too large Load Diff

View File

@ -32,7 +32,7 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifdef __FreeBSD__
#if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet6/sctp6_var.h 317457 2017-04-26 19:26:40Z tuexen $");
#endif
@ -44,41 +44,33 @@ __FBSDID("$FreeBSD: head/sys/netinet6/sctp6_var.h 317457 2017-04-26 19:26:40Z tu
#ifdef INET
extern void in6_sin6_2_sin(struct sockaddr_in *, struct sockaddr_in6 *);
extern void in6_sin6_2_sin_in_sock(struct sockaddr *);
extern void in6_sin_2_v4mapsin6(struct sockaddr_in *, struct sockaddr_in6 *);
extern void in6_sin_2_v4mapsin6(const struct sockaddr_in *, struct sockaddr_in6 *);
#endif
#endif
#if defined(_KERNEL)
#if defined(__FreeBSD__) || (__APPLE__) || defined(__Windows__)
#if !defined(__Userspace__)
SYSCTL_DECL(_net_inet6_sctp6);
extern struct pr_usrreqs sctp6_usrreqs;
#else
int sctp6_usrreq(struct socket *, int, struct mbuf *, struct mbuf *, struct mbuf *);
#endif
#if defined(__APPLE__)
#if defined(__APPLE__) && !defined(__Userspace__)
int sctp6_input(struct mbuf **, int *);
int sctp6_input_with_port(struct mbuf **, int *, uint16_t);
#elif defined(__Panda__)
int sctp6_input (pakhandle_type *);
#elif defined(__FreeBSD__) && __FreeBSD_version < 902000
int sctp6_input __P((struct mbuf **, int *, int));
int sctp6_input_with_port __P((struct mbuf **, int *, uint16_t));
#else
int sctp6_input(struct mbuf **, int *, int);
int sctp6_input_with_port(struct mbuf **, int *, uint16_t);
#endif
#if defined(__FreeBSD__) && __FreeBSD_version < 902000
int sctp6_output
__P((struct sctp_inpcb *, struct mbuf *, struct sockaddr *,
struct mbuf *, struct proc *));
void sctp6_ctlinput __P((int, struct sockaddr *, void *));
#else
int sctp6_output(struct sctp_inpcb *, struct mbuf *, struct sockaddr *,
struct mbuf *, struct proc *);
#if defined(__APPLE__) && !defined(__Userspace__) && !defined(APPLE_LEOPARD) && !defined(APPLE_SNOWLEOPARD) && !defined(APPLE_LION) && !defined(APPLE_MOUNTAINLION) && !defined(APPLE_ELCAPITAN)
void sctp6_ctlinput(int, struct sockaddr *, void *, struct ifnet * SCTP_UNUSED);
#else
void sctp6_ctlinput(int, struct sockaddr *, void *);
#endif
#if !(defined(__FreeBSD__) || defined(__APPLE__))
#if !((defined(__FreeBSD__) || defined(__APPLE__)) && !defined(__Userspace__))
extern void in6_sin_2_v4mapsin6(struct sockaddr_in *, struct sockaddr_in6 *);
extern void in6_sin6_2_sin(struct sockaddr_in *, struct sockaddr_in6 *);
extern void in6_sin6_2_sin_in_sock(struct sockaddr *);

View File

@ -42,8 +42,8 @@
#include <stdio.h>
#include <sys/types.h>
#if defined(__Userspace_os_Darwin) || defined (__Userspace_os_Windows)
#if defined (__Userspace_os_Windows)
#if defined(__APPLE__) || defined(_WIN32)
#if defined(_WIN32)
#define atomic_add_int(addr, val) InterlockedExchangeAdd((LPLONG)addr, (LONG)val)
#define atomic_fetchadd_int(addr, val) InterlockedExchangeAdd((LPLONG)addr, (LONG)val)
#define atomic_subtract_int(addr, val) InterlockedExchangeAdd((LPLONG)addr,-((LONG)val))
@ -77,10 +77,10 @@
} \
}
#endif
#if defined(__Userspace_os_Windows)
static void atomic_init() {} /* empty when we are not using atomic_mtx */
#if defined(_WIN32)
static void atomic_init(void) {} /* empty when we are not using atomic_mtx */
#else
static inline void atomic_init() {} /* empty when we are not using atomic_mtx */
static inline void atomic_init(void) {} /* empty when we are not using atomic_mtx */
#endif
#else
@ -132,7 +132,7 @@ static inline void atomic_init() {} /* empty when we are not using atomic_mtx */
} \
}
#endif
static inline void atomic_init() {} /* empty when we are not using atomic_mtx */
static inline void atomic_init(void) {} /* empty when we are not using atomic_mtx */
#endif
#if 0 /* using libatomic_ops */
@ -173,7 +173,7 @@ static inline void atomic_init() {} /* empty when we are not using atomic_mtx */
extern userland_mutex_t atomic_mtx;
#if defined (__Userspace_os_Windows)
#if defined(_WIN32)
static inline void atomic_init() {
InitializeCriticalSection(&atomic_mtx);
}

View File

@ -31,7 +31,7 @@
/* __Userspace__ */
#include <stdlib.h>
#if !defined (__Userspace_os_Windows)
#if !defined(_WIN32)
#include <stdint.h>
#include <netinet/sctp_os_userspace.h>
#endif
@ -64,9 +64,28 @@ userland_mutex_t atomic_mtx;
* provide _some_ kind of randomness. This should only be used
* inside other RNG's, like arc4random(9).
*/
#if defined(__Userspace_os_FreeBSD) || defined(__Userspace_os_Darwin)
static int
read_random_phony(void *buf, int count)
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
void
init_random(void)
{
return;
}
int
read_random(void *buf, int count)
{
memset(buf, 'A', count);
return (count);
}
#elif defined(__FreeBSD__) || defined(__DragonFly__) || defined(__OpenBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
void
init_random(void)
{
return;
}
int
read_random(void *buf, int count)
{
if (count >= 0) {
arc4random_buf(buf, count);
@ -74,14 +93,33 @@ read_random_phony(void *buf, int count)
return (count);
}
#else
static int
read_random_phony(void *buf, int count)
void
init_random(void)
{
struct timeval now;
unsigned int seed;
(void)SCTP_GETTIME_TIMEVAL(&now);
seed = 0;
seed |= (unsigned int)now.tv_sec;
seed |= (unsigned int)now.tv_usec;
#if !defined(_WIN32) &&! defined(__native_client__)
seed |= getpid();
#endif
#if defined(_WIN32) || defined(__native_client__)
srand(seed);
#else
srandom(seed);
#endif
return;
}
int
read_random(void *buf, int count)
{
uint32_t randval;
int size, i;
/* srandom() is called in kern/init_main.c:proc0_post() */
/* Fill buf[] with random(9) output */
for (i = 0; i < count; i+= (int)sizeof(uint32_t)) {
randval = random();
@ -92,13 +130,3 @@ read_random_phony(void *buf, int count)
return (count);
}
#endif
static int (*read_func)(void *, int) = read_random_phony;
/* Userland-visible version of read_random */
int
read_random(void *buf, int count)
{
return ((*read_func)(buf, count));
}

View File

@ -33,12 +33,12 @@
/* __Userspace__ */
#include <sys/types.h>
#ifdef __Userspace_os_FreeBSD
#ifdef __FreeBSD__
#ifndef _SYS_MUTEX_H_
#include <sys/mutex.h>
#endif
#endif
#if defined (__Userspace_os_Windows)
#if defined(_WIN32)
#include "netinet/sctp_os_userspace.h"
#endif
@ -54,7 +54,7 @@ extern int maxsockets;
extern int hz;
/* The following two ints define a range of available ephermal ports. */
/* The following two ints define a range of available ephemeral ports. */
extern int ipport_firstauto, ipport_lastauto;
/* nmbclusters is used in sctp_usrreq.c (e.g., sctp_init). In the FreeBSD kernel,
@ -62,12 +62,13 @@ extern int ipport_firstauto, ipport_lastauto;
*/
extern int nmbclusters;
#if !defined (__Userspace_os_Windows)
#define min(a,b) ((a)>(b)?(b):(a))
#define max(a,b) ((a)>(b)?(a):(b))
#if !defined(_MSC_VER) && !defined(__MINGW32__)
#define min(a,b) (((a)>(b))?(b):(a))
#define max(a,b) (((a)>(b))?(a):(b))
#endif
extern int read_random(void *buf, int count);
void init_random(void);
int read_random(void *, int);
/* errno's may differ per OS. errno.h now included in sctp_os_userspace.h */
/* Source: /usr/src/sys/sys/errno.h */
@ -82,7 +83,7 @@ extern int read_random(void *buf, int count);
/* Source ip_output.c. extern'd in ip_var.h */
extern u_short ip_id;
#if defined(__Userspace_os_Linux)
#if defined(__linux__)
#define IPV6_VERSION 0x60
#endif
@ -96,7 +97,7 @@ terminate_non_graceful(void) {
#define panic(...) \
do { \
SCTP_PRINTF("%s(): ", __FUNCTION__);\
SCTP_PRINTF("%s(): ", __func__); \
SCTP_PRINTF(__VA_ARGS__); \
SCTP_PRINTF("\n"); \
terminate_non_graceful(); \

View File

@ -35,8 +35,6 @@
#include <user_route.h> /* was <net/route.h> */
#define in6pcb inpcb /* for KAME src sync over BSD*'s */
#define in6p_sp inp_sp /* for KAME src sync over BSD*'s */
struct inpcbpolicy;
/*
@ -56,7 +54,7 @@ LIST_HEAD(inpcbporthead, inpcbport);
* the following structure.
*/
struct in_addr_4in6 {
u_int32_t ia46_pad32[3];
uint32_t ia46_pad32[3];
struct in_addr ia46_addr4;
};
@ -65,8 +63,8 @@ struct in_addr_4in6 {
* some extra padding to accomplish this.
*/
struct in_endpoints {
u_int16_t ie_fport; /* foreign port */
u_int16_t ie_lport; /* local port */
uint16_t ie_fport; /* foreign port */
uint16_t ie_lport; /* local port */
/* protocol dependent part, local and foreign addr */
union {
/* foreign host table entry */
@ -89,13 +87,13 @@ struct in_endpoints {
* references.
*/
struct in_conninfo {
u_int8_t inc_flags;
u_int8_t inc_len;
u_int16_t inc_pad; /* XXX alignment for in_endpoints */
uint8_t inc_flags;
uint8_t inc_len;
uint16_t inc_pad; /* XXX alignment for in_endpoints */
/* protocol dependent part */
struct in_endpoints inc_ie;
};
#define inc_isipv6 inc_flags /* temp compatability */
#define inc_isipv6 inc_flags /* temp compatibility */
#define inc_fport inc_ie.ie_fport
#define inc_lport inc_ie.ie_lport
#define inc_faddr inc_ie.ie_faddr
@ -112,7 +110,7 @@ struct inpcb {
struct inpcbinfo *inp_pcbinfo; /* PCB list info */
struct socket *inp_socket; /* back pointer to socket */
u_int32_t inp_flow;
uint32_t inp_flow;
int inp_flags; /* generic IP/datagram flags */
u_char inp_vflag; /* IP version flag (v4/v6) */
@ -326,13 +324,11 @@ struct inpcbinfo {
#define INPLOOKUP_WILDCARD 1
#define sotoinpcb(so) ((struct inpcb *)(so)->so_pcb)
#define sotoin6pcb(so) sotoinpcb(so) /* for KAME src sync over BSD*'s */
#define INP_SOCKAF(so) so->so_proto->pr_domain->dom_family
#define INP_CHECK_SOCKAF(so, af) (INP_SOCKAF(so) == af)
/* #ifdef _KERNEL */
extern int ipport_reservedhigh;
extern int ipport_reservedlow;
extern int ipport_lowfirstauto;
@ -373,6 +369,5 @@ void ipport_tick(void *xtp);
*/
void db_print_inpcb(struct inpcb *inp, const char *name, int indent);
/* #endif _KERNEL */
#endif /* !_NETINET_IN_PCB_H_ */

View File

@ -60,16 +60,16 @@
#ifndef _USER_IP6_VAR_H_
#define _USER_IP6_VAR_H_
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
struct ip6_hdr {
union {
struct ip6_hdrctl {
u_int32_t ip6_un1_flow; /* 20 bits of flow-ID */
u_int16_t ip6_un1_plen; /* payload length */
u_int8_t ip6_un1_nxt; /* next header */
u_int8_t ip6_un1_hlim; /* hop limit */
uint32_t ip6_un1_flow; /* 20 bits of flow-ID */
uint16_t ip6_un1_plen; /* payload length */
uint8_t ip6_un1_nxt; /* next header */
uint8_t ip6_un1_hlim; /* hop limit */
} ip6_un1;
u_int8_t ip6_un2_vfc; /* 4 bits version, top 4 bits class */
uint8_t ip6_un2_vfc; /* 4 bits version, top 4 bits class */
} ip6_ctlun;
struct in6_addr ip6_src; /* source address */
struct in6_addr ip6_dst; /* destination address */
@ -84,18 +84,18 @@ struct ip6_hdr {
#define IPV6_VERSION 0x60
#endif
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
#define s6_addr16 u.Word
#endif
#if !defined(__Userspace_os_Windows)
#if !defined(__Userspace_os_Linux)
#if !defined(_WIN32)
#if !defined(__linux__)
#define s6_addr8 __u6_addr.__u6_addr8
#define s6_addr16 __u6_addr.__u6_addr16
#define s6_addr32 __u6_addr.__u6_addr32
#endif
#endif
#if !defined(__Userspace_os_FreeBSD) && !defined(__Userspace_os_OpenBSD) && !defined(__Userspace_os_DragonFly)
#if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__DragonFly__)
struct route_in6 {
struct rtentry *ro_rt;
struct llentry *ro_lle;

View File

@ -40,8 +40,8 @@
* Internal of an ICMP Router Advertisement
*/
struct icmp_ra_addr {
u_int32_t ira_addr;
u_int32_t ira_preference;
uint32_t ira_addr;
uint32_t ira_preference;
};
/*
@ -53,16 +53,16 @@ struct icmphdr {
u_short icmp_cksum; /* ones complement cksum of struct */
};
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
#pragma pack (push, 1)
struct icmp6_hdr {
u_int8_t icmp6_type;
u_int8_t icmp6_code;
u_int16_t icmp6_cksum;
uint8_t icmp6_type;
uint8_t icmp6_code;
uint16_t icmp6_cksum;
union {
u_int32_t icmp6_un_data32[1];
u_int16_t icmp6_un_data16[2];
u_int8_t icmp6_un_data8[4];
uint32_t icmp6_un_data32[1];
uint16_t icmp6_un_data16[2];
uint8_t icmp6_un_data8[4];
} icmp6_dataun;
};
#pragma pack(pop)
@ -98,7 +98,7 @@ struct icmp {
struct ih_rtradv {
u_char irt_num_addrs;
u_char irt_wpa;
u_int16_t irt_lifetime;
uint16_t irt_lifetime;
} ih_rtradv;
} icmp_hun;
#define icmp_pptr icmp_hun.ih_pptr
@ -126,7 +126,7 @@ struct icmp {
/* options and then 64 bits of data */
} id_ip;
struct icmp_ra_addr id_radv;
u_int32_t id_mask;
uint32_t id_mask;
char id_data[1];
} icmp_dun;
#define icmp_otime icmp_dun.id_ts.its_otime

View File

@ -37,11 +37,11 @@
/*__Userspace__*/
#include <stdlib.h>
#include <sys/types.h>
#if !defined (__Userspace_os_Windows)
#if !defined(_WIN32)
#include <strings.h>
#include <stdint.h>
#else
#if defined(_MSC_VER) && _MSC_VER >= 1600
#if (defined(_MSC_VER) && _MSC_VER >= 1600) || (defined(__MSVCRT_VERSION__) && __MSVCRT_VERSION__ >= 1400)
#include <stdint.h>
#elif defined(SCTP_STDINT_INCLUDE)
#include SCTP_STDINT_INCLUDE
@ -200,67 +200,4 @@ Start copy: Copied code for __Userspace__ */
} \
} while (0);
/* End copy: Copied code for __Userspace__ */
#if 0
#ifdef _KERNEL
#define MALLOC_DEFINE(type, shortdesc, longdesc) \
struct malloc_type type[1] = { \
{ NULL, 0, 0, 0, 0, 0, M_MAGIC, shortdesc, NULL, NULL, \
NULL, 0, NULL, NULL, 0, 0 } \
}; \
SYSINIT(type##_init, SI_SUB_KMEM, SI_ORDER_SECOND, malloc_init, \
type); \
SYSUNINIT(type##_uninit, SI_SUB_KMEM, SI_ORDER_ANY, \
malloc_uninit, type)
#define MALLOC_DECLARE(type) \
extern struct malloc_type type[1]
MALLOC_DECLARE(M_CACHE);
MALLOC_DECLARE(M_DEVBUF);
MALLOC_DECLARE(M_TEMP);
MALLOC_DECLARE(M_IP6OPT); /* for INET6 */
MALLOC_DECLARE(M_IP6NDP); /* for INET6 */
/*
* Deprecated macro versions of not-quite-malloc() and free().
*/
#define MALLOC(space, cast, size, type, flags) \
((space) = (cast)malloc((u_long)(size), (type), (flags)))
#define FREE(addr, type) free((addr), (type))
/*
* XXX this should be declared in <sys/uio.h>, but that tends to fail
* because <sys/uio.h> is included in a header before the source file
* has a chance to include <sys/malloc.h> to get MALLOC_DECLARE() defined.
*/
MALLOC_DECLARE(M_IOV);
extern struct mtx malloc_mtx;
/* XXX struct malloc_type is unused for contig*(). */
void contigfree(void *addr, unsigned long size, struct malloc_type *type);
void *contigmalloc(unsigned long size, struct malloc_type *type, int flags,
vm_paddr_t low, vm_paddr_t high, unsigned long alignment,
unsigned long boundary);
void free(void *addr, struct malloc_type *type);
void *malloc(unsigned long size, struct malloc_type *type, int flags);
void malloc_init(void *);
int malloc_last_fail(void);
void malloc_type_allocated(struct malloc_type *type, unsigned long size);
void malloc_type_freed(struct malloc_type *type, unsigned long size);
void malloc_uninit(void *);
void *realloc(void *addr, unsigned long size, struct malloc_type *type,
int flags);
void *reallocf(void *addr, unsigned long size, struct malloc_type *type,
int flags);
#endif /* _KERNEL */
#endif
#endif /* !_SYS_MALLOC_H_ */

View File

@ -46,7 +46,6 @@
#include "user_atomic.h"
#include "netinet/sctp_pcb.h"
struct mbstat mbstat;
#define KIPC_MAX_LINKHDR 4 /* int: max length of link header (see sys/sysclt.h) */
#define KIPC_MAX_PROTOHDR 5 /* int: max length of network header (see sys/sysclt.h)*/
int max_linkhdr = KIPC_MAX_LINKHDR;
@ -272,9 +271,9 @@ m_clget(struct mbuf *m, int how)
mclust_ret = SCTP_ZONE_GET(zone_clust, char);
#endif
/*mclust_ret = umem_cache_alloc(zone_clust, UMEM_DEFAULT);*/
if (NULL == mclust_ret) {
SCTPDBG(SCTP_DEBUG_USR, "Memory allocation failure in %s\n", __func__);
}
/* if (NULL == mclust_ret) { */
SCTPDBG(SCTP_DEBUG_USR, "Memory allocation failure in %s\n", __func__);
/* } */
}
#if USING_MBUF_CONSTRUCTOR
@ -286,6 +285,166 @@ m_clget(struct mbuf *m, int how)
#endif
}
struct mbuf *
m_getm2(struct mbuf *m, int len, int how, short type, int flags, int allonebuf)
{
struct mbuf *mb, *nm = NULL, *mtail = NULL;
int size, mbuf_threshold, space_needed = len;
KASSERT(len >= 0, ("%s: len is < 0", __func__));
/* Validate flags. */
flags &= (M_PKTHDR | M_EOR);
/* Packet header mbuf must be first in chain. */
if ((flags & M_PKTHDR) && m != NULL) {
flags &= ~M_PKTHDR;
}
if (allonebuf == 0)
mbuf_threshold = SCTP_BASE_SYSCTL(sctp_mbuf_threshold_count);
else
mbuf_threshold = 1;
/* Loop and append maximum sized mbufs to the chain tail. */
while (len > 0) {
if ((!allonebuf && len >= MCLBYTES) || (len > (int)(((mbuf_threshold - 1) * MLEN) + MHLEN))) {
mb = m_gethdr(how, type);
MCLGET(mb, how);
size = MCLBYTES;
/* SCTP_BUF_LEN(mb) = MCLBYTES; */
} else if (flags & M_PKTHDR) {
mb = m_gethdr(how, type);
if (len < MHLEN) {
size = len;
} else {
size = MHLEN;
}
} else {
mb = m_get(how, type);
if (len < MLEN) {
size = len;
} else {
size = MLEN;
}
}
/* Fail the whole operation if one mbuf can't be allocated. */
if (mb == NULL) {
if (nm != NULL)
m_freem(nm);
return (NULL);
}
if (allonebuf != 0 && size < space_needed) {
m_freem(mb);
return (NULL);
}
/* Book keeping. */
len -= size;
if (mtail != NULL)
mtail->m_next = mb;
else
nm = mb;
mtail = mb;
flags &= ~M_PKTHDR; /* Only valid on the first mbuf. */
}
if (flags & M_EOR) {
mtail->m_flags |= M_EOR; /* Only valid on the last mbuf. */
}
/* If mbuf was supplied, append new chain to the end of it. */
if (m != NULL) {
for (mtail = m; mtail->m_next != NULL; mtail = mtail->m_next);
mtail->m_next = nm;
mtail->m_flags &= ~M_EOR;
} else {
m = nm;
}
return (m);
}
/*
* Copy the contents of uio into a properly sized mbuf chain.
*/
struct mbuf *
m_uiotombuf(struct uio *uio, int how, int len, int align, int flags)
{
struct mbuf *m, *mb;
int error, length;
ssize_t total;
int progress = 0;
/*
* len can be zero or an arbitrary large value bound by
* the total data supplied by the uio.
*/
if (len > 0)
total = min(uio->uio_resid, len);
else
total = uio->uio_resid;
/*
* The smallest unit returned by m_getm2() is a single mbuf
* with pkthdr. We can't align past it.
*/
if (align >= MHLEN)
return (NULL);
/*
* Give us the full allocation or nothing.
* If len is zero return the smallest empty mbuf.
*/
m = m_getm2(NULL, (int)max(total + align, 1), how, MT_DATA, flags, 0);
if (m == NULL)
return (NULL);
m->m_data += align;
/* Fill all mbufs with uio data and update header information. */
for (mb = m; mb != NULL; mb = mb->m_next) {
length = (int)min(M_TRAILINGSPACE(mb), total - progress);
error = uiomove(mtod(mb, void *), length, uio);
if (error) {
m_freem(m);
return (NULL);
}
mb->m_len = length;
progress += length;
if (flags & M_PKTHDR)
m->m_pkthdr.len += length;
}
KASSERT(progress == total, ("%s: progress != total", __func__));
return (m);
}
u_int
m_length(struct mbuf *m0, struct mbuf **last)
{
struct mbuf *m;
u_int len;
len = 0;
for (m = m0; m != NULL; m = m->m_next) {
len += m->m_len;
if (m->m_next == NULL)
break;
}
if (last != NULL)
*last = m;
return (len);
}
struct mbuf *
m_last(struct mbuf *m)
{
while (m->m_next) {
m = m->m_next;
}
return (m);
}
/*
* Unlink a tag from the list of tags associated with an mbuf.
*/
@ -313,7 +472,7 @@ m_tag_free(struct m_tag *t)
* XXX probably should be called m_tag_init, but that was already taken.
*/
static __inline void
m_tag_setup(struct m_tag *t, u_int32_t cookie, int type, int len)
m_tag_setup(struct m_tag *t, uint32_t cookie, int type, int len)
{
t->m_tag_id = type;
@ -376,26 +535,6 @@ mbuf_initialize(void *dummy)
*
*/
/*
* [Re]set counters and local statistics knobs.
*
*/
mbstat.m_mbufs = 0;
mbstat.m_mclusts = 0;
mbstat.m_drain = 0;
mbstat.m_msize = MSIZE;
mbstat.m_mclbytes = MCLBYTES;
mbstat.m_minclsize = MINCLSIZE;
mbstat.m_mlen = MLEN;
mbstat.m_mhlen = MHLEN;
mbstat.m_numtypes = MT_NTYPES;
mbstat.m_mcfail = mbstat.m_mpfail = 0;
mbstat.sf_iocnt = 0;
mbstat.sf_allocwait = mbstat.sf_allocfail = 0;
}
@ -749,7 +888,6 @@ m_pullup(struct mbuf *n, int len)
return (m);
bad:
m_freem(n);
mbstat.m_mpfail++; /* XXX: No consistency. */
return (NULL);
}
@ -885,16 +1023,14 @@ m_pulldown(struct mbuf *m, int off, int len, int *offp)
* easy cases first.
* we need to use m_copydata() to get data from <n->m_next, 0>.
*/
if ((off == 0 || offp) && M_TRAILINGSPACE(n) >= tlen
&& writable) {
if ((off == 0 || offp) && (M_TRAILINGSPACE(n) >= tlen) && writable) {
m_copydata(n->m_next, 0, tlen, mtod(n, caddr_t) + n->m_len);
n->m_len += tlen;
m_adj(n->m_next, tlen);
goto ok;
}
if ((off == 0 || offp) && M_LEADINGSPACE(n->m_next) >= hlen
&& writable) {
if ((off == 0 || offp) && (M_LEADINGSPACE(n->m_next) >= hlen) && writable) {
n->m_next->m_data -= hlen;
n->m_next->m_len += hlen;
memcpy( mtod(n->m_next, caddr_t), mtod(n, caddr_t) + off,hlen);
@ -994,7 +1130,6 @@ m_copym(struct mbuf *m, int off0, int len, int wait)
return (NULL);
}
#endif
if (off == 0 && m->m_flags & M_PKTHDR)
copyhdr = 1;
while (off > 0) {
@ -1039,13 +1174,10 @@ m_copym(struct mbuf *m, int off0, int len, int wait)
m = m->m_next;
np = &n->m_next;
}
if (top == NULL)
mbstat.m_mcfail++; /* XXX: No consistency. */
return (top);
nospace:
m_freem(top);
mbstat.m_mcfail++; /* XXX: No consistency. */
return (NULL);
}
@ -1107,7 +1239,7 @@ m_tag_copy(struct m_tag *t, int how)
/* Get a packet tag structure along with specified data following. */
struct m_tag *
m_tag_alloc(u_int32_t cookie, int type, int len, int wait)
m_tag_alloc(uint32_t cookie, int type, int len, int wait)
{
struct m_tag *t;

View File

@ -55,7 +55,10 @@ struct mbuf * m_gethdr(int how, short type);
struct mbuf * m_get(int how, short type);
struct mbuf * m_free(struct mbuf *m);
void m_clget(struct mbuf *m, int how);
struct mbuf * m_getm2(struct mbuf *m, int len, int how, short type, int flags, int allonebuf);
struct mbuf *m_uiotombuf(struct uio *uio, int how, int len, int align, int flags);
u_int m_length(struct mbuf *m0, struct mbuf **last);
struct mbuf *m_last(struct mbuf *m);
/* mbuf initialization function */
void mbuf_initialize(void *);
@ -107,7 +110,7 @@ void m_cat(struct mbuf *m, struct mbuf *n);
void m_adj(struct mbuf *, int);
void mb_free_ext(struct mbuf *);
void m_freem(struct mbuf *);
struct m_tag *m_tag_alloc(u_int32_t, int, int, int);
struct m_tag *m_tag_alloc(uint32_t, int, int, int);
struct mbuf *m_copym(struct mbuf *, int, int, int);
void m_copyback(struct mbuf *, int, int, caddr_t);
struct mbuf *m_pullup(struct mbuf *, int);
@ -125,35 +128,6 @@ void m_copydata(const struct mbuf *, int, int, caddr_t);
#define MT_NOINIT 255 /* Not a type but a flag to allocate
a non-initialized mbuf */
/*
* General mbuf allocator statistics structure.
* __Userspace__ mbstat may be useful for gathering statistics.
* In the kernel many of these statistics are no longer used as
* they track allocator statistics through kernel UMA's built in statistics mechanism.
*/
struct mbstat {
u_long m_mbufs; /* XXX */
u_long m_mclusts; /* XXX */
u_long m_drain; /* times drained protocols for space */
u_long m_mcfail; /* XXX: times m_copym failed */
u_long m_mpfail; /* XXX: times m_pullup failed */
u_long m_msize; /* length of an mbuf */
u_long m_mclbytes; /* length of an mbuf cluster */
u_long m_minclsize; /* min length of data to allocate a cluster */
u_long m_mlen; /* length of data in an mbuf */
u_long m_mhlen; /* length of data in a header mbuf */
/* Number of mbtypes (gives # elems in mbtypes[] array: */
short m_numtypes;
/* XXX: Sendfile stats should eventually move to their own struct */
u_long sf_iocnt; /* times sendfile had to do disk I/O */
u_long sf_allocfail; /* times sfbuf allocation failed */
u_long sf_allocwait; /* times sfbuf allocation had to wait */
};
/*
* Mbufs are of a single size, MSIZE (sys/param.h), which includes overhead.
* An mbuf may add a single "mbuf cluster" of size MCLBYTES (also in
@ -187,9 +161,9 @@ struct m_hdr {
*/
struct m_tag {
SLIST_ENTRY(m_tag) m_tag_link; /* List of packet tags */
u_int16_t m_tag_id; /* Tag ID */
u_int16_t m_tag_len; /* Length of data */
u_int32_t m_tag_cookie; /* ABI/Module ID */
uint16_t m_tag_id; /* Tag ID */
uint16_t m_tag_len; /* Length of data */
uint32_t m_tag_cookie; /* ABI/Module ID */
void (*m_tag_free)(struct m_tag *);
};
@ -204,8 +178,8 @@ struct pkthdr {
/* variables for hardware checksum */
int csum_flags; /* flags regarding checksum */
int csum_data; /* data field used by csum routines */
u_int16_t tso_segsz; /* TSO segment size */
u_int16_t ether_vtag; /* Ethernet 802.1p+q vlan tag */
uint16_t tso_segsz; /* TSO segment size */
uint16_t ether_vtag; /* Ethernet 802.1p+q vlan tag */
SLIST_HEAD(packet_tags, m_tag) tags; /* list of packet tags */
};
@ -349,9 +323,6 @@ void m_tag_free_default(struct m_tag *);
extern int max_linkhdr; /* Largest link-level header */
extern int max_protohdr; /* Size of largest protocol layer header. See user_mbuf.c */
extern struct mbstat mbstat; /* General mbuf stats/infos */
/*
* Evaluate TRUE if it's safe to write to the mbuf m's data region (this can
* be both the local data payload, or an external buffer area, depending on
@ -370,9 +341,9 @@ extern struct mbstat mbstat; /* General mbuf stats/infos */
* of checking writability of the mbuf data area rests solely with the caller.
*/
#define M_LEADINGSPACE(m) \
((m)->m_flags & M_EXT ? \
(((m)->m_flags & M_EXT) ? \
(M_WRITABLE(m) ? (m)->m_data - (m)->m_ext.ext_buf : 0): \
(m)->m_flags & M_PKTHDR ? (m)->m_data - (m)->m_pktdat : \
((m)->m_flags & M_PKTHDR)? (m)->m_data - (m)->m_pktdat : \
(m)->m_data - (m)->m_dat)
/*
@ -382,7 +353,7 @@ extern struct mbstat mbstat; /* General mbuf stats/infos */
* of checking writability of the mbuf data area rests solely with the caller.
*/
#define M_TRAILINGSPACE(m) \
((m)->m_flags & M_EXT ? \
(((m)->m_flags & M_EXT) ? \
(M_WRITABLE(m) ? (m)->m_ext.ext_buf + (m)->m_ext.ext_size \
- ((m)->m_data + (m)->m_len) : 0) : \
&(m)->m_dat[MLEN] - ((m)->m_data + (m)->m_len))
@ -434,4 +405,9 @@ extern struct mbstat mbstat; /* General mbuf stats/infos */
(m)->m_data += (MHLEN - (len)) & ~(sizeof(long) - 1); \
} while (0)
#define M_SIZE(m) \
(((m)->m_flags & M_EXT) ? (m)->m_ext.ext_size : \
((m)->m_flags & M_PKTHDR) ? MHLEN : \
MLEN)
#endif

View File

@ -144,8 +144,8 @@ struct name { \
#define SLIST_HEAD_INITIALIZER(head) \
{ NULL }
#if defined (__Userspace_os_Windows)
#if defined (SLIST_ENTRY)
#if defined(_WIN32)
#if defined(SLIST_ENTRY)
#undef SLIST_ENTRY
#endif
#endif

View File

@ -30,12 +30,12 @@
#if defined(INET) || defined(INET6)
#include <sys/types.h>
#if !defined(__Userspace_os_Windows)
#if !defined(_WIN32)
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
#include <pthread.h>
#if !defined(__Userspace_os_DragonFly) && !defined(__Userspace_os_FreeBSD) && !defined(__Userspace_os_NetBSD)
#if !defined(__DragonFly__) && !defined(__FreeBSD__) && !defined(__NetBSD__)
#include <sys/uio.h>
#else
#include <user_ip6_var.h>
@ -46,7 +46,7 @@
#include <netinet/sctp_pcb.h>
#include <netinet/sctp_input.h>
#if 0
#if defined(__Userspace_os_Linux)
#if defined(__linux__)
#include <linux/netlink.h>
#ifdef HAVE_LINUX_IF_ADDR_H
#include <linux/if_addr.h>
@ -56,23 +56,26 @@
#endif
#endif
#endif
#if defined(__Userspace_os_Darwin) || defined(__Userspace_os_DragonFly) || defined(__Userspace_os_FreeBSD)
#if defined(__APPLE__) || defined(__DragonFly__) || defined(__FreeBSD__)
#include <net/route.h>
#endif
/* local macros and datatypes used to get IP addresses system independently */
#if !defined(IP_PKTINFO ) && ! defined(IP_RECVDSTADDR)
#if !defined(IP_PKTINFO ) && !defined(IP_RECVDSTADDR)
# error "Can't determine socket option to use to get UDP IP"
#endif
void recv_thread_destroy(void);
#define MAXLEN_MBUF_CHAIN 32 /* What should this value be? */
#define MAXLEN_MBUF_CHAIN 128
#define ROUNDUP(a, size) (((a) & ((size)-1)) ? (1 + ((a) | ((size)-1))) : (a))
#if defined(__Userspace_os_Darwin) || defined(__Userspace_os_DragonFly) || defined(__Userspace_os_FreeBSD)
#if defined(__APPLE__) || defined(__DragonFly__) || defined(__FreeBSD__)
#define NEXT_SA(ap) ap = (struct sockaddr *) \
((caddr_t) ap + (ap->sa_len ? ROUNDUP(ap->sa_len, sizeof (uint32_t)) : sizeof(uint32_t)))
#endif
#if defined(__Userspace_os_Darwin) || defined(__Userspace_os_DragonFly) || defined(__Userspace_os_FreeBSD)
#if defined(__APPLE__) || defined(__DragonFly__) || defined(__FreeBSD__)
static void
sctp_get_rtaddrs(int addrs, struct sockaddr *sa, struct sockaddr **rti_info)
{
@ -164,7 +167,7 @@ recv_function_route(void *arg)
}
}
if (ret < 0) {
if (errno == EAGAIN) {
if (errno == EAGAIN || errno == EINTR) {
continue;
} else {
break;
@ -211,7 +214,7 @@ recv_function_route(void *arg)
len = recvmsg(SCTP_BASE_VAR(userspace_route), &msg, 0);
if (len < 0) {
if (errno == EAGAIN) {
if (errno == EAGAIN || errno == EINTR) {
continue;
} else {
break;
@ -267,12 +270,10 @@ recv_function_raw(void *arg)
struct sctphdr *sh;
uint16_t port;
int offset, ecn = 0;
#if !defined(SCTP_WITH_NO_CSUM)
int compute_crc = 1;
#endif
struct sctp_chunkhdr *ch;
struct sockaddr_in src, dst;
#if !defined(__Userspace_os_Windows)
#if !defined(_WIN32)
unsigned int ncounter;
struct msghdr msg;
struct iovec recv_iovec[MAXLEN_MBUF_CHAIN];
@ -307,7 +308,7 @@ recv_function_raw(void *arg)
Have tried both sending and receiving
*/
recvmbuf[i] = sctp_get_mbuf_for_msg(iovlen, want_header, M_NOWAIT, want_ext, MT_DATA);
#if !defined(__Userspace_os_Windows)
#if !defined(_WIN32)
recv_iovec[i].iov_base = (caddr_t)recvmbuf[i]->m_data;
recv_iovec[i].iov_len = iovlen;
#else
@ -316,7 +317,7 @@ recv_function_raw(void *arg)
#endif
}
to_fill = 0;
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
flags = 0;
ncounter = 0;
fromlen = sizeof(struct sockaddr_in);
@ -325,12 +326,10 @@ recv_function_raw(void *arg)
nResult = WSARecvFrom(SCTP_BASE_VAR(userspace_rawsctp), recv_iovec, MAXLEN_MBUF_CHAIN, &ncounter, &flags, (struct sockaddr *)&from, &fromlen, NULL, NULL);
if (nResult != 0) {
m_ErrorCode = WSAGetLastError();
if (m_ErrorCode == WSAETIMEDOUT) {
continue;
}
if ((m_ErrorCode == WSAENOTSOCK) || (m_ErrorCode == WSAEINTR)) {
break;
}
continue;
}
n = ncounter;
#else
@ -343,7 +342,7 @@ recv_function_raw(void *arg)
msg.msg_controllen = 0;
ncounter = n = recvmsg(SCTP_BASE_VAR(userspace_rawsctp), &msg, 0);
if (n < 0) {
if (errno == EAGAIN) {
if (errno == EAGAIN || errno == EINTR) {
continue;
} else {
break;
@ -407,28 +406,22 @@ recv_function_raw(void *arg)
port = 0;
#if defined(SCTP_WITH_NO_CSUM)
SCTP_STAT_INCR(sctps_recvnocrc);
#else
if (SCTP_BASE_SYSCTL(sctp_no_csum_on_loopback) &&
((IN4_ISLOOPBACK_ADDRESS(&src.sin_addr) &&
IN4_ISLOOPBACK_ADDRESS(&dst.sin_addr)) ||
(src.sin_addr.s_addr == dst.sin_addr.s_addr))) {
compute_crc = 0;
SCTP_STAT_INCR(sctps_recvnocrc);
SCTP_STAT_INCR(sctps_recvhwcrc);
} else {
SCTP_STAT_INCR(sctps_recvswcrc);
}
#endif
SCTPDBG(SCTP_DEBUG_USR, "%s: Received %d bytes.", __func__, n);
SCTPDBG(SCTP_DEBUG_USR, " - calling sctp_common_input_processing with off=%d\n", offset);
sctp_common_input_processing(&recvmbuf[0], sizeof(struct ip), offset, n,
(struct sockaddr *)&src,
(struct sockaddr *)&dst,
sh, ch,
#if !defined(SCTP_WITH_NO_CSUM)
compute_crc,
#endif
ecn,
SCTP_DEFAULT_VRFID, port);
if (recvmbuf[0]) {
@ -440,6 +433,7 @@ recv_function_raw(void *arg)
}
/* free the array itself */
free(recvmbuf);
SCTPDBG(SCTP_DEBUG_USR, "%s: Exiting SCTP/IP4 rcv\n", __func__);
return (NULL);
}
#endif
@ -449,7 +443,7 @@ static void *
recv_function_raw6(void *arg)
{
struct mbuf **recvmbuf6;
#if !defined(__Userspace_os_Windows)
#if !defined(_WIN32)
unsigned int ncounter = 0;
struct iovec recv_iovec[MAXLEN_MBUF_CHAIN];
struct msghdr msg;
@ -458,10 +452,8 @@ recv_function_raw6(void *arg)
#else
WSABUF recv_iovec[MAXLEN_MBUF_CHAIN];
int nResult, m_ErrorCode;
DWORD flags;
DWORD ncounter = 0;
struct sockaddr_in6 from;
int fromlen;
GUID WSARecvMsg_GUID = WSAID_WSARECVMSG;
LPFN_WSARECVMSG WSARecvMsg;
WSACMSGHDR *cmsgptr;
@ -477,9 +469,7 @@ recv_function_raw6(void *arg)
int to_fill = MAXLEN_MBUF_CHAIN;
/* iovlen is the size of each mbuf in the chain */
int i, n;
#if !defined(SCTP_WITH_NO_CSUM)
int compute_crc = 1;
#endif
unsigned int iovlen = MCLBYTES;
int want_ext = (iovlen > MLEN)? 1 : 0;
int want_header = 0;
@ -495,7 +485,7 @@ recv_function_raw6(void *arg)
Have tried both sending and receiving
*/
recvmbuf6[i] = sctp_get_mbuf_for_msg(iovlen, want_header, M_NOWAIT, want_ext, MT_DATA);
#if !defined(__Userspace_os_Windows)
#if !defined(_WIN32)
recv_iovec[i].iov_base = (caddr_t)recvmbuf6[i]->m_data;
recv_iovec[i].iov_len = iovlen;
#else
@ -504,10 +494,8 @@ recv_function_raw6(void *arg)
#endif
}
to_fill = 0;
#if defined(__Userspace_os_Windows)
flags = 0;
#if defined(_WIN32)
ncounter = 0;
fromlen = sizeof(struct sockaddr_in6);
memset(&from, 0, sizeof(struct sockaddr_in6));
nResult = WSAIoctl(SCTP_BASE_VAR(userspace_rawsctp6), SIO_GET_EXTENSION_FUNCTION_POINTER,
&WSARecvMsg_GUID, sizeof WSARecvMsg_GUID,
@ -525,10 +513,10 @@ recv_function_raw6(void *arg)
}
if (nResult != 0) {
m_ErrorCode = WSAGetLastError();
if (m_ErrorCode == WSAETIMEDOUT)
continue;
if (m_ErrorCode == WSAENOTSOCK || m_ErrorCode == WSAEINTR)
if ((m_ErrorCode == WSAENOTSOCK) || (m_ErrorCode == WSAEINTR)) {
break;
}
continue;
}
n = ncounter;
#else
@ -541,12 +529,12 @@ recv_function_raw6(void *arg)
msg.msg_iov = recv_iovec;
msg.msg_iovlen = MAXLEN_MBUF_CHAIN;
msg.msg_control = (void *)cmsgbuf;
msg.msg_controllen = (socklen_t)CMSG_LEN(sizeof (struct in6_pktinfo));
msg.msg_controllen = (socklen_t)CMSG_SPACE(sizeof (struct in6_pktinfo));
msg.msg_flags = 0;
ncounter = n = recvmsg(SCTP_BASE_VAR(userspace_rawsctp6), &msg, 0);
if (n < 0) {
if (errno == EAGAIN) {
if (errno == EAGAIN || errno == EINTR) {
continue;
} else {
break;
@ -606,25 +594,20 @@ recv_function_raw6(void *arg)
src.sin6_len = sizeof(struct sockaddr_in6);
#endif
src.sin6_port = sh->src_port;
#if defined(SCTP_WITH_NO_CSUM)
SCTP_STAT_INCR(sctps_recvnocrc);
#else
if (memcmp(&src.sin6_addr, &dst.sin6_addr, sizeof(struct in6_addr)) == 0) {
if (SCTP_BASE_SYSCTL(sctp_no_csum_on_loopback) &&
(memcmp(&src.sin6_addr, &dst.sin6_addr, sizeof(struct in6_addr)) == 0)) {
compute_crc = 0;
SCTP_STAT_INCR(sctps_recvnocrc);
SCTP_STAT_INCR(sctps_recvhwcrc);
} else {
SCTP_STAT_INCR(sctps_recvswcrc);
}
#endif
SCTPDBG(SCTP_DEBUG_USR, "%s: Received %d bytes.", __func__, n);
SCTPDBG(SCTP_DEBUG_USR, " - calling sctp_common_input_processing with off=%d\n", offset);
sctp_common_input_processing(&recvmbuf6[0], 0, offset, n,
(struct sockaddr *)&src,
(struct sockaddr *)&dst,
sh, ch,
#if !defined(SCTP_WITH_NO_CSUM)
compute_crc,
#endif
0,
SCTP_DEFAULT_VRFID, 0);
if (recvmbuf6[0]) {
@ -636,6 +619,7 @@ recv_function_raw6(void *arg)
}
/* free the array itself */
free(recvmbuf6);
SCTPDBG(SCTP_DEBUG_USR, "%s: Exiting SCTP/IP6 rcv\n", __func__);
return (NULL);
}
#endif
@ -662,10 +646,8 @@ recv_function_udp(void *arg)
#else
char cmsgbuf[CMSG_SPACE(sizeof(struct in_addr))];
#endif
#if !defined(SCTP_WITH_NO_CSUM)
int compute_crc = 1;
#endif
#if !defined(__Userspace_os_Windows)
#if !defined(_WIN32)
unsigned int ncounter;
struct iovec iov[MAXLEN_MBUF_CHAIN];
struct msghdr msg;
@ -692,7 +674,7 @@ recv_function_udp(void *arg)
Have tried both sending and receiving
*/
udprecvmbuf[i] = sctp_get_mbuf_for_msg(iovlen, want_header, M_NOWAIT, want_ext, MT_DATA);
#if !defined(__Userspace_os_Windows)
#if !defined(_WIN32)
iov[i].iov_base = (caddr_t)udprecvmbuf[i]->m_data;
iov[i].iov_len = iovlen;
#else
@ -701,7 +683,7 @@ recv_function_udp(void *arg)
#endif
}
to_fill = 0;
#if !defined(__Userspace_os_Windows)
#if !defined(_WIN32)
memset(&msg, 0, sizeof(struct msghdr));
#else
memset(&msg, 0, sizeof(WSAMSG));
@ -710,7 +692,7 @@ recv_function_udp(void *arg)
memset(&dst, 0, sizeof(struct sockaddr_in));
memset(cmsgbuf, 0, sizeof(cmsgbuf));
#if !defined(__Userspace_os_Windows)
#if !defined(_WIN32)
msg.msg_name = (void *)&src;
msg.msg_namelen = sizeof(struct sockaddr_in);
msg.msg_iov = iov;
@ -721,7 +703,7 @@ recv_function_udp(void *arg)
ncounter = n = recvmsg(SCTP_BASE_VAR(userspace_udpsctp), &msg, 0);
if (n < 0) {
if (errno == EAGAIN) {
if (errno == EAGAIN || errno == EINTR) {
continue;
} else {
break;
@ -744,12 +726,10 @@ recv_function_udp(void *arg)
}
if (nResult != 0) {
m_ErrorCode = WSAGetLastError();
if (m_ErrorCode == WSAETIMEDOUT) {
continue;
}
if ((m_ErrorCode == WSAENOTSOCK) || (m_ErrorCode == WSAEINTR)) {
break;
}
continue;
}
n = ncounter;
#endif
@ -820,25 +800,20 @@ recv_function_udp(void *arg)
port = src.sin_port;
src.sin_port = sh->src_port;
dst.sin_port = sh->dest_port;
#if defined(SCTP_WITH_NO_CSUM)
SCTP_STAT_INCR(sctps_recvnocrc);
#else
if (src.sin_addr.s_addr == dst.sin_addr.s_addr) {
if (SCTP_BASE_SYSCTL(sctp_no_csum_on_loopback) &&
(src.sin_addr.s_addr == dst.sin_addr.s_addr)) {
compute_crc = 0;
SCTP_STAT_INCR(sctps_recvnocrc);
SCTP_STAT_INCR(sctps_recvhwcrc);
} else {
SCTP_STAT_INCR(sctps_recvswcrc);
}
#endif
SCTPDBG(SCTP_DEBUG_USR, "%s: Received %d bytes.", __func__, n);
SCTPDBG(SCTP_DEBUG_USR, " - calling sctp_common_input_processing with off=%d\n", offset);
sctp_common_input_processing(&udprecvmbuf[0], 0, offset, n,
(struct sockaddr *)&src,
(struct sockaddr *)&dst,
sh, ch,
#if !defined(SCTP_WITH_NO_CSUM)
compute_crc,
#endif
0,
SCTP_DEFAULT_VRFID, port);
if (udprecvmbuf[0]) {
@ -850,6 +825,7 @@ recv_function_udp(void *arg)
}
/* free the array itself */
free(udprecvmbuf);
SCTPDBG(SCTP_DEBUG_USR, "%s: Exiting SCTP/UDP/IP4 rcv\n", __func__);
return (NULL);
}
#endif
@ -872,14 +848,12 @@ recv_function_udp6(void *arg)
uint16_t port;
struct sctp_chunkhdr *ch;
char cmsgbuf[CMSG_SPACE(sizeof (struct in6_pktinfo))];
#if !defined(SCTP_WITH_NO_CSUM)
int compute_crc = 1;
#endif
#if !defined(__Userspace_os_Windows)
unsigned int ncounter;
#if !defined(_WIN32)
struct iovec iov[MAXLEN_MBUF_CHAIN];
struct msghdr msg;
struct cmsghdr *cmsgptr;
unsigned int ncounter;
#else
GUID WSARecvMsg_GUID = WSAID_WSARECVMSG;
LPFN_WSARECVMSG WSARecvMsg;
@ -887,8 +861,8 @@ recv_function_udp6(void *arg)
WSABUF iov[MAXLEN_MBUF_CHAIN];
WSAMSG msg;
int nResult, m_ErrorCode;
DWORD ncounter;
WSACMSGHDR *cmsgptr;
DWORD ncounter;
#endif
sctp_userspace_set_threadname("SCTP/UDP/IP6 rcv");
@ -901,7 +875,7 @@ recv_function_udp6(void *arg)
Have tried both sending and receiving
*/
udprecvmbuf6[i] = sctp_get_mbuf_for_msg(iovlen, want_header, M_NOWAIT, want_ext, MT_DATA);
#if !defined(__Userspace_os_Windows)
#if !defined(_WIN32)
iov[i].iov_base = (caddr_t)udprecvmbuf6[i]->m_data;
iov[i].iov_len = iovlen;
#else
@ -911,7 +885,7 @@ recv_function_udp6(void *arg)
}
to_fill = 0;
#if !defined(__Userspace_os_Windows)
#if !defined(_WIN32)
memset(&msg, 0, sizeof(struct msghdr));
#else
memset(&msg, 0, sizeof(WSAMSG));
@ -920,18 +894,18 @@ recv_function_udp6(void *arg)
memset(&dst, 0, sizeof(struct sockaddr_in6));
memset(cmsgbuf, 0, CMSG_SPACE(sizeof (struct in6_pktinfo)));
#if !defined(__Userspace_os_Windows)
#if !defined(_WIN32)
msg.msg_name = (void *)&src;
msg.msg_namelen = sizeof(struct sockaddr_in6);
msg.msg_iov = iov;
msg.msg_iovlen = MAXLEN_MBUF_CHAIN;
msg.msg_control = (void *)cmsgbuf;
msg.msg_controllen = (socklen_t)CMSG_LEN(sizeof (struct in6_pktinfo));
msg.msg_controllen = (socklen_t)CMSG_SPACE(sizeof (struct in6_pktinfo));
msg.msg_flags = 0;
ncounter = n = recvmsg(SCTP_BASE_VAR(userspace_udpsctp6), &msg, 0);
if (n < 0) {
if (errno == EAGAIN) {
if (errno == EAGAIN || errno == EINTR) {
continue;
} else {
break;
@ -958,12 +932,10 @@ recv_function_udp6(void *arg)
}
if (nResult != 0) {
m_ErrorCode = WSAGetLastError();
if (m_ErrorCode == WSAETIMEDOUT) {
continue;
}
if ((m_ErrorCode == WSAENOTSOCK) || (m_ErrorCode == WSAEINTR)) {
break;
}
continue;
}
n = ncounter;
#endif
@ -1016,25 +988,20 @@ recv_function_udp6(void *arg)
port = src.sin6_port;
src.sin6_port = sh->src_port;
dst.sin6_port = sh->dest_port;
#if defined(SCTP_WITH_NO_CSUM)
SCTP_STAT_INCR(sctps_recvnocrc);
#else
if ((memcmp(&src.sin6_addr, &dst.sin6_addr, sizeof(struct in6_addr)) == 0)) {
if (SCTP_BASE_SYSCTL(sctp_no_csum_on_loopback) &&
(memcmp(&src.sin6_addr, &dst.sin6_addr, sizeof(struct in6_addr)) == 0)) {
compute_crc = 0;
SCTP_STAT_INCR(sctps_recvnocrc);
SCTP_STAT_INCR(sctps_recvhwcrc);
} else {
SCTP_STAT_INCR(sctps_recvswcrc);
}
#endif
SCTPDBG(SCTP_DEBUG_USR, "%s: Received %d bytes.", __func__, n);
SCTPDBG(SCTP_DEBUG_USR, " - calling sctp_common_input_processing with off=%d\n", (int)sizeof(struct sctphdr));
sctp_common_input_processing(&udprecvmbuf6[0], 0, offset, n,
(struct sockaddr *)&src,
(struct sockaddr *)&dst,
sh, ch,
#if !defined(SCTP_WITH_NO_CSUM)
compute_crc,
#endif
0,
SCTP_DEFAULT_VRFID, port);
if (udprecvmbuf6[0]) {
@ -1046,11 +1013,12 @@ recv_function_udp6(void *arg)
}
/* free the array itself */
free(udprecvmbuf6);
SCTPDBG(SCTP_DEBUG_USR, "%s: Exiting SCTP/UDP/IP6 rcv\n", __func__);
return (NULL);
}
#endif
#if defined (__Userspace_os_Windows)
#if defined(_WIN32)
static void
setReceiveBufferSize(SOCKET sfd, int new_size)
#else
@ -1061,7 +1029,7 @@ setReceiveBufferSize(int sfd, int new_size)
int ch = new_size;
if (setsockopt (sfd, SOL_SOCKET, SO_RCVBUF, (void*)&ch, sizeof(ch)) < 0) {
#if defined (__Userspace_os_Windows)
#if defined(_WIN32)
SCTPDBG(SCTP_DEBUG_USR, "Can't set recv-buffers size (errno = %d).\n", WSAGetLastError());
#else
SCTPDBG(SCTP_DEBUG_USR, "Can't set recv-buffers size (errno = %d).\n", errno);
@ -1070,7 +1038,7 @@ setReceiveBufferSize(int sfd, int new_size)
return;
}
#if defined (__Userspace_os_Windows)
#if defined(_WIN32)
static void
setSendBufferSize(SOCKET sfd, int new_size)
#else
@ -1081,7 +1049,7 @@ setSendBufferSize(int sfd, int new_size)
int ch = new_size;
if (setsockopt (sfd, SOL_SOCKET, SO_SNDBUF, (void*)&ch, sizeof(ch)) < 0) {
#if defined (__Userspace_os_Windows)
#if defined(_WIN32)
SCTPDBG(SCTP_DEBUG_USR, "Can't set send-buffers size (errno = %d).\n", WSAGetLastError());
#else
SCTPDBG(SCTP_DEBUG_USR, "Can't set send-buffers size (errno = %d).\n", errno);
@ -1104,7 +1072,7 @@ recv_thread_init(void)
#if defined(INET) || defined(INET6)
const int on = 1;
#endif
#if !defined(__Userspace_os_Windows)
#if !defined(_WIN32)
struct timeval timeout;
memset(&timeout, 0, sizeof(struct timeval));
@ -1113,7 +1081,7 @@ recv_thread_init(void)
#else
unsigned int timeout = SOCKET_TIMEOUT; /* Timeout in milliseconds */
#endif
#if defined(__Userspace_os_Darwin) || defined(__Userspace_os_DragonFly) || defined(__Userspace_os_FreeBSD)
#if defined(__APPLE__) || defined(__DragonFly__) || defined(__FreeBSD__)
if (SCTP_BASE_VAR(userspace_route) == -1) {
if ((SCTP_BASE_VAR(userspace_route) = socket(AF_ROUTE, SOCK_RAW, 0)) == -1) {
SCTPDBG(SCTP_DEBUG_USR, "Can't create routing socket (errno = %d).\n", errno);
@ -1142,7 +1110,7 @@ recv_thread_init(void)
if (SCTP_BASE_VAR(userspace_route) != -1) {
if (setsockopt(SCTP_BASE_VAR(userspace_route), SOL_SOCKET, SO_RCVTIMEO,(const void*)&timeout, sizeof(struct timeval)) < 0) {
SCTPDBG(SCTP_DEBUG_USR, "Can't set timeout on routing socket (errno = %d).\n", errno);
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
closesocket(SCTP_BASE_VAR(userspace_route));
#else
close(SCTP_BASE_VAR(userspace_route));
@ -1155,7 +1123,7 @@ recv_thread_init(void)
#if defined(INET)
if (SCTP_BASE_VAR(userspace_rawsctp) == -1) {
if ((SCTP_BASE_VAR(userspace_rawsctp) = socket(AF_INET, SOCK_RAW, IPPROTO_SCTP)) == -1) {
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
SCTPDBG(SCTP_DEBUG_USR, "Can't create raw socket for IPv4 (errno = %d).\n", WSAGetLastError());
#else
SCTPDBG(SCTP_DEBUG_USR, "Can't create raw socket for IPv4 (errno = %d).\n", errno);
@ -1163,7 +1131,7 @@ recv_thread_init(void)
} else {
/* complete setting up the raw SCTP socket */
if (setsockopt(SCTP_BASE_VAR(userspace_rawsctp), IPPROTO_IP, IP_HDRINCL,(const void*)&hdrincl, sizeof(int)) < 0) {
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
SCTPDBG(SCTP_DEBUG_USR, "Can't set IP_HDRINCL (errno = %d).\n", WSAGetLastError());
closesocket(SCTP_BASE_VAR(userspace_rawsctp));
#else
@ -1172,7 +1140,7 @@ recv_thread_init(void)
#endif
SCTP_BASE_VAR(userspace_rawsctp) = -1;
} else if (setsockopt(SCTP_BASE_VAR(userspace_rawsctp), SOL_SOCKET, SO_RCVTIMEO, (const void *)&timeout, sizeof(timeout)) < 0) {
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
SCTPDBG(SCTP_DEBUG_USR, "Can't set timeout on socket for SCTP/IPv4 (errno = %d).\n", WSAGetLastError());
closesocket(SCTP_BASE_VAR(userspace_rawsctp));
#else
@ -1189,7 +1157,7 @@ recv_thread_init(void)
addr_ipv4.sin_port = htons(0);
addr_ipv4.sin_addr.s_addr = htonl(INADDR_ANY);
if (bind(SCTP_BASE_VAR(userspace_rawsctp), (const struct sockaddr *)&addr_ipv4, sizeof(struct sockaddr_in)) < 0) {
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
SCTPDBG(SCTP_DEBUG_USR, "Can't bind socket for SCTP/IPv4 (errno = %d).\n", WSAGetLastError());
closesocket(SCTP_BASE_VAR(userspace_rawsctp));
#else
@ -1206,7 +1174,7 @@ recv_thread_init(void)
}
if (SCTP_BASE_VAR(userspace_udpsctp) == -1) {
if ((SCTP_BASE_VAR(userspace_udpsctp) = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) {
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
SCTPDBG(SCTP_DEBUG_USR, "Can't create socket for SCTP/UDP/IPv4 (errno = %d).\n", WSAGetLastError());
#else
SCTPDBG(SCTP_DEBUG_USR, "Can't create socket for SCTP/UDP/IPv4 (errno = %d).\n", errno);
@ -1217,7 +1185,7 @@ recv_thread_init(void)
#else
if (setsockopt(SCTP_BASE_VAR(userspace_udpsctp), IPPROTO_IP, IP_RECVDSTADDR, (const void *)&on, (int)sizeof(int)) < 0) {
#endif
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
#if defined(IP_PKTINFO)
SCTPDBG(SCTP_DEBUG_USR, "Can't set IP_PKTINFO on socket for SCTP/UDP/IPv4 (errno = %d).\n", WSAGetLastError());
#else
@ -1234,7 +1202,7 @@ recv_thread_init(void)
#endif
SCTP_BASE_VAR(userspace_udpsctp) = -1;
} else if (setsockopt(SCTP_BASE_VAR(userspace_udpsctp), SOL_SOCKET, SO_RCVTIMEO, (const void *)&timeout, sizeof(timeout)) < 0) {
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
SCTPDBG(SCTP_DEBUG_USR, "Can't set timeout on socket for SCTP/UDP/IPv4 (errno = %d).\n", WSAGetLastError());
closesocket(SCTP_BASE_VAR(userspace_udpsctp));
#else
@ -1251,7 +1219,7 @@ recv_thread_init(void)
addr_ipv4.sin_port = htons(SCTP_BASE_SYSCTL(sctp_udp_tunneling_port));
addr_ipv4.sin_addr.s_addr = htonl(INADDR_ANY);
if (bind(SCTP_BASE_VAR(userspace_udpsctp), (const struct sockaddr *)&addr_ipv4, sizeof(struct sockaddr_in)) < 0) {
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
SCTPDBG(SCTP_DEBUG_USR, "Can't bind socket for SCTP/UDP/IPv4 (errno = %d).\n", WSAGetLastError());
closesocket(SCTP_BASE_VAR(userspace_udpsctp));
#else
@ -1270,7 +1238,7 @@ recv_thread_init(void)
#if defined(INET6)
if (SCTP_BASE_VAR(userspace_rawsctp6) == -1) {
if ((SCTP_BASE_VAR(userspace_rawsctp6) = socket(AF_INET6, SOCK_RAW, IPPROTO_SCTP)) == -1) {
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
SCTPDBG(SCTP_DEBUG_USR, "Can't create socket for SCTP/IPv6 (errno = %d).\n", WSAGetLastError());
#else
SCTPDBG(SCTP_DEBUG_USR, "Can't create socket for SCTP/IPv6 (errno = %d).\n", errno);
@ -1279,7 +1247,7 @@ recv_thread_init(void)
/* complete setting up the raw SCTP socket */
#if defined(IPV6_RECVPKTINFO)
if (setsockopt(SCTP_BASE_VAR(userspace_rawsctp6), IPPROTO_IPV6, IPV6_RECVPKTINFO, (const void *)&on, sizeof(on)) < 0) {
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
SCTPDBG(SCTP_DEBUG_USR, "Can't set IPV6_RECVPKTINFO on socket for SCTP/IPv6 (errno = %d).\n", WSAGetLastError());
closesocket(SCTP_BASE_VAR(userspace_rawsctp6));
#else
@ -1290,7 +1258,7 @@ recv_thread_init(void)
} else {
#else
if (setsockopt(SCTP_BASE_VAR(userspace_rawsctp6), IPPROTO_IPV6, IPV6_PKTINFO,(const void*)&on, sizeof(on)) < 0) {
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
SCTPDBG(SCTP_DEBUG_USR, "Can't set IPV6_PKTINFO on socket for SCTP/IPv6 (errno = %d).\n", WSAGetLastError());
closesocket(SCTP_BASE_VAR(userspace_rawsctp6));
#else
@ -1301,14 +1269,14 @@ recv_thread_init(void)
} else {
#endif
if (setsockopt(SCTP_BASE_VAR(userspace_rawsctp6), IPPROTO_IPV6, IPV6_V6ONLY, (const void*)&on, (socklen_t)sizeof(on)) < 0) {
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
SCTPDBG(SCTP_DEBUG_USR, "Can't set IPV6_V6ONLY on socket for SCTP/IPv6 (errno = %d).\n", WSAGetLastError());
#else
SCTPDBG(SCTP_DEBUG_USR, "Can't set IPV6_V6ONLY on socket for SCTP/IPv6 (errno = %d).\n", errno);
#endif
}
if (setsockopt(SCTP_BASE_VAR(userspace_rawsctp6), SOL_SOCKET, SO_RCVTIMEO, (const void *)&timeout, sizeof(timeout)) < 0) {
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
SCTPDBG(SCTP_DEBUG_USR, "Can't set timeout on socket for SCTP/IPv6 (errno = %d).\n", WSAGetLastError());
closesocket(SCTP_BASE_VAR(userspace_rawsctp6));
#else
@ -1325,7 +1293,7 @@ recv_thread_init(void)
addr_ipv6.sin6_port = htons(0);
addr_ipv6.sin6_addr = in6addr_any;
if (bind(SCTP_BASE_VAR(userspace_rawsctp6), (const struct sockaddr *)&addr_ipv6, sizeof(struct sockaddr_in6)) < 0) {
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
SCTPDBG(SCTP_DEBUG_USR, "Can't bind socket for SCTP/IPv6 (errno = %d).\n", WSAGetLastError());
closesocket(SCTP_BASE_VAR(userspace_rawsctp6));
#else
@ -1343,7 +1311,7 @@ recv_thread_init(void)
}
if (SCTP_BASE_VAR(userspace_udpsctp6) == -1) {
if ((SCTP_BASE_VAR(userspace_udpsctp6) = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP)) == -1) {
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
SCTPDBG(SCTP_DEBUG_USR, "Can't create socket for SCTP/UDP/IPv6 (errno = %d).\n", WSAGetLastError());
#else
SCTPDBG(SCTP_DEBUG_USR, "Can't create socket for SCTP/UDP/IPv6 (errno = %d).\n", errno);
@ -1351,7 +1319,7 @@ recv_thread_init(void)
}
#if defined(IPV6_RECVPKTINFO)
if (setsockopt(SCTP_BASE_VAR(userspace_udpsctp6), IPPROTO_IPV6, IPV6_RECVPKTINFO, (const void *)&on, (int)sizeof(int)) < 0) {
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
SCTPDBG(SCTP_DEBUG_USR, "Can't set IPV6_RECVPKTINFO on socket for SCTP/UDP/IPv6 (errno = %d).\n", WSAGetLastError());
closesocket(SCTP_BASE_VAR(userspace_udpsctp6));
#else
@ -1362,7 +1330,7 @@ recv_thread_init(void)
} else {
#else
if (setsockopt(SCTP_BASE_VAR(userspace_udpsctp6), IPPROTO_IPV6, IPV6_PKTINFO, (const void *)&on, (int)sizeof(int)) < 0) {
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
SCTPDBG(SCTP_DEBUG_USR, "Can't set IPV6_PKTINFO on socket for SCTP/UDP/IPv6 (errno = %d).\n", WSAGetLastError());
closesocket(SCTP_BASE_VAR(userspace_udpsctp6));
#else
@ -1373,14 +1341,14 @@ recv_thread_init(void)
} else {
#endif
if (setsockopt(SCTP_BASE_VAR(userspace_udpsctp6), IPPROTO_IPV6, IPV6_V6ONLY, (const void *)&on, (socklen_t)sizeof(on)) < 0) {
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
SCTPDBG(SCTP_DEBUG_USR, "Can't set IPV6_V6ONLY on socket for SCTP/UDP/IPv6 (errno = %d).\n", WSAGetLastError());
#else
SCTPDBG(SCTP_DEBUG_USR, "Can't set IPV6_V6ONLY on socket for SCTP/UDP/IPv6 (errno = %d).\n", errno);
#endif
}
if (setsockopt(SCTP_BASE_VAR(userspace_udpsctp6), SOL_SOCKET, SO_RCVTIMEO, (const void *)&timeout, sizeof(timeout)) < 0) {
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
SCTPDBG(SCTP_DEBUG_USR, "Can't set timeout on socket for SCTP/UDP/IPv6 (errno = %d).\n", WSAGetLastError());
closesocket(SCTP_BASE_VAR(userspace_udpsctp6));
#else
@ -1397,7 +1365,7 @@ recv_thread_init(void)
addr_ipv6.sin6_port = htons(SCTP_BASE_SYSCTL(sctp_udp_tunneling_port));
addr_ipv6.sin6_addr = in6addr_any;
if (bind(SCTP_BASE_VAR(userspace_udpsctp6), (const struct sockaddr *)&addr_ipv6, sizeof(struct sockaddr_in6)) < 0) {
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
SCTPDBG(SCTP_DEBUG_USR, "Can't bind socket for SCTP/UDP/IPv6 (errno = %d).\n", WSAGetLastError());
closesocket(SCTP_BASE_VAR(userspace_udpsctp6));
#else
@ -1413,7 +1381,7 @@ recv_thread_init(void)
}
}
#endif
#if defined(__Userspace_os_Darwin) || defined(__Userspace_os_DragonFly) || defined(__Userspace_os_FreeBSD)
#if defined(__APPLE__) || defined(__DragonFly__) || defined(__FreeBSD__)
#if defined(INET) || defined(INET6)
if (SCTP_BASE_VAR(userspace_route) != -1) {
int rc;
@ -1432,7 +1400,7 @@ recv_thread_init(void)
if ((rc = sctp_userspace_thread_create(&SCTP_BASE_VAR(recvthreadraw), &recv_function_raw))) {
SCTPDBG(SCTP_DEBUG_USR, "Can't start SCTP/IPv4 recv thread (%d).\n", rc);
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
closesocket(SCTP_BASE_VAR(userspace_rawsctp));
#else
close(SCTP_BASE_VAR(userspace_rawsctp));
@ -1445,7 +1413,7 @@ recv_thread_init(void)
if ((rc = sctp_userspace_thread_create(&SCTP_BASE_VAR(recvthreadudp), &recv_function_udp))) {
SCTPDBG(SCTP_DEBUG_USR, "Can't start SCTP/UDP/IPv4 recv thread (%d).\n", rc);
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
closesocket(SCTP_BASE_VAR(userspace_udpsctp));
#else
close(SCTP_BASE_VAR(userspace_udpsctp));
@ -1460,7 +1428,7 @@ recv_thread_init(void)
if ((rc = sctp_userspace_thread_create(&SCTP_BASE_VAR(recvthreadraw6), &recv_function_raw6))) {
SCTPDBG(SCTP_DEBUG_USR, "Can't start SCTP/IPv6 recv thread (%d).\n", rc);
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
closesocket(SCTP_BASE_VAR(userspace_rawsctp6));
#else
close(SCTP_BASE_VAR(userspace_rawsctp6));
@ -1473,7 +1441,7 @@ recv_thread_init(void)
if ((rc = sctp_userspace_thread_create(&SCTP_BASE_VAR(recvthreadudp6), &recv_function_udp6))) {
SCTPDBG(SCTP_DEBUG_USR, "Can't start SCTP/UDP/IPv6 recv thread (%d).\n", rc);
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
closesocket(SCTP_BASE_VAR(userspace_udpsctp6));
#else
close(SCTP_BASE_VAR(userspace_udpsctp6));
@ -1487,42 +1455,63 @@ recv_thread_init(void)
void
recv_thread_destroy(void)
{
#if defined(__Userspace_os_Darwin) || defined(__Userspace_os_DragonFly) || defined(__Userspace_os_FreeBSD)
#if defined(__APPLE__) || defined(__DragonFly__) || defined(__FreeBSD__)
#if defined(INET) || defined(INET6)
if (SCTP_BASE_VAR(userspace_route) != -1) {
close(SCTP_BASE_VAR(userspace_route));
pthread_join(SCTP_BASE_VAR(recvthreadroute), NULL);
}
#endif
#endif
#if defined(INET)
if (SCTP_BASE_VAR(userspace_rawsctp) != -1) {
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
closesocket(SCTP_BASE_VAR(userspace_rawsctp));
SCTP_BASE_VAR(userspace_rawsctp) = -1;
WaitForSingleObject(SCTP_BASE_VAR(recvthreadraw), INFINITE);
CloseHandle(SCTP_BASE_VAR(recvthreadraw));
#else
close(SCTP_BASE_VAR(userspace_rawsctp));
SCTP_BASE_VAR(userspace_rawsctp) = -1;
pthread_join(SCTP_BASE_VAR(recvthreadraw), NULL);
#endif
}
if (SCTP_BASE_VAR(userspace_udpsctp) != -1) {
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
closesocket(SCTP_BASE_VAR(userspace_udpsctp));
SCTP_BASE_VAR(userspace_udpsctp) = -1;
WaitForSingleObject(SCTP_BASE_VAR(recvthreadudp), INFINITE);
CloseHandle(SCTP_BASE_VAR(recvthreadudp));
#else
close(SCTP_BASE_VAR(userspace_udpsctp));
SCTP_BASE_VAR(userspace_udpsctp) = -1;
pthread_join(SCTP_BASE_VAR(recvthreadudp), NULL);
#endif
}
#endif
#if defined(INET6)
if (SCTP_BASE_VAR(userspace_rawsctp6) != -1) {
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
closesocket(SCTP_BASE_VAR(userspace_rawsctp6));
SCTP_BASE_VAR(userspace_rawsctp6) = -1;
WaitForSingleObject(SCTP_BASE_VAR(recvthreadraw6), INFINITE);
CloseHandle(SCTP_BASE_VAR(recvthreadraw6));
#else
close(SCTP_BASE_VAR(userspace_rawsctp6));
SCTP_BASE_VAR(userspace_rawsctp6) = -1;
pthread_join(SCTP_BASE_VAR(recvthreadraw6), NULL);
#endif
}
if (SCTP_BASE_VAR(userspace_udpsctp6) != -1) {
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
SCTP_BASE_VAR(userspace_udpsctp6) = -1;
closesocket(SCTP_BASE_VAR(userspace_udpsctp6));
WaitForSingleObject(SCTP_BASE_VAR(recvthreadudp6), INFINITE);
CloseHandle(SCTP_BASE_VAR(recvthreadudp6));
#else
close(SCTP_BASE_VAR(userspace_udpsctp6));
SCTP_BASE_VAR(userspace_udpsctp6) = -1;
pthread_join(SCTP_BASE_VAR(recvthreadudp6), NULL);
#endif
}
#endif

File diff suppressed because it is too large Load Diff

View File

@ -33,7 +33,7 @@
#ifndef _USER_SOCKETVAR_H_
#define _USER_SOCKETVAR_H_
#if defined(__Userspace_os_Darwin)
#if defined(__APPLE__)
#include <sys/types.h>
#include <unistd.h>
#endif
@ -42,7 +42,7 @@
/* #include <sys/_lock.h> was 0 byte file */
/* #include <sys/_mutex.h> was 0 byte file */
/* #include <sys/_sx.h> */ /*__Userspace__ alternative?*/
#if !defined(__Userspace_os_DragonFly) && !defined(__Userspace_os_FreeBSD) && !defined(__Userspace_os_NetBSD) && !defined(__Userspace_os_Windows) && !defined(__Userspace_os_NaCl)
#if !defined(__DragonFly__) && !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(_WIN32) && !defined(__native_client__)
#include <sys/uio.h>
#endif
#define SOCK_MAXADDRLEN 255
@ -54,16 +54,16 @@
#define SS_CANTRCVMORE 0x020
#define SS_CANTSENDMORE 0x010
#if defined(__Userspace_os_Darwin) || defined(__Userspace_os_DragonFly) || defined(__Userspace_os_FreeBSD) || defined(__Userspace_os_OpenBSD) || defined (__Userspace_os_Windows) || defined(__Userspace_os_NaCl)
#if defined(__APPLE__) || defined(__DragonFly__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(_WIN32) || defined(__native_client__)
#define UIO_MAXIOV 1024
#define ERESTART (-1)
#endif
#if !defined(__Userspace_os_Darwin) && !defined(__Userspace_os_NetBSD) && !defined(__Userspace_os_OpenBSD)
#if !defined(__APPLE__) && !defined(__NetBSD__) && !defined(__OpenBSD__)
enum uio_rw { UIO_READ, UIO_WRITE };
#endif
#if !defined(__Userspace_os_NetBSD) && !defined(__Userspace_os_OpenBSD)
#if !defined(__NetBSD__) && !defined(__OpenBSD__)
/* Segment flag values. */
enum uio_seg {
UIO_USERSPACE, /* from user data space */
@ -72,7 +72,7 @@ enum uio_seg {
#endif
struct proc {
int stub; /* struct proc is a dummy for __Userspace__ */
int stub; /* struct proc is a dummy for __Userspace__ */
};
MALLOC_DECLARE(M_ACCF);
@ -83,12 +83,12 @@ MALLOC_DECLARE(M_SONAME);
* Removing struct thread *uio_td; owner field
*/
struct uio {
struct iovec *uio_iov; /* scatter/gather list */
int uio_iovcnt; /* length of scatter/gather list */
off_t uio_offset; /* offset in target object */
ssize_t uio_resid; /* remaining bytes to process */
enum uio_seg uio_segflg; /* address space */
enum uio_rw uio_rw; /* operation */
struct iovec *uio_iov; /* scatter/gather list */
int uio_iovcnt; /* length of scatter/gather list */
off_t uio_offset; /* offset in target object */
ssize_t uio_resid; /* remaining bytes to process */
enum uio_seg uio_segflg; /* address space */
enum uio_rw uio_rw; /* operation */
};
@ -100,9 +100,11 @@ struct uio {
* handle on protocol and pointer to protocol
* private data and error information.
*/
#if defined (__Userspace_os_Windows)
#if defined(_WIN32)
#define AF_ROUTE 17
#if !defined(__MINGW32__)
typedef __int32 pid_t;
#endif
typedef unsigned __int32 uid_t;
enum sigType {
SIGNAL = 0,
@ -235,7 +237,7 @@ struct socket {
* avoid defining a lock order between listen and accept sockets
* until such time as it proves to be a good idea.
*/
#if defined(__Userspace_os_Windows)
#if defined(_WIN32)
extern userland_mutex_t accept_mtx;
extern userland_cond_t accept_cond;
#define ACCEPT_LOCK_ASSERT()
@ -270,7 +272,7 @@ extern userland_cond_t accept_cond;
* buffer.
*/
#define SOCKBUF_MTX(_sb) (&(_sb)->sb_mtx)
#if defined (__Userspace_os_Windows)
#if defined(_WIN32)
#define SOCKBUF_LOCK_INIT(_sb, _name) \
InitializeCriticalSection(SOCKBUF_MTX(_sb))
#define SOCKBUF_LOCK_DESTROY(_sb) DeleteCriticalSection(SOCKBUF_MTX(_sb))
@ -365,338 +367,11 @@ extern userland_cond_t accept_cond;
#define SQ_COMP 0x1000 /* unaccepted, complete connection */
/*
* Externalized form of struct socket used by the sysctl(3) interface.
* Socket event flags
*/
struct xsocket {
size_t xso_len; /* length of this structure */
struct socket *xso_so; /* makes a convenient handle sometimes */
short so_type;
short so_options;
short so_linger;
short so_state;
caddr_t so_pcb; /* another convenient handle */
int xso_protocol;
int xso_family;
u_short so_qlen;
u_short so_incqlen;
u_short so_qlimit;
short so_timeo;
u_short so_error;
pid_t so_pgid;
u_long so_oobmark;
struct xsockbuf {
u_int sb_cc;
u_int sb_hiwat;
u_int sb_mbcnt;
u_int sb_mbmax;
int sb_lowat;
int sb_timeo;
short sb_flags;
} so_rcv, so_snd;
uid_t so_uid; /* XXX */
};
#if defined(_KERNEL)
/*
* Macros for sockets and socket buffering.
*/
/*
* Do we need to notify the other side when I/O is possible?
*/
#define sb_notify(sb) (((sb)->sb_flags & (SB_WAIT | SB_SEL | SB_ASYNC | \
SB_UPCALL | SB_AIO | SB_KNOTE)) != 0)
/*
* How much space is there in a socket buffer (so->so_snd or so->so_rcv)?
* This is problematical if the fields are unsigned, as the space might
* still be negative (cc > hiwat or mbcnt > mbmax). Should detect
* overflow and return 0. Should use "lmin" but it doesn't exist now.
*/
#define sbspace(sb) \
((long) imin((int)((sb)->sb_hiwat - (sb)->sb_cc), \
(int)((sb)->sb_mbmax - (sb)->sb_mbcnt)))
/* do we have to send all at once on a socket? */
#define sosendallatonce(so) \
((so)->so_proto->pr_flags & PR_ATOMIC)
/* can we read something from so? */
#define soreadable(so) \
((so)->so_rcv.sb_cc >= (so)->so_rcv.sb_lowat || \
((so)->so_rcv.sb_state & SBS_CANTRCVMORE) || \
!TAILQ_EMPTY(&(so)->so_comp) || (so)->so_error)
/* can we write something to so? */
#define sowriteable(so) \
((sbspace(&(so)->so_snd) >= (so)->so_snd.sb_lowat && \
(((so)->so_state&SS_ISCONNECTED) || \
((so)->so_proto->pr_flags&PR_CONNREQUIRED)==0)) || \
((so)->so_snd.sb_state & SBS_CANTSENDMORE) || \
(so)->so_error)
/* adjust counters in sb reflecting allocation of m */
#define sballoc(sb, m) { \
(sb)->sb_cc += (m)->m_len; \
if ((m)->m_type != MT_DATA && (m)->m_type != MT_OOBDATA) \
(sb)->sb_ctl += (m)->m_len; \
(sb)->sb_mbcnt += MSIZE; \
if ((m)->m_flags & M_EXT) \
(sb)->sb_mbcnt += (m)->m_ext.ext_size; \
}
/* adjust counters in sb reflecting freeing of m */
#define sbfree(sb, m) { \
(sb)->sb_cc -= (m)->m_len; \
if ((m)->m_type != MT_DATA && (m)->m_type != MT_OOBDATA) \
(sb)->sb_ctl -= (m)->m_len; \
(sb)->sb_mbcnt -= MSIZE; \
if ((m)->m_flags & M_EXT) \
(sb)->sb_mbcnt -= (m)->m_ext.ext_size; \
if ((sb)->sb_sndptr == (m)) { \
(sb)->sb_sndptr = NULL; \
(sb)->sb_sndptroff = 0; \
} \
if ((sb)->sb_sndptroff != 0) \
(sb)->sb_sndptroff -= (m)->m_len; \
}
/*
* soref()/sorele() ref-count the socket structure. Note that you must
* still explicitly close the socket, but the last ref count will free
* the structure.
*/
#define soref(so) do { \
SOCK_LOCK_ASSERT(so); \
++(so)->so_count; \
} while (0)
#define sorele(so) do { \
ACCEPT_LOCK_ASSERT(); \
SOCK_LOCK_ASSERT(so); \
KASSERT((so)->so_count > 0, ("sorele")); \
if (--(so)->so_count == 0) \
sofree(so); \
else { \
SOCK_UNLOCK(so); \
ACCEPT_UNLOCK(); \
} \
} while (0)
#define sotryfree(so) do { \
ACCEPT_LOCK_ASSERT(); \
SOCK_LOCK_ASSERT(so); \
if ((so)->so_count == 0) \
sofree(so); \
else { \
SOCK_UNLOCK(so); \
ACCEPT_UNLOCK(); \
} \
} while(0)
/*
* In sorwakeup() and sowwakeup(), acquire the socket buffer lock to
* avoid a non-atomic test-and-wakeup. However, sowakeup is
* responsible for releasing the lock if it is called. We unlock only
* if we don't call into sowakeup. If any code is introduced that
* directly invokes the underlying sowakeup() primitives, it must
* maintain the same semantics.
*/
#define sorwakeup_locked(so) do { \
SOCKBUF_LOCK_ASSERT(&(so)->so_rcv); \
if (sb_notify(&(so)->so_rcv)) \
sowakeup((so), &(so)->so_rcv); \
else \
SOCKBUF_UNLOCK(&(so)->so_rcv); \
} while (0)
#define sorwakeup(so) do { \
SOCKBUF_LOCK(&(so)->so_rcv); \
sorwakeup_locked(so); \
} while (0)
#define sowwakeup_locked(so) do { \
SOCKBUF_LOCK_ASSERT(&(so)->so_snd); \
if (sb_notify(&(so)->so_snd)) \
sowakeup((so), &(so)->so_snd); \
else \
SOCKBUF_UNLOCK(&(so)->so_snd); \
} while (0)
#define sowwakeup(so) do { \
SOCKBUF_LOCK(&(so)->so_snd); \
sowwakeup_locked(so); \
} while (0)
/*
* Argument structure for sosetopt et seq. This is in the KERNEL
* section because it will never be visible to user code.
*/
enum sopt_dir { SOPT_GET, SOPT_SET };
struct sockopt {
enum sopt_dir sopt_dir; /* is this a get or a set? */
int sopt_level; /* second arg of [gs]etsockopt */
int sopt_name; /* third arg of [gs]etsockopt */
void *sopt_val; /* fourth arg of [gs]etsockopt */
size_t sopt_valsize; /* (almost) fifth arg of [gs]etsockopt */
struct thread *sopt_td; /* calling thread or null if kernel */
};
struct accept_filter {
char accf_name[16];
void (*accf_callback)
(struct socket *so, void *arg, int waitflag);
void * (*accf_create)
(struct socket *so, char *arg);
void (*accf_destroy)
(struct socket *so);
SLIST_ENTRY(accept_filter) accf_next;
};
extern int maxsockets;
extern u_long sb_max;
extern struct uma_zone *socket_zone;
extern so_gen_t so_gencnt;
struct mbuf;
struct sockaddr;
struct ucred;
struct uio;
/*
* From uipc_socket and friends
*/
int do_getopt_accept_filter(struct socket *so, struct sockopt *sopt);
int do_setopt_accept_filter(struct socket *so, struct sockopt *sopt);
int so_setsockopt(struct socket *so, int level, int optname,
void *optval, size_t optlen);
int sockargs(struct mbuf **mp, caddr_t buf, int buflen, int type);
int getsockaddr(struct sockaddr **namp, caddr_t uaddr, size_t len);
void sbappend(struct sockbuf *sb, struct mbuf *m);
void sbappend_locked(struct sockbuf *sb, struct mbuf *m);
void sbappendstream(struct sockbuf *sb, struct mbuf *m);
void sbappendstream_locked(struct sockbuf *sb, struct mbuf *m);
int sbappendaddr(struct sockbuf *sb, const struct sockaddr *asa,
struct mbuf *m0, struct mbuf *control);
int sbappendaddr_locked(struct sockbuf *sb, const struct sockaddr *asa,
struct mbuf *m0, struct mbuf *control);
int sbappendcontrol(struct sockbuf *sb, struct mbuf *m0,
struct mbuf *control);
int sbappendcontrol_locked(struct sockbuf *sb, struct mbuf *m0,
struct mbuf *control);
void sbappendrecord(struct sockbuf *sb, struct mbuf *m0);
void sbappendrecord_locked(struct sockbuf *sb, struct mbuf *m0);
void sbcheck(struct sockbuf *sb);
void sbcompress(struct sockbuf *sb, struct mbuf *m, struct mbuf *n);
struct mbuf *
sbcreatecontrol(caddr_t p, int size, int type, int level);
void sbdestroy(struct sockbuf *sb, struct socket *so);
void sbdrop(struct sockbuf *sb, int len);
void sbdrop_locked(struct sockbuf *sb, int len);
void sbdroprecord(struct sockbuf *sb);
void sbdroprecord_locked(struct sockbuf *sb);
void sbflush(struct sockbuf *sb);
void sbflush_locked(struct sockbuf *sb);
void sbrelease(struct sockbuf *sb, struct socket *so);
void sbrelease_locked(struct sockbuf *sb, struct socket *so);
int sbreserve(struct sockbuf *sb, u_long cc, struct socket *so,
struct thread *td);
int sbreserve_locked(struct sockbuf *sb, u_long cc, struct socket *so,
struct thread *td);
struct mbuf *
sbsndptr(struct sockbuf *sb, u_int off, u_int len, u_int *moff);
void sbtoxsockbuf(struct sockbuf *sb, struct xsockbuf *xsb);
int sbwait(struct sockbuf *sb);
int sblock(struct sockbuf *sb, int flags);
void sbunlock(struct sockbuf *sb);
void soabort(struct socket *so);
int soaccept(struct socket *so, struct sockaddr **nam);
int socheckuid(struct socket *so, uid_t uid);
int sobind(struct socket *so, struct sockaddr *nam, struct thread *td);
void socantrcvmore(struct socket *so);
void socantrcvmore_locked(struct socket *so);
void socantsendmore(struct socket *so);
void socantsendmore_locked(struct socket *so);
int soclose(struct socket *so);
int soconnect(struct socket *so, struct sockaddr *nam, struct thread *td);
int soconnect2(struct socket *so1, struct socket *so2);
int socow_setup(struct mbuf *m0, struct uio *uio);
int socreate(int dom, struct socket **aso, int type, int proto,
struct ucred *cred, struct thread *td);
int sodisconnect(struct socket *so);
struct sockaddr *sodupsockaddr(const struct sockaddr *sa, int mflags);
void sofree(struct socket *so);
int sogetopt(struct socket *so, struct sockopt *sopt);
void sohasoutofband(struct socket *so);
void soisconnected(struct socket *so);
void soisconnecting(struct socket *so);
void soisdisconnected(struct socket *so);
void soisdisconnecting(struct socket *so);
int solisten(struct socket *so, int backlog, struct thread *td);
void solisten_proto(struct socket *so, int backlog);
int solisten_proto_check(struct socket *so);
struct socket *
sonewconn(struct socket *head, int connstatus);
int sooptcopyin(struct sockopt *sopt, void *buf, size_t len, size_t minlen);
int sooptcopyout(struct sockopt *sopt, const void *buf, size_t len);
/* XXX; prepare mbuf for (__FreeBSD__ < 3) routines. */
int soopt_getm(struct sockopt *sopt, struct mbuf **mp);
int soopt_mcopyin(struct sockopt *sopt, struct mbuf *m);
int soopt_mcopyout(struct sockopt *sopt, struct mbuf *m);
int sopoll(struct socket *so, int events, struct ucred *active_cred,
struct thread *td);
int sopoll_generic(struct socket *so, int events,
struct ucred *active_cred, struct thread *td);
int soreceive(struct socket *so, struct sockaddr **paddr, struct uio *uio,
struct mbuf **mp0, struct mbuf **controlp, int *flagsp);
int soreceive_generic(struct socket *so, struct sockaddr **paddr,
struct uio *uio, struct mbuf **mp0, struct mbuf **controlp,
int *flagsp);
int soreserve(struct socket *so, u_long sndcc, u_long rcvcc);
void sorflush(struct socket *so);
int sosend(struct socket *so, struct sockaddr *addr, struct uio *uio,
struct mbuf *top, struct mbuf *control, int flags,
struct thread *td);
int sosend_dgram(struct socket *so, struct sockaddr *addr,
struct uio *uio, struct mbuf *top, struct mbuf *control,
int flags, struct thread *td);
int sosend_generic(struct socket *so, struct sockaddr *addr,
struct uio *uio, struct mbuf *top, struct mbuf *control,
int flags, struct thread *td);
int sosetopt(struct socket *so, struct sockopt *sopt);
int soshutdown(struct socket *so, int how);
void sotoxsocket(struct socket *so, struct xsocket *xso);
void sowakeup(struct socket *so, struct sockbuf *sb);
#ifdef SOCKBUF_DEBUG
void sblastrecordchk(struct sockbuf *, const char *, int);
#define SBLASTRECORDCHK(sb) sblastrecordchk((sb), __FILE__, __LINE__)
void sblastmbufchk(struct sockbuf *, const char *, int);
#define SBLASTMBUFCHK(sb) sblastmbufchk((sb), __FILE__, __LINE__)
#else
#define SBLASTRECORDCHK(sb) /* nothing */
#define SBLASTMBUFCHK(sb) /* nothing */
#endif /* SOCKBUF_DEBUG */
/*
* Accept filter functions (duh).
*/
int accept_filt_add(struct accept_filter *filt);
int accept_filt_del(char *name);
struct accept_filter *accept_filt_get(char *name);
#ifdef ACCEPT_FILTER_MOD
#ifdef SYSCTL_DECL
SYSCTL_DECL(_net_inet_accf);
#endif
int accept_filt_generic_mod_event(module_t mod, int event, void *data);
#endif
#endif /* _KERNEL */
#define SCTP_EVENT_READ 0x0001 /* socket is readable */
#define SCTP_EVENT_WRITE 0x0002 /* socket is writeable */
#define SCTP_EVENT_ERROR 0x0004 /* socket has an error state */
/*-------------------------------------------------------------*/
@ -708,7 +383,6 @@ int accept_filt_generic_mod_event(module_t mod, int event, void *data);
* above into, avoiding having to port the entire thing at once...
* For function prototypes, the full bodies are in user_socket.c .
*/
#if defined(__Userspace__)
/* ---------------------------------------------------------- */
/* --- function prototypes (implemented in user_socket.c) --- */
@ -719,6 +393,7 @@ void soisconnected(struct socket *so);
struct socket * sonewconn(struct socket *head, int connstatus);
void socantrcvmore(struct socket *so);
void socantsendmore(struct socket *so);
void sofree(struct socket *so);
@ -782,9 +457,7 @@ extern int sctp_listen(struct socket *so, int backlog, struct proc *p);
extern void socantrcvmore_locked(struct socket *so);
extern int sctp_bind(struct socket *so, struct sockaddr *addr);
extern int sctp6_bind(struct socket *so, struct sockaddr *addr, void *proc);
#if defined(__Userspace__)
extern int sctpconn_bind(struct socket *so, struct sockaddr *addr);
#endif
extern int sctp_accept(struct socket *so, struct sockaddr **addr);
extern int sctp_attach(struct socket *so, int proto, uint32_t vrf_id);
extern int sctp6_attach(struct socket *so, int proto, uint32_t vrf_id);
@ -803,9 +476,7 @@ extern int soconnect(struct socket *so, struct sockaddr *nam);
extern int sctp_disconnect(struct socket *so);
extern int sctp_connect(struct socket *so, struct sockaddr *addr);
extern int sctp6_connect(struct socket *so, struct sockaddr *addr);
#if defined(__Userspace__)
extern int sctpconn_connect(struct socket *so, struct sockaddr *addr);
#endif
extern void sctp_finish(void);
/* ------------------------------------------------ */
@ -853,8 +524,4 @@ extern void sctp_finish(void);
sowwakeup_locked(so); \
} while (0)
#endif /* __Userspace__ */
#endif /* !_SYS_SOCKETVAR_H_ */

View File

@ -46,11 +46,11 @@ typedef struct uma_zone * uma_zone_t;
typedef struct uma_keg * uma_keg_t;
struct uma_cache {
int stub; /* TODO __Userspace__ */
int stub; /* TODO __Userspace__ */
};
struct uma_keg {
int stub; /* TODO __Userspace__ */
int stub; /* TODO __Userspace__ */
};
struct uma_zone {
@ -83,16 +83,14 @@ struct uma_zone {
/* Prototype */
uma_zone_t
uma_zcreate(char *name, size_t size, uma_ctor ctor, uma_dtor dtor,
uma_init uminit, uma_fini fini, int align, u_int32_t flags);
uma_init uminit, uma_fini fini, int align, uint32_t flags);
#define uma_zone_set_max(zone, number) /* stub TODO __Userspace__ */
uma_zone_t
uma_zcreate(char *name, size_t size, uma_ctor ctor, uma_dtor dtor,
uma_init uminit, uma_fini fini, int align, u_int32_t flags)
{
return NULL; /* stub TODO __Userspace__. Also place implementation in a separate .c file */
uma_init uminit, uma_fini fini, int align, uint32_t flags) {
return NULL; /* stub TODO __Userspace__. Also place implementation in a separate .c file */
}
#endif

View File

@ -72,7 +72,16 @@ extern "C" {
#define int32_t __int32
#endif
#define ssize_t __int64
#ifndef ssize_t
#ifdef _WIN64
#define ssize_t __int64
#elif defined _WIN32
#define ssize_t int
#else
#error "Unknown platform!"
#endif
#endif
#define MSG_EOR 0x8
#ifndef EWOULDBLOCK
#define EWOULDBLOCK WSAEWOULDBLOCK
@ -127,12 +136,8 @@ struct sockaddr_conn {
#endif
union sctp_sockstore {
#if defined(INET)
struct sockaddr_in sin;
#endif
#if defined(INET6)
struct sockaddr_in6 sin6;
#endif
struct sockaddr_conn sconn;
struct sockaddr sa;
};
@ -141,6 +146,10 @@ union sctp_sockstore {
#define SCTP_CURRENT_ASSOC 1
#define SCTP_ALL_ASSOC 2
#define SCTP_EVENT_READ 0x0001
#define SCTP_EVENT_WRITE 0x0002
#define SCTP_EVENT_ERROR 0x0004
/*** Structures and definitions to use the socket API ***/
#define SCTP_ALIGN_RESV_PAD 92
@ -272,12 +281,13 @@ struct sctp_assoc_change {
#define SCTP_CANT_STR_ASSOC 0x0005
/* sac_info values */
#define SCTP_ASSOC_SUPPORTS_PR 0x01
#define SCTP_ASSOC_SUPPORTS_AUTH 0x02
#define SCTP_ASSOC_SUPPORTS_ASCONF 0x03
#define SCTP_ASSOC_SUPPORTS_MULTIBUF 0x04
#define SCTP_ASSOC_SUPPORTS_RE_CONFIG 0x05
#define SCTP_ASSOC_SUPPORTS_MAX 0x05
#define SCTP_ASSOC_SUPPORTS_PR 0x01
#define SCTP_ASSOC_SUPPORTS_AUTH 0x02
#define SCTP_ASSOC_SUPPORTS_ASCONF 0x03
#define SCTP_ASSOC_SUPPORTS_MULTIBUF 0x04
#define SCTP_ASSOC_SUPPORTS_RE_CONFIG 0x05
#define SCTP_ASSOC_SUPPORTS_INTERLEAVING 0x06
#define SCTP_ASSOC_SUPPORTS_MAX 0x06
/* Address event */
struct sctp_paddr_change {
@ -306,7 +316,7 @@ struct sctp_remote_error {
uint32_t sre_length;
uint16_t sre_error;
sctp_assoc_t sre_assoc_id;
uint8_t sre_data[4];
uint8_t sre_data[];
};
/* shutdown event */
@ -471,6 +481,8 @@ struct sctp_event_subscribe {
/* Flags that go into the sinfo->sinfo_flags field */
#define SCTP_DATA_LAST_FRAG 0x0001 /* tail part of the message could not be sent */
#define SCTP_DATA_NOT_FRAG 0x0003 /* complete message could not be sent */
#define SCTP_NOTIFICATION 0x0010 /* next message is a notification */
#define SCTP_COMPLETE 0x0020 /* next message is complete */
#define SCTP_EOF 0x0100 /* Start shutdown procedures */
@ -540,6 +552,14 @@ struct sctp_event_subscribe {
#define SCTP_DEFAULT_SNDINFO 0x00000021
#define SCTP_DEFAULT_PRINFO 0x00000022
#define SCTP_REMOTE_UDP_ENCAPS_PORT 0x00000024
#define SCTP_ECN_SUPPORTED 0x00000025
#define SCTP_PR_SUPPORTED 0x00000026
#define SCTP_AUTH_SUPPORTED 0x00000027
#define SCTP_ASCONF_SUPPORTED 0x00000028
#define SCTP_RECONFIG_SUPPORTED 0x00000029
#define SCTP_NRSACK_SUPPORTED 0x00000030
#define SCTP_PKTDROP_SUPPORTED 0x00000031
#define SCTP_MAX_CWND 0x00000032
#define SCTP_ENABLE_STREAM_RESET 0x00000900 /* struct sctp_assoc_value */
@ -875,6 +895,11 @@ usrsctp_init(uint16_t,
int (*)(void *addr, void *buffer, size_t length, uint8_t tos, uint8_t set_df),
void (*)(const char *format, ...));
void
usrsctp_init_nothreads(uint16_t,
int (*)(void *addr, void *buffer, size_t length, uint8_t tos, uint8_t set_df),
void (*)(const char *format, ...));
struct socket *
usrsctp_socket(int domain, int type, int protocol,
int (*receive_cb)(struct socket *sock, union sctp_sockstore addr, void *data,
@ -1008,6 +1033,21 @@ usrsctp_deregister_address(void *);
int
usrsctp_set_ulpinfo(struct socket *, void *);
int
usrsctp_get_ulpinfo(struct socket *, void **);
int
usrsctp_set_upcall(struct socket *so,
void (*upcall)(struct socket *, void *, int),
void *arg);
int
usrsctp_get_events(struct socket *so);
void
usrsctp_handle_timers(uint32_t elapsed_milliseconds);
#define SCTP_DUMP_OUTBOUND 1
#define SCTP_DUMP_INBOUND 0
@ -1026,8 +1066,16 @@ usrsctp_disable_crc32c_offload(void);
uint32_t
usrsctp_crc32c(void *, size_t);
#define USRSCTP_SYSCTL_DECL(__field) \
void usrsctp_sysctl_set_ ## __field(uint32_t value);\
#define USRSCTP_TUNABLE_DECL(__field) \
int usrsctp_tunable_set_ ## __field(uint32_t value);\
uint32_t usrsctp_sysctl_get_ ## __field(void);
USRSCTP_TUNABLE_DECL(sctp_hashtblsize)
USRSCTP_TUNABLE_DECL(sctp_pcbtblsize)
USRSCTP_TUNABLE_DECL(sctp_chunkscale)
#define USRSCTP_SYSCTL_DECL(__field) \
int usrsctp_sysctl_set_ ## __field(uint32_t value);\
uint32_t usrsctp_sysctl_get_ ## __field(void);
USRSCTP_SYSCTL_DECL(sctp_sendspace)
@ -1041,16 +1089,11 @@ USRSCTP_SYSCTL_DECL(sctp_asconf_enable)
USRSCTP_SYSCTL_DECL(sctp_reconfig_enable)
USRSCTP_SYSCTL_DECL(sctp_nrsack_enable)
USRSCTP_SYSCTL_DECL(sctp_pktdrop_enable)
#if !defined(SCTP_WITH_NO_CSUM)
USRSCTP_SYSCTL_DECL(sctp_no_csum_on_loopback)
#endif
USRSCTP_SYSCTL_DECL(sctp_peer_chunk_oh)
USRSCTP_SYSCTL_DECL(sctp_max_burst_default)
USRSCTP_SYSCTL_DECL(sctp_max_chunks_on_queue)
USRSCTP_SYSCTL_DECL(sctp_hashtblsize)
USRSCTP_SYSCTL_DECL(sctp_pcbtblsize)
USRSCTP_SYSCTL_DECL(sctp_min_split_point)
USRSCTP_SYSCTL_DECL(sctp_chunkscale)
USRSCTP_SYSCTL_DECL(sctp_delayed_sack_time_default)
USRSCTP_SYSCTL_DECL(sctp_sack_freq_default)
USRSCTP_SYSCTL_DECL(sctp_system_free_resc_limit)
@ -1091,6 +1134,7 @@ USRSCTP_SYSCTL_DECL(sctp_udp_tunneling_port)
USRSCTP_SYSCTL_DECL(sctp_enable_sack_immediately)
USRSCTP_SYSCTL_DECL(sctp_vtag_time_wait)
USRSCTP_SYSCTL_DECL(sctp_blackhole)
USRSCTP_SYSCTL_DECL(sctp_sendall_limit)
USRSCTP_SYSCTL_DECL(sctp_diag_info_code)
USRSCTP_SYSCTL_DECL(sctp_fr_max_burst_default)
USRSCTP_SYSCTL_DECL(sctp_path_pf_threshold)
@ -1156,7 +1200,7 @@ struct sctpstat {
uint32_t sctps_recvauthfailed; /* total number of auth failed */
uint32_t sctps_recvexpress; /* total fast path receives all one chunk */
uint32_t sctps_recvexpressm; /* total fast path multi-part data */
uint32_t sctps_recvnocrc;
uint32_t sctps_recv_spare; /* formerly sctps_recvnocrc */
uint32_t sctps_recvswcrc;
uint32_t sctps_recvhwcrc;
@ -1173,7 +1217,7 @@ struct sctpstat {
uint32_t sctps_sendecne; /* total output ECNE chunks */
uint32_t sctps_sendauth; /* total output AUTH chunks FIXME */
uint32_t sctps_senderrors; /* ip_output error counter */
uint32_t sctps_sendnocrc;
uint32_t sctps_send_spare; /* formerly sctps_sendnocrc */
uint32_t sctps_sendswcrc;
uint32_t sctps_sendhwcrc;
/* PCKDROPREP statistics: */