From 251e1d698d5e947858cd68033199a178643871b0 Mon Sep 17 00:00:00 2001 From: Stefan Sperling Date: Thu, 22 Feb 2018 17:25:25 +0100 Subject: destroy hnb context from the txflush() callback These are the osmo-iuh changes corresponding to the libosmo-netif branch 'destroy_conn_with_txflush_callback'. Change-Id: I380e9e41161cbf51b272c7f3725ccaeef625546c --- include/osmocom/iuh/hnbgw.h | 4 ++++ src/hnbgw.c | 11 +++++++++++ src/hnbgw_hnbap.c | 10 +++++++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/include/osmocom/iuh/hnbgw.h b/include/osmocom/iuh/hnbgw.h index db49dc1..4e02d5f 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 cd492bb..188b292 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 c9a8807..207f49f 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; } } -- cgit v1.2.3