Module: kamailio Branch: master Commit: 785ede5bacfe55e88381ae8f7d672b24ec4b8cf6 URL: https://github.com/kamailio/kamailio/commit/785ede5bacfe55e88381ae8f7d672b24ec4b8cf6
Author: Daniel-Constantin Mierla <mico...@gmail.com> Committer: Daniel-Constantin Mierla <mico...@gmail.com> Date: 2018-12-28T09:56:26+01:00 rtpengine: use version number to track building rtpengine sockets on reload - check on list size fails if same list is reloaded with different attributes - reload command has a safe interval of 10 seconds between executions to allow building internal list of sockets --- Modified: src/modules/rtpengine/rtpengine.c --- Diff: https://github.com/kamailio/kamailio/commit/785ede5bacfe55e88381ae8f7d672b24ec4b8cf6.diff Patch: https://github.com/kamailio/kamailio/commit/785ede5bacfe55e88381ae8f7d672b24ec4b8cf6.patch --- diff --git a/src/modules/rtpengine/rtpengine.c b/src/modules/rtpengine/rtpengine.c index 46a55e6669..484ce05f35 100644 --- a/src/modules/rtpengine/rtpengine.c +++ b/src/modules/rtpengine/rtpengine.c @@ -169,6 +169,16 @@ struct minmax_stats_vals { long long avg_samples; /* our own running count to average the averages */ }; +#define RTPE_LIST_VERSION_DELAY 10 + +typedef struct rtpe_list_version { + int vernum; + time_t vertime; +} rtpe_list_version_t; + +static rtpe_list_version_t *_rtpe_list_version = NULL; +static int _rtpe_list_vernum_local = 0; + static char *gencookie(); static int rtpp_test(struct rtpp_node*, int, int); static int start_recording_f(struct sip_msg *, char *, char *); @@ -283,7 +293,6 @@ static struct minmax_mos_label_stats global_mos_stats, int got_any_mos_pvs; - static cmd_export_t cmds[] = { {"set_rtpengine_set", (cmd_function)set_rtpengine_set_f, 1, fixup_set_id, 0, @@ -1169,16 +1178,26 @@ static int rtpp_test_ping(struct rtpp_node *node) static void rtpengine_rpc_reload(rpc_t* rpc, void* ctx) { + time_t tnow; + if (rtpp_db_url.s == NULL) { // no database rpc->fault(ctx, 500, "No Database URL"); return; } + if(!sr_instance_ready()) { rpc->fault(ctx, 500, "Initializing - try later"); return; } + tnow = time(NULL); + if(tnow - _rtpe_list_version->vertime < RTPE_LIST_VERSION_DELAY) { + rpc->fault(ctx, 500, "Too short reload interval - try later"); + return; + } + _rtpe_list_version->vertime = tnow; + if (init_rtpproxy_db() < 0) { // fail reloading from database rpc->fault(ctx, 500, "Failed reloading db"); @@ -1186,9 +1205,15 @@ static void rtpengine_rpc_reload(rpc_t* rpc, void* ctx) } if (build_rtpp_socks(1, 1)) { - rpc->fault(ctx, 500, "Out of memory"); + rpc->fault(ctx, 500, "Failed to build rtpengine sockets"); return; } + + _rtpe_list_version->vernum += 1; + _rtpe_list_version->vertime = time(NULL); + LM_DBG("current rtpengines list version: %d (%u)\n", + _rtpe_list_version->vernum, + (unsigned int)_rtpe_list_version->vertime); } static int rtpengine_rpc_iterate(rpc_t* rpc, void* ctx, const str *rtpp_url, @@ -1473,6 +1498,14 @@ mod_init(void) unsigned short avp_flags; str s; + _rtpe_list_version = (rtpe_list_version_t*)shm_mallocxz(sizeof(rtpe_list_version_t)); + if(_rtpe_list_version==NULL) { + LM_ERR("no more shm memory for rtpe list version\n"); + return -1; + } + _rtpe_list_version->vernum = 1; + _rtpe_list_version->vertime = time(NULL); + if(rtpengine_rpc_init()<0) { LM_ERR("failed to register RPC commands\n"); @@ -1666,13 +1699,15 @@ static int build_rtpp_socks(int lmode, int rtest) { int ip_mtu_discover = IP_PMTUDISC_DONT; #endif + if(_rtpe_list_vernum_local == _rtpe_list_version->vernum) { + /* same version for the list of rtpengines */ + return 0; + } + rtpe_reload_lock_get(rtpp_no_lock); current_rtpp_no = *rtpp_no; rtpe_reload_lock_release(rtpp_no_lock); - if (current_rtpp_no == rtpp_socks_size) - return 0; - // close current sockets for (i = 0; i < rtpp_socks_size; i++) { if (rtpp_socks[i] >= 0) { @@ -1690,6 +1725,7 @@ static int build_rtpp_socks(int lmode, int rtest) { memset(rtpp_socks, -1, sizeof(int)*(rtpp_socks_size)); rtpe_reload_lock_get(rtpp_set_list->rset_head_lock); + _rtpe_list_vernum_local = _rtpe_list_version->vernum; for (rtpp_list = rtpp_set_list->rset_first; rtpp_list != 0; rtpp_list = rtpp_list->rset_next) { @@ -1948,6 +1984,10 @@ static void mod_destroy(void) } else { LM_DBG("rtpengine_hash_table_destroy() success!\n"); } + if(_rtpe_list_version!=NULL) { + shm_free(_rtpe_list_version); + _rtpe_list_version = NULL; + } } _______________________________________________ Kamailio (SER) - Development Mailing List sr-dev@lists.kamailio.org https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev