[sr-dev] [kamailio/kamailio] topos module producing invalid SIP message (missing Via header) when handling 200 OK to OPTIONS request (#1350)

George Diamantopoulos notifications at github.com
Sun Dec 3 02:01:35 CET 2017


Hello all,

I've come across the following issue with topos on Kamailio 5.1.0-rc2.

### Description
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).

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.

### Troubleshooting

#### Reproduction
Configure a peer in asterisk with outboundproxy option set to kamailio's IP address. Set qualify=yes.

Adjust kamailio's default configuration so that OPTIONs to other hosts besides itself are routed. Change the following section in request_route:

```
if ($rU==$null) {
		# request with no Username in RURI
		sl_send_reply("484","Address Incomplete");
		exit;
}
```
to:
```
        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);
        }
```

Enable and configure the topos module with database.

#### SIP Traffic

asterisk:5060 -> kamailio:5060                         
```
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 at domain.tld>;tag=as690c2406                     
To: <sip:peer.domain.tld>
Contact: <sip:asterisk at asterisk:5060>                                                   
Call-ID: 6548f43b2d8740122186bb0c6e72ac78 at 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
```
kamailio:5060 -> peer:5060
```
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 at domain.tld>;tag=as690c2406                     
To: <sip:peer.domain.tld>
Contact: <sip:asterisk at asterisk:5060>                                                   
Call-ID: 6548f43b2d8740122186bb0c6e72ac78 at 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
```
peer:5060 -> kamailio:5060
```
SIP/2.0 200 OK
Via: SIP/2.0/UDP kamailio;branch=z9hG4bKda8d.cc03bd2def8ad36e8c43f61ab31a636f.0;received=kamailio;rport=5060
From: "asterisk" <sip:asterisk at domain.tld>;tag=as690c2406
To: <sip:peer.domain.tld>;tag=as472874ee
Call-ID: 6548f43b2d8740122186bb0c6e72ac78 at 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
```
**kamailio:5060 -> asterisk:5060: Missing Via Header**
```
SIP/2.0 200 OK
From: "asterisk" <sip:asterisk at domain.tld>;tag=as690c2406
To: <sip:peer.domain.tld>;tag=as472874ee
Call-ID: 6548f43b2d8740122186bb0c6e72ac78 at 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
```
### Additional Information

  * **Kamailio Version** - output of `kamailio -v`

```
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
```

* **Operating System**:

```
Debian 9.1
```

* **Other pertinent configuration information**:
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.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/kamailio/kamailio/issues/1350
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.kamailio.org/pipermail/sr-dev/attachments/20171203/3473ed10/attachment-0001.html>


More information about the sr-dev mailing list