From 6e8241356b832d6d45a4d5051fb1397701e59071 Mon Sep 17 00:00:00 2001 From: Max Date: Sat, 11 Feb 2023 15:32:50 +0300 Subject: [PATCH] SS7: do not attempt transfer if AS is down The attempt to route message via AS which is down will fail anyway: let's make it explicit. Add osmo_ss7_as_down() and use it to check AS state before transferring the message. Change-Id: I0d5f3b6265e7fdaa79e32fbc30f829ef79e7dad1 --- include/osmocom/sigtran/osmo_ss7.h | 1 + src/osmo_ss7.c | 12 ++++++++++++ src/osmo_ss7_hmrt.c | 6 ++++++ 3 files changed, 19 insertions(+) diff --git a/include/osmocom/sigtran/osmo_ss7.h b/include/osmocom/sigtran/osmo_ss7.h index 1755859e..cd1779c6 100644 --- a/include/osmocom/sigtran/osmo_ss7.h +++ b/include/osmocom/sigtran/osmo_ss7.h @@ -352,6 +352,7 @@ int osmo_ss7_as_del_asp(struct osmo_ss7_as *as, const char *asp_name); void osmo_ss7_as_destroy(struct osmo_ss7_as *as); bool osmo_ss7_as_has_asp(const struct osmo_ss7_as *as, const struct osmo_ss7_asp *asp); +bool osmo_ss7_as_down(const struct osmo_ss7_as *as); bool osmo_ss7_as_active(const struct osmo_ss7_as *as); bool osmo_ss7_as_tmode_compatible_xua(struct osmo_ss7_as *as, uint32_t m3ua_tmt); void osmo_ss7_asp_disconnect(struct osmo_ss7_asp *asp); diff --git a/src/osmo_ss7.c b/src/osmo_ss7.c index a4af7271..3dc0d51e 100644 --- a/src/osmo_ss7.c +++ b/src/osmo_ss7.c @@ -1143,6 +1143,18 @@ bool osmo_ss7_as_active(const struct osmo_ss7_as *as) return as->fi->state == XUA_AS_S_ACTIVE; } +/*! Determine if given AS is in the down state. + * \param[in] as Application Server. + * \returns true in case as is down; false otherwise. */ +bool osmo_ss7_as_down(const struct osmo_ss7_as *as) +{ + OSMO_ASSERT(as); + + if (!as->fi) + return true; + return as->fi->state == XUA_AS_S_DOWN; +} + /*********************************************************************** * SS7 Application Server Process ***********************************************************************/ diff --git a/src/osmo_ss7_hmrt.c b/src/osmo_ss7_hmrt.c index f5fcd64c..3ac43b8e 100644 --- a/src/osmo_ss7_hmrt.c +++ b/src/osmo_ss7_hmrt.c @@ -228,6 +228,12 @@ static int hmrt_message_for_routing(struct osmo_ss7_instance *inst, dpc, osmo_ss7_pointcode_print(inst, dpc), rt_name); } + if (osmo_ss7_as_down(as)) { + LOGP(DLSS7, LOGL_ERROR, "Unable to route HMRT message: the AS %s is down\n", + as->cfg.name); + return -ENETDOWN; + } + rate_ctr_inc2(as->ctrg, SS7_AS_CTR_TX_MSU_TOTAL); switch (as->cfg.proto) {