Search code examples
sipsip-serverkamailio

Configure Kamailio to allow sip user from sending message to anyone but a specific user


We have a Kamailio SIP server up and running with authentication. Now we want that a SIP User say abc@localhost.com can only communicate to a specific SIP User say xyz@locahost.com and not to all other SIP users that are stored in a database table. I tried to find the solution, but could find a way to do it. Any help will be appreciated.

So scenario is:

SIP User 1 ---------------> SIP User 2 only and if SIP User 1 ---------------> SIP User 3 Access should be denied


Solution

  • You have to keep the relation between an user and what it can dial. One option is to create your own table in database and use sqlops to check it.

    Say the table (named dialrules) will have src and dst columns, to tell if src is allowed to call dst.

    Some sample records for alice to be allowed to call bob, carol, david:

    {src: "alice", dst: "bob"}
    {src: "alice", dst: "carol"}
    {src: "alice", dst: "david"}
    

    Then, when someone (alice) is calling, have a condition like:

    sql_query("ca", "select dst from dialrules where src='$fU' and dst='$rU'", "ra");
    if($dbr(ra=>rows)<=0) {
      # not allowed to dial this dst
      send_reply("404", "Dst forbidden");
      exit;
    }