diff options
author | Philipp Maier <pmaier@sysmocom.de> | 2018-08-07 11:31:51 +0200 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2018-08-07 15:11:41 +0000 |
commit | 628a05e738b5f37e2fecd544780240e56db54036 (patch) | |
tree | 6f6d89d30b77177980ed5a01c00057dc6f05d32a /src/osmo-bsc/a_reset.c | |
parent | bf4e29a7dff6e3b5ce9e4da150b8b1dfce86be83 (diff) |
GSCON: call api of a_reset.c with msc object directly
The API of a_reset.c is currently called with a pointer to struct
reset_ctx. This puts the responsibility of checking the presence of
msc->a.reset_fsm to the caller. It would be much more effective if the
caller would check if msc->a.reset_fsm before dereferencing it.
This also fixes at least one segfault that ocurrs when gscon_timer_cb()
is called but no sccp connection is present yet. Therefore the pointer
to bsc_msc_data would not be populated. This is now detected by
a_reset.c itsself.
- minor code cleanups
- call a_reset.c functions with msc (struct bsc_msc_data)
Change-Id: I0802aaadf0af4e58e41c98999e8c6823838adb61
Related: OS#3447
Diffstat (limited to 'src/osmo-bsc/a_reset.c')
-rw-r--r-- | src/osmo-bsc/a_reset.c | 61 |
1 files changed, 38 insertions, 23 deletions
diff --git a/src/osmo-bsc/a_reset.c b/src/osmo-bsc/a_reset.c index b8f8c8cbd..3c2114219 100644 --- a/src/osmo-bsc/a_reset.c +++ b/src/osmo-bsc/a_reset.c @@ -137,68 +137,83 @@ static struct osmo_fsm fsm = { }; /* Create and start state machine which handles the reset/reset-ack procedure */ -struct osmo_fsm_inst *a_reset_alloc(void *ctx, const char *name, void *cb, void *priv) +void a_reset_alloc(struct bsc_msc_data *msc, const char *name, void *cb) { - OSMO_ASSERT(name); - struct reset_ctx *reset_ctx; struct osmo_fsm_inst *reset_fsm; + OSMO_ASSERT(msc); + OSMO_ASSERT(name); + OSMO_ASSERT(cb); + + /* There must not be any double allocation! */ + OSMO_ASSERT(msc->a.reset_fsm == NULL); + /* Register the fsm description (if not already done) */ if (osmo_fsm_find_by_name(fsm.name) != &fsm) osmo_fsm_register(&fsm); /* Allocate and configure a new fsm instance */ - reset_ctx = talloc_zero(ctx, struct reset_ctx); + reset_ctx = talloc_zero(msc, struct reset_ctx); OSMO_ASSERT(reset_ctx); - reset_ctx->priv = priv; + reset_ctx->priv = msc; reset_ctx->cb = cb; reset_ctx->conn_loss_counter = 0; - reset_fsm = osmo_fsm_inst_alloc(&fsm, ctx, reset_ctx, LOGL_DEBUG, name); + reset_fsm = osmo_fsm_inst_alloc(&fsm, msc, reset_ctx, LOGL_DEBUG, name); OSMO_ASSERT(reset_fsm); /* kick off reset-ack sending mechanism */ osmo_fsm_inst_state_chg(reset_fsm, ST_DISC, RESET_RESEND_INTERVAL, RESET_RESEND_TIMER_NO); - return reset_fsm; + msc->a.reset_fsm = reset_fsm; } /* Confirm that we sucessfully received a reset acknowlege message */ -void a_reset_ack_confirm(struct osmo_fsm_inst *reset_fsm) +void a_reset_ack_confirm(struct bsc_msc_data *msc) { - OSMO_ASSERT(reset_fsm); - osmo_fsm_inst_dispatch(reset_fsm, EV_RESET_ACK, NULL); + if (!msc) + return; + + if (!msc->a.reset_fsm) + return; + + osmo_fsm_inst_dispatch(msc->a.reset_fsm, EV_RESET_ACK, NULL); } /* Report a failed connection */ -void a_reset_conn_fail(struct osmo_fsm_inst *reset_fsm) +void a_reset_conn_fail(struct bsc_msc_data *msc) { - /* If no reset context is supplied, just drop the info */ - if (!reset_fsm) + if (!msc) + return; + + if (!msc->a.reset_fsm) return; - osmo_fsm_inst_dispatch(reset_fsm, EV_N_DISCONNECT, NULL); + osmo_fsm_inst_dispatch(msc->a.reset_fsm, EV_N_DISCONNECT, NULL); } /* Report a successful connection */ -void a_reset_conn_success(struct osmo_fsm_inst *reset_fsm) +void a_reset_conn_success(struct bsc_msc_data *msc) { - /* If no reset context is supplied, just drop the info */ - if (!reset_fsm) + if (!msc) return; - osmo_fsm_inst_dispatch(reset_fsm, EV_N_CONNECT, NULL); + if (!msc->a.reset_fsm) + return; + + osmo_fsm_inst_dispatch(msc->a.reset_fsm, EV_N_CONNECT, NULL); } /* Check if we have a connection to a specified msc */ -bool a_reset_conn_ready(struct osmo_fsm_inst *reset_fsm) +bool a_reset_conn_ready(struct bsc_msc_data *msc) { - /* If no reset context is supplied, we assume that - * the connection can't be ready! */ - if (!reset_fsm) + if (!msc) + return false; + + if (!msc->a.reset_fsm) return false; - if (reset_fsm->state == ST_CONN) + if (msc->a.reset_fsm->state == ST_CONN) return true; return false; |