<p></p>
<h3 dir="auto">Description</h3>
<p dir="auto">I established a call between two extensions using TLS, and the presence state was replicated between two Kamailio servers using presence_dmq (no database backing).  This all worked correctly except when it comes to sending a PUBLISH with a state terminated in the body, the presence_dmq sent the serialized data correctly, but the Kamailio server sends the wrong state and the  caller is marked as busy on all subscribed phones until Kamailio is restarted.  This occurs on version 5.6.1.  In order generate this data, we use a separate script which responds to Asterisk events and sends the right PUBLISH at the right time to Kamailio, eg. if it sees a Hangup event, it sends a PUBLISH with the state in the body set to 'terminated' and the Expires: header set to 0.  This appears to prompt Kamailio to send a NOTIFY with a state of early or confirmed to all subscribers.</p>
<h3 dir="auto">Troubleshooting</h3>
<h4 dir="auto">Reproduction</h4>
<p dir="auto">Install two Kamailio servers running Kamailio 5.6.1.  I am using this installation command:<br>
<code class="notranslate">sudo apt install kamailio=5.6.1+bpo9 kamailio-dbg=5.6.1+bpo9 kamailio-lua-modules=5.6.1+bpo9 kamailio-memcached-modules=5.6.1+bpo9 kamailio-mysql-modules=5.6.1+bpo9 kamailio-presence-modules=5.6.1+bpo9 kamailio-redis-modules=5.6.1+bpo9 kamailio-tls-modules=5.6.1+bpo9 kamailio-utils-modules=5.6.1+bpo9</code></p>
<p dir="auto">Some configuration detail for /etc/kamailio/kamailio.cfg:</p>
<p dir="auto">listen=tls:172.22.0.155:5061</p>
<h1 dir="auto">This ensures we have a UDP socket for sending HEP datagrams (we also send the plaintext UDP PUBLISH here)</h1>
<p dir="auto">listen=udp:172.22.0.155:9060<br>
port=5061<br>
enable_tls=yes<br>
tcp_connection_lifetime=3605</p>
<p dir="auto">#modules (this is not an exhaustive list)<br>
loadmodule "dmq.so"<br>
loadmodule "dialog.so"<br>
loadmodule "presence.so"<br>
loadmodule "presence_xml.so"<br>
loadmodule "presence_dialoginfo.so"<br>
loadmodule "pua.so"<br>
loadmodule "pua_dialoginfo.so"<br>
loadmodule "tls.so"</p>
<p dir="auto">modparam("dmq", "server_address", "sip:172.22.0.155:9060")<br>
modparam("dmq", "notification_address", "sip:172.22.1.124:9060")<br>
modparam("dialog", "db_url", DBURL)<br>
modparam("dialog", "enable_stats", 1)<br>
modparam("dialog", "db_mode", 0) # 0 - NO_DB - the memory content is not flushed into DB<br>
modparam("dialog", "dlg_flag", 9)<br>
modparam("dialog", "enable_dmq", 1)<br>
modparam("pua", "db_url", DBURL)<br>
modparam("pua", "db_mode", 0) # high speed memory based storage<br>
modparam("pua", "outbound_proxy", "sips:172.22.0.155:5061;transport=tls")<br>
modparam("pua_dialoginfo", "include_localremote", 0)<br>
modparam("presence", "db_url", DBURL)<br>
modparam("presence", "server_address", "sips:this.host.example.org:5061;transport=tls")<br>
modparam("presence", "db_table_lock_type", 0)<br>
modparam("presence", "subs_db_mode", 0) # 0 - This disables database completely.<br>
modparam("presence", "enable_dmq", 1)<br>
modparam("presence", "publ_cache", 2)<br>
modparam("presence", "subs_remove_match", 1)<br>
modparam("presence", "timeout_rm_subs", 0)<br>
modparam("presence_dialoginfo", "force_dummy_dialog", 1)<br>
modparam("presence_dialoginfo", "force_single_dialog", 1)<br>
modparam("presence_xml", "force_active", 1)<br>
modparam("presence_xml", "force_presence_single_body", 1)</p>
<h4 dir="auto">Log Messages</h4>
<p dir="auto">These log aren't directly linked but Kamailio reports a 200 OK in response to the PUBLISH, but the NOTIFY to the handset is <em>not</em> terminated.  Difficult to capture this because of TLS.</p>
<pre class="notranslate"><code class="notranslate">Aug 26 13:32:26 this.host.example.org /usr/sbin/kamailio[4187]: DEBUG: presence [presence_dmq.c:467]: pres_dmq_replicate_presentity(): sending serialized data {"action":1,"presentity":{"domain":"sip.prod.example.org","user":"XXXX469","etag":"a.1661495738.4187.2612.0","expires":3600,"recv":1661520746,"event":"dialog"},"t_new":1,"cur_etag":"","ruid":"pres-630869ce-105b-43a","body":"<?xml version=\"1.0\"?>\n<dialog-info xmlns=\"urn:ietf:params:xml:ns:dialog-info\" version=\"0\" state=\"full\" entity=\"sip:XXXX469@sip.prod.example.org\">\n<dialog id=\"c95340dd-5266-450a-8c53-a5cd75c4bb67\" call-id=\"c95340dd-5266-450a-8c53-a5cd75c4bb67\" direction=\"recipient\">\n<state>confirmed</state>\n</dialog>\n</dialog-info>\n"}

