From d157a56361c9b42bc63dc998183b2c4471a5ef04 Mon Sep 17 00:00:00 2001 From: Vadim Yanitskiy Date: Sat, 1 Dec 2018 00:03:39 +0700 Subject: [PATCH] SS/USSD: make NCSS session timeout configurable It may happen that either the MS or an ESME would become unresponsive, e.g. due to a bug, or a dropped message. This is why we have SS session timeout, that prevents keeping 'stalled' sessions forever. Let's introduce a VTY option, which can be used to configure this timer (by default it's set to 30 seconds): hlr ... ! Use 0 to disable this timer ncss-guard-timeout 30 Change-Id: I971fc2cee6fd46d4d5d6dac6c634e0b22fff183d Related: OS#3717 --- src/hlr.c | 3 +++ src/hlr.h | 3 +++ src/hlr_ussd.c | 9 +++++---- src/hlr_ussd.h | 2 ++ src/hlr_vty.c | 15 +++++++++++++++ tests/test_nodes.vty | 1 + 6 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/hlr.c b/src/hlr.c index 14945b66..4873a66f 100644 --- a/src/hlr.c +++ b/src/hlr.c @@ -611,6 +611,9 @@ int main(int argc, char **argv) INIT_LLIST_HEAD(&g_hlr->ss_sessions); INIT_LLIST_HEAD(&g_hlr->ussd_routes); + /* Init default (call independent) SS session guard timeout value */ + g_hlr->ncss_guard_timeout = NCSS_GUARD_TIMEOUT_DEFAULT; + rc = osmo_init_logging2(hlr_ctx, &hlr_log_info); if (rc < 0) { fprintf(stderr, "Error initializing logging\n"); diff --git a/src/hlr.h b/src/hlr.h index 315c3dd0..e9cc747f 100644 --- a/src/hlr.h +++ b/src/hlr.h @@ -45,6 +45,9 @@ struct hlr { struct hlr_euse *euse_default; struct llist_head iuse_list; + /* NCSS (call independent) session guard timeout value */ + int ncss_guard_timeout; + struct llist_head ussd_routes; struct llist_head ss_sessions; diff --git a/src/hlr_ussd.c b/src/hlr_ussd.c index b7aaba48..16a197c0 100644 --- a/src/hlr_ussd.c +++ b/src/hlr_ussd.c @@ -209,10 +209,11 @@ struct ss_session *ss_session_alloc(struct hlr *hlr, const char *imsi, uint32_t OSMO_STRLCPY_ARRAY(ss->imsi, imsi); ss->session_id = session_id; osmo_timer_setup(&ss->timeout, ss_session_timeout, ss); - /* NOTE: The timeout is currently global and not refreshed with subsequent messages - * within the SS/USSD session. So 30s after the initial SS message, the session will - * timeout! */ - osmo_timer_schedule(&ss->timeout, 30, 0); + /* NOTE: The timeout is currently not refreshed with subsequent messages + * within the SS/USSD session. So X seconds after the initial SS message, + * the session will timeout! */ + if (g_hlr->ncss_guard_timeout > 0) + osmo_timer_schedule(&ss->timeout, g_hlr->ncss_guard_timeout, 0); llist_add_tail(&ss->list, &hlr->ss_sessions); return ss; diff --git a/src/hlr_ussd.h b/src/hlr_ussd.h index 04149245..393ca6ce 100644 --- a/src/hlr_ussd.h +++ b/src/hlr_ussd.h @@ -7,6 +7,8 @@ #include "gsup_server.h" +#define NCSS_GUARD_TIMEOUT_DEFAULT 30 + struct hlr_ussd_route { /* g_hlr.routes */ struct llist_head list; diff --git a/src/hlr_vty.c b/src/hlr_vty.c index 2d9b9296..6706aa44 100644 --- a/src/hlr_vty.c +++ b/src/hlr_vty.c @@ -35,6 +35,7 @@ #include "hlr.h" #include "hlr_vty.h" #include "hlr_vty_subscr.h" +#include "hlr_ussd.h" #include "gsup_server.h" struct cmd_node hlr_node = { @@ -288,9 +289,22 @@ static int config_write_euse(struct vty *vty) if (g_hlr->euse_default) vty_out(vty, " ussd default-route external %s%s", g_hlr->euse_default->name, VTY_NEWLINE); + if (g_hlr->ncss_guard_timeout != NCSS_GUARD_TIMEOUT_DEFAULT) + vty_out(vty, " ncss-guard-timeout %i%s", + g_hlr->ncss_guard_timeout, VTY_NEWLINE); + return 0; } +DEFUN(cfg_ncss_guard_timeout, cfg_ncss_guard_timeout_cmd, + "ncss-guard-timeout <0-255>", + "Set guard timer for NCSS (call independent SS) session activity\n" + "Guard timer value (sec.), or 0 to disable") +{ + g_hlr->ncss_guard_timeout = atoi(argv[0]); + return CMD_SUCCESS; +} + /*********************************************************************** * Common Code ***********************************************************************/ @@ -353,6 +367,7 @@ void hlr_vty_init(const struct log_info *cat) install_element(HLR_NODE, &cfg_ussd_no_route_pfx_cmd); install_element(HLR_NODE, &cfg_ussd_defaultroute_cmd); install_element(HLR_NODE, &cfg_ussd_no_defaultroute_cmd); + install_element(HLR_NODE, &cfg_ncss_guard_timeout_cmd); hlr_vty_subscriber_init(); } diff --git a/tests/test_nodes.vty b/tests/test_nodes.vty index e1f57a96..63d3da0b 100644 --- a/tests/test_nodes.vty +++ b/tests/test_nodes.vty @@ -78,6 +78,7 @@ OsmoHLR(config-hlr)# list no ussd route prefix PREFIX ussd default-route external EUSE no ussd default-route + ncss-guard-timeout <0-255> OsmoHLR(config-hlr)# gsup OsmoHLR(config-hlr-gsup)# list