destroy hnb context by sending a zero-len msgb after rejecting a HNB

These are the osmo-iuh changes corresponding to the libosmo-netif
branch 'destroy_conn_with_zero_msg'.

Change-Id: I15f90a2e899789320e9329e33b3d294a65cc16b6
This commit is contained in:
Stefan Sperling 2018-02-22 17:20:16 +01:00
parent cc6ed397a6
commit 50fb6f9d64
3 changed files with 29 additions and 8 deletions

View File

@ -161,7 +161,7 @@ struct ue_context *ue_context_alloc(struct hnb_context *hnb, const char *imsi,
void ue_context_free(struct ue_context *ue); void ue_context_free(struct ue_context *ue);
struct hnb_context *hnb_context_alloc(struct hnb_gw *gw, struct osmo_stream_srv_link *link, int new_fd); struct hnb_context *hnb_context_alloc(struct hnb_gw *gw, struct osmo_stream_srv_link *link, int new_fd);
void hnb_context_release(struct hnb_context *ctx); void hnb_context_release(struct hnb_context *ctx, bool destroy_conn);
void hnbgw_vty_init(struct hnb_gw *gw, void *tall_ctx); void hnbgw_vty_init(struct hnb_gw *gw, void *tall_ctx);
int hnbgw_vty_go_parent(struct vty *vty); int hnbgw_vty_go_parent(struct vty *vty);

View File

@ -204,6 +204,11 @@ void ue_context_free(struct ue_context *ue)
} }
static int hnb_close_cb(struct osmo_stream_srv *conn) static int hnb_close_cb(struct osmo_stream_srv *conn)
{ {
struct hnb_context *hnb = osmo_stream_srv_get_data(conn);
if (hnb)
hnb_context_release(hnb, false);
return 0; return 0;
} }
@ -228,10 +233,10 @@ static int hnb_read_cb(struct osmo_stream_srv *conn)
} else if (rc < 0) { } else if (rc < 0) {
LOGP(DMAIN, LOGL_ERROR, "Error during sctp_recvmsg()\n"); LOGP(DMAIN, LOGL_ERROR, "Error during sctp_recvmsg()\n");
/* FIXME: clean up after disappeared HNB */ /* FIXME: clean up after disappeared HNB */
hnb_context_release(hnb); hnb_context_release(hnb, true);
goto out; goto out;
} else if (rc == 0) { } else if (rc == 0) {
hnb_context_release(hnb); hnb_context_release(hnb, true);
rc = -1; rc = -1;
goto out; goto out;
@ -288,7 +293,7 @@ struct hnb_context *hnb_context_alloc(struct hnb_gw *gw, struct osmo_stream_srv_
return ctx; return ctx;
} }
void hnb_context_release(struct hnb_context *ctx) void hnb_context_release(struct hnb_context *ctx, bool destroy_conn)
{ {
struct hnbgw_context_map *map, *map2; struct hnbgw_context_map *map, *map2;
@ -305,6 +310,8 @@ void hnb_context_release(struct hnb_context *ctx)
context_map_deactivate(map); context_map_deactivate(map);
} }
ue_context_free_by_hnb(ctx->gw, ctx); ue_context_free_by_hnb(ctx->gw, ctx);
if (destroy_conn)
osmo_stream_srv_destroy(ctx->conn); osmo_stream_srv_destroy(ctx->conn);
talloc_free(ctx); talloc_free(ctx);

View File

@ -53,7 +53,7 @@ static int hnbgw_tx_hnb_register_rej(struct hnb_context *ctx)
{ {
HNBRegisterReject_t reject_out; HNBRegisterReject_t reject_out;
HNBRegisterRejectIEs_t reject; HNBRegisterRejectIEs_t reject;
struct msgb *msg; struct msgb *msg, *msg0;
int rc; int rc;
reject.presenceMask = 0, reject.presenceMask = 0,
@ -69,6 +69,10 @@ static int hnbgw_tx_hnb_register_rej(struct hnb_context *ctx)
return rc; return rc;
} }
msg0 = msgb_alloc(0, "zero-length terminating message");
if (msg0 == NULL)
return -ENOMEM;
/* generate a successfull outcome PDU */ /* generate a successfull outcome PDU */
msg = hnbap_generate_unsuccessful_outcome(ProcedureCode_id_HNBRegister, msg = hnbap_generate_unsuccessful_outcome(ProcedureCode_id_HNBRegister,
Criticality_reject, Criticality_reject,
@ -77,7 +81,17 @@ static int hnbgw_tx_hnb_register_rej(struct hnb_context *ctx)
ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_HNBRegisterReject, &reject_out); ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_HNBRegisterReject, &reject_out);
return hnbgw_hnbap_tx(ctx, msg); rc = hnbgw_hnbap_tx(ctx, msg);
if (rc == 0) {
/* Enqueue a zero-length message to destroy the connection
* after sending HNB-REGISTER-REJECT. */
if (hnbgw_hnbap_tx(ctx, msg0) != 0)
LOGP(DHNBAP, LOGL_ERROR, "Failure to send zero-length message after "
"HNB-REGISTER-REJECT to %s: rc=%d; the connection won't be closed "
"from our side\n", ctx->identity_info, rc);
}
return rc;
} }
static int hnbgw_tx_hnb_register_acc(struct hnb_context *ctx) static int hnbgw_tx_hnb_register_acc(struct hnb_context *ctx)
@ -393,7 +407,7 @@ static int hnbgw_rx_hnb_deregister(struct hnb_context *ctx, ANY_t *in)
hnbap_cause_str(&ies.cause)); hnbap_cause_str(&ies.cause));
hnbap_free_hnbde_registeries(&ies); hnbap_free_hnbde_registeries(&ies);
hnb_context_release(ctx); hnb_context_release(ctx, true);
return 0; return 0;
} }