提交 0b676ed2 authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo
上级 caada823
...@@ -38,6 +38,8 @@ if (NOT CMAKE_BUILD_TYPE) ...@@ -38,6 +38,8 @@ if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "DEBUG") set(CMAKE_BUILD_TYPE "DEBUG")
endif () endif ()
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
include(CheckStructHasMember) include(CheckStructHasMember)
include(CheckIncludeFile) include(CheckIncludeFile)
include(CheckIncludeFiles) include(CheckIncludeFiles)
...@@ -108,6 +110,11 @@ if (have_netinet_ip_icmp_h) ...@@ -108,6 +110,11 @@ if (have_netinet_ip_icmp_h)
add_definitions(-DHAVE_NETINET_IP_ICMP_H) add_definitions(-DHAVE_NETINET_IP_ICMP_H)
endif () endif ()
check_include_files("net/route.h" have_net_route_h)
if (have_net_route_h)
add_definitions(-DHAVE_NET_ROUTE_H)
endif ()
check_include_files("stdatomic.h" have_stdatomic_h) check_include_files("stdatomic.h" have_stdatomic_h)
if (have_stdatomic_h) if (have_stdatomic_h)
add_definitions(-DHAVE_STDATOMIC_H) add_definitions(-DHAVE_STDATOMIC_H)
......
...@@ -364,7 +364,7 @@ SCTP_RECVRCVINFO | int | r/w ...@@ -364,7 +364,7 @@ SCTP_RECVRCVINFO | int | r/w
SCTP_RECVNXTINFO | int | r/w SCTP_RECVNXTINFO | int | r/w
SCTP_DEFAULT_SNDINFO | struct sctp_sndinfo | r/w SCTP_DEFAULT_SNDINFO | struct sctp_sndinfo | r/w
SCTP_DEFAULT_PRINFO | struct sctp_default_prinfo | r/w SCTP_DEFAULT_PRINFO | struct sctp_default_prinfo | r/w
SCTP_REMOTE_UDP_ENCAPS_PORT | int | r/w SCTP_REMOTE_UDP_ENCAPS_PORT | struct sctp_udpencaps | r/w
SCTP_ENABLE_STREAM_RESET | struct sctp_assoc_value | r/w SCTP_ENABLE_STREAM_RESET | struct sctp_assoc_value | r/w
SCTP_STATUS | struct sctp_status | r SCTP_STATUS | struct sctp_status | r
SCTP_GET_PEER_ADDR_INFO | struct sctp_paddrinfo | r SCTP_GET_PEER_ADDR_INFO | struct sctp_paddrinfo | r
......
find_path(MBEDTLS_INCLUDE_DIRS mbedtls/ssl.h)
find_library(MBEDTLS_LIBRARY mbedtls)
find_library(MBEDX509_LIBRARY mbedx509)
find_library(MBEDCRYPTO_LIBRARY mbedcrypto)
set(MBEDTLS_LIBRARIES "${MBEDTLS_LIBRARY}" "${MBEDX509_LIBRARY}" "${MBEDCRYPTO_LIBRARY}")
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(MbedTLS DEFAULT_MSG
MBEDTLS_LIBRARY MBEDTLS_INCLUDE_DIRS MBEDX509_LIBRARY MBEDCRYPTO_LIBRARY)
mark_as_advanced(MBEDTLS_INCLUDE_DIRS MBEDTLS_LIBRARY MBEDX509_LIBRARY MBEDCRYPTO_LIBRARY)
if(NOT TARGET MbedTLS)
message("in mbedtls ${MBEDTLS_LIBRARY}")
add_library(MbedTLS UNKNOWN IMPORTED)
set_target_properties(MbedTLS PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${MBEDTLS_INCLUDE_DIRS}"
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION "${MBEDTLS_LIBRARY}")
endif()
if(NOT TARGET MbedCrypto)
add_library(MbedCrypto UNKNOWN IMPORTED)
set_target_properties(MbedCrypto PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${MBEDTLS_INCLUDE_DIRS}"
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION "${MBEDCRYPTO_LIBRARY}")
endif()
if(NOT TARGET MbedX509)
add_library(MbedX509 UNKNOWN IMPORTED)
set_target_properties(MbedX509 PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${MBEDTLS_INCLUDE_DIRS}"
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION "${MBEDX509_LIBRARY}")
endif()
...@@ -143,6 +143,7 @@ AC_CHECK_HEADERS(sys/queue.h) ...@@ -143,6 +143,7 @@ AC_CHECK_HEADERS(sys/queue.h)
AC_CHECK_HEADERS(linux/if_addr.h, [], [], [#include <sys/socket.h>]) AC_CHECK_HEADERS(linux/if_addr.h, [], [], [#include <sys/socket.h>])
AC_CHECK_HEADERS(linux/rtnetlink.h, [], [], [#include <sys/socket.h>]) AC_CHECK_HEADERS(linux/rtnetlink.h, [], [], [#include <sys/socket.h>])
AC_CHECK_HEADERS(netinet/ip_icmp.h, [], [], [#include <netinet/ip.h>]) AC_CHECK_HEADERS(netinet/ip_icmp.h, [], [], [#include <netinet/ip.h>])
AC_CHECK_HEADERS(net/route.h)
AC_CHECK_MEMBER(struct sockaddr.sa_len, AC_CHECK_MEMBER(struct sockaddr.sa_len,
AC_DEFINE(HAVE_SA_LEN, 1, [Define this if your stack has sa_len in sockaddr struct.]),, AC_DEFINE(HAVE_SA_LEN, 1, [Define this if your stack has sa_len in sockaddr struct.]),,
......
...@@ -114,6 +114,11 @@ if have_sys_types and have_netinet_in and have_netinet_ip and have_netinet_ip_ic ...@@ -114,6 +114,11 @@ if have_sys_types and have_netinet_in and have_netinet_ip and have_netinet_ip_ic
add_project_arguments('-DHAVE_NETINET_IP_ICMP_H', language: 'c') add_project_arguments('-DHAVE_NETINET_IP_ICMP_H', language: 'c')
endif endif
# Feature: net/route
if compiler.has_header('net/route.h')
add_project_arguments('-DHAVE_NET_ROUTE_H', language: 'c')
endif
# Feature: stdatomic # Feature: stdatomic
if compiler.has_header('stdatomic.h') if compiler.has_header('stdatomic.h')
add_project_arguments('-DHAVE_STDATOMIC_H', language: 'c') add_project_arguments('-DHAVE_STDATOMIC_H', language: 'c')
......
...@@ -52,10 +52,18 @@ set(CMAKE_MACOSX_RPATH 1) ...@@ -52,10 +52,18 @@ set(CMAKE_MACOSX_RPATH 1)
include(CheckCCompilerFlag) include(CheckCCompilerFlag)
option(SCTP_USE_MBEDTLS_SHA1 "Build with mbedtls sha1 support." OFF)
add_definitions(-D__Userspace__) add_definitions(-D__Userspace__)
add_definitions(-DSCTP_SIMPLE_ALLOCATOR) add_definitions(-DSCTP_SIMPLE_ALLOCATOR)
add_definitions(-DSCTP_PROCESS_LEVEL_LOCKS) add_definitions(-DSCTP_PROCESS_LEVEL_LOCKS)
if(SCTP_USE_MBEDTLS_SHA1)
add_definitions(-DSCTP_USE_MBEDTLS_SHA1)
find_package(MbedTLS REQUIRED)
endif()
################################################# #################################################
# OS DEPENDENT # OS DEPENDENT
...@@ -176,11 +184,20 @@ add_library(usrsctp ${usrsctp_sources} ${usrsctp_headers}) ...@@ -176,11 +184,20 @@ add_library(usrsctp ${usrsctp_sources} ${usrsctp_headers})
target_include_directories(usrsctp PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_include_directories(usrsctp PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
if(SCTP_USE_MBEDTLS_SHA1)
target_include_directories(usrsctp PRIVATE ${MBEDTLS_INCLUDE_DIRS})
endif()
if (WIN32) if (WIN32)
message(STATUS "link library: ws2_32") message(STATUS "link library: ws2_32")
target_link_libraries(usrsctp ws2_32 iphlpapi) target_link_libraries(usrsctp ws2_32 iphlpapi)
endif () endif ()
if(SCTP_USE_MBEDTLS_SHA1)
target_link_libraries(usrsctp PRIVATE ${MBEDTLS_LIBRARIES})
endif()
set_target_properties(usrsctp PROPERTIES IMPORT_SUFFIX "_import.lib") set_target_properties(usrsctp PROPERTIES IMPORT_SUFFIX "_import.lib")
set_target_properties(usrsctp PROPERTIES SOVERSION ${SOVERSION_SHORT} VERSION ${SOVERSION_FULL}) set_target_properties(usrsctp PROPERTIES SOVERSION ${SOVERSION_SHORT} VERSION ${SOVERSION_FULL})
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
#if defined(__FreeBSD__) && !defined(__Userspace__) #if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h> #include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_constants.h 365071 2020-09-01 21:19:14Z mjg $"); __FBSDID("$FreeBSD$");
#endif #endif
#ifndef _NETINET_SCTP_CONSTANTS_H_ #ifndef _NETINET_SCTP_CONSTANTS_H_
...@@ -610,7 +610,7 @@ extern void getwintimeofday(struct timeval *tv); ...@@ -610,7 +610,7 @@ extern void getwintimeofday(struct timeval *tv);
#define SCTP_RTO_UPPER_BOUND (60000) /* 60 sec in ms */ #define SCTP_RTO_UPPER_BOUND (60000) /* 60 sec in ms */
#define SCTP_RTO_LOWER_BOUND (1000) /* 1 sec is ms */ #define SCTP_RTO_LOWER_BOUND (1000) /* 1 sec is ms */
#define SCTP_RTO_INITIAL (3000) /* 3 sec in ms */ #define SCTP_RTO_INITIAL (1000) /* 1 sec in ms */
#define SCTP_INP_KILL_TIMEOUT 20 /* number of ms to retry kill of inpcb */ #define SCTP_INP_KILL_TIMEOUT 20 /* number of ms to retry kill of inpcb */
#define SCTP_ASOC_KILL_TIMEOUT 10 /* number of ms to retry kill of inpcb */ #define SCTP_ASOC_KILL_TIMEOUT 10 /* number of ms to retry kill of inpcb */
......
...@@ -108,57 +108,12 @@ sctp_handle_init(struct mbuf *m, int iphlen, int offset, ...@@ -108,57 +108,12 @@ sctp_handle_init(struct mbuf *m, int iphlen, int offset,
if (stcb == NULL) { if (stcb == NULL) {
SCTP_INP_RLOCK(inp); SCTP_INP_RLOCK(inp);
} }
/* validate length */ /* Validate parameters */
if (ntohs(cp->ch.chunk_length) < sizeof(struct sctp_init_chunk)) {
op_err = sctp_generate_cause(SCTP_CAUSE_INVALID_PARAM, "");
sctp_abort_association(inp, stcb, m, iphlen, src, dst, sh, op_err,
#if defined(__FreeBSD__) && !defined(__Userspace__)
mflowtype, mflowid,
#endif
vrf_id, port);
if (stcb)
*abort_no_unlock = 1;
goto outnow;
}
/* validate parameters */
init = &cp->init; init = &cp->init;
if (init->initiate_tag == 0) { if ((ntohl(init->initiate_tag) == 0) ||
/* protocol error... send abort */ (ntohl(init->a_rwnd) < SCTP_MIN_RWND) ||
op_err = sctp_generate_cause(SCTP_CAUSE_INVALID_PARAM, ""); (ntohs(init->num_inbound_streams) == 0) ||
sctp_abort_association(inp, stcb, m, iphlen, src, dst, sh, op_err, (ntohs(init->num_outbound_streams) == 0)) {
#if defined(__FreeBSD__) && !defined(__Userspace__)
mflowtype, mflowid,
#endif
vrf_id, port);
if (stcb)
*abort_no_unlock = 1;
goto outnow;
}
if (ntohl(init->a_rwnd) < SCTP_MIN_RWND) {
/* invalid parameter... send abort */
op_err = sctp_generate_cause(SCTP_CAUSE_INVALID_PARAM, "");
sctp_abort_association(inp, stcb, m, iphlen, src, dst, sh, op_err,
#if defined(__FreeBSD__) && !defined(__Userspace__)
mflowtype, mflowid,
#endif
vrf_id, port);
if (stcb)
*abort_no_unlock = 1;
goto outnow;
}
if (init->num_inbound_streams == 0) {
/* protocol error... send abort */
op_err = sctp_generate_cause(SCTP_CAUSE_INVALID_PARAM, "");
sctp_abort_association(inp, stcb, m, iphlen, src, dst, sh, op_err,
#if defined(__FreeBSD__) && !defined(__Userspace__)
mflowtype, mflowid,
#endif
vrf_id, port);
if (stcb)
*abort_no_unlock = 1;
goto outnow;
}
if (init->num_outbound_streams == 0) {
/* protocol error... send abort */ /* protocol error... send abort */
op_err = sctp_generate_cause(SCTP_CAUSE_INVALID_PARAM, ""); op_err = sctp_generate_cause(SCTP_CAUSE_INVALID_PARAM, "");
sctp_abort_association(inp, stcb, m, iphlen, src, dst, sh, op_err, sctp_abort_association(inp, stcb, m, iphlen, src, dst, sh, op_err,
...@@ -514,18 +469,26 @@ sctp_process_init_ack(struct mbuf *m, int iphlen, int offset, ...@@ -514,18 +469,26 @@ sctp_process_init_ack(struct mbuf *m, int iphlen, int offset,
asoc = &stcb->asoc; asoc = &stcb->asoc;
asoc->peer_supports_nat = (uint8_t)nat_friendly; asoc->peer_supports_nat = (uint8_t)nat_friendly;
/* process the peer's parameters in the INIT-ACK */ /* process the peer's parameters in the INIT-ACK */
retval = sctp_process_init((struct sctp_init_chunk *)cp, stcb); if (sctp_process_init((struct sctp_init_chunk *)cp, stcb) < 0) {
if (retval < 0) {
if (op_err != NULL) { if (op_err != NULL) {
sctp_m_freem(op_err); sctp_m_freem(op_err);
} }
return (retval); op_err = sctp_generate_cause(SCTP_CAUSE_OUT_OF_RESC, "");
SCTPDBG(SCTP_DEBUG_INPUT1, "sctp_process_init() failed\n");
sctp_abort_association(stcb->sctp_ep, stcb, m, iphlen,
src, dst, sh, op_err,
#if defined(__FreeBSD__) && !defined(__Userspace__)
mflowtype, mflowid,
#endif
vrf_id, net->port);
*abort_no_unlock = 1;
return (-1);
} }
initack_limit = offset + ntohs(cp->ch.chunk_length); initack_limit = offset + ntohs(cp->ch.chunk_length);
/* load all addresses */ /* load all addresses */
if ((retval = sctp_load_addresses_from_init(stcb, m, if ((retval = sctp_load_addresses_from_init(stcb, m,
(offset + sizeof(struct sctp_init_chunk)), initack_limit, offset + sizeof(struct sctp_init_chunk),
src, dst, NULL, stcb->asoc.port))) { initack_limit, src, dst, NULL, stcb->asoc.port)) < 0) {
if (op_err != NULL) { if (op_err != NULL) {
sctp_m_freem(op_err); sctp_m_freem(op_err);
} }
...@@ -1420,57 +1383,12 @@ sctp_handle_init_ack(struct mbuf *m, int iphlen, int offset, ...@@ -1420,57 +1383,12 @@ sctp_handle_init_ack(struct mbuf *m, int iphlen, int offset,
"sctp_handle_init_ack: TCB is null\n"); "sctp_handle_init_ack: TCB is null\n");
return (-1); return (-1);
} }
if (ntohs(cp->ch.chunk_length) < sizeof(struct sctp_init_ack_chunk)) {
/* Invalid length */
op_err = sctp_generate_cause(SCTP_CAUSE_INVALID_PARAM, "");
sctp_abort_association(stcb->sctp_ep, stcb, m, iphlen,
src, dst, sh, op_err,
#if defined(__FreeBSD__) && !defined(__Userspace__)
mflowtype, mflowid,
#endif
vrf_id, net->port);
*abort_no_unlock = 1;
return (-1);
}
init_ack = &cp->init; init_ack = &cp->init;
/* validate parameters */ /* Validate parameters. */
if (init_ack->initiate_tag == 0) { if ((ntohl(init_ack->initiate_tag) == 0) ||
/* protocol error... send an abort */ (ntohl(init_ack->a_rwnd) < SCTP_MIN_RWND) ||
op_err = sctp_generate_cause(SCTP_CAUSE_INVALID_PARAM, ""); (ntohs(init_ack->num_inbound_streams) == 0) ||
sctp_abort_association(stcb->sctp_ep, stcb, m, iphlen, (ntohs(init_ack->num_outbound_streams) == 0)) {
src, dst, sh, op_err,
#if defined(__FreeBSD__) && !defined(__Userspace__)
mflowtype, mflowid,
#endif
vrf_id, net->port);
*abort_no_unlock = 1;
return (-1);
}
if (ntohl(init_ack->a_rwnd) < SCTP_MIN_RWND) {
/* protocol error... send an abort */
op_err = sctp_generate_cause(SCTP_CAUSE_INVALID_PARAM, "");
sctp_abort_association(stcb->sctp_ep, stcb, m, iphlen,
src, dst, sh, op_err,
#if defined(__FreeBSD__) && !defined(__Userspace__)
mflowtype, mflowid,
#endif
vrf_id, net->port);
*abort_no_unlock = 1;
return (-1);
}
if (init_ack->num_inbound_streams == 0) {
/* protocol error... send an abort */
op_err = sctp_generate_cause(SCTP_CAUSE_INVALID_PARAM, "");
sctp_abort_association(stcb->sctp_ep, stcb, m, iphlen,
src, dst, sh, op_err,
#if defined(__FreeBSD__) && !defined(__Userspace__)
mflowtype, mflowid,
#endif
vrf_id, net->port);
*abort_no_unlock = 1;
return (-1);
}
if (init_ack->num_outbound_streams == 0) {
/* protocol error... send an abort */ /* protocol error... send an abort */
op_err = sctp_generate_cause(SCTP_CAUSE_INVALID_PARAM, ""); op_err = sctp_generate_cause(SCTP_CAUSE_INVALID_PARAM, "");
sctp_abort_association(stcb->sctp_ep, stcb, m, iphlen, sctp_abort_association(stcb->sctp_ep, stcb, m, iphlen,
...@@ -1624,6 +1542,7 @@ sctp_process_cookie_existing(struct mbuf *m, int iphlen, int offset, ...@@ -1624,6 +1542,7 @@ sctp_process_cookie_existing(struct mbuf *m, int iphlen, int offset,
vrf_id, net->port); vrf_id, net->port);
if (how_indx < sizeof(asoc->cookie_how)) if (how_indx < sizeof(asoc->cookie_how))
asoc->cookie_how[how_indx] = 2; asoc->cookie_how[how_indx] = 2;
SCTP_TCB_UNLOCK(stcb);
return (NULL); return (NULL);
} }
/* /*
...@@ -1638,9 +1557,11 @@ sctp_process_cookie_existing(struct mbuf *m, int iphlen, int offset, ...@@ -1638,9 +1557,11 @@ sctp_process_cookie_existing(struct mbuf *m, int iphlen, int offset,
(uint8_t *) & init_buf); (uint8_t *) & init_buf);
if (init_cp == NULL) { if (init_cp == NULL) {
/* could not pull a INIT chunk in cookie */ /* could not pull a INIT chunk in cookie */
SCTP_TCB_UNLOCK(stcb);
return (NULL); return (NULL);
} }
if (init_cp->ch.chunk_type != SCTP_INITIATION) { if (init_cp->ch.chunk_type != SCTP_INITIATION) {
SCTP_TCB_UNLOCK(stcb);
return (NULL); return (NULL);
} }
/* /*
...@@ -1653,9 +1574,11 @@ sctp_process_cookie_existing(struct mbuf *m, int iphlen, int offset, ...@@ -1653,9 +1574,11 @@ sctp_process_cookie_existing(struct mbuf *m, int iphlen, int offset,
(uint8_t *) & initack_buf); (uint8_t *) & initack_buf);
if (initack_cp == NULL) { if (initack_cp == NULL) {
/* could not pull INIT-ACK chunk in cookie */ /* could not pull INIT-ACK chunk in cookie */
SCTP_TCB_UNLOCK(stcb);
return (NULL); return (NULL);
} }
if (initack_cp->ch.chunk_type != SCTP_INITIATION_ACK) { if (initack_cp->ch.chunk_type != SCTP_INITIATION_ACK) {
SCTP_TCB_UNLOCK(stcb);
return (NULL); return (NULL);
} }
if ((ntohl(initack_cp->init.initiate_tag) == asoc->my_vtag) && if ((ntohl(initack_cp->init.initiate_tag) == asoc->my_vtag) &&
...@@ -1681,6 +1604,7 @@ sctp_process_cookie_existing(struct mbuf *m, int iphlen, int offset, ...@@ -1681,6 +1604,7 @@ sctp_process_cookie_existing(struct mbuf *m, int iphlen, int offset,
*/ */
if (how_indx < sizeof(asoc->cookie_how)) if (how_indx < sizeof(asoc->cookie_how))
asoc->cookie_how[how_indx] = 17; asoc->cookie_how[how_indx] = 17;
SCTP_TCB_UNLOCK(stcb);
return (NULL); return (NULL);
} }
switch (SCTP_GET_STATE(stcb)) { switch (SCTP_GET_STATE(stcb)) {
...@@ -1693,10 +1617,17 @@ sctp_process_cookie_existing(struct mbuf *m, int iphlen, int offset, ...@@ -1693,10 +1617,17 @@ sctp_process_cookie_existing(struct mbuf *m, int iphlen, int offset,
* have the right seq no's. * have the right seq no's.
*/ */
/* First we must process the INIT !! */ /* First we must process the INIT !! */
retval = sctp_process_init(init_cp, stcb); if (sctp_process_init(init_cp, stcb) < 0) {
if (retval < 0) {
if (how_indx < sizeof(asoc->cookie_how)) if (how_indx < sizeof(asoc->cookie_how))
asoc->cookie_how[how_indx] = 3; asoc->cookie_how[how_indx] = 3;
op_err = sctp_generate_cause(SCTP_CAUSE_OUT_OF_RESC, "");
SCTPDBG(SCTP_DEBUG_INPUT1, "sctp_process_init() failed\n");
sctp_abort_association(stcb->sctp_ep, stcb, m, iphlen,
src, dst, sh, op_err,
#if defined(__FreeBSD__) && !defined(__Userspace__)
mflowtype, mflowid,
#endif
vrf_id, net->port);
return (NULL); return (NULL);
} }
/* we have already processed the INIT so no problem */ /* we have already processed the INIT so no problem */
...@@ -1741,6 +1672,7 @@ sctp_process_cookie_existing(struct mbuf *m, int iphlen, int offset, ...@@ -1741,6 +1672,7 @@ sctp_process_cookie_existing(struct mbuf *m, int iphlen, int offset,
SCTP_TCB_LOCK(stcb); SCTP_TCB_LOCK(stcb);
atomic_add_int(&stcb->asoc.refcnt, -1); atomic_add_int(&stcb->asoc.refcnt, -1);
if (stcb->asoc.state & SCTP_STATE_CLOSED_SOCKET) { if (stcb->asoc.state & SCTP_STATE_CLOSED_SOCKET) {
SCTP_TCB_UNLOCK(stcb);
SCTP_SOCKET_UNLOCK(so, 1); SCTP_SOCKET_UNLOCK(so, 1);
return (NULL); return (NULL);
} }
...@@ -1776,16 +1708,22 @@ sctp_process_cookie_existing(struct mbuf *m, int iphlen, int offset, ...@@ -1776,16 +1708,22 @@ sctp_process_cookie_existing(struct mbuf *m, int iphlen, int offset,
break; break;
} /* end switch */ } /* end switch */
sctp_stop_all_cookie_timers(stcb); sctp_stop_all_cookie_timers(stcb);
/* if ((retval = sctp_load_addresses_from_init(stcb, m,
* We ignore the return code here.. not sure if we should
* somehow abort.. but we do have an existing asoc. This
* really should not fail.
*/
if (sctp_load_addresses_from_init(stcb, m,
init_offset + sizeof(struct sctp_init_chunk), init_offset + sizeof(struct sctp_init_chunk),
initack_offset, src, dst, init_src, stcb->asoc.port)) { initack_offset, src, dst, init_src, stcb->asoc.port)) < 0) {
if (how_indx < sizeof(asoc->cookie_how)) if (how_indx < sizeof(asoc->cookie_how))
asoc->cookie_how[how_indx] = 4; asoc->cookie_how[how_indx] = 4;
op_err = sctp_generate_cause(SCTP_BASE_SYSCTL(sctp_diag_info_code),
"Problem with address parameters");
SCTPDBG(SCTP_DEBUG_INPUT1,
"Load addresses from INIT causes an abort %d\n",
retval);
sctp_abort_association(stcb->sctp_ep, stcb, m, iphlen,
src, dst, sh, op_err,
#if defined(__FreeBSD__) && !defined(__Userspace__)
mflowtype, mflowid,
#endif
vrf_id, net->port);
return (NULL); return (NULL);
} }
/* respond with a COOKIE-ACK */ /* respond with a COOKIE-ACK */
...@@ -1805,6 +1743,7 @@ sctp_process_cookie_existing(struct mbuf *m, int iphlen, int offset, ...@@ -1805,6 +1743,7 @@ sctp_process_cookie_existing(struct mbuf *m, int iphlen, int offset,
*/ */
if (how_indx < sizeof(asoc->cookie_how)) if (how_indx < sizeof(asoc->cookie_how))
asoc->cookie_how[how_indx] = 6; asoc->cookie_how[how_indx] = 6;
SCTP_TCB_UNLOCK(stcb);
return (NULL); return (NULL);
} }
/* If nat support, and the below and stcb is established, /* If nat support, and the below and stcb is established,
...@@ -1830,6 +1769,7 @@ sctp_process_cookie_existing(struct mbuf *m, int iphlen, int offset, ...@@ -1830,6 +1769,7 @@ sctp_process_cookie_existing(struct mbuf *m, int iphlen, int offset,
mflowtype, mflowid, inp->fibnum, mflowtype, mflowid, inp->fibnum,
#endif #endif
vrf_id, port); vrf_id, port);
SCTP_TCB_UNLOCK(stcb);
return (NULL); return (NULL);
} }
if ((ntohl(initack_cp->init.initiate_tag) == asoc->my_vtag) && if ((ntohl(initack_cp->init.initiate_tag) == asoc->my_vtag) &&
...@@ -1859,6 +1799,7 @@ sctp_process_cookie_existing(struct mbuf *m, int iphlen, int offset, ...@@ -1859,6 +1799,7 @@ sctp_process_cookie_existing(struct mbuf *m, int iphlen, int offset,
if (how_indx < sizeof(asoc->cookie_how)) if (how_indx < sizeof(asoc->cookie_how))
asoc->cookie_how[how_indx] = 7; asoc->cookie_how[how_indx] = 7;
SCTP_TCB_UNLOCK(stcb);
return (NULL); return (NULL);
} }
if (how_indx < sizeof(asoc->cookie_how)) if (how_indx < sizeof(asoc->cookie_how))
...@@ -1901,17 +1842,35 @@ sctp_process_cookie_existing(struct mbuf *m, int iphlen, int offset, ...@@ -1901,17 +1842,35 @@ sctp_process_cookie_existing(struct mbuf *m, int iphlen, int offset,
} }
} }
/* process the INIT info (peer's info) */ /* process the INIT info (peer's info) */
retval = sctp_process_init(init_cp, stcb); if (sctp_process_init(init_cp, stcb) < 0) {
if (retval < 0) {
if (how_indx < sizeof(asoc->cookie_how)) if (how_indx < sizeof(asoc->cookie_how))
asoc->cookie_how[how_indx] = 9; asoc->cookie_how[how_indx] = 9;
op_err = sctp_generate_cause(SCTP_CAUSE_OUT_OF_RESC, "");
SCTPDBG(SCTP_DEBUG_INPUT1, "sctp_process_init() failed\n");
sctp_abort_association(stcb->sctp_ep, stcb, m, iphlen,
src, dst, sh, op_err,
#if defined(__FreeBSD__) && !defined(__Userspace__)
mflowtype, mflowid,
#endif
vrf_id, net->port);
return (NULL); return (NULL);
} }
if (sctp_load_addresses_from_init(stcb, m, if ((retval = sctp_load_addresses_from_init(stcb, m,
init_offset + sizeof(struct sctp_init_chunk), init_offset + sizeof(struct sctp_init_chunk),
initack_offset, src, dst, init_src, stcb->asoc.port)) { initack_offset, src, dst, init_src, stcb->asoc.port)) < 0) {
if (how_indx < sizeof(asoc->cookie_how)) if (how_indx < sizeof(asoc->cookie_how))
asoc->cookie_how[how_indx] = 10; asoc->cookie_how[how_indx] = 10;
op_err = sctp_generate_cause(SCTP_BASE_SYSCTL(sctp_diag_info_code),
"Problem with address parameters");
SCTPDBG(SCTP_DEBUG_INPUT1,
"Load addresses from INIT causes an abort %d\n",
retval);
sctp_abort_association(stcb->sctp_ep, stcb, m, iphlen,
src, dst, sh, op_err,
#if defined(__FreeBSD__) && !defined(__Userspace__)
mflowtype, mflowid,
#endif
vrf_id, net->port);
return (NULL); return (NULL);
} }
if ((SCTP_GET_STATE(stcb) == SCTP_STATE_COOKIE_WAIT) || if ((SCTP_GET_STATE(stcb) == SCTP_STATE_COOKIE_WAIT) ||
...@@ -1933,6 +1892,7 @@ sctp_process_cookie_existing(struct mbuf *m, int iphlen, int offset, ...@@ -1933,6 +1892,7 @@ sctp_process_cookie_existing(struct mbuf *m, int iphlen, int offset,
SCTP_TCB_LOCK(stcb); SCTP_TCB_LOCK(stcb);
atomic_add_int(&stcb->asoc.refcnt, -1); atomic_add_int(&stcb->asoc.refcnt, -1);
if (stcb->asoc.state & SCTP_STATE_CLOSED_SOCKET) { if (stcb->asoc.state & SCTP_STATE_CLOSED_SOCKET) {
SCTP_TCB_UNLOCK(stcb);
SCTP_SOCKET_UNLOCK(so, 1); SCTP_SOCKET_UNLOCK(so, 1);
return (NULL); return (NULL);
} }
...@@ -1985,19 +1945,25 @@ sctp_process_cookie_existing(struct mbuf *m, int iphlen, int offset, ...@@ -1985,19 +1945,25 @@ sctp_process_cookie_existing(struct mbuf *m, int iphlen, int offset,
#endif #endif
if (asoc->peer_supports_nat) { if (asoc->peer_supports_nat) {
struct sctp_tcb *local_stcb;
/* This is a gross gross hack. /* This is a gross gross hack.
* Just call the cookie_new code since we * Just call the cookie_new code since we
* are allowing a duplicate association. * are allowing a duplicate association.
* I hope this works... * I hope this works...
*/ */
return (sctp_process_cookie_new(m, iphlen, offset, src, dst, local_stcb = sctp_process_cookie_new(m, iphlen, offset, src, dst,
sh, cookie, cookie_len, sh, cookie, cookie_len,
inp, netp, init_src,notification, inp, netp, init_src,notification,
auth_skipped, auth_offset, auth_len, auth_skipped, auth_offset, auth_len,
#if defined(__FreeBSD__) && !defined(__Userspace__) #if defined(__FreeBSD__) && !defined(__Userspace__)
mflowtype, mflowid, mflowtype, mflowid,
#endif #endif
vrf_id, port)); vrf_id, port);
if (local_stcb == NULL) {
SCTP_TCB_UNLOCK(stcb);
}
return (local_stcb);
} }
/* /*
* case A in Section 5.2.4 Table 2: XXMM (peer restarted) * case A in Section 5.2.4 Table 2: XXMM (peer restarted)
...@@ -2005,11 +1971,7 @@ sctp_process_cookie_existing(struct mbuf *m, int iphlen, int offset, ...@@ -2005,11 +1971,7 @@ sctp_process_cookie_existing(struct mbuf *m, int iphlen, int offset,
/* temp code */ /* temp code */
if (how_indx < sizeof(asoc->cookie_how)) if (how_indx < sizeof(asoc->cookie_how))
asoc->cookie_how[how_indx] = 12; asoc->cookie_how[how_indx] = 12;
sctp_timer_stop(SCTP_TIMER_TYPE_INIT, inp, stcb, net, sctp_stop_association_timers(stcb, false);
SCTP_FROM_SCTP_INPUT + SCTP_LOC_16);
sctp_timer_stop(SCTP_TIMER_TYPE_HEARTBEAT, inp, stcb, net,
SCTP_FROM_SCTP_INPUT + SCTP_LOC_17);
/* notify upper layer */ /* notify upper layer */
*notification = SCTP_NOTIFY_ASSOC_RESTART; *notification = SCTP_NOTIFY_ASSOC_RESTART;
atomic_add_int(&stcb->asoc.refcnt, 1); atomic_add_int(&stcb->asoc.refcnt, 1);
...@@ -2042,6 +2004,10 @@ sctp_process_cookie_existing(struct mbuf *m, int iphlen, int offset, ...@@ -2042,6 +2004,10 @@ sctp_process_cookie_existing(struct mbuf *m, int iphlen, int offset,
asoc->str_reset_seq_in = asoc->init_seq_number; asoc->str_reset_seq_in = asoc->init_seq_number;
asoc->advanced_peer_ack_point = asoc->last_acked_seq; asoc->advanced_peer_ack_point = asoc->last_acked_seq;
asoc->send_sack = 1; asoc->send_sack = 1;
asoc->data_pkts_seen = 0;
asoc->last_data_chunk_from = NULL;
asoc->last_control_chunk_from = NULL;
asoc->last_net_cmt_send_started = NULL;
if (asoc->mapping_array) { if (asoc->mapping_array) {
memset(asoc->mapping_array, 0, memset(asoc->mapping_array, 0,
asoc->mapping_array_size); asoc->mapping_array_size);
...@@ -2106,6 +2072,9 @@ sctp_process_cookie_existing(struct mbuf *m, int iphlen, int offset, ...@@ -2106,6 +2072,9 @@ sctp_process_cookie_existing(struct mbuf *m, int iphlen, int offset,
SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_chunk), chk); SCTP_ZONE_FREE(SCTP_BASE_INFO(ipi_zone_chunk), chk);
SCTP_DECR_CHK_COUNT(); SCTP_DECR_CHK_COUNT();
} }
asoc->ctrl_queue_cnt = 0;
asoc->str_reset = NULL;
asoc->stream_reset_outstanding = 0;
TAILQ_FOREACH_SAFE(chk, &asoc->asconf_send_queue, sctp_next, nchk) { TAILQ_FOREACH_SAFE(chk, &asoc->asconf_send_queue, sctp_next, nchk) {
TAILQ_REMOVE(&asoc->asconf_send_queue, chk, sctp_next); TAILQ_REMOVE(&asoc->asconf_send_queue, chk, sctp_next);
if (chk->data) { if (chk->data) {
...@@ -2154,11 +2123,17 @@ sctp_process_cookie_existing(struct mbuf *m, int iphlen, int offset, ...@@ -2154,11 +2123,17 @@ sctp_process_cookie_existing(struct mbuf *m, int iphlen, int offset,
asoc->total_flight = 0; asoc->total_flight = 0;
asoc->total_flight_count = 0; asoc->total_flight_count = 0;
/* process the INIT info (peer's info) */ /* process the INIT info (peer's info) */
retval = sctp_process_init(init_cp, stcb); if (sctp_process_init(init_cp, stcb) < 0) {
if (retval < 0) {
if (how_indx < sizeof(asoc->cookie_how)) if (how_indx < sizeof(asoc->cookie_how))
asoc->cookie_how[how_indx] = 13; asoc->cookie_how[how_indx] = 13;
op_err = sctp_generate_cause(SCTP_CAUSE_OUT_OF_RESC, "");
SCTPDBG(SCTP_DEBUG_INPUT1, "sctp_process_init() failed\n");
sctp_abort_association(stcb->sctp_ep, stcb, m, iphlen,
src, dst, sh, op_err,
#if defined(__FreeBSD__) && !defined(__Userspace__)
mflowtype, mflowid,
#endif
vrf_id, net->port);
return (NULL); return (NULL);
} }
/* /*
...@@ -2167,26 +2142,38 @@ sctp_process_cookie_existing(struct mbuf *m, int iphlen, int offset, ...@@ -2167,26 +2142,38 @@ sctp_process_cookie_existing(struct mbuf *m, int iphlen, int offset,
*/ */
net->hb_responded = 1; net->hb_responded = 1;
if (sctp_load_addresses_from_init(stcb, m, if ((retval = sctp_load_addresses_from_init(stcb, m,
init_offset + sizeof(struct sctp_init_chunk), init_offset + sizeof(struct sctp_init_chunk),
initack_offset, src, dst, init_src, stcb->asoc.port)) { initack_offset, src, dst, init_src, stcb->asoc.port)) < 0) {
if (how_indx < sizeof(asoc->cookie_how)) if (how_indx < sizeof(asoc->cookie_how))
asoc->cookie_how[how_indx] = 14; asoc->cookie_how[how_indx] = 14;
op_err = sctp_generate_cause(SCTP_BASE_SYSCTL(sctp_diag_info_code),
"Problem with address parameters");
SCTPDBG(SCTP_DEBUG_INPUT1,
"Load addresses from INIT causes an abort %d\n",
retval);
sctp_abort_association(stcb->sctp_ep, stcb, m, iphlen,
src, dst, sh, op_err,
#if defined(__FreeBSD__) && !defined(__Userspace__)
mflowtype, mflowid,
#endif
vrf_id, net->port);
return (NULL); return (NULL);
} }
/* respond with a COOKIE-ACK */ /* respond with a COOKIE-ACK */
sctp_stop_all_cookie_timers(stcb);
sctp_toss_old_cookies(stcb, asoc);
sctp_send_cookie_ack(stcb); sctp_send_cookie_ack(stcb);
if (how_indx < sizeof(asoc->cookie_how)) if (how_indx < sizeof(asoc->cookie_how))
asoc->cookie_how[how_indx] = 15; asoc->cookie_how[how_indx] = 15;
if (sctp_is_feature_on(inp, SCTP_PCB_FLAGS_AUTOCLOSE) &&
(asoc->sctp_autoclose_ticks > 0)) {
sctp_timer_start(SCTP_TIMER_TYPE_AUTOCLOSE, inp, stcb, NULL);
}
return (stcb); return (stcb);
} }
if (how_indx < sizeof(asoc->cookie_how)) if (how_indx < sizeof(asoc->cookie_how))
asoc->cookie_how[how_indx] = 16; asoc->cookie_how[how_indx] = 16;
/* all other cases... */ /* all other cases... */
SCTP_TCB_UNLOCK(stcb);
return (NULL); return (NULL);
} }
...@@ -2360,8 +2347,7 @@ sctp_process_cookie_new(struct mbuf *m, int iphlen, int offset, ...@@ -2360,8 +2347,7 @@ sctp_process_cookie_new(struct mbuf *m, int iphlen, int offset,
asoc->advanced_peer_ack_point = asoc->last_acked_seq; asoc->advanced_peer_ack_point = asoc->last_acked_seq;
/* process the INIT info (peer's info) */ /* process the INIT info (peer's info) */
retval = sctp_process_init(init_cp, stcb); if (sctp_process_init(init_cp, stcb) < 0) {
if (retval < 0) {
#if defined(__APPLE__) && !defined(__Userspace__) #if defined(__APPLE__) && !defined(__Userspace__)
atomic_add_int(&stcb->asoc.refcnt, 1); atomic_add_int(&stcb->asoc.refcnt, 1);
SCTP_TCB_UNLOCK(stcb); SCTP_TCB_UNLOCK(stcb);
...@@ -2377,9 +2363,9 @@ sctp_process_cookie_new(struct mbuf *m, int iphlen, int offset, ...@@ -2377,9 +2363,9 @@ sctp_process_cookie_new(struct mbuf *m, int iphlen, int offset,
return (NULL); return (NULL);
} }
/* load all addresses */ /* load all addresses */
if (sctp_load_addresses_from_init(stcb, m, if ((retval = sctp_load_addresses_from_init(stcb, m,
init_offset + sizeof(struct sctp_init_chunk), initack_offset, init_offset + sizeof(struct sctp_init_chunk),
src, dst, init_src, port)) { initack_offset, src, dst, init_src, port)) < 0) {
#if defined(__APPLE__) && !defined(__Userspace__) #if defined(__APPLE__) && !defined(__Userspace__)
atomic_add_int(&stcb->asoc.refcnt, 1); atomic_add_int(&stcb->asoc.refcnt, 1);
SCTP_TCB_UNLOCK(stcb); SCTP_TCB_UNLOCK(stcb);
...@@ -2962,6 +2948,9 @@ sctp_handle_cookie_echo(struct mbuf *m, int iphlen, int offset, ...@@ -2962,6 +2948,9 @@ sctp_handle_cookie_echo(struct mbuf *m, int iphlen, int offset,
mflowtype, mflowid, mflowtype, mflowid,
#endif #endif
vrf_id, port); vrf_id, port);
if (*stcb == NULL) {
*locked_tcb = NULL;
}
} }
if (*stcb == NULL) { if (*stcb == NULL) {
...@@ -3847,19 +3836,16 @@ sctp_find_stream_reset(struct sctp_tcb *stcb, uint32_t seq, struct sctp_tmit_chu ...@@ -3847,19 +3836,16 @@ sctp_find_stream_reset(struct sctp_tcb *stcb, uint32_t seq, struct sctp_tmit_chu
int len, clen; int len, clen;
asoc = &stcb->asoc; asoc = &stcb->asoc;
if (TAILQ_EMPTY(&stcb->asoc.control_send_queue)) { chk = asoc->str_reset;
asoc->stream_reset_outstanding = 0; if (TAILQ_EMPTY(&asoc->control_send_queue) ||
return (NULL); (chk == NULL)) {
}
if (stcb->asoc.str_reset == NULL) {
asoc->stream_reset_outstanding = 0; asoc->stream_reset_outstanding = 0;
return (NULL); return (NULL);
} }
chk = stcb->asoc.str_reset;
if (chk->data == NULL) { if (chk->data == NULL) {
return (NULL); return (NULL);
} }
if (bchk) { if (bchk != NULL) {
/* he wants a copy of the chk pointer */ /* he wants a copy of the chk pointer */
*bchk = chk; *bchk = chk;
} }
...@@ -4798,6 +4784,7 @@ sctp_process_control(struct mbuf *m, int iphlen, int *offset, int length, ...@@ -4798,6 +4784,7 @@ sctp_process_control(struct mbuf *m, int iphlen, int *offset, int length,
int ret; int ret;
int abort_no_unlock = 0; int abort_no_unlock = 0;
int ecne_seen = 0; int ecne_seen = 0;
int abort_flag;
/* /*
* How big should this be, and should it be alloc'd? Lets try the * How big should this be, and should it be alloc'd? Lets try the
* d-mtu-ceiling for now (2k) and that should hopefully work ... * d-mtu-ceiling for now (2k) and that should hopefully work ...
...@@ -4962,29 +4949,6 @@ sctp_process_control(struct mbuf *m, int iphlen, int *offset, int length, ...@@ -4962,29 +4949,6 @@ sctp_process_control(struct mbuf *m, int iphlen, int *offset, int length,
} }
return (NULL); return (NULL);
} }
} else if (ch->chunk_type == SCTP_SHUTDOWN_ACK) {
if (vtag_in != asoc->my_vtag) {
/*
* this could be a stale SHUTDOWN-ACK or the
* peer never got the SHUTDOWN-COMPLETE and
* is still hung; we have started a new asoc
* but it won't complete until the shutdown
* is completed
*/
if (stcb != NULL) {
SCTP_TCB_UNLOCK(stcb);
}
SCTP_SNPRINTF(msg, sizeof(msg), "OOTB, %s:%d at %s", __FILE__, __LINE__, __func__);
op_err = sctp_generate_cause(SCTP_BASE_SYSCTL(sctp_diag_info_code),
msg);
sctp_handle_ootb(m, iphlen, *offset, src, dst,
sh, inp, op_err,
#if defined(__FreeBSD__) && !defined(__Userspace__)
mflowtype, mflowid, fibnum,
#endif
vrf_id, port);
return (NULL);
}
} else { } else {
/* for all other chunks, vtag must match */ /* for all other chunks, vtag must match */
if (vtag_in != asoc->my_vtag) { if (vtag_in != asoc->my_vtag) {
...@@ -5047,10 +5011,7 @@ sctp_process_control(struct mbuf *m, int iphlen, int *offset, int length, ...@@ -5047,10 +5011,7 @@ sctp_process_control(struct mbuf *m, int iphlen, int *offset, int length,
chunk_buf); chunk_buf);
if (ch == NULL) { if (ch == NULL) {
*offset = length; *offset = length;
if (stcb != NULL) { return (stcb);
SCTP_TCB_UNLOCK(stcb);
}
return (NULL);
} }
num_chunks++; num_chunks++;
...@@ -5084,12 +5045,12 @@ sctp_process_control(struct mbuf *m, int iphlen, int *offset, int length, ...@@ -5084,12 +5045,12 @@ sctp_process_control(struct mbuf *m, int iphlen, int *offset, int length,
/* The INIT chunk must be the only chunk. */ /* The INIT chunk must be the only chunk. */
if ((num_chunks > 1) || if ((num_chunks > 1) ||
(length - *offset > (int)SCTP_SIZE32(chk_length))) { (length - *offset > (int)SCTP_SIZE32(chk_length))) {
/* RFC 4960 requires that no ABORT is sent */ /*
* RFC 4960bis requires stopping the
* processing of the packet.
*/
*offset = length; *offset = length;
if (stcb != NULL) { return (stcb);
SCTP_TCB_UNLOCK(stcb);
}
return (NULL);
} }
/* Honor our resource limit. */ /* Honor our resource limit. */
if (chk_length > SCTP_LARGEST_INIT_ACCEPTED) { if (chk_length > SCTP_LARGEST_INIT_ACCEPTED) {
...@@ -5303,8 +5264,7 @@ sctp_process_control(struct mbuf *m, int iphlen, int *offset, int length, ...@@ -5303,8 +5264,7 @@ sctp_process_control(struct mbuf *m, int iphlen, int *offset, int length,
SCTPDBG(SCTP_DEBUG_INPUT3, "SCTP_HEARTBEAT_ACK\n"); SCTPDBG(SCTP_DEBUG_INPUT3, "SCTP_HEARTBEAT_ACK\n");
if ((stcb == NULL) || (chk_length != sizeof(struct sctp_heartbeat_chunk))) { if ((stcb == NULL) || (chk_length != sizeof(struct sctp_heartbeat_chunk))) {
/* Its not ours */ /* Its not ours */
*offset = length; break;
return (stcb);
} }
SCTP_STAT_INCR(sctps_recvheartbeatack); SCTP_STAT_INCR(sctps_recvheartbeatack);
if ((netp != NULL) && (*netp != NULL)) { if ((netp != NULL) && (*netp != NULL)) {
...@@ -5330,12 +5290,10 @@ sctp_process_control(struct mbuf *m, int iphlen, int *offset, int length, ...@@ -5330,12 +5290,10 @@ sctp_process_control(struct mbuf *m, int iphlen, int *offset, int length,
SCTPDBG(SCTP_DEBUG_INPUT3, "SCTP_SHUTDOWN, stcb %p\n", SCTPDBG(SCTP_DEBUG_INPUT3, "SCTP_SHUTDOWN, stcb %p\n",
(void *)stcb); (void *)stcb);
if ((stcb == NULL) || (chk_length != sizeof(struct sctp_shutdown_chunk))) { if ((stcb == NULL) || (chk_length != sizeof(struct sctp_shutdown_chunk))) {
*offset = length; break;
return (stcb);
} }
if ((netp != NULL) && (*netp != NULL)) { if ((netp != NULL) && (*netp != NULL)) {
int abort_flag = 0; abort_flag = 0;
sctp_handle_shutdown((struct sctp_shutdown_chunk *)ch, sctp_handle_shutdown((struct sctp_shutdown_chunk *)ch,
stcb, *netp, &abort_flag); stcb, *netp, &abort_flag);
if (abort_flag) { if (abort_flag) {
...@@ -5346,11 +5304,12 @@ sctp_process_control(struct mbuf *m, int iphlen, int *offset, int length, ...@@ -5346,11 +5304,12 @@ sctp_process_control(struct mbuf *m, int iphlen, int *offset, int length,
break; break;
case SCTP_SHUTDOWN_ACK: case SCTP_SHUTDOWN_ACK:
SCTPDBG(SCTP_DEBUG_INPUT3, "SCTP_SHUTDOWN_ACK, stcb %p\n", (void *)stcb); SCTPDBG(SCTP_DEBUG_INPUT3, "SCTP_SHUTDOWN_ACK, stcb %p\n", (void *)stcb);
if ((stcb != NULL) && (netp != NULL) && (*netp != NULL)) { if ((chk_length == sizeof(struct sctp_shutdown_ack_chunk)) &&
(stcb != NULL) && (netp != NULL) && (*netp != NULL)) {
sctp_handle_shutdown_ack((struct sctp_shutdown_ack_chunk *)ch, stcb, *netp); sctp_handle_shutdown_ack((struct sctp_shutdown_ack_chunk *)ch, stcb, *netp);
}
*offset = length; *offset = length;
return (NULL); return (NULL);
}
break; break;
case SCTP_OPERATION_ERROR: case SCTP_OPERATION_ERROR:
SCTPDBG(SCTP_DEBUG_INPUT3, "SCTP_OP_ERR\n"); SCTPDBG(SCTP_DEBUG_INPUT3, "SCTP_OP_ERR\n");
...@@ -5494,7 +5453,7 @@ sctp_process_control(struct mbuf *m, int iphlen, int *offset, int length, ...@@ -5494,7 +5453,7 @@ sctp_process_control(struct mbuf *m, int iphlen, int *offset, int length,
case SCTP_COOKIE_ACK: case SCTP_COOKIE_ACK:
SCTPDBG(SCTP_DEBUG_INPUT3, "SCTP_COOKIE_ACK, stcb %p\n", (void *)stcb); SCTPDBG(SCTP_DEBUG_INPUT3, "SCTP_COOKIE_ACK, stcb %p\n", (void *)stcb);
if ((stcb == NULL) || chk_length != sizeof(struct sctp_cookie_ack_chunk)) { if ((stcb == NULL) || chk_length != sizeof(struct sctp_cookie_ack_chunk)) {
return (stcb); break;
} }
if (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) { if (inp->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) {
/* We are not interested anymore */ /* We are not interested anymore */
...@@ -5524,26 +5483,29 @@ sctp_process_control(struct mbuf *m, int iphlen, int *offset, int length, ...@@ -5524,26 +5483,29 @@ sctp_process_control(struct mbuf *m, int iphlen, int *offset, int length,
break; break;
case SCTP_ECN_ECHO: case SCTP_ECN_ECHO:
SCTPDBG(SCTP_DEBUG_INPUT3, "SCTP_ECN_ECHO\n"); SCTPDBG(SCTP_DEBUG_INPUT3, "SCTP_ECN_ECHO\n");
if ((stcb == NULL) || (chk_length != sizeof(struct sctp_ecne_chunk))) { if (stcb == NULL) {
/* Its not ours */ break;
*offset = length;
return (stcb);
} }
if (stcb->asoc.ecn_supported == 0) { if (stcb->asoc.ecn_supported == 0) {
goto unknown_chunk; goto unknown_chunk;
} }
if (chk_length != sizeof(struct sctp_ecne_chunk)) {
break;
}
sctp_handle_ecn_echo((struct sctp_ecne_chunk *)ch, stcb); sctp_handle_ecn_echo((struct sctp_ecne_chunk *)ch, stcb);
ecne_seen = 1; ecne_seen = 1;
break; break;
case SCTP_ECN_CWR: case SCTP_ECN_CWR:
SCTPDBG(SCTP_DEBUG_INPUT3, "SCTP_ECN_CWR\n"); SCTPDBG(SCTP_DEBUG_INPUT3, "SCTP_ECN_CWR\n");
if ((stcb == NULL) || (chk_length != sizeof(struct sctp_cwr_chunk))) { if (stcb == NULL) {
*offset = length; break;
return (stcb);
} }
if (stcb->asoc.ecn_supported == 0) { if (stcb->asoc.ecn_supported == 0) {
goto unknown_chunk; goto unknown_chunk;
} }
if (chk_length != sizeof(struct sctp_cwr_chunk)) {
break;
}
sctp_handle_ecn_cwr((struct sctp_cwr_chunk *)ch, stcb, *netp); sctp_handle_ecn_cwr((struct sctp_cwr_chunk *)ch, stcb, *netp);
break; break;
case SCTP_SHUTDOWN_COMPLETE: case SCTP_SHUTDOWN_COMPLETE:
...@@ -5554,12 +5516,13 @@ sctp_process_control(struct mbuf *m, int iphlen, int *offset, int length, ...@@ -5554,12 +5516,13 @@ sctp_process_control(struct mbuf *m, int iphlen, int *offset, int length,
*offset = length; *offset = length;
return (stcb); return (stcb);
} }
if ((stcb != NULL) && (netp != NULL) && (*netp != NULL)) { if ((chk_length == sizeof(struct sctp_shutdown_complete_chunk)) &&
(stcb != NULL) && (netp != NULL) && (*netp != NULL)) {
sctp_handle_shutdown_complete((struct sctp_shutdown_complete_chunk *)ch, sctp_handle_shutdown_complete((struct sctp_shutdown_complete_chunk *)ch,
stcb, *netp); stcb, *netp);
}
*offset = length; *offset = length;
return (NULL); return (NULL);
}
break; break;
case SCTP_ASCONF: case SCTP_ASCONF:
SCTPDBG(SCTP_DEBUG_INPUT3, "SCTP_ASCONF\n"); SCTPDBG(SCTP_DEBUG_INPUT3, "SCTP_ASCONF\n");
...@@ -5574,15 +5537,16 @@ sctp_process_control(struct mbuf *m, int iphlen, int *offset, int length, ...@@ -5574,15 +5537,16 @@ sctp_process_control(struct mbuf *m, int iphlen, int *offset, int length,
break; break;
case SCTP_ASCONF_ACK: case SCTP_ASCONF_ACK:
SCTPDBG(SCTP_DEBUG_INPUT3, "SCTP_ASCONF_ACK\n"); SCTPDBG(SCTP_DEBUG_INPUT3, "SCTP_ASCONF_ACK\n");
if (chk_length < sizeof(struct sctp_asconf_ack_chunk)) { if (stcb == NULL) {
/* Its not ours */ break;
*offset = length;
return (stcb);
} }
if ((stcb != NULL) && (netp != NULL) && (*netp != NULL)) {
if (stcb->asoc.asconf_supported == 0) { if (stcb->asoc.asconf_supported == 0) {
goto unknown_chunk; goto unknown_chunk;
} }
if (chk_length < sizeof(struct sctp_asconf_ack_chunk)) {
break;
}
if ((netp != NULL) && (*netp != NULL)) {
/* He's alive so give him credit */ /* He's alive so give him credit */
if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_THRESHOLD_LOGGING) { if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_THRESHOLD_LOGGING) {
sctp_misc_ints(SCTP_THRESHOLD_CLEAR, sctp_misc_ints(SCTP_THRESHOLD_CLEAR,
...@@ -5602,18 +5566,15 @@ sctp_process_control(struct mbuf *m, int iphlen, int *offset, int length, ...@@ -5602,18 +5566,15 @@ sctp_process_control(struct mbuf *m, int iphlen, int *offset, int length,
case SCTP_IFORWARD_CUM_TSN: case SCTP_IFORWARD_CUM_TSN:
SCTPDBG(SCTP_DEBUG_INPUT3, "%s\n", SCTPDBG(SCTP_DEBUG_INPUT3, "%s\n",
ch->chunk_type == SCTP_FORWARD_CUM_TSN ? "FORWARD_TSN" : "I_FORWARD_TSN"); ch->chunk_type == SCTP_FORWARD_CUM_TSN ? "FORWARD_TSN" : "I_FORWARD_TSN");
if (chk_length < sizeof(struct sctp_forward_tsn_chunk)) { if (stcb == NULL) {
/* Its not ours */ break;
*offset = length;
return (stcb);
} }
if (stcb != NULL) {
int abort_flag = 0;
if (stcb->asoc.prsctp_supported == 0) { if (stcb->asoc.prsctp_supported == 0) {
goto unknown_chunk; goto unknown_chunk;
} }
if (chk_length < sizeof(struct sctp_forward_tsn_chunk)) {
break;
}
if (((stcb->asoc.idata_supported == 1) && (ch->chunk_type == SCTP_FORWARD_CUM_TSN)) || if (((stcb->asoc.idata_supported == 1) && (ch->chunk_type == SCTP_FORWARD_CUM_TSN)) ||
((stcb->asoc.idata_supported == 0) && (ch->chunk_type == SCTP_IFORWARD_CUM_TSN))) { ((stcb->asoc.idata_supported == 0) && (ch->chunk_type == SCTP_IFORWARD_CUM_TSN))) {
if (ch->chunk_type == SCTP_FORWARD_CUM_TSN) { if (ch->chunk_type == SCTP_FORWARD_CUM_TSN) {
...@@ -5650,24 +5611,25 @@ sctp_process_control(struct mbuf *m, int iphlen, int *offset, int length, ...@@ -5650,24 +5611,25 @@ sctp_process_control(struct mbuf *m, int iphlen, int *offset, int length,
* chunks. * chunks.
*/ */
stcb->asoc.last_data_chunk_from = stcb->asoc.last_control_chunk_from; stcb->asoc.last_data_chunk_from = stcb->asoc.last_control_chunk_from;
abort_flag = 0;
sctp_handle_forward_tsn(stcb, sctp_handle_forward_tsn(stcb,
(struct sctp_forward_tsn_chunk *)ch, &abort_flag, m, *offset); (struct sctp_forward_tsn_chunk *)ch, &abort_flag, m, *offset);
if (abort_flag) { if (abort_flag) {
*offset = length; *offset = length;
return (NULL); return (NULL);
} }
}
break; break;
case SCTP_STREAM_RESET: case SCTP_STREAM_RESET:
SCTPDBG(SCTP_DEBUG_INPUT3, "SCTP_STREAM_RESET\n"); SCTPDBG(SCTP_DEBUG_INPUT3, "SCTP_STREAM_RESET\n");
if ((stcb == NULL) || (chk_length < sizeof(struct sctp_stream_reset_tsn_req))) { if (stcb == NULL) {
/* Its not ours */ break;
*offset = length;
return (stcb);
} }
if (stcb->asoc.reconfig_supported == 0) { if (stcb->asoc.reconfig_supported == 0) {
goto unknown_chunk; goto unknown_chunk;
} }
if (chk_length < sizeof(struct sctp_stream_reset_tsn_req)) {
break;
}
if (sctp_handle_stream_reset(stcb, m, *offset, ch)) { if (sctp_handle_stream_reset(stcb, m, *offset, ch)) {
/* stop processing */ /* stop processing */
*offset = length; *offset = length;
...@@ -5676,17 +5638,16 @@ sctp_process_control(struct mbuf *m, int iphlen, int *offset, int length, ...@@ -5676,17 +5638,16 @@ sctp_process_control(struct mbuf *m, int iphlen, int *offset, int length,
break; break;
case SCTP_PACKET_DROPPED: case SCTP_PACKET_DROPPED:
SCTPDBG(SCTP_DEBUG_INPUT3, "SCTP_PACKET_DROPPED\n"); SCTPDBG(SCTP_DEBUG_INPUT3, "SCTP_PACKET_DROPPED\n");
/* re-get it all please */ if (stcb == NULL) {
if (chk_length < sizeof(struct sctp_pktdrop_chunk)) { break;
/* Its not ours */
*offset = length;
return (stcb);
} }
if ((stcb != NULL) && (netp != NULL) && (*netp != NULL)) {
if (stcb->asoc.pktdrop_supported == 0) { if (stcb->asoc.pktdrop_supported == 0) {
goto unknown_chunk; goto unknown_chunk;
} }
if (chk_length < sizeof(struct sctp_pktdrop_chunk)) {
break;
}
if ((netp != NULL) && (*netp != NULL)) {
sctp_handle_packet_dropped((struct sctp_pktdrop_chunk *)ch, sctp_handle_packet_dropped((struct sctp_pktdrop_chunk *)ch,
stcb, *netp, stcb, *netp,
min(chk_length, contiguous)); min(chk_length, contiguous));
...@@ -5702,7 +5663,7 @@ sctp_process_control(struct mbuf *m, int iphlen, int *offset, int length, ...@@ -5702,7 +5663,7 @@ sctp_process_control(struct mbuf *m, int iphlen, int *offset, int length,
auth_skipped = 1; auth_skipped = 1;
} }
/* skip this chunk (temporarily) */ /* skip this chunk (temporarily) */
goto next_chunk; break;
} }
if (stcb->asoc.auth_supported == 0) { if (stcb->asoc.auth_supported == 0) {
goto unknown_chunk; goto unknown_chunk;
...@@ -5716,7 +5677,7 @@ sctp_process_control(struct mbuf *m, int iphlen, int *offset, int length, ...@@ -5716,7 +5677,7 @@ sctp_process_control(struct mbuf *m, int iphlen, int *offset, int length,
} }
if (got_auth == 1) { if (got_auth == 1) {
/* skip this chunk... it's already auth'd */ /* skip this chunk... it's already auth'd */
goto next_chunk; break;
} }
got_auth = 1; got_auth = 1;
if (sctp_handle_auth(stcb, (struct sctp_auth_chunk *)ch, m, *offset)) { if (sctp_handle_auth(stcb, (struct sctp_auth_chunk *)ch, m, *offset)) {
......
...@@ -886,7 +886,7 @@ int sctp_userspace_get_mtu_from_ifn(uint32_t if_index, int af); ...@@ -886,7 +886,7 @@ int sctp_userspace_get_mtu_from_ifn(uint32_t if_index, int af);
#define SCTP_GATHER_MTU_FROM_ROUTE(sctp_ifa, sa, rt) ((rt != NULL) ? rt->rt_rmx.rmx_mtu : 0) #define SCTP_GATHER_MTU_FROM_ROUTE(sctp_ifa, sa, rt) ((rt != NULL) ? rt->rt_rmx.rmx_mtu : 0)
#define SCTP_GATHER_MTU_FROM_INTFC(sctp_ifn) sctp_userspace_get_mtu_from_ifn(if_nametoindex(((struct ifaddrs *) (sctp_ifn))->ifa_name), AF_INET) #define SCTP_GATHER_MTU_FROM_INTFC(sctp_ifn) (sctp_ifn->ifn_mtu)
#define SCTP_SET_MTU_OF_ROUTE(sa, rt, mtu) do { \ #define SCTP_SET_MTU_OF_ROUTE(sa, rt, mtu) do { \
if (rt != NULL) \ if (rt != NULL) \
......
...@@ -7543,11 +7543,15 @@ sctp_load_addresses_from_init(struct sctp_tcb *stcb, struct mbuf *m, ...@@ -7543,11 +7543,15 @@ sctp_load_addresses_from_init(struct sctp_tcb *stcb, struct mbuf *m,
/* remove and free it */ /* remove and free it */
stcb->asoc.numnets--; stcb->asoc.numnets--;
TAILQ_REMOVE(&stcb->asoc.nets, net, sctp_next); TAILQ_REMOVE(&stcb->asoc.nets, net, sctp_next);
sctp_free_remote_addr(net); if (net == stcb->asoc.alternate) {
sctp_free_remote_addr(stcb->asoc.alternate);
stcb->asoc.alternate = NULL;
}
if (net == stcb->asoc.primary_destination) { if (net == stcb->asoc.primary_destination) {
stcb->asoc.primary_destination = NULL; stcb->asoc.primary_destination = NULL;
sctp_select_primary_destination(stcb); sctp_select_primary_destination(stcb);
} }
sctp_free_remote_addr(net);
} }
} }
if ((stcb->asoc.ecn_supported == 1) && if ((stcb->asoc.ecn_supported == 1) &&
......
...@@ -80,7 +80,25 @@ sctp_sha1_final(unsigned char *digest, struct sctp_sha1_context *ctx) ...@@ -80,7 +80,25 @@ sctp_sha1_final(unsigned char *digest, struct sctp_sha1_context *ctx)
{ {
SHA1_Final(digest, &ctx->sha_ctx); SHA1_Final(digest, &ctx->sha_ctx);
} }
#elif defined(SCTP_USE_MBEDTLS_SHA1)
void
sctp_sha1_init(struct sctp_sha1_context *ctx)
{
mbedtls_sha1_init(&ctx->sha1_ctx);
mbedtls_sha1_starts_ret(&ctx->sha1_ctx);
}
void
sctp_sha1_update(struct sctp_sha1_context *ctx, const unsigned char *ptr, unsigned int siz)
{
mbedtls_sha1_update_ret(&ctx->sha1_ctx, ptr, siz);
}
void
sctp_sha1_final(unsigned char *digest, struct sctp_sha1_context *ctx)
{
mbedtls_sha1_finish_ret(&ctx->sha1_ctx, digest);
}
#else #else
#include <string.h> #include <string.h>
......
...@@ -46,6 +46,8 @@ __FBSDID("$FreeBSD$"); ...@@ -46,6 +46,8 @@ __FBSDID("$FreeBSD$");
#include <pk11pub.h> #include <pk11pub.h>
#elif defined(SCTP_USE_OPENSSL_SHA1) #elif defined(SCTP_USE_OPENSSL_SHA1)
#include <openssl/sha.h> #include <openssl/sha.h>
#elif defined(SCTP_USE_MBEDTLS_SHA1)
#include <mbedtls/sha1.h>
#endif #endif
struct sctp_sha1_context { struct sctp_sha1_context {
...@@ -53,6 +55,8 @@ struct sctp_sha1_context { ...@@ -53,6 +55,8 @@ struct sctp_sha1_context {
struct PK11Context *pk11_ctx; struct PK11Context *pk11_ctx;
#elif defined(SCTP_USE_OPENSSL_SHA1) #elif defined(SCTP_USE_OPENSSL_SHA1)
SHA_CTX sha_ctx; SHA_CTX sha_ctx;
#elif defined(SCTP_USE_MBEDTLS_SHA1)
mbedtls_sha1_context sha1_ctx;
#else #else
unsigned int A; unsigned int A;
unsigned int B; unsigned int B;
......
...@@ -98,23 +98,42 @@ sctp_userspace_set_threadname(const char *name) ...@@ -98,23 +98,42 @@ sctp_userspace_set_threadname(const char *name)
int int
sctp_userspace_get_mtu_from_ifn(uint32_t if_index, int af) sctp_userspace_get_mtu_from_ifn(uint32_t if_index, int af)
{ {
#if defined(INET) || defined(INET6)
struct ifreq ifr; struct ifreq ifr;
int fd; int fd;
#endif
int mtu;
switch (af) {
#if defined(INET)
case AF_INET:
#endif
#if defined(INET6)
case AF_INET6:
#endif
#if defined(INET) || defined(INET6)
memset(&ifr, 0, sizeof(struct ifreq)); memset(&ifr, 0, sizeof(struct ifreq));
mtu = 0;
if (if_indextoname(if_index, ifr.ifr_name) != NULL) { if (if_indextoname(if_index, ifr.ifr_name) != NULL) {
/* TODO can I use the raw socket here and not have to open a new one with each query? */ /* TODO can I use the raw socket here and not have to open a new one with each query? */
if ((fd = socket(af, SOCK_DGRAM, 0)) < 0) if ((fd = socket(af, SOCK_DGRAM, 0)) < 0) {
return (0); break;
if (ioctl(fd, SIOCGIFMTU, &ifr) < 0) { }
close(fd); if (ioctl(fd, SIOCGIFMTU, &ifr) >= 0) {
return (0); mtu = ifr.ifr_mtu;
} }
close(fd); close(fd);
return ifr.ifr_mtu;
} else {
return (0);
} }
break;
#endif
case AF_CONN:
mtu = 1280;
break;
default:
mtu = 0;
break;
}
return (mtu);
} }
#endif #endif
...@@ -143,41 +162,60 @@ timingsafe_bcmp(const void *b1, const void *b2, size_t n) ...@@ -143,41 +162,60 @@ timingsafe_bcmp(const void *b1, const void *b2, size_t n)
int int
sctp_userspace_get_mtu_from_ifn(uint32_t if_index, int af) sctp_userspace_get_mtu_from_ifn(uint32_t if_index, int af)
{ {
#if defined(INET) || defined(INET6)
PIP_ADAPTER_ADDRESSES pAdapterAddrs, pAdapt; PIP_ADAPTER_ADDRESSES pAdapterAddrs, pAdapt;
DWORD AdapterAddrsSize, Err; DWORD AdapterAddrsSize, Err;
int ret; #endif
int mtu;
ret = 0; switch (af) {
#if defined(INET)
case AF_INET:
#endif
#if defined(INET6)
case AF_INET6:
#endif
#if defined(INET) || defined(INET6)
mtu = 0;
AdapterAddrsSize = 0; AdapterAddrsSize = 0;
pAdapterAddrs = NULL; pAdapterAddrs = NULL;
if ((Err = GetAdaptersAddresses(AF_UNSPEC, 0, NULL, NULL, &AdapterAddrsSize)) != 0) { if ((Err = GetAdaptersAddresses(AF_UNSPEC, 0, NULL, NULL, &AdapterAddrsSize)) != 0) {
if ((Err != ERROR_BUFFER_OVERFLOW) && (Err != ERROR_INSUFFICIENT_BUFFER)) { if ((Err != ERROR_BUFFER_OVERFLOW) && (Err != ERROR_INSUFFICIENT_BUFFER)) {
SCTPDBG(SCTP_DEBUG_USR, "GetAdaptersAddresses() sizing failed with error code %d, AdapterAddrsSize = %d\n", Err, AdapterAddrsSize); SCTPDBG(SCTP_DEBUG_USR, "GetAdaptersAddresses() sizing failed with error code %d, AdapterAddrsSize = %d\n", Err, AdapterAddrsSize);
ret = -1; mtu = -1;
goto cleanup; goto cleanup;
} }
} }
if ((pAdapterAddrs = (PIP_ADAPTER_ADDRESSES) GlobalAlloc(GPTR, AdapterAddrsSize)) == NULL) { if ((pAdapterAddrs = (PIP_ADAPTER_ADDRESSES) GlobalAlloc(GPTR, AdapterAddrsSize)) == NULL) {
SCTPDBG(SCTP_DEBUG_USR, "Memory allocation error!\n"); SCTPDBG(SCTP_DEBUG_USR, "Memory allocation error!\n");
ret = -1; mtu = -1;
goto cleanup; goto cleanup;
} }
if ((Err = GetAdaptersAddresses(AF_UNSPEC, 0, NULL, pAdapterAddrs, &AdapterAddrsSize)) != ERROR_SUCCESS) { if ((Err = GetAdaptersAddresses(AF_UNSPEC, 0, NULL, pAdapterAddrs, &AdapterAddrsSize)) != ERROR_SUCCESS) {
SCTPDBG(SCTP_DEBUG_USR, "GetAdaptersAddresses() failed with error code %d\n", Err); SCTPDBG(SCTP_DEBUG_USR, "GetAdaptersAddresses() failed with error code %d\n", Err);
ret = -1; mtu = -1;
goto cleanup; goto cleanup;
} }
for (pAdapt = pAdapterAddrs; pAdapt; pAdapt = pAdapt->Next) { for (pAdapt = pAdapterAddrs; pAdapt; pAdapt = pAdapt->Next) {
if (pAdapt->IfIndex == if_index) { if (pAdapt->IfIndex == if_index) {
ret = pAdapt->Mtu; mtu = pAdapt->Mtu;
break; break;
} }
} }
cleanup: cleanup:
if (pAdapterAddrs != NULL) { if (pAdapterAddrs != NULL) {
GlobalFree(pAdapterAddrs); GlobalFree(pAdapterAddrs);
} }
return (ret); break;
#endif
case AF_CONN:
mtu = 1280;
break;
default:
mtu = 0;
break;
}
return (mtu);
} }
void void
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
#if defined(__FreeBSD__) && !defined(__Userspace__) #if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h> #include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet/sctp_usrreq.c 366750 2020-10-16 10:44:48Z tuexen $"); __FBSDID("$FreeBSD$");
#endif #endif
#include <netinet/sctp_os.h> #include <netinet/sctp_os.h>
...@@ -974,29 +974,29 @@ sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr, ...@@ -974,29 +974,29 @@ sctp_sendm(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) || ((inp->sctp_flags & SCTP_PCB_FLAGS_CONNECTED) ||
(inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE))) { (inp->sctp_flags & SCTP_PCB_FLAGS_TCPTYPE))) {
goto connected_type; goto connected_type;
} else if (addr == NULL) { }
error = 0;
if (addr == NULL) {
SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ); SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
error = EDESTADDRREQ; error = EDESTADDRREQ;
sctp_m_freem(m); } else if (addr->sa_family != AF_INET) {
if (control) { SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EAFNOSUPPORT);
sctp_m_freem(control); error = EAFNOSUPPORT;
control = NULL; #if defined(HAVE_SA_LEN)
} } else if (addr->sa_len != sizeof(struct sockaddr_in)) {
return (error); SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EINVAL);
error = EINVAL;
#endif
} }
#ifdef INET6 if (error != 0) {
if (addr->sa_family != AF_INET) {
/* must be a v4 address! */
SCTP_LTRACE_ERR_RET_PKT(m, inp, NULL, NULL, SCTP_FROM_SCTP_USRREQ, EDESTADDRREQ);
sctp_m_freem(m); sctp_m_freem(m);
if (control) { if (control) {
sctp_m_freem(control); sctp_m_freem(control);
control = NULL; control = NULL;
} }
error = EDESTADDRREQ;
return (error); return (error);
} }
#endif /* INET6 */
connected_type: connected_type:
/* now what about control */ /* now what about control */
if (control) { if (control) {
...@@ -6112,6 +6112,7 @@ sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize, ...@@ -6112,6 +6112,7 @@ sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
return (EINVAL); return (EINVAL);
} }
if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) && if ((paddrp->spp_flags & SPP_PMTUD_DISABLE) &&
(paddrp->spp_pathmtu > 0) &&
((paddrp->spp_pathmtu < SCTP_SMALLEST_PMTU) || ((paddrp->spp_pathmtu < SCTP_SMALLEST_PMTU) ||
(paddrp->spp_pathmtu > SCTP_LARGEST_PMTU))) { (paddrp->spp_pathmtu > SCTP_LARGEST_PMTU))) {
if (stcb) if (stcb)
...@@ -6156,6 +6157,7 @@ sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize, ...@@ -6156,6 +6157,7 @@ sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
SCTP_FROM_SCTP_USRREQ + SCTP_LOC_11); SCTP_FROM_SCTP_USRREQ + SCTP_LOC_11);
} }
net->dest_state |= SCTP_ADDR_NO_PMTUD; net->dest_state |= SCTP_ADDR_NO_PMTUD;
if (paddrp->spp_pathmtu > 0) {
net->mtu = paddrp->spp_pathmtu; net->mtu = paddrp->spp_pathmtu;
switch (net->ro._l_addr.sa.sa_family) { switch (net->ro._l_addr.sa.sa_family) {
#ifdef INET #ifdef INET
...@@ -6180,13 +6182,14 @@ sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize, ...@@ -6180,13 +6182,14 @@ sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
sctp_pathmtu_adjustment(stcb, net->mtu); sctp_pathmtu_adjustment(stcb, net->mtu);
} }
} }
}
if (paddrp->spp_flags & SPP_PMTUD_ENABLE) { if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) { if (!SCTP_OS_TIMER_PENDING(&net->pmtu_timer.timer)) {
sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net); sctp_timer_start(SCTP_TIMER_TYPE_PATHMTURAISE, inp, stcb, net);
} }
net->dest_state &= ~SCTP_ADDR_NO_PMTUD; net->dest_state &= ~SCTP_ADDR_NO_PMTUD;
} }
if (paddrp->spp_pathmaxrxt) { if (paddrp->spp_pathmaxrxt > 0) {
if (net->dest_state & SCTP_ADDR_PF) { if (net->dest_state & SCTP_ADDR_PF) {
if (net->error_count > paddrp->spp_pathmaxrxt) { if (net->error_count > paddrp->spp_pathmaxrxt) {
net->dest_state &= ~SCTP_ADDR_PF; net->dest_state &= ~SCTP_ADDR_PF;
...@@ -6229,7 +6232,7 @@ sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize, ...@@ -6229,7 +6232,7 @@ sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
#endif #endif
} else { } else {
/************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/ /************************ASSOC ONLY -- NO NET SPECIFIC SET ******************/
if (paddrp->spp_pathmaxrxt != 0) { if (paddrp->spp_pathmaxrxt > 0) {
stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt; stcb->asoc.def_net_failure = paddrp->spp_pathmaxrxt;
TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) { TAILQ_FOREACH(net, &stcb->asoc.nets, sctp_next) {
if (net->dest_state & SCTP_ADDR_PF) { if (net->dest_state & SCTP_ADDR_PF) {
...@@ -6261,7 +6264,6 @@ sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize, ...@@ -6261,7 +6264,6 @@ sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
net->failure_threshold = paddrp->spp_pathmaxrxt; net->failure_threshold = paddrp->spp_pathmaxrxt;
} }
} }
if (paddrp->spp_flags & SPP_HB_ENABLE) { if (paddrp->spp_flags & SPP_HB_ENABLE) {
if (paddrp->spp_hbinterval != 0) { if (paddrp->spp_hbinterval != 0) {
stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval; stcb->asoc.heart_beat_delay = paddrp->spp_hbinterval;
...@@ -6304,6 +6306,7 @@ sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize, ...@@ -6304,6 +6306,7 @@ sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
SCTP_FROM_SCTP_USRREQ + SCTP_LOC_16); SCTP_FROM_SCTP_USRREQ + SCTP_LOC_16);
} }
net->dest_state |= SCTP_ADDR_NO_PMTUD; net->dest_state |= SCTP_ADDR_NO_PMTUD;
if (paddrp->spp_pathmtu > 0) {
net->mtu = paddrp->spp_pathmtu; net->mtu = paddrp->spp_pathmtu;
switch (net->ro._l_addr.sa.sa_family) { switch (net->ro._l_addr.sa.sa_family) {
#ifdef INET #ifdef INET
...@@ -6328,7 +6331,10 @@ sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize, ...@@ -6328,7 +6331,10 @@ sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
sctp_pathmtu_adjustment(stcb, net->mtu); sctp_pathmtu_adjustment(stcb, net->mtu);
} }
} }
}
if (paddrp->spp_pathmtu > 0) {
stcb->asoc.default_mtu = paddrp->spp_pathmtu; stcb->asoc.default_mtu = paddrp->spp_pathmtu;
}
sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD); sctp_stcb_feature_on(inp, stcb, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
} }
if (paddrp->spp_flags & SPP_PMTUD_ENABLE) { if (paddrp->spp_flags & SPP_PMTUD_ENABLE) {
...@@ -6374,7 +6380,7 @@ sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize, ...@@ -6374,7 +6380,7 @@ sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
* For the TOS/FLOWLABEL stuff you set it * For the TOS/FLOWLABEL stuff you set it
* with the options on the socket * with the options on the socket
*/ */
if (paddrp->spp_pathmaxrxt != 0) { if (paddrp->spp_pathmaxrxt > 0) {
inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt; inp->sctp_ep.def_net_failure = paddrp->spp_pathmaxrxt;
} }
...@@ -6400,7 +6406,9 @@ sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize, ...@@ -6400,7 +6406,9 @@ sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize,
inp->sctp_ep.default_mtu = 0; inp->sctp_ep.default_mtu = 0;
sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD); sctp_feature_off(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
} else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) { } else if (paddrp->spp_flags & SPP_PMTUD_DISABLE) {
if (paddrp->spp_pathmtu > 0) {
inp->sctp_ep.default_mtu = paddrp->spp_pathmtu; inp->sctp_ep.default_mtu = paddrp->spp_pathmtu;
}
sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD); sctp_feature_on(inp, SCTP_PCB_FLAGS_DO_NOT_PMTUD);
} }
if (paddrp->spp_flags & SPP_DSCP) { if (paddrp->spp_flags & SPP_DSCP) {
......
...@@ -4837,7 +4837,7 @@ sctp_handle_ootb(struct mbuf *m, int iphlen, int offset, ...@@ -4837,7 +4837,7 @@ sctp_handle_ootb(struct mbuf *m, int iphlen, int offset,
* if there is return 1, else return 0. * if there is return 1, else return 0.
*/ */
int int
sctp_is_there_an_abort_here(struct mbuf *m, int iphlen, uint32_t * vtagfill) sctp_is_there_an_abort_here(struct mbuf *m, int iphlen, uint32_t *vtag)
{ {
struct sctp_chunkhdr *ch; struct sctp_chunkhdr *ch;
struct sctp_init_chunk *init_chk, chunk_buf; struct sctp_init_chunk *init_chk, chunk_buf;
...@@ -4858,12 +4858,13 @@ sctp_is_there_an_abort_here(struct mbuf *m, int iphlen, uint32_t * vtagfill) ...@@ -4858,12 +4858,13 @@ sctp_is_there_an_abort_here(struct mbuf *m, int iphlen, uint32_t * vtagfill)
/* yep, tell them */ /* yep, tell them */
return (1); return (1);
} }
if (ch->chunk_type == SCTP_INITIATION) { if ((ch->chunk_type == SCTP_INITIATION) ||
(ch->chunk_type == SCTP_INITIATION_ACK)) {
/* need to update the Vtag */ /* need to update the Vtag */
init_chk = (struct sctp_init_chunk *)sctp_m_getptr(m, init_chk = (struct sctp_init_chunk *)sctp_m_getptr(m,
offset, sizeof(*init_chk), (uint8_t *) & chunk_buf); offset, sizeof(struct sctp_init_chunk), (uint8_t *) & chunk_buf);
if (init_chk != NULL) { if (init_chk != NULL) {
*vtagfill = ntohl(init_chk->init.initiate_tag); *vtag = ntohl(init_chk->init.initiate_tag);
} }
} }
/* Nope, move to the next chunk */ /* Nope, move to the next chunk */
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
#if defined(__FreeBSD__) && !defined(__Userspace__) #if defined(__FreeBSD__) && !defined(__Userspace__)
#include <sys/cdefs.h> #include <sys/cdefs.h>
__FBSDID("$FreeBSD: head/sys/netinet6/sctp6_usrreq.c 365071 2020-09-01 21:19:14Z mjg $"); __FBSDID("$FreeBSD$");
#endif #endif
#include <netinet/sctp_os.h> #include <netinet/sctp_os.h>
...@@ -259,13 +259,14 @@ sctp6_input(struct mbuf **i_pak, int *offp, int proto) ...@@ -259,13 +259,14 @@ sctp6_input(struct mbuf **i_pak, int *offp, int proto)
if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)) { if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)) {
goto out; goto out;
} }
ecn_bits = ((ntohl(ip6->ip6_flow) >> 20) & 0x000000ff);
#if defined(__FreeBSD__) #if defined(__FreeBSD__)
ecn_bits = IPV6_TRAFFIC_CLASS(ip6);
if (m->m_pkthdr.csum_flags & CSUM_SCTP_VALID) { if (m->m_pkthdr.csum_flags & CSUM_SCTP_VALID) {
SCTP_STAT_INCR(sctps_recvhwcrc); SCTP_STAT_INCR(sctps_recvhwcrc);
compute_crc = 0; compute_crc = 0;
} else { } else {
#else #else
ecn_bits = ((ntohl(ip6->ip6_flow) >> 20) & 0x000000ff);
if (SCTP_BASE_SYSCTL(sctp_no_csum_on_loopback) && if (SCTP_BASE_SYSCTL(sctp_no_csum_on_loopback) &&
(IN6_ARE_ADDR_EQUAL(&src.sin6_addr, &dst.sin6_addr))) { (IN6_ARE_ADDR_EQUAL(&src.sin6_addr, &dst.sin6_addr))) {
SCTP_STAT_INCR(sctps_recvhwcrc); SCTP_STAT_INCR(sctps_recvhwcrc);
...@@ -654,9 +655,10 @@ out: ...@@ -654,9 +655,10 @@ out:
return (error); return (error);
} }
SYSCTL_PROC(_net_inet6_sctp6, OID_AUTO, getcred, CTLTYPE_OPAQUE | CTLFLAG_RW, SYSCTL_PROC(_net_inet6_sctp6, OID_AUTO, getcred,
0, 0, CTLTYPE_OPAQUE | CTLFLAG_RW | CTLFLAG_NEEDGIANT,
sctp6_getcred, "S,ucred", "Get the ucred of a SCTP6 connection"); 0, 0, sctp6_getcred, "S,ucred",
"Get the ucred of a SCTP6 connection");
#endif #endif
/* This is the same as the sctp_abort() could be made common */ /* This is the same as the sctp_abort() could be made common */
...@@ -1007,6 +1009,46 @@ sctp6_send(struct socket *so, int flags, struct mbuf *m, struct mbuf *nam, ...@@ -1007,6 +1009,46 @@ sctp6_send(struct socket *so, int flags, struct mbuf *m, struct mbuf *nam,
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, EDESTADDRREQ); SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, EDESTADDRREQ);
return (EDESTADDRREQ); return (EDESTADDRREQ);
} }
switch (addr->sa_family) {
#ifdef INET
case AF_INET:
#if defined(HAVE_SA_LEN)
if (addr->sa_len != sizeof(struct sockaddr_in)) {
if (control) {
SCTP_RELEASE_PKT(control);
control = NULL;
}
SCTP_RELEASE_PKT(m);
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, EINVAL);
return (EINVAL);
}
#endif
break;
#endif
#ifdef INET6
case AF_INET6:
#if defined(HAVE_SA_LEN)
if (addr->sa_len != sizeof(struct sockaddr_in6)) {
if (control) {
SCTP_RELEASE_PKT(control);
control = NULL;
}
SCTP_RELEASE_PKT(m);
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, EINVAL);
return (EINVAL);
}
#endif
break;
#endif
default:
if (control) {
SCTP_RELEASE_PKT(control);
control = NULL;
}
SCTP_RELEASE_PKT(m);
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, EINVAL);
return (EINVAL);
}
#ifdef INET #ifdef INET
sin6 = (struct sockaddr_in6 *)addr; sin6 = (struct sockaddr_in6 *)addr;
if (SCTP_IPV6_V6ONLY(inp)) { if (SCTP_IPV6_V6ONLY(inp)) {
...@@ -1015,10 +1057,20 @@ sctp6_send(struct socket *so, int flags, struct mbuf *m, struct mbuf *nam, ...@@ -1015,10 +1057,20 @@ sctp6_send(struct socket *so, int flags, struct mbuf *m, struct mbuf *nam,
* v4 addr or v4-mapped addr * v4 addr or v4-mapped addr
*/ */
if (addr->sa_family == AF_INET) { if (addr->sa_family == AF_INET) {
if (control) {
SCTP_RELEASE_PKT(control);
control = NULL;
}
SCTP_RELEASE_PKT(m);
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, EINVAL); SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, EINVAL);
return (EINVAL); return (EINVAL);
} }
if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) { if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
if (control) {
SCTP_RELEASE_PKT(control);
control = NULL;
}
SCTP_RELEASE_PKT(m);
SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, EINVAL); SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, EINVAL);
return (EINVAL); return (EINVAL);
} }
......
...@@ -56,8 +56,14 @@ ...@@ -56,8 +56,14 @@
#endif #endif
#endif #endif
#endif #endif
#if defined(__APPLE__) || defined(__DragonFly__) || defined(__FreeBSD__) #if defined(HAVE_NET_ROUTE_H)
#include <net/route.h> # include <net/route.h>
#elif defined(__APPLE__)
/* Apple SDKs for iOS, tvOS, watchOS, etc. don't ship this header */
# define RTM_NEWADDR 0xc
# define RTM_DELADDR 0xd
# define RTAX_IFA 5
# define RTAX_MAX 8
#endif #endif
/* local macros and datatypes used to get IP addresses system independently */ /* 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)
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论