Aug 26 13:33:00 this.host.example.org /usr/sbin/kamailio[4187]: DEBUG: presence [presence_dmq.c:467]: pres_dmq_replicate_presentity(): sending serialized data {"action":1,"presentity":{"domain":"sip.prod.example.org","user":"XXXX469","etag":"a.1661495738.4187.2622.0","expires":0,"recv":1661520780,"event":"dialog"},"t_new":1,"cur_etag":"","ruid":"pres-630869ce-105b-e3a","body":"<?xml version=\"1.0\"?>\n<dialog-info xmlns=\"urn:ietf:params:xml:ns:dialog-info\" version=\"0\" state=\"full\" entity=\"sip:XXXX469@sip.prod.example.org\">\n<dialog id=\"c95340dd-5266-450a-8c53-a5cd75c4bb67\" call-id=\"c95340dd-5266-450a-8c53-a5cd75c4bb67\" direction=\"recipient\">\n<state>terminated</state>\n</dialog>\n</dialog-info>\n"}
</code></pre>
<p dir="auto">This is a similar example:</p>
<pre class="notranslate"><code class="notranslate">Sep  1 12:37:14 this.host.example.org /usr/sbin/kamailio[5176]: INFO: presence [notify.c:1738]: send_notify_request(): NOTIFY sip:XXXX475@sip.prod.example.org via ÿÿÿÿÿÿÿÿ on behalf of sip:XXXX472@sip.prod.example.org for event dialog : 2_2191795053@172.31.29.18
Sep  1 12:37:14 this.host.example.org /usr/sbin/kamailio[5176]: DEBUG: presence [presence_dmq.c:400]: pres_dmq_replicate_presentity(): replicating presentity record - old etag a.1662035772.5176.17.0, new etag , ruid pres-6310a741-1438-11
Sep  1 12:37:14 this.host.example.org /usr/sbin/kamailio[5176]: DEBUG: presence [presence_dmq.c:467]: pres_dmq_replicate_presentity(): sending serialized data {"action":1,"presentity":{"domain":"sip.prod.example.org","user":"XXXX472","etag":"a.1662035772.5176.17.0","expires":0,"recv":1662035834,"event":"dialog"},"t_new":1,"cur_etag":"","ruid":"pres-6310a741-1438-11","body":"<?xml version=\"1.0\"?>\n<dialog-info xmlns=\"urn:ietf:params:xml:ns:dialog-info\" version=\"0\" state=\"full\" entity=\"sip:XXXX472@sip.prod.example.org\">\n<dialog id=\"76024a0e-2d35-47d8-afd1-a1363acbf859\" call-id=\"76024a0e-2d35-47d8-afd1-a1363acbf859\" direction=\"recipient\">\n<state>terminated</state>\n</dialog>\n</dialog-info>\n"}
Sep  1 12:37:14 this.host.example.org /usr/sbin/kamailio[5176]: DEBUG: presence [presence_dmq.c:149]: pres_dmq_send(): sending dmq broadcast...
</code></pre>
<h4 dir="auto">SIP Traffic</h4>
<pre class="notranslate"><code class="notranslate">PUBLISH sip:XXXX469@sip.prod.example.org SIP/2.0
Via: SIP/2.0/UDP this.host.example.org;branch=656ebca4-5e71-4082-984a-7efa54bdd2cc
To: sip:XXXX469@sip.prod.example.org
From: sip:XXXX469@sip.prod.example.org;tag=a06f8d92-609b-4210-a1f0-f7042b871f07
CSeq: 12 PUBLISH
Call-ID: d67c8bb5-f507-4ada-8f98-d7caa6d86721@this.host.example.org
Content-Length: 323
User-Agent: Astertisk-Event-Bridge
Max-Forwards: 70
Event: dialog
Expires: 0
Content-Type: application/dialog-info+xml
<?xml version="1.0"?>
<dialog-info xmlns="urn:ietf:params:xml:ns:dialog-info" version="0" state="full" entity="sip:XXXX469@sip.prod.example.org">
<dialog id="9fa5bf3c-63f3-4d3f-82c5-cdff374c4e13" call-id="9fa5bf3c-63f3-4d3f-82c5-cdff374c4e13" direction="recipient">
<state>terminated</state>
</dialog>
</dialog-info>
</code></pre>
<h3 dir="auto">Possible Solutions</h3>
<p dir="auto">Downgrading to Kamailio version 5.5.4 resolves this problem.</p>
<h3 dir="auto">Additional Information</h3>
<ul dir="auto">
<li><strong>Kamailio Version</strong> - output of <code class="notranslate">kamailio -v</code></li>
</ul>
<pre class="notranslate"><code class="notranslate">$ kamailio -v
version: kamailio 5.6.1 (x86_64/linux)
flags: USE_TCP, USE_TLS, USE_SCTP, TLS_HOOKS, USE_RAW_SOCKS, DISABLE_NAGLE, USE_MCAST, DNS_IP_HACK, SHM_MMAP, PKG_MALLOC, Q_MALLOC, F_MALLOC, TLSF_MALLOC, DBG_SR_MEMORY, USE_FUTEX, FAST_LOCK-ADAPTIVE_WAIT, USE_DNS_CACHE, USE_DNS_FAILOVER, USE_NAPTR, USE_DST_BLOCKLIST, HAVE_RESOLV_RES, TLS_PTHREAD_MUTEX_SHARED
ADAPTIVE_WAIT_LOOPS 1024, MAX_RECV_BUFFER_SIZE 262144, MAX_URI_SIZE 1024, BUF_SIZE 65535, DEFAULT PKG_SIZE 8MB
poll method support: poll, epoll_lt, epoll_et, sigio_rt, select.
id: unknown
compiled with gcc 6.3.0

