freetdm: set proper flags when a given layer (ISUP, MTP3 etc) is started

and verify such flags on shutdown to avoid segfault when shutting down
         a layer that was never started - fix issue #741
This commit is contained in:
Moises Silva 2011-06-13 17:33:41 -04:00
parent 401cef7479
commit c23c3d8730
5 changed files with 58 additions and 35 deletions

View File

@ -99,17 +99,18 @@ int ft_to_sngss7_cfg_all(void)
return 1; return 1;
} else { } else {
SS7_INFO("Started Stack Manager!\n"); SS7_INFO("Started Stack Manager!\n");
sngss7_set_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_SM); sngss7_set_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_SM_STARTED);
} }
/* check if the configuration had a Relay Channel */ /* check if the configuration had a Relay Channel */
if (sngss7_test_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_RY)) { if (sngss7_test_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_RY_PRESENT)) {
/* start up the relay task */ /* start up the relay task */
if (sng_isup_init_relay()) { if (sng_isup_init_relay()) {
SS7_CRITICAL("Failed to start Relay\n"); SS7_CRITICAL("Failed to start Relay\n");
return 1; return 1;
} else { } else {
SS7_INFO("Started Relay!\n"); SS7_INFO("Started Relay!\n");
sngss7_set_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_RY_STARTED);
} }
/* run general configuration on the relay task */ /* run general configuration on the relay task */
@ -122,12 +123,13 @@ int ft_to_sngss7_cfg_all(void)
} /* if (sngss7_test_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_RY)) */ } /* if (sngss7_test_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_RY)) */
if (sngss7_test_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_CC)) { if (sngss7_test_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_CC_PRESENT)) {
if (sng_isup_init_cc()) { if (sng_isup_init_cc()) {
SS7_CRITICAL("Failed to start Call-Control\n"); SS7_CRITICAL("Failed to start Call-Control\n");
return 1; return 1;
} else { } else {
SS7_INFO("Started Call-Control!\n"); SS7_INFO("Started Call-Control!\n");
sngss7_set_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_CC_STARTED);
} }
if (ftmod_ss7_cc_gen_config()) { if (ftmod_ss7_cc_gen_config()) {
SS7_CRITICAL("CC General configuration FAILED!\n"); SS7_CRITICAL("CC General configuration FAILED!\n");
@ -143,12 +145,13 @@ int ft_to_sngss7_cfg_all(void)
} }
} /* if (sngss7_test_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_CC)) */ } /* if (sngss7_test_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_CC)) */
if (sngss7_test_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_ISUP)) { if (sngss7_test_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_ISUP_PRESENT)) {
if (sng_isup_init_isup()) { if (sng_isup_init_isup()) {
SS7_CRITICAL("Failed to start ISUP\n"); SS7_CRITICAL("Failed to start ISUP\n");
return 1; return 1;
} else { } else {
SS7_INFO("Started ISUP!\n"); SS7_INFO("Started ISUP!\n");
sngss7_set_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_ISUP_STARTED);
} }
if (ftmod_ss7_isup_gen_config()) { if (ftmod_ss7_isup_gen_config()) {
SS7_CRITICAL("ISUP General configuration FAILED!\n"); SS7_CRITICAL("ISUP General configuration FAILED!\n");
@ -158,12 +161,13 @@ int ft_to_sngss7_cfg_all(void)
} }
} /* if (sngss7_test_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_ISUP)) */ } /* if (sngss7_test_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_ISUP)) */
if (sngss7_test_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_MTP3)) { if (sngss7_test_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_MTP3_PRESENT)) {
if (sng_isup_init_mtp3()) { if (sng_isup_init_mtp3()) {
SS7_CRITICAL("Failed to start MTP3\n"); SS7_CRITICAL("Failed to start MTP3\n");
return 1; return 1;
} else { } else {
SS7_INFO("Started MTP3!\n"); SS7_INFO("Started MTP3!\n");
sngss7_set_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_MTP3_STARTED);
} }
if (ftmod_ss7_mtp3_gen_config()) { if (ftmod_ss7_mtp3_gen_config()) {
@ -174,18 +178,20 @@ int ft_to_sngss7_cfg_all(void)
} }
} /* if (sngss7_test_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_MTP3)) */ } /* if (sngss7_test_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_MTP3)) */
if (sngss7_test_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_MTP2)) { if (sngss7_test_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_MTP2_PRESENT)) {
if (sng_isup_init_mtp2()) { if (sng_isup_init_mtp2()) {
SS7_CRITICAL("Failed to start MTP2\n"); SS7_CRITICAL("Failed to start MTP2\n");
return 1; return 1;
} else { } else {
SS7_INFO("Started MTP2!\n"); SS7_INFO("Started MTP2!\n");
sngss7_set_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_MTP2_STARTED);
} }
if (sng_isup_init_mtp1()) { if (sng_isup_init_mtp1()) {
SS7_CRITICAL("Failed to start MTP2\n"); SS7_CRITICAL("Failed to start MTP1\n");
return 1; return 1;
} else { } else {
SS7_INFO("Started MTP1!\n"); SS7_INFO("Started MTP1!\n");
sngss7_set_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_MTP1_STARTED);
} }
if (ftmod_ss7_mtp1_gen_config()) { if (ftmod_ss7_mtp1_gen_config()) {
SS7_CRITICAL("MTP1 General configuration FAILED!\n"); SS7_CRITICAL("MTP1 General configuration FAILED!\n");
@ -376,7 +382,7 @@ int ft_to_sngss7_cfg_all(void)
x++; x++;
} /* while (x < (MAX_ISAPS)) */ } /* while (x < (MAX_ISAPS)) */
if (sngss7_test_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_ISUP)) { if (sngss7_test_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_ISUP_STARTED)) {
x = 1; x = 1;
while (x < (MAX_ISUP_INFS)) { while (x < (MAX_ISUP_INFS)) {
/* check if this link has been configured already */ /* check if this link has been configured already */

View File

@ -1621,32 +1621,36 @@ static FIO_SIG_UNLOAD_FUNCTION(ftdm_sangoma_ss7_unload)
ftdm_log (FTDM_LOG_INFO, "Starting ftmod_sangoma_ss7 unload...\n"); ftdm_log (FTDM_LOG_INFO, "Starting ftmod_sangoma_ss7 unload...\n");
if (sngss7_test_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_CC)) { if (sngss7_test_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_CC_STARTED)) {
sng_isup_free_cc(); sng_isup_free_cc();
sngss7_clear_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_CC); sngss7_clear_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_CC_STARTED);
} }
if (sngss7_test_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_ISUP)) { if (sngss7_test_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_ISUP_STARTED)) {
ftmod_ss7_shutdown_isup(); ftmod_ss7_shutdown_isup();
sng_isup_free_isup(); sng_isup_free_isup();
sngss7_clear_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_ISUP); sngss7_clear_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_ISUP_STARTED);
} }
if (sngss7_test_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_MTP3)) { if (sngss7_test_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_MTP3_STARTED)) {
ftmod_ss7_shutdown_mtp3(); ftmod_ss7_shutdown_mtp3();
sng_isup_free_mtp3(); sng_isup_free_mtp3();
sngss7_clear_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_MTP3); sngss7_clear_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_MTP3_STARTED);
} }
if (sngss7_test_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_MTP2)) { if (sngss7_test_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_MTP2_STARTED)) {
ftmod_ss7_shutdown_mtp2(); ftmod_ss7_shutdown_mtp2();
sng_isup_free_mtp2(); sng_isup_free_mtp2();
sng_isup_free_mtp1(); sngss7_clear_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_MTP2_STARTED);
sngss7_clear_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_MTP2);
} }
if (sngss7_test_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_RY)) { if (sngss7_test_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_MTP1_STARTED)) {
/* go through all the relays channels and configure it */ sng_isup_free_mtp1();
sngss7_clear_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_MTP1_STARTED);
}
if (sngss7_test_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_RY_STARTED)) {
/* go through all the relays channels and disable them */
x = 1; x = 1;
while (x < (MAX_RELAY_CHANNELS)) { while (x < (MAX_RELAY_CHANNELS)) {
/* check if this relay channel has been configured already */ /* check if this relay channel has been configured already */
@ -1668,11 +1672,12 @@ static FIO_SIG_UNLOAD_FUNCTION(ftdm_sangoma_ss7_unload)
ftmod_ss7_shutdown_relay(); ftmod_ss7_shutdown_relay();
sng_isup_free_relay(); sng_isup_free_relay();
sngss7_clear_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_RY); sngss7_clear_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_RY_STARTED);
} }
if (sngss7_test_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_SM)) { if (sngss7_test_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_SM_STARTED)) {
sng_isup_free_sm(); sng_isup_free_sm();
sngss7_clear_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_SM_STARTED);
} }
sng_isup_free_gen(); sng_isup_free_gen();

