From dcf515ffafd6765f852d7dc656e64e7c56b7d68b Mon Sep 17 00:00:00 2001 From: Konrad Hammel Date: Mon, 7 Mar 2011 11:36:18 -0500 Subject: [PATCH] freetdm: ss7 - bug fix for race condition on startup causing seg fault --- .../ftmod_sangoma_ss7_handle.c | 20 +++++++++++++++++++ .../ftmod_sangoma_ss7_main.c | 3 +++ 2 files changed, 23 insertions(+) diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_handle.c b/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_handle.c index 331312fafb..cb742ac4c9 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_handle.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_handle.c @@ -884,6 +884,12 @@ ftdm_status_t handle_sta_ind(uint32_t suInstId, uint32_t spInstId, uint32_t circ sngss7_chan_data_t *sngss7_info ; ftdm_channel_t *ftdmchan; + /* confirm that the circuit is active on our side otherwise move to the next circuit */ + if (!sngss7_test_flag(&g_ftdm_sngss7_data.cfg.isupCkt[circuit], SNGSS7_ACTIVE)) { + SS7_ERROR("[CIC:%d]Circuit is not active yet, skipping!\n",g_ftdm_sngss7_data.cfg.isupCkt[circuit].cic); + return FTDM_FAIL; + } + /* get the ftdmchan and ss7_chan_data from the circuit */ if (extract_chan_data(circuit, &sngss7_info, &ftdmchan)) { SS7_ERROR("Failed to extract channel data for circuit = %d!\n", circuit); @@ -1189,6 +1195,13 @@ ftdm_status_t handle_pause(uint32_t suInstId, uint32_t spInstId, uint32_t circui /* check that the infId matches and that this is not a siglink */ if ((g_ftdm_sngss7_data.cfg.isupCkt[i].infId == infId) && (g_ftdm_sngss7_data.cfg.isupCkt[i].type == VOICE)) { + + /* confirm that the circuit is active on our side otherwise move to the next circuit */ + if (!sngss7_test_flag(&g_ftdm_sngss7_data.cfg.isupCkt[i], SNGSS7_ACTIVE)) { + SS7_ERROR("[CIC:%d]Circuit is not active yet, skipping!\n",g_ftdm_sngss7_data.cfg.isupCkt[i].cic); + i++; + continue; + } /* get the ftdmchan and ss7_chan_data from the circuit */ if (extract_chan_data(i, &sngss7_info, &ftdmchan)) { @@ -1248,6 +1261,13 @@ ftdm_status_t handle_resume(uint32_t suInstId, uint32_t spInstId, uint32_t circu if ((g_ftdm_sngss7_data.cfg.isupCkt[i].infId == infId) && (g_ftdm_sngss7_data.cfg.isupCkt[i].type == VOICE)) { + /* confirm that the circuit is active on our side otherwise move to the next circuit */ + if (!sngss7_test_flag(&g_ftdm_sngss7_data.cfg.isupCkt[i], SNGSS7_ACTIVE)) { + SS7_ERROR("[CIC:%d]Circuit is not active yet, skipping!\n",g_ftdm_sngss7_data.cfg.isupCkt[i].cic); + i++; + continue; + } + /* get the ftdmchan and ss7_chan_data from the circuit */ if (extract_chan_data(i, &sngss7_info, &ftdmchan)) { SS7_ERROR("Failed to extract channel data for circuit = %d!\n", circuit); diff --git a/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_main.c b/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_main.c index 2f630fe462..10e73d3fbd 100644 --- a/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_main.c +++ b/libs/freetdm/src/ftmod/ftmod_sangoma_ss7/ftmod_sangoma_ss7_main.c @@ -1397,6 +1397,9 @@ static ftdm_status_t ftdm_sangoma_ss7_start(ftdm_span_t * span) /* lock the channel */ ftdm_mutex_lock(ftdmchan->mutex); + /* flag the circuit as active */ + sngss7_set_flag(sngss7_info->circuit, SNGSS7_ACTIVE); + /* check if the interface is paused or resumed */ if (sngss7_test_flag(sngss7_intf, SNGSS7_PAUSED)) { SS7_DEBUG_CHAN(ftdmchan, "ISUP intf %d is PAUSED\n", sngss7_intf->id);