From e7acd4d138e0faa6b4a3cec1667015c430e8f3f6 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 21 Feb 2011 20:17:58 -0600 Subject: [PATCH] FS-3054 re-open if this does not fix it. --- .../endpoints/mod_dingaling/mod_dingaling.c | 6 ++-- src/mod/endpoints/mod_sofia/mod_sofia.c | 35 ++++++++++++++++--- src/switch_nat.c | 6 ++-- 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/src/mod/endpoints/mod_dingaling/mod_dingaling.c b/src/mod/endpoints/mod_dingaling/mod_dingaling.c index 9fb1f39e11..f9f0788c93 100644 --- a/src/mod/endpoints/mod_dingaling/mod_dingaling.c +++ b/src/mod/endpoints/mod_dingaling/mod_dingaling.c @@ -596,9 +596,9 @@ static void ipchanged_event_handler(switch_event_t *event) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "EVENT_TRAP: IP change detected\n"); - if (cond && !strcmp(cond, "network-address-change")) { - const char *old_ip4 = switch_event_get_header_nil(event, "network-address-previous-v4"); - const char *new_ip4 = switch_event_get_header_nil(event, "network-address-change-v4"); + if (cond && !strcmp(cond, "network-external-address-change")) { + const char *old_ip4 = switch_event_get_header_nil(event, "network-external-address-previous-v4"); + const char *new_ip4 = switch_event_get_header_nil(event, "network-external-address-change-v4"); switch_hash_index_t *hi; void *val; char *tmp; diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index 7125bceb7c..dff33ee6f5 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -4587,17 +4587,42 @@ static void general_event_handler(switch_event_t *event) case SWITCH_EVENT_TRAP: { const char *cond = switch_event_get_header(event, "condition"); + switch_hash_index_t *hi; + const void *var; + void *val; + sofia_profile_t *profile; + if (zstr(cond)) { + cond = ""; + } - if (cond && !strcmp(cond, "network-address-change") && mod_sofia_globals.auto_restart) { + if (!strcmp(cond, "network-external-address-change") && mod_sofia_globals.auto_restart) { + const char *old_ip4 = switch_event_get_header_nil(event, "network-external-address-previous-v4"); + const char *new_ip4 = switch_event_get_header_nil(event, "network-external-address-change-v4"); + + switch_mutex_lock(mod_sofia_globals.hash_mutex); + if (mod_sofia_globals.profile_hash) { + for (hi = switch_hash_first(NULL, mod_sofia_globals.profile_hash); hi; hi = switch_hash_next(hi)) { + switch_hash_this(hi, &var, NULL, &val); + + if ((profile = (sofia_profile_t *) val)) { + if (!strcmp(profile->extsipip, old_ip4)) { + profile->extsipip = switch_core_strdup(profile->pool, new_ip4); + } + + if (!strcmp(profile->extrtpip, old_ip4)) { + profile->extrtpip = switch_core_strdup(profile->pool, new_ip4); + } + } + } + } + switch_mutex_unlock(mod_sofia_globals.hash_mutex); + sofia_glue_restart_all_profiles(); + } else if (!strcmp(cond, "network-address-change") && mod_sofia_globals.auto_restart) { const char *old_ip4 = switch_event_get_header_nil(event, "network-address-previous-v4"); const char *new_ip4 = switch_event_get_header_nil(event, "network-address-change-v4"); const char *old_ip6 = switch_event_get_header_nil(event, "network-address-previous-v6"); const char *new_ip6 = switch_event_get_header_nil(event, "network-address-change-v6"); - switch_hash_index_t *hi; - const void *var; - void *val; - sofia_profile_t *profile; switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "EVENT_TRAP: IP change detected\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "IP change detected [%s]->[%s] [%s]->[%s]\n", old_ip4, new_ip4, old_ip6, new_ip6); diff --git a/src/switch_nat.c b/src/switch_nat.c index 85b0247d6d..d9110efe18 100644 --- a/src/switch_nat.c +++ b/src/switch_nat.c @@ -325,9 +325,9 @@ static void *SWITCH_THREAD_FUNC switch_nat_multicast_runtime(switch_thread_t * t do_repub = SWITCH_TRUE; switch_event_create(&event, SWITCH_EVENT_TRAP); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "condition", "network-address-change"); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "network-address-previous-v4", nat_globals.pub_addr); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "network-address-change-v4", newip); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "condition", "network-external-address-change"); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "network-external-address-previous-v4", nat_globals.pub_addr); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "network-external-address-change-v4", newip); switch_event_fire(&event); switch_set_string(nat_globals.pub_addr, newip);