我正在尝试通过 kamailio 代理将所有呼叫路由到 twilio。使用我的配置文件,呼叫接通后大约 30 秒后自动挂断。这是因为发送给 twilio 的 200 OK ACK 不正确。Twilio 期望 200 OK 响应中的 ruri 与联系人相同,但 kamailio 发送的却不同。如何修复此错误?
200 OK response
[email protected]|k
SIP/2.0 200 OK
To: <sip:[email protected]>;tag=52642973_6772d868_f5ff7ec8-2860-4963-894d-4686de291299
Via: SIP/2.0/UDP 54.69.159.69:5060;branch=z9hG4bKcdde.3a10daa4c4dfb45218165e7003bc1925.0
Via: SIP/2.0/UDP 64.2.142.90;branch=z9hG4bKcdde.0da1e6a5.0
Via: SIP/2.0/UDP 64.2.142.153:5060;received=64.2.142.153;branch=z9hG4bK0c18e9b5;rport=5060
Record-Route: <sip:107.21.211.20:5060;lr;ftag=as0b111d7b>
Record-Route: <sip:54.69.159.69:5060;lr=on>
Record-Route: <sip:64.2.142.90;lr=on>
CSeq: 102 INVITE
Call-ID: [email protected]
From: "+14088271419" <sip:[email protected]>;tag=as0b111d7b
Contact: <sip:10.108.170.11:5060>
Content-Type: application/sdp
X-Twilio-CallSid: CA2d519006d553f3acf89f1dd2fef77cc3
Content-Length: 247
v=0
o=- 1132985615 1132985615 IN IP4 54.82.64.195
s=session
c=IN IP4 54.82.64.195
t=0 0
m=audio 13800 RTP/AVP 0 101
a=rtpmap:0 PCMU/8000
a=rtpmap:101 telephone-event/8000
a=fmtp:101 0-16
a=silenceSupp:off - - - -
a=ptime:20
a=sendrecv
ACK 转发至 twilio
E@d
kCACK sip:107.21.211.20:5060;lr;ftag=as0b111d7b SIP/2.0
Via: SIP/2.0/UDP 54.69.159.69:5060;branch=z9hG4bKcdde.95210bf832aa38aeeccc727ba583b66f.0
Via: SIP/2.0/UDP 54.69.159.69:5060;branch=z9hG4bKcdde.0a606545da03734a8b332edc9b21079f.0
Via: SIP/2.0/UDP 64.2.142.90;branch=z9hG4bKcdde.0da1e6a5.2
Via: SIP/2.0/UDP 64.2.142.153:5060;received=64.2.142.153;branch=z9hG4bK32a73a53;rport=5060
From: "+14088271419" <sip:[email protected]>;tag=as0b111d7b
To: <sip:[email protected]:5060>;tag=52642973_6772d868_f5ff7ec8-2860-4963-894d-4686de291299
Contact: <sip:[email protected]>
Call-ID: [email protected]
CSeq: 102 ACK
User-Agent: packetrino
Max-Forwards: 67
Content-Length: 0
这是我的配置文件。(IP 和账户名已更改)
#!KAMAILIO
#
# sample config file for dispatcher module
# - load balancing of VoIP calls with round robin
# - no TPC listening
# - don't dispatch REGISTER and presence requests
# Direct your questions about this file to: [email protected]
#
#
# *** To run in debug mode:
# - define WITH_DEBUG
#
#!ifndef DBURL
#!define DBURL "mysql://kamailio:kamailiorw@localhost/kamailio"
#!endif
####### Global Parameters #########
#!ifdef WITH_DEBUG
debug=4
log_stderror=yes
#!else
debug=2
log_stderror=no
#!endif
memdbg=5
memlog=5
log_facility=LOG_LOCAL0
fork=yes
children=4
/* comment the next line to enable TCP */
disable_tcp=yes
/* 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="54.69.159.69"
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:172.31.22.10:5060 advertise 54.69.159.69:5060
#advertised_address="54.69.159.69"
#advertised_port=5060
sip_warning=no
####### Modules Section ########
#set module path
mpath="/usr/local/lib64/kamailio/modules_k/:/usr/local/lib64/kamailio/modules/"
loadmodule "db_mysql.so"
loadmodule "mi_fifo.so"
loadmodule "kex.so"
loadmodule "tm.so"
loadmodule "tmx.so"
loadmodule "sl.so"
loadmodule "rr.so"
loadmodule "pv.so"
loadmodule "maxfwd.so"
loadmodule "textops.so"
loadmodule "siputils.so"
loadmodule "xlog.so"
loadmodule "sanity.so"
loadmodule "ctl.so"
loadmodule "mi_rpc.so"
loadmodule "acc.so"
loadmodule "dispatcher.so"
loadmodule "pdt.so"
loadmodule "nathelper.so"
loadmodule "avpops.so"
loadmodule "htable.so"
# ----------------- setting module-specific parameters ---------------
# ----- mi_fifo params -----
modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo")
# ----- 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", "log_flag", 1)
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")
# ----- tm params -----
modparam("tm", "fr_timer", 2000)
modparam("tm", "fr_inv_timer", 40000)
# ----- dispatcher params -----
modparam("dispatcher", "db_url", DBURL)
modparam("dispatcher", "table_name", "dispatcher")
modparam("dispatcher", "flags_col", "flags")
modparam("dispatcher", "priority_col", "priority")
modparam("dispatcher", "dst_avp", "$avp(AVP_DST)")
modparam("dispatcher", "grp_avp", "$avp(AVP_GRP)")
modparam("dispatcher", "cnt_avp", "$avp(AVP_CNT)")
modparam("dispatcher", "force_dst", 1)
#-------pdt--------------
modparam("pdt", "db_table", "pdt")
modparam("pdt", "domain_column", "sdomain")
modparam("pdt", "prefix_column", "prefix")
modparam("pdt", "domain_column", "domain")
#-----------------nat-----------
modparam("nathelper", "natping_interval", 0)
modparam("nathelper", "ping_nated_only", 0)
#modparam("nathelper", "sipping_bflag", FLB_NATSIPPING)
modparam("nathelper", "sipping_from", "sip:172.31.22.10:5060")
#-----------acc------------
modparam("acc", "report_ack", 1)
####### Routing Logic ########
# main request routing logic
route {
# per request initial checks
route(REQINIT);
# handle requests within SIP dialogs
route(WITHINDLG);
### only initial requests (no To tag)
# CANCEL processing
if (is_method("CANCEL"))
{
if (t_check_trans())
t_relay();
exit;
}
t_check_trans();
# record routing for dialog forming requests (in case they are routed)
# - remove preloaded route headers
remove_hf("Route");
if (is_method("INVITE|SUBSCRIBE"))
#add_rr_param(";nat=yes");
record_route_advertised_address("54.69.159.69:5060");
#record_route();
# account only INVITEs
if (is_method("INVITE"))
{
setflag(1); # do accounting
}
# handle presence related requests
route(PRESENCE);
# handle registrations
route(REGISTRAR);
if ($rU==$null)
{
# request with no Username in RURI
sl_send_reply("484","Address Incomplete");
exit;
}
# dispatch destinations
route(DISPATCH);
}
route[RELAY] {
if (!t_relay()) {
sl_reply_error();
}
exit;
}
# Per SIP request initial checks
route[REQINIT] {
if (!mf_process_maxfwd_header("10")) {
sl_send_reply("483","Too Many Hops");
exit;
}
if(!sanity_check("1511", "7"))
{
xlog("Malformed SIP message from $si:$sp\n");
exit;
}
}
# Handle requests within SIP dialogs
route[WITHINDLG] {
t_check_trans();
if (has_totag()) {
# sequential request withing a dialog should
# take the path determined by record-routing
if (loose_route()) {
if (is_method("BYE")) {
setflag(1); # do accounting ...
setflag(3); # ... even if the transaction fails
}
route(RELAY);
} else {
if (is_method("SUBSCRIBE") && uri == myself) {
# in-dialog subscribe requests
route(PRESENCE);
exit;
}
if ( is_method("ACK") ) {
if ( t_check_trans() ) {
# non loose-route, but stateful ACK;
# must be ACK after a 487 or e.g. 404 from upstream server
t_relay();
exit;
} else {
# ACK without matching transaction ... ignore and discard.
exit;
}
}
sl_send_reply("404","Not here");
}
exit;
}
}
# Handle SIP registrations
route[REGISTRAR] {
if(!is_method("REGISTER"))
return;
sl_send_reply("404", "No registrar");
exit;
}
# Presence server route
route[PRESENCE] {
if(!is_method("PUBLISH|SUBSCRIBE"))
return;
sl_send_reply("404", "Not here");
exit;
}
# Dispatch requests
route[DISPATCH] {
if(prefix2domain("2", "0")) {
$ru = "sip:" + $rU + "@" + $rd;
t_relay();
exit;
}
# round robin dispatching on gateways group '1'
if(!ds_select_dst("1", "4"))
{
send_reply("404", "No destination");
exit;
}
xlog("L_DBG", "--- SCRIPT: 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;
}
# next DST - only for 500 or local timeout
if (t_check_status("500")
or (t_branch_timeout() and !t_branch_replied()))
{
if(ds_next_dst())
{
t_on_failure("RTF_DISPATCH");
route(RELAY);
exit;
}
}
}