[Freeswitch-svn] [commit] r11428 - in freeswitch/trunk/src: . mod/endpoints/mod_sofia

FreeSWITCH SVN anthm at freeswitch.org
Thu Jan 22 15:07:31 PST 2009


Author: anthm
Date: Thu Jan 22 17:07:31 2009
New Revision: 11428

Log:
only auto-restart if the binded ip changes

Modified:
   freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c
   freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h
   freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c
   freeswitch/trunk/src/switch_core.c

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c	Thu Jan 22 17:07:31 2009
@@ -2756,6 +2756,48 @@
 			const char *cond = switch_event_get_header(event, "condition");
 
 			if (cond && !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, "IP change detected [%s]->[%s] [%s]->[%s]\n", old_ip4, new_ip4, old_ip6, new_ip6);
+
+				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)) {
+						int rb = 0;
+						switch_hash_this(hi, &var, NULL, &val);
+						if ((profile = (sofia_profile_t *) val) && profile->auto_restart) {
+							if (!strcmp(profile->sipip, old_ip4)) {
+								profile->sipip = switch_core_strdup(profile->pool, new_ip4);
+								rb++;
+							}
+							if (!strcmp(profile->rtpip, old_ip4)) {
+								profile->rtpip = switch_core_strdup(profile->pool, new_ip4);
+								rb++;
+							}
+							if (!strcmp(profile->sipip, old_ip6)) {
+								profile->sipip = switch_core_strdup(profile->pool, new_ip6);
+								rb++;
+							}
+							if (!strcmp(profile->rtpip, old_ip6)) {
+								profile->rtpip = switch_core_strdup(profile->pool, new_ip6);
+								rb++;
+							}
+
+							if (rb) {
+								sofia_set_pflag_locked(profile, PFLAG_RESPAWN);
+								sofia_clear_pflag_locked(profile, PFLAG_RUNNING);
+							}
+						}
+					}
+				}
+
 				sofia_glue_restart_all_profiles();
 			}
 			

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h	Thu Jan 22 17:07:31 2009
@@ -384,6 +384,7 @@
 	char *presence_hosts;
 	char *challenge_realm;
 	sofia_dtmf_t dtmf_type;
+	int auto_restart;
 	int sip_port;
 	int tls_sip_port;
 	int tls_version;

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c	Thu Jan 22 17:07:31 2009
@@ -1279,6 +1279,8 @@
 						parse_rtp_bugs(profile, val);
 					} else if (!strcasecmp(var, "user-agent-string")) { 
 						profile->user_agent = switch_core_strdup(profile->pool, val);
+					} else if (!strcasecmp(var, "auto-restart")) {
+						profile->auto_restart = switch_true(val);
 					} else if (!strcasecmp(var, "dtmf-type")) {
 						if (!strcasecmp(val, "rfc2833")) {
 							profile->dtmf_type = DTMF_2833;
@@ -1688,7 +1690,8 @@
 				profile->rport_level = 1;
 				profile->pflags |= PFLAG_STUN_ENABLED;
 				profile->pflags |= PFLAG_DISABLE_100REL;
-				
+				profile->auto_restart = 1;
+
 				for (param = switch_xml_child(settings, "param"); param; param = param->next) {
 					char *var = (char *) switch_xml_attr_soft(param, "name");
 					char *val = (char *) switch_xml_attr_soft(param, "value");
@@ -1711,6 +1714,8 @@
 #endif
 					} else if (!strcasecmp(var, "user-agent-string")) {
 						profile->user_agent = switch_core_strdup(profile->pool, val);
+					} else if (!strcasecmp(var, "auto-restart")) {
+						profile->auto_restart = switch_true(val);
 					} else if (!strcasecmp(var, "dtmf-type")) {
 						if (!strcasecmp(val, "rfc2833")) {
 							profile->dtmf_type = DTMF_2833;

Modified: freeswitch/trunk/src/switch_core.c
==============================================================================
--- freeswitch/trunk/src/switch_core.c	(original)
+++ freeswitch/trunk/src/switch_core.c	Thu Jan 22 17:07:31 2009
@@ -85,6 +85,8 @@
 static void check_ip(void) {
 	char guess_ip4[256] = "";
 	char guess_ip6[256] = "";
+	char old_ip4[256] = "";
+	char old_ip6[256] = "";
 	int ok4 = 1, ok6 = 1;
 	
 	switch_find_local_ip(guess_ip4, sizeof(guess_ip4), AF_INET);
@@ -94,6 +96,7 @@
 		switch_set_string(main_ip4, guess_ip4);
 	} else {
 		if (!(ok4 = !strcmp(main_ip4, guess_ip4))) {
+			switch_set_string(old_ip4, main_ip4);
 			switch_set_string(main_ip4, guess_ip4);
 			switch_core_set_variable("local_ip_v4", guess_ip4);
 		}
@@ -103,6 +106,7 @@
 		switch_set_string(main_ip6, guess_ip6);
 	} else {
 		if (!(ok6 = !strcmp(main_ip6, guess_ip6))) {
+			switch_set_string(old_ip6, main_ip6);
 			switch_set_string(main_ip6, guess_ip6);
 			switch_core_set_variable("local_ip_v6", guess_ip6);
 		}
@@ -114,9 +118,11 @@
 		if (switch_event_create(&event, SWITCH_EVENT_TRAP) == SWITCH_STATUS_SUCCESS) {
 			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "condition", "network-address-change");
 			if (!ok4) {
+				switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "network-address-previous-v4", old_ip4);
 				switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "network-address-change-v4", main_ip4);
 			}
 			if (!ok6) {
+				switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "network-address-previous-v6", old_ip6);
 				switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "network-address-change-v6", main_ip6);
 			}
 			switch_event_fire(&event);



More information about the Freeswitch-svn mailing list