hnbgw: Fix recent regression not closing conn upon rx of SCTP_SHUTDOWN_EVENT

Before handling of OSMO_STREAM_SCTP_MSG_FLAGS_NOTIFICATION in recent
commit (see Fixes: below), osmo_stream_srv_recv() and
internal _sctp_recvmsg_wrapper() in libosmo-netif would return either
-EAGAIN or 0 when an sctp notification was received from the kernel.

After adding handling of OSMO_STREAM_SCTP_MSG_FLAGS_NOTIFICATION, the
code paths for "rc == -EAGAIN" and "rc == 0" would not be executed
anymore since the first branch takes preference in the if-else
tree. For "rc == -EAGAIN" it's fine because the new branch superseeds
what's done on the "rc == -EAGAIN" branch. However, for the "rc == 0",
we forgot to actually destroy the connection. The "rc == 0" branch was
basically reached when SCTP_SHUTDOWN_EVENT was received because
osmo_stream_srv_recv() tried to resemble the interface of regular
recv(); let's hence check for that explicitly and destroy the conn
object (and the related hnb context in the process) when we receive
that event.

Fixes: 1de2091515
Related: SYS#6113
Change-Id: I11b6af51a58dc250975a696b98d0c0c9ff3df9e0
This commit is contained in:
Pau Espin 2022-09-22 16:10:34 +02:00
parent 1de2091515
commit 3bf5395102
1 changed files with 11 additions and 4 deletions

View File

@ -254,6 +254,7 @@ static int hnb_read_cb(struct osmo_stream_srv *conn)
/* Notification received */ /* Notification received */
if (msgb_sctp_msg_flags(msg) & OSMO_STREAM_SCTP_MSG_FLAGS_NOTIFICATION) { if (msgb_sctp_msg_flags(msg) & OSMO_STREAM_SCTP_MSG_FLAGS_NOTIFICATION) {
union sctp_notification *notif = (union sctp_notification *)msgb_data(msg); union sctp_notification *notif = (union sctp_notification *)msgb_data(msg);
rc = 0;
switch (notif->sn_header.sn_type) { switch (notif->sn_header.sn_type) {
case SCTP_ASSOC_CHANGE: case SCTP_ASSOC_CHANGE:
switch (notif->sn_assoc_change.sac_state) { switch (notif->sn_assoc_change.sac_state) {
@ -261,17 +262,23 @@ static int hnb_read_cb(struct osmo_stream_srv *conn)
LOGHNB(hnb, DMAIN, LOGL_NOTICE, "HNB SCTP conn RESTARTed, marking as HNBAP-unregistered\n"); LOGHNB(hnb, DMAIN, LOGL_NOTICE, "HNB SCTP conn RESTARTed, marking as HNBAP-unregistered\n");
hnb->hnb_registered = false; hnb->hnb_registered = false;
break; break;
case SCTP_SHUTDOWN_EVENT:
LOGHNB(hnb, DMAIN, LOGL_NOTICE,
"sctp_recvmsg(%s) = SCTP_SHUTDOWN_EVENT, closing conn\n",
osmo_sock_get_name2(osmo_stream_srv_get_ofd(conn)->fd));
osmo_stream_srv_destroy(conn);
rc = -1;
break;
} }
break; break;
} }
msgb_free(msg); goto out;
return 0;
} else if (rc == -EAGAIN) { } else if (rc == -EAGAIN) {
/* Older versions of osmo_stream_srv_recv() not supporting /* Older versions of osmo_stream_srv_recv() not supporting
* msgb_sctp_msg_flags() may still return -EAGAIN when an sctp * msgb_sctp_msg_flags() may still return -EAGAIN when an sctp
* notification is received. */ * notification is received. */
msgb_free(msg); rc = 0;
return 0; goto out;
} else if (rc < 0) { } else if (rc < 0) {
LOGHNB(hnb, DMAIN, LOGL_ERROR, "Error during sctp_recvmsg(%s)\n", LOGHNB(hnb, DMAIN, LOGL_ERROR, "Error during sctp_recvmsg(%s)\n",
osmo_sock_get_name2(osmo_stream_srv_get_ofd(conn)->fd)); osmo_sock_get_name2(osmo_stream_srv_get_ofd(conn)->fd));