View File

@ -632,13 +632,25 @@ typedef enum {
} sng_cfg_flag_t; } sng_cfg_flag_t;
typedef enum { typedef enum {
SNGSS7_SM = (1 << 0), SNGSS7_SM_STARTED = (1 << 0),
SNGSS7_RY = (1 << 1),
SNGSS7_MTP1 = (1 << 2), SNGSS7_RY_PRESENT = (1 << 2),
SNGSS7_MTP2 = (1 << 3), SNGSS7_RY_STARTED = (1 << 3),
SNGSS7_MTP3 = (1 << 4),
SNGSS7_ISUP = (1 << 5), SNGSS7_MTP1_PRESENT = (1 << 4),
SNGSS7_CC = (1 << 6) SNGSS7_MTP1_STARTED = (1 << 5),
SNGSS7_MTP2_PRESENT = (1 << 6),
SNGSS7_MTP2_STARTED = (1 << 7),
SNGSS7_MTP3_PRESENT = (1 << 8),
SNGSS7_MTP3_STARTED = (1 << 9),
SNGSS7_ISUP_PRESENT = (1 << 10),
SNGSS7_ISUP_STARTED = (1 << 11),
SNGSS7_CC_PRESENT = (1 << 12),
SNGSS7_CC_STARTED = (1 << 13),
} sng_task_flag_t; } sng_task_flag_t;
/******************************************************************************/ /******************************************************************************/

