Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experimental usrsctp support #1637

Draft
wants to merge 17 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
62 changes: 59 additions & 3 deletions erts/configure.in
Expand Up @@ -175,7 +175,7 @@ AS_HELP_STRING([--enable-sctp=lib], [enable sctp support
to link against the SCTP library])
AS_HELP_STRING([--disable-sctp], [disable sctp support]),
[ case "x$enableval" in
xno|xyes|xlib|x)
xno|xyes|xlib|xusrsctp|x)
;;
x*)
AC_MSG_ERROR("invalid value --enable-sctp=$enableval")
Expand Down Expand Up @@ -1647,7 +1647,8 @@ AC_CHECK_HEADERS([sys/timerfd.h])

dnl Check for kernel SCTP support
AC_SUBST(LIBSCTP)
if test "x$enable_sctp" != "xno" ; then
if test "x$enable_sctp" != "xno" && \
test "x$enable_sctp" != "xusrsctp" ; then
AC_CHECK_HEADER(netinet/sctp.h,
[LIBSCTP=libsctp.so.1
AC_DEFINE(HAVE_SCTP_H, [1],
Expand All @@ -1659,7 +1660,30 @@ if test "x$enable_sctp" != "xno" ; then
])
fi

if test x"$ac_cv_header_netinet_sctp_h" = x"yes"; then
AC_SUBST(LIBSCTP)
if test "x$enable_sctp" = "xusrsctp" ; then
case $host_os in
darwin*)
SCTPLIB=libusrsctp.dylib
;;
linux*)
SCTPLIB=libusrsctp.so
;;
esac
AC_CHECK_HEADER(usrsctp.h,
[LIBSCTP=$SCTPLIB
AC_DEFINE(HAVE_SCTP_H, [1],
[Define to 1 if you have the SCTP support])
AC_DEFINE(HAVE_USRSCTP, [1],
[Define to 1 if you have the <usrsctp.h> header file])],
[],
[#if HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
])
fi

if test x"$ac_cv_header_netinet_sctp_h" = x"yes" ; then
AS_IF([test "x$enable_sctp" = "xlib"],
AC_CHECK_LIB(sctp, sctp_bindx))
AC_CHECK_FUNCS([sctp_bindx sctp_peeloff sctp_getladdrs sctp_freeladdrs sctp_getpaddrs sctp_freepaddrs])
Expand Down Expand Up @@ -1694,6 +1718,38 @@ if test x"$ac_cv_header_netinet_sctp_h" = x"yes"; then
])
fi

if test x"$ac_cv_header_usrsctp_h" = x"yes" ; then
AC_CHECK_DECLS([SCTP_UNORDERED, SCTP_ADDR_OVER, SCTP_ABORT,
SCTP_EOF, SCTP_SENDALL, SCTP_ADDR_CONFIRMED,
SCTP_DELAYED_ACK_TIME,
SCTP_EMPTY, SCTP_UNCONFIRMED,
SCTP_CLOSED, SCTPS_IDLE,
SCTP_BOUND, SCTPS_BOUND,
SCTP_LISTEN, SCTPS_LISTEN,
SCTP_COOKIE_WAIT, SCTPS_COOKIE_WAIT,
SCTP_COOKIE_ECHOED, SCTPS_COOKIE_ECHOED,
SCTP_ESTABLISHED, SCTPS_ESTABLISHED,
SCTP_SHUTDOWN_PENDING, SCTPS_SHUTDOWN_PENDING,
SCTP_SHUTDOWN_SENT, SCTPS_SHUTDOWN_SENT,
SCTP_SHUTDOWN_RECEIVED, SCTPS_SHUTDOWN_RECEIVED,
SCTP_SHUTDOWN_ACK_SENT, SCTPS_SHUTDOWN_ACK_SENT], [], [],
[#if HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#include <usrsctp.h>
])
AC_CHECK_MEMBERS([struct sctp_paddrparams.spp_pathmtu,
struct sctp_paddrparams.spp_sackdelay,
struct sctp_paddrparams.spp_flags,
struct sctp_remote_error.sre_data,
struct sctp_send_failed.ssf_data], [], [],
[#if HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#include <usrsctp.h>
])
fi

