Skip to content

Commit

Permalink
Add configure option to disable upcalls.
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanLennox committed Apr 22, 2024
1 parent 76c5508 commit a3b68cc
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
9 changes: 9 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
12 changes: 12 additions & 0 deletions usrsctplib/netinet/sctputil.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) &&
Expand All @@ -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) &&
Expand All @@ -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)) {
Expand All @@ -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) ||
Expand All @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions usrsctplib/user_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) \
Expand Down

0 comments on commit a3b68cc

Please sign in to comment.