diff --git a/include/osmocom/iuh/hnbgw.h b/include/osmocom/iuh/hnbgw.h index db49dc15..4e02d5f8 100644 --- a/include/osmocom/iuh/hnbgw.h +++ b/include/osmocom/iuh/hnbgw.h @@ -101,6 +101,10 @@ struct hnb_context { * this entire data structure is freed if the HNB sends HNB-DE-REGISTER-REQ. */ bool hnb_registered; + /*! True if a HNB-REGISTER-REJECT has been sent to this HNB. If this flag + * is set we will close the connection once its Tx queue has been flushed. */ + bool hnb_rejected; + /* linked list of hnbgw_context_map */ struct llist_head map_list; }; diff --git a/src/hnbgw.c b/src/hnbgw.c index cd492bb2..188b292c 100644 --- a/src/hnbgw.c +++ b/src/hnbgw.c @@ -267,6 +267,15 @@ out: return rc; } +static void txflushed_cb(struct osmo_stream_srv *conn, void *data) +{ + struct hnb_context *hnb = osmo_stream_srv_get_data(conn); + + /* Close connection after sending HNB-REGISTER-REJECT and the Tx queue has been flushed. */ + if (hnb->hnb_rejected) + hnb_context_release(hnb); +} + struct hnb_context *hnb_context_alloc(struct hnb_gw *gw, struct osmo_stream_srv_link *link, int new_fd) { struct hnb_context *ctx; @@ -284,6 +293,8 @@ struct hnb_context *hnb_context_alloc(struct hnb_gw *gw, struct osmo_stream_srv_ return NULL; } + osmo_stream_srv_set_txflushed_cb(ctx->conn, txflushed_cb); + llist_add_tail(&ctx->list, &gw->hnb_list); return ctx; } diff --git a/src/hnbgw_hnbap.c b/src/hnbgw_hnbap.c index c9a8807e..207f49ff 100644 --- a/src/hnbgw_hnbap.c +++ b/src/hnbgw_hnbap.c @@ -428,7 +428,15 @@ static int hnbgw_rx_hnb_register_req(struct hnb_context *ctx, ANY_t *in) "MCC=%u,MNC=%u,LAC=%u,RAC=%u,SAC=%u,CID=%u from %s\n", ctx->id.mcc, ctx->id.mnc, ctx->id.lac, ctx->id.rac, ctx->id.sac, ctx->id.cid, name); talloc_free(name); - return hnbgw_tx_hnb_register_rej(ctx); + rc = hnbgw_tx_hnb_register_rej(ctx); + if (rc != 0) { + /* The message was not queued. Clean up HNB right away. */ + hnb_context_release(ctx); + } else { + /* Release the HNB once the message has been sent. */ + ctx->hnb_rejected = true; + } + return rc; } }