From a3b68cc7cf73f788c547f8e6aab3ab6e1163bbeb Mon Sep 17 00:00:00 2001 From: Jonathan Lennox Date: Mon, 22 Apr 2024 14:08:32 -0400 Subject: [PATCH] Add configure option to disable upcalls. --- configure.ac | 9 +++++++++ usrsctplib/netinet/sctputil.c | 12 ++++++++++++ usrsctplib/user_socket.c | 5 +++++ 3 files changed, 26 insertions(+) diff --git a/configure.ac b/configure.ac index 55f00991f..29364fe84 100644 --- a/configure.ac +++ b/configure.ac @@ -140,6 +140,15 @@ AC_ARG_ENABLE(programs, enable_programs=$enableval,enable_programs=yes) AM_CONDITIONAL([COND_PROGRAMS], [test "$enable_programs" = yes]) +AC_ARG_ENABLE(upcalls, + AC_HELP_STRING( [--enable-upcalls], + [enable socket upcall support @<:@default=yes@:>@]), + enable_upcalls=$enableval,enable_upcalls=yes) +if test x$enable_upcalls = xno; then + APPCFLAGS="$APPCFLAGS -DDISABLE_UPCALLS" + AC_DEFINE(DISABLE_UPCALLS, 1, [Disable upcall support]) +fi + AC_CHECK_TYPE(size_t) AC_CHECK_TYPE(ssize_t) diff --git a/usrsctplib/netinet/sctputil.c b/usrsctplib/netinet/sctputil.c index 6c5de480a..c190f1e03 100755 --- a/usrsctplib/netinet/sctputil.c +++ b/usrsctplib/netinet/sctputil.c @@ -8682,6 +8682,9 @@ sctp_add_substate(struct sctp_tcb *stcb, int substate) #if defined(__Userspace__) struct socket* sctp_get_upcall_socket(struct sctp_tcb * stcb) { +#ifdef DISABLE_UPCALLS + return NULL; +#else struct socket* upcall_socket = NULL; if ((stcb != NULL) && ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) && @@ -8692,10 +8695,14 @@ struct socket* sctp_get_upcall_socket(struct sctp_tcb * stcb) SOCK_UNLOCK(upcall_socket); } return upcall_socket; +#endif } struct socket* sctp_get_upcall_socket_or_accept_head(struct sctp_tcb * stcb) { +#ifdef DISABLE_UPCALLS + return NULL; +#else struct socket* upcall_socket = NULL; if ((stcb != NULL) && ((stcb->sctp_ep->sctp_flags & SCTP_PCB_FLAGS_SOCKET_GONE) == 0) && @@ -8712,11 +8719,13 @@ struct socket* sctp_get_upcall_socket_or_accept_head(struct sctp_tcb * stcb) ACCEPT_UNLOCK(); } return upcall_socket; +#endif } void sctp_do_upcall_socket_if_error(struct socket *upcall_socket) { +#ifndef DISABLE_UPCALLS if (upcall_socket != NULL) { if ((upcall_socket->so_upcall != NULL) && (upcall_socket->so_error != 0)) { @@ -8726,10 +8735,12 @@ void sctp_do_upcall_socket_if_error(struct socket *upcall_socket) SOCK_LOCK(upcall_socket); sorele(upcall_socket); } +#endif } void sctp_do_upcall_socket_if_readable_writeable_or_error(struct socket *upcall_socket) { +#ifndef DISABLE_UPCALLS if (upcall_socket != NULL) { if (upcall_socket->so_upcall != NULL) { if (soreadable(upcall_socket) || @@ -8742,6 +8753,7 @@ void sctp_do_upcall_socket_if_readable_writeable_or_error(struct socket *upcall_ SOCK_LOCK(upcall_socket); sorele(upcall_socket); } +#endif } void sctp_upcall_socket_if_error(struct sctp_tcb *stcb) diff --git a/usrsctplib/user_socket.c b/usrsctplib/user_socket.c index cde6ecc41..ecfc17258 100755 --- a/usrsctplib/user_socket.c +++ b/usrsctplib/user_socket.c @@ -3369,6 +3369,10 @@ usrsctp_set_upcall(struct socket *so, void (*upcall)(struct socket *, void *, in return (-1); } +#ifdef DISABLE_UPCALLS + errno = ENOSYS; + return -1; +#else SOCK_LOCK(so); so->so_upcall = upcall; so->so_upcallarg = arg; @@ -3377,6 +3381,7 @@ usrsctp_set_upcall(struct socket *so, void (*upcall)(struct socket *, void *, in SOCK_UNLOCK(so); return (0); +#endif } #define USRSCTP_TUNABLE_SET_DEF(__field, __prefix) \