From a3b21912c20a7ea92250a47407898f409a0b251b Mon Sep 17 00:00:00 2001 From: Sergey Safarov Date: Wed, 21 Mar 2018 08:03:57 +0000 Subject: [PATCH] Added SIP_TRACE_ROLE --- kamailio/default.cfg | 39 +++++++++++++++--------- kamailio/defs.cfg | 19 ++++++++++++ kamailio/local.cfg | 10 +++++++ kamailio/sip_trace-role.cfg | 60 +++++++++++++++++++++++++++++++++++++ 4 files changed, 114 insertions(+), 14 deletions(-) create mode 100644 kamailio/sip_trace-role.cfg diff --git a/kamailio/default.cfg b/kamailio/default.cfg index 3441d0f..1d248a7 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -8,7 +8,8 @@ flags FLAG_ASSOCIATE_USER: 4, FLAG_TRUSTED_SOURCE: 5, FLAG_SESSION_PROGRESS: 6, - FLAG_IS_REPLY: 7; + FLAG_IS_REPLY: 7, + FLAG_SIP_TRACE: 8; ####### Global Parameters ######### fork = yes @@ -273,6 +274,9 @@ include_file "responder-role.cfg" #!ifdef NODES_ROLE include_file "nodes-role.cfg" #!endif +#!ifdef SIP_TRACE_ROLE +include_file "sip_trace-role.cfg" +#!endif ####### Permissions module ########## @@ -349,19 +353,19 @@ route route(PUSHER_ROUTE); #!endif + #!ifdef RESPONDER_ROLE if (isflagset(FLAG_INTERNALLY_SOURCED)) { - #!ifdef RESPONDER_ROLE route(HANDLE_RESPOND); - #!endif - route(INTERNAL_TO_EXTERNAL_RELAY); - exit(); } + #!endif #!ifdef DISPATCHER_ROLE - route(DISPATCHER_FIND_ROUTES); + if (!isflagset(FLAG_INTERNALLY_SOURCED)) { + route(DISPATCHER_FIND_ROUTES); + } #!endif - route(EXTERNAL_TO_INTERNAL_RELAY); + route(RELAY); } route[CHECK_RETRANS] @@ -490,11 +494,11 @@ route[HANDLE_MESSAGE] lookup("location"); xlog("L_INFO", "$ci|log|routing to $ruid\n"); } - route(INTERNAL_TO_EXTERNAL_RELAY); #!ifdef TRAFFIC_FILTER_ROLE } else if (!isflagset(FLAG_TRUSTED_SOURCE) && $rd =~ "[0-9]{1,3}\.[0-9]{1,3}.[0-9]{1,3}\.[0-9]{1,3}") { xlog("L_WARN", "$ci|end|dropping MESSAGE request with IP domain\n"); + exit(); #!endif } else { xlog("L_WARN", "$ci|end|MESSAGE $(hdr(Content-Type))\n"); @@ -506,19 +510,17 @@ route[HANDLE_MESSAGE] sl_send_reply("202", "Accepted"); } else { route(DISPATCHER_FIND_ROUTES); - route(EXTERNAL_TO_INTERNAL_RELAY); } } - exit(); + route(RELAY); } #!else if (is_method("MESSAGE")) { - if (isflagset(FLAG_INTERNALLY_SOURCED)) { - route(INTERNAL_TO_EXTERNAL_RELAY); - } else { + if (!isflagset(FLAG_INTERNALLY_SOURCED)) { sl_send_reply("202", "delivered to /dev/null"); exit(); } + route(RELAY); } #!endif } @@ -621,8 +623,16 @@ route[PREPARE_INITIAL_REQUESTS] route[RELAY] { + #!ifdef SIP_TRACE_ROLE + route(SEND_SIP_TRACE); + #!endif + if (isflagset(FLAG_INTERNALLY_SOURCED)) { route(INTERNAL_TO_EXTERNAL_RELAY); + #!ifdef MESSAGE_ROLE + } else if (is_method("MESSAGE") && src_ip == myself) { + route(INTERNAL_TO_EXTERNAL_RELAY); + #!endif } else { route(EXTERNAL_TO_INTERNAL_RELAY); } @@ -697,9 +707,10 @@ route[EXTERNAL_TO_INTERNAL_RELAY] #!endif remove_hf_re("^X-.*"); + append_hf("X-AUTH-IP: $si\r\n"); append_hf("X-AUTH-PORT: $sp\r\n"); - + #!ifdef REGISTRAR_ROLE route(ADD_AUTHORIZATION_HEADERS); #!endif diff --git a/kamailio/defs.cfg b/kamailio/defs.cfg index 35cecc1..a793f99 100644 --- a/kamailio/defs.cfg +++ b/kamailio/defs.cfg @@ -99,4 +99,23 @@ #!define KZ_PRESENCE_REQUEST_PROBE 1 #!endif +################################# +## Defs related to SIP_TRACE_ROLE +## +#!ifdef SIP_TRACE_ROLE +#!trydef KZ_TRACE 0 +#!trydef KZ_TRACE_INTERNAL 1 +#!trydef KZ_TRACE_EXTERNAL 1 +#!trydef KZ_TRACE_INTERNAL_INCOMING 1 +#!trydef KZ_TRACE_INTERNAL_OUTGOING 1 +#!trydef KZ_TRACE_EXTERNAL_INCOMING 1 +#!trydef KZ_TRACE_EXTERNAL_OUTGOING 1 +#!ifndef SIP_TRACE_URI +#!substdef "!SIP_TRACE_URI!sip:127.0.0.1:9060!g" +#!endif +#!ifndef HEP_CAPTURE_ID +#!substdef "!HEP_CAPTURE_ID!1!g" +#!endif +#!endif + # vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab diff --git a/kamailio/local.cfg b/kamailio/local.cfg index a333d8a..e232100 100644 --- a/kamailio/local.cfg +++ b/kamailio/local.cfg @@ -22,6 +22,7 @@ # # #!trydef PUSHER_ROLE # # #!trydef REGISTRAR_SYNC_ROLE # # #!trydef PRESENCE_NOTIFY_SYNC_ROLE +# # #!trydef SIP_TRACE_ROLE ################################################################################ ## SERVER INFORMATION @@ -82,6 +83,15 @@ ## destination. This reduces performance. mhomed=0 +################################################################################ +## SIP traffic mirroring to SIP_TRACE server +################################################################################ +## This parameter is OPTIONAL. +## If you have installed SIP_TRACE server (Homer as example), +## then you can mirror INVITE and MESSAGE here +# # #!substdef "!SIP_TRACE_URI!sip:127.0.0.1:9060!g" +# # #!substdef "!HEP_CAPTURE_ID!1!g" + ## YOU SHOULD NOT HAVE TO CHANGE THESE! ## By setting MY_IP_ADDRESS above these will resolve ## to the proper bindings. These are here diff --git a/kamailio/sip_trace-role.cfg b/kamailio/sip_trace-role.cfg new file mode 100644 index 0000000..736975d --- /dev/null +++ b/kamailio/sip_trace-role.cfg @@ -0,0 +1,60 @@ +############################################################## +## Kamailio siptrace settings configration examples at runtime +## kamcmd siptrace.status on +## kamcmd cfg.seti kazoo trace_external 0 +## kamcmd cfg.seti kazoo trace_internal 0 + +kazoo.trace_external = KZ_TRACE_INTERNAL descr "activates tracing from external sources" +kazoo.trace_internal = KZ_TRACE_EXTERNAL descr "activates tracing from internal sources" + +kazoo.trace_internal_incoming = KZ_TRACE_INTERNAL_INCOMING descr "traces the original request as received from internal sources" +kazoo.trace_internal_outgoing = KZ_TRACE_INTERNAL_OUTGOING descr "traces the outgoing request to external sources after possible modification" +kazoo.trace_external_incoming = KZ_TRACE_EXTERNAL_INCOMING descr "traces the original request as received from external sources" +kazoo.trace_external_outgoing = KZ_TRACE_EXTERNAL_OUTGOING descr "traces the outgoing request to internal sources after possible modification" + +####### Siptrace module ########## + +loadmodule "siptrace.so" +modparam("siptrace", "duplicate_uri", "SIP_TRACE_URI") +modparam("siptrace", "hep_mode_on", 1) +modparam("siptrace", "hep_version", 3) +modparam("siptrace", "hep_capture_id", HEP_CAPTURE_ID) +modparam("siptrace", "trace_to_database", 0) +## `trace_flag` value must be equal to FLAG_SIP_TRACE value at head of "default.cfg" file +modparam("siptrace", "trace_flag", 8) +modparam("siptrace", "trace_on", KZ_TRACE) + +route[SIP_TRACE_INTERNAL] +{ + if(@cfg_get.kazoo.trace_internal == 0) { + return; + } + if(@cfg_get.kazoo.trace_internal_incoming == 1) { + sip_trace(); + } + if(@cfg_get.kazoo.trace_internal_outgoing == 1) { + setflag(FLAG_SIP_TRACE); + } +} + +route[SIP_TRACE_EXTERNAL] +{ + if(@cfg_get.kazoo.trace_external == 0) { + return; + } + if(@cfg_get.kazoo.trace_external_incoming == 1) { + sip_trace(); + } + if(@cfg_get.kazoo.trace_external_outgoing == 1) { + setflag(FLAG_SIP_TRACE); + } +} + +route[SEND_SIP_TRACE] +{ + if (isflagset(FLAG_INTERNALLY_SOURCED)) { + route(SIP_TRACE_INTERNAL); + } else { + route(SIP_TRACE_EXTERNAL); + } +}