Hi.
I try to use Kamailio 4.1 git version as registrar and PSTN gw.
Need accept register from users. Its OK, I made it and use save() function - from keep registrations in case of kamailio restart.
Need forward calls to gw, but only for registered users. If I understand correctly in INVITE enough check registered("location"), isnt it? but it's not work, i need verify auth again.
Routing part of my config:
route { # initial sanity checks - skip in letter
# We are registrar!
if (is_method("REGISTER")) { sl_send_reply("100", "Trying"); # send "Trying, dont threat on me if(isflagset(FLT_NATS)) { setbflag(FLB_NATB); # uncomment next line to do SIP NAT pinging ## setbflag(FLB_NATSIPPING); }
# we must check auth right now # WORK: if (!www_authorize("$fd", "subscriber")) if (!auth_check("$fd", "subscriber", "1")) { # WORK: www_challenge("$fd", "0"); auth_challenge("$fd", "0"); # send me requisites plz exit; } else { # ok. auth accepted, save in location if (save("location")) #if (save("location","0x04","$fd")) { xlog("L_WARN", "Save OK in location sip:$au@$fd"); } else { xlog("L_WARN", "Save FAIL in location sip:$au@$fd"); } }
xlog("L_WARN", "REGISTERED method done"); exit; }
if (is_method("INVITE")) { if ($si == $sel(cfg_get.pstn.gw_ip)) { # incoming calls xlog("L_WARN", "Incoming call"); } else { # outgoing calls
xlog("L_WARN", "Outgoing call"); # check auth # we must check auth right now
if (!proxy_authorize("$fd", "subscriber")) { proxy_challenge("$fd", "0"); exit; }
consume_credentials();
### THAT FUNCTIONS ALWAYS WRITE IN LOGS # "!registered" "!lookup" for both registered and unregged users
# if (!registered("location")) xlog("L_WARN","!registered"); # if (!lookup("location")) xlog("L_WARN", "!lookup");
# number change - FIX late # check may be used dialplan automatically?
# route $ru = "sip:" + $rU + "@" + $sel(cfg_get.pstn.gw_ip); xlog("L_WARN", "Rewrite to $ru, send to PSTN."); if (!t_relay()) { sl_reply_error(); } }
} else { # reply 2 keepalive and drop all # if (!t_relay()) { sl_reply_error(); } }
}
Hello,
do you want to check if caller (origin) is registered or if callee (destination) is registered? Like one can call to pstn only if has a phone registered for itself?
Or you want to say that you want to forward to gateway only for registered users. But maybe you want for local subscribers.
Cheers, Daniel
On 3/12/13 3:04 PM, Victor V. Kustov wrote:
Hi.
I try to use Kamailio 4.1 git version as registrar and PSTN gw.
Need accept register from users. Its OK, I made it and use save() function - from keep registrations in case of kamailio restart.
Need forward calls to gw, but only for registered users. If I understand correctly in INVITE enough check registered("location"), isnt it? but it's not work, i need verify auth again.
Routing part of my config:
route { # initial sanity checks - skip in letter
# We are registrar!
if (is_method("REGISTER")) { sl_send_reply("100", "Trying"); # send "Trying, dont threat on me if(isflagset(FLT_NATS)) { setbflag(FLB_NATB); # uncomment next line to do SIP NAT pinging ## setbflag(FLB_NATSIPPING); } # we must check auth right now # WORK: if (!www_authorize("$fd", "subscriber")) if (!auth_check("$fd", "subscriber", "1")) { # WORK: www_challenge("$fd", "0"); auth_challenge("$fd", "0"); # send me requisites plz exit; } else { # ok. auth accepted, save in location if (save("location")) #if (save("location","0x04","$fd")) { xlog("L_WARN", "Save OK in location sip:$au@$fd"); } else { xlog("L_WARN", "Save FAIL in location sip:$au@$fd"); } } xlog("L_WARN", "REGISTERED method done"); exit; } if (is_method("INVITE")) { if ($si == $sel(cfg_get.pstn.gw_ip)) { # incoming calls xlog("L_WARN", "Incoming call"); } else { # outgoing calls xlog("L_WARN", "Outgoing call"); # check auth # we must check auth right now if (!proxy_authorize("$fd", "subscriber")) { proxy_challenge("$fd", "0"); exit; } consume_credentials();
### THAT FUNCTIONS ALWAYS WRITE IN LOGS # "!registered" "!lookup" for both registered and unregged users
# if (!registered("location")) xlog("L_WARN","!registered"); # if (!lookup("location")) xlog("L_WARN", "!lookup");
# number change - FIX late # check may be used dialplan automatically? # route $ru = "sip:" + $rU + "@" + $sel(cfg_get.pstn.gw_ip); xlog("L_WARN", "Rewrite to $ru, send to PSTN.");
if (!t_relay()) { sl_reply_error(); } }
} else { # reply 2 keepalive and drop all # if (!t_relay()) { sl_reply_error(); } }
}
Hello, Daniel. Thanks for reply.
do you want to check if caller (origin) is registered or if callee (destination) is registered? Like one can call to pstn only if has a phone registered for itself?
In our scheme all calls forwards to PSTN GW, if that call from our to our users, GW turn call back and kamailio receive it as incoming. So, no "local calls" in this scheme.
For outgoing calls (to PSTN) i want check caller (origin) is registered. For incoming calls (from PSTN) i want callee is registered.
Need cache registrations (DB, memcached or something). I try that way: 1. REGISTER - if ok, than we save("location"). 2. Other methods - check !registered("location") or !lookup("location"). But in INVITE seems both !registered("location") and !lookup("location") return TRUE. I dont understand why.
In topicstart letter i citate part of my cfg: in INVITE i check registration again and it work - registered users may call to PSTN, unregged may not. But no cache for registration and look as overhead. Must be more "beauty" solution.
Hello,
On 3/13/13 10:00 AM, Victor V. Kustov wrote:
Hello, Daniel. Thanks for reply.
do you want to check if caller (origin) is registered or if callee (destination) is registered? Like one can call to pstn only if has a phone registered for itself?
In our scheme all calls forwards to PSTN GW, if that call from our to our users, GW turn call back and kamailio receive it as incoming. So, no "local calls" in this scheme.
For outgoing calls (to PSTN) i want check caller (origin) is registered. For incoming calls (from PSTN) i want callee is registered.
Need cache registrations (DB, memcached or something). I try that way:
- REGISTER - if ok, than we save("location").
- Other methods - check !registered("location") or !lookup("location").
But in INVITE seems both !registered("location") and !lookup("location") return TRUE. I dont understand why.
In topicstart letter i citate part of my cfg: in INVITE i check registration again and it work - registered users may call to PSTN, unregged may not. But no cache for registration and look as overhead. Must be more "beauty" solution.
when you need to check if caller is registered use:
- registered("location", "$fu") See more details at: - http://kamailio.org/docs/modules/stable/modules/registrar.html#id2512620
If used without the second parameter is checking if R-URI ($ru) is registered.
Cheers, Daniel