Hi<br><div class="gmail_quote">
<div><br></div><div>I have an installation based on Daniel-Constantin Mierla&#39;s excellent Kamailio 3.3 / Asterisk 10 Realtime document (<a href="http://kb.asipto.com/asterisk:realtime:kamailio-3.3.x-asterisk-10.7.0-astdb" target="_blank">http://kb.asipto.com/asterisk:realtime:kamailio-3.3.x-asterisk-10.7.0-astdb</a>) but have come across an issue which is a potential problem.</div>


<div><br></div><div>In this installation all SIP clients register with Kamailio, and the registrations are forwarded to Asterisk. This means that all registered clients (stored in sipregs table) have the same IP address and Port: that of the Kamailio server. The &quot;secret&quot; which Asterisk reads is empty to avoid Asterisk issuing a challenge.</div>


<div><br></div><div>I have discovered that if a client successfully registers with Kamailio, but for whatever reason this user is not in the database Asterisk is accessing - say for example if two MySQL slaves are out of sync - and then sends an INVITE, Asterisk ends up picking the first user in sipregs which shares the same IP and Port as the incoming request and treats this as the Caller. Of course in our scenario there will be many of these because all clients are registered from Kamailio&#39;s IP/Port.</div>



<div><br></div><div>For example, here is the sequence of database queries Asterisk performs when a client with a From of 101864 attempts to make a call:</div><div><br></div><div><br></div><div><div>SELECT * FROM ast_sipusers WHERE name = &#39;101864&#39; AND host = &#39;dynamic&#39;</div>



<div>SELECT * FROM ast_sipusers WHERE name = &#39;101864&#39;</div><div>SELECT * FROM ast_sipusers WHERE host = &#39;10.5.76.67&#39; AND port = &#39;5060&#39; AND callbackextension = &#39;<a href="tel:014373500" value="+35314373500" target="_blank">014373500</a>&#39;</div>


<div><br></div>
<div>OK, the above are fine. Asterisk looks for a user, and a callback exten.</div><div><br></div><div>SELECT * FROM ast_sipusers WHERE host = &#39;10.5.76.67&#39; AND port = &#39;5060&#39;</div><div><br></div><div>Now Asterisk looks for a peer. Still OK.</div>



<div><br></div><div>SELECT * FROM ast_sipregs WHERE ipaddr = &#39;10.5.76.67&#39; AND port = &#39;5060&#39;</div><div><br></div><div>Here Asterisk is checking sipregs for ANY entry with the IP and Port of Kamailio. In this case it finds the first such user, 485833</div>



<div><br></div><div>SELECT * FROM ast_sipusers WHERE name = &#39;485833&#39;</div></div><div><br></div><div>Now Asterisk treats this call as if it was coming from 485833, which is totally wrong and very bad.</div><div><br>



</div><div>Does anyone know what I would need to do in order to ensure that Asterisk rejects the call attempt if it does not find an exact username match?</div><div><br></div><div><br></div><div>Thanks</div><span class="HOEnZb"><font color="#888888"><div>

<br clear="all">
<div>-Barry Flanagan<br><br><br><br><br><br></div>

</div>
</font></span></div><br>