Setup Kamailio to accept only register request with FQDN and block IP request

217 Views Asked by At

I have set up Kamailio and am quite new to the process, I'm able to register with FQDN and IP directly to Kamailio but my main setup is Kamailio as edge proxy to asterisk to allow register only with FQDN and not IP ,using tls also, just for allowing registration with FQDN and relay all request directly to PBX.

route  
{ 
if (!is_domain("$hdr(Contact:user)")) 
{ 
sl_send_reply("403", "Forbidden"); 
exit;
} 
t_relay(); 
} 

I found this and implemented it on kamailio.cfg but not working, Appreciate to help point me in the right direction.

1

There are 1 best solutions below

2
arheops On

is_domain(is_domain_local in the currentr version) will match all domains of current host by default.

If your domain table is not set, it will be auto-discovery and IP also in the list.

You can give kamailio exact list of domain in table.

Another option is use regexp match.

pcre_match (string, pcre_regex)

Matches the given string parameter against the regular expression pcre_regex, which is compiled in runtime into a PCRE object. Returns TRUE if it matches, FALSE otherwise.

Meaning of the parameters is as follows:

    string - String or pseudo-variable to compare.

    pcre_regex - Regular expression to be compiled in a PCRE object. It can be a string or pseudo-variable.

NOTE: To use the "end of line" symbol '$' in the pcre_regex parameter use '$$'.

This function can be used from REQUEST_ROUTE, FAILURE_ROUTE, ONREPLY_ROUTE, BRANCH_ROUTE and LOCAL_ROUTE.

Example 1.8.  pcre_match usage (forcing case insensitive)

...
if (pcre_match("$ua", "(?i)^twinkle")) {
    xlog("L_INFO", "User-Agent matches\n");
}
...