From ff1c384e13f07afaac98334532667ebf8093a1f1 Mon Sep 17 00:00:00 2001 From: Sergey Safarov Date: Sun, 27 Mar 2016 21:39:48 +0300 Subject: [PATCH] FS-7125 Added sofia event "wrong_calls_state". This is for fail2ban logging --- src/mod/endpoints/mod_sofia/mod_sofia.c | 9 +++++++++ src/mod/endpoints/mod_sofia/mod_sofia.h | 1 + src/mod/endpoints/mod_sofia/sofia.c | 9 ++++----- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index 9fc3ccd47f..cfb571bcd3 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -598,6 +598,15 @@ switch_status_t sofia_on_hangup(switch_core_session_t *session) switch_safe_free(bye_headers); } + if (cause == SWITCH_CAUSE_WRONG_CALL_STATE) { + switch_event_t *s_event; + if (switch_event_create_subclass(&s_event, SWITCH_EVENT_CUSTOM, MY_EVENT_WRONG_CALL_STATE) == SWITCH_STATUS_SUCCESS) { + switch_event_add_header_string(s_event, SWITCH_STACK_BOTTOM, "network_ip", tech_pvt->mparams.remote_ip); + switch_event_add_header(s_event, SWITCH_STACK_BOTTOM, "network_port", "%d", tech_pvt->mparams.remote_port); + switch_event_fire(&s_event); + } + } + sofia_clear_flag(tech_pvt, TFLAG_IO); if (tech_pvt->sofia_private) { diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.h b/src/mod/endpoints/mod_sofia/mod_sofia.h index a41e75abee..27c3a68b7f 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.h +++ b/src/mod/endpoints/mod_sofia/mod_sofia.h @@ -97,6 +97,7 @@ typedef struct private_object private_object_t; #define MY_EVENT_ERROR "sofia::error" #define MY_EVENT_PROFILE_START "sofia::profile_start" #define MY_EVENT_NOTIFY_WATCHED_HEADER "sofia::notify_watched_header" +#define MY_EVENT_WRONG_CALL_STATE "sofia::wrong_call_state" #define MY_EVENT_TRANSFEROR "sofia::transferor" #define MY_EVENT_TRANSFEREE "sofia::transferee" diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 1ef255ca1f..a5f83fce67 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -9491,6 +9491,10 @@ void sofia_handle_sip_i_invite(switch_core_session_t *session, nua_t *nua, sofia } } + + tech_pvt->mparams.remote_ip = switch_core_session_strdup(session, network_ip); + tech_pvt->mparams.remote_port = network_port; + if (!is_auth && (sofia_test_pflag(profile, PFLAG_AUTH_CALLS) || (!sofia_test_pflag(profile, PFLAG_BLIND_AUTH) && (sip->sip_proxy_authorization || sip->sip_authorization)))) { @@ -9517,11 +9521,6 @@ void sofia_handle_sip_i_invite(switch_core_session_t *session, nua_t *nua, sofia is_auth++; } - - - tech_pvt->mparams.remote_ip = switch_core_session_strdup(session, network_ip); - tech_pvt->mparams.remote_port = network_port; - channel = tech_pvt->channel = switch_core_session_get_channel(session); switch_channel_set_variable_printf(channel, "sip_local_network_addr", "%s", profile->extsipip ? profile->extsipip : profile->sipip);