From da7a5a99f552bacf1e2683323565279df026ec18 Mon Sep 17 00:00:00 2001 From: Daniel Finke Date: Fri, 7 Sep 2018 15:54:31 +0000 Subject: [PATCH 001/210] Add KZQ_HAS_PRESENTITY to db_queries_mysql --- kamailio/db_queries_mysql.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/kamailio/db_queries_mysql.cfg b/kamailio/db_queries_mysql.cfg index 9dcd2a1..7385add 100644 --- a/kamailio/db_queries_mysql.cfg +++ b/kamailio/db_queries_mysql.cfg @@ -11,4 +11,5 @@ #!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_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" From 14b5b3e7028e47636feb7b5f65074bc7fc7c2230 Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 24 Oct 2018 00:10:09 +0100 Subject: [PATCH 002/210] ignore online/offline probe --- kamailio/presence-role.cfg | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/kamailio/presence-role.cfg b/kamailio/presence-role.cfg index 81af925..d5d4997 100644 --- a/kamailio/presence-role.cfg +++ b/kamailio/presence-role.cfg @@ -3,6 +3,8 @@ #!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;") modparam("htable", "htable", "first=>size=32;autoexpire=3600;initval =0;updateexpire=1;") @@ -56,6 +58,7 @@ modparam("nat_traversal", "keepalive_interval", 45) 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" +kazoo.presence_ignore_status_probe_resp = KZ_PRESENCE_IGNORE_STATUS_PROBE_RESP descr "ignore online/offline probe replies" #!ifdef FAST_PICKUP_ROLE #!include_file "fast-pickup-role.cfg" @@ -339,7 +342,13 @@ event_route[kazoo:consumer-event-presence-mwi-update] event_route[kazoo:consumer-event-presence-update] { - xlog("L_INFO", "$(kzE{kz.json,Call-ID})|log|received presence update for $(kzE{kz.json,Presence-ID}) : $kzE\n"); + if(@cfg_get.kazoo.presence_ignore_status_probe_resp == 1) { + if($(kzE{kz.json,State}) == "offline" || $(kzE{kz.json,State}) == "online") { + return; + } + } + + xlog("L_INFO", "$(kzE{kz.json,Call-ID})|log|received presence update for $(kzE{kz.json,Presence-ID})\n"); $var(JObj) = $kzE; $var(presentity) = $_s(sip:$(kzE{kz.json,Presence-ID})); $var(payload) = $kzE; From 7703c1ede3df1bf6ee52bbfd47cf35ee9befc44a Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 14 Nov 2018 23:08:11 +0000 Subject: [PATCH 003/210] 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 5437a8e86daa21a0e50a51bacd442630dcceb553 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 15 Nov 2018 01:04:07 +0000 Subject: [PATCH 004/210] 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 be2cdba506aaa482e1316d1a3143b357752006bb Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 15 Nov 2018 18:07:36 +0000 Subject: [PATCH 005/210] 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 67c96e70094e895ea8c4a5ba19550e905207f8c6 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 15 Nov 2018 23:34:29 +0000 Subject: [PATCH 006/210] 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 6c3f23da02e6a70cabda1b1acb44915d79249ff6 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 15 Nov 2018 23:47:06 +0000 Subject: [PATCH 007/210] 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 12eb4bf819be1e604294619ecf9e71f8c52a8fd0 Mon Sep 17 00:00:00 2001 From: lazedo Date: Fri, 16 Nov 2018 00:03:04 +0000 Subject: [PATCH 008/210] 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 6bfc74d65cd935f1f9dd88e8d2d097dba99524c7 Mon Sep 17 00:00:00 2001 From: lazedo Date: Fri, 16 Nov 2018 00:57:59 +0000 Subject: [PATCH 009/210] 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 17092c0bf42bf44c78001ca1bc80951758fb21a1 Mon Sep 17 00:00:00 2001 From: lazedo Date: Fri, 16 Nov 2018 01:35:57 +0000 Subject: [PATCH 010/210] 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 70e7aef55833555fe66707da8ebd04424271a5c7 Mon Sep 17 00:00:00 2001 From: lazedo Date: Fri, 16 Nov 2018 19:08:32 +0000 Subject: [PATCH 011/210] 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 e708a00460d4cf444d9a3c8b20c8276d71a8691e Mon Sep 17 00:00:00 2001 From: lazedo Date: Fri, 16 Nov 2018 23:24:24 +0000 Subject: [PATCH 012/210] 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 cdc8bd9b7c6526b3fc6d9d6e721a1d88b65a863d Mon Sep 17 00:00:00 2001 From: lazedo Date: Sat, 17 Nov 2018 12:05:54 +0000 Subject: [PATCH 013/210] 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 378af34ecd51ff1a3281b4244e052e5af730fa60 Mon Sep 17 00:00:00 2001 From: lazedo Date: Sat, 17 Nov 2018 13:38:25 +0000 Subject: [PATCH 014/210] 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 5d3f9dfc0d0996a12ec821c7e1fe8279d28c64ff Mon Sep 17 00:00:00 2001 From: lazedo Date: Sat, 17 Nov 2018 13:41:03 +0000 Subject: [PATCH 015/210] 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 d5a1f82fd90a37b435fb3b76ee99722d11e60764 Mon Sep 17 00:00:00 2001 From: lazedo Date: Sat, 17 Nov 2018 13:41:26 +0000 Subject: [PATCH 016/210] 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 7d1af72c0781ab47e204754fb2141a12bb7cc8a6 Mon Sep 17 00:00:00 2001 From: lazedo Date: Sat, 17 Nov 2018 13:49:23 +0000 Subject: [PATCH 017/210] 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 b249ca299fad9e6f14a295a0845c16690c3e03e3 Mon Sep 17 00:00:00 2001 From: lazedo Date: Sat, 17 Nov 2018 13:59:14 +0000 Subject: [PATCH 018/210] 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 aabcf4a7fbc2d79624e88f2491b59f290894eda4 Mon Sep 17 00:00:00 2001 From: lazedo Date: Sat, 17 Nov 2018 14:03:43 +0000 Subject: [PATCH 019/210] 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 8349bd727e7fc0d7a0b8cc0bf6ce69619bb17847 Mon Sep 17 00:00:00 2001 From: lazedo Date: Sat, 17 Nov 2018 14:07:29 +0000 Subject: [PATCH 020/210] 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 fa80fef7844a0d559d994bf95a0cd198ba8f9a97 Mon Sep 17 00:00:00 2001 From: lazedo Date: Mon, 19 Nov 2018 14:49:12 +0000 Subject: [PATCH 021/210] 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 cda63e4ab998558548dfbf1bd4e06c9186817260 Mon Sep 17 00:00:00 2001 From: lazedo Date: Mon, 19 Nov 2018 18:41:58 +0000 Subject: [PATCH 022/210] 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 08c9548a3212eef1117fe0a9981d4ee9950bb0fe Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 20 Nov 2018 19:04:06 +0000 Subject: [PATCH 023/210] 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 29831aee9079513252c941d9ed1e0dabaa08b3ad Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 21 Nov 2018 10:00:37 +0000 Subject: [PATCH 024/210] 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 05e93bb8cd297a97593a239efdda41ab4d6c1ea5 Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 21 Nov 2018 10:18:24 +0000 Subject: [PATCH 025/210] 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 b8b915eaef8534c229ec2f40f77a77fd73b7816e Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 21 Nov 2018 11:05:14 +0000 Subject: [PATCH 026/210] 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 dd9b7133e9c3ba82688cdde0ce4d0ef3e7db5201 Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 21 Nov 2018 13:46:54 +0000 Subject: [PATCH 027/210] 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 ce0493224726e6051408efd234578d9179d54990 Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 21 Nov 2018 13:47:34 +0000 Subject: [PATCH 028/210] 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 968773a65365b5543cde145d75c057e8f1bed152 Mon Sep 17 00:00:00 2001 From: lazedo Date: Mon, 26 Nov 2018 13:45:13 +0000 Subject: [PATCH 029/210] 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 e147eae4be842103ac8b2ec059706589ad859c43 Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 28 Nov 2018 10:53:54 +0000 Subject: [PATCH 030/210] 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 94c4f74b2d1105ddfee005cc2ce580986f8050e8 Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 28 Nov 2018 15:30:18 +0000 Subject: [PATCH 031/210] 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 4cea7663d67c92041fb51ce19c049627ff5c6b5e Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 28 Nov 2018 15:31:12 +0000 Subject: [PATCH 032/210] 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 022c0dd8b0f92ae87f6d6af39ca2c980e9b4b44d Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 28 Nov 2018 15:31:56 +0000 Subject: [PATCH 033/210] 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 b8aad0bf3ac59cba68c3a57a5685cee1a9ed127a Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 29 Nov 2018 00:40:15 +0000 Subject: [PATCH 034/210] 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 58a4390cd5c25ba5da59d532897af5d55ea03f39 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 29 Nov 2018 02:46:38 +0000 Subject: [PATCH 035/210] !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 e4c0a9435a2a4de1be302e253b921f455246fd3c Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 29 Nov 2018 15:35:53 +0000 Subject: [PATCH 036/210] 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 f08248d30e9d3449b2ff2fa85b94781cb4a09311 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 29 Nov 2018 17:01:50 +0000 Subject: [PATCH 037/210] 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 6ea09368d452fc5ef55dbfb0f24a411e030f9f05 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 29 Nov 2018 17:02:59 +0000 Subject: [PATCH 038/210] 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 1983d7a458e6e14b7e8ebecfe3f112b1b35ad13e Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 29 Nov 2018 18:23:24 +0000 Subject: [PATCH 039/210] 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 93c798b4d2d8447070d66179141396ccd2cd6524 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 29 Nov 2018 20:45:30 +0000 Subject: [PATCH 040/210] 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 646e2e86abd1fb12f38e296496aabb4bf16bad1d Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 29 Nov 2018 22:08:11 +0000 Subject: [PATCH 041/210] 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 c4aa9e05162158c46287a8bca1cd7f8196a1630f Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 29 Nov 2018 22:10:17 +0000 Subject: [PATCH 042/210] 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 1275e9cfd7ae36ee2060e31a7918b91d301cb46a Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 29 Nov 2018 22:17:03 +0000 Subject: [PATCH 043/210] 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 761a085cb2b6a07053f83b5930b6454d10283fbd Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 29 Nov 2018 23:08:18 +0000 Subject: [PATCH 044/210] 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 6f6e40340150fabf9aa34bd295dea2646de87d5c Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 29 Nov 2018 23:28:49 +0000 Subject: [PATCH 045/210] 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 928755686d63402857950fbac0123abd5eefe358 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 29 Nov 2018 23:33:31 +0000 Subject: [PATCH 046/210] 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 0d5b9b89b7566b1313d24e2c79b193927796e4d8 Mon Sep 17 00:00:00 2001 From: lazedo Date: Fri, 30 Nov 2018 00:52:04 +0000 Subject: [PATCH 047/210] 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 29b6983db5d9cb52760b64e11165613cd39b9b11 Mon Sep 17 00:00:00 2001 From: lazedo Date: Fri, 30 Nov 2018 18:39:22 +0000 Subject: [PATCH 048/210] 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 02125e77a628383cccd407b7bbc7305da0fd4cd0 Mon Sep 17 00:00:00 2001 From: lazedo Date: Fri, 30 Nov 2018 19:39:00 +0000 Subject: [PATCH 049/210] 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 5e4615e173fb978ef706bfe8183c3180ccfcff99 Mon Sep 17 00:00:00 2001 From: lazedo Date: Sat, 1 Dec 2018 03:22:59 +0000 Subject: [PATCH 050/210] 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 419a670e542eb30d49bd3240e02acf5720a775da Mon Sep 17 00:00:00 2001 From: lazedo Date: Mon, 10 Dec 2018 22:50:24 +0000 Subject: [PATCH 051/210] 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 4acd6a26bb87f6c34fc82221c5d6f10cf3144cf2 Mon Sep 17 00:00:00 2001 From: lazedo Date: Fri, 14 Dec 2018 18:41:56 +0000 Subject: [PATCH 052/210] 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 5d56b6eb7289cfb76212524acdfd4fc1b3cb4a99 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 27 Dec 2018 15:21:40 +0000 Subject: [PATCH 053/210] 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 c4c62c19ede8591035196242aadb805571c42ff1 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 27 Dec 2018 15:50:18 +0000 Subject: [PATCH 054/210] 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 5a625d0217a2fdb49eb33e9979f8d074c1d514ac Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 27 Dec 2018 16:27:13 +0000 Subject: [PATCH 055/210] 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 df8b23a32c223fa2fe735a7e37b5c69b76aa4aeb Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 27 Dec 2018 16:46:23 +0000 Subject: [PATCH 056/210] 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 8ab98e235bbe5ec7cf273fa0420f6a0cab9064b2 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 3 Jan 2019 09:54:27 +0000 Subject: [PATCH 057/210] 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 b71fcb0ba906681391c86cd81e1d19c6520d8ce7 Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 8 Jan 2019 17:49:09 +0000 Subject: [PATCH 058/210] 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 ea7712425cd833b03affe8db02c5e9765d4496ba Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 9 Jan 2019 12:32:05 +0000 Subject: [PATCH 059/210] 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 4bae98240ea1c74ea147759e5eb3fb1c68402f9e Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 10 Jan 2019 05:54:57 +0000 Subject: [PATCH 060/210] 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 88aef4191c3f6aece29b4c476da67c7bf4a36ae7 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 10 Jan 2019 05:56:12 +0000 Subject: [PATCH 061/210] 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 1996b28b8b34b09f526d809e69f4d59568bf0747 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 10 Jan 2019 05:57:47 +0000 Subject: [PATCH 062/210] 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 6a0087277bafdbf79686b46cec6335c40b46a700 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 10 Jan 2019 05:58:48 +0000 Subject: [PATCH 063/210] 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 419bed5d83b8f7442d900678755b84361cfb961b Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 10 Jan 2019 06:06:12 +0000 Subject: [PATCH 064/210] 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 7d7516b6661748e1b011227fefa509a873368415 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 10 Jan 2019 06:06:38 +0000 Subject: [PATCH 065/210] 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 f5bb8319ba30644f27d6aea15c3abd65e3674abf Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 10 Jan 2019 11:19:52 +0000 Subject: [PATCH 066/210] 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 cb5cb9b7ffbad2291c0a03092f32ba70e6838d28 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 10 Jan 2019 11:21:29 +0000 Subject: [PATCH 067/210] 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 88b8e0199eb155c5d2b807ea206a79e054cefa1f Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 10 Jan 2019 11:21:49 +0000 Subject: [PATCH 068/210] 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 dafab4644d5b61626c737491d13e8d533db44506 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 10 Jan 2019 12:22:24 +0000 Subject: [PATCH 069/210] 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 4014155c1fea830b6986eec68031dda1377fd4f0 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 10 Jan 2019 14:22:56 +0000 Subject: [PATCH 070/210] 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 d58d9481afb1dac629fddbfebad6f4d26ef90752 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 10 Jan 2019 14:40:46 +0000 Subject: [PATCH 071/210] 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 07de9ebac471ae00e616c464eddd06210098752a Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 10 Jan 2019 15:54:02 +0000 Subject: [PATCH 072/210] 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 4c9afb9c94ea3fdb65d18bc645bf08891a5d96cc Mon Sep 17 00:00:00 2001 From: lazedo Date: Sat, 12 Jan 2019 18:41:29 +0000 Subject: [PATCH 073/210] 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 a21c799de2096ac3510c544061e249ac861396c9 Mon Sep 17 00:00:00 2001 From: lazedo Date: Sat, 12 Jan 2019 18:42:01 +0000 Subject: [PATCH 074/210] 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 48ba777d003510f33d5dfd82c6020f07daee0b87 Mon Sep 17 00:00:00 2001 From: lazedo Date: Sun, 13 Jan 2019 11:58:51 +0000 Subject: [PATCH 075/210] 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 fd90d9df193b36e2b5672c80141e0a5f3ffded99 Mon Sep 17 00:00:00 2001 From: lazedo Date: Sun, 13 Jan 2019 19:33:53 +0000 Subject: [PATCH 076/210] 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 c25515bed5aac2c63f783d87934b2b96ddb9c6e6 Mon Sep 17 00:00:00 2001 From: lazedo Date: Mon, 14 Jan 2019 11:33:43 +0000 Subject: [PATCH 077/210] 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 53900274eb2a96d15492e5b4d497132335076518 Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 15 Jan 2019 16:12:49 +0000 Subject: [PATCH 078/210] 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 cff16eb6c680e7b113f7dc5ead51f798d92538bf Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 16 Jan 2019 18:03:37 +0000 Subject: [PATCH 079/210] 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 b4b9b670eb633827c8222241d9b47e683d91f3ac Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 16 Jan 2019 20:24:44 +0000 Subject: [PATCH 080/210] 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 5c3a592c4d1c780fd21f5c1ccd1d33a7ad323290 Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 16 Jan 2019 23:03:46 +0000 Subject: [PATCH 081/210] 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 f672b8926b9b7c0235160eab8817a342001f4cde Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 17 Jan 2019 04:57:59 +0000 Subject: [PATCH 082/210] 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 ee35f2f1294c8067f0ed5a927fa4e2af02471e79 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 17 Jan 2019 05:02:32 +0000 Subject: [PATCH 083/210] 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 6ba389fcea1641a06cf828c756a42b7b88104454 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 17 Jan 2019 05:41:03 +0000 Subject: [PATCH 084/210] 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 013da14864cd0a1acf59f27da43d72ead596bb0f Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 17 Jan 2019 08:07:28 +0000 Subject: [PATCH 085/210] 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 03a5c57a6b9a986a29034cba7ddda589501bf229 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 17 Jan 2019 12:45:22 +0000 Subject: [PATCH 086/210] 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 f0de0c7596d14af610d4ba36cde4d988117f5a81 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 17 Jan 2019 14:23:59 +0000 Subject: [PATCH 087/210] 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 d42460ffcbf8dd191b5433a29702130984a2d9e4 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 17 Jan 2019 17:01:37 +0000 Subject: [PATCH 088/210] 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 742ff3ea17329e28107053cea5d15a2dd752dc4a Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 17 Jan 2019 17:03:34 +0000 Subject: [PATCH 089/210] 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 272409e19654080ff9a1716631dbebb2f66588a6 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 17 Jan 2019 17:13:25 +0000 Subject: [PATCH 090/210] 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 e4b932558302d7e8f5e02006997219bd71650fe8 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 17 Jan 2019 17:48:34 +0000 Subject: [PATCH 091/210] 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 20b51d1ff6f234c27f8e3b2c4a56ff9f40214aa6 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 17 Jan 2019 18:45:43 +0000 Subject: [PATCH 092/210] 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 0f35dc46b0f4da76dfca8ce16065e5d07fc13d16 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 17 Jan 2019 20:20:28 +0000 Subject: [PATCH 093/210] 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 40a14584f8522760633131600ba66f8990f8a336 Mon Sep 17 00:00:00 2001 From: lazedo Date: Fri, 18 Jan 2019 12:30:59 +0000 Subject: [PATCH 094/210] 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 d13e410d67223b431c3d61a4791a8d1b7d6a3366 Mon Sep 17 00:00:00 2001 From: lazedo Date: Fri, 18 Jan 2019 12:58:48 +0000 Subject: [PATCH 095/210] 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 ab5c9c69a2a636d6a587592a184a973399a2a052 Mon Sep 17 00:00:00 2001 From: lazedo Date: Fri, 18 Jan 2019 14:09:17 +0000 Subject: [PATCH 096/210] 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 42dce54dd430f48ade76f9da6bdc5363b5181db8 Mon Sep 17 00:00:00 2001 From: lazedo Date: Fri, 18 Jan 2019 15:17:33 +0000 Subject: [PATCH 097/210] 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 8ca0cd31f09b77ced33a9ba03d703bfd714629a0 Mon Sep 17 00:00:00 2001 From: lazedo Date: Fri, 18 Jan 2019 17:52:56 +0000 Subject: [PATCH 098/210] 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 9182cc50cd064f97174dc8471f51934ea739ee53 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 24 Jan 2019 15:50:17 +0000 Subject: [PATCH 099/210] 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 4d784e26be1c7bee942bee8a56ff016678a9dbbf Mon Sep 17 00:00:00 2001 From: lazedo Date: Mon, 28 Jan 2019 21:41:57 +0000 Subject: [PATCH 100/210] 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 2a32c9c663718ceaba46cf6b1f0b3e8102f7cfd1 Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 29 Jan 2019 00:17:29 +0000 Subject: [PATCH 101/210] 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 4dab51ee41a095043b988dd889acc19fc0eeb12a Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 29 Jan 2019 12:52:09 +0000 Subject: [PATCH 102/210] 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 32450fa1b036b34481660d3fc93fc0d51abbbf5e Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 6 Feb 2019 04:38:45 +0000 Subject: [PATCH 103/210] 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 5c0df888b21af548551f226f72bbe0c3164efa9e Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 12 Feb 2019 11:21:53 +0000 Subject: [PATCH 104/210] 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 104ac3303e33c3a05d9cdd4ed5f7c071e907127b Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 12 Feb 2019 11:22:17 +0000 Subject: [PATCH 105/210] 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 21db8369488d9c4fc28ac1135e5d0505fc3976ae Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 12 Feb 2019 11:52:00 +0000 Subject: [PATCH 106/210] 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 ee94e095c0b25ffe1482538c076bc39dfea2bf91 Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 12 Feb 2019 20:08:20 +0000 Subject: [PATCH 107/210] 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 2a01496f964c96360f5a3739789cc4ee0c269318 Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 13 Feb 2019 02:12:15 +0000 Subject: [PATCH 108/210] 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 d86cca43650d72cc975a15babbed96f48f74f0ed Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 14 Feb 2019 18:43:53 +0000 Subject: [PATCH 109/210] 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 628f661859879019bce415653c1d5ea6067d2567 Mon Sep 17 00:00:00 2001 From: lazedo Date: Fri, 15 Feb 2019 15:10:47 +0000 Subject: [PATCH 110/210] 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 5daf2d9b542ac70b92426131a8cf63cc7bd42637 Mon Sep 17 00:00:00 2001 From: lazedo Date: Sat, 16 Feb 2019 14:19:46 +0000 Subject: [PATCH 111/210] 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 0526ce2f910c4207dc77e84a0eecb921de1193db Mon Sep 17 00:00:00 2001 From: lazedo Date: Sat, 16 Feb 2019 16:06:55 +0000 Subject: [PATCH 112/210] 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 fd45db66ca999deafba52174c5d939d34cef33b2 Mon Sep 17 00:00:00 2001 From: lazedo Date: Sat, 16 Feb 2019 16:45:27 +0000 Subject: [PATCH 113/210] 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 65e135d00bb3f5910ac2ec7ac84f9e97fc213c39 Mon Sep 17 00:00:00 2001 From: lazedo Date: Sun, 17 Feb 2019 09:41:01 +0000 Subject: [PATCH 114/210] 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 15a68cbbe2713b1272f5f484efebeb7000118f90 Mon Sep 17 00:00:00 2001 From: lazedo Date: Sun, 24 Feb 2019 14:35:04 +0000 Subject: [PATCH 115/210] 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 4fa36f07fb3a36a95e4bbb332c457b5954221e90 Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 27 Feb 2019 18:17:17 +0000 Subject: [PATCH 116/210] 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 a41c15b603c77831985e13ecdd57e53175de4f57 Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 27 Feb 2019 18:19:13 +0000 Subject: [PATCH 117/210] 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 1babdafb0d90b0dabdea0bdb920df28c70bd51df Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 27 Feb 2019 18:20:48 +0000 Subject: [PATCH 118/210] 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 ec6c9d138b6ee27971a718ad112c9e83c2333004 Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 27 Feb 2019 18:21:35 +0000 Subject: [PATCH 119/210] 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 2ecbeda741c8bea37a5c740fe8610a45515a772b Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 27 Feb 2019 18:24:10 +0000 Subject: [PATCH 120/210] 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 b4d224e1fd600b3da9cd652f8db268c6efd20282 Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 27 Feb 2019 18:24:27 +0000 Subject: [PATCH 121/210] 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 bb836ad243823a51a651be05b215ae350a9c18a3 Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 27 Feb 2019 18:25:58 +0000 Subject: [PATCH 122/210] 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 bfec04f8c3925da4814b7229867b2a64384797f4 Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 27 Feb 2019 18:26:18 +0000 Subject: [PATCH 123/210] 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 23cf96c6aa22930c56eab67cf680430523112e50 Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 27 Feb 2019 18:27:07 +0000 Subject: [PATCH 124/210] 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 4c4c07fb6ee8eb081422e742b5b3adbb197a17a3 Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 27 Feb 2019 18:27:50 +0000 Subject: [PATCH 125/210] 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 c33bd1cfdae75322a2dbb4381006e632d6888d83 Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 27 Feb 2019 18:37:38 +0000 Subject: [PATCH 126/210] 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 1bddebc043f9c9dcc6314cb1e34891a37ba4c9ac Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 28 Feb 2019 01:46:33 +0000 Subject: [PATCH 127/210] 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 1e726da37e6666d70237fdc6601a0ad8c6a1ea31 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 28 Feb 2019 01:57:41 +0000 Subject: [PATCH 128/210] 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 34bcc3520c0829e3b0231e11c78c0abb8de81758 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 28 Feb 2019 02:01:08 +0000 Subject: [PATCH 129/210] 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 a7c27fea0c03eb70db2784ecfd6d8b54c1594ecc Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 28 Feb 2019 05:23:59 +0000 Subject: [PATCH 130/210] 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 5a2fffaf2b1e1d59b7e947a84705dab730255a7a Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 28 Feb 2019 06:48:45 +0000 Subject: [PATCH 131/210] 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 80f1f1b42d34c813776a15f82ee2a0d1a25ed002 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 28 Feb 2019 06:49:26 +0000 Subject: [PATCH 132/210] 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 429a42a6b358d50ffa84ac887e38f2929477d89b Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 28 Feb 2019 06:49:56 +0000 Subject: [PATCH 133/210] 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 1a2a6bdeb3449b0f5ca2c4f05926e213622567f0 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 28 Feb 2019 06:52:35 +0000 Subject: [PATCH 134/210] 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 45e8d5638ca884312dc24c03eb0f93e0336fbc1c Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 28 Feb 2019 09:11:39 +0000 Subject: [PATCH 135/210] 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 5b47d34d4d1af24d50d88d3d5d0e89e723b4b374 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 28 Feb 2019 16:14:23 +0000 Subject: [PATCH 136/210] 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 ae3fc615a427e1c0fc9f824882f307a44f47e5ca Mon Sep 17 00:00:00 2001 From: lazedo Date: Fri, 1 Mar 2019 19:57:43 +0000 Subject: [PATCH 137/210] 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 9d9fd35023c67836ef2d293983fae085edb16a97 Mon Sep 17 00:00:00 2001 From: lazedo Date: Fri, 1 Mar 2019 21:56:24 +0000 Subject: [PATCH 138/210] 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 2997c5191ce1bd8b01d1c8736e16e074de87871f Mon Sep 17 00:00:00 2001 From: lazedo Date: Sat, 2 Mar 2019 00:15:25 +0000 Subject: [PATCH 139/210] 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 ff7874141d72dfcc56154946e0182ed38aedacea Mon Sep 17 00:00:00 2001 From: lazedo Date: Sat, 2 Mar 2019 02:50:15 +0000 Subject: [PATCH 140/210] 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 c6ad6dbb8cd3c76ff69bbf5ace41f01750c1820a Mon Sep 17 00:00:00 2001 From: lazedo Date: Mon, 4 Mar 2019 08:27:39 +0000 Subject: [PATCH 141/210] 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 420a4281e6ab244c6cc52d218a30813a15d275af Mon Sep 17 00:00:00 2001 From: lazedo Date: Mon, 4 Mar 2019 08:29:49 +0000 Subject: [PATCH 142/210] 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 ab753be08993c22ac4eb654beae784c0f38d0ada Mon Sep 17 00:00:00 2001 From: lazedo Date: Mon, 4 Mar 2019 08:30:29 +0000 Subject: [PATCH 143/210] 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 1e47348c438666eae5aff41cda48f7b701ae41b7 Mon Sep 17 00:00:00 2001 From: lazedo Date: Mon, 4 Mar 2019 08:31:12 +0000 Subject: [PATCH 144/210] 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 4cad20d6d44e50f7bdd84be7d0f8e9db638b3b95 Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 5 Mar 2019 17:50:27 +0000 Subject: [PATCH 145/210] 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 6857b35c4def1bbdc274740b0c5aefd4ae236adf Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 5 Mar 2019 20:51:10 +0000 Subject: [PATCH 146/210] 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 dad34428b79afa401b10e0e285a6699d6dbe40df Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 7 Mar 2019 15:04:26 +0000 Subject: [PATCH 147/210] 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 e9eb219a92662d7e21761976a1dae30aadc4a387 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 7 Mar 2019 22:24:58 +0000 Subject: [PATCH 148/210] 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 f7f7e3fca3abf3a7d78a56ade4c38a20d2c400bd Mon Sep 17 00:00:00 2001 From: lazedo Date: Mon, 11 Mar 2019 10:29:54 +0000 Subject: [PATCH 149/210] 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 75acf0ee260600332bf9e924aee66d78584be49f Mon Sep 17 00:00:00 2001 From: lazedo Date: Mon, 11 Mar 2019 13:07:42 +0000 Subject: [PATCH 150/210] 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 99f9e807718c54ca76c1876a00677299f6ff3c3c Mon Sep 17 00:00:00 2001 From: lazedo Date: Mon, 11 Mar 2019 13:08:21 +0000 Subject: [PATCH 151/210] 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 5758f8c6d367ce503d09d4f9aa077cdaa56216ac Mon Sep 17 00:00:00 2001 From: lazedo Date: Mon, 11 Mar 2019 13:17:31 +0000 Subject: [PATCH 152/210] 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 dc51608ee4b103f84dbcaa69eef8c4ba6b869761 Mon Sep 17 00:00:00 2001 From: lazedo Date: Mon, 11 Mar 2019 14:43:21 +0000 Subject: [PATCH 153/210] 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 f121b5134b26f63069f7fee5771e16dd48d400cf Mon Sep 17 00:00:00 2001 From: lazedo Date: Mon, 11 Mar 2019 14:45:23 +0000 Subject: [PATCH 154/210] 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 1a82cb2fa938d207ff12928f055e102da8802ebe Mon Sep 17 00:00:00 2001 From: lazedo Date: Mon, 11 Mar 2019 15:14:14 +0000 Subject: [PATCH 155/210] 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 c6f981a5d4e34b476cf1bedd19e2b6f53d5446aa Mon Sep 17 00:00:00 2001 From: lazedo Date: Mon, 11 Mar 2019 18:04:35 +0000 Subject: [PATCH 156/210] 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 40c7de246d29e4aaa4da847fd165b8062faee753 Mon Sep 17 00:00:00 2001 From: lazedo Date: Mon, 11 Mar 2019 15:15:06 +0000 Subject: [PATCH 157/210] 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 d849e98d6a0172d6e55574a790e37789fc3aec89 Mon Sep 17 00:00:00 2001 From: lazedo Date: Mon, 11 Mar 2019 19:25:28 +0000 Subject: [PATCH 158/210] 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 dca4afcd79751c384ca419770d238abb32cbdd44 Mon Sep 17 00:00:00 2001 From: lazedo Date: Mon, 11 Mar 2019 21:13:58 +0000 Subject: [PATCH 159/210] 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 50d014a43ca3ba73a862bd36d0fa87a5dddf2ea5 Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 12 Mar 2019 01:11:14 +0000 Subject: [PATCH 160/210] 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 15cab44061bbfc73b1524cc7d53a143af729df93 Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 12 Mar 2019 01:57:14 +0000 Subject: [PATCH 161/210] 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 f1acc8fcae708fc82ecf1ae0cadb5a917f7ea05a Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 12 Mar 2019 02:39:29 +0000 Subject: [PATCH 162/210] 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 7e4472f12409023b6d785a35dbc22c775b970585 Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 12 Mar 2019 22:00:55 +0000 Subject: [PATCH 163/210] 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 1c5258746d33bc61ee7a4a21b2ad264e9644383b Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 12 Mar 2019 22:01:27 +0000 Subject: [PATCH 164/210] 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 4dd00f161245aca4939d063070dd697341c53a98 Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 12 Mar 2019 22:01:42 +0000 Subject: [PATCH 165/210] 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 382f8521d0926fc10eadb18611c959469500f521 Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 12 Mar 2019 22:13:50 +0000 Subject: [PATCH 166/210] 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 1733cfef26bfce9141408e231b2cf54ca1e53640 Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 12 Mar 2019 22:14:35 +0000 Subject: [PATCH 167/210] 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 7195128c9cdc9b2f4d2d20db652685ce285c6119 Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 13 Mar 2019 02:21:24 +0000 Subject: [PATCH 168/210] 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 cebd0b11d6bad2a4342b5315d1e5ef8795d2e21c Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 13 Mar 2019 02:21:46 +0000 Subject: [PATCH 169/210] 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 83e89bd8374c919428c5fb59b3a44eced4507989 Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 13 Mar 2019 02:22:37 +0000 Subject: [PATCH 170/210] 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 73d945c4fdbcba3d794433c78b0162fbbdff4e61 Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 13 Mar 2019 02:28:06 +0000 Subject: [PATCH 171/210] 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 a3e967e08aedfc2506e9391ccf024753797321e6 Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 13 Mar 2019 02:32:42 +0000 Subject: [PATCH 172/210] 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 411634b95477b626fe29c33f41aa06b02da4ce49 Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 13 Mar 2019 02:35:33 +0000 Subject: [PATCH 173/210] 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 5d67f349bd3d20eb6cda6212257aef34ba41ae9d Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 13 Mar 2019 03:59:44 +0000 Subject: [PATCH 174/210] 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 f33753d5bc8566fa1a391b3f7d108f39f21e5f50 Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 13 Mar 2019 05:35:15 +0000 Subject: [PATCH 175/210] 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 b435966eda59d8e9d61de429d44fa1d407b86b03 Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 13 Mar 2019 05:37:54 +0000 Subject: [PATCH 176/210] 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 21ed2661530046520d09aee69c8b0c3ed03f67cf Mon Sep 17 00:00:00 2001 From: lazedo Date: Fri, 15 Mar 2019 23:52:55 +0000 Subject: [PATCH 177/210] 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 235a4bb8b5140eabe9f0279e56c5bbe067fbd4dc Mon Sep 17 00:00:00 2001 From: lazedo Date: Fri, 15 Mar 2019 23:54:12 +0000 Subject: [PATCH 178/210] 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 9ae2ed21c3290f0041f482e45d7747198dd82e3e Mon Sep 17 00:00:00 2001 From: lazedo Date: Fri, 15 Mar 2019 23:55:22 +0000 Subject: [PATCH 179/210] 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 490a5be8d23edd7aa86149fa33dfb8b2fa710c31 Mon Sep 17 00:00:00 2001 From: lazedo Date: Fri, 15 Mar 2019 23:55:55 +0000 Subject: [PATCH 180/210] 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 a8899cd1fc935e679307b06176e9617986ccdb5e Mon Sep 17 00:00:00 2001 From: lazedo Date: Sat, 16 Mar 2019 00:01:27 +0000 Subject: [PATCH 181/210] 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 7b434329dcd321964932ccedf80eb91697918361 Mon Sep 17 00:00:00 2001 From: lazedo Date: Sat, 16 Mar 2019 01:54:11 +0000 Subject: [PATCH 182/210] 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 241ca7c0d984c95e0657e7d007219b86cc2c1d0d Mon Sep 17 00:00:00 2001 From: lazedo Date: Sat, 16 Mar 2019 02:28:10 +0000 Subject: [PATCH 183/210] 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 f9235cdd1d5db66b4493ee6d8ef40fc30007475e Mon Sep 17 00:00:00 2001 From: lazedo Date: Sat, 16 Mar 2019 02:33:59 +0000 Subject: [PATCH 184/210] 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 4261e277e3dedc0e454e70e4ce7d88d235406b3d Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 19 Mar 2019 01:47:32 +0000 Subject: [PATCH 185/210] 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 172a130fb14888ac5ea8588d4135729d4e5ba00f Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 19 Mar 2019 01:50:20 +0000 Subject: [PATCH 186/210] 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 eb2ce85893c935eb40bbf968153719036f1a1987 Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 19 Mar 2019 01:53:49 +0000 Subject: [PATCH 187/210] 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 0bc353e552b3c4a46b457822cae173afc1253860 Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 19 Mar 2019 01:55:05 +0000 Subject: [PATCH 188/210] 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 2eadcd4bef59b91d14188ae51df2f2fc8caff695 Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 19 Mar 2019 01:56:16 +0000 Subject: [PATCH 189/210] 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 9649e7e978bef51ef0cfafca11f935e95c962b94 Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 19 Mar 2019 01:56:52 +0000 Subject: [PATCH 190/210] 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 af4382edc3c3b9c6fdfd37a34f09725c59bac752 Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 19 Mar 2019 06:05:40 +0000 Subject: [PATCH 191/210] 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 a7a14f5ddc92b6f5a822a4258a6908d670109fd2 Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 19 Mar 2019 08:14:29 +0000 Subject: [PATCH 192/210] 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 58148319ae7fe873890ab4fb20e375a5c62e00b5 Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 19 Mar 2019 19:53:38 +0000 Subject: [PATCH 193/210] 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 fcc2d0904a39e6c9ca302ba1d9924af41b6f6ba3 Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 19 Mar 2019 19:58:18 +0000 Subject: [PATCH 194/210] 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 4ef8835ce18ef6089d4fcf66ca6796d1e3b7aae3 Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 19 Mar 2019 20:01:36 +0000 Subject: [PATCH 195/210] 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 4eb1dc075881420ef29b79532f7cd9717b0e7112 Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 20 Mar 2019 17:10:32 +0000 Subject: [PATCH 196/210] 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 f7d89cd7bdcc7c8ecf66ddaacd547b2407bbdb54 Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 20 Mar 2019 17:11:10 +0000 Subject: [PATCH 197/210] 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 00bc4a86b4a9cbffbfeea51aa3dcda2909360e05 Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 20 Mar 2019 23:06:19 +0000 Subject: [PATCH 198/210] 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 6b66c1d1f4c461036247330673e81aa1d4a6f9b7 Mon Sep 17 00:00:00 2001 From: lazedo Date: Wed, 20 Mar 2019 23:07:10 +0000 Subject: [PATCH 199/210] 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 23eda1c9fa56c2f4a9d8111480ff6176516d351c Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 9 Apr 2019 21:45:07 +0000 Subject: [PATCH 200/210] 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 63a2d3a6a3dc462586cca8261f58e4862e83b970 Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 9 Apr 2019 21:45:49 +0000 Subject: [PATCH 201/210] 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 c0cc9501a7bb402c6850236be089ab9978d3ff48 Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 9 Apr 2019 21:46:34 +0000 Subject: [PATCH 202/210] 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 26cbbfec1368f313241d12b879c07865e8abd5b7 Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 9 Apr 2019 21:47:20 +0000 Subject: [PATCH 203/210] 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 8ae0296fffa56b0da8da76e0faea38e33b76be67 Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 9 Apr 2019 21:49:28 +0000 Subject: [PATCH 204/210] 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 772067a794a20944fa4eb2276f34bb82e40f4a16 Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 9 Apr 2019 21:49:50 +0000 Subject: [PATCH 205/210] 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 7e8f70042c0b782423565131181d3eb0ecc37c83 Mon Sep 17 00:00:00 2001 From: lazedo Date: Mon, 15 Apr 2019 13:47:51 +0000 Subject: [PATCH 206/210] 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 637ce55531f73614e683994cc6428f2c5f7b9845 Mon Sep 17 00:00:00 2001 From: lazedo Date: Mon, 15 Apr 2019 14:43:43 +0000 Subject: [PATCH 207/210] 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 91d3d6f86b8563c4666a10000663009af6bf5efa Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 16 Apr 2019 08:58:25 +0000 Subject: [PATCH 208/210] 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 678cd54505142fd740b319ccc2663add4816b7b9 Mon Sep 17 00:00:00 2001 From: lazedo Date: Tue, 16 Apr 2019 09:02:18 +0000 Subject: [PATCH 209/210] 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 3fba5c0dc7adfc993c4b70eddc774ff62868aa4a Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 18 Apr 2019 00:47:00 +0000 Subject: [PATCH 210/210] 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");