Hi list,
Hope you are all well!

I'm using Kamailio version 5.6.4 (installed from the repo
rpm.kamailio.org/centos/7) and noticed that every route that uses "return
false" is exiting the script, instead of returning.... This was not the
case on version 5.4.6 as the same script is running fine.....
>From this page
https://www.kamailio.org/wikidocs/tutorials/faq/main/#how-is-the-function-return-code-evaluated,
I would think that when a route returns false, it would return -1 and not
stop execution, since negative is equal to false, but it is actually
stopping (same as return 0)...
So, as an example, this test code doesn't work as expected. In case the
source is a public IP, the script doesn't print the "SRC public" it just
exits and then of course every other logic meant to be done is not
executed....

route[is_src_private]
{
        if (is_ip_rfc1918("$si")) {
                return true;
        }
        return false;
        #return is_ip_rfc1918("$si"); *# this doesn't work too in case the
$si is a public IP*
}
request_route
{
...
        if (route(is_src_private)) {
                xlog("L_NOTICE", "SRC private\n");
        } else {
                xlog("L_NOTICE", "SRC public\n");
        }
...
}
If is_src_private is changed to return -1 instead of false, then it all
works fine.

Also, I noticed that the following code will print "TEST: 0" in case the
$si is public and then stop execution. So looks like false is really being
converted to 0, but I guess that's unexpected... anyway apologies if I'm
missing something obvious....
route[is_src_private]
{
        $var(t) = false;
        if (is_ip_rfc1918("$si")) {
                $var(t) = true;
        }
        xlog("L_ERR", "TEST: $var(t)\n");
        return $var(t);
}

I could not find a recent ticket or email related to this situation and
I've already spent hours trying to understand what is the logic/problem
here, so would anyone have been across a similar case that could provide
some insight and clarify what is the expected behaviour of the *false*
usage (and boolean in general if possible)?

Thank you,
Kind regards,
Patrick Wakano
__________________________________________________________
Kamailio - Users Mailing List - Non Commercial Discussions
To unsubscribe send an email to sr-users-le...@lists.kamailio.org
Important: keep the mailing list in the recipients, do not reply only to the 
sender!
Edit mailing list options or unsubscribe:

Reply via email to