Hi all,
Got another anomaly in 4.1.5. I have this block of code which does
t_relay_tcp:
if ($var(isTpgw) == 1)
{
xlog("L_INFO","[$ci][$mi][CSeq $cs] isTpgw = $var(isTpgw)");
if (!t_relay_to_tcp())
{
xlog("L_INFO","[$ci][$mi][CSeq $cs] $ua Relaying
[$rm] from ($si) to ($rd) via tcp....Error...\n");
t_on_failure("DISPATCHER_FAIL");
}
else
{
xlog("L_INFO","[$ci][$mi][CSeq $cs] $ua Relaying
[$rm] from ($si) to ($rd) via tcp\n");
}
}
But when I looked at my sip capture tool, it showed the Via marked by the
Kam to use UDP:
INVITE sip:######@<some domain>:5060 SIP/2.0
Record-Route: <sip:206.81.191.30;r2=on;lr=on>
Record-Route: <sip:206.81.191.30;transport=tcp;r2=on;lr=on>
Call-ID: DL9dc0c8dd93-1079779342(a)gs-3924.GSLAB.COM
To: "sip:6204857@sjomaintpsg50.fuzemeeting.com"
<sip:6204857@sjomaintpsg50.fuzemeeting.com>
From: "LifesizeSIP"
<sip:LifesizeSIP@gs-3924.GSLAB.COM:5060>;tag=DL325a9e10c7;epid=062EE468
CSeq: 1 INVITE
Max-Forwards: 69
Via: SIP/2.0/UDP
206.81.191.30;branch=z9hG4bKb16b.bd6a0791c798e3c859f8608993d584ae.1;i=5611
Via: SIP/2.0/TCP 10.101.199.105:5060;rport=53272;branch=z9hG4bK-fc8090ecf8-DL
206.81.191.30 is the Kam.
I also log the activity as seen in the code with those xlog:
Apr 11 19:38:37 sjomaintpsg50 /usr/local/sbin/kamailio[16348]: INFO:
<script>: [DL9dc0c8dd93-1079779342(a)gs-3924.GSLAB.COM][42][CSeq 1] isTpgw = 1
Apr 11 19:38:37 sjomaintpsg50 /usr/local/sbin/kamailio[16348]: INFO:
<script>: [DL9dc0c8dd93-1079779342(a)gs-3924.GSLAB.COM][42][CSeq 1] LifeSize
Softphone 8.1.12 (Windows) Relaying [INVITE] from (10.101.19
9.105) to (206.81.191.72) via tcp
So why did the Kamailio mark the Via header on the outgoing INVITE UDP?
--
Andy Chen
Sr. Telephony Lead Engineer
achen@ <achen(a)thinkingphones.com>fuze.com
--
*Confidentiality Notice: The information contained in this e-mail and any
attachments may be confidential. If you are not an intended recipient, you
are hereby notified that any dissemination, distribution or copying of this
e-mail is strictly prohibited. If you have received this e-mail in error,
please notify the sender and permanently delete the e-mail and any
attachments immediately. You should not retain, copy or use this e-mail or
any attachment for any purpose, nor disclose all or any part of the
contents to any other person. Thank you.*
When a client sends a SUBSCRIBE with Expires: 0, Kamailio responds correctly with a "202 OK".
But then Kamailio sends a NOTIFY to the same client with "Subscription-State: terminated;reason=timeout".
The client rejects this NOTIFY with a "481 Dialog/Transaction Does Not Exist".
Why does Kamailio send this NOTIFY, and is there any way to fix or disable it because it's always rejected by the client?
The client is IMSDroid, and Kamailio is 5.2.2 with a default configuration.
Packet 1 = Client sending SUBSCRIBE with Expires: 0
SUBSCRIBE sip:X.X.X.X:443;transport=tcp SIP/2.0Via: SIP/2.0/TCP 192.168.0.21:45336;branch=z9hG4bK-670576127From: <sip:username@domain.com>;tag=1372208921To: <sip:kamailio.domain.com>;tag=c4eb72dabf44e7588b972bd3b454ea11-0cd6Contact: <sip:username@192.168.0.21:45336;transport=tcp>Call-ID: e8cffa8f-948d-eb99-69ca-c9f18bdf11a0CSeq: 1321654295 SUBSCRIBEExpires: 0Content-Length: 299Max-Forwards: 70Allow: INVITE, ACK, CANCEL, BYE, MESSAGE, OPTIONS, NOTIFY, PRACK, UPDATE, REFERAccept: application/pidf+xmlEvent: presence
Packet 2 = Kamailio responding with 202 OK
SIP/2.0 202 OKVia: SIP/2.0/TCP 192.168.0.21:45336;branch=z9hG4bK-670576127From: <sip:username@domain.com>;tag=1372208921To: <sip:kamailio@domain.com>;tag=c4eb72dabf44e7588b972bd3b454ea11-0cd6Call-ID: e8cffa8f-948d-eb99-69ca-c9f18bdf11a0CSeq: 1321654295 SUBSCRIBEExpires: 0Contact: <sip:X.X.X.X:443;transport=tcp>Server: kamailio (5.2.2 (x86_64/linux))Content-Length: 0
Packet 3 = Kamailio sending a NOTIFY
NOTIFY sip:username@192.168.0.21:45336;transport=tcp SIP/2.0Via: SIP/2.0/TCP X.X.X.X:443;branch=z9hG4bKefe7.5f8ec435000000000000000000000000.0To: <sip:username@domain.com>;tag=1372208921From: <sip:kamailio@domain.com>;tag=c4eb72dabf44e7588b972bd3b454ea11-0cd6CSeq: 3 NOTIFYCall-ID: e8cffa8f-948d-eb99-69ca-c9f18bdf11a0Content-Length: 0Max-Forwards: 70Event: presenceContact: <sip:X.X.X.X:443;transport=tcp>Subscription-State: terminated;reason=timeout
Packet 4 = Client responding to the NOTIFY with "481 Dialog/Transaction Does Not Exist"
SIP/2.0 481 Dialog/Transaction Does Not ExistVia: SIP/2.0/TCP X.X.X.X:443;branch=z9hG4bKefe7.5f8ec435000000000000000000000000.0From: <sip:kamailio@domain.com>;tag=c4eb72dabf44e7588b972bd3b454ea11-0cd6To: <sip:username@domain.com>;tag=1372208921Call-ID: e8cffa8f-948d-eb99-69ca-c9f18bdf11a0CSeq: 3 NOTIFYContent-Length: 0
There are two entries in the Kamailio log:
INFO: {1 1321654295 SUBSCRIBE e8cffa8f-948d-eb99-69ca-c9f18bdf11a0} presence [notify.c:1614]: send_notify_request(): NOTIFY sip:username@domain.com via sip:Y.Y.Y.Y:45336;transport=tcp on behalf of sip:kamailio.domain.com for event presence : e8cffa8f-948d-eb99-69ca-c9f18bdf11a0
ERROR: {2 3 NOTIFY e8cffa8f-948d-eb99-69ca-c9f18bdf11a0} presence [subscribe.c:497]: delete_subs(): Failed to delete subscription from memory [slot: 174 ev: sip:kamailio.domain.com pu: presence ci: e8cffa8f-948d-eb99-69ca-c9f18bdf11a0 ft: 1372208921 tt: c4eb72dabf44e7588b972bd3b454ea11-0cd6]
These are the presence settings in the Kamailio config file:
#!ifdef WITH_PRESENCE# ----- presence params -----modparam("presence", "db_url", DBURL)modparam("presence", "send_fast_notify", 0)
# ----- presence_xml params -----modparam("presence_xml", "db_url", DBURL)modparam("presence_xml", "force_active", 1)modparam("presence_xml", "force_dummy_presence", 0)#!endif
Appreciate your help.
Hello all,
I am dealing with a no audio issue, phones are not even ringing. There is a
private IP address in the "VIA" section of the message header of the INVITE:
Via: SIP/2.0/UDP 192.168.1.25:65291
;rport;branch=z9hG4bKPj9e3849d1981a4094a8323dad5826ec34
and in the contact too:
Contact: <sip:5002@192.168.1.25:65291;ob>
In the "status 100 Attempting to connect your call" from the server, I can
see the public IP of the phone under received:
Via: SIP/2.0/UDP 192.168.1.25:65291
;rport=53990;branch=z9hG4bKPj9e3849d1981a4094a8323dad5826ec34;received=PHONE_PUBLIC_IP
And in the "status 200 ok" from the server, I have:
Via: SIP/2.0/UDP 192.168.1.25:65291
;received=PHONE_PUBLIC_IP;rport=53990;branch=z9hG4bKPj9e3849d1981a4094a8323dad5826ec34
Record-Route:
<sip:SERVER_PUBLIC_IP;lr=on;ftag=9284528256a54f8b81e692133a15684c>
I don't know what steps to take to resolve this issue.
hello dears
i'm trying to build kamailio & asterisk with the following :
* Kamailio will listen to All the interfaces :
listen=udp:0.0.0.0:5050
listen=udp:0.0.0.0:5060
* it will add the record header as in the following part :
if (!isflagset(FLT_RR)) record_route();
setflag(FLT_RR);
when the sip message get from kamailio to asterisk the record route header will be like "<sip:0.0.0.0:5060;....etc.>"
So is there any way to make the Via and record route headers has a specific IP instead of (0.0.0.0) i mean Something like "record_route("$Ri")".
thanks & regards
HI
this is Gaurav
im using kamailio 5.1.2 on ubuntu 18.4
i want to change kamailio SIP port 5060 to other port for security purpose
plz help me
--
*Regards:*
Gaurav Kumar
Hi Again,
Here is an issue with TCP connection being kept for more:
Yesterday, I have discovered that a User-Agent (<Avaya IP Phone 1120E
(SIP1120e.04.04.30.00)> tried to register a lot. It was sending REGISTER
over new established TCP socket *every 2 seconds*.
All the REGISTER was rejected with 401. (may be the device was
misconfigured? or not receiving any of my answer? I can't tell)
NOTE: You can see the expires header was very large: 86400, ie: 24 hours...
I was checking the TCP/TLS connections on my server and discovered more
than 1000 TCP established connection to that user/ip, and thus, I have
tried to understand what happened.
Checking the logs, I received 4855 REGISTER from this device from "Mar 25
03:47:09" to "Mar 25 07:56:13" which is a rate of approx one new TCP
connection every 2.5 seconds...
Today, I decided to check it again around 11am.
jack@sip:~$ sudo kamctl stats tcp
{
"jsonrpc": "2.0",
"result": [
"tcp:con_reset = 1857",
"tcp:con_timeout = 35927",
"tcp:connect_failed = 25",
"tcp:connect_success = 2",
"tcp:current_opened_connections = 2291",
"tcp:current_write_queue_size = 0",
"tcp:established = 80778",
"tcp:local_reject = 0",
"tcp:passive_open = 80776",
"tcp:send_timeout = 2",
"tcp:sendq_full = 0"
],
"id": 7305
}
There was still A LOT of established connections. And the connections have
been established more than 24 hours ago.
At 11H16:
$> lsof -n -l | grep kamailio | grep TCP | grep 41.234.242.69 | grep ESTA |
wc -l
1161
At 11H22:
$> lsof -n -l | grep kamailio | grep TCP | grep 41.234.242.69 | grep ESTA |
wc -l
1018
At 11H35:
$> lsof -n -l | grep kamailio | grep TCP | grep 41.234.242.69 | grep ESTA |
wc -l
655
At 13H
$> lsof -n -l | grep kamailio | grep TCP | grep 41.234.242.69 | grep ESTA |
wc -l
0
So the established connections are all gone now.
Between 11h16 and 11H35, I was seeing the server regularly sending [FIN,
ACK] over each TCP established connection, with retransmissions for all of
them. (no incoming trafic)
I do not have numbers/capture/stats, but I think that kamailio was already
closing some
connection yesterday. I don't know when kamailio started to try closing
those connections.
I'm now back with this status:
At 13pm:
jack@sip:~$ sudo kamctl stats tcp
{
"jsonrpc": "2.0",
"result": [
"tcp:con_reset = 1896",
"tcp:con_timeout = 38042",
"tcp:connect_failed = 26",
"tcp:connect_success = 2",
"tcp:current_opened_connections = 939",
"tcp:current_write_queue_size = 0",
"tcp:established = 81950",
"tcp:local_reject = 0",
"tcp:passive_open = 81948",
"tcp:send_timeout = 2",
"tcp:sendq_full = 0"
],
"id": 12734
}
With around 155 registration entries using TCP and TLS in my location
database.
As you can see, tcp:current_opened_connections = 939 is still pretty high
compared to
my currently registred users.
I have "modparam("registrar", "max_expires", 86400)", because I'm keeping
contact entries (even with TCP connection down) for push notifications.
I have "tcp_connection_lifetime=3600" configured.
Question 1
With "tcp_connection_lifetime=3600", I would expect kamailio to close the
established connection after 3600 seconds without traffic. It is pretty
obvious that no data has been exchanged over the 4855 established
connection during a day.
Despite the issue with the Avaya phones is solved automatically after a
day, I guess similar stuff or happening, at a different rate, for other
users as well. (because current_opened_connections is way higher than
registred TCP/TLS users)
Question 2
I can list TLS connection with "kamctl rpc tls.list"
Can I get a similar list for TCP? (lsof returns a lot of duplicates...)
Tks
Aymeric
--
Antisip - http://www.antisip.com
Greetings,
Is there a difference for Kamailio between these 2 situations.
1 - Method with 2 Route Headers, each one with one address and one uri
2 - Method with 1 Route Header that includes 2 Route URI
Best Regards,
Duarte Rocha
HI
this is Gaurav
im using kamailio 5.1.2 on ubuntu 18.4
i wan to implement user based calling on kamailio , that only can call how
registered with user
plz help
--
*Regards:*
Gaurav Kumar
Hi all,
I'm building an automated load testing system for an rtp media server with TURN that uses Kamailio for SIP.
When a client sends an INVITE to Kamailio, I need Kamailio to respond with "200 OK" and the SDP generated by rtpengine.
I've enabled auto-answer in the client, so as soon as it receives the response from Kamailio it will start sending RTP packets.
Right now I'm using send_reply("200", "OK"); which is sending the right 200 response back to the client, but it doesn't include any body.
How can I get Kamailio to send a "200 OK" and add the rtpengine_answer into the body?
Appreciate any help, I've been struggling with this for three days.
Cheers.
rtpengine_offer("SIP-source-address ICE=force-relay RTP");send_reply("200", "OK");
Hi all,
I've the following infrastructure
(fake IPs)
62.128.128.68 (Telco SBC Inbound)
|
|
10.19.139.66 (Kamailio + RTPEngine)
|
|
10.19.139.69 (Asterisk 13)
|
|
62.128.128.68 (Telco SBC Outbound)
Test scenario is:
- a mobile calls a destination; the call comes in from Telco SBC Inbound,
goes through Kamailio+RTPengine and then to Asterisk which redirects the
call to Telco SBC Outbound.
- Asterisk box is set with canreinvite=no and nat=force_rport,comedia so it
stays in the path
when a call comes in SBC Inbound, it is correctly redireted to SBC
Outbound. The call is answered, and after 5 or so seconds, SBC Inbound
sends a new INVITE to force codecs, which Asterisk replies correctly.
the problem is that between Kamailio and SBC Inbund, when Asterisk replies
to the second invite, the media port changes, resulting in audio loss:
during the call, audio from destination to originator works OK but
originator to destination is mute.
According to the telco's guys,this is due to the fact that Kamailio is
changing during call the media port from original media port to a new one,
on reply to the second Invite, and this is wrong and reason why sound from
the originator to destination is lost (but not from destination to
originator)
I'm lost too here.....
Any clue? Can anyone help? Resuming I need to make sure that, if during a
call some INVITES are sent from SBC to Asterisk, that the reply keeps the
same IP_ADDR:port from beginning to the end of the call. As it is today,
the second invite changes te RTP Media port and no audi is heard....
If needed I can send PCap files.
please find below my kamailio.cfg file
#!define WITH_NAT
#!define WITH_PSTN
/* enables Accounting Log functions */
#!define FLT_ACC 1
/* enable Accounting of missed or failed calls */
#!define FLT_ACCMISSED 2
#!define FLT_ACCFAILED 3
/* sets the dispatcher list file path */
#!define DS_LIST "/etc/kamailio/dispatcher.list"
/* sets the RTP Engine address and port; RTP Engine is a NAT enabled RTP
Proxy */
#!define RTP_ENGINE_ADDR "udp:127.0.0.1:60000"
// was udp:localhost:60000
/* defines DB connection string */
#!ifndef DBURL
#!define DBURL "mysql://kamailio:kamailiorw@10.19.139.110/kamailio"
#!endif
# - the value for 'use_domain' parameters
#!define MULTIDOMAIN 1
####### Global Parameters #########
#!ifdef WITH_DEBUG
debug=4
log_stderror=yes
#!else
debug=2
log_stderror=no
#!endif
#!define FLT_DISPATCH_SETID 1
#!define FLT_FS 10
#!define FLT_NATS 5
#!define FLB_NATB 6
#!define FLB_NATSIPPING 7
memdbg=5
memlog=5
log_facility=LOG_LOCAL0
fork=yes
children=4
/* comment the next line to enable TCP */
disable_tcp=no
/* uncomment the next line to disable the auto discovery of local aliases
based on revers DNS on IPs (default on) */
auto_aliases=no
/* add local domain aliases */
# alias="mysipserver.com"
port=5060
/* uncomment and configure the following line if you want Kamailio to
bind on a specific interface/port/proto (default bind on all available)
*/
//listen=udp:10.19.139.66:5060
listen=udp:eth1:5060
sip_warning=no;
####### Modules Section ########
#set module path
mpath="/usr/lib64/kamailio/modules/"
loadmodule "db_mysql.so"
loadmodule "jsonrpcs.so"
loadmodule "kex.so"
loadmodule "tm.so"
loadmodule "tmx.so"
loadmodule "sl.so"
loadmodule "rr.so"
loadmodule "pv.so"
loadmodule "maxfwd.so"
/**************/
loadmodule "usrloc.so"
/**************/
loadmodule "textops.so"
loadmodule "siputils.so"
loadmodule "xlog.so"
loadmodule "sanity.so"
loadmodule "ctl.so"
loadmodule "acc.so"
loadmodule "path.so"
loadmodule "dispatcher.so"
loadmodule "rtpengine.so"
loadmodule "nathelper.so"
loadmodule "rtimer.so"
loadmodule "sqlops.so"
# ----------------- setting module-specific parameters ---------------
# ----- jsonrpcs params -----
modparam("jsonrpcs", "fifo_name", "/var/run/kamailio/kamailio_rpc.fifo")
modparam("jsonrpcs", "pretty_format", 1)
# ----- rr params -----
# add value to ;lr param to cope with most of the UAs
modparam("rr", "enable_full_lr", 1)
# do not append from tag to the RR (no need for this script)
modparam("rr", "append_fromtag", 0)
# ----- acc params -----
modparam("acc", "failed_transaction_flag", 3)
modparam("acc",
"log_extra","src_user=$fU;src_domain=$fd;dst_ouser=$tU;dst_user=$rU;dst_domain=$rd;src_ip=$si")
# ----- acc params -----
/* what special events should be accounted ? */
modparam("acc", "early_media", 0)
modparam("acc", "report_ack", 0)
modparam("acc", "report_cancels", 0)
/* by default we do not adjust the direct of the sequential requests.
if you enable this parameter, be sure the enable "append_fromtag"
in "rr" module */
modparam("acc", "detect_direction", 0)
/* account triggers (flags) */
modparam("acc", "log_flag", FLT_ACC)
modparam("acc", "log_missed_flag", FLT_ACCMISSED)
modparam("acc",
"log_extra","src_user=$fU;src_domain=$fd;src_ip=$si;dst_ouser=$tU;dst_user=$rU;dst_domain=$rd")
modparam("acc", "failed_transaction_flag", FLT_ACCFAILED)
/* enhanced DB accounting */
modparam("acc", "db_flag", FLT_ACC)
modparam("acc", "db_missed_flag", FLT_ACCMISSED)
modparam("acc", "db_url", DBURL)
modparam("acc",
"db_extra","src_user=$fU;src_domain=$fd;src_ip=$si;dst_ouser=$tU;dst_user=$rU;dst_domain=$rd")
//;calltype=$avp(calltype)")
# ----- usrloc params -----
/* enable DB persistency for location entries */
modparam("usrloc", "db_url", DBURL)
modparam("usrloc", "db_mode", 2)
modparam("usrloc", "use_domain", MULTIDOMAIN)
# ----- tm params -----
# ----- the TM module enables stateful processing of SIP requests
modparam("tm", "fr_timer", 2000)
modparam("tm", "fr_inv_timer", 40000)
# ----- dispatcher params -----
modparam("dispatcher", "list_file", DS_LIST)
modparam("dispatcher", "flags", 2)
modparam("dispatcher", "dst_avp", "$avp(AVP_DST)")
modparam("dispatcher", "grp_avp", "$avp(AVP_GRP)")
modparam("dispatcher", "cnt_avp", "$avp(AVP_CNT)")
modparam("dispatcher", "sock_avp", "$avp(AVP_SOCK)")
modparam("dispatcher", "ds_hash_size", 9)
modparam("dispatcher", "dstid_avp", "$avp(dsdstid)")
modparam("path", "use_received", 1)
# ----- rtpproxy params -----
modparam("rtpengine", "rtpengine_sock", RTP_ENGINE_ADDR)
modparam("nathelper", "received_avp", "$avp(s:rcv)")
/************************/
# ----- nathelper params -----
modparam("nathelper", "natping_interval", 30)
modparam("nathelper", "ping_nated_only", 1)
modparam("nathelper", "sipping_bflag", FLB_NATSIPPING)
modparam("nathelper", "sipping_from", "sip:ping@kamailio.org")
# params needed for NAT traversal in other modules
modparam("usrloc", "nat_bflag", FLB_NATB)
/***********************/
modparam("rtimer", "timer", "name=cdr;interval=300;mode=1;")
modparam("rtimer", "exec", "timer=cdr;route=CDRS")
modparam("sqlops", "sqlcon",
"ca=>mysql://kamailio:**********@*************/kamailio")
####### Routing Logic ########
# main request routing logic
route {
xlog("L_INFO","$rm from $si");
xlog("L_DBG","[$fU@$si:$sp]{$rm} {$ru} ");
# OPTIONS requests without a username in the Request-URI but one
# of our domains or IPs are addressed to the proxy itself and
# can be answered statelessly.
if (is_method("OPTIONS")) // && $fU=="ping" )// && $si=="62.28.173.10" &&
$fU=="ping")// && strempty((a)ruri.user) && (uri == myself))
{
sl_send_reply("200","OK");
exit;
}
# per request initial checks
route(REQINIT);
rtpengine_manage();
# NAT detection
route(NATDETECT);
# handle requests within SIP dialogs
### only initial requests (no To tag)
# CANCEL processing
if (is_method("CANCEL"))
{
if (t_check_trans()){
route(RELAY);
}
exit;
}
# handle retransmissions
if (!is_method("ACK")) {
if(t_precheck_trans()) {
t_check_trans();
exit;
}
t_check_trans();
}
route(WITHINDLG);
# record routing for dialog forming requests (in case they are routed)
# - remove preloaded route headers
xlog("L_INFO","Removing Headers");
remove_hf("Route");
if (is_method("INVITE|SUBSCRIBE")){
xlog("L_INFO","Recording Route");
record_route();
if (is_method("INVITE")) {
if (has_body("application/sdp")) {
if (rtpengine_offer())
t_on_reply("1");
} else {
t_on_reply("2");
}
}
}
if (is_method("ACK") && has_body("application/sdp"))
rtpengine_answer();
# account only INVITEs
if (is_method("INVITE"))
{
setflag(FLT_ACC); # do accounting
}
//route(SIPOUT);
xlog("L_INFO","Setting PRESENCE");
# handle presence related requests
route(PRESENCE);
# handle registrations
xlog("L_INFO","Handling REGISTRAR");
route(REGISTRAR);
if ($rU==$null)
{
# request with no Username in RURI
sl_send_reply("484","Address Incomplete");
exit;
}
# dispatch destinations
route(DISPATCH);
xlog("L_INFO","**********END*************");
}
onreply_route[1]
{
if (has_body("application/sdp"))
rtpengine_answer();
}
onreply_route[2]
{
if (has_body("application/sdp"))
rtpengine_offer();
}
# Per SIP request initial checks
route[REQINIT] {
xlog("L_INFO","REQINIT Starting");
if (!mf_process_maxfwd_header("10")) {
xlog("L_INFO","483 - Too Many Hops");
sl_send_reply("483","Too Many Hops");
exit;
}
if(!sanity_check("1511", "7"))
{
xlog("Sanity Check -> Malformed SIP message from
$si:$sp\n");
exit;
}
xlog("L_INFO","REQINIT Finishing");
}
/***********************/
# Caller NAT detection
route[NATDETECT] {
xlog("L_INFO","Entering NATDTECT");
#!ifdef WITH_NAT
force_rport();
if (nat_uac_test("19")) {
if (is_method("REGISTER")) {
xlog("L_INFO","Fix Nated Register");
fix_nated_register();
} else {
if(is_first_hop())
{
xlog("L_INFO","Set Contact Alias");
set_contact_alias();
}
}
xlog("L_INFO","Set FLT_NATS" + FLT_NATS);
setflag(FLT_NATS);
}
#!endif
xlog("L_INFO","NAT Detect set FLT_NTS = " + FLT_NATS);
xlog("L_INFO","Finishing NATDETECT");
return;
}
/***********************/
# Handle requests within SIP dialogs
route[WITHINDLG] {
xlog("L_INFO","Entering WITHDLG");
if (!has_totag()) return;
# sequential request withing a dialog should
# take the path determined by record-routing
if (loose_route()) {
route(DLGURI);
if (is_method("BYE")) {
setflag(FLT_ACC); # do accounting ...
setflag(FLT_ACCFAILED); # ... even if the
transaction fails
}
else if ( is_method("ACK") ) {
# ACK is forwarded statelessy
xlog("L_INFO","Going to NATMANAGE");
route(NATMANAGE);
}
else if ( is_method("NOTIFY") ) {
# Add Record-Route for in-dialog NOTIFY as per RFC
6665.
record_route();
}
route(RELAY);
exit;
}
if (is_method("SUBSCRIBE") && uri == myself) {
# in-dialog subscribe requests
route(PRESENCE);
exit;
}
if ( is_method("ACK") ) {
if ( t_check_trans() ) {
# no loose-route, but stateful ACK;
# must be an ACK after a 487
# or e.g. 404 from upstream server
route(RELAY);
exit;
} else {
# ACK without matching transaction. Try to route
anyway - being optimistic
# since it has at least a To Tag
route(RELAY);
exit;
}
}
sl_send_reply("404","Not here");
xlog("L_INFO","Finishing WITHINDLG");
exit;
}
# Routing to foreign domains
route[SIPOUT] {
xlog("L_INFO","Entering SIPOUT");
if (uri==myself)
{
xlog("L_INFO","URI is MySelf!");
return;
}
append_hf("P-hint: outbound\r\n");
xlog("L_INFO","Finishing SIPOUT");
route(RELAY);
exit;
}
# Wrapper for relaying requests
route[RELAY] {
xlog("L_INFO","******** RELAY *******");
# enable additional event routes for forwarded requests
# - serial forking, RTP relaying handling, a.s.o.
if (is_method("INVITE|BYE|SUBSCRIBE|UPDATE")) {
if(!t_is_set("branch_route")) {
xlog("L_INFO","branch_route NOT SET!");
t_on_branch("MANAGE_BRANCH");
}
}
if (is_method("INVITE|SUBSCRIBE|UPDATE")) {
if(!t_is_set("onreply_route")) {
xlog("L_INFO","onreply_route NOT SET!");
t_on_reply("MANAGE_REPLY");
}
}
if (is_method("INVITE")) {
if(!t_is_set("failure_route")) {
xlog("L_INFO","failure_route NOT SET!");
t_on_failure("MANAGE_FAILURE");
}
}
if (!t_relay()) {
xlog("L_INFO","t_relay returns FALSE");
sl_reply_error();
}
exit;
}
# URI update for dialog requests
route[DLGURI] {
xlog("L_INFO","Entering DLGURI");
#!ifdef WITH_NAT
if(!isdsturiset()) {
xlog("L_INFO","Handle ruri ALIAS");
handle_ruri_alias();
}
#!endif
return;
}
# RTPProxy control and singaling updates for NAT traversal
route[NATMANAGE] {
xlog("L_INFO","Entering NATMANAGE");
#!ifdef WITH_NAT
if (is_request()) {
if(has_totag()) {
if(check_route_param("nat=yes")) {
xlog("L_INFO","nat=yes --- Setting FLB_NATB");
setbflag(FLB_NATB);
}
}
}
if (!(isflagset(FLT_NATS) || isbflagset(FLB_NATB) ))
{
xlog("L_INFO","NO FLT_NATS/B Set!!! Getting out of NATMANAGE");
return;
}
xlog("L_INFO","Starting RTPEngine");
rtpengine_manage();
if (is_request()) {
if (!has_totag()) {
if(t_is_branch_route()) {
xlog("L_INFO","adding nat=yes");
add_rr_param(";nat=yes");
}
}
}
if (is_reply()) {
if(isbflagset(FLB_NATB)) {
if(is_first_hop())
{
xlog("L_INFO","Set Contact Alias");
set_contact_alias();
}
}
}
#!endif
return;
}
# Handle SIP registrations
route[REGISTRAR] {
if(!is_method("REGISTER"))
return;
add_path_received();
route(DISPATCH);
}
# Presence server route
route[PRESENCE] {
if(!is_method("PUBLISH|SUBSCRIBE"))
return;
sl_send_reply("404", "Not here");
exit;
}
# Dispatch requests
route[DISPATCH] {
xlog("L_INFO","Entering DISPATCH");
# hash over callerid dispatching on gateways group '1'
if(!ds_select_dst("1", "10","4"))
{
xlog("L_INFO","no destination selected from dispatcher list!");
send_reply("404", "No destination");
exit;
}
xlog("L_INFO","going to <$ru> via <$du>\n");
t_on_failure("RTF_DISPATCH");
route(RELAY);
exit;
}
# Sample failure route
failure_route[RTF_DISPATCH] {
if (t_is_canceled()) {
exit;
}
xlog("L_INFO", "Media server $du failed to answer, selecting other one!");
# next DST - only for 500 or local timeout
if ( t_check_status("500") || (t_branch_timeout() && !t_branch_replied()) )
{
#we mark the destination Inactive and Probing
ds_mark_dst("ip");
if(ds_next_dst())
{
t_on_failure("RTF_DISPATCH");
route(RELAY);
exit;
}
}
}
route[CDRS]{
sql_query("ca","call kamailio_cdrs();","rb");
sql_query("ca","call kamailio_rating('default');","rb");
}
Cheers,
*Sérgio *