From: <abe...@us...> - 2014-08-29 23:41:20
|
Revision: 6678 http://sourceforge.net/p/astlinux/code/6678 Author: abelbeck Date: 2014-08-29 23:41:17 +0000 (Fri, 29 Aug 2014) Log Message: ----------- kamailio, add WITH_ASTERISK switch to the kamailio.cfg, still work in progress, add 'uac' module Ref: http://kb.asipto.com/asterisk:realtime:kamailio-4.0.x-asterisk-11.3.0-astdb Modified Paths: -------------- branches/1.0/package/kamailio/etc/kamailio.cfg branches/1.0/package/kamailio/kamailio.mk Modified: branches/1.0/package/kamailio/etc/kamailio.cfg =================================================================== --- branches/1.0/package/kamailio/etc/kamailio.cfg 2014-08-28 18:37:53 UTC (rev 6677) +++ branches/1.0/package/kamailio/etc/kamailio.cfg 2014-08-29 23:41:17 UTC (rev 6678) @@ -80,6 +80,13 @@ # - set the value of voicemail.srv_ip # - adjust the value of voicemail.srv_port # +# *** To enable Asterisk routing execute: +# - define WITH_ASTERISK +# - set the value of asterisk.bindip +# - adjust the value of asterisk.bindport +# - set the value of kamailio.bindip +# - adjust the value of kamailio.bindport +# # *** To enhance accounting execute: # - enable sqlite # - define WITH_ACCDB @@ -203,6 +210,13 @@ voicemail.srv_port = "5060" desc "VoiceMail Port" #!endif +#!ifdef WITH_ASTERISK +asterisk.bindip = "127.0.0.1" desc "Asterisk IP Address" +asterisk.bindport = "5080" desc "Asterisk Port" +kamailio.bindip = "127.0.0.1" desc "Kamailio IP Address" +kamailio.bindport = "5060" desc "Kamailio Port" +#!endif + ####### Modules Section ######## # set paths to location of modules (to sources or installation folders) @@ -285,6 +299,10 @@ loadmodule "debugger.so" #!endif +#!ifdef WITH_ASTERISK +loadmodule "uac.so" +#!endif + # ----------------- setting module-specific parameters --------------- @@ -310,7 +328,11 @@ # 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) +#!ifdef WITH_ASTERISK +modparam("rr", "append_fromtag", 1) +#!else modparam("rr", "append_fromtag", 0) +#!endif # ----- registrar params ----- @@ -363,11 +385,19 @@ # ----- auth_db params ----- #!ifdef WITH_AUTH +modparam("auth_db", "calculate_ha1", yes) +modparam("auth_db", "load_credentials", "") + +##!ifdef WITH_ASTERISK +#modparam("auth_db", "user_column", "name") +#modparam("auth_db", "password_column", "sippasswd") +#modparam("auth_db", "db_url", DBASTURL) +#modparam("auth_db", "version_table", 0) +##!else modparam("auth_db", "db_url", DBURL) -modparam("auth_db", "calculate_ha1", yes) modparam("auth_db", "password_column", "password") -modparam("auth_db", "load_credentials", "") modparam("auth_db", "use_domain", MULTIDOMAIN) +##!endif # ----- permissions params ----- #!ifdef WITH_IPAUTH @@ -638,6 +668,10 @@ if (!save("location")) sl_reply_error(); +#!ifdef WITH_ASTERISK + route(REGFWD); +#!endif + exit; } } @@ -658,6 +692,16 @@ route(SIPOUT); #!endif +#!ifdef WITH_ASTERISK + if(is_method("INVITE") && (!route(FROMASTERISK))) { + # if new call from out there - send to Asterisk + # - non-INVITE request are routed directly by Kamailio + # - traffic from Asterisk is routed also directy by Kamailio + route(TOASTERISK); + exit; + } +#!endif + $avp(oexten) = $rU; if (!lookup("location")) { $var(rc) = $rc; @@ -725,8 +769,23 @@ # Authentication route route[AUTH] { + + # if caller is not local subscriber, then check if it calls + # a local destination, otherwise deny, not an open relay here + if (from_uri!=myself && uri!=myself) + { + sl_send_reply("403","Not relaying"); + exit; + } + #!ifdef WITH_AUTH +#!ifdef WITH_ASTERISK + # do not auth traffic from Asterisk - trusted! + if(route(FROMASTERISK)) + return; +#!endif + #!ifdef WITH_IPAUTH if((!is_method("REGISTER")) && allow_source_address()) { @@ -738,7 +797,11 @@ if (is_method("REGISTER") || from_uri==myself) { # authenticate requests +##!ifdef WITH_ASTERISK +# if (!auth_check("$fd", "sipusers", "1")) { +##!else if (!auth_check("$fd", "subscriber", "1")) { +##!endif auth_challenge("$fd", "0"); exit; } @@ -746,14 +809,6 @@ if(!is_method("REGISTER|PUBLISH")) consume_credentials(); } - # if caller is not local subscriber, then check if it calls - # a local destination, otherwise deny, not an open relay here - if (from_uri!=myself && uri!=myself) - { - sl_send_reply("403","Not relaying"); - exit; - } - #!endif return; } @@ -948,3 +1003,43 @@ } #!endif } + +#!ifdef WITH_ASTERISK +# Test if coming from Asterisk +route[FROMASTERISK] { + if($si==$sel(cfg_get.asterisk.bindip) + && $sp==$sel(cfg_get.asterisk.bindport)) + return 1; + return -1; +} + +# Send to Asterisk +route[TOASTERISK] { + $du = "sip:" + $sel(cfg_get.asterisk.bindip) + ":" + + $sel(cfg_get.asterisk.bindport); + route(RELAY); + exit; +} + +# Forward REGISTER to Asterisk +route[REGFWD] { + if(!is_method("REGISTER")) + { + return; + } + $var(rip) = $sel(cfg_get.asterisk.bindip); + $uac_req(method)="REGISTER"; + $uac_req(ruri)="sip:" + $var(rip) + ":" + $sel(cfg_get.asterisk.bindport); + $uac_req(furi)="sip:" + $au + "@" + $var(rip); + $uac_req(turi)="sip:" + $au + "@" + $var(rip); + $uac_req(hdrs)="Contact: <sip:" + $au + "@" + + $sel(cfg_get.kamailio.bindip) + + ":" + $sel(cfg_get.kamailio.bindport) + ">\r\n"; + if($sel(contact.expires) != $null) + $uac_req(hdrs)= $uac_req(hdrs) + "Expires: " + $sel(contact.expires) + "\r\n"; + else + $uac_req(hdrs)= $uac_req(hdrs) + "Expires: " + $hdr(Expires) + "\r\n"; + uac_req_send(); +} +#!endif + Modified: branches/1.0/package/kamailio/kamailio.mk =================================================================== --- branches/1.0/package/kamailio/kamailio.mk 2014-08-28 18:37:53 UTC (rev 6677) +++ branches/1.0/package/kamailio/kamailio.mk 2014-08-29 23:41:17 UTC (rev 6678) @@ -10,7 +10,7 @@ KAMAILIO_DEPENDENCIES = openssl KAMAILIO_GROUP_MODULES = standard -KAMAILIO_INCLUDE_MODULES = acc htable outbound permissions registrar tls usrloc +KAMAILIO_INCLUDE_MODULES = acc htable outbound permissions registrar tls uac usrloc KAMAILIO_EXCLUDE_MODULES = rtpproxy-ng xhttp xhttp_rpc ifeq ($(strip $(BR2_PACKAGE_SQLITE)),y) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |