<p>Hello all,</p>
<p>I've come across the following issue with topos on Kamailio 5.1.0-rc2.</p>
<h3>Description</h3>
<p>Kamailio acts as a proxy for asterisk instances residing in a private IP range. Asterisk's peers are configured with their public IP address or hostname, but asterisk will dispatch requests to them to kamailio instead (because kamailio's IP is set in outboundproxy option in peer definition).</p>
<p>This works fine for INVITEs, but if qualify=yes is set for the peer, asterisk will send out OPTIONs to monitor these peers. If the topos module is loaded, 200 OK replies to these OPTIONs will be malformed when forwarded from kamailio to asterisk (no Via header present). Disabling the topos module will resolve this.</p>
<h3>Troubleshooting</h3>
<h4>Reproduction</h4>
<p>Configure a peer in asterisk with outboundproxy option set to kamailio's IP address. Set qualify=yes.</p>
<p>Adjust kamailio's default configuration so that OPTIONs to other hosts besides itself are routed. Change the following section in request_route:</p>
<pre><code>if ($rU==$null) {
                # request with no Username in RURI
                sl_send_reply("484","Address Incomplete");
                exit;
}
</code></pre>
<p>to:</p>
<pre><code>        if ( ($rU==$null) && !(is_method("OPTIONS")) ) {
            # request with no Username in RURI
            sl_send_reply("484","Address Incomplete");
            exit;
        }

        # Permit asterisk's monitoring using options
        if(is_method("OPTIONS") && uri!=myself) {
            route(RELAY);
        }
</code></pre>
<p>Enable and configure the topos module with database.</p>
<h4>SIP Traffic</h4>
<p>asterisk:5060 -> kamailio:5060</p>
<pre><code>OPTIONS sip:peer.domain.tld SIP/2.0                                                              
Via: SIP/2.0/UDP asterisk:5060;branch=z9hG4bK460330cf;rport
Max-Forwards: 70
From: "asterisk" <sip:asterisk@domain.tld>;tag=as690c2406                     
To: <sip:peer.domain.tld>
Contact: <sip:asterisk@asterisk:5060>                                                   
Call-ID: 6548f43b2d8740122186bb0c6e72ac78@domain.tld
CSeq: 102 OPTIONS
User-Agent: myUA
Date: Sun, 03 Dec 2017 00:39:38 GMT
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
Content-Length: 0
</code></pre>
<p>kamailio:5060 -> peer:5060</p>
<pre><code>OPTIONS sip:peer.domain.tld SIP/2.0                                                              
Via: SIP/2.0/UDP kamailio:5060;branch=z9hG4bK460330cf;rport
Max-Forwards: 69
From: "asterisk" <sip:asterisk@domain.tld>;tag=as690c2406                     
To: <sip:peer.domain.tld>
Contact: <sip:asterisk@asterisk:5060>                                                   
Call-ID: 6548f43b2d8740122186bb0c6e72ac78@domain.tld
CSeq: 102 OPTIONS
User-Agent: myUA
Date: Sun, 03 Dec 2017 00:39:38 GMT
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
Content-Length: 0
</code></pre>
<p>peer:5060 -> kamailio:5060</p>
<pre><code>SIP/2.0 200 OK
Via: SIP/2.0/UDP kamailio;branch=z9hG4bKda8d.cc03bd2def8ad36e8c43f61ab31a636f.0;received=kamailio;rport=5060
From: "asterisk" <sip:asterisk@domain.tld>;tag=as690c2406
To: <sip:peer.domain.tld>;tag=as472874ee
Call-ID: 6548f43b2d8740122186bb0c6e72ac78@domain.tld
CSeq: 102 OPTIONS
Server: myUA
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
Contact: <sip:peer:5060>
Accept: application/sdp
Content-Length: 0
</code></pre>
<p><strong>kamailio:5060 -> asterisk:5060: Missing Via Header</strong></p>
<pre><code>SIP/2.0 200 OK
From: "asterisk" <sip:asterisk@domain.tld>;tag=as690c2406
To: <sip:peer.domain.tld>;tag=as472874ee
Call-ID: 6548f43b2d8740122186bb0c6e72ac78@domain.tld
CSeq: 102 OPTIONS
Server: myUA
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
Contact: <sip:peer:5060>
Accept: application/sdp
Content-Length: 0
</code></pre>
<h3>Additional Information</h3>
<ul>
<li><strong>Kamailio Version</strong> - output of <code>kamailio -v</code></li>
</ul>
<pre><code>version: kamailio 5.1.0-rc2 (x86_64/linux) 
flags: STATS: Off, USE_TCP, USE_TLS, USE_SCTP, TLS_HOOKS, DISABLE_NAGLE, USE_MCAST, DNS_IP_HACK, SHM_MEM, 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_BLACKLIST, HAVE_RESOLV_RES
ADAPTIVE_WAIT_LOOPS=1024, MAX_RECV_BUFFER_SIZE 262144, MAX_LISTEN 16, 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
</code></pre>
<ul>
<li><strong>Operating System</strong>:</li>
</ul>
<pre><code>Debian 9.1
</code></pre>
<ul>
<li><strong>Other pertinent configuration information</strong>:<br>
This kamailio box has several network interfaces. mhomed is not used, instead force_send_socket is called where necessary. I'm mentioning this in case it's what might trigger this issue with topos.</li>
</ul>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/kamailio/kamailio/issues/1350">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AF36ZTAOHGXlY2PseAkrYYzpwHO44KLSks5s8fLugaJpZM4Qzia_">mute the thread</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/AF36ZeeZ65v0IbVYXjOa4pYLkod5bT2Bks5s8fLugaJpZM4Qzia_.gif" width="1" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
<div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
  <link itemprop="url" href="https://github.com/kamailio/kamailio/issues/1350"></link>
  <meta itemprop="name" content="View Issue"></meta>
</div>
<meta itemprop="description" content="View this Issue on GitHub"></meta>
</div>

<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/kamailio/kamailio","title":"kamailio/kamailio","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/kamailio/kamailio"}},"updates":{"snippets":[{"icon":"DESCRIPTION","message":"topos module producing invalid SIP message (missing Via header) when handling 200 OK to OPTIONS request (#1350)"}],"action":{"name":"View Issue","url":"https://github.com/kamailio/kamailio/issues/1350"}}}</script>