Hello, I have a problem which I am not sure the best way to solve with Kamailio. I have many asterisk servers which use Kamailio as their outbound gateway to route calls to the PSTN. This works great, I use the LCR engine to control routing.
What I want to do is have the ability to dial a random SIP URI from my asterisk servers, but route the call through my Kamailio server for accounting and security purposes. My asterisk servers are not allowed SIP messaging from anything other than my Kamailio gateway. What I am considering doing is something like this:
Since asterisk is fairly limited in your ability to route calls, I need to do a little magic to make the call route through a proxy. Maybe I'm wrong, but I haven't yet been able to figure it out. My theory is that I will add a special header at the asterisk level and send the invite to Kamailio.
[test] exten => 1,1,SipAddHeader("P-Forward-URI: bob@somedomain.com") exten => 1,n,Dial(SIP/forward@kamailio,30)
[From Asterisk To Kamailio] INVITE sip:forward@10.1.1.1 SIP/2.0 Via: SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bK776asdhds Max-Forwards: 70 To: sip:forward@10.1.1.1 From: "" sip:5555551212@pc33.atlanta.com;tag=1928301774 Call-ID: a84b4c76e66710@pc33.atlanta.com CSeq: 314159 INVITE Contact: sip:5555551212@pc33.atlanta.com Content-Type: application/sdp Content-Length: 142 P-Forward-URL: bob@somedomain.com
if(is_present_hf("P-Forward-URL")){ //what do i do here to rewrite the To and INVITE parts before doing record_route() and t_relay() }
Maybe I'm totally off track here, but this is all I have come up with so far! Perhaps there is a mechanism in SIP which already allows me to do this, and I don't know about it... I don't know what I don't know :)
Thanks, Geoff
2009/3/7 Geoffrey Mina geoffreymina@gmail.com:
P-Forward-URL: bob@somedomain.com
Use the estandar "Route" header instead of a custom one. You will need no code in Kamailio to handle it (it wll be done automatically): When a proxy receives a request with a Route header: - It must inspect if the URI into the Route header is the proxy itself. If so, remove it and route the request based on the following Route header (if present) or on the RURI. If there is no Route header then route the request based on the RURI.
if(is_present_hf("P-Forward-URL")){ //what do i do here to rewrite the To and INVITE parts before doing record_route() and t_relay() }
You don't need it, just do loose_route() and insert before Route header (in Asterisk) with an URI poinitng to the gateway address.
Maybe I'm totally off track here, but this is all I have come up with so far! Perhaps there is a mechanism in SIP which already allows me to do this, and I don't know about it... I don't know what I don't know :)
Yes, there is: Route header :)
Hello,
On 03/07/2009 06:13 PM, Geoffrey Mina wrote:
Hello, I have a problem which I am not sure the best way to solve with Kamailio. I have many asterisk servers which use Kamailio as their outbound gateway to route calls to the PSTN. This works great, I use the LCR engine to control routing.
What I want to do is have the ability to dial a random SIP URI from my asterisk servers, but route the call through my Kamailio server for accounting and security purposes. My asterisk servers are not allowed SIP messaging from anything other than my Kamailio gateway. What I am considering doing is something like this:
Since asterisk is fairly limited in your ability to route calls, I need to do a little magic to make the call route through a proxy. Maybe I'm wrong, but I haven't yet been able to figure it out. My theory is that I will add a special header at the asterisk level and send the invite to Kamailio.
[test] exten => 1,1,SipAddHeader("P-Forward-URI: bob@somedomain.com") exten => 1,n,Dial(SIP/forward@kamailio,30)
[From Asterisk To Kamailio] INVITE sip:forward@10.1.1.1 SIP/2.0 Via: SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bK776asdhds Max-Forwards: 70 To: sip:forward@10.1.1.1 From: "" sip:5555551212@pc33.atlanta.com;tag=1928301774 Call-ID: a84b4c76e66710@pc33.atlanta.com CSeq: 314159 INVITE Contact: sip:5555551212@pc33.atlanta.com Content-Type: application/sdp Content-Length: 142 P-Forward-URL: bob@somedomain.com
if(is_present_hf("P-Forward-URL")){ //what do i do here to rewrite the To and INVITE parts before doing record_route() and t_relay() }
Maybe I'm totally off track here, but this is all I have come up with so far! Perhaps there is a mechanism in SIP which already allows me to do this, and I don't know about it... I don't know what I don't know :)
IIRC, Asterisk has a mechanism to specify the outbound proxy.
Anyhow, what you do is ok and you can take the uri from the particular header, add it to R-RUI and remove the header. The problem is in rewriting the To, but you should not need this if the callee is RFC3261. Rewriting To header must be avoided as much as possible.
Cheers, Daniel