From 1de2091515530e531196ebca27b1445cecd1b88d Mon Sep 17 00:00:00 2001 From: Pau Espin Pedrol Date: Mon, 19 Sep 2022 14:54:35 +0200 Subject: [PATCH] hnbgw: Unregister HNB if SCTP link is restarted Sometimes an hNodeB may reconnect (SCTP INIT) using same SCTP tuple without closing the previous conn. This is handled by the SCTP stack by means of pushing a RESET notification up the stack to the sctp_recvmsg() user. Let's handle this by marking the HNB as unregistered, since most probably a HNB Register Req comes next as the upper layer state is considered lost. Depends: libosmo-netif.git Change-Id I0ee94846a15a23950b9d70eaaef1251267296bdd Related: SYS#6113 Change-Id: Ib22881b1a34b1c3dd350912b3de8904917cf34ef --- src/osmo-hnbgw/hnbgw.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/osmo-hnbgw/hnbgw.c b/src/osmo-hnbgw/hnbgw.c index 8c2dc64..124a647 100644 --- a/src/osmo-hnbgw/hnbgw.c +++ b/src/osmo-hnbgw/hnbgw.c @@ -251,8 +251,25 @@ static int hnb_read_cb(struct osmo_stream_srv *conn) msg->dst = hnb; rc = osmo_stream_srv_recv(conn, msg); - if (rc == -EAGAIN) { - /* Notification received */ + /* Notification received */ + if (msgb_sctp_msg_flags(msg) & OSMO_STREAM_SCTP_MSG_FLAGS_NOTIFICATION) { + union sctp_notification *notif = (union sctp_notification *)msgb_data(msg); + switch (notif->sn_header.sn_type) { + case SCTP_ASSOC_CHANGE: + switch (notif->sn_assoc_change.sac_state) { + case SCTP_RESTART: + LOGHNB(hnb, DMAIN, LOGL_NOTICE, "HNB SCTP conn RESTARTed, marking as HNBAP-unregistered\n"); + hnb->hnb_registered = false; + break; + } + break; + } + msgb_free(msg); + return 0; + } else if (rc == -EAGAIN) { + /* Older versions of osmo_stream_srv_recv() not supporting + * msgb_sctp_msg_flags() may still return -EAGAIN when an sctp + * notification is received. */ msgb_free(msg); return 0; } else if (rc < 0) {