Calls working without dispatcher and loadbalancig and rtp is working only 1 way

This commit is contained in:
2024-09-09 11:57:10 +02:00
parent 3c65ea9e12
commit 6c52ef8811
3 changed files with 2477 additions and 27 deletions

View File

@@ -8,6 +8,14 @@ loadmodule "rtpengine.so"
loadmodule "dispatcher.so"
loadmodule "nathelper.so"
loadmodule "ctl"
loadmodule "pv"
loadmodule "db_mysql.so"
loadmodule "uac.so"
loadmodule "xlog.so"
loadmodule "tmx"
loadmodule "siputils"
loadmodule "sanity"
loadmodule "acc"
# Global parameters
cfgengine "native"
@@ -20,24 +28,184 @@ modparam("rtpengine", "rtpengine_sock", "udp:127.0.0.1:2223")
modparam("dispatcher", "list_file", "/etc/kamailio/dispatcher.list")
# KAMCTL config
modparam("ctl", "binrpc", "/var/run/kamailio/kamailio_ctl")
# Main request routing logic
route {
# Max forward check
if (!mf_process_maxfwd_header("10")) {
sl_send_reply("483", "Too Many Hops");
exit;
}
# Record routing for stateful processing
record_route();
# Load balance using dispatcher
if (!ds_select_dst("1", "4")) {
sl_send_reply("500", "No destination");
exit;
}
# Engage RTPProxy for RTP traffic
if (is_method("INVITE")) {
rtpengine_manage();
}
# Forward the request
t_relay();
# UAC settings
modparam("uac","reg_contact_addr", "10.0.5.7:5060")
modparam("uac","reg_db_url", "mysql://kamailio:kamailiow@localhost/kamailio")
modparam("uac","auth_username_avp","$avp(auser)")
modparam("uac","auth_password_avp","$avp(apass)")
modparam("uac","auth_realm_avp","$avp(arealm)")
# TM settings
modparam("tm", "auto_inv_100_reason", "Trying")
/* Main SIP request routing logic
* - processing of any incoming SIP request starts with this route
* - note: this is the same as route { ... } */
request_route {
# per request initial checks
route(REQINIT);
# 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();
}
# handle requests within SIP dialogs
route(WITHINDLG);
### only initial requests (no To tag)
# record routing for dialog forming requests (in case they are routed)
# - remove preloaded route headers
remove_hf("Route");
if (is_method("INVITE|SUBSCRIBE")) {
record_route();
}
if ($rU==$null) {
# request with no Username in RURI
sl_send_reply("484", "Address Incomplete");
exit;
}
# Force RTPENGINE
if (is_method("INVITE")) {
rtpengine_manage("replace-origin replace-session-connection force-relay");
}
# update $du to set the destination address for proxying
if ($siz=="10.0.5.7") {
xlog("Incomming call from SIP provider");
$du = "sip:" + "10.0.5.4";
} else {
xlog("Incomming call from Customer PBX");
$du = "sip:" + "10.0.5.7";
}
route(RELAY);
exit;
}
# Wrapper for relaying requests
route[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")) t_on_branch("MANAGE_BRANCH");
}
if (is_method("INVITE|SUBSCRIBE|UPDATE")) {
if(!t_is_set("onreply_route")) t_on_reply("MANAGE_REPLY");
}
if (is_method("INVITE")) {
if(!t_is_set("failure_route")) t_on_failure("MANAGE_FAILURE");
}
t_on_failure("TRUNKAUTH");
t_relay();
exit;
}
# TRUNK AUTH ROUTE
failure_route[TRUNKAUTH] {
xlog("trunk auth");
if (t_is_canceled()) {
exit;
}
xlog("Checking status code");
if(t_check_status("401|407")) {
xlog("status code is valid auth challenge");
$avp(auser) = "kam";
$avp(apass) = "kam";
uac_auth();
xlog("after uac_auth");
t_relay();
exit;
}
}
# Per SIP request initial checks
route[REQINIT] {
if($ua =~ "friendly-scanner|sipcli|VaxSIPUserAgent") {
# silent drop for scanners - uncomment next line if want to reply
# sl_send_reply("200", "OK");
exit;
}
if (!mf_process_maxfwd_header("10")) {
sl_send_reply("483", "Too Many Hops");
exit;
}
if(is_method("OPTIONS") && uri==myself && $rU==$null) {
sl_send_reply("200", "Keepalive");
exit;
}
if(!sanity_check("1511", "7")) {
xlog("Malformed SIP message from $si:$sp\n");
exit;
}
}
# Handle requests within SIP dialogs
route[WITHINDLG] {
if (!has_totag()) return;
# sequential request within a dialog should
# take the path determined by record-routing
if (loose_route()) {
if (is_method("BYE")) {
rtpengine_delete();
route(RELAY);
exit;
} else if ( is_method("NOTIFY") ) {
# Add Record-Route for in-dialog NOTIFY as per RFC 6665.
record_route();
}
route(RELAY);
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 ... ignore and discard
exit;
}
}
sl_send_reply("404", "Not here");
exit;
}
# Manage outgoing branches
branch_route[MANAGE_BRANCH] {
xdbg("new branch [$T_branch_idx] to $ru\n");
}
# Manage incoming replies
onreply_route[MANAGE_REPLY] {
if (is_method("INVITE")) {
# Force RTP relay on reply
rtpengine_manage("force-relay");
xdbg("incoming reply\n");
}
}
# Manage failure routing cases
failure_route[MANAGE_FAILURE] {
if (t_is_canceled()) exit;
}

2282
kamailio.sql Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -15,25 +15,25 @@
##
## If you want to setup a database with kamdbctl, you must at least specify
## this parameter.
# DBENGINE=MYSQL
DBENGINE=MYSQL
## database host
# DBHOST=localhost
DBHOST=localhost
## database port
# DBPORT=3306
DBPORT=3306
## database name (for ORACLE this is TNS name)
# DBNAME=kamailio
DBNAME=kamailio
## database path used by dbtext, db_berkeley or sqlite
# DB_PATH="/usr/local/etc/kamailio/dbtext"
## database read/write user
# DBRWUSER="kamailio"
DBRWUSER="kamailio"
## password for database read/write user
# DBRWPW="kamailiorw"
DBRWPW="kamailiorw"
## database read only user
# DBROUSER="kamailioro"
@@ -56,7 +56,7 @@
# DBINITASK=yes
## database character set (used by MySQL when creating database)
#CHARSET="latin1"
CHARSET="latin1"
## user name column
# USERCOL="username"