dnl Check for setns
AC_CHECK_HEADERS(sched.h setns.h)
AC_CHECK_FUNCS([setns])
Expand Down
1 change: 1 addition & 0 deletions erts/emulator/beam/erl_alloc.types
Expand Up @@ -362,6 +362,7 @@ type POLL_FDS LONG_LIVED SYSTEM poll_fds
type POLL_RES_EVS LONG_LIVED SYSTEM poll_result_events
type FD_STATUS LONG_LIVED SYSTEM fd_status
type SELECT_FDS LONG_LIVED SYSTEM select_fds
type DRV_SCTP_SOCK LONG_LIVED SYSTEM driver_sctp_sock

+if unix

Expand Down
9 changes: 8 additions & 1 deletion erts/emulator/beam/erl_driver.h
Expand Up @@ -38,7 +38,11 @@
#endif

#include "erl_drv_nif.h"

#if SIZEOF_VOID_P == SIZEOF_LONG
typedef unsigned long Eterm;
#elif SIZEOF_VOID_P == SIZEOF_INT
typedef unsigned int Eterm;
#endif
#include <stdlib.h>

#if defined(__WIN32__) || defined(_WIN32) || defined(_WIN32_)
Expand Down Expand Up @@ -342,6 +346,9 @@ EXTERN ErlDrvSizeT driver_vec_to_buf(ErlIOVec *ev, char *buf, ErlDrvSizeT len);
EXTERN int driver_set_timer(ErlDrvPort port, unsigned long time);
EXTERN int driver_cancel_timer(ErlDrvPort port);
EXTERN int driver_read_timer(ErlDrvPort port, unsigned long *time_left);
EXTERN Eterm driver_erts_drvport2id(ErlDrvPort port);
EXTERN int driver_port_task_input_schedule(Eterm port);
EXTERN int driver_port_task_output_schedule(Eterm port);

/*
* Inform runtime system about lengthy work.
Expand Down
9 changes: 9 additions & 0 deletions erts/emulator/beam/erl_driver_global.h
@@ -0,0 +1,9 @@
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#ifdef HAVE_USRSCTP
extern int sctp_raw_ipv4;
extern int sctp_raw_ipv6;
extern int sctp_raw_route;
#endif
15 changes: 15 additions & 0 deletions erts/emulator/beam/erl_init.c
Expand Up @@ -50,6 +50,7 @@
#define ERTS_WANT_TIMER_WHEEL_API
#include "erl_time.h"
#include "erl_check_io.h"
#include "erl_driver_global.h"

#ifdef HIPE
#include "hipe_mode_switch.h" /* for hipe_mode_switch_init() */
Expand Down Expand Up @@ -2106,6 +2107,20 @@ erl_start(int argc, char **argv)
erts_usage();
}
}
#ifdef HAVE_USRSCTP
else if (has_prefix("sctp_raw_ipv4", sub_param)) {
arg = get_arg(sub_param+13, argv[i+1], &i);
sctp_raw_ipv4 = atoi(arg);
}
else if (has_prefix("sctp_raw_ipv6", sub_param)) {
arg = get_arg(sub_param+13, argv[i+1], &i);
sctp_raw_ipv6 = atoi(arg);
}
else if (has_prefix("sctp_raw_route", sub_param)) {
arg = get_arg(sub_param+14, argv[i+1], &i);
sctp_raw_route = atoi(arg);
}
#endif
else {
erts_fprintf(stderr, "bad -z option %s\n", argv[i]);
erts_usage();
Expand Down
5 changes: 4 additions & 1 deletion erts/emulator/beam/erl_port_task.c
Expand Up @@ -1569,7 +1569,10 @@ erts_port_task_schedule(Eterm id,
fail:

if (dhndl != ERTS_THR_PRGR_DHANDLE_MANAGED)
erts_port_dec_refc(pp);
{
if(pp)
erts_port_dec_refc(pp);
}

if (ptp) {
abort_signal_task(pp, ERTS_PROC2PORT_SIG_ABORT,
Expand Down
4 changes: 2 additions & 2 deletions erts/emulator/beam/safe_hash.c
Expand Up @@ -29,8 +29,8 @@

#include "safe_hash.h"

/* Currently only used by erl_check_io on Windows */
#ifndef ERTS_SYS_CONTINOUS_FD_NUMBERS
/* Currently only used by erl_check_io on Windows and USRSCTP if enabled */
#if !defined(ERTS_SYS_CONTINOUS_FD_NUMBERS) || defined(HAVE_USRSCTP)


static ERTS_INLINE void set_size(SafeHash* h, int size)
Expand Down