From 5f19597b021fbe21198834fbc7919da5c9b72adf Mon Sep 17 00:00:00 2001 From: Pau Espin Pedrol Date: Fri, 30 Sep 2022 14:46:16 +0200 Subject: [PATCH] Close conn when receiving SCTP_ASSOC_CHANGE notification It was seen on a real pcap trace (sctp & gsmtap_log) that the kernel stack may decide to kill the connection (sending an ABORT) if it fails to transmit some data after a while: ABORT Cause code: "Protocol violation (0x000d)", Cause Information: "Association exceeded its max_retrans count". When this occurs, the kernel sends the MSG_NOTIFICATION,SCTP_ASSOC_CHANGE,SCTP_COMM_LOST notification when reading from the socket with sctp_recvmsg(). This basically signals that the socket conn is dead, and subsequent writes to it will result in send() failures (and receive SCTP_SEND_FAILED notification upon follow up reads). It's important to notice that after those events, there's no other sort of different event like SHUTDOWN coming in, so that's the time at which we must tell the user to close the socket. Hence, let's signal the caller that the socket is dead by returning 0, to comply with usual recv() API. Related: SYS#6113 Change-Id: If35efd404405f926a4a6cc45862eeadd1b04e08c --- src/osmo-hnbgw/hnbgw.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/osmo-hnbgw/hnbgw.c b/src/osmo-hnbgw/hnbgw.c index 0c59c7d..dd0999c 100644 --- a/src/osmo-hnbgw/hnbgw.c +++ b/src/osmo-hnbgw/hnbgw.c @@ -258,6 +258,13 @@ static int hnb_read_cb(struct osmo_stream_srv *conn) switch (notif->sn_header.sn_type) { case SCTP_ASSOC_CHANGE: switch (notif->sn_assoc_change.sac_state) { + case SCTP_COMM_LOST: + LOGHNB(hnb, DMAIN, LOGL_NOTICE, + "sctp_recvmsg(%s) = SCTP_COMM_LOST, closing conn\n", + osmo_sock_get_name2(osmo_stream_srv_get_ofd(conn)->fd)); + osmo_stream_srv_destroy(conn); + rc = -1; + break; case SCTP_RESTART: LOGHNB(hnb, DMAIN, LOGL_NOTICE, "HNB SCTP conn RESTARTed, marking as HNBAP-unregistered\n"); hnb->hnb_registered = false;