Hi Aidar,
I believe $rc is the return code of the last function called (ref https://www.kamailio.org/wiki/cookbooks/4.4.x/pseudovariables#rc_-_returned_code)

In your example you call xwarn() and then test $rc… so by the time you test $rc it is no longer the result of the lookup() function.

Try storing $rc in a $var before calling xwarn() instead and see if it works the way you expect it to:
        if (!lookup("location")) {
                $var(rc) = $rc;
                xwarn("method ($rm) r-uri ($ru)\n");   ################## HERE ##########################
               
                route(TOVOICEMAIL);
                t_newtran();
                switch ($var(rc)) {
                        case -1:
                        case -3:
                                send_reply("404", "Not Found");
                                exit;
                        case -2:
                                send_reply("405", "Method Not Allowed");
                                exit;
                }
        }

Paul Smith