View File

@ -300,7 +300,7 @@ ftdm_status_t disable_all_sigs_for_relay(uint32_t procId)
ftdm_status_t disble_all_mtp2_sigs_for_relay(void) ftdm_status_t disble_all_mtp2_sigs_for_relay(void)
{ {
/* check if there is a local mtp2 link*/ /* check if there is a local mtp2 link*/
if (sngss7_test_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_MTP2)) { if (sngss7_test_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_MTP2_STARTED)) {
SS7_INFO("Disalbing all mtp2 sig links on local system\n"); SS7_INFO("Disalbing all mtp2 sig links on local system\n");
ftmod_ss7_disable_grp_mtp2Link(1); ftmod_ss7_disable_grp_mtp2Link(1);

View File

@ -2082,7 +2082,7 @@ static int ftmod_ss7_fill_in_relay_channel(sng_relay_t *relay_channel)
relay_channel->port, relay_channel->port,
relay_channel->procId, relay_channel->procId,
relay_channel->id); relay_channel->id);
sngss7_set_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_RY); sngss7_set_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_RY_PRESENT);
} else { } else {
relay_channel->id = i; relay_channel->id = i;
SS7_DEBUG("found existing relay channel on type:%d, hostname:%s, port:%d, procId:%d, id = %d\n", SS7_DEBUG("found existing relay channel on type:%d, hostname:%s, port:%d, procId:%d, id = %d\n",
@ -2116,7 +2116,7 @@ static int ftmod_ss7_fill_in_mtp1_link(sng_mtp1_link_t *mtp1Link)
/* check if this id value has been used already */ /* check if this id value has been used already */
if (g_ftdm_sngss7_data.cfg.mtp1Link[i].id == 0) { if (g_ftdm_sngss7_data.cfg.mtp1Link[i].id == 0) {
SS7_DEBUG("Found new MTP1 Link: id=%d, name=%s\n", mtp1Link->id, mtp1Link->name); SS7_DEBUG("Found new MTP1 Link: id=%d, name=%s\n", mtp1Link->id, mtp1Link->name);
sngss7_set_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_MTP1); sngss7_set_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_MTP1_PRESENT);
} else { } else {
SS7_DEBUG("Found an existing MTP1 Link: id=%d, name=%s (old name=%s)\n", SS7_DEBUG("Found an existing MTP1 Link: id=%d, name=%s (old name=%s)\n",
mtp1Link->id, mtp1Link->id,
@ -2142,7 +2142,7 @@ static int ftmod_ss7_fill_in_mtp2_link(sng_mtp2_link_t *mtp2Link)
/* check if this id value has been used already */ /* check if this id value has been used already */
if (g_ftdm_sngss7_data.cfg.mtp2Link[i].id == 0) { if (g_ftdm_sngss7_data.cfg.mtp2Link[i].id == 0) {
SS7_DEBUG("Found new MTP2 Link: id=%d, name=%s\n", mtp2Link->id, mtp2Link->name); SS7_DEBUG("Found new MTP2 Link: id=%d, name=%s\n", mtp2Link->id, mtp2Link->name);
sngss7_set_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_MTP2); sngss7_set_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_MTP2_PRESENT);
} else { } else {
SS7_DEBUG("Found an existing MTP2 Link: id=%d, name=%s (old name=%s)\n", SS7_DEBUG("Found an existing MTP2 Link: id=%d, name=%s (old name=%s)\n",
mtp2Link->id, mtp2Link->id,
@ -2219,7 +2219,7 @@ static int ftmod_ss7_fill_in_mtp3_link(sng_mtp3_link_t *mtp3Link)
/* check if this id value has been used already */ /* check if this id value has been used already */
if (g_ftdm_sngss7_data.cfg.mtp3Link[i].id == 0) { if (g_ftdm_sngss7_data.cfg.mtp3Link[i].id == 0) {
SS7_DEBUG("Found new MTP3 Link: id=%d, name=%s\n", mtp3Link->id, mtp3Link->name); SS7_DEBUG("Found new MTP3 Link: id=%d, name=%s\n", mtp3Link->id, mtp3Link->name);
sngss7_set_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_MTP3); sngss7_set_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_MTP3_PRESENT);
} else { } else {
SS7_DEBUG("Found an existing MTP3 Link: id=%d, name=%s (old name=%s)\n", SS7_DEBUG("Found an existing MTP3 Link: id=%d, name=%s (old name=%s)\n",
mtp3Link->id, mtp3Link->id,
@ -2560,7 +2560,7 @@ static int ftmod_ss7_fill_in_isup_interface(sng_isup_inf_t *sng_isup)
/* check if this id value has been used already */ /* check if this id value has been used already */
if (g_ftdm_sngss7_data.cfg.isupIntf[i].id == 0) { if (g_ftdm_sngss7_data.cfg.isupIntf[i].id == 0) {
SS7_DEBUG("Found new ISUP Interface: id=%d, name=%s\n", sng_isup->id, sng_isup->name); SS7_DEBUG("Found new ISUP Interface: id=%d, name=%s\n", sng_isup->id, sng_isup->name);
sngss7_set_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_ISUP); sngss7_set_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_ISUP_PRESENT);
} else { } else {
SS7_DEBUG("Found an existing ISUP Interface: id=%d, name=%s (old name=%s)\n", SS7_DEBUG("Found an existing ISUP Interface: id=%d, name=%s (old name=%s)\n",
sng_isup->id, sng_isup->id,
@ -2908,7 +2908,7 @@ static int ftmod_ss7_fill_in_ccSpan(sng_ccSpan_t *ccSpan)
g_ftdm_sngss7_data.cfg.isupCkt[x].type = VOICE; g_ftdm_sngss7_data.cfg.isupCkt[x].type = VOICE;
/* throw the flag to indicate that we need to start call control */ /* throw the flag to indicate that we need to start call control */
sngss7_set_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_CC); sngss7_set_flag(&g_ftdm_sngss7_data.cfg, SNGSS7_CC_PRESENT);
} }
if (timeslot.channel) { if (timeslot.channel) {