$ dpkg -l | egrep '^ii' | grep kamailio | awk '{ print $2, $3 }'
kamailio 5.6.1+bpo9
kamailio-dbg:amd64 5.6.1+bpo9
kamailio-lua-modules:amd64 5.6.1+bpo9
kamailio-memcached-modules:amd64 5.6.1+bpo9
kamailio-mysql-modules:amd64 5.6.1+bpo9
kamailio-presence-modules:amd64 5.6.1+bpo9
kamailio-redis-modules:amd64 5.6.1+bpo9
kamailio-tls-modules:amd64 5.6.1+bpo9
kamailio-utils-modules:amd64 5.6.1+bpo9
</code></pre>
<ul dir="auto">
<li><strong>Operating System</strong>:</li>
</ul>
<pre class="notranslate"><code class="notranslate">$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux 9.2 (stretch)
Release:        9.2
Codename:       stretch

$ uname -a
Linux this.host.example.org 4.9.0-16-amd64 #1 SMP Debian 4.9.272-2 (2021-07-19) x86_64 GNU/Linux
</code></pre>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />Reply to this email directly, <a href="https://github.com/kamailio/kamailio/issues/3229">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/ABO7UZOYVPRVB4WBATG6NOTV4CRM3ANCNFSM6AAAAAAQCKOIEA">unsubscribe</a>.<br />You are receiving this because you are subscribed to this thread.<img src="https://github.com/notifications/beacon/ABO7UZOCP6P3ITAD6M4RQBTV4CRM3A5CNFSM6AAAAAAQCKOIECWGG33NNVSW45C7OR4XAZNFJFZXG5LFVJRW63LNMVXHIX3JMTHFB7NI6Q.gif" height="1" width="1" alt="" /><span style="color: transparent; font-size: 0; display: none; visibility: hidden; overflow: hidden; opacity: 0; width: 0; height: 0; max-width: 0; max-height: 0; mso-hide: all">Message ID: <span><kamailio/kamailio/issues/3229</span><span>@</span><span>github</span><span>.</span><span>com></span></span></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/kamailio/kamailio/issues/3229",
"url": "https://github.com/kamailio/kamailio/issues/3229",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>