From dfb56088a070aecf6f65adea33e716acacab90ce Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 14 Nov 2018 23:08:11 +0000 Subject: [PATCH 001/209] WIP --- kamailio/db_queries_kazoo.cfg | 5 +- kamailio/db_scripts/check-kazoodb-sql.sh | 41 +++ kamailio/db_scripts/create-kazoodb-sql.sh | 103 +----- kamailio/db_scripts/db_kazoo-specific | 34 +- kamailio/db_scripts/kazoodb-sql.sh | 96 ++++++ kamailio/db_scripts/vw_presentities.sql | 20 ++ kamailio/db_scripts/vw_wdispatcher.sql | 6 + kamailio/default.cfg | 75 ++-- kamailio/defs.cfg | 51 +-- kamailio/dispatcher-role.cfg | 20 +- kamailio/fast-pickup-role.cfg | 22 +- kamailio/kazoo-bindings.cfg | 10 + kamailio/message-role.cfg | 2 +- kamailio/nat-traversal-role.cfg | 1 + kamailio/nodes-role.cfg | 23 +- ...tify_sync-role.cfg => presence-notify.cfg} | 52 ++- ...ence_query-role.cfg => presence-query.cfg} | 7 +- kamailio/presence-reset.cfg | 3 +- kamailio/presence-role.cfg | 161 +++++---- kamailio/pusher-role.cfg | 3 + kamailio/registrar-role.cfg | 325 +++++++++--------- kamailio/websockets-role.cfg | 2 - system/sbin/kazoo-kamailio | 235 +++++++------ 23 files changed, 777 insertions(+), 520 deletions(-) create mode 100755 kamailio/db_scripts/check-kazoodb-sql.sh create mode 100755 kamailio/db_scripts/kazoodb-sql.sh create mode 100644 kamailio/db_scripts/vw_presentities.sql create mode 100644 kamailio/db_scripts/vw_wdispatcher.sql rename kamailio/{presence_notify_sync-role.cfg => presence-notify.cfg} (64%) rename kamailio/{presence_query-role.cfg => presence-query.cfg} (91%) diff --git a/kamailio/db_queries_kazoo.cfg b/kamailio/db_queries_kazoo.cfg index b7e542d..29801d5 100644 --- a/kamailio/db_queries_kazoo.cfg +++ b/kamailio/db_queries_kazoo.cfg @@ -9,7 +9,8 @@ #!substdef "!KZQ_RESET_ACCOUNT_DELETE!delete from presentity where domain=\"\$(kzE{kz.json,Realm})\"!g" #!substdef "!KZQ_RESET_ACCOUNT_UPDATE!update active_watchers set expires = \$TS where watcher_domain=\"\$(kzE{kz.json,Realm})\"!g" #!substdef "!KZQ_RESET_PUBLISHER_UPDATE!update active_watchers set expires = \$TS where id in (select b.id from presentity a inner join active_watchers b on a.username = b.to_user and a.domain = b.to_domain and a.event = b.event where a.sender = \"\$var(MediaUrl)\")!g" -#!substdef "!KZQ_PRESENCE_SEARCH_DETAIL!select * from active_watchers_log where presentity_uri = \"\$var(presentity_uri)\"!g" -#!substdef "!KZQ_PRESENCE_SEARCH_SUMMARY!select * from active_watchers where watcher_domain = \"\$var(Domain)\"!g" +#!substdef "!KZQ_PRESENCE_SEARCH_DETAIL!select * from active_watchers_log where presentity_uri = \"\$var(presentity_uri)\" and callid in(select callid from active_watchers where presentity_uri = \"\$var(presentity_uri)\")!g" +#!substdef "!KZQ_PRESENCE_SEARCH_SUMMARY!select * from active_watchers where to_domain = \"\$var(Domain)\"!g" #!substdef "!KZQ_HAS_PRESENTITY!select count(*) as count from presentity where username = \"\$subs(to_user)\" and domain = \"\$subs(to_domain)\" and event = \"\$subs(event)\"!g" #!substdef "!KZQ_PRESENCE_RESET!delete from presentity where sender = \"\$var(MediaUrl)\"!g" +#!substdef "!KZQ_REPLACE_WATCHERS_LOG!REPLACE INTO active_watchers_log (presentity_uri, watcher_username, watcher_domain, event, callid, to_user, to_domain, user_agent, time, result, sent_msg, received_msg) VALUES (\"\$subs(uri)\", \"\$subs(watcher_username)\", \"\$subs(watcher_domain)\", \"\$subs(event)\",\"\$subs(callid)\",\"\$subs(to_user)\",\"\$subs(to_domain)\", '\$(subs(user_agent){s.escape.common}{s.replace,\\\',''}{s.replace,\$\$,})', \$TS, \$notify_reply(\$rs), '\$(mb{s.escape.common}{s.replace,\\\',''}{s.replace,\$\$,})', '\$(notify_reply(\$mb){s.escape.common}{s.replace,\\\',''}{s.replace,\$\$,})')!g" diff --git a/kamailio/db_scripts/check-kazoodb-sql.sh b/kamailio/db_scripts/check-kazoodb-sql.sh new file mode 100755 index 0000000..6db754d --- /dev/null +++ b/kamailio/db_scripts/check-kazoodb-sql.sh @@ -0,0 +1,41 @@ +#!/bin/sh + +TEMP_DB_LOCATION=/tmp/db +TEMP_DB=${TEMP_DB_LOCATION}/kazoo.db + +rm -rf ${TEMP_DB_LOCATION} +. $(dirname $0)/kazoodb-sql.sh --source-only + +file=$(sql_db_prepare) +sql_setup $file ${TEMP_DB_LOCATION} + +DB_VERSION=`KazooDB -db ${TEMP_DB} "select sum(table_version) from version;"` + +DB_CURRENT_DB=${DB_LOCATION:-/etc/kazoo/kamailio}/kazoo.db +DB_CURRENT_VERSION=`KazooDB -db ${DB_CURRENT_DB} "select sum(table_version) from version;"` + + +if [[ $DB_CURRENT_VERSION -lt $DB_VERSION ]]; then + echo "db required version is ${DB_VERSION}, existing version is ${DB_CURRENT_VERSION}, applying diff" + KazooDB-diff --schema ${DB_CURRENT_DB} ${TEMP_DB} | KazooDB -db ${DB_CURRENT_DB} + KazooDB-diff --table version ${DB_CURRENT_DB} ${TEMP_DB} | KazooDB -db ${DB_CURRENT_DB} +fi + + +for VIEW in `ls ${DB_SCRIPT_DIR}/vw_*.sql`; do + filename=$(basename -- "$VIEW") + filename="${filename%.*}" + viewname=$(echo -n "$filename" | cut -d'_' -f2) + v1=$(KazooDB -db ${DB_CURRENT_DB} "select sql from sqlite_master where type='view' and name='$viewname'" 2> /dev/null | tr -d ' ' | md5sum | cut -d ' ' -f1) + v2=$(cat $VIEW | tr -d ' ' | md5sum | cut -d ' ' -f1) + if [[ "$v1" != "$v2" ]]; then + echo "rebuilding view $viewname" + KazooDB -db ${DB_CURRENT_DB} "drop view if exists $viewname;" + KazooDB -db ${DB_CURRENT_DB} < $VIEW + fi +done + +if [ -f ${DB_SCRIPT_DIR}/db_extra_check.sql ]; then + . ${DB_SCRIPT_DIR}/db_extra_check.sql --source-only + do_db_extra_check; +fi diff --git a/kamailio/db_scripts/create-kazoodb-sql.sh b/kamailio/db_scripts/create-kazoodb-sql.sh index 0663a0e..ebfc0ae 100755 --- a/kamailio/db_scripts/create-kazoodb-sql.sh +++ b/kamailio/db_scripts/create-kazoodb-sql.sh @@ -1,104 +1,9 @@ #!/bin/sh -e -##################################################################################### -## -## If you want prepare SQL file for PostgreSQL or MySQL server, then need to execute -## DB_ENGINE=postgres ./create-kazoodb-sql.sh -## -##################################################################################### -KAMAILIO_SHARE_DIR=${KAMAILIO_SHARE_DIR:-/usr/share/kamailio} -DB_ENGINE=${DB_ENGINE:-db_kazoo} -RESULTED_SQL=${RESULTED_SQL:-/tmp/kamailio_initdb.sql} +. $(dirname $0)/kazoodb-sql.sh --source-only -. $(dirname $0)/$DB_ENGINE-specific --source-only - -sql_filelist() { -cat << EOF -acc-create.sql -lcr-create.sql -domain-create.sql -group-create.sql -permissions-create.sql -registrar-create.sql -usrloc-create.sql -msilo-create.sql -alias_db-create.sql -uri_db-create.sql -speeddial-create.sql -avpops-create.sql -auth_db-create.sql -pdt-create.sql -dialog-create.sql -dispatcher-create.sql -dialplan-create.sql -topos-create.sql -presence-create.sql -rls-create.sql -imc-create.sql -cpl-create.sql -siptrace-create.sql -domainpolicy-create.sql -carrierroute-create.sql -userblacklist-create.sql -htable-create.sql -purple-create.sql -uac-create.sql -pipelimit-create.sql -mtree-create.sql -sca-create.sql -mohqueue-create.sql -rtpproxy-create.sql -uid_auth_db-create.sql -uid_avp_db-create.sql -uid_domain-create.sql -uid_gflags-create.sql -uid_uri_db-create.sql -EOF -} - -sql_all_header() { -cat << EOF -CREATE TABLE version ( - table_name VARCHAR(32) NOT NULL, - table_version INTEGER DEFAULT 0 NOT NULL, - CONSTRAINT version_table_name_idx UNIQUE (table_name) -); -INSERT INTO version VALUES('version',1); - -EOF -} - -sql_all_extra_tables() { -cat << EOF - -CREATE TABLE event_list ( event varchar(25) PRIMARY KEY NOT NULL); -INSERT INTO event_list VALUES('dialog'); -INSERT INTO event_list VALUES('presence'); -INSERT INTO event_list VALUES('message-summary'); -INSERT INTO version VALUES('event_list',1); - -EOF -} - -sql_all_footer() { -cat << EOF -COMMIT; -EOF -} - -echo "Creating kamailio database init file in '$RESULTED_SQL'" - -sql_db_pre_setup > $RESULTED_SQL -sql_all_header >> $RESULTED_SQL -sql_header >> $RESULTED_SQL -for i in $(sql_filelist); do - cat $KAMAILIO_SHARE_DIR/$DB_ENGINE/$i >> $RESULTED_SQL -done -sql_all_extra_tables >> $RESULTED_SQL -sql_extra_tables >> $RESULTED_SQL -sql_footer >> $RESULTED_SQL -sql_all_footer >> $RESULTED_SQL - -sql_setup $RESULTED_SQL +$file=$(sql_db_prepare) +echo "setting up kazoo db from init script $file" +sql_setup $file exit 0 diff --git a/kamailio/db_scripts/db_kazoo-specific b/kamailio/db_scripts/db_kazoo-specific index 014fd78..e21ab71 100644 --- a/kamailio/db_scripts/db_kazoo-specific +++ b/kamailio/db_scripts/db_kazoo-specific @@ -6,15 +6,16 @@ cat << EOF PRAGMA foreign_keys=OFF; PRAGMA wal=on; PRAGMA journal_mode=WAL; +PRAGMA wal_autocheckpoint=25; BEGIN TRANSACTION; EOF } sql_setup() { - DB_KAZOO_LOCATION=${DB_KAZOO_LOCATION:-/etc/kazoo/kamailio/db} - mkdir -p ${DB_KAZOO_LOCATION} - KazooDB -db ${DB_KAZOO_LOCATION}/kazoo.db < $1 + DB_KAZOO_LOCATION=${2:-${DB_KAZOO_LOCATION:-/etc/kazoo/kamailio/db}} + mkdir -p ${DB_KAZOO_LOCATION} + KazooDB -db ${DB_KAZOO_LOCATION}/kazoo.db < $1 > /dev/null } sql_header() { @@ -40,6 +41,33 @@ CREATE TABLE active_watchers_log ( user_agent VARCHAR(255) DEFAULT '' COLLATE NOCASE, CONSTRAINT active_watchers_active_watchers_log_idx UNIQUE (presentity_uri, watcher_username, watcher_domain, event) ); + + create view presentities as select id, cast(printf("sip:%s@%s",username,domain) as varchar(64)) presentity_uri , + username, domain, event, cast(substr(etag, instr(etag,"@")+1) as varchar(64)) callid, + datetime(received_time, 'unixepoch') as received, + datetime(expires, 'unixepoch') as expire_date, + expires, cast(sender as varchar(30)) sender, + lower(cast( case when event = "dialog" + then substr(body, instr(BODY,"")+7, instr(body,"") - instr(body,"") - 7) + when event = "presence" + then case when instr(body,"") == 0 + then replace(substr(body, instr(body,"")+6, instr(body,"") - instr(body,"") - 6), " ", "") + else replace(substr(body, instr(body,"")+9, instr(body,"") - instr(body,"") - 9), " ", "") + end + when event = "message-summary" + then case when instr(body,"Messages-Waiting: yes") = 0 + then "Waiting" + else "Not-Waiting" + end + end as varchar(12))) state + from presentity; + + create view wdispatcher as select *, + cast(substr(attrs, instr(attrs, "zone=")+5, instr(attrs, ";profile")-instr(attrs, "zone=")-5) as varchar(20)) zone, + cast(substr(attrs, instr(attrs, "idx=")+4, instr(attrs, ";node")-instr(attrs, "idx=")-4) as integer) idx, + cast(substr(attrs, instr(attrs, "node=")+5) as varchar(50)) node + from dispatcher; + EOF } diff --git a/kamailio/db_scripts/kazoodb-sql.sh b/kamailio/db_scripts/kazoodb-sql.sh new file mode 100755 index 0000000..e4e36dd --- /dev/null +++ b/kamailio/db_scripts/kazoodb-sql.sh @@ -0,0 +1,96 @@ +#!/bin/sh -e + +KAMAILIO_SHARE_DIR=${KAMAILIO_SHARE_DIR:-/usr/share/kamailio} +DB_ENGINE=${DB_ENGINE:-db_kazoo} +RESULTED_SQL=${RESULTED_SQL:-/tmp/kamailio_initdb.sql} + +. $(dirname $0)/$DB_ENGINE-specific --source-only + +sql_filelist() { +cat << EOF +acc-create.sql +lcr-create.sql +domain-create.sql +group-create.sql +permissions-create.sql +registrar-create.sql +usrloc-create.sql +msilo-create.sql +alias_db-create.sql +uri_db-create.sql +speeddial-create.sql +avpops-create.sql +auth_db-create.sql +pdt-create.sql +dialog-create.sql +dispatcher-create.sql +dialplan-create.sql +topos-create.sql +presence-create.sql +rls-create.sql +imc-create.sql +cpl-create.sql +siptrace-create.sql +domainpolicy-create.sql +carrierroute-create.sql +userblacklist-create.sql +htable-create.sql +purple-create.sql +uac-create.sql +pipelimit-create.sql +mtree-create.sql +sca-create.sql +mohqueue-create.sql +rtpproxy-create.sql +uid_auth_db-create.sql +uid_avp_db-create.sql +uid_domain-create.sql +uid_gflags-create.sql +uid_uri_db-create.sql +EOF +} + +sql_all_header() { +cat << EOF +CREATE TABLE version ( + table_name VARCHAR(32) NOT NULL, + table_version INTEGER DEFAULT 0 NOT NULL, + CONSTRAINT version_table_name_idx UNIQUE (table_name) +); +INSERT INTO version VALUES('version',1); + +EOF +} + +sql_all_extra_tables() { +cat << EOF + +CREATE TABLE event_list ( event varchar(25) PRIMARY KEY NOT NULL); +INSERT INTO event_list VALUES('dialog'); +INSERT INTO event_list VALUES('presence'); +INSERT INTO event_list VALUES('message-summary'); +INSERT INTO version VALUES('event_list',1); + +EOF +} + +sql_all_footer() { +cat << EOF +COMMIT; +EOF +} + +sql_db_prepare() { + sql_db_pre_setup > $RESULTED_SQL + sql_all_header >> $RESULTED_SQL + sql_header >> $RESULTED_SQL + for i in $(sql_filelist); do + cat $KAMAILIO_SHARE_DIR/$DB_ENGINE/$i >> $RESULTED_SQL + done + sql_all_extra_tables >> $RESULTED_SQL + sql_extra_tables >> $RESULTED_SQL + sql_footer >> $RESULTED_SQL + sql_all_footer >> $RESULTED_SQL + + echo "$RESULTED_SQL" +} diff --git a/kamailio/db_scripts/vw_presentities.sql b/kamailio/db_scripts/vw_presentities.sql new file mode 100644 index 0000000..4c95a38 --- /dev/null +++ b/kamailio/db_scripts/vw_presentities.sql @@ -0,0 +1,20 @@ +CREATE VIEW presentities as +select id, cast(printf("sip:%s@%s",username,domain) as varchar(64)) presentity_uri , + username, domain, event, cast(substr(etag, instr(etag,"@")+1) as varchar(64)) callid, + datetime(received_time, 'unixepoch') as received, + datetime(expires, 'unixepoch') as expire_date, + expires, cast(sender as varchar(30)) sender, + lower(cast( case when event = "dialog" + then substr(body, instr(BODY,"")+7, instr(body,"") - instr(body,"") - 7) + when event = "presence" + then case when instr(body,"") == 0 + then replace(substr(body, instr(body,"")+6, instr(body,"") - instr(body,"") - 6), " ", "") + else replace(substr(body, instr(body,"")+9, instr(body,"") - instr(body,"") - 9), " ", "") + end + when event = "message-summary" + then case when instr(body,"Messages-Waiting: yes") = 0 + then "Waiting" + else "Not-Waiting" + end + end as varchar(12))) state + from presentity diff --git a/kamailio/db_scripts/vw_wdispatcher.sql b/kamailio/db_scripts/vw_wdispatcher.sql new file mode 100644 index 0000000..1643b92 --- /dev/null +++ b/kamailio/db_scripts/vw_wdispatcher.sql @@ -0,0 +1,6 @@ +CREATE VIEW wdispatcher as + select *, + cast(substr(attrs, instr(attrs, "zone=")+5, instr(attrs, ";profile")-instr(attrs, "zone=")-5) as varchar(20)) zone, + cast(substr(attrs, instr(attrs, "idx=")+4, instr(attrs, ";node")-instr(attrs, "idx=")-4) as integer) idx, + cast(substr(attrs, instr(attrs, "node=")+5) as varchar(50)) node + from dispatcher diff --git a/kamailio/default.cfg b/kamailio/default.cfg index bf51561..09c2d55 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -30,7 +30,7 @@ debug = KAZOO_LOG_LEVEL memdbg = 10 memlog = L_INFO corelog = L_ERR -mem_summary = 12 +mem_summary = 0 log_stderror = no log_facility = LOG_LOCAL0 log_name="kamailio" @@ -71,14 +71,14 @@ udp4_raw = 0 # #udp_mtu_try_proto = TCP ####### DNS Parameters ######### -dns = no +dns = yes rev_dns = no dns_try_ipv6 = no use_dns_cache = on dns_cache_del_nonexp = yes dns_cache_flags = 1 dns_cache_gc_interval = 120 -dns_cache_init = 0 +dns_cache_init = 1 dns_cache_mem = 1000 dns_cache_negative_ttl = 60 dns_try_naptr = no @@ -299,7 +299,7 @@ route # log the basic info regarding this call xlog("L_INFO", "$ci|start|received $pr request $rm $ou\n"); - xlog("L_INFO", "$ci|log|source $si:$sp -> $Ri:$Rp\n"); + xlog("L_INFO", "$ci|log|source $si:$sp -> $RAi:$RAp\n"); xlog("L_INFO", "$ci|log|from $fu\n"); xlog("L_INFO", "$ci|log|to $tu\n"); @@ -380,17 +380,20 @@ route[CHECK_RETRANS] } } + +modparam("htable", "htable", "insane=>size=32;autoexpire=120;initval=0;updateexpire=1;") + route[SANITY_CHECK] { - ## CVE-2018-14767 - if($(hdr(To)[1]) != $null) { - xlog("second To header not null - dropping message"); + if($sht(insane=>$si:$sp) > 3) { drop; - } - - if (!sanity_check()) { - xlog("L_WARN", "$ci|end|message from $si:$sp is insane\n"); exit; + }; + + if (!sanity_check()) { + $var(insane) = $shtinc(insane=>$si:$sp); + xlog("L_WARN", "$ci|end|message from $si:$sp is insane ($var(insane))\n"); + drop; } if (!mf_process_maxfwd_header("10")) { @@ -406,7 +409,7 @@ route[SANITY_CHECK] $ua =~ "PortSIP" || $ua =~ "sipcli" ) { xlog("L_WARN", "$ci|end|dropping message with user-agent $ua from $si:$sp\n"); - exit; + drop; } } @@ -729,7 +732,9 @@ onreply_route[EXTERNAL_REPLY] #!endif #!ifdef NAT_TRAVERSAL_ROLE + if(!t_check_status("302")) { route(NAT_TEST_AND_CORRECT); + } #!endif #!ifdef ACL_ROLE @@ -752,7 +757,7 @@ onreply_route[EXTERNAL_REPLY] onreply_route[INTERNAL_REPLY] { # this route handles replies that are comming from our media server - xlog("L_INFO", "$ci|start|received internal reply $T_reply_code $rr\n"); + xlog("L_INFO", "$ci|start|received internal reply $T_reply_code $T_reply_reason\n"); xlog("L_INFO", "$ci|log|source $si:$sp\n"); #!ifdef WEBSOCKETS_ROLE @@ -787,7 +792,6 @@ onreply_route[INTERNAL_REPLY] xlog("L_INFO", "$ci|pass|$T_req($si):$T_req($sp)\n"); } - $var(reply_reason) = $rr; } failure_route[INTERNAL_FAULT] @@ -824,24 +828,24 @@ failure_route[INTERNAL_FAULT] # change 6xx to 4xx if (t_check_status("6[0-9][0-9]") && !t_check_status("600|603|604|606")) { $var(new_code) = "4" + $(T_reply_code{s.substr,1,0}); - xlog("L_INFO", "$ci|log|sending 6XX reply as $var(new_code) $var(reply_reason)\n"); - t_reply("$(var(new_code){s.int})", "$var(reply_reason)"); + xlog("L_INFO", "$ci|log|sending 6XX reply as $var(new_code) $T_reply_reason\n"); + t_reply("$(var(new_code){s.int})", "$T_reply_reason"); # if the failure case was something that we should recover # from then try to find a new media server - } else if ($var(reply_reason) =~ "call barred") { + } else if ($T_reply_reason =~ "call barred") { xlog("L_INFO", "$ci|log|failure route ignoring call barred\n"); } else if (isflagset(FLAG_SESSION_PROGRESS)) { xlog("L_INFO", "$ci|log|failure route ignoring failure after session progress\n"); - } else if (t_check_status("403") && $var(reply_reason)=="Forbidden") { + } else if (t_check_status("403") && $T_reply_reason=="Forbidden") { xlog("L_WARNING", "$ci|log|failure route ignoring. Failed auth from IP $si\n"); } else if (t_check_status("(401)|(407)|(486)|(403)")) { - xlog("L_INFO", "$ci|log|failure route ignoring auth reply $T_reply_code $var(reply_reason)\n"); + xlog("L_INFO", "$ci|log|failure route ignoring auth reply $T_reply_code $T_reply_reason\n"); } else if (t_check_status("402")) { xlog("L_INFO", "$ci|log|failure route overriding reply code 402 with 486\n"); send_reply("486", "Insufficient Funds"); } else if (t_check_status("(4[0-9][0-9])|(5[0-9][0-9])")) { - xlog("L_INFO", "$ci|start|received failure reply $T_reply_code $rr\n"); + xlog("L_INFO", "$ci|start|received failure reply $T_reply_code $T_reply_reason\n"); #!ifdef DISPATCHER_ROLE route(DISPATCHER_NEXT_ROUTE); @@ -849,7 +853,8 @@ failure_route[INTERNAL_FAULT] send_reply("486", "Unable to Comply"); } else { - xlog("L_INFO", "$ci|log|failure route ignoring reply $T_reply_code $rr\n"); + xlog("L_INFO", "$ci|log|failure route ignoring reply $T_reply_code $T_reply_reason\n"); + send_reply("$T_reply_code", "$T_reply_reason"); } xlog("L_INFO", "$ci|pass|$si:$sp\n"); } @@ -885,6 +890,28 @@ onsend_route { } #!ifdef REGISTRAR_ROLE + +#!ifdef WITH_AUTH_TOKEN +route[ADD_AUTHORIZATION_HEADERS] +{ + if (!is_method("INVITE|MESSAGE|REFER")) { + return; + } + + $xavp(regcfg=>match_received) = $su; + if (registered("location","$fu", 2, 1) == 1) { + if($(xavp(ulattrs=>token){s.len}) > 0) { + append_hf("X-AUTH-Token: $xavp(ulattrs=>token)\r\n"); + } else { + if($(xavp(ulattrs=>Authorizing-ID){s.len}) > 0 && $(xavp(ulattrs=>Account-ID){s.len})) { + append_hf("X-AUTH-Token: $xavp(ulattrs=>Authorizing-ID)@$xavp(ulattrs=>Account-ID)\r\n"); + } + } + } +} + +#!else + route[ADD_AUTHORIZATION_HEADERS] { if (!is_method("INVITE|MESSAGE|REFER")) { @@ -923,11 +950,15 @@ route[ADD_AUTHORIZATION_HEADERS] } #!endif -#!ifdef PRESENCE_NOTIFY_INIT +#!endif + +#!ifdef PRESENCE_ROLE event_route[tm:local-request] { route(PRESENCE_LOCAL_NOTIFY); } #!endif +#!import_file "custom-init.cfg" + # vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab diff --git a/kamailio/defs.cfg b/kamailio/defs.cfg index 2cb4cc7..24b72ae 100644 --- a/kamailio/defs.cfg +++ b/kamailio/defs.cfg @@ -31,14 +31,6 @@ #!define TCP_CHILDREN 25 #!endif -#!ifndef OPENBTS_AUTH_SECRET -#!substdef "!OPENBTS_AUTH_SECRET!b3a54fa8317c7d9cb1d89d8970947b30eda273124d97fc3a079ccc98ecc2569b!g" -#!endif - -#!ifndef KZ_USE_DISPATCHER_LIST -#!trydef KZ_USE_DISPATCHER_TABLE -#!endif - #!ifndef ANTIFLOOD_CACHE_PERIOD #!substdef "!ANTIFLOOD_CACHE_PERIOD!600!g" #!endif @@ -67,10 +59,6 @@ #!substdef "!MY_AMQP_ZONE!local!g" #!endif -#!ifndef DISPATCHER_ADD_SERVERS -#!define DISPATCHER_ADD_SERVERS 1 -#!endif - #!ifndef PRESENCE_RESET_BLF_DEFER_UPDATE #!define PRESENCE_RESET_BLF_DEFER_UPDATE 0 #!endif @@ -87,17 +75,10 @@ #!substdef "!MEDIA_SERVERS_HASH_SIZE!256!g" #!endif -#!ifndef KZ_PRESENCE_AMQP_PUBLISH -#!define KZ_PRESENCE_AMQP_PUBLISH 0 -#!endif - -#!ifndef KZ_PRESENCE_REQUEST_RESUBSCRIBE_PROBE -#!define KZ_PRESENCE_REQUEST_RESUBSCRIBE_PROBE 0 -#!endif +#!trydef KZ_PRESENCE_AMQP_PUBLISH 0 -#!ifndef KZ_PRESENCE_REQUEST_PROBE -#!define KZ_PRESENCE_REQUEST_PROBE 1 -#!endif +#!trydef KZ_PRESENCE_REQUEST_RESUBSCRIBE_PROBE 0 +#!trydef KZ_PRESENCE_REQUEST_PROBE 1 #!ifndef NAT_UAC_TEST_LEVEL #!substdef "!NAT_UAC_TEST_LEVEL!3!g" @@ -130,6 +111,32 @@ #!trydef KZ_TLS_REGISTRAR_PORT 7000 #!endif +#!trydef KZ_FAST_PICKUP_COOKIES 1 +#!trydef KZ_FAST_PICKUP_REALTIME 1 + +#!trydef KZ_MULTI_HOMED 0 + +#!ifndef KZ_DISABLE_WEBSOCKETS_REGISTRAR_PORT +#!trydef KZ_WEBSOCKETS_REGISTRAR_PORT 7000 +#!endif + +#!ifndef KZ_DISABLE_TLS_REGISTRAR_PORT +#!trydef KZ_TLS_REGISTRAR_PORT 7000 +#!endif + +################################################################################ +## BINDINGS +################################################################################ +## This parameter is OPTIONAL. +## It will try to locate outbound interface +## on multihomed host. By default forward +## requests use the incoming socket disregarding +## the destination location. When enabled Kamailio +## will select a socket that can reach the +## destination. This reduces performance. +mhomed=KZ_MULTI_HOMED + + #!trydef KZ_FAST_PICKUP_COOKIES 1 #!trydef KZ_FAST_PICKUP_REALTIME 1 diff --git a/kamailio/dispatcher-role.cfg b/kamailio/dispatcher-role.cfg index 24b26cc..8dfeef2 100644 --- a/kamailio/dispatcher-role.cfg +++ b/kamailio/dispatcher-role.cfg @@ -1,7 +1,12 @@ ######## Generic Hash Table container in shared memory ######## modparam("htable", "htable", "failover=>size=16;autoexpire=120") +#!trydef KZ_DISPATCHER_PROBE_MODE 1 +#!trydef DISPATCHER_ADD_SERVERS 1 +#!trydef DISPATCHER_ALG 4 + kazoo.dispatcher_auto_add = DISPATCHER_ADD_SERVERS descr "adds media servers reported by ecallmgr" +kazoo.dispatcher_algorithm = DISPATCHER_ALG descr "dispatcher algorithm to use" ####### Dispatcher module ######## loadmodule "dispatcher.so" @@ -18,7 +23,7 @@ modparam("dispatcher", "setid_pvname", "$var(setid)") modparam("dispatcher", "ds_ping_method", "OPTIONS") modparam("dispatcher", "ds_ping_interval", 10) modparam("dispatcher", "ds_probing_threshold", 3) -modparam("dispatcher", "ds_probing_mode", 1) +modparam("dispatcher", "ds_probing_mode", KZ_DISPATCHER_PROBE_MODE) modparam("dispatcher", "ds_ping_reply_codes", "501,403,404,400,200") modparam("dispatcher", "ds_ping_from", "sip:sipcheck@MY_HOSTNAME") @@ -87,9 +92,9 @@ route[DISPATCHER_FIND_ROUTES] $var(ds_group) = $var(ds_primary_group); - if (!ds_select_dst("$var(ds_primary_group)", "0") || $(avp(ds_dst)[0]) == $null) { + if (!ds_select_dst("$var(ds_primary_group)", "$sel(cfg_get.kazoo.dispatcher_algorithm)") || $(avp(ds_dst)[0]) == $null) { # we selected from primary group, try again in backup group - if (!ds_select_dst("$var(ds_backup_group)", "0") || $(avp(ds_dst)[0]) == $null) { + if (!ds_select_dst("$var(ds_backup_group)", "$sel(cfg_get.kazoo.dispatcher_algorithm)") || $(avp(ds_dst)[0]) == $null) { xlog("L_WARN", "$ci|end|no servers available in primary or backup group\n"); sl_send_reply("480", "All servers busy"); exit; @@ -227,12 +232,19 @@ route[DISPATCHER_CHECK_MEDIA_SERVER] if($var(Zone) != "MY_AMQP_ZONE") { $var(SetId) = 2; } - sql_query("exec", "KZQ_CHECK_MEDIA_SERVER_INSERT"); + if($(var(MediaUrl){uri.port}) == 12000) { + $var(SetId) = $var(SetId) + 50; + } + $var(flags) = 10; + $var(attrs) = $_s(zone=$var(Zone);profile=$var(MediaProfile);idx=$(var(MediaUrl){s.corehash, MEDIA_SERVERS_HASH_SIZE});node=$var(MediaName)); + sql_query("exec", "insert into dispatcher (setid, destination, flags, attrs, description) select $var(SetId), \"$var(MediaUrl)\", $var(flags), \"$var(attrs)\", \"added by nodes role\" where not exists(select * from dispatcher where destination = \"$var(MediaUrl)\")"); if($sqlrows(exec) > 0) { xlog("L_WARNING", "reloading dispatcher table\n"); ds_reload(); + return 1; } } + return 0; } route[DISPATCHER_STATUS] diff --git a/kamailio/fast-pickup-role.cfg b/kamailio/fast-pickup-role.cfg index 36c05e7..2714eb3 100644 --- a/kamailio/fast-pickup-role.cfg +++ b/kamailio/fast-pickup-role.cfg @@ -13,7 +13,6 @@ route[FAST_PICKUP_START] route[FAST_PICKUP_LOAD] { sht_reset("fp"); -#!ifndef KZ_USE_DISPATCHER_LIST xlog("L_INFO", "$ci|log|fast|initializing fastpick hash table from dispatcher\n"); if (sql_xquery("exec", "select destination from dispatcher", "ra") == 1) { while($xavp(ra) != $null) { @@ -31,9 +30,6 @@ route[FAST_PICKUP_LOAD] pv_unset("$xavp(ra)"); } } -#!else - xlog("L_INFO", "$ci|log|fast|cannot initialize hash table from dispatcher. check KZ_USE_DISPATCHER_LIST option in local.cfg\n"); -#!endif } route[FAST_PICKUP_ATTEMPT] @@ -107,6 +103,21 @@ route[FAST_PICKUP_ATTEMPT] route(EXTERNAL_TO_INTERNAL_RELAY); exit(); } + + ##### CALL-PARK IN KAZOO #### + if($(ru{uri.user}) =~ "\*[3-4]" && !($rd =~ "[0-9]{1,3}\.[0-9]{1,3}.[0-9]{1,3}\.[0-9]{1,3}") ) { + xlog("L_INFO", "$ci|log|checking park request to $(ru{uri.user})@$(ru{uri.domain})\n"); + $var(amqp_payload_request) = '{"Event-Category" : "call_event" , "Event-Name" : "query_user_channels_req", "Username" : "$(ru{uri.user})", "Realm" : "$(ru{uri.domain})", "Active-Only" : true }'; + $var(amqp_routing_key) = "call.status_req." + $(var(replaced_call_id){kz.encode}); + if(kazoo_query("callevt", $var(amqp_routing_key), $var(amqp_payload_request))) { + $du = $(kzR{kz.json,Channels[0].switch_url}); + if($du != $null) { + xlog("L_INFO", "$ci|log|redirecting park request to $du, courtesy of kazoo\n"); + route(EXTERNAL_TO_INTERNAL_RELAY); + exit(); + } + } + } } route[FAST_PICKUP_OPTION] @@ -136,7 +147,6 @@ route[FAST_PICKUP_INIT] } else { $sht(park=>$(kzE{kz.json,Presence-ID})) = $(kzE{kz.json,Switch-URI}); } - } ## fast pickup with cookies @@ -151,7 +161,7 @@ route[FAST_PICKUP_INIT] $var(Cookie) = $(kzE{kz.json,Switch-URI}{s.md5}); $var(call_id) = $(kzE{kz.json,Call-ID}); $var(JObj) = $(kzE{re.subst,/"Call-ID"\s*\:\s*"([^"]*)"/"Call-ID" : "kfp+$var(Option)$var(Cookie)@\1"/}); - xlog("L_INFO", "$var(call_id)|fast|shortcut ($var(Pickup)) kfp+$var(Option)$var(Cookie)@$var(call_id)\n"); + xlog("L_DEBUG", "$var(call_id)|fast|shortcut ($var(Pickup)) kfp+$var(Option)$var(Cookie)@$var(call_id)\n"); } } diff --git a/kamailio/kazoo-bindings.cfg b/kamailio/kazoo-bindings.cfg index c4c520f..cf243b7 100644 --- a/kamailio/kazoo-bindings.cfg +++ b/kamailio/kazoo-bindings.cfg @@ -59,4 +59,14 @@ event_route[kazoo:consumer-event-connection-closed] xlog("L_INFO","connection to $(kzE{kz.json,host}) closed\n"); } +event_route[kazoo:consumer-event-connection-zone-available] +{ + xlog("L_NOTICE","amqp zone $(kzE{kz.json,zone}) is available\n"); +} + +event_route[kazoo:consumer-event-connection-zone-unavailable] +{ + xlog("L_WARN","amqp zone $(kzE{kz.json,zone}) is unavailable\n"); +} + # vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab diff --git a/kamailio/message-role.cfg b/kamailio/message-role.cfg index a0fa312..1b56a5a 100644 --- a/kamailio/message-role.cfg +++ b/kamailio/message-role.cfg @@ -54,7 +54,7 @@ route[MESSAGE_REPLY] route[MESSAGE_BINDINGS] { $var(key) = "kamailio@MY_HOSTNAME"; - $var(payload) = "{ 'exchange' : 'sms' , 'type' : 'topic', 'queue' : 'MSG-QUEUE-MY_HOSTNAME', 'routing' : 'message.route." + $(var(key){kz.encode}) + ".*', 'no_ack' : 0 }"; + $var(payload) = $_s({"exchange": "sms", "type": "topic", "queue": "MSG-QUEUE-MY_HOSTNAME", "routing": "message.route.$(var(key){kz.encode}).*", "no_ack": 0 }); kazoo_subscribe("$var(payload)"); } diff --git a/kamailio/nat-traversal-role.cfg b/kamailio/nat-traversal-role.cfg index 7166446..7b087bf 100644 --- a/kamailio/nat-traversal-role.cfg +++ b/kamailio/nat-traversal-role.cfg @@ -1,6 +1,7 @@ ######## NAT Traversal module - signaling functions ######## #!ifndef NATHELPER_LOADED loadmodule "nathelper.so" +#!trydef NATHELPER_LOADED #!endif modparam("nathelper", "received_avp", "$avp(AVP_RECV_PARAM)") modparam("nathelper", "sipping_from", "sip:sipcheck@MY_HOSTNAME") diff --git a/kamailio/nodes-role.cfg b/kamailio/nodes-role.cfg index c3df110..8faf114 100644 --- a/kamailio/nodes-role.cfg +++ b/kamailio/nodes-role.cfg @@ -1,12 +1,7 @@ ######## Nodes role - pushes info to kazoo ######## -#!ifndef NODES_EXPIRE -#!define NODES_EXPIRE 10 -#!endif - -#!ifndef NODES_FUDGE_FACTOR -#!define NODES_FUDGE_FACTOR 10 -#!endif +#!trydef NODES_EXPIRE 10 +#!trydef NODES_FUDGE_EXPIRE 45 modparam("htable", "htable", "nodes=>size=8;initval=0;autoexpire=60"); modparam("htable", "htable", "media=>size=8;initval=0;autoexpire=60"); @@ -61,7 +56,7 @@ route(LISTENER_STATUS); #!endif $var(Roles) = $_s("Roles" : {"Proxy" : $var(listeners) $var(Dispatcher) $var(Presence) $var(Registrar)}); - $var(Payload) = '{"Event-Category" : "nodes", "Event-Name" : "advertise", "Expires" : 15000, "Used-Memory" : $(stat(real_used_size){s.int}), "Startup" : $Tb, "WhApps" : {"kamailio" : {"Startup" : $Tb }}, $var(Roles)}'; + $var(Payload) = $_s({"Event-Category" : "nodes", "Event-Name" : "advertise", "Expires" : 15000, "Used-Memory" : $(stat(real_used_size){s.int}), "Startup" : $Tb, "WhApps" : {"kamailio" : {"Startup" : $Tb }}, $var(Roles)}); kazoo_publish("nodes", "", $var(Payload)); } @@ -117,7 +112,7 @@ route[NODE_HEARTBEAT_ROUTE] route(CHECK_MEDIA_SERVERS); $sht(nodes=>$var(Node)) = $var(Payload); - $shtex(nodes=>$var(Node)) = ($(var(Payload){kz.json,Expires}{s.int}) / 1000) + NODES_FUDGE_FACTOR; + $shtex(nodes=>$var(Node)) = ($(var(Payload){kz.json,Expires}{s.int}) / 1000) + NODES_FUDGE_EXPIRE; $var(runloop) = $var(runloop) + 1; } } @@ -153,7 +148,7 @@ route[CHECK_MEDIA_SERVERS] $shtex(media=>$var(MediaUrl)::zone) = 0; route(MEDIA_SERVER_UP); }; - $var(MediaExpire) = ($(var(Payload){kz.json,Expires}{s.int}) / 1000) + NODES_FUDGE_FACTOR; + $var(MediaExpire) = ($(var(Payload){kz.json,Expires}{s.int}) / 1000) + NODES_FUDGE_EXPIRE; xlog("L_DEBUG", "nodes|media|$var(Node) media expiration $var(MediaExpire) for $var(MediaUrl)\n"); $shtex(media=>$var(MediaUrl)::count) = $var(MediaExpire); $var(ProfileIdx) = $var(ProfileIdx) + 1; @@ -198,7 +193,7 @@ route[MEDIA_SERVER_DOWN] #!ifndef NODES_CUSTOM_BINDINGS route[NODES_BINDINGS] { - $var(payload) = "{ 'exchange' : 'nodes' , 'type' : 'fanout', 'queue' : 'nodes-MY_HOSTNAME', 'exclusive' : 0, 'federate' : 1}"; + $var(payload) = $_s({"exchange" : "nodes" , "type" : "fanout", "queue" : "nodes-MY_HOSTNAME", "exclusive":0, "federate":1 }); kazoo_subscribe("$var(payload)"); } #!endif @@ -215,6 +210,12 @@ route[LISTENER_STATUS] $var(proto) = $(var(listener){kz.json,PROTO}); $var(address) = $(var(listener){kz.json,ADDRLIST.ADDR}); $var(port) = $(var(listener){kz.json,PORT}); + if($var(port) == "WS_PORT") { + $var(proto) = "ws"; + } + if($var(port) == "WSS_PORT") { + $var(proto) = "wss"; + } $var(uri) = $_s($var(proto):$var(address):$var(port)); if($(var(listener){kz.json,ADVERTISE}) != "-") { $var(advertise) = $_s( , "advertise" : "$(var(listener){kz.json,ADVERTISE})"); diff --git a/kamailio/presence_notify_sync-role.cfg b/kamailio/presence-notify.cfg similarity index 64% rename from kamailio/presence_notify_sync-role.cfg rename to kamailio/presence-notify.cfg index d8b4b8e..107f740 100644 --- a/kamailio/presence_notify_sync-role.cfg +++ b/kamailio/presence-notify.cfg @@ -6,7 +6,7 @@ kazoo.presence_notify_log_to_table = 1 descr "logs notify/reply to active_watche kazoo.presence_notify_log_to_amqp = 0 descr "logs notify/reply to amqp" kazoo.presence_notify_record_route = 1 descr "add record route header to notify msg sent" kazoo.presence_notify_log_init_body = 0 descr "logs the body before its sent" -kazoo.presence_notify_force_send_socket = 0 descr "forces the send socket to the contact" +kazoo.presence_notify_force_send_socket = 1 descr "forces the send socket to the contact" ######## Generic Hash Table container in shared memory ######## modparam("htable", "htable", "notify=>size=16;autoexpire=3600;updateexpire=1;initval=0") @@ -20,17 +20,22 @@ route[PRESENCE_LOCAL_NOTIFY] return; } t_set_fr(@cfg_get.kazoo.presence_notify_timeout, @cfg_get.kazoo.presence_notify_timeout); - xlog("L_INFO", "$ci|log|init preparing $subs(event) notify to $subs(watcher_username)@$subs(watcher_domain) on behalf of $subs(pres_uri) : $du\n"); + xlog("L_DEBUG", "$ci|log|init preparing $subs(event) notify to $subs(watcher_username)@$subs(watcher_domain) on behalf of $subs(pres_uri) : $du\n"); if(@cfg_get.kazoo.presence_notify_log_init_body == 1) { xlog("L_INFO", "$ci|log|init|body $(mb{s.escape.common}{s.replace,\','}{s.replace,$$,})\n"); } if(@cfg_get.kazoo.presence_notify_force_send_socket == 1) { $fs = $_s($(pr{s.tolower}):$(hdr(Contact){nameaddr.uri}{uri.host}):$(hdr(Contact){nameaddr.uri}{uri.port})); - xlog("L_INFO", "$ci|log|init|forcing socket to $fs, $(pr{s.tolower}):$(hdr(Contact){nameaddr.uri}{uri.host}):$(hdr(Contact){nameaddr.uri}{uri.port}) , $ct\n"); + xlog("L_DEBUG", "$ci|log|init|forcing socket to $fs, $(pr{s.tolower}):$(hdr(Contact){nameaddr.uri}{uri.host}):$(hdr(Contact){nameaddr.uri}{uri.port}) , $ct\n"); } if(@cfg_get.kazoo.presence_notify_record_route == 1) { record_route(); } + + #!ifdef SIP_TRACE_ROLE + route(SEND_SIP_TRACE); + #!endif + } modparam("mqueue","mqueue", "name=presence_last_notity") @@ -40,9 +45,10 @@ modparam("mqueue","mqueue", "name=presence_last_notity") loadmodule "rtimer.so" #!trydef RTIMER_LOADED #!endif -modparam("rtimer", "timer", "name=notifytimer;interval=500000u;mode=2;") +modparam("rtimer", "timer", "name=notifytimer;interval=500000u;mode=1;") modparam("rtimer", "exec", "timer=notifytimer;route=PRESENCE_LOG_TIMER_ROUTE") - +modparam("rtimer", "timer", "name=pres_cleanup;interval=10;mode=1;") +modparam("rtimer", "exec", "timer=pres_cleanup;route=PRESENCE_CLEANUP") event_route[presence:notify-reply] { @@ -53,13 +59,17 @@ event_route[presence:notify-reply] if($subs(reason) == "timeout") { $xavp(pres=>delete_subscription) = 1; - xlog("L_INFO", "$ci|end|deleting subscribtion $subs(pres_uri) for $subs(watcher_username)@$subs(watcher_domain) due to timeout\n"); + xlog("L_INFO", "$ci|end|deleting subscription $subs(pres_uri) for $subs(watcher_username)@$subs(watcher_domain) due to timeout\n"); } else if($notify_reply($rs) == 200) { $sht(notify=>$ci) = $null; $sht(notify=>$ci::count) = 0; xlog("L_INFO", "$ci|end|notified $subs(watcher_username)@$subs(watcher_domain) on behalf of $subs(pres_uri)\n"); + } else if($notify_reply($rs) == 481 && $subs(reason) == "timeout") { + xlog("L_INFO","$ci|end|sent subscription $hdr(Subscription-State)\n"); + } else if($notify_reply($rs) == 481) { + $xavp(pres=>delete_subscription) = 1; + xlog("L_INFO", "$ci|end|deleting subscription $subs(pres_uri) as $subs(watcher_username)@$subs(watcher_domain) replied with 481 (non existent)\n"); } else { - xlog("L_ERROR", "$ci|error|received $notify_reply($rs) when notifying $subs(watcher_username)@$subs(watcher_domain) on behalf of $subs(pres_uri)\n"); if($rP != "UDP") { $xavp(pres=>delete_subscription) = 1; xlog("L_ERROR", "$ci|error|removing $rP watcher $subs(watcher_username)@$subs(watcher_domain) for $subs(pres_uri)\n"); @@ -68,6 +78,9 @@ event_route[presence:notify-reply] if($var(shtinc) > MAX_NOTIFY_ERROR) { $xavp(pres=>delete_subscription) = 1; xlog("L_ERROR", "$ci|error|removing $rP watcher $subs(watcher_username)@$subs(watcher_domain) for $subs(pres_uri)\n"); + } else { + $var(max_notify) = MAX_NOTIFY_ERROR; + xlog("L_WARN", "$ci|error|received $notify_reply($rs) ($var(shtinc)/$var(max_notify)) when notifying $subs(watcher_username)@$subs(watcher_domain) on behalf of $subs(pres_uri)\n"); } } } @@ -81,8 +94,10 @@ event_route[presence:notify-reply] } if(@cfg_get.kazoo.presence_notify_log_to_table == 1) { - $var(Query) = $_s(REPLACE INTO active_watchers_log (presentity_uri, watcher_username, watcher_domain, event, callid, to_user, to_domain, user_agent, time, result, sent_msg, received_msg) VALUES ("$subs(uri)", "$subs(watcher_username)", "$subs(watcher_domain)", "$subs(event)","$subs(callid)","$subs(to_user)","$subs(to_domain)", '$(subs(user_agent){s.escape.common}{s.replace,\',''}{s.replace,$$,})', $TS, $notify_reply($rs), '$(mb{s.escape.common}{s.replace,\',''}{s.replace,$$,})', '$(notify_reply($mb){s.escape.common}{s.replace,\',''}{s.replace,$$,})')); - mq_add("presence_last_notity", "$subs(callid)", "$var(Query)"); + if($xavp(pres=>delete_subscription) != 1 && $subs(reason) != "timeout") { + $var(Query) = $_s(KZQ_REPLACE_WATCHERS_LOG); + mq_add("presence_last_notity", "$subs(callid)", "$var(Query)"); + } } } @@ -96,12 +111,12 @@ route[PRESENCE_LOG_TIMER_ROUTE] $var(sqlres) = sql_query("cb", "$mqv(presence_last_notity)"); xlog("L_DEBUG", "Query result : $var(sqlres)\n"); if($var(sqlres) < 0) { - xlog("L_ERROR", "$var(ci)|log|error updating active_watchers_log\n"); + xlog("L_ERROR", "$var(ci)|log|error running query : $mqv(presence_last_notity)\n"); } else { $var(nrows) = $sqlrows(cb); xlog("L_DEBUG", "$var(ci)|log|end UPDATED $var(nrows)\n"); if($var(nrows) == 0) { - xlog("L_ERROR", "$var(ci)|log|error no rows affected when updating active_watchers_log\n"); + xlog("L_DEBUG", "$var(ci)|log|error no rows affected when running query\n"); } } $var(runloop) = $var(runloop) + 1; @@ -115,3 +130,18 @@ route[PRESENCE_NOTIFY_AMQP] kazoo_publish("omnipresence", "$var(rk)", $var(amqp_payload_request)); xlog("L_INFO", "$ci|log|sent notify callback for event $subs(event) : $tu\n"); } + + +route[PRESENCE_CLEANUP] +{ + $var(Query) = $_s(DELETE FROM active_watchers WHERE expires > 0 AND datetime(expires, 'unixepoch') < datetime('now', '-90 seconds');); + mq_add("presence_last_notity", "$uuid(g)", "$var(Query)"); + $var(Query) = $_s(DELETE FROM PRESENTITY WHERE expires > 0 AND datetime(expires, 'unixepoch') < datetime('now', '-90 seconds');); + mq_add("presence_last_notity", "$uuid(g)", "$var(Query)"); + $var(Query) = $_s(DELETE FROM PRESENTITY WHERE ID IN(select id from presentities where event = "dialog" and state = "terminated" and received < datetime('now', '-5 minutes'));); + mq_add("presence_last_notity", "$uuid(g)", "$var(Query)"); + $var(Query) = $_s(DELETE FROM ACTIVE_WATCHERS_LOG WHERE ID IN(select id from active_watchers_log a where not exists(select callid from active_watchers b where b.callid = a.callid and b.watcher_username = a.watcher_username and b.watcher_domain = a.watcher_domain));); + mq_add("presence_last_notity", "$uuid(g)", "$var(Query)"); +} + +#!import_file "presence-custom-cleanup.cfg" diff --git a/kamailio/presence_query-role.cfg b/kamailio/presence-query.cfg similarity index 91% rename from kamailio/presence_query-role.cfg rename to kamailio/presence-query.cfg index ac087cc..2041cb0 100644 --- a/kamailio/presence_query-role.cfg +++ b/kamailio/presence-query.cfg @@ -56,6 +56,7 @@ route[PRESENCE_SEARCH_DETAIL] { xlog("L_INFO", "processing presence query detail for $(kzE{kz.json,Username}) in realm $(kzE{kz.json,Realm})\n"); $var(Queue) = $(kzE{kz.json,Server-ID}); + $var(Msg-ID) = $(kzE{kz.json,Msg-ID}); $var(Event) = $(kzE{kz.json,Event-Package}); $var(Domain) = $(kzE{kz.json,Realm}); $var(Username) = $(kzE{kz.json,Username}); @@ -75,14 +76,14 @@ route[PRESENCE_SEARCH_DETAIL] while($xavp(ra) != $null && $var(Event) == $xavp(ra=>event)) { $var(Sub) = $_s("$var(Username)" : {"$xavp(ra=>event)" : { "$xavp(ra=>watcher_username)" : {"kamailio@MY_HOSTNAME" : {"$xavp(ra=>callid)" : {"time" : $xavp(ra=>time), "result" : $xavp(ra=>result), "sent" : "$(xavp(ra=>sent_msg){s.escape.common}{s.replace,\','}{s.replace,$$,})", "received" : "$(xavp(ra=>received_msg){s.escape.common}{s.replace,\','}{s.replace,$$,})", "user_agent" : "$(xavp(ra=>user_agent){s.escape.common}{s.replace,\','}{s.replace,$$,})"}}}}}); xlog("L_DEBUG", "$ci| RESULT \"Subscriptions\" : { $var(Sub) }\n"); - $var(amqp_payload_request) = '{"Event-Category" : "presence", "Event-Name" : "search_partial_resp", "Msg-ID" : "$(kzE{kz.json,Msg-ID})", "Subscriptions" : { $var(Sub) } }'; + $var(amqp_payload_request) = '{"Event-Category" : "presence", "Event-Name" : "search_partial_resp", "Msg-ID" : "$var(Msg-ID)", "Subscriptions" : { $var(Sub) } }'; kazoo_publish("targeted", "$var(Queue)", $var(amqp_payload_request)); pv_unset("$xavp(ra)"); } } } - $var(amqp_payload_request) = '{"Event-Category" : "presence", "Event-Name" : "search_resp", "Msg-ID" : "$(kzE{kz.json,Msg-ID})" }'; + $var(amqp_payload_request) = '{"Event-Category" : "presence", "Event-Name" : "search_resp", "Msg-ID" : "$var(Msg-ID)" }'; kazoo_publish("targeted", "$var(Queue)", $var(amqp_payload_request)); } @@ -105,7 +106,7 @@ event_route[kazoo:consumer-event-presence-search-req] route[PRESENCE_QUERY_BINDINGS] { - $var(payload) = "{ 'exchange' : 'presence' , 'type' : 'topic', 'queue' : 'presence-search-MY_HOSTNAME', 'routing' : 'presence.search_req.*', 'exclusive' : 0, 'federate' : 1 }"; + $var(payload) = $_s({"exchange": "presence", "type": "topic", "queue": "presence-search-MY_HOSTNAME", "routing": "presence.search_req.*", "exclusive": 0, "federate": 1 }); kazoo_subscribe("$var(payload)"); } diff --git a/kamailio/presence-reset.cfg b/kamailio/presence-reset.cfg index eafd672..b450ad7 100644 --- a/kamailio/presence-reset.cfg +++ b/kamailio/presence-reset.cfg @@ -19,7 +19,7 @@ route[PRESENCE_RESET_BINDINGS] #!import_file "presence-reset-custom-bindings.cfg" #!ifndef PRESENCE_RESET_CUSTOM_BINDINGS - $var(payload) = "{ 'exchange' : 'presence' , 'queue' : 'presence-reset-MY_HOSTNAME', 'type' : 'topic', 'routing' : 'presence.reset.*.*', 'exclusive' : 0, 'federate' : 1 }"; + $var(payload) = $_s({"exchange": "presence", "queue": "presence-reset-MY_HOSTNAME", "type": "topic", "routing": "presence.reset.*.*", "exclusive": 0, "federate": 1 }); kazoo_subscribe("$var(payload)"); #!endif @@ -98,7 +98,6 @@ route[RESET_WILDCARD] } - event_route[kazoo:consumer-event-presence-reset] { if($(kzE{kz.json,Username}) == "*" || $(kzE{kz.json,Realm}) == "*") { diff --git a/kamailio/presence-role.cfg b/kamailio/presence-role.cfg index d5d4997..3ce222f 100644 --- a/kamailio/presence-role.cfg +++ b/kamailio/presence-role.cfg @@ -2,7 +2,6 @@ #!trydef PRESENCE_MIN_EXPIRES 300 #!trydef PRESENCE_MIN_EXPIRES_ACTION 1 #!trydef PRESENCE_MAX_EXPIRES 3600 - #!trydef KZ_PRESENCE_IGNORE_STATUS_PROBE_RESP 1 modparam("htable", "htable", "p=>size=32;autoexpire=3600;") @@ -24,8 +23,10 @@ modparam("presence_xml", "disable_bla", 1) modparam("presence", "subs_db_mode", 3) modparam("presence", "expires_offset", 0) modparam("presence", "send_fast_notify", 1) -modparam("presence", "clean_period", 30) -modparam("presence", "db_update_period", 10) + +modparam("presence", "clean_period", 0) +modparam("presence", "db_update_period", 0) + modparam("presence", "publ_cache", 0) modparam("presence", "min_expires_action", PRESENCE_MIN_EXPIRES_ACTION) modparam("presence", "min_expires", PRESENCE_MIN_EXPIRES) @@ -63,12 +64,10 @@ kazoo.presence_ignore_status_probe_resp = KZ_PRESENCE_IGNORE_STATUS_PROBE_RESP d #!ifdef FAST_PICKUP_ROLE #!include_file "fast-pickup-role.cfg" #!endif -#!ifdef PRESENCE_QUERY_ROLE -#!include_file "presence_query-role.cfg" -#!endif -#!ifdef PRESENCE_NOTIFY_SYNC_ROLE -#!include_file "presence_notify_sync-role.cfg" -#!endif + +#!include_file "presence-query.cfg" +#!include_file "presence-notify.cfg" +#!include_file "presence-reset.cfg" ####### Presence Logic ######## @@ -90,8 +89,25 @@ route[HANDLE_SUBSCRIBE] return; } + if ($hdr(Event) != "dialog" + && $hdr(Event) != "presence" + && $hdr(Event) != "message-summary") { + xlog("L_INFO", "$ci|presence|subscribe event $hdr(Event) not supported\n"); + send_reply(489, "Bad Event"); + exit(); + } + + if (!t_newtran()) { + sl_reply_error(); + exit; + } + + #!ifdef SIP_TRACE_ROLE + route(SEND_SIP_TRACE); + #!endif + #!ifdef NAT_TRAVERSAL_ROLE - route(PRESENCE_NAT); + route(PRESENCE_NAT); #!endif if(has_totag()) { @@ -100,11 +116,6 @@ route[HANDLE_SUBSCRIBE] record_route(); - if (!t_newtran()) { - sl_reply_error(); - exit; - } - if(has_totag()) { route(HANDLE_RESUBSCRIBE); } else { @@ -116,6 +127,11 @@ route[HANDLE_SUBSCRIBE] exit; } +route[DELETE_DUPLICATED_SUBSCRIPTIONS] +{ + sql_query("exec", '$_s(DELETE FROM ACTIVE_WATCHERS WHERE FROM_USER = "$subs(from_user)" AND FROM_DOMAIN="$subs(from_domain)" AND EVENT="$subs(event)" AND PRESENTITY_URI="$subs(uri)" AND CALLID <> "$subs(callid)")'); +} + route[HANDLE_RESUBSCRIBE] { @@ -124,7 +140,9 @@ route[HANDLE_RESUBSCRIBE] $sht(first=>$subs(callid)) = $null; $sht(first=>$subs(from_user)::$subs(pres_uri)::$subs(from_domain)::$subs(event)) = $null; } + route(DELETE_DUPLICATED_SUBSCRIPTIONS); route(SUBSCRIBE_AMQP); + route(REQUEST_PROBE); }; } @@ -164,6 +182,7 @@ route[HANDLE_NEW_SUBSCRIBE] if (handle_subscribe()) { xlog("L_INFO","$ci|end|new $hdr(Event) subscription from $fU to $tU in realm $fd : $sht(first=>$ci) : $sht(first=>$fU::$tU::$fd::$hdr(Event))\n"); + route(DELETE_DUPLICATED_SUBSCRIPTIONS); route(SUBSCRIBE_AMQP); route(REQUEST_PROBE); } else { @@ -209,26 +228,38 @@ route[REQUEST_PROBE] route[REQUEST_MWI] { - xlog("L_INFO", "$ci|sub|requesting mwi probe for $var(mwi) in realm $subs(to_domain)\n"); - $var(rk) = "mwi_queries." + $(subs(to_domain){kz.encode}); - $var(amqp_payload_request) = $_s({"Event-Category" : "presence", "Event-Name" : "mwi_query", "Username" : "$var(mwi)", "Realm" : "$fd", "Call-ID" : "$ci"}); - kazoo_publish("presence", "$var(rk)", $var(amqp_payload_request)); + xlog("L_INFO", "$ci|sub|requesting mwi probe for $var(mwi) in realm $subs(to_domain)\n"); + $var(rk) = "mwi_queries." + $(subs(to_domain){kz.encode}); + $var(amqp_payload_request) = $_s({"Event-Category" : "presence", "Event-Name" : "mwi_query", "Username" : "$var(mwi)", "Realm" : "$fd", "Call-ID" : "$ci"}); + kazoo_publish("presence", "$var(rk)", $var(amqp_payload_request)); } route[HANDLE_PUBLISH] { - if (is_method("PUBLISH")) { - if (!t_newtran()) { - sl_reply_error(); - exit; - } - if($hdr(Sender)!= $null) - handle_publish("$hdr(Sender)"); - else - handle_publish(); - t_release(); + if(!is_method("PUBLISH")) { + return; + } + + if ($hdr(Event) != "dialog" + && $hdr(Event) != "presence" + && $hdr(Event) != "message-summary") { + xlog("L_INFO", "$ci|presence|publish event $hdr(Event) not supported\n"); + send_reply(489, "Bad Event"); + exit(); + } + + if (!t_newtran()) { + sl_reply_error(); exit; } + + if($hdr(Sender)!= $null) { + handle_publish("$hdr(Sender)"); + } else { + handle_publish(); + } + t_release(); + exit; } route[HAS_PRESENTITY] @@ -248,7 +279,7 @@ route[HAS_PRESENTITY] route[COUNT_PRESENTITIES] { $var(Query) = $_s(KZQ_COUNT_PRESENTITIES); - $var(p) = $_s(uri=$var(presentity)); + $var(p) = $_s(presence_id='$var(presentity)'); if (sql_xquery("cb", "$var(Query)", "subs") == 1) { while($xavp(subs) != $null) { @@ -262,7 +293,7 @@ route[COUNT_PRESENTITIES] route[COUNT_ALL_PRESENTITIES] { $var(Query) = $_s(select event, (select count(*) from presentity b where b.event = a.event) count from event_list a); - $var(p) = "uri=none"; + $var(p) = "presence_id=none"; if (sql_xquery("cb", "$var(Query)", "subs") == 1) { while($xavp(subs) != $null) { @@ -293,7 +324,7 @@ route[COUNT_ALL_SUBSCRIBERS] route[COUNT_SUBSCRIBERS] { $var(Query) = $_s(KZQ_COUNT_SUBSCRIBERS); - $var(p) = $_s(uri=$var(presentity)); + $var(p) = $_s(presence_id='$var(presentity)'); if (sql_xquery("cb", "$var(Query)", "subs") == 1) { while($xavp(subs) != $null) { @@ -306,37 +337,40 @@ route[COUNT_SUBSCRIBERS] event_route[kazoo:consumer-event-presence-dialog-update] { - $var(Now) = $TS; - xlog("L_INFO", "$(kzE{kz.json,Call-ID})|log|received $(kzE{kz.json,Event-Package}) update for $(kzE{kz.json,From}) state $(kzE{kz.json,State}) from $(kzE{kz.json,Switch-URI}) at $(kzE{kz.json,AMQP-Received})/$var(Now)\n"); + $var(StartRoute) = $(TV(Sn){s.replace,.,}); + $var(delta_to_start) = $var(StartRoute) - $(kzE{kz.json,AMQP-Received}); + xlog("L_INFO", "$(kzE{kz.json,Call-ID})|log|received $(kzE{kz.json,Event-Package}) update for $(kzE{kz.json,From}) state $(kzE{kz.json,State}) from $(kzE{kz.json,AMQP-Broker-Zone}) => $(kzE{kz.json,Switch-URI}) (Δ1 $(kzE{kz.json,AMQP-Elapsed-Micro}) μs , Δ2 $var(delta_to_start) μs)\n"); + $var(JObj) = $kzE; #!ifdef FAST_PICKUP_ROLE route(FAST_PICKUP_INIT); #!endif - + $var(presentity) = $(kzE{kz.json,From}); $var(payload) = $kzE; - + route(PRESENCE_UPDATE); - - xlog("L_INFO", "$(kzE{kz.json,Call-ID})|log|finished processing $(kzE{kz.json,Event-Package}) update for $(kzE{kz.json,From}) state $(kzE{kz.json,State}) from $(kzE{kz.json,Switch-URI}) at $(kzE{kz.json,AMQP-Received})/$var(Now)/$TS\n"); + $var(EndRoute) = $(TV(Sn){s.replace,.,}); + $var(delta_to_finish) = $var(EndRoute) - $var(StartRoute); + + xlog("L_INFO", "$(kzE{kz.json,Call-ID})|log|finished processing $(kzE{kz.json,Event-Package}) update for $(kzE{kz.json,From}) state $(kzE{kz.json,State}) from $(kzE{kz.json,AMQP-Broker-Zone}) => $(kzE{kz.json,Switch-URI}) (Δ1 $(kzE{kz.json,AMQP-Elapsed-Micro}) μs , Δ2 $var(delta_to_start) μs, Δ3 $var(delta_to_finish) μs)\n"); } event_route[kazoo:consumer-event-presence-mwi-update] { - xlog("L_INFO", "$(kzE{kz.json,Call-ID})|log|received message-summary update for $(kzE{kz.json,From})\n"); + xlog("L_DBG", "$(kzE{kz.json,Call-ID})|log|received message-summary update for $(kzE{kz.json,From}) ($(kzE{kz.json,AMQP-Broker-Zone}))\n"); $var(presentity) = $(kzE{kz.json,From}); + $var(payload) = $kzE; route(COUNT_SUBSCRIBERS); if($xavp(watchers=>message-summary) > 0) { xlog("L_INFO", "$(kzE{kz.json,Call-ID})|log|publishing $(kzE{kz.json,From}) message-summary update for $xavp(watchers=>message-summary) watchers\n"); kazoo_pua_publish_mwi($kzE); pres_refresh_watchers("$(kzE{kz.json,From})", "message-summary", 1); - } else { - xlog("L_DEBUG", "$(kzE{kz.json,Call-ID})|log|skip message-summary update for $(kzE{kz.json,From})\n"); } route(MWI_AS_PRESENCE); - xlog("L_INFO", "$(kzE{kz.json,Call-ID})|log|finished processing message-summary update for $(kzE{kz.json,From}) light should be on ? $(kzE{kz.json,Messages-Waiting}) at $(kzE{kz.json,AMQP-Received})/$var(Now)/$TS\n"); + xlog("L_DBG", "$(kzE{kz.json,Call-ID})|log|finished processing message-summary update for $(kzE{kz.json,From}) light should be on ? $(kzE{kz.json,Messages-Waiting}) at $(kzE{kz.json,AMQP-Received})/$var(Now)/$TS\n"); } @@ -344,17 +378,18 @@ event_route[kazoo:consumer-event-presence-update] { if(@cfg_get.kazoo.presence_ignore_status_probe_resp == 1) { if($(kzE{kz.json,State}) == "offline" || $(kzE{kz.json,State}) == "online") { + xlog("L_DEBUG", "$(kzE{kz.json,Call-ID})|log|ignoring $(kzE{kz.json,State}) state $(kzE{kz.json,Presence-ID})\n"); return; } } - xlog("L_INFO", "$(kzE{kz.json,Call-ID})|log|received presence update for $(kzE{kz.json,Presence-ID})\n"); + xlog("L_DEBUG", "$(kzE{kz.json,Call-ID})|log|received presence update for $(kzE{kz.json,Presence-ID})"); $var(JObj) = $kzE; $var(presentity) = $_s(sip:$(kzE{kz.json,Presence-ID})); $var(payload) = $kzE; route(PRESENCE_UPDATE); - xlog("L_INFO", "$(kzE{kz.json,Call-ID})|log|finished processing $(kzE{kz.json,Event-Package}) update for $(kzE{kz.json,From}) state $(kzE{kz.json,State}) from $(kzE{kz.json,Switch-URI}) at $(kzE{kz.json,AMQP-Received})/$var(Now)/$TS\n"); + xlog("L_DEBUG", "$(kzE{kz.json,Call-ID})|log|finished processing $(kzE{kz.json,Event-Package}) update for $(kzE{kz.json,From}) state $(kzE{kz.json,State}) from $(kzE{kz.json,Switch-URI}) Δ at $(kzE{kz.json,AMQP-Received})/$var(Now)/$TS\n"); } route[PRESENCE_UPDATE] @@ -366,20 +401,23 @@ route[PRESENCE_UPDATE] } if($xavp(watchers=>dialog) > 0) { - xlog("L_INFO", "$(var(payload){kz.json,Call-ID})|log|publishing $var(presentity) dialog update for $xavp(watchers=>dialog) watchers\n"); - kazoo_pua_publish_dialoginfo($var(JObj)); - pres_refresh_watchers("$var(presentity)", "dialog", 1); - } else { - xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|skip dialog update for $var(presentity)\n"); + if($(var(payload){kz.json,State}) == "terminated") { + xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|publishing $var(presentity) dialog update for terminated dialog\n"); + } else { + xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|publishing $var(presentity) dialog update for $xavp(watchers=>dialog) watchers\n"); + } + if(kazoo_pua_publish_dialoginfo($var(JObj)) == 1) { + pres_refresh_watchers("$var(presentity)", "dialog", 1); + } else { + xlog("L_ERR", "$(var(payload){kz.json,Call-ID})|log|error publishing $var(presentity) dialog update\n"); + }; } if($xavp(watchers=>presence) > 0) { - xlog("L_INFO", "$(var(payload){kz.json,Call-ID})|log|publishing $var(presentity) presence update for $xavp(watchers=>presence) watchers\n"); + xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|publishing $var(presentity) presence update for $xavp(watchers=>presence) watchers\n"); kazoo_pua_publish_presence($var(payload)); pres_refresh_watchers("$var(presentity)", "presence", 1); - } else { - xlog("L_DEBUG", "$(kzE{kz.json,Call-ID})|log|skip presence update for $var(presentity)\n"); - } + } } @@ -405,38 +443,26 @@ route[MWI_AS_PRESENCE] $var(State) = "confirmed"; } else { $var(State) = "terminated"; - } + } $var(payload) = MWI_PRESENCE_BODY $var(JObj) = $var(payload); - route(PRESENCE_UPDATE); } -#!include_file "presence-reset.cfg" - route[PRESENCE_BINDINGS] { #!import_file "presence-custom-bindings.cfg" #!ifndef PRESENCE_CUSTOM_BINDINGS - $var(payload) = $_s({ "exchange" : "presence", "type" : "topic", "queue" : "presence-dialog-MY_HOSTNAME", "routing" : "dialog.*.*", "exclusive" : 0, "federate" : 1 }); - kazoo_subscribe("$var(payload)"); - - - $var(payload) = $_s({ "exchange" : "presence", "type" : "topic", "queue" : "presence-presence-MY_HOSTNAME", "routing" : "update.*.*", "exclusive" : 0, "federate" : 1 }); + $var(payload) = $_s({ "exchange" : "presence", "type" : "topic", "queue" : "presence-dialog-MY_HOSTNAME", "routing" : ["dialog.*.*", "update.*.*", "mwi_updates.*.*"], "exclusive" : 0, "federate" : 1 }); kazoo_subscribe("$var(payload)"); - $var(payload) = $_s({ "exchange" : "presence", "type" : "topic", "queue" : "presence-mwi-MY_HOSTNAME", "routing" : "mwi_updates.*.*", "exclusive" : 0 , "federate" : 1 }); - kazoo_subscribe("$var(payload)"); #!endif route(PRESENCE_RESET_BINDINGS); - - #!ifdef PRESENCE_QUERY_ROLE route(PRESENCE_QUERY_BINDINGS); - #!endif #!ifdef FAST_PICKUP_ROLE route(FAST_PICKUP_START); @@ -445,4 +471,5 @@ route[PRESENCE_BINDINGS] } + # vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab diff --git a/kamailio/pusher-role.cfg b/kamailio/pusher-role.cfg index 6097a06..a15ec68 100644 --- a/kamailio/pusher-role.cfg +++ b/kamailio/pusher-role.cfg @@ -126,6 +126,7 @@ route[PUSHER_ATTEMPT_REGISTRATION] $xavp(ulattrs=>custom_channel_vars) = "{}"; $xavp(ulattrs[0]=>x_token_reg) = $hdr(X-Token-Reg); route(SAVE_LOCATION); + exit; } else { xlog("L_INFO", "$ci|pusher|registration x-token-reg '$hdr(X-Token-Reg)' from header was not found\n"); } @@ -139,6 +140,7 @@ route[PUSHER_ATTEMPT_REGISTRATION] $xavp(ulattrs=>custom_channel_vars) = "{}"; $xavp(ulattrs[0]=>x_token_reg) = $(sel(contact.uri){uri.param,x-token-reg}); route(SAVE_LOCATION); + exit; } else { xlog("L_INFO", "$ci|pusher|registration x-token-reg from contact uri param '$(sel(contact.uri){uri.param,x-token-reg})' was not found\n"); } @@ -152,6 +154,7 @@ route[PUSHER_ATTEMPT_REGISTRATION] $xavp(ulattrs=>custom_channel_vars) = "{}"; $xavp(ulattrs[0]=>x_token_reg) = $(sel(contact){tobody.params}{param.value,x-token-reg}); route(SAVE_LOCATION); + exit; } else { xlog("L_INFO", "$ci|pusher|registration x-token-reg from contact param '$(sel(contact){tobody.params}{param.value,x-token-reg})' was not found\n"); } diff --git a/kamailio/registrar-role.cfg b/kamailio/registrar-role.cfg index 3474fd0..e5aa6fc 100644 --- a/kamailio/registrar-role.cfg +++ b/kamailio/registrar-role.cfg @@ -2,8 +2,12 @@ #!trydef REGISTRAR_NAT_PING_WORKERS 5 #!trydef REGISTRAR_MIN_EXPIRES 300 #!trydef REGISTRAR_MAX_EXPIRES 3600 +#!trydef REGISTRAR_DEFAULT_EXPIRES 600 +#!trydef REGISTRAR_ERROR_MIN_EXPIRES 1 #!trydef REGISTRAR_CONTACT_MAX_SIZE 2048 +#!trydef REGISTRAR_QUERY_TIMEOUT_MS 2500 + #!trydef REGISTRAR_HANDLE_LOST_TCP 1 #!trydef REGISTRAR_CLOSE_EXPIRED_TCP 1 @@ -17,13 +21,10 @@ modparam("htable", "htable", "auth_cache=>size=16;autoexpire=7200;") ####### Authentication Interface module ########## loadmodule "auth.so" +modparam("auth", "auth_checks_register", 11) +modparam("auth", "qop", "auth") +modparam("auth", "nonce_expire", 90) -#!ifdef OPENBTS_AUTH_ROLE -loadmodule "auth_openbts.so" -modparam("auth", "qop", "") -modparam("auth", "secret", "OPENBTS_AUTH_SECRET") -modparam("auth_openbts", "challenge_attr", "$avp(digest_challenge)") -#!endif ####### User Location Implementation module ########## loadmodule "usrloc.so" @@ -47,7 +48,7 @@ modparam("usrloc", "close_expired_tcp", REGISTRAR_CLOSE_EXPIRED_TCP) #!trydef NATHELPER_LOADED loadmodule "nathelper.so" modparam("nathelper", "natping_interval", REGISTRAR_NAT_PING_INTERVAL) -modparam("nathelper", "ping_nated_only", 0) +modparam("nathelper", "ping_nated_only", 1) modparam("nathelper", "natping_processes", REGISTRAR_NAT_PING_WORKERS) modparam("nathelper", "sipping_bflag", FLB_NATSIPPING) #!endif @@ -57,6 +58,7 @@ loadmodule "registrar.so" modparam("registrar", "received_avp", "$avp(AVP_RECV_PARAM)") modparam("registrar", "min_expires", REGISTRAR_MIN_EXPIRES) modparam("registrar", "max_expires", REGISTRAR_MAX_EXPIRES) +modparam("registrar", "default_expires", REGISTRAR_DEFAULT_EXPIRES) modparam("registrar", "xavp_cfg", "regcfg") modparam("registrar", "gruu_enabled", 1) modparam("registrar", "outbound_mode", 1) @@ -64,41 +66,52 @@ modparam("registrar", "regid_mode", 1) modparam("registrar", "path_mode", 1) modparam("registrar", "use_path", 1) modparam("registrar", "received_param", "") -##modparam("registrar", "xavp_rcd", "ulrcd") +modparam("registrar", "xavp_rcd", "ulrcd") modparam("registrar", "contact_max_size", REGISTRAR_CONTACT_MAX_SIZE) +kazoo.registrar_error_min_expires = REGISTRAR_ERROR_MIN_EXPIRES descr "send error when UAS sends expires < min-expires" + ##### handle expired registrations realtime params ##### kazoo.registrar_handle_expired_tcp = REGISTRAR_HANDLE_EXPIRED_TCP descr "handles expired tcp registrations" kazoo.registrar_handle_expired_udp = REGISTRAR_HANDLE_EXPIRED_UDP descr "handles expired udp registrations" kazoo.registrar_handle_expired_tls = REGISTRAR_HANDLE_EXPIRED_TLS descr "handles expired tls registrations" kazoo.registrar_handle_expired_ws = REGISTRAR_HANDLE_EXPIRED_WS descr "handles expired ws registrations" +kazoo.registrar_query_timeout_ms = REGISTRAR_QUERY_TIMEOUT_MS descr "timeout waiting for reply from registrar" + +kazoo.registrar_failover = 0 descr "force failover if 1" + ####### Registrar Logic ######## route[HANDLE_REGISTER] { - if (is_method("REGISTER")) { - - #!ifdef NAT_TRAVERSAL_ROLE - if (nat_uac_test("3")) { - xlog("L_INFO", "$ci|log|correcting NATed contact in registration\n"); - force_rport(); - } - fix_nated_register(); - - ## KAZOO-1846: Cisco SPA8000 freaks out on options pings - if (!($ua =~ "Linksys/SPA8000" - || $ua =~ "OpenBTS" - || $ua =~ "SIPp" - || (af==INET6) - )) { - setbflag(FLB_NATB); - setbflag(FLB_NATSIPPING); - } - #!endif + if (!is_method("REGISTER")) { + return; + } - route(ATTEMPT_AUTHORIZATION); + resetbflag(FLB_NATB); + resetbflag(FLB_NATSIPPING); + #!ifdef NAT_TRAVERSAL_ROLE + if (nat_uac_test("3")) { + xlog("L_INFO", "$ci|log|correcting NATed contact in registration\n"); + force_rport(); + } + fix_nated_register(); + + ## KAZOO-1846: Cisco SPA8000 freaks out on options pings + if (!($ua =~ "Linksys/SPA8000" + || $ua =~ "SIPp" + || (af==INET6) + )) { + setbflag(FLB_NATB); + setbflag(FLB_NATSIPPING); } + #!else + $avp(AVP_RECV_PARAM) = $su; + #!endif + + route(ATTEMPT_AUTHORIZATION); + } route[AUTHORIZATION_CHECK] @@ -120,7 +133,6 @@ route[AUTHORIZATION_CHECK] xlog("L_INFO", "$ci|log|not authorized $fu from $si:$sp\n"); send_reply("503", "Not Registered"); exit; -# route(ATTEMPT_AUTHORIZATION); } } @@ -130,106 +142,101 @@ route[ATTEMPT_AUTHORIZATION] route(PUSHER_ATTEMPT_REGISTRATION); #!endif - $var(nonce) = $(uuid(g){s.rm,-}); - #!ifdef OPENBTS_AUTH_ROLE - if($ua =~ "OpenBTS" && $sht(auth_cache=>$Au::nonce) != $null ) { - $var(nonce) = $sht(auth_cache=>$Au::nonce); - } - #!endif - $xavp(regcfg=>match_received) = $su; - if($sht(auth_cache=>$Au) != $null && registered("location", "$rz:$Au", 2, 1) == 1 && $(xavp(ulattrs=>custom_channel_vars){s.len}) > 1) { + if($sht(auth_cache=>$Au) != $null + && registered("location", "$rz:$Au", 2, 1) == 1 + && $(xavp(ulattrs=>custom_channel_vars){s.len}) > 1) + && @cfg_get.kazoo.registrar_failover == 0 { $var(password) = $sht(auth_cache=>$Au); route(SAVE_LOCATION); + exit; } - if( is_present_hf("Authorization")) { - route(KAZOO_AUTHORIZATION); + if($td =~ "[0-9]{1,3}\.[0-9]{1,3}.[0-9]{1,3}\.[0-9]{1,3}" || + $fd =~ "[0-9]{1,3}\.[0-9]{1,3}.[0-9]{1,3}\.[0-9]{1,3}") { + xlog("L_INFO", "$ci|log|register|invalid domain\n"); + drop; } - #!ifdef OPENBTS_AUTH_ROLE - if($ua =~ "OpenBTS") { - openbts_auth_challenge("$fd", "$var(nonce)"); - } else { - #!endif - auth_challenge("$fd", "0"); - #!ifdef OPENBTS_AUTH_ROLE + if (!t_newtran()) { + xlog("L_ERROR", "$ci|log|failed to create transaction to query for authentication credentials for $Au $si:$sp\n"); + drop; } - #!endif - xlog("L_INFO", "$ci|end|issued auth challenge to new registration for $fu $si:$sp\n"); - exit; -} + if($xavp(amqpc=>default::MY_AMQP_ZONE) == 0) { + xlog("L_INFO", "$ci|log|register|no amqp connection available for default worker in zone MY_AMQP_ZONE\n"); + t_drop(); + } -route[KAZOO_AUTHORIZATION] -{ - $var(nonce) = $adn; - $var(amqp_payload_request) = $_s({"Event-Category" : "directory" , "Event-Name" : "authn_req", "Method" : "REGISTER", "Auth-Nonce" : "$adn", "Auth-Realm" : "$fd", "Auth-User" : "$fU", "From" : "$fu", "To" : "$tu", "Orig-IP" : "$si", "Orig-Port" : "$sp", "User-Agent" : "$(ua{s.escape.common}{s.replace,\','}{s.replace,$$,})", "Contact" : "$(ct{s.escape.common}{s.replace,\','}{s.replace,$$,})", "Call-ID" : "$ci" }); - $var(amqp_routing_key) = "authn.req." + $(fd{kz.encode}); - $avp(kz_timeout) = 2500; - if (!t_newtran()) { - sl_reply_error(); - exit(); + if(@cfg_get.kazoo.registrar_failover == 1) { + xlog("L_INFO", "$ci|log|register|forcing failover\n"); + t_drop(); + } + + if(@cfg_get.kazoo.registrar_error_min_expires == 1) { + route(REGISTRAR_BOUNDS); } - if(kazoo_async_query("callmgr", $var(amqp_routing_key), $var(amqp_payload_request), "KAZOO_AUTHORIZATION_OK", "KAZOO_AUTHORIZATION_ERROR") != 1) { - xlog("L_INFO", "$ci|log|failed to send Kazoo query for authentication credentials for $Au $si:$sp\n"); - append_to_reply("Retry-After: 60\r\n"); - send_reply("503", "Retry Later"); + + $var(auth) = pv_auth_check("$fd", "$uuid(g)", "0", "0"); + if($var(auth) != -2) { + xlog("L_INFO", "$ci|end|challenging $Au $si:$sp\n"); + $var(auth) = auth_challenge("$fd", "21"); + if($var(auth) != 1) { + xlog("L_ERROR", "$ci|register|error creating or sending challenge to registration attempt for $fu from $si:$sp\n"); + t_drop(); + } exit; } + + $var(amqp_payload_request) = $_s({"Event-Category" : "directory" , "Event-Name" : "authn_req", "Method" : "REGISTER", "Auth-Nonce" : "$adn", "Auth-Realm" : "$fd", "Auth-User" : "$fU", "From" : "$fu", "To" : "$tu", "Orig-IP" : "$si", "Orig-Port" : "$sp", "User-Agent" : "$(ua{s.escape.common}{s.replace,\','}{s.replace,$$,})", "Contact" : "$(ct{s.escape.common}{s.replace,\','}{s.replace,$$,})", "Call-ID" : "$ci" }); + $var(amqp_routing_key) = "authn.req." + $(fd{kz.encode}); + $avp(kz_timeout) = $sel(cfg_get.kazoo.registrar_query_timeout_ms); + + sl_send_reply("100", "checking your credentials"); + + if(kazoo_async_query("callmgr", $var(amqp_routing_key), $var(amqp_payload_request), "KZ_AUTHORIZATION_OK", "KZ_AUTHORIZATION_ERROR") != 1) { + xlog("L_INFO", "$ci|log|failed to send registrar query for authentication credentials for $Au $si:$sp\n"); + t_drop(); + } } -route[KAZOO_AUTHORIZATION_OK] +failure_route[KZ_AUTHORIZATION_ERROR] { + xlog("L_INFO", "$ci|log|failed $T_reply_code to query Kazoo for authentication credentials for $Au $si:$sp\n"); + t_drop(); +} + +onreply_route[KZ_AUTHORIZATION_OK] +{ + xlog("L_INFO", "$ci|log|received $(kzR{kz.json,Event-Category}) $(kzR{kz.json,Event-Name}) reply from $(kzR{kz.json,App-Name})-$(kzR{kz.json,App-Version})\n"); $var(password) = $(kzR{kz.json,Auth-Password}); $var(nonce) = $adn; - #!ifdef OPENBTS_AUTH_ROLE - if( $(kzR{kz.json,Auth-Nonce}) != "" && $var(nonce) != $(kzR{kz.json,Auth-Nonce})) { - xlog("L_INFO", "$ci|log|nonce replace $var(nonce) with $(kzR{kz.json,Auth-Nonce})\n"); - $var(nonce) = $(kzR{kz.json,Auth-Nonce}); - $sht(auth_cache=>$Au::nonce) = $var(nonce); - } - #!endif - if( $(kzR{kz.json,Event-Name}) == "authn_err" ) { - auth_challenge("$fd", "0"); - xlog("L_INFO", "$ci|end|issued auth challenge to registration attempt for $Au $si:$sp\n"); + if( $(kzR{kz.json,Event-Name}) == "authn_err" ) { + #!ifdef ANTIFLOOD_ROLE + route(ANITFLOOD_FAILED_AUTH); + #!endif + auth_challenge("$fd", "21"); + xlog("L_INFO", "$ci|end|challenging $Au $si:$sp via $(kzR{kz.json,App-Name})-$(kzR{kz.json,App-Version}) response\n"); exit; } else { - $xavp(ulattrs=>custom_channel_vars) = $(kzR{kz.json,Custom-Channel-Vars}); - xlog("L_INFO", "$ci|log|authenticating $Au via Kazoo query response\n"); + xlog("L_INFO", "$ci|log|authenticating $Au via $(kzR{kz.json,App-Name})-$(kzR{kz.json,App-Version}) response\n"); route(CHECK_AUTHORIZATION); } } -route[KAZOO_AUTHORIZATION_ERROR] -{ - xlog("L_INFO", "$ci|log|failed to query Kazoo for authentication credentials for $Au $si:$sp\n"); - append_to_reply("Retry-After: 60\r\n"); - send_reply("503", "Retry Later"); - exit; -} + route[CHECK_AUTHORIZATION] { - if($ua =~ "OpenBTS") { - xlog("L_INFO", "$ci|end|OPENBTS attempt for $Au $si:$sp\n"); - } else { - if($var(password) == $null || $var(password) == "") { - auth_challenge("$fd", "0"); - xlog("L_INFO", "$ci|end|issued auth challenge to registration attempt for $Au $si:$sp\n"); - exit; - } - - if (!pv_auth_check("$fd", "$var(password)", "0", "0")) { - #!ifdef ANTIFLOOD_ROLE - route(ANITFLOOD_FAILED_AUTH); - #!endif + if (!pv_auth_check("$fd", "$var(password)", "0", "0")) { + #!ifdef ANTIFLOOD_ROLE + route(ANITFLOOD_FAILED_AUTH); + #!endif - auth_challenge("$fd", "0"); - xlog("L_WARNING", "$ci|end|issued auth challenge to failed registration attempt for $Au from IP $si:$sp\n"); - exit; - } + xlog("L_WARNING", "$ci|end|issuing auth challenge to failed registration attempt for $Au from IP $si:$sp\n"); + auth_challenge("$fd", "21"); + exit; } #!ifdef ANTIFLOOD_ROLE @@ -239,26 +246,23 @@ route[CHECK_AUTHORIZATION] # user authenticated - remove auth header consume_credentials(); + $xavp(ulattrs=>custom_channel_vars) = $(kzR{kz.json,Custom-Channel-Vars}); + $xavp(ulattrs[0]=>token) = $_s($(kzR{kz.json,Custom-Channel-Vars.Authorizing-ID})@$(kzR{kz.json,Custom-Channel-Vars.Account-ID})); + route(SAVE_LOCATION); } route[SAVE_LOCATION] { - if ($sht(auth_cache=>$Au) == $null) { + + if ($sht(auth_cache=>$Au) == $null && $var(password) != $null) { xlog("L_INFO", "$ci|log|caching sip credentials for $Au\n"); }; $sht(auth_cache=>$Au) = $var(password); - #!ifdef OPENBTS_AUTH_ROLE - if($ua =~ "OpenBTS") { - $sht(auth_cache=>$Au::nonce) = $var(nonce); - } - #!endif $var(save_result) = save("location", "0x04"); - if($var(save_result) == -1) { - auth_challenge("$fd", "0"); - xlog("L_INFO", "$ci|end|issued auth challenge after failed attempt to save contact for $Au $si:$sp\n"); + if($var(save_result) < 0) { exit; } else { if($var(save_result) == 1) { @@ -268,34 +272,17 @@ route[SAVE_LOCATION] } } - if((int)@contact.expires) { - $var(expires) = @contact.expires; + if($var(save_result) == 3) { + $var(expires) = 0; } else { - if(is_present_hf("Expires")) { - $var(expires) = $hdr(Expires); - } else { - $var(expires) = REGISTRAR_MIN_EXPIRES; - } + $var(expires) = $xavp(ulrcd=>expires); } -## this is what we should be using -## but ulrcd seems to have a weird leak -## if($var(save_result) == 3) { -## $var(expires) = 0; -## } else { -## $var(expires) = $xavp(ulrcd=>expires); -## } - if($var(expires) == 0) { xlog("L_INFO", "$ci|end|unregister request from $Au $si:$sp\n"); $var(Status) = "Unregistered"; } else { $var(Status) = "Registered"; - if($var(expires) < REGISTRAR_MIN_EXPIRES) { - $var(expires) = REGISTRAR_MIN_EXPIRES; - } else if($var(expires) > REGISTRAR_MAX_EXPIRES) { - $var(expires) = REGISTRAR_MAX_EXPIRES; - } } $var(ip) = $Ri; @@ -334,18 +321,17 @@ route[SAVE_LOCATION] default: $var(port) = $Rp; } - + $var(AdvIP) = $RAi; if(af==INET6) { $var(AdvIP) = "[" + $RAi + "]"; } - - $var(amqp_payload_request) = $_s({"Event-Category" : "directory", "Event-Name" : "reg_success", "Status" : "$var(Status)", "Event-Timestamp" : $TS, "Expires" : $(var(expires){s.int}), "First-Registration" : $var(new_reg), "Contact" : "$(ct{s.escape.common}{s.replace,\','}{s.replace,$$,})", "Call-ID" : "$ci", "Realm" : "$fd", "Username" : "$fU", "From-User" : "$fU", "From-Host" : "$fd", "To-User" : "$tU", "To-Host" : "$td", "User-Agent" : "$(ua{s.escape.common}{s.replace,\','}{s.replace,$$,})" , "Custom-Channel-Vars" : $xavp(ulattrs=>custom_channel_vars), "Proxy-Path" : "sip:$var(ip):$var(port)", "Proxy-Protocol" : "$proto", "Proxy-IP" : "$var(AdvIP)", "Proxy-Port" : "$RAp", "Source-IP": "$si", "Source-Port": "$sp" }); + $var(amqp_payload_request) = $_s({"Event-Category" : "directory", "Event-Name" : "reg_success", "Status" : "$var(Status)", "Event-Timestamp" : $TS, "Expires" : $(var(expires){s.int}), "First-Registration" : $var(new_reg), "Contact" : "$(ct{s.escape.common}{s.replace,\','}{s.replace,$$,})", "Call-ID" : "$ci", "Realm" : "$fd", "Username" : "$fU", "From-User" : "$fU", "From-Host" : "$fd", "To-User" : "$tU", "To-Host" : "$td", "User-Agent" : "$(ua{s.escape.common}{s.replace,\','}{s.replace,$$,})" , "Custom-Channel-Vars" : $xavp(ulattrs=>custom_channel_vars), "Proxy-Path" : "sip:MY_IP_ADDRESS:$var(port)", "Proxy-Protocol" : "$proto", "Proxy-IP" : "$var(AdvIP)", "Proxy-Port" : "$RAp", "Source-IP": "$si", "Source-Port": "$sp" }); $var(amqp_routing_key) = "registration.success." + $(fd{kz.encode}) + "." + $(fU{kz.encode}); kazoo_publish("registrar", $var(amqp_routing_key), $var(amqp_payload_request)); - xlog("L_INFO", "$ci|end|successful $(var(Status){s.tolower}) with contact : $ct\n"); + xlog("L_INFO", "$ci|end|successful $(var(Status){s.tolower}) with contact : $ct : $var(expires)\n"); #!ifdef PUSHER_ROLE route(PUSHER_ON_REGISTRATION); @@ -379,8 +365,59 @@ event_route[kazoo:consumer-event-directory-reg-flush] #!endif } +route[REGISTRAR_BINDINGS] +{ + #!import_file "registrar-custom-bindings.cfg" + + #!ifndef REGISTRAR_CUSTOM_BINDINGS + + $var(payload) = $_s({"exchange": "registrar", "type": "topic", "queue": "registrar-flush-MY_HOSTNAME", "routing": "registration.flush.*", "federate": 1 }); + kazoo_subscribe("$var(payload)"); + + #!endif + + #!ifdef REGISTRAR_SYNC_ROLE + route(REGISTRAR_SYNC_BINDINGS); + #!endif + +} + +route[REGISTRAR_BOUNDS] +{ + if((int)@contact.expires) { + $var(expires) = @contact.expires; + } else if(is_present_hf("Expires")) { + $var(expires) = $hdr(Expires); + } else if($(sel(contact){tobody.params}{param.value,expires}) != "") { + $var(expires) = $(sel(contact){tobody.params}{param.value,expires}{s.int}); + } else { + send_reply("400", "Missing Expires"); + exit; + } + + if($var(expires) != 0) { + if($var(expires) < REGISTRAR_MIN_EXPIRES) { + $var(expires) = REGISTRAR_MIN_EXPIRES; + append_to_reply("Min-Expires: $var(expires)\r\n"); + send_reply("423", "Interval Too Brief"); + exit; + } + } + +} + +## +## this needs handling logic in ecallmgr +## because we will fire the unregister from this server +## after device registers in another proxy +## causing ecallmgr to delete the registration +## from the other server +## event_route[usrloc:contact-expired] { + ## return until we handle this in ecallmr + return; + $var(transport) = $(ulc(exp=>received){uri.transport}); $var(proto) = $(ulc(exp=>socket){re.subst,/^([^:]*):(.*)/\1/}); if($var(proto) == "tls" && $var(transport) == "ws") { @@ -425,27 +462,9 @@ event_route[usrloc:contact-expired] $var(amqp_payload_request) = $_s({"Event-Category" : "directory", "Event-Name" : "reg_success", "Status" : "Unregistered", "Event-Timestamp" : $TS, "Expires" : 0, "First-Registration" : false, "Contact" : "$(ulc(exp=>addr){s.escape.common}{s.replace,\','}{s.replace,$$,})", "Call-ID" : "$ulc(exp=>callid)", "Realm" : "$var(domain)", "Username" : "$var(username)", "From-User" : "$var(username)", "From-Host" : "$var(domain)", "To-User" : "$var(username)", "To-Host" : "$var(domain)", "Proxy-Path" : "$ulc(exp=>socket)", "User-Agent" : "$(ulc(exp=>user_agent){s.escape.common}{s.replace,\','}{s.replace,$$,})"}); $var(amqp_routing_key) = "registration.success." + $(var(domain){kz.encode}) + "." + $(var(username){kz.encode}); kazoo_publish("registrar", $var(amqp_routing_key), $var(amqp_payload_request)); - xlog("L_INFO", "$ulc(exp=>callid)|expired|notified kazoo about removed registration with contact : $ulc(exp=>addr)\n"); - } else { - xlog("L_INFO", "$ulc(exp=>callid)|expired|removed registration with contact : $ulc(exp=>addr)\n"); + xlog("L_INFO", "$ulc(exp=>callid)|expired|notified registration removal with contact : $ulc(exp=>addr)\n"); } -} - -route[REGISTRAR_BINDINGS] -{ - #!import_file "registrar-custom-bindings.cfg" - - #!ifndef REGISTRAR_CUSTOM_BINDINGS - - $var(payload) = "{ 'exchange' : 'registrar' , 'type' : 'topic', 'queue' : 'registrar-flush-MY_HOSTNAME', 'routing' : 'registration.flush.*', 'federate' : 1 }"; - kazoo_subscribe("$var(payload)"); - - #!endif - - #!ifdef REGISTRAR_SYNC_ROLE - route(REGISTRAR_SYNC_BINDINGS); - #!endif - + xlog("L_INFO", "$ulc(exp=>callid)|expired|removed registration with contact : $ulc(exp=>addr)\n"); } #!ifdef REGISTRAR_SYNC_ROLE diff --git a/kamailio/websockets-role.cfg b/kamailio/websockets-role.cfg index 0f6ee8a..3d28127 100644 --- a/kamailio/websockets-role.cfg +++ b/kamailio/websockets-role.cfg @@ -1,10 +1,8 @@ tcp_accept_no_cl=yes listen=TCP_WS -listen=UDP_WS_SIP #!ifdef TLS_ROLE listen=TLS_WSS -listen=UDP_WSS_SIP #!endif ######## NAT Traversal module - signaling functions ######## diff --git a/system/sbin/kazoo-kamailio b/system/sbin/kazoo-kamailio index 9fa4e00..f8d7539 100755 --- a/system/sbin/kazoo-kamailio +++ b/system/sbin/kazoo-kamailio @@ -1,20 +1,26 @@ #!/bin/bash if [ -f /etc/default/kamailio ]; then - . /etc/default/kamailio + . /etc/default/kamailio fi if [ -f /etc/sysconfig/kamailio ]; then - . /etc/sysconfig/kamailio + . /etc/sysconfig/kamailio fi RETVAL=1 USER=${KAMAILIO_USER:-kamailio} -GROUP=${KAMAILIO_GROUP:-kamailio} +GROUP=${KAMAILIO_GROUP:-daemon} BIN_FILE=${KAMAILIO_BIN:-/usr/sbin/kamailio} PID_FILE=${KAMAILIO_PID:-/var/run/kamailio/kazoo-kamailio.pid} CFG_FILE=${KAMAILIO_CONFIG:-/etc/kazoo/kamailio/kamailio.cfg} +CFG_DIR=$(dirname ${CFG_FILE}) +export DB_SCRIPT_DIR=${KAMAILIO_DB_SCRIPT_DIR:-${CFG_DIR}/db_scripts} +export DB_LOCATION=${KAMAILIO_DB_LOCATION:-/etc/kazoo/kamailio/db} +export KAMAILIO_SHARE_DIR=${KAMAILIO_SHARE_DIR:-/usr/share/kamailio} export HOME=${KAMAILIO_HOME:-/var/run/kamailio} +RAM_DISK_SIZE=${RAM_DISK_SIZE:-256m} +RAM_DISK_ENABLED=${RAM_DISK_ENABLED:-false} SHM_MEMORY=$((`echo $SHM_MEMORY | sed -e 's/[^0-9]//g'`)) PKG_MEMORY=$((`echo $PKG_MEMORY | sed -e 's/[^0-9]//g'`)) @@ -22,159 +28,164 @@ PKG_MEMORY=$((`echo $PKG_MEMORY | sed -e 's/[^0-9]//g'`)) [ $PKG_MEMORY -le 0 ] && PKG_MEMORY=8 if test "$DUMP_CORE" = "yes" ; then - ulimit -c unlimited + ulimit -c unlimited fi prepare() { - mkdir -p /var/run/kamailio - chown -R ${USER} /var/run/kamailio - if [ -e ${PID_FILE} ]; then - rm -rf ${PID_FILE} - fi - if ram_disk_enabled; then - if ! mount_point_exists; then - if [ -f /etc/kazoo/kamailio/kazoo.db ]; then - mv /etc/kazoo/kamailio/db /etc/kazoo/kamailio/db-backup - fi - mount -t tmpfs -o size=256m tmpfs /etc/kazoo/kamailio/db - if [ -f /etc/kazoo/kamailio/db-backup/kazoo.db ]; then - cp -a /etc/kazoo/kamailio/db-backup/* /etc/kazoo/kamailio/db/ - fi - fi - fi - if [ ! -f /etc/kazoo/kamailio/db/kazoo.db ]; then + mkdir -p /var/run/kamailio + chown -R ${USER} /var/run/kamailio + if [ -e ${PID_FILE} ]; then + rm -rf ${PID_FILE} + fi + if ram_disk_enabled; then + if ! mount_point_exists; then + if [ -d ${DB_LOCATION} ]; then + mv ${DB_LOCATION} ${DB_LOCATION}/../db-backup-temp + mkdir -p ${DB_LOCATION} + fi + mount -t tmpfs -o size=${RAM_DISK_SIZE} tmpfs ${DB_LOCATION} + if [ -f ${DB_LOCATION}/../db-backup-temp/kazoo.db ]; then + cp -f ${DB_LOCATION}/../db-backup-temp/* ${DB_LOCATION}/ + fi + if [ -d ${DB_LOCATION}/../db-backup-temp ]; then + rm -rf ${DB_LOCATION}/../db-backup-temp + fi + fi + fi + if [ ! -f ${DB_LOCATION}/kazoo.db ]; then init_database - fi - chown -R ${USER} /etc/kazoo/kamailio/db - RETVAL=$? + else + check_database + fi + chown -R ${USER} ${DB_LOCATION} + RETVAL=$? } ram_disk_enabled() { - grep -e "enable_ram_disk = true" /etc/kazoo/kamailio/local.cfg &> /dev/null - return $? + + grep -e "enable_ram_disk = true" ${CFG_DIR}/local.cfg &> /dev/null + config_enabled=$? + if [[ $RAM_DISK_ENABLED -eq "true" ]] || [[ $config_enabled -eq 0 ]]; then + return 0 + else + return 1 + fi } mount_point_exists() { - mount | grep /etc/kazoo/kamailio/db &> /dev/null - return $? + mount | grep $(readlink -f ${DB_LOCATION}) &> /dev/null + return $? } init_database() { - /etc/kazoo/kamailio/db_scripts/create-kazoodb-sql.sh + ${DB_SCRIPT_DIR}/create-kazoodb-sql.sh } +check_database() { + ${DB_SCRIPT_DIR}/check-kazoodb-sql.sh +} start() { - cd ${HOME} - - check_config - check_fork - - if [ "$(whoami)" == "${USER}" ]; then - set -- ${BIN_FILE} -f ${CFG_FILE} -m ${SHM_MEMORY} -M ${PKG_MEMORY} ${EXTRA_OPTIONS} "$@" - exec "$@" - else - set -- ${BIN_FILE} -f ${CFG_FILE} -m ${SHM_MEMORY} -M ${PKG_MEMORY} -u ${USER} -g ${GROUP} ${EXTRA_OPTIONS} "$@" - runuser -s /bin/bash ${USER} -c "$*" - fi - RETVAL=$? - - if [ ${RETVAL} -ne 0 ]; then - echo "Failed to start Kamailio!" - RETVAL=1 - fi + cd ${HOME} + + check_config + check_fork + + if [ "$(whoami)" == "${USER}" ]; then + set -- ${BIN_FILE} -f ${CFG_FILE} -m ${SHM_MEMORY} -M ${PKG_MEMORY} ${EXTRA_OPTIONS} "$@" + exec "$@" + else + set -- ${BIN_FILE} -f ${CFG_FILE} -m ${SHM_MEMORY} -M ${PKG_MEMORY} -u ${USER} -g ${GROUP} ${EXTRA_OPTIONS} "$@" + runuser -s /bin/bash ${USER} -c "$*" + fi + RETVAL=$? + + if [ ${RETVAL} -ne 0 ]; then + echo "Failed to start Kamailio!" + RETVAL=1 + fi } stop() { - killall ${BIN_FILE} - RETVAL=$? - if mount_point_exists; then - if [ -f /etc/kazoo/kamailio/kazoo.db ]; then - mv /etc/kazoo/kamailio/db /etc/kazoo/kamailio/db-backup - fi - fi + killall ${BIN_FILE} + RETVAL=$? + if mount_point_exists; then + mkdir -p ${DB_LOCATION}/../db-backup + cp -f ${DB_LOCATION}/* ${DB_LOCATION}/../db-backup/ + fi } restart() { - stop - start + stop + start } reset-restart() { - cd /etc/kazoo/kamailio/dbtext/ - stop - - head -n1 active_watchers > active_watchers.tmp - mv -f active_watchers.tmp active_watchers - - head -n1 watchers > watchers.tmp - mv -f watchers.tmp watchers - - head -n1 presentity > presentity.tmp - mv -f presentity.tmp presentity + cd /etc/kazoo/kamailio/dbtext/ + stop - chown kamailio:daemon * + chown kamailio:daemon * - start + start } status() { - kamcmd dispatcher.list - RETVAL=$? + kamcmd dispatcher.list + RETVAL=$? } # Do not start kamailio if fork=no is set in the config file # otherwise the boot process will just stop check_fork () { - if grep -q "^[[:space:]]*fork[[:space:]]*=[[:space:]]*no.*" $CFG_FILE; then - echo "WARNING: fork=no specified in config file" - exit 1 - fi + if grep -q "^[[:space:]]*fork[[:space:]]*=[[:space:]]*no.*" $CFG_FILE; then + echo "WARNING: fork=no specified in config file" + exit 1 + fi } check_config () { - local ERRORS=$($BIN_FILE -c -f ${CFG_FILE} 2>&1 > /dev/null) - RETVAL=$? - - if [ ${RETVAL} -ne 0 ]; then - echo "ERROR: Invalid configuration file ${CFG_FILE}!" - echo -e "\n${ERRORS}\n" - else - echo "No errors found in ${CFG_FILE}" - fi + local ERRORS=$($BIN_FILE -c -f ${CFG_FILE} 2>&1 > /dev/null) + RETVAL=$? + + if [ ${RETVAL} -eq 0 ]; then + echo "ERROR: Invalid configuration file ${CFG_FILE}!" + echo -e "\n${ERRORS}\n" + else + echo "No errors found in ${CFG_FILE}" + fi } case "$1" in - prepare) - prepare - ;; - background) - shift - start $@ - ;; - start) - shift - start -DD $@ - ;; - stop) - stop - ;; - restart) - restart - ;; - reset-restart) - reset-restart - ;; - status) - status - ;; - check) - check_config - ;; - *) - echo $"Usage: $0 {prepare|start|background|stop|restart|reset-restart|status|check|pid}" + prepare) + prepare + ;; + background) + shift + start $@ + ;; + start) + shift + start -DD $@ + ;; + stop) + stop + ;; + restart) + restart + ;; + reset-restart) + reset-restart + ;; + status) + status + ;; + check) + check_config + ;; + *) + echo $"Usage: $0 {prepare|start|background|stop|restart|reset-restart|status|check|pid}" esac exit ${RETVAL} From fd4f453fabcfe5090a8aad2a6990060dea0a65ca Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 15 Nov 2018 01:04:07 +0000 Subject: [PATCH 002/209] fast pickup for *5, looks into *3 --- kamailio/fast-pickup-role.cfg | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/kamailio/fast-pickup-role.cfg b/kamailio/fast-pickup-role.cfg index 2714eb3..0e404ff 100644 --- a/kamailio/fast-pickup-role.cfg +++ b/kamailio/fast-pickup-role.cfg @@ -97,6 +97,15 @@ route[FAST_PICKUP_ATTEMPT] } ##### CALL-PARK #### + if($(ru{uri.user}) =~ "\*5") { + $var(park) = $_s(*3$(ru{uri.user}{s.substr,2,0})@$(ru{uri.domain})); + if($sht(park=>$var(park)) != $null) { + $du = $sht(park=>$var(park)); + xlog("L_INFO", "$ci|log|redirecting park request to $du\n"); + route(EXTERNAL_TO_INTERNAL_RELAY); + exit(); + } + } if($sht(park=>$(ru{uri.user})@$(ru{uri.domain})) != $null) { $du = $sht(park=>$(ru{uri.user})@$(ruri{uri.domain})); xlog("L_INFO", "$ci|log|redirecting park request to $du\n"); @@ -105,7 +114,7 @@ route[FAST_PICKUP_ATTEMPT] } ##### CALL-PARK IN KAZOO #### - if($(ru{uri.user}) =~ "\*[3-4]" && !($rd =~ "[0-9]{1,3}\.[0-9]{1,3}.[0-9]{1,3}\.[0-9]{1,3}") ) { + if($(ru{uri.user}) =~ "\*[3,5]" && !($rd =~ "[0-9]{1,3}\.[0-9]{1,3}.[0-9]{1,3}\.[0-9]{1,3}") ) { xlog("L_INFO", "$ci|log|checking park request to $(ru{uri.user})@$(ru{uri.domain})\n"); $var(amqp_payload_request) = '{"Event-Category" : "call_event" , "Event-Name" : "query_user_channels_req", "Username" : "$(ru{uri.user})", "Realm" : "$(ru{uri.domain})", "Active-Only" : true }'; $var(amqp_routing_key) = "call.status_req." + $(var(replaced_call_id){kz.encode}); From 5a79e6fbda6661c9bbb1b5c01a3f55d6c302120d Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 15 Nov 2018 18:07:36 +0000 Subject: [PATCH 003/209] missing files --- kamailio/custom-init.cfg | 16 ++++++++++++++++ kamailio/db_scripts/db_extra_check.sql | 23 +++++++++++++++++++++++ kamailio/presence-custom-cleanup.cfg | 15 +++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 kamailio/custom-init.cfg create mode 100644 kamailio/db_scripts/db_extra_check.sql create mode 100644 kamailio/presence-custom-cleanup.cfg diff --git a/kamailio/custom-init.cfg b/kamailio/custom-init.cfg new file mode 100644 index 0000000..e4096a1 --- /dev/null +++ b/kamailio/custom-init.cfg @@ -0,0 +1,16 @@ + +#!ifdef PRESENCE_ROLE + +######## async operations module ######## +loadmodule "async.so" +modparam("async", "workers", 5) + + +event_route[core:worker-one-init] +{ +// t_newtran(); + async_route("PRESENCE_INITIAL_CLEANUP", "20"); +// t_drop(); +## route(PRESENCE_INITIAL_CLEANUP); +} +#!endif diff --git a/kamailio/db_scripts/db_extra_check.sql b/kamailio/db_scripts/db_extra_check.sql new file mode 100644 index 0000000..5e9c9c5 --- /dev/null +++ b/kamailio/db_scripts/db_extra_check.sql @@ -0,0 +1,23 @@ + +do_db_extra_check() { + +# location +KazooDB -db ${DB_CURRENT_DB} "delete from location where socket not like 'udp:%';" +KazooDB -db ${DB_CURRENT_DB} "delete from location where expires > 0 and datetime(expires, 'unixepoch') < datetime('now', '-10 seconds');" +KazooDB -db ${DB_CURRENT_DB} "delete from location_attrs where not exists(select id from location where ruid = location_attrs.ruid);" + +## presence +KazooDB -db ${DB_CURRENT_DB} "delete from active_watchers where socket_info not like 'udp:%';" +KazooDB -db ${DB_CURRENT_DB} "delete from active_watchers where expires > 0 and datetime(expires, 'unixepoch') < datetime('now', '-10 seconds');" +KazooDB -db ${DB_CURRENT_DB} "delete from presentity where expires > 0 AND datetime(expires, 'unixepoch') < datetime('now', '-10 seconds');" +KazooDB -db ${DB_CURRENT_DB} "delete from presentity where id in(select id from presentities where state in('terminated','available'));" +KazooDB -db ${DB_CURRENT_DB} "delete from active_watchers_log where id in(select id from active_watchers_log a where not exists(select callid from active_watchers b where b.callid = a.callid and b.watcher_username = a.watcher_username and b.watcher_domain = a.watcher_domain));" +KazooDB -db ${DB_CURRENT_DB} "delete from presentity where id in(select id from presentities a where not exists(select * from active_watchers where presentity_uri = a.presentity_uri));" + +## notify watchers of pending calls +## 'create temp table as' because it will be dropped as soon as we ended the session +KazooDB -db ${DB_CURRENT_DB} "drop table if exists tmp_probe;" +KazooDB -db ${DB_CURRENT_DB} "create table tmp_probe as select distinct b.event, a.presentity_uri from presentities a inner join active_watchers b on a.presentity_uri = b.presentity_uri where state in('early', 'confirmed', 'onthephone', 'busy');" +KazooDB -db ${DB_CURRENT_DB} "delete from presentity where id in(select id from presentities where state in('early', 'confirmed', 'onthephone', 'busy'));" + +} diff --git a/kamailio/presence-custom-cleanup.cfg b/kamailio/presence-custom-cleanup.cfg new file mode 100644 index 0000000..91f6078 --- /dev/null +++ b/kamailio/presence-custom-cleanup.cfg @@ -0,0 +1,15 @@ + +route[PRESENCE_INITIAL_CLEANUP] +{ + xlog("L_INFO", "processing presence initial cleanup\n"); + if (sql_xquery("cb", "select * from tmp_probe", "ra") == 1) + { + while($xavp(ra) != $null) { + xlog("L_WARNING", "processing $xavp(ra=>event) notifies for $xavp(ra=>presentity_uri)\n"); + pres_refresh_watchers("$xavp(ra=>presentity_uri)", "$xavp(ra=>event)", 1); + pv_unset("$xavp(ra)"); + } + } +// t_release(); +// t_drop(); +} From 6c2773f929388b026235cc0de17046df243856bf Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 15 Nov 2018 23:34:29 +0000 Subject: [PATCH 004/209] keep current behaviour --- kamailio/dispatcher-role.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kamailio/dispatcher-role.cfg b/kamailio/dispatcher-role.cfg index 8dfeef2..080229c 100644 --- a/kamailio/dispatcher-role.cfg +++ b/kamailio/dispatcher-role.cfg @@ -3,7 +3,7 @@ modparam("htable", "htable", "failover=>size=16;autoexpire=120") #!trydef KZ_DISPATCHER_PROBE_MODE 1 #!trydef DISPATCHER_ADD_SERVERS 1 -#!trydef DISPATCHER_ALG 4 +#!trydef DISPATCHER_ALG 0 kazoo.dispatcher_auto_add = DISPATCHER_ADD_SERVERS descr "adds media servers reported by ecallmgr" kazoo.dispatcher_algorithm = DISPATCHER_ALG descr "dispatcher algorithm to use" From d2ae9ce20da4ac28c15f139f9aaa2a5c12e4f9a0 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 15 Nov 2018 23:47:06 +0000 Subject: [PATCH 005/209] fix comparison & return from ram_disk_enabled --- system/sbin/kazoo-kamailio | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/system/sbin/kazoo-kamailio b/system/sbin/kazoo-kamailio index f8d7539..896be10 100755 --- a/system/sbin/kazoo-kamailio +++ b/system/sbin/kazoo-kamailio @@ -65,10 +65,10 @@ ram_disk_enabled() { grep -e "enable_ram_disk = true" ${CFG_DIR}/local.cfg &> /dev/null config_enabled=$? - if [[ $RAM_DISK_ENABLED -eq "true" ]] || [[ $config_enabled -eq 0 ]]; then - return 0 - else + if [[ $RAM_DISK_ENABLED == "true" ]] || [[ $config_enabled -eq 0 ]]; then return 1 + else + return 0 fi } From 11337a4f72d203d2ae6163c156edbb96a649e75a Mon Sep 17 00:00:00 2001 From: lazedo Date: Fri, 16 Nov 2018 00:03:04 +0000 Subject: [PATCH 006/209] distraction --- kamailio/db_scripts/create-kazoodb-sql.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kamailio/db_scripts/create-kazoodb-sql.sh b/kamailio/db_scripts/create-kazoodb-sql.sh index ebfc0ae..b720415 100755 --- a/kamailio/db_scripts/create-kazoodb-sql.sh +++ b/kamailio/db_scripts/create-kazoodb-sql.sh @@ -2,7 +2,7 @@ . $(dirname $0)/kazoodb-sql.sh --source-only -$file=$(sql_db_prepare) +file=$(sql_db_prepare) echo "setting up kazoo db from init script $file" sql_setup $file From 533d6091a9ec816fe1514d63e65b5c981470b515 Mon Sep 17 00:00:00 2001 From: lazedo Date: Fri, 16 Nov 2018 00:57:59 +0000 Subject: [PATCH 007/209] mount & umount review --- system/sbin/kazoo-kamailio | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/system/sbin/kazoo-kamailio b/system/sbin/kazoo-kamailio index 896be10..04582d2 100755 --- a/system/sbin/kazoo-kamailio +++ b/system/sbin/kazoo-kamailio @@ -51,6 +51,15 @@ prepare() { rm -rf ${DB_LOCATION}/../db-backup-temp fi fi + else + if mount_point_exists; then + mkdir -p ${DB_LOCATION}/../db-backup-temp + cp -f ${DB_LOCATION}/* ${DB_LOCATION}/../db-backup-temp/ + umount ${DB_LOCATION} + rm -rf ${DB_LOCATION} + mkdir -p ${DB_LOCATION} + cp -f ${DB_LOCATION}/../db-backup-temp/* ${DB_LOCATION}/ + fi fi if [ ! -f ${DB_LOCATION}/kazoo.db ]; then init_database @@ -66,9 +75,9 @@ ram_disk_enabled() { grep -e "enable_ram_disk = true" ${CFG_DIR}/local.cfg &> /dev/null config_enabled=$? if [[ $RAM_DISK_ENABLED == "true" ]] || [[ $config_enabled -eq 0 ]]; then - return 1 - else return 0 + else + return 1 fi } @@ -146,10 +155,9 @@ check_fork () check_config () { - local ERRORS=$($BIN_FILE -c -f ${CFG_FILE} 2>&1 > /dev/null) + ERRORS="$($BIN_FILE -c -f ${CFG_FILE} -x tlsf 2>&1 > /dev/null)" RETVAL=$? - - if [ ${RETVAL} -eq 0 ]; then + if [ ${RETVAL} -ne 0 ]; then echo "ERROR: Invalid configuration file ${CFG_FILE}!" echo -e "\n${ERRORS}\n" else From 4447b82d0ceff36a7b338bc20de07fcfffca4bd2 Mon Sep 17 00:00:00 2001 From: lazedo Date: Fri, 16 Nov 2018 01:35:57 +0000 Subject: [PATCH 008/209] when querying kazoo channels for parking, use *3 so that it handles *5 --- kamailio/fast-pickup-role.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kamailio/fast-pickup-role.cfg b/kamailio/fast-pickup-role.cfg index 0e404ff..ca5398c 100644 --- a/kamailio/fast-pickup-role.cfg +++ b/kamailio/fast-pickup-role.cfg @@ -116,7 +116,7 @@ route[FAST_PICKUP_ATTEMPT] ##### CALL-PARK IN KAZOO #### if($(ru{uri.user}) =~ "\*[3,5]" && !($rd =~ "[0-9]{1,3}\.[0-9]{1,3}.[0-9]{1,3}\.[0-9]{1,3}") ) { xlog("L_INFO", "$ci|log|checking park request to $(ru{uri.user})@$(ru{uri.domain})\n"); - $var(amqp_payload_request) = '{"Event-Category" : "call_event" , "Event-Name" : "query_user_channels_req", "Username" : "$(ru{uri.user})", "Realm" : "$(ru{uri.domain})", "Active-Only" : true }'; + $var(amqp_payload_request) = '{"Event-Category" : "call_event" , "Event-Name" : "query_user_channels_req", "Username" : "*3$(ru{uri.user}{s.substr,2,0})", "Realm" : "$(ru{uri.domain})", "Active-Only" : true }'; $var(amqp_routing_key) = "call.status_req." + $(var(replaced_call_id){kz.encode}); if(kazoo_query("callevt", $var(amqp_routing_key), $var(amqp_payload_request))) { $du = $(kzR{kz.json,Channels[0].switch_url}); From df8668d79a8aa675eb704b05429bda8b03426ee5 Mon Sep 17 00:00:00 2001 From: lazedo Date: Fri, 16 Nov 2018 19:08:32 +0000 Subject: [PATCH 009/209] allow db downgrade --- kamailio/db_scripts/check-kazoodb-sql.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kamailio/db_scripts/check-kazoodb-sql.sh b/kamailio/db_scripts/check-kazoodb-sql.sh index 6db754d..959be75 100755 --- a/kamailio/db_scripts/check-kazoodb-sql.sh +++ b/kamailio/db_scripts/check-kazoodb-sql.sh @@ -15,7 +15,7 @@ DB_CURRENT_DB=${DB_LOCATION:-/etc/kazoo/kamailio}/kazoo.db DB_CURRENT_VERSION=`KazooDB -db ${DB_CURRENT_DB} "select sum(table_version) from version;"` -if [[ $DB_CURRENT_VERSION -lt $DB_VERSION ]]; then +if [[ $DB_CURRENT_VERSION -ne $DB_VERSION ]]; then echo "db required version is ${DB_VERSION}, existing version is ${DB_CURRENT_VERSION}, applying diff" KazooDB-diff --schema ${DB_CURRENT_DB} ${TEMP_DB} | KazooDB -db ${DB_CURRENT_DB} KazooDB-diff --table version ${DB_CURRENT_DB} ${TEMP_DB} | KazooDB -db ${DB_CURRENT_DB} From 93837823ae9ded1948c4758859dfd91dbb752f2a Mon Sep 17 00:00:00 2001 From: lazedo Date: Fri, 16 Nov 2018 23:24:24 +0000 Subject: [PATCH 010/209] HELP-40268 impose a maximum calls per presentity * usefull for multiple dialog in notify but it also prevents the loaded bodies from presentity to calculate final body (even on single, because we need to check the state) to fill PKG memory --- kamailio/db_queries_kazoo.cfg | 2 +- kamailio/presence-role.cfg | 44 +++++++++++++++++++++-------------- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/kamailio/db_queries_kazoo.cfg b/kamailio/db_queries_kazoo.cfg index 29801d5..cb23157 100644 --- a/kamailio/db_queries_kazoo.cfg +++ b/kamailio/db_queries_kazoo.cfg @@ -2,7 +2,7 @@ #!substdef "!KZQ_CHECK_MEDIA_SERVER_INSERT!insert into dispatcher (setid, destination) select \$var(SetId), \"\$var(MediaUrl)\" where not exists(select * from dispatcher where destination = \"\$var(MediaUrl)\")!g" #!substdef "!KZQ_COUNT_ALL_SUBSCRIBERS!select a.event, count(distinct watcher_username || \"@\" || watcher_domain) count_unique, count(*) count from event_list a, active_watchers b where b.event = a.event group by a.event!g" #!substdef "!KZQ_COUNT_PRESENTITIES!select event, (select count(*) from presentity b where username = \"\$(var(payload){kz.json,From}{uri.user})\" and domain = \"\$(var(payload){kz.json,From}{uri.domain})\" and b.event = a.event) count from event_list a!g" -#!substdef "!KZQ_COUNT_SUBSCRIBERS!select event, (select count(*) from active_watchers b where presentity_uri = \"\$var(presentity)\" and b.event = a.event) count from event_list a!g" +#!substdef "!KZQ_COUNT_SUBSCRIBERS!select event, (select count(*) from active_watchers b where presentity_uri = \"\$var(presentity)\" and b.event = a.event) count from event_list a union select \"self\", count(*) from presentities where presentity_uri = \"\$var(presentity)\"!g" #!substdef "!KZQ_EVENT_PRESENCE_RESET_DELETE!delete from presentity where domain=\"\$(kzE{kz.json,Realm})\" and username = \"\$(kzE{kz.json,Username})\"!g" #!substdef "!KZQ_HANDLE_NEW_SUBSCRIBE_DELETE1!delete from active_watchers where callid = \"\$ci\"!g" #!substdef "!KZQ_HANDLE_NEW_SUBSCRIBE_DELETE2!delete from active_watchers where watcher_username=\"\$fU\" and presentity_uri=\"\$var(presentity_uri)\" and to_user=\"\$tU\" and watcher_domain=\"\$fd\" and event=\"\$hdr(Event)\"!g" diff --git a/kamailio/presence-role.cfg b/kamailio/presence-role.cfg index 3ce222f..ab3540e 100644 --- a/kamailio/presence-role.cfg +++ b/kamailio/presence-role.cfg @@ -4,6 +4,8 @@ #!trydef PRESENCE_MAX_EXPIRES 3600 #!trydef KZ_PRESENCE_IGNORE_STATUS_PROBE_RESP 1 +#!trydef KZ_PRESENCE_MAX_CALL_PER_PRESENTITY 10 + modparam("htable", "htable", "p=>size=32;autoexpire=3600;") modparam("htable", "htable", "first=>size=32;autoexpire=3600;initval =0;updateexpire=1;") @@ -60,6 +62,7 @@ kazoo.presence_sync_amqp = KZ_PRESENCE_AMQP_PUBLISH descr "sync subscriptions to kazoo.presence_request_probe = KZ_PRESENCE_REQUEST_PROBE descr "request probe for new subscriptions" kazoo.presence_request_resubscribe_probe = KZ_PRESENCE_REQUEST_RESUBSCRIBE_PROBE descr "request probe for resubscriptions" kazoo.presence_ignore_status_probe_resp = KZ_PRESENCE_IGNORE_STATUS_PROBE_RESP descr "ignore online/offline probe replies" +kazoo.presence_max_call_per_presentity = KZ_PRESENCE_MAX_CALL_PER_PRESENTITY descr "max number of calls per presentity" #!ifdef FAST_PICKUP_ROLE #!include_file "fast-pickup-role.cfg" @@ -400,23 +403,30 @@ route[PRESENCE_UPDATE] route(COUNT_SUBSCRIBERS); } - if($xavp(watchers=>dialog) > 0) { - if($(var(payload){kz.json,State}) == "terminated") { - xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|publishing $var(presentity) dialog update for terminated dialog\n"); - } else { - xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|publishing $var(presentity) dialog update for $xavp(watchers=>dialog) watchers\n"); - } - if(kazoo_pua_publish_dialoginfo($var(JObj)) == 1) { - pres_refresh_watchers("$var(presentity)", "dialog", 1); - } else { - xlog("L_ERR", "$(var(payload){kz.json,Call-ID})|log|error publishing $var(presentity) dialog update\n"); - }; - } - - if($xavp(watchers=>presence) > 0) { - xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|publishing $var(presentity) presence update for $xavp(watchers=>presence) watchers\n"); - kazoo_pua_publish_presence($var(payload)); - pres_refresh_watchers("$var(presentity)", "presence", 1); + if($xavp(watchers=>self) > $sel(cfg_get.kazoo.presence_max_call_per_presentity) && + ( $(var(payload){kz.json,State}) == "early" || + ($(var(payload){kz.json,State}) == "confirmed" && $(var(payload){kz.json,State}) == "initiator") + )) { + xlog("L_WARN", "$(var(payload){kz.json,Call-ID})|log|not publishing state $(var(payload){kz.json,State}) for presentity $var(presentity) with $xavp(watchers=>self) calls, policy limit of $sel(cfg_get.kazoo.presence_max_call_per_presentity) calls per presentity \n"); + } else { + if($xavp(watchers=>dialog) > 0) { + if($(var(payload){kz.json,State}) == "terminated") { + xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|publishing $var(presentity) dialog update for terminated dialog\n"); + } else { + xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|publishing $var(presentity) dialog update for $xavp(watchers=>dialog) watchers\n"); + } + if(kazoo_pua_publish_dialoginfo($var(JObj)) == 1) { + pres_refresh_watchers("$var(presentity)", "dialog", 1); + } else { + xlog("L_ERR", "$(var(payload){kz.json,Call-ID})|log|error publishing $var(presentity) dialog update\n"); + }; + } + + if($xavp(watchers=>presence) > 0) { + xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|publishing $var(presentity) presence update for $xavp(watchers=>presence) watchers\n"); + kazoo_pua_publish_presence($var(payload)); + pres_refresh_watchers("$var(presentity)", "presence", 1); + } } } From 11882b6a5adbf1b9ac973ab31d48fe333c4e2d30 Mon Sep 17 00:00:00 2001 From: lazedo Date: Sat, 17 Nov 2018 12:05:54 +0000 Subject: [PATCH 011/209] remove commented lines --- kamailio/custom-init.cfg | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/kamailio/custom-init.cfg b/kamailio/custom-init.cfg index e4096a1..d4b76c2 100644 --- a/kamailio/custom-init.cfg +++ b/kamailio/custom-init.cfg @@ -8,9 +8,7 @@ modparam("async", "workers", 5) event_route[core:worker-one-init] { -// t_newtran(); async_route("PRESENCE_INITIAL_CLEANUP", "20"); -// t_drop(); -## route(PRESENCE_INITIAL_CLEANUP); } + #!endif From 7d5d95d96dcfa59c62f60020fcfc7cae18752518 Mon Sep 17 00:00:00 2001 From: lazedo Date: Sat, 17 Nov 2018 13:38:25 +0000 Subject: [PATCH 012/209] allow extensibility on custom init --- kamailio/custom-init.cfg | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/kamailio/custom-init.cfg b/kamailio/custom-init.cfg index d4b76c2..ecd73a6 100644 --- a/kamailio/custom-init.cfg +++ b/kamailio/custom-init.cfg @@ -1,6 +1,3 @@ - -#!ifdef PRESENCE_ROLE - ######## async operations module ######## loadmodule "async.so" modparam("async", "workers", 5) @@ -8,7 +5,16 @@ modparam("async", "workers", 5) event_route[core:worker-one-init] { - async_route("PRESENCE_INITIAL_CLEANUP", "20"); + async_route("DEFERRED_INIT", "20"); } -#!endif + +route[DEFERRED_INIT] +{ + xlog("L_INFO", "processing deferred init\n"); + + #!ifdef PRESENCE_ROLE + route(PRESENCE_INITIAL_CLEANUP); + #!endif + +} From 657624d775faa4c0f5940ebb9a3938a97da1e75d Mon Sep 17 00:00:00 2001 From: lazedo Date: Sat, 17 Nov 2018 13:41:03 +0000 Subject: [PATCH 013/209] deferred reload for dispatcher * when adding several media servers, reload all of them instead of reload after each insert --- kamailio/db_queries_kazoo.cfg | 2 +- kamailio/dispatcher-role.cfg | 30 +++++++++++++++++++++++------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/kamailio/db_queries_kazoo.cfg b/kamailio/db_queries_kazoo.cfg index cb23157..cf79f5c 100644 --- a/kamailio/db_queries_kazoo.cfg +++ b/kamailio/db_queries_kazoo.cfg @@ -1,5 +1,5 @@ ####### Database queries ######## -#!substdef "!KZQ_CHECK_MEDIA_SERVER_INSERT!insert into dispatcher (setid, destination) select \$var(SetId), \"\$var(MediaUrl)\" where not exists(select * from dispatcher where destination = \"\$var(MediaUrl)\")!g" +#!substdef "!KZQ_CHECK_MEDIA_SERVER_INSERT!insert into dispatcher (setid, destination, flags, attrs, description) select \$var(SetId), \"\$var(MediaUrl)\", \$var(flags), \"\$var(attrs)\", \"added by nodes role\" where not exists(select * from dispatcher where destination = \"\$var(MediaUrl)\")!g" #!substdef "!KZQ_COUNT_ALL_SUBSCRIBERS!select a.event, count(distinct watcher_username || \"@\" || watcher_domain) count_unique, count(*) count from event_list a, active_watchers b where b.event = a.event group by a.event!g" #!substdef "!KZQ_COUNT_PRESENTITIES!select event, (select count(*) from presentity b where username = \"\$(var(payload){kz.json,From}{uri.user})\" and domain = \"\$(var(payload){kz.json,From}{uri.domain})\" and b.event = a.event) count from event_list a!g" #!substdef "!KZQ_COUNT_SUBSCRIBERS!select event, (select count(*) from active_watchers b where presentity_uri = \"\$var(presentity)\" and b.event = a.event) count from event_list a union select \"self\", count(*) from presentities where presentity_uri = \"\$var(presentity)\"!g" diff --git a/kamailio/dispatcher-role.cfg b/kamailio/dispatcher-role.cfg index 080229c..432bcbe 100644 --- a/kamailio/dispatcher-role.cfg +++ b/kamailio/dispatcher-role.cfg @@ -4,6 +4,7 @@ modparam("htable", "htable", "failover=>size=16;autoexpire=120") #!trydef KZ_DISPATCHER_PROBE_MODE 1 #!trydef DISPATCHER_ADD_SERVERS 1 #!trydef DISPATCHER_ALG 0 +#!trydef KZ_DISPATCHER_ADD_FLAGS 10 kazoo.dispatcher_auto_add = DISPATCHER_ADD_SERVERS descr "adds media servers reported by ecallmgr" kazoo.dispatcher_algorithm = DISPATCHER_ALG descr "dispatcher algorithm to use" @@ -36,6 +37,15 @@ modparam("dispatcher", "ds_ping_from", "sip:sipcheck@MY_HOSTNAME") ## 10 - Presence servers (if not locally handled) ## 20 - Registrar servers (if not locally handled) + +####### RTIMER module for dispatcher reload ########## +#!ifndef RTIMER_LOADED +loadmodule "rtimer.so" +#!trydef RTIMER_LOADED +#!endif +modparam("rtimer", "timer", "name=dispatcher_reload;interval=20;mode=1;") +modparam("rtimer", "exec", "timer=dispatcher_reload;route=DISPATCHER_RELOAD") + ####### Dispatcher Logic ######## route[DISPATCHER_CLASSIFY_SOURCE] { @@ -232,21 +242,27 @@ route[DISPATCHER_CHECK_MEDIA_SERVER] if($var(Zone) != "MY_AMQP_ZONE") { $var(SetId) = 2; } - if($(var(MediaUrl){uri.port}) == 12000) { - $var(SetId) = $var(SetId) + 50; - } - $var(flags) = 10; + $var(flags) = KZ_DISPATCHER_ADD_FLAGS; $var(attrs) = $_s(zone=$var(Zone);profile=$var(MediaProfile);idx=$(var(MediaUrl){s.corehash, MEDIA_SERVERS_HASH_SIZE});node=$var(MediaName)); - sql_query("exec", "insert into dispatcher (setid, destination, flags, attrs, description) select $var(SetId), \"$var(MediaUrl)\", $var(flags), \"$var(attrs)\", \"added by nodes role\" where not exists(select * from dispatcher where destination = \"$var(MediaUrl)\")"); + #!import_file "dispatcher-custom-media-check.cfg" + sql_query("exec", "KZQ_CHECK_MEDIA_SERVER_INSERT"); if($sqlrows(exec) > 0) { - xlog("L_WARNING", "reloading dispatcher table\n"); - ds_reload(); + $shv(dispatcher_reload) = 1; return 1; } } return 0; } +route[DISPATCHER_RELOAD] +{ + if($shv(dispatcher_reload) == 1) { + xlog("L_WARNING", "reloading dispatcher table\n"); + ds_reload(); + }; + $shv(dispatcher_reload) = 0; +} + route[DISPATCHER_STATUS] { jsonrpc_exec('{"jsonrpc": "2.0", "method": "dispatcher.list", "id": 1}'); From 7e8553d1fe4082c2ee430544a6ae092dc09f31eb Mon Sep 17 00:00:00 2001 From: lazedo Date: Sat, 17 Nov 2018 13:41:26 +0000 Subject: [PATCH 014/209] remove commented code --- kamailio/presence-custom-cleanup.cfg | 2 -- 1 file changed, 2 deletions(-) diff --git a/kamailio/presence-custom-cleanup.cfg b/kamailio/presence-custom-cleanup.cfg index 91f6078..20389cf 100644 --- a/kamailio/presence-custom-cleanup.cfg +++ b/kamailio/presence-custom-cleanup.cfg @@ -10,6 +10,4 @@ route[PRESENCE_INITIAL_CLEANUP] pv_unset("$xavp(ra)"); } } -// t_release(); -// t_drop(); } From 79984514e7a436648ff3ef71778f03dd455226fe Mon Sep 17 00:00:00 2001 From: lazedo Date: Sat, 17 Nov 2018 13:49:23 +0000 Subject: [PATCH 015/209] use $sel for selectors --- kamailio/dispatcher-role.cfg | 2 +- kamailio/fast-pickup-role.cfg | 4 ++-- kamailio/presence-notify.cfg | 18 +++++++++--------- kamailio/presence-reset.cfg | 2 +- kamailio/presence-role.cfg | 8 ++++---- kamailio/registrar-role.cfg | 14 +++++++------- kamailio/sip_trace-role.cfg | 12 ++++++------ 7 files changed, 30 insertions(+), 30 deletions(-) diff --git a/kamailio/dispatcher-role.cfg b/kamailio/dispatcher-role.cfg index 432bcbe..eeb4cdb 100644 --- a/kamailio/dispatcher-role.cfg +++ b/kamailio/dispatcher-role.cfg @@ -237,7 +237,7 @@ event_route[dispatcher:dst-up] route[DISPATCHER_CHECK_MEDIA_SERVER] { - if(@cfg_get.kazoo.dispatcher_auto_add == 1) { + if($sel(cfg_get.kazoo.dispatcher_auto_add) == 1) { $var(SetId) = 1; if($var(Zone) != "MY_AMQP_ZONE") { $var(SetId) = 2; diff --git a/kamailio/fast-pickup-role.cfg b/kamailio/fast-pickup-role.cfg index ca5398c..22904a4 100644 --- a/kamailio/fast-pickup-role.cfg +++ b/kamailio/fast-pickup-role.cfg @@ -65,7 +65,7 @@ route[FAST_PICKUP_ATTEMPT] } } - if(@cfg_get.kazoo.fast_pickup_realtime == 1) { + if($sel(cfg_get.kazoo.fast_pickup_realtime) == 1) { if($var(replaced_call_id) != "none") { xlog("L_INFO", "$ci|log|request has replaces call-id $var(replaced_call_id)\n"); $var(amqp_payload_request) = '{"Event-Category" : "call_event" , "Event-Name" : "channel_status_req", "Call-ID" : "' + $var(replaced_call_id) + '", "Active-Only" : true }'; @@ -159,7 +159,7 @@ route[FAST_PICKUP_INIT] } ## fast pickup with cookies - if(@cfg_get.kazoo.fast_pickup_cookies == 1) { + if($sel(cfg_get.kazoo.fast_pickup_cookies) == 1) { if($var(AppName) == "park") { $var(Pickup) = 1; #";a-leg=true"; } else { diff --git a/kamailio/presence-notify.cfg b/kamailio/presence-notify.cfg index 107f740..59d66bc 100644 --- a/kamailio/presence-notify.cfg +++ b/kamailio/presence-notify.cfg @@ -19,16 +19,16 @@ route[PRESENCE_LOCAL_NOTIFY] if($rm != "NOTIFY") { return; } - t_set_fr(@cfg_get.kazoo.presence_notify_timeout, @cfg_get.kazoo.presence_notify_timeout); + t_set_fr($sel(cfg_get.kazoo.presence_notify_timeout), $sel(cfg_get.kazoo.presence_notify_timeout)); xlog("L_DEBUG", "$ci|log|init preparing $subs(event) notify to $subs(watcher_username)@$subs(watcher_domain) on behalf of $subs(pres_uri) : $du\n"); - if(@cfg_get.kazoo.presence_notify_log_init_body == 1) { + if($sel(cfg_get.kazoo.presence_notify_log_init_body) == 1) { xlog("L_INFO", "$ci|log|init|body $(mb{s.escape.common}{s.replace,\','}{s.replace,$$,})\n"); } - if(@cfg_get.kazoo.presence_notify_force_send_socket == 1) { + if($sel(cfg_get.kazoo.presence_notify_force_send_socket) == 1) { $fs = $_s($(pr{s.tolower}):$(hdr(Contact){nameaddr.uri}{uri.host}):$(hdr(Contact){nameaddr.uri}{uri.port})); xlog("L_DEBUG", "$ci|log|init|forcing socket to $fs, $(pr{s.tolower}):$(hdr(Contact){nameaddr.uri}{uri.host}):$(hdr(Contact){nameaddr.uri}{uri.port}) , $ct\n"); } - if(@cfg_get.kazoo.presence_notify_record_route == 1) { + if($sel(cfg_get.kazoo.presence_notify_record_route) == 1) { record_route(); } @@ -52,7 +52,7 @@ modparam("rtimer", "exec", "timer=pres_cleanup;route=PRESENCE_CLEANUP") event_route[presence:notify-reply] { - if(@cfg_get.kazoo.presence_notify != 1) + if($sel(cfg_get.kazoo.presence_notify) != 1) return; $xavp(pres=>delete_subscription) = 0; @@ -84,16 +84,16 @@ event_route[presence:notify-reply] } } } - if(@cfg_get.kazoo.presence_notify_log_body == 1) + if($sel(cfg_get.kazoo.presence_notify_log_body) == 1) xlog("L_INFO", "$ci|log|sent|body $(mb{s.escape.common}{s.replace,\','}{s.replace,$$,})\n"); - if(@cfg_get.kazoo.presence_notify_log_resp_body == 1) + if($sel(cfg_get.kazoo.presence_notify_log_resp_body) == 1) xlog("L_INFO", "$ci|log|resp|body $(notify_reply($mb){s.escape.common}{s.replace,\','}{s.replace,$$,})\n"); - if(@cfg_get.kazoo.presence_notify_log_to_amqp == 1) { + if($sel(cfg_get.kazoo.presence_notify_log_to_amqp) == 1) { route(PRESENCE_NOTIFY_AMQP); } - if(@cfg_get.kazoo.presence_notify_log_to_table == 1) { + if($sel(cfg_get.kazoo.presence_notify_log_to_table) == 1) { if($xavp(pres=>delete_subscription) != 1 && $subs(reason) != "timeout") { $var(Query) = $_s(KZQ_REPLACE_WATCHERS_LOG); mq_add("presence_last_notity", "$subs(callid)", "$var(Query)"); diff --git a/kamailio/presence-reset.cfg b/kamailio/presence-reset.cfg index b450ad7..5d6ec15 100644 --- a/kamailio/presence-reset.cfg +++ b/kamailio/presence-reset.cfg @@ -28,7 +28,7 @@ route[PRESENCE_RESET_BINDINGS] route[RESET_PUBLISHER] { xlog("L_INFO", "$var(Msg-ID)|reset|received presence reset for publisher $var(MediaUrl))\n"); - if(@cfg_get.kazoo.presence_reset_blf_defer_update == 0) { + if($sel(cfg_get.kazoo.presence_reset_blf_defer_update) == 0) { $var(Query) = $_s(KZQ_RESET_PUBLISHER_UPDATE); sql_query("exec", "$var(Query)"); } diff --git a/kamailio/presence-role.cfg b/kamailio/presence-role.cfg index ab3540e..95a0865 100644 --- a/kamailio/presence-role.cfg +++ b/kamailio/presence-role.cfg @@ -199,7 +199,7 @@ route[HANDLE_NEW_SUBSCRIBE] route[SUBSCRIBE_AMQP] { - if(@cfg_get.kazoo.presence_sync_amqp == 1) { + if($sel(cfg_get.kazoo.presence_sync_amqp) == 1) { $var(rk) = "subscribe." + $(subs(to_domain){kz.encode}) + "." + $(subs(to_user){kz.encode}); $var(amqp_payload_request) = $_s({"Event-Category" : "presence", "Event-Name" : "subscription", "Event-Package" : "$hdr(event)", "Expires" : $subs(expires), "Queue" : "BLF-MY_HOSTNAME", "Server-ID" : "BLF-MY_HOSTNAME" , "Contact" : "$(ct{s.escape.common}{s.replace,\','}{s.replace,$$,})", "Call-ID" : "$ci", "From" : "$fu", "User" : "$subs(uri)", "User-Agent" : "$(ua{s.escape.common}{s.replace,\','}{s.replace,$$,})" }); kazoo_publish("omnipresence", "$var(rk)", $var(amqp_payload_request)); @@ -208,8 +208,8 @@ route[SUBSCRIBE_AMQP] route[REQUEST_PROBE] { - if( (@cfg_get.kazoo.presence_request_probe == 1 && (!has_totag())) - || (@cfg_get.kazoo.presence_request_resubscribe_probe == 1 && has_totag()) ) { + if( ($sel(cfg_get.kazoo.presence_request_probe) == 1 && (!has_totag())) + || ($sel(cfg_get.kazoo.presence_request_resubscribe_probe) == 1 && has_totag()) ) { if( route(HAS_PRESENTITY) == 0) { if($hdr(event) == "message-summary") { $var(mwi) = $tU; @@ -379,7 +379,7 @@ event_route[kazoo:consumer-event-presence-mwi-update] event_route[kazoo:consumer-event-presence-update] { - if(@cfg_get.kazoo.presence_ignore_status_probe_resp == 1) { + if($sel(cfg_get.kazoo.presence_ignore_status_probe_resp) == 1) { if($(kzE{kz.json,State}) == "offline" || $(kzE{kz.json,State}) == "online") { xlog("L_DEBUG", "$(kzE{kz.json,Call-ID})|log|ignoring $(kzE{kz.json,State}) state $(kzE{kz.json,Presence-ID})\n"); return; diff --git a/kamailio/registrar-role.cfg b/kamailio/registrar-role.cfg index e5aa6fc..e0a2d06 100644 --- a/kamailio/registrar-role.cfg +++ b/kamailio/registrar-role.cfg @@ -146,7 +146,7 @@ route[ATTEMPT_AUTHORIZATION] if($sht(auth_cache=>$Au) != $null && registered("location", "$rz:$Au", 2, 1) == 1 && $(xavp(ulattrs=>custom_channel_vars){s.len}) > 1) - && @cfg_get.kazoo.registrar_failover == 0 { + && $sel(cfg_get.kazoo.registrar_failover) == 0 { $var(password) = $sht(auth_cache=>$Au); route(SAVE_LOCATION); exit; @@ -168,12 +168,12 @@ route[ATTEMPT_AUTHORIZATION] t_drop(); } - if(@cfg_get.kazoo.registrar_failover == 1) { + if($sel(cfg_get.kazoo.registrar_failover) == 1) { xlog("L_INFO", "$ci|log|register|forcing failover\n"); t_drop(); } - if(@cfg_get.kazoo.registrar_error_min_expires == 1) { + if($sel(cfg_get.kazoo.registrar_error_min_expires) == 1) { route(REGISTRAR_BOUNDS); } @@ -428,25 +428,25 @@ event_route[usrloc:contact-expired] { case "ws": case "wss": - if(@cfg_get.kazoo.registrar_handle_expired_ws == 1) { + if($sel(cfg_get.kazoo.registrar_handle_expired_ws) == 1) { $var(handle) = 1; } break; case "tls": - if(@cfg_get.kazoo.registrar_handle_expired_tls == 1) { + if($sel(cfg_get.kazoo.registrar_handle_expired_tls) == 1) { $var(handle) = 1; } break; case "tcp": - if(@cfg_get.kazoo.registrar_handle_expired_tcp == 1) { + if($sel(cfg_get.kazoo.registrar_handle_expired_tcp) == 1) { $var(handle) = 1; } break; case "udp": - if(@cfg_get.kazoo.registrar_handle_expired_udp == 1) { + if($sel(cfg_get.kazoo.registrar_handle_expired_udp) == 1) { $var(handle) = 1; } break; diff --git a/kamailio/sip_trace-role.cfg b/kamailio/sip_trace-role.cfg index 6fb847b..7508567 100644 --- a/kamailio/sip_trace-role.cfg +++ b/kamailio/sip_trace-role.cfg @@ -26,26 +26,26 @@ modparam("siptrace", "trace_on", KZ_TRACE) route[SIP_TRACE_INTERNAL] { - if(@cfg_get.kazoo.trace_internal == 0) { + if($sel(cfg_get.kazoo.trace_internal) == 0) { return; } - if(@cfg_get.kazoo.trace_internal_incoming == 1) { + if($sel(cfg_get.kazoo.trace_internal_incoming) == 1) { sip_trace(); } - if(@cfg_get.kazoo.trace_internal_outgoing == 1) { + if($sel(cfg_get.kazoo.trace_internal_outgoing) == 1) { setflag(FLAG_SIP_TRACE); } } route[SIP_TRACE_EXTERNAL] { - if(@cfg_get.kazoo.trace_external == 0) { + if($sel(cfg_get.kazoo.trace_external) == 0) { return; } - if(@cfg_get.kazoo.trace_external_incoming == 1) { + if($sel(cfg_get.kazoo.trace_external_incoming) == 1) { sip_trace(); } - if(@cfg_get.kazoo.trace_external_outgoing == 1) { + if($sel(cfg_get.kazoo.trace_external_outgoing) == 1) { setflag(FLAG_SIP_TRACE); } } From baf8794060eea2b5347e878d2ff2be80a318f82e Mon Sep 17 00:00:00 2001 From: lazedo Date: Sat, 17 Nov 2018 13:59:14 +0000 Subject: [PATCH 016/209] trydefs --- kamailio/defs.cfg | 48 +++++++++++++---------------------------------- 1 file changed, 13 insertions(+), 35 deletions(-) diff --git a/kamailio/defs.cfg b/kamailio/defs.cfg index 24b72ae..7581a4e 100644 --- a/kamailio/defs.cfg +++ b/kamailio/defs.cfg @@ -3,9 +3,9 @@ ####### defs ######## -#!ifndef KAZOO_LOG_LEVEL -#!define KAZOO_LOG_LEVEL L_INFO -#!endif +#!trydef KAZOO_LOG_LEVEL L_INFO + +#!trydef KZ_ASYNC_WORKERS 3 #!ifndef KAMAILIO_DBMS #!substdef "!KAMAILIO_DBMS!kazoo!g" @@ -23,52 +23,30 @@ #!substdef "!MAX_WHILE_LOOPS!500!g" #!endif -#!ifndef CHILDREN -#!define CHILDREN 25 -#!endif - -#!ifndef TCP_CHILDREN -#!define TCP_CHILDREN 25 -#!endif +#!trydef CHILDREN 25 +#!trydef TCP_CHILDREN 25 #!ifndef ANTIFLOOD_CACHE_PERIOD #!substdef "!ANTIFLOOD_CACHE_PERIOD!600!g" #!endif -#!ifndef MY_AMQP_MAX_CHANNELS -#!define MY_AMQP_MAX_CHANNELS 25 -#!endif +#!trydef MY_AMQP_MAX_CHANNELS 25 +#!trydef MY_AMQP_CONSUMER_PROCESSES 4 +#!trydef MY_AMQP_CONSUMER_WORKERS 16 +#!trydef MY_AMQP_HEARTBEATS 5 -#!ifndef MY_AMQP_CONSUMER_PROCESSES -#!define MY_AMQP_CONSUMER_PROCESSES 4 -#!endif - -#!ifndef MY_AMQP_CONSUMER_WORKERS -#!define MY_AMQP_CONSUMER_WORKERS 16 -#!endif - -#!ifndef MY_AMQP_HEARTBEATS -#!define MY_AMQP_HEARTBEATS 5 -#!endif - -#!ifndef BLF_USE_SINGLE_DIALOG -#!define BLF_USE_SINGLE_DIALOG 1 -#!endif +#!trydef BLF_USE_SINGLE_DIALOG 1 #!ifndef MY_AMQP_ZONE #!substdef "!MY_AMQP_ZONE!local!g" #!endif -#!ifndef PRESENCE_RESET_BLF_DEFER_UPDATE -#!define PRESENCE_RESET_BLF_DEFER_UPDATE 0 -#!endif +#!trydef PRESENCE_RESET_BLF_DEFER_UPDATE 0 -#!ifndef MY_AMQP_PUA_MODE #!ifdef PRESENCE_ROLE -#!define MY_AMQP_PUA_MODE 1 +#!trydef MY_AMQP_PUA_MODE 1 #!else -#!define MY_AMQP_PUA_MODE 0 -#!endif +#!trydef MY_AMQP_PUA_MODE 0 #!endif #!ifndef MEDIA_SERVERS_HASH_SIZE From a521a823fe9d51709ade8631e775d8ff48cf0088 Mon Sep 17 00:00:00 2001 From: lazedo Date: Sat, 17 Nov 2018 14:03:43 +0000 Subject: [PATCH 017/209] simplify init deferred --- kamailio/custom-init.cfg | 20 -------------------- kamailio/default.cfg | 23 ++++++++++++++++++++++- kamailio/presence-custom-cleanup.cfg | 13 ------------- kamailio/presence-notify.cfg | 13 ++++++++++++- 4 files changed, 34 insertions(+), 35 deletions(-) delete mode 100644 kamailio/custom-init.cfg delete mode 100644 kamailio/presence-custom-cleanup.cfg diff --git a/kamailio/custom-init.cfg b/kamailio/custom-init.cfg deleted file mode 100644 index ecd73a6..0000000 --- a/kamailio/custom-init.cfg +++ /dev/null @@ -1,20 +0,0 @@ -######## async operations module ######## -loadmodule "async.so" -modparam("async", "workers", 5) - - -event_route[core:worker-one-init] -{ - async_route("DEFERRED_INIT", "20"); -} - - -route[DEFERRED_INIT] -{ - xlog("L_INFO", "processing deferred init\n"); - - #!ifdef PRESENCE_ROLE - route(PRESENCE_INITIAL_CLEANUP); - #!endif - -} diff --git a/kamailio/default.cfg b/kamailio/default.cfg index 09c2d55..361575d 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -160,6 +160,10 @@ modparam("htable", "htable", "redirects=>size=16;autoexpire=5") ######## Pseudo-Variables module ######## loadmodule "pv.so" +######## async operations module ######## +loadmodule "async.so" +modparam("async", "workers", KZ_ASYNC_WORKERS) + ######## Advanced logger module ######## loadmodule "xlog.so" @@ -959,6 +963,23 @@ event_route[tm:local-request] } #!endif -#!import_file "custom-init.cfg" +event_route[core:worker-one-init] +{ + async_route("DEFERRED_INIT", "20"); +} + + +route[DEFERRED_INIT] +{ + xlog("L_INFO", "processing deferred init\n"); + + #!ifdef PRESENCE_ROLE + route(PRESENCE_INITIAL_CLEANUP); + #!endif + + #!import_file "custom-init.cfg" + +} + # vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab diff --git a/kamailio/presence-custom-cleanup.cfg b/kamailio/presence-custom-cleanup.cfg deleted file mode 100644 index 20389cf..0000000 --- a/kamailio/presence-custom-cleanup.cfg +++ /dev/null @@ -1,13 +0,0 @@ - -route[PRESENCE_INITIAL_CLEANUP] -{ - xlog("L_INFO", "processing presence initial cleanup\n"); - if (sql_xquery("cb", "select * from tmp_probe", "ra") == 1) - { - while($xavp(ra) != $null) { - xlog("L_WARNING", "processing $xavp(ra=>event) notifies for $xavp(ra=>presentity_uri)\n"); - pres_refresh_watchers("$xavp(ra=>presentity_uri)", "$xavp(ra=>event)", 1); - pv_unset("$xavp(ra)"); - } - } -} diff --git a/kamailio/presence-notify.cfg b/kamailio/presence-notify.cfg index 59d66bc..58f3ab5 100644 --- a/kamailio/presence-notify.cfg +++ b/kamailio/presence-notify.cfg @@ -144,4 +144,15 @@ route[PRESENCE_CLEANUP] mq_add("presence_last_notity", "$uuid(g)", "$var(Query)"); } -#!import_file "presence-custom-cleanup.cfg" +route[PRESENCE_INITIAL_CLEANUP] +{ + xlog("L_INFO", "processing presence initial cleanup\n"); + if (sql_xquery("cb", "select * from tmp_probe", "ra") == 1) + { + while($xavp(ra) != $null) { + xlog("L_WARNING", "processing $xavp(ra=>event) notifies for $xavp(ra=>presentity_uri)\n"); + pres_refresh_watchers("$xavp(ra=>presentity_uri)", "$xavp(ra=>event)", 1); + pv_unset("$xavp(ra)"); + } + } +} From 7a418d507d836cc95c5fb5c642885abdffd83943 Mon Sep 17 00:00:00 2001 From: lazedo Date: Sat, 17 Nov 2018 14:07:29 +0000 Subject: [PATCH 018/209] move rtimer load to default --- kamailio/default.cfg | 3 +++ kamailio/dispatcher-role.cfg | 5 ----- kamailio/nodes-role.cfg | 5 ----- kamailio/presence-notify.cfg | 5 ----- 4 files changed, 3 insertions(+), 15 deletions(-) diff --git a/kamailio/default.cfg b/kamailio/default.cfg index 361575d..c794c45 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -164,6 +164,9 @@ loadmodule "pv.so" loadmodule "async.so" modparam("async", "workers", KZ_ASYNC_WORKERS) +####### RTIMER module ########## +loadmodule "rtimer.so" + ######## Advanced logger module ######## loadmodule "xlog.so" diff --git a/kamailio/dispatcher-role.cfg b/kamailio/dispatcher-role.cfg index eeb4cdb..aecf3a0 100644 --- a/kamailio/dispatcher-role.cfg +++ b/kamailio/dispatcher-role.cfg @@ -38,11 +38,6 @@ modparam("dispatcher", "ds_ping_from", "sip:sipcheck@MY_HOSTNAME") ## 20 - Registrar servers (if not locally handled) -####### RTIMER module for dispatcher reload ########## -#!ifndef RTIMER_LOADED -loadmodule "rtimer.so" -#!trydef RTIMER_LOADED -#!endif modparam("rtimer", "timer", "name=dispatcher_reload;interval=20;mode=1;") modparam("rtimer", "exec", "timer=dispatcher_reload;route=DISPATCHER_RELOAD") diff --git a/kamailio/nodes-role.cfg b/kamailio/nodes-role.cfg index 8faf114..1976773 100644 --- a/kamailio/nodes-role.cfg +++ b/kamailio/nodes-role.cfg @@ -6,11 +6,6 @@ modparam("htable", "htable", "nodes=>size=8;initval=0;autoexpire=60"); modparam("htable", "htable", "media=>size=8;initval=0;autoexpire=60"); -####### RTIMER module ########## -#!ifndef RTIMER_LOADED -loadmodule "rtimer.so" -#!trydef RTIMER_LOADED -#!endif modparam("rtimer", "timer", "name=ta;interval=2;mode=2;") modparam("rtimer", "timer", "name=retry;interval=5;mode=2;") modparam("rtimer", "timer", "name=pub;interval=10;mode=1;") diff --git a/kamailio/presence-notify.cfg b/kamailio/presence-notify.cfg index 58f3ab5..4a33f24 100644 --- a/kamailio/presence-notify.cfg +++ b/kamailio/presence-notify.cfg @@ -40,11 +40,6 @@ route[PRESENCE_LOCAL_NOTIFY] modparam("mqueue","mqueue", "name=presence_last_notity") -####### RTIMER module ########## -#!ifndef RTIMER_LOADED -loadmodule "rtimer.so" -#!trydef RTIMER_LOADED -#!endif modparam("rtimer", "timer", "name=notifytimer;interval=500000u;mode=1;") modparam("rtimer", "exec", "timer=notifytimer;route=PRESENCE_LOG_TIMER_ROUTE") modparam("rtimer", "timer", "name=pres_cleanup;interval=10;mode=1;") From cd91a270562f1357a8c6a57b79a210413d7268f3 Mon Sep 17 00:00:00 2001 From: lazedo Date: Mon, 19 Nov 2018 14:49:12 +0000 Subject: [PATCH 019/209] use evrexec for deferred init --- kamailio/default.cfg | 16 +++++----------- kamailio/defs.cfg | 2 -- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/kamailio/default.cfg b/kamailio/default.cfg index c794c45..7591f31 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -160,13 +160,13 @@ modparam("htable", "htable", "redirects=>size=16;autoexpire=5") ######## Pseudo-Variables module ######## loadmodule "pv.so" -######## async operations module ######## -loadmodule "async.so" -modparam("async", "workers", KZ_ASYNC_WORKERS) - ####### RTIMER module ########## loadmodule "rtimer.so" +####### evrexec module ########## +loadmodule "evrexec.so" +modparam("evrexec", "exec", "name=evrexec:DEFERRED_INIT;wait=20000000;workers=1;") + ######## Advanced logger module ######## loadmodule "xlog.so" @@ -966,13 +966,7 @@ event_route[tm:local-request] } #!endif -event_route[core:worker-one-init] -{ - async_route("DEFERRED_INIT", "20"); -} - - -route[DEFERRED_INIT] +event_route[evrexec:DEFERRED_INIT] { xlog("L_INFO", "processing deferred init\n"); diff --git a/kamailio/defs.cfg b/kamailio/defs.cfg index 7581a4e..325e32d 100644 --- a/kamailio/defs.cfg +++ b/kamailio/defs.cfg @@ -5,8 +5,6 @@ #!trydef KAZOO_LOG_LEVEL L_INFO -#!trydef KZ_ASYNC_WORKERS 3 - #!ifndef KAMAILIO_DBMS #!substdef "!KAMAILIO_DBMS!kazoo!g" #!endif From 43eae1cdfba4b1ac475e465ecff87f01adee403d Mon Sep 17 00:00:00 2001 From: lazedo Date: Mon, 19 Nov 2018 18:41:58 +0000 Subject: [PATCH 020/209] remove stale indication on challenge --- kamailio/registrar-role.cfg | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kamailio/registrar-role.cfg b/kamailio/registrar-role.cfg index e0a2d06..d8332ed 100644 --- a/kamailio/registrar-role.cfg +++ b/kamailio/registrar-role.cfg @@ -215,7 +215,7 @@ onreply_route[KZ_AUTHORIZATION_OK] #!ifdef ANTIFLOOD_ROLE route(ANITFLOOD_FAILED_AUTH); #!endif - auth_challenge("$fd", "21"); + auth_challenge("$fd", "5"); xlog("L_INFO", "$ci|end|challenging $Au $si:$sp via $(kzR{kz.json,App-Name})-$(kzR{kz.json,App-Version}) response\n"); exit; } else { @@ -235,7 +235,7 @@ route[CHECK_AUTHORIZATION] #!endif xlog("L_WARNING", "$ci|end|issuing auth challenge to failed registration attempt for $Au from IP $si:$sp\n"); - auth_challenge("$fd", "21"); + auth_challenge("$fd", "5"); exit; } From a342f6f21e898935782fba9763691e7cd815e3b6 Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 20 Nov 2018 19:04:06 +0000 Subject: [PATCH 021/209] check ramdisk size and ensure minimum free space --- system/sbin/kazoo-kamailio | 75 +++++++++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 2 deletions(-) diff --git a/system/sbin/kazoo-kamailio b/system/sbin/kazoo-kamailio index 04582d2..78be345 100755 --- a/system/sbin/kazoo-kamailio +++ b/system/sbin/kazoo-kamailio @@ -20,6 +20,7 @@ export DB_LOCATION=${KAMAILIO_DB_LOCATION:-/etc/kazoo/kamailio/db} export KAMAILIO_SHARE_DIR=${KAMAILIO_SHARE_DIR:-/usr/share/kamailio} export HOME=${KAMAILIO_HOME:-/var/run/kamailio} RAM_DISK_SIZE=${RAM_DISK_SIZE:-256m} +RAM_DISK_FREE_SIZE_PERC=${RAM_DISK_FREE_SIZE:-30} RAM_DISK_ENABLED=${RAM_DISK_ENABLED:-false} SHM_MEMORY=$((`echo $SHM_MEMORY | sed -e 's/[^0-9]//g'`)) @@ -39,10 +40,15 @@ prepare() { fi if ram_disk_enabled; then if ! mount_point_exists; then + if [ -d ${DB_LOCATION}/../db-backup-temp ]; then + rm -rf ${DB_LOCATION}/../db-backup-temp + fi if [ -d ${DB_LOCATION} ]; then - mv ${DB_LOCATION} ${DB_LOCATION}/../db-backup-temp - mkdir -p ${DB_LOCATION} + mkdir -p ${DB_LOCATION}/../db-backup-temp + cp -f ${DB_LOCATION}/* ${DB_LOCATION}/../db-backup-temp/ + rm -rf ${DB_LOCATION} fi + mkdir -p ${DB_LOCATION} mount -t tmpfs -o size=${RAM_DISK_SIZE} tmpfs ${DB_LOCATION} if [ -f ${DB_LOCATION}/../db-backup-temp/kazoo.db ]; then cp -f ${DB_LOCATION}/../db-backup-temp/* ${DB_LOCATION}/ @@ -50,9 +56,47 @@ prepare() { if [ -d ${DB_LOCATION}/../db-backup-temp ]; then rm -rf ${DB_LOCATION}/../db-backup-temp fi + else + ### check ramdisk size + mountcurrentsize=$(mount_point_size) + mountwantedsize=$(convert_size ${RAM_DISK_SIZE}) + if [ $mountcurrentsize -lt $mountwantedsize ]; then + echo "current size is $mountcurrentsize is below wanted size of $mountwantedsize, remounting" + rm -rf ${DB_LOCATION}/../db-backup-temp + mkdir -p ${DB_LOCATION}/../db-backup-temp + cp -f ${DB_LOCATION}/* ${DB_LOCATION}/../db-backup-temp/ + umount ${DB_LOCATION} + rm -rf ${DB_LOCATION} + mkdir -p ${DB_LOCATION} + mount -t tmpfs -o size=${RAM_DISK_SIZE} tmpfs ${DB_LOCATION} + cp -f ${DB_LOCATION}/../db-backup-temp/* ${DB_LOCATION}/ + rm -rf ${DB_LOCATION}/../db-backup-temp + elif [ $mountcurrentsize -gt $mountwantedsize ]; then + # check if it fits + echo "wanted size of $mountwantedsize is below current size of $mountcurrentsize , remounting" + mountusedsize=$(mount_point_used_size) + requiredsize=$(( mountusedsize * (100 + ${RAM_DISK_FREE_SIZE_PERC}) / 100)) + if [ $requiredsize -gt $mountwantedsize ]; then + echo "wanted size of $mountwantedsize doesn't have enough space for required size of $requiredsize , setting to $requiredsize" + mountwantedsize=$requiredsize + fi + echo "resizing from $mountcurrentsize to $mountwantedsize" + rm -rf ${DB_LOCATION}/../db-backup-temp + mkdir -p ${DB_LOCATION}/../db-backup-temp + cp -f ${DB_LOCATION}/* ${DB_LOCATION}/../db-backup-temp/ + umount ${DB_LOCATION} + rm -rf ${DB_LOCATION} + mkdir -p ${DB_LOCATION} + mount -t tmpfs -o size=$mountwantedsize tmpfs ${DB_LOCATION} + cp -f ${DB_LOCATION}/../db-backup-temp/* ${DB_LOCATION}/ + rm -rf ${DB_LOCATION}/../db-backup-temp + fi fi else if mount_point_exists; then + if [ -d ${DB_LOCATION}/../db-backup-temp ]; then + rm -rf ${DB_LOCATION}/../db-backup-temp + fi mkdir -p ${DB_LOCATION}/../db-backup-temp cp -f ${DB_LOCATION}/* ${DB_LOCATION}/../db-backup-temp/ umount ${DB_LOCATION} @@ -86,6 +130,33 @@ mount_point_exists() { return $? } +mount_point_size() { + echo $(df --block-size=1 | grep $(readlink -f ${DB_LOCATION}) | tr -s ' ' | cut -d ' ' --fields=2) +} + +mount_point_used_size() { + echo $(df --block-size=1 | grep $(readlink -f ${DB_LOCATION}) | tr -s ' ' | cut -d ' ' --fields=3) +} + +mount_point_free_size() { + echo $(df --block-size=1 | grep $(readlink -f ${DB_LOCATION}) | tr -s ' ' | cut -d ' ' --fields=4) +} + +convert_size() { + echo "$1" | awk \ + 'BEGIN{IGNORECASE = 1} + function printpower(n,b,p) {printf "%u\n", n*b^p; next} + /[0-9]$/{print $1;next}; + /K(iB)?$/{printpower($1, 2, 10)}; + /M(iB)?$/{printpower($1, 2, 20)}; + /G(iB)?$/{printpower($1, 2, 30)}; + /T(iB)?$/{printpower($1, 2, 40)}; + /KB$/{ printpower($1, 10, 3)}; + /MB$/{ printpower($1, 10, 6)}; + /GB$/{ printpower($1, 10, 9)}; + /TB$/{ printpower($1, 10, 12)}' +} + init_database() { ${DB_SCRIPT_DIR}/create-kazoodb-sql.sh } From a15ec5a060f67fa98fa3ef130a7723af7cc9686a Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 21 Nov 2018 10:00:37 +0000 Subject: [PATCH 022/209] use proper variable for resetting associations --- kamailio/dispatcher-role.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kamailio/dispatcher-role.cfg b/kamailio/dispatcher-role.cfg index aecf3a0..b8d9596 100644 --- a/kamailio/dispatcher-role.cfg +++ b/kamailio/dispatcher-role.cfg @@ -121,7 +121,7 @@ route[DISPATCHER_FIND_ROUTES] $var(prefered_route) = $sht(associations=>$var(user_source)); xlog("L_INFO", "$ci|log|found association for contact uri $var(user_source)\n"); if (!route(DISPATCHER_REORDER_ROUTES)) { - $sht(associations=>$var(association)) = $null; + $sht(associations=>$var(user_source)) = $null; } } } From a883c275911e3ab50a0a8f7081c6cd32162185a7 Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 21 Nov 2018 10:18:24 +0000 Subject: [PATCH 023/209] indentation & remove rr in handle_in_dialog, settings for rr --- kamailio/default.cfg | 96 +++++++++++++++++++++++--------------------- kamailio/defs.cfg | 4 ++ 2 files changed, 54 insertions(+), 46 deletions(-) diff --git a/kamailio/default.cfg b/kamailio/default.cfg index 7591f31..af3ace8 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -132,8 +132,9 @@ loadmodule "sl.so" ######## Record-Route and Route module ######## loadmodule "rr.so" -modparam("rr", "enable_full_lr", 1) -modparam("rr", "enable_double_rr", 1) +modparam("rr", "enable_full_lr", RR_FULL_LR) +modparam("rr", "enable_double_rr", RR_DOUBLE_RR) +modparam("rr", "force_send_socket", RR_FORCE_SOCKET) ######## Max-Forward processor module ######## loadmodule "maxfwd.so" @@ -172,6 +173,9 @@ loadmodule "xlog.so" ######## UAC ######## loadmodule "uac.so" +modparam("uac","restore_mode","manual") +modparam("uac","restore_from_avp","$avp(original_uri_from)") +modparam("uac","restore_to_avp","$avp(original_uri_to)") ######## AVP's ######## loadmodule "avp.so" @@ -456,8 +460,7 @@ route[HANDLE_OPTIONS] route[HANDLE_NOTIFY] { - if (has_totag()) - return; + if (has_totag()) return; if (is_method("NOTIFY")) { if (isflagset(FLAG_INTERNALLY_SOURCED)) { @@ -545,51 +548,52 @@ route[HANDLE_MESSAGE] route[HANDLE_IN_DIALOG_REQUESTS] { - if (has_totag()) { - if (is_method("INVITE")) { - setflag(FLAG_SESSION_PROGRESS); - record_route(); - } - if (loose_route()) { + if (!has_totag()) return; + + if (is_method("INVITE")) { + setflag(FLAG_SESSION_PROGRESS); +# record_route(); + } - #!ifdef ACCOUNTING_ROLE - if (is_method("BYE")) { - setflag(FLAG_ACC); - setflag(FLAG_ACCFAILED); - } - #!endif + if (loose_route()) { - #!ifdef NAT_TRAVERSAL_ROLE - if(!isdsturiset()) { - handle_ruri_alias(); - } - #!endif + #!ifdef ACCOUNTING_ROLE + if (is_method("BYE")) { + setflag(FLAG_ACC); + setflag(FLAG_ACCFAILED); + } + #!endif - xlog("L_INFO", "$ci|log|loose_route in-dialog message\n"); - # Called on in-dialog requests - # If the request in an Invite for on hold from external to internal, - # associate the contact with the media server - # if Invite for on hold, we need to associate the contact URI with the next hop - if (is_method("INVITE") && !isflagset(FLAG_INTERNALLY_SOURCED) && is_audio_on_hold()) { - setflag(FLAG_ASSOCIATE_USER); - } - if ( is_method("NOTIFY") ) { - # Add Record-Route for in-dialog NOTIFY as per RFC 6665. - record_route(); - } - route(RELAY); - } else if (isflagset(FLAG_INTERNALLY_SOURCED)) { - xlog("L_INFO", "$ci|log|relay internally sourced in-dialog message without loose_route\n"); - route(RELAY); - } else if (t_check_trans()) { - xlog("L_INFO", "$ci|log|allow message for a known transaction\n"); - route(RELAY); - } else { - xlog("L_INFO", "$ci|log|message had a to-tag but can't be loose routed\n"); - sl_send_reply("481", "Call Leg/Transaction Does Not Exist"); + #!ifdef NAT_TRAVERSAL_ROLE + if(!isdsturiset()) { + handle_ruri_alias(); } - exit(); + #!endif + + xlog("L_INFO", "$ci|log|loose_route in-dialog message\n"); + # Called on in-dialog requests + # If the request in an Invite for on hold from external to internal, + # associate the contact with the media server + # if Invite for on hold, we need to associate the contact URI with the next hop + if (is_method("INVITE") && !isflagset(FLAG_INTERNALLY_SOURCED) && is_audio_on_hold()) { + setflag(FLAG_ASSOCIATE_USER); + } + if ( is_method("NOTIFY") ) { + # Add Record-Route for in-dialog NOTIFY as per RFC 6665. + record_route(); + } + route(RELAY); + } else if (isflagset(FLAG_INTERNALLY_SOURCED)) { + xlog("L_INFO", "$ci|log|relay internally sourced in-dialog message without loose_route\n"); + route(RELAY); + } else if (t_check_trans()) { + xlog("L_INFO", "$ci|log|allow message for a known transaction\n"); + route(RELAY); + } else { + xlog("L_INFO", "$ci|log|message had a to-tag but can't be loose routed\n"); + sl_send_reply("481", "Call Leg/Transaction Does Not Exist"); } + exit(); } route[PREPARE_INITIAL_REQUESTS] @@ -718,8 +722,8 @@ route[EXTERNAL_TO_INTERNAL_RELAY] append_hf("X-AUTH-IP: $si\r\n"); append_hf("X-AUTH-PORT: $sp\r\n"); - #!ifdef REGISTRAR_ROLE - route(ADD_AUTHORIZATION_HEADERS); + #!ifdef REGISTRAR_ROLE + route(ADD_AUTHORIZATION_HEADERS); #!endif t_on_reply("INTERNAL_REPLY"); diff --git a/kamailio/defs.cfg b/kamailio/defs.cfg index 325e32d..f7eb69e 100644 --- a/kamailio/defs.cfg +++ b/kamailio/defs.cfg @@ -60,6 +60,10 @@ #!substdef "!NAT_UAC_TEST_LEVEL!3!g" #!endif +#!trydef RR_FULL_LR 1 +#!trydef RR_DOUBLE_RR 1 +#!trydef RR_FORCE_SOCKET 1 + ################################# ## Defs related to SIP_TRACE_ROLE ## From 001fe85dd6298b19ef57e88fc76a69a8fe717e1c Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 21 Nov 2018 11:05:14 +0000 Subject: [PATCH 024/209] mhomed as a #!trydef --- kamailio/default.cfg | 3 +++ kamailio/defs.cfg | 13 ------------- kamailio/local.cfg | 3 ++- 3 files changed, 5 insertions(+), 14 deletions(-) diff --git a/kamailio/default.cfg b/kamailio/default.cfg index af3ace8..aa6427e 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -88,6 +88,9 @@ dns_srv_lb = off ####### SCTP Parameters ######### disable_sctp = yes +####### multi homed ######### +mhomed=KZ_MULTI_HOMED + ######## Kamailio mqueue module ######## loadmodule "mqueue.so" diff --git a/kamailio/defs.cfg b/kamailio/defs.cfg index f7eb69e..426f711 100644 --- a/kamailio/defs.cfg +++ b/kamailio/defs.cfg @@ -104,19 +104,6 @@ #!trydef KZ_TLS_REGISTRAR_PORT 7000 #!endif -################################################################################ -## BINDINGS -################################################################################ -## This parameter is OPTIONAL. -## It will try to locate outbound interface -## on multihomed host. By default forward -## requests use the incoming socket disregarding -## the destination location. When enabled Kamailio -## will select a socket that can reach the -## destination. This reduces performance. -mhomed=KZ_MULTI_HOMED - - #!trydef KZ_FAST_PICKUP_COOKIES 1 #!trydef KZ_FAST_PICKUP_REALTIME 1 diff --git a/kamailio/local.cfg b/kamailio/local.cfg index 36b0363..9bb050b 100644 --- a/kamailio/local.cfg +++ b/kamailio/local.cfg @@ -75,13 +75,14 @@ ## BINDINGS ################################################################################ ## This parameter is OPTIONAL. +## when set to 1, ## It will try to locate outbound interface ## on multihomed host. By default forward ## requests use the incoming socket disregarding ## the destination location. When enabled Kamailio ## will select a socket that can reach the ## destination. This reduces performance. -mhomed=0 +##!define KZ_MULTI_HOMED 1 ################################################################################ ## KZ_DISABLE_REGISTRAR_PORTS From f04166002b6f06878d992a3b7bb332b1bab73aa8 Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 21 Nov 2018 13:46:54 +0000 Subject: [PATCH 025/209] use kamcmd to stop kamailio --- system/sbin/kazoo-kamailio | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/sbin/kazoo-kamailio b/system/sbin/kazoo-kamailio index 78be345..675f369 100755 --- a/system/sbin/kazoo-kamailio +++ b/system/sbin/kazoo-kamailio @@ -187,7 +187,7 @@ start() { } stop() { - killall ${BIN_FILE} + kamcmd core.kill RETVAL=$? if mount_point_exists; then mkdir -p ${DB_LOCATION}/../db-backup From b06adadcbffd789b1aab994c527d83bf86732e28 Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 21 Nov 2018 13:47:34 +0000 Subject: [PATCH 026/209] set log level to notice in core --- kamailio/default.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/kamailio/default.cfg b/kamailio/default.cfg index aa6427e..a8b3fb2 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -303,6 +303,7 @@ modparam("permissions", "db_mode", 1) loadmodule "debugger.so" modparam("debugger", "mod_hash_size", 5) modparam("debugger", "mod_level_mode", 1) +modparam("debugger", "mod_level", "core=1") ####### Routing Logic ######## route From 353768e45335a54dcbb131fce4e0527a95e6224b Mon Sep 17 00:00:00 2001 From: lazedo Date: Mon, 26 Nov 2018 13:45:13 +0000 Subject: [PATCH 027/209] add runtime variable to force kazoo query on register --- kamailio/registrar-role.cfg | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/kamailio/registrar-role.cfg b/kamailio/registrar-role.cfg index d8332ed..3ccb286 100644 --- a/kamailio/registrar-role.cfg +++ b/kamailio/registrar-role.cfg @@ -80,6 +80,7 @@ kazoo.registrar_handle_expired_ws = REGISTRAR_HANDLE_EXPIRED_WS descr "handles e kazoo.registrar_query_timeout_ms = REGISTRAR_QUERY_TIMEOUT_MS descr "timeout waiting for reply from registrar" kazoo.registrar_failover = 0 descr "force failover if 1" +kazoo.registrar_force_query = 0 descr "force query if 1" ####### Registrar Logic ######## route[HANDLE_REGISTER] @@ -142,14 +143,16 @@ route[ATTEMPT_AUTHORIZATION] route(PUSHER_ATTEMPT_REGISTRATION); #!endif - $xavp(regcfg=>match_received) = $su; - if($sht(auth_cache=>$Au) != $null - && registered("location", "$rz:$Au", 2, 1) == 1 - && $(xavp(ulattrs=>custom_channel_vars){s.len}) > 1) - && $sel(cfg_get.kazoo.registrar_failover) == 0 { - $var(password) = $sht(auth_cache=>$Au); - route(SAVE_LOCATION); - exit; + if($sel(cfg_get.kazoo.registrar_force_query) == 0) { + $xavp(regcfg=>match_received) = $su; + if($sht(auth_cache=>$Au) != $null + && registered("location", "$rz:$Au", 2, 1) == 1 + && $(xavp(ulattrs=>custom_channel_vars){s.len}) > 1) + && $sel(cfg_get.kazoo.registrar_failover) == 0 { + $var(password) = $sht(auth_cache=>$Au); + route(SAVE_LOCATION); + exit; + } } if($td =~ "[0-9]{1,3}\.[0-9]{1,3}.[0-9]{1,3}\.[0-9]{1,3}" || From ec924a6c12245c86b45cd13344e68c0b66b91302 Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 28 Nov 2018 10:53:54 +0000 Subject: [PATCH 028/209] increase cseq_offset --- kamailio/presence-role.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kamailio/presence-role.cfg b/kamailio/presence-role.cfg index 95a0865..78d8548 100644 --- a/kamailio/presence-role.cfg +++ b/kamailio/presence-role.cfg @@ -42,7 +42,7 @@ modparam("presence", "local_log_level", 6) modparam("presence", "startup_mode", 0) modparam("presence", "force_delete", 1) modparam("presence", "timeout_rm_subs", 0) -modparam("presence", "cseq_offset", 1) +modparam("presence", "cseq_offset", 2) modparam("kazoo", "db_url", "KAZOO_DB_URL") modparam("kazoo", "pua_mode", 1) From d0d74d2a0040836a7a7b817668335549c371bc0b Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 28 Nov 2018 15:30:18 +0000 Subject: [PATCH 029/209] move cseq to trydef --- kamailio/presence-role.cfg | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kamailio/presence-role.cfg b/kamailio/presence-role.cfg index 78d8548..e6a6919 100644 --- a/kamailio/presence-role.cfg +++ b/kamailio/presence-role.cfg @@ -2,8 +2,11 @@ #!trydef PRESENCE_MIN_EXPIRES 300 #!trydef PRESENCE_MIN_EXPIRES_ACTION 1 #!trydef PRESENCE_MAX_EXPIRES 3600 + #!trydef KZ_PRESENCE_IGNORE_STATUS_PROBE_RESP 1 +#!trydef KZ_PRESENCE_CSEQ_OFFSET 2 + #!trydef KZ_PRESENCE_MAX_CALL_PER_PRESENTITY 10 modparam("htable", "htable", "p=>size=32;autoexpire=3600;") @@ -42,7 +45,7 @@ modparam("presence", "local_log_level", 6) modparam("presence", "startup_mode", 0) modparam("presence", "force_delete", 1) modparam("presence", "timeout_rm_subs", 0) -modparam("presence", "cseq_offset", 2) +modparam("presence", "cseq_offset", KZ_PRESENCE_CSEQ_OFFSET) modparam("kazoo", "db_url", "KAZOO_DB_URL") modparam("kazoo", "pua_mode", 1) From 85716fb5da90ef2de3dbbd222704d95d9400cb57 Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 28 Nov 2018 15:31:12 +0000 Subject: [PATCH 030/209] count distinct callid for presentity count --- kamailio/db_queries_kazoo.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kamailio/db_queries_kazoo.cfg b/kamailio/db_queries_kazoo.cfg index cf79f5c..6bc50f2 100644 --- a/kamailio/db_queries_kazoo.cfg +++ b/kamailio/db_queries_kazoo.cfg @@ -2,7 +2,7 @@ #!substdef "!KZQ_CHECK_MEDIA_SERVER_INSERT!insert into dispatcher (setid, destination, flags, attrs, description) select \$var(SetId), \"\$var(MediaUrl)\", \$var(flags), \"\$var(attrs)\", \"added by nodes role\" where not exists(select * from dispatcher where destination = \"\$var(MediaUrl)\")!g" #!substdef "!KZQ_COUNT_ALL_SUBSCRIBERS!select a.event, count(distinct watcher_username || \"@\" || watcher_domain) count_unique, count(*) count from event_list a, active_watchers b where b.event = a.event group by a.event!g" #!substdef "!KZQ_COUNT_PRESENTITIES!select event, (select count(*) from presentity b where username = \"\$(var(payload){kz.json,From}{uri.user})\" and domain = \"\$(var(payload){kz.json,From}{uri.domain})\" and b.event = a.event) count from event_list a!g" -#!substdef "!KZQ_COUNT_SUBSCRIBERS!select event, (select count(*) from active_watchers b where presentity_uri = \"\$var(presentity)\" and b.event = a.event) count from event_list a union select \"self\", count(*) from presentities where presentity_uri = \"\$var(presentity)\"!g" +#!substdef "!KZQ_COUNT_SUBSCRIBERS!select event, (select count(*) from active_watchers b where presentity_uri = \"\$var(presentity)\" and b.event = a.event) count from event_list a union select \"self\", count(distinct callid) from presentities where presentity_uri = \"\$var(presentity)\"!g" #!substdef "!KZQ_EVENT_PRESENCE_RESET_DELETE!delete from presentity where domain=\"\$(kzE{kz.json,Realm})\" and username = \"\$(kzE{kz.json,Username})\"!g" #!substdef "!KZQ_HANDLE_NEW_SUBSCRIBE_DELETE1!delete from active_watchers where callid = \"\$ci\"!g" #!substdef "!KZQ_HANDLE_NEW_SUBSCRIBE_DELETE2!delete from active_watchers where watcher_username=\"\$fU\" and presentity_uri=\"\$var(presentity_uri)\" and to_user=\"\$tU\" and watcher_domain=\"\$fd\" and event=\"\$hdr(Event)\"!g" From f8ac48abb0619726de0ee72bf7722d3f06e247a6 Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 28 Nov 2018 15:31:56 +0000 Subject: [PATCH 031/209] expires in location table is timestamp --- kamailio/db_scripts/db_extra_check.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kamailio/db_scripts/db_extra_check.sql b/kamailio/db_scripts/db_extra_check.sql index 5e9c9c5..3a809de 100644 --- a/kamailio/db_scripts/db_extra_check.sql +++ b/kamailio/db_scripts/db_extra_check.sql @@ -3,7 +3,7 @@ do_db_extra_check() { # location KazooDB -db ${DB_CURRENT_DB} "delete from location where socket not like 'udp:%';" -KazooDB -db ${DB_CURRENT_DB} "delete from location where expires > 0 and datetime(expires, 'unixepoch') < datetime('now', '-10 seconds');" +KazooDB -db ${DB_CURRENT_DB} "delete from location where expires > 0 and datetime(expires) < datetime('now', '-30 seconds');" KazooDB -db ${DB_CURRENT_DB} "delete from location_attrs where not exists(select id from location where ruid = location_attrs.ruid);" ## presence From 62dfcc1ef0ae992c80c7e9f7bbf78fc613b7f11a Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 29 Nov 2018 00:40:15 +0000 Subject: [PATCH 032/209] add extra sets for dispatcher classify --- kamailio/dispatcher-role.cfg | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kamailio/dispatcher-role.cfg b/kamailio/dispatcher-role.cfg index b8d9596..db979ce 100644 --- a/kamailio/dispatcher-role.cfg +++ b/kamailio/dispatcher-role.cfg @@ -52,6 +52,9 @@ route[DISPATCHER_CLASSIFY_SOURCE] ds_is_from_list(1, 3) || ds_is_from_list(2, 3) || ds_is_from_list(3, 3) || + ds_is_from_list(51, 3) || + ds_is_from_list(52, 3) || + ds_is_from_list(53, 3) || ds_is_from_list(10, 3) || ds_is_from_list(20, 3) ) { From ce080ba5e783790cf15d5fcfc8437a2270b9adea Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 29 Nov 2018 02:46:38 +0000 Subject: [PATCH 033/209] !trydefs for dispatcher groups and runtime selection --- kamailio/dispatcher-role.cfg | 45 ++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/kamailio/dispatcher-role.cfg b/kamailio/dispatcher-role.cfg index db979ce..5610ec9 100644 --- a/kamailio/dispatcher-role.cfg +++ b/kamailio/dispatcher-role.cfg @@ -5,9 +5,22 @@ modparam("htable", "htable", "failover=>size=16;autoexpire=120") #!trydef DISPATCHER_ADD_SERVERS 1 #!trydef DISPATCHER_ALG 0 #!trydef KZ_DISPATCHER_ADD_FLAGS 10 +#!trydef KZ_DISPATCHER_PRIMARY_GROUP 1 +#!trydef KZ_DISPATCHER_SECONDARY_GROUP 2 +#!trydef KZ_DISPATCHER_CLASSIFY_GROUP 3 +#!trydef KZ_DISPATCHER_ALTNET1_PRIMARY_GROUP 51 +#!trydef KZ_DISPATCHER_ALTNET1_SECONDARY_GROUP 52 +#!trydef KZ_DISPATCHER_ALTNET2_PRIMARY_GROUP 53 +#!trydef KZ_DISPATCHER_ALTNET2_SECONDARY_GROUP 54 +#!trydef KZ_DISPATCHER_PRESENCE_PRIMARY_GROUP 10 +#!trydef KZ_DISPATCHER_PRESENCE_SECONDARY_GROUP 11 +#!trydef KZ_DISPATCHER_REGISTRAR_PRIMARY_GROUP 20 +#!trydef KZ_DISPATCHER_REGISTRAR_SECONDARY_GROUP 21 kazoo.dispatcher_auto_add = DISPATCHER_ADD_SERVERS descr "adds media servers reported by ecallmgr" kazoo.dispatcher_algorithm = DISPATCHER_ALG descr "dispatcher algorithm to use" +kazoo.dispatcher_primary_group = KZ_DISPATCHER_PRIMARY_GROUP descr "dispatcher primary group" +kazoo.dispatcher_secondary_group = KZ_DISPATCHER_SECONDARY_GROUP descr "dispatcher secondary group" ####### Dispatcher module ######## loadmodule "dispatcher.so" @@ -49,17 +62,19 @@ route[DISPATCHER_CLASSIFY_SOURCE] if (is_myself("$ou")) { xlog("L_INFO", "$ci|log|original R-URI ($ou) is this proxy, treating as external sources\n"); } else if ( - ds_is_from_list(1, 3) || - ds_is_from_list(2, 3) || - ds_is_from_list(3, 3) || - ds_is_from_list(51, 3) || - ds_is_from_list(52, 3) || - ds_is_from_list(53, 3) || - ds_is_from_list(10, 3) || - ds_is_from_list(20, 3) + ds_is_from_list(KZ_DISPATCHER_PRIMARY_GROUP, 3) || + ds_is_from_list(KZ_DISPATCHER_SECONDARY_GROUP, 3) || + ds_is_from_list(KZ_DISPATCHER_CLASSIFY_GROUP, 3) || + ds_is_from_list(KZ_DISPATCHER_ALTNET1_PRIMARY_GROUP, 3) || + ds_is_from_list(KZ_DISPATCHER_ALTNET1_SECONDARY_GROUP, 3) || + ds_is_from_list(KZ_DISPATCHER_ALTNET2_PRIMARY_GROUP, 3) || + ds_is_from_list(KZ_DISPATCHER_ALTNET2_SECONDARY_GROUP, 3) || + ds_is_from_list(KZ_DISPATCHER_PRESENCE_PRIMARY_GROUP, 3) || + ds_is_from_list(KZ_DISPATCHER_PRESENCE_SECONDARY_GROUP, 3) || + ds_is_from_list(KZ_DISPATCHER_REGISTRAR_PRIMARY_GROUP, 3) || + ds_is_from_list(KZ_DISPATCHER_REGISTRAR_SECONDARY_GROUP, 3) ) { xlog("L_INFO", "$ci|log|originated from internal sources\n"); - setflag(FLAG_INTERNALLY_SOURCED); } else { xlog("L_INFO", "$ci|log|originated from external sources\n"); @@ -75,20 +90,20 @@ route[DISPATCHER_FIND_ROUTES] return; } - $var(ds_primary_group) = 1; - $var(ds_backup_group) = 2; + $var(ds_primary_group) = $sel(cfg_get.kazoo.dispatcher_primary_group); + $var(ds_backup_group) = $sel(cfg_get.kazoo.dispatcher_secondary_group); #!ifndef PRESENCE_ROLE if (is_method("SUBSCRIBE")) { - $var(ds_primary_group) = 10; - $var(ds_backup_group) = 11; + $var(ds_primary_group) = KZ_DISPATCHER_PRESENCE_PRIMARY_GROUP; + $var(ds_backup_group) = KZ_DISPATCHER_PRESENCE_SECONDARY_GROUP; } #!endif #!ifndef REGISTRAR_ROLE if (is_method("REGISTER")) { - $var(ds_primary_group) = 20; - $var(ds_backup_group) = 21; + $var(ds_primary_group) = KZ_DISPATCHER_REGISTRAR_PRIMARY_GROUP; + $var(ds_backup_group) = KZ_DISPATCHER_REGISTRAR_SECONDARY_GROUP; } #!endif From 831dc2e7de6904da01fb7cc5251c08db0296fd09 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 29 Nov 2018 15:35:53 +0000 Subject: [PATCH 034/209] track media instance-id --- kamailio/nodes-role.cfg | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/kamailio/nodes-role.cfg b/kamailio/nodes-role.cfg index 1976773..54cf6d0 100644 --- a/kamailio/nodes-role.cfg +++ b/kamailio/nodes-role.cfg @@ -138,10 +138,18 @@ route[CHECK_MEDIA_SERVERS] $var(MediaProfile) = $(avp(ProfileKeys)[$var(ProfileIdx)]); $var(MediaRawUrl) = $(var(Payload){kz.json,Media-Servers.$var(MediaKey).Interfaces.$var(MediaProfile).URL}); $var(MediaUrl) = $(var(MediaRawUrl){re.subst,/^sip:(.*)@(.*)/sip:\2/}); + $var(MediaInstanceUUID) = $(var(Payload){kz.json,Media-Servers.$var(MediaKey).Instance-UUID}); if($shtinc(media=>$var(MediaUrl)::count) == 1) { $sht(media=>$var(MediaUrl)::zone) = $var(Zone); $shtex(media=>$var(MediaUrl)::zone) = 0; + $sht(media=>$var(MediaUrl)::uuid) = $var(MediaInstanceUUID); + $shtex(media=>$var(MediaUrl)::uuid) = 0; route(MEDIA_SERVER_UP); + } else if($sht(media=>$var(MediaUrl)::uuid) != $var(MediaInstanceUUID)) { + $sht(media=>$var(MediaUrl)::uuid) = $var(MediaInstanceUUID); + $shtex(media=>$var(MediaUrl)::uuid) = 0; + $var(Zone) = $sht(media=>$var(MediaUrl)::zone); + route(MEDIA_SERVER_RESTART); }; $var(MediaExpire) = ($(var(Payload){kz.json,Expires}{s.int}) / 1000) + NODES_FUDGE_EXPIRE; xlog("L_DEBUG", "nodes|media|$var(Node) media expiration $var(MediaExpire) for $var(MediaUrl)\n"); @@ -185,6 +193,16 @@ route[MEDIA_SERVER_DOWN] } +route[MEDIA_SERVER_RESTART] +{ + xlog("L_WARNING", "htable|media|media server $var(MediaUrl) restarted in zone $var(Zone)\n"); + +#!ifdef PRESENCE_ROLE + route(RESET_PUBLISHER); +#!endif + +} + #!ifndef NODES_CUSTOM_BINDINGS route[NODES_BINDINGS] { From 8556277c052a9f547a51c770b4057713d6d3e4a6 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 29 Nov 2018 17:01:50 +0000 Subject: [PATCH 035/209] join the event too --- kamailio/db_scripts/db_extra_check.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kamailio/db_scripts/db_extra_check.sql b/kamailio/db_scripts/db_extra_check.sql index 3a809de..bb88caa 100644 --- a/kamailio/db_scripts/db_extra_check.sql +++ b/kamailio/db_scripts/db_extra_check.sql @@ -17,7 +17,7 @@ KazooDB -db ${DB_CURRENT_DB} "delete from presentity where id in(select id from ## notify watchers of pending calls ## 'create temp table as' because it will be dropped as soon as we ended the session KazooDB -db ${DB_CURRENT_DB} "drop table if exists tmp_probe;" -KazooDB -db ${DB_CURRENT_DB} "create table tmp_probe as select distinct b.event, a.presentity_uri from presentities a inner join active_watchers b on a.presentity_uri = b.presentity_uri where state in('early', 'confirmed', 'onthephone', 'busy');" +KazooDB -db ${DB_CURRENT_DB} "create table tmp_probe as select distinct a.event, a.presentity_uri from presentities a inner join active_watchers b on a.presentity_uri = b.presentity_uri and a.event = b.event where state in('early', 'confirmed', 'onthephone', 'busy');" KazooDB -db ${DB_CURRENT_DB} "delete from presentity where id in(select id from presentities where state in('early', 'confirmed', 'onthephone', 'busy'));" } From 06fdce2a0aaaef4043a0318f3752c835e8849afc Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 29 Nov 2018 17:02:59 +0000 Subject: [PATCH 036/209] presence reset updates --- kamailio/db_queries_kazoo.cfg | 12 ++++++++---- kamailio/default.cfg | 2 +- kamailio/defs.cfg | 2 -- kamailio/presence-notify.cfg | 11 +++++++++-- kamailio/presence-reset.cfg | 13 ++++++++++--- 5 files changed, 28 insertions(+), 12 deletions(-) diff --git a/kamailio/db_queries_kazoo.cfg b/kamailio/db_queries_kazoo.cfg index 6bc50f2..721efeb 100644 --- a/kamailio/db_queries_kazoo.cfg +++ b/kamailio/db_queries_kazoo.cfg @@ -6,11 +6,15 @@ #!substdef "!KZQ_EVENT_PRESENCE_RESET_DELETE!delete from presentity where domain=\"\$(kzE{kz.json,Realm})\" and username = \"\$(kzE{kz.json,Username})\"!g" #!substdef "!KZQ_HANDLE_NEW_SUBSCRIBE_DELETE1!delete from active_watchers where callid = \"\$ci\"!g" #!substdef "!KZQ_HANDLE_NEW_SUBSCRIBE_DELETE2!delete from active_watchers where watcher_username=\"\$fU\" and presentity_uri=\"\$var(presentity_uri)\" and to_user=\"\$tU\" and watcher_domain=\"\$fd\" and event=\"\$hdr(Event)\"!g" -#!substdef "!KZQ_RESET_ACCOUNT_DELETE!delete from presentity where domain=\"\$(kzE{kz.json,Realm})\"!g" -#!substdef "!KZQ_RESET_ACCOUNT_UPDATE!update active_watchers set expires = \$TS where watcher_domain=\"\$(kzE{kz.json,Realm})\"!g" -#!substdef "!KZQ_RESET_PUBLISHER_UPDATE!update active_watchers set expires = \$TS where id in (select b.id from presentity a inner join active_watchers b on a.username = b.to_user and a.domain = b.to_domain and a.event = b.event where a.sender = \"\$var(MediaUrl)\")!g" #!substdef "!KZQ_PRESENCE_SEARCH_DETAIL!select * from active_watchers_log where presentity_uri = \"\$var(presentity_uri)\" and callid in(select callid from active_watchers where presentity_uri = \"\$var(presentity_uri)\")!g" #!substdef "!KZQ_PRESENCE_SEARCH_SUMMARY!select * from active_watchers where to_domain = \"\$var(Domain)\"!g" #!substdef "!KZQ_HAS_PRESENTITY!select count(*) as count from presentity where username = \"\$subs(to_user)\" and domain = \"\$subs(to_domain)\" and event = \"\$subs(event)\"!g" -#!substdef "!KZQ_PRESENCE_RESET!delete from presentity where sender = \"\$var(MediaUrl)\"!g" #!substdef "!KZQ_REPLACE_WATCHERS_LOG!REPLACE INTO active_watchers_log (presentity_uri, watcher_username, watcher_domain, event, callid, to_user, to_domain, user_agent, time, result, sent_msg, received_msg) VALUES (\"\$subs(uri)\", \"\$subs(watcher_username)\", \"\$subs(watcher_domain)\", \"\$subs(event)\",\"\$subs(callid)\",\"\$subs(to_user)\",\"\$subs(to_domain)\", '\$(subs(user_agent){s.escape.common}{s.replace,\\\',''}{s.replace,\$\$,})', \$TS, \$notify_reply(\$rs), '\$(mb{s.escape.common}{s.replace,\\\',''}{s.replace,\$\$,})', '\$(notify_reply(\$mb){s.escape.common}{s.replace,\\\',''}{s.replace,\$\$,})')!g" + +# # #!substdef "!KZQ_RESET_PUBLISHER_UPDATE!update active_watchers set expires = \$TS where id in (select b.id from presentity a inner join active_watchers b on a.username = b.to_user and a.domain = b.to_domain and a.event = b.event where a.sender = \"\$var(MediaUrl)\")!g" +#!substdef "!KZQ_RESET_PUBLISHER_UPDATE!INSERT INTO tmp_probe select distinct a.event, a.presentity_uri from presentities a inner join active_watchers b on a.presentity_uri = b.presentity_uri and a.event = b.event where sender = \"\$var(MediaUrl)\" and state in('early', 'confirmed', 'onthephone', 'busy')!g" +#!substdef "!KZQ_PRESENCE_RESET!delete from presentity where sender = \"\$var(MediaUrl)\"!g" + +# # #!substdef "!KZQ_RESET_ACCOUNT_UPDATE!update active_watchers set expires = \$TS where watcher_domain=\"\$(kzE{kz.json,Realm})\"!g" +#!substdef "!KZQ_RESET_ACCOUNT_UPDATE!INSERT INTO tmp_probe select distinct a.event, a.presentity_uri from presentities a inner join active_watchers b on a.presentity_uri = b.presentity_uri and a.event = b.event where domain=\"\$(kzE{kz.json,Realm})\" and state in('early', 'confirmed', 'onthephone', 'busy')!g" +#!substdef "!KZQ_RESET_ACCOUNT_RESET!delete from presentity where domain=\"\$(kzE{kz.json,Realm})\"!g" diff --git a/kamailio/default.cfg b/kamailio/default.cfg index a8b3fb2..4cafa3e 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -979,7 +979,7 @@ event_route[evrexec:DEFERRED_INIT] xlog("L_INFO", "processing deferred init\n"); #!ifdef PRESENCE_ROLE - route(PRESENCE_INITIAL_CLEANUP); + route(PRESENCE_PUBLISHER_CLEANUP); #!endif #!import_file "custom-init.cfg" diff --git a/kamailio/defs.cfg b/kamailio/defs.cfg index 426f711..51dcb70 100644 --- a/kamailio/defs.cfg +++ b/kamailio/defs.cfg @@ -39,8 +39,6 @@ #!substdef "!MY_AMQP_ZONE!local!g" #!endif -#!trydef PRESENCE_RESET_BLF_DEFER_UPDATE 0 - #!ifdef PRESENCE_ROLE #!trydef MY_AMQP_PUA_MODE 1 #!else diff --git a/kamailio/presence-notify.cfg b/kamailio/presence-notify.cfg index 4a33f24..e8305e2 100644 --- a/kamailio/presence-notify.cfg +++ b/kamailio/presence-notify.cfg @@ -139,9 +139,9 @@ route[PRESENCE_CLEANUP] mq_add("presence_last_notity", "$uuid(g)", "$var(Query)"); } -route[PRESENCE_INITIAL_CLEANUP] +route[PRESENCE_PUBLISHER_CLEANUP] { - xlog("L_INFO", "processing presence initial cleanup\n"); + xlog("L_INFO", "processing presence publisher cleanup\n"); if (sql_xquery("cb", "select * from tmp_probe", "ra") == 1) { while($xavp(ra) != $null) { @@ -150,4 +150,11 @@ route[PRESENCE_INITIAL_CLEANUP] pv_unset("$xavp(ra)"); } } + $var(sqlres) = sql_query("cb", "delete from tmp_probe"); + if($var(sqlres) < 0) { + xlog("L_ERROR", "$var(ci)|log|error cleaning tmp_probe\n"); + } else { + $var(nrows) = $sqlrows(cb); + xlog("L_INFO", "presence publisher cleanup processed $var(nrows) rows\n"); + } } diff --git a/kamailio/presence-reset.cfg b/kamailio/presence-reset.cfg index 5d6ec15..7511110 100644 --- a/kamailio/presence-reset.cfg +++ b/kamailio/presence-reset.cfg @@ -1,3 +1,4 @@ +#!trydef PRESENCE_RESET_BLF_DEFER_UPDATE 0 kazoo.presence_reset_blf_defer_update = PRESENCE_RESET_BLF_DEFER_UPDATE descr "defers blf reset" @@ -27,7 +28,7 @@ route[PRESENCE_RESET_BINDINGS] route[RESET_PUBLISHER] { - xlog("L_INFO", "$var(Msg-ID)|reset|received presence reset for publisher $var(MediaUrl))\n"); + xlog("L_INFO", "$var(Msg-ID)|reset|received presence reset for publisher $var(MediaUrl)\n"); if($sel(cfg_get.kazoo.presence_reset_blf_defer_update) == 0) { $var(Query) = $_s(KZQ_RESET_PUBLISHER_UPDATE); sql_query("exec", "$var(Query)"); @@ -36,6 +37,9 @@ route[RESET_PUBLISHER] sql_query("exec", "$var(Query)"); $var(presentities) = $sqlrows(exec); xlog("L_INFO", "$var(Msg-ID)|reset|removed $var(presentities) presentities from publisher $var(MediaUrl)\n"); + if($var(presentities) > 0) { + route(PRESENCE_PUBLISHER_CLEANUP); + } } route[RESET_ALL] @@ -62,11 +66,14 @@ route[RESET_SERVER] route[RESET_ACCOUNT] { xlog("L_INFO", "$(kzE{kz.json,Msg-ID})|reset|received presence reset for realm $(kzE{kz.json,Realm})\n"); - sql_query("exec", 'KZQ_RESET_ACCOUNT_DELETE'); - $var(presentities) = $sqlrows(exec); sql_query("exec", 'KZQ_RESET_ACCOUNT_UPDATE'); $var(watchers) = $sqlrows(exec); + sql_query("exec", 'KZQ_RESET_ACCOUNT_RESET'); + $var(presentities) = $sqlrows(exec); xlog("L_INFO", "$(kzE{kz.json,Msg-ID})|reset|removed $var(presentities) presentities and expired $var(watchers) subscribers for realm $(kzE{kz.json,Realm})\n"); + if($var(watchers) > 0) { + route(PRESENCE_PUBLISHER_CLEANUP); + } } route[RESET_WILDCARD] From 42b90ab27d8a59f9ebc47b4bdb2f0238036e8686 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 29 Nov 2018 18:23:24 +0000 Subject: [PATCH 037/209] change log level for publisher cleanup --- kamailio/presence-notify.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kamailio/presence-notify.cfg b/kamailio/presence-notify.cfg index e8305e2..4c6fb4a 100644 --- a/kamailio/presence-notify.cfg +++ b/kamailio/presence-notify.cfg @@ -145,7 +145,7 @@ route[PRESENCE_PUBLISHER_CLEANUP] if (sql_xquery("cb", "select * from tmp_probe", "ra") == 1) { while($xavp(ra) != $null) { - xlog("L_WARNING", "processing $xavp(ra=>event) notifies for $xavp(ra=>presentity_uri)\n"); + xlog("L_DEBUG", "processing $xavp(ra=>event) notifies for $xavp(ra=>presentity_uri)\n"); pres_refresh_watchers("$xavp(ra=>presentity_uri)", "$xavp(ra=>event)", 1); pv_unset("$xavp(ra)"); } From 7a8b6a3f03ea0b4b48c006ba8681bbabb7298568 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 29 Nov 2018 20:45:30 +0000 Subject: [PATCH 038/209] revert dns enablement --- kamailio/default.cfg | 4 ++-- kamailio/fast-pickup-role.cfg | 9 ++++----- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/kamailio/default.cfg b/kamailio/default.cfg index 4cafa3e..f4e0a8d 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -71,14 +71,14 @@ udp4_raw = 0 # #udp_mtu_try_proto = TCP ####### DNS Parameters ######### -dns = yes +dns = no rev_dns = no dns_try_ipv6 = no use_dns_cache = on dns_cache_del_nonexp = yes dns_cache_flags = 1 dns_cache_gc_interval = 120 -dns_cache_init = 1 +dns_cache_init = 0 dns_cache_mem = 1000 dns_cache_negative_ttl = 60 dns_try_naptr = no diff --git a/kamailio/fast-pickup-role.cfg b/kamailio/fast-pickup-role.cfg index 22904a4..554b121 100644 --- a/kamailio/fast-pickup-role.cfg +++ b/kamailio/fast-pickup-role.cfg @@ -21,12 +21,11 @@ route[FAST_PICKUP_LOAD] $var(destination) = $xavp(ra=>destination); $var(i) = 0; if(!is_ip("$var(host)")) { - if(dns_query("$var(host)", "xyz")) { - $var(destination) = $_s(sip:$dns(xyz=>addr[$var(i)]):$var(port)); - } + xlog("L_INFO", "$ci|log|fast|ignoring $var(host) since its not a ip address\n"); + } else { + xlog("L_INFO", "$ci|log|fast|adding key $(var(destination){s.md5}) for $var(destination)\n"); + $sht(fp=>$(var(destination){s.md5})) = $var(destination); } - xlog("L_INFO", "$ci|log|fast|adding key $(var(destination){s.md5}) for $var(destination)\n"); - $sht(fp=>$(var(destination){s.md5})) = $var(destination); pv_unset("$xavp(ra)"); } } From 983fae6652d12529b51421936776f80fb33687aa Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 29 Nov 2018 22:08:11 +0000 Subject: [PATCH 039/209] remove 302 condition --- kamailio/default.cfg | 3 --- 1 file changed, 3 deletions(-) diff --git a/kamailio/default.cfg b/kamailio/default.cfg index f4e0a8d..3141ab4 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -402,7 +402,6 @@ route[SANITY_CHECK] { if($sht(insane=>$si:$sp) > 3) { drop; - exit; }; if (!sanity_check()) { @@ -747,9 +746,7 @@ onreply_route[EXTERNAL_REPLY] #!endif #!ifdef NAT_TRAVERSAL_ROLE - if(!t_check_status("302")) { route(NAT_TEST_AND_CORRECT); - } #!endif #!ifdef ACL_ROLE From 58ce88d0cf395161f9f4fab265b3a695605188fc Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 29 Nov 2018 22:10:17 +0000 Subject: [PATCH 040/209] remove uac params --- kamailio/default.cfg | 3 --- 1 file changed, 3 deletions(-) diff --git a/kamailio/default.cfg b/kamailio/default.cfg index 3141ab4..2b87976 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -176,9 +176,6 @@ loadmodule "xlog.so" ######## UAC ######## loadmodule "uac.so" -modparam("uac","restore_mode","manual") -modparam("uac","restore_from_avp","$avp(original_uri_from)") -modparam("uac","restore_to_avp","$avp(original_uri_to)") ######## AVP's ######## loadmodule "avp.so" From 6222cbece175a149811e81cda1240e78db7bdf2e Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 29 Nov 2018 22:17:03 +0000 Subject: [PATCH 041/209] remove sanity htable counter --- kamailio/default.cfg | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/kamailio/default.cfg b/kamailio/default.cfg index 2b87976..9c75912 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -392,17 +392,15 @@ route[CHECK_RETRANS] } } - -modparam("htable", "htable", "insane=>size=32;autoexpire=120;initval=0;updateexpire=1;") - route[SANITY_CHECK] { - if($sht(insane=>$si:$sp) > 3) { + ## CVE-2018-14767 + if($(hdr(To)[1]) != $null) { + xlog("second To header not null - dropping message"); drop; - }; + } if (!sanity_check()) { - $var(insane) = $shtinc(insane=>$si:$sp); xlog("L_WARN", "$ci|end|message from $si:$sp is insane ($var(insane))\n"); drop; } From 274543d4d1b6db981bcf36001500daa03402215f Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 29 Nov 2018 23:08:18 +0000 Subject: [PATCH 042/209] allow opt-out str 5 processing andalso change at runtime --- kamailio/defs.cfg | 3 --- kamailio/fast-pickup-role.cfg | 32 +++++++++++++++++++++++--------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/kamailio/defs.cfg b/kamailio/defs.cfg index 51dcb70..558dc96 100644 --- a/kamailio/defs.cfg +++ b/kamailio/defs.cfg @@ -89,9 +89,6 @@ #!trydef KZ_TLS_REGISTRAR_PORT 7000 #!endif -#!trydef KZ_FAST_PICKUP_COOKIES 1 -#!trydef KZ_FAST_PICKUP_REALTIME 1 - #!trydef KZ_MULTI_HOMED 0 #!ifndef KZ_DISABLE_WEBSOCKETS_REGISTRAR_PORT diff --git a/kamailio/fast-pickup-role.cfg b/kamailio/fast-pickup-role.cfg index 554b121..b822b76 100644 --- a/kamailio/fast-pickup-role.cfg +++ b/kamailio/fast-pickup-role.cfg @@ -2,8 +2,13 @@ modparam("htable", "htable", "park=>size=16;autoexpire=600") modparam("htable", "htable", "fp=>size=8"); +#!trydef KZ_FAST_PICKUP_COOKIES 1 +#!trydef KZ_FAST_PICKUP_REALTIME 1 +#!trydef KZ_FAST_PICKUP_STAR_5 1 + kazoo.fast_pickup_cookies = KZ_FAST_PICKUP_COOKIES descr "maintains a hash table for correlating call-ids with media servers" kazoo.fast_pickup_realtime = KZ_FAST_PICKUP_REALTIME descr "queries channels api for realtime status of call-id" +kazoo.fast_pickup_star_5 = KZ_FAST_PICKUP_STAR_5 descr "treats *5 as park pickup, queries state of *3" route[FAST_PICKUP_START] { @@ -96,15 +101,20 @@ route[FAST_PICKUP_ATTEMPT] } ##### CALL-PARK #### - if($(ru{uri.user}) =~ "\*5") { - $var(park) = $_s(*3$(ru{uri.user}{s.substr,2,0})@$(ru{uri.domain})); - if($sht(park=>$var(park)) != $null) { - $du = $sht(park=>$var(park)); - xlog("L_INFO", "$ci|log|redirecting park request to $du\n"); - route(EXTERNAL_TO_INTERNAL_RELAY); - exit(); - } + + ##### STAR 5 CHECK #### + if($sel(cfg_get.kazoo.fast_pickup_star_5) == 1) { + if($(ru{uri.user}) =~ "\*5") { + $var(park) = $_s(*3$(ru{uri.user}{s.substr,2,0})@$(ru{uri.domain})); + if($sht(park=>$var(park)) != $null) { + $du = $sht(park=>$var(park)); + xlog("L_INFO", "$ci|log|redirecting park request to $du\n"); + route(EXTERNAL_TO_INTERNAL_RELAY); + exit(); + } + } } + if($sht(park=>$(ru{uri.user})@$(ru{uri.domain})) != $null) { $du = $sht(park=>$(ru{uri.user})@$(ruri{uri.domain})); xlog("L_INFO", "$ci|log|redirecting park request to $du\n"); @@ -113,7 +123,11 @@ route[FAST_PICKUP_ATTEMPT] } ##### CALL-PARK IN KAZOO #### - if($(ru{uri.user}) =~ "\*[3,5]" && !($rd =~ "[0-9]{1,3}\.[0-9]{1,3}.[0-9]{1,3}\.[0-9]{1,3}") ) { + $var(park_extension) = "\*3"; + if($sel(cfg_get.kazoo.fast_pickup_star_5) == 1) { + $var(park_extension) = "\*[3,5]"; + } + if($(ru{uri.user}) =~ $var(park_extension) && !($rd =~ "[0-9]{1,3}\.[0-9]{1,3}.[0-9]{1,3}\.[0-9]{1,3}") ) { xlog("L_INFO", "$ci|log|checking park request to $(ru{uri.user})@$(ru{uri.domain})\n"); $var(amqp_payload_request) = '{"Event-Category" : "call_event" , "Event-Name" : "query_user_channels_req", "Username" : "*3$(ru{uri.user}{s.substr,2,0})", "Realm" : "$(ru{uri.domain})", "Active-Only" : true }'; $var(amqp_routing_key) = "call.status_req." + $(var(replaced_call_id){kz.encode}); From e106c86061fc5156d955528bdb1f30c92f9f4562 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 29 Nov 2018 23:28:49 +0000 Subject: [PATCH 043/209] update count and cleanup queries --- kamailio/db_queries_kazoo.cfg | 2 +- kamailio/presence-notify.cfg | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/kamailio/db_queries_kazoo.cfg b/kamailio/db_queries_kazoo.cfg index 721efeb..1aa3635 100644 --- a/kamailio/db_queries_kazoo.cfg +++ b/kamailio/db_queries_kazoo.cfg @@ -2,7 +2,7 @@ #!substdef "!KZQ_CHECK_MEDIA_SERVER_INSERT!insert into dispatcher (setid, destination, flags, attrs, description) select \$var(SetId), \"\$var(MediaUrl)\", \$var(flags), \"\$var(attrs)\", \"added by nodes role\" where not exists(select * from dispatcher where destination = \"\$var(MediaUrl)\")!g" #!substdef "!KZQ_COUNT_ALL_SUBSCRIBERS!select a.event, count(distinct watcher_username || \"@\" || watcher_domain) count_unique, count(*) count from event_list a, active_watchers b where b.event = a.event group by a.event!g" #!substdef "!KZQ_COUNT_PRESENTITIES!select event, (select count(*) from presentity b where username = \"\$(var(payload){kz.json,From}{uri.user})\" and domain = \"\$(var(payload){kz.json,From}{uri.domain})\" and b.event = a.event) count from event_list a!g" -#!substdef "!KZQ_COUNT_SUBSCRIBERS!select event, (select count(*) from active_watchers b where presentity_uri = \"\$var(presentity)\" and b.event = a.event) count from event_list a union select \"self\", count(distinct callid) from presentities where presentity_uri = \"\$var(presentity)\"!g" +#!substdef "!KZQ_COUNT_SUBSCRIBERS!select event, (select count(*) from active_watchers b where presentity_uri = \"\$var(presentity)\" and b.event = a.event) count from event_list a union select \"self\", count(distinct callid) from presentities where presentity_uri = \"\$var(presentity)\" and state in('early', 'confirmed', 'onthephone', 'busy')!g" #!substdef "!KZQ_EVENT_PRESENCE_RESET_DELETE!delete from presentity where domain=\"\$(kzE{kz.json,Realm})\" and username = \"\$(kzE{kz.json,Username})\"!g" #!substdef "!KZQ_HANDLE_NEW_SUBSCRIBE_DELETE1!delete from active_watchers where callid = \"\$ci\"!g" #!substdef "!KZQ_HANDLE_NEW_SUBSCRIBE_DELETE2!delete from active_watchers where watcher_username=\"\$fU\" and presentity_uri=\"\$var(presentity_uri)\" and to_user=\"\$tU\" and watcher_domain=\"\$fd\" and event=\"\$hdr(Event)\"!g" diff --git a/kamailio/presence-notify.cfg b/kamailio/presence-notify.cfg index 4c6fb4a..c6c9a2c 100644 --- a/kamailio/presence-notify.cfg +++ b/kamailio/presence-notify.cfg @@ -131,7 +131,7 @@ route[PRESENCE_CLEANUP] { $var(Query) = $_s(DELETE FROM active_watchers WHERE expires > 0 AND datetime(expires, 'unixepoch') < datetime('now', '-90 seconds');); mq_add("presence_last_notity", "$uuid(g)", "$var(Query)"); - $var(Query) = $_s(DELETE FROM PRESENTITY WHERE expires > 0 AND datetime(expires, 'unixepoch') < datetime('now', '-90 seconds');); + $var(Query) = $_s(DELETE FROM PRESENTITY WHERE expires > 0 AND datetime(expires, 'unixepoch') < datetime('now');); mq_add("presence_last_notity", "$uuid(g)", "$var(Query)"); $var(Query) = $_s(DELETE FROM PRESENTITY WHERE ID IN(select id from presentities where event = "dialog" and state = "terminated" and received < datetime('now', '-5 minutes'));); mq_add("presence_last_notity", "$uuid(g)", "$var(Query)"); From 8f12e655db0c4b681b831a00112c395215c46bc7 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 29 Nov 2018 23:33:31 +0000 Subject: [PATCH 044/209] change default due to loopback channels --- kamailio/presence-role.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kamailio/presence-role.cfg b/kamailio/presence-role.cfg index e6a6919..81674ff 100644 --- a/kamailio/presence-role.cfg +++ b/kamailio/presence-role.cfg @@ -7,7 +7,7 @@ #!trydef KZ_PRESENCE_CSEQ_OFFSET 2 -#!trydef KZ_PRESENCE_MAX_CALL_PER_PRESENTITY 10 +#!trydef KZ_PRESENCE_MAX_CALL_PER_PRESENTITY 20 modparam("htable", "htable", "p=>size=32;autoexpire=3600;") modparam("htable", "htable", "first=>size=32;autoexpire=3600;initval =0;updateexpire=1;") From eb9446455499c7f7748d31e18be81b727e995513 Mon Sep 17 00:00:00 2001 From: lazedo Date: Fri, 30 Nov 2018 00:52:04 +0000 Subject: [PATCH 045/209] less noise in logs --- kamailio/presence-role.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kamailio/presence-role.cfg b/kamailio/presence-role.cfg index 81674ff..3028ea2 100644 --- a/kamailio/presence-role.cfg +++ b/kamailio/presence-role.cfg @@ -345,7 +345,7 @@ event_route[kazoo:consumer-event-presence-dialog-update] { $var(StartRoute) = $(TV(Sn){s.replace,.,}); $var(delta_to_start) = $var(StartRoute) - $(kzE{kz.json,AMQP-Received}); - xlog("L_INFO", "$(kzE{kz.json,Call-ID})|log|received $(kzE{kz.json,Event-Package}) update for $(kzE{kz.json,From}) state $(kzE{kz.json,State}) from $(kzE{kz.json,AMQP-Broker-Zone}) => $(kzE{kz.json,Switch-URI}) (Δ1 $(kzE{kz.json,AMQP-Elapsed-Micro}) μs , Δ2 $var(delta_to_start) μs)\n"); + xlog("L_DEBUG", "$(kzE{kz.json,Call-ID})|log|received $(kzE{kz.json,Event-Package}) update for $(kzE{kz.json,From}) state $(kzE{kz.json,State}) from $(kzE{kz.json,AMQP-Broker-Zone}) => $(kzE{kz.json,Switch-URI}) (Δ1 $(kzE{kz.json,AMQP-Elapsed-Micro}) μs , Δ2 $var(delta_to_start) μs)\n"); $var(JObj) = $kzE; #!ifdef FAST_PICKUP_ROLE From 8de93984bef4ef5715445ef10d73d9411b7b11e8 Mon Sep 17 00:00:00 2001 From: lazedo Date: Fri, 30 Nov 2018 18:39:22 +0000 Subject: [PATCH 046/209] handle the case where listener is not available for a zone --- kamailio/db_queries_kazoo.cfg | 3 +++ kamailio/kazoo-bindings.cfg | 50 ++++++++++++++++++++++++++++++++--- kamailio/presence-notify.cfg | 6 +++-- kamailio/presence-reset.cfg | 24 +++++++++++++++++ kamailio/presence-role.cfg | 2 +- 5 files changed, 79 insertions(+), 6 deletions(-) diff --git a/kamailio/db_queries_kazoo.cfg b/kamailio/db_queries_kazoo.cfg index 1aa3635..e022c02 100644 --- a/kamailio/db_queries_kazoo.cfg +++ b/kamailio/db_queries_kazoo.cfg @@ -18,3 +18,6 @@ # # #!substdef "!KZQ_RESET_ACCOUNT_UPDATE!update active_watchers set expires = \$TS where watcher_domain=\"\$(kzE{kz.json,Realm})\"!g" #!substdef "!KZQ_RESET_ACCOUNT_UPDATE!INSERT INTO tmp_probe select distinct a.event, a.presentity_uri from presentities a inner join active_watchers b on a.presentity_uri = b.presentity_uri and a.event = b.event where domain=\"\$(kzE{kz.json,Realm})\" and state in('early', 'confirmed', 'onthephone', 'busy')!g" #!substdef "!KZQ_RESET_ACCOUNT_RESET!delete from presentity where domain=\"\$(kzE{kz.json,Realm})\"!g" + +#!substdef "!KZQ_RESET_PUBLISHER_ZONE_UPDATE!INSERT INTO tmp_probe select distinct a.event, a.presentity_uri from presentities a inner join wdispatcher c on a.sender = c.destination inner join active_watchers b on a.presentity_uri = b.presentity_uri and a.event = b.event where zone = \"\$var(Zone)\" and state in('early', 'confirmed', 'onthephone', 'busy')!g" +#!substdef "!KZQ_PRESENCE_ZONE_RESET!delete from presentity where id in(select a.id from presentities a join wdispatcher c on a.sender = c.destination where zone = \"\$var(Zone)\")!g" diff --git a/kamailio/kazoo-bindings.cfg b/kamailio/kazoo-bindings.cfg index cf243b7..7118dc2 100644 --- a/kamailio/kazoo-bindings.cfg +++ b/kamailio/kazoo-bindings.cfg @@ -46,17 +46,17 @@ event_route[kazoo:mod-init] event_route[kazoo:consumer-event] { - xlog("L_INFO","unhandled AMQP event, payload: $kzE\n"); + xlog("L_DEBUG","unhandled AMQP event, payload: $kzE\n"); } event_route[kazoo:consumer-event-connection-open] { - xlog("L_INFO","connection to $(kzE{kz.json,host}) opened\n"); + xlog("L_NOTICE","connection to $(kzE{kz.json,host}) opened\n"); } event_route[kazoo:consumer-event-connection-closed] { - xlog("L_INFO","connection to $(kzE{kz.json,host}) closed\n"); + xlog("L_WARN","connection to $(kzE{kz.json,host}) closed\n"); } event_route[kazoo:consumer-event-connection-zone-available] @@ -69,4 +69,48 @@ event_route[kazoo:consumer-event-connection-zone-unavailable] xlog("L_WARN","amqp zone $(kzE{kz.json,zone}) is unavailable\n"); } +event_route[kazoo:consumer-event-connection-available] +{ + xlog("L_DEBUG","amqp zone $(kzE{kz.json,zone}) is available\n"); +} + +event_route[kazoo:consumer-event-connection-unavailable] +{ + xlog("L_DEBUG","amqp zone $(kzE{kz.json,zone}) is unavailable\n"); +} + +event_route[kazoo:consumer-event-connection-zone-listener-available] +{ + xlog("L_DEBUG","amqp zone $(kzE{kz.json,zone}) is available\n"); +} + +event_route[kazoo:consumer-event-connection-zone-listener-unavailable] +{ + xlog("L_DEBUG","amqp zone $(kzE{kz.json,zone}) is unavailable\n"); +} + +event_route[kazoo:consumer-event-connection-listener-zone-available] +{ + xlog("L_DEBUG","amqp zone $(kzE{kz.json,zone}) is available\n"); +} + +event_route[kazoo:consumer-event-connection-listener-zone-unavailable] +{ + xlog("L_DEBUG","amqp zone $(kzE{kz.json,zone}) is unavailable\n"); + + #!ifdef PRESENCE_ROLE + route(PRESENCE_ZONE_UNAVAILABLE); + #!endif +} + +event_route[kazoo:consumer-event-connection-listener-available] +{ + xlog("L_DEBUG","amqp zone $(kzE{kz.json,zone}) is available\n"); +} + +event_route[kazoo:consumer-event-connection-listener-unavailable] +{ + xlog("L_DEBUG","amqp zone $(kzE{kz.json,zone}) is unavailable\n"); +} + # vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab diff --git a/kamailio/presence-notify.cfg b/kamailio/presence-notify.cfg index c6c9a2c..1ff7c09 100644 --- a/kamailio/presence-notify.cfg +++ b/kamailio/presence-notify.cfg @@ -154,7 +154,9 @@ route[PRESENCE_PUBLISHER_CLEANUP] if($var(sqlres) < 0) { xlog("L_ERROR", "$var(ci)|log|error cleaning tmp_probe\n"); } else { - $var(nrows) = $sqlrows(cb); - xlog("L_INFO", "presence publisher cleanup processed $var(nrows) rows\n"); + $var(nrows) = $sqlrows(cb); + if($var(nrows) > 0) { + xlog("L_INFO", "presence publisher cleanup processed $var(nrows) rows\n"); + } } } diff --git a/kamailio/presence-reset.cfg b/kamailio/presence-reset.cfg index 7511110..027fa8d 100644 --- a/kamailio/presence-reset.cfg +++ b/kamailio/presence-reset.cfg @@ -42,6 +42,30 @@ route[RESET_PUBLISHER] } } +route[PRESENCE_ZONE_UNAVAILABLE] +{ + if($(kzE{kz.json,name}) == "presence") { + $var(Zone) = $(kzE{kz.json,zone}); + xlog("L_WARN", "amqp|reset|resetting publisher zone $var(Zone)\n"); + route(RESET_PUBLISHER_ZONE); + } +} + +route[RESET_PUBLISHER_ZONE] +{ + if($sel(cfg_get.kazoo.presence_reset_blf_defer_update) == 0) { + $var(Query) = $_s(KZQ_RESET_PUBLISHER_ZONE_UPDATE); + sql_query("exec", "$var(Query)"); + } + $var(Query) = $_s(KZQ_PRESENCE_ZONE_RESET); + sql_query("exec", "$var(Query)"); + $var(presentities) = $sqlrows(exec); + xlog("L_INFO", "$var(Msg-ID)|reset|removed $var(presentities) presentities from publisher $var(MediaUrl)\n"); + if($var(presentities) > 0) { + route(PRESENCE_PUBLISHER_CLEANUP); + } +} + route[RESET_ALL] { xlog("L_INFO", "$var(Msg-ID)|reset|received presence reset ALL\n"); diff --git a/kamailio/presence-role.cfg b/kamailio/presence-role.cfg index 3028ea2..260ef1b 100644 --- a/kamailio/presence-role.cfg +++ b/kamailio/presence-role.cfg @@ -469,7 +469,7 @@ route[PRESENCE_BINDINGS] #!import_file "presence-custom-bindings.cfg" #!ifndef PRESENCE_CUSTOM_BINDINGS - $var(payload) = $_s({ "exchange" : "presence", "type" : "topic", "queue" : "presence-dialog-MY_HOSTNAME", "routing" : ["dialog.*.*", "update.*.*", "mwi_updates.*.*"], "exclusive" : 0, "federate" : 1 }); + $var(payload) = $_s({ "name" : "presence", "exchange" : "presence", "type" : "topic", "queue" : "presence-dialog-MY_HOSTNAME", "routing" : ["dialog.*.*", "update.*.*", "mwi_updates.*.*"], "exclusive" : 0, "federate" : 1 }); kazoo_subscribe("$var(payload)"); #!endif From d955ed249d2bd604002efe35839defce3fdec456 Mon Sep 17 00:00:00 2001 From: lazedo Date: Fri, 30 Nov 2018 19:39:00 +0000 Subject: [PATCH 047/209] add index to dispatcher --- kamailio/db_scripts/db_kazoo-specific | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kamailio/db_scripts/db_kazoo-specific b/kamailio/db_scripts/db_kazoo-specific index e21ab71..85d731b 100644 --- a/kamailio/db_scripts/db_kazoo-specific +++ b/kamailio/db_scripts/db_kazoo-specific @@ -67,6 +67,8 @@ CREATE TABLE active_watchers_log ( cast(substr(attrs, instr(attrs, "idx=")+4, instr(attrs, ";node")-instr(attrs, "idx=")-4) as integer) idx, cast(substr(attrs, instr(attrs, "node=")+5) as varchar(50)) node from dispatcher; + + create unique index if not exists idx_dispatcher_destination on dispatcher(destination); EOF } From 3b26d5509fd46a3958b8872601d6d434deda3fd6 Mon Sep 17 00:00:00 2001 From: lazedo Date: Sat, 1 Dec 2018 03:22:59 +0000 Subject: [PATCH 048/209] fix log message for reset zone --- kamailio/presence-reset.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kamailio/presence-reset.cfg b/kamailio/presence-reset.cfg index 027fa8d..1a40e7c 100644 --- a/kamailio/presence-reset.cfg +++ b/kamailio/presence-reset.cfg @@ -60,7 +60,7 @@ route[RESET_PUBLISHER_ZONE] $var(Query) = $_s(KZQ_PRESENCE_ZONE_RESET); sql_query("exec", "$var(Query)"); $var(presentities) = $sqlrows(exec); - xlog("L_INFO", "$var(Msg-ID)|reset|removed $var(presentities) presentities from publisher $var(MediaUrl)\n"); + xlog("L_INFO", "amqp|reset|removed $var(presentities) presentities from zone $var(Zone)\n"); if($var(presentities) > 0) { route(PRESENCE_PUBLISHER_CLEANUP); } From 2948a2e05e1a72d76f346502848e7c43e4b163a8 Mon Sep 17 00:00:00 2001 From: lazedo Date: Mon, 10 Dec 2018 22:50:24 +0000 Subject: [PATCH 049/209] rework presence cleanup --- kamailio/db_queries_kazoo.cfg | 6 ++-- kamailio/db_scripts/db_extra_check.sql | 2 +- kamailio/default.cfg | 2 +- kamailio/presence-notify.cfg | 50 ++++++++++++++++++++------ 4 files changed, 45 insertions(+), 15 deletions(-) diff --git a/kamailio/db_queries_kazoo.cfg b/kamailio/db_queries_kazoo.cfg index e022c02..315c327 100644 --- a/kamailio/db_queries_kazoo.cfg +++ b/kamailio/db_queries_kazoo.cfg @@ -12,12 +12,12 @@ #!substdef "!KZQ_REPLACE_WATCHERS_LOG!REPLACE INTO active_watchers_log (presentity_uri, watcher_username, watcher_domain, event, callid, to_user, to_domain, user_agent, time, result, sent_msg, received_msg) VALUES (\"\$subs(uri)\", \"\$subs(watcher_username)\", \"\$subs(watcher_domain)\", \"\$subs(event)\",\"\$subs(callid)\",\"\$subs(to_user)\",\"\$subs(to_domain)\", '\$(subs(user_agent){s.escape.common}{s.replace,\\\',''}{s.replace,\$\$,})', \$TS, \$notify_reply(\$rs), '\$(mb{s.escape.common}{s.replace,\\\',''}{s.replace,\$\$,})', '\$(notify_reply(\$mb){s.escape.common}{s.replace,\\\',''}{s.replace,\$\$,})')!g" # # #!substdef "!KZQ_RESET_PUBLISHER_UPDATE!update active_watchers set expires = \$TS where id in (select b.id from presentity a inner join active_watchers b on a.username = b.to_user and a.domain = b.to_domain and a.event = b.event where a.sender = \"\$var(MediaUrl)\")!g" -#!substdef "!KZQ_RESET_PUBLISHER_UPDATE!INSERT INTO tmp_probe select distinct a.event, a.presentity_uri from presentities a inner join active_watchers b on a.presentity_uri = b.presentity_uri and a.event = b.event where sender = \"\$var(MediaUrl)\" and state in('early', 'confirmed', 'onthephone', 'busy')!g" +#!substdef "!KZQ_RESET_PUBLISHER_UPDATE!INSERT INTO tmp_probe select distinct a.event, a.presentity_uri, 0 from presentities a inner join active_watchers b on a.presentity_uri = b.presentity_uri and a.event = b.event where sender = \"\$var(MediaUrl)\" and state in('early', 'confirmed', 'onthephone', 'busy')!g" #!substdef "!KZQ_PRESENCE_RESET!delete from presentity where sender = \"\$var(MediaUrl)\"!g" # # #!substdef "!KZQ_RESET_ACCOUNT_UPDATE!update active_watchers set expires = \$TS where watcher_domain=\"\$(kzE{kz.json,Realm})\"!g" -#!substdef "!KZQ_RESET_ACCOUNT_UPDATE!INSERT INTO tmp_probe select distinct a.event, a.presentity_uri from presentities a inner join active_watchers b on a.presentity_uri = b.presentity_uri and a.event = b.event where domain=\"\$(kzE{kz.json,Realm})\" and state in('early', 'confirmed', 'onthephone', 'busy')!g" +#!substdef "!KZQ_RESET_ACCOUNT_UPDATE!INSERT INTO tmp_probe select distinct a.event, a.presentity_uri, 0 from presentities a inner join active_watchers b on a.presentity_uri = b.presentity_uri and a.event = b.event where domain=\"\$(kzE{kz.json,Realm})\" and state in('early', 'confirmed', 'onthephone', 'busy')!g" #!substdef "!KZQ_RESET_ACCOUNT_RESET!delete from presentity where domain=\"\$(kzE{kz.json,Realm})\"!g" -#!substdef "!KZQ_RESET_PUBLISHER_ZONE_UPDATE!INSERT INTO tmp_probe select distinct a.event, a.presentity_uri from presentities a inner join wdispatcher c on a.sender = c.destination inner join active_watchers b on a.presentity_uri = b.presentity_uri and a.event = b.event where zone = \"\$var(Zone)\" and state in('early', 'confirmed', 'onthephone', 'busy')!g" +#!substdef "!KZQ_RESET_PUBLISHER_ZONE_UPDATE!INSERT INTO tmp_probe select distinct a.event, a.presentity_uri, 0 from presentities a inner join wdispatcher c on a.sender = c.destination inner join active_watchers b on a.presentity_uri = b.presentity_uri and a.event = b.event where zone = \"\$var(Zone)\" and state in('early', 'confirmed', 'onthephone', 'busy')!g" #!substdef "!KZQ_PRESENCE_ZONE_RESET!delete from presentity where id in(select a.id from presentities a join wdispatcher c on a.sender = c.destination where zone = \"\$var(Zone)\")!g" diff --git a/kamailio/db_scripts/db_extra_check.sql b/kamailio/db_scripts/db_extra_check.sql index bb88caa..157d7bf 100644 --- a/kamailio/db_scripts/db_extra_check.sql +++ b/kamailio/db_scripts/db_extra_check.sql @@ -17,7 +17,7 @@ KazooDB -db ${DB_CURRENT_DB} "delete from presentity where id in(select id from ## notify watchers of pending calls ## 'create temp table as' because it will be dropped as soon as we ended the session KazooDB -db ${DB_CURRENT_DB} "drop table if exists tmp_probe;" -KazooDB -db ${DB_CURRENT_DB} "create table tmp_probe as select distinct a.event, a.presentity_uri from presentities a inner join active_watchers b on a.presentity_uri = b.presentity_uri and a.event = b.event where state in('early', 'confirmed', 'onthephone', 'busy');" +KazooDB -db ${DB_CURRENT_DB} "create table tmp_probe as select distinct a.event, a.presentity_uri, cast(2 as integer) action from presentities a inner join active_watchers b on a.presentity_uri = b.presentity_uri and a.event = b.event where state in('early', 'confirmed', 'onthephone', 'busy');" KazooDB -db ${DB_CURRENT_DB} "delete from presentity where id in(select id from presentities where state in('early', 'confirmed', 'onthephone', 'busy'));" } diff --git a/kamailio/default.cfg b/kamailio/default.cfg index 9c75912..1f748a3 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -971,7 +971,7 @@ event_route[evrexec:DEFERRED_INIT] xlog("L_INFO", "processing deferred init\n"); #!ifdef PRESENCE_ROLE - route(PRESENCE_PUBLISHER_CLEANUP); + route(PRESENCE_DEFERRED_INIT); #!endif #!import_file "custom-init.cfg" diff --git a/kamailio/presence-notify.cfg b/kamailio/presence-notify.cfg index 1ff7c09..437c43c 100644 --- a/kamailio/presence-notify.cfg +++ b/kamailio/presence-notify.cfg @@ -44,6 +44,9 @@ modparam("rtimer", "timer", "name=notifytimer;interval=500000u;mode=1;") modparam("rtimer", "exec", "timer=notifytimer;route=PRESENCE_LOG_TIMER_ROUTE") modparam("rtimer", "timer", "name=pres_cleanup;interval=10;mode=1;") modparam("rtimer", "exec", "timer=pres_cleanup;route=PRESENCE_CLEANUP") +modparam("rtimer", "timer", "name=pres_publisher_cleanup;interval=5;mode=1;") +modparam("rtimer", "exec", "timer=pres_publisher_cleanup;route=PRESENCE_PUBLISHER_CLEANUP") + event_route[presence:notify-reply] { @@ -141,22 +144,49 @@ route[PRESENCE_CLEANUP] route[PRESENCE_PUBLISHER_CLEANUP] { - xlog("L_INFO", "processing presence publisher cleanup\n"); - if (sql_xquery("cb", "select * from tmp_probe", "ra") == 1) - { - while($xavp(ra) != $null) { - xlog("L_DEBUG", "processing $xavp(ra=>event) notifies for $xavp(ra=>presentity_uri)\n"); - pres_refresh_watchers("$xavp(ra=>presentity_uri)", "$xavp(ra=>event)", 1); - pv_unset("$xavp(ra)"); + xlog("L_DEBUG", "processing presence publisher cleanup\n"); + + $var(sqlres) = sql_query("cb", "update tmp_probe set action = 1 where action = 0"); + if($var(sqlres) < 0) { + xlog("L_ERROR", "$var(ci)|log|error cleaning tmp_probe\n"); + return; + } else { + $var(nrows) = $sqlrows(cb); + if($var(nrows) > 0) { + if (sql_xquery("cb", "select * from tmp_probe where action = 1", "cleanup_pres") == 1) + { + while($xavp(cleanup_pres) != $null) { + xlog("L_DEBUG", "processing $xavp(cleanup_pres=>event) notifies for $xavp(cleanup_pres=>presentity_uri)\n"); + pres_refresh_watchers("$xavp(cleanup_pres=>presentity_uri)", "$xavp(cleanup_pres=>event)", 1); + pv_unset("$xavp(cleanup_pres)"); + } + } + + $var(sqlres) = sql_query("cb", "delete from tmp_probe where action = 1"); + if($var(sqlres) < 0) { + xlog("L_ERROR", "$var(ci)|log|error cleaning tmp_probe\n"); + } else { + $var(nrows) = $sqlrows(cb); + if($var(nrows) > 0) { + xlog("L_DEBUG", "presence publisher cleanup processed $var(nrows) rows\n"); + } + } } } - $var(sqlres) = sql_query("cb", "delete from tmp_probe"); + +} + +route[PRESENCE_DEFERRED_INIT] +{ + xlog("L_INFO", "processing presence deferred init\n"); + $var(sqlres) = sql_query("cb", "update tmp_probe set action = 0 where action = 2"); if($var(sqlres) < 0) { xlog("L_ERROR", "$var(ci)|log|error cleaning tmp_probe\n"); + return; } else { $var(nrows) = $sqlrows(cb); if($var(nrows) > 0) { - xlog("L_INFO", "presence publisher cleanup processed $var(nrows) rows\n"); + xlog("L_NOTICE", "scheduled update for $var(nrows) watched presentities/event\n"); } } -} +} \ No newline at end of file From f5be8ad5c797897909f76b92256042c71938d5d2 Mon Sep 17 00:00:00 2001 From: lazedo Date: Fri, 14 Dec 2018 18:41:56 +0000 Subject: [PATCH 050/209] presence detail should query based on active watchers --- kamailio/db_queries_kazoo.cfg | 4 +++- kamailio/presence-query.cfg | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/kamailio/db_queries_kazoo.cfg b/kamailio/db_queries_kazoo.cfg index 315c327..7ce9458 100644 --- a/kamailio/db_queries_kazoo.cfg +++ b/kamailio/db_queries_kazoo.cfg @@ -6,8 +6,10 @@ #!substdef "!KZQ_EVENT_PRESENCE_RESET_DELETE!delete from presentity where domain=\"\$(kzE{kz.json,Realm})\" and username = \"\$(kzE{kz.json,Username})\"!g" #!substdef "!KZQ_HANDLE_NEW_SUBSCRIBE_DELETE1!delete from active_watchers where callid = \"\$ci\"!g" #!substdef "!KZQ_HANDLE_NEW_SUBSCRIBE_DELETE2!delete from active_watchers where watcher_username=\"\$fU\" and presentity_uri=\"\$var(presentity_uri)\" and to_user=\"\$tU\" and watcher_domain=\"\$fd\" and event=\"\$hdr(Event)\"!g" -#!substdef "!KZQ_PRESENCE_SEARCH_DETAIL!select * from active_watchers_log where presentity_uri = \"\$var(presentity_uri)\" and callid in(select callid from active_watchers where presentity_uri = \"\$var(presentity_uri)\")!g" + #!substdef "!KZQ_PRESENCE_SEARCH_SUMMARY!select * from active_watchers where to_domain = \"\$var(Domain)\"!g" +#!substdef "!KZQ_PRESENCE_SEARCH_DETAIL!select a.*, b.time, b.result, b.sent_msg, b.received_msg from active_watchers a left outer join active_watchers_log b on a.presentity_uri = b.presentity_uri and a.event = b.event and a.callid = b.callid where a.presentity_uri = \"\$var(presentity_uri)\" !g" + #!substdef "!KZQ_HAS_PRESENTITY!select count(*) as count from presentity where username = \"\$subs(to_user)\" and domain = \"\$subs(to_domain)\" and event = \"\$subs(event)\"!g" #!substdef "!KZQ_REPLACE_WATCHERS_LOG!REPLACE INTO active_watchers_log (presentity_uri, watcher_username, watcher_domain, event, callid, to_user, to_domain, user_agent, time, result, sent_msg, received_msg) VALUES (\"\$subs(uri)\", \"\$subs(watcher_username)\", \"\$subs(watcher_domain)\", \"\$subs(event)\",\"\$subs(callid)\",\"\$subs(to_user)\",\"\$subs(to_domain)\", '\$(subs(user_agent){s.escape.common}{s.replace,\\\',''}{s.replace,\$\$,})', \$TS, \$notify_reply(\$rs), '\$(mb{s.escape.common}{s.replace,\\\',''}{s.replace,\$\$,})', '\$(notify_reply(\$mb){s.escape.common}{s.replace,\\\',''}{s.replace,\$\$,})')!g" diff --git a/kamailio/presence-query.cfg b/kamailio/presence-query.cfg index 2041cb0..ce48eea 100644 --- a/kamailio/presence-query.cfg +++ b/kamailio/presence-query.cfg @@ -65,7 +65,7 @@ route[PRESENCE_SEARCH_DETAIL] $var(Items) = ""; $var(Query) = $_s(KZQ_PRESENCE_SEARCH_DETAIL); if($var(Event) != "") { - $var(Query) = $var(Query) + $_s( and event = "$var(Event)"); + $var(Query) = $var(Query) + $_s( and a.event = "$var(Event)"); } $var(Query) = $var(Query) + " order by event, watcher_username, callid"; xlog("L_DEBUG", "$ci| STATUS QUERY $var(Query)\n"); From 889fa8f9e112a4b3c40c07f34899135813027672 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 27 Dec 2018 15:21:40 +0000 Subject: [PATCH 051/209] do not try to resize if it doesn't fit --- system/sbin/kazoo-kamailio | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/system/sbin/kazoo-kamailio b/system/sbin/kazoo-kamailio index 675f369..df7c0f0 100755 --- a/system/sbin/kazoo-kamailio +++ b/system/sbin/kazoo-kamailio @@ -73,23 +73,24 @@ prepare() { rm -rf ${DB_LOCATION}/../db-backup-temp elif [ $mountcurrentsize -gt $mountwantedsize ]; then # check if it fits - echo "wanted size of $mountwantedsize is below current size of $mountcurrentsize , remounting" + echo "wanted size of $mountwantedsize is below current size of $mountcurrentsize , checking sizes" mountusedsize=$(mount_point_used_size) requiredsize=$(( mountusedsize * (100 + ${RAM_DISK_FREE_SIZE_PERC}) / 100)) if [ $requiredsize -gt $mountwantedsize ]; then - echo "wanted size of $mountwantedsize doesn't have enough space for required size of $requiredsize , setting to $requiredsize" + echo "wanted size of $mountwantedsize doesn't have enough space for required size of $requiredsize" mountwantedsize=$requiredsize + else + echo "resizing from $mountcurrentsize to $mountwantedsize" + rm -rf ${DB_LOCATION}/../db-backup-temp + mkdir -p ${DB_LOCATION}/../db-backup-temp + cp -f ${DB_LOCATION}/* ${DB_LOCATION}/../db-backup-temp/ + umount ${DB_LOCATION} + rm -rf ${DB_LOCATION} + mkdir -p ${DB_LOCATION} + mount -t tmpfs -o size=$mountwantedsize tmpfs ${DB_LOCATION} + cp -f ${DB_LOCATION}/../db-backup-temp/* ${DB_LOCATION}/ + rm -rf ${DB_LOCATION}/../db-backup-temp fi - echo "resizing from $mountcurrentsize to $mountwantedsize" - rm -rf ${DB_LOCATION}/../db-backup-temp - mkdir -p ${DB_LOCATION}/../db-backup-temp - cp -f ${DB_LOCATION}/* ${DB_LOCATION}/../db-backup-temp/ - umount ${DB_LOCATION} - rm -rf ${DB_LOCATION} - mkdir -p ${DB_LOCATION} - mount -t tmpfs -o size=$mountwantedsize tmpfs ${DB_LOCATION} - cp -f ${DB_LOCATION}/../db-backup-temp/* ${DB_LOCATION}/ - rm -rf ${DB_LOCATION}/../db-backup-temp fi fi else From 4f6ac2310231fa2044d43361a0f507fc3590b03f Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 27 Dec 2018 15:50:18 +0000 Subject: [PATCH 052/209] simpler log line --- kamailio/presence-role.cfg | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kamailio/presence-role.cfg b/kamailio/presence-role.cfg index 260ef1b..7b75c31 100644 --- a/kamailio/presence-role.cfg +++ b/kamailio/presence-role.cfg @@ -360,7 +360,7 @@ event_route[kazoo:consumer-event-presence-dialog-update] $var(EndRoute) = $(TV(Sn){s.replace,.,}); $var(delta_to_finish) = $var(EndRoute) - $var(StartRoute); - xlog("L_INFO", "$(kzE{kz.json,Call-ID})|log|finished processing $(kzE{kz.json,Event-Package}) update for $(kzE{kz.json,From}) state $(kzE{kz.json,State}) from $(kzE{kz.json,AMQP-Broker-Zone}) => $(kzE{kz.json,Switch-URI}) (Δ1 $(kzE{kz.json,AMQP-Elapsed-Micro}) μs , Δ2 $var(delta_to_start) μs, Δ3 $var(delta_to_finish) μs)\n"); + xlog("L_INFO", "$(kzE{kz.json,Call-ID})|log|$(kzE{kz.json,Event-Package}) update for $(kzE{kz.json,From}) state $(kzE{kz.json,State}) from $(kzE{kz.json,AMQP-Broker-Zone}) => $(kzE{kz.json,Switch-URI}) (Δ1 $(kzE{kz.json,AMQP-Elapsed-Micro}) μs , Δ2 $var(delta_to_start) μs, Δ3 $var(delta_to_finish) μs)\n"); } event_route[kazoo:consumer-event-presence-mwi-update] @@ -376,7 +376,7 @@ event_route[kazoo:consumer-event-presence-mwi-update] } route(MWI_AS_PRESENCE); - xlog("L_DBG", "$(kzE{kz.json,Call-ID})|log|finished processing message-summary update for $(kzE{kz.json,From}) light should be on ? $(kzE{kz.json,Messages-Waiting}) at $(kzE{kz.json,AMQP-Received})/$var(Now)/$TS\n"); + xlog("L_DBG", "$(kzE{kz.json,Call-ID})|log|message-summary update for $(kzE{kz.json,From}) light should be on ? $(kzE{kz.json,Messages-Waiting}) at $(kzE{kz.json,AMQP-Received})/$var(Now)/$TS\n"); } @@ -395,7 +395,7 @@ event_route[kazoo:consumer-event-presence-update] $var(payload) = $kzE; route(PRESENCE_UPDATE); - xlog("L_DEBUG", "$(kzE{kz.json,Call-ID})|log|finished processing $(kzE{kz.json,Event-Package}) update for $(kzE{kz.json,From}) state $(kzE{kz.json,State}) from $(kzE{kz.json,Switch-URI}) Δ at $(kzE{kz.json,AMQP-Received})/$var(Now)/$TS\n"); + xlog("L_DEBUG", "$(kzE{kz.json,Call-ID})|log|$(kzE{kz.json,Event-Package}) update for $(kzE{kz.json,From}) state $(kzE{kz.json,State}) from $(kzE{kz.json,Switch-URI}) Δ at $(kzE{kz.json,AMQP-Received})/$var(Now)/$TS\n"); } route[PRESENCE_UPDATE] From 9708ee97c79b079d52f5096d44105a933fbd9c56 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 27 Dec 2018 16:27:13 +0000 Subject: [PATCH 053/209] allow tracking all presence packages --- kamailio/presence-role.cfg | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/kamailio/presence-role.cfg b/kamailio/presence-role.cfg index 7b75c31..1bfd65e 100644 --- a/kamailio/presence-role.cfg +++ b/kamailio/presence-role.cfg @@ -373,6 +373,17 @@ event_route[kazoo:consumer-event-presence-mwi-update] xlog("L_INFO", "$(kzE{kz.json,Call-ID})|log|publishing $(kzE{kz.json,From}) message-summary update for $xavp(watchers=>message-summary) watchers\n"); kazoo_pua_publish_mwi($kzE); pres_refresh_watchers("$(kzE{kz.json,From})", "message-summary", 1); + } else { +#!ifdef PRESENCE_TRACK_ALL_PKG_MWI + if($(kzE{kz.json,Event-Package}) == "message-summary") { + xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|saving $var(presentity) from mwi update => $var(payload)\n"); + if(kazoo_pua_publish_mwi($kzE) != 1) { + xlog("L_ERR", "$(var(payload){kz.json,Call-ID})|log|error publishing $var(presentity) mwi update => $var(payload)\n"); + } + } +#!else + xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|skip mwi update for $var(presentity)\n"); +#!endif } route(MWI_AS_PRESENCE); @@ -423,12 +434,34 @@ route[PRESENCE_UPDATE] } else { xlog("L_ERR", "$(var(payload){kz.json,Call-ID})|log|error publishing $var(presentity) dialog update\n"); }; + } else { +#!ifdef PRESENCE_TRACK_ALL_PKG_DIALOG + if($(kzE{kz.json,Event-Package}) == "dialog") { + xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|saving $var(presentity) from dialog update => $var(payload)\n"); + if(kazoo_pua_publish_dialoginfo($var(JObj)) != 1) { + xlog("L_ERR", "$(var(payload){kz.json,Call-ID})|log|error publishing $var(presentity) dialog update => $var(payload)\n"); + } + } +#!else + xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|skip dialog update for $var(presentity)\n"); +#!endif } if($xavp(watchers=>presence) > 0) { xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|publishing $var(presentity) presence update for $xavp(watchers=>presence) watchers\n"); kazoo_pua_publish_presence($var(payload)); pres_refresh_watchers("$var(presentity)", "presence", 1); + } else { +#!ifdef PRESENCE_TRACK_ALL_PKG_PRESENCE + if($(kzE{kz.json,Event-Package}) == "presence") { + xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|saving $var(presentity) from dialog update => $var(payload)\n"); + if(kazoo_pua_publish_dialoginfo($var(JObj)) != 1) { + xlog("L_ERR", "$(var(payload){kz.json,Call-ID})|log|error publishing $var(presentity) dialog update => $var(payload)\n"); + } + } +#!else + xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|skip dialog update for $var(presentity)\n"); +#!endif } } From c7bd8344d4388b0601ac2b6a20f62fa46f2bd3cf Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 27 Dec 2018 16:46:23 +0000 Subject: [PATCH 054/209] fix log line --- kamailio/presence-role.cfg | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kamailio/presence-role.cfg b/kamailio/presence-role.cfg index 1bfd65e..f86720c 100644 --- a/kamailio/presence-role.cfg +++ b/kamailio/presence-role.cfg @@ -443,7 +443,7 @@ route[PRESENCE_UPDATE] } } #!else - xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|skip dialog update for $var(presentity)\n"); + xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|skip dialog update for $var(presentity)\n"); #!endif } @@ -460,8 +460,8 @@ route[PRESENCE_UPDATE] } } #!else - xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|skip dialog update for $var(presentity)\n"); -#!endif + xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|skip presence update for $var(presentity)\n"); +#!endif } } From d8f70d89339eaad4de204f24377886a9b44ce351 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 3 Jan 2019 09:54:27 +0000 Subject: [PATCH 055/209] add delta logging to registrar --- kamailio/registrar-role.cfg | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/kamailio/registrar-role.cfg b/kamailio/registrar-role.cfg index 3ccb286..8fbf4fa 100644 --- a/kamailio/registrar-role.cfg +++ b/kamailio/registrar-role.cfg @@ -191,27 +191,30 @@ route[ATTEMPT_AUTHORIZATION] exit; } + sl_send_reply("100", "checking your credentials"); $var(amqp_payload_request) = $_s({"Event-Category" : "directory" , "Event-Name" : "authn_req", "Method" : "REGISTER", "Auth-Nonce" : "$adn", "Auth-Realm" : "$fd", "Auth-User" : "$fU", "From" : "$fu", "To" : "$tu", "Orig-IP" : "$si", "Orig-Port" : "$sp", "User-Agent" : "$(ua{s.escape.common}{s.replace,\','}{s.replace,$$,})", "Contact" : "$(ct{s.escape.common}{s.replace,\','}{s.replace,$$,})", "Call-ID" : "$ci" }); $var(amqp_routing_key) = "authn.req." + $(fd{kz.encode}); $avp(kz_timeout) = $sel(cfg_get.kazoo.registrar_query_timeout_ms); + $xavp(deltas=>query) = $(TV(Sn){s.replace,.,}); - sl_send_reply("100", "checking your credentials"); - - if(kazoo_async_query("callmgr", $var(amqp_routing_key), $var(amqp_payload_request), "KZ_AUTHORIZATION_OK", "KZ_AUTHORIZATION_ERROR") != 1) { + if(kazoo_async_query("callmgr", $var(amqp_routing_key), $var(amqp_payload_request), "KZ_AUTHORIZATION_REPLY", "KZ_AUTHORIZATION_TIMEOUT") != 1) { xlog("L_INFO", "$ci|log|failed to send registrar query for authentication credentials for $Au $si:$sp\n"); t_drop(); } } -failure_route[KZ_AUTHORIZATION_ERROR] +failure_route[KZ_AUTHORIZATION_TIMEOUT] { xlog("L_INFO", "$ci|log|failed $T_reply_code to query Kazoo for authentication credentials for $Au $si:$sp\n"); t_drop(); } -onreply_route[KZ_AUTHORIZATION_OK] +onreply_route[KZ_AUTHORIZATION_REPLY] { - xlog("L_INFO", "$ci|log|received $(kzR{kz.json,Event-Category}) $(kzR{kz.json,Event-Name}) reply from $(kzR{kz.json,App-Name})-$(kzR{kz.json,App-Version})\n"); + $var(StartRoute) = $(TV(Sn){s.replace,.,}); + $var(delta_to_start) = $var(StartRoute) - $(kzR{kz.json,AMQP-Received}); + $var(delta_from_query) = $(kzR{kz.json,AMQP-Received}) - $xavp(deltas=>query); + xlog("L_INFO", "$ci|log|received $(kzR{kz.json,Event-Category}) $(kzR{kz.json,Event-Name}) reply from $(kzR{kz.json,App-Name})-$(kzR{kz.json,App-Version}) (Δ1 $(kzR{kz.json,AMQP-Elapsed-Micro}) μs , Δ2 $var(delta_to_start) μs, Δ3 $var(delta_from_query) μs)\n"); $var(password) = $(kzR{kz.json,Auth-Password}); $var(nonce) = $adn; if( $(kzR{kz.json,Event-Name}) == "authn_err" ) { From 0bf1987c7464fa68756dbafe3688c77a80324670 Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 8 Jan 2019 17:49:09 +0000 Subject: [PATCH 056/209] decouple nat port/contact tests --- kamailio/defs.cfg | 4 ---- kamailio/local.cfg | 7 +++---- kamailio/nat-traversal-role.cfg | 11 ++++++++++- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/kamailio/defs.cfg b/kamailio/defs.cfg index 558dc96..1e3d26b 100644 --- a/kamailio/defs.cfg +++ b/kamailio/defs.cfg @@ -54,10 +54,6 @@ #!trydef KZ_PRESENCE_REQUEST_RESUBSCRIBE_PROBE 0 #!trydef KZ_PRESENCE_REQUEST_PROBE 1 -#!ifndef NAT_UAC_TEST_LEVEL -#!substdef "!NAT_UAC_TEST_LEVEL!3!g" -#!endif - #!trydef RR_FULL_LR 1 #!trydef RR_DOUBLE_RR 1 #!trydef RR_FORCE_SOCKET 1 diff --git a/kamailio/local.cfg b/kamailio/local.cfg index 9bb050b..5dfb13f 100644 --- a/kamailio/local.cfg +++ b/kamailio/local.cfg @@ -111,10 +111,9 @@ ## NAT ################################################################################ ## These parameters are OPTIONAL. -## It allows overriding the nat_uac_test with a different value than "3" -## (default) as it is proven that it fixes the issue reported here: -## https://lists.kamailio.org/pipermail/sr-users/2016-August/094211.html -# # #!substdef "!NAT_UAC_TEST_LEVEL!1!g" +## It allows overriding the nat_uac_test for port / contact with different values +# # #!trydef KZ_NAT_CONTACT_DETECT "1" +# # #!trydef KZ_NAT_PORT_DETECT "2" ################################################################################ ## SIP traffic mirroring to SIP_TRACE server diff --git a/kamailio/nat-traversal-role.cfg b/kamailio/nat-traversal-role.cfg index 7b087bf..8e66e98 100644 --- a/kamailio/nat-traversal-role.cfg +++ b/kamailio/nat-traversal-role.cfg @@ -6,6 +6,9 @@ loadmodule "nathelper.so" modparam("nathelper", "received_avp", "$avp(AVP_RECV_PARAM)") modparam("nathelper", "sipping_from", "sip:sipcheck@MY_HOSTNAME") +#!trydef KZ_NAT_CONTACT_DETECT "1" +#!trydef KZ_NAT_PORT_DETECT "2" + ####### NAT Traversal Logic ######## route[NAT_TEST_AND_CORRECT] { @@ -20,6 +23,7 @@ route[NAT_TEST_AND_CORRECT] $var(i) = $var(i) + 1; if (!is_myself("$(var(rr){nameaddr.uri})")) { setflag(FLAG_SKIP_NAT_CORRECTION); + xlog("L_DEBUG", "$ci|log|skipping nat correction on record-route $(var(rr){nameaddr.uri})\n"); } $var(rr_idx) = $var(rr_idx) + 1; $var(rr) = $(var(rr_base){s.select,$var(rr_idx),,}); @@ -33,8 +37,13 @@ route[NAT_TEST_AND_CORRECT] return(); } - if (nat_uac_test("NAT_UAC_TEST_LEVEL")) { + if (nat_uac_test(KZ_NAT_PORT_DETECT)) { + xlog("L_DEBUG", "$ci|nat|forcing rport\n"); force_rport(); + } + + if (nat_uac_test(KZ_NAT_CONTACT_DETECT)) { + xlog("L_DEBUG", "$ci|nat|contact correction\n"); fix_nated_contact(); } From a3952523c895f8637081e4c48b8498de594faf23 Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 9 Jan 2019 12:32:05 +0000 Subject: [PATCH 057/209] memlog must be lower than debug for kamcmd corex.shm_summary to work, we still don't log on exit --- kamailio/default.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kamailio/default.cfg b/kamailio/default.cfg index 1f748a3..1777d68 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -28,7 +28,7 @@ mem_join=1 ####### Logging Parameters ######### debug = KAZOO_LOG_LEVEL memdbg = 10 -memlog = L_INFO +memlog = L_BUG corelog = L_ERR mem_summary = 0 log_stderror = no From b8f39a5327ea3b24c8aa6c4c8210dc8d76b71076 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 10 Jan 2019 05:54:57 +0000 Subject: [PATCH 058/209] add some flags --- kamailio/accounting-role.cfg | 6 +++--- kamailio/default.cfg | 5 ++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/kamailio/accounting-role.cfg b/kamailio/accounting-role.cfg index 7c58cb5..fb1b916 100644 --- a/kamailio/accounting-role.cfg +++ b/kamailio/accounting-role.cfg @@ -1,8 +1,8 @@ ####### Flags ####### flags - FLAG_ACC: 8, - FLAG_ACCMISSED: 9, - FLAG_ACCFAILED: 10; + FLAG_ACC: 12, + FLAG_ACCMISSED: 13, + FLAG_ACCFAILED: 14; ######## Accounting module ######## loadmodule "acc.so" diff --git a/kamailio/default.cfg b/kamailio/default.cfg index 1777d68..6118cf3 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -9,7 +9,10 @@ flags FLAG_TRUSTED_SOURCE: 5, FLAG_SESSION_PROGRESS: 6, FLAG_IS_REPLY: 7, - FLAG_SIP_TRACE: 8; + FLAG_SIP_TRACE: 8, + FLAG_AOR: 9, + FLAG_T38: 10, + FLAG_NAT: 11; ####### Global Parameters ######### fork = yes From d3bd6bd6295c2948c116ff5f4a9c43312b4bc1c4 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 10 Jan 2019 05:56:12 +0000 Subject: [PATCH 059/209] flag T38 requests --- kamailio/default.cfg | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/kamailio/default.cfg b/kamailio/default.cfg index 6118cf3..cd97b70 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -159,6 +159,9 @@ modparam("sanity", "autodrop", 0) loadmodule "textops.so" loadmodule "textopsx.so" +######## sdp operations module ######## +loadmodule "sdpops.so" + ######## Generic Hash Table container in shared memory ######## loadmodule "htable.so" modparam("htable", "htable", "associations=>size=16;autoexpire=7200") @@ -579,6 +582,14 @@ route[HANDLE_IN_DIALOG_REQUESTS] if (is_method("INVITE") && !isflagset(FLAG_INTERNALLY_SOURCED) && is_audio_on_hold()) { setflag(FLAG_ASSOCIATE_USER); } + + # If the request in an Invite for t38 from internal, + # mark the request with FLAG_T38 + if (is_method("INVITE") && isflagset(FLAG_INTERNALLY_SOURCED) && sdp_with_media("image")) { + xlog("L_DEBUG", "$ci|log|T38 RE-INVITE\n"); + setflag(FLAG_T38); + } + if ( is_method("NOTIFY") ) { # Add Record-Route for in-dialog NOTIFY as per RFC 6665. record_route(); From 008968a7333eee4cc31e96f36bc2c3f40f3fd79c Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 10 Jan 2019 05:57:47 +0000 Subject: [PATCH 060/209] initialize debug settings with macro --- kamailio/registrar-role.cfg | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/kamailio/registrar-role.cfg b/kamailio/registrar-role.cfg index 8fbf4fa..aaacade 100644 --- a/kamailio/registrar-role.cfg +++ b/kamailio/registrar-role.cfg @@ -16,6 +16,9 @@ #!trydef REGISTRAR_HANDLE_EXPIRED_TLS 1 #!trydef REGISTRAR_HANDLE_EXPIRED_WS 1 +#!trydef REGISTRAR_FORCE_QUERY 0 +#!trydef REGISTRAR_FORCE_FAILOVER 0 + ######## Generic Hash Table container in shared memory ######## modparam("htable", "htable", "auth_cache=>size=16;autoexpire=7200;") @@ -79,8 +82,8 @@ kazoo.registrar_handle_expired_ws = REGISTRAR_HANDLE_EXPIRED_WS descr "handles e kazoo.registrar_query_timeout_ms = REGISTRAR_QUERY_TIMEOUT_MS descr "timeout waiting for reply from registrar" -kazoo.registrar_failover = 0 descr "force failover if 1" -kazoo.registrar_force_query = 0 descr "force query if 1" +kazoo.registrar_failover = REGISTRAR_FORCE_FAILOVER descr "force failover if 1" +kazoo.registrar_force_query = REGISTRAR_FORCE_QUERY descr "force query if 1" ####### Registrar Logic ######## route[HANDLE_REGISTER] From 70a3a6fa9570b68cbab6ca8ee5ee838acf5d9ba3 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 10 Jan 2019 05:58:48 +0000 Subject: [PATCH 061/209] flag AOR usage and move route to registrar-role --- kamailio/default.cfg | 21 +-------------------- kamailio/registrar-role.cfg | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/kamailio/default.cfg b/kamailio/default.cfg index cd97b70..ade6840 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -683,26 +683,7 @@ route[INTERNAL_TO_EXTERNAL_RELAY] #!endif #!ifdef REGISTRAR_ROLE - if ($hdr(X-KAZOO-AOR) != $null) { - xlog("L_INFO", "$ci|log|using AOR $hdr(X-KAZOO-AOR)\n"); - if ($hdr(X-KAZOO-INVITE-FORMAT) == "contact") { - if(lookup("location", "$hdr(X-KAZOO-AOR)") > 0){ - xlog("L_INFO", "$ci|end|routing to contact $ru\n"); - } else { - xlog("L_INFO", "$ci|end|lookup for AOR $hdr(X-KAZOO-AOR) failed\n"); - sl_send_reply("410", "Not registered"); - exit; - } - } else if (reg_fetch_contacts("location", "$hdr(X-KAZOO-AOR)", "callee")) { - $du = $(ulc(callee=>received)); - $fs = $(ulc(callee=>socket)); - xlog("L_INFO", "$ci|log|routing $hdr(X-KAZOO-AOR) to $du via $fs\n"); - } else { - xlog("L_INFO", "$ci|end|user is not registered\n"); - sl_send_reply("410", "Not registered"); - exit; - } - } + route(REGISTRAR_ROUTE_TO_AOR); #!endif remove_hf_re("^X-.*"); diff --git a/kamailio/registrar-role.cfg b/kamailio/registrar-role.cfg index aaacade..978dc3f 100644 --- a/kamailio/registrar-role.cfg +++ b/kamailio/registrar-role.cfg @@ -480,4 +480,32 @@ event_route[usrloc:contact-expired] #!include_file "registrar-sync-role.cfg" #!endif +route[REGISTRAR_ROUTE_TO_AOR] +{ + if ($hdr(X-KAZOO-AOR) == $null) { + return(); + } + + xlog("L_INFO", "$ci|log|using AOR $hdr(X-KAZOO-AOR)\n"); + setflag(FLAG_AOR); + if ($hdr(X-KAZOO-INVITE-FORMAT) == "contact") { + if(lookup("location", "$hdr(X-KAZOO-AOR)") > 0){ + xlog("L_INFO", "$ci|end|routing to contact $ru\n"); + handle_ruri_alias(); + } else { + xlog("L_INFO", "$ci|end|lookup for AOR $hdr(X-KAZOO-AOR) failed\n"); + sl_send_reply("410", "Not registered"); + exit; + } + } else if (reg_fetch_contacts("location", "$hdr(X-KAZOO-AOR)", "callee")) { + $du = $(ulc(callee=>received)); + $fs = $(ulc(callee=>socket)); + xlog("L_INFO", "$ci|log|routing $hdr(X-KAZOO-AOR) to $du via $fs\n"); + } else { + xlog("L_INFO", "$ci|end|user is not registered\n"); + sl_send_reply("410", "Not registered"); + exit; + } +} + # vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab From 5f0e8884723daaf4cb3506863dc4487912f38c55 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 10 Jan 2019 06:06:12 +0000 Subject: [PATCH 062/209] rework nat with set_contact_alias/handle_ruri_alias --- kamailio/default.cfg | 28 +++------ kamailio/nat-traversal-role.cfg | 102 +++++++++++++++++++------------- kamailio/presence-notify.cfg | 6 ++ kamailio/presence-role.cfg | 7 +-- kamailio/registrar-role.cfg | 30 ++++------ kamailio/websockets-role.cfg | 13 ++-- 6 files changed, 99 insertions(+), 87 deletions(-) diff --git a/kamailio/default.cfg b/kamailio/default.cfg index ade6840..66e4548 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -344,6 +344,10 @@ route route(HANDLE_WEBSOCKETS); #!endif + #!ifdef NAT_TRAVERSAL_ROLE + route(NAT_INITIAL_TEST); + #!endif + route(HANDLE_OPTIONS); route(HANDLE_NOTIFY); @@ -452,10 +456,6 @@ route[HANDLE_OPTIONS] } #!endif - #!ifdef NAT_TRAVERSAL_ROLE - route(NAT_TEST_AND_CORRECT); - #!endif - sl_send_reply("200", "Rawr!!"); } exit; @@ -487,14 +487,6 @@ route[HANDLE_NOTIFY] } #!endif - #!ifdef WEBSOCKETS_ROLE - route(NAT_WEBSOCKETS_CORRECT); - #!endif - - #!ifdef NAT_TRAVERSAL_ROLE - route(NAT_TEST_AND_CORRECT); - #!endif - if($hdr(Event) == "keep-alive") { xlog("L_INFO", "$ci|stop|replying to keep alive\n"); sl_send_reply("405", "Stay Alive / Method Not Allowed"); @@ -704,12 +696,6 @@ route[EXTERNAL_TO_INTERNAL_RELAY] } #!endif - #!ifdef NAT_TRAVERSAL_ROLE - if (!isflagset(FLAG_INTERNALLY_SOURCED)) { - route(NAT_TEST_AND_CORRECT); - } - #!endif - remove_hf_re("^X-.*"); append_hf("X-AUTH-IP: $si\r\n"); @@ -736,7 +722,7 @@ onreply_route[EXTERNAL_REPLY] #!endif #!ifdef NAT_TRAVERSAL_ROLE - route(NAT_TEST_AND_CORRECT); + route(NAT_REPLY_TEST); #!endif #!ifdef ACL_ROLE @@ -766,6 +752,10 @@ onreply_route[INTERNAL_REPLY] route(NAT_WEBSOCKETS_CORRECT); #!endif + #!ifdef NAT_TRAVERSAL_ROLE + route(NAT_REPLY_TEST); + #!endif + #!ifdef ACL_ROLE setflag(FLAG_IS_REPLY); route(ACL_CHECK); diff --git a/kamailio/nat-traversal-role.cfg b/kamailio/nat-traversal-role.cfg index 8e66e98..33e9c9b 100644 --- a/kamailio/nat-traversal-role.cfg +++ b/kamailio/nat-traversal-role.cfg @@ -6,50 +6,70 @@ loadmodule "nathelper.so" modparam("nathelper", "received_avp", "$avp(AVP_RECV_PARAM)") modparam("nathelper", "sipping_from", "sip:sipcheck@MY_HOSTNAME") -#!trydef KZ_NAT_CONTACT_DETECT "1" -#!trydef KZ_NAT_PORT_DETECT "2" +#!trydef KZ_NAT_DETECT "19" ####### NAT Traversal Logic ######## -route[NAT_TEST_AND_CORRECT] +route[NAT_INITIAL_TEST] { - if (is_present_hf("Record-Route")) { - $var(i) = 0; - $var(rr_count) = $rr_count; - while($var(i) < $var(rr_count)) { - $var(rr_base) = $(hdr(Record-Route)[$var(i)]); - $var(rr_idx) = 0; - $var(rr) = $(var(rr_base){s.select,$var(rr_idx),,}); - while($var(rr) != $null && $var(rr) != "") { - $var(i) = $var(i) + 1; - if (!is_myself("$(var(rr){nameaddr.uri})")) { - setflag(FLAG_SKIP_NAT_CORRECTION); - xlog("L_DEBUG", "$ci|log|skipping nat correction on record-route $(var(rr){nameaddr.uri})\n"); - } - $var(rr_idx) = $var(rr_idx) + 1; - $var(rr) = $(var(rr_base){s.select,$var(rr_idx),,}); - } - } - } else if ($Rp == "5080") { - setflag(FLAG_SKIP_NAT_CORRECTION); - } - - if (isflagset(FLAG_SKIP_NAT_CORRECTION)) { - return(); - } - - if (nat_uac_test(KZ_NAT_PORT_DETECT)) { - xlog("L_DEBUG", "$ci|nat|forcing rport\n"); - force_rport(); - } - - if (nat_uac_test(KZ_NAT_CONTACT_DETECT)) { - xlog("L_DEBUG", "$ci|nat|contact correction\n"); - fix_nated_contact(); - } - - if (has_body("application/sdp") && nat_uac_test("8")) { - fix_nated_sdp("10"); - } + if(nat_uac_test(64)) return(); + + if(!is_method("INVITE|REGISTER|SUBSCRIBE")) return(); + + if ($Rp == "5080") { + setflag(FLAG_SKIP_NAT_CORRECTION); + } else { + if (is_present_hf("Record-Route")) { + $var(i) = 0; + $var(rr_count) = $rr_count; + while($var(i) < $var(rr_count)) { + $var(rr_base) = $(hdr(Record-Route)[$var(i)]); + $var(rr_idx) = 0; + $var(rr) = $(var(rr_base){s.select,$var(rr_idx),,}); + while($var(rr) != $null && $var(rr) != "") { + $var(i) = $var(i) + 1; + if (!is_myself("$(var(rr){nameaddr.uri})")) { + setflag(FLAG_SKIP_NAT_CORRECTION); + xlog("L_DEBUG", "$ci|log|skipping nat correction on record-route $(var(rr){nameaddr.uri})\n"); + } + $var(rr_idx) = $var(rr_idx) + 1; + $var(rr) = $(var(rr_base){s.select,$var(rr_idx),,}); + } + } + } + } + + if (isflagset(FLAG_SKIP_NAT_CORRECTION)) { + return(); + } + + if(nat_uac_test(KZ_NAT_DETECT)) { + force_rport(); + setflag(FLAG_NAT); + if (!is_method("REGISTER")) { + if(is_first_hop()) set_contact_alias(); + } + } + + if (has_body("application/sdp") && nat_uac_test("8")) { + fix_nated_sdp("10"); + } + +} + +route[NAT_REPLY_TEST] +{ + if(nat_uac_test(64)) return(); + + if(nat_uac_test(KZ_NAT_DETECT)) { + setflag(FLAG_NAT); + force_rport(); + set_contact_alias(); + } + + if (has_body("application/sdp") && nat_uac_test("8")) { + fix_nated_sdp("10"); + } + } # vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab diff --git a/kamailio/presence-notify.cfg b/kamailio/presence-notify.cfg index 437c43c..51e961d 100644 --- a/kamailio/presence-notify.cfg +++ b/kamailio/presence-notify.cfg @@ -32,6 +32,12 @@ route[PRESENCE_LOCAL_NOTIFY] record_route(); } + #!ifdef NAT_TRAVERSAL_ROLE + if(!isdsturiset()) { + handle_ruri_alias(); + } + #!endif + #!ifdef SIP_TRACE_ROLE route(SEND_SIP_TRACE); #!endif diff --git a/kamailio/presence-role.cfg b/kamailio/presence-role.cfg index f86720c..dbb4b0f 100644 --- a/kamailio/presence-role.cfg +++ b/kamailio/presence-role.cfg @@ -80,12 +80,9 @@ kazoo.presence_max_call_per_presentity = KZ_PRESENCE_MAX_CALL_PER_PRESENTITY des #!ifdef NAT_TRAVERSAL_ROLE route[PRESENCE_NAT] { - force_rport(); - if (client_nat_test("3")) { - if(is_first_hop()) - set_contact_alias(); + if (isflagset(FLAG_NAT)) { + nat_keepalive(); } - nat_keepalive(); } #!endif diff --git a/kamailio/registrar-role.cfg b/kamailio/registrar-role.cfg index 978dc3f..adbf71e 100644 --- a/kamailio/registrar-role.cfg +++ b/kamailio/registrar-role.cfg @@ -95,24 +95,20 @@ route[HANDLE_REGISTER] resetbflag(FLB_NATB); resetbflag(FLB_NATSIPPING); - #!ifdef NAT_TRAVERSAL_ROLE - if (nat_uac_test("3")) { - xlog("L_INFO", "$ci|log|correcting NATed contact in registration\n"); - force_rport(); - } - fix_nated_register(); - - ## KAZOO-1846: Cisco SPA8000 freaks out on options pings - if (!($ua =~ "Linksys/SPA8000" - || $ua =~ "SIPp" - || (af==INET6) - )) { - setbflag(FLB_NATB); - setbflag(FLB_NATSIPPING); + if (isflagset(FLAG_NAT)) { + fix_nated_register(); + + ## KAZOO-1846: Cisco SPA8000 freaks out on options pings + if (!($ua =~ "Linksys/SPA8000" + || $ua =~ "SIPp" + || (af==INET6) + )) { + setbflag(FLB_NATB); + setbflag(FLB_NATSIPPING); + } + } else { + $avp(AVP_RECV_PARAM) = $su; } - #!else - $avp(AVP_RECV_PARAM) = $su; - #!endif route(ATTEMPT_AUTHORIZATION); diff --git a/kamailio/websockets-role.cfg b/kamailio/websockets-role.cfg index 3d28127..d17d8d0 100644 --- a/kamailio/websockets-role.cfg +++ b/kamailio/websockets-role.cfg @@ -33,13 +33,15 @@ route[HANDLE_WEBSOCKETS] # connection - even if it is not behind a NAT! # This won't be needed in the future if Kamailio and the # WebSocket client support Outbound and Path. + + if(!is_method("INVITE|REGISTER|PUBLISH|SUBSCRIBE")) return(); + if (nat_uac_test(64)) { + setflag(FLAG_NAT); xlog("L_INFO", "$ci|log|this is a websocket request\n"); force_rport(); - if (is_method("REGISTER")) { - fix_nated_register(); - } else { - if (!add_contact_alias()) { + if (!is_method("REGISTER")) { + if (is_first_hop() && !set_contact_alias()) { xlog("L_INFO", "$ci|stop|error aliasing contact <$ct>\n"); sl_send_reply("400", "Bad Request"); exit; @@ -56,7 +58,8 @@ route[NAT_WEBSOCKETS_CORRECT] # WebSocket client support Outbound and Path. if (nat_uac_test(64)) { xlog("L_INFO", "$ci|log|this is a websocket request\n"); - add_contact_alias(); + setflag(FLAG_NAT); + set_contact_alias(); } } From 371c6a82b8e050628537823822c0466eafa0fc9b Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 10 Jan 2019 06:06:38 +0000 Subject: [PATCH 063/209] indentation --- kamailio/default.cfg | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kamailio/default.cfg b/kamailio/default.cfg index 66e4548..baaf1e9 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -906,9 +906,9 @@ route[ADD_AUTHORIZATION_HEADERS] route[ADD_AUTHORIZATION_HEADERS] { - if (!is_method("INVITE|MESSAGE|REFER")) { - return; - } + if (!is_method("INVITE|MESSAGE|REFER")) { + return; + } $xavp(regcfg=>match_received) = $su; if (registered("location","$fu", 2, 1) == 1) { From ff179e8b6e434c47c71a1133433013693e4e6302 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 10 Jan 2019 11:19:52 +0000 Subject: [PATCH 064/209] redefine flags --- kamailio/accounting-role.cfg | 7 +++---- kamailio/default.cfg | 24 ++++++++++++------------ kamailio/presence-role.cfg | 2 +- kamailio/registrar-role.cfg | 6 +++--- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/kamailio/accounting-role.cfg b/kamailio/accounting-role.cfg index fb1b916..13b866d 100644 --- a/kamailio/accounting-role.cfg +++ b/kamailio/accounting-role.cfg @@ -1,8 +1,7 @@ ####### Flags ####### -flags - FLAG_ACC: 12, - FLAG_ACCMISSED: 13, - FLAG_ACCFAILED: 14; +#!trydef FLAG_ACC 13 +#!trydef FLAG_ACCMISSED 14 +#!trydef FLAG_ACCFAILED 15 ######## Accounting module ######## loadmodule "acc.so" diff --git a/kamailio/default.cfg b/kamailio/default.cfg index baaf1e9..0d46897 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -1,18 +1,18 @@ ## NOTE: DO NOT CHANGE THIS FILE, EDIT local.cfg ## ####### Flags ####### -flags - FLAG_INTERNALLY_SOURCED: 1, - FLAG_ASSOCIATE_SERVER: 2, - FLAG_SKIP_NAT_CORRECTION: 3, - FLAG_ASSOCIATE_USER: 4, - FLAG_TRUSTED_SOURCE: 5, - FLAG_SESSION_PROGRESS: 6, - FLAG_IS_REPLY: 7, - FLAG_SIP_TRACE: 8, - FLAG_AOR: 9, - FLAG_T38: 10, - FLAG_NAT: 11; +#!trydef FLAG_INTERNALLY_SOURCED 1 +#!trydef FLAG_ASSOCIATE_SERVER 2 +#!trydef FLAG_SKIP_NAT_CORRECTION 3 +#!trydef FLAG_ASSOCIATE_USER 4 +#!trydef FLAG_TRUSTED_SOURCE 5 +#!trydef FLAG_SESSION_PROGRESS 6 +#!trydef FLAG_IS_REPLY 7 +#!trydef FLAG_SIP_TRACE 8 +#!trydef FLT_AOR 9 +#!trydef FLT_T38 10 +#!trydef FLT_NATS 11 +#!trydef FLB_NATB 12 ####### Global Parameters ######### fork = yes diff --git a/kamailio/presence-role.cfg b/kamailio/presence-role.cfg index dbb4b0f..285102e 100644 --- a/kamailio/presence-role.cfg +++ b/kamailio/presence-role.cfg @@ -80,7 +80,7 @@ kazoo.presence_max_call_per_presentity = KZ_PRESENCE_MAX_CALL_PER_PRESENTITY des #!ifdef NAT_TRAVERSAL_ROLE route[PRESENCE_NAT] { - if (isflagset(FLAG_NAT)) { + if (isflagset(FLT_NATS)) { nat_keepalive(); } } diff --git a/kamailio/registrar-role.cfg b/kamailio/registrar-role.cfg index adbf71e..578b24f 100644 --- a/kamailio/registrar-role.cfg +++ b/kamailio/registrar-role.cfg @@ -95,7 +95,8 @@ route[HANDLE_REGISTER] resetbflag(FLB_NATB); resetbflag(FLB_NATSIPPING); - if (isflagset(FLAG_NAT)) { + if (isflagset(FLT_NATS)) { + setbflag(FLB_NATB); fix_nated_register(); ## KAZOO-1846: Cisco SPA8000 freaks out on options pings @@ -103,7 +104,6 @@ route[HANDLE_REGISTER] || $ua =~ "SIPp" || (af==INET6) )) { - setbflag(FLB_NATB); setbflag(FLB_NATSIPPING); } } else { @@ -483,7 +483,7 @@ route[REGISTRAR_ROUTE_TO_AOR] } xlog("L_INFO", "$ci|log|using AOR $hdr(X-KAZOO-AOR)\n"); - setflag(FLAG_AOR); + setflag(FLT_AOR); if ($hdr(X-KAZOO-INVITE-FORMAT) == "contact") { if(lookup("location", "$hdr(X-KAZOO-AOR)") > 0){ xlog("L_INFO", "$ci|end|routing to contact $ru\n"); From c2a1b07de1499c44e4d9a47ca4ff8d0a98fa7888 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 10 Jan 2019 11:21:29 +0000 Subject: [PATCH 065/209] rework nat --- kamailio/default.cfg | 53 ++++++++++++++++----------- kamailio/nat-traversal-role.cfg | 63 ++++++++++++++++++++++----------- kamailio/websockets-role.cfg | 24 +++---------- 3 files changed, 80 insertions(+), 60 deletions(-) diff --git a/kamailio/default.cfg b/kamailio/default.cfg index 0d46897..4e0e33b 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -345,7 +345,7 @@ route #!endif #!ifdef NAT_TRAVERSAL_ROLE - route(NAT_INITIAL_TEST); + route(NAT_DETECT); #!endif route(HANDLE_OPTIONS); @@ -548,11 +548,20 @@ route[HANDLE_IN_DIALOG_REQUESTS] if (is_method("INVITE")) { setflag(FLAG_SESSION_PROGRESS); -# record_route(); } if (loose_route()) { + #!ifdef NAT_TRAVERSAL_ROLE + if(!isdsturiset()) { + handle_ruri_alias(); + } + if ( is_method("ACK") ) { + # ACK is forwarded statelessly + route(NAT_MANAGE); + } + #!endif + #!ifdef ACCOUNTING_ROLE if (is_method("BYE")) { setflag(FLAG_ACC); @@ -560,12 +569,6 @@ route[HANDLE_IN_DIALOG_REQUESTS] } #!endif - #!ifdef NAT_TRAVERSAL_ROLE - if(!isdsturiset()) { - handle_ruri_alias(); - } - #!endif - xlog("L_INFO", "$ci|log|loose_route in-dialog message\n"); # Called on in-dialog requests # If the request in an Invite for on hold from external to internal, @@ -576,10 +579,10 @@ route[HANDLE_IN_DIALOG_REQUESTS] } # If the request in an Invite for t38 from internal, - # mark the request with FLAG_T38 + # mark the request with FLT_T38 if (is_method("INVITE") && isflagset(FLAG_INTERNALLY_SOURCED) && sdp_with_media("image")) { xlog("L_DEBUG", "$ci|log|T38 RE-INVITE\n"); - setflag(FLAG_T38); + setflag(FLT_T38); } if ( is_method("NOTIFY") ) { @@ -646,12 +649,24 @@ route[PREPARE_INITIAL_REQUESTS] record_route(); } +# Manage outgoing branches +branch_route[MANAGE_BRANCH] { + xlog("L_DEBUG", "$ci|branch|new branch [$T_branch_idx] to $ru\n"); + #!ifdef NAT_TRAVERSAL_ROLE + route(NAT_MANAGE); + #!endif +} + route[RELAY] { #!ifdef SIP_TRACE_ROLE route(SEND_SIP_TRACE); #!endif - + + if (is_method("INVITE|BYE|SUBSCRIBE|UPDATE")) { + if(!t_is_set("branch_route")) t_on_branch("MANAGE_BRANCH"); + } + if (isflagset(FLAG_INTERNALLY_SOURCED)) { route(INTERNAL_TO_EXTERNAL_RELAY); #!ifdef MESSAGE_ROLE @@ -717,12 +732,10 @@ onreply_route[EXTERNAL_REPLY] { xlog("L_INFO", "$ci|log|external reply $T_reply_code\n"); - #!ifdef WEBSOCKETS_ROLE - route(NAT_WEBSOCKETS_CORRECT); - #!endif - #!ifdef NAT_TRAVERSAL_ROLE - route(NAT_REPLY_TEST); + if(status=~"[12][0-9][0-9]") { + route(NAT_MANAGE); + } #!endif #!ifdef ACL_ROLE @@ -748,12 +761,10 @@ onreply_route[INTERNAL_REPLY] xlog("L_INFO", "$ci|start|received internal reply $T_reply_code $T_reply_reason\n"); xlog("L_INFO", "$ci|log|source $si:$sp\n"); - #!ifdef WEBSOCKETS_ROLE - route(NAT_WEBSOCKETS_CORRECT); - #!endif - #!ifdef NAT_TRAVERSAL_ROLE - route(NAT_REPLY_TEST); + if(status=~"[12][0-9][0-9]") { + route(NAT_MANAGE); + } #!endif #!ifdef ACL_ROLE diff --git a/kamailio/nat-traversal-role.cfg b/kamailio/nat-traversal-role.cfg index 33e9c9b..210d7bc 100644 --- a/kamailio/nat-traversal-role.cfg +++ b/kamailio/nat-traversal-role.cfg @@ -6,17 +6,27 @@ loadmodule "nathelper.so" modparam("nathelper", "received_avp", "$avp(AVP_RECV_PARAM)") modparam("nathelper", "sipping_from", "sip:sipcheck@MY_HOSTNAME") -#!trydef KZ_NAT_DETECT "19" +#!ifdef WEBSOCKETS_ROLE +#!trydef KZ_NAT_DETECT 83 +#!else +#!trydef KZ_NAT_DETECT 19 +#!endif -####### NAT Traversal Logic ######## -route[NAT_INITIAL_TEST] -{ - if(nat_uac_test(64)) return(); +#!trydef KZ_NAT_FIX_SDP_REQUEST 1 +#!trydef KZ_NAT_FIX_SDP_REPLY 1 +#!trydef KZ_NAT_SDP_TEST 8 +#!trydef KZ_NAT_SDP_FIX 10 - if(!is_method("INVITE|REGISTER|SUBSCRIBE")) return(); +kazoo.nat_fix_sdp_request = KZ_NAT_FIX_SDP_REQUEST descr "performs request sdp replacement of private addresses" +kazoo.nat_fix_sdp_reply = KZ_NAT_FIX_SDP_REPLY descr "performs reply sdp replacement of private addresses" + +####### NAT Traversal Logic ######## +route[NAT_DETECT] +{ if ($Rp == "5080") { setflag(FLAG_SKIP_NAT_CORRECTION); + xlog("L_DEBUG", "$ci|log|skipping nat correction on PORT 5080\n"); } else { if (is_present_hf("Record-Route")) { $var(i) = 0; @@ -42,34 +52,47 @@ route[NAT_INITIAL_TEST] return(); } + force_rport(); + if(nat_uac_test(KZ_NAT_DETECT)) { - force_rport(); - setflag(FLAG_NAT); + setflag(FLT_NATS); if (!is_method("REGISTER")) { if(is_first_hop()) set_contact_alias(); } } - if (has_body("application/sdp") && nat_uac_test("8")) { - fix_nated_sdp("10"); + if($sel(cfg_get.kazoo.nat_fix_sdp_request) == 1) { + if (has_body("application/sdp") && nat_uac_test(KZ_NAT_SDP_TEST)) { + fix_nated_sdp(KZ_NAT_SDP_FIX); + } } } -route[NAT_REPLY_TEST] +route[NAT_MANAGE] { - if(nat_uac_test(64)) return(); + if ( is_request() && isflagset(FLAG_INTERNALLY_SOURCED) && isflagset(FLT_AOR)) { + setbflag(FLB_NATB); + } - if(nat_uac_test(KZ_NAT_DETECT)) { - setflag(FLAG_NAT); - force_rport(); - set_contact_alias(); + if (!(isflagset(FLT_NATS) || isbflagset(FLB_NATB))) { + return; } - - if (has_body("application/sdp") && nat_uac_test("8")) { - fix_nated_sdp("10"); + + if (is_reply()) { + if(isflagset(FLT_NATS) || isbflagset(FLB_NATB)) { + if(is_first_hop()) { + set_contact_alias(); + } + } } - + + if($sel(cfg_get.kazoo.nat_fix_sdp_reply) == 1) { + if (has_body("application/sdp") && nat_uac_test(KZ_NAT_SDP_TEST)) { + fix_nated_sdp(KZ_NAT_SDP_FIX); + } + } + } # vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab diff --git a/kamailio/websockets-role.cfg b/kamailio/websockets-role.cfg index d17d8d0..7bdaf1c 100644 --- a/kamailio/websockets-role.cfg +++ b/kamailio/websockets-role.cfg @@ -33,21 +33,9 @@ route[HANDLE_WEBSOCKETS] # connection - even if it is not behind a NAT! # This won't be needed in the future if Kamailio and the # WebSocket client support Outbound and Path. + + return(); - if(!is_method("INVITE|REGISTER|PUBLISH|SUBSCRIBE")) return(); - - if (nat_uac_test(64)) { - setflag(FLAG_NAT); - xlog("L_INFO", "$ci|log|this is a websocket request\n"); - force_rport(); - if (!is_method("REGISTER")) { - if (is_first_hop() && !set_contact_alias()) { - xlog("L_INFO", "$ci|stop|error aliasing contact <$ct>\n"); - sl_send_reply("400", "Bad Request"); - exit; - } - } - } } route[NAT_WEBSOCKETS_CORRECT] @@ -56,11 +44,9 @@ route[NAT_WEBSOCKETS_CORRECT] # - even if it is not behind a NAT! # This won't be needed in the future if Kamailio and the # WebSocket client support Outbound and Path. - if (nat_uac_test(64)) { - xlog("L_INFO", "$ci|log|this is a websocket request\n"); - setflag(FLAG_NAT); - set_contact_alias(); - } + + return(); + } event_route[xhttp:request] From c5bae621d688959217db32cd645efec03241c8ae Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 10 Jan 2019 11:21:49 +0000 Subject: [PATCH 066/209] log local generated requests --- kamailio/default.cfg | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/kamailio/default.cfg b/kamailio/default.cfg index 4e0e33b..1333b14 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -955,12 +955,17 @@ route[ADD_AUTHORIZATION_HEADERS] #!endif -#!ifdef PRESENCE_ROLE event_route[tm:local-request] { + xlog("L_DEBUG", "$ci|local|start $pr request $rm $ou\n"); + xlog("L_DEBUG", "$ci|local|source $si:$sp -> $dd:$dp\n"); + xlog("L_DEBUG", "$ci|local|from $fu\n"); + xlog("L_DEBUG", "$ci|local|to $tu\n"); + + #!ifdef PRESENCE_ROLE route(PRESENCE_LOCAL_NOTIFY); + #!endif } -#!endif event_route[evrexec:DEFERRED_INIT] { From 21b95f036e2571a3314fba14ddb07e072f6001a0 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 10 Jan 2019 12:22:24 +0000 Subject: [PATCH 067/209] set KZ_NAT_FIX_SDP_REPLY default to 0 --- kamailio/nat-traversal-role.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kamailio/nat-traversal-role.cfg b/kamailio/nat-traversal-role.cfg index 210d7bc..1e282e7 100644 --- a/kamailio/nat-traversal-role.cfg +++ b/kamailio/nat-traversal-role.cfg @@ -13,7 +13,7 @@ modparam("nathelper", "sipping_from", "sip:sipcheck@MY_HOSTNAME") #!endif #!trydef KZ_NAT_FIX_SDP_REQUEST 1 -#!trydef KZ_NAT_FIX_SDP_REPLY 1 +#!trydef KZ_NAT_FIX_SDP_REPLY 0 #!trydef KZ_NAT_SDP_TEST 8 #!trydef KZ_NAT_SDP_FIX 10 From 0312d2fd0049ffb04f9dc2afb0d1c377b28761aa Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 10 Jan 2019 14:22:56 +0000 Subject: [PATCH 068/209] handle in dialog requests for nat --- kamailio/nat-traversal-role.cfg | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kamailio/nat-traversal-role.cfg b/kamailio/nat-traversal-role.cfg index 1e282e7..2ae1155 100644 --- a/kamailio/nat-traversal-role.cfg +++ b/kamailio/nat-traversal-role.cfg @@ -75,6 +75,10 @@ route[NAT_MANAGE] setbflag(FLB_NATB); } + if ( is_request() && has_totag() ) { + setbflag(FLB_NATB); + } + if (!(isflagset(FLT_NATS) || isbflagset(FLB_NATB))) { return; } From 691f62145ddd6472c325c1fa2aea48723a71bc73 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 10 Jan 2019 14:40:46 +0000 Subject: [PATCH 069/209] duplicate definition of FLB_NATB --- kamailio/default.cfg | 1 - 1 file changed, 1 deletion(-) diff --git a/kamailio/default.cfg b/kamailio/default.cfg index 1333b14..dfb8aa4 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -12,7 +12,6 @@ #!trydef FLT_AOR 9 #!trydef FLT_T38 10 #!trydef FLT_NATS 11 -#!trydef FLB_NATB 12 ####### Global Parameters ######### fork = yes From f2b60857047a56783e26252cce8ecbd7a64d93ab Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 10 Jan 2019 15:54:02 +0000 Subject: [PATCH 070/209] remove FLT_AOR check --- kamailio/nat-traversal-role.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kamailio/nat-traversal-role.cfg b/kamailio/nat-traversal-role.cfg index 2ae1155..c18bae2 100644 --- a/kamailio/nat-traversal-role.cfg +++ b/kamailio/nat-traversal-role.cfg @@ -71,7 +71,7 @@ route[NAT_DETECT] route[NAT_MANAGE] { - if ( is_request() && isflagset(FLAG_INTERNALLY_SOURCED) && isflagset(FLT_AOR)) { + if ( is_request() && isflagset(FLAG_INTERNALLY_SOURCED)) { setbflag(FLB_NATB); } From 6c58db6a99cf1041776adf0c55560f6c272cda36 Mon Sep 17 00:00:00 2001 From: lazedo Date: Sat, 12 Jan 2019 18:41:29 +0000 Subject: [PATCH 071/209] name the bindings --- kamailio/nodes-role.cfg | 2 +- kamailio/presence-query.cfg | 2 +- kamailio/presence-reset.cfg | 2 +- kamailio/registrar-role.cfg | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/kamailio/nodes-role.cfg b/kamailio/nodes-role.cfg index 54cf6d0..5210d0d 100644 --- a/kamailio/nodes-role.cfg +++ b/kamailio/nodes-role.cfg @@ -206,7 +206,7 @@ route[MEDIA_SERVER_RESTART] #!ifndef NODES_CUSTOM_BINDINGS route[NODES_BINDINGS] { - $var(payload) = $_s({"exchange" : "nodes" , "type" : "fanout", "queue" : "nodes-MY_HOSTNAME", "exclusive":0, "federate":1 }); + $var(payload) = $_s({"name": "nodes", "exchange" : "nodes" , "type" : "fanout", "queue" : "nodes-MY_HOSTNAME", "exclusive":0, "federate":1 }); kazoo_subscribe("$var(payload)"); } #!endif diff --git a/kamailio/presence-query.cfg b/kamailio/presence-query.cfg index ce48eea..cbfd290 100644 --- a/kamailio/presence-query.cfg +++ b/kamailio/presence-query.cfg @@ -106,7 +106,7 @@ event_route[kazoo:consumer-event-presence-search-req] route[PRESENCE_QUERY_BINDINGS] { - $var(payload) = $_s({"exchange": "presence", "type": "topic", "queue": "presence-search-MY_HOSTNAME", "routing": "presence.search_req.*", "exclusive": 0, "federate": 1 }); + $var(payload) = $_s({"name": "presence-query", "exchange": "presence", "type": "topic", "queue": "presence-search-MY_HOSTNAME", "routing": "presence.search_req.*", "exclusive": 0, "federate": 1 }); kazoo_subscribe("$var(payload)"); } diff --git a/kamailio/presence-reset.cfg b/kamailio/presence-reset.cfg index 1a40e7c..002772e 100644 --- a/kamailio/presence-reset.cfg +++ b/kamailio/presence-reset.cfg @@ -20,7 +20,7 @@ route[PRESENCE_RESET_BINDINGS] #!import_file "presence-reset-custom-bindings.cfg" #!ifndef PRESENCE_RESET_CUSTOM_BINDINGS - $var(payload) = $_s({"exchange": "presence", "queue": "presence-reset-MY_HOSTNAME", "type": "topic", "routing": "presence.reset.*.*", "exclusive": 0, "federate": 1 }); + $var(payload) = $_s({"name": "presence-reset", "exchange": "presence", "queue": "presence-reset-MY_HOSTNAME", "type": "topic", "routing": "presence.reset.*.*", "exclusive": 0, "federate": 1 }); kazoo_subscribe("$var(payload)"); #!endif diff --git a/kamailio/registrar-role.cfg b/kamailio/registrar-role.cfg index 578b24f..3a10c0a 100644 --- a/kamailio/registrar-role.cfg +++ b/kamailio/registrar-role.cfg @@ -376,7 +376,7 @@ route[REGISTRAR_BINDINGS] #!ifndef REGISTRAR_CUSTOM_BINDINGS - $var(payload) = $_s({"exchange": "registrar", "type": "topic", "queue": "registrar-flush-MY_HOSTNAME", "routing": "registration.flush.*", "federate": 1 }); + $var(payload) = $_s({"name": "registrar", "exchange": "registrar", "type": "topic", "queue": "registrar-flush-MY_HOSTNAME", "routing": "registration.flush.*", "federate": 1 }); kazoo_subscribe("$var(payload)"); #!endif From 5767c8528c729c20238c901a7d99f061412bab3e Mon Sep 17 00:00:00 2001 From: lazedo Date: Sat, 12 Jan 2019 18:42:01 +0000 Subject: [PATCH 072/209] update amqp logging --- kamailio/kazoo-bindings.cfg | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/kamailio/kazoo-bindings.cfg b/kamailio/kazoo-bindings.cfg index 7118dc2..7c192e1 100644 --- a/kamailio/kazoo-bindings.cfg +++ b/kamailio/kazoo-bindings.cfg @@ -54,9 +54,19 @@ event_route[kazoo:consumer-event-connection-open] xlog("L_NOTICE","connection to $(kzE{kz.json,host}) opened\n"); } +event_route[kazoo:consumer-event-connection-error] +{ + xlog("L_ERR","amqp|error|$(kzE{kz.json,zone})|$(kzE{kz.json,name})| $(kzE{kz.json,message})\n"); +} + +event_route[kazoo:consumer-event-connection-message] +{ + xlog("L_NOTICE","amqp|msg|$(kzE{kz.json,zone})|$(kzE{kz.json,name})| $(kzE{kz.json,message})\n"); +} + event_route[kazoo:consumer-event-connection-closed] { - xlog("L_WARN","connection to $(kzE{kz.json,host}) closed\n"); + xlog("L_WARN","amqp|closed|$(kzE{kz.json,zone})|$(kzE{kz.json,name})| connection to $(kzE{kz.json,host}) closed\n"); } event_route[kazoo:consumer-event-connection-zone-available] From 6ea94e1fbaaa5393753c4f76c5f9a9e08e71b2d8 Mon Sep 17 00:00:00 2001 From: lazedo Date: Sun, 13 Jan 2019 11:58:51 +0000 Subject: [PATCH 073/209] move search & reset to api --- kamailio/presence-query.cfg | 6 ------ kamailio/presence-reset.cfg | 19 ++++--------------- kamailio/presence-role.cfg | 13 ++++++++++--- 3 files changed, 14 insertions(+), 24 deletions(-) diff --git a/kamailio/presence-query.cfg b/kamailio/presence-query.cfg index cbfd290..2a7c3cb 100644 --- a/kamailio/presence-query.cfg +++ b/kamailio/presence-query.cfg @@ -104,10 +104,4 @@ event_route[kazoo:consumer-event-presence-search-req] } } -route[PRESENCE_QUERY_BINDINGS] -{ - $var(payload) = $_s({"name": "presence-query", "exchange": "presence", "type": "topic", "queue": "presence-search-MY_HOSTNAME", "routing": "presence.search_req.*", "exclusive": 0, "federate": 1 }); - kazoo_subscribe("$var(payload)"); -} - # vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab diff --git a/kamailio/presence-reset.cfg b/kamailio/presence-reset.cfg index 002772e..61315e7 100644 --- a/kamailio/presence-reset.cfg +++ b/kamailio/presence-reset.cfg @@ -15,17 +15,6 @@ route[PRESENCE_RESET_ROUTE] } } -route[PRESENCE_RESET_BINDINGS] -{ - #!import_file "presence-reset-custom-bindings.cfg" - - #!ifndef PRESENCE_RESET_CUSTOM_BINDINGS - $var(payload) = $_s({"name": "presence-reset", "exchange": "presence", "queue": "presence-reset-MY_HOSTNAME", "type": "topic", "routing": "presence.reset.*.*", "exclusive": 0, "federate": 1 }); - kazoo_subscribe("$var(payload)"); - #!endif - -} - route[RESET_PUBLISHER] { xlog("L_INFO", "$var(Msg-ID)|reset|received presence reset for publisher $var(MediaUrl)\n"); @@ -136,7 +125,7 @@ event_route[kazoo:consumer-event-presence-reset] exit(); } - xlog("L_INFO", "$(kzE{kz.json,Msg-ID})|reset|received presence reset for $(kzE{kz.json,Username})@$(kzE{kz.json,Realm})\n"); + xlog("L_INFO", "$(kzE{kz.json,Msg-ID})|reset|received presence reset for $(kzE{kz.json,Username})@$(kzE{kz.json,Realm})\n"); $var(presentity) = $_s(sip:$(kzE{kz.json,Username})@$(kzE{kz.json,Realm})); route(COUNT_SUBSCRIBERS); sql_query("exec", 'KZQ_EVENT_PRESENCE_RESET_DELETE'); @@ -145,21 +134,21 @@ event_route[kazoo:consumer-event-presence-reset] xlog("L_INFO", "$(kzE{kz.json,Msg-ID})|reset|notifying $xavp(watchers=>message-summary) message-summary subscribers of $var(presentity)\n"); pres_refresh_watchers("$var(presentity)", "message-summary", 1); } else { - xlog("L_INFO", "$(kzE{kz.json,Msg-ID})|reset|skip message-summary subscriber notification for $var(presentity)\n"); + xlog("L_DEBUG", "$(kzE{kz.json,Msg-ID})|reset|skip message-summary subscriber notification for $var(presentity)\n"); } if($xavp(watchers=>presence) > 0) { xlog("L_INFO", "$(kzE{kz.json,Msg-ID})|reset|notifying $xavp(watchers=>presence) presence subscribers of $var(presentity)\n"); pres_refresh_watchers("$var(presentity)", "presence", 1); } else { - xlog("L_INFO", "$(kzE{kz.json,Msg-ID})|reset|skip presence subscriber notification for $var(presentity)\n"); + xlog("L_DEBUG", "$(kzE{kz.json,Msg-ID})|reset|skip presence subscriber notification for $var(presentity)\n"); } if($xavp(watchers=>dialog) > 0) { xlog("L_INFO", "$(kzE{kz.json,Msg-ID})|reset|notifying $xavp(watchers=>dialog) dialog subscribers of $var(presentity)\n"); pres_refresh_watchers("$var(presentity)", "dialog", 1); } else { - xlog("L_INFO", "$(kzE{kz.json,Msg-ID})|reset|skip dialog subscriber notification for $var(presentity)\n"); + xlog("L_DEBUG", "$(kzE{kz.json,Msg-ID})|reset|skip dialog subscriber notification for $var(presentity)\n"); } } diff --git a/kamailio/presence-role.cfg b/kamailio/presence-role.cfg index 285102e..3c929de 100644 --- a/kamailio/presence-role.cfg +++ b/kamailio/presence-role.cfg @@ -501,11 +501,9 @@ route[PRESENCE_BINDINGS] #!ifndef PRESENCE_CUSTOM_BINDINGS $var(payload) = $_s({ "name" : "presence", "exchange" : "presence", "type" : "topic", "queue" : "presence-dialog-MY_HOSTNAME", "routing" : ["dialog.*.*", "update.*.*", "mwi_updates.*.*"], "exclusive" : 0, "federate" : 1 }); kazoo_subscribe("$var(payload)"); - #!endif - route(PRESENCE_RESET_BINDINGS); - route(PRESENCE_QUERY_BINDINGS); + route(PRESENCE_API_BINDINGS); #!ifdef FAST_PICKUP_ROLE route(FAST_PICKUP_START); @@ -513,6 +511,15 @@ route[PRESENCE_BINDINGS] } +route[PRESENCE_API_BINDINGS] +{ + #!import_file "presence-api-custom-bindings.cfg" + + #!ifndef PRESENCE_API_CUSTOM_BINDINGS + $var(payload) = $_s({"name": "presence-api", "exchange": "presence", "type": "topic", "queue": "presence-api-MY_HOSTNAME", "routing": ["presence.search_req.*", "presence.reset.*.*"], "exclusive": 0, "federate": 1 }); + kazoo_subscribe("$var(payload)"); + #!endif +} # vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab From b6ad5682634224a64d143f0576eba2a37634ce51 Mon Sep 17 00:00:00 2001 From: lazedo Date: Sun, 13 Jan 2019 19:33:53 +0000 Subject: [PATCH 074/209] more bindings and logs --- kamailio/acl-role.cfg | 6 ++++++ kamailio/kazoo-bindings.cfg | 19 +++++++++---------- kamailio/message-role.cfg | 2 +- kamailio/registrar-role.cfg | 2 +- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/kamailio/acl-role.cfg b/kamailio/acl-role.cfg index 664298d..f4fc1df 100644 --- a/kamailio/acl-role.cfg +++ b/kamailio/acl-role.cfg @@ -265,3 +265,9 @@ event_route[kazoo:consumer-event-acl-acl-flush] } } + +route[ACL_BINDINGS] +{ + $var(payload) = $_s({"name": "acl-role", "exchange" : "frontier_acl" , "type" : "topic", "queue" : "FRONTIERACL-FLUSH-MY_HOSTNAME", "routing" : "flush" }); + kazoo_subscribe("$var(payload)"); +} \ No newline at end of file diff --git a/kamailio/kazoo-bindings.cfg b/kamailio/kazoo-bindings.cfg index 7c192e1..5b35e79 100644 --- a/kamailio/kazoo-bindings.cfg +++ b/kamailio/kazoo-bindings.cfg @@ -36,8 +36,7 @@ event_route[kazoo:mod-init] #!endif #!ifdef ACL_ROLE - $var(payload) = "{ 'exchange' : 'frontier_acl' , 'type' : 'topic', 'queue' : 'FRONTIERACL-FLUSH-MY_HOSTNAME', 'routing' : 'flush' }"; - kazoo_subscribe("$var(payload)"); + route(ACL_BINDINGS); #!endif #!import_file "kazoo-custom-bindings.cfg" @@ -51,32 +50,32 @@ event_route[kazoo:consumer-event] event_route[kazoo:consumer-event-connection-open] { - xlog("L_NOTICE","connection to $(kzE{kz.json,host}) opened\n"); + xlog("L_DEBUG","connection to $(kzE{kz.json,host}) opened\n"); } event_route[kazoo:consumer-event-connection-error] { - xlog("L_ERR","amqp|error|$(kzE{kz.json,zone})|$(kzE{kz.json,name})| $(kzE{kz.json,message})\n"); + xlog("L_ERR","amqp|error|$(kzE{kz.json,zone})|$(kzE{kz.json,name})|$(kzE{kz.json,message})\n"); } event_route[kazoo:consumer-event-connection-message] { - xlog("L_NOTICE","amqp|msg|$(kzE{kz.json,zone})|$(kzE{kz.json,name})| $(kzE{kz.json,message})\n"); + xlog("L_DEBUG","amqp|msg|$(kzE{kz.json,zone})|$(kzE{kz.json,name})|$(kzE{kz.json,message})\n"); } event_route[kazoo:consumer-event-connection-closed] { - xlog("L_WARN","amqp|closed|$(kzE{kz.json,zone})|$(kzE{kz.json,name})| connection to $(kzE{kz.json,host}) closed\n"); + xlog("L_DEBUG","amqp|closed|$(kzE{kz.json,zone})|$(kzE{kz.json,name})|connection to $(kzE{kz.json,host}) closed\n"); } event_route[kazoo:consumer-event-connection-zone-available] { - xlog("L_NOTICE","amqp zone $(kzE{kz.json,zone}) is available\n"); + xlog("L_DEBUG","amqp zone $(kzE{kz.json,zone}) is available\n"); } event_route[kazoo:consumer-event-connection-zone-unavailable] { - xlog("L_WARN","amqp zone $(kzE{kz.json,zone}) is unavailable\n"); + xlog("L_DEBUG","amqp zone $(kzE{kz.json,zone}) is unavailable\n"); } event_route[kazoo:consumer-event-connection-available] @@ -106,7 +105,7 @@ event_route[kazoo:consumer-event-connection-listener-zone-available] event_route[kazoo:consumer-event-connection-listener-zone-unavailable] { - xlog("L_DEBUG","amqp zone $(kzE{kz.json,zone}) is unavailable\n"); + xlog("L_WARN","amqp|connection|$(kzE{kz.json,zone})|$(kzE{kz.json,name})|listener unavailable\n"); #!ifdef PRESENCE_ROLE route(PRESENCE_ZONE_UNAVAILABLE); @@ -115,7 +114,7 @@ event_route[kazoo:consumer-event-connection-listener-zone-unavailable] event_route[kazoo:consumer-event-connection-listener-available] { - xlog("L_DEBUG","amqp zone $(kzE{kz.json,zone}) is available\n"); + xlog("L_NOTICE","amqp|connection|$(kzE{kz.json,zone})|$(kzE{kz.json,name})|listener available\n"); } event_route[kazoo:consumer-event-connection-listener-unavailable] diff --git a/kamailio/message-role.cfg b/kamailio/message-role.cfg index 1b56a5a..559ee21 100644 --- a/kamailio/message-role.cfg +++ b/kamailio/message-role.cfg @@ -54,7 +54,7 @@ route[MESSAGE_REPLY] route[MESSAGE_BINDINGS] { $var(key) = "kamailio@MY_HOSTNAME"; - $var(payload) = $_s({"exchange": "sms", "type": "topic", "queue": "MSG-QUEUE-MY_HOSTNAME", "routing": "message.route.$(var(key){kz.encode}).*", "no_ack": 0 }); + $var(payload) = $_s({"name": "sms", "exchange": "sms", "type": "topic", "queue": "MSG-QUEUE-MY_HOSTNAME", "routing": "message.route.$(var(key){kz.encode}).*", "no_ack": 0 }); kazoo_subscribe("$var(payload)"); } diff --git a/kamailio/registrar-role.cfg b/kamailio/registrar-role.cfg index 3a10c0a..b3a0263 100644 --- a/kamailio/registrar-role.cfg +++ b/kamailio/registrar-role.cfg @@ -376,7 +376,7 @@ route[REGISTRAR_BINDINGS] #!ifndef REGISTRAR_CUSTOM_BINDINGS - $var(payload) = $_s({"name": "registrar", "exchange": "registrar", "type": "topic", "queue": "registrar-flush-MY_HOSTNAME", "routing": "registration.flush.*", "federate": 1 }); + $var(payload) = $_s({"name": "registrar-api", "exchange": "registrar", "type": "topic", "queue": "registrar-flush-MY_HOSTNAME", "routing": "registration.flush.*", "federate": 1 }); kazoo_subscribe("$var(payload)"); #!endif From 1ac94061ae984b0dc3f34e028397d6c7c4d8649d Mon Sep 17 00:00:00 2001 From: lazedo Date: Mon, 14 Jan 2019 11:33:43 +0000 Subject: [PATCH 075/209] change log level to show by zone --- kamailio/kazoo-bindings.cfg | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kamailio/kazoo-bindings.cfg b/kamailio/kazoo-bindings.cfg index 5b35e79..9a52a92 100644 --- a/kamailio/kazoo-bindings.cfg +++ b/kamailio/kazoo-bindings.cfg @@ -100,7 +100,7 @@ event_route[kazoo:consumer-event-connection-zone-listener-unavailable] event_route[kazoo:consumer-event-connection-listener-zone-available] { - xlog("L_DEBUG","amqp zone $(kzE{kz.json,zone}) is available\n"); + xlog("L_NOTICE","amqp|connection|$(kzE{kz.json,zone})|$(kzE{kz.json,name})|listener available\n"); } event_route[kazoo:consumer-event-connection-listener-zone-unavailable] @@ -114,7 +114,7 @@ event_route[kazoo:consumer-event-connection-listener-zone-unavailable] event_route[kazoo:consumer-event-connection-listener-available] { - xlog("L_NOTICE","amqp|connection|$(kzE{kz.json,zone})|$(kzE{kz.json,name})|listener available\n"); + xlog("L_DEBUG","amqp|connection|$(kzE{kz.json,zone})|$(kzE{kz.json,name})|listener available\n"); } event_route[kazoo:consumer-event-connection-listener-unavailable] From 5a4e38429625605719643da136698603e323463b Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 15 Jan 2019 16:12:49 +0000 Subject: [PATCH 076/209] remove trailing white spaces --- kamailio/antiflood-role.cfg | 4 ++-- kamailio/default.cfg | 32 ++++++++++++++++---------------- kamailio/defs.cfg | 2 +- kamailio/dispatcher-role.cfg | 8 +++++--- kamailio/fast-pickup-role.cfg | 4 ++-- kamailio/kazoo-bindings.cfg | 2 +- kamailio/local.cfg | 2 +- kamailio/message-role.cfg | 2 +- kamailio/nat-traversal-role.cfg | 6 +++--- kamailio/nodes-role.cfg | 18 +++++++++--------- kamailio/presence-query.cfg | 4 ++-- kamailio/presence-role.cfg | 24 ++++++++++++------------ kamailio/pusher-role.cfg | 10 +++++----- kamailio/registrar-role.cfg | 18 +++++++++--------- kamailio/websockets-role.cfg | 2 +- 15 files changed, 70 insertions(+), 68 deletions(-) diff --git a/kamailio/antiflood-role.cfg b/kamailio/antiflood-role.cfg index 342a555..2f0345f 100644 --- a/kamailio/antiflood-role.cfg +++ b/kamailio/antiflood-role.cfg @@ -73,7 +73,7 @@ route[ANITFLOOD_FAILED_AUTH] xlog("L_INFO", "$ci|log|$var(count) errounous authorization response for $Au $si:$sp\n"); - if ($var(count) >= ANTIFLOOD_FAILED_AUTH_DENSITY) { + if ($var(count) >= ANTIFLOOD_FAILED_AUTH_DENSITY) { $var(exp) = $Ts - ANTIFLOOD_FAILED_AUTH_WINDOW; if($sht(antiflood=>$Au::$si::last) > $var(exp)){ xlog("L_NOTICE", "$ci|end|request at authorization failure limit for $Au $si:$sp\n"); @@ -84,7 +84,7 @@ route[ANITFLOOD_FAILED_AUTH] } } -event_route[htable:expired:antiflood] +event_route[htable:expired:antiflood] { xlog("L_NOTICE", "antiflood expired record $shtrecord(key) => $shtrecord(value)\n"); } diff --git a/kamailio/default.cfg b/kamailio/default.cfg index dfb8aa4..4e677f5 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -311,7 +311,7 @@ modparam("debugger", "mod_level", "core=1") route { route(SANITY_CHECK); - + route(CHECK_RETRANS); # log the basic info regarding this call @@ -544,7 +544,7 @@ route[HANDLE_MESSAGE] route[HANDLE_IN_DIALOG_REQUESTS] { if (!has_totag()) return; - + if (is_method("INVITE")) { setflag(FLAG_SESSION_PROGRESS); } @@ -560,7 +560,7 @@ route[HANDLE_IN_DIALOG_REQUESTS] route(NAT_MANAGE); } #!endif - + #!ifdef ACCOUNTING_ROLE if (is_method("BYE")) { setflag(FLAG_ACC); @@ -572,7 +572,7 @@ route[HANDLE_IN_DIALOG_REQUESTS] # Called on in-dialog requests # If the request in an Invite for on hold from external to internal, # associate the contact with the media server - # if Invite for on hold, we need to associate the contact URI with the next hop + # if Invite for on hold, we need to associate the contact URI with the next hop if (is_method("INVITE") && !isflagset(FLAG_INTERNALLY_SOURCED) && is_audio_on_hold()) { setflag(FLAG_ASSOCIATE_USER); } @@ -661,11 +661,11 @@ route[RELAY] #!ifdef SIP_TRACE_ROLE route(SEND_SIP_TRACE); #!endif - + if (is_method("INVITE|BYE|SUBSCRIBE|UPDATE")) { if(!t_is_set("branch_route")) t_on_branch("MANAGE_BRANCH"); } - + if (isflagset(FLAG_INTERNALLY_SOURCED)) { route(INTERNAL_TO_EXTERNAL_RELAY); #!ifdef MESSAGE_ROLE @@ -746,7 +746,7 @@ onreply_route[EXTERNAL_REPLY] setflag(FLAG_IS_REPLY); route(DOS_PREVENTION); #!endif - + #!ifdef MESSAGE_ROLE if (is_method("MESSAGE")) { route(MESSAGE_REPLY); @@ -924,28 +924,28 @@ route[ADD_AUTHORIZATION_HEADERS] if (registered("location","$fu", 2, 1) == 1) { if($(xavp(ulattrs=>custom_channel_vars){kz.json,Account-ID}{s.len}) > 0) append_hf("X-ecallmgr_Account-ID: $(xavp(ulattrs=>custom_channel_vars){kz.json,Account-ID})\r\n"); - + if($(xavp(ulattrs=>custom_channel_vars){kz.json,Authorizing-Type}{s.len}) > 0) append_hf("X-ecallmgr_Authorizing-Type: $(xavp(ulattrs=>custom_channel_vars){kz.json,Authorizing-Type})\r\n"); - + if($(xavp(ulattrs=>custom_channel_vars){kz.json,Authorizing-ID}{s.len}) > 0) append_hf("X-ecallmgr_Authorizing-ID: $(xavp(ulattrs=>custom_channel_vars){kz.json,Authorizing-ID})\r\n"); - + if($(xavp(ulattrs=>custom_channel_vars){kz.json,Username}{s.len}) > 0) append_hf("X-ecallmgr_Username: $(xavp(ulattrs=>custom_channel_vars){kz.json,Username})\r\n"); - + if($(xavp(ulattrs=>custom_channel_vars){kz.json,Realm}{s.len}) > 0) append_hf("X-ecallmgr_Realm: $(xavp(ulattrs=>custom_channel_vars){kz.json,Realm})\r\n"); - + if($(xavp(ulattrs=>custom_channel_vars){kz.json,Account-Realm}{s.len}) > 0) append_hf("X-ecallmgr_Account-Realm: $(xavp(ulattrs=>custom_channel_vars){kz.json,Account-Realm})\r\n"); - + if($(xavp(ulattrs=>custom_channel_vars){kz.json,Account-Name}{s.len}) > 0) append_hf("X-ecallmgr_Account-Name: $(xavp(ulattrs=>custom_channel_vars){kz.json,Account-Name})\r\n"); - + if($(xavp(ulattrs=>custom_channel_vars){kz.json,Presence-ID}{s.len}) > 0) append_hf("X-ecallmgr_Presence-ID: $(xavp(ulattrs=>custom_channel_vars){kz.json,Presence-ID})\r\n"); - + if($(xavp(ulattrs=>custom_channel_vars){kz.json,Owner-ID}{s.len}) > 0) append_hf("X-ecallmgr_Owner-ID: $(xavp(ulattrs=>custom_channel_vars){kz.json,Owner-ID})\r\n"); } @@ -960,7 +960,7 @@ event_route[tm:local-request] xlog("L_DEBUG", "$ci|local|source $si:$sp -> $dd:$dp\n"); xlog("L_DEBUG", "$ci|local|from $fu\n"); xlog("L_DEBUG", "$ci|local|to $tu\n"); - + #!ifdef PRESENCE_ROLE route(PRESENCE_LOCAL_NOTIFY); #!endif diff --git a/kamailio/defs.cfg b/kamailio/defs.cfg index 1e3d26b..56e0900 100644 --- a/kamailio/defs.cfg +++ b/kamailio/defs.cfg @@ -57,7 +57,7 @@ #!trydef RR_FULL_LR 1 #!trydef RR_DOUBLE_RR 1 #!trydef RR_FORCE_SOCKET 1 - + ################################# ## Defs related to SIP_TRACE_ROLE ## diff --git a/kamailio/dispatcher-role.cfg b/kamailio/dispatcher-role.cfg index 5610ec9..7be99c0 100644 --- a/kamailio/dispatcher-role.cfg +++ b/kamailio/dispatcher-role.cfg @@ -58,7 +58,7 @@ modparam("rtimer", "exec", "timer=dispatcher_reload;route=DISPATCHER_RELOAD") route[DISPATCHER_CLASSIFY_SOURCE] { #!import_file "dispatcher-network-classify.cfg" - + if (is_myself("$ou")) { xlog("L_INFO", "$ci|log|original R-URI ($ou) is this proxy, treating as external sources\n"); } else if ( @@ -92,11 +92,12 @@ route[DISPATCHER_FIND_ROUTES] $var(ds_primary_group) = $sel(cfg_get.kazoo.dispatcher_primary_group); $var(ds_backup_group) = $sel(cfg_get.kazoo.dispatcher_secondary_group); - + #!ifndef PRESENCE_ROLE if (is_method("SUBSCRIBE")) { $var(ds_primary_group) = KZ_DISPATCHER_PRESENCE_PRIMARY_GROUP; $var(ds_backup_group) = KZ_DISPATCHER_PRESENCE_SECONDARY_GROUP; + add_path(); } #!endif @@ -104,6 +105,7 @@ route[DISPATCHER_FIND_ROUTES] if (is_method("REGISTER")) { $var(ds_primary_group) = KZ_DISPATCHER_REGISTRAR_PRIMARY_GROUP; $var(ds_backup_group) = KZ_DISPATCHER_REGISTRAR_SECONDARY_GROUP; + add_path(); } #!endif @@ -273,7 +275,7 @@ route[DISPATCHER_RELOAD] xlog("L_WARNING", "reloading dispatcher table\n"); ds_reload(); }; - $shv(dispatcher_reload) = 0; + $shv(dispatcher_reload) = 0; } route[DISPATCHER_STATUS] diff --git a/kamailio/fast-pickup-role.cfg b/kamailio/fast-pickup-role.cfg index b822b76..bfe00bd 100644 --- a/kamailio/fast-pickup-role.cfg +++ b/kamailio/fast-pickup-role.cfg @@ -101,7 +101,7 @@ route[FAST_PICKUP_ATTEMPT] } ##### CALL-PARK #### - + ##### STAR 5 CHECK #### if($sel(cfg_get.kazoo.fast_pickup_star_5) == 1) { if($(ru{uri.user}) =~ "\*5") { @@ -139,7 +139,7 @@ route[FAST_PICKUP_ATTEMPT] exit(); } } - } + } } route[FAST_PICKUP_OPTION] diff --git a/kamailio/kazoo-bindings.cfg b/kamailio/kazoo-bindings.cfg index 9a52a92..cb3e7eb 100644 --- a/kamailio/kazoo-bindings.cfg +++ b/kamailio/kazoo-bindings.cfg @@ -100,7 +100,7 @@ event_route[kazoo:consumer-event-connection-zone-listener-unavailable] event_route[kazoo:consumer-event-connection-listener-zone-available] { - xlog("L_NOTICE","amqp|connection|$(kzE{kz.json,zone})|$(kzE{kz.json,name})|listener available\n"); + xlog("L_NOTICE","amqp|connection|$(kzE{kz.json,zone})|$(kzE{kz.json,name})|listener available\n"); } event_route[kazoo:consumer-event-connection-listener-zone-unavailable] diff --git a/kamailio/local.cfg b/kamailio/local.cfg index 5dfb13f..8981287 100644 --- a/kamailio/local.cfg +++ b/kamailio/local.cfg @@ -75,7 +75,7 @@ ## BINDINGS ################################################################################ ## This parameter is OPTIONAL. -## when set to 1, +## when set to 1, ## It will try to locate outbound interface ## on multihomed host. By default forward ## requests use the incoming socket disregarding diff --git a/kamailio/message-role.cfg b/kamailio/message-role.cfg index 559ee21..1122a1e 100644 --- a/kamailio/message-role.cfg +++ b/kamailio/message-role.cfg @@ -40,7 +40,7 @@ route[MESSAGE_REPLY] } $var(Payload) = '{ "Event-Category" : "message", "Event-Name" : "delivery", "Call-ID" : "$(sht(msg=>$ci){kz.json,Call-ID})", "Message-ID" : "$(sht(msg=>$ci){kz.json,Message-ID})" , "Delivery-Result-Code" : "sip:$T_reply_code", "Msg-ID" : "$(sht(msg=>$ci){kz.json,Msg-ID})" , "Status" : "$var(Result)"}'; - + $var(RoutingKey) = $(sht(msg=>$ci){kz.json,Server-ID}); $var(exchange) = "targeted"; if($var(RoutingKey) == "") { diff --git a/kamailio/nat-traversal-role.cfg b/kamailio/nat-traversal-role.cfg index c18bae2..b1dffd2 100644 --- a/kamailio/nat-traversal-role.cfg +++ b/kamailio/nat-traversal-role.cfg @@ -60,16 +60,16 @@ route[NAT_DETECT] if(is_first_hop()) set_contact_alias(); } } - + if($sel(cfg_get.kazoo.nat_fix_sdp_request) == 1) { if (has_body("application/sdp") && nat_uac_test(KZ_NAT_SDP_TEST)) { fix_nated_sdp(KZ_NAT_SDP_FIX); } } - + } -route[NAT_MANAGE] +route[NAT_MANAGE] { if ( is_request() && isflagset(FLAG_INTERNALLY_SOURCED)) { setbflag(FLB_NATB); diff --git a/kamailio/nodes-role.cfg b/kamailio/nodes-role.cfg index 5210d0d..c03afbf 100644 --- a/kamailio/nodes-role.cfg +++ b/kamailio/nodes-role.cfg @@ -58,7 +58,7 @@ route(LISTENER_STATUS); event_route[kazoo:consumer-event-nodes-advertise] { - $var(count) = $shtinc(nodes=>$(kzE{kz.json,Node})::count); + $var(count) = $shtinc(nodes=>$(kzE{kz.json,Node})::count); if($var(count) == 0) { xlog("L_WARNING", "$(kzE{kz.json,Msg-ID})|nodes|heartbeat for reconnected node $(kzE{kz.json,Node})\n"); $var(count) = $shtinc(nodes=>$(kzE{kz.json,Node})::count); @@ -68,7 +68,7 @@ event_route[kazoo:consumer-event-nodes-advertise] } else { xlog("L_DEBUG", "$(kzE{kz.json,Msg-ID})|nodes|heartbeat from existing node $(kzE{kz.json,Node})\n"); } - } + } mq_add("node_heartbeat", "$(kzE{kz.json,Node})", "$kzE"); } @@ -105,11 +105,11 @@ route[NODE_HEARTBEAT_ROUTE] xlog("L_DEBUG", "$(var(Payload){kz.json,Msg-ID})|nodes|processing heartbeat for node $var(Node)\n"); route(CHECK_MEDIA_SERVERS); - + $sht(nodes=>$var(Node)) = $var(Payload); - $shtex(nodes=>$var(Node)) = ($(var(Payload){kz.json,Expires}{s.int}) / 1000) + NODES_FUDGE_EXPIRE; + $shtex(nodes=>$var(Node)) = ($(var(Payload){kz.json,Expires}{s.int}) / 1000) + NODES_FUDGE_EXPIRE; $var(runloop) = $var(runloop) + 1; - } + } } route[CHECK_MEDIA_SERVERS] @@ -152,7 +152,7 @@ route[CHECK_MEDIA_SERVERS] route(MEDIA_SERVER_RESTART); }; $var(MediaExpire) = ($(var(Payload){kz.json,Expires}{s.int}) / 1000) + NODES_FUDGE_EXPIRE; - xlog("L_DEBUG", "nodes|media|$var(Node) media expiration $var(MediaExpire) for $var(MediaUrl)\n"); + xlog("L_DEBUG", "nodes|media|$var(Node) media expiration $var(MediaExpire) for $var(MediaUrl)\n"); $shtex(media=>$var(MediaUrl)::count) = $var(MediaExpire); $var(ProfileIdx) = $var(ProfileIdx) + 1; } @@ -186,7 +186,7 @@ route[MEDIA_SERVER_UP] route[MEDIA_SERVER_DOWN] { xlog("L_WARNING", "htable|media|heartbeat expired for media server $var(MediaUrl) in zone $var(Zone)\n"); - + #!ifdef PRESENCE_ROLE route(RESET_PUBLISHER); #!endif @@ -196,7 +196,7 @@ route[MEDIA_SERVER_DOWN] route[MEDIA_SERVER_RESTART] { xlog("L_WARNING", "htable|media|media server $var(MediaUrl) restarted in zone $var(Zone)\n"); - + #!ifdef PRESENCE_ROLE route(RESET_PUBLISHER); #!endif @@ -235,7 +235,7 @@ route[LISTENER_STATUS] } else { $var(advertise) = ""; } - $var(x) = $_s("$var(uri)" : {"proto" : "$var(proto)", "address" : "$var(address)", "port" : $var(port) $var(advertise) }); + $var(x) = $_s("$var(uri)" : {"proto" : "$var(proto)", "address" : "$var(address)", "port" : $var(port) $var(advertise) }); $var(listeners) = $_s($var(listeners)$var(sep)$var(x)); $var(loop) = $var(loop) + 1; $var(sep) = " , "; diff --git a/kamailio/presence-query.cfg b/kamailio/presence-query.cfg index 2a7c3cb..9894e15 100644 --- a/kamailio/presence-query.cfg +++ b/kamailio/presence-query.cfg @@ -2,7 +2,7 @@ route[PRESENCE_SEARCH_SUMMARY] { - xlog("L_INFO", "processing presence summary query for $(kzE{kz.json,Realm})\n"); + xlog("L_INFO", "$(kzE{kz.json,Msg-ID})|query|processing presence summary query for $(kzE{kz.json,Realm})\n"); $var(Queue) = $(kzE{kz.json,Server-ID}); $var(Event) = $(kzE{kz.json,Event-Package}); $var(Domain) = $(kzE{kz.json,Realm}); @@ -54,7 +54,7 @@ route[PRESENCE_SEARCH_SUMMARY] route[PRESENCE_SEARCH_DETAIL] { - xlog("L_INFO", "processing presence query detail for $(kzE{kz.json,Username}) in realm $(kzE{kz.json,Realm})\n"); + xlog("L_INFO", "$(kzE{kz.json,Msg-ID})|query|processing presence query detail for $(kzE{kz.json,Username}) in realm $(kzE{kz.json,Realm})\n"); $var(Queue) = $(kzE{kz.json,Server-ID}); $var(Msg-ID) = $(kzE{kz.json,Msg-ID}); $var(Event) = $(kzE{kz.json,Event-Package}); diff --git a/kamailio/presence-role.cfg b/kamailio/presence-role.cfg index 3c929de..093e760 100644 --- a/kamailio/presence-role.cfg +++ b/kamailio/presence-role.cfg @@ -97,7 +97,7 @@ route[HANDLE_SUBSCRIBE] && $hdr(Event) != "message-summary") { xlog("L_INFO", "$ci|presence|subscribe event $hdr(Event) not supported\n"); send_reply(489, "Bad Event"); - exit(); + exit(); } if (!t_newtran()) { @@ -137,7 +137,7 @@ route[DELETE_DUPLICATED_SUBSCRIPTIONS] route[HANDLE_RESUBSCRIBE] { - + if(handle_subscribe()) { if($subs(remote_cseq) < 5) { $sht(first=>$subs(callid)) = $null; @@ -210,7 +210,7 @@ route[REQUEST_PROBE] { if( ($sel(cfg_get.kazoo.presence_request_probe) == 1 && (!has_totag())) || ($sel(cfg_get.kazoo.presence_request_resubscribe_probe) == 1 && has_totag()) ) { - if( route(HAS_PRESENTITY) == 0) { + if( route(HAS_PRESENTITY) == 0) { if($hdr(event) == "message-summary") { $var(mwi) = $tU; route(REQUEST_MWI); @@ -248,7 +248,7 @@ route[HANDLE_PUBLISH] && $hdr(Event) != "message-summary") { xlog("L_INFO", "$ci|presence|publish event $hdr(Event) not supported\n"); send_reply(489, "Bad Event"); - exit(); + exit(); } if (!t_newtran()) { @@ -380,9 +380,9 @@ event_route[kazoo:consumer-event-presence-mwi-update] } #!else xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|skip mwi update for $var(presentity)\n"); -#!endif +#!endif } - + route(MWI_AS_PRESENCE); xlog("L_DBG", "$(kzE{kz.json,Call-ID})|log|message-summary update for $(kzE{kz.json,From}) light should be on ? $(kzE{kz.json,Messages-Waiting}) at $(kzE{kz.json,AMQP-Received})/$var(Now)/$TS\n"); @@ -402,8 +402,8 @@ event_route[kazoo:consumer-event-presence-update] $var(presentity) = $_s(sip:$(kzE{kz.json,Presence-ID})); $var(payload) = $kzE; route(PRESENCE_UPDATE); - - xlog("L_DEBUG", "$(kzE{kz.json,Call-ID})|log|$(kzE{kz.json,Event-Package}) update for $(kzE{kz.json,From}) state $(kzE{kz.json,State}) from $(kzE{kz.json,Switch-URI}) Δ at $(kzE{kz.json,AMQP-Received})/$var(Now)/$TS\n"); + + xlog("L_DEBUG", "$(kzE{kz.json,Call-ID})|log|$(kzE{kz.json,Event-Package}) update for $(kzE{kz.json,From}) state $(kzE{kz.json,State}) from $(kzE{kz.json,Switch-URI}) Δ at $(kzE{kz.json,AMQP-Received})/$var(Now)/$TS\n"); } route[PRESENCE_UPDATE] @@ -418,7 +418,7 @@ route[PRESENCE_UPDATE] ( $(var(payload){kz.json,State}) == "early" || ($(var(payload){kz.json,State}) == "confirmed" && $(var(payload){kz.json,State}) == "initiator") )) { - xlog("L_WARN", "$(var(payload){kz.json,Call-ID})|log|not publishing state $(var(payload){kz.json,State}) for presentity $var(presentity) with $xavp(watchers=>self) calls, policy limit of $sel(cfg_get.kazoo.presence_max_call_per_presentity) calls per presentity \n"); + xlog("L_WARN", "$(var(payload){kz.json,Call-ID})|log|not publishing state $(var(payload){kz.json,State}) for presentity $var(presentity) with $xavp(watchers=>self) calls, policy limit of $sel(cfg_get.kazoo.presence_max_call_per_presentity) calls per presentity \n"); } else { if($xavp(watchers=>dialog) > 0) { if($(var(payload){kz.json,State}) == "terminated") { @@ -443,7 +443,7 @@ route[PRESENCE_UPDATE] xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|skip dialog update for $var(presentity)\n"); #!endif } - + if($xavp(watchers=>presence) > 0) { xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|publishing $var(presentity) presence update for $xavp(watchers=>presence) watchers\n"); kazoo_pua_publish_presence($var(payload)); @@ -497,7 +497,7 @@ route[MWI_AS_PRESENCE] route[PRESENCE_BINDINGS] { #!import_file "presence-custom-bindings.cfg" - + #!ifndef PRESENCE_CUSTOM_BINDINGS $var(payload) = $_s({ "name" : "presence", "exchange" : "presence", "type" : "topic", "queue" : "presence-dialog-MY_HOSTNAME", "routing" : ["dialog.*.*", "update.*.*", "mwi_updates.*.*"], "exclusive" : 0, "federate" : 1 }); kazoo_subscribe("$var(payload)"); @@ -514,7 +514,7 @@ route[PRESENCE_BINDINGS] route[PRESENCE_API_BINDINGS] { #!import_file "presence-api-custom-bindings.cfg" - + #!ifndef PRESENCE_API_CUSTOM_BINDINGS $var(payload) = $_s({"name": "presence-api", "exchange": "presence", "type": "topic", "queue": "presence-api-MY_HOSTNAME", "routing": ["presence.search_req.*", "presence.reset.*.*"], "exclusive": 0, "federate": 1 }); kazoo_subscribe("$var(payload)"); diff --git a/kamailio/pusher-role.cfg b/kamailio/pusher-role.cfg index a15ec68..d969eb7 100644 --- a/kamailio/pusher-role.cfg +++ b/kamailio/pusher-role.cfg @@ -66,7 +66,7 @@ route[PUSHER_PREPARE_PUSH] route[PUSHER_PREPARE_PUSH_PAYLOAD] { - + $var(TokenID) = $hdr(X-KAZOO-PUSHER-Token-ID); $var(TokenType) = $hdr(X-KAZOO-PUSHER-Token-Type); $var(TokenApp) = $hdr(X-KAZOO-PUSHER-Token-App); @@ -90,13 +90,13 @@ route[PUSHER_PREPARE_PUSH_PAYLOAD] $var(from_user) = $(hdr(From){tobody.user}); $var(from_name) = $(hdr(From){tobody.display}{re.subst,/"//g}); } - + $var(from) = $_s($var(from_user) - $var(from_name)); $var(PushPayload) = $_s({"call-id" : "$ci", "proxy" : "$var(TokenProxy)", "caller-id-number" : "$var(from_user)", "caller-id-name" : "$var(from_name)", "registration-token" : "$var(TokenReg)"}); $var(Payload) = $_s({ "Event-Category" : "notification", "Event-Name" : "push_req", "Call-ID" : "$ci", "Token-ID" : "$var(TokenID)", "Token-Type" : "$var(TokenType)", "Token-App" : "$var(TokenApp)", "Alert-Key" : "IC_SIL", "Alert-Params" : ["$var(from)"], "Sound" : "ring.caf", "Payload" : $var(PushPayload) }); - + $avp(push_routing_key) = "notification.push." + $var(TokenType) + "." + $var(TokenID); $avp(push_payload) = $var(Payload); } @@ -163,8 +163,8 @@ route[PUSHER_ATTEMPT_REGISTRATION] route[PUSHER_ON_REGISTRATION] { - if( ( $(xavp(ulattrs=>x_token_reg){s.len}) > 0 || - $(xavp(ulattrs=>custom_channel_vars){kz.json,Pusher-Application}{s.len}) > 0) && + if( ( $(xavp(ulattrs=>x_token_reg){s.len}) > 0 || + $(xavp(ulattrs=>custom_channel_vars){kz.json,Pusher-Application}{s.len}) > 0) && $var(Status) == "Registered") { if($sht(push_cache=>$(tu{s.tolower})) != $null) { xlog("L_INFO", "$ci|pusher|device registered, delivering the call\n"); diff --git a/kamailio/registrar-role.cfg b/kamailio/registrar-role.cfg index b3a0263..d14f137 100644 --- a/kamailio/registrar-role.cfg +++ b/kamailio/registrar-role.cfg @@ -96,9 +96,9 @@ route[HANDLE_REGISTER] resetbflag(FLB_NATSIPPING); if (isflagset(FLT_NATS)) { - setbflag(FLB_NATB); + setbflag(FLB_NATB); fix_nated_register(); - + ## KAZOO-1846: Cisco SPA8000 freaks out on options pings if (!($ua =~ "Linksys/SPA8000" || $ua =~ "SIPp" @@ -142,7 +142,7 @@ route[ATTEMPT_AUTHORIZATION] route(PUSHER_ATTEMPT_REGISTRATION); #!endif - if($sel(cfg_get.kazoo.registrar_force_query) == 0) { + if($sel(cfg_get.kazoo.registrar_force_query) == 0) { $xavp(regcfg=>match_received) = $su; if($sht(auth_cache=>$Au) != $null && registered("location", "$rz:$Au", 2, 1) == 1 @@ -326,7 +326,7 @@ route[SAVE_LOCATION] default: $var(port) = $Rp; } - + $var(AdvIP) = $RAi; if(af==INET6) { $var(AdvIP) = "[" + $RAi + "]"; @@ -399,7 +399,7 @@ route[REGISTRAR_BOUNDS] send_reply("400", "Missing Expires"); exit; } - + if($var(expires) != 0) { if($var(expires) < REGISTRAR_MIN_EXPIRES) { $var(expires) = REGISTRAR_MIN_EXPIRES; @@ -408,12 +408,12 @@ route[REGISTRAR_BOUNDS] exit; } } - + } ## -## this needs handling logic in ecallmgr -## because we will fire the unregister from this server +## this needs handling logic in ecallmgr +## because we will fire the unregister from this server ## after device registers in another proxy ## causing ecallmgr to delete the registration ## from the other server @@ -481,7 +481,7 @@ route[REGISTRAR_ROUTE_TO_AOR] if ($hdr(X-KAZOO-AOR) == $null) { return(); } - + xlog("L_INFO", "$ci|log|using AOR $hdr(X-KAZOO-AOR)\n"); setflag(FLT_AOR); if ($hdr(X-KAZOO-INVITE-FORMAT) == "contact") { diff --git a/kamailio/websockets-role.cfg b/kamailio/websockets-role.cfg index 7bdaf1c..ca18f0e 100644 --- a/kamailio/websockets-role.cfg +++ b/kamailio/websockets-role.cfg @@ -33,7 +33,7 @@ route[HANDLE_WEBSOCKETS] # connection - even if it is not behind a NAT! # This won't be needed in the future if Kamailio and the # WebSocket client support Outbound and Path. - + return(); } From 0bb2cd7a2844b10331d31f81246f4097514738fe Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 16 Jan 2019 18:03:37 +0000 Subject: [PATCH 077/209] better defaults for ip and hostname --- kamailio/default.cfg | 6 ------ kamailio/defs.cfg | 19 ++++++++++++++----- kamailio/kamailio.cfg | 14 ++++++++++++++ kamailio/kazoo-bindings.cfg | 14 -------------- kamailio/local.cfg | 23 ++++++++--------------- kamailio/sip_trace-role.cfg | 2 +- 6 files changed, 37 insertions(+), 41 deletions(-) diff --git a/kamailio/default.cfg b/kamailio/default.cfg index 4e677f5..965f03f 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -105,9 +105,6 @@ loadmodule "stun.so" ######## Kamailio path module ######## loadmodule "path.so" -######## Kamailio ipops module ######## -loadmodule "ipops.so" - ######## Kamailio control connector module ######## loadmodule "ctl.so" modparam("ctl", "binrpc_buffer_size", 4096) @@ -166,9 +163,6 @@ loadmodule "htable.so" modparam("htable", "htable", "associations=>size=16;autoexpire=7200") modparam("htable", "htable", "redirects=>size=16;autoexpire=5") -######## Pseudo-Variables module ######## -loadmodule "pv.so" - ####### RTIMER module ########## loadmodule "rtimer.so" diff --git a/kamailio/defs.cfg b/kamailio/defs.cfg index 56e0900..d0991e4 100644 --- a/kamailio/defs.cfg +++ b/kamailio/defs.cfg @@ -3,6 +3,18 @@ ####### defs ######## +#!ifndef MY_HOSTNAME +#!substdef "!MY_HOSTNAME!$HN(f)!g" +#!endif + +#!ifndef MY_HOSTNAME +#!substdef "!MY_IP_ADDRESS!$HN(i)!g" +#!endif + +#!ifndef MY_HOSTNAME +#!substdef "!MY_WEBSOCKET_DOMAIN!$HN(d)!g" +#!endif + #!trydef KAZOO_LOG_LEVEL L_INFO #!ifndef KAMAILIO_DBMS @@ -69,11 +81,8 @@ #!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" +#!trydef SIP_TRACE_URI "sip:127.0.0.1:9060" +#!trydef HEP_CAPTURE_ID 1 #!endif #!endif diff --git a/kamailio/kamailio.cfg b/kamailio/kamailio.cfg index 2528128..bf27b31 100644 --- a/kamailio/kamailio.cfg +++ b/kamailio/kamailio.cfg @@ -23,6 +23,20 @@ #!define FLB_UAC_REDIRECT 3 #!define TRUSTED_ADR_GROUP 1 +################ +# Kamailio modules to help substdef setup +# these need to go before local.cfg +# so they can be used +# +# ipops - ip , domain, hostname +# pv - $def(existing definition) +# +# +################ +loadmodule "ipops.so" +loadmodule "pv.so" + + ####### Local Configuration ######## include_file "local.cfg" diff --git a/kamailio/kazoo-bindings.cfg b/kamailio/kazoo-bindings.cfg index cb3e7eb..7de1665 100644 --- a/kamailio/kazoo-bindings.cfg +++ b/kamailio/kazoo-bindings.cfg @@ -1,18 +1,4 @@ ######## kazoo bindings ######## -### use this simple form of binding a listener -### kazoo_subscribe("dialoginfo", "direct", "BLF-QUEUE-MY_HOSTNAME", "BLF-MY_HOSTNAME"); -### -### or unleash the power of rabbit to kazoo-blf -### -### 'no_ack' : 1 => needs ack, -### 'wait_for_consumer_ack' -### : 1 => when it receives, it processses on the AMQP Worker ad after that it confirms -### : 0 => when it receives, it acks then processes in the AMQP Worker -### only works if no_ack : 0 -### -### Rabbit Policy for ha-mode -### pattern : ^BLF -### definition : ha-mode: all ### ### diff --git a/kamailio/local.cfg b/kamailio/local.cfg index 8981287..24ea1a2 100644 --- a/kamailio/local.cfg +++ b/kamailio/local.cfg @@ -27,14 +27,14 @@ ################################################################################ ## SERVER INFORMATION ################################################################################ -## CHANGE "kamailio.2600hz.com" TO YOUR SERVERS HOSTNAME -#!substdef "!MY_HOSTNAME!kamailio.2600hz.com!g" +## UNCOMMENT & CHANGE "kamailio.2600hz.com" TO YOUR SERVERS HOSTNAME +# # #!substdef "!MY_HOSTNAME!kamailio.2600hz.com!g" -## CHANGE "127.0.0.1" TO YOUR SERVERS IP ADDRESS +## UNCOMMENT & CHANGE "127.0.0.1" TO YOUR SERVERS IP ADDRESS ## Usually your public IP. If you need ## to listen on addtional ports or IPs ## add them in "BINDINGS" at the bottom. -#!substdef "!MY_IP_ADDRESS!0.0.0.0!g" +# # #!substdef "!MY_IP_ADDRESS!127.0.0.1!g" ## CHANGE "kazoo://guest:guest@127.0.0.1:5672" TO THE AMQP URL ## This should be the primary RabbitMQ server @@ -46,7 +46,7 @@ ## Origin header on a new websocket request ## or it will be rejected. If you remove ## it completely the validation will be disabled. -#!substdef "!MY_WEBSOCKET_DOMAIN!2600hz.com!g" +# # #!substdef "!MY_WEBSOCKET_DOMAIN!2600hz.com!g" ################################################################################ ## DATABASE @@ -107,22 +107,15 @@ ##!define KZ_UDP_REGISTRAR_PORT 7000 ##!define KZ_TCP_REGISTRAR_PORT 7000 -################################################################################ -## NAT -################################################################################ -## These parameters are OPTIONAL. -## It allows overriding the nat_uac_test for port / contact with different values -# # #!trydef KZ_NAT_CONTACT_DETECT "1" -# # #!trydef KZ_NAT_PORT_DETECT "2" - ################################################################################ ## 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" +# # #!define SIP_TRACE_URI "sip:127.0.0.1:9060" +# # #!define HEP_CAPTURE_ID 1 + ## YOU SHOULD NOT HAVE TO CHANGE THESE! ## By setting MY_IP_ADDRESS above these will resolve diff --git a/kamailio/sip_trace-role.cfg b/kamailio/sip_trace-role.cfg index 7508567..cbd286a 100644 --- a/kamailio/sip_trace-role.cfg +++ b/kamailio/sip_trace-role.cfg @@ -15,7 +15,7 @@ kazoo.trace_external_outgoing = KZ_TRACE_EXTERNAL_OUTGOING descr "traces the out ####### Siptrace module ########## loadmodule "siptrace.so" -modparam("siptrace", "duplicate_uri", "SIP_TRACE_URI") +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) From a188c578435facad511fa1158f2bc31c0c27ca22 Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 16 Jan 2019 20:24:44 +0000 Subject: [PATCH 078/209] more defaults and squashed fast pickup into presence --- kamailio/defs.cfg | 12 ++++--- kamailio/dispatcher-role.cfg | 4 +-- kamailio/local.cfg | 4 +-- kamailio/nodes-role.cfg | 4 +-- ...ckup-role.cfg => presence-fast-pickup.cfg} | 34 +++++++++---------- kamailio/presence-role.cfg | 13 ++----- kamailio/websockets-role.cfg | 2 +- 7 files changed, 33 insertions(+), 40 deletions(-) rename kamailio/{fast-pickup-role.cfg => presence-fast-pickup.cfg} (86%) diff --git a/kamailio/defs.cfg b/kamailio/defs.cfg index d0991e4..3648826 100644 --- a/kamailio/defs.cfg +++ b/kamailio/defs.cfg @@ -7,11 +7,11 @@ #!substdef "!MY_HOSTNAME!$HN(f)!g" #!endif -#!ifndef MY_HOSTNAME +#!ifndef MY_IP_ADDRESS #!substdef "!MY_IP_ADDRESS!$HN(i)!g" #!endif -#!ifndef MY_HOSTNAME +#!ifndef MY_WEBSOCKET_DOMAIN #!substdef "!MY_WEBSOCKET_DOMAIN!$HN(d)!g" #!endif @@ -74,6 +74,7 @@ ## Defs related to SIP_TRACE_ROLE ## #!ifdef SIP_TRACE_ROLE + #!trydef KZ_TRACE 0 #!trydef KZ_TRACE_INTERNAL 1 #!trydef KZ_TRACE_EXTERNAL 1 @@ -83,7 +84,8 @@ #!trydef KZ_TRACE_EXTERNAL_OUTGOING 1 #!trydef SIP_TRACE_URI "sip:127.0.0.1:9060" #!trydef HEP_CAPTURE_ID 1 -#!endif + + #!endif #!ifndef KZ_DISABLE_WEBSOCKETS_REGISTRAR_PORT @@ -104,7 +106,7 @@ #!trydef KZ_TLS_REGISTRAR_PORT 7000 #!endif -#!trydef KZ_FAST_PICKUP_COOKIES 1 -#!trydef KZ_FAST_PICKUP_REALTIME 1 +#!trydef KZ_PRESENCE_FAST_PICKUP_COOKIES 1 +#!trydef KZ_PRESENCE_FAST_PICKUP_REALTIME 1 # vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab diff --git a/kamailio/dispatcher-role.cfg b/kamailio/dispatcher-role.cfg index 7be99c0..14b9ecc 100644 --- a/kamailio/dispatcher-role.cfg +++ b/kamailio/dispatcher-role.cfg @@ -109,8 +109,8 @@ route[DISPATCHER_FIND_ROUTES] } #!endif - #!ifdef FAST_PICKUP_ROLE - route(FAST_PICKUP_ATTEMPT); + #!ifdef PRESENCE_ROLE + route(PRESENCE_FAST_PICKUP_ATTEMPT); #!endif #!import_file "dispatcher-network-find.cfg" diff --git a/kamailio/local.cfg b/kamailio/local.cfg index 24ea1a2..7d51dfc 100644 --- a/kamailio/local.cfg +++ b/kamailio/local.cfg @@ -8,8 +8,6 @@ #!trydef PRESENCE_ROLE #!trydef RESPONDER_ROLE #!trydef NODES_ROLE -#!trydef FAST_PICKUP_ROLE -#!trydef PRESENCE_QUERY_ROLE ## Disabled Roles - remove all but the last '#' to enable # # #!trydef TRAFFIC_FILTER_ROLE @@ -39,7 +37,7 @@ ## CHANGE "kazoo://guest:guest@127.0.0.1:5672" TO THE AMQP URL ## This should be the primary RabbitMQ server ## in the zone that this server will service. -#!substdef "!MY_AMQP_URL!kazoo://guest:guest@127.0.0.1:5672!g" +#!substdef "!MY_AMQP_URL!amqp://guest:guest@127.0.0.1:5672!g" ## This parameter is only required if you are using websockets ## This value must be present in the HTTP diff --git a/kamailio/nodes-role.cfg b/kamailio/nodes-role.cfg index c03afbf..76f7598 100644 --- a/kamailio/nodes-role.cfg +++ b/kamailio/nodes-role.cfg @@ -177,8 +177,8 @@ route[MEDIA_SERVER_UP] route(DISPATCHER_CHECK_MEDIA_SERVER); #!endif -#!ifdef FAST_PICKUP_ROLE - route(FAST_PICKUP_START); +#!ifdef PRESENCE_ROLE + route(PRESENCE_FAST_PICKUP_START); #!endif } diff --git a/kamailio/fast-pickup-role.cfg b/kamailio/presence-fast-pickup.cfg similarity index 86% rename from kamailio/fast-pickup-role.cfg rename to kamailio/presence-fast-pickup.cfg index bfe00bd..af9f263 100644 --- a/kamailio/fast-pickup-role.cfg +++ b/kamailio/presence-fast-pickup.cfg @@ -2,20 +2,20 @@ modparam("htable", "htable", "park=>size=16;autoexpire=600") modparam("htable", "htable", "fp=>size=8"); -#!trydef KZ_FAST_PICKUP_COOKIES 1 -#!trydef KZ_FAST_PICKUP_REALTIME 1 -#!trydef KZ_FAST_PICKUP_STAR_5 1 +#!trydef KZ_PRESENCE_FAST_PICKUP_COOKIES 1 +#!trydef KZ_PRESENCE_FAST_PICKUP_REALTIME 1 +#!trydef KZ_PRESENCE_FAST_PICKUP_STAR_5 1 -kazoo.fast_pickup_cookies = KZ_FAST_PICKUP_COOKIES descr "maintains a hash table for correlating call-ids with media servers" -kazoo.fast_pickup_realtime = KZ_FAST_PICKUP_REALTIME descr "queries channels api for realtime status of call-id" -kazoo.fast_pickup_star_5 = KZ_FAST_PICKUP_STAR_5 descr "treats *5 as park pickup, queries state of *3" +kazoo.presence_fast_pickup_cookies = KZ_PRESENCE_FAST_PICKUP_COOKIES descr "maintains a hash table for correlating call-ids with media servers" +kazoo.presence_fast_pickup_realtime = KZ_PRESENCE_FAST_PICKUP_REALTIME descr "queries channels api for realtime status of call-id" +kazoo.presence_fast_pickup_star_5 = KZ_PRESENCE_FAST_PICKUP_STAR_5 descr "treats *5 as park pickup, queries state of *3" -route[FAST_PICKUP_START] +route[PRESENCE_FAST_PICKUP_START] { $sht(fp=>count) = 0; } -route[FAST_PICKUP_LOAD] +route[PRESENCE_FAST_PICKUP_LOAD] { sht_reset("fp"); xlog("L_INFO", "$ci|log|fast|initializing fastpick hash table from dispatcher\n"); @@ -36,7 +36,7 @@ route[FAST_PICKUP_LOAD] } } -route[FAST_PICKUP_ATTEMPT] +route[PRESENCE_FAST_PICKUP_ATTEMPT] { if (!is_method("INVITE")) { return; @@ -50,14 +50,14 @@ route[FAST_PICKUP_ATTEMPT] if($var(replaced_call_id) =~ "kfp+") { if($shtinc(fp=>count) == 1) { - route(FAST_PICKUP_LOAD); + route(PRESENCE_FAST_PICKUP_LOAD); } remove_hf_re("^Replaces"); $var(PickupOptions) = $(var(replaced_call_id){re.subst,/^kfp\+(.{2})([^@]*)@(.*)/\1/}{s.decode.hexa}); $var(md5) = $(var(replaced_call_id){re.subst,/^kfp\+(.{2})([^@]*)@(.*)/\2/}); $var(replaced_call_id) = $(var(replaced_call_id){re.subst,/^kfp\+(.{2})([^@]*)@(.*)/\3/}); if( $sht(fp=>$var(md5)) != $null) { - route(FAST_PICKUP_OPTION); + route(PRESENCE_FAST_PICKUP_OPTION); $du = $sht(fp=>$var(md5)); append_hf("Replaces: $var(replaced_call_id)$var(Pickup)\r\n"); xlog("L_INFO", "$ci|log|fast|found shortcut for call-id $var(replaced_call_id) , redirecting ($(ru{uri.user})) to $du\n"); @@ -69,7 +69,7 @@ route[FAST_PICKUP_ATTEMPT] } } - if($sel(cfg_get.kazoo.fast_pickup_realtime) == 1) { + if($sel(cfg_get.kazoo.presence_fast_pickup_realtime) == 1) { if($var(replaced_call_id) != "none") { xlog("L_INFO", "$ci|log|request has replaces call-id $var(replaced_call_id)\n"); $var(amqp_payload_request) = '{"Event-Category" : "call_event" , "Event-Name" : "channel_status_req", "Call-ID" : "' + $var(replaced_call_id) + '", "Active-Only" : true }'; @@ -103,7 +103,7 @@ route[FAST_PICKUP_ATTEMPT] ##### CALL-PARK #### ##### STAR 5 CHECK #### - if($sel(cfg_get.kazoo.fast_pickup_star_5) == 1) { + if($sel(cfg_get.kazoo.presence_fast_pickup_star_5) == 1) { if($(ru{uri.user}) =~ "\*5") { $var(park) = $_s(*3$(ru{uri.user}{s.substr,2,0})@$(ru{uri.domain})); if($sht(park=>$var(park)) != $null) { @@ -124,7 +124,7 @@ route[FAST_PICKUP_ATTEMPT] ##### CALL-PARK IN KAZOO #### $var(park_extension) = "\*3"; - if($sel(cfg_get.kazoo.fast_pickup_star_5) == 1) { + if($sel(cfg_get.kazoo.presence_fast_pickup_star_5) == 1) { $var(park_extension) = "\*[3,5]"; } if($(ru{uri.user}) =~ $var(park_extension) && !($rd =~ "[0-9]{1,3}\.[0-9]{1,3}.[0-9]{1,3}\.[0-9]{1,3}") ) { @@ -142,7 +142,7 @@ route[FAST_PICKUP_ATTEMPT] } } -route[FAST_PICKUP_OPTION] +route[PRESENCE_FAST_PICKUP_OPTION] { $var(Pickup) = ""; switch($var(PickupOptions)) @@ -158,7 +158,7 @@ route[FAST_PICKUP_OPTION] } } -route[FAST_PICKUP_INIT] +route[PRESENCE_FAST_PICKUP_INIT] { $var(AppName) = $(kzE{kz.json,App-Name}); @@ -172,7 +172,7 @@ route[FAST_PICKUP_INIT] } ## fast pickup with cookies - if($sel(cfg_get.kazoo.fast_pickup_cookies) == 1) { + if($sel(cfg_get.kazoo.presence_fast_pickup_cookies) == 1) { if($var(AppName) == "park") { $var(Pickup) = 1; #";a-leg=true"; } else { diff --git a/kamailio/presence-role.cfg b/kamailio/presence-role.cfg index 093e760..0987747 100644 --- a/kamailio/presence-role.cfg +++ b/kamailio/presence-role.cfg @@ -67,13 +67,10 @@ kazoo.presence_request_resubscribe_probe = KZ_PRESENCE_REQUEST_RESUBSCRIBE_PROBE kazoo.presence_ignore_status_probe_resp = KZ_PRESENCE_IGNORE_STATUS_PROBE_RESP descr "ignore online/offline probe replies" kazoo.presence_max_call_per_presentity = KZ_PRESENCE_MAX_CALL_PER_PRESENTITY descr "max number of calls per presentity" -#!ifdef FAST_PICKUP_ROLE -#!include_file "fast-pickup-role.cfg" -#!endif - #!include_file "presence-query.cfg" #!include_file "presence-notify.cfg" #!include_file "presence-reset.cfg" +#!include_file "presence-fast-pickup.cfg" ####### Presence Logic ######## @@ -345,9 +342,7 @@ event_route[kazoo:consumer-event-presence-dialog-update] xlog("L_DEBUG", "$(kzE{kz.json,Call-ID})|log|received $(kzE{kz.json,Event-Package}) update for $(kzE{kz.json,From}) state $(kzE{kz.json,State}) from $(kzE{kz.json,AMQP-Broker-Zone}) => $(kzE{kz.json,Switch-URI}) (Δ1 $(kzE{kz.json,AMQP-Elapsed-Micro}) μs , Δ2 $var(delta_to_start) μs)\n"); $var(JObj) = $kzE; - #!ifdef FAST_PICKUP_ROLE - route(FAST_PICKUP_INIT); - #!endif + route(PRESENCE_FAST_PICKUP_INIT); $var(presentity) = $(kzE{kz.json,From}); $var(payload) = $kzE; @@ -505,9 +500,7 @@ route[PRESENCE_BINDINGS] route(PRESENCE_API_BINDINGS); - #!ifdef FAST_PICKUP_ROLE - route(FAST_PICKUP_START); - #!endif + route(PRESENCE_FAST_PICKUP_START); } diff --git a/kamailio/websockets-role.cfg b/kamailio/websockets-role.cfg index ca18f0e..0dcc48b 100644 --- a/kamailio/websockets-role.cfg +++ b/kamailio/websockets-role.cfg @@ -80,7 +80,7 @@ event_route[xhttp:request] #!ifdef MY_WEBSOCKET_DOMAIN if (!($hdr(Origin) =~ "MY_WEBSOCKET_DOMAIN")) { - xlog("L_INFO", "websocket|log|rejecting HTTP request with unknown origin $hdr(Origin) from $si:$sp\n"); + xlog("L_INFO", "websocket|log|rejecting HTTP request with unauthorized origin $hdr(Origin) from $si:$sp, allowed origin is MY_WEBSOCKET_DOMAIN\n"); xhttp_reply("400", "Bad Request", "", ""); exit; } From 819b2071e785deb15906e66b89693fb39e920d1f Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 16 Jan 2019 23:03:46 +0000 Subject: [PATCH 079/209] origin restriction by default --- kamailio/defs.cfg | 2 ++ kamailio/local.cfg | 20 ++++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/kamailio/defs.cfg b/kamailio/defs.cfg index 3648826..3efe795 100644 --- a/kamailio/defs.cfg +++ b/kamailio/defs.cfg @@ -11,9 +11,11 @@ #!substdef "!MY_IP_ADDRESS!$HN(i)!g" #!endif +#!ifndef WEBSOCKET_NO_ORIGIN_RESTRICTION #!ifndef MY_WEBSOCKET_DOMAIN #!substdef "!MY_WEBSOCKET_DOMAIN!$HN(d)!g" #!endif +#!endif #!trydef KAZOO_LOG_LEVEL L_INFO diff --git a/kamailio/local.cfg b/kamailio/local.cfg index 7d51dfc..2ed1086 100644 --- a/kamailio/local.cfg +++ b/kamailio/local.cfg @@ -39,12 +39,24 @@ ## in the zone that this server will service. #!substdef "!MY_AMQP_URL!amqp://guest:guest@127.0.0.1:5672!g" -## This parameter is only required if you are using websockets +################################################################################ +## WEBSOCKETS +################################################################################ +## +## These parameters are only required if you are using websockets +## +## MY_WEBSOCKET_DOMAIN ## This value must be present in the HTTP ## Origin header on a new websocket request -## or it will be rejected. If you remove -## it completely the validation will be disabled. -# # #!substdef "!MY_WEBSOCKET_DOMAIN!2600hz.com!g" +## or it will be rejected. default value is +## domain of this server. +## #!substdef "!MY_WEBSOCKET_DOMAIN!2600hz.com!g" +## +## WEBSOCKET_NO_ORIGIN_RESTRICTION +## if defined, it will disable the origin validation. +## +## #!trydef WEBSOCKET_NO_ORIGIN_RESTRICTION +## ################################################################################ ## DATABASE From 1a3401d66ebf638cdcf802a0ca77fb1343675a70 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 17 Jan 2019 04:57:59 +0000 Subject: [PATCH 080/209] substdefs for listeners need the IP_ADDRESS resolved --- kamailio/defs.cfg | 4 ++++ kamailio/local.cfg | 1 + 2 files changed, 5 insertions(+) diff --git a/kamailio/defs.cfg b/kamailio/defs.cfg index 3efe795..01b8d8d 100644 --- a/kamailio/defs.cfg +++ b/kamailio/defs.cfg @@ -2,6 +2,8 @@ ####### defs ######## +#!ifndef DEFAULTS_INCLUDED +#!trydef DEFAULTS_INCLUDED #!ifndef MY_HOSTNAME #!substdef "!MY_HOSTNAME!$HN(f)!g" @@ -111,4 +113,6 @@ #!trydef KZ_PRESENCE_FAST_PICKUP_COOKIES 1 #!trydef KZ_PRESENCE_FAST_PICKUP_REALTIME 1 +#!endif + # vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab diff --git a/kamailio/local.cfg b/kamailio/local.cfg index 2ed1086..807b296 100644 --- a/kamailio/local.cfg +++ b/kamailio/local.cfg @@ -126,6 +126,7 @@ # # #!define SIP_TRACE_URI "sip:127.0.0.1:9060" # # #!define HEP_CAPTURE_ID 1 +include_file "defs.cfg" ## YOU SHOULD NOT HAVE TO CHANGE THESE! ## By setting MY_IP_ADDRESS above these will resolve From b3c125f863f85036999ec5675db7ece3bbce7ad4 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 17 Jan 2019 05:02:32 +0000 Subject: [PATCH 081/209] use more meaningful method --- kamailio/defs.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kamailio/defs.cfg b/kamailio/defs.cfg index 01b8d8d..028800b 100644 --- a/kamailio/defs.cfg +++ b/kamailio/defs.cfg @@ -3,7 +3,7 @@ ####### defs ######## #!ifndef DEFAULTS_INCLUDED -#!trydef DEFAULTS_INCLUDED +#!define DEFAULTS_INCLUDED #!ifndef MY_HOSTNAME #!substdef "!MY_HOSTNAME!$HN(f)!g" From f88cba7f7e7d0d9ace40372701a7b09596abc518 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 17 Jan 2019 05:41:03 +0000 Subject: [PATCH 082/209] start moving role specific definitions --- kamailio/default.cfg | 2 + kamailio/defs-amqp.cfg | 86 +++++++++++++++++++++++++++++++++++++ kamailio/defs.cfg | 50 +-------------------- kamailio/presence-role.cfg | 7 +++ kamailio/sip_trace-role.cfg | 15 ++++++- 5 files changed, 110 insertions(+), 50 deletions(-) create mode 100644 kamailio/defs-amqp.cfg diff --git a/kamailio/default.cfg b/kamailio/default.cfg index 965f03f..68e372a 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -205,7 +205,9 @@ modparam("kazoo", "amqp_max_channels", MY_AMQP_MAX_CHANNELS) modparam("kazoo", "amqp_consumer_processes", MY_AMQP_CONSUMER_PROCESSES) modparam("kazoo", "amqp_consumer_workers", MY_AMQP_CONSUMER_WORKERS) ## amqp connections +#!ifdef MY_AMQP_URL modparam("kazoo", "amqp_connection", "MY_AMQP_URL") +#!endif #!ifdef MY_AMQP_SECONDARY_URL modparam("kazoo", "amqp_connection", "MY_AMQP_SECONDARY_URL") #!endif diff --git a/kamailio/defs-amqp.cfg b/kamailio/defs-amqp.cfg new file mode 100644 index 0000000..f103111 --- /dev/null +++ b/kamailio/defs-amqp.cfg @@ -0,0 +1,86 @@ +## NOTE: DO NOT CHANGE THIS FILE, EDIT local.cfg ## + + +####### amqp defs ######## +#!ifndef AMQP_DEFAULTS_INCLUDED +#!define AMQP_DEFAULTS_INCLUDED + +#!trydef MY_AMQP_MAX_CHANNELS 25 +#!trydef MY_AMQP_CONSUMER_PROCESSES 4 +#!trydef MY_AMQP_CONSUMER_WORKERS 16 +#!trydef MY_AMQP_HEARTBEATS 5 + +#!ifndef MY_AMQP_ZONE +#!substdef "!MY_AMQP_ZONE!local!g" +#!endif + +#!ifdef PRESENCE_ROLE +#!trydef MY_AMQP_PUA_MODE 1 +#!else +#!trydef MY_AMQP_PUA_MODE 0 +#!endif + +#!ifndef MY_AMQP_URL +#!ifdef AMQP_URL1 +#!substdef "!MY_AMQP_URL!$def(AMQP_URL1)!g" +#!endif +#!endif + +#!ifndef MY_AMQP_SECONDARY_URL +#!ifdef AMQP_URL2 +#!substdef "!MY_AMQP_SECONDARY_URL!$def(AMQP_URL2)!g" +#!endif +#!endif + +#!ifndef MY_AMQP_TERTIARY_URL +#!ifdef AMQP_URL3 +#!substdef "!MY_AMQP_TERTIARY_URL!$def(AMQP_URL3)!g" +#!endif +#!endif + +#!ifndef MY_AMQP_QUATERNARY_URL +#!ifdef AMQP_URL4 +#!substdef "!MY_AMQP_QUATERNARY_URL!$def(AMQP_URL4)!g" +#!endif +#!endif + +#!ifndef MY_AMQP_QUINARY_URL +#!ifdef AMQP_URL5 +#!substdef "!MY_AMQP_QUINARY_URL!$def(AMQP_URL5)!g" +#!endif +#!endif + +#!ifndef MY_AMQP_SENARY_URL +#!ifdef AMQP_URL6 +#!substdef "!MY_AMQP_SENARY_URL!$def(AMQP_URL6)!g" +#!endif +#!endif + +#!ifndef MY_AMQP_SEPTENARY_URL +#!ifdef AMQP_URL7 +#!substdef "!MY_AMQP_SEPTENARY_URL!$def(AMQP_URL7)!g" +#!endif +#!endif + +#!ifndef MY_AMQP_OCTONARY_URL +#!ifdef AMQP_URL8 +#!substdef "!MY_AMQP_OCTONARY_URL!$def(AMQP_URL8)!g" +#!endif +#!endif + +#!ifndef MY_AMQP_NONARY_URL +#!ifdef AMQP_URL9 +#!substdef "!MY_AMQP_NONARY_URL!$def(AMQP_URL9)!g" +#!endif +#!endif + +#!ifndef MY_AMQP_DENARY_URL +#!ifdef AMQP_URL10 +#!substdef "!MY_AMQP_DENARY_URL!$def(AMQP_URL10)!g" +#!endif +#!endif + + +#!endif + +# vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab diff --git a/kamailio/defs.cfg b/kamailio/defs.cfg index 028800b..1a51094 100644 --- a/kamailio/defs.cfg +++ b/kamailio/defs.cfg @@ -44,54 +44,16 @@ #!substdef "!ANTIFLOOD_CACHE_PERIOD!600!g" #!endif -#!trydef MY_AMQP_MAX_CHANNELS 25 -#!trydef MY_AMQP_CONSUMER_PROCESSES 4 -#!trydef MY_AMQP_CONSUMER_WORKERS 16 -#!trydef MY_AMQP_HEARTBEATS 5 - -#!trydef BLF_USE_SINGLE_DIALOG 1 - -#!ifndef MY_AMQP_ZONE -#!substdef "!MY_AMQP_ZONE!local!g" -#!endif - -#!ifdef PRESENCE_ROLE -#!trydef MY_AMQP_PUA_MODE 1 -#!else -#!trydef MY_AMQP_PUA_MODE 0 -#!endif +#!include_file "defs-amqp.cfg" #!ifndef MEDIA_SERVERS_HASH_SIZE #!substdef "!MEDIA_SERVERS_HASH_SIZE!256!g" #!endif -#!trydef KZ_PRESENCE_AMQP_PUBLISH 0 - -#!trydef KZ_PRESENCE_REQUEST_RESUBSCRIBE_PROBE 0 -#!trydef KZ_PRESENCE_REQUEST_PROBE 1 - #!trydef RR_FULL_LR 1 #!trydef RR_DOUBLE_RR 1 #!trydef RR_FORCE_SOCKET 1 -################################# -## 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 -#!trydef SIP_TRACE_URI "sip:127.0.0.1:9060" -#!trydef HEP_CAPTURE_ID 1 - - -#!endif - #!ifndef KZ_DISABLE_WEBSOCKETS_REGISTRAR_PORT #!trydef KZ_WEBSOCKETS_REGISTRAR_PORT 7000 #!endif @@ -102,16 +64,6 @@ #!trydef KZ_MULTI_HOMED 0 -#!ifndef KZ_DISABLE_WEBSOCKETS_REGISTRAR_PORT -#!trydef KZ_WEBSOCKETS_REGISTRAR_PORT 7000 -#!endif - -#!ifndef KZ_DISABLE_TLS_REGISTRAR_PORT -#!trydef KZ_TLS_REGISTRAR_PORT 7000 -#!endif - -#!trydef KZ_PRESENCE_FAST_PICKUP_COOKIES 1 -#!trydef KZ_PRESENCE_FAST_PICKUP_REALTIME 1 #!endif diff --git a/kamailio/presence-role.cfg b/kamailio/presence-role.cfg index 0987747..3fbdc83 100644 --- a/kamailio/presence-role.cfg +++ b/kamailio/presence-role.cfg @@ -9,6 +9,13 @@ #!trydef KZ_PRESENCE_MAX_CALL_PER_PRESENTITY 20 +#!trydef BLF_USE_SINGLE_DIALOG 1 + +#!trydef KZ_PRESENCE_AMQP_PUBLISH 0 + +#!trydef KZ_PRESENCE_REQUEST_RESUBSCRIBE_PROBE 0 +#!trydef KZ_PRESENCE_REQUEST_PROBE 1 + modparam("htable", "htable", "p=>size=32;autoexpire=3600;") modparam("htable", "htable", "first=>size=32;autoexpire=3600;initval =0;updateexpire=1;") diff --git a/kamailio/sip_trace-role.cfg b/kamailio/sip_trace-role.cfg index cbd286a..70ae4a2 100644 --- a/kamailio/sip_trace-role.cfg +++ b/kamailio/sip_trace-role.cfg @@ -1,5 +1,18 @@ +################################# +## SIP_TRACE_ROLE Defs + +#!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 +#!trydef SIP_TRACE_URI "sip:127.0.0.1:9060" +#!trydef HEP_CAPTURE_ID 1 + ############################################################## -## Kamailio siptrace settings configration examples at runtime +## Kamailio siptrace settings configuration examples at runtime ## kamcmd siptrace.status on ## kamcmd cfg.seti kazoo trace_external 0 ## kamcmd cfg.seti kazoo trace_internal 0 From 3a0134c809bfce35655160e9b7fb60a15ae86110 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 17 Jan 2019 08:07:28 +0000 Subject: [PATCH 083/209] remove default for amqp --- kamailio/local.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kamailio/local.cfg b/kamailio/local.cfg index 807b296..5cb844d 100644 --- a/kamailio/local.cfg +++ b/kamailio/local.cfg @@ -37,7 +37,7 @@ ## CHANGE "kazoo://guest:guest@127.0.0.1:5672" TO THE AMQP URL ## This should be the primary RabbitMQ server ## in the zone that this server will service. -#!substdef "!MY_AMQP_URL!amqp://guest:guest@127.0.0.1:5672!g" +# # #!substdef "!MY_AMQP_URL!amqp://guest:guest@127.0.0.1:5672!g" ################################################################################ ## WEBSOCKETS From f97b5b7907ddc2e27c0b337657753bc62f1ef470 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 17 Jan 2019 12:45:22 +0000 Subject: [PATCH 084/209] handle sip trace from one place --- kamailio/default.cfg | 13 ++++++++++--- kamailio/presence-notify.cfg | 4 ---- kamailio/presence-role.cfg | 4 ---- kamailio/sip_trace-role.cfg | 14 +++++++++++++- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/kamailio/default.cfg b/kamailio/default.cfg index 68e372a..8882b79 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -12,6 +12,7 @@ #!trydef FLT_AOR 9 #!trydef FLT_T38 10 #!trydef FLT_NATS 11 +#!trydef FLAG_LOCAL_REQUEST 12 ####### Global Parameters ######### fork = yes @@ -345,6 +346,10 @@ route route(HANDLE_OPTIONS); + #!ifdef SIP_TRACE_ROLE + route(SIP_TRACE); + #!endif + route(HANDLE_NOTIFY); #!ifdef AUTHORIZATION_ROLE @@ -654,9 +659,6 @@ branch_route[MANAGE_BRANCH] { route[RELAY] { - #!ifdef SIP_TRACE_ROLE - route(SEND_SIP_TRACE); - #!endif if (is_method("INVITE|BYE|SUBSCRIBE|UPDATE")) { if(!t_is_set("branch_route")) t_on_branch("MANAGE_BRANCH"); @@ -952,11 +954,16 @@ route[ADD_AUTHORIZATION_HEADERS] event_route[tm:local-request] { + setflag(FLAG_LOCAL_REQUEST); xlog("L_DEBUG", "$ci|local|start $pr request $rm $ou\n"); xlog("L_DEBUG", "$ci|local|source $si:$sp -> $dd:$dp\n"); xlog("L_DEBUG", "$ci|local|from $fu\n"); xlog("L_DEBUG", "$ci|local|to $tu\n"); + #!ifdef SIP_TRACE_ROLE + route(SIP_TRACE); + #!endif + #!ifdef PRESENCE_ROLE route(PRESENCE_LOCAL_NOTIFY); #!endif diff --git a/kamailio/presence-notify.cfg b/kamailio/presence-notify.cfg index 51e961d..d196a60 100644 --- a/kamailio/presence-notify.cfg +++ b/kamailio/presence-notify.cfg @@ -38,10 +38,6 @@ route[PRESENCE_LOCAL_NOTIFY] } #!endif - #!ifdef SIP_TRACE_ROLE - route(SEND_SIP_TRACE); - #!endif - } modparam("mqueue","mqueue", "name=presence_last_notity") diff --git a/kamailio/presence-role.cfg b/kamailio/presence-role.cfg index 3fbdc83..785bdc0 100644 --- a/kamailio/presence-role.cfg +++ b/kamailio/presence-role.cfg @@ -109,10 +109,6 @@ route[HANDLE_SUBSCRIBE] exit; } - #!ifdef SIP_TRACE_ROLE - route(SEND_SIP_TRACE); - #!endif - #!ifdef NAT_TRAVERSAL_ROLE route(PRESENCE_NAT); #!endif diff --git a/kamailio/sip_trace-role.cfg b/kamailio/sip_trace-role.cfg index 70ae4a2..a2768c9 100644 --- a/kamailio/sip_trace-role.cfg +++ b/kamailio/sip_trace-role.cfg @@ -4,6 +4,7 @@ #!trydef KZ_TRACE 0 #!trydef KZ_TRACE_INTERNAL 1 #!trydef KZ_TRACE_EXTERNAL 1 +#!trydef KZ_TRACE_LOCAL 1 #!trydef KZ_TRACE_INTERNAL_INCOMING 1 #!trydef KZ_TRACE_INTERNAL_OUTGOING 1 #!trydef KZ_TRACE_EXTERNAL_INCOMING 1 @@ -19,6 +20,7 @@ kazoo.trace_external = KZ_TRACE_EXTERNAL descr "activates tracing from external sources" kazoo.trace_internal = KZ_TRACE_INTERNAL descr "activates tracing from internal sources" +kazoo.trace_local = KZ_TRACE_LOCAL descr "activates tracing for local requests" 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" @@ -63,10 +65,20 @@ route[SIP_TRACE_EXTERNAL] } } -route[SEND_SIP_TRACE] +route[SIP_TRACE_LOCAL] +{ + if($sel(cfg_get.kazoo.trace_local) == 0) { + return; + } + sip_trace(); +} + +route[SIP_TRACE] { if (isflagset(FLAG_INTERNALLY_SOURCED)) { route(SIP_TRACE_INTERNAL); + } else if (isflagset(FLAG_LOCAL_REQUEST)) { + route(SIP_TRACE_LOCAL); } else { route(SIP_TRACE_EXTERNAL); } From c14c8411187865bb5c25ab908e9fdc712be81394 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 17 Jan 2019 14:23:59 +0000 Subject: [PATCH 085/209] add option to run (prepare/start) helpful for containers --- system/sbin/kazoo-kamailio | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/system/sbin/kazoo-kamailio b/system/sbin/kazoo-kamailio index df7c0f0..d682b95 100755 --- a/system/sbin/kazoo-kamailio +++ b/system/sbin/kazoo-kamailio @@ -238,6 +238,17 @@ check_config () } case "$1" in + runuser) + shift + prepare + USER="$(whoami)" + start $@ + ;; + run) + shift + prepare + start $@ + ;; prepare) prepare ;; From f22b6e5a7a4e4729d5caf57f5f5a60bba0a3d0e6 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 17 Jan 2019 17:01:37 +0000 Subject: [PATCH 086/209] fix sip trace ack credits to miconda & sergey-safarov --- kamailio/default.cfg | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/kamailio/default.cfg b/kamailio/default.cfg index 8882b79..3a2b17d 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -885,6 +885,12 @@ onsend_route { xlog("L_INFO", "$ci|log|associate traffic from $var(user_source) with media server sip:$sndto(ip):$sndto(port)\n"); $sht(associations=>$var(user_source))= "sip:" + $sndto(ip) + ":" + $sndto(port); } + + #!ifdef SIP_TRACE_ROLE + if (is_method("ACK")) { + sip_trace(); + } + #!endif xlog("L_INFO", "$ci|pass|$sndfrom(ip):$sndfrom(port) -> $sndto(ip):$sndto(port)\n"); } From ffc3381a5e682f8da32364c7dc68cd0e58441ed9 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 17 Jan 2019 17:03:34 +0000 Subject: [PATCH 087/209] check database on creation --- system/sbin/kazoo-kamailio | 1 + 1 file changed, 1 insertion(+) diff --git a/system/sbin/kazoo-kamailio b/system/sbin/kazoo-kamailio index d682b95..5c64fcd 100755 --- a/system/sbin/kazoo-kamailio +++ b/system/sbin/kazoo-kamailio @@ -160,6 +160,7 @@ convert_size() { init_database() { ${DB_SCRIPT_DIR}/create-kazoodb-sql.sh + check_database } check_database() { From 19b5e2a4cca3164d357ef3af7f6cac67d02a6274 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 17 Jan 2019 17:13:25 +0000 Subject: [PATCH 088/209] Revert "add option to run (prepare/start)" This reverts commit 156cd6a013fd40b3c475dbe480b6d67ef68c4f7c. --- system/sbin/kazoo-kamailio | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/system/sbin/kazoo-kamailio b/system/sbin/kazoo-kamailio index 5c64fcd..c793b29 100755 --- a/system/sbin/kazoo-kamailio +++ b/system/sbin/kazoo-kamailio @@ -239,17 +239,6 @@ check_config () } case "$1" in - runuser) - shift - prepare - USER="$(whoami)" - start $@ - ;; - run) - shift - prepare - start $@ - ;; prepare) prepare ;; From cb746053de4a87abfa441da21d54ab5488d6cf8e Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 17 Jan 2019 17:48:34 +0000 Subject: [PATCH 089/209] restrict ack's that need tracing credits to sergey-safarov for noticing --- kamailio/default.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kamailio/default.cfg b/kamailio/default.cfg index 3a2b17d..41498c7 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -887,7 +887,7 @@ onsend_route { } #!ifdef SIP_TRACE_ROLE - if (is_method("ACK")) { + if (is_method("ACK") && isflagset(FLAG_SIP_TRACE)) { sip_trace(); } #!endif From 060c320a9bafa3e8b90ce2138f74ddaca869dd45 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 17 Jan 2019 18:45:43 +0000 Subject: [PATCH 090/209] less noise in logs unless we want --- kamailio/presence-role.cfg | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/kamailio/presence-role.cfg b/kamailio/presence-role.cfg index 785bdc0..e8e32ce 100644 --- a/kamailio/presence-role.cfg +++ b/kamailio/presence-role.cfg @@ -16,6 +16,8 @@ #!trydef KZ_PRESENCE_REQUEST_RESUBSCRIBE_PROBE 0 #!trydef KZ_PRESENCE_REQUEST_PROBE 1 +#!trydef KZ_PRESENCE_NO_TARGETS_LOG_LEVEL L_DBG + modparam("htable", "htable", "p=>size=32;autoexpire=3600;") modparam("htable", "htable", "first=>size=32;autoexpire=3600;initval =0;updateexpire=1;") @@ -73,6 +75,7 @@ kazoo.presence_request_probe = KZ_PRESENCE_REQUEST_PROBE descr "request probe fo kazoo.presence_request_resubscribe_probe = KZ_PRESENCE_REQUEST_RESUBSCRIBE_PROBE descr "request probe for resubscriptions" kazoo.presence_ignore_status_probe_resp = KZ_PRESENCE_IGNORE_STATUS_PROBE_RESP descr "ignore online/offline probe replies" kazoo.presence_max_call_per_presentity = KZ_PRESENCE_MAX_CALL_PER_PRESENTITY descr "max number of calls per presentity" +kazoo.presence_no_targets_log_level = KZ_PRESENCE_NO_TARGETS_LOG_LEVEL descr "when a presence event is received and there no targets we can log at another level" #!include_file "presence-query.cfg" #!include_file "presence-notify.cfg" @@ -340,6 +343,7 @@ route[COUNT_SUBSCRIBERS] event_route[kazoo:consumer-event-presence-dialog-update] { + $var(presence_log_level) = $sel(cfg_get.kazoo.presence_no_targets_log_level); $var(StartRoute) = $(TV(Sn){s.replace,.,}); $var(delta_to_start) = $var(StartRoute) - $(kzE{kz.json,AMQP-Received}); xlog("L_DEBUG", "$(kzE{kz.json,Call-ID})|log|received $(kzE{kz.json,Event-Package}) update for $(kzE{kz.json,From}) state $(kzE{kz.json,State}) from $(kzE{kz.json,AMQP-Broker-Zone}) => $(kzE{kz.json,Switch-URI}) (Δ1 $(kzE{kz.json,AMQP-Elapsed-Micro}) μs , Δ2 $var(delta_to_start) μs)\n"); @@ -355,16 +359,18 @@ event_route[kazoo:consumer-event-presence-dialog-update] $var(EndRoute) = $(TV(Sn){s.replace,.,}); $var(delta_to_finish) = $var(EndRoute) - $var(StartRoute); - xlog("L_INFO", "$(kzE{kz.json,Call-ID})|log|$(kzE{kz.json,Event-Package}) update for $(kzE{kz.json,From}) state $(kzE{kz.json,State}) from $(kzE{kz.json,AMQP-Broker-Zone}) => $(kzE{kz.json,Switch-URI}) (Δ1 $(kzE{kz.json,AMQP-Elapsed-Micro}) μs , Δ2 $var(delta_to_start) μs, Δ3 $var(delta_to_finish) μs)\n"); + xlog("$var(presence_log_level)", "$(kzE{kz.json,Call-ID})|log|$(kzE{kz.json,Event-Package}) update for $(kzE{kz.json,From}) state $(kzE{kz.json,State}) from $(kzE{kz.json,AMQP-Broker-Zone}) => $(kzE{kz.json,Switch-URI}) (Δ1 $(kzE{kz.json,AMQP-Elapsed-Micro}) μs , Δ2 $var(delta_to_start) μs, Δ3 $var(delta_to_finish) μs)\n"); } event_route[kazoo:consumer-event-presence-mwi-update] { + $var(presence_log_level) = $sel(cfg_get.kazoo.presence_no_targets_log_level); xlog("L_DBG", "$(kzE{kz.json,Call-ID})|log|received message-summary update for $(kzE{kz.json,From}) ($(kzE{kz.json,AMQP-Broker-Zone}))\n"); $var(presentity) = $(kzE{kz.json,From}); $var(payload) = $kzE; route(COUNT_SUBSCRIBERS); if($xavp(watchers=>message-summary) > 0) { + $var(presence_log_level) = L_INFO; xlog("L_INFO", "$(kzE{kz.json,Call-ID})|log|publishing $(kzE{kz.json,From}) message-summary update for $xavp(watchers=>message-summary) watchers\n"); kazoo_pua_publish_mwi($kzE); pres_refresh_watchers("$(kzE{kz.json,From})", "message-summary", 1); @@ -382,12 +388,13 @@ event_route[kazoo:consumer-event-presence-mwi-update] } route(MWI_AS_PRESENCE); - xlog("L_DBG", "$(kzE{kz.json,Call-ID})|log|message-summary update for $(kzE{kz.json,From}) light should be on ? $(kzE{kz.json,Messages-Waiting}) at $(kzE{kz.json,AMQP-Received})/$var(Now)/$TS\n"); + xlog("$var(presence_log_level)", "$(kzE{kz.json,Call-ID})|log|message-summary update for $(kzE{kz.json,From}) light should be on ? $(kzE{kz.json,Messages-Waiting}) at $(kzE{kz.json,AMQP-Received})/$var(Now)/$TS\n"); } event_route[kazoo:consumer-event-presence-update] { + $var(presence_log_level) = $sel(cfg_get.kazoo.presence_no_targets_log_level); if($sel(cfg_get.kazoo.presence_ignore_status_probe_resp) == 1) { if($(kzE{kz.json,State}) == "offline" || $(kzE{kz.json,State}) == "online") { xlog("L_DEBUG", "$(kzE{kz.json,Call-ID})|log|ignoring $(kzE{kz.json,State}) state $(kzE{kz.json,Presence-ID})\n"); @@ -401,7 +408,7 @@ event_route[kazoo:consumer-event-presence-update] $var(payload) = $kzE; route(PRESENCE_UPDATE); - xlog("L_DEBUG", "$(kzE{kz.json,Call-ID})|log|$(kzE{kz.json,Event-Package}) update for $(kzE{kz.json,From}) state $(kzE{kz.json,State}) from $(kzE{kz.json,Switch-URI}) Δ at $(kzE{kz.json,AMQP-Received})/$var(Now)/$TS\n"); + xlog("$var(presence_log_level)", "$(kzE{kz.json,Call-ID})|log|$(kzE{kz.json,Event-Package}) update for $(kzE{kz.json,From}) state $(kzE{kz.json,State}) from $(kzE{kz.json,Switch-URI}) Δ at $(kzE{kz.json,AMQP-Received})/$var(Now)/$TS\n"); } route[PRESENCE_UPDATE] @@ -419,6 +426,7 @@ route[PRESENCE_UPDATE] xlog("L_WARN", "$(var(payload){kz.json,Call-ID})|log|not publishing state $(var(payload){kz.json,State}) for presentity $var(presentity) with $xavp(watchers=>self) calls, policy limit of $sel(cfg_get.kazoo.presence_max_call_per_presentity) calls per presentity \n"); } else { if($xavp(watchers=>dialog) > 0) { + $var(presence_log_level) = L_INFO; if($(var(payload){kz.json,State}) == "terminated") { xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|publishing $var(presentity) dialog update for terminated dialog\n"); } else { @@ -443,12 +451,14 @@ route[PRESENCE_UPDATE] } if($xavp(watchers=>presence) > 0) { + $var(presence_log_level) = L_INFO; xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|publishing $var(presentity) presence update for $xavp(watchers=>presence) watchers\n"); kazoo_pua_publish_presence($var(payload)); pres_refresh_watchers("$var(presentity)", "presence", 1); } else { #!ifdef PRESENCE_TRACK_ALL_PKG_PRESENCE if($(kzE{kz.json,Event-Package}) == "presence") { + $var(presence_log_level) = L_INFO; xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|saving $var(presentity) from dialog update => $var(payload)\n"); if(kazoo_pua_publish_dialoginfo($var(JObj)) != 1) { xlog("L_ERR", "$(var(payload){kz.json,Call-ID})|log|error publishing $var(presentity) dialog update => $var(payload)\n"); From 7ffe373d69de2ca4aa8f7537517a47419f0708cb Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 17 Jan 2019 20:20:28 +0000 Subject: [PATCH 091/209] change var for logging, fix msg & missing test --- kamailio/presence-role.cfg | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/kamailio/presence-role.cfg b/kamailio/presence-role.cfg index e8e32ce..9cfdf49 100644 --- a/kamailio/presence-role.cfg +++ b/kamailio/presence-role.cfg @@ -343,7 +343,7 @@ route[COUNT_SUBSCRIBERS] event_route[kazoo:consumer-event-presence-dialog-update] { - $var(presence_log_level) = $sel(cfg_get.kazoo.presence_no_targets_log_level); + $var(kz_presence_log_level) = $(sel(cfg_get.kazoo.presence_no_targets_log_level){s.int}); $var(StartRoute) = $(TV(Sn){s.replace,.,}); $var(delta_to_start) = $var(StartRoute) - $(kzE{kz.json,AMQP-Received}); xlog("L_DEBUG", "$(kzE{kz.json,Call-ID})|log|received $(kzE{kz.json,Event-Package}) update for $(kzE{kz.json,From}) state $(kzE{kz.json,State}) from $(kzE{kz.json,AMQP-Broker-Zone}) => $(kzE{kz.json,Switch-URI}) (Δ1 $(kzE{kz.json,AMQP-Elapsed-Micro}) μs , Δ2 $var(delta_to_start) μs)\n"); @@ -359,24 +359,25 @@ event_route[kazoo:consumer-event-presence-dialog-update] $var(EndRoute) = $(TV(Sn){s.replace,.,}); $var(delta_to_finish) = $var(EndRoute) - $var(StartRoute); - xlog("$var(presence_log_level)", "$(kzE{kz.json,Call-ID})|log|$(kzE{kz.json,Event-Package}) update for $(kzE{kz.json,From}) state $(kzE{kz.json,State}) from $(kzE{kz.json,AMQP-Broker-Zone}) => $(kzE{kz.json,Switch-URI}) (Δ1 $(kzE{kz.json,AMQP-Elapsed-Micro}) μs , Δ2 $var(delta_to_start) μs, Δ3 $var(delta_to_finish) μs)\n"); + xlog("$var(kz_presence_log_level)", "$(kzE{kz.json,Call-ID})|log|$(kzE{kz.json,Event-Package}) update for $(kzE{kz.json,From}) state $(kzE{kz.json,State}) from $(kzE{kz.json,AMQP-Broker-Zone}) => $(kzE{kz.json,Switch-URI}) (Δ1 $(kzE{kz.json,AMQP-Elapsed-Micro}) μs , Δ2 $var(delta_to_start) μs, Δ3 $var(delta_to_finish) μs)\n"); } event_route[kazoo:consumer-event-presence-mwi-update] { - $var(presence_log_level) = $sel(cfg_get.kazoo.presence_no_targets_log_level); + $var(kz_presence_log_level) = $(sel(cfg_get.kazoo.presence_no_targets_log_level){s.int}); xlog("L_DBG", "$(kzE{kz.json,Call-ID})|log|received message-summary update for $(kzE{kz.json,From}) ($(kzE{kz.json,AMQP-Broker-Zone}))\n"); $var(presentity) = $(kzE{kz.json,From}); $var(payload) = $kzE; route(COUNT_SUBSCRIBERS); if($xavp(watchers=>message-summary) > 0) { - $var(presence_log_level) = L_INFO; + $var(kz_presence_log_level) = L_INFO; xlog("L_INFO", "$(kzE{kz.json,Call-ID})|log|publishing $(kzE{kz.json,From}) message-summary update for $xavp(watchers=>message-summary) watchers\n"); kazoo_pua_publish_mwi($kzE); pres_refresh_watchers("$(kzE{kz.json,From})", "message-summary", 1); } else { #!ifdef PRESENCE_TRACK_ALL_PKG_MWI if($(kzE{kz.json,Event-Package}) == "message-summary") { + $var(kz_presence_log_level) = L_INFO; xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|saving $var(presentity) from mwi update => $var(payload)\n"); if(kazoo_pua_publish_mwi($kzE) != 1) { xlog("L_ERR", "$(var(payload){kz.json,Call-ID})|log|error publishing $var(presentity) mwi update => $var(payload)\n"); @@ -388,13 +389,13 @@ event_route[kazoo:consumer-event-presence-mwi-update] } route(MWI_AS_PRESENCE); - xlog("$var(presence_log_level)", "$(kzE{kz.json,Call-ID})|log|message-summary update for $(kzE{kz.json,From}) light should be on ? $(kzE{kz.json,Messages-Waiting}) at $(kzE{kz.json,AMQP-Received})/$var(Now)/$TS\n"); + xlog("$var(kz_presence_log_level)", "$(kzE{kz.json,Call-ID})|log|message-summary update for $(kzE{kz.json,From}) light should be on ? $(kzE{kz.json,Messages-Waiting}) at $(kzE{kz.json,AMQP-Received})/$var(Now)/$TS\n"); } event_route[kazoo:consumer-event-presence-update] { - $var(presence_log_level) = $sel(cfg_get.kazoo.presence_no_targets_log_level); + $var(kz_presence_log_level) = $(sel(cfg_get.kazoo.presence_no_targets_log_level){s.int}); if($sel(cfg_get.kazoo.presence_ignore_status_probe_resp) == 1) { if($(kzE{kz.json,State}) == "offline" || $(kzE{kz.json,State}) == "online") { xlog("L_DEBUG", "$(kzE{kz.json,Call-ID})|log|ignoring $(kzE{kz.json,State}) state $(kzE{kz.json,Presence-ID})\n"); @@ -408,7 +409,7 @@ event_route[kazoo:consumer-event-presence-update] $var(payload) = $kzE; route(PRESENCE_UPDATE); - xlog("$var(presence_log_level)", "$(kzE{kz.json,Call-ID})|log|$(kzE{kz.json,Event-Package}) update for $(kzE{kz.json,From}) state $(kzE{kz.json,State}) from $(kzE{kz.json,Switch-URI}) Δ at $(kzE{kz.json,AMQP-Received})/$var(Now)/$TS\n"); + xlog("$var(kz_presence_log_level)", "$(kzE{kz.json,Call-ID})|log|$(kzE{kz.json,Event-Package}) update for $(kzE{kz.json,From}) state $(kzE{kz.json,State}) from $(kzE{kz.json,Switch-URI}) Δ at $(kzE{kz.json,AMQP-Received})/$var(Now)/$TS\n"); } route[PRESENCE_UPDATE] @@ -426,7 +427,7 @@ route[PRESENCE_UPDATE] xlog("L_WARN", "$(var(payload){kz.json,Call-ID})|log|not publishing state $(var(payload){kz.json,State}) for presentity $var(presentity) with $xavp(watchers=>self) calls, policy limit of $sel(cfg_get.kazoo.presence_max_call_per_presentity) calls per presentity \n"); } else { if($xavp(watchers=>dialog) > 0) { - $var(presence_log_level) = L_INFO; + $var(kz_presence_log_level) = L_INFO; if($(var(payload){kz.json,State}) == "terminated") { xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|publishing $var(presentity) dialog update for terminated dialog\n"); } else { @@ -440,6 +441,7 @@ route[PRESENCE_UPDATE] } else { #!ifdef PRESENCE_TRACK_ALL_PKG_DIALOG if($(kzE{kz.json,Event-Package}) == "dialog") { + $var(kz_presence_log_level) = L_INFO; xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|saving $var(presentity) from dialog update => $var(payload)\n"); if(kazoo_pua_publish_dialoginfo($var(JObj)) != 1) { xlog("L_ERR", "$(var(payload){kz.json,Call-ID})|log|error publishing $var(presentity) dialog update => $var(payload)\n"); @@ -451,17 +453,17 @@ route[PRESENCE_UPDATE] } if($xavp(watchers=>presence) > 0) { - $var(presence_log_level) = L_INFO; + $var(kz_presence_log_level) = L_INFO; xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|publishing $var(presentity) presence update for $xavp(watchers=>presence) watchers\n"); kazoo_pua_publish_presence($var(payload)); pres_refresh_watchers("$var(presentity)", "presence", 1); } else { #!ifdef PRESENCE_TRACK_ALL_PKG_PRESENCE if($(kzE{kz.json,Event-Package}) == "presence") { - $var(presence_log_level) = L_INFO; - xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|saving $var(presentity) from dialog update => $var(payload)\n"); + $var(kz_presence_log_level) = L_INFO; + xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|saving $var(presentity) from presence update => $var(payload)\n"); if(kazoo_pua_publish_dialoginfo($var(JObj)) != 1) { - xlog("L_ERR", "$(var(payload){kz.json,Call-ID})|log|error publishing $var(presentity) dialog update => $var(payload)\n"); + xlog("L_ERR", "$(var(payload){kz.json,Call-ID})|log|error publishing $var(presentity) presence update => $var(payload)\n"); } } #!else From 7a725589d2ea7c5e91661abcb57529cdb8464a9e Mon Sep 17 00:00:00 2001 From: lazedo Date: Fri, 18 Jan 2019 12:30:59 +0000 Subject: [PATCH 092/209] allow override of missing expires on REGISTER --- kamailio/registrar-role.cfg | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/kamailio/registrar-role.cfg b/kamailio/registrar-role.cfg index d14f137..c5ef230 100644 --- a/kamailio/registrar-role.cfg +++ b/kamailio/registrar-role.cfg @@ -4,6 +4,7 @@ #!trydef REGISTRAR_MAX_EXPIRES 3600 #!trydef REGISTRAR_DEFAULT_EXPIRES 600 #!trydef REGISTRAR_ERROR_MIN_EXPIRES 1 +#!trydef REGISTRAR_ERROR_MISSING_EXPIRES 1 #!trydef REGISTRAR_CONTACT_MAX_SIZE 2048 #!trydef REGISTRAR_QUERY_TIMEOUT_MS 2500 @@ -73,6 +74,7 @@ modparam("registrar", "xavp_rcd", "ulrcd") modparam("registrar", "contact_max_size", REGISTRAR_CONTACT_MAX_SIZE) kazoo.registrar_error_min_expires = REGISTRAR_ERROR_MIN_EXPIRES descr "send error when UAS sends expires < min-expires" +kazoo.registrar_error_missing_expires = REGISTRAR_ERROR_MISSING_EXPIRES descr "send error when UAS do not send expires header" ##### handle expired registrations realtime params ##### kazoo.registrar_handle_expired_tcp = REGISTRAR_HANDLE_EXPIRED_TCP descr "handles expired tcp registrations" @@ -175,9 +177,7 @@ route[ATTEMPT_AUTHORIZATION] t_drop(); } - if($sel(cfg_get.kazoo.registrar_error_min_expires) == 1) { - route(REGISTRAR_BOUNDS); - } + route(REGISTRAR_BOUNDS); $var(auth) = pv_auth_check("$fd", "$uuid(g)", "0", "0"); if($var(auth) != -2) { @@ -396,16 +396,24 @@ route[REGISTRAR_BOUNDS] } else if($(sel(contact){tobody.params}{param.value,expires}) != "") { $var(expires) = $(sel(contact){tobody.params}{param.value,expires}{s.int}); } else { - send_reply("400", "Missing Expires"); - exit; + if($sel(cfg_get.kazoo.registrar_error_missing_expires) == 1) { + xlog("L_WARNING", "$ci|end|missing expires registering $Au from IP $si:$sp\n"); + send_reply("400", "Missing Expires"); + exit; + } else { + xlog("L_WARNING", "$ci|end|allowing missing expires registering $Au from IP $si:$sp\n"); + } } if($var(expires) != 0) { - if($var(expires) < REGISTRAR_MIN_EXPIRES) { - $var(expires) = REGISTRAR_MIN_EXPIRES; - append_to_reply("Min-Expires: $var(expires)\r\n"); - send_reply("423", "Interval Too Brief"); - exit; + if($sel(cfg_get.kazoo.registrar_error_min_expires) == 1) { + if($var(expires) < REGISTRAR_MIN_EXPIRES) { + $var(expires) = REGISTRAR_MIN_EXPIRES; + xlog("L_WARNING", "$ci|end|expires $var(expires) too brief registering $Au from IP $si:$sp\n"); + append_to_reply("Min-Expires: $var(expires)\r\n"); + send_reply("423", "Interval Too Brief"); + exit; + } } } From e4511af0e2a879d50c73b8145710de20b83ab397 Mon Sep 17 00:00:00 2001 From: lazedo Date: Fri, 18 Jan 2019 12:58:48 +0000 Subject: [PATCH 093/209] change log level in nodes * i'm not warning you, i'm letting you know --- kamailio/nodes-role.cfg | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/kamailio/nodes-role.cfg b/kamailio/nodes-role.cfg index 76f7598..27493ef 100644 --- a/kamailio/nodes-role.cfg +++ b/kamailio/nodes-role.cfg @@ -60,11 +60,11 @@ event_route[kazoo:consumer-event-nodes-advertise] { $var(count) = $shtinc(nodes=>$(kzE{kz.json,Node})::count); if($var(count) == 0) { - xlog("L_WARNING", "$(kzE{kz.json,Msg-ID})|nodes|heartbeat for reconnected node $(kzE{kz.json,Node})\n"); + xlog("L_NOTICE", "$(kzE{kz.json,Msg-ID})|nodes|heartbeat for reconnected node $(kzE{kz.json,Node})\n"); $var(count) = $shtinc(nodes=>$(kzE{kz.json,Node})::count); } else { if($var(count) == 1) { - xlog("L_WARNING", "$(kzE{kz.json,Msg-ID})|nodes|heartbeat from new node $(kzE{kz.json,Node})\n"); + xlog("L_NOTICE", "$(kzE{kz.json,Msg-ID})|nodes|heartbeat from new node $(kzE{kz.json,Node})\n"); } else { xlog("L_DEBUG", "$(kzE{kz.json,Msg-ID})|nodes|heartbeat from existing node $(kzE{kz.json,Node})\n"); } @@ -171,7 +171,7 @@ event_route[htable:expired:media] route[MEDIA_SERVER_UP] { - xlog("L_WARNING", "nodes|media|$var(Node) reported new media server $var(MediaUrl) in zone $var(Zone)\n"); + xlog("L_NOTICE", "nodes|media|$var(Node) reported new media server $var(MediaUrl) in zone $var(Zone)\n"); #!ifdef DISPATCHER_ROLE route(DISPATCHER_CHECK_MEDIA_SERVER); @@ -195,7 +195,7 @@ route[MEDIA_SERVER_DOWN] route[MEDIA_SERVER_RESTART] { - xlog("L_WARNING", "htable|media|media server $var(MediaUrl) restarted in zone $var(Zone)\n"); + xlog("L_NOTICE", "htable|media|media server $var(MediaUrl) restarted in zone $var(Zone)\n"); #!ifdef PRESENCE_ROLE route(RESET_PUBLISHER); From cffef8dfba0f089d0ac3afd62fa1006ae7b8fdb6 Mon Sep 17 00:00:00 2001 From: lazedo Date: Fri, 18 Jan 2019 14:09:17 +0000 Subject: [PATCH 094/209] fix log message for min-expires in registrar --- kamailio/registrar-role.cfg | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/kamailio/registrar-role.cfg b/kamailio/registrar-role.cfg index c5ef230..be5780c 100644 --- a/kamailio/registrar-role.cfg +++ b/kamailio/registrar-role.cfg @@ -408,9 +408,8 @@ route[REGISTRAR_BOUNDS] if($var(expires) != 0) { if($sel(cfg_get.kazoo.registrar_error_min_expires) == 1) { if($var(expires) < REGISTRAR_MIN_EXPIRES) { - $var(expires) = REGISTRAR_MIN_EXPIRES; - xlog("L_WARNING", "$ci|end|expires $var(expires) too brief registering $Au from IP $si:$sp\n"); - append_to_reply("Min-Expires: $var(expires)\r\n"); + xlog("L_WARNING", "$ci|end|expires $var(expires) too brief (configured $def(REGISTRAR_MIN_EXPIRES)) registering $Au from IP $si:$sp\n"); + append_to_reply("Min-Expires: $def(REGISTRAR_MIN_EXPIRES)\r\n"); send_reply("423", "Interval Too Brief"); exit; } From 52b7c58d84122ac031d34bc398a62004ee7fb000 Mon Sep 17 00:00:00 2001 From: lazedo Date: Fri, 18 Jan 2019 15:17:33 +0000 Subject: [PATCH 095/209] log levels for dispatcher --- kamailio/dispatcher-role.cfg | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kamailio/dispatcher-role.cfg b/kamailio/dispatcher-role.cfg index 14b9ecc..2e9d0ec 100644 --- a/kamailio/dispatcher-role.cfg +++ b/kamailio/dispatcher-role.cfg @@ -241,12 +241,12 @@ route[DISPATCHER_NEXT_ROUTE] event_route[dispatcher:dst-down] { - xlog("L_ERR", "Destination down: $ru\n"); + xlog("L_WARNING", "Destination down: $ru\n"); } event_route[dispatcher:dst-up] { - xlog("L_WARNING", "Destination up: $ru\n"); + xlog("L_NOTICE", "Destination up: $ru\n"); } @@ -272,7 +272,7 @@ route[DISPATCHER_CHECK_MEDIA_SERVER] route[DISPATCHER_RELOAD] { if($shv(dispatcher_reload) == 1) { - xlog("L_WARNING", "reloading dispatcher table\n"); + xlog("L_NOTICE", "reloading dispatcher table\n"); ds_reload(); }; $shv(dispatcher_reload) = 0; From c168a3508a9680e2d49b9b20fcf956b6c22d4304 Mon Sep 17 00:00:00 2001 From: lazedo Date: Fri, 18 Jan 2019 17:52:56 +0000 Subject: [PATCH 096/209] missing deltas in mwi / presence --- kamailio/presence-role.cfg | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/kamailio/presence-role.cfg b/kamailio/presence-role.cfg index 9cfdf49..2481d3f 100644 --- a/kamailio/presence-role.cfg +++ b/kamailio/presence-role.cfg @@ -365,6 +365,8 @@ event_route[kazoo:consumer-event-presence-dialog-update] event_route[kazoo:consumer-event-presence-mwi-update] { $var(kz_presence_log_level) = $(sel(cfg_get.kazoo.presence_no_targets_log_level){s.int}); + $var(StartRoute) = $(TV(Sn){s.replace,.,}); + $var(delta_to_start) = $var(StartRoute) - $(kzE{kz.json,AMQP-Received}); xlog("L_DBG", "$(kzE{kz.json,Call-ID})|log|received message-summary update for $(kzE{kz.json,From}) ($(kzE{kz.json,AMQP-Broker-Zone}))\n"); $var(presentity) = $(kzE{kz.json,From}); $var(payload) = $kzE; @@ -389,13 +391,23 @@ event_route[kazoo:consumer-event-presence-mwi-update] } route(MWI_AS_PRESENCE); - xlog("$var(kz_presence_log_level)", "$(kzE{kz.json,Call-ID})|log|message-summary update for $(kzE{kz.json,From}) light should be on ? $(kzE{kz.json,Messages-Waiting}) at $(kzE{kz.json,AMQP-Received})/$var(Now)/$TS\n"); + $var(mwi_state) = "ON"; + if($(kzE{kz.json,Messages-Waiting}) == "no") { + $var(mwi_state) = "OFF"; + } + + $var(EndRoute) = $(TV(Sn){s.replace,.,}); + $var(delta_to_finish) = $var(EndRoute) - $var(StartRoute); + + xlog("$var(kz_presence_log_level)", "$(kzE{kz.json,Call-ID})|log|message-summary update for $(kzE{kz.json,From}) light should be $var(mwi_state) (Δ1 $(kzE{kz.json,AMQP-Elapsed-Micro}) μs , Δ2 $var(delta_to_start) μs, Δ3 $var(delta_to_finish) μs)\n"); } event_route[kazoo:consumer-event-presence-update] { $var(kz_presence_log_level) = $(sel(cfg_get.kazoo.presence_no_targets_log_level){s.int}); + $var(StartRoute) = $(TV(Sn){s.replace,.,}); + $var(delta_to_start) = $var(StartRoute) - $(kzE{kz.json,AMQP-Received}); if($sel(cfg_get.kazoo.presence_ignore_status_probe_resp) == 1) { if($(kzE{kz.json,State}) == "offline" || $(kzE{kz.json,State}) == "online") { xlog("L_DEBUG", "$(kzE{kz.json,Call-ID})|log|ignoring $(kzE{kz.json,State}) state $(kzE{kz.json,Presence-ID})\n"); @@ -409,7 +421,10 @@ event_route[kazoo:consumer-event-presence-update] $var(payload) = $kzE; route(PRESENCE_UPDATE); - xlog("$var(kz_presence_log_level)", "$(kzE{kz.json,Call-ID})|log|$(kzE{kz.json,Event-Package}) update for $(kzE{kz.json,From}) state $(kzE{kz.json,State}) from $(kzE{kz.json,Switch-URI}) Δ at $(kzE{kz.json,AMQP-Received})/$var(Now)/$TS\n"); + $var(EndRoute) = $(TV(Sn){s.replace,.,}); + $var(delta_to_finish) = $var(EndRoute) - $var(StartRoute); + + xlog("$var(kz_presence_log_level)", "$(kzE{kz.json,Call-ID})|log|$(kzE{kz.json,Event-Package}) update for $(kzE{kz.json,From}) state $(kzE{kz.json,State}) from $(kzE{kz.json,AMQP-Broker-Zone}) => $(kzE{kz.json,Switch-URI}) (Δ1 $(kzE{kz.json,AMQP-Elapsed-Micro}) μs , Δ2 $var(delta_to_start) μs, Δ3 $var(delta_to_finish) μs)\n"); } route[PRESENCE_UPDATE] From e10084ecfd59804a46233ef0a2b379874f97e14f Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 24 Jan 2019 15:50:17 +0000 Subject: [PATCH 097/209] handle directory flush with cache-only --- kamailio/registrar-role.cfg | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kamailio/registrar-role.cfg b/kamailio/registrar-role.cfg index be5780c..912ed4a 100644 --- a/kamailio/registrar-role.cfg +++ b/kamailio/registrar-role.cfg @@ -355,6 +355,10 @@ event_route[kazoo:consumer-event-directory-reg-flush] $sht(auth_cache=>$var(user)) = $null; } + if( $(kzE{kz.json,Cache-Only}) == "true") { + return; + } + if(reg_fetch_contacts("location", "sip:$var(user)", "caller")) { $var(i) = 0; while($var(i) < $(ulc(caller=>count))) { From ccb7d4300bf31640a38abcdb02619f4d0d77fc1b Mon Sep 17 00:00:00 2001 From: lazedo Date: Mon, 28 Jan 2019 21:41:57 +0000 Subject: [PATCH 098/209] add missing defaults --- kamailio/defs-amqp.cfg | 2 ++ system/sbin/kazoo-kamailio | 1 + 2 files changed, 3 insertions(+) diff --git a/kamailio/defs-amqp.cfg b/kamailio/defs-amqp.cfg index f103111..fa116c9 100644 --- a/kamailio/defs-amqp.cfg +++ b/kamailio/defs-amqp.cfg @@ -23,6 +23,8 @@ #!ifndef MY_AMQP_URL #!ifdef AMQP_URL1 #!substdef "!MY_AMQP_URL!$def(AMQP_URL1)!g" +#!else +#!substdef "!MY_AMQP_URL!amqp://guest:guest@127.0.0.1:5672!g" #!endif #!endif diff --git a/system/sbin/kazoo-kamailio b/system/sbin/kazoo-kamailio index c793b29..62c4bab 100755 --- a/system/sbin/kazoo-kamailio +++ b/system/sbin/kazoo-kamailio @@ -22,6 +22,7 @@ export HOME=${KAMAILIO_HOME:-/var/run/kamailio} RAM_DISK_SIZE=${RAM_DISK_SIZE:-256m} RAM_DISK_FREE_SIZE_PERC=${RAM_DISK_FREE_SIZE:-30} RAM_DISK_ENABLED=${RAM_DISK_ENABLED:-false} +EXTRA_OPTIONS=${EXTRA_OPTIONS:-"-x tlsf -w /tmp"} SHM_MEMORY=$((`echo $SHM_MEMORY | sed -e 's/[^0-9]//g'`)) PKG_MEMORY=$((`echo $PKG_MEMORY | sed -e 's/[^0-9]//g'`)) From af4a8470307b1915a342deba0e541bdbbc1a4d5e Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 29 Jan 2019 00:17:29 +0000 Subject: [PATCH 099/209] defaults for ip address --- kamailio/defs.cfg | 4 ++++ system/sbin/kazoo-kamailio | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/kamailio/defs.cfg b/kamailio/defs.cfg index 1a51094..e9e6b3a 100644 --- a/kamailio/defs.cfg +++ b/kamailio/defs.cfg @@ -10,8 +10,12 @@ #!endif #!ifndef MY_IP_ADDRESS +#!ifdef MY_LOCAL_IP +#!substdef "!MY_IP_ADDRESS!$def(MY_LOCAL_IP)!g" +#!else #!substdef "!MY_IP_ADDRESS!$HN(i)!g" #!endif +#!endif #!ifndef WEBSOCKET_NO_ORIGIN_RESTRICTION #!ifndef MY_WEBSOCKET_DOMAIN diff --git a/system/sbin/kazoo-kamailio b/system/sbin/kazoo-kamailio index 62c4bab..2fefde2 100755 --- a/system/sbin/kazoo-kamailio +++ b/system/sbin/kazoo-kamailio @@ -24,6 +24,16 @@ RAM_DISK_FREE_SIZE_PERC=${RAM_DISK_FREE_SIZE:-30} RAM_DISK_ENABLED=${RAM_DISK_ENABLED:-false} EXTRA_OPTIONS=${EXTRA_OPTIONS:-"-x tlsf -w /tmp"} +MY_LOCAL_IP=$(ip route get 8.8.8.8 2> /dev/null | awk '{print "\""$NF"\""; exit}') +if [[ ! -z ${MY_LOCAL_IP} ]]; then + EXTRA_OPTIONS+=" -A MY_LOCAL_IP=${MY_LOCAL_IP}" +fi + +MY_PUBLIC_IP=$(dig @ns1.google.com TXT o-o.myaddr.l.google.com +short -4 2> /dev/null) +if [[ ! -z ${MY_PUBLIC_IP} ]]; then + EXTRA_OPTIONS+=" -A MY_PUBLIC_IP=${MY_PUBLIC_IP}" +fi + SHM_MEMORY=$((`echo $SHM_MEMORY | sed -e 's/[^0-9]//g'`)) PKG_MEMORY=$((`echo $PKG_MEMORY | sed -e 's/[^0-9]//g'`)) [ $SHM_MEMORY -le 0 ] && SHM_MEMORY=64 From 47754e6b65d2532ca2fea3ff4b7799a2de8f1bf1 Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 29 Jan 2019 12:52:09 +0000 Subject: [PATCH 100/209] optional REGISTRAR_CHECK_AMQP_AVAILABILITY --- kamailio/registrar-role.cfg | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/kamailio/registrar-role.cfg b/kamailio/registrar-role.cfg index 912ed4a..a3912ee 100644 --- a/kamailio/registrar-role.cfg +++ b/kamailio/registrar-role.cfg @@ -20,6 +20,8 @@ #!trydef REGISTRAR_FORCE_QUERY 0 #!trydef REGISTRAR_FORCE_FAILOVER 0 +#!trydef REGISTRAR_CHECK_AMQP_AVAILABILITY 1 + ######## Generic Hash Table container in shared memory ######## modparam("htable", "htable", "auth_cache=>size=16;autoexpire=7200;") @@ -86,6 +88,8 @@ kazoo.registrar_query_timeout_ms = REGISTRAR_QUERY_TIMEOUT_MS descr "timeout wai kazoo.registrar_failover = REGISTRAR_FORCE_FAILOVER descr "force failover if 1" kazoo.registrar_force_query = REGISTRAR_FORCE_QUERY descr "force query if 1" +kazoo.registrar_check_amqp_availability = REGISTRAR_CHECK_AMQP_AVAILABILITY descr "checks if amqp connection is available before querying registrar" + ####### Registrar Logic ######## route[HANDLE_REGISTER] @@ -167,9 +171,11 @@ route[ATTEMPT_AUTHORIZATION] drop; } - if($xavp(amqpc=>default::MY_AMQP_ZONE) == 0) { - xlog("L_INFO", "$ci|log|register|no amqp connection available for default worker in zone MY_AMQP_ZONE\n"); - t_drop(); + if($sel(cfg_get.kazoo.registrar_check_amqp_availability) == 1) { + if($xavp(amqpc=>default::MY_AMQP_ZONE) == 0) { + xlog("L_INFO", "$ci|log|register|no amqp connection available for default worker in zone MY_AMQP_ZONE\n"); + t_drop(); + } } if($sel(cfg_get.kazoo.registrar_failover) == 1) { From 614aebc2b591af35eb7b20cbbf02f0f174267442 Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 6 Feb 2019 04:38:45 +0000 Subject: [PATCH 101/209] allow check for media internal sip addresses --- kamailio/dispatcher-role.cfg | 25 +++++++++++++++++++++++-- kamailio/nodes-role.cfg | 1 + 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/kamailio/dispatcher-role.cfg b/kamailio/dispatcher-role.cfg index 2e9d0ec..cc28e79 100644 --- a/kamailio/dispatcher-role.cfg +++ b/kamailio/dispatcher-role.cfg @@ -3,6 +3,8 @@ modparam("htable", "htable", "failover=>size=16;autoexpire=120") #!trydef KZ_DISPATCHER_PROBE_MODE 1 #!trydef DISPATCHER_ADD_SERVERS 1 +#!trydef DISPATCHER_ADD_SECONDARY_IP 1 +#!trydef DISPATCHER_SECONDARY_IP_GROUP 3 #!trydef DISPATCHER_ALG 0 #!trydef KZ_DISPATCHER_ADD_FLAGS 10 #!trydef KZ_DISPATCHER_PRIMARY_GROUP 1 @@ -18,6 +20,9 @@ modparam("htable", "htable", "failover=>size=16;autoexpire=120") #!trydef KZ_DISPATCHER_REGISTRAR_SECONDARY_GROUP 21 kazoo.dispatcher_auto_add = DISPATCHER_ADD_SERVERS descr "adds media servers reported by ecallmgr" +kazoo.dispatcher_add_secondary_ip = DISPATCHER_ADD_SECONDARY_IP descr "adds internal ip from media servers reported by ecallmgr" +kazoo.dispatcher_add_secondary_ip_group = DISPATCHER_SECONDARY_IP_GROUP descr "sets the group where to add internal ip from media servers reported by ecallmgr" + kazoo.dispatcher_algorithm = DISPATCHER_ALG descr "dispatcher algorithm to use" kazoo.dispatcher_primary_group = KZ_DISPATCHER_PRIMARY_GROUP descr "dispatcher primary group" kazoo.dispatcher_secondary_group = KZ_DISPATCHER_SECONDARY_GROUP descr "dispatcher secondary group" @@ -252,6 +257,7 @@ event_route[dispatcher:dst-up] route[DISPATCHER_CHECK_MEDIA_SERVER] { + $var(check_media_server_ret) = 0; if($sel(cfg_get.kazoo.dispatcher_auto_add) == 1) { $var(SetId) = 1; if($var(Zone) != "MY_AMQP_ZONE") { @@ -263,10 +269,25 @@ route[DISPATCHER_CHECK_MEDIA_SERVER] sql_query("exec", "KZQ_CHECK_MEDIA_SERVER_INSERT"); if($sqlrows(exec) > 0) { $shv(dispatcher_reload) = 1; - return 1; + $var(check_media_server_ret) = 1; + } + + if($sel(cfg_get.kazoo.dispatcher_add_secondary_ip) == 1) { + if($var(MediaIP) != "" && $var(MediaIP) != $(var(MediaUrl){uri.host})) { + $var(MediaUrlBack) = $var(MediaUrl); + $var(MediaUrl) = $_s($(var(MediaUrlBack){uri.scheme}):$var(MediaIP):$(var(MediaUrlBack){uri.port})); + $var(SetId) = $sel(cfg_get.kazoo.dispatcher_add_secondary_ip_group); + sql_query("exec", "KZQ_CHECK_MEDIA_SERVER_INSERT"); + if($sqlrows(exec) > 0) { + $shv(dispatcher_reload) = 1; + $var(check_media_server_ret) = 1; + } + $var(MediaUrl) = $var(MediaUrlBack); + } } + } - return 0; + return $var(check_media_server_ret); } route[DISPATCHER_RELOAD] diff --git a/kamailio/nodes-role.cfg b/kamailio/nodes-role.cfg index 27493ef..3b1ecdd 100644 --- a/kamailio/nodes-role.cfg +++ b/kamailio/nodes-role.cfg @@ -139,6 +139,7 @@ route[CHECK_MEDIA_SERVERS] $var(MediaRawUrl) = $(var(Payload){kz.json,Media-Servers.$var(MediaKey).Interfaces.$var(MediaProfile).URL}); $var(MediaUrl) = $(var(MediaRawUrl){re.subst,/^sip:(.*)@(.*)/sip:\2/}); $var(MediaInstanceUUID) = $(var(Payload){kz.json,Media-Servers.$var(MediaKey).Instance-UUID}); + $var(MediaIP) = $(var(Payload){kz.json,Media-Servers.$var(MediaKey).Interfaces.$var(MediaProfile).SIP-IP}); if($shtinc(media=>$var(MediaUrl)::count) == 1) { $sht(media=>$var(MediaUrl)::zone) = $var(Zone); $shtex(media=>$var(MediaUrl)::zone) = 0; From 808449c92d8423e62c39e6155850cf977f52d36e Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 12 Feb 2019 11:21:53 +0000 Subject: [PATCH 102/209] move AOR back to default --- kamailio/default.cfg | 31 ++++++++++++++++++++++++++++++- kamailio/registrar-role.cfg | 28 ---------------------------- 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/kamailio/default.cfg b/kamailio/default.cfg index 41498c7..2b20b52 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -687,7 +687,7 @@ route[INTERNAL_TO_EXTERNAL_RELAY] #!endif #!ifdef REGISTRAR_ROLE - route(REGISTRAR_ROUTE_TO_AOR); + route(ROUTE_TO_AOR); #!endif remove_hf_re("^X-.*"); @@ -895,6 +895,35 @@ onsend_route { xlog("L_INFO", "$ci|pass|$sndfrom(ip):$sndfrom(port) -> $sndto(ip):$sndto(port)\n"); } +route[ROUTE_TO_AOR] +{ + if ($hdr(X-KAZOO-AOR) == $null) { + return; + } + + xlog("L_INFO", "$ci|log|using AOR $hdr(X-KAZOO-AOR)\n"); + if ($hdr(X-KAZOO-INVITE-FORMAT) == "contact") { + if(lookup("location", "$hdr(X-KAZOO-AOR)") > 0){ + xlog("L_INFO", "$ci|end|routing to contact $ru\n"); + handle_ruri_alias(); + } else { + xlog("L_INFO", "$ci|end|lookup for AOR $hdr(X-KAZOO-AOR) failed\n"); + sl_send_reply("410", "Not registered"); + exit; + } + } else if (reg_fetch_contacts("location", "$hdr(X-KAZOO-AOR)", "callee")) { + $du = $(ulc(callee=>received)); + $fs = $(ulc(callee=>socket)); + xlog("L_INFO", "$ci|log|routing $hdr(X-KAZOO-AOR) to $du via $fs\n"); + + } else { + xlog("L_INFO", "$ci|end|user is not registered\n"); + sl_send_reply("410", "Not registered"); + exit; + } +} + + #!ifdef REGISTRAR_ROLE #!ifdef WITH_AUTH_TOKEN diff --git a/kamailio/registrar-role.cfg b/kamailio/registrar-role.cfg index a3912ee..1c7730e 100644 --- a/kamailio/registrar-role.cfg +++ b/kamailio/registrar-role.cfg @@ -493,32 +493,4 @@ event_route[usrloc:contact-expired] #!include_file "registrar-sync-role.cfg" #!endif -route[REGISTRAR_ROUTE_TO_AOR] -{ - if ($hdr(X-KAZOO-AOR) == $null) { - return(); - } - - xlog("L_INFO", "$ci|log|using AOR $hdr(X-KAZOO-AOR)\n"); - setflag(FLT_AOR); - if ($hdr(X-KAZOO-INVITE-FORMAT) == "contact") { - if(lookup("location", "$hdr(X-KAZOO-AOR)") > 0){ - xlog("L_INFO", "$ci|end|routing to contact $ru\n"); - handle_ruri_alias(); - } else { - xlog("L_INFO", "$ci|end|lookup for AOR $hdr(X-KAZOO-AOR) failed\n"); - sl_send_reply("410", "Not registered"); - exit; - } - } else if (reg_fetch_contacts("location", "$hdr(X-KAZOO-AOR)", "callee")) { - $du = $(ulc(callee=>received)); - $fs = $(ulc(callee=>socket)); - xlog("L_INFO", "$ci|log|routing $hdr(X-KAZOO-AOR) to $du via $fs\n"); - } else { - xlog("L_INFO", "$ci|end|user is not registered\n"); - sl_send_reply("410", "Not registered"); - exit; - } -} - # vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab From 44a88189a5f9f82d6dff8d22922e49485988b593 Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 12 Feb 2019 11:22:17 +0000 Subject: [PATCH 103/209] buffer size & slots --- kamailio/default.cfg | 4 +++- kamailio/defs.cfg | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/kamailio/default.cfg b/kamailio/default.cfg index 2b20b52..8998359 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -25,7 +25,9 @@ mlock_pages = yes phone2tel = 1 max_while_loops = MAX_WHILE_LOOPS -pv_buffer_size=65536 +pv_buffer_size = PV_BUFFER_SIZE +pv_buffer_slots = PV_BUFFER_SLOTS + mem_join=1 ####### Logging Parameters ######### diff --git a/kamailio/defs.cfg b/kamailio/defs.cfg index e9e6b3a..6118805 100644 --- a/kamailio/defs.cfg +++ b/kamailio/defs.cfg @@ -25,6 +25,9 @@ #!trydef KAZOO_LOG_LEVEL L_INFO +#!trydef PV_BUFFER_SIZE 8192 +#!trydef PV_BUFFER_SLOTS 20 + #!ifndef KAMAILIO_DBMS #!substdef "!KAMAILIO_DBMS!kazoo!g" #!endif From ff7116c984168136df1087f56ad2a02fe54a8a04 Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 12 Feb 2019 11:52:00 +0000 Subject: [PATCH 104/209] 16kb default for buffer size --- kamailio/defs.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kamailio/defs.cfg b/kamailio/defs.cfg index 6118805..09eefc3 100644 --- a/kamailio/defs.cfg +++ b/kamailio/defs.cfg @@ -25,7 +25,7 @@ #!trydef KAZOO_LOG_LEVEL L_INFO -#!trydef PV_BUFFER_SIZE 8192 +#!trydef PV_BUFFER_SIZE 16384 #!trydef PV_BUFFER_SLOTS 20 #!ifndef KAMAILIO_DBMS From d2bcd29b6dd77b5ba8c4dba3ba8a529136ba17d9 Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 12 Feb 2019 20:08:20 +0000 Subject: [PATCH 105/209] fix nat sdp handling --- kamailio/nat-traversal-role.cfg | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/kamailio/nat-traversal-role.cfg b/kamailio/nat-traversal-role.cfg index b1dffd2..7c64f84 100644 --- a/kamailio/nat-traversal-role.cfg +++ b/kamailio/nat-traversal-role.cfg @@ -13,7 +13,7 @@ modparam("nathelper", "sipping_from", "sip:sipcheck@MY_HOSTNAME") #!endif #!trydef KZ_NAT_FIX_SDP_REQUEST 1 -#!trydef KZ_NAT_FIX_SDP_REPLY 0 +#!trydef KZ_NAT_FIX_SDP_REPLY 1 #!trydef KZ_NAT_SDP_TEST 8 #!trydef KZ_NAT_SDP_FIX 10 @@ -71,6 +71,12 @@ route[NAT_DETECT] route[NAT_MANAGE] { + if(is_reply() && $sel(cfg_get.kazoo.nat_fix_sdp_reply) == 1) { + if (has_body("application/sdp") && nat_uac_test(KZ_NAT_SDP_TEST)) { + fix_nated_sdp(KZ_NAT_SDP_FIX); + } + } + if ( is_request() && isflagset(FLAG_INTERNALLY_SOURCED)) { setbflag(FLB_NATB); } @@ -91,12 +97,6 @@ route[NAT_MANAGE] } } - if($sel(cfg_get.kazoo.nat_fix_sdp_reply) == 1) { - if (has_body("application/sdp") && nat_uac_test(KZ_NAT_SDP_TEST)) { - fix_nated_sdp(KZ_NAT_SDP_FIX); - } - } - } # vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab From 2cba3c19cd57e0505a17074f9bfb8a2b8e540833 Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 13 Feb 2019 02:12:15 +0000 Subject: [PATCH 106/209] add NAT_SDP route --- kamailio/nat-traversal-role.cfg | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/kamailio/nat-traversal-role.cfg b/kamailio/nat-traversal-role.cfg index 7c64f84..3236e6c 100644 --- a/kamailio/nat-traversal-role.cfg +++ b/kamailio/nat-traversal-role.cfg @@ -22,8 +22,28 @@ kazoo.nat_fix_sdp_request = KZ_NAT_FIX_SDP_REQUEST descr "performs request sdp r kazoo.nat_fix_sdp_reply = KZ_NAT_FIX_SDP_REPLY descr "performs reply sdp replacement of private addresses" ####### NAT Traversal Logic ######## +route[NAT_SDP] +{ + if( has_body("application/sdp")) { + if( nat_uac_test(KZ_NAT_SDP_TEST)) { + xlog("L_DEBUG", "$ci|log|applying sdp nat fix\n"); + $var(ret) = fix_nated_sdp(KZ_NAT_SDP_FIX); + xlog("L_DEBUG", "$ci|log|result of applying sdp nat fix is $var(ret)\n"); + } else if( is_method("INVITE") && !isflagset(FLAG_INTERNALLY_SOURCED) && is_audio_on_hold()) { + xlog("L_DEBUG", "$ci|log|applying sdp nat fix for held channel\n"); + $var(ret) = fix_nated_sdp(KZ_NAT_SDP_FIX); + xlog("L_DEBUG", "$ci|log|result of applying sdp nat fix for held channel is $var(ret)\n"); + } + } +} + route[NAT_DETECT] { + + if($sel(cfg_get.kazoo.nat_fix_sdp_request) == 1) { + route(NAT_SDP); + } + if ($Rp == "5080") { setflag(FLAG_SKIP_NAT_CORRECTION); xlog("L_DEBUG", "$ci|log|skipping nat correction on PORT 5080\n"); @@ -61,20 +81,12 @@ route[NAT_DETECT] } } - if($sel(cfg_get.kazoo.nat_fix_sdp_request) == 1) { - if (has_body("application/sdp") && nat_uac_test(KZ_NAT_SDP_TEST)) { - fix_nated_sdp(KZ_NAT_SDP_FIX); - } - } - } route[NAT_MANAGE] { - if(is_reply() && $sel(cfg_get.kazoo.nat_fix_sdp_reply) == 1) { - if (has_body("application/sdp") && nat_uac_test(KZ_NAT_SDP_TEST)) { - fix_nated_sdp(KZ_NAT_SDP_FIX); - } + if( is_reply() && $sel(cfg_get.kazoo.nat_fix_sdp_reply) == 1) { + route(NAT_SDP); } if ( is_request() && isflagset(FLAG_INTERNALLY_SOURCED)) { From 3a334b55ea088ff3faca58c8cbc7de69655f1b61 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 14 Feb 2019 18:43:53 +0000 Subject: [PATCH 107/209] add REGISTRAR_NAT_PING_NAT_ONLY macro and default to 0 --- kamailio/registrar-role.cfg | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/kamailio/registrar-role.cfg b/kamailio/registrar-role.cfg index 1c7730e..2c1eb69 100644 --- a/kamailio/registrar-role.cfg +++ b/kamailio/registrar-role.cfg @@ -1,4 +1,5 @@ #!trydef REGISTRAR_NAT_PING_INTERVAL 30 +#!trydef REGISTRAR_NAT_PING_NAT_ONLY 0 #!trydef REGISTRAR_NAT_PING_WORKERS 5 #!trydef REGISTRAR_MIN_EXPIRES 300 #!trydef REGISTRAR_MAX_EXPIRES 3600 @@ -54,7 +55,7 @@ modparam("usrloc", "close_expired_tcp", REGISTRAR_CLOSE_EXPIRED_TCP) #!trydef NATHELPER_LOADED loadmodule "nathelper.so" modparam("nathelper", "natping_interval", REGISTRAR_NAT_PING_INTERVAL) -modparam("nathelper", "ping_nated_only", 1) +modparam("nathelper", "ping_nated_only", REGISTRAR_NAT_PING_NAT_ONLY) modparam("nathelper", "natping_processes", REGISTRAR_NAT_PING_WORKERS) modparam("nathelper", "sipping_bflag", FLB_NATSIPPING) #!endif @@ -98,9 +99,6 @@ route[HANDLE_REGISTER] return; } - resetbflag(FLB_NATB); - resetbflag(FLB_NATSIPPING); - if (isflagset(FLT_NATS)) { setbflag(FLB_NATB); fix_nated_register(); From 0bb91ef23ba652fb107524f58ccf72b78ecab165 Mon Sep 17 00:00:00 2001 From: lazedo Date: Fri, 15 Feb 2019 15:10:47 +0000 Subject: [PATCH 108/209] more nat related changes --- kamailio/authorization-role.cfg | 23 ++++++++++++++++ kamailio/default.cfg | 3 +++ kamailio/nat-traversal-role.cfg | 6 +++-- kamailio/presence-notify.cfg | 6 ++--- kamailio/presence-role.cfg | 6 ++--- kamailio/registrar-role.cfg | 48 +++++++++++++-------------------- 6 files changed, 55 insertions(+), 37 deletions(-) create mode 100644 kamailio/authorization-role.cfg diff --git a/kamailio/authorization-role.cfg b/kamailio/authorization-role.cfg new file mode 100644 index 0000000..5b55be2 --- /dev/null +++ b/kamailio/authorization-role.cfg @@ -0,0 +1,23 @@ +## to be enhanced + +route[AUTHORIZATION_CHECK] +{ + if (!is_method("MESSAGE|NOTIFY|SUBSCRIBE|PUBLISH")) + return; + + if(has_totag()) + return; + + if (isflagset(FLAG_INTERNALLY_SOURCED)) + return; + + if (isflagset(FLAG_TRUSTED_SOURCE)) + return; + + $xavp(regcfg=>match_received) = $su; + if(!(registered("location", "$fu", 2, 1) == 1 && $(xavp(ulattrs=>custom_channel_vars){s.len}) > 1)) { + xlog("L_INFO", "$ci|log|not authorized $fu from $si:$sp\n"); + send_reply("503", "Not Registered"); + exit; + } +} diff --git a/kamailio/default.cfg b/kamailio/default.cfg index 8998359..09fe902 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -244,6 +244,9 @@ modparam("kazoo", "amqp_connection", "MY_AMQP_DENARY_URL") include_file "kazoo-bindings.cfg" ####### Role Configurations ########## +#!ifdef AUTHORIZATION_ROLE +include_file "authorization-role.cfg" +#!endif #!ifdef DISPATCHER_ROLE include_file "dispatcher-role.cfg" #!endif diff --git a/kamailio/nat-traversal-role.cfg b/kamailio/nat-traversal-role.cfg index 3236e6c..879721b 100644 --- a/kamailio/nat-traversal-role.cfg +++ b/kamailio/nat-traversal-role.cfg @@ -4,7 +4,7 @@ loadmodule "nathelper.so" #!trydef NATHELPER_LOADED #!endif modparam("nathelper", "received_avp", "$avp(AVP_RECV_PARAM)") -modparam("nathelper", "sipping_from", "sip:sipcheck@MY_HOSTNAME") +modparam("nathelper", "sipping_from", "sip:registrar-check@MY_HOSTNAME") #!ifdef WEBSOCKETS_ROLE #!trydef KZ_NAT_DETECT 83 @@ -69,12 +69,14 @@ route[NAT_DETECT] } if (isflagset(FLAG_SKIP_NAT_CORRECTION)) { - return(); + xlog("L_DEBUG", "$ci|log|skipping nat detection\n"); + return; } force_rport(); if(nat_uac_test(KZ_NAT_DETECT)) { + xlog("L_DEBUG", "$ci|log|detected nat request\n"); setflag(FLT_NATS); if (!is_method("REGISTER")) { if(is_first_hop()) set_contact_alias(); diff --git a/kamailio/presence-notify.cfg b/kamailio/presence-notify.cfg index d196a60..7d480d0 100644 --- a/kamailio/presence-notify.cfg +++ b/kamailio/presence-notify.cfg @@ -72,15 +72,15 @@ event_route[presence:notify-reply] } else { if($rP != "UDP") { $xavp(pres=>delete_subscription) = 1; - xlog("L_ERROR", "$ci|error|removing $rP watcher $subs(watcher_username)@$subs(watcher_domain) for $subs(pres_uri)\n"); + xlog("L_ERROR", "$ci|error|removing $rP watcher $subs(watcher_username)@$subs(watcher_domain) for $subs(pres_uri) with reason $subs(reason) and reply $notify_reply($rs)\n"); } else { $var(shtinc) = $shtinc(notify=>$ci::count); if($var(shtinc) > MAX_NOTIFY_ERROR) { $xavp(pres=>delete_subscription) = 1; - xlog("L_ERROR", "$ci|error|removing $rP watcher $subs(watcher_username)@$subs(watcher_domain) for $subs(pres_uri)\n"); + xlog("L_ERROR", "$ci|error|removing $rP watcher $subs(watcher_username)@$subs(watcher_domain) for $subs(pres_uri) with reason $subs(reason) and reply $notify_reply($rs)\n"); } else { $var(max_notify) = MAX_NOTIFY_ERROR; - xlog("L_WARN", "$ci|error|received $notify_reply($rs) ($var(shtinc)/$var(max_notify)) when notifying $subs(watcher_username)@$subs(watcher_domain) on behalf of $subs(pres_uri)\n"); + xlog("L_WARN", "$ci|error|received $notify_reply($rs) ($var(shtinc)/$var(max_notify)) when notifying $subs(watcher_username)@$subs(watcher_domain) on behalf of $subs(pres_uri) with reason $subs(reason) and reply $notify_reply($rs)\n"); } } } diff --git a/kamailio/presence-role.cfg b/kamailio/presence-role.cfg index 2481d3f..6081711 100644 --- a/kamailio/presence-role.cfg +++ b/kamailio/presence-role.cfg @@ -65,9 +65,9 @@ modparam("kazoo", "pua_mode", 1) loadmodule "nat_traversal.so" #!endif modparam("nat_traversal", "keepalive_method", "OPTIONS") -modparam("nat_traversal", "keepalive_from", "sip:sipcheck@MY_HOSTNAME") +modparam("nat_traversal", "keepalive_from", "sip:presence-check@MY_HOSTNAME") modparam("nat_traversal", "keepalive_state_file", "KAZOO_DATA_DIR/keep_alive_state") -modparam("nat_traversal", "keepalive_interval", 45) +modparam("nat_traversal", "keepalive_interval", 30) #!endif kazoo.presence_sync_amqp = KZ_PRESENCE_AMQP_PUBLISH descr "sync subscriptions to amqp" @@ -87,7 +87,7 @@ kazoo.presence_no_targets_log_level = KZ_PRESENCE_NO_TARGETS_LOG_LEVEL descr "wh #!ifdef NAT_TRAVERSAL_ROLE route[PRESENCE_NAT] { - if (isflagset(FLT_NATS)) { + if (isflagset(FLT_NATS) && proto==UDP) { nat_keepalive(); } } diff --git a/kamailio/registrar-role.cfg b/kamailio/registrar-role.cfg index 2c1eb69..355aa39 100644 --- a/kamailio/registrar-role.cfg +++ b/kamailio/registrar-role.cfg @@ -1,6 +1,13 @@ +#### NAT PINGING PARAMS ### +## NEXT 2 SHOULD GO TOGETHER +## REGISTRAR_NAT_PING_TIMEOUT should be (REGISTRAR_NAT_PING_INTERVAL + 10) or 0 to disable #!trydef REGISTRAR_NAT_PING_INTERVAL 30 -#!trydef REGISTRAR_NAT_PING_NAT_ONLY 0 +#!trydef REGISTRAR_NAT_PING_TIMEOUT 40 + +#!trydef REGISTRAR_NAT_PING_NAT_ONLY 1 #!trydef REGISTRAR_NAT_PING_WORKERS 5 +##### + #!trydef REGISTRAR_MIN_EXPIRES 300 #!trydef REGISTRAR_MAX_EXPIRES 3600 #!trydef REGISTRAR_DEFAULT_EXPIRES 600 @@ -58,6 +65,7 @@ modparam("nathelper", "natping_interval", REGISTRAR_NAT_PING_INTERVAL) modparam("nathelper", "ping_nated_only", REGISTRAR_NAT_PING_NAT_ONLY) modparam("nathelper", "natping_processes", REGISTRAR_NAT_PING_WORKERS) modparam("nathelper", "sipping_bflag", FLB_NATSIPPING) +modparam("nathelper", "keepalive_timeout", REGISTRAR_NAT_PING_TIMEOUT) #!endif ####### SIP Registrar implementation module ########## @@ -93,13 +101,11 @@ kazoo.registrar_check_amqp_availability = REGISTRAR_CHECK_AMQP_AVAILABILITY desc ####### Registrar Logic ######## -route[HANDLE_REGISTER] -{ - if (!is_method("REGISTER")) { - return; - } +route[REGISTRAR_NAT] +{ if (isflagset(FLT_NATS)) { + xlog("L_INFO", "$ci|log|fixing contact for nat request\n"); setbflag(FLB_NATB); fix_nated_register(); @@ -107,41 +113,23 @@ route[HANDLE_REGISTER] if (!($ua =~ "Linksys/SPA8000" || $ua =~ "SIPp" || (af==INET6) + || (proto!=UDP) + || ($(xavp(ulattrs=>custom_channel_vars){kz.json,Keep-Alive}) == "false") )) { + xlog("L_INFO", "$ci|log|set nat pinging\n"); setbflag(FLB_NATSIPPING); } } else { $avp(AVP_RECV_PARAM) = $su; } - - route(ATTEMPT_AUTHORIZATION); - } -route[AUTHORIZATION_CHECK] +route[HANDLE_REGISTER] { - if (!is_method("MESSAGE|NOTIFY|SUBSCRIBE|PUBLISH")) - return; - - if(has_totag()) - return; - - if (isflagset(FLAG_INTERNALLY_SOURCED)) - return; - - if (isflagset(FLAG_TRUSTED_SOURCE)) + if (!is_method("REGISTER")) { return; - - $xavp(regcfg=>match_received) = $su; - if(!(registered("location", "$fu", 2, 1) == 1 && $(xavp(ulattrs=>custom_channel_vars){s.len}) > 1)) { - xlog("L_INFO", "$ci|log|not authorized $fu from $si:$sp\n"); - send_reply("503", "Not Registered"); - exit; } -} -route[ATTEMPT_AUTHORIZATION] -{ #!ifdef PUSHER_ROLE route(PUSHER_ATTEMPT_REGISTRATION); #!endif @@ -270,6 +258,8 @@ route[SAVE_LOCATION] }; $sht(auth_cache=>$Au) = $var(password); + route(REGISTRAR_NAT); + $var(save_result) = save("location", "0x04"); if($var(save_result) < 0) { exit; From a914218704394e872604234cf86b119fc29e6fa0 Mon Sep 17 00:00:00 2001 From: lazedo Date: Sat, 16 Feb 2019 14:19:46 +0000 Subject: [PATCH 109/209] websocket logs and macros --- kamailio/websockets-role.cfg | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/kamailio/websockets-role.cfg b/kamailio/websockets-role.cfg index 0dcc48b..83c337e 100644 --- a/kamailio/websockets-role.cfg +++ b/kamailio/websockets-role.cfg @@ -12,18 +12,26 @@ loadmodule "nathelper.so" #!endif ######## Generic Hash Table container in shared memory ######## -modparam("htable", "htable", "websockets=>size=16;autoexpire=7200;initval=0") +modparam("htable", "htable", "websockets=>size=16;initval=0") ######## Basic HTTP request handling ######## loadmodule "xhttp.so" + +#!trydef WS_KEEPALIVE_MECHANISM 1 +#!trydef WS_KEEPALIVE_TIMEOUT 30 +#!trydef WS_KEEPALIVE_PROCESSES 3 +#!trydef WS_KEEPALIVE_INTERVAL 1 +#!trydef WS_KEEPALIVE_DATA "Kazoo encourages you to keep alive" +#!trydef WS_MAX_CONNECTIONS_PER_IP 50 + ######## Websocket module ######## loadmodule "websocket.so" -modparam("websocket", "keepalive_mechanism", 0) -modparam("websocket", "keepalive_timeout", 30) -modparam("websocket", "keepalive_processes", 1) -modparam("websocket", "keepalive_interval", 1) -modparam("websocket", "ping_application_data", "Kazoo encourages you to keep alive") +modparam("websocket", "keepalive_mechanism", WS_KEEPALIVE_MECHANISM) +modparam("websocket", "keepalive_timeout", WS_KEEPALIVE_TIMEOUT) +modparam("websocket", "keepalive_processes", WS_KEEPALIVE_PROCESSES) +modparam("websocket", "keepalive_interval", WS_KEEPALIVE_INTERVAL) +modparam("websocket", "ping_application_data", WS_KEEPALIVE_DATA) modparam("websocket", "sub_protocols", 1) ####### Websocket Logic ######## @@ -86,15 +94,15 @@ event_route[xhttp:request] } #!endif - if($sht(websockets=>$si::count) > 50) { - xlog("L_WARN", "websocket|log|$si:$sp is at the maximum allowable sockets per IP, rejecting request for another websocket\n"); + if($sht(websockets=>$si::count) > WS_MAX_CONNECTIONS_PER_IP) { + xlog("L_WARN", "websocket|log|$si:$sp is at the maximum $def(WS_MAX_CONNECTIONS_PER_IP) allowable sockets per IP, rejecting request for another websocket\n"); xhttp_reply("403", "Forbidden", "", ""); exit; } if (ws_handle_handshake()) { - $var(shtinc) = $shtinc(websockets=>$si::count); - xlog("L_INFO", "websocket|log|opened websocket $var(count) of 50 for $si:$sp\n"); + $var(count) = $shtinc(websockets=>$si::count); + xlog("L_INFO", "websocket|log|opened websocket $var(count) of $def(WS_MAX_CONNECTIONS_PER_IP) for $si:$sp\n"); exit; } @@ -103,10 +111,10 @@ event_route[xhttp:request] } event_route[websocket:closed] { - $var(shtdec) = $shtdec(websockets=>$si::count); - if ($sht(websockets=>$si::count) < 1) { + $var(count) = $shtdec(websockets=>$si::count); + if ($var(count) < 1) { xlog("L_INFO", "websocket|log|$si:$sp closed last websocket to that IP\n"); - sht_rm_name_re("websockets=>$(si{re.subst,/\\./\\\\./g})::.*"); + $sht(websockets=>$si::count) = $null; } else { xlog("L_INFO", "websocket|log|closed websocket from $si:$sp, $var(count) remaining from that IP\n"); } From a22d1fb716194db38582a322e16e5eca9b8285a1 Mon Sep 17 00:00:00 2001 From: lazedo Date: Sat, 16 Feb 2019 16:06:55 +0000 Subject: [PATCH 110/209] registrar nat msg log level --- kamailio/registrar-role.cfg | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kamailio/registrar-role.cfg b/kamailio/registrar-role.cfg index 355aa39..0ecedf3 100644 --- a/kamailio/registrar-role.cfg +++ b/kamailio/registrar-role.cfg @@ -105,7 +105,7 @@ kazoo.registrar_check_amqp_availability = REGISTRAR_CHECK_AMQP_AVAILABILITY desc route[REGISTRAR_NAT] { if (isflagset(FLT_NATS)) { - xlog("L_INFO", "$ci|log|fixing contact for nat request\n"); + xlog("L_DEBUG", "$ci|log|fixing contact for nat request\n"); setbflag(FLB_NATB); fix_nated_register(); @@ -116,7 +116,7 @@ route[REGISTRAR_NAT] || (proto!=UDP) || ($(xavp(ulattrs=>custom_channel_vars){kz.json,Keep-Alive}) == "false") )) { - xlog("L_INFO", "$ci|log|set nat pinging\n"); + xlog("L_DEBUG", "$ci|log|set nat pinging\n"); setbflag(FLB_NATSIPPING); } } else { From 9e6652c31fe1de0e69231fb43fd6fc070e9254a6 Mon Sep 17 00:00:00 2001 From: lazedo Date: Sat, 16 Feb 2019 16:45:27 +0000 Subject: [PATCH 111/209] change default number of buffer slots --- kamailio/defs.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kamailio/defs.cfg b/kamailio/defs.cfg index 09eefc3..c406ea7 100644 --- a/kamailio/defs.cfg +++ b/kamailio/defs.cfg @@ -26,7 +26,7 @@ #!trydef KAZOO_LOG_LEVEL L_INFO #!trydef PV_BUFFER_SIZE 16384 -#!trydef PV_BUFFER_SLOTS 20 +#!trydef PV_BUFFER_SLOTS 30 #!ifndef KAMAILIO_DBMS #!substdef "!KAMAILIO_DBMS!kazoo!g" From ec06b7e29a62d85505408320d416a952f484d784 Mon Sep 17 00:00:00 2001 From: lazedo Date: Sun, 17 Feb 2019 09:41:01 +0000 Subject: [PATCH 112/209] update ws connection count for proxied connections * adds allowed proxies * adds allowed connections per proxy --- kamailio/default.cfg | 4 -- kamailio/websockets-role.cfg | 76 ++++++++++++++++++++++-------------- 2 files changed, 47 insertions(+), 33 deletions(-) diff --git a/kamailio/default.cfg b/kamailio/default.cfg index 09fe902..5e7cd3b 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -341,10 +341,6 @@ route route(DOS_PREVENTION); #!endif - #!ifdef WEBSOCKETS_ROLE - route(HANDLE_WEBSOCKETS); - #!endif - #!ifdef NAT_TRAVERSAL_ROLE route(NAT_DETECT); #!endif diff --git a/kamailio/websockets-role.cfg b/kamailio/websockets-role.cfg index 83c337e..c31d4a0 100644 --- a/kamailio/websockets-role.cfg +++ b/kamailio/websockets-role.cfg @@ -24,6 +24,8 @@ loadmodule "xhttp.so" #!trydef WS_KEEPALIVE_INTERVAL 1 #!trydef WS_KEEPALIVE_DATA "Kazoo encourages you to keep alive" #!trydef WS_MAX_CONNECTIONS_PER_IP 50 +#!trydef WS_MAX_CONNECTIONS_PER_PROXY 0 +#!trydef WS_ALLOWED_PROXIES "0.0.0.0/0" ######## Websocket module ######## loadmodule "websocket.so" @@ -35,27 +37,10 @@ modparam("websocket", "ping_application_data", WS_KEEPALIVE_DATA) modparam("websocket", "sub_protocols", 1) ####### Websocket Logic ######## -route[HANDLE_WEBSOCKETS] -{ - # Do NAT traversal stuff for requests from a WebSocket - # connection - even if it is not behind a NAT! - # This won't be needed in the future if Kamailio and the - # WebSocket client support Outbound and Path. - - return(); - -} - -route[NAT_WEBSOCKETS_CORRECT] -{ - # Do NAT traversal stuff for replies to a WebSocket connection - # - even if it is not behind a NAT! - # This won't be needed in the future if Kamailio and the - # WebSocket client support Outbound and Path. - - return(); -} +kazoo.ws_allowed_proxies = WS_ALLOWED_PROXIES desc "comma separated list of allowed proxies in cidr notation" +kazoo.ws_max_connection_per_ip = WS_MAX_CONNECTIONS_PER_IP desc "max connections per ip" +kazoo.ws_max_connection_per_proxy = WS_MAX_CONNECTIONS_PER_PROXY desc "max connections per proxy" event_route[xhttp:request] { @@ -94,15 +79,42 @@ event_route[xhttp:request] } #!endif - if($sht(websockets=>$si::count) > WS_MAX_CONNECTIONS_PER_IP) { - xlog("L_WARN", "websocket|log|$si:$sp is at the maximum $def(WS_MAX_CONNECTIONS_PER_IP) allowable sockets per IP, rejecting request for another websocket\n"); + if ($hdr(X-Forwarded-For) == $null) { + $var(ws_orig_ip) = $si; + } else { + xlog("L_INFO", "websocket|log|request X-Forwarded-For $hdr(X-Forwarded-For) from $si\n"); + $var(ws_orig_ip) = $hdr(X-Forwarded-For); + } + + if($si != $var(ws_orig_ip)) { + if(!is_in_subnet($si, $sel(cfg_get.kazoo.ws_allowed_proxies))) { + xlog("L_WARNING", "websocket|log|request X-Forwarded-For $hdr(X-Forwarded-For) from invalid ip $si - allowed $sel(cfg_get.kazoo.ws_allowed_proxies)\n"); + xhttp_reply("403", "Forbidden", "", ""); + exit; + } + + if($sel(cfg_get.kazoo.ws_max_connection_per_proxy) > 0 && $sht(websockets=>$si::count) > $sel(cfg_get.kazoo.ws_max_connection_per_proxy)) { + xlog("L_WARN", "websocket|log|$si is at the maximum $sel(cfg_get.kazoo.ws_max_connection_per_proxy) allowable sockets per PROXY IP, rejecting request for another websocket\n"); + xhttp_reply("403", "Forbidden", "", ""); + exit; + } + } + + if($sel(cfg_get.kazoo.ws_max_connection_per_ip) > 0 && $sht(websockets=>$var(ws_orig_ip)::count) > $sel(cfg_get.kazoo.ws_max_connection_per_ip)) { + xlog("L_WARN", "websocket|log|$var(ws_orig_ip) is at the maximum $sel(cfg_get.kazoo.ws_max_connection_per_ip) allowable sockets per IP, rejecting request for another websocket\n"); xhttp_reply("403", "Forbidden", "", ""); exit; } if (ws_handle_handshake()) { - $var(count) = $shtinc(websockets=>$si::count); - xlog("L_INFO", "websocket|log|opened websocket $var(count) of $def(WS_MAX_CONNECTIONS_PER_IP) for $si:$sp\n"); + $var(count) = $shtinc(websockets=>$var(ws_orig_ip)::count); + if($si != $var(ws_orig_ip)) { + $var(proxy_count) = $shtinc(websockets=>$si::count); + xlog("L_INFO", "websocket|log|opened proxied websocket $ws_conid from $si for $var(ws_orig_ip):$sp\n"); + $sht(websockets=>$ws_conid::ws_orig_ip) = $var(ws_orig_ip); + } else { + xlog("L_INFO", "websocket|log|opened websocket $ws_conid from $var(ws_orig_ip):$sp\n"); + } exit; } @@ -110,12 +122,18 @@ event_route[xhttp:request] xhttp_reply("404", "Not Found", "", ""); } -event_route[websocket:closed] { +event_route[websocket:closed] +{ + $var(ws_orig_ip) = $sht(websockets=>$ws_conid::ws_orig_ip); + $sht(websockets=>$ws_conid::ws_orig_ip) = $null; + $var(count) = $shtdec(websockets=>$si::count); - if ($var(count) < 1) { - xlog("L_INFO", "websocket|log|$si:$sp closed last websocket to that IP\n"); - $sht(websockets=>$si::count) = $null; + if($var(ws_orig_ip) != $null && $si != $var(ws_orig_ip)) { + $var(countip) = $shtdec(websockets=>$var(ws_orig_ip)::count); + xlog("L_INFO", "websocket|log|$si closed proxied websocket $ws_conid for $var(ws_orig_ip):$sp\n"); + if ($var(countip) < 1) $sht(websockets=>$var(ws_orig_ip)::count) = $null; } else { - xlog("L_INFO", "websocket|log|closed websocket from $si:$sp, $var(count) remaining from that IP\n"); + xlog("L_INFO", "websocket|log|closed websocket $ws_conid from $var(ws_orig_ip):$sp\n"); } + if ($var(count) < 1) $sht(websockets=>$si::count) = $null; } From 30306fe13a5899aaee7f529113a2fc3147c41437 Mon Sep 17 00:00:00 2001 From: lazedo Date: Sun, 24 Feb 2019 14:35:04 +0000 Subject: [PATCH 113/209] remove quotes from ips --- system/sbin/kazoo-kamailio | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system/sbin/kazoo-kamailio b/system/sbin/kazoo-kamailio index 2fefde2..81e4aa9 100755 --- a/system/sbin/kazoo-kamailio +++ b/system/sbin/kazoo-kamailio @@ -24,12 +24,12 @@ RAM_DISK_FREE_SIZE_PERC=${RAM_DISK_FREE_SIZE:-30} RAM_DISK_ENABLED=${RAM_DISK_ENABLED:-false} EXTRA_OPTIONS=${EXTRA_OPTIONS:-"-x tlsf -w /tmp"} -MY_LOCAL_IP=$(ip route get 8.8.8.8 2> /dev/null | awk '{print "\""$NF"\""; exit}') +MY_LOCAL_IP=$(ip route get 8.8.8.8 2> /dev/null | awk '{print ""$NF""; exit}') if [[ ! -z ${MY_LOCAL_IP} ]]; then EXTRA_OPTIONS+=" -A MY_LOCAL_IP=${MY_LOCAL_IP}" fi -MY_PUBLIC_IP=$(dig @ns1.google.com TXT o-o.myaddr.l.google.com +short -4 2> /dev/null) +MY_PUBLIC_IP=$(dig @ns1.google.com TXT o-o.myaddr.l.google.com +short -4 2> /dev/null | sed s/\"//g ) if [[ ! -z ${MY_PUBLIC_IP} ]]; then EXTRA_OPTIONS+=" -A MY_PUBLIC_IP=${MY_PUBLIC_IP}" fi From d8dab117d607b73c5b992bbf335ebb99c10dd65e Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 27 Feb 2019 18:17:17 +0000 Subject: [PATCH 114/209] move sanity to own cfg file --- kamailio/default.cfg | 39 +++------------------------- kamailio/sanity.cfg | 62 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 36 deletions(-) create mode 100644 kamailio/sanity.cfg diff --git a/kamailio/default.cfg b/kamailio/default.cfg index 5e7cd3b..ab64e90 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -148,12 +148,6 @@ modparam("maxfwd", "max_limit", 50) ######## SIP utilities [requires sl] ######## loadmodule "siputils.so" -######## SIP message formatting sanity checks [requires sl] ######## -loadmodule "sanity.so" -modparam("sanity", "default_checks", 1511) -modparam("sanity", "uri_checks", 7) -modparam("sanity", "autodrop", 0) - ######## Text operations module ######## loadmodule "textops.so" loadmodule "textopsx.so" @@ -243,6 +237,9 @@ modparam("kazoo", "amqp_connection", "MY_AMQP_DENARY_URL") ###### kazoo bindings ###### include_file "kazoo-bindings.cfg" +## sanity ## +include_file "sanity.cfg" + ####### Role Configurations ########## #!ifdef AUTHORIZATION_ROLE include_file "authorization-role.cfg" @@ -403,36 +400,6 @@ route[CHECK_RETRANS] } } -route[SANITY_CHECK] -{ - ## CVE-2018-14767 - if($(hdr(To)[1]) != $null) { - xlog("second To header not null - dropping message"); - drop; - } - - if (!sanity_check()) { - xlog("L_WARN", "$ci|end|message from $si:$sp is insane ($var(insane))\n"); - drop; - } - - if (!mf_process_maxfwd_header("10")) { - xlog("L_WARN", "$ci|end|too much hops, not enough barley from $si:$sp\n"); - send_reply("483", "Too Many Hops"); - exit; - } - - if ($ua == "friendly-scanner" || - $ua == "sundayddr" || - $ua == "pplsip" || - $ua =~ "NiceGuy" || - $ua =~ "PortSIP" || - $ua =~ "sipcli" ) { - xlog("L_WARN", "$ci|end|dropping message with user-agent $ua from $si:$sp\n"); - drop; - } -} - route[CLASSIFY_SOURCE] { #!ifdef DISPATCHER_ROLE diff --git a/kamailio/sanity.cfg b/kamailio/sanity.cfg new file mode 100644 index 0000000..287b0ec --- /dev/null +++ b/kamailio/sanity.cfg @@ -0,0 +1,62 @@ + +#!trydef SANITY_CHECK_USE_PORT 1 +#!trydef SANITY_DROPS_REQUEST 1 +#!trydef SANITY_DEFAULT_CHECK 17895 +#!trydef SANITY_URI_CHECKS 7 + +#!substdef "!SANITY_SUBST_CACHE_PERIOD!$def(SANITY_CACHE_PERIOD)!g" + +######## SIP message formatting sanity checks [requires sl] ######## +loadmodule "sanity.so" +modparam("sanity", "default_checks", SANITY_DEFAULT_CHECK) +modparam("sanity", "uri_checks", SANITY_URI_CHECKS) +modparam("sanity", "autodrop", 0) +modparam("sanity", "noreply", 1) + +modparam("debugger", "mod_level", "sanity=-3") + +kazoo.sanity_check_use_port = SANITY_CHECK_USE_PORT descr "should we keep track of ip and port for sanity failures" +kazoo.sanity_drops_request = SANITY_DROPS_REQUEST descr "should we drop the request or send error on sanity failure" + +route[SANITY_CHECK] +{ + ## CVE-2018-14767 + if($(hdr(To)[1]) != $null) { + xlog("second To header not null - dropping message"); + drop; + } + + $var(sanity_key) = ""; + if($sel(cfg_get.kazoo.sanity_check_use_port) == 1) { + $var(sanity_key) = $_s("$si::$sp"); + } else { + $var(sanity_key) = $_s("$si"); + } + + if (!sanity_check()) { + if($sel(cfg_get.kazoo.sanity_drops_request) == 1) { + xlog("L_WARN", "$ci|end|dropping insane message from $si:$sp\n"); + drop; + } else { + xlog("L_WARN", "$ci|end|insane message from $si:$sp\n"); + send_reply("400", "Bad Request"); + exit; + } + } + + if (!mf_process_maxfwd_header("10")) { + xlog("L_WARN", "$ci|end|too much hops, not enough barley from $si:$sp\n"); + send_reply("483", "Too Many Hops"); + exit; + } + + if ($ua == "friendly-scanner" || + $ua == "sundayddr" || + $ua == "pplsip" || + $ua =~ "NiceGuy" || + $ua =~ "PortSIP" || + $ua =~ "sipcli" ) { + xlog("L_WARN", "$ci|end|dropping message with user-agent $ua from $si:$sp\n"); + drop; + } +} From 2f54da587227f27fa90ff927179d88a40249a088 Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 27 Feb 2019 18:19:13 +0000 Subject: [PATCH 115/209] antiflood macros & auth by port --- kamailio/antiflood-role.cfg | 92 ++++++++++++++++++++++++++++--------- 1 file changed, 71 insertions(+), 21 deletions(-) diff --git a/kamailio/antiflood-role.cfg b/kamailio/antiflood-role.cfg index 2f0345f..edb0455 100644 --- a/kamailio/antiflood-role.cfg +++ b/kamailio/antiflood-role.cfg @@ -4,9 +4,17 @@ #!trydef ANTIFLOOD_RATE_EXPIRE 4 #!trydef ANTIFLOOD_FAILED_AUTH_WINDOW 300 #!trydef ANTIFLOOD_FAILED_AUTH_DENSITY 4 +#!trydef ANTIFLOOD_FAILED_AUTH_USE_PORT 1 +#!trydef ANTIFLOOD_FAILED_AUTH_ACTION 2 +#!trydef ANTIFLOOD_RATE_LIMIT_ENABLED 1 +#!trydef ANTIFLOOD_AUTH_LIMIT_ENABLED 1 +#!trydef ANTIFLOOD_RATE_DROP 1 +#!trydef ANTIFLOOD_CACHE_PERIOD 300 + +#!substdef "!ANTIFLOOD_SUBST_CACHE_PERIOD!$def(ANTIFLOOD_CACHE_PERIOD)!g" ######## Flood Prevention Hash Tables ######## -modparam("htable", "htable", "antiflood=>size=16;autoexpire=ANTIFLOOD_CACHE_PERIOD;initval=0") +modparam("htable", "htable", "antiflood=>size=16;autoexpire=ANTIFLOOD_SUBST_CACHE_PERIOD;initval=0") ######## Flood Prevention Module ######## loadmodule "pike.so" @@ -14,6 +22,21 @@ modparam("pike", "sampling_time_unit", ANTIFLOOD_RATE_WINDOW) modparam("pike", "reqs_density_per_unit", ANTIFLOOD_RATE_DENSITY) modparam("pike", "remove_latency", ANTIFLOOD_RATE_EXPIRE) +kazoo.antiflood_failed_auth_use_port = ANTIFLOOD_FAILED_AUTH_USE_PORT descr "should we keep track of ip and port for auth failures" +kazoo.antiflood_failed_auth_action = ANTIFLOOD_FAILED_AUTH_ACTION descr "0 - log, 1 - drop, 2 - reply with 403" +kazoo.antiflood_rate_limit_enabled = ANTIFLOOD_RATE_LIMIT_ENABLED descr "antiflood rate limit enabled" +kazoo.antiflood_auth_limit_enabled = ANTIFLOOD_AUTH_LIMIT_ENABLED descr "antiflood auth limit enabled" +kazoo.antiflood_rate_drop = ANTIFLOOD_RATE_DROP descr "should we drop on rate limit" + +route[ANTIFLOOD_LIMIT] +{ + if($sel(cfg_get.kazoo.antiflood_rate_limit_enabled) == 1) { + route(ANTIFLOOD_RATE_LIMIT); + } + if($sel(cfg_get.kazoo.antiflood_auth_limit_enabled) == 1) { + route(ANTIFLOOD_AUTH_LIMIT); + } +} route[ANTIFLOOD_RATE_LIMIT] { @@ -25,13 +48,16 @@ route[ANTIFLOOD_RATE_LIMIT] # use pike to control the rates if (!pike_check_req()) { - xlog("L_WARN", "$ci|end|dropping request from $fu due to rate of requests with source $si:$sp\n"); - drop(); - exit; + if($sel(cfg_get.kazoo.antiflood_rate_drop) == 1) { + xlog("L_WARN", "$ci|end|dropping request from $fu due to rate of requests with source $si:$sp\n"); + drop(); + } else { + xlog("L_WARN", "$ci|end|request from $fu exceeded rate of requests with source $si:$sp\n"); + } } } -route[ANITFLOOD_AUTH_LIMIT] +route[ANTIFLOOD_AUTH_LIMIT] { if (has_totag() || isflagset(FLAG_TRUSTED_SOURCE) @@ -39,21 +65,38 @@ route[ANITFLOOD_AUTH_LIMIT] return(1); } - if ($Au != $null && - $sht(antiflood=>$Au::$si::count) >= ANTIFLOOD_FAILED_AUTH_DENSITY + $var(auth_key) = ""; + if($sel(cfg_get.kazoo.antiflood_failed_auth_use_port) == 1) { + $var(auth_key) = $_s("$Au::$si::$sp"); + } else { + $var(auth_key) = $_s("$Au::$si"); + } + if ($Au != $null && + $sht(antiflood=>$var(auth_key)::count) >= ANTIFLOOD_FAILED_AUTH_DENSITY ) { - xlog("L_NOTICE", "$ci|end|request at authorization failure limit for $Au $si:$sp\n"); - $shtex(antiflood=>$Au::$si::count) = ANTIFLOOD_FAILED_AUTH_WINDOW; - $sht(antiflood=>$Au::$si::last) = $Ts; - append_to_reply("Retry-After: 3600\r\n"); - send_reply("500", "Retry Later"); - exit; + $shtex(antiflood=>$var(auth_key)::count) = ANTIFLOOD_FAILED_AUTH_WINDOW; + $sht(antiflood=>$var(auth_key)::last) = $Ts; + if($sel(cfg_get.kazoo.antiflood_failed_auth_action) == 1) { + xlog("L_WARNING", "$ci|end|dropping request authorization failure limit $def(ANTIFLOOD_FAILED_AUTH_DENSITY) for $Au $si:$sp\n"); + drop(); + } else if($sel(cfg_get.kazoo.antiflood_failed_auth_action) == 2) { + xlog("L_NOTICE", "$ci|end|authorization failure limit $def(ANTIFLOOD_FAILED_AUTH_DENSITY) for $Au $si:$sp\n"); + append_to_reply("Retry-After: 3600\r\n"); + send_reply("403", "Forbidden"); + exit; + } else { + xlog("L_NOTICE", "$ci|log|authorization failure limit $def(ANTIFLOOD_FAILED_AUTH_DENSITY) for $Au $si:$sp\n"); + } } } route[ANTIFLOOD_SUCCESSFUL_AUTH] { - sht_rm_name_re("antiflood=>$(Au{re.subst,/\\./\\\\./g})::$(si{re.subst,/\\./\\\\./g})::.*"); + if($sel(cfg_get.kazoo.antiflood_failed_auth_use_port) == 1) { + sht_rm_name_re("antiflood=>$(Au{re.subst,/\\./\\\\./g})::$(si{re.subst,/\\./\\\\./g})::$sp::.*"); + } else { + sht_rm_name_re("antiflood=>$(Au{re.subst,/\\./\\\\./g})::$(si{re.subst,/\\./\\\\./g})::.*"); + } } route[ANTIFLOOD_RESET_AUTH] @@ -68,20 +111,27 @@ route[ANITFLOOD_FAILED_AUTH] return; } - $var(count) = $shtinc(antiflood=>$Au::$si::count); - $sht(antiflood=>$Au::$si::last) = $Ts; + $var(auth_key) = ""; + if($sel(cfg_get.kazoo.antiflood_failed_auth_use_port) == 1) { + $var(auth_key) = $_s("$Au::$si::$sp"); + } else { + $var(auth_key) = $_s("$Au::$si"); + } + + $var(count) = $shtinc(antiflood=>$var(auth_key)::count); + $sht(antiflood=>$var(auth_key)::last) = $Ts; xlog("L_INFO", "$ci|log|$var(count) errounous authorization response for $Au $si:$sp\n"); - if ($var(count) >= ANTIFLOOD_FAILED_AUTH_DENSITY) { + if ($var(count) >= ANTIFLOOD_FAILED_AUTH_DENSITY) { $var(exp) = $Ts - ANTIFLOOD_FAILED_AUTH_WINDOW; - if($sht(antiflood=>$Au::$si::last) > $var(exp)){ - xlog("L_NOTICE", "$ci|end|request at authorization failure limit for $Au $si:$sp\n"); + if($sht(antiflood=>$var(auth_key)::last) > $var(exp)) { + xlog("L_NOTICE", "$ci|end|request at authorization failure limit $def(ANTIFLOOD_FAILED_AUTH_DENSITY) for $Au $si:$sp\n"); append_to_reply("Retry-After: 3600\r\n"); - send_reply("500", "Retry Later"); + send_reply("403", "Forbidden"); exit; } - } + } } event_route[htable:expired:antiflood] From 87e06b530b2c2dfe696060cd7b762cafafd51ad6 Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 27 Feb 2019 18:20:48 +0000 Subject: [PATCH 116/209] move debugger so other cfg files can declare mod_level --- kamailio/default.cfg | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/kamailio/default.cfg b/kamailio/default.cfg index ab64e90..b398e7d 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -188,6 +188,12 @@ loadmodule "sqlops.so" modparam("sqlops","sqlcon", "cb=>KAZOO_DB_URL") modparam("sqlops","sqlcon", "exec=>KAZOO_DB_URL") +####### DEBUG ###### +loadmodule "debugger.so" +modparam("debugger", "mod_hash_size", 5) +modparam("debugger", "mod_level_mode", 1) +modparam("debugger", "mod_level", "core=1") + ####### DATABASE module ########## loadmodule "db_KAMAILIO_DBMS.so" @@ -299,13 +305,6 @@ loadmodule "permissions.so" modparam("permissions", "db_url", "KAZOO_DB_URL") modparam("permissions", "db_mode", 1) - -####### DEBUG ###### -loadmodule "debugger.so" -modparam("debugger", "mod_hash_size", 5) -modparam("debugger", "mod_level_mode", 1) -modparam("debugger", "mod_level", "core=1") - ####### Routing Logic ######## route { From b4a991b9133d6c3a5b5f811dbedffda6a9f6295e Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 27 Feb 2019 18:21:35 +0000 Subject: [PATCH 117/209] route ANTIFLOOD_LIMIT --- kamailio/default.cfg | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/kamailio/default.cfg b/kamailio/default.cfg index b398e7d..f9aa14c 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -321,8 +321,7 @@ route route(CLASSIFY_SOURCE); #!ifdef ANTIFLOOD_ROLE - route(ANTIFLOOD_RATE_LIMIT); - route(ANITFLOOD_AUTH_LIMIT); + route(ANTIFLOOD_LIMIT); #!endif #!ifdef TRAFFIC_FILTER_ROLE From 7d5dfbc72a2683dc29184c67abb26ca747e46d3c Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 27 Feb 2019 18:24:10 +0000 Subject: [PATCH 118/209] allow not logging OPTIONS --- kamailio/default.cfg | 39 +++++++++++++++++++++++++++--------- kamailio/dispatcher-role.cfg | 6 +++--- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/kamailio/default.cfg b/kamailio/default.cfg index f9aa14c..45bf547 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -312,14 +312,6 @@ route route(CHECK_RETRANS); - # log the basic info regarding this call - xlog("L_INFO", "$ci|start|received $pr request $rm $ou\n"); - xlog("L_INFO", "$ci|log|source $si:$sp -> $RAi:$RAp\n"); - xlog("L_INFO", "$ci|log|from $fu\n"); - xlog("L_INFO", "$ci|log|to $tu\n"); - - route(CLASSIFY_SOURCE); - #!ifdef ANTIFLOOD_ROLE route(ANTIFLOOD_LIMIT); #!endif @@ -336,6 +328,10 @@ route route(DOS_PREVENTION); #!endif + route(LOG_REQUEST); + + route(CLASSIFY_SOURCE); + #!ifdef NAT_TRAVERSAL_ROLE route(NAT_DETECT); #!endif @@ -386,6 +382,24 @@ route route(RELAY); } +#!trydef KZ_LOG_REQUEST_OPTIONS 0 +kazoo.log_request_options = KZ_LOG_REQUEST_OPTIONS descr "log OPTIONS requests, default is 0 for preserving log size" + +route[LOG_REQUEST] +{ + if($sel(cfg_get.kazoo.log_request_options) == 0 && is_method("OPTIONS")) { + $var(log_request_level) = L_DBG; + } else { + $var(log_request_level) = L_INFO; + } + + # log the basic info regarding this call + xlog("$var(log_request_level)", "$ci|start|received $pr request $rm $ou\n"); + xlog("$var(log_request_level)", "$ci|log|source $si:$sp -> $RAi:$RAp\n"); + xlog("$var(log_request_level)", "$ci|log|from $fu\n"); + xlog("$var(log_request_level)", "$ci|log|to $tu\n"); +} + route[CHECK_RETRANS] { # handle retransmissions @@ -404,10 +418,15 @@ route[CLASSIFY_SOURCE] route(DISPATCHER_CLASSIFY_SOURCE); #!endif - if (isflagset(FLAG_INTERNALLY_SOURCED) || allow_source_address(TRUSTED_ADR_GROUP) || is_myself($si)) { - xlog("L_INFO", "$ci|log|request from trusted IP\n"); + if (allow_source_address(TRUSTED_ADR_GROUP)) { + xlog("$var(log_request_level)", "$ci|log|request from trusted IP\n"); setflag(FLAG_TRUSTED_SOURCE); } + + if (isflagset(FLAG_INTERNALLY_SOURCED) || is_myself($si)) { + setflag(FLAG_TRUSTED_SOURCE); + } + } route[HANDLE_OPTIONS] diff --git a/kamailio/dispatcher-role.cfg b/kamailio/dispatcher-role.cfg index cc28e79..b9afffe 100644 --- a/kamailio/dispatcher-role.cfg +++ b/kamailio/dispatcher-role.cfg @@ -65,7 +65,7 @@ route[DISPATCHER_CLASSIFY_SOURCE] #!import_file "dispatcher-network-classify.cfg" if (is_myself("$ou")) { - xlog("L_INFO", "$ci|log|original R-URI ($ou) is this proxy, treating as external sources\n"); + xlog("$var(log_request_level)", "$ci|log|original R-URI ($ou) is this proxy, treating as external sources\n"); } else if ( ds_is_from_list(KZ_DISPATCHER_PRIMARY_GROUP, 3) || ds_is_from_list(KZ_DISPATCHER_SECONDARY_GROUP, 3) || @@ -79,10 +79,10 @@ route[DISPATCHER_CLASSIFY_SOURCE] ds_is_from_list(KZ_DISPATCHER_REGISTRAR_PRIMARY_GROUP, 3) || ds_is_from_list(KZ_DISPATCHER_REGISTRAR_SECONDARY_GROUP, 3) ) { - xlog("L_INFO", "$ci|log|originated from internal sources\n"); + xlog("$var(log_request_level)", "$ci|log|originated from internal sources\n"); setflag(FLAG_INTERNALLY_SOURCED); } else { - xlog("L_INFO", "$ci|log|originated from external sources\n"); + xlog("$var(log_request_level)", "$ci|log|originated from external sources\n"); } } From 65085c3037269e03a3415ff1780749be470ede22 Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 27 Feb 2019 18:24:27 +0000 Subject: [PATCH 119/209] websocker origin_ip --- kamailio/websockets-role.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kamailio/websockets-role.cfg b/kamailio/websockets-role.cfg index c31d4a0..074f60f 100644 --- a/kamailio/websockets-role.cfg +++ b/kamailio/websockets-role.cfg @@ -108,10 +108,10 @@ event_route[xhttp:request] if (ws_handle_handshake()) { $var(count) = $shtinc(websockets=>$var(ws_orig_ip)::count); + $sht(websockets=>$ws_conid::ws_orig_ip) = $var(ws_orig_ip); if($si != $var(ws_orig_ip)) { $var(proxy_count) = $shtinc(websockets=>$si::count); xlog("L_INFO", "websocket|log|opened proxied websocket $ws_conid from $si for $var(ws_orig_ip):$sp\n"); - $sht(websockets=>$ws_conid::ws_orig_ip) = $var(ws_orig_ip); } else { xlog("L_INFO", "websocket|log|opened websocket $ws_conid from $var(ws_orig_ip):$sp\n"); } From 01587b98c6b08cb0224ae2bc958ddc60b58d5975 Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 27 Feb 2019 18:25:58 +0000 Subject: [PATCH 120/209] tls mod_level and low_mem --- kamailio/tls-role.cfg | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kamailio/tls-role.cfg b/kamailio/tls-role.cfg index b1ea5ba..df6507e 100644 --- a/kamailio/tls-role.cfg +++ b/kamailio/tls-role.cfg @@ -6,4 +6,8 @@ listen=TLS_ALG_SIP ####### TLS Parameters ######### loadmodule "tls.so" modparam("tls", "config", "/etc/kazoo/kamailio/tls.cfg") -modparam("tls", "low_mem_threshold1", 0) +modparam("tls", "low_mem_threshold1", 1) +modparam("tls", "low_mem_threshold2", 1) + +modparam("debugger", "mod_level", "tls=1") + From 40c2aa04a5254f2cd3e8edfd1f600793020b34f5 Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 27 Feb 2019 18:26:18 +0000 Subject: [PATCH 121/209] antiflood def moved --- kamailio/defs.cfg | 4 ---- 1 file changed, 4 deletions(-) diff --git a/kamailio/defs.cfg b/kamailio/defs.cfg index c406ea7..c9a3ddd 100644 --- a/kamailio/defs.cfg +++ b/kamailio/defs.cfg @@ -47,10 +47,6 @@ #!trydef CHILDREN 25 #!trydef TCP_CHILDREN 25 -#!ifndef ANTIFLOOD_CACHE_PERIOD -#!substdef "!ANTIFLOOD_CACHE_PERIOD!600!g" -#!endif - #!include_file "defs-amqp.cfg" #!ifndef MEDIA_SERVERS_HASH_SIZE From c8d71a1e706cd19541c005fc5c507f9044c1839d Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 27 Feb 2019 18:27:07 +0000 Subject: [PATCH 122/209] define L_DEBUG --- kamailio/kamailio.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/kamailio/kamailio.cfg b/kamailio/kamailio.cfg index bf27b31..1964c03 100644 --- a/kamailio/kamailio.cfg +++ b/kamailio/kamailio.cfg @@ -10,6 +10,7 @@ #!define L_NOTICE 1 #!define L_INFO 2 #!define L_DBG 3 +#!define L_DEBUG 4 #!define AVP_RECV_PARAM "recv_param" #!define AVP_LOG_LEVEL "log_level" From d48e0f2910d760dc9cad1ab98aa2d2feeef54b53 Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 27 Feb 2019 18:27:50 +0000 Subject: [PATCH 123/209] add empty line for better viewing --- kamailio/db_queries_kazoo.cfg | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kamailio/db_queries_kazoo.cfg b/kamailio/db_queries_kazoo.cfg index 7ce9458..9135825 100644 --- a/kamailio/db_queries_kazoo.cfg +++ b/kamailio/db_queries_kazoo.cfg @@ -1,8 +1,10 @@ ####### Database queries ######## #!substdef "!KZQ_CHECK_MEDIA_SERVER_INSERT!insert into dispatcher (setid, destination, flags, attrs, description) select \$var(SetId), \"\$var(MediaUrl)\", \$var(flags), \"\$var(attrs)\", \"added by nodes role\" where not exists(select * from dispatcher where destination = \"\$var(MediaUrl)\")!g" #!substdef "!KZQ_COUNT_ALL_SUBSCRIBERS!select a.event, count(distinct watcher_username || \"@\" || watcher_domain) count_unique, count(*) count from event_list a, active_watchers b where b.event = a.event group by a.event!g" + #!substdef "!KZQ_COUNT_PRESENTITIES!select event, (select count(*) from presentity b where username = \"\$(var(payload){kz.json,From}{uri.user})\" and domain = \"\$(var(payload){kz.json,From}{uri.domain})\" and b.event = a.event) count from event_list a!g" #!substdef "!KZQ_COUNT_SUBSCRIBERS!select event, (select count(*) from active_watchers b where presentity_uri = \"\$var(presentity)\" and b.event = a.event) count from event_list a union select \"self\", count(distinct callid) from presentities where presentity_uri = \"\$var(presentity)\" and state in('early', 'confirmed', 'onthephone', 'busy')!g" + #!substdef "!KZQ_EVENT_PRESENCE_RESET_DELETE!delete from presentity where domain=\"\$(kzE{kz.json,Realm})\" and username = \"\$(kzE{kz.json,Username})\"!g" #!substdef "!KZQ_HANDLE_NEW_SUBSCRIBE_DELETE1!delete from active_watchers where callid = \"\$ci\"!g" #!substdef "!KZQ_HANDLE_NEW_SUBSCRIBE_DELETE2!delete from active_watchers where watcher_username=\"\$fU\" and presentity_uri=\"\$var(presentity_uri)\" and to_user=\"\$tU\" and watcher_domain=\"\$fd\" and event=\"\$hdr(Event)\"!g" From b7d4f44a77f96c50006e933c3d6e0786fb9e9d50 Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 27 Feb 2019 18:37:38 +0000 Subject: [PATCH 124/209] nat keepalive options --- kamailio/presence-notify.cfg | 2 +- kamailio/presence-role.cfg | 16 ++++++++-------- kamailio/registrar-role.cfg | 23 ++++++++++------------- 3 files changed, 19 insertions(+), 22 deletions(-) diff --git a/kamailio/presence-notify.cfg b/kamailio/presence-notify.cfg index 7d480d0..2d9e214 100644 --- a/kamailio/presence-notify.cfg +++ b/kamailio/presence-notify.cfg @@ -1,5 +1,5 @@ kazoo.presence_notify = 1 descr "enable/disable sending notify callback to omnipresence" -kazoo.presence_notify_timeout = 3000 descr "timeout in ms waiting for notify reply" +kazoo.presence_notify_timeout = 3500 descr "timeout in ms waiting for notify reply" kazoo.presence_notify_log_body = 0 descr "logs the body sent in the notification" kazoo.presence_notify_log_resp_body = 0 descr "logs the body received from notification" kazoo.presence_notify_log_to_table = 1 descr "logs notify/reply to active_watchers_log table" diff --git a/kamailio/presence-role.cfg b/kamailio/presence-role.cfg index 6081711..d0101d2 100644 --- a/kamailio/presence-role.cfg +++ b/kamailio/presence-role.cfg @@ -4,19 +4,14 @@ #!trydef PRESENCE_MAX_EXPIRES 3600 #!trydef KZ_PRESENCE_IGNORE_STATUS_PROBE_RESP 1 - #!trydef KZ_PRESENCE_CSEQ_OFFSET 2 - #!trydef KZ_PRESENCE_MAX_CALL_PER_PRESENTITY 20 - #!trydef BLF_USE_SINGLE_DIALOG 1 - #!trydef KZ_PRESENCE_AMQP_PUBLISH 0 - #!trydef KZ_PRESENCE_REQUEST_RESUBSCRIBE_PROBE 0 #!trydef KZ_PRESENCE_REQUEST_PROBE 1 - #!trydef KZ_PRESENCE_NO_TARGETS_LOG_LEVEL L_DBG +#!trydef KZ_PRESENCE_KEEPALIVE_UDP_ONLY 0 modparam("htable", "htable", "p=>size=32;autoexpire=3600;") modparam("htable", "htable", "first=>size=32;autoexpire=3600;initval =0;updateexpire=1;") @@ -76,6 +71,7 @@ kazoo.presence_request_resubscribe_probe = KZ_PRESENCE_REQUEST_RESUBSCRIBE_PROBE kazoo.presence_ignore_status_probe_resp = KZ_PRESENCE_IGNORE_STATUS_PROBE_RESP descr "ignore online/offline probe replies" kazoo.presence_max_call_per_presentity = KZ_PRESENCE_MAX_CALL_PER_PRESENTITY descr "max number of calls per presentity" kazoo.presence_no_targets_log_level = KZ_PRESENCE_NO_TARGETS_LOG_LEVEL descr "when a presence event is received and there no targets we can log at another level" +kazoo.presence_keepalive_udp_only = KZ_PRESENCE_KEEPALIVE_UDP_ONLY descr "should we keepalive nat phones for udp only" #!include_file "presence-query.cfg" #!include_file "presence-notify.cfg" @@ -87,8 +83,12 @@ kazoo.presence_no_targets_log_level = KZ_PRESENCE_NO_TARGETS_LOG_LEVEL descr "wh #!ifdef NAT_TRAVERSAL_ROLE route[PRESENCE_NAT] { - if (isflagset(FLT_NATS) && proto==UDP) { - nat_keepalive(); + if (isflagset(FLT_NATS)) { + if(!( ($sel(cfg_get.kazoo.presence_keepalive_udp_only) == 1 && $proto != "udp") + || ($proto =="ws" || $proto == "wss") + )) { + nat_keepalive(); + } } } #!endif diff --git a/kamailio/registrar-role.cfg b/kamailio/registrar-role.cfg index 0ecedf3..4acf6c1 100644 --- a/kamailio/registrar-role.cfg +++ b/kamailio/registrar-role.cfg @@ -16,19 +16,16 @@ #!trydef REGISTRAR_CONTACT_MAX_SIZE 2048 #!trydef REGISTRAR_QUERY_TIMEOUT_MS 2500 - #!trydef REGISTRAR_HANDLE_LOST_TCP 1 #!trydef REGISTRAR_CLOSE_EXPIRED_TCP 1 - #!trydef REGISTRAR_HANDLE_EXPIRED_TCP 1 #!trydef REGISTRAR_HANDLE_EXPIRED_UDP 0 #!trydef REGISTRAR_HANDLE_EXPIRED_TLS 1 #!trydef REGISTRAR_HANDLE_EXPIRED_WS 1 - #!trydef REGISTRAR_FORCE_QUERY 0 #!trydef REGISTRAR_FORCE_FAILOVER 0 - #!trydef REGISTRAR_CHECK_AMQP_AVAILABILITY 1 +#!trydef KZ_REGISTRAR_KEEPALIVE_UDP_ONLY 0 ######## Generic Hash Table container in shared memory ######## modparam("htable", "htable", "auth_cache=>size=16;autoexpire=7200;") @@ -84,21 +81,18 @@ modparam("registrar", "received_param", "") modparam("registrar", "xavp_rcd", "ulrcd") modparam("registrar", "contact_max_size", REGISTRAR_CONTACT_MAX_SIZE) +##### registrar realtime params ##### kazoo.registrar_error_min_expires = REGISTRAR_ERROR_MIN_EXPIRES descr "send error when UAS sends expires < min-expires" kazoo.registrar_error_missing_expires = REGISTRAR_ERROR_MISSING_EXPIRES descr "send error when UAS do not send expires header" - -##### handle expired registrations realtime params ##### kazoo.registrar_handle_expired_tcp = REGISTRAR_HANDLE_EXPIRED_TCP descr "handles expired tcp registrations" kazoo.registrar_handle_expired_udp = REGISTRAR_HANDLE_EXPIRED_UDP descr "handles expired udp registrations" kazoo.registrar_handle_expired_tls = REGISTRAR_HANDLE_EXPIRED_TLS descr "handles expired tls registrations" kazoo.registrar_handle_expired_ws = REGISTRAR_HANDLE_EXPIRED_WS descr "handles expired ws registrations" - kazoo.registrar_query_timeout_ms = REGISTRAR_QUERY_TIMEOUT_MS descr "timeout waiting for reply from registrar" - kazoo.registrar_failover = REGISTRAR_FORCE_FAILOVER descr "force failover if 1" kazoo.registrar_force_query = REGISTRAR_FORCE_QUERY descr "force query if 1" kazoo.registrar_check_amqp_availability = REGISTRAR_CHECK_AMQP_AVAILABILITY descr "checks if amqp connection is available before querying registrar" - +kazoo.registrar_keepalive_udp_only = KZ_REGISTRAR_KEEPALIVE_UDP_ONLY descr "should we keepalive nat phones for udp only" ####### Registrar Logic ######## @@ -113,7 +107,8 @@ route[REGISTRAR_NAT] if (!($ua =~ "Linksys/SPA8000" || $ua =~ "SIPp" || (af==INET6) - || (proto!=UDP) + || ($sel(cfg_get.kazoo.registrar_keepalive_udp_only) == 1 && $proto != "udp") + || ($proto =="ws" || $proto == "wss") || ($(xavp(ulattrs=>custom_channel_vars){kz.json,Keep-Alive}) == "false") )) { xlog("L_DEBUG", "$ci|log|set nat pinging\n"); @@ -196,7 +191,7 @@ route[HANDLE_REGISTER] failure_route[KZ_AUTHORIZATION_TIMEOUT] { - xlog("L_INFO", "$ci|log|failed $T_reply_code to query Kazoo for authentication credentials for $Au $si:$sp\n"); + xlog("L_INFO", "$ci|end|failed $T_reply_code querying directory for authentication credentials for $Au $si:$sp\n"); t_drop(); } @@ -404,12 +399,14 @@ route[REGISTRAR_BOUNDS] } if($var(expires) != 0) { - if($sel(cfg_get.kazoo.registrar_error_min_expires) == 1) { - if($var(expires) < REGISTRAR_MIN_EXPIRES) { + if($var(expires) < REGISTRAR_MIN_EXPIRES) { + if($sel(cfg_get.kazoo.registrar_error_min_expires) == 1) { xlog("L_WARNING", "$ci|end|expires $var(expires) too brief (configured $def(REGISTRAR_MIN_EXPIRES)) registering $Au from IP $si:$sp\n"); append_to_reply("Min-Expires: $def(REGISTRAR_MIN_EXPIRES)\r\n"); send_reply("423", "Interval Too Brief"); exit; + } else { + xlog("L_WARNING", "$ci|end|allowing expires $var(expires) too brief (configured $def(REGISTRAR_MIN_EXPIRES)) registering $Au from IP $si:$sp\n"); } } } From 774cb1315414e37293e153e0b53b68a9670125d2 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 28 Feb 2019 01:46:33 +0000 Subject: [PATCH 125/209] move auth headers to own file --- kamailio/auth.cfg | 95 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 kamailio/auth.cfg diff --git a/kamailio/auth.cfg b/kamailio/auth.cfg new file mode 100644 index 0000000..df389a2 --- /dev/null +++ b/kamailio/auth.cfg @@ -0,0 +1,95 @@ + + +route[AUTH] +{ + if (!is_method("INVITE|MESSAGE|REFER")) { + return; + } + + #!ifdef DISPATCHER_ROLE + if (!isflagset(FLAG_INTERNALLY_SOURCED)) { + route(SETUP_AUTH_HEADERS); + } + #!endif +} + +route[AUTH_HEADERS] +{ + remove_hf_re("^X-"); + + xavp_params_implode("hf", "$var(outx)"); + $var(out) = $(var(outx){re.subst,/^(.*);$$/\1/}); + $var(c) = $(var(out){param.count}); + xlog("L_DEBUG", "$ci|auth|headers $var(c) => $var(out) => $var(outx)\n"); + while($var(c) > 0) { + $var(idx) = $var(c) - 1; + xlog("L_DEBUG", "$ci|auth|adding $(var(out){param.name,$var(idx)}): $(var(out){param.valueat,$var(idx)})\n"); + append_hf("$(var(out){param.name,$var(idx)}): $(var(out){param.valueat,$var(idx)})\r\n"); + $var(c) = $var(c) - 1; + } + +} + +route[SETUP_AUTH_HEADERS] +{ + + $xavp(hf=>X-AUTH-IP) = $si; + $xavp(hf[0]=>X-AUTH-PORT) = $sp; + + #!ifdef REGISTRAR_ROLE + #!ifdef WITH_AUTH_TOKEN + route(AUTH_TOKEN); + #!else + route(AUTH_CCVS); + #!endif + #!endif + +} + +route[AUTH_TOKEN] +{ + $xavp(regcfg=>match_received) = $su; + if (registered("location","$fu", 2, 1) == 1) { + dlg_setflag(FLT_AOR); + if($(xavp(ulattrs=>token){s.len}) > 0) { + $xavp(hf[0]=>X-AUTH-Token) = $xavp(ulattrs=>token); + } else { + if($(xavp(ulattrs=>Authorizing-ID){s.len}) > 0 && $(xavp(ulattrs=>Account-ID){s.len})) { + $xavp(hf[0]=>X-AUTH-Token) = $_s("$xavp(ulattrs=>Authorizing-ID)@$xavp(ulattrs=>Account-ID)"); + } + } + } +} + +route[AUTH_CCVS] +{ + $xavp(regcfg=>match_received) = $su; + if (registered("location","$fu", 2, 1) == 1) { + if($(xavp(ulattrs=>custom_channel_vars){kz.json,Account-ID}{s.len}) > 0) + $xavp(hf[0]=>X-ecallmgr_Account-ID) = $(xavp(ulattrs=>custom_channel_vars){kz.json,Account-ID}); + + if($(xavp(ulattrs=>custom_channel_vars){kz.json,Authorizing-Type}{s.len}) > 0) + $xavp(hf[0]=>X-ecallmgr_Authorizing-Type) = $(xavp(ulattrs=>custom_channel_vars){kz.json,Authorizing-Type}); + + if($(xavp(ulattrs=>custom_channel_vars){kz.json,Authorizing-ID}{s.len}) > 0) + $xavp(hf[0]=>X-ecallmgr_Authorizing-ID) = $(xavp(ulattrs=>custom_channel_vars){kz.json,Authorizing-ID}); + + if($(xavp(ulattrs=>custom_channel_vars){kz.json,Username}{s.len}) > 0) + $xavp(hf[0]=>X-ecallmgr_Username) = $(xavp(ulattrs=>custom_channel_vars){kz.json,Username}); + + if($(xavp(ulattrs=>custom_channel_vars){kz.json,Realm}{s.len}) > 0) + $xavp(hf[0]=>X-ecallmgr_Realm) = $(xavp(ulattrs=>custom_channel_vars){kz.json,Realm}); + + if($(xavp(ulattrs=>custom_channel_vars){kz.json,Account-Realm}{s.len}) > 0) + $xavp(hf[0]=>X-ecallmgr_Account-Realm) = $(xavp(ulattrs=>custom_channel_vars){kz.json,Account-Realm}); + + if($(xavp(ulattrs=>custom_channel_vars){kz.json,Account-Name}{s.len}) > 0) + $xavp(hf[0]=>X-ecallmgr_Account-Name) = $(xavp(ulattrs=>custom_channel_vars){kz.json,Account-Name}); + + if($(xavp(ulattrs=>custom_channel_vars){kz.json,Presence-ID}{s.len}) > 0) + $xavp(hf[0]=>X-ecallmgr_Presence-ID) = $(xavp(ulattrs=>custom_channel_vars){kz.json,Presence-ID}); + + if($(xavp(ulattrs=>custom_channel_vars){kz.json,Owner-ID}{s.len}) > 0) + $xavp(hf[0]=>X-ecallmgr_Owner-ID) = $(xavp(ulattrs=>custom_channel_vars){kz.json,Owner-ID}); + } +} From bc336505d19a49f9e9e058b7e20ac2d55ce23457 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 28 Feb 2019 01:57:41 +0000 Subject: [PATCH 126/209] setup route & auth --- kamailio/auth.cfg | 4 ++ kamailio/default.cfg | 127 +++++++++++++------------------------------ 2 files changed, 43 insertions(+), 88 deletions(-) diff --git a/kamailio/auth.cfg b/kamailio/auth.cfg index df389a2..783e3da 100644 --- a/kamailio/auth.cfg +++ b/kamailio/auth.cfg @@ -46,6 +46,8 @@ route[SETUP_AUTH_HEADERS] } +#!ifdef REGISTRAR_ROLE + route[AUTH_TOKEN] { $xavp(regcfg=>match_received) = $su; @@ -93,3 +95,5 @@ route[AUTH_CCVS] $xavp(hf[0]=>X-ecallmgr_Owner-ID) = $(xavp(ulattrs=>custom_channel_vars){kz.json,Owner-ID}); } } + +#!endif diff --git a/kamailio/default.cfg b/kamailio/default.cfg index 45bf547..20c727d 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -299,6 +299,9 @@ include_file "nodes-role.cfg" include_file "sip_trace-role.cfg" #!endif +## auth ## +include_file "auth.cfg" + ####### Permissions module ########## loadmodule "permissions.so" @@ -373,13 +376,10 @@ route } #!endif - #!ifdef DISPATCHER_ROLE - if (!isflagset(FLAG_INTERNALLY_SOURCED)) { - route(DISPATCHER_FIND_ROUTES); - } - #!endif + route(AUTH); + + route(SETUP); - route(RELAY); } #!trydef KZ_LOG_REQUEST_OPTIONS 0 @@ -502,7 +502,7 @@ route[HANDLE_MESSAGE] exit(); #!endif } else { - xlog("L_WARN", "$ci|end|MESSAGE $(hdr(Content-Type))\n"); + xlog("L_WARN", "$ci|end|MESSAGE $hdr(Content-Type)\n"); if( $hdr(Content-Type) == "application/im-iscomposing+xml" ) { xlog("L_WARN", "$ci|end|dropping MESSAGE application/im-iscomposing+xml\n"); sl_send_reply("200", "OK"); @@ -634,17 +634,46 @@ route[PREPARE_INITIAL_REQUESTS] record_route(); } +route[SETUP] +{ + #!ifdef DISPATCHER_ROLE + if (!isflagset(FLAG_INTERNALLY_SOURCED)) { + route(DISPATCHER_FIND_ROUTES); + } + #!endif + + #!ifdef REGISTRAR_ROLE + if (isflagset(FLAG_INTERNALLY_SOURCED)) { + route(ROUTE_TO_AOR); + } + #!endif + + route(RELAY); +} + +route[BRANCH_HEADERS] +{ + if (!isflagset(FLAG_INTERNALLY_SOURCED)) { + route(AUTH_HEADERS); + } else { + remove_hf_re("^X-"); + } + +} + # Manage outgoing branches branch_route[MANAGE_BRANCH] { - xlog("L_DEBUG", "$ci|branch|new branch [$T_branch_idx] to $ru\n"); + xlog("L_DEBUG", "$ci|branch|new branch [$T_branch_idx] to $ru => $du\n"); #!ifdef NAT_TRAVERSAL_ROLE route(NAT_MANAGE); #!endif + + route(BRANCH_HEADERS); + } route[RELAY] { - if (is_method("INVITE|BYE|SUBSCRIBE|UPDATE")) { if(!t_is_set("branch_route")) t_on_branch("MANAGE_BRANCH"); } @@ -671,11 +700,6 @@ route[INTERNAL_TO_EXTERNAL_RELAY] } #!endif - #!ifdef REGISTRAR_ROLE - route(ROUTE_TO_AOR); - #!endif - - remove_hf_re("^X-.*"); t_on_reply("EXTERNAL_REPLY"); @@ -693,15 +717,6 @@ 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 - t_on_reply("INTERNAL_REPLY"); t_on_failure("INTERNAL_FAULT"); @@ -824,7 +839,7 @@ failure_route[INTERNAL_FAULT] xlog("L_INFO", "$ci|log|failure route ignoring failure after session progress\n"); } else if (t_check_status("403") && $T_reply_reason=="Forbidden") { xlog("L_WARNING", "$ci|log|failure route ignoring. Failed auth from IP $si\n"); - } else if (t_check_status("(401)|(407)|(486)|(403)")) { + } else if (t_check_status("(401)|(407)|(486)")) { xlog("L_INFO", "$ci|log|failure route ignoring auth reply $T_reply_code $T_reply_reason\n"); } else if (t_check_status("402")) { xlog("L_INFO", "$ci|log|failure route overriding reply code 402 with 486\n"); @@ -908,70 +923,6 @@ route[ROUTE_TO_AOR] } } - -#!ifdef REGISTRAR_ROLE - -#!ifdef WITH_AUTH_TOKEN -route[ADD_AUTHORIZATION_HEADERS] -{ - if (!is_method("INVITE|MESSAGE|REFER")) { - return; - } - - $xavp(regcfg=>match_received) = $su; - if (registered("location","$fu", 2, 1) == 1) { - if($(xavp(ulattrs=>token){s.len}) > 0) { - append_hf("X-AUTH-Token: $xavp(ulattrs=>token)\r\n"); - } else { - if($(xavp(ulattrs=>Authorizing-ID){s.len}) > 0 && $(xavp(ulattrs=>Account-ID){s.len})) { - append_hf("X-AUTH-Token: $xavp(ulattrs=>Authorizing-ID)@$xavp(ulattrs=>Account-ID)\r\n"); - } - } - } -} - -#!else - -route[ADD_AUTHORIZATION_HEADERS] -{ - if (!is_method("INVITE|MESSAGE|REFER")) { - return; - } - - $xavp(regcfg=>match_received) = $su; - if (registered("location","$fu", 2, 1) == 1) { - if($(xavp(ulattrs=>custom_channel_vars){kz.json,Account-ID}{s.len}) > 0) - append_hf("X-ecallmgr_Account-ID: $(xavp(ulattrs=>custom_channel_vars){kz.json,Account-ID})\r\n"); - - if($(xavp(ulattrs=>custom_channel_vars){kz.json,Authorizing-Type}{s.len}) > 0) - append_hf("X-ecallmgr_Authorizing-Type: $(xavp(ulattrs=>custom_channel_vars){kz.json,Authorizing-Type})\r\n"); - - if($(xavp(ulattrs=>custom_channel_vars){kz.json,Authorizing-ID}{s.len}) > 0) - append_hf("X-ecallmgr_Authorizing-ID: $(xavp(ulattrs=>custom_channel_vars){kz.json,Authorizing-ID})\r\n"); - - if($(xavp(ulattrs=>custom_channel_vars){kz.json,Username}{s.len}) > 0) - append_hf("X-ecallmgr_Username: $(xavp(ulattrs=>custom_channel_vars){kz.json,Username})\r\n"); - - if($(xavp(ulattrs=>custom_channel_vars){kz.json,Realm}{s.len}) > 0) - append_hf("X-ecallmgr_Realm: $(xavp(ulattrs=>custom_channel_vars){kz.json,Realm})\r\n"); - - if($(xavp(ulattrs=>custom_channel_vars){kz.json,Account-Realm}{s.len}) > 0) - append_hf("X-ecallmgr_Account-Realm: $(xavp(ulattrs=>custom_channel_vars){kz.json,Account-Realm})\r\n"); - - if($(xavp(ulattrs=>custom_channel_vars){kz.json,Account-Name}{s.len}) > 0) - append_hf("X-ecallmgr_Account-Name: $(xavp(ulattrs=>custom_channel_vars){kz.json,Account-Name})\r\n"); - - if($(xavp(ulattrs=>custom_channel_vars){kz.json,Presence-ID}{s.len}) > 0) - append_hf("X-ecallmgr_Presence-ID: $(xavp(ulattrs=>custom_channel_vars){kz.json,Presence-ID})\r\n"); - - if($(xavp(ulattrs=>custom_channel_vars){kz.json,Owner-ID}{s.len}) > 0) - append_hf("X-ecallmgr_Owner-ID: $(xavp(ulattrs=>custom_channel_vars){kz.json,Owner-ID})\r\n"); - } -} -#!endif - -#!endif - event_route[tm:local-request] { setflag(FLAG_LOCAL_REQUEST); From d46a691c924ee1f090981af5a220ad2c0530cebc Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 28 Feb 2019 02:01:08 +0000 Subject: [PATCH 127/209] fix relay in dispatcher --- kamailio/dispatcher-role.cfg | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/kamailio/dispatcher-role.cfg b/kamailio/dispatcher-role.cfg index b9afffe..46bd6b4 100644 --- a/kamailio/dispatcher-role.cfg +++ b/kamailio/dispatcher-role.cfg @@ -233,12 +233,8 @@ route[DISPATCHER_NEXT_ROUTE] # reset the final reply timer $avp(final_reply_timer) = 3; - t_on_reply("INTERNAL_REPLY"); - - t_on_failure("INTERNAL_FAULT"); - # relay the request to the new media server - route(EXTERNAL_TO_INTERNAL_RELAY); + route(RELAY); exit(); } From d9ed5cebaf85e04241d2589fd4c0d79298061a06 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 28 Feb 2019 05:23:59 +0000 Subject: [PATCH 128/209] presence notify logging --- kamailio/presence-notify.cfg | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/kamailio/presence-notify.cfg b/kamailio/presence-notify.cfg index 2d9e214..bd99b01 100644 --- a/kamailio/presence-notify.cfg +++ b/kamailio/presence-notify.cfg @@ -72,15 +72,15 @@ event_route[presence:notify-reply] } else { if($rP != "UDP") { $xavp(pres=>delete_subscription) = 1; - xlog("L_ERROR", "$ci|error|removing $rP watcher $subs(watcher_username)@$subs(watcher_domain) for $subs(pres_uri) with reason $subs(reason) and reply $notify_reply($rs)\n"); + xlog("L_ERROR", "$ci|error|removing $rP watcher $subs(watcher_username)@$subs(watcher_domain) for $subs(pres_uri) with reply $notify_reply($rs)\n"); } else { $var(shtinc) = $shtinc(notify=>$ci::count); if($var(shtinc) > MAX_NOTIFY_ERROR) { $xavp(pres=>delete_subscription) = 1; - xlog("L_ERROR", "$ci|error|removing $rP watcher $subs(watcher_username)@$subs(watcher_domain) for $subs(pres_uri) with reason $subs(reason) and reply $notify_reply($rs)\n"); + xlog("L_ERROR", "$ci|error|removing $rP watcher $subs(watcher_username)@$subs(watcher_domain) for $subs(pres_uri) with reply $notify_reply($rs)\n"); } else { - $var(max_notify) = MAX_NOTIFY_ERROR; - xlog("L_WARN", "$ci|error|received $notify_reply($rs) ($var(shtinc)/$var(max_notify)) when notifying $subs(watcher_username)@$subs(watcher_domain) on behalf of $subs(pres_uri) with reason $subs(reason) and reply $notify_reply($rs)\n"); + $var(level) = 4 - $var(shtinc); + xlog("$var(level)", "$ci|error|received $notify_reply($rs) ($var(shtinc)/$def(MAX_NOTIFY_ERROR)) when notifying $subs(watcher_username)@$subs(watcher_domain) on behalf of $subs(pres_uri) with reply $notify_reply($rs)\n"); } } } From dc011abca52bb509a99ca762832d177f18681712 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 28 Feb 2019 06:48:45 +0000 Subject: [PATCH 129/209] remove dlg from auth --- kamailio/auth.cfg | 1 - 1 file changed, 1 deletion(-) diff --git a/kamailio/auth.cfg b/kamailio/auth.cfg index 783e3da..1313be2 100644 --- a/kamailio/auth.cfg +++ b/kamailio/auth.cfg @@ -52,7 +52,6 @@ route[AUTH_TOKEN] { $xavp(regcfg=>match_received) = $su; if (registered("location","$fu", 2, 1) == 1) { - dlg_setflag(FLT_AOR); if($(xavp(ulattrs=>token){s.len}) > 0) { $xavp(hf[0]=>X-AUTH-Token) = $xavp(ulattrs=>token); } else { From 7e61d706cb4d3fe4042bd00159ecebf4dbd810c0 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 28 Feb 2019 06:49:26 +0000 Subject: [PATCH 130/209] granular reply configuration for presence query --- kamailio/presence-query.cfg | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/kamailio/presence-query.cfg b/kamailio/presence-query.cfg index 9894e15..95fa96d 100644 --- a/kamailio/presence-query.cfg +++ b/kamailio/presence-query.cfg @@ -1,5 +1,8 @@ ######## Presence query server module ######## +#!trydef KZ_PRESENCE_QUERY_REPLY_ZONES 0 +kazoo.presence_query_reply_zones = KZ_PRESENCE_QUERY_REPLY_ZONES descr "0 - all, 1 - local, 2 - remote" + route[PRESENCE_SEARCH_SUMMARY] { xlog("L_INFO", "$(kzE{kz.json,Msg-ID})|query|processing presence summary query for $(kzE{kz.json,Realm})\n"); @@ -88,19 +91,22 @@ route[PRESENCE_SEARCH_DETAIL] } - - event_route[kazoo:consumer-event-presence-search-req] { - switch($(kzE{kz.json,Search-Type})) { - case "summary": - route(PRESENCE_SEARCH_SUMMARY); - break; - case "detail": - route(PRESENCE_SEARCH_DETAIL); - break; - default: - xlog("L_INFO", "$ci|search type '$(kzE{kz.json,Search-Type})' not handled\n"); + $var(Zone) = $(kzE{kz.json,AMQP-Broker-Zone}); + if( ($var(Zone) == "MY_AMQP_ZONE" && $sel(cfg_get.kazoo.presence_query_reply_zones) != 2) || + ($var(Zone) != "MY_AMQP_ZONE" && $sel(cfg_get.kazoo.presence_query_reply_zones) != 1)) { + + switch($(kzE{kz.json,Search-Type})) { + case "summary": + route(PRESENCE_SEARCH_SUMMARY); + break; + case "detail": + route(PRESENCE_SEARCH_DETAIL); + break; + default: + xlog("L_INFO", "$ci|search type '$(kzE{kz.json,Search-Type})' not handled\n"); + } } } From 723d19b28d371bfbe83dc1ed22a68cf99cf67d5c Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 28 Feb 2019 06:49:56 +0000 Subject: [PATCH 131/209] allow exchage configuration for registrar --- kamailio/registrar-role.cfg | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kamailio/registrar-role.cfg b/kamailio/registrar-role.cfg index 4acf6c1..9b0e3a0 100644 --- a/kamailio/registrar-role.cfg +++ b/kamailio/registrar-role.cfg @@ -26,6 +26,7 @@ #!trydef REGISTRAR_FORCE_FAILOVER 0 #!trydef REGISTRAR_CHECK_AMQP_AVAILABILITY 1 #!trydef KZ_REGISTRAR_KEEPALIVE_UDP_ONLY 0 +#!trydef REGISTRAR_AMQP_EXCHANGE callmgr ######## Generic Hash Table container in shared memory ######## modparam("htable", "htable", "auth_cache=>size=16;autoexpire=7200;") @@ -183,7 +184,7 @@ route[HANDLE_REGISTER] $avp(kz_timeout) = $sel(cfg_get.kazoo.registrar_query_timeout_ms); $xavp(deltas=>query) = $(TV(Sn){s.replace,.,}); - if(kazoo_async_query("callmgr", $var(amqp_routing_key), $var(amqp_payload_request), "KZ_AUTHORIZATION_REPLY", "KZ_AUTHORIZATION_TIMEOUT") != 1) { + if(kazoo_async_query("$def(REGISTRAR_AMQP_EXCHANGE)", $var(amqp_routing_key), $var(amqp_payload_request), "KZ_AUTHORIZATION_REPLY", "KZ_AUTHORIZATION_TIMEOUT") != 1) { xlog("L_INFO", "$ci|log|failed to send registrar query for authentication credentials for $Au $si:$sp\n"); t_drop(); } From ae4ced059eed7ea838b4390a0c2aa5033d6e8f55 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 28 Feb 2019 06:52:35 +0000 Subject: [PATCH 132/209] log call-id for park redirect --- kamailio/presence-fast-pickup.cfg | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/kamailio/presence-fast-pickup.cfg b/kamailio/presence-fast-pickup.cfg index af9f263..39d780d 100644 --- a/kamailio/presence-fast-pickup.cfg +++ b/kamailio/presence-fast-pickup.cfg @@ -61,7 +61,7 @@ route[PRESENCE_FAST_PICKUP_ATTEMPT] $du = $sht(fp=>$var(md5)); append_hf("Replaces: $var(replaced_call_id)$var(Pickup)\r\n"); xlog("L_INFO", "$ci|log|fast|found shortcut for call-id $var(replaced_call_id) , redirecting ($(ru{uri.user})) to $du\n"); - route(EXTERNAL_TO_INTERNAL_RELAY); + route(RELAY); exit(); } else { $var(replaced_call_id) = "none"; @@ -89,7 +89,7 @@ route[PRESENCE_FAST_PICKUP_ATTEMPT] remove_hf_re("^Replaces"); append_hf("Replaces: $var(rep)\r\n"); xlog("L_INFO", "$ci|log|call-id $var(replaced_call_id) found, redirecting call ($(ru{uri.user})) to $du => $var(rep)\n"); - route(EXTERNAL_TO_INTERNAL_RELAY); + route(RELAY); exit(); } else { xlog("L_WARN", "$ci|log|call-id $var(replaced_call_id) not found in cluster, proceeding with normal dispatch\n"); @@ -108,8 +108,8 @@ route[PRESENCE_FAST_PICKUP_ATTEMPT] $var(park) = $_s(*3$(ru{uri.user}{s.substr,2,0})@$(ru{uri.domain})); if($sht(park=>$var(park)) != $null) { $du = $sht(park=>$var(park)); - xlog("L_INFO", "$ci|log|redirecting park request to $du\n"); - route(EXTERNAL_TO_INTERNAL_RELAY); + xlog("L_INFO", "$ci|log|redirecting park request to $du , callid : $sht(park=>$var(park)::callid)\n"); + route(RELAY); exit(); } } @@ -117,8 +117,8 @@ route[PRESENCE_FAST_PICKUP_ATTEMPT] if($sht(park=>$(ru{uri.user})@$(ru{uri.domain})) != $null) { $du = $sht(park=>$(ru{uri.user})@$(ruri{uri.domain})); - xlog("L_INFO", "$ci|log|redirecting park request to $du\n"); - route(EXTERNAL_TO_INTERNAL_RELAY); + xlog("L_INFO", "$ci|log|redirecting park request to $du, callid: $sht(park=>$(ru{uri.user})@$(ruri{uri.domain})::callid)\n"); + route(RELAY); exit(); } @@ -135,7 +135,7 @@ route[PRESENCE_FAST_PICKUP_ATTEMPT] $du = $(kzR{kz.json,Channels[0].switch_url}); if($du != $null) { xlog("L_INFO", "$ci|log|redirecting park request to $du, courtesy of kazoo\n"); - route(EXTERNAL_TO_INTERNAL_RELAY); + route(RELAY); exit(); } } @@ -166,8 +166,10 @@ route[PRESENCE_FAST_PICKUP_INIT] if($var(AppName) == "park") { if($(kzE{kz.json,State}) == "terminated") { $sht(park=>$(kzE{kz.json,Presence-ID})) = $null; + $sht(park=>$(kzE{kz.json,Presence-ID})::callid) = $null; } else { $sht(park=>$(kzE{kz.json,Presence-ID})) = $(kzE{kz.json,Switch-URI}); + $sht(park=>$(kzE{kz.json,Presence-ID})::callid) = $(kzE{kz.json,Call-ID}); } } From b64508eca4d9feefdee3f412dd955add4d2ca2a1 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 28 Feb 2019 09:11:39 +0000 Subject: [PATCH 133/209] reply logs --- kamailio/default.cfg | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/kamailio/default.cfg b/kamailio/default.cfg index 20c727d..a686b05 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -727,7 +727,7 @@ route[EXTERNAL_TO_INTERNAL_RELAY] onreply_route[EXTERNAL_REPLY] { - xlog("L_INFO", "$ci|log|external reply $T_reply_code\n"); + xlog("L_INFO", "$ci|log|external reply $T_reply_code $T_reply_reason\n"); #!ifdef NAT_TRAVERSAL_ROLE if(status=~"[12][0-9][0-9]") { @@ -755,8 +755,10 @@ onreply_route[EXTERNAL_REPLY] onreply_route[INTERNAL_REPLY] { # this route handles replies that are comming from our media server - xlog("L_INFO", "$ci|start|received internal reply $T_reply_code $T_reply_reason\n"); - xlog("L_INFO", "$ci|log|source $si:$sp\n"); + if ($rs < 300) { + xlog("L_INFO", "$ci|log|internal reply $T_reply_code $T_reply_reason\n"); + xlog("L_DEBUG", "$ci|log|source $si:$sp\n"); + } #!ifdef NAT_TRAVERSAL_ROLE if(status=~"[12][0-9][0-9]") { @@ -828,32 +830,33 @@ failure_route[INTERNAL_FAULT] # change 6xx to 4xx if (t_check_status("6[0-9][0-9]") && !t_check_status("600|603|604|606")) { $var(new_code) = "4" + $(T_reply_code{s.substr,1,0}); - xlog("L_INFO", "$ci|log|sending 6XX reply as $var(new_code) $T_reply_reason\n"); + xlog("L_INFO", "$ci|failure|sending $T_reply_code reply as $var(new_code) $T_reply_reason\n"); t_reply("$(var(new_code){s.int})", "$T_reply_reason"); # if the failure case was something that we should recover # from then try to find a new media server } else if ($T_reply_reason =~ "call barred") { - xlog("L_INFO", "$ci|log|failure route ignoring call barred\n"); + xlog("L_INFO", "$ci|failure|ignoring call barred\n"); } else if (isflagset(FLAG_SESSION_PROGRESS)) { - xlog("L_INFO", "$ci|log|failure route ignoring failure after session progress\n"); + xlog("L_INFO", "$ci|failure|ignoring failure after session progress\n"); } else if (t_check_status("403") && $T_reply_reason=="Forbidden") { - xlog("L_WARNING", "$ci|log|failure route ignoring. Failed auth from IP $si\n"); + xlog("L_WARNING", "$ci|failure|Failed auth from IP $si\n"); } else if (t_check_status("(401)|(407)|(486)")) { - xlog("L_INFO", "$ci|log|failure route ignoring auth reply $T_reply_code $T_reply_reason\n"); + xlog("L_INFO", "$ci|failure|auth reply $T_reply_code $T_reply_reason\n"); } else if (t_check_status("402")) { - xlog("L_INFO", "$ci|log|failure route overriding reply code 402 with 486\n"); + xlog("L_INFO", "$ci|failure|overriding reply code 402 with 486\n"); send_reply("486", "Insufficient Funds"); } else if (t_check_status("(4[0-9][0-9])|(5[0-9][0-9])")) { - xlog("L_INFO", "$ci|start|received failure reply $T_reply_code $T_reply_reason\n"); + xlog("L_INFO", "$ci|failure|internal reply $T_reply_code $T_reply_reason\n"); #!ifdef DISPATCHER_ROLE route(DISPATCHER_NEXT_ROUTE); #!endif send_reply("486", "Unable to Comply"); + } else { - xlog("L_INFO", "$ci|log|failure route ignoring reply $T_reply_code $T_reply_reason\n"); + xlog("L_INFO", "$ci|failure|internal reply $T_reply_code $T_reply_reason\n"); send_reply("$T_reply_code", "$T_reply_reason"); } xlog("L_INFO", "$ci|pass|$si:$sp\n"); From 0e6d6651383041ed498eb4403d050b7800c67dc8 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 28 Feb 2019 16:14:23 +0000 Subject: [PATCH 134/209] websocket with proxy only connections --- kamailio/websockets-role.cfg | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/kamailio/websockets-role.cfg b/kamailio/websockets-role.cfg index 074f60f..df0c3e7 100644 --- a/kamailio/websockets-role.cfg +++ b/kamailio/websockets-role.cfg @@ -26,6 +26,7 @@ loadmodule "xhttp.so" #!trydef WS_MAX_CONNECTIONS_PER_IP 50 #!trydef WS_MAX_CONNECTIONS_PER_PROXY 0 #!trydef WS_ALLOWED_PROXIES "0.0.0.0/0" +#!trydef WS_CONNECTIONS_FROM_PROXY_ONLY 0 ######## Websocket module ######## loadmodule "websocket.so" @@ -41,6 +42,7 @@ modparam("websocket", "sub_protocols", 1) kazoo.ws_allowed_proxies = WS_ALLOWED_PROXIES desc "comma separated list of allowed proxies in cidr notation" kazoo.ws_max_connection_per_ip = WS_MAX_CONNECTIONS_PER_IP desc "max connections per ip" kazoo.ws_max_connection_per_proxy = WS_MAX_CONNECTIONS_PER_PROXY desc "max connections per proxy" +kazoo.ws_connections_via_proxy_only = WS_CONNECTIONS_FROM_PROXY_ONLY desc "only allow connections via proxy" event_route[xhttp:request] { @@ -80,7 +82,13 @@ event_route[xhttp:request] #!endif if ($hdr(X-Forwarded-For) == $null) { - $var(ws_orig_ip) = $si; + if($sel(cfg_get.kazoo.ws_connections_via_proxy_only) == 1) { + xlog("L_INFO", "websocket|log|request from $si without X-Forwarded-For Header and only allowed connections are via proxy\n"); + xhttp_reply("403", "Forbidden", "", ""); + exit; + } else { + $var(ws_orig_ip) = $si; + } } else { xlog("L_INFO", "websocket|log|request X-Forwarded-For $hdr(X-Forwarded-For) from $si\n"); $var(ws_orig_ip) = $hdr(X-Forwarded-For); From 80fbf77af5f506ad2a284089e594ed0dc45fe0a2 Mon Sep 17 00:00:00 2001 From: lazedo Date: Fri, 1 Mar 2019 19:57:43 +0000 Subject: [PATCH 135/209] registrar warm cache --- kamailio/db_scripts/check-kazoodb-sql.sh | 4 ++ kamailio/db_scripts/db_extra_check.sql | 3 ++ kamailio/registrar-role.cfg | 49 +++++++++++++++++------- 3 files changed, 42 insertions(+), 14 deletions(-) diff --git a/kamailio/db_scripts/check-kazoodb-sql.sh b/kamailio/db_scripts/check-kazoodb-sql.sh index 959be75..0937e3b 100755 --- a/kamailio/db_scripts/check-kazoodb-sql.sh +++ b/kamailio/db_scripts/check-kazoodb-sql.sh @@ -39,3 +39,7 @@ if [ -f ${DB_SCRIPT_DIR}/db_extra_check.sql ]; then . ${DB_SCRIPT_DIR}/db_extra_check.sql --source-only do_db_extra_check; fi + +for INIT in `ls ${DB_SCRIPT_DIR}/db_init_*.sql`; do + KazooDB -db ${DB_CURRENT_DB} < $INIT +done diff --git a/kamailio/db_scripts/db_extra_check.sql b/kamailio/db_scripts/db_extra_check.sql index 157d7bf..df1b7c8 100644 --- a/kamailio/db_scripts/db_extra_check.sql +++ b/kamailio/db_scripts/db_extra_check.sql @@ -1,6 +1,9 @@ do_db_extra_check() { +# warm cache +KazooDB -db ${DB_CURRENT_DB} "create table if not exists auth_cache as select * from htable;" + # location KazooDB -db ${DB_CURRENT_DB} "delete from location where socket not like 'udp:%';" KazooDB -db ${DB_CURRENT_DB} "delete from location where expires > 0 and datetime(expires) < datetime('now', '-30 seconds');" diff --git a/kamailio/registrar-role.cfg b/kamailio/registrar-role.cfg index 9b0e3a0..7708655 100644 --- a/kamailio/registrar-role.cfg +++ b/kamailio/registrar-role.cfg @@ -27,9 +27,18 @@ #!trydef REGISTRAR_CHECK_AMQP_AVAILABILITY 1 #!trydef KZ_REGISTRAR_KEEPALIVE_UDP_ONLY 0 #!trydef REGISTRAR_AMQP_EXCHANGE callmgr +#!trydef REGISTRAR_AMQP_FLAGS 0 +#!trydef REGISTRAR_AMQP_RK_PREFIX authn.req. +#!trydef REGISTRAR_SEND_100 1 + +#!ifdef REGISTRAR_WARM_CACHE +#!substdef "!REGISTRAR_S_WARM_CACHE!dbtable=auth_cache;dbmode=1;!g" +#!else +#!substdef "!REGISTRAR_S_WARM_CACHE!!g" +#!endif ######## Generic Hash Table container in shared memory ######## -modparam("htable", "htable", "auth_cache=>size=16;autoexpire=7200;") +modparam("htable", "htable", "auth_cache=>size=16;autoexpire=7200;REGISTRAR_S_WARM_CACHE") ####### Authentication Interface module ########## loadmodule "auth.so" @@ -94,6 +103,7 @@ kazoo.registrar_failover = REGISTRAR_FORCE_FAILOVER descr "force failover if 1" kazoo.registrar_force_query = REGISTRAR_FORCE_QUERY descr "force query if 1" kazoo.registrar_check_amqp_availability = REGISTRAR_CHECK_AMQP_AVAILABILITY descr "checks if amqp connection is available before querying registrar" kazoo.registrar_keepalive_udp_only = KZ_REGISTRAR_KEEPALIVE_UDP_ONLY descr "should we keepalive nat phones for udp only" +kazoo.registrar_send_100 = REGISTRAR_SEND_100 descr "should we send 100 reply while doing directory search" ####### Registrar Logic ######## @@ -153,9 +163,9 @@ route[HANDLE_REGISTER] drop; } - if($sel(cfg_get.kazoo.registrar_check_amqp_availability) == 1) { + if($sel(cfg_get.kazoo.registrar_check_amqp_availability) == 1) { if($xavp(amqpc=>default::MY_AMQP_ZONE) == 0) { - xlog("L_INFO", "$ci|log|register|no amqp connection available for default worker in zone MY_AMQP_ZONE\n"); + xlog("L_WARNING", "$ci|end|register|no amqp connection available for default worker in zone MY_AMQP_ZONE\n"); t_drop(); } } @@ -178,13 +188,17 @@ route[HANDLE_REGISTER] exit; } - sl_send_reply("100", "checking your credentials"); + if($sel(cfg_get.kazoo.registrar_send_100) == 1) { + sl_send_reply("100", "checking your credentials"); + } + $var(amqp_payload_request) = $_s({"Event-Category" : "directory" , "Event-Name" : "authn_req", "Method" : "REGISTER", "Auth-Nonce" : "$adn", "Auth-Realm" : "$fd", "Auth-User" : "$fU", "From" : "$fu", "To" : "$tu", "Orig-IP" : "$si", "Orig-Port" : "$sp", "User-Agent" : "$(ua{s.escape.common}{s.replace,\','}{s.replace,$$,})", "Contact" : "$(ct{s.escape.common}{s.replace,\','}{s.replace,$$,})", "Call-ID" : "$ci" }); - $var(amqp_routing_key) = "authn.req." + $(fd{kz.encode}); + $var(amqp_routing_key) = $_s($def(REGISTRAR_AMQP_RK_PREFIX)$(fd{kz.encode})); $avp(kz_timeout) = $sel(cfg_get.kazoo.registrar_query_timeout_ms); $xavp(deltas=>query) = $(TV(Sn){s.replace,.,}); - if(kazoo_async_query("$def(REGISTRAR_AMQP_EXCHANGE)", $var(amqp_routing_key), $var(amqp_payload_request), "KZ_AUTHORIZATION_REPLY", "KZ_AUTHORIZATION_TIMEOUT") != 1) { + xlog("L_DEBUG", "$ci|amqp|publishing to $def(REGISTRAR_AMQP_EXCHANGE) => $var(amqp_routing_key) : $def(REGISTRAR_AMQP_FLAGS) : $var(amqp_payload_request)\n"); + if(kazoo_async_query("$def(REGISTRAR_AMQP_EXCHANGE)", $var(amqp_routing_key), $var(amqp_payload_request), "KZ_AUTHORIZATION_REPLY", "KZ_AUTHORIZATION_TIMEOUT", "$def(REGISTRAR_AMQP_FLAGS)") != 1) { xlog("L_INFO", "$ci|log|failed to send registrar query for authentication credentials for $Au $si:$sp\n"); t_drop(); } @@ -192,7 +206,11 @@ route[HANDLE_REGISTER] failure_route[KZ_AUTHORIZATION_TIMEOUT] { - xlog("L_INFO", "$ci|end|failed $T_reply_code querying directory for authentication credentials for $Au $si:$sp\n"); + if($(kzR{kz.json,Event-Name}) == "message_returned" ) { + xlog("L_WARNING", "$ci|amqp|message was returned by broker $(kzR{kz.json,Error-Code}) $(kzR{kz.json,Error-Reason})\n"); + } else { + xlog("L_WARNING", "$ci|end|failed $T_reply_code $T_reply_reason querying directory for authentication credentials for $Au $si:$sp\n"); + } t_drop(); } @@ -205,15 +223,18 @@ onreply_route[KZ_AUTHORIZATION_REPLY] $var(password) = $(kzR{kz.json,Auth-Password}); $var(nonce) = $adn; if( $(kzR{kz.json,Event-Name}) == "authn_err" ) { - #!ifdef ANTIFLOOD_ROLE - route(ANITFLOOD_FAILED_AUTH); - #!endif - auth_challenge("$fd", "5"); - xlog("L_INFO", "$ci|end|challenging $Au $si:$sp via $(kzR{kz.json,App-Name})-$(kzR{kz.json,App-Version}) response\n"); - exit; - } else { + #!ifdef ANTIFLOOD_ROLE + route(ANITFLOOD_FAILED_AUTH); + #!endif + auth_challenge("$fd", "5"); + xlog("L_INFO", "$ci|end|challenging $Au $si:$sp via $(kzR{kz.json,App-Name})-$(kzR{kz.json,App-Version}) response\n"); + exit; + } else if( $(kzR{kz.json,Event-Name}) == "authn_resp" ) { xlog("L_INFO", "$ci|log|authenticating $Au via $(kzR{kz.json,App-Name})-$(kzR{kz.json,App-Version}) response\n"); route(CHECK_AUTHORIZATION); + } else { + xlog("L_INFO", "$ci|log|unhandle response from directory $Au via $(kzR{kz.json,App-Name})-$(kzR{kz.json,App-Version})\n"); + t_drop(); } } From 3e57a7d50c067d6ecc25ee3f51759c4eb7c61105 Mon Sep 17 00:00:00 2001 From: lazedo Date: Fri, 1 Mar 2019 21:56:24 +0000 Subject: [PATCH 136/209] log contact expiration --- kamailio/registrar-role.cfg | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kamailio/registrar-role.cfg b/kamailio/registrar-role.cfg index 7708655..89f035c 100644 --- a/kamailio/registrar-role.cfg +++ b/kamailio/registrar-role.cfg @@ -445,6 +445,7 @@ route[REGISTRAR_BOUNDS] event_route[usrloc:contact-expired] { ## return until we handle this in ecallmr + xlog("L_INFO", "$ulc(exp=>callid)|expired|removed registration for $ulc(exp=>aor) with contact : $ulc(exp=>addr)\n"); return; $var(transport) = $(ulc(exp=>received){uri.transport}); @@ -493,7 +494,7 @@ event_route[usrloc:contact-expired] kazoo_publish("registrar", $var(amqp_routing_key), $var(amqp_payload_request)); xlog("L_INFO", "$ulc(exp=>callid)|expired|notified registration removal with contact : $ulc(exp=>addr)\n"); } - xlog("L_INFO", "$ulc(exp=>callid)|expired|removed registration with contact : $ulc(exp=>addr)\n"); + xlog("L_INFO", "$ulc(exp=>callid)|expired|removed registration for $ulc(exp=>aor) with contact : $ulc(exp=>addr)\n"); } #!ifdef REGISTRAR_SYNC_ROLE From 99359c14f7963356ac90b5750f046dff8af5139c Mon Sep 17 00:00:00 2001 From: lazedo Date: Sat, 2 Mar 2019 00:15:25 +0000 Subject: [PATCH 137/209] include all sql files from shared dir --- kamailio/db_scripts/kazoodb-sql.sh | 42 +----------------------------- 1 file changed, 1 insertion(+), 41 deletions(-) diff --git a/kamailio/db_scripts/kazoodb-sql.sh b/kamailio/db_scripts/kazoodb-sql.sh index e4e36dd..2c07f39 100755 --- a/kamailio/db_scripts/kazoodb-sql.sh +++ b/kamailio/db_scripts/kazoodb-sql.sh @@ -7,47 +7,7 @@ RESULTED_SQL=${RESULTED_SQL:-/tmp/kamailio_initdb.sql} . $(dirname $0)/$DB_ENGINE-specific --source-only sql_filelist() { -cat << EOF -acc-create.sql -lcr-create.sql -domain-create.sql -group-create.sql -permissions-create.sql -registrar-create.sql -usrloc-create.sql -msilo-create.sql -alias_db-create.sql -uri_db-create.sql -speeddial-create.sql -avpops-create.sql -auth_db-create.sql -pdt-create.sql -dialog-create.sql -dispatcher-create.sql -dialplan-create.sql -topos-create.sql -presence-create.sql -rls-create.sql -imc-create.sql -cpl-create.sql -siptrace-create.sql -domainpolicy-create.sql -carrierroute-create.sql -userblacklist-create.sql -htable-create.sql -purple-create.sql -uac-create.sql -pipelimit-create.sql -mtree-create.sql -sca-create.sql -mohqueue-create.sql -rtpproxy-create.sql -uid_auth_db-create.sql -uid_avp_db-create.sql -uid_domain-create.sql -uid_gflags-create.sql -uid_uri_db-create.sql -EOF + echo `ls -A1 ${KAMAILIO_SHARE_DIR}/${DB_ENGINE}/*.sql | grep -v standard | tr '\n' '\0' | xargs -0 -n 1 basename | sort` } sql_all_header() { From 01bb28e22e9013568d303b6b4c19e9e74b0cc895 Mon Sep 17 00:00:00 2001 From: lazedo Date: Sat, 2 Mar 2019 02:50:15 +0000 Subject: [PATCH 138/209] add db_url to htable for registrar warm cache --- kamailio/default.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/kamailio/default.cfg b/kamailio/default.cfg index a686b05..7dce53c 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -159,6 +159,7 @@ loadmodule "sdpops.so" loadmodule "htable.so" modparam("htable", "htable", "associations=>size=16;autoexpire=7200") modparam("htable", "htable", "redirects=>size=16;autoexpire=5") +modparam("htable", "db_url", "KAZOO_DB_URL") ####### RTIMER module ########## loadmodule "rtimer.so" From 0f0a944e77359729b90b992bea56d4d949a038c0 Mon Sep 17 00:00:00 2001 From: lazedo Date: Mon, 4 Mar 2019 08:27:39 +0000 Subject: [PATCH 139/209] macros for tcp parameters --- kamailio/default.cfg | 16 ++++++++-------- kamailio/defs.cfg | 10 ++++++++++ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/kamailio/default.cfg b/kamailio/default.cfg index 7dce53c..cc97967 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -49,22 +49,22 @@ tos = IPTOS_LOWDELAY ####### TCP Parameters ######### tcp_children = TCP_CHILDREN disable_tcp = no -tcp_max_connections = 4096 -tcp_connection_lifetime = 3605 +tcp_max_connections = TCP_MAX_CONNECTIONS +tcp_connection_lifetime = TCP_CONNECTION_LIFETIME tcp_accept_aliases = no tcp_async = yes -tcp_connect_timeout = 10 +tcp_connect_timeout = TCP_CONNECTION_TIMEOUT tcp_conn_wq_max = 65536 tcp_crlf_ping = yes tcp_delayed_ack = yes tcp_fd_cache = yes -tcp_keepalive = yes -tcp_keepcnt = 3 -tcp_keepidle = 30 -tcp_keepintvl = 10 +tcp_keepalive = TCP_KEEP_ALIVE +tcp_keepcnt = TCP_KEEP_COUNT +tcp_keepidle = TCP_KEEP_IDLE +tcp_keepintvl = TCP_KEEP_INTERVAL tcp_linger2 = 30 tcp_rd_buf_size = 80000 -tcp_send_timeout = 10 +tcp_send_timeout = TCP_SEND_TIMEOUT tcp_wq_blk_size = 2100 tcp_wq_max = 10485760 diff --git a/kamailio/defs.cfg b/kamailio/defs.cfg index c9a3ddd..03776c4 100644 --- a/kamailio/defs.cfg +++ b/kamailio/defs.cfg @@ -44,9 +44,19 @@ #!substdef "!MAX_WHILE_LOOPS!500!g" #!endif +#### tcp parameters ## #!trydef CHILDREN 25 #!trydef TCP_CHILDREN 25 +#!trydef TCP_MAX_CONNECTIONS 4096 +#!trydef TCP_CONNECTION_LIFETIME 60 +#!trydef TCP_CONNECTION_TIMEOUT 5 +#!trydef TCP_KEEP_ALIVE yes +#!trydef TCP_KEEP_COUNT 3 +#!trydef TCP_KEEP_IDLE 30 +#!trydef TCP_KEEP_INTERVAL 5 +#!trydef TCP_SEND_TIMEOUT 3 + #!include_file "defs-amqp.cfg" #!ifndef MEDIA_SERVERS_HASH_SIZE From 974c8647bd177f2d1b59bd72f0c9397cc9e571b4 Mon Sep 17 00:00:00 2001 From: lazedo Date: Mon, 4 Mar 2019 08:29:49 +0000 Subject: [PATCH 140/209] avoid duplicated pings remove udp check as nat_traversal explicitly checks for udp --- kamailio/presence-role.cfg | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/kamailio/presence-role.cfg b/kamailio/presence-role.cfg index d0101d2..f8be4c6 100644 --- a/kamailio/presence-role.cfg +++ b/kamailio/presence-role.cfg @@ -11,7 +11,6 @@ #!trydef KZ_PRESENCE_REQUEST_RESUBSCRIBE_PROBE 0 #!trydef KZ_PRESENCE_REQUEST_PROBE 1 #!trydef KZ_PRESENCE_NO_TARGETS_LOG_LEVEL L_DBG -#!trydef KZ_PRESENCE_KEEPALIVE_UDP_ONLY 0 modparam("htable", "htable", "p=>size=32;autoexpire=3600;") modparam("htable", "htable", "first=>size=32;autoexpire=3600;initval =0;updateexpire=1;") @@ -71,7 +70,6 @@ kazoo.presence_request_resubscribe_probe = KZ_PRESENCE_REQUEST_RESUBSCRIBE_PROBE kazoo.presence_ignore_status_probe_resp = KZ_PRESENCE_IGNORE_STATUS_PROBE_RESP descr "ignore online/offline probe replies" kazoo.presence_max_call_per_presentity = KZ_PRESENCE_MAX_CALL_PER_PRESENTITY descr "max number of calls per presentity" kazoo.presence_no_targets_log_level = KZ_PRESENCE_NO_TARGETS_LOG_LEVEL descr "when a presence event is received and there no targets we can log at another level" -kazoo.presence_keepalive_udp_only = KZ_PRESENCE_KEEPALIVE_UDP_ONLY descr "should we keepalive nat phones for udp only" #!include_file "presence-query.cfg" #!include_file "presence-notify.cfg" @@ -84,8 +82,9 @@ kazoo.presence_keepalive_udp_only = KZ_PRESENCE_KEEPALIVE_UDP_ONLY descr "should route[PRESENCE_NAT] { if (isflagset(FLT_NATS)) { - if(!( ($sel(cfg_get.kazoo.presence_keepalive_udp_only) == 1 && $proto != "udp") - || ($proto =="ws" || $proto == "wss") + $xavp(regcfg=>match_received) = $su; + if(!( ($proto != "udp") || + (registered("location", "$rz:$Au", 2, 1) == 1) )) { nat_keepalive(); } From 87e20e4be3432685d9f7bce5a88f3ea91976310b Mon Sep 17 00:00:00 2001 From: lazedo Date: Mon, 4 Mar 2019 08:30:29 +0000 Subject: [PATCH 141/209] log transaction id in registrar --- kamailio/registrar-role.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kamailio/registrar-role.cfg b/kamailio/registrar-role.cfg index 89f035c..d8b4f2b 100644 --- a/kamailio/registrar-role.cfg +++ b/kamailio/registrar-role.cfg @@ -209,7 +209,7 @@ failure_route[KZ_AUTHORIZATION_TIMEOUT] if($(kzR{kz.json,Event-Name}) == "message_returned" ) { xlog("L_WARNING", "$ci|amqp|message was returned by broker $(kzR{kz.json,Error-Code}) $(kzR{kz.json,Error-Reason})\n"); } else { - xlog("L_WARNING", "$ci|end|failed $T_reply_code $T_reply_reason querying directory for authentication credentials for $Au $si:$sp\n"); + xlog("L_WARNING", "$ci|end|failed $T_reply_code $T_reply_reason [$T(id_index):$T(id_label)] querying directory for authentication credentials for $Au $si:$sp\n"); } t_drop(); } From 73f4875d2180828bba0ba65431cddf8552344814 Mon Sep 17 00:00:00 2001 From: lazedo Date: Mon, 4 Mar 2019 08:31:12 +0000 Subject: [PATCH 142/209] remove watchers on registration expiration --- kamailio/presence-notify.cfg | 16 +++++++++++++++- kamailio/registrar-role.cfg | 4 ++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/kamailio/presence-notify.cfg b/kamailio/presence-notify.cfg index bd99b01..7c263e6 100644 --- a/kamailio/presence-notify.cfg +++ b/kamailio/presence-notify.cfg @@ -1,3 +1,5 @@ +#!trydef KZ_PRESENCE_REMOVE_WATCHER_ON_EXPIRED_REGISTRATION 1 + kazoo.presence_notify = 1 descr "enable/disable sending notify callback to omnipresence" kazoo.presence_notify_timeout = 3500 descr "timeout in ms waiting for notify reply" kazoo.presence_notify_log_body = 0 descr "logs the body sent in the notification" @@ -7,6 +9,7 @@ kazoo.presence_notify_log_to_amqp = 0 descr "logs notify/reply to amqp" kazoo.presence_notify_record_route = 1 descr "add record route header to notify msg sent" kazoo.presence_notify_log_init_body = 0 descr "logs the body before its sent" kazoo.presence_notify_force_send_socket = 1 descr "forces the send socket to the contact" +kazoo.presence_remove_watcher_on_expired_registration = KZ_PRESENCE_REMOVE_WATCHER_ON_EXPIRED_REGISTRATION descr "removes watcher on expired registration" ######## Generic Hash Table container in shared memory ######## modparam("htable", "htable", "notify=>size=16;autoexpire=3600;updateexpire=1;initval=0") @@ -191,4 +194,15 @@ route[PRESENCE_DEFERRED_INIT] xlog("L_NOTICE", "scheduled update for $var(nrows) watched presentities/event\n"); } } -} \ No newline at end of file +} + +route[PRESENCE_EXPIRED_REGISTRATION] +{ + if($sel(cfg_get.kazoo.presence_remove_watcher_on_expired_registration) == 1) { + $var(watcher) = $_s(sip:$ulc(exp=>aor)); + $var(watcher_username) = $(var(watcher){uri.user}); + $var(watcher_domain) = $(var(watcher){uri.host}); + $var(Query) = $_s(DELETE FROM active_watchers WHERE watcher_username = "$var(watcher_username)" and watcher_domain = "$var(watcher_domain)";); + mq_add("presence_last_notity", "$uuid(g)", "$var(Query)"); + } +} diff --git a/kamailio/registrar-role.cfg b/kamailio/registrar-role.cfg index d8b4f2b..e281ad4 100644 --- a/kamailio/registrar-role.cfg +++ b/kamailio/registrar-role.cfg @@ -444,6 +444,10 @@ route[REGISTRAR_BOUNDS] ## event_route[usrloc:contact-expired] { + #!ifdef PRESENCE_ROLE + route(PRESENCE_EXPIRED_REGISTRATION); + #!endif + ## return until we handle this in ecallmr xlog("L_INFO", "$ulc(exp=>callid)|expired|removed registration for $ulc(exp=>aor) with contact : $ulc(exp=>addr)\n"); return; From f485603215a5bcb93a900498ec8861da2e3a0106 Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 5 Mar 2019 17:50:27 +0000 Subject: [PATCH 143/209] presence nat --- kamailio/db_scripts/db_extra_check.sql | 3 + kamailio/db_scripts/db_init_presence_nat.sql | 10 ++ kamailio/db_scripts/db_kazoo-specific | 13 +- kamailio/default.cfg | 3 +- kamailio/nat-traversal-role.cfg | 2 +- kamailio/presence-nat.cfg | 122 +++++++++++++++++++ kamailio/presence-notify.cfg | 4 +- kamailio/presence-role.cfg | 45 +++---- kamailio/registrar-role.cfg | 4 + 9 files changed, 171 insertions(+), 35 deletions(-) create mode 100644 kamailio/db_scripts/db_init_presence_nat.sql create mode 100644 kamailio/presence-nat.cfg diff --git a/kamailio/db_scripts/db_extra_check.sql b/kamailio/db_scripts/db_extra_check.sql index df1b7c8..74522a9 100644 --- a/kamailio/db_scripts/db_extra_check.sql +++ b/kamailio/db_scripts/db_extra_check.sql @@ -23,4 +23,7 @@ KazooDB -db ${DB_CURRENT_DB} "drop table if exists tmp_probe;" KazooDB -db ${DB_CURRENT_DB} "create table tmp_probe as select distinct a.event, a.presentity_uri, cast(2 as integer) action from presentities a inner join active_watchers b on a.presentity_uri = b.presentity_uri and a.event = b.event where state in('early', 'confirmed', 'onthephone', 'busy');" KazooDB -db ${DB_CURRENT_DB} "delete from presentity where id in(select id from presentities where state in('early', 'confirmed', 'onthephone', 'busy'));" +## presence nat +KazooDB -db ${DB_CURRENT_DB} "delete from presence_nat where id in(select id from presence_nat a where not exists (select id from active_watchers b where b.contact = a.contact));" + } diff --git a/kamailio/db_scripts/db_init_presence_nat.sql b/kamailio/db_scripts/db_init_presence_nat.sql new file mode 100644 index 0000000..0df244d --- /dev/null +++ b/kamailio/db_scripts/db_init_presence_nat.sql @@ -0,0 +1,10 @@ +CREATE TABLE if not exists presence_nat ( + id INTEGER PRIMARY KEY NOT NULL, + contact VARCHAR(2048) NOT NULL COLLATE NOCASE, + local_contact VARCHAR(32) NOT NULL COLLATE NOCASE, + time_inserted timestamp DEFAULT CURRENT_TIMESTAMP, + time_sent timestamp DEFAULT CURRENT_TIMESTAMP, + slot INTEGER NOT NULL, + selected INTEGER DEFAULT 0, + CONSTRAINT presence_nat_idx UNIQUE (contact) + ); diff --git a/kamailio/db_scripts/db_kazoo-specific b/kamailio/db_scripts/db_kazoo-specific index 85d731b..b8a3c2d 100644 --- a/kamailio/db_scripts/db_kazoo-specific +++ b/kamailio/db_scripts/db_kazoo-specific @@ -41,7 +41,18 @@ CREATE TABLE active_watchers_log ( user_agent VARCHAR(255) DEFAULT '' COLLATE NOCASE, CONSTRAINT active_watchers_active_watchers_log_idx UNIQUE (presentity_uri, watcher_username, watcher_domain, event) ); - + +CREATE TABLE presence_nat ( + id INTEGER PRIMARY KEY NOT NULL, + contact VARCHAR(2048) NOT NULL COLLATE NOCASE, + local_contact VARCHAR(128) NOT NULL COLLATE NOCASE, + time_inserted timestamp DEFAULT CURRENT_TIMESTAMP, + time_sent timestamp DEFAULT CURRENT_TIMESTAMP, + slot INTEGER NOT NULL, + selected INTEGER DEFAULT 0, + CONSTRAINT presence_nat_idx UNIQUE (contact) + ); + create view presentities as select id, cast(printf("sip:%s@%s",username,domain) as varchar(64)) presentity_uri , username, domain, event, cast(substr(etag, instr(etag,"@")+1) as varchar(64)) callid, datetime(received_time, 'unixepoch') as received, diff --git a/kamailio/default.cfg b/kamailio/default.cfg index cc97967..52e8bcd 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -940,8 +940,9 @@ event_route[tm:local-request] #!endif #!ifdef PRESENCE_ROLE - route(PRESENCE_LOCAL_NOTIFY); + route(PRESENCE_LOCAL_REQUEST); #!endif + } event_route[evrexec:DEFERRED_INIT] diff --git a/kamailio/nat-traversal-role.cfg b/kamailio/nat-traversal-role.cfg index 879721b..6d62690 100644 --- a/kamailio/nat-traversal-role.cfg +++ b/kamailio/nat-traversal-role.cfg @@ -4,7 +4,7 @@ loadmodule "nathelper.so" #!trydef NATHELPER_LOADED #!endif modparam("nathelper", "received_avp", "$avp(AVP_RECV_PARAM)") -modparam("nathelper", "sipping_from", "sip:registrar-check@MY_HOSTNAME") +modparam("nathelper", "sipping_from", "sip:registrar@MY_HOSTNAME") #!ifdef WEBSOCKETS_ROLE #!trydef KZ_NAT_DETECT 83 diff --git a/kamailio/presence-nat.cfg b/kamailio/presence-nat.cfg new file mode 100644 index 0000000..e3913bf --- /dev/null +++ b/kamailio/presence-nat.cfg @@ -0,0 +1,122 @@ +######## Presence NAT ######## + +modparam("htable", "htable", "keepalive=>size=32;autoexpire=3600;initval=0;") + +#!trydef KZ_PRESENCE_KEEPALIVE_UDP_ONLY 0 +#!trydef PRESENCE_NAT_TIMERS 4 +#!trydef PRESENCE_NAT_INTERVAL 30 +#!trydef PRESENCE_NAT_SKIP_REGISTERED 1 +#!trydef PRESENCE_NAT_FROM_URI sip:keepalive@MY_HOSTNAME +#!trydef PRESENCE_NAT_TIMEOUT 3500 + +#!substdef "!PRESENCE_NAT_S_FROM_URI!sip:keepalive@MY_HOSTNAME!g" +#!substdef "!PRESENCE_NAT_S_TIMERS!$def(PRESENCE_NAT_TIMERS)!g" + +kazoo.presence_keepalive_udp_only = KZ_PRESENCE_KEEPALIVE_UDP_ONLY descr "should we keepalive nat phones for udp only" +kazoo.presence_keepalive_skip_registered = PRESENCE_NAT_SKIP_REGISTERED descr "skip if there's a registered contact from same ip/port (avoids multiple pings)" + +modparam("rtimer", "timer", "name=presence_nat_timer;interval=1;mode=PRESENCE_NAT_S_TIMERS;") +modparam("rtimer", "exec", "timer=presence_nat_timer;route=PRESENCE_NAT_TIMER") + +####### Presence Logic ######## + +route[PRESENCE_NAT] +{ + #!ifdef NAT_TRAVERSAL_ROLE + if (isflagset(FLT_NATS)) { + $xavp(regcfg=>match_received) = $su; + if(!( ($sel(cfg_get.kazoo.presence_keepalive_udp_only) == 1 && $proto != "udp") + || ($proto == "ws" || $proto == "wss") +#!ifdef REGISTRAR_ROLE + || ($sel(cfg_get.kazoo.presence_keepalive_skip_registered) == 1 && registered("location", "$rz:$Au", 2, 1) == 1) +#!endif + )) { + $var(slot) = $(subs(contact){s.corehash, PRESENCE_NAT_S_TIMERS}); + $var(sql) = $_s(INSERT OR IGNORE INTO presence_nat (contact, local_contact, slot) values("$subs(contact)", "$subs(local_contact)", $var(slot))); + mq_add("presence_last_notity", "$ci", "$var(sql)"); + } + } + #!endif + + return; +} + + +route[PRESENCE_NAT_TIMER] +{ + $var(Query) = $_s(UPDATE presence_nat SET selected = 1 WHERE slot = $rtimer_worker AND selected = 0 AND time_sent < datetime('now', '-$def(PRESENCE_NAT_INTERVAL) seconds')); + $var(sqlres) = sql_query("cb", "$var(Query)"); + if($var(sqlres) < 0) { + xlog("L_ERROR", "$rtimer_worker|log|error running query : $var(Query)\n"); + } else { + $var(nrows) = $sqlrows(cb); + xlog("L_DEBUG", "$rtimer_worker|log|selected $var(nrows) endpoints to ping\n"); + } + + $var(Query) = $_s(SELECT id, contact, local_contact from presence_nat WHERE slot = $rtimer_worker AND selected = 1); + xlog("L_DEBUG", "$rtimer_worker|timer|SQL => $var(Query)\n"); + if (sql_xquery("cb", "$var(Query)", "ra") == 1) + { + while($xavp(ra) != $null) { + $var(loop) = 0; + while($xavp(ra) != $null && $var(loop) < MAX_WHILE_LOOPS) { + route(PRESENCE_NAT_PING); + pv_unset("$xavp(ra)"); + $var(loop) = $var(loop) + 1; + } + } + } + + $var(Query) = $_s(UPDATE presence_nat SET selected = 2 WHERE slot = $rtimer_worker AND selected = 1); + $var(sqlres) = sql_query("cb", "$var(Query)"); + if($var(sqlres) < 0) { + xlog("L_ERROR", "$rtimer_worker|log|error running query : $var(Query)\n"); + } + +} + +route[PRESENCE_NAT_PING] +{ + $var(CallId) = $uuid(g); + xlog("L_DEBUG", "$var(CallId)|$rtimer_worker|timer|SENDING PING FROM $(xavp(ra=>local_contact){uri.tosocket}) TO => $xavp(ra=>contact)\n"); + t_uac_send("OPTIONS", "$xavp(ra=>contact)", "", "$(xavp(ra=>local_contact){uri.tosocket})", "CSeq: 1 OPTIONS\r\nFrom: PRESENCE_NAT_S_FROM_URI\r\nTo: $xavp(ra=>contact);nat_id=$xavp(ra=>id)\r\nContact: <$xavp(ra=>local_contact)>\r\nCall-ID: $var(CallId)\r\n", ""); +} + +onreply_route[PRESENCE_NAT_REPLY] +{ + xlog("L_DEBUG", "$ci|nat|NAT REPLY $(tu{nameaddr.uri})\n"); + $var(Query) = $_s(UPDATE presence_nat SET selected = 0, time_sent = datetime('now') WHERE id = $(tu{uri.param,nat_id});); + xlog("L_DEBUG", "$ci|nat|NAT UPDATE SQL => '$var(Query)'\n"); + mq_add("presence_last_notity", "$uuid(g)", "$var(Query)"); +} + +failure_route[PRESENCE_NAT_FAULT] +{ + xlog("L_WARNING", "$ci|nat|received error $T_reply_code $T_reply_reason from $(tu{nameaddr.uri})\n"); + $var(Query) = $_s(DELETE FROM presence_nat WHERE id = $(tu{uri.param,nat_id});); + xlog("L_DEBUG", "$ci|nat|NAT REMOVE SQL => '$var(Query)'\n"); + mq_add("presence_last_notity", "$uuid(g)", "$var(Query)"); +} + +route[PRESENCE_LOCAL_REQ_NAT] +{ + #!ifdef NAT_TRAVERSAL_ROLE + if($rm == "OPTIONS" && $fu == "PRESENCE_NAT_S_FROM_URI") { + t_on_reply("PRESENCE_NAT_REPLY"); + t_on_failure("PRESENCE_NAT_FAULT"); + t_set_fr(0, PRESENCE_NAT_TIMEOUT); + handle_ruri_alias(); + record_route(); + } + #!endif + return; +} + +route[PRESENCE_NAT_ON_REGISTRATION] +{ + #!ifdef NAT_TRAVERSAL_ROLE + $var(Query) = $_s(DELETE FROM presence_nat WHERE contact like "$xavp(ulrcd=>contact)%";); + mq_add("presence_last_notity", "$uuid(g)", "$var(Query)"); + #!endif + return; +} diff --git a/kamailio/presence-notify.cfg b/kamailio/presence-notify.cfg index 7c263e6..0b9f46f 100644 --- a/kamailio/presence-notify.cfg +++ b/kamailio/presence-notify.cfg @@ -17,7 +17,7 @@ modparam("htable", "htable", "notify=>size=16;autoexpire=3600;updateexpire=1;ini #!trydef PRESENCE_NOTIFY_INIT #!trydef MAX_NOTIFY_ERROR 5 -route[PRESENCE_LOCAL_NOTIFY] +route[PRESENCE_LOCAL_REQ_NOTIFY] { if($rm != "NOTIFY") { return; @@ -202,6 +202,8 @@ route[PRESENCE_EXPIRED_REGISTRATION] $var(watcher) = $_s(sip:$ulc(exp=>aor)); $var(watcher_username) = $(var(watcher){uri.user}); $var(watcher_domain) = $(var(watcher){uri.host}); + $var(Query) = $_s(DELETE FROM presence_nat where contact in(select distinct contact from active_watchers WHERE watcher_username = "$var(watcher_username)" and watcher_domain = "$var(watcher_domain)");); + mq_add("presence_last_notity", "$uuid(g)", "$var(Query)"); $var(Query) = $_s(DELETE FROM active_watchers WHERE watcher_username = "$var(watcher_username)" and watcher_domain = "$var(watcher_domain)";); mq_add("presence_last_notity", "$uuid(g)", "$var(Query)"); } diff --git a/kamailio/presence-role.cfg b/kamailio/presence-role.cfg index f8be4c6..78e52d3 100644 --- a/kamailio/presence-role.cfg +++ b/kamailio/presence-role.cfg @@ -12,8 +12,7 @@ #!trydef KZ_PRESENCE_REQUEST_PROBE 1 #!trydef KZ_PRESENCE_NO_TARGETS_LOG_LEVEL L_DBG -modparam("htable", "htable", "p=>size=32;autoexpire=3600;") -modparam("htable", "htable", "first=>size=32;autoexpire=3600;initval =0;updateexpire=1;") +modparam("htable", "htable", "first=>size=32;autoexpire=3600;initval=0;") loadmodule "presence.so" loadmodule "presence_dialoginfo.so" @@ -53,17 +52,6 @@ modparam("presence", "cseq_offset", KZ_PRESENCE_CSEQ_OFFSET) modparam("kazoo", "db_url", "KAZOO_DB_URL") modparam("kazoo", "pua_mode", 1) -#!ifdef NAT_TRAVERSAL_ROLE -#!ifndef NAT_TRAVERSAL_LOADED -#!trydef NAT_TRAVERSAL_LOADED -loadmodule "nat_traversal.so" -#!endif -modparam("nat_traversal", "keepalive_method", "OPTIONS") -modparam("nat_traversal", "keepalive_from", "sip:presence-check@MY_HOSTNAME") -modparam("nat_traversal", "keepalive_state_file", "KAZOO_DATA_DIR/keep_alive_state") -modparam("nat_traversal", "keepalive_interval", 30) -#!endif - kazoo.presence_sync_amqp = KZ_PRESENCE_AMQP_PUBLISH descr "sync subscriptions to amqp" kazoo.presence_request_probe = KZ_PRESENCE_REQUEST_PROBE descr "request probe for new subscriptions" kazoo.presence_request_resubscribe_probe = KZ_PRESENCE_REQUEST_RESUBSCRIBE_PROBE descr "request probe for resubscriptions" @@ -75,23 +63,10 @@ kazoo.presence_no_targets_log_level = KZ_PRESENCE_NO_TARGETS_LOG_LEVEL descr "wh #!include_file "presence-notify.cfg" #!include_file "presence-reset.cfg" #!include_file "presence-fast-pickup.cfg" +#!include_file "presence-nat.cfg" ####### Presence Logic ######## -#!ifdef NAT_TRAVERSAL_ROLE -route[PRESENCE_NAT] -{ - if (isflagset(FLT_NATS)) { - $xavp(regcfg=>match_received) = $su; - if(!( ($proto != "udp") || - (registered("location", "$rz:$Au", 2, 1) == 1) - )) { - nat_keepalive(); - } - } -} -#!endif - route[HANDLE_SUBSCRIBE] { if (!is_method("SUBSCRIBE")) { @@ -111,10 +86,6 @@ route[HANDLE_SUBSCRIBE] exit; } - #!ifdef NAT_TRAVERSAL_ROLE - route(PRESENCE_NAT); - #!endif - if(has_totag()) { loose_route(); } @@ -190,6 +161,7 @@ route[HANDLE_NEW_SUBSCRIBE] route(DELETE_DUPLICATED_SUBSCRIPTIONS); route(SUBSCRIBE_AMQP); route(REQUEST_PROBE); + route(PRESENCE_NAT); } else { xlog("L_INFO", "$ci|stop|error $T_reply_code for new $hdr(Event) subscription from $fU to $tU in realm $fd\n"); } @@ -544,4 +516,15 @@ route[PRESENCE_API_BINDINGS] } +route[PRESENCE_LOCAL_REQUEST] +{ + route(PRESENCE_LOCAL_REQ_NOTIFY); + route(PRESENCE_LOCAL_REQ_NAT); +} + +route[PRESENCE_ON_REGISTRATION] +{ + route(PRESENCE_NAT_ON_REGISTRATION); +} + # vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab diff --git a/kamailio/registrar-role.cfg b/kamailio/registrar-role.cfg index e281ad4..453077f 100644 --- a/kamailio/registrar-role.cfg +++ b/kamailio/registrar-role.cfg @@ -353,6 +353,10 @@ route[SAVE_LOCATION] route(PUSHER_ON_REGISTRATION); #!endif + #!ifdef PRESENCE_ROLE + route(PRESENCE_ON_REGISTRATION); + #!endif + exit; } From 3092be7f61a4033e5e121c666d280d96224186ba Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 5 Mar 2019 20:51:10 +0000 Subject: [PATCH 144/209] apply db diff with primary key --- kamailio/db_scripts/check-kazoodb-sql.sh | 2 +- kamailio/db_scripts/kazoodb-sql.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/kamailio/db_scripts/check-kazoodb-sql.sh b/kamailio/db_scripts/check-kazoodb-sql.sh index 0937e3b..ab00bec 100755 --- a/kamailio/db_scripts/check-kazoodb-sql.sh +++ b/kamailio/db_scripts/check-kazoodb-sql.sh @@ -18,7 +18,7 @@ DB_CURRENT_VERSION=`KazooDB -db ${DB_CURRENT_DB} "select sum(table_version) from if [[ $DB_CURRENT_VERSION -ne $DB_VERSION ]]; then echo "db required version is ${DB_VERSION}, existing version is ${DB_CURRENT_VERSION}, applying diff" KazooDB-diff --schema ${DB_CURRENT_DB} ${TEMP_DB} | KazooDB -db ${DB_CURRENT_DB} - KazooDB-diff --table version ${DB_CURRENT_DB} ${TEMP_DB} | KazooDB -db ${DB_CURRENT_DB} + KazooDB-diff --primarykey --table version ${DB_CURRENT_DB} ${TEMP_DB} | KazooDB -db ${DB_CURRENT_DB} fi diff --git a/kamailio/db_scripts/kazoodb-sql.sh b/kamailio/db_scripts/kazoodb-sql.sh index 2c07f39..6351266 100755 --- a/kamailio/db_scripts/kazoodb-sql.sh +++ b/kamailio/db_scripts/kazoodb-sql.sh @@ -15,7 +15,7 @@ cat << EOF CREATE TABLE version ( table_name VARCHAR(32) NOT NULL, table_version INTEGER DEFAULT 0 NOT NULL, - CONSTRAINT version_table_name_idx UNIQUE (table_name) + PRIMARY KEY(table_name) ); INSERT INTO version VALUES('version',1); From 0d93ba61d56944e243abebfd954e801679eb6ac5 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 7 Mar 2019 15:04:26 +0000 Subject: [PATCH 145/209] nat with loop --- kamailio/default.cfg | 25 +++++++++++++++++++-- kamailio/presence-nat.cfg | 43 +++++++++++++++++++++++++------------ kamailio/presence-role.cfg | 1 - kamailio/sip_trace-role.cfg | 4 ++++ 4 files changed, 56 insertions(+), 17 deletions(-) diff --git a/kamailio/default.cfg b/kamailio/default.cfg index 52e8bcd..e8dd78c 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -13,6 +13,7 @@ #!trydef FLT_T38 10 #!trydef FLT_NATS 11 #!trydef FLAG_LOCAL_REQUEST 12 +#!trydef FLAG_LOCAL_ROUTE 17 ####### Global Parameters ######### fork = yes @@ -309,9 +310,15 @@ loadmodule "permissions.so" modparam("permissions", "db_url", "KAZOO_DB_URL") modparam("permissions", "db_mode", 1) +###### local route ###### +tcp_children = 5 +listen=tcp:127.0.0.1:5090 + ####### Routing Logic ######## route { + route(LOCAL_REQUEST); + route(SANITY_CHECK); route(CHECK_RETRANS); @@ -889,14 +896,16 @@ onsend_route { xlog("L_INFO", "$ci|log|associate traffic from $var(user_source) with media server sip:$sndto(ip):$sndto(port)\n"); $sht(associations=>$var(user_source))= "sip:" + $sndto(ip) + ":" + $sndto(port); } - + #!ifdef SIP_TRACE_ROLE if (is_method("ACK") && isflagset(FLAG_SIP_TRACE)) { sip_trace(); } #!endif - xlog("L_INFO", "$ci|pass|$sndfrom(ip):$sndfrom(port) -> $sndto(ip):$sndto(port)\n"); + if(!isflagset(FLAG_LOCAL_ROUTE)) { + xlog("L_INFO", "$ci|pass|$sndfrom(ip):$sndfrom(port) -> $sndto(ip):$sndto(port)\n"); + } } route[ROUTE_TO_AOR] @@ -957,5 +966,17 @@ event_route[evrexec:DEFERRED_INIT] } +route[LOCAL_REQUEST] +{ + if(src_ip != myself || $hdr(X-TM-Local) == $null) { + return; + } + xlog("L_DEBUG", "internal route $hdr(X-TM-Local)\n"); + $var(LocalRoute) = $hdr(X-TM-Local); + remove_hf_re("^X-TM-Local"); + route_if_exists("$var(LocalRoute)"); + exit; +} + # vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab diff --git a/kamailio/presence-nat.cfg b/kamailio/presence-nat.cfg index e3913bf..7932c2a 100644 --- a/kamailio/presence-nat.cfg +++ b/kamailio/presence-nat.cfg @@ -79,37 +79,52 @@ route[PRESENCE_NAT_PING] { $var(CallId) = $uuid(g); xlog("L_DEBUG", "$var(CallId)|$rtimer_worker|timer|SENDING PING FROM $(xavp(ra=>local_contact){uri.tosocket}) TO => $xavp(ra=>contact)\n"); - t_uac_send("OPTIONS", "$xavp(ra=>contact)", "", "$(xavp(ra=>local_contact){uri.tosocket})", "CSeq: 1 OPTIONS\r\nFrom: PRESENCE_NAT_S_FROM_URI\r\nTo: $xavp(ra=>contact);nat_id=$xavp(ra=>id)\r\nContact: <$xavp(ra=>local_contact)>\r\nCall-ID: $var(CallId)\r\n", ""); + + $uac_req(method)="OPTIONS"; + $uac_req(hdrs) = "X-TM-Local: PRESENCE_ROUTE_NAT_PING\r\nX-TM-Contact: " + $xavp(ra=>local_contact) + "\r\n"; + $uac_req(turi) = $xavp(ra=>contact); + $uac_req(ruri) = $xavp(ra=>contact); + $uac_req(furi) = $_s(PRESENCE_NAT_S_FROM_URI;nat_id=$xavp(ra=>id)); + $uac_req(ouri) = "sip:127.0.0.1:5090;transport=tcp"; + $uac_req(callid) = $var(CallId); + uac_req_send(); + } onreply_route[PRESENCE_NAT_REPLY] { xlog("L_DEBUG", "$ci|nat|NAT REPLY $(tu{nameaddr.uri})\n"); - $var(Query) = $_s(UPDATE presence_nat SET selected = 0, time_sent = datetime('now') WHERE id = $(tu{uri.param,nat_id});); + $var(Query) = $_s(UPDATE presence_nat SET selected = 0, time_sent = datetime('now') WHERE id = $(fu{uri.param,nat_id});); xlog("L_DEBUG", "$ci|nat|NAT UPDATE SQL => '$var(Query)'\n"); mq_add("presence_last_notity", "$uuid(g)", "$var(Query)"); + t_drop(); } failure_route[PRESENCE_NAT_FAULT] { xlog("L_WARNING", "$ci|nat|received error $T_reply_code $T_reply_reason from $(tu{nameaddr.uri})\n"); - $var(Query) = $_s(DELETE FROM presence_nat WHERE id = $(tu{uri.param,nat_id});); + $var(Query) = $_s(DELETE FROM presence_nat WHERE id = $(fu{uri.param,nat_id});); xlog("L_DEBUG", "$ci|nat|NAT REMOVE SQL => '$var(Query)'\n"); mq_add("presence_last_notity", "$uuid(g)", "$var(Query)"); + t_drop(); } -route[PRESENCE_LOCAL_REQ_NAT] +route[PRESENCE_ROUTE_NAT_PING] { - #!ifdef NAT_TRAVERSAL_ROLE - if($rm == "OPTIONS" && $fu == "PRESENCE_NAT_S_FROM_URI") { - t_on_reply("PRESENCE_NAT_REPLY"); - t_on_failure("PRESENCE_NAT_FAULT"); - t_set_fr(0, PRESENCE_NAT_TIMEOUT); - handle_ruri_alias(); - record_route(); - } - #!endif - return; + $fs = $(hdr(X-TM-Contact){uri.tosocket}); + remove_hf_re("^X-TM-Contact"); + + force_rport(); + handle_ruri_alias(); + record_route(); + xlog("L_DEBUG", "$ci|local|sending nat keepalive from $fu to $ru => $du => $tu\n"); + setflag(FLAG_LOCAL_ROUTE); + + t_on_reply("PRESENCE_NAT_REPLY"); + t_on_failure("PRESENCE_NAT_FAULT"); + t_set_fr(0, PRESENCE_NAT_TIMEOUT); + + t_relay(); } route[PRESENCE_NAT_ON_REGISTRATION] diff --git a/kamailio/presence-role.cfg b/kamailio/presence-role.cfg index 78e52d3..5f88ede 100644 --- a/kamailio/presence-role.cfg +++ b/kamailio/presence-role.cfg @@ -519,7 +519,6 @@ route[PRESENCE_API_BINDINGS] route[PRESENCE_LOCAL_REQUEST] { route(PRESENCE_LOCAL_REQ_NOTIFY); - route(PRESENCE_LOCAL_REQ_NAT); } route[PRESENCE_ON_REGISTRATION] diff --git a/kamailio/sip_trace-role.cfg b/kamailio/sip_trace-role.cfg index a2768c9..89af0f0 100644 --- a/kamailio/sip_trace-role.cfg +++ b/kamailio/sip_trace-role.cfg @@ -75,6 +75,10 @@ route[SIP_TRACE_LOCAL] route[SIP_TRACE] { + if(src_ip == 127.0.0.1 || dst_ip == 127.0.0.1) { + return; + } + if (isflagset(FLAG_INTERNALLY_SOURCED)) { route(SIP_TRACE_INTERNAL); } else if (isflagset(FLAG_LOCAL_REQUEST)) { From ce7218078a4313e7aac99ac21e8720bbc4afd603 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 7 Mar 2019 22:24:58 +0000 Subject: [PATCH 146/209] some tweaks move param failure_exec_mode from pusher role to default move handling of FLAG_LOCAL_ROUTE add optional require for authn on subscribe trace local route requests --- kamailio/default.cfg | 26 ++++++++++++++++++-------- kamailio/presence-nat.cfg | 1 - kamailio/presence-role.cfg | 18 ++++++++++++++++++ kamailio/pusher-role.cfg | 2 -- kamailio/sip_trace-role.cfg | 22 +++++++++++++++------- 5 files changed, 51 insertions(+), 18 deletions(-) diff --git a/kamailio/default.cfg b/kamailio/default.cfg index e8dd78c..61ad856 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -130,6 +130,8 @@ modparam("tm", "auto_inv_100_reason", "Attempting to connect your call") modparam("tm", "cancel_b_method", 2) modparam("tm", "ruri_matching", 0) modparam("tm", "failure_reply_mode", 3) +modparam("tm", "failure_exec_mode", 1) + # modparam("tm", "fr_timer", 30000) # modparam("tm", "fr_inv_timer", 120000) @@ -968,14 +970,22 @@ event_route[evrexec:DEFERRED_INIT] route[LOCAL_REQUEST] { - if(src_ip != myself || $hdr(X-TM-Local) == $null) { - return; - } - xlog("L_DEBUG", "internal route $hdr(X-TM-Local)\n"); - $var(LocalRoute) = $hdr(X-TM-Local); - remove_hf_re("^X-TM-Local"); - route_if_exists("$var(LocalRoute)"); - exit; + if(src_ip != myself || $hdr(X-TM-Local) == $null) { + return; + } + + xlog("L_DEBUG", "internal route $hdr(X-TM-Local)\n"); + + setflag(FLAG_LOCAL_ROUTE); + + #!ifdef SIP_TRACE_ROLE + route(SIP_TRACE); + #!endif + + $var(LocalRoute) = $hdr(X-TM-Local); + remove_hf_re("^X-TM-Local"); + route_if_exists("$var(LocalRoute)"); + exit; } diff --git a/kamailio/presence-nat.cfg b/kamailio/presence-nat.cfg index 7932c2a..a78ddfd 100644 --- a/kamailio/presence-nat.cfg +++ b/kamailio/presence-nat.cfg @@ -118,7 +118,6 @@ route[PRESENCE_ROUTE_NAT_PING] handle_ruri_alias(); record_route(); xlog("L_DEBUG", "$ci|local|sending nat keepalive from $fu to $ru => $du => $tu\n"); - setflag(FLAG_LOCAL_ROUTE); t_on_reply("PRESENCE_NAT_REPLY"); t_on_failure("PRESENCE_NAT_FAULT"); diff --git a/kamailio/presence-role.cfg b/kamailio/presence-role.cfg index 5f88ede..83c6a01 100644 --- a/kamailio/presence-role.cfg +++ b/kamailio/presence-role.cfg @@ -11,6 +11,7 @@ #!trydef KZ_PRESENCE_REQUEST_RESUBSCRIBE_PROBE 0 #!trydef KZ_PRESENCE_REQUEST_PROBE 1 #!trydef KZ_PRESENCE_NO_TARGETS_LOG_LEVEL L_DBG +#!trydef KZ_PRESENCE_REQUIRE_AUTHN 0 modparam("htable", "htable", "first=>size=32;autoexpire=3600;initval=0;") @@ -58,6 +59,7 @@ kazoo.presence_request_resubscribe_probe = KZ_PRESENCE_REQUEST_RESUBSCRIBE_PROBE kazoo.presence_ignore_status_probe_resp = KZ_PRESENCE_IGNORE_STATUS_PROBE_RESP descr "ignore online/offline probe replies" kazoo.presence_max_call_per_presentity = KZ_PRESENCE_MAX_CALL_PER_PRESENTITY descr "max number of calls per presentity" kazoo.presence_no_targets_log_level = KZ_PRESENCE_NO_TARGETS_LOG_LEVEL descr "when a presence event is received and there no targets we can log at another level" +kazoo.presence_require_authn = KZ_PRESENCE_REQUIRE_AUTHN descr "require authenticated devices for presence" #!include_file "presence-query.cfg" #!include_file "presence-notify.cfg" @@ -80,6 +82,8 @@ route[HANDLE_SUBSCRIBE] send_reply(489, "Bad Event"); exit(); } + + route(PRESENCE_AUTHN); if (!t_newtran()) { sl_reply_error(); @@ -225,6 +229,8 @@ route[HANDLE_PUBLISH] exit(); } + route(PRESENCE_AUTHN); + if (!t_newtran()) { sl_reply_error(); exit; @@ -526,4 +532,16 @@ route[PRESENCE_ON_REGISTRATION] route(PRESENCE_NAT_ON_REGISTRATION); } +route[PRESENCE_AUTHN] +{ + if($sel(cfg_get.kazoo.presence_require_authn) == 1) { + $xavp(regcfg=>match_received) = $su; + if(registered("location", "$rz:$Au", 2, 1) != 1) { + xlog("L_WARNING", "$ci|stop|$rm from unregistered ($rz:$Au) user agent $ua => $su\n"); + send_reply(403, "Forbidden"); + exit; + } + } +} + # vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab diff --git a/kamailio/pusher-role.cfg b/kamailio/pusher-role.cfg index d969eb7..8925ac3 100644 --- a/kamailio/pusher-role.cfg +++ b/kamailio/pusher-role.cfg @@ -3,8 +3,6 @@ ######## Generic Hash Table container in shared memory ######## modparam("htable", "htable", "push_cache=>autoexpire=60;") -modparam("tm", "failure_exec_mode", 1) - route[PUSHER_ROUTE] { if ( (!is_method("INVITE")) || (!isflagset(FLAG_INTERNALLY_SOURCED)) || $hdr(X-KAZOO-PUSHER-Token-ID) == $null) diff --git a/kamailio/sip_trace-role.cfg b/kamailio/sip_trace-role.cfg index 89af0f0..afae3c7 100644 --- a/kamailio/sip_trace-role.cfg +++ b/kamailio/sip_trace-role.cfg @@ -70,19 +70,27 @@ route[SIP_TRACE_LOCAL] if($sel(cfg_get.kazoo.trace_local) == 0) { return; } + + if($hdr(X-TM-Local) != $null) { + return; + } + sip_trace(); } -route[SIP_TRACE] +route[SIP_TRACE_LOCAL_ROUTE] { - if(src_ip == 127.0.0.1 || dst_ip == 127.0.0.1) { - return; - } + setflag(FLAG_SIP_TRACE); +} - if (isflagset(FLAG_INTERNALLY_SOURCED)) { - route(SIP_TRACE_INTERNAL); +route[SIP_TRACE] +{ + if (isflagset(FLAG_LOCAL_ROUTE)) { + route(SIP_TRACE_LOCAL_ROUTE); } else if (isflagset(FLAG_LOCAL_REQUEST)) { - route(SIP_TRACE_LOCAL); + route(SIP_TRACE_LOCAL); + } else if (isflagset(FLAG_INTERNALLY_SOURCED)) { + route(SIP_TRACE_INTERNAL); } else { route(SIP_TRACE_EXTERNAL); } From 42a13450223b626b29b764a08ae84cb4c1b42e97 Mon Sep 17 00:00:00 2001 From: lazedo Date: Mon, 11 Mar 2019 10:29:54 +0000 Subject: [PATCH 147/209] defaults for nat ping timeout and timer interval --- kamailio/registrar-role.cfg | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kamailio/registrar-role.cfg b/kamailio/registrar-role.cfg index 453077f..a8b9984 100644 --- a/kamailio/registrar-role.cfg +++ b/kamailio/registrar-role.cfg @@ -2,7 +2,7 @@ ## NEXT 2 SHOULD GO TOGETHER ## REGISTRAR_NAT_PING_TIMEOUT should be (REGISTRAR_NAT_PING_INTERVAL + 10) or 0 to disable #!trydef REGISTRAR_NAT_PING_INTERVAL 30 -#!trydef REGISTRAR_NAT_PING_TIMEOUT 40 +#!trydef REGISTRAR_NAT_PING_TIMEOUT 100 #!trydef REGISTRAR_NAT_PING_NAT_ONLY 1 #!trydef REGISTRAR_NAT_PING_WORKERS 5 @@ -57,7 +57,7 @@ modparam("usrloc", "db_mode", 1) modparam("usrloc", "handle_lost_tcp", 1) modparam("usrloc", "xavp_contact", "ulattrs") modparam("usrloc", "db_check_update", 1) -modparam("usrloc", "timer_interval", 30) +modparam("usrloc", "timer_interval", 5) modparam("usrloc", "timer_procs", 1) modparam("usrloc", "db_timer_clean", 1) modparam("usrloc", "fetch_rows", 400) @@ -279,6 +279,7 @@ route[SAVE_LOCATION] $var(save_result) = save("location", "0x04"); if($var(save_result) < 0) { + xlog("L_WARNING", "$ci|end|not expected result $var(save_result) when saving $Au registration from IP $si:$sp\n"); exit; } else { if($var(save_result) == 1) { From 9c361c85d59aa682b6ed249b9ad2e19185ba10bf Mon Sep 17 00:00:00 2001 From: lazedo Date: Mon, 11 Mar 2019 13:07:42 +0000 Subject: [PATCH 148/209] add versions to kazoo specific tables --- kamailio/db_scripts/db_extra_check.sql | 7 ++----- kamailio/db_scripts/db_init_presence_nat.sql | 10 ---------- kamailio/db_scripts/db_kazoo-specific | 14 +++++++++++--- 3 files changed, 13 insertions(+), 18 deletions(-) delete mode 100644 kamailio/db_scripts/db_init_presence_nat.sql diff --git a/kamailio/db_scripts/db_extra_check.sql b/kamailio/db_scripts/db_extra_check.sql index 74522a9..68a73d9 100644 --- a/kamailio/db_scripts/db_extra_check.sql +++ b/kamailio/db_scripts/db_extra_check.sql @@ -1,9 +1,6 @@ do_db_extra_check() { -# warm cache -KazooDB -db ${DB_CURRENT_DB} "create table if not exists auth_cache as select * from htable;" - # location KazooDB -db ${DB_CURRENT_DB} "delete from location where socket not like 'udp:%';" KazooDB -db ${DB_CURRENT_DB} "delete from location where expires > 0 and datetime(expires) < datetime('now', '-30 seconds');" @@ -23,7 +20,7 @@ KazooDB -db ${DB_CURRENT_DB} "drop table if exists tmp_probe;" KazooDB -db ${DB_CURRENT_DB} "create table tmp_probe as select distinct a.event, a.presentity_uri, cast(2 as integer) action from presentities a inner join active_watchers b on a.presentity_uri = b.presentity_uri and a.event = b.event where state in('early', 'confirmed', 'onthephone', 'busy');" KazooDB -db ${DB_CURRENT_DB} "delete from presentity where id in(select id from presentities where state in('early', 'confirmed', 'onthephone', 'busy'));" -## presence nat -KazooDB -db ${DB_CURRENT_DB} "delete from presence_nat where id in(select id from presence_nat a where not exists (select id from active_watchers b where b.contact = a.contact));" +## keepalive +KazooDB -db ${DB_CURRENT_DB} "delete from keepalive where sockinfo NOT LIKE 'udp%';" } diff --git a/kamailio/db_scripts/db_init_presence_nat.sql b/kamailio/db_scripts/db_init_presence_nat.sql deleted file mode 100644 index 0df244d..0000000 --- a/kamailio/db_scripts/db_init_presence_nat.sql +++ /dev/null @@ -1,10 +0,0 @@ -CREATE TABLE if not exists presence_nat ( - id INTEGER PRIMARY KEY NOT NULL, - contact VARCHAR(2048) NOT NULL COLLATE NOCASE, - local_contact VARCHAR(32) NOT NULL COLLATE NOCASE, - time_inserted timestamp DEFAULT CURRENT_TIMESTAMP, - time_sent timestamp DEFAULT CURRENT_TIMESTAMP, - slot INTEGER NOT NULL, - selected INTEGER DEFAULT 0, - CONSTRAINT presence_nat_idx UNIQUE (contact) - ); diff --git a/kamailio/db_scripts/db_kazoo-specific b/kamailio/db_scripts/db_kazoo-specific index b8a3c2d..50655f2 100644 --- a/kamailio/db_scripts/db_kazoo-specific +++ b/kamailio/db_scripts/db_kazoo-specific @@ -41,17 +41,25 @@ CREATE TABLE active_watchers_log ( user_agent VARCHAR(255) DEFAULT '' COLLATE NOCASE, CONSTRAINT active_watchers_active_watchers_log_idx UNIQUE (presentity_uri, watcher_username, watcher_domain, event) ); +INSERT INTO version (table_name, table_version) values ('active_watchers_log','1'); -CREATE TABLE presence_nat ( +CREATE TABLE keepalive ( id INTEGER PRIMARY KEY NOT NULL, contact VARCHAR(2048) NOT NULL COLLATE NOCASE, - local_contact VARCHAR(128) NOT NULL COLLATE NOCASE, + sockinfo VARCHAR(128) NOT NULL COLLATE NOCASE, time_inserted timestamp DEFAULT CURRENT_TIMESTAMP, time_sent timestamp DEFAULT CURRENT_TIMESTAMP, slot INTEGER NOT NULL, selected INTEGER DEFAULT 0, - CONSTRAINT presence_nat_idx UNIQUE (contact) + failed INTEGER DEFAULT 0, + CONSTRAINT keepalive_idx UNIQUE (contact), + CONSTRAINT keepalive_idx_2 UNIQUE (slot, selected, time_sent, contact) ); + +INSERT INTO version (table_name, table_version) values ('keepalive','1'); + +create table auth_cache as select * from htable; +INSERT INTO version (table_name, table_version) select 'auth_cache', table_version from version where table_name = 'htable'; create view presentities as select id, cast(printf("sip:%s@%s",username,domain) as varchar(64)) presentity_uri , username, domain, event, cast(substr(etag, instr(etag,"@")+1) as varchar(64)) callid, From 095f9898a7fb4ed57b465b390df1beac6d0c98af Mon Sep 17 00:00:00 2001 From: lazedo Date: Mon, 11 Mar 2019 13:08:21 +0000 Subject: [PATCH 149/209] option & notify early exit --- kamailio/default.cfg | 82 ++++++++++++++++++++++++-------------------- 1 file changed, 45 insertions(+), 37 deletions(-) diff --git a/kamailio/default.cfg b/kamailio/default.cfg index 61ad856..e197fb5 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -441,57 +441,65 @@ route[CLASSIFY_SOURCE] route[HANDLE_OPTIONS] { - if (is_method("OPTIONS")) { - if (isflagset(FLAG_INTERNALLY_SOURCED)) { - route(INTERNAL_TO_EXTERNAL_RELAY); - } else { - #!ifdef TRAFFIC_FILTER_ROLE - if (!isflagset(FLAG_TRUSTED_SOURCE)) { - route(FILTER_REQUEST_DOMAIN); - } - #!endif + if (!is_method("OPTIONS")) { + return; + } - sl_send_reply("200", "Rawr!!"); + if (isflagset(FLAG_INTERNALLY_SOURCED)) { + route(INTERNAL_TO_EXTERNAL_RELAY); + } else { + #!ifdef TRAFFIC_FILTER_ROLE + if (!isflagset(FLAG_TRUSTED_SOURCE)) { + route(FILTER_REQUEST_DOMAIN); } - exit; + #!endif + + ## TODO: remove nat if client is sending options + + sl_send_reply("200", "Rawr!!"); } + exit; } route[HANDLE_NOTIFY] { + if (!is_method("NOTIFY")) return; + if (has_totag()) return; - if (is_method("NOTIFY")) { - if (isflagset(FLAG_INTERNALLY_SOURCED)) { - if (loose_route()) { - xlog("L_INFO", "$ci|log|Able to loose-route. Cool beans!\n"); - } + if (isflagset(FLAG_INTERNALLY_SOURCED)) { + if (loose_route()) { + xlog("L_INFO", "$ci|log|Able to loose-route. Cool beans!\n"); + } - #!ifdef REGISTRAR_ROLE - if (registered("location")) { - lookup("location"); - xlog("L_INFO", "$ci|log|routing to $ruid\n"); - } - #!endif + #!ifdef REGISTRAR_ROLE + if (registered("location")) { + lookup("location"); + xlog("L_INFO", "$ci|log|routing to $ruid\n"); + } + #!endif - route(INTERNAL_TO_EXTERNAL_RELAY); - } else { - #!ifdef TRAFFIC_FILTER_ROLE - if (!isflagset(FLAG_TRUSTED_SOURCE)) { - route(FILTER_REQUEST_DOMAIN); - } - #!endif + ## TODO: verify we're not routing to ourselves - if($hdr(Event) == "keep-alive") { - xlog("L_INFO", "$ci|stop|replying to keep alive\n"); - sl_send_reply("405", "Stay Alive / Method Not Allowed"); - } else { - xlog("L_INFO", "$ci|stop|consuming event $hdr(Event)\n"); - sl_send_reply("200", "Rawr!!"); - } + route(INTERNAL_TO_EXTERNAL_RELAY); + } else { + #!ifdef TRAFFIC_FILTER_ROLE + if (!isflagset(FLAG_TRUSTED_SOURCE)) { + route(FILTER_REQUEST_DOMAIN); + } + #!endif + + ## TODO: remove nat if client is sending notify for keepalive + + if($hdr(Event) == "keep-alive") { + xlog("L_INFO", "$ci|stop|replying to keep alive\n"); + sl_send_reply("405", "Stay Alive / Method Not Allowed"); + } else { + xlog("L_INFO", "$ci|stop|consuming event $hdr(Event)\n"); + sl_send_reply("200", "Rawr!!"); } - exit; } + exit; } route[HANDLE_MESSAGE] From 75b192c1b428ff6af0c9e35e5cffcf48f99201dd Mon Sep 17 00:00:00 2001 From: lazedo Date: Mon, 11 Mar 2019 13:17:31 +0000 Subject: [PATCH 150/209] add keepalive --- kamailio/keepalive.cfg | 167 ++++++++++++++++++++++++++++++++ kamailio/nat-traversal-role.cfg | 2 + kamailio/presence-nat.cfg | 136 -------------------------- kamailio/presence-notify.cfg | 2 +- kamailio/presence-role.cfg | 10 +- kamailio/registrar-role.cfg | 41 +++++--- 6 files changed, 198 insertions(+), 160 deletions(-) create mode 100644 kamailio/keepalive.cfg delete mode 100644 kamailio/presence-nat.cfg diff --git a/kamailio/keepalive.cfg b/kamailio/keepalive.cfg new file mode 100644 index 0000000..dfa02b1 --- /dev/null +++ b/kamailio/keepalive.cfg @@ -0,0 +1,167 @@ +######## KEEPALIVE PINGING ######## + +#!trydef KEEPALIVE_NAT_ONLY 0 +#!trydef KEEPALIVE_UDP_ONLY 0 +#!trydef KEEPALIVE_TIMERS 7 +#!trydef KEEPALIVE_INTERVAL 30 +#!trydef KEEPALIVE_TIMEOUT 3500 + +#!substdef "!KEEPALIVE_S_FROM_URI!sip:keepalive@MY_HOSTNAME!g" +#!substdef "!KEEPALIVE_S_TIMERS!$def(KEEPALIVE_TIMERS)!g" + +kazoo.keepalive_udp_only = KEEPALIVE_UDP_ONLY descr "should we send keepalive for udp only" +kazoo.keepalive_nat_only = KEEPALIVE_NAT_ONLY descr "should we send keepalive for nat phones only" + +modparam("rtimer", "timer", "name=keepalive_timer;interval=1;mode=KEEPALIVE_S_TIMERS;") +modparam("rtimer", "exec", "timer=keepalive_timer;route=KEEPALIVE_TIMER") + +modparam("rtimer", "timer", "name=keepalive_db_timer;interval=250000u;mode=1;") +modparam("rtimer", "exec", "timer=keepalive_db_timer;route=KEEPALIVE_DB_TIMER") + +modparam("mqueue","mqueue", "name=keepalive_db_queue") + +route[KEEPALIVE_DB_TIMER] +{ + $var(runloop) = 1; + while(mq_fetch("keepalive_db_queue") == 1 && $var(runloop) < MAX_WHILE_LOOPS) { + $var(ci) = $mqk(keepalive_db_queue); + xlog("L_DEBUG", "Query : $mqv(keepalive_db_queue)\n"); + $var(sqlres) = sql_query("cb", "$mqv(keepalive_db_queue)"); + xlog("L_DEBUG", "Query result : $var(sqlres)\n"); + if($var(sqlres) < 0) { + xlog("L_ERROR", "$var(ci)|log|error running query : $mqv(keepalive_db_queue)\n"); + } else { + $var(nrows) = $sqlrows(cb); + xlog("L_DEBUG", "$var(ci)|log|end UPDATED $var(nrows)\n"); + if($var(nrows) == 0) { + xlog("L_DEBUG", "$var(ci)|log|error no rows affected when running query\n"); + } + } + $var(runloop) = $var(runloop) + 1; + } +} + +route[KEEPALIVE_TIMER] +{ + $var(Query) = $_s(UPDATE keepalive SET selected = 1 WHERE slot = $rtimer_worker AND selected = 0 AND time_sent < datetime('now', '-$def(KEEPALIVE_INTERVAL) seconds')); + $var(sqlres) = sql_query("cb", "$var(Query)"); + if($var(sqlres) < 0) { + xlog("L_ERROR", "$rtimer_worker|log|error running query : $var(Query)\n"); + } else { + $var(nrows) = $sqlrows(cb); + xlog("L_DEBUG", "$rtimer_worker|log|selected $var(nrows) endpoints to ping\n"); + } + + $var(Query) = $_s(SELECT id, contact, sockinfo from keepalive WHERE slot = $rtimer_worker AND selected = 1); + xlog("L_DEBUG", "$rtimer_worker|timer|SQL => $var(Query)\n"); + if (sql_xquery("cb", "$var(Query)", "ra") == 1) + { + while($xavp(ra) != $null) { + $var(loop) = 0; + while($xavp(ra) != $null && $var(loop) < MAX_WHILE_LOOPS) { + route(KEEPALIVE_SEND_PING); + pv_unset("$xavp(ra)"); + $var(loop) = $var(loop) + 1; + } + } + } + + $var(Query) = $_s(UPDATE keepalive SET selected = 2 WHERE slot = $rtimer_worker AND selected = 1); + $var(sqlres) = sql_query("cb", "$var(Query)"); + if($var(sqlres) < 0) { + xlog("L_ERROR", "$rtimer_worker|log|error running query : $var(Query)\n"); + } + +} + +route[KEEPALIVE_SEND_PING] +{ + $var(CallId) = $uuid(g); + xlog("L_DEBUG", "$var(CallId)|$rtimer_worker|timer|SENDING PING FROM $xavp(ra=>local_contact) TO => $xavp(ra=>contact)\n"); + + $uac_req(method)="OPTIONS"; + $uac_req(hdrs) = "X-TM-Local: KEEPALIVE_PING\r\nX-TM-SockInfo: " + $xavp(ra=>sockinfo) + "\r\n"; + $uac_req(turi) = $xavp(ra=>contact); + $uac_req(ruri) = $xavp(ra=>contact); + $uac_req(furi) = $_s(KEEPALIVE_S_FROM_URI;nat_id=$xavp(ra=>id)); + $uac_req(ouri) = "sip:127.0.0.1:5090;transport=tcp"; + $uac_req(callid) = $var(CallId); + uac_req_send(); + +} + +onreply_route[KEEPALIVE_REPLY] +{ + xlog("L_DEBUG", "$ci|keepalive|KEEPALIVE REPLY $(tu{nameaddr.uri})\n"); + $var(Query) = $_s(UPDATE keepalive SET selected = 0, failed = 0, time_sent = datetime('now') WHERE id = $(fu{uri.param,nat_id});); + xlog("L_DEBUG", "$ci|keepalive|KEEPALIVE UPDATE SQL => '$var(Query)'\n"); + mq_add("keepalive_db_queue", "$uuid(g)", "$var(Query)"); + t_drop(); +} + +failure_route[KEEPALIVE_FAULT] +{ + xlog("L_WARNING", "$ci|keepalive|received error $T_reply_code $T_reply_reason from $(tu{nameaddr.uri})\n"); + $var(Query) = $_s(UPDATE keepalive SET selected = 0, failed = failed + 1, time_sent = datetime('now') WHERE id = $(fu{uri.param,nat_id});); + xlog("L_DEBUG", "$ci|keepalive|KEEPALIVE REMOVE SQL => '$var(Query)'\n"); + mq_add("keepalive_db_queue", "$uuid(g)", "$var(Query)"); + t_drop(); +} + +route[KEEPALIVE_PING] +{ + $fs = $hdr(X-TM-SockInfo); + remove_hf_re("^X-TM-SockInfo"); + + force_rport(); + handle_ruri_alias(); + record_route(); + xlog("L_DEBUG", "$ci|local|sending $proto keepalive using $fs to $ru => $du => $tu\n"); + + t_on_reply("KEEPALIVE_REPLY"); + t_on_failure("KEEPALIVE_FAULT"); + t_set_fr(0, KEEPALIVE_TIMEOUT); + + t_relay(); +} + +route[KEEPALIVE_ON_REGISTRATION] +{ + + if($proto == "ws" || $proto == "wss") { + return; + } + + if (isbflagset(FLB_NATB)) { + if(!isbflagset(FLB_NATSIPPING)) { + return; + } + } else { + if($sel(cfg_get.kazoo.keepalive_nat_only) == 1) { + return; + } + } + + $var(alias) = $(avp(AVP_RECV_PARAM){uri.host}) + "~" + $(avp(AVP_RECV_PARAM){uri.port}) + "~" + $prid; + $var(contact) = $(ct{nameaddr.uri}) + ";alias=" + $var(alias); + $var(local_contact) = "sip:" + $Ri + ":" + $Rp + ";transport=" + $proto; + xlog("L_DEBUG", "$ci|keepalive|KEEPALIVE ON REG $var(save_result) $proto $RAut $var(contact) $var(alias) $(ct{nameaddr.uri}) $ct $avp(AVP_RECV_PARAM) $tu $xavp(ulrcd=>ruid) , $xavp(ulrcd=>contact) , $xavp(ulrcd=>expires)\n"); + + $var(slot) = $(var(contact){s.corehash, KEEPALIVE_S_TIMERS}); + $var(sql) = $_s(INSERT OR IGNORE INTO keepalive (contact, sockinfo, slot) values("$var(contact)", "$(RAut{uri.tosocket})", $var(slot))); + mq_add("keepalive_db_queue", "$ci", "$var(sql)"); + + return; +} + +route[KEEPALIVE_ON_SUBSCRIBE] +{ + if(!( ($sel(cfg_get.kazoo.keepalive_udp_only) == 1 && $proto != "udp") + || (!isflagset(FLT_NATS) && $sel(cfg_get.kazoo.keepalive_nat_only) == 1) + || ($proto == "ws" || $proto == "wss") + )) { + $var(slot) = $(subs(contact){s.corehash, KEEPALIVE_S_TIMERS}); + $var(sql) = $_s(INSERT OR IGNORE INTO keepalive (contact, sockinfo, slot) values("$subs(contact)", "$subs(sockinfo)", $var(slot))); + mq_add("keepalive_db_queue", "$ci", "$var(sql)"); + } +} diff --git a/kamailio/nat-traversal-role.cfg b/kamailio/nat-traversal-role.cfg index 6d62690..9d9451f 100644 --- a/kamailio/nat-traversal-role.cfg +++ b/kamailio/nat-traversal-role.cfg @@ -113,4 +113,6 @@ route[NAT_MANAGE] } +#!include_file "keepalive.cfg" + # vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab diff --git a/kamailio/presence-nat.cfg b/kamailio/presence-nat.cfg deleted file mode 100644 index a78ddfd..0000000 --- a/kamailio/presence-nat.cfg +++ /dev/null @@ -1,136 +0,0 @@ -######## Presence NAT ######## - -modparam("htable", "htable", "keepalive=>size=32;autoexpire=3600;initval=0;") - -#!trydef KZ_PRESENCE_KEEPALIVE_UDP_ONLY 0 -#!trydef PRESENCE_NAT_TIMERS 4 -#!trydef PRESENCE_NAT_INTERVAL 30 -#!trydef PRESENCE_NAT_SKIP_REGISTERED 1 -#!trydef PRESENCE_NAT_FROM_URI sip:keepalive@MY_HOSTNAME -#!trydef PRESENCE_NAT_TIMEOUT 3500 - -#!substdef "!PRESENCE_NAT_S_FROM_URI!sip:keepalive@MY_HOSTNAME!g" -#!substdef "!PRESENCE_NAT_S_TIMERS!$def(PRESENCE_NAT_TIMERS)!g" - -kazoo.presence_keepalive_udp_only = KZ_PRESENCE_KEEPALIVE_UDP_ONLY descr "should we keepalive nat phones for udp only" -kazoo.presence_keepalive_skip_registered = PRESENCE_NAT_SKIP_REGISTERED descr "skip if there's a registered contact from same ip/port (avoids multiple pings)" - -modparam("rtimer", "timer", "name=presence_nat_timer;interval=1;mode=PRESENCE_NAT_S_TIMERS;") -modparam("rtimer", "exec", "timer=presence_nat_timer;route=PRESENCE_NAT_TIMER") - -####### Presence Logic ######## - -route[PRESENCE_NAT] -{ - #!ifdef NAT_TRAVERSAL_ROLE - if (isflagset(FLT_NATS)) { - $xavp(regcfg=>match_received) = $su; - if(!( ($sel(cfg_get.kazoo.presence_keepalive_udp_only) == 1 && $proto != "udp") - || ($proto == "ws" || $proto == "wss") -#!ifdef REGISTRAR_ROLE - || ($sel(cfg_get.kazoo.presence_keepalive_skip_registered) == 1 && registered("location", "$rz:$Au", 2, 1) == 1) -#!endif - )) { - $var(slot) = $(subs(contact){s.corehash, PRESENCE_NAT_S_TIMERS}); - $var(sql) = $_s(INSERT OR IGNORE INTO presence_nat (contact, local_contact, slot) values("$subs(contact)", "$subs(local_contact)", $var(slot))); - mq_add("presence_last_notity", "$ci", "$var(sql)"); - } - } - #!endif - - return; -} - - -route[PRESENCE_NAT_TIMER] -{ - $var(Query) = $_s(UPDATE presence_nat SET selected = 1 WHERE slot = $rtimer_worker AND selected = 0 AND time_sent < datetime('now', '-$def(PRESENCE_NAT_INTERVAL) seconds')); - $var(sqlres) = sql_query("cb", "$var(Query)"); - if($var(sqlres) < 0) { - xlog("L_ERROR", "$rtimer_worker|log|error running query : $var(Query)\n"); - } else { - $var(nrows) = $sqlrows(cb); - xlog("L_DEBUG", "$rtimer_worker|log|selected $var(nrows) endpoints to ping\n"); - } - - $var(Query) = $_s(SELECT id, contact, local_contact from presence_nat WHERE slot = $rtimer_worker AND selected = 1); - xlog("L_DEBUG", "$rtimer_worker|timer|SQL => $var(Query)\n"); - if (sql_xquery("cb", "$var(Query)", "ra") == 1) - { - while($xavp(ra) != $null) { - $var(loop) = 0; - while($xavp(ra) != $null && $var(loop) < MAX_WHILE_LOOPS) { - route(PRESENCE_NAT_PING); - pv_unset("$xavp(ra)"); - $var(loop) = $var(loop) + 1; - } - } - } - - $var(Query) = $_s(UPDATE presence_nat SET selected = 2 WHERE slot = $rtimer_worker AND selected = 1); - $var(sqlres) = sql_query("cb", "$var(Query)"); - if($var(sqlres) < 0) { - xlog("L_ERROR", "$rtimer_worker|log|error running query : $var(Query)\n"); - } - -} - -route[PRESENCE_NAT_PING] -{ - $var(CallId) = $uuid(g); - xlog("L_DEBUG", "$var(CallId)|$rtimer_worker|timer|SENDING PING FROM $(xavp(ra=>local_contact){uri.tosocket}) TO => $xavp(ra=>contact)\n"); - - $uac_req(method)="OPTIONS"; - $uac_req(hdrs) = "X-TM-Local: PRESENCE_ROUTE_NAT_PING\r\nX-TM-Contact: " + $xavp(ra=>local_contact) + "\r\n"; - $uac_req(turi) = $xavp(ra=>contact); - $uac_req(ruri) = $xavp(ra=>contact); - $uac_req(furi) = $_s(PRESENCE_NAT_S_FROM_URI;nat_id=$xavp(ra=>id)); - $uac_req(ouri) = "sip:127.0.0.1:5090;transport=tcp"; - $uac_req(callid) = $var(CallId); - uac_req_send(); - -} - -onreply_route[PRESENCE_NAT_REPLY] -{ - xlog("L_DEBUG", "$ci|nat|NAT REPLY $(tu{nameaddr.uri})\n"); - $var(Query) = $_s(UPDATE presence_nat SET selected = 0, time_sent = datetime('now') WHERE id = $(fu{uri.param,nat_id});); - xlog("L_DEBUG", "$ci|nat|NAT UPDATE SQL => '$var(Query)'\n"); - mq_add("presence_last_notity", "$uuid(g)", "$var(Query)"); - t_drop(); -} - -failure_route[PRESENCE_NAT_FAULT] -{ - xlog("L_WARNING", "$ci|nat|received error $T_reply_code $T_reply_reason from $(tu{nameaddr.uri})\n"); - $var(Query) = $_s(DELETE FROM presence_nat WHERE id = $(fu{uri.param,nat_id});); - xlog("L_DEBUG", "$ci|nat|NAT REMOVE SQL => '$var(Query)'\n"); - mq_add("presence_last_notity", "$uuid(g)", "$var(Query)"); - t_drop(); -} - -route[PRESENCE_ROUTE_NAT_PING] -{ - $fs = $(hdr(X-TM-Contact){uri.tosocket}); - remove_hf_re("^X-TM-Contact"); - - force_rport(); - handle_ruri_alias(); - record_route(); - xlog("L_DEBUG", "$ci|local|sending nat keepalive from $fu to $ru => $du => $tu\n"); - - t_on_reply("PRESENCE_NAT_REPLY"); - t_on_failure("PRESENCE_NAT_FAULT"); - t_set_fr(0, PRESENCE_NAT_TIMEOUT); - - t_relay(); -} - -route[PRESENCE_NAT_ON_REGISTRATION] -{ - #!ifdef NAT_TRAVERSAL_ROLE - $var(Query) = $_s(DELETE FROM presence_nat WHERE contact like "$xavp(ulrcd=>contact)%";); - mq_add("presence_last_notity", "$uuid(g)", "$var(Query)"); - #!endif - return; -} diff --git a/kamailio/presence-notify.cfg b/kamailio/presence-notify.cfg index 0b9f46f..cfef4e7 100644 --- a/kamailio/presence-notify.cfg +++ b/kamailio/presence-notify.cfg @@ -1,7 +1,7 @@ #!trydef KZ_PRESENCE_REMOVE_WATCHER_ON_EXPIRED_REGISTRATION 1 kazoo.presence_notify = 1 descr "enable/disable sending notify callback to omnipresence" -kazoo.presence_notify_timeout = 3500 descr "timeout in ms waiting for notify reply" +kazoo.presence_notify_timeout = 5000 descr "timeout in ms waiting for notify reply" kazoo.presence_notify_log_body = 0 descr "logs the body sent in the notification" kazoo.presence_notify_log_resp_body = 0 descr "logs the body received from notification" kazoo.presence_notify_log_to_table = 1 descr "logs notify/reply to active_watchers_log table" diff --git a/kamailio/presence-role.cfg b/kamailio/presence-role.cfg index 83c6a01..8d405fc 100644 --- a/kamailio/presence-role.cfg +++ b/kamailio/presence-role.cfg @@ -65,7 +65,6 @@ kazoo.presence_require_authn = KZ_PRESENCE_REQUIRE_AUTHN descr "require authenti #!include_file "presence-notify.cfg" #!include_file "presence-reset.cfg" #!include_file "presence-fast-pickup.cfg" -#!include_file "presence-nat.cfg" ####### Presence Logic ######## @@ -165,7 +164,9 @@ route[HANDLE_NEW_SUBSCRIBE] route(DELETE_DUPLICATED_SUBSCRIPTIONS); route(SUBSCRIBE_AMQP); route(REQUEST_PROBE); - route(PRESENCE_NAT); + #!ifdef NAT_TRAVERSAL_ROLE + route(KEEPALIVE_ON_SUBSCRIBE); + #!endif } else { xlog("L_INFO", "$ci|stop|error $T_reply_code for new $hdr(Event) subscription from $fU to $tU in realm $fd\n"); } @@ -527,11 +528,6 @@ route[PRESENCE_LOCAL_REQUEST] route(PRESENCE_LOCAL_REQ_NOTIFY); } -route[PRESENCE_ON_REGISTRATION] -{ - route(PRESENCE_NAT_ON_REGISTRATION); -} - route[PRESENCE_AUTHN] { if($sel(cfg_get.kazoo.presence_require_authn) == 1) { diff --git a/kamailio/registrar-role.cfg b/kamailio/registrar-role.cfg index a8b9984..299234a 100644 --- a/kamailio/registrar-role.cfg +++ b/kamailio/registrar-role.cfg @@ -1,6 +1,6 @@ #### NAT PINGING PARAMS ### ## NEXT 2 SHOULD GO TOGETHER -## REGISTRAR_NAT_PING_TIMEOUT should be (REGISTRAR_NAT_PING_INTERVAL + 10) or 0 to disable +## REGISTRAR_NAT_PING_TIMEOUT should be (REGISTRAR_NAT_PING_INTERVAL * 3 + 10) or 0 to disable #!trydef REGISTRAR_NAT_PING_INTERVAL 30 #!trydef REGISTRAR_NAT_PING_TIMEOUT 100 @@ -64,17 +64,6 @@ modparam("usrloc", "fetch_rows", 400) modparam("usrloc", "handle_lost_tcp", REGISTRAR_HANDLE_LOST_TCP) modparam("usrloc", "close_expired_tcp", REGISTRAR_CLOSE_EXPIRED_TCP) -######## NAT Traversal module - signaling functions ######## -#!ifdef NAT_TRAVERSAL_ROLE -#!trydef NATHELPER_LOADED -loadmodule "nathelper.so" -modparam("nathelper", "natping_interval", REGISTRAR_NAT_PING_INTERVAL) -modparam("nathelper", "ping_nated_only", REGISTRAR_NAT_PING_NAT_ONLY) -modparam("nathelper", "natping_processes", REGISTRAR_NAT_PING_WORKERS) -modparam("nathelper", "sipping_bflag", FLB_NATSIPPING) -modparam("nathelper", "keepalive_timeout", REGISTRAR_NAT_PING_TIMEOUT) -#!endif - ####### SIP Registrar implementation module ########## loadmodule "registrar.so" modparam("registrar", "received_avp", "$avp(AVP_RECV_PARAM)") @@ -91,6 +80,24 @@ modparam("registrar", "received_param", "") modparam("registrar", "xavp_rcd", "ulrcd") modparam("registrar", "contact_max_size", REGISTRAR_CONTACT_MAX_SIZE) +####### NAT ########## +#!ifdef NAT_TRAVERSAL_ROLE +#!ifndef NATHELPER_LOADED +loadmodule "nathelper.so" +#!trydef NATHELPER_LOADED +#!endif +#!ifdef KEEPALIVE_USE_NATHELPER +modparam("nathelper", "natping_interval", REGISTRAR_NAT_PING_INTERVAL) +modparam("nathelper", "ping_nated_only", REGISTRAR_NAT_PING_NAT_ONLY) +modparam("nathelper", "natping_processes", REGISTRAR_NAT_PING_WORKERS) +modparam("nathelper", "sipping_bflag", FLB_NATSIPPING) +modparam("nathelper", "keepalive_timeout", REGISTRAR_NAT_PING_TIMEOUT) +#!else +modparam("nathelper", "natping_interval", 0) +modparam("nathelper", "natping_processes", 0) +#!endif +#!endif + ##### registrar realtime params ##### kazoo.registrar_error_min_expires = REGISTRAR_ERROR_MIN_EXPIRES descr "send error when UAS sends expires < min-expires" kazoo.registrar_error_missing_expires = REGISTRAR_ERROR_MISSING_EXPIRES descr "send error when UAS do not send expires header" @@ -107,7 +114,7 @@ kazoo.registrar_send_100 = REGISTRAR_SEND_100 descr "should we send 100 reply wh ####### Registrar Logic ######## -route[REGISTRAR_NAT] +route[REGISTRAR_NAT_FLAGS] { if (isflagset(FLT_NATS)) { xlog("L_DEBUG", "$ci|log|fixing contact for nat request\n"); @@ -275,7 +282,7 @@ route[SAVE_LOCATION] }; $sht(auth_cache=>$Au) = $var(password); - route(REGISTRAR_NAT); + route(REGISTRAR_NAT_FLAGS); $var(save_result) = save("location", "0x04"); if($var(save_result) < 0) { @@ -354,8 +361,10 @@ route[SAVE_LOCATION] route(PUSHER_ON_REGISTRATION); #!endif - #!ifdef PRESENCE_ROLE - route(PRESENCE_ON_REGISTRATION); + #!ifdef NAT_TRAVERSAL_ROLE + #!ifndef KEEPALIVE_USE_NATHELPER + route(KEEPALIVE_ON_REGISTRATION); + #!endif #!endif exit; From e2172a52afdef7317534eb723bb0abcad5eef144 Mon Sep 17 00:00:00 2001 From: lazedo Date: Mon, 11 Mar 2019 14:43:21 +0000 Subject: [PATCH 151/209] keepalive cleanup --- kamailio/keepalive.cfg | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/kamailio/keepalive.cfg b/kamailio/keepalive.cfg index dfa02b1..da9c620 100644 --- a/kamailio/keepalive.cfg +++ b/kamailio/keepalive.cfg @@ -5,6 +5,7 @@ #!trydef KEEPALIVE_TIMERS 7 #!trydef KEEPALIVE_INTERVAL 30 #!trydef KEEPALIVE_TIMEOUT 3500 +#!trydef KEEPALIVE_FAILED_THRESHOLD 2 #!substdef "!KEEPALIVE_S_FROM_URI!sip:keepalive@MY_HOSTNAME!g" #!substdef "!KEEPALIVE_S_TIMERS!$def(KEEPALIVE_TIMERS)!g" @@ -41,8 +42,20 @@ route[KEEPALIVE_DB_TIMER] } } +route[KEEPALIVE_CLEANUP] +{ + $var(Query) = $_s(update location set expires = last_modified where id in(select a.id from loc a inner join (select cast(substr(contact, 1, instr(contact,";")-1) as varchar(32)) contact from keepalive where slot = $rtimer_worker AND failed > $def(KEEPALIVE_FAILED_THRESHOLD)) b on substr(a.contact, 1, instr(a.contact,";")-1) = b.contact)); + sql_query("cb", "$var(Query)"); + $var(Query) = $_s(DELETE FROM active_watchers where id in(select a.id from keepalive a inner join active_watchers b on a.contact=b.contact where slot = $rtimer_worker and failed > $def(KEEPALIVE_FAILED_THRESHOLD))); + sql_query("cb", "$var(Query)"); + $var(Query) = $_s(DELETE FROM keepalive where slot = $rtimer_worker and failed > $def(KEEPALIVE_FAILED_THRESHOLD)); + sql_query("cb", "$var(Query)"); +} + route[KEEPALIVE_TIMER] { + route(KEEPALIVE_CLEANUP); + $var(Query) = $_s(UPDATE keepalive SET selected = 1 WHERE slot = $rtimer_worker AND selected = 0 AND time_sent < datetime('now', '-$def(KEEPALIVE_INTERVAL) seconds')); $var(sqlres) = sql_query("cb", "$var(Query)"); if($var(sqlres) < 0) { From a312696a90e47177d30de3a0fcdf6b9a8223d3d8 Mon Sep 17 00:00:00 2001 From: lazedo Date: Mon, 11 Mar 2019 14:45:23 +0000 Subject: [PATCH 152/209] comment udp checks --- kamailio/db_scripts/db_extra_check.sql | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/kamailio/db_scripts/db_extra_check.sql b/kamailio/db_scripts/db_extra_check.sql index 68a73d9..ebff6b3 100644 --- a/kamailio/db_scripts/db_extra_check.sql +++ b/kamailio/db_scripts/db_extra_check.sql @@ -2,12 +2,12 @@ do_db_extra_check() { # location -KazooDB -db ${DB_CURRENT_DB} "delete from location where socket not like 'udp:%';" +# KazooDB -db ${DB_CURRENT_DB} "delete from location where socket not like 'udp:%';" KazooDB -db ${DB_CURRENT_DB} "delete from location where expires > 0 and datetime(expires) < datetime('now', '-30 seconds');" KazooDB -db ${DB_CURRENT_DB} "delete from location_attrs where not exists(select id from location where ruid = location_attrs.ruid);" ## presence -KazooDB -db ${DB_CURRENT_DB} "delete from active_watchers where socket_info not like 'udp:%';" +# KazooDB -db ${DB_CURRENT_DB} "delete from active_watchers where socket_info not like 'udp:%';" KazooDB -db ${DB_CURRENT_DB} "delete from active_watchers where expires > 0 and datetime(expires, 'unixepoch') < datetime('now', '-10 seconds');" KazooDB -db ${DB_CURRENT_DB} "delete from presentity where expires > 0 AND datetime(expires, 'unixepoch') < datetime('now', '-10 seconds');" KazooDB -db ${DB_CURRENT_DB} "delete from presentity where id in(select id from presentities where state in('terminated','available'));" @@ -21,6 +21,7 @@ KazooDB -db ${DB_CURRENT_DB} "create table tmp_probe as select distinct a.event, KazooDB -db ${DB_CURRENT_DB} "delete from presentity where id in(select id from presentities where state in('early', 'confirmed', 'onthephone', 'busy'));" ## keepalive -KazooDB -db ${DB_CURRENT_DB} "delete from keepalive where sockinfo NOT LIKE 'udp%';" +# KazooDB -db ${DB_CURRENT_DB} "delete from keepalive where sockinfo NOT LIKE 'udp%';" +KazooDB -db ${DB_CURRENT_DB} "update keepalive set selected = 0;" } From efc8dd1a7b0a4ef57ba98eeda5d2732888511735 Mon Sep 17 00:00:00 2001 From: lazedo Date: Mon, 11 Mar 2019 15:14:14 +0000 Subject: [PATCH 153/209] add KEEPALIVE_ON_EXPIRED_REGISTRATION --- kamailio/presence-notify.cfg | 4 +--- kamailio/registrar-role.cfg | 6 ++++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/kamailio/presence-notify.cfg b/kamailio/presence-notify.cfg index cfef4e7..cf0edb6 100644 --- a/kamailio/presence-notify.cfg +++ b/kamailio/presence-notify.cfg @@ -1,4 +1,4 @@ -#!trydef KZ_PRESENCE_REMOVE_WATCHER_ON_EXPIRED_REGISTRATION 1 +#!trydef KZ_PRESENCE_REMOVE_WATCHER_ON_EXPIRED_REGISTRATION 0 kazoo.presence_notify = 1 descr "enable/disable sending notify callback to omnipresence" kazoo.presence_notify_timeout = 5000 descr "timeout in ms waiting for notify reply" @@ -202,8 +202,6 @@ route[PRESENCE_EXPIRED_REGISTRATION] $var(watcher) = $_s(sip:$ulc(exp=>aor)); $var(watcher_username) = $(var(watcher){uri.user}); $var(watcher_domain) = $(var(watcher){uri.host}); - $var(Query) = $_s(DELETE FROM presence_nat where contact in(select distinct contact from active_watchers WHERE watcher_username = "$var(watcher_username)" and watcher_domain = "$var(watcher_domain)");); - mq_add("presence_last_notity", "$uuid(g)", "$var(Query)"); $var(Query) = $_s(DELETE FROM active_watchers WHERE watcher_username = "$var(watcher_username)" and watcher_domain = "$var(watcher_domain)";); mq_add("presence_last_notity", "$uuid(g)", "$var(Query)"); } diff --git a/kamailio/registrar-role.cfg b/kamailio/registrar-role.cfg index 299234a..fd54ae1 100644 --- a/kamailio/registrar-role.cfg +++ b/kamailio/registrar-role.cfg @@ -462,6 +462,12 @@ event_route[usrloc:contact-expired] route(PRESENCE_EXPIRED_REGISTRATION); #!endif + #!ifdef NAT_TRAVERSAL_ROLE + #!ifndef KEEPALIVE_USE_NATHELPER + route(KEEPALIVE_ON_EXPIRED_REGISTRATION); + #!endif + #!endif + ## return until we handle this in ecallmr xlog("L_INFO", "$ulc(exp=>callid)|expired|removed registration for $ulc(exp=>aor) with contact : $ulc(exp=>addr)\n"); return; From af6a0244490ba41fd0570580e8effeb2bc188c1b Mon Sep 17 00:00:00 2001 From: lazedo Date: Mon, 11 Mar 2019 15:15:06 +0000 Subject: [PATCH 154/209] remove unused code --- kamailio/keepalive.cfg | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/kamailio/keepalive.cfg b/kamailio/keepalive.cfg index da9c620..4beb48a 100644 --- a/kamailio/keepalive.cfg +++ b/kamailio/keepalive.cfg @@ -178,3 +178,9 @@ route[KEEPALIVE_ON_SUBSCRIBE] mq_add("keepalive_db_queue", "$ci", "$var(sql)"); } } + +route[KEEPALIVE_ON_EXPIRED_REGISTRATION] +{ + $var(Query) = $_s(DELETE FROM keepalive where contact like "$ulc(exp=>addr)%"); + mq_add("keepalive_db_queue", "$uuid(g)", "$var(Query)"); +} From 1d7fbc80c97fd7a789e168ae318fdb0f0c834279 Mon Sep 17 00:00:00 2001 From: lazedo Date: Mon, 11 Mar 2019 18:04:35 +0000 Subject: [PATCH 155/209] use db_mode 3 by default on registrar --- kamailio/registrar-role.cfg | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/kamailio/registrar-role.cfg b/kamailio/registrar-role.cfg index fd54ae1..a7c6eaa 100644 --- a/kamailio/registrar-role.cfg +++ b/kamailio/registrar-role.cfg @@ -30,6 +30,10 @@ #!trydef REGISTRAR_AMQP_FLAGS 0 #!trydef REGISTRAR_AMQP_RK_PREFIX authn.req. #!trydef REGISTRAR_SEND_100 1 +#!trydef REGISTRAR_DB_MODE 3 +#!trydef REGISTRAR_DB_TIMER_CLEANUP 0 +#!trydef REGISTRAR_HANDLE_LOST_TCP 0 +#!trydef REGISTRAR_DB_TIMER_CLEANUP 0 #!ifdef REGISTRAR_WARM_CACHE #!substdef "!REGISTRAR_S_WARM_CACHE!dbtable=auth_cache;dbmode=1;!g" @@ -53,13 +57,20 @@ modparam("usrloc", "db_update_as_insert", 0) modparam("usrloc", "use_domain", 1) modparam("usrloc", "nat_bflag", FLB_NATB) modparam("usrloc", "db_url", "KAZOO_DB_URL") -modparam("usrloc", "db_mode", 1) -modparam("usrloc", "handle_lost_tcp", 1) -modparam("usrloc", "xavp_contact", "ulattrs") + +modparam("usrloc", "db_mode", REGISTRAR_DB_MODE) + +modparam("usrloc", "db_timer_clean", REGISTRAR_DB_TIMER_CLEANUP) +modparam("usrloc", "handle_lost_tcp", REGISTRAR_HANDLE_LOST_TCP) +modparam("usrloc", "rm_expired_delay", 30) + modparam("usrloc", "db_check_update", 1) +modparam("usrloc", "db_ops_ruid", 1) + + +modparam("usrloc", "xavp_contact", "ulattrs") modparam("usrloc", "timer_interval", 5) modparam("usrloc", "timer_procs", 1) -modparam("usrloc", "db_timer_clean", 1) modparam("usrloc", "fetch_rows", 400) modparam("usrloc", "handle_lost_tcp", REGISTRAR_HANDLE_LOST_TCP) modparam("usrloc", "close_expired_tcp", REGISTRAR_CLOSE_EXPIRED_TCP) From 69d6b053cb2b317521fd4be8d174f16faeeb1ed4 Mon Sep 17 00:00:00 2001 From: lazedo Date: Mon, 11 Mar 2019 19:25:28 +0000 Subject: [PATCH 156/209] fix table name --- kamailio/keepalive.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kamailio/keepalive.cfg b/kamailio/keepalive.cfg index 4beb48a..c98fbba 100644 --- a/kamailio/keepalive.cfg +++ b/kamailio/keepalive.cfg @@ -44,7 +44,7 @@ route[KEEPALIVE_DB_TIMER] route[KEEPALIVE_CLEANUP] { - $var(Query) = $_s(update location set expires = last_modified where id in(select a.id from loc a inner join (select cast(substr(contact, 1, instr(contact,";")-1) as varchar(32)) contact from keepalive where slot = $rtimer_worker AND failed > $def(KEEPALIVE_FAILED_THRESHOLD)) b on substr(a.contact, 1, instr(a.contact,";")-1) = b.contact)); + $var(Query) = $_s(update location set expires = last_modified where id in(select a.id from location a inner join (select cast(substr(contact, 1, instr(contact,";")-1) as varchar(32)) contact from keepalive where slot = $rtimer_worker AND failed > $def(KEEPALIVE_FAILED_THRESHOLD)) b on substr(a.contact, 1, instr(a.contact,";")-1) = b.contact)); sql_query("cb", "$var(Query)"); $var(Query) = $_s(DELETE FROM active_watchers where id in(select a.id from keepalive a inner join active_watchers b on a.contact=b.contact where slot = $rtimer_worker and failed > $def(KEEPALIVE_FAILED_THRESHOLD))); sql_query("cb", "$var(Query)"); From 695ff9dd9fd61f74d36518f85a83a766e0143cd5 Mon Sep 17 00:00:00 2001 From: lazedo Date: Mon, 11 Mar 2019 21:13:58 +0000 Subject: [PATCH 157/209] keepalive defaults --- kamailio/keepalive.cfg | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kamailio/keepalive.cfg b/kamailio/keepalive.cfg index c98fbba..2b2f608 100644 --- a/kamailio/keepalive.cfg +++ b/kamailio/keepalive.cfg @@ -2,9 +2,9 @@ #!trydef KEEPALIVE_NAT_ONLY 0 #!trydef KEEPALIVE_UDP_ONLY 0 -#!trydef KEEPALIVE_TIMERS 7 +#!trydef KEEPALIVE_TIMERS 8 #!trydef KEEPALIVE_INTERVAL 30 -#!trydef KEEPALIVE_TIMEOUT 3500 +#!trydef KEEPALIVE_TIMEOUT 5000 #!trydef KEEPALIVE_FAILED_THRESHOLD 2 #!substdef "!KEEPALIVE_S_FROM_URI!sip:keepalive@MY_HOSTNAME!g" From b2d71110a887a8b9257de39458839bdb956bb1e0 Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 12 Mar 2019 01:11:14 +0000 Subject: [PATCH 158/209] handle deregistrations in keepalive --- kamailio/keepalive.cfg | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/kamailio/keepalive.cfg b/kamailio/keepalive.cfg index 2b2f608..f153a58 100644 --- a/kamailio/keepalive.cfg +++ b/kamailio/keepalive.cfg @@ -160,8 +160,12 @@ route[KEEPALIVE_ON_REGISTRATION] $var(local_contact) = "sip:" + $Ri + ":" + $Rp + ";transport=" + $proto; xlog("L_DEBUG", "$ci|keepalive|KEEPALIVE ON REG $var(save_result) $proto $RAut $var(contact) $var(alias) $(ct{nameaddr.uri}) $ct $avp(AVP_RECV_PARAM) $tu $xavp(ulrcd=>ruid) , $xavp(ulrcd=>contact) , $xavp(ulrcd=>expires)\n"); - $var(slot) = $(var(contact){s.corehash, KEEPALIVE_S_TIMERS}); - $var(sql) = $_s(INSERT OR IGNORE INTO keepalive (contact, sockinfo, slot) values("$var(contact)", "$(RAut{uri.tosocket})", $var(slot))); + if($var(save_result) == 3) { + $var(sql) = $_s(DELETE FROM keepalive WHERE contact = "$var(contact)"); + } else { + $var(slot) = $(var(contact){s.corehash, KEEPALIVE_S_TIMERS}); + $var(sql) = $_s(INSERT OR IGNORE INTO keepalive (contact, sockinfo, slot) values("$var(contact)", "$(RAut{uri.tosocket})", $var(slot))); + } mq_add("keepalive_db_queue", "$ci", "$var(sql)"); return; From f7d64e84126e42957bb43ce7aec60f12ce7d1d3e Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 12 Mar 2019 01:57:14 +0000 Subject: [PATCH 159/209] allow runtime configuration of keepalive timeout --- kamailio/keepalive.cfg | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kamailio/keepalive.cfg b/kamailio/keepalive.cfg index f153a58..fd13a59 100644 --- a/kamailio/keepalive.cfg +++ b/kamailio/keepalive.cfg @@ -12,6 +12,7 @@ kazoo.keepalive_udp_only = KEEPALIVE_UDP_ONLY descr "should we send keepalive for udp only" kazoo.keepalive_nat_only = KEEPALIVE_NAT_ONLY descr "should we send keepalive for nat phones only" +kazoo.keepalive_timeout = KEEPALIVE_TIMEOUT descr "timeout in ms for keepalive transaction" modparam("rtimer", "timer", "name=keepalive_timer;interval=1;mode=KEEPALIVE_S_TIMERS;") modparam("rtimer", "exec", "timer=keepalive_timer;route=KEEPALIVE_TIMER") @@ -133,7 +134,7 @@ route[KEEPALIVE_PING] t_on_reply("KEEPALIVE_REPLY"); t_on_failure("KEEPALIVE_FAULT"); - t_set_fr(0, KEEPALIVE_TIMEOUT); + t_set_fr(0, $sel(cfg_get.kazoo.keepalive_timeout)); t_relay(); } From 4ad641cd90fc9df8f13de0fe626fab64b2f86f0e Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 12 Mar 2019 02:39:29 +0000 Subject: [PATCH 160/209] disable keepalive for clients that send OPTIONS/NOTIFY --- kamailio/default.cfg | 19 +++++++++++++++---- kamailio/keepalive.cfg | 12 ++++++++++++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/kamailio/default.cfg b/kamailio/default.cfg index e197fb5..1af80db 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -454,9 +454,11 @@ route[HANDLE_OPTIONS] } #!endif - ## TODO: remove nat if client is sending options - sl_send_reply("200", "Rawr!!"); + + #!ifdef NAT_TRAVERSAL_ROLE + route(KEEPALIVE_ON_OPTIONS); + #!endif } exit; } @@ -479,7 +481,12 @@ route[HANDLE_NOTIFY] } #!endif - ## TODO: verify we're not routing to ourselves + ## verify we're not routing to ourselves + if(is_myself($du)) { + xlog("L_INFO", "$ci|log|notify from internal to invalid destination $ruid\n"); + sl_send_reply("200", "Rawr!!"); + exit; + } route(INTERNAL_TO_EXTERNAL_RELAY); } else { @@ -489,7 +496,6 @@ route[HANDLE_NOTIFY] } #!endif - ## TODO: remove nat if client is sending notify for keepalive if($hdr(Event) == "keep-alive") { xlog("L_INFO", "$ci|stop|replying to keep alive\n"); @@ -498,6 +504,11 @@ route[HANDLE_NOTIFY] xlog("L_INFO", "$ci|stop|consuming event $hdr(Event)\n"); sl_send_reply("200", "Rawr!!"); } + + #!ifdef NAT_TRAVERSAL_ROLE + route(KEEPALIVE_ON_NOTIFY); + #!endif + } exit; } diff --git a/kamailio/keepalive.cfg b/kamailio/keepalive.cfg index fd13a59..faf52a2 100644 --- a/kamailio/keepalive.cfg +++ b/kamailio/keepalive.cfg @@ -189,3 +189,15 @@ route[KEEPALIVE_ON_EXPIRED_REGISTRATION] $var(Query) = $_s(DELETE FROM keepalive where contact like "$ulc(exp=>addr)%"); mq_add("keepalive_db_queue", "$uuid(g)", "$var(Query)"); } + +route[KEEPALIVE_ON_OPTIONS] +{ + $var(Query) = $_s(UPDATE keepalive set selected = 3 where contact like "%alias=$si~$sp~$prid%"); + mq_add("keepalive_db_queue", "$uuid(g)", "$var(Query)"); +} + +route[KEEPALIVE_ON_NOTIFY] +{ + $var(Query) = $_s(UPDATE keepalive set selected = 4 where contact like "%alias=$si~$sp~$prid%"); + mq_add("keepalive_db_queue", "$uuid(g)", "$var(Query)"); +} From 7b92ece9e41333eed7be668c262baaa9d89ab6a8 Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 12 Mar 2019 22:00:55 +0000 Subject: [PATCH 161/209] add REGISTRAR_DB_REMOVE_EXPIRED_DELAY macro --- kamailio/registrar-role.cfg | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kamailio/registrar-role.cfg b/kamailio/registrar-role.cfg index a7c6eaa..6144bd6 100644 --- a/kamailio/registrar-role.cfg +++ b/kamailio/registrar-role.cfg @@ -34,6 +34,7 @@ #!trydef REGISTRAR_DB_TIMER_CLEANUP 0 #!trydef REGISTRAR_HANDLE_LOST_TCP 0 #!trydef REGISTRAR_DB_TIMER_CLEANUP 0 +#!trydef REGISTRAR_DB_REMOVE_EXPIRED_DELAY 30 #!ifdef REGISTRAR_WARM_CACHE #!substdef "!REGISTRAR_S_WARM_CACHE!dbtable=auth_cache;dbmode=1;!g" @@ -62,7 +63,7 @@ modparam("usrloc", "db_mode", REGISTRAR_DB_MODE) modparam("usrloc", "db_timer_clean", REGISTRAR_DB_TIMER_CLEANUP) modparam("usrloc", "handle_lost_tcp", REGISTRAR_HANDLE_LOST_TCP) -modparam("usrloc", "rm_expired_delay", 30) +modparam("usrloc", "rm_expired_delay", REGISTRAR_DB_REMOVE_EXPIRED_DELAY) modparam("usrloc", "db_check_update", 1) modparam("usrloc", "db_ops_ruid", 1) From aefb3582355b48b560f293bc1c848864f95813b6 Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 12 Mar 2019 22:01:27 +0000 Subject: [PATCH 162/209] cfgutils lock_set_size param --- kamailio/default.cfg | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/kamailio/default.cfg b/kamailio/default.cfg index 1af80db..ec71f21 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -113,7 +113,12 @@ loadmodule "path.so" loadmodule "ctl.so" modparam("ctl", "binrpc_buffer_size", 4096) loadmodule "cfg_rpc.so" + +######## Kamailio config utils module ######## loadmodule "cfgutils.so" +modparam("cfgutils", "lock_set_size", 4) + +######## Kamailio corex module ######## loadmodule "corex.so" ######## Kamailio uuid module ######## From 3627e1eecf01ca8bb992f829306a9b34b8beefde Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 12 Mar 2019 22:01:42 +0000 Subject: [PATCH 163/209] escape account name --- kamailio/auth.cfg | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/kamailio/auth.cfg b/kamailio/auth.cfg index 1313be2..4ba7e17 100644 --- a/kamailio/auth.cfg +++ b/kamailio/auth.cfg @@ -16,15 +16,15 @@ route[AUTH] route[AUTH_HEADERS] { remove_hf_re("^X-"); - + xavp_params_implode("hf", "$var(outx)"); $var(out) = $(var(outx){re.subst,/^(.*);$$/\1/}); $var(c) = $(var(out){param.count}); xlog("L_DEBUG", "$ci|auth|headers $var(c) => $var(out) => $var(outx)\n"); while($var(c) > 0) { $var(idx) = $var(c) - 1; - xlog("L_DEBUG", "$ci|auth|adding $(var(out){param.name,$var(idx)}): $(var(out){param.valueat,$var(idx)})\n"); - append_hf("$(var(out){param.name,$var(idx)}): $(var(out){param.valueat,$var(idx)})\r\n"); + xlog("L_DEBUG", "$ci|auth|adding $(var(out){param.name,$var(idx)}): $(var(out){param.valueat,$var(idx)}{s.unescape.param})\n"); + append_hf("$(var(out){param.name,$var(idx)}): $(var(out){param.valueat,$var(idx)}{s.unescape.param})\r\n"); $var(c) = $var(c) - 1; } @@ -85,7 +85,8 @@ route[AUTH_CCVS] $xavp(hf[0]=>X-ecallmgr_Account-Realm) = $(xavp(ulattrs=>custom_channel_vars){kz.json,Account-Realm}); if($(xavp(ulattrs=>custom_channel_vars){kz.json,Account-Name}{s.len}) > 0) - $xavp(hf[0]=>X-ecallmgr_Account-Name) = $(xavp(ulattrs=>custom_channel_vars){kz.json,Account-Name}); + $xavp(hf[0]=>X-ecallmgr_Account-Name) = $(xavp(ulattrs=>custom_channel_vars){kz.json,Account-Name}{s.escape.param}); + if($(xavp(ulattrs=>custom_channel_vars){kz.json,Presence-ID}{s.len}) > 0) $xavp(hf[0]=>X-ecallmgr_Presence-ID) = $(xavp(ulattrs=>custom_channel_vars){kz.json,Presence-ID}); From f615f23212be138c6dc4258750cd0ca7c2a1c91b Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 12 Mar 2019 22:13:50 +0000 Subject: [PATCH 164/209] add a lock for db ops since we have several workers --- kamailio/keepalive.cfg | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/kamailio/keepalive.cfg b/kamailio/keepalive.cfg index faf52a2..159b3fb 100644 --- a/kamailio/keepalive.cfg +++ b/kamailio/keepalive.cfg @@ -17,7 +17,7 @@ kazoo.keepalive_timeout = KEEPALIVE_TIMEOUT descr "timeout in ms for keepalive t modparam("rtimer", "timer", "name=keepalive_timer;interval=1;mode=KEEPALIVE_S_TIMERS;") modparam("rtimer", "exec", "timer=keepalive_timer;route=KEEPALIVE_TIMER") -modparam("rtimer", "timer", "name=keepalive_db_timer;interval=250000u;mode=1;") +modparam("rtimer", "timer", "name=keepalive_db_timer;interval=1;mode=1;") modparam("rtimer", "exec", "timer=keepalive_db_timer;route=KEEPALIVE_DB_TIMER") modparam("mqueue","mqueue", "name=keepalive_db_queue") @@ -28,6 +28,7 @@ route[KEEPALIVE_DB_TIMER] while(mq_fetch("keepalive_db_queue") == 1 && $var(runloop) < MAX_WHILE_LOOPS) { $var(ci) = $mqk(keepalive_db_queue); xlog("L_DEBUG", "Query : $mqv(keepalive_db_queue)\n"); + lock("keepalive"); $var(sqlres) = sql_query("cb", "$mqv(keepalive_db_queue)"); xlog("L_DEBUG", "Query result : $var(sqlres)\n"); if($var(sqlres) < 0) { @@ -39,24 +40,28 @@ route[KEEPALIVE_DB_TIMER] xlog("L_DEBUG", "$var(ci)|log|error no rows affected when running query\n"); } } + unlock("keepalive"); $var(runloop) = $var(runloop) + 1; } } route[KEEPALIVE_CLEANUP] { + lock("keepalive"); $var(Query) = $_s(update location set expires = last_modified where id in(select a.id from location a inner join (select cast(substr(contact, 1, instr(contact,";")-1) as varchar(32)) contact from keepalive where slot = $rtimer_worker AND failed > $def(KEEPALIVE_FAILED_THRESHOLD)) b on substr(a.contact, 1, instr(a.contact,";")-1) = b.contact)); sql_query("cb", "$var(Query)"); $var(Query) = $_s(DELETE FROM active_watchers where id in(select a.id from keepalive a inner join active_watchers b on a.contact=b.contact where slot = $rtimer_worker and failed > $def(KEEPALIVE_FAILED_THRESHOLD))); sql_query("cb", "$var(Query)"); $var(Query) = $_s(DELETE FROM keepalive where slot = $rtimer_worker and failed > $def(KEEPALIVE_FAILED_THRESHOLD)); sql_query("cb", "$var(Query)"); + unlock("keepalive"); } route[KEEPALIVE_TIMER] { route(KEEPALIVE_CLEANUP); + lock("keepalive"); $var(Query) = $_s(UPDATE keepalive SET selected = 1 WHERE slot = $rtimer_worker AND selected = 0 AND time_sent < datetime('now', '-$def(KEEPALIVE_INTERVAL) seconds')); $var(sqlres) = sql_query("cb", "$var(Query)"); if($var(sqlres) < 0) { @@ -65,7 +70,9 @@ route[KEEPALIVE_TIMER] $var(nrows) = $sqlrows(cb); xlog("L_DEBUG", "$rtimer_worker|log|selected $var(nrows) endpoints to ping\n"); } + unlock("keepalive"); + lock("keepalive"); $var(Query) = $_s(SELECT id, contact, sockinfo from keepalive WHERE slot = $rtimer_worker AND selected = 1); xlog("L_DEBUG", "$rtimer_worker|timer|SQL => $var(Query)\n"); if (sql_xquery("cb", "$var(Query)", "ra") == 1) @@ -79,12 +86,16 @@ route[KEEPALIVE_TIMER] } } } + unlock("keepalive"); + lock("keepalive"); $var(Query) = $_s(UPDATE keepalive SET selected = 2 WHERE slot = $rtimer_worker AND selected = 1); $var(sqlres) = sql_query("cb", "$var(Query)"); if($var(sqlres) < 0) { xlog("L_ERROR", "$rtimer_worker|log|error running query : $var(Query)\n"); } + unlock("keepalive"); + } From d67f030acb8bde51d4436bf5ff574310b2cb4675 Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 12 Mar 2019 22:14:35 +0000 Subject: [PATCH 165/209] don't advertise 127.0.0.1 --- kamailio/nodes-role.cfg | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/kamailio/nodes-role.cfg b/kamailio/nodes-role.cfg index 3b1ecdd..cb985a2 100644 --- a/kamailio/nodes-role.cfg +++ b/kamailio/nodes-role.cfg @@ -223,23 +223,25 @@ route[LISTENER_STATUS] $var(listener) = $(jsonrpl(body){kz.json,result[$var(loop)]}); $var(proto) = $(var(listener){kz.json,PROTO}); $var(address) = $(var(listener){kz.json,ADDRLIST.ADDR}); - $var(port) = $(var(listener){kz.json,PORT}); - if($var(port) == "WS_PORT") { - $var(proto) = "ws"; + if($var(address) != "127.0.0.1") { + $var(port) = $(var(listener){kz.json,PORT}); + if($var(port) == "WS_PORT") { + $var(proto) = "ws"; + } + if($var(port) == "WSS_PORT") { + $var(proto) = "wss"; + } + $var(uri) = $_s($var(proto):$var(address):$var(port)); + if($(var(listener){kz.json,ADVERTISE}) != "-") { + $var(advertise) = $_s( , "advertise" : "$(var(listener){kz.json,ADVERTISE})"); + } else { + $var(advertise) = ""; + } + $var(x) = $_s("$var(uri)" : {"proto" : "$var(proto)", "address" : "$var(address)", "port" : $var(port) $var(advertise) }); + $var(listeners) = $_s($var(listeners)$var(sep)$var(x)); + $var(sep) = " , "; } - if($var(port) == "WSS_PORT") { - $var(proto) = "wss"; - } - $var(uri) = $_s($var(proto):$var(address):$var(port)); - if($(var(listener){kz.json,ADVERTISE}) != "-") { - $var(advertise) = $_s( , "advertise" : "$(var(listener){kz.json,ADVERTISE})"); - } else { - $var(advertise) = ""; - } - $var(x) = $_s("$var(uri)" : {"proto" : "$var(proto)", "address" : "$var(address)", "port" : $var(port) $var(advertise) }); - $var(listeners) = $_s($var(listeners)$var(sep)$var(x)); $var(loop) = $var(loop) + 1; - $var(sep) = " , "; } $var(listeners) = $_s({"Listeners" : { $var(listeners) }}); } From 8bf8d8afe8ed443473fd10d820dfb43e32e651e3 Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 13 Mar 2019 02:21:24 +0000 Subject: [PATCH 166/209] reset only local options --- kamailio/db_scripts/db_extra_check.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kamailio/db_scripts/db_extra_check.sql b/kamailio/db_scripts/db_extra_check.sql index ebff6b3..a9d3502 100644 --- a/kamailio/db_scripts/db_extra_check.sql +++ b/kamailio/db_scripts/db_extra_check.sql @@ -22,6 +22,6 @@ KazooDB -db ${DB_CURRENT_DB} "delete from presentity where id in(select id from ## keepalive # KazooDB -db ${DB_CURRENT_DB} "delete from keepalive where sockinfo NOT LIKE 'udp%';" -KazooDB -db ${DB_CURRENT_DB} "update keepalive set selected = 0;" +KazooDB -db ${DB_CURRENT_DB} "update keepalive set selected = 0, time_sent = datetime('now') where selected < 3;" } From d5a8e26d531238e70a1943d5ed4a12474d3fd504 Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 13 Mar 2019 02:21:46 +0000 Subject: [PATCH 167/209] update db schema & views --- kamailio/db_scripts/db_kazoo-specific | 25 +++++++++++++++++++++- kamailio/db_scripts/ww_keepalive_views.sql | 20 +++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 kamailio/db_scripts/ww_keepalive_views.sql diff --git a/kamailio/db_scripts/db_kazoo-specific b/kamailio/db_scripts/db_kazoo-specific index 50655f2..5c608f5 100644 --- a/kamailio/db_scripts/db_kazoo-specific +++ b/kamailio/db_scripts/db_kazoo-specific @@ -54,9 +54,10 @@ CREATE TABLE keepalive ( failed INTEGER DEFAULT 0, CONSTRAINT keepalive_idx UNIQUE (contact), CONSTRAINT keepalive_idx_2 UNIQUE (slot, selected, time_sent, contact) + CONSTRAINT keepalive_idx_3 UNIQUE (slot, failed, contact) ); -INSERT INTO version (table_name, table_version) values ('keepalive','1'); +INSERT INTO version (table_name, table_version) values ('keepalive','2'); create table auth_cache as select * from htable; INSERT INTO version (table_name, table_version) select 'auth_cache', table_version from version where table_name = 'htable'; @@ -89,6 +90,28 @@ INSERT INTO version (table_name, table_version) select 'auth_cache', table_versi create unique index if not exists idx_dispatcher_destination on dispatcher(destination); + +CREATE VIEW w_keepalive_contact as +SELECT id, slot, failed, case when instr(contact,";") > 0 + then substr(contact, 1, instr(contact,";")-1) + else contact + end as contact +from keepalive; + +CREATE VIEW w_location_contact as +SELECT id, case when instr(contact,";") > 0 + then substr(contact, 1, instr(contact,";")-1) + else contact + end as contact +from location; + +CREATE VIEW w_watchers_contact as +select id, case when instr(contact,";") > 0 + then substr(contact, 1, instr(contact,";")-1) + else contact + end as contact +from active_watchers; + EOF } diff --git a/kamailio/db_scripts/ww_keepalive_views.sql b/kamailio/db_scripts/ww_keepalive_views.sql new file mode 100644 index 0000000..7882ed2 --- /dev/null +++ b/kamailio/db_scripts/ww_keepalive_views.sql @@ -0,0 +1,20 @@ +CREATE VIEW w_keepalive_contact as +SELECT id, slot, failed, case when instr(contact,";") > 0 + then substr(contact, 1, instr(contact,";")-1) + else contact + end as contact +from keepalive; + +CREATE VIEW w_location_contact as +SELECT id, case when instr(contact,";") > 0 + then substr(contact, 1, instr(contact,";")-1) + else contact + end as contact +from location; + +CREATE VIEW w_watchers_contact as +select id, case when instr(contact,";") > 0 + then substr(contact, 1, instr(contact,";")-1) + else contact + end as contact +from active_watchers; From 06f4c6394222c95657757025d5fdcd5bb524ee4c Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 13 Mar 2019 02:22:37 +0000 Subject: [PATCH 168/209] update keepalive --- kamailio/keepalive.cfg | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/kamailio/keepalive.cfg b/kamailio/keepalive.cfg index 159b3fb..76cac86 100644 --- a/kamailio/keepalive.cfg +++ b/kamailio/keepalive.cfg @@ -6,6 +6,8 @@ #!trydef KEEPALIVE_INTERVAL 30 #!trydef KEEPALIVE_TIMEOUT 5000 #!trydef KEEPALIVE_FAILED_THRESHOLD 2 +#!trydef KEEPALIVE_EXPIRE_SUBSCRIPTIONS 1 +#!trydef KEEPALIVE_EXPIRE_REGISTRATIONS 1 #!substdef "!KEEPALIVE_S_FROM_URI!sip:keepalive@MY_HOSTNAME!g" #!substdef "!KEEPALIVE_S_TIMERS!$def(KEEPALIVE_TIMERS)!g" @@ -13,6 +15,8 @@ kazoo.keepalive_udp_only = KEEPALIVE_UDP_ONLY descr "should we send keepalive for udp only" kazoo.keepalive_nat_only = KEEPALIVE_NAT_ONLY descr "should we send keepalive for nat phones only" kazoo.keepalive_timeout = KEEPALIVE_TIMEOUT descr "timeout in ms for keepalive transaction" +kazoo.keepalive_expire_subscriptions = KEEPALIVE_EXPIRE_SUBSCRIPTIONS descr "expires subscriptions that do not respond to OPTIONS" +kazoo.keepalive_expire_registrations = KEEPALIVE_EXPIRE_REGISTRATIONS descr "expires registrations that do not respond to OPTIONS" modparam("rtimer", "timer", "name=keepalive_timer;interval=1;mode=KEEPALIVE_S_TIMERS;") modparam("rtimer", "exec", "timer=keepalive_timer;route=KEEPALIVE_TIMER") @@ -48,10 +52,14 @@ route[KEEPALIVE_DB_TIMER] route[KEEPALIVE_CLEANUP] { lock("keepalive"); - $var(Query) = $_s(update location set expires = last_modified where id in(select a.id from location a inner join (select cast(substr(contact, 1, instr(contact,";")-1) as varchar(32)) contact from keepalive where slot = $rtimer_worker AND failed > $def(KEEPALIVE_FAILED_THRESHOLD)) b on substr(a.contact, 1, instr(a.contact,";")-1) = b.contact)); - sql_query("cb", "$var(Query)"); - $var(Query) = $_s(DELETE FROM active_watchers where id in(select a.id from keepalive a inner join active_watchers b on a.contact=b.contact where slot = $rtimer_worker and failed > $def(KEEPALIVE_FAILED_THRESHOLD))); - sql_query("cb", "$var(Query)"); + if($sel(cfg_get.kazoo.keepalive_expire_registrations) == 1) { + $var(Query) = $_s(update location set expires = last_modified where id in(select b.id from w_keepalive_contact a inner join w_location_contact b on a.contact = b.contact where slot = $rtimer_worker AND failed > $def(KEEPALIVE_FAILED_THRESHOLD))); + sql_query("cb", "$var(Query)"); + } + if($sel(cfg_get.kazoo.keepalive_expire_subscriptions) == 1) { + $var(Query) = $_s(DELETE FROM active_watchers where id in(select b.id from w_keepalive_contact a inner join w_watchers_contact b on a.contact = b.contact where slot = $rtimer_worker and failed > $def(KEEPALIVE_FAILED_THRESHOLD))); + sql_query("cb", "$var(Query)"); + } $var(Query) = $_s(DELETE FROM keepalive where slot = $rtimer_worker and failed > $def(KEEPALIVE_FAILED_THRESHOLD)); sql_query("cb", "$var(Query)"); unlock("keepalive"); From feabd068f339221a036c6f4febc6db806c71a1e3 Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 13 Mar 2019 02:28:06 +0000 Subject: [PATCH 169/209] runtime for failed threshold --- kamailio/keepalive.cfg | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/kamailio/keepalive.cfg b/kamailio/keepalive.cfg index 76cac86..d5f68fd 100644 --- a/kamailio/keepalive.cfg +++ b/kamailio/keepalive.cfg @@ -15,6 +15,7 @@ kazoo.keepalive_udp_only = KEEPALIVE_UDP_ONLY descr "should we send keepalive for udp only" kazoo.keepalive_nat_only = KEEPALIVE_NAT_ONLY descr "should we send keepalive for nat phones only" kazoo.keepalive_timeout = KEEPALIVE_TIMEOUT descr "timeout in ms for keepalive transaction" +kazoo.keepalive_failed_threshold = KEEPALIVE_FAILED_THRESHOLD descr "how many times can a device fail to respond to OPTIONS" kazoo.keepalive_expire_subscriptions = KEEPALIVE_EXPIRE_SUBSCRIPTIONS descr "expires subscriptions that do not respond to OPTIONS" kazoo.keepalive_expire_registrations = KEEPALIVE_EXPIRE_REGISTRATIONS descr "expires registrations that do not respond to OPTIONS" @@ -53,14 +54,14 @@ route[KEEPALIVE_CLEANUP] { lock("keepalive"); if($sel(cfg_get.kazoo.keepalive_expire_registrations) == 1) { - $var(Query) = $_s(update location set expires = last_modified where id in(select b.id from w_keepalive_contact a inner join w_location_contact b on a.contact = b.contact where slot = $rtimer_worker AND failed > $def(KEEPALIVE_FAILED_THRESHOLD))); + $var(Query) = $_s(update location set expires = last_modified where id in(select b.id from w_keepalive_contact a inner join w_location_contact b on a.contact = b.contact where slot = $rtimer_worker AND failed > $sel(cfg_get.kazoo.keepalive_failed_threshold))); sql_query("cb", "$var(Query)"); } if($sel(cfg_get.kazoo.keepalive_expire_subscriptions) == 1) { - $var(Query) = $_s(DELETE FROM active_watchers where id in(select b.id from w_keepalive_contact a inner join w_watchers_contact b on a.contact = b.contact where slot = $rtimer_worker and failed > $def(KEEPALIVE_FAILED_THRESHOLD))); + $var(Query) = $_s(DELETE FROM active_watchers where id in(select b.id from w_keepalive_contact a inner join w_watchers_contact b on a.contact = b.contact where slot = $rtimer_worker and failed > $sel(cfg_get.kazoo.keepalive_failed_threshold))); sql_query("cb", "$var(Query)"); } - $var(Query) = $_s(DELETE FROM keepalive where slot = $rtimer_worker and failed > $def(KEEPALIVE_FAILED_THRESHOLD)); + $var(Query) = $_s(DELETE FROM keepalive where slot = $rtimer_worker and failed > $sel(cfg_get.kazoo.keepalive_failed_threshold)); sql_query("cb", "$var(Query)"); unlock("keepalive"); } From 1b601b66765342c69201784304023d73c0e16807 Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 13 Mar 2019 02:32:42 +0000 Subject: [PATCH 170/209] RESET_NON_UDP_ENABLED from env --- kamailio/db_scripts/db_extra_check.sql | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/kamailio/db_scripts/db_extra_check.sql b/kamailio/db_scripts/db_extra_check.sql index a9d3502..92e18ba 100644 --- a/kamailio/db_scripts/db_extra_check.sql +++ b/kamailio/db_scripts/db_extra_check.sql @@ -2,12 +2,17 @@ do_db_extra_check() { # location -# KazooDB -db ${DB_CURRENT_DB} "delete from location where socket not like 'udp:%';" +if [[ $RESET_NON_UDP_ENABLED == "true" ]]; then + KazooDB -db ${DB_CURRENT_DB} "delete from location where socket not like 'udp:%';" +fi + KazooDB -db ${DB_CURRENT_DB} "delete from location where expires > 0 and datetime(expires) < datetime('now', '-30 seconds');" KazooDB -db ${DB_CURRENT_DB} "delete from location_attrs where not exists(select id from location where ruid = location_attrs.ruid);" ## presence -# KazooDB -db ${DB_CURRENT_DB} "delete from active_watchers where socket_info not like 'udp:%';" +if [[ $RESET_NON_UDP_ENABLED == "true" ]]; then + KazooDB -db ${DB_CURRENT_DB} "delete from active_watchers where socket_info not like 'udp:%';" +fi KazooDB -db ${DB_CURRENT_DB} "delete from active_watchers where expires > 0 and datetime(expires, 'unixepoch') < datetime('now', '-10 seconds');" KazooDB -db ${DB_CURRENT_DB} "delete from presentity where expires > 0 AND datetime(expires, 'unixepoch') < datetime('now', '-10 seconds');" KazooDB -db ${DB_CURRENT_DB} "delete from presentity where id in(select id from presentities where state in('terminated','available'));" @@ -21,7 +26,9 @@ KazooDB -db ${DB_CURRENT_DB} "create table tmp_probe as select distinct a.event, KazooDB -db ${DB_CURRENT_DB} "delete from presentity where id in(select id from presentities where state in('early', 'confirmed', 'onthephone', 'busy'));" ## keepalive -# KazooDB -db ${DB_CURRENT_DB} "delete from keepalive where sockinfo NOT LIKE 'udp%';" +if [[ $RESET_NON_UDP_ENABLED == "true" ]]; then + KazooDB -db ${DB_CURRENT_DB} "delete from keepalive where sockinfo NOT LIKE 'udp%';" +fi KazooDB -db ${DB_CURRENT_DB} "update keepalive set selected = 0, time_sent = datetime('now') where selected < 3;" } From b0f81e0bbb3f6697b235809f8731f119315ea02d Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 13 Mar 2019 02:35:33 +0000 Subject: [PATCH 171/209] allow options to be loaded from kazoo-kamailio folder --- system/sbin/kazoo-kamailio | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/system/sbin/kazoo-kamailio b/system/sbin/kazoo-kamailio index 81e4aa9..ff533a9 100755 --- a/system/sbin/kazoo-kamailio +++ b/system/sbin/kazoo-kamailio @@ -8,6 +8,10 @@ if [ -f /etc/sysconfig/kamailio ]; then . /etc/sysconfig/kamailio fi +if [ -f /etc/kazoo/kamailio/options ]; then + . /etc/kazoo/kamailio/options +fi + RETVAL=1 USER=${KAMAILIO_USER:-kamailio} GROUP=${KAMAILIO_GROUP:-daemon} From d156f5f9d4f421d3d3a19d36cb0efe91a142c750 Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 13 Mar 2019 03:59:44 +0000 Subject: [PATCH 172/209] schema update --- kamailio/db_scripts/check-kazoodb-sql.sh | 2 +- kamailio/db_scripts/db_kazoo-specific | 4 +++- .../db_scripts/vw_w_keepalive_contact.sql | 6 ++++++ kamailio/db_scripts/vw_w_location_contact.sql | 6 ++++++ kamailio/db_scripts/vw_w_watchers_contact.sql | 6 ++++++ kamailio/db_scripts/ww_keepalive_views.sql | 20 ------------------- 6 files changed, 22 insertions(+), 22 deletions(-) create mode 100644 kamailio/db_scripts/vw_w_keepalive_contact.sql create mode 100644 kamailio/db_scripts/vw_w_location_contact.sql create mode 100644 kamailio/db_scripts/vw_w_watchers_contact.sql delete mode 100644 kamailio/db_scripts/ww_keepalive_views.sql diff --git a/kamailio/db_scripts/check-kazoodb-sql.sh b/kamailio/db_scripts/check-kazoodb-sql.sh index ab00bec..80d0955 100755 --- a/kamailio/db_scripts/check-kazoodb-sql.sh +++ b/kamailio/db_scripts/check-kazoodb-sql.sh @@ -25,7 +25,7 @@ fi for VIEW in `ls ${DB_SCRIPT_DIR}/vw_*.sql`; do filename=$(basename -- "$VIEW") filename="${filename%.*}" - viewname=$(echo -n "$filename" | cut -d'_' -f2) + viewname=${filename#*_} v1=$(KazooDB -db ${DB_CURRENT_DB} "select sql from sqlite_master where type='view' and name='$viewname'" 2> /dev/null | tr -d ' ' | md5sum | cut -d ' ' -f1) v2=$(cat $VIEW | tr -d ' ' | md5sum | cut -d ' ' -f1) if [[ "$v1" != "$v2" ]]; then diff --git a/kamailio/db_scripts/db_kazoo-specific b/kamailio/db_scripts/db_kazoo-specific index 5c608f5..c67b5ca 100644 --- a/kamailio/db_scripts/db_kazoo-specific +++ b/kamailio/db_scripts/db_kazoo-specific @@ -57,7 +57,9 @@ CREATE TABLE keepalive ( CONSTRAINT keepalive_idx_3 UNIQUE (slot, failed, contact) ); -INSERT INTO version (table_name, table_version) values ('keepalive','2'); +INSERT INTO version (table_name, table_version) values ('keepalive','3'); + +CREATE UNIQUE INDEX active_watchers_contact ON active_watchers (contact, id); create table auth_cache as select * from htable; INSERT INTO version (table_name, table_version) select 'auth_cache', table_version from version where table_name = 'htable'; diff --git a/kamailio/db_scripts/vw_w_keepalive_contact.sql b/kamailio/db_scripts/vw_w_keepalive_contact.sql new file mode 100644 index 0000000..ce12ec5 --- /dev/null +++ b/kamailio/db_scripts/vw_w_keepalive_contact.sql @@ -0,0 +1,6 @@ +CREATE VIEW w_keepalive_contact as + select id, slot, failed, case when instr(contact,";") > 0 + then substr(contact, 1, instr(contact,";")-1) + else contact + end as contact + from keepalive diff --git a/kamailio/db_scripts/vw_w_location_contact.sql b/kamailio/db_scripts/vw_w_location_contact.sql new file mode 100644 index 0000000..6227b0c --- /dev/null +++ b/kamailio/db_scripts/vw_w_location_contact.sql @@ -0,0 +1,6 @@ +CREATE VIEW w_location_contact as + select id, case when instr(contact,";") > 0 + then substr(contact, 1, instr(contact,";")-1) + else contact + end as contact + from location diff --git a/kamailio/db_scripts/vw_w_watchers_contact.sql b/kamailio/db_scripts/vw_w_watchers_contact.sql new file mode 100644 index 0000000..96d0186 --- /dev/null +++ b/kamailio/db_scripts/vw_w_watchers_contact.sql @@ -0,0 +1,6 @@ +CREATE VIEW w_watchers_contact as + select id, case when instr(contact,";") > 0 + then substr(contact, 1, instr(contact,";")-1) + else contact + end as contact + from active_watchers diff --git a/kamailio/db_scripts/ww_keepalive_views.sql b/kamailio/db_scripts/ww_keepalive_views.sql deleted file mode 100644 index 7882ed2..0000000 --- a/kamailio/db_scripts/ww_keepalive_views.sql +++ /dev/null @@ -1,20 +0,0 @@ -CREATE VIEW w_keepalive_contact as -SELECT id, slot, failed, case when instr(contact,";") > 0 - then substr(contact, 1, instr(contact,";")-1) - else contact - end as contact -from keepalive; - -CREATE VIEW w_location_contact as -SELECT id, case when instr(contact,";") > 0 - then substr(contact, 1, instr(contact,";")-1) - else contact - end as contact -from location; - -CREATE VIEW w_watchers_contact as -select id, case when instr(contact,";") > 0 - then substr(contact, 1, instr(contact,";")-1) - else contact - end as contact -from active_watchers; From cb721316bff6b1ef9466dabe3127b6ed99a226f6 Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 13 Mar 2019 05:35:15 +0000 Subject: [PATCH 173/209] macros/runtime for max notify error and loglevel --- kamailio/presence-notify.cfg | 39 +++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/kamailio/presence-notify.cfg b/kamailio/presence-notify.cfg index cf0edb6..0ef1cdf 100644 --- a/kamailio/presence-notify.cfg +++ b/kamailio/presence-notify.cfg @@ -1,4 +1,7 @@ #!trydef KZ_PRESENCE_REMOVE_WATCHER_ON_EXPIRED_REGISTRATION 0 +#!trydef KZ_PRESENCE_MAX_NOTIFY_ERROR 3 +#!trydef KZ_PRESENCE_NOTIFY_LOG_LEVEL 4 + kazoo.presence_notify = 1 descr "enable/disable sending notify callback to omnipresence" kazoo.presence_notify_timeout = 5000 descr "timeout in ms waiting for notify reply" @@ -10,13 +13,12 @@ kazoo.presence_notify_record_route = 1 descr "add record route header to notify kazoo.presence_notify_log_init_body = 0 descr "logs the body before its sent" kazoo.presence_notify_force_send_socket = 1 descr "forces the send socket to the contact" kazoo.presence_remove_watcher_on_expired_registration = KZ_PRESENCE_REMOVE_WATCHER_ON_EXPIRED_REGISTRATION descr "removes watcher on expired registration" +kazoo.presence_max_notify_error = KZ_PRESENCE_MAX_NOTIFY_ERROR descr "number of consecutive fails allowed before removing the subscription" +kazoo.presence_notify_log_level = KZ_PRESENCE_NOTIFY_LOG_LEVEL descr "loglevel for informational log messages" ######## Generic Hash Table container in shared memory ######## modparam("htable", "htable", "notify=>size=16;autoexpire=3600;updateexpire=1;initval=0") -#!trydef PRESENCE_NOTIFY_INIT -#!trydef MAX_NOTIFY_ERROR 5 - route[PRESENCE_LOCAL_REQ_NOTIFY] { if($rm != "NOTIFY") { @@ -60,33 +62,34 @@ event_route[presence:notify-reply] $xavp(pres=>delete_subscription) = 0; - if($subs(reason) == "timeout") { - $xavp(pres=>delete_subscription) = 1; - xlog("L_INFO", "$ci|end|deleting subscription $subs(pres_uri) for $subs(watcher_username)@$subs(watcher_domain) due to timeout\n"); - } else if($notify_reply($rs) == 200) { + if($notify_reply($rs) == 200) { $sht(notify=>$ci) = $null; $sht(notify=>$ci::count) = 0; - xlog("L_INFO", "$ci|end|notified $subs(watcher_username)@$subs(watcher_domain) on behalf of $subs(pres_uri)\n"); - } else if($notify_reply($rs) == 481 && $subs(reason) == "timeout") { - xlog("L_INFO","$ci|end|sent subscription $hdr(Subscription-State)\n"); - } else if($notify_reply($rs) == 481) { + xlog("$(sel(cfg_get.kazoo.presence_notify_log_level){s.int})", "$ci|end|notified $subs(watcher_username)@$subs(watcher_domain) on behalf of $subs(pres_uri)\n"); + } else if($subs(reason) == "timeout") { $xavp(pres=>delete_subscription) = 1; - xlog("L_INFO", "$ci|end|deleting subscription $subs(pres_uri) as $subs(watcher_username)@$subs(watcher_domain) replied with 481 (non existent)\n"); - } else { + xlog("L_DEBUG", "$ci|end|deleting subscription $subs(pres_uri) for $subs(watcher_username)@$subs(watcher_domain) due to timeout\n"); + } else if($notify_reply($rs) == 481 && $subs(reason) == "timeout") { + xlog("L_DEBUG","$ci|end|sent subscription $hdr(Subscription-State)\n"); + } else if($notify_reply($rs) == 408) { if($rP != "UDP") { $xavp(pres=>delete_subscription) = 1; - xlog("L_ERROR", "$ci|error|removing $rP watcher $subs(watcher_username)@$subs(watcher_domain) for $subs(pres_uri) with reply $notify_reply($rs)\n"); + xlog("L_ERROR", "$ci|warning|removing $rP watcher $subs(watcher_username)@$subs(watcher_domain) for $subs(pres_uri) with reply $notify_reply($rs)\n"); } else { $var(shtinc) = $shtinc(notify=>$ci::count); - if($var(shtinc) > MAX_NOTIFY_ERROR) { + if($var(shtinc) > $sel(cfg_get.kazoo.presence_max_notify_error)) { $xavp(pres=>delete_subscription) = 1; - xlog("L_ERROR", "$ci|error|removing $rP watcher $subs(watcher_username)@$subs(watcher_domain) for $subs(pres_uri) with reply $notify_reply($rs)\n"); + xlog("L_WARNING", "$ci|error|removing $rP watcher $subs(watcher_username)@$subs(watcher_domain) for $subs(pres_uri) with reply $notify_reply($rs)\n"); } else { - $var(level) = 4 - $var(shtinc); - xlog("$var(level)", "$ci|error|received $notify_reply($rs) ($var(shtinc)/$def(MAX_NOTIFY_ERROR)) when notifying $subs(watcher_username)@$subs(watcher_domain) on behalf of $subs(pres_uri) with reply $notify_reply($rs)\n"); + $var(level) = 6 - $var(shtinc); + xlog("$var(level)", "$ci|error|received $notify_reply($rs) ($var(shtinc)/$sel(cfg_get.kazoo.presence_max_notify_error)) when notifying $subs(watcher_username)@$subs(watcher_domain) on behalf of $subs(pres_uri) with reply $notify_reply($rs)\n"); } } + } else { + $xavp(pres=>delete_subscription) = 1; + xlog("L_WARNING", "$ci|end|deleting subscription $subs(pres_uri) as $subs(watcher_username)@$subs(watcher_domain) replied with $notify_reply($rs)\n"); } + if($sel(cfg_get.kazoo.presence_notify_log_body) == 1) xlog("L_INFO", "$ci|log|sent|body $(mb{s.escape.common}{s.replace,\','}{s.replace,$$,})\n"); if($sel(cfg_get.kazoo.presence_notify_log_resp_body) == 1) From e388dd30c0e3395055b528cb4063fe9a3df3737a Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 13 Mar 2019 05:37:54 +0000 Subject: [PATCH 174/209] macro/runtime for keepalive failed loglevel --- kamailio/keepalive.cfg | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kamailio/keepalive.cfg b/kamailio/keepalive.cfg index d5f68fd..a79f3ff 100644 --- a/kamailio/keepalive.cfg +++ b/kamailio/keepalive.cfg @@ -8,6 +8,7 @@ #!trydef KEEPALIVE_FAILED_THRESHOLD 2 #!trydef KEEPALIVE_EXPIRE_SUBSCRIPTIONS 1 #!trydef KEEPALIVE_EXPIRE_REGISTRATIONS 1 +#!trydef KEEPALIVE_FAILED_LOG_LEVEL 0 #!substdef "!KEEPALIVE_S_FROM_URI!sip:keepalive@MY_HOSTNAME!g" #!substdef "!KEEPALIVE_S_TIMERS!$def(KEEPALIVE_TIMERS)!g" @@ -18,6 +19,7 @@ kazoo.keepalive_timeout = KEEPALIVE_TIMEOUT descr "timeout in ms for keepalive t kazoo.keepalive_failed_threshold = KEEPALIVE_FAILED_THRESHOLD descr "how many times can a device fail to respond to OPTIONS" kazoo.keepalive_expire_subscriptions = KEEPALIVE_EXPIRE_SUBSCRIPTIONS descr "expires subscriptions that do not respond to OPTIONS" kazoo.keepalive_expire_registrations = KEEPALIVE_EXPIRE_REGISTRATIONS descr "expires registrations that do not respond to OPTIONS" +kazoo.keepalive_failed_log_level = KEEPALIVE_FAILED_LOG_LEVEL descr "loglevel for keepalive failed reply" modparam("rtimer", "timer", "name=keepalive_timer;interval=1;mode=KEEPALIVE_S_TIMERS;") modparam("rtimer", "exec", "timer=keepalive_timer;route=KEEPALIVE_TIMER") @@ -135,7 +137,7 @@ onreply_route[KEEPALIVE_REPLY] failure_route[KEEPALIVE_FAULT] { - xlog("L_WARNING", "$ci|keepalive|received error $T_reply_code $T_reply_reason from $(tu{nameaddr.uri})\n"); + xlog("$(sel(cfg_get.kazoo.keepalive_failed_log_level){s.int})", "$ci|keepalive|received error $T_reply_code $T_reply_reason from $(tu{nameaddr.uri})\n"); $var(Query) = $_s(UPDATE keepalive SET selected = 0, failed = failed + 1, time_sent = datetime('now') WHERE id = $(fu{uri.param,nat_id});); xlog("L_DEBUG", "$ci|keepalive|KEEPALIVE REMOVE SQL => '$var(Query)'\n"); mq_add("keepalive_db_queue", "$uuid(g)", "$var(Query)"); From 1dadc3578f2ee406e4392b95db42563670179f1b Mon Sep 17 00:00:00 2001 From: lazedo Date: Fri, 15 Mar 2019 23:52:55 +0000 Subject: [PATCH 175/209] move kazoo param to kazoo-bindings & allow db module configuration --- kamailio/db_kazoo.cfg | 12 ++++++++++ kamailio/db_mysql.cfg | 4 ++++ kamailio/db_postgres.cfg | 4 ++++ kamailio/default.cfg | 46 ++----------------------------------- kamailio/kazoo-bindings.cfg | 42 +++++++++++++++++++++++++++++++++ 5 files changed, 64 insertions(+), 44 deletions(-) create mode 100644 kamailio/db_kazoo.cfg create mode 100644 kamailio/db_mysql.cfg create mode 100644 kamailio/db_postgres.cfg diff --git a/kamailio/db_kazoo.cfg b/kamailio/db_kazoo.cfg new file mode 100644 index 0000000..61de31e --- /dev/null +++ b/kamailio/db_kazoo.cfg @@ -0,0 +1,12 @@ +#### db_kazoo module ### + +#!trydef KZ_DB_HOOK_TRACE 1 +#!trydef KZ_DB_TRACE 0 +#!trydef KZ_DB_TRACE_LOG_LEVEL 3 + +loadmodule "db_kazoo.so" +modparam("db_kazoo", "trace_hook", KZ_DB_HOOK_TRACE) +modparam("db_kazoo", "trace_enable", KZ_DB_TRACE) +modparam("db_kazoo", "trace_log_level", KZ_DB_TRACE_LOG_LEVEL) + +include_file "db_queries_kazoo.cfg" diff --git a/kamailio/db_mysql.cfg b/kamailio/db_mysql.cfg new file mode 100644 index 0000000..9000b57 --- /dev/null +++ b/kamailio/db_mysql.cfg @@ -0,0 +1,4 @@ +#### db_mysql module ### +loadmodule "db_mysql.so" + +include_file "db_queries_mysql.cfg" diff --git a/kamailio/db_postgres.cfg b/kamailio/db_postgres.cfg new file mode 100644 index 0000000..51dbd44 --- /dev/null +++ b/kamailio/db_postgres.cfg @@ -0,0 +1,4 @@ +#### db_postgres module ### +loadmodule "db_postgres.so" + +include_file "db_queries_postgres.cfg" diff --git a/kamailio/default.cfg b/kamailio/default.cfg index ec71f21..77dc71a 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -203,51 +203,9 @@ modparam("debugger", "mod_hash_size", 5) modparam("debugger", "mod_level_mode", 1) modparam("debugger", "mod_level", "core=1") -####### DATABASE module ########## -loadmodule "db_KAMAILIO_DBMS.so" - -####### Kazoo Integration module ########## -loadmodule "kazoo.so" -modparam("kazoo", "pua_mode", MY_AMQP_PUA_MODE) -modparam("kazoo", "amqp_primary_zone", "MY_AMQP_ZONE") -modparam("kazoo", "amqp_query_timeout_avp", "$avp(kz_timeout)") -modparam("kazoo", "node_hostname", "MY_HOSTNAME") -modparam("kazoo", "amqp_heartbeats", MY_AMQP_HEARTBEATS) -modparam("kazoo", "amqp_max_channels", MY_AMQP_MAX_CHANNELS) -modparam("kazoo", "amqp_consumer_processes", MY_AMQP_CONSUMER_PROCESSES) -modparam("kazoo", "amqp_consumer_workers", MY_AMQP_CONSUMER_WORKERS) -## amqp connections -#!ifdef MY_AMQP_URL -modparam("kazoo", "amqp_connection", "MY_AMQP_URL") -#!endif -#!ifdef MY_AMQP_SECONDARY_URL -modparam("kazoo", "amqp_connection", "MY_AMQP_SECONDARY_URL") -#!endif -#!ifdef MY_AMQP_TERTIARY_URL -modparam("kazoo", "amqp_connection", "MY_AMQP_TERTIARY_URL") -#!endif -#!ifdef MY_AMQP_QUATERNARY_URL -modparam("kazoo", "amqp_connection", "MY_AMQP_QUATERNARY_URL") -#!endif -#!ifdef MY_AMQP_QUINARY_URL -modparam("kazoo", "amqp_connection", "MY_AMQP_QUINARY_URL") -#!endif -#!ifdef MY_AMQP_SENARY_URL -modparam("kazoo", "amqp_connection", "MY_AMQP_SENARY_URL") -#!endif -#!ifdef MY_AMQP_SEPTENARY_URL -modparam("kazoo", "amqp_connection", "MY_AMQP_SEPTENARY_URL") -#!endif -#!ifdef MY_AMQP_OCTONARY_URL -modparam("kazoo", "amqp_connection", "MY_AMQP_OCTONARY_URL") -#!endif -#!ifdef MY_AMQP_NONARY_URL -modparam("kazoo", "amqp_connection", "MY_AMQP_NONARY_URL") -#!endif -#!ifdef MY_AMQP_DENARY_URL -modparam("kazoo", "amqp_connection", "MY_AMQP_DENARY_URL") -#!endif +####### DATABASE module ########## +include_file "db_KAMAILIO_DBMS.cfg" ###### kazoo bindings ###### include_file "kazoo-bindings.cfg" diff --git a/kamailio/kazoo-bindings.cfg b/kamailio/kazoo-bindings.cfg index 7de1665..d63bcf7 100644 --- a/kamailio/kazoo-bindings.cfg +++ b/kamailio/kazoo-bindings.cfg @@ -2,6 +2,48 @@ ### ### +####### Kazoo Integration module ########## +loadmodule "kazoo.so" +modparam("kazoo", "pua_mode", MY_AMQP_PUA_MODE) +modparam("kazoo", "amqp_primary_zone", "MY_AMQP_ZONE") +modparam("kazoo", "amqp_query_timeout_avp", "$avp(kz_timeout)") +modparam("kazoo", "node_hostname", "MY_HOSTNAME") +modparam("kazoo", "amqp_heartbeats", MY_AMQP_HEARTBEATS) +modparam("kazoo", "amqp_max_channels", MY_AMQP_MAX_CHANNELS) +modparam("kazoo", "amqp_consumer_processes", MY_AMQP_CONSUMER_PROCESSES) +modparam("kazoo", "amqp_consumer_workers", MY_AMQP_CONSUMER_WORKERS) +## amqp connections +#!ifdef MY_AMQP_URL +modparam("kazoo", "amqp_connection", "MY_AMQP_URL") +#!endif +#!ifdef MY_AMQP_SECONDARY_URL +modparam("kazoo", "amqp_connection", "MY_AMQP_SECONDARY_URL") +#!endif +#!ifdef MY_AMQP_TERTIARY_URL +modparam("kazoo", "amqp_connection", "MY_AMQP_TERTIARY_URL") +#!endif +#!ifdef MY_AMQP_QUATERNARY_URL +modparam("kazoo", "amqp_connection", "MY_AMQP_QUATERNARY_URL") +#!endif +#!ifdef MY_AMQP_QUINARY_URL +modparam("kazoo", "amqp_connection", "MY_AMQP_QUINARY_URL") +#!endif +#!ifdef MY_AMQP_SENARY_URL +modparam("kazoo", "amqp_connection", "MY_AMQP_SENARY_URL") +#!endif +#!ifdef MY_AMQP_SEPTENARY_URL +modparam("kazoo", "amqp_connection", "MY_AMQP_SEPTENARY_URL") +#!endif +#!ifdef MY_AMQP_OCTONARY_URL +modparam("kazoo", "amqp_connection", "MY_AMQP_OCTONARY_URL") +#!endif +#!ifdef MY_AMQP_NONARY_URL +modparam("kazoo", "amqp_connection", "MY_AMQP_NONARY_URL") +#!endif +#!ifdef MY_AMQP_DENARY_URL +modparam("kazoo", "amqp_connection", "MY_AMQP_DENARY_URL") +#!endif + event_route[kazoo:mod-init] { From 5e76ccff63b3a628e8271739d4b018e505cd40d8 Mon Sep 17 00:00:00 2001 From: lazedo Date: Fri, 15 Mar 2019 23:54:12 +0000 Subject: [PATCH 176/209] add a block component allow to view msg buf in logs & block misconfigured devices --- kamailio/block.cfg | 43 +++++++++++++++++++++++++++++++++++++++++++ kamailio/default.cfg | 2 ++ 2 files changed, 45 insertions(+) create mode 100644 kamailio/block.cfg diff --git a/kamailio/block.cfg b/kamailio/block.cfg new file mode 100644 index 0000000..0b74219 --- /dev/null +++ b/kamailio/block.cfg @@ -0,0 +1,43 @@ +######## BLOCK BY IP[PORT] ######## + +#!ifndef KZ_BLOCK_DISABLE + +#!trydef KZ_BLOCK_ENABLE 1 +#!trydef KZ_BLOCK_LOG_LEVEL 1 +#!trydef KZ_BLOCK_LOG_BUFFER 0 +#!trydef KZ_BLOCK_DRY_RUN 0 + +#!ifdef KZ_BLOCK_COLD_CACHE +#!substdef "!BLOCK_S_WARM_CACHE!!g" +#!else +#!substdef "!BLOCK_S_WARM_CACHE!dbtable=block_cache;dbmode=1;!g" +#!endif + +modparam("htable", "htable", "block=>size=8;BLOCK_S_WARM_CACHE") +modparam("statistics","variable", "block:blocked_requests") + +kazoo.block_enable = KZ_BLOCK_ENABLE descr "enable block processing" +kazoo.block_log_level = KZ_BLOCK_LOG_LEVEL descr "block log level" +kazoo.block_log_buffer = KZ_BLOCK_LOG_BUFFER descr "log the received buffer" +kazoo.block_dry_run = KZ_BLOCK_DRY_RUN descr "log but keep processing" + +## global param to enable route +received_route_mode=1 + +event_route[core:msg-received] +{ + if($sel(cfg_get.kazoo.block_enable) == 1) { + if($sht(block=>$rcv(srcip)) || $sht(block=>$rcv(srcip)::$rcv(srcport))) { + if($sel(cfg_get.kazoo.block_log_buffer) == 1) { + xlog("$(sel(cfg_get.kazoo.block_log_level){s.int})", "|block|request from [$rcv(srcip):$rcv(srcport)] to [$rcv(rcvip):$rcv(rcvport)] was blocked => [$rcv(buf)]\n"); + } else { + xlog("$(sel(cfg_get.kazoo.block_log_level){s.int})", "|block|request from [$rcv(srcip):$rcv(srcport)] to [$rcv(rcvip):$rcv(rcvport)] was blocked\n"); + } + if($sel(cfg_get.kazoo.block_dry_run) == 0) { + drop; + } + } + } +} + +#!endif diff --git a/kamailio/default.cfg b/kamailio/default.cfg index 77dc71a..35206a4 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -269,6 +269,8 @@ include_file "sip_trace-role.cfg" ## auth ## include_file "auth.cfg" +## block ## +include_file "block.cfg" ####### Permissions module ########## loadmodule "permissions.so" From 1e4eb6e8d3d5d5f7bf684649b45ca7af0d993591 Mon Sep 17 00:00:00 2001 From: lazedo Date: Fri, 15 Mar 2019 23:55:22 +0000 Subject: [PATCH 177/209] db module macro --- kamailio/defs.cfg | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/kamailio/defs.cfg b/kamailio/defs.cfg index 03776c4..753828b 100644 --- a/kamailio/defs.cfg +++ b/kamailio/defs.cfg @@ -28,9 +28,8 @@ #!trydef PV_BUFFER_SIZE 16384 #!trydef PV_BUFFER_SLOTS 30 -#!ifndef KAMAILIO_DBMS -#!substdef "!KAMAILIO_DBMS!kazoo!g" -#!endif +#!trydef KZ_DB_MODULE kazoo +#!substdef "!KAMAILIO_DBMS!$def(KZ_DB_MODULE)!g" #!ifndef KAZOO_DATA_DIR #!substdef "!KAZOO_DATA_DIR!/etc/kazoo/kamailio/db!g" From 210b82ca30de1fb3af4d90a7c5bf23c7fcd1feb7 Mon Sep 17 00:00:00 2001 From: lazedo Date: Fri, 15 Mar 2019 23:55:55 +0000 Subject: [PATCH 178/209] remove include file --- kamailio/kamailio.cfg | 3 --- 1 file changed, 3 deletions(-) diff --git a/kamailio/kamailio.cfg b/kamailio/kamailio.cfg index 1964c03..e515b9b 100644 --- a/kamailio/kamailio.cfg +++ b/kamailio/kamailio.cfg @@ -44,9 +44,6 @@ include_file "local.cfg" ####### defaults not configured in local ######## include_file "defs.cfg" -####### DBMS query selection ######## -include_file "db_queries_KAMAILIO_DBMS.cfg" - ####### Default Configuration ###### include_file "default.cfg" From 17dedcbc7e0471cf31c358c7dd89f471a0d1e618 Mon Sep 17 00:00:00 2001 From: lazedo Date: Sat, 16 Mar 2019 00:01:27 +0000 Subject: [PATCH 179/209] db changes --- kamailio/db_queries_kazoo.cfg | 2 +- .../db_scripts/db_init_watcher_triggers.sql | 14 ++++++ kamailio/db_scripts/db_kazoo-specific | 45 +++++++++++++++---- .../db_scripts/vw_w_keepalive_contact.sql | 8 ++-- 4 files changed, 56 insertions(+), 13 deletions(-) create mode 100644 kamailio/db_scripts/db_init_watcher_triggers.sql diff --git a/kamailio/db_queries_kazoo.cfg b/kamailio/db_queries_kazoo.cfg index 9135825..41f5f4d 100644 --- a/kamailio/db_queries_kazoo.cfg +++ b/kamailio/db_queries_kazoo.cfg @@ -1,6 +1,6 @@ ####### Database queries ######## #!substdef "!KZQ_CHECK_MEDIA_SERVER_INSERT!insert into dispatcher (setid, destination, flags, attrs, description) select \$var(SetId), \"\$var(MediaUrl)\", \$var(flags), \"\$var(attrs)\", \"added by nodes role\" where not exists(select * from dispatcher where destination = \"\$var(MediaUrl)\")!g" -#!substdef "!KZQ_COUNT_ALL_SUBSCRIBERS!select a.event, count(distinct watcher_username || \"@\" || watcher_domain) count_unique, count(*) count from event_list a, active_watchers b where b.event = a.event group by a.event!g" +#!substdef "!KZQ_COUNT_ALL_SUBSCRIBERS!select a.event, count(distinct watcher_uri) count_unique, count(*) count from event_list a left outer join active_watchers b on a.event = b.event group by a.event!g" #!substdef "!KZQ_COUNT_PRESENTITIES!select event, (select count(*) from presentity b where username = \"\$(var(payload){kz.json,From}{uri.user})\" and domain = \"\$(var(payload){kz.json,From}{uri.domain})\" and b.event = a.event) count from event_list a!g" #!substdef "!KZQ_COUNT_SUBSCRIBERS!select event, (select count(*) from active_watchers b where presentity_uri = \"\$var(presentity)\" and b.event = a.event) count from event_list a union select \"self\", count(distinct callid) from presentities where presentity_uri = \"\$var(presentity)\" and state in('early', 'confirmed', 'onthephone', 'busy')!g" diff --git a/kamailio/db_scripts/db_init_watcher_triggers.sql b/kamailio/db_scripts/db_init_watcher_triggers.sql new file mode 100644 index 0000000..8e5a202 --- /dev/null +++ b/kamailio/db_scripts/db_init_watcher_triggers.sql @@ -0,0 +1,14 @@ +CREATE TRIGGER if not exists active_watchers_watcher_uri_insert +AFTER INSERT ON active_watchers +FOR EACH ROW +BEGIN + UPDATE active_watchers SET watcher_uri = "sip:" || NEW.watcher_username || "@" || NEW.watcher_domain where id = NEW.id; +END; + +CREATE TRIGGER if not exists active_watchers_watcher_uri_update +AFTER UPDATE ON active_watchers +FOR EACH ROW +WHEN OLD.watcher_username <> NEW.watcher_username OR OLD.watcher_domain <> NEW.watcher_domain +BEGIN + UPDATE active_watchers SET watcher_uri = "sip:" || NEW.watcher_username || "@" || NEW.watcher_domain where id = NEW.id; +END; diff --git a/kamailio/db_scripts/db_kazoo-specific b/kamailio/db_scripts/db_kazoo-specific index c67b5ca..800bb26 100644 --- a/kamailio/db_scripts/db_kazoo-specific +++ b/kamailio/db_scripts/db_kazoo-specific @@ -46,6 +46,7 @@ INSERT INTO version (table_name, table_version) values ('active_watchers_log','1 CREATE TABLE keepalive ( id INTEGER PRIMARY KEY NOT NULL, contact VARCHAR(2048) NOT NULL COLLATE NOCASE, + received VARCHAR(32) NOT NULL COLLATE NOCASE, sockinfo VARCHAR(128) NOT NULL COLLATE NOCASE, time_inserted timestamp DEFAULT CURRENT_TIMESTAMP, time_sent timestamp DEFAULT CURRENT_TIMESTAMP, @@ -53,17 +54,45 @@ CREATE TABLE keepalive ( selected INTEGER DEFAULT 0, failed INTEGER DEFAULT 0, CONSTRAINT keepalive_idx UNIQUE (contact), - CONSTRAINT keepalive_idx_2 UNIQUE (slot, selected, time_sent, contact) - CONSTRAINT keepalive_idx_3 UNIQUE (slot, failed, contact) + CONSTRAINT keepalive_idx_2 UNIQUE (slot, failed, contact) ); - -INSERT INTO version (table_name, table_version) values ('keepalive','3'); + +CREATE INDEX keepalive_idx_3 ON keepalive (slot, selected, time_sent); +CREATE INDEX keepalive_idx_4 ON keepalive (received, selected); + +INSERT INTO version (table_name, table_version) values ('keepalive','4'); + +ALTER TABLE active_watchers ADD COLUMN watcher_uri varchar(64) NOT NULL DEFAULT "sip:no_watcher@no_domain"; + +CREATE TRIGGER active_watchers_watcher_uri_insert +AFTER INSERT ON active_watchers +FOR EACH ROW +BEGIN + UPDATE active_watchers SET watcher_uri = "sip:" || NEW.watcher_username || "@" || NEW.watcher_domain where id = NEW.id; +END; + +CREATE TRIGGER active_watchers_watcher_uri_update +AFTER UPDATE ON active_watchers +FOR EACH ROW +WHEN OLD.watcher_username <> NEW.watcher_username OR OLD.watcher_domain <> NEW.watcher_domain +BEGIN + UPDATE active_watchers SET watcher_uri = "sip:" || NEW.watcher_username || "@" || NEW.watcher_domain where id = NEW.id; +END; CREATE UNIQUE INDEX active_watchers_contact ON active_watchers (contact, id); +CREATE INDEX active_watchers_event_watcher_uri ON active_watchers (event, watcher_uri); + + +CREATE INDEX location_attrs_ruid ON location_attrs (ruid); +CREATE UNIQUE INDEX location_ruid ON location (ruid); create table auth_cache as select * from htable; INSERT INTO version (table_name, table_version) select 'auth_cache', table_version from version where table_name = 'htable'; +create table block_cache as select * from htable; +INSERT INTO version (table_name, table_version) select 'block_cache', table_version from version where table_name = 'htable'; + + create view presentities as select id, cast(printf("sip:%s@%s",username,domain) as varchar(64)) presentity_uri , username, domain, event, cast(substr(etag, instr(etag,"@")+1) as varchar(64)) callid, datetime(received_time, 'unixepoch') as received, @@ -94,10 +123,10 @@ INSERT INTO version (table_name, table_version) select 'auth_cache', table_versi CREATE VIEW w_keepalive_contact as -SELECT id, slot, failed, case when instr(contact,";") > 0 - then substr(contact, 1, instr(contact,";")-1) - else contact - end as contact +SELECT id, slot, selected, failed, case when instr(contact,";") > 0 + then substr(contact, 1, instr(contact,";")-1) + else contact + end as contact from keepalive; CREATE VIEW w_location_contact as diff --git a/kamailio/db_scripts/vw_w_keepalive_contact.sql b/kamailio/db_scripts/vw_w_keepalive_contact.sql index ce12ec5..1639650 100644 --- a/kamailio/db_scripts/vw_w_keepalive_contact.sql +++ b/kamailio/db_scripts/vw_w_keepalive_contact.sql @@ -1,6 +1,6 @@ CREATE VIEW w_keepalive_contact as - select id, slot, failed, case when instr(contact,";") > 0 - then substr(contact, 1, instr(contact,";")-1) - else contact - end as contact + select id, slot, selected, failed, case when instr(contact,";") > 0 + then substr(contact, 1, instr(contact,";")-1) + else contact + end as contact from keepalive From 6a09d9b4c1fd4509343325ca8ce229cb07ae14e8 Mon Sep 17 00:00:00 2001 From: lazedo Date: Sat, 16 Mar 2019 01:54:11 +0000 Subject: [PATCH 180/209] registrar stats & cache authn_err --- kamailio/registrar-role.cfg | 74 ++++++++++++++++++++++++++++++------- 1 file changed, 61 insertions(+), 13 deletions(-) diff --git a/kamailio/registrar-role.cfg b/kamailio/registrar-role.cfg index 6144bd6..913ad8c 100644 --- a/kamailio/registrar-role.cfg +++ b/kamailio/registrar-role.cfg @@ -110,6 +110,27 @@ modparam("nathelper", "natping_processes", 0) #!endif #!endif +## stats ## +modparam("statistics","variable", "registrar:force_failover") +modparam("statistics","variable", "registrar:cached") +modparam("statistics","variable", "registrar:ip_realm") +modparam("statistics","variable", "registrar:new_tran") +modparam("statistics","variable", "registrar:amqp_not_available") +modparam("statistics","variable", "registrar:challenge") +modparam("statistics","variable", "registrar:amqp_async_error") +modparam("statistics","variable", "registrar:amqp_returned") +modparam("statistics","variable", "registrar:amqp_timeout") +modparam("statistics","variable", "registrar:drops") +modparam("statistics","variable", "registrar:authn_err") +modparam("statistics","variable", "registrar:authn_resp") +modparam("statistics","variable", "registrar:authn_unknown") +modparam("statistics","variable", "registrar:save_error") +modparam("statistics","variable", "registrar:missing_expires") +modparam("statistics","variable", "registrar:missing_expires_allowed") +modparam("statistics","variable", "registrar:min_expires") +modparam("statistics","variable", "registrar:min_expires_allowed") + + ##### registrar realtime params ##### kazoo.registrar_error_min_expires = REGISTRAR_ERROR_MIN_EXPIRES descr "send error when UAS sends expires < min-expires" kazoo.registrar_error_missing_expires = REGISTRAR_ERROR_MISSING_EXPIRES descr "send error when UAS do not send expires header" @@ -159,47 +180,58 @@ route[HANDLE_REGISTER] route(PUSHER_ATTEMPT_REGISTRATION); #!endif + if($sel(cfg_get.kazoo.registrar_failover) == 1) { + xlog("L_INFO", "$ci|log|register|forcing failover\n"); + update_stat("registrar:force_failover", "+1"); + drop; + } + if($sel(cfg_get.kazoo.registrar_force_query) == 0) { - $xavp(regcfg=>match_received) = $su; - if($sht(auth_cache=>$Au) != $null - && registered("location", "$rz:$Au", 2, 1) == 1 - && $(xavp(ulattrs=>custom_channel_vars){s.len}) > 1) - && $sel(cfg_get.kazoo.registrar_failover) == 0 { - $var(password) = $sht(auth_cache=>$Au); - route(SAVE_LOCATION); - exit; + if($sht(auth_cache=>$Au) == "authn_err") { + xlog("L_WARNING", "$ci|end|issuing auth challenge to cached failed registration attempt for $Au from IP $si:$sp\n"); + update_stat("registrar:challenge", "+1"); + auth_challenge("$fd", "5"); + } else if($sht(auth_cache=>$Au) != $null) { + $xavp(regcfg=>match_received) = $su; + if(registered("location", "$rz:$Au", 2, 1) == 1) { + if($(xavp(ulattrs=>custom_channel_vars){s.len}) > 1) { + $var(password) = $sht(auth_cache=>$Au); + update_stat("registrar:cached", "+1"); + route(SAVE_LOCATION); + exit; + } + } } } if($td =~ "[0-9]{1,3}\.[0-9]{1,3}.[0-9]{1,3}\.[0-9]{1,3}" || $fd =~ "[0-9]{1,3}\.[0-9]{1,3}.[0-9]{1,3}\.[0-9]{1,3}") { xlog("L_INFO", "$ci|log|register|invalid domain\n"); + update_stat("registrar:ip_realm", "+1"); drop; } if (!t_newtran()) { xlog("L_ERROR", "$ci|log|failed to create transaction to query for authentication credentials for $Au $si:$sp\n"); + update_stat("registrar:new_tran", "+1"); drop; } if($sel(cfg_get.kazoo.registrar_check_amqp_availability) == 1) { if($xavp(amqpc=>default::MY_AMQP_ZONE) == 0) { xlog("L_WARNING", "$ci|end|register|no amqp connection available for default worker in zone MY_AMQP_ZONE\n"); + update_stat("registrar:amqp_not_available", "+1"); t_drop(); } } - if($sel(cfg_get.kazoo.registrar_failover) == 1) { - xlog("L_INFO", "$ci|log|register|forcing failover\n"); - t_drop(); - } - route(REGISTRAR_BOUNDS); $var(auth) = pv_auth_check("$fd", "$uuid(g)", "0", "0"); if($var(auth) != -2) { xlog("L_INFO", "$ci|end|challenging $Au $si:$sp\n"); $var(auth) = auth_challenge("$fd", "21"); + update_stat("registrar:challenge", "+1"); if($var(auth) != 1) { xlog("L_ERROR", "$ci|register|error creating or sending challenge to registration attempt for $fu from $si:$sp\n"); t_drop(); @@ -219,6 +251,7 @@ route[HANDLE_REGISTER] xlog("L_DEBUG", "$ci|amqp|publishing to $def(REGISTRAR_AMQP_EXCHANGE) => $var(amqp_routing_key) : $def(REGISTRAR_AMQP_FLAGS) : $var(amqp_payload_request)\n"); if(kazoo_async_query("$def(REGISTRAR_AMQP_EXCHANGE)", $var(amqp_routing_key), $var(amqp_payload_request), "KZ_AUTHORIZATION_REPLY", "KZ_AUTHORIZATION_TIMEOUT", "$def(REGISTRAR_AMQP_FLAGS)") != 1) { xlog("L_INFO", "$ci|log|failed to send registrar query for authentication credentials for $Au $si:$sp\n"); + update_stat("registrar:amqp_async_error", "+1"); t_drop(); } } @@ -227,9 +260,12 @@ failure_route[KZ_AUTHORIZATION_TIMEOUT] { if($(kzR{kz.json,Event-Name}) == "message_returned" ) { xlog("L_WARNING", "$ci|amqp|message was returned by broker $(kzR{kz.json,Error-Code}) $(kzR{kz.json,Error-Reason})\n"); + update_stat("registrar:amqp_returned", "+1"); } else { xlog("L_WARNING", "$ci|end|failed $T_reply_code $T_reply_reason [$T(id_index):$T(id_label)] querying directory for authentication credentials for $Au $si:$sp\n"); + update_stat("registrar:amqp_timeout", "+1"); } + update_stat("registrar:drops", "+1"); t_drop(); } @@ -242,16 +278,22 @@ onreply_route[KZ_AUTHORIZATION_REPLY] $var(password) = $(kzR{kz.json,Auth-Password}); $var(nonce) = $adn; if( $(kzR{kz.json,Event-Name}) == "authn_err" ) { + $sht(auth_cache=>$Au) = "authn_err"; + update_stat("registrar:authn_err", "+1"); #!ifdef ANTIFLOOD_ROLE route(ANITFLOOD_FAILED_AUTH); #!endif + update_stat("registrar:challenge", "+1"); auth_challenge("$fd", "5"); xlog("L_INFO", "$ci|end|challenging $Au $si:$sp via $(kzR{kz.json,App-Name})-$(kzR{kz.json,App-Version}) response\n"); exit; } else if( $(kzR{kz.json,Event-Name}) == "authn_resp" ) { + update_stat("registrar:authn_resp", "+1"); xlog("L_INFO", "$ci|log|authenticating $Au via $(kzR{kz.json,App-Name})-$(kzR{kz.json,App-Version}) response\n"); route(CHECK_AUTHORIZATION); } else { + update_stat("registrar:authn_unknown", "+1"); + update_stat("registrar:drops", "+1"); xlog("L_INFO", "$ci|log|unhandle response from directory $Au via $(kzR{kz.json,App-Name})-$(kzR{kz.json,App-Version})\n"); t_drop(); } @@ -268,6 +310,7 @@ route[CHECK_AUTHORIZATION] #!endif xlog("L_WARNING", "$ci|end|issuing auth challenge to failed registration attempt for $Au from IP $si:$sp\n"); + update_stat("registrar:challenge", "+1"); auth_challenge("$fd", "5"); exit; } @@ -299,6 +342,7 @@ route[SAVE_LOCATION] $var(save_result) = save("location", "0x04"); if($var(save_result) < 0) { xlog("L_WARNING", "$ci|end|not expected result $var(save_result) when saving $Au registration from IP $si:$sp\n"); + update_stat("registrar:save_error", "+1"); exit; } else { if($var(save_result) == 1) { @@ -440,8 +484,10 @@ route[REGISTRAR_BOUNDS] if($sel(cfg_get.kazoo.registrar_error_missing_expires) == 1) { xlog("L_WARNING", "$ci|end|missing expires registering $Au from IP $si:$sp\n"); send_reply("400", "Missing Expires"); + update_stat("registrar:missing_expires", "+1"); exit; } else { + update_stat("registrar:missing_expires_allowed", "+1"); xlog("L_WARNING", "$ci|end|allowing missing expires registering $Au from IP $si:$sp\n"); } } @@ -452,8 +498,10 @@ route[REGISTRAR_BOUNDS] xlog("L_WARNING", "$ci|end|expires $var(expires) too brief (configured $def(REGISTRAR_MIN_EXPIRES)) registering $Au from IP $si:$sp\n"); append_to_reply("Min-Expires: $def(REGISTRAR_MIN_EXPIRES)\r\n"); send_reply("423", "Interval Too Brief"); + update_stat("registrar:min_expires", "+1"); exit; } else { + update_stat("registrar:min_expires_allowed", "+1"); xlog("L_WARNING", "$ci|end|allowing expires $var(expires) too brief (configured $def(REGISTRAR_MIN_EXPIRES)) registering $Au from IP $si:$sp\n"); } } From 29b10bb4d97c0fe45038bf9b71dfcc84a5279b46 Mon Sep 17 00:00:00 2001 From: lazedo Date: Sat, 16 Mar 2019 02:28:10 +0000 Subject: [PATCH 181/209] add statistics module --- kamailio/default.cfg | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kamailio/default.cfg b/kamailio/default.cfg index 35206a4..4d90022 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -203,6 +203,8 @@ modparam("debugger", "mod_hash_size", 5) modparam("debugger", "mod_level_mode", 1) modparam("debugger", "mod_level", "core=1") +####### STATISTICS ###### +loadmodule "statistics.so" ####### DATABASE module ########## include_file "db_KAMAILIO_DBMS.cfg" From 5c2ac1d6f9311a7ef0ce1f83d505a069e007cef8 Mon Sep 17 00:00:00 2001 From: lazedo Date: Sat, 16 Mar 2019 02:33:59 +0000 Subject: [PATCH 182/209] add stats to keepalive & change some defaults --- kamailio/keepalive.cfg | 170 +++++++++++++++++++++++++++++------------ 1 file changed, 123 insertions(+), 47 deletions(-) diff --git a/kamailio/keepalive.cfg b/kamailio/keepalive.cfg index a79f3ff..64c1b20 100644 --- a/kamailio/keepalive.cfg +++ b/kamailio/keepalive.cfg @@ -2,13 +2,18 @@ #!trydef KEEPALIVE_NAT_ONLY 0 #!trydef KEEPALIVE_UDP_ONLY 0 -#!trydef KEEPALIVE_TIMERS 8 -#!trydef KEEPALIVE_INTERVAL 30 +#!trydef KEEPALIVE_TIMERS 4 +#!trydef KEEPALIVE_INTERVAL 60 #!trydef KEEPALIVE_TIMEOUT 5000 #!trydef KEEPALIVE_FAILED_THRESHOLD 2 #!trydef KEEPALIVE_EXPIRE_SUBSCRIPTIONS 1 #!trydef KEEPALIVE_EXPIRE_REGISTRATIONS 1 +#!trydef KEEPALIVE_FAILED_ACTION 1 #!trydef KEEPALIVE_FAILED_LOG_LEVEL 0 +#!trydef KEEPALIVE_EXPIRED_SUBSCRIPTION_ACTION 1 +#!trydef KEEPALIVE_EXPIRED_REGISTRATION_ACTION 1 +#!trydef KEEPALIVE_ON_SUBSCRIPTION_ACTION 1 +#!trydef KEEPALIVE_ON_REGISTRATION_ACTION 1 #!substdef "!KEEPALIVE_S_FROM_URI!sip:keepalive@MY_HOSTNAME!g" #!substdef "!KEEPALIVE_S_TIMERS!$def(KEEPALIVE_TIMERS)!g" @@ -20,6 +25,12 @@ kazoo.keepalive_failed_threshold = KEEPALIVE_FAILED_THRESHOLD descr "how many ti kazoo.keepalive_expire_subscriptions = KEEPALIVE_EXPIRE_SUBSCRIPTIONS descr "expires subscriptions that do not respond to OPTIONS" kazoo.keepalive_expire_registrations = KEEPALIVE_EXPIRE_REGISTRATIONS descr "expires registrations that do not respond to OPTIONS" kazoo.keepalive_failed_log_level = KEEPALIVE_FAILED_LOG_LEVEL descr "loglevel for keepalive failed reply" +kazoo.keepalive_failed_action = KEEPALIVE_FAILED_ACTION descr "action for devices that exceed the threshold. 1 = disable, 2 = delete" +kazoo.keepalive_interval = KEEPALIVE_INTERVAL descr "interval in seconds between attempts to send OPTIONS to device" +kazoo.keepalive_expired_registration_action = KEEPALIVE_EXPIRED_REGISTRATION_ACTION descr "action when registrar expires a registration, 1 = delete , 2 = disable, 0 = none" +kazoo.keepalive_expired_subscription_action = KEEPALIVE_EXPIRED_SUBSCRIPTION_ACTION descr "action when presence expires a subscription, 1 = delete , 2 = disable, 0 = none" +kazoo.keepalive_on_registration_action = KEEPALIVE_ON_REGISTRATION_ACTION descr "action on registration, 1 = insert in keepalive , 0 = none" +kazoo.keepalive_on_subscription_action = KEEPALIVE_ON_SUBSCRIPTION_ACTION descr "action on subscription, 1 = insert in keepalive , 0 = none" modparam("rtimer", "timer", "name=keepalive_timer;interval=1;mode=KEEPALIVE_S_TIMERS;") modparam("rtimer", "exec", "timer=keepalive_timer;route=KEEPALIVE_TIMER") @@ -27,67 +38,109 @@ modparam("rtimer", "exec", "timer=keepalive_timer;route=KEEPALIVE_TIMER") modparam("rtimer", "timer", "name=keepalive_db_timer;interval=1;mode=1;") modparam("rtimer", "exec", "timer=keepalive_db_timer;route=KEEPALIVE_DB_TIMER") +modparam("rtimer", "timer", "name=keepalive_cleanup;interval=5;mode=1;") +modparam("rtimer", "exec", "timer=keepalive_cleanup;route=KEEPALIVE_CLEANUP") + modparam("mqueue","mqueue", "name=keepalive_db_queue") +modparam("statistics","variable", "keepalive:success") +modparam("statistics","variable", "keepalive:failure") +modparam("statistics","variable", "keepalive:db:success") +modparam("statistics","variable", "keepalive:db:failure") +modparam("statistics","variable", "keepalive:client_options") +modparam("statistics","variable", "keepalive:client_notify") +modparam("statistics","variable", "keepalive:disabled") +modparam("statistics","variable", "keepalive:removed") +modparam("statistics","variable", "keepalive:expired_registrations") +modparam("statistics","variable", "keepalive:expired_subscriptions") + +modparam("statistics","variable", "keepalive:from_registration") +modparam("statistics","variable", "keepalive:from_subscription") + +modparam("statistics","variable", "keepalive:removed_from_registration") +modparam("statistics","variable", "keepalive:removed_from_subscription") + +modparam("statistics","variable", "keepalive:disabled_from_expired_registration") +modparam("statistics","variable", "keepalive:removed_from_expired_registration") + +modparam("statistics","variable", "keepalive:disabled_from_expired_subscription") +modparam("statistics","variable", "keepalive:removed_from_expired_subscription") + route[KEEPALIVE_DB_TIMER] { $var(runloop) = 1; while(mq_fetch("keepalive_db_queue") == 1 && $var(runloop) < MAX_WHILE_LOOPS) { $var(ci) = $mqk(keepalive_db_queue); - xlog("L_DEBUG", "Query : $mqv(keepalive_db_queue)\n"); - lock("keepalive"); + xlog("L_DEBUG", "Query : $var(ci) => $mqv(keepalive_db_queue)\n"); $var(sqlres) = sql_query("cb", "$mqv(keepalive_db_queue)"); xlog("L_DEBUG", "Query result : $var(sqlres)\n"); if($var(sqlres) < 0) { xlog("L_ERROR", "$var(ci)|log|error running query : $mqv(keepalive_db_queue)\n"); } else { + $var(stat_update) = $_s(+$sqlrows(cb)); + update_stat("$var(ci)", "$var(stat_update)"); + $var(nrows) = $sqlrows(cb); - xlog("L_DEBUG", "$var(ci)|log|end UPDATED $var(nrows)\n"); + xlog("L_DEBUG", "$var(ci)|log|end UPDATED $var(nrows) => $var(stat_update)\n"); if($var(nrows) == 0) { xlog("L_DEBUG", "$var(ci)|log|error no rows affected when running query\n"); } } - unlock("keepalive"); $var(runloop) = $var(runloop) + 1; } } route[KEEPALIVE_CLEANUP] { - lock("keepalive"); + $var(Query) = $_s(UPDATE keepalive SET SELECTED = 9 where selected < 3 and failed > $sel(cfg_get.kazoo.keepalive_failed_threshold)); + sql_query("cb", "$var(Query)"); + if($sel(cfg_get.kazoo.keepalive_expire_registrations) == 1) { - $var(Query) = $_s(update location set expires = last_modified where id in(select b.id from w_keepalive_contact a inner join w_location_contact b on a.contact = b.contact where slot = $rtimer_worker AND failed > $sel(cfg_get.kazoo.keepalive_failed_threshold))); + $var(Query) = $_s(update location set expires = last_modified where id in(select b.id from w_keepalive_contact a inner join w_location_contact b on a.contact = b.contact where selected = 9)); sql_query("cb", "$var(Query)"); + $var(stat_update) = $_s(+$sqlrows(cb)); + update_stat("keepalive:expired_registrations", "$var(stat_update)"); } + if($sel(cfg_get.kazoo.keepalive_expire_subscriptions) == 1) { - $var(Query) = $_s(DELETE FROM active_watchers where id in(select b.id from w_keepalive_contact a inner join w_watchers_contact b on a.contact = b.contact where slot = $rtimer_worker and failed > $sel(cfg_get.kazoo.keepalive_failed_threshold))); + $var(Query) = $_s(DELETE FROM active_watchers where id in(select b.id from w_keepalive_contact a inner join w_watchers_contact b on a.contact = b.contact where selected = 9)); sql_query("cb", "$var(Query)"); + $var(stat_update) = $_s(+$sqlrows(cb)); + update_stat("keepalive:expired_subscriptions", "$var(stat_update)"); + } + + if($sel(cfg_get.kazoo.keepalive_failed_action) == 2) { + ## disable + $var(Query) = $_s(UPDATE keepalive SET SELECTED = 10 where selected = 9); + $var(stat) = "keepalive:disabled"; + } else if($sel(cfg_get.kazoo.keepalive_failed_action) == 1) { + ## delete - will be recreated on registration/subscription with same contact + $var(Query) = $_s(DELETE FROM keepalive where selected = 9); + $var(stat) = "keepalive:removed"; } - $var(Query) = $_s(DELETE FROM keepalive where slot = $rtimer_worker and failed > $sel(cfg_get.kazoo.keepalive_failed_threshold)); sql_query("cb", "$var(Query)"); - unlock("keepalive"); + $var(stat_update) = $_s(+$sqlrows(cb)); + update_stat("$var(stat)", "$var(stat_update)"); } route[KEEPALIVE_TIMER] { - route(KEEPALIVE_CLEANUP); - - lock("keepalive"); - $var(Query) = $_s(UPDATE keepalive SET selected = 1 WHERE slot = $rtimer_worker AND selected = 0 AND time_sent < datetime('now', '-$def(KEEPALIVE_INTERVAL) seconds')); + $var(base_slot) = $rtimer_worker * $sel(cfg_get.kazoo.keepalive_interval); + $var(slot) = $var(base_slot) + $var(tick); + $var(Query) = $_s(UPDATE keepalive SET selected = 1 WHERE slot = $var(slot) AND selected = 0 AND time_sent < datetime('now', '-$sel(cfg_get.kazoo.keepalive_interval) seconds')); $var(sqlres) = sql_query("cb", "$var(Query)"); if($var(sqlres) < 0) { - xlog("L_ERROR", "$rtimer_worker|log|error running query : $var(Query)\n"); + xlog("L_ERROR", "$rtimer_worker|$var(tick)|log|error running query : $var(Query)\n"); } else { $var(nrows) = $sqlrows(cb); - xlog("L_DEBUG", "$rtimer_worker|log|selected $var(nrows) endpoints to ping\n"); + xlog("L_DEBUG", "$rtimer_worker|$var(tick)|log|selected $var(nrows) endpoints to ping\n"); } - unlock("keepalive"); - lock("keepalive"); - $var(Query) = $_s(SELECT id, contact, sockinfo from keepalive WHERE slot = $rtimer_worker AND selected = 1); - xlog("L_DEBUG", "$rtimer_worker|timer|SQL => $var(Query)\n"); - if (sql_xquery("cb", "$var(Query)", "ra") == 1) - { + $var(Query) = $_s(SELECT id, contact, sockinfo from keepalive WHERE slot = $var(slot) AND selected = 1); + xlog("L_DEBUG", "$rtimer_worker|$var(tick)|timer|SQL => $var(Query)\n"); + $var(result) =sql_xquery("cb", "$var(Query)", "ra"); + + if($var(result) == 1) { while($xavp(ra) != $null) { $var(loop) = 0; while($xavp(ra) != $null && $var(loop) < MAX_WHILE_LOOPS) { @@ -97,17 +150,18 @@ route[KEEPALIVE_TIMER] } } } - unlock("keepalive"); - lock("keepalive"); - $var(Query) = $_s(UPDATE keepalive SET selected = 2 WHERE slot = $rtimer_worker AND selected = 1); + $var(Query) = $_s(UPDATE keepalive SET selected = 2 WHERE slot = $var(slot) AND selected = 1); $var(sqlres) = sql_query("cb", "$var(Query)"); if($var(sqlres) < 0) { - xlog("L_ERROR", "$rtimer_worker|log|error running query : $var(Query)\n"); + xlog("L_ERROR", "$rtimer_worker|$var(tick)|log|error running query : $var(Query)\n"); } - unlock("keepalive"); - + $var(tick) = $var(tick) + 1; + if($var(tick) > $sel(cfg_get.kazoo.keepalive_interval)) { + $var(tick) = 0; + } + } route[KEEPALIVE_SEND_PING] @@ -129,19 +183,21 @@ route[KEEPALIVE_SEND_PING] onreply_route[KEEPALIVE_REPLY] { xlog("L_DEBUG", "$ci|keepalive|KEEPALIVE REPLY $(tu{nameaddr.uri})\n"); - $var(Query) = $_s(UPDATE keepalive SET selected = 0, failed = 0, time_sent = datetime('now') WHERE id = $(fu{uri.param,nat_id});); + $var(Query) = $_s(UPDATE keepalive SET selected = 0, failed = 0, time_sent = datetime('now') WHERE id = $(fu{uri.param,nat_id}) AND SELECTED = 2); xlog("L_DEBUG", "$ci|keepalive|KEEPALIVE UPDATE SQL => '$var(Query)'\n"); - mq_add("keepalive_db_queue", "$uuid(g)", "$var(Query)"); - t_drop(); + mq_add("keepalive_db_queue", "keepalive:db:success", "$var(Query)"); + update_stat("keepalive:success", "+1"); + resetflag(FLAG_SIP_TRACE); } failure_route[KEEPALIVE_FAULT] { xlog("$(sel(cfg_get.kazoo.keepalive_failed_log_level){s.int})", "$ci|keepalive|received error $T_reply_code $T_reply_reason from $(tu{nameaddr.uri})\n"); - $var(Query) = $_s(UPDATE keepalive SET selected = 0, failed = failed + 1, time_sent = datetime('now') WHERE id = $(fu{uri.param,nat_id});); + $var(Query) = $_s(UPDATE keepalive SET selected = 0, failed = failed + 1, time_sent = datetime('now') WHERE id = $(fu{uri.param,nat_id}) AND SELECTED = 2); xlog("L_DEBUG", "$ci|keepalive|KEEPALIVE REMOVE SQL => '$var(Query)'\n"); - mq_add("keepalive_db_queue", "$uuid(g)", "$var(Query)"); - t_drop(); + mq_add("keepalive_db_queue", "keepalive:db:failure", "$var(Query)"); + update_stat("keepalive:failure", "+1"); + resetflag(FLAG_SIP_TRACE); } route[KEEPALIVE_PING] @@ -163,6 +219,10 @@ route[KEEPALIVE_PING] route[KEEPALIVE_ON_REGISTRATION] { + + if($sel(cfg_get.kazoo.keepalive_on_registration_action) == 0) { + return; + } if($proto == "ws" || $proto == "wss") { return; @@ -185,41 +245,57 @@ route[KEEPALIVE_ON_REGISTRATION] if($var(save_result) == 3) { $var(sql) = $_s(DELETE FROM keepalive WHERE contact = "$var(contact)"); + $var(stat) = "keepalive:removed_from_registration"; } else { - $var(slot) = $(var(contact){s.corehash, KEEPALIVE_S_TIMERS}); - $var(sql) = $_s(INSERT OR IGNORE INTO keepalive (contact, sockinfo, slot) values("$var(contact)", "$(RAut{uri.tosocket})", $var(slot))); + $var(max_slots) = $sel(cfg_get.kazoo.keepalive_interval) * KEEPALIVE_S_TIMERS; + $var(slot) = $(var(contact){s.corehash, $var(max_slots)}); + $var(sql) = $_s(INSERT OR IGNORE INTO keepalive (contact, received, sockinfo, slot) values("$var(contact)", "$var(alias)", "$(RAut{uri.tosocket})", $var(slot))); + $var(stat) = "keepalive:from_registration"; } - mq_add("keepalive_db_queue", "$ci", "$var(sql)"); + mq_add("keepalive_db_queue", "$var(stat)", "$var(sql)"); return; } route[KEEPALIVE_ON_SUBSCRIBE] { + if($sel(cfg_get.kazoo.keepalive_on_subscription_action) == 0) { + return; + } + if(!( ($sel(cfg_get.kazoo.keepalive_udp_only) == 1 && $proto != "udp") || (!isflagset(FLT_NATS) && $sel(cfg_get.kazoo.keepalive_nat_only) == 1) || ($proto == "ws" || $proto == "wss") )) { - $var(slot) = $(subs(contact){s.corehash, KEEPALIVE_S_TIMERS}); - $var(sql) = $_s(INSERT OR IGNORE INTO keepalive (contact, sockinfo, slot) values("$subs(contact)", "$subs(sockinfo)", $var(slot))); - mq_add("keepalive_db_queue", "$ci", "$var(sql)"); + $var(max_slots) = $sel(cfg_get.kazoo.keepalive_interval) * KEEPALIVE_S_TIMERS; + $var(slot) = $(subs(contact){s.corehash, $var(max_slots)}); + $var(alias) = $(subs(contact){uri.param,alias}); + $var(sql) = $_s(INSERT OR IGNORE INTO keepalive (contact, received, sockinfo, slot) values("$subs(contact)", "$var(alias)", "$subs(sockinfo)", $var(slot))); + mq_add("keepalive_db_queue", "keepalive:from_subscription", "$var(sql)"); } } route[KEEPALIVE_ON_EXPIRED_REGISTRATION] { - $var(Query) = $_s(DELETE FROM keepalive where contact like "$ulc(exp=>addr)%"); - mq_add("keepalive_db_queue", "$uuid(g)", "$var(Query)"); + if($sel(cfg_get.kazoo.keepalive_expired_registration_action) == 2) { + ## disable + $var(Query) = $_s(UPDATE keepalive SET SELECTED = 10 where selected < 3 and contact like "$ulc(exp=>addr)%"); + mq_add("keepalive_db_queue", "keepalive:disabled_from_expired_registration", "$var(Query)"); + } else if($sel(cfg_get.kazoo.keepalive_expired_registration_action) == 1) { + ## delete - will be recreated on registration with same contact + $var(Query) = $_s(DELETE FROM keepalive where selected < 3 and contact like "$ulc(exp=>addr)%"); + mq_add("keepalive_db_queue", "keepalive:removed_from_expired_registration", "$var(Query)"); + } } route[KEEPALIVE_ON_OPTIONS] { - $var(Query) = $_s(UPDATE keepalive set selected = 3 where contact like "%alias=$si~$sp~$prid%"); - mq_add("keepalive_db_queue", "$uuid(g)", "$var(Query)"); + $var(Query) = $_s(UPDATE keepalive set selected = 3 where received = "$si~$sp~$prid" and selected <> 3 ); + mq_add("keepalive_db_queue", "keepalive:client_options", "$var(Query)"); } route[KEEPALIVE_ON_NOTIFY] { - $var(Query) = $_s(UPDATE keepalive set selected = 4 where contact like "%alias=$si~$sp~$prid%"); - mq_add("keepalive_db_queue", "$uuid(g)", "$var(Query)"); + $var(Query) = $_s(UPDATE keepalive set selected = 4 where received = "$si~$sp~$prid" and selected <> 4 ); + mq_add("keepalive_db_queue", "keepalive:client_notify", "$var(Query)"); } From 0704f225428686d08cfe07a9c7f1bd14a12e1268 Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 19 Mar 2019 01:47:32 +0000 Subject: [PATCH 183/209] add registrar perm error condition & macros & defaults --- kamailio/registrar-role.cfg | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/kamailio/registrar-role.cfg b/kamailio/registrar-role.cfg index 913ad8c..e2c7c43 100644 --- a/kamailio/registrar-role.cfg +++ b/kamailio/registrar-role.cfg @@ -30,11 +30,13 @@ #!trydef REGISTRAR_AMQP_FLAGS 0 #!trydef REGISTRAR_AMQP_RK_PREFIX authn.req. #!trydef REGISTRAR_SEND_100 1 -#!trydef REGISTRAR_DB_MODE 3 +#!trydef REGISTRAR_DB_MODE 2 #!trydef REGISTRAR_DB_TIMER_CLEANUP 0 #!trydef REGISTRAR_HANDLE_LOST_TCP 0 -#!trydef REGISTRAR_DB_TIMER_CLEANUP 0 -#!trydef REGISTRAR_DB_REMOVE_EXPIRED_DELAY 30 +#!trydef REGISTRAR_DB_REMOVE_EXPIRED_DELAY 0 +#!trydef REGISTRAR_SYNC_TIMER_INTERVAL 5 +#!trydef REGISTRAR_SYNC_TIMER_PROCS 1 + #!ifdef REGISTRAR_WARM_CACHE #!substdef "!REGISTRAR_S_WARM_CACHE!dbtable=auth_cache;dbmode=1;!g" @@ -70,8 +72,9 @@ modparam("usrloc", "db_ops_ruid", 1) modparam("usrloc", "xavp_contact", "ulattrs") -modparam("usrloc", "timer_interval", 5) -modparam("usrloc", "timer_procs", 1) +modparam("usrloc", "timer_interval", REGISTRAR_SYNC_TIMER_INTERVAL) +modparam("usrloc", "timer_procs", REGISTRAR_SYNC_TIMER_PROCS) + modparam("usrloc", "fetch_rows", 400) modparam("usrloc", "handle_lost_tcp", REGISTRAR_HANDLE_LOST_TCP) modparam("usrloc", "close_expired_tcp", REGISTRAR_CLOSE_EXPIRED_TCP) @@ -121,6 +124,7 @@ modparam("statistics","variable", "registrar:amqp_async_error") modparam("statistics","variable", "registrar:amqp_returned") modparam("statistics","variable", "registrar:amqp_timeout") modparam("statistics","variable", "registrar:drops") +modparam("statistics","variable", "registrar:authn_perm_err") modparam("statistics","variable", "registrar:authn_err") modparam("statistics","variable", "registrar:authn_resp") modparam("statistics","variable", "registrar:authn_unknown") @@ -187,10 +191,15 @@ route[HANDLE_REGISTER] } if($sel(cfg_get.kazoo.registrar_force_query) == 0) { - if($sht(auth_cache=>$Au) == "authn_err") { - xlog("L_WARNING", "$ci|end|issuing auth challenge to cached failed registration attempt for $Au from IP $si:$sp\n"); + if($sht(auth_cache=>$Au) == "authn_perm_err") { + xlog("L_INFO", "$ci|end|issuing auth challenge to cached permanent failed registration attempt for $Au from IP $si:$sp\n"); + update_stat("registrar:authn_perm_err", "+1"); + #!ifdef ANTIFLOOD_ROLE + route(ANITFLOOD_FAILED_AUTH); + #!endif update_stat("registrar:challenge", "+1"); auth_challenge("$fd", "5"); + exit; } else if($sht(auth_cache=>$Au) != $null) { $xavp(regcfg=>match_received) = $su; if(registered("location", "$rz:$Au", 2, 1) == 1) { @@ -278,7 +287,9 @@ onreply_route[KZ_AUTHORIZATION_REPLY] $var(password) = $(kzR{kz.json,Auth-Password}); $var(nonce) = $adn; if( $(kzR{kz.json,Event-Name}) == "authn_err" ) { - $sht(auth_cache=>$Au) = "authn_err"; + if($(kzR{kz.json,Permanent-Error}) == "true") { + $sht(auth_cache=>$Au) = "authn_perm_err"; + } update_stat("registrar:authn_err", "+1"); #!ifdef ANTIFLOOD_ROLE route(ANITFLOOD_FAILED_AUTH); @@ -288,19 +299,17 @@ onreply_route[KZ_AUTHORIZATION_REPLY] xlog("L_INFO", "$ci|end|challenging $Au $si:$sp via $(kzR{kz.json,App-Name})-$(kzR{kz.json,App-Version}) response\n"); exit; } else if( $(kzR{kz.json,Event-Name}) == "authn_resp" ) { - update_stat("registrar:authn_resp", "+1"); + update_stat("registrar:authn_resp", "+1"); xlog("L_INFO", "$ci|log|authenticating $Au via $(kzR{kz.json,App-Name})-$(kzR{kz.json,App-Version}) response\n"); route(CHECK_AUTHORIZATION); } else { update_stat("registrar:authn_unknown", "+1"); - update_stat("registrar:drops", "+1"); + update_stat("registrar:drops", "+1"); xlog("L_INFO", "$ci|log|unhandle response from directory $Au via $(kzR{kz.json,App-Name})-$(kzR{kz.json,App-Version})\n"); t_drop(); } } - - route[CHECK_AUTHORIZATION] { From 5325d4e1f9b25efab17c987b821abbbc5932d53d Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 19 Mar 2019 01:50:20 +0000 Subject: [PATCH 184/209] add presence_with_targets_log_level --- kamailio/presence-role.cfg | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/kamailio/presence-role.cfg b/kamailio/presence-role.cfg index 8d405fc..f079f85 100644 --- a/kamailio/presence-role.cfg +++ b/kamailio/presence-role.cfg @@ -11,6 +11,7 @@ #!trydef KZ_PRESENCE_REQUEST_RESUBSCRIBE_PROBE 0 #!trydef KZ_PRESENCE_REQUEST_PROBE 1 #!trydef KZ_PRESENCE_NO_TARGETS_LOG_LEVEL L_DBG +#!trydef KZ_PRESENCE_WITH_TARGETS_LOG_LEVEL L_INFO #!trydef KZ_PRESENCE_REQUIRE_AUTHN 0 modparam("htable", "htable", "first=>size=32;autoexpire=3600;initval=0;") @@ -59,6 +60,7 @@ kazoo.presence_request_resubscribe_probe = KZ_PRESENCE_REQUEST_RESUBSCRIBE_PROBE kazoo.presence_ignore_status_probe_resp = KZ_PRESENCE_IGNORE_STATUS_PROBE_RESP descr "ignore online/offline probe replies" kazoo.presence_max_call_per_presentity = KZ_PRESENCE_MAX_CALL_PER_PRESENTITY descr "max number of calls per presentity" kazoo.presence_no_targets_log_level = KZ_PRESENCE_NO_TARGETS_LOG_LEVEL descr "when a presence event is received and there no targets we can log at another level" +kazoo.presence_with_targets_log_level = KZ_PRESENCE_WITH_TARGETS_LOG_LEVEL descr "when a presence event is received and there are targets we can log at another level" kazoo.presence_require_authn = KZ_PRESENCE_REQUIRE_AUTHN descr "require authenticated devices for presence" #!include_file "presence-query.cfg" @@ -350,14 +352,14 @@ event_route[kazoo:consumer-event-presence-mwi-update] $var(payload) = $kzE; route(COUNT_SUBSCRIBERS); if($xavp(watchers=>message-summary) > 0) { - $var(kz_presence_log_level) = L_INFO; + $var(kz_presence_log_level) = $(sel(cfg_get.kazoo.presence_with_targets_log_level){s.int}); xlog("L_INFO", "$(kzE{kz.json,Call-ID})|log|publishing $(kzE{kz.json,From}) message-summary update for $xavp(watchers=>message-summary) watchers\n"); kazoo_pua_publish_mwi($kzE); pres_refresh_watchers("$(kzE{kz.json,From})", "message-summary", 1); } else { #!ifdef PRESENCE_TRACK_ALL_PKG_MWI if($(kzE{kz.json,Event-Package}) == "message-summary") { - $var(kz_presence_log_level) = L_INFO; + $var(kz_presence_log_level) = $(sel(cfg_get.kazoo.presence_with_targets_log_level){s.int}); xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|saving $var(presentity) from mwi update => $var(payload)\n"); if(kazoo_pua_publish_mwi($kzE) != 1) { xlog("L_ERR", "$(var(payload){kz.json,Call-ID})|log|error publishing $var(presentity) mwi update => $var(payload)\n"); @@ -420,7 +422,7 @@ route[PRESENCE_UPDATE] xlog("L_WARN", "$(var(payload){kz.json,Call-ID})|log|not publishing state $(var(payload){kz.json,State}) for presentity $var(presentity) with $xavp(watchers=>self) calls, policy limit of $sel(cfg_get.kazoo.presence_max_call_per_presentity) calls per presentity \n"); } else { if($xavp(watchers=>dialog) > 0) { - $var(kz_presence_log_level) = L_INFO; + $var(kz_presence_log_level) = $(sel(cfg_get.kazoo.presence_with_targets_log_level){s.int}); if($(var(payload){kz.json,State}) == "terminated") { xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|publishing $var(presentity) dialog update for terminated dialog\n"); } else { @@ -434,7 +436,7 @@ route[PRESENCE_UPDATE] } else { #!ifdef PRESENCE_TRACK_ALL_PKG_DIALOG if($(kzE{kz.json,Event-Package}) == "dialog") { - $var(kz_presence_log_level) = L_INFO; + $var(kz_presence_log_level) = $(sel(cfg_get.kazoo.presence_with_targets_log_level){s.int}); xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|saving $var(presentity) from dialog update => $var(payload)\n"); if(kazoo_pua_publish_dialoginfo($var(JObj)) != 1) { xlog("L_ERR", "$(var(payload){kz.json,Call-ID})|log|error publishing $var(presentity) dialog update => $var(payload)\n"); @@ -446,16 +448,16 @@ route[PRESENCE_UPDATE] } if($xavp(watchers=>presence) > 0) { - $var(kz_presence_log_level) = L_INFO; + $var(kz_presence_log_level) = $(sel(cfg_get.kazoo.presence_with_targets_log_level){s.int}); xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|publishing $var(presentity) presence update for $xavp(watchers=>presence) watchers\n"); kazoo_pua_publish_presence($var(payload)); pres_refresh_watchers("$var(presentity)", "presence", 1); } else { #!ifdef PRESENCE_TRACK_ALL_PKG_PRESENCE if($(kzE{kz.json,Event-Package}) == "presence") { - $var(kz_presence_log_level) = L_INFO; + $var(kz_presence_log_level) = $(sel(cfg_get.kazoo.presence_with_targets_log_level){s.int}); xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|saving $var(presentity) from presence update => $var(payload)\n"); - if(kazoo_pua_publish_dialoginfo($var(JObj)) != 1) { + if(kazoo_pua_publish_presence($var(JObj)) != 1) { xlog("L_ERR", "$(var(payload){kz.json,Call-ID})|log|error publishing $var(presentity) presence update => $var(payload)\n"); } } From 9fcc17dadaf35089399337d7c76157bfd57f36e1 Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 19 Mar 2019 01:53:49 +0000 Subject: [PATCH 185/209] change notify timer interval --- kamailio/presence-notify.cfg | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kamailio/presence-notify.cfg b/kamailio/presence-notify.cfg index 0ef1cdf..7107249 100644 --- a/kamailio/presence-notify.cfg +++ b/kamailio/presence-notify.cfg @@ -47,10 +47,12 @@ route[PRESENCE_LOCAL_REQ_NOTIFY] modparam("mqueue","mqueue", "name=presence_last_notity") -modparam("rtimer", "timer", "name=notifytimer;interval=500000u;mode=1;") +modparam("rtimer", "timer", "name=notifytimer;interval=1;mode=1;") modparam("rtimer", "exec", "timer=notifytimer;route=PRESENCE_LOG_TIMER_ROUTE") + modparam("rtimer", "timer", "name=pres_cleanup;interval=10;mode=1;") modparam("rtimer", "exec", "timer=pres_cleanup;route=PRESENCE_CLEANUP") + modparam("rtimer", "timer", "name=pres_publisher_cleanup;interval=5;mode=1;") modparam("rtimer", "exec", "timer=pres_publisher_cleanup;route=PRESENCE_PUBLISHER_CLEANUP") From e57719f8c7ed1e24a4c27d05ac5a7eebbc2fa35f Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 19 Mar 2019 01:55:05 +0000 Subject: [PATCH 186/209] macros for db_kazoo --- kamailio/db_kazoo.cfg | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kamailio/db_kazoo.cfg b/kamailio/db_kazoo.cfg index 61de31e..d28d125 100644 --- a/kamailio/db_kazoo.cfg +++ b/kamailio/db_kazoo.cfg @@ -3,10 +3,14 @@ #!trydef KZ_DB_HOOK_TRACE 1 #!trydef KZ_DB_TRACE 0 #!trydef KZ_DB_TRACE_LOG_LEVEL 3 +#!trydef KZ_DB_MAX_ROWS 0 +#!trydef KZ_DB_TRACE_FILTER 110 loadmodule "db_kazoo.so" modparam("db_kazoo", "trace_hook", KZ_DB_HOOK_TRACE) modparam("db_kazoo", "trace_enable", KZ_DB_TRACE) modparam("db_kazoo", "trace_log_level", KZ_DB_TRACE_LOG_LEVEL) +modparam("db_kazoo", "trace_filter", KZ_DB_TRACE_FILTER) +modparam("db_kazoo", "max_rows", KZ_DB_MAX_ROWS) include_file "db_queries_kazoo.cfg" From 202bb0cda2fc63c7715db81459ca2a8d059b8cfd Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 19 Mar 2019 01:56:16 +0000 Subject: [PATCH 187/209] don't delete registrations on startup sync timer will take care of that --- kamailio/db_scripts/db_extra_check.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kamailio/db_scripts/db_extra_check.sql b/kamailio/db_scripts/db_extra_check.sql index 92e18ba..88210bd 100644 --- a/kamailio/db_scripts/db_extra_check.sql +++ b/kamailio/db_scripts/db_extra_check.sql @@ -6,7 +6,7 @@ if [[ $RESET_NON_UDP_ENABLED == "true" ]]; then KazooDB -db ${DB_CURRENT_DB} "delete from location where socket not like 'udp:%';" fi -KazooDB -db ${DB_CURRENT_DB} "delete from location where expires > 0 and datetime(expires) < datetime('now', '-30 seconds');" +##KazooDB -db ${DB_CURRENT_DB} "delete from location where expires > 0 and datetime(expires) < datetime('now', '-30 seconds');" KazooDB -db ${DB_CURRENT_DB} "delete from location_attrs where not exists(select id from location where ruid = location_attrs.ruid);" ## presence From 08a807ce949dd004419ea2cb90fb49cd0feff7dc Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 19 Mar 2019 01:56:52 +0000 Subject: [PATCH 188/209] add ruid to w_location_contact view --- kamailio/db_scripts/db_kazoo-specific | 8 ++++---- kamailio/db_scripts/vw_w_location_contact.sql | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/kamailio/db_scripts/db_kazoo-specific b/kamailio/db_scripts/db_kazoo-specific index 800bb26..2f87516 100644 --- a/kamailio/db_scripts/db_kazoo-specific +++ b/kamailio/db_scripts/db_kazoo-specific @@ -130,10 +130,10 @@ SELECT id, slot, selected, failed, case when instr(contact,";") > 0 from keepalive; CREATE VIEW w_location_contact as -SELECT id, case when instr(contact,";") > 0 - then substr(contact, 1, instr(contact,";")-1) - else contact - end as contact +SELECT id, ruid, case when instr(contact,";") > 0 + then substr(contact, 1, instr(contact,";")-1) + else contact + end as contact from location; CREATE VIEW w_watchers_contact as diff --git a/kamailio/db_scripts/vw_w_location_contact.sql b/kamailio/db_scripts/vw_w_location_contact.sql index 6227b0c..6914519 100644 --- a/kamailio/db_scripts/vw_w_location_contact.sql +++ b/kamailio/db_scripts/vw_w_location_contact.sql @@ -1,6 +1,6 @@ CREATE VIEW w_location_contact as - select id, case when instr(contact,";") > 0 - then substr(contact, 1, instr(contact,";")-1) - else contact - end as contact + select id, ruid, case when instr(contact,";") > 0 + then substr(contact, 1, instr(contact,";")-1) + else contact + end as contact from location From 23dc74baa3c3315e982fa03e8449ff4a6894a04c Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 19 Mar 2019 06:05:40 +0000 Subject: [PATCH 189/209] move keepalive to a new experimental role --- kamailio/db_kazoo.cfg | 2 - kamailio/default.cfg | 8 ++- kamailio/keepalive.cfg | 120 +++++++++++++++++++++----------- kamailio/nat-traversal-role.cfg | 2 - kamailio/presence-role.cfg | 36 +++++++++- kamailio/registrar-role.cfg | 22 +++--- 6 files changed, 130 insertions(+), 60 deletions(-) diff --git a/kamailio/db_kazoo.cfg b/kamailio/db_kazoo.cfg index d28d125..4989a32 100644 --- a/kamailio/db_kazoo.cfg +++ b/kamailio/db_kazoo.cfg @@ -3,7 +3,6 @@ #!trydef KZ_DB_HOOK_TRACE 1 #!trydef KZ_DB_TRACE 0 #!trydef KZ_DB_TRACE_LOG_LEVEL 3 -#!trydef KZ_DB_MAX_ROWS 0 #!trydef KZ_DB_TRACE_FILTER 110 loadmodule "db_kazoo.so" @@ -11,6 +10,5 @@ modparam("db_kazoo", "trace_hook", KZ_DB_HOOK_TRACE) modparam("db_kazoo", "trace_enable", KZ_DB_TRACE) modparam("db_kazoo", "trace_log_level", KZ_DB_TRACE_LOG_LEVEL) modparam("db_kazoo", "trace_filter", KZ_DB_TRACE_FILTER) -modparam("db_kazoo", "max_rows", KZ_DB_MAX_ROWS) include_file "db_queries_kazoo.cfg" diff --git a/kamailio/default.cfg b/kamailio/default.cfg index 4d90022..9e21478 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -267,6 +267,9 @@ include_file "nodes-role.cfg" #!ifdef SIP_TRACE_ROLE include_file "sip_trace-role.cfg" #!endif +#!ifdef KEEPALIVE_ROLE +include_file "keepalive.cfg" +#!endif ## auth ## include_file "auth.cfg" @@ -423,7 +426,7 @@ route[HANDLE_OPTIONS] sl_send_reply("200", "Rawr!!"); - #!ifdef NAT_TRAVERSAL_ROLE + #!ifdef KEEPALIVE_ROLE route(KEEPALIVE_ON_OPTIONS); #!endif } @@ -463,7 +466,6 @@ route[HANDLE_NOTIFY] } #!endif - if($hdr(Event) == "keep-alive") { xlog("L_INFO", "$ci|stop|replying to keep alive\n"); sl_send_reply("405", "Stay Alive / Method Not Allowed"); @@ -472,7 +474,7 @@ route[HANDLE_NOTIFY] sl_send_reply("200", "Rawr!!"); } - #!ifdef NAT_TRAVERSAL_ROLE + #!ifdef KEEPALIVE_ROLE route(KEEPALIVE_ON_NOTIFY); #!endif diff --git a/kamailio/keepalive.cfg b/kamailio/keepalive.cfg index 64c1b20..b7d28e1 100644 --- a/kamailio/keepalive.cfg +++ b/kamailio/keepalive.cfg @@ -1,5 +1,6 @@ ######## KEEPALIVE PINGING ######## +#!trydef KEEPALIVE_ENABLED 1 #!trydef KEEPALIVE_NAT_ONLY 0 #!trydef KEEPALIVE_UDP_ONLY 0 #!trydef KEEPALIVE_TIMERS 4 @@ -31,6 +32,7 @@ kazoo.keepalive_expired_registration_action = KEEPALIVE_EXPIRED_REGISTRATION_ACT kazoo.keepalive_expired_subscription_action = KEEPALIVE_EXPIRED_SUBSCRIPTION_ACTION descr "action when presence expires a subscription, 1 = delete , 2 = disable, 0 = none" kazoo.keepalive_on_registration_action = KEEPALIVE_ON_REGISTRATION_ACTION descr "action on registration, 1 = insert in keepalive , 0 = none" kazoo.keepalive_on_subscription_action = KEEPALIVE_ON_SUBSCRIPTION_ACTION descr "action on subscription, 1 = insert in keepalive , 0 = none" +kazoo.keepalive_enable = KEEPALIVE_ENABLED descr "enable keepalive, 1 = on , 0 = off" modparam("rtimer", "timer", "name=keepalive_timer;interval=1;mode=KEEPALIVE_S_TIMERS;") modparam("rtimer", "exec", "timer=keepalive_timer;route=KEEPALIVE_TIMER") @@ -38,8 +40,8 @@ modparam("rtimer", "exec", "timer=keepalive_timer;route=KEEPALIVE_TIMER") modparam("rtimer", "timer", "name=keepalive_db_timer;interval=1;mode=1;") modparam("rtimer", "exec", "timer=keepalive_db_timer;route=KEEPALIVE_DB_TIMER") -modparam("rtimer", "timer", "name=keepalive_cleanup;interval=5;mode=1;") -modparam("rtimer", "exec", "timer=keepalive_cleanup;route=KEEPALIVE_CLEANUP") +##modparam("rtimer", "timer", "name=keepalive_cleanup;interval=5;mode=1;") +##modparam("rtimer", "exec", "timer=keepalive_cleanup;route=KEEPALIVE_CLEANUP") modparam("mqueue","mqueue", "name=keepalive_db_queue") @@ -66,6 +68,8 @@ modparam("statistics","variable", "keepalive:removed_from_expired_registration") modparam("statistics","variable", "keepalive:disabled_from_expired_subscription") modparam("statistics","variable", "keepalive:removed_from_expired_subscription") +modparam("htable", "htable", "keepalive=>size=32;") + route[KEEPALIVE_DB_TIMER] { $var(runloop) = 1; @@ -92,42 +96,58 @@ route[KEEPALIVE_DB_TIMER] route[KEEPALIVE_CLEANUP] { - $var(Query) = $_s(UPDATE keepalive SET SELECTED = 9 where selected < 3 and failed > $sel(cfg_get.kazoo.keepalive_failed_threshold)); - sql_query("cb", "$var(Query)"); + if($sel(cfg_get.kazoo.keepalive_enable) == 0) return; - if($sel(cfg_get.kazoo.keepalive_expire_registrations) == 1) { - $var(Query) = $_s(update location set expires = last_modified where id in(select b.id from w_keepalive_contact a inner join w_location_contact b on a.contact = b.contact where selected = 9)); - sql_query("cb", "$var(Query)"); - $var(stat_update) = $_s(+$sqlrows(cb)); - update_stat("keepalive:expired_registrations", "$var(stat_update)"); - } + $var(Query) = $_s(UPDATE keepalive SET SELECTED = 9 WHERE slot = $var(slot) AND selected = 0 and failed > $sel(cfg_get.kazoo.keepalive_failed_threshold)); +# $var(Query) = $_s(UPDATE keepalive SET SELECTED = 9 where selected < 3 and failed > $sel(cfg_get.kazoo.keepalive_failed_threshold)); + sql_query("cb", "$var(Query)"); - if($sel(cfg_get.kazoo.keepalive_expire_subscriptions) == 1) { - $var(Query) = $_s(DELETE FROM active_watchers where id in(select b.id from w_keepalive_contact a inner join w_watchers_contact b on a.contact = b.contact where selected = 9)); + if($sqlrows(cb) > 0) { + + if($sel(cfg_get.kazoo.keepalive_expire_registrations) == 1) { + if($def(REGISTRAR_DB_MODE) == 3) { + $var(Query) = $_s(update location set expires = last_modified where id in(select b.id from w_keepalive_contact a inner join w_location_contact b on a.contact = b.contact where selected = 9)); + sql_query("cb", "$var(Query)"); + $var(stat_update) = $_s(+$sqlrows(cb)); + update_stat("keepalive:expired_registrations", "$var(stat_update)"); + } else { + $var(Query) = $_s(update location set expires = last_modified where id in(select b.id from w_keepalive_contact a inner join w_location_contact b on a.contact = b.contact where selected = 9)); + sql_query("cb", "$var(Query)"); + $var(stat_update) = $_s(+$sqlrows(cb)); + update_stat("keepalive:expired_registrations", "$var(stat_update)"); + } + } + + if($sel(cfg_get.kazoo.keepalive_expire_subscriptions) == 1) { + $var(Query) = $_s(DELETE FROM active_watchers where id in(select b.id from w_keepalive_contact a inner join w_watchers_contact b on a.contact = b.contact where selected = 9)); + sql_query("cb", "$var(Query)"); + $var(stat_update) = $_s(+$sqlrows(cb)); + update_stat("keepalive:expired_subscriptions", "$var(stat_update)"); + } + + if($sel(cfg_get.kazoo.keepalive_failed_action) == 2) { + ## disable + $var(Query) = $_s(UPDATE keepalive SET SELECTED = 10 where selected = 9); + $var(stat) = "keepalive:disabled"; + } else if($sel(cfg_get.kazoo.keepalive_failed_action) == 1) { + ## delete - will be recreated on registration/subscription with same contact + $var(Query) = $_s(DELETE FROM keepalive where selected = 9); + $var(stat) = "keepalive:removed"; + } sql_query("cb", "$var(Query)"); $var(stat_update) = $_s(+$sqlrows(cb)); - update_stat("keepalive:expired_subscriptions", "$var(stat_update)"); - } - - if($sel(cfg_get.kazoo.keepalive_failed_action) == 2) { - ## disable - $var(Query) = $_s(UPDATE keepalive SET SELECTED = 10 where selected = 9); - $var(stat) = "keepalive:disabled"; - } else if($sel(cfg_get.kazoo.keepalive_failed_action) == 1) { - ## delete - will be recreated on registration/subscription with same contact - $var(Query) = $_s(DELETE FROM keepalive where selected = 9); - $var(stat) = "keepalive:removed"; + update_stat("$var(stat)", "$var(stat_update)"); } - sql_query("cb", "$var(Query)"); - $var(stat_update) = $_s(+$sqlrows(cb)); - update_stat("$var(stat)", "$var(stat_update)"); } route[KEEPALIVE_TIMER] { + if($sel(cfg_get.kazoo.keepalive_enable) == 0) return; + $var(base_slot) = $rtimer_worker * $sel(cfg_get.kazoo.keepalive_interval); $var(slot) = $var(base_slot) + $var(tick); $var(Query) = $_s(UPDATE keepalive SET selected = 1 WHERE slot = $var(slot) AND selected = 0 AND time_sent < datetime('now', '-$sel(cfg_get.kazoo.keepalive_interval) seconds')); +## xlog("L_NOTICE", "SQLTIMER ($var(base_slot) + $var(tick))> $var(Query)\n"); $var(sqlres) = sql_query("cb", "$var(Query)"); if($var(sqlres) < 0) { xlog("L_ERROR", "$rtimer_worker|$var(tick)|log|error running query : $var(Query)\n"); @@ -135,6 +155,8 @@ route[KEEPALIVE_TIMER] $var(nrows) = $sqlrows(cb); xlog("L_DEBUG", "$rtimer_worker|$var(tick)|log|selected $var(nrows) endpoints to ping\n"); } + + route(KEEPALIVE_CLEANUP); $var(Query) = $_s(SELECT id, contact, sockinfo from keepalive WHERE slot = $var(slot) AND selected = 1); xlog("L_DEBUG", "$rtimer_worker|$var(tick)|timer|SQL => $var(Query)\n"); @@ -219,6 +241,7 @@ route[KEEPALIVE_PING] route[KEEPALIVE_ON_REGISTRATION] { + if($sel(cfg_get.kazoo.keepalive_enable) == 0) return; if($sel(cfg_get.kazoo.keepalive_on_registration_action) == 0) { return; @@ -227,6 +250,10 @@ route[KEEPALIVE_ON_REGISTRATION] if($proto == "ws" || $proto == "wss") { return; } + + if($sht(keepalive=>$si~$sp~$prid) != $null) { + return; + } if (isbflagset(FLB_NATB)) { if(!isbflagset(FLB_NATSIPPING)) { @@ -259,24 +286,28 @@ route[KEEPALIVE_ON_REGISTRATION] route[KEEPALIVE_ON_SUBSCRIBE] { + if($sel(cfg_get.kazoo.keepalive_enable) == 0) return; + if($sel(cfg_get.kazoo.keepalive_on_subscription_action) == 0) { return; } - if(!( ($sel(cfg_get.kazoo.keepalive_udp_only) == 1 && $proto != "udp") - || (!isflagset(FLT_NATS) && $sel(cfg_get.kazoo.keepalive_nat_only) == 1) - || ($proto == "ws" || $proto == "wss") - )) { - $var(max_slots) = $sel(cfg_get.kazoo.keepalive_interval) * KEEPALIVE_S_TIMERS; - $var(slot) = $(subs(contact){s.corehash, $var(max_slots)}); - $var(alias) = $(subs(contact){uri.param,alias}); - $var(sql) = $_s(INSERT OR IGNORE INTO keepalive (contact, received, sockinfo, slot) values("$subs(contact)", "$var(alias)", "$subs(sockinfo)", $var(slot))); - mq_add("keepalive_db_queue", "keepalive:from_subscription", "$var(sql)"); + if($sht(keepalive=>$si~$sp~$prid) != $null) { + return; } + + $var(max_slots) = $sel(cfg_get.kazoo.keepalive_interval) * KEEPALIVE_S_TIMERS; + $var(slot) = $(subs(contact){s.corehash, $var(max_slots)}); + $var(alias) = $(subs(contact){uri.param,alias}); + $var(sql) = $_s(INSERT OR IGNORE INTO keepalive (contact, received, sockinfo, slot) values("$subs(contact)", "$var(alias)", "$subs(sockinfo)", $var(slot))); + mq_add("keepalive_db_queue", "keepalive:from_subscription", "$var(sql)"); + } route[KEEPALIVE_ON_EXPIRED_REGISTRATION] { + if($sel(cfg_get.kazoo.keepalive_enable) == 0) return; + if($sel(cfg_get.kazoo.keepalive_expired_registration_action) == 2) { ## disable $var(Query) = $_s(UPDATE keepalive SET SELECTED = 10 where selected < 3 and contact like "$ulc(exp=>addr)%"); @@ -286,16 +317,27 @@ route[KEEPALIVE_ON_EXPIRED_REGISTRATION] $var(Query) = $_s(DELETE FROM keepalive where selected < 3 and contact like "$ulc(exp=>addr)%"); mq_add("keepalive_db_queue", "keepalive:removed_from_expired_registration", "$var(Query)"); } + } route[KEEPALIVE_ON_OPTIONS] { - $var(Query) = $_s(UPDATE keepalive set selected = 3 where received = "$si~$sp~$prid" and selected <> 3 ); - mq_add("keepalive_db_queue", "keepalive:client_options", "$var(Query)"); + if($sel(cfg_get.kazoo.keepalive_enable) == 0) return; + + if($shtinc(keepalive=>$si~$sp~$prid) == 1) { + $var(Query) = $_s(UPDATE keepalive set selected = 3 where received = "$si~$sp~$prid" and selected <> 3 ); + mq_add("keepalive_db_queue", "keepalive:client_options", "$var(Query)"); + } + } route[KEEPALIVE_ON_NOTIFY] { - $var(Query) = $_s(UPDATE keepalive set selected = 4 where received = "$si~$sp~$prid" and selected <> 4 ); - mq_add("keepalive_db_queue", "keepalive:client_notify", "$var(Query)"); + if($sel(cfg_get.kazoo.keepalive_enable) == 0) return; + + if($shtinc(keepalive=>$si~$sp~$prid) == 1) { + $var(Query) = $_s(UPDATE keepalive set selected = 4 where received = "$si~$sp~$prid" and selected <> 4 ); + mq_add("keepalive_db_queue", "keepalive:client_notify", "$var(Query)"); + } + } diff --git a/kamailio/nat-traversal-role.cfg b/kamailio/nat-traversal-role.cfg index 9d9451f..6d62690 100644 --- a/kamailio/nat-traversal-role.cfg +++ b/kamailio/nat-traversal-role.cfg @@ -113,6 +113,4 @@ route[NAT_MANAGE] } -#!include_file "keepalive.cfg" - # vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab diff --git a/kamailio/presence-role.cfg b/kamailio/presence-role.cfg index f079f85..ecfe2de 100644 --- a/kamailio/presence-role.cfg +++ b/kamailio/presence-role.cfg @@ -13,6 +13,24 @@ #!trydef KZ_PRESENCE_NO_TARGETS_LOG_LEVEL L_DBG #!trydef KZ_PRESENCE_WITH_TARGETS_LOG_LEVEL L_INFO #!trydef KZ_PRESENCE_REQUIRE_AUTHN 0 +#!trydef KZ_PRESENCE_KEEPALIVE_NAT_ONLY 0 +#!trydef KZ_PRESENCE_KEEPALIVE_UDP_ONLY 0 + + +#!ifdef NAT_TRAVERSAL_ROLE +#!ifndef KEEPALIVE_ROLE +#!ifndef NAT_TRAVERSAL_LOADED +#!trydef NAT_TRAVERSAL_LOADED +loadmodule "nat_traversal.so" +#!endif + +modparam("nat_traversal", "keepalive_method", "OPTIONS") +modparam("nat_traversal", "keepalive_from", "sip:sipcheck@MY_HOSTNAME") +modparam("nat_traversal", "keepalive_state_file", "KAZOO_DATA_DIR/keep_alive_state") +modparam("nat_traversal", "keepalive_interval", 45) +#!endif +#!endif + modparam("htable", "htable", "first=>size=32;autoexpire=3600;initval=0;") @@ -62,6 +80,8 @@ kazoo.presence_max_call_per_presentity = KZ_PRESENCE_MAX_CALL_PER_PRESENTITY des kazoo.presence_no_targets_log_level = KZ_PRESENCE_NO_TARGETS_LOG_LEVEL descr "when a presence event is received and there no targets we can log at another level" kazoo.presence_with_targets_log_level = KZ_PRESENCE_WITH_TARGETS_LOG_LEVEL descr "when a presence event is received and there are targets we can log at another level" kazoo.presence_require_authn = KZ_PRESENCE_REQUIRE_AUTHN descr "require authenticated devices for presence" +kazoo.presence_keepalive_udp_only = KZ_PRESENCE_KEEPALIVE_UDP_ONLY descr "should we send keepalive for udp only" +kazoo.presence_keepalive_nat_only = KZ_PRESENCE_KEEPALIVE_NAT_ONLY descr "should we send keepalive for nat phones only" #!include_file "presence-query.cfg" #!include_file "presence-notify.cfg" @@ -70,6 +90,20 @@ kazoo.presence_require_authn = KZ_PRESENCE_REQUIRE_AUTHN descr "require authenti ####### Presence Logic ######## +route[PRESENCE_NAT] +{ + if(!( ($sel(cfg_get.kazoo.presence_keepalive_udp_only) == 1 && $proto != "udp") + || (!isflagset(FLT_NATS) && $sel(cfg_get.kazoo.presence_keepalive_nat_only) == 1) + || ($proto == "ws" || $proto == "wss") + )) { + #!ifdef KEEPALIVE_ROLE + route(KEEPALIVE_ON_SUBSCRIBE); + #!else + nat_keepalive(); + #!endif + } +} + route[HANDLE_SUBSCRIBE] { if (!is_method("SUBSCRIBE")) { @@ -167,7 +201,7 @@ route[HANDLE_NEW_SUBSCRIBE] route(SUBSCRIBE_AMQP); route(REQUEST_PROBE); #!ifdef NAT_TRAVERSAL_ROLE - route(KEEPALIVE_ON_SUBSCRIBE); + route(PRESENCE_NAT); #!endif } else { xlog("L_INFO", "$ci|stop|error $T_reply_code for new $hdr(Event) subscription from $fU to $tU in realm $fd\n"); diff --git a/kamailio/registrar-role.cfg b/kamailio/registrar-role.cfg index e2c7c43..4876acc 100644 --- a/kamailio/registrar-role.cfg +++ b/kamailio/registrar-role.cfg @@ -1,8 +1,8 @@ #### NAT PINGING PARAMS ### -## NEXT 2 SHOULD GO TOGETHER -## REGISTRAR_NAT_PING_TIMEOUT should be (REGISTRAR_NAT_PING_INTERVAL * 3 + 10) or 0 to disable #!trydef REGISTRAR_NAT_PING_INTERVAL 30 -#!trydef REGISTRAR_NAT_PING_TIMEOUT 100 + +## REGISTRAR_NAT_PING_TIMEOUT should be (REGISTRAR_NAT_PING_INTERVAL * 3 + 10) or 0 to disable +#!trydef REGISTRAR_NAT_PING_TIMEOUT 0 #!trydef REGISTRAR_NAT_PING_NAT_ONLY 1 #!trydef REGISTRAR_NAT_PING_WORKERS 5 @@ -101,15 +101,15 @@ modparam("registrar", "contact_max_size", REGISTRAR_CONTACT_MAX_SIZE) loadmodule "nathelper.so" #!trydef NATHELPER_LOADED #!endif -#!ifdef KEEPALIVE_USE_NATHELPER +#!ifdef KEEPALIVE_ROLE +modparam("nathelper", "natping_interval", 0) +modparam("nathelper", "natping_processes", 0) +#!else modparam("nathelper", "natping_interval", REGISTRAR_NAT_PING_INTERVAL) modparam("nathelper", "ping_nated_only", REGISTRAR_NAT_PING_NAT_ONLY) modparam("nathelper", "natping_processes", REGISTRAR_NAT_PING_WORKERS) modparam("nathelper", "sipping_bflag", FLB_NATSIPPING) modparam("nathelper", "keepalive_timeout", REGISTRAR_NAT_PING_TIMEOUT) -#!else -modparam("nathelper", "natping_interval", 0) -modparam("nathelper", "natping_processes", 0) #!endif #!endif @@ -426,11 +426,9 @@ route[SAVE_LOCATION] route(PUSHER_ON_REGISTRATION); #!endif - #!ifdef NAT_TRAVERSAL_ROLE - #!ifndef KEEPALIVE_USE_NATHELPER + #!ifdef KEEPALIVE_ROLE route(KEEPALIVE_ON_REGISTRATION); #!endif - #!endif exit; } @@ -531,11 +529,9 @@ event_route[usrloc:contact-expired] route(PRESENCE_EXPIRED_REGISTRATION); #!endif - #!ifdef NAT_TRAVERSAL_ROLE - #!ifndef KEEPALIVE_USE_NATHELPER + #!ifdef KEEPALIVE_ROLE route(KEEPALIVE_ON_EXPIRED_REGISTRATION); #!endif - #!endif ## return until we handle this in ecallmr xlog("L_INFO", "$ulc(exp=>callid)|expired|removed registration for $ulc(exp=>aor) with contact : $ulc(exp=>addr)\n"); From 40eb110bb33c6c2bc448aae94b0fb3fc56dafd07 Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 19 Mar 2019 08:14:29 +0000 Subject: [PATCH 190/209] move block as role, rename keepalive script --- kamailio/{block.cfg => blocker-role.cfg} | 0 kamailio/default.cfg | 8 ++++---- kamailio/{keepalive.cfg => keepalive-role.cfg} | 0 3 files changed, 4 insertions(+), 4 deletions(-) rename kamailio/{block.cfg => blocker-role.cfg} (100%) rename kamailio/{keepalive.cfg => keepalive-role.cfg} (100%) diff --git a/kamailio/block.cfg b/kamailio/blocker-role.cfg similarity index 100% rename from kamailio/block.cfg rename to kamailio/blocker-role.cfg diff --git a/kamailio/default.cfg b/kamailio/default.cfg index 9e21478..9dacc05 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -268,15 +268,15 @@ include_file "nodes-role.cfg" include_file "sip_trace-role.cfg" #!endif #!ifdef KEEPALIVE_ROLE -include_file "keepalive.cfg" +include_file "keepalive-role.cfg" +#!endif +#!ifdef BLOCKER_ROLE +include_file "blocker-role.cfg" #!endif ## auth ## include_file "auth.cfg" -## block ## -include_file "block.cfg" - ####### Permissions module ########## loadmodule "permissions.so" modparam("permissions", "db_url", "KAZOO_DB_URL") diff --git a/kamailio/keepalive.cfg b/kamailio/keepalive-role.cfg similarity index 100% rename from kamailio/keepalive.cfg rename to kamailio/keepalive-role.cfg From d14cfe4f961e2fa7dd3cc2226d5e0a2a48341595 Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 19 Mar 2019 19:53:38 +0000 Subject: [PATCH 191/209] add Hotdesk-Current-ID and format --- kamailio/auth.cfg | 61 +++++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/kamailio/auth.cfg b/kamailio/auth.cfg index 4ba7e17..f69a322 100644 --- a/kamailio/auth.cfg +++ b/kamailio/auth.cfg @@ -64,36 +64,39 @@ route[AUTH_TOKEN] route[AUTH_CCVS] { - $xavp(regcfg=>match_received) = $su; - if (registered("location","$fu", 2, 1) == 1) { - if($(xavp(ulattrs=>custom_channel_vars){kz.json,Account-ID}{s.len}) > 0) - $xavp(hf[0]=>X-ecallmgr_Account-ID) = $(xavp(ulattrs=>custom_channel_vars){kz.json,Account-ID}); - - if($(xavp(ulattrs=>custom_channel_vars){kz.json,Authorizing-Type}{s.len}) > 0) - $xavp(hf[0]=>X-ecallmgr_Authorizing-Type) = $(xavp(ulattrs=>custom_channel_vars){kz.json,Authorizing-Type}); - - if($(xavp(ulattrs=>custom_channel_vars){kz.json,Authorizing-ID}{s.len}) > 0) - $xavp(hf[0]=>X-ecallmgr_Authorizing-ID) = $(xavp(ulattrs=>custom_channel_vars){kz.json,Authorizing-ID}); - - if($(xavp(ulattrs=>custom_channel_vars){kz.json,Username}{s.len}) > 0) - $xavp(hf[0]=>X-ecallmgr_Username) = $(xavp(ulattrs=>custom_channel_vars){kz.json,Username}); + $xavp(regcfg=>match_received) = $su; + if (registered("location","$fu", 2, 1) != 1) return; + + if($(xavp(ulattrs=>custom_channel_vars){kz.json,Account-ID}{s.len}) > 0) + $xavp(hf[0]=>X-ecallmgr_Account-ID) = $(xavp(ulattrs=>custom_channel_vars){kz.json,Account-ID}); + + if($(xavp(ulattrs=>custom_channel_vars){kz.json,Authorizing-Type}{s.len}) > 0) + $xavp(hf[0]=>X-ecallmgr_Authorizing-Type) = $(xavp(ulattrs=>custom_channel_vars){kz.json,Authorizing-Type}); + + if($(xavp(ulattrs=>custom_channel_vars){kz.json,Authorizing-ID}{s.len}) > 0) + $xavp(hf[0]=>X-ecallmgr_Authorizing-ID) = $(xavp(ulattrs=>custom_channel_vars){kz.json,Authorizing-ID}); + + if($(xavp(ulattrs=>custom_channel_vars){kz.json,Username}{s.len}) > 0) + $xavp(hf[0]=>X-ecallmgr_Username) = $(xavp(ulattrs=>custom_channel_vars){kz.json,Username}); + + if($(xavp(ulattrs=>custom_channel_vars){kz.json,Realm}{s.len}) > 0) + $xavp(hf[0]=>X-ecallmgr_Realm) = $(xavp(ulattrs=>custom_channel_vars){kz.json,Realm}); + + if($(xavp(ulattrs=>custom_channel_vars){kz.json,Account-Realm}{s.len}) > 0) + $xavp(hf[0]=>X-ecallmgr_Account-Realm) = $(xavp(ulattrs=>custom_channel_vars){kz.json,Account-Realm}); + + if($(xavp(ulattrs=>custom_channel_vars){kz.json,Account-Name}{s.len}) > 0) + $xavp(hf[0]=>X-ecallmgr_Account-Name) = $(xavp(ulattrs=>custom_channel_vars){kz.json,Account-Name}{s.escape.param}); + + if($(xavp(ulattrs=>custom_channel_vars){kz.json,Presence-ID}{s.len}) > 0) + $xavp(hf[0]=>X-ecallmgr_Presence-ID) = $(xavp(ulattrs=>custom_channel_vars){kz.json,Presence-ID}); + + if($(xavp(ulattrs=>custom_channel_vars){kz.json,Owner-ID}{s.len}) > 0) + $xavp(hf[0]=>X-ecallmgr_Owner-ID) = $(xavp(ulattrs=>custom_channel_vars){kz.json,Owner-ID}); + + if($(xavp(ulattrs=>custom_channel_vars){kz.json,Hotdesk-Current-ID}{s.len}) > 0) + $xavp(hf[0]=>X-ecallmgr_Hotdesk-Current-ID) = $(xavp(ulattrs=>custom_channel_vars){kz.json,Hotdesk-Current-ID}); - if($(xavp(ulattrs=>custom_channel_vars){kz.json,Realm}{s.len}) > 0) - $xavp(hf[0]=>X-ecallmgr_Realm) = $(xavp(ulattrs=>custom_channel_vars){kz.json,Realm}); - - if($(xavp(ulattrs=>custom_channel_vars){kz.json,Account-Realm}{s.len}) > 0) - $xavp(hf[0]=>X-ecallmgr_Account-Realm) = $(xavp(ulattrs=>custom_channel_vars){kz.json,Account-Realm}); - - if($(xavp(ulattrs=>custom_channel_vars){kz.json,Account-Name}{s.len}) > 0) - $xavp(hf[0]=>X-ecallmgr_Account-Name) = $(xavp(ulattrs=>custom_channel_vars){kz.json,Account-Name}{s.escape.param}); - - - if($(xavp(ulattrs=>custom_channel_vars){kz.json,Presence-ID}{s.len}) > 0) - $xavp(hf[0]=>X-ecallmgr_Presence-ID) = $(xavp(ulattrs=>custom_channel_vars){kz.json,Presence-ID}); - - if($(xavp(ulattrs=>custom_channel_vars){kz.json,Owner-ID}{s.len}) > 0) - $xavp(hf[0]=>X-ecallmgr_Owner-ID) = $(xavp(ulattrs=>custom_channel_vars){kz.json,Owner-ID}); - } } #!endif From 6dacb6a844e44b95746ae9b0e474bcd63e0dd6fe Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 19 Mar 2019 19:58:18 +0000 Subject: [PATCH 192/209] call status req --- kamailio/presence-fast-pickup.cfg | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kamailio/presence-fast-pickup.cfg b/kamailio/presence-fast-pickup.cfg index 39d780d..692a32e 100644 --- a/kamailio/presence-fast-pickup.cfg +++ b/kamailio/presence-fast-pickup.cfg @@ -130,11 +130,11 @@ route[PRESENCE_FAST_PICKUP_ATTEMPT] if($(ru{uri.user}) =~ $var(park_extension) && !($rd =~ "[0-9]{1,3}\.[0-9]{1,3}.[0-9]{1,3}\.[0-9]{1,3}") ) { xlog("L_INFO", "$ci|log|checking park request to $(ru{uri.user})@$(ru{uri.domain})\n"); $var(amqp_payload_request) = '{"Event-Category" : "call_event" , "Event-Name" : "query_user_channels_req", "Username" : "*3$(ru{uri.user}{s.substr,2,0})", "Realm" : "$(ru{uri.domain})", "Active-Only" : true }'; - $var(amqp_routing_key) = "call.status_req." + $(var(replaced_call_id){kz.encode}); + $var(amqp_routing_key) = "call.status_req." + $(ci{kz.encode}); if(kazoo_query("callevt", $var(amqp_routing_key), $var(amqp_payload_request))) { $du = $(kzR{kz.json,Channels[0].switch_url}); if($du != $null) { - xlog("L_INFO", "$ci|log|redirecting park request to $du, courtesy of kazoo\n"); + xlog("L_INFO", "$ci|log|redirecting park request to $du from realtime query reply\n"); route(RELAY); exit(); } From 520c6bbc5466a2d57200b7ed08f3525f0922b5dc Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 19 Mar 2019 20:01:36 +0000 Subject: [PATCH 193/209] less restrictive auth --- kamailio/registrar-role.cfg | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/kamailio/registrar-role.cfg b/kamailio/registrar-role.cfg index 4876acc..d79e36f 100644 --- a/kamailio/registrar-role.cfg +++ b/kamailio/registrar-role.cfg @@ -49,10 +49,6 @@ modparam("htable", "htable", "auth_cache=>size=16;autoexpire=7200;REGISTRAR_S_WA ####### Authentication Interface module ########## loadmodule "auth.so" -modparam("auth", "auth_checks_register", 11) -modparam("auth", "qop", "auth") -modparam("auth", "nonce_expire", 90) - ####### User Location Implementation module ########## loadmodule "usrloc.so" @@ -198,7 +194,7 @@ route[HANDLE_REGISTER] route(ANITFLOOD_FAILED_AUTH); #!endif update_stat("registrar:challenge", "+1"); - auth_challenge("$fd", "5"); + auth_challenge("$fd", "4"); exit; } else if($sht(auth_cache=>$Au) != $null) { $xavp(regcfg=>match_received) = $su; @@ -220,17 +216,11 @@ route[HANDLE_REGISTER] drop; } - if (!t_newtran()) { - xlog("L_ERROR", "$ci|log|failed to create transaction to query for authentication credentials for $Au $si:$sp\n"); - update_stat("registrar:new_tran", "+1"); - drop; - } - if($sel(cfg_get.kazoo.registrar_check_amqp_availability) == 1) { if($xavp(amqpc=>default::MY_AMQP_ZONE) == 0) { xlog("L_WARNING", "$ci|end|register|no amqp connection available for default worker in zone MY_AMQP_ZONE\n"); update_stat("registrar:amqp_not_available", "+1"); - t_drop(); + drop; } } @@ -239,15 +229,21 @@ route[HANDLE_REGISTER] $var(auth) = pv_auth_check("$fd", "$uuid(g)", "0", "0"); if($var(auth) != -2) { xlog("L_INFO", "$ci|end|challenging $Au $si:$sp\n"); - $var(auth) = auth_challenge("$fd", "21"); + $var(auth) = auth_challenge("$fd", "4"); update_stat("registrar:challenge", "+1"); if($var(auth) != 1) { xlog("L_ERROR", "$ci|register|error creating or sending challenge to registration attempt for $fu from $si:$sp\n"); - t_drop(); + drop; } exit; } + if (!t_newtran()) { + xlog("L_ERROR", "$ci|log|failed to create transaction to query for authentication credentials for $Au $si:$sp\n"); + update_stat("registrar:new_tran", "+1"); + drop; + } + if($sel(cfg_get.kazoo.registrar_send_100) == 1) { sl_send_reply("100", "checking your credentials"); } @@ -295,7 +291,7 @@ onreply_route[KZ_AUTHORIZATION_REPLY] route(ANITFLOOD_FAILED_AUTH); #!endif update_stat("registrar:challenge", "+1"); - auth_challenge("$fd", "5"); + auth_challenge("$fd", "4"); xlog("L_INFO", "$ci|end|challenging $Au $si:$sp via $(kzR{kz.json,App-Name})-$(kzR{kz.json,App-Version}) response\n"); exit; } else if( $(kzR{kz.json,Event-Name}) == "authn_resp" ) { From 4b1ae719eb953d1ea6aece57f4248b732a588e91 Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 20 Mar 2019 17:10:32 +0000 Subject: [PATCH 194/209] move sanity script --- kamailio/default.cfg | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kamailio/default.cfg b/kamailio/default.cfg index 9dacc05..bae74ba 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -212,9 +212,6 @@ include_file "db_KAMAILIO_DBMS.cfg" ###### kazoo bindings ###### include_file "kazoo-bindings.cfg" -## sanity ## -include_file "sanity.cfg" - ####### Role Configurations ########## #!ifdef AUTHORIZATION_ROLE include_file "authorization-role.cfg" @@ -274,6 +271,9 @@ include_file "keepalive-role.cfg" include_file "blocker-role.cfg" #!endif +## sanity ## +include_file "sanity.cfg" + ## auth ## include_file "auth.cfg" From 0616ddc508e15d26b18aa9a8d6a4b6ee9de136b1 Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 20 Mar 2019 17:11:10 +0000 Subject: [PATCH 195/209] allow trace failed sanity requests --- kamailio/sanity.cfg | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/kamailio/sanity.cfg b/kamailio/sanity.cfg index 287b0ec..92ba2fc 100644 --- a/kamailio/sanity.cfg +++ b/kamailio/sanity.cfg @@ -3,6 +3,7 @@ #!trydef SANITY_DROPS_REQUEST 1 #!trydef SANITY_DEFAULT_CHECK 17895 #!trydef SANITY_URI_CHECKS 7 +#!trydef SANITY_TRACE_REQUEST 1 #!substdef "!SANITY_SUBST_CACHE_PERIOD!$def(SANITY_CACHE_PERIOD)!g" @@ -17,6 +18,7 @@ modparam("debugger", "mod_level", "sanity=-3") kazoo.sanity_check_use_port = SANITY_CHECK_USE_PORT descr "should we keep track of ip and port for sanity failures" kazoo.sanity_drops_request = SANITY_DROPS_REQUEST descr "should we drop the request or send error on sanity failure" +kazoo.sanity_trace_request = SANITY_TRACE_REQUEST descr "should we trace the request if sip trace role is enabled" route[SANITY_CHECK] { @@ -34,6 +36,9 @@ route[SANITY_CHECK] } if (!sanity_check()) { + #!ifdef SIP_TRACE_ROLE + sip_trace(); + #!endif if($sel(cfg_get.kazoo.sanity_drops_request) == 1) { xlog("L_WARN", "$ci|end|dropping insane message from $si:$sp\n"); drop; From 4dfd03bb565aeb10df40cee3282745829692766e Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 20 Mar 2019 23:06:19 +0000 Subject: [PATCH 196/209] blocker is a role, no needed for define --- kamailio/blocker-role.cfg | 4 ---- 1 file changed, 4 deletions(-) diff --git a/kamailio/blocker-role.cfg b/kamailio/blocker-role.cfg index 0b74219..8da3adf 100644 --- a/kamailio/blocker-role.cfg +++ b/kamailio/blocker-role.cfg @@ -1,7 +1,5 @@ ######## BLOCK BY IP[PORT] ######## -#!ifndef KZ_BLOCK_DISABLE - #!trydef KZ_BLOCK_ENABLE 1 #!trydef KZ_BLOCK_LOG_LEVEL 1 #!trydef KZ_BLOCK_LOG_BUFFER 0 @@ -39,5 +37,3 @@ event_route[core:msg-received] } } } - -#!endif From 13df967a6dd650a0e48496d4cddadce05dd37d4a Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 20 Mar 2019 23:07:10 +0000 Subject: [PATCH 197/209] fix antiflood rate log --- kamailio/antiflood-role.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kamailio/antiflood-role.cfg b/kamailio/antiflood-role.cfg index edb0455..3a98318 100644 --- a/kamailio/antiflood-role.cfg +++ b/kamailio/antiflood-role.cfg @@ -52,7 +52,7 @@ route[ANTIFLOOD_RATE_LIMIT] xlog("L_WARN", "$ci|end|dropping request from $fu due to rate of requests with source $si:$sp\n"); drop(); } else { - xlog("L_WARN", "$ci|end|request from $fu exceeded rate of requests with source $si:$sp\n"); + xlog("L_WARN", "$ci|allowed|request from $fu exceeded rate of requests with source $si:$sp\n"); } } } From 963e9b4251b72062e700bd91c6b826f2adcd1018 Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 9 Apr 2019 21:45:07 +0000 Subject: [PATCH 198/209] check event_list diff --- kamailio/db_scripts/check-kazoodb-sql.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/kamailio/db_scripts/check-kazoodb-sql.sh b/kamailio/db_scripts/check-kazoodb-sql.sh index 80d0955..4ff700a 100755 --- a/kamailio/db_scripts/check-kazoodb-sql.sh +++ b/kamailio/db_scripts/check-kazoodb-sql.sh @@ -19,6 +19,7 @@ if [[ $DB_CURRENT_VERSION -ne $DB_VERSION ]]; then echo "db required version is ${DB_VERSION}, existing version is ${DB_CURRENT_VERSION}, applying diff" KazooDB-diff --schema ${DB_CURRENT_DB} ${TEMP_DB} | KazooDB -db ${DB_CURRENT_DB} KazooDB-diff --primarykey --table version ${DB_CURRENT_DB} ${TEMP_DB} | KazooDB -db ${DB_CURRENT_DB} + KazooDB-diff --primarykey --table event_list ${DB_CURRENT_DB} ${TEMP_DB} | KazooDB -db ${DB_CURRENT_DB} fi From 23874d56833c61a1c112079ebe3298243978bc10 Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 9 Apr 2019 21:45:49 +0000 Subject: [PATCH 199/209] add X-AUTH-Token from CCVs --- kamailio/auth.cfg | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/kamailio/auth.cfg b/kamailio/auth.cfg index f69a322..aca5bec 100644 --- a/kamailio/auth.cfg +++ b/kamailio/auth.cfg @@ -56,7 +56,7 @@ route[AUTH_TOKEN] $xavp(hf[0]=>X-AUTH-Token) = $xavp(ulattrs=>token); } else { if($(xavp(ulattrs=>Authorizing-ID){s.len}) > 0 && $(xavp(ulattrs=>Account-ID){s.len})) { - $xavp(hf[0]=>X-AUTH-Token) = $_s("$xavp(ulattrs=>Authorizing-ID)@$xavp(ulattrs=>Account-ID)"); + $xavp(hf[0]=>X-AUTH-Token) = $_s($(xavp(ulattrs=>custom_channel_vars){kz.json,Authorizing-ID})@$(xavp(ulattrs=>custom_channel_vars){kz.json,Account-ID})); } } } @@ -66,34 +66,37 @@ route[AUTH_CCVS] { $xavp(regcfg=>match_received) = $su; if (registered("location","$fu", 2, 1) != 1) return; - + if($(xavp(ulattrs=>custom_channel_vars){kz.json,Account-ID}{s.len}) > 0) $xavp(hf[0]=>X-ecallmgr_Account-ID) = $(xavp(ulattrs=>custom_channel_vars){kz.json,Account-ID}); - + if($(xavp(ulattrs=>custom_channel_vars){kz.json,Authorizing-Type}{s.len}) > 0) $xavp(hf[0]=>X-ecallmgr_Authorizing-Type) = $(xavp(ulattrs=>custom_channel_vars){kz.json,Authorizing-Type}); - + + if($(xavp(ulattrs=>custom_channel_vars){kz.json,Account-ID}{s.len}) > 0 && $(xavp(ulattrs=>custom_channel_vars){kz.json,Authorizing-Type}{s.len}) > 0) + $xavp(hf[0]=>X-AUTH-Token) = $_s($(xavp(ulattrs=>custom_channel_vars){kz.json,Authorizing-ID})@$(xavp(ulattrs=>custom_channel_vars){kz.json,Account-ID})); + if($(xavp(ulattrs=>custom_channel_vars){kz.json,Authorizing-ID}{s.len}) > 0) $xavp(hf[0]=>X-ecallmgr_Authorizing-ID) = $(xavp(ulattrs=>custom_channel_vars){kz.json,Authorizing-ID}); - + if($(xavp(ulattrs=>custom_channel_vars){kz.json,Username}{s.len}) > 0) $xavp(hf[0]=>X-ecallmgr_Username) = $(xavp(ulattrs=>custom_channel_vars){kz.json,Username}); - + if($(xavp(ulattrs=>custom_channel_vars){kz.json,Realm}{s.len}) > 0) $xavp(hf[0]=>X-ecallmgr_Realm) = $(xavp(ulattrs=>custom_channel_vars){kz.json,Realm}); - + if($(xavp(ulattrs=>custom_channel_vars){kz.json,Account-Realm}{s.len}) > 0) $xavp(hf[0]=>X-ecallmgr_Account-Realm) = $(xavp(ulattrs=>custom_channel_vars){kz.json,Account-Realm}); - + if($(xavp(ulattrs=>custom_channel_vars){kz.json,Account-Name}{s.len}) > 0) $xavp(hf[0]=>X-ecallmgr_Account-Name) = $(xavp(ulattrs=>custom_channel_vars){kz.json,Account-Name}{s.escape.param}); - + if($(xavp(ulattrs=>custom_channel_vars){kz.json,Presence-ID}{s.len}) > 0) $xavp(hf[0]=>X-ecallmgr_Presence-ID) = $(xavp(ulattrs=>custom_channel_vars){kz.json,Presence-ID}); - + if($(xavp(ulattrs=>custom_channel_vars){kz.json,Owner-ID}{s.len}) > 0) $xavp(hf[0]=>X-ecallmgr_Owner-ID) = $(xavp(ulattrs=>custom_channel_vars){kz.json,Owner-ID}); - + if($(xavp(ulattrs=>custom_channel_vars){kz.json,Hotdesk-Current-ID}{s.len}) > 0) $xavp(hf[0]=>X-ecallmgr_Hotdesk-Current-ID) = $(xavp(ulattrs=>custom_channel_vars){kz.json,Hotdesk-Current-ID}); From b7637d75104579964d6ac2da21482637cdc9509c Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 9 Apr 2019 21:46:34 +0000 Subject: [PATCH 200/209] change reparse_on_dns_failover default on tm module --- kamailio/default.cfg | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kamailio/default.cfg b/kamailio/default.cfg index bae74ba..22b2f47 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -136,6 +136,8 @@ modparam("tm", "cancel_b_method", 2) modparam("tm", "ruri_matching", 0) modparam("tm", "failure_reply_mode", 3) modparam("tm", "failure_exec_mode", 1) +modparam("tm", "reparse_on_dns_failover", 0) + # modparam("tm", "fr_timer", 30000) # modparam("tm", "fr_inv_timer", 120000) From dbd34fac026728ea80e527c27680e65c737b194b Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 9 Apr 2019 21:47:20 +0000 Subject: [PATCH 201/209] add REFER handling --- kamailio/default.cfg | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/kamailio/default.cfg b/kamailio/default.cfg index 22b2f47..72b12a7 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -344,6 +344,8 @@ route route(HANDLE_REGISTER); #!endif + route(HANDLE_REFER); + route(HANDLE_IN_DIALOG_REQUESTS); route(PREPARE_INITIAL_REQUESTS); @@ -526,6 +528,26 @@ route[HANDLE_MESSAGE] #!endif } +route[HANDLE_REFER] +{ + if (!is_method("REFER")) { + return; + } + + if(is_present_hf("Referred-By")) { + $var(referred_by) = $hdr(Referred-By); + } else { + $var(referred_by) = $_s(;created=true); + } + $xavp(regcfg=>match_received) = $su; + if(registered("location", "$rz:$Au", 2, 1) == 1) { + $var(referred_by) = $_s($var(referred_by);endpoint_id=$(xavp(ulattrs=>token){re.subst,/(.*)@(.*)/\1/});account_id=$(xavp(ulattrs=>token){re.subst,/(.*)@(.*)/\2/})); + } + + remove_hf_re("^Referred-By"); + append_hf("Referred-By: $var(referred_by)\r\n"); + +} route[HANDLE_IN_DIALOG_REQUESTS] { From 95c6add4e9b1c3caadb54d0c75f4d15c0ec1d3cb Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 9 Apr 2019 21:49:28 +0000 Subject: [PATCH 202/209] websockets defaults * libwebphone related --- kamailio/registrar-role.cfg | 3 +-- kamailio/websockets-role.cfg | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/kamailio/registrar-role.cfg b/kamailio/registrar-role.cfg index d79e36f..172d581 100644 --- a/kamailio/registrar-role.cfg +++ b/kamailio/registrar-role.cfg @@ -17,7 +17,7 @@ #!trydef REGISTRAR_QUERY_TIMEOUT_MS 2500 #!trydef REGISTRAR_HANDLE_LOST_TCP 1 -#!trydef REGISTRAR_CLOSE_EXPIRED_TCP 1 +#!trydef REGISTRAR_CLOSE_EXPIRED_TCP 0 #!trydef REGISTRAR_HANDLE_EXPIRED_TCP 1 #!trydef REGISTRAR_HANDLE_EXPIRED_UDP 0 #!trydef REGISTRAR_HANDLE_EXPIRED_TLS 1 @@ -32,7 +32,6 @@ #!trydef REGISTRAR_SEND_100 1 #!trydef REGISTRAR_DB_MODE 2 #!trydef REGISTRAR_DB_TIMER_CLEANUP 0 -#!trydef REGISTRAR_HANDLE_LOST_TCP 0 #!trydef REGISTRAR_DB_REMOVE_EXPIRED_DELAY 0 #!trydef REGISTRAR_SYNC_TIMER_INTERVAL 5 #!trydef REGISTRAR_SYNC_TIMER_PROCS 1 diff --git a/kamailio/websockets-role.cfg b/kamailio/websockets-role.cfg index df0c3e7..2c8b77b 100644 --- a/kamailio/websockets-role.cfg +++ b/kamailio/websockets-role.cfg @@ -18,7 +18,7 @@ modparam("htable", "htable", "websockets=>size=16;initval=0") loadmodule "xhttp.so" -#!trydef WS_KEEPALIVE_MECHANISM 1 +#!trydef WS_KEEPALIVE_MECHANISM 0 #!trydef WS_KEEPALIVE_TIMEOUT 30 #!trydef WS_KEEPALIVE_PROCESSES 3 #!trydef WS_KEEPALIVE_INTERVAL 1 From 641f0f2f16e83af118ab4a699fbf7c4d2f67af25 Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 9 Apr 2019 21:49:50 +0000 Subject: [PATCH 203/209] formatting --- kamailio/registrar-role.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kamailio/registrar-role.cfg b/kamailio/registrar-role.cfg index 172d581..52952be 100644 --- a/kamailio/registrar-role.cfg +++ b/kamailio/registrar-role.cfg @@ -211,7 +211,7 @@ route[HANDLE_REGISTER] if($td =~ "[0-9]{1,3}\.[0-9]{1,3}.[0-9]{1,3}\.[0-9]{1,3}" || $fd =~ "[0-9]{1,3}\.[0-9]{1,3}.[0-9]{1,3}\.[0-9]{1,3}") { xlog("L_INFO", "$ci|log|register|invalid domain\n"); - update_stat("registrar:ip_realm", "+1"); + update_stat("registrar:ip_realm", "+1"); drop; } From 46e308c20e050e6ec1163f72c00226d5412ba1af Mon Sep 17 00:00:00 2001 From: lazedo Date: Mon, 15 Apr 2019 13:47:51 +0000 Subject: [PATCH 204/209] check if result of iproute is ip address --- system/sbin/kazoo-kamailio | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/system/sbin/kazoo-kamailio b/system/sbin/kazoo-kamailio index ff533a9..63b2a66 100755 --- a/system/sbin/kazoo-kamailio +++ b/system/sbin/kazoo-kamailio @@ -12,6 +12,24 @@ if [ -f /etc/kazoo/kamailio/options ]; then . /etc/kazoo/kamailio/options fi +is_ipaddress () +{ +if [ $(echo $1 | grep -o '\.' | wc -l) -ne 3 ]; then + return 1 +elif [ $(echo $1 | tr '.' ' ' | wc -w) -ne 4 ]; then + return 1 +else + for OCTET in $(echo $1 | tr '.' ' '); do + if ! [[ $OCTET =~ ^[0-9]+$ ]]; then + return 1 + elif [[ $OCTET -lt 0 || $OCTET -gt 255 ]]; then + return 1 + fi + done +fi +return 0 +} + RETVAL=1 USER=${KAMAILIO_USER:-kamailio} GROUP=${KAMAILIO_GROUP:-daemon} @@ -29,7 +47,7 @@ RAM_DISK_ENABLED=${RAM_DISK_ENABLED:-false} EXTRA_OPTIONS=${EXTRA_OPTIONS:-"-x tlsf -w /tmp"} MY_LOCAL_IP=$(ip route get 8.8.8.8 2> /dev/null | awk '{print ""$NF""; exit}') -if [[ ! -z ${MY_LOCAL_IP} ]]; then +if is_ipaddress ${MY_LOCAL_IP}; then EXTRA_OPTIONS+=" -A MY_LOCAL_IP=${MY_LOCAL_IP}" fi From b3d5a86aff1bcb319325b70f959dea72b6b66150 Mon Sep 17 00:00:00 2001 From: lazedo Date: Mon, 15 Apr 2019 14:43:43 +0000 Subject: [PATCH 205/209] use column 7 --- system/sbin/kazoo-kamailio | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/sbin/kazoo-kamailio b/system/sbin/kazoo-kamailio index 63b2a66..23321be 100755 --- a/system/sbin/kazoo-kamailio +++ b/system/sbin/kazoo-kamailio @@ -46,7 +46,7 @@ RAM_DISK_FREE_SIZE_PERC=${RAM_DISK_FREE_SIZE:-30} RAM_DISK_ENABLED=${RAM_DISK_ENABLED:-false} EXTRA_OPTIONS=${EXTRA_OPTIONS:-"-x tlsf -w /tmp"} -MY_LOCAL_IP=$(ip route get 8.8.8.8 2> /dev/null | awk '{print ""$NF""; exit}') +MY_LOCAL_IP=$(ip route get 8.8.8.8 2> /dev/null | awk '{print ""$7""; exit}') if is_ipaddress ${MY_LOCAL_IP}; then EXTRA_OPTIONS+=" -A MY_LOCAL_IP=${MY_LOCAL_IP}" fi From 01bdfe636d0b8ef5d0ea0d9ed85fb94c9a81a91e Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 16 Apr 2019 08:58:25 +0000 Subject: [PATCH 206/209] change column order to use indexes * also change self to use "union all" --- kamailio/db_queries_kazoo.cfg | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kamailio/db_queries_kazoo.cfg b/kamailio/db_queries_kazoo.cfg index 41f5f4d..745898b 100644 --- a/kamailio/db_queries_kazoo.cfg +++ b/kamailio/db_queries_kazoo.cfg @@ -3,11 +3,12 @@ #!substdef "!KZQ_COUNT_ALL_SUBSCRIBERS!select a.event, count(distinct watcher_uri) count_unique, count(*) count from event_list a left outer join active_watchers b on a.event = b.event group by a.event!g" #!substdef "!KZQ_COUNT_PRESENTITIES!select event, (select count(*) from presentity b where username = \"\$(var(payload){kz.json,From}{uri.user})\" and domain = \"\$(var(payload){kz.json,From}{uri.domain})\" and b.event = a.event) count from event_list a!g" -#!substdef "!KZQ_COUNT_SUBSCRIBERS!select event, (select count(*) from active_watchers b where presentity_uri = \"\$var(presentity)\" and b.event = a.event) count from event_list a union select \"self\", count(distinct callid) from presentities where presentity_uri = \"\$var(presentity)\" and state in('early', 'confirmed', 'onthephone', 'busy')!g" +#!substdef "!KZQ_COUNT_SUBSCRIBERS!select event, (select count(*) from active_watchers b where presentity_uri = \"\$var(presentity)\" and b.event = a.event) count from event_list a union all select \"self\", count(distinct callid) from presentities where presentity_uri = \"\$var(presentity)\" and callid <> \"\$var(callid)\" and state in('early', 'confirmed', 'onthephone', 'busy')!g" +#!substdef "!KZQ_FETCH_PRESENCE!select * from presentities where presentity_uri = \"\$var(presentity)\" and event = \"presence\"!g" #!substdef "!KZQ_EVENT_PRESENCE_RESET_DELETE!delete from presentity where domain=\"\$(kzE{kz.json,Realm})\" and username = \"\$(kzE{kz.json,Username})\"!g" #!substdef "!KZQ_HANDLE_NEW_SUBSCRIBE_DELETE1!delete from active_watchers where callid = \"\$ci\"!g" -#!substdef "!KZQ_HANDLE_NEW_SUBSCRIBE_DELETE2!delete from active_watchers where watcher_username=\"\$fU\" and presentity_uri=\"\$var(presentity_uri)\" and to_user=\"\$tU\" and watcher_domain=\"\$fd\" and event=\"\$hdr(Event)\"!g" +#!substdef "!KZQ_HANDLE_NEW_SUBSCRIBE_DELETE2!delete from active_watchers where presentity_uri=\"\$var(presentity_uri)\" and event=\"\$hdr(Event)\" and watcher_username=\"\$fU\" and to_user=\"\$tU\" and watcher_domain=\"\$fd\"!g" #!substdef "!KZQ_PRESENCE_SEARCH_SUMMARY!select * from active_watchers where to_domain = \"\$var(Domain)\"!g" #!substdef "!KZQ_PRESENCE_SEARCH_DETAIL!select a.*, b.time, b.result, b.sent_msg, b.received_msg from active_watchers a left outer join active_watchers_log b on a.presentity_uri = b.presentity_uri and a.event = b.event and a.callid = b.callid where a.presentity_uri = \"\$var(presentity_uri)\" !g" From ca139058535ecac04d5ee96b6467909bea9298fb Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 16 Apr 2019 09:02:18 +0000 Subject: [PATCH 207/209] handle state for presence event * unlike dialog, presence is not aggregated with state handling, we need to do it here. --- kamailio/presence-role.cfg | 54 +++++++++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 10 deletions(-) diff --git a/kamailio/presence-role.cfg b/kamailio/presence-role.cfg index ecfe2de..89088a2 100644 --- a/kamailio/presence-role.cfg +++ b/kamailio/presence-role.cfg @@ -144,7 +144,7 @@ route[HANDLE_SUBSCRIBE] route[DELETE_DUPLICATED_SUBSCRIPTIONS] { - sql_query("exec", '$_s(DELETE FROM ACTIVE_WATCHERS WHERE FROM_USER = "$subs(from_user)" AND FROM_DOMAIN="$subs(from_domain)" AND EVENT="$subs(event)" AND PRESENTITY_URI="$subs(uri)" AND CALLID <> "$subs(callid)")'); + sql_query("exec", '$_s(DELETE FROM ACTIVE_WATCHERS WHERE PRESENTITY_URI="$subs(uri)" AND EVENT="$subs(event)" AND FROM_USER = "$subs(from_user)" AND FROM_DOMAIN="$subs(from_domain)" AND CALLID <> "$subs(callid)")'); } route[HANDLE_RESUBSCRIBE] @@ -355,6 +355,21 @@ route[COUNT_SUBSCRIBERS] xavp_params_explode($var(p), "watchers"); } +route[PRESENCE_STATE] +{ + $var(state) = ""; + if($(var(payload){kz.json,State}) == "terminated") { + $var(state) = "available"; + } else if($(var(payload){kz.json,State}) == "early") { + $var(state) = "busy"; + } else if($(var(payload){kz.json,State}) == "confirmed") { + $var(state) = "onthephone"; + } + + $var(Query) = $_s(KZQ_FETCH_PRESENCE); + sql_xquery("cb", "$var(Query)", "presence"); +} + event_route[kazoo:consumer-event-presence-dialog-update] { $var(kz_presence_log_level) = $(sel(cfg_get.kazoo.presence_no_targets_log_level){s.int}); @@ -443,6 +458,7 @@ event_route[kazoo:consumer-event-presence-update] route[PRESENCE_UPDATE] { + $var(callid) = $(var(payload){kz.json,Call-ID}); if($(var(payload){kz.json,State}) == "terminated") { route(COUNT_PRESENTITIES); } else { @@ -482,18 +498,36 @@ route[PRESENCE_UPDATE] } if($xavp(watchers=>presence) > 0) { - $var(kz_presence_log_level) = $(sel(cfg_get.kazoo.presence_with_targets_log_level){s.int}); - xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|publishing $var(presentity) presence update for $xavp(watchers=>presence) watchers\n"); - kazoo_pua_publish_presence($var(payload)); - pres_refresh_watchers("$var(presentity)", "presence", 1); + route(PRESENCE_STATE); + xlog("L_DEBUG", "presence state => $(var(payload){kz.json,Call-ID})|log|$xavp(presence=>callid) , $var(callid), $xavp(presence=>state), $var(state)\n"); + if($xavp(presence=>callid) == $var(callid) + || $var(state) == "onthephone" + || ($var(state) == "busy" && $xavp(presence=>state) != "onthephone") + ) { + + $var(kz_presence_log_level) = $(sel(cfg_get.kazoo.presence_with_targets_log_level){s.int}); + xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|publishing $var(presentity) presence update for $xavp(watchers=>presence) watchers\n"); + if(kazoo_pua_publish_presence($var(JObj)) == 1) { + pres_refresh_watchers("$var(presentity)", "presence", 1); + } else { + xlog("L_ERR", "$(var(payload){kz.json,Call-ID})|log|error publishing $var(presentity) presence update\n"); + }; + } } else { #!ifdef PRESENCE_TRACK_ALL_PKG_PRESENCE if($(kzE{kz.json,Event-Package}) == "presence") { - $var(kz_presence_log_level) = $(sel(cfg_get.kazoo.presence_with_targets_log_level){s.int}); - xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|saving $var(presentity) from presence update => $var(payload)\n"); - if(kazoo_pua_publish_presence($var(JObj)) != 1) { - xlog("L_ERR", "$(var(payload){kz.json,Call-ID})|log|error publishing $var(presentity) presence update => $var(payload)\n"); - } + route(PRESENCE_STATE); + xlog("L_DEBUG", "presence state => $(var(payload){kz.json,Call-ID})|log|$xavp(presence=>callid) , $var(callid), $xavp(presence=>state), $var(state)\n"); + if($xavp(presence=>callid) == $var(callid) + || $var(state) == "onthephone" + || ($var(state) == "busy" && $xavp(presence=>state) != "onthephone") + ) { + $var(kz_presence_log_level) = $(sel(cfg_get.kazoo.presence_with_targets_log_level){s.int}); + xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|saving $var(presentity) from presence update => $var(payload)\n"); + if(kazoo_pua_publish_presence($var(JObj)) != 1) { + xlog("L_ERR", "$(var(payload){kz.json,Call-ID})|log|error publishing $var(presentity) presence update => $var(payload)\n"); + } + } } #!else xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|skip presence update for $var(presentity)\n"); From 247fc9390f4b7e64547478dc7d2695d092f4a77f Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 18 Apr 2019 00:47:00 +0000 Subject: [PATCH 208/209] update presence handling --- kamailio/db_queries_kazoo.cfg | 9 +++--- kamailio/presence-role.cfg | 54 +++++++++-------------------------- 2 files changed, 18 insertions(+), 45 deletions(-) diff --git a/kamailio/db_queries_kazoo.cfg b/kamailio/db_queries_kazoo.cfg index 745898b..f3de127 100644 --- a/kamailio/db_queries_kazoo.cfg +++ b/kamailio/db_queries_kazoo.cfg @@ -3,8 +3,7 @@ #!substdef "!KZQ_COUNT_ALL_SUBSCRIBERS!select a.event, count(distinct watcher_uri) count_unique, count(*) count from event_list a left outer join active_watchers b on a.event = b.event group by a.event!g" #!substdef "!KZQ_COUNT_PRESENTITIES!select event, (select count(*) from presentity b where username = \"\$(var(payload){kz.json,From}{uri.user})\" and domain = \"\$(var(payload){kz.json,From}{uri.domain})\" and b.event = a.event) count from event_list a!g" -#!substdef "!KZQ_COUNT_SUBSCRIBERS!select event, (select count(*) from active_watchers b where presentity_uri = \"\$var(presentity)\" and b.event = a.event) count from event_list a union all select \"self\", count(distinct callid) from presentities where presentity_uri = \"\$var(presentity)\" and callid <> \"\$var(callid)\" and state in('early', 'confirmed', 'onthephone', 'busy')!g" -#!substdef "!KZQ_FETCH_PRESENCE!select * from presentities where presentity_uri = \"\$var(presentity)\" and event = \"presence\"!g" +#!substdef "!KZQ_COUNT_SUBSCRIBERS!select event, (select count(*) from active_watchers b where presentity_uri = \"\$var(presentity)\" and b.event = a.event) count from event_list a union all select \"self\", count(distinct callid) from presentities where presentity_uri = \"\$var(presentity)\" and callid <> \"\$var(callid)\" and state in('early', 'confirmed', 'onthephone', 'busy', 'ringing')!g" #!substdef "!KZQ_EVENT_PRESENCE_RESET_DELETE!delete from presentity where domain=\"\$(kzE{kz.json,Realm})\" and username = \"\$(kzE{kz.json,Username})\"!g" #!substdef "!KZQ_HANDLE_NEW_SUBSCRIBE_DELETE1!delete from active_watchers where callid = \"\$ci\"!g" @@ -17,12 +16,12 @@ #!substdef "!KZQ_REPLACE_WATCHERS_LOG!REPLACE INTO active_watchers_log (presentity_uri, watcher_username, watcher_domain, event, callid, to_user, to_domain, user_agent, time, result, sent_msg, received_msg) VALUES (\"\$subs(uri)\", \"\$subs(watcher_username)\", \"\$subs(watcher_domain)\", \"\$subs(event)\",\"\$subs(callid)\",\"\$subs(to_user)\",\"\$subs(to_domain)\", '\$(subs(user_agent){s.escape.common}{s.replace,\\\',''}{s.replace,\$\$,})', \$TS, \$notify_reply(\$rs), '\$(mb{s.escape.common}{s.replace,\\\',''}{s.replace,\$\$,})', '\$(notify_reply(\$mb){s.escape.common}{s.replace,\\\',''}{s.replace,\$\$,})')!g" # # #!substdef "!KZQ_RESET_PUBLISHER_UPDATE!update active_watchers set expires = \$TS where id in (select b.id from presentity a inner join active_watchers b on a.username = b.to_user and a.domain = b.to_domain and a.event = b.event where a.sender = \"\$var(MediaUrl)\")!g" -#!substdef "!KZQ_RESET_PUBLISHER_UPDATE!INSERT INTO tmp_probe select distinct a.event, a.presentity_uri, 0 from presentities a inner join active_watchers b on a.presentity_uri = b.presentity_uri and a.event = b.event where sender = \"\$var(MediaUrl)\" and state in('early', 'confirmed', 'onthephone', 'busy')!g" +#!substdef "!KZQ_RESET_PUBLISHER_UPDATE!INSERT INTO tmp_probe select distinct a.event, a.presentity_uri, 0 from presentities a inner join active_watchers b on a.presentity_uri = b.presentity_uri and a.event = b.event where sender = \"\$var(MediaUrl)\" and state in('early', 'confirmed', 'onthephone', 'busy', 'ringing')!g" #!substdef "!KZQ_PRESENCE_RESET!delete from presentity where sender = \"\$var(MediaUrl)\"!g" # # #!substdef "!KZQ_RESET_ACCOUNT_UPDATE!update active_watchers set expires = \$TS where watcher_domain=\"\$(kzE{kz.json,Realm})\"!g" -#!substdef "!KZQ_RESET_ACCOUNT_UPDATE!INSERT INTO tmp_probe select distinct a.event, a.presentity_uri, 0 from presentities a inner join active_watchers b on a.presentity_uri = b.presentity_uri and a.event = b.event where domain=\"\$(kzE{kz.json,Realm})\" and state in('early', 'confirmed', 'onthephone', 'busy')!g" +#!substdef "!KZQ_RESET_ACCOUNT_UPDATE!INSERT INTO tmp_probe select distinct a.event, a.presentity_uri, 0 from presentities a inner join active_watchers b on a.presentity_uri = b.presentity_uri and a.event = b.event where domain=\"\$(kzE{kz.json,Realm})\" and state in('early', 'confirmed', 'onthephone', 'busy', 'ringing')!g" #!substdef "!KZQ_RESET_ACCOUNT_RESET!delete from presentity where domain=\"\$(kzE{kz.json,Realm})\"!g" -#!substdef "!KZQ_RESET_PUBLISHER_ZONE_UPDATE!INSERT INTO tmp_probe select distinct a.event, a.presentity_uri, 0 from presentities a inner join wdispatcher c on a.sender = c.destination inner join active_watchers b on a.presentity_uri = b.presentity_uri and a.event = b.event where zone = \"\$var(Zone)\" and state in('early', 'confirmed', 'onthephone', 'busy')!g" +#!substdef "!KZQ_RESET_PUBLISHER_ZONE_UPDATE!INSERT INTO tmp_probe select distinct a.event, a.presentity_uri, 0 from presentities a inner join wdispatcher c on a.sender = c.destination inner join active_watchers b on a.presentity_uri = b.presentity_uri and a.event = b.event where zone = \"\$var(Zone)\" and state in('early', 'confirmed', 'onthephone', 'busy', 'ringing')!g" #!substdef "!KZQ_PRESENCE_ZONE_RESET!delete from presentity where id in(select a.id from presentities a join wdispatcher c on a.sender = c.destination where zone = \"\$var(Zone)\")!g" diff --git a/kamailio/presence-role.cfg b/kamailio/presence-role.cfg index 89088a2..e7e4815 100644 --- a/kamailio/presence-role.cfg +++ b/kamailio/presence-role.cfg @@ -355,21 +355,6 @@ route[COUNT_SUBSCRIBERS] xavp_params_explode($var(p), "watchers"); } -route[PRESENCE_STATE] -{ - $var(state) = ""; - if($(var(payload){kz.json,State}) == "terminated") { - $var(state) = "available"; - } else if($(var(payload){kz.json,State}) == "early") { - $var(state) = "busy"; - } else if($(var(payload){kz.json,State}) == "confirmed") { - $var(state) = "onthephone"; - } - - $var(Query) = $_s(KZQ_FETCH_PRESENCE); - sql_xquery("cb", "$var(Query)", "presence"); -} - event_route[kazoo:consumer-event-presence-dialog-update] { $var(kz_presence_log_level) = $(sel(cfg_get.kazoo.presence_no_targets_log_level){s.int}); @@ -498,36 +483,25 @@ route[PRESENCE_UPDATE] } if($xavp(watchers=>presence) > 0) { - route(PRESENCE_STATE); - xlog("L_DEBUG", "presence state => $(var(payload){kz.json,Call-ID})|log|$xavp(presence=>callid) , $var(callid), $xavp(presence=>state), $var(state)\n"); - if($xavp(presence=>callid) == $var(callid) - || $var(state) == "onthephone" - || ($var(state) == "busy" && $xavp(presence=>state) != "onthephone") - ) { - - $var(kz_presence_log_level) = $(sel(cfg_get.kazoo.presence_with_targets_log_level){s.int}); + $var(kz_presence_log_level) = $(sel(cfg_get.kazoo.presence_with_targets_log_level){s.int}); + if($(var(payload){kz.json,State}) == "terminated") { + xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|publishing $var(presentity) presence update for terminated dialog\n"); + } else { xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|publishing $var(presentity) presence update for $xavp(watchers=>presence) watchers\n"); - if(kazoo_pua_publish_presence($var(JObj)) == 1) { - pres_refresh_watchers("$var(presentity)", "presence", 1); - } else { - xlog("L_ERR", "$(var(payload){kz.json,Call-ID})|log|error publishing $var(presentity) presence update\n"); - }; } + if(kazoo_pua_publish_presence($var(JObj)) == 1) { + pres_refresh_watchers("$var(presentity)", "presence", 1); + } else { + xlog("L_ERR", "$(var(payload){kz.json,Call-ID})|log|error publishing $var(presentity) presence update\n"); + }; } else { #!ifdef PRESENCE_TRACK_ALL_PKG_PRESENCE if($(kzE{kz.json,Event-Package}) == "presence") { - route(PRESENCE_STATE); - xlog("L_DEBUG", "presence state => $(var(payload){kz.json,Call-ID})|log|$xavp(presence=>callid) , $var(callid), $xavp(presence=>state), $var(state)\n"); - if($xavp(presence=>callid) == $var(callid) - || $var(state) == "onthephone" - || ($var(state) == "busy" && $xavp(presence=>state) != "onthephone") - ) { - $var(kz_presence_log_level) = $(sel(cfg_get.kazoo.presence_with_targets_log_level){s.int}); - xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|saving $var(presentity) from presence update => $var(payload)\n"); - if(kazoo_pua_publish_presence($var(JObj)) != 1) { - xlog("L_ERR", "$(var(payload){kz.json,Call-ID})|log|error publishing $var(presentity) presence update => $var(payload)\n"); - } - } + $var(kz_presence_log_level) = $(sel(cfg_get.kazoo.presence_with_targets_log_level){s.int}); + xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|saving $var(presentity) from presence update => $var(payload)\n"); + if(kazoo_pua_publish_presence($var(JObj)) != 1) { + xlog("L_ERR", "$(var(payload){kz.json,Call-ID})|log|error publishing $var(presentity) presence update => $var(payload)\n"); + } } #!else xlog("L_DEBUG", "$(var(payload){kz.json,Call-ID})|log|skip presence update for $var(presentity)\n"); From f288ed7714d69b842174403cd300e9034b64f700 Mon Sep 17 00:00:00 2001 From: karl anderson Date: Fri, 19 Apr 2019 19:16:27 +0000 Subject: [PATCH 209/209] resolve conflict --- kamailio/sanity.cfg | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/kamailio/sanity.cfg b/kamailio/sanity.cfg index 92ba2fc..01d323e 100644 --- a/kamailio/sanity.cfg +++ b/kamailio/sanity.cfg @@ -64,4 +64,11 @@ route[SANITY_CHECK] xlog("L_WARN", "$ci|end|dropping message with user-agent $ua from $si:$sp\n"); drop; } + + if(sdp_get_line_startswith("$avp(sanity_sline)", "s=")) { + if ($avp(sanity_sline) == "s=portsip.com") { + xlog("L_WARN", "$ci|end|dropping message with '$avp(sanity_sline)' string in SDP\n"); + exit; + } + } }