mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-07-24 05:02:10 +00:00
LOOK OUT BELOW... (FSCORE-381)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@14055 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
@@ -31,6 +31,7 @@
|
||||
* Bret McDanel <trixter AT 0xdecafbad.com>
|
||||
* Cesar Cepeda <cesar@auronix.com>
|
||||
* Massimo Cetra <devel@navynet.it>
|
||||
* Rupa Schomaker <rupa@rupa.com>
|
||||
*
|
||||
*
|
||||
* mod_commands.c -- Misc. Command Module
|
||||
@@ -47,9 +48,11 @@ SWITCH_MODULE_DEFINITION(mod_commands, mod_commands_load, mod_commands_shutdown,
|
||||
SWITCH_STANDARD_API(nat_map_function)
|
||||
{
|
||||
int argc;
|
||||
char *mydata = NULL, *argv[4];
|
||||
char *mydata = NULL, *argv[5];
|
||||
switch_nat_ip_proto_t proto = SWITCH_NAT_UDP;
|
||||
switch_port_t external_port = 0;
|
||||
char *tmp = NULL;
|
||||
switch_bool_t sticky = SWITCH_FALSE;
|
||||
|
||||
if (!cmd) {
|
||||
goto error;
|
||||
@@ -60,6 +63,27 @@ SWITCH_STANDARD_API(nat_map_function)
|
||||
|
||||
argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
|
||||
|
||||
if (argc < 1) {
|
||||
goto error;
|
||||
}
|
||||
if (argv[0] && switch_stristr("status", argv[0])) {
|
||||
tmp = switch_nat_status();
|
||||
stream->write_function(stream, tmp);
|
||||
switch_safe_free(tmp);
|
||||
goto ok;
|
||||
} else if (argv[0] && switch_stristr("republish", argv[0])) {
|
||||
switch_nat_republish();
|
||||
stream->write_function(stream, "true");
|
||||
goto ok;
|
||||
} else if (argv[0] && switch_stristr("reinit", argv[0])) {
|
||||
switch_nat_reinit();
|
||||
stream->write_function(stream, "true");
|
||||
tmp = switch_nat_status();
|
||||
stream->write_function(stream, tmp);
|
||||
switch_safe_free(tmp);
|
||||
goto ok;
|
||||
}
|
||||
|
||||
if (argc < 3) {
|
||||
goto error;
|
||||
}
|
||||
@@ -69,9 +93,13 @@ SWITCH_STANDARD_API(nat_map_function)
|
||||
} else if (argv[2] && switch_stristr("udp", argv[2])) {
|
||||
proto = SWITCH_NAT_UDP;
|
||||
}
|
||||
|
||||
if (argv[3] && switch_stristr("sticky", argv[3])) {
|
||||
sticky = SWITCH_TRUE;
|
||||
}
|
||||
|
||||
if (argv[0] && switch_stristr("add", argv[0])) {
|
||||
if (switch_nat_add_mapping((switch_port_t)atoi(argv[1]), proto, &external_port) == SWITCH_STATUS_SUCCESS) {
|
||||
if (switch_nat_add_mapping((switch_port_t)atoi(argv[1]), proto, &external_port, sticky) == SWITCH_STATUS_SUCCESS) {
|
||||
stream->write_function(stream, "%d", (int)external_port);
|
||||
goto ok;
|
||||
}
|
||||
@@ -2700,7 +2728,7 @@ SWITCH_STANDARD_API(alias_function)
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
#define SHOW_SYNTAX "codec|endpoint|application|api|dialplan|file|timer|calls [count]|channels [count]|distinct_channels|aliases|complete|chat|endpoint|management|modules|say|interfaces|interface_types"
|
||||
#define SHOW_SYNTAX "codec|endpoint|application|api|dialplan|file|timer|calls [count]|channels [count]|distinct_channels|aliases|complete|chat|endpoint|management|modules|nat_map|say|interfaces|interface_types"
|
||||
SWITCH_STANDARD_API(show_function)
|
||||
{
|
||||
char sql[1024];
|
||||
@@ -2844,6 +2872,18 @@ SWITCH_STANDARD_API(show_function)
|
||||
} else {
|
||||
switch_snprintf(sql, sizeof(sql) - 1, "select name, syntax, description, key from interfaces where type = 'api' order by name");
|
||||
}
|
||||
} else if (!strcasecmp(command, "nat_map")) {
|
||||
switch_snprintf(sql, sizeof(sql) - 1,
|
||||
"SELECT port, "
|
||||
" CASE proto "
|
||||
" WHEN 0 THEN 'udp' "
|
||||
" WHEN 1 THEN 'tcp' "
|
||||
" ELSE 'unknown' "
|
||||
" END AS proto, "
|
||||
" proto AS proto_num, "
|
||||
" sticky "
|
||||
" FROM nat ORDER BY port, proto"
|
||||
);
|
||||
} else {
|
||||
stream->write_function(stream, "-USAGE: %s\n", SHOW_SYNTAX);
|
||||
goto end;
|
||||
@@ -2900,6 +2940,7 @@ SWITCH_STANDARD_API(show_function)
|
||||
|
||||
switch_xml_set_attr(switch_xml_set_flag(holder.xml, SWITCH_XML_DUP), strdup("row_count"), strdup(count));
|
||||
xmlstr = switch_xml_toxml(holder.xml, SWITCH_FALSE);
|
||||
switch_xml_free(holder.xml);
|
||||
|
||||
if (xmlstr) {
|
||||
holder.stream->write_function(holder.stream, "%s", xmlstr);
|
||||
@@ -3537,7 +3578,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load)
|
||||
SWITCH_ADD_API(commands_api_interface, "stun", "stun", stun_function, "<stun_server>[:port]");
|
||||
SWITCH_ADD_API(commands_api_interface, "system", "Execute a system command", system_function, SYSTEM_SYNTAX);
|
||||
SWITCH_ADD_API(commands_api_interface, "time_test", "time_test", time_test_function, "<mss>");
|
||||
SWITCH_ADD_API(commands_api_interface, "nat_map", "nat_map", nat_map_function, "[add|del] <port> [tcp|udp]");
|
||||
SWITCH_ADD_API(commands_api_interface, "nat_map", "nat_map", nat_map_function, "[status|republish|reinit] | [add|del] <port> [tcp|udp] [static]");
|
||||
|
||||
/* indicate that the module should continue to be loaded */
|
||||
return SWITCH_STATUS_NOUNLOAD;
|
||||
|
||||
@@ -578,6 +578,34 @@ static void roster_event_handler(switch_event_t *event)
|
||||
|
||||
}
|
||||
|
||||
static void ipchanged_event_handler(switch_event_t *event)
|
||||
{
|
||||
const char *cond = switch_event_get_header(event, "condition");
|
||||
|
||||
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");
|
||||
switch_hash_index_t *hi;
|
||||
void *val;
|
||||
char *tmp;
|
||||
mdl_profile_t *profile;
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "IP change detected [%s]->[%s]\n", old_ip4, new_ip4);
|
||||
if (globals.profile_hash) {
|
||||
for (hi = switch_hash_first(NULL, globals.profile_hash); hi; hi = switch_hash_next(hi)) {
|
||||
switch_hash_this(hi, NULL, NULL, &val);
|
||||
profile = (mdl_profile_t *) val;
|
||||
if (!strcmp(profile->extip, old_ip4)) {
|
||||
tmp = profile->extip;
|
||||
profile->extip = strdup(new_ip4);
|
||||
switch_safe_free(tmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int so_callback(void *pArg, int argc, char **argv, char **columnNames)
|
||||
{
|
||||
mdl_profile_t *profile = (mdl_profile_t *) pArg;
|
||||
@@ -845,7 +873,7 @@ static int activate_rtp(struct private_object *tech_pvt)
|
||||
if(globals.auto_nat && tech_pvt->profile->local_network &&
|
||||
!switch_check_network_list_ip(tech_pvt->remote_ip, tech_pvt->profile->local_network)) {
|
||||
switch_port_t external_port = 0;
|
||||
switch_nat_add_mapping((switch_port_t)tech_pvt->local_port, SWITCH_NAT_UDP, &external_port);
|
||||
switch_nat_add_mapping((switch_port_t)tech_pvt->local_port, SWITCH_NAT_UDP, &external_port, SWITCH_FALSE);
|
||||
tech_pvt->local_port = external_port;
|
||||
}
|
||||
|
||||
@@ -1800,6 +1828,12 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_dingaling_load)
|
||||
return SWITCH_STATUS_GENERR;
|
||||
}
|
||||
|
||||
if (switch_event_bind(modname, SWITCH_EVENT_TRAP, SWITCH_EVENT_SUBCLASS_ANY, ipchanged_event_handler, NULL) != SWITCH_STATUS_SUCCESS) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
|
||||
return SWITCH_STATUS_GENERR;
|
||||
}
|
||||
|
||||
|
||||
/* connect my internal structure to the blank pointer passed to me */
|
||||
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
|
||||
dingaling_endpoint_interface = switch_loadable_module_create_interface(*module_interface, SWITCH_ENDPOINT_INTERFACE);
|
||||
|
||||
@@ -3157,6 +3157,8 @@ static void general_event_handler(switch_event_t *event)
|
||||
{
|
||||
const char *cond = switch_event_get_header(event, "condition");
|
||||
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "EVENT_TRAP: IP change detected\n");
|
||||
|
||||
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");
|
||||
|
||||
@@ -766,13 +766,13 @@ void *SWITCH_THREAD_FUNC sofia_profile_thread_run(switch_thread_t *thread, void
|
||||
);
|
||||
|
||||
if (sofia_test_pflag(profile, PFLAG_AUTO_NAT) && switch_core_get_variable("nat_type")) {
|
||||
if (switch_nat_add_mapping(profile->sip_port, SWITCH_NAT_UDP, NULL) == SWITCH_STATUS_SUCCESS) {
|
||||
if (switch_nat_add_mapping(profile->sip_port, SWITCH_NAT_UDP, NULL, SWITCH_FALSE) == SWITCH_STATUS_SUCCESS) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Created UDP nat mapping for %s port %d\n", profile->name, profile->sip_port);
|
||||
}
|
||||
if (switch_nat_add_mapping(profile->sip_port, SWITCH_NAT_TCP, NULL) == SWITCH_STATUS_SUCCESS) {
|
||||
if (switch_nat_add_mapping(profile->sip_port, SWITCH_NAT_TCP, NULL, SWITCH_FALSE) == SWITCH_STATUS_SUCCESS) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Created TCP nat mapping for %s port %d\n", profile->name, profile->sip_port);
|
||||
}
|
||||
if(sofia_test_pflag(profile, PFLAG_TLS) && switch_nat_add_mapping(profile->tls_sip_port, SWITCH_NAT_TCP, NULL) == SWITCH_STATUS_SUCCESS) {
|
||||
if(sofia_test_pflag(profile, PFLAG_TLS) && switch_nat_add_mapping(profile->tls_sip_port, SWITCH_NAT_TCP, NULL, SWITCH_FALSE) == SWITCH_STATUS_SUCCESS) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Created TCP/TLS nat mapping for %s port %d\n", profile->name, profile->tls_sip_port);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -672,7 +672,7 @@ switch_status_t sofia_glue_tech_choose_port(private_object_t *tech_pvt, int forc
|
||||
|
||||
if (tech_pvt->profile->extrtpip && sofia_glue_check_nat(tech_pvt->profile, tech_pvt->remote_ip)) {
|
||||
tech_pvt->adv_sdp_audio_ip = switch_core_session_strdup(tech_pvt->session, tech_pvt->profile->extrtpip);
|
||||
switch_nat_add_mapping((switch_port_t)sdp_port, SWITCH_NAT_UDP, &external_port);
|
||||
switch_nat_add_mapping((switch_port_t)sdp_port, SWITCH_NAT_UDP, &external_port, SWITCH_FALSE);
|
||||
} else {
|
||||
tech_pvt->adv_sdp_audio_ip = switch_core_session_strdup(tech_pvt->session, ip);
|
||||
}
|
||||
@@ -719,7 +719,7 @@ switch_status_t sofia_glue_tech_choose_video_port(private_object_t *tech_pvt, in
|
||||
}
|
||||
|
||||
if (sofia_glue_check_nat(tech_pvt->profile, tech_pvt->remote_ip)) {
|
||||
switch_nat_add_mapping((switch_port_t)sdp_port, SWITCH_NAT_UDP, &external_port);
|
||||
switch_nat_add_mapping((switch_port_t)sdp_port, SWITCH_NAT_UDP, &external_port, SWITCH_FALSE);
|
||||
}
|
||||
|
||||
tech_pvt->adv_sdp_video_port = external_port != 0 ? external_port : sdp_port;
|
||||
|
||||
@@ -2291,7 +2291,7 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_event_socket_runtime)
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Socket up listening on %s:%u\n", prefs.ip, prefs.port);
|
||||
|
||||
if (prefs.nat_map) {
|
||||
switch_nat_add_mapping(prefs.port, SWITCH_NAT_TCP, NULL);
|
||||
switch_nat_add_mapping(prefs.port, SWITCH_NAT_TCP, NULL, SWITCH_FALSE);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user