On Wed, Apr 05, 2017 at 02:25:29PM +0200, Abdoul Osséni wrote:
The advantage of the SIP ping options is a bidirectional traffic through NAT. I think in this case, my issue will be solved.
Due to some limitations of the nat helper pinger (3 backends, one should ping at hh:mm:00, the other at hh:mm:20 and last at hh:mm:40) I decided to run my own external pinger process that sends OPTIONS to all registered users via kamailio (in my case via a loadbalancer based on path headers). Based on the $fU and source ip these requests are forwarded to the endpoints (in my example from path received header, in your case that may be just received (and transport for the tcp/tls clients) in contact).
kamailio.cfg option forwarding:
if(is_method("OPTIONS") && $fU=="pinger" && is_in_subnet($si, "127.0.0.0/8")) { record_route(); remove_hf("Route");
$avp(route)=$(hdr(Route)[0]); $avp(route)=$(avp(route){s.strip,1}); $avp(route)=$(avp(route){s.striptail,1}); $avp(received)=$(avp(route){uri.param,received}); $avp(received)=$(avp(received){s.unescape.param});
$du=$avp(received);
route(RELAY); exit; }
The options are generated with a php script:
if($res=mysql_query("select * from location order by rand()")) { while($row=mysql_fetch_assoc($res)) { usleep(1000); $branch=uniqid(); $dst=preg_replace('/.*@([^;]+);.*/',"$1",$row['path']); $dst=explode(':',$dst); if(count($dst)<2) { $dst[1]=5060; } $str=<<<EOS OPTIONS {$row['contact']} SIP/2.0\r Via: SIP/2.0/UDP 127.0.1.1:$listenport;branch=$branch;rport;alias\r Route: {$row['path']}\r From: sip:pinger@my.doma.in;tag={$row['ruid']}\r To: {$row['contact']}\r Call-ID: {$row['id']}-$listenport-$uid@localhost\r CSeq: 1 OPTIONS\r Content-Length: 0\r \r
EOS; socket_sendto($sock,$str,strlen($str),MSG_EOR,$dst[0],$dst[1]); } }