diff --git a/opensips/dispatcher.list b/opensips/dispatcher.list new file mode 100644 index 0000000..3f5b04b --- /dev/null +++ b/opensips/dispatcher.list @@ -0,0 +1,11 @@ +# setit(integer) destination(sip uri) flags (integer, optional) +1 sip:184.106.179.143:5060 2 +1 sip:184.106.169.42:5060 2 +1 sip:209.114.34.232:5060 2 +1 sip:209.114.32.203:5060 2 +#1 sip:184.106.189.9:5060 2 +#1 sip:184.106.170.41:5060 2 +#1 sip:184.73.45.119:5060 2 +#1 sip:50.16.89.56:5060 2 +#1 sip:67.202.51.166:5060 2 +#1 sip:50.17.16.247:5060 2 diff --git a/opensips/dispatcher.sh b/opensips/dispatcher.sh new file mode 100644 index 0000000..c8f2e47 --- /dev/null +++ b/opensips/dispatcher.sh @@ -0,0 +1,53 @@ +#!/bin/bash +DISPATCHER_FILE="/usr/local/etc/opensips/dispatcher.list" +OSIP_CTL="/usr/local/etc/opensips/opensipsctl" + +fUsage () { + echo "Usage: $0 [Media Server IP] [-a active] [-i inactive] [-p probing] [-r reload]" + exit 1 +} + +cd `dirname $0` + +[[ ! $1 == -* ]] && server=$1 && shift + +while [ -n "$*" ]; do + case "x$1" in + x-a) + action="a" + ;; + x-i) + action="i" + ;; + x-p) + action="p" + ;; + x-r) + action="r" + ;; + x--help) + fUsage + ;; + *) + fUsage + ;; + esac + shift +done + +if [ -z $action ]; then + echo "# $OSIP_CTL fifo ds_list" + $OSIP_CTL fifo ds_list + exit 0 +elif [ $action == "r" ]; then + echo "# $OSIP_CTL fifo ds_reload" + $OSIP_CTL fifo ds_reload + exit 0 +elif grep -q $server $DISPATCHER_FILE; then + echo "# $OSIP_CTL fifo ds_set_state $action `grep $server $DISPATCHER_FILE | cut -d' ' -f 1` `grep $server $DISPATCHER_FILE | cut -d' ' -f 2`" + $OSIP_CTL fifo ds_set_state $action `grep $server $DISPATCHER_FILE | cut -d' ' -f 1` `grep $server $DISPATCHER_FILE | cut -d' ' -f 2` + exit 0 +else + echo "ERROR: Could not locate $server in $DISPATCHER_FILE" + exit 1 +fi diff --git a/opensips/opensips.cfg b/opensips/opensips.cfg new file mode 100644 index 0000000..a95fcc4 --- /dev/null +++ b/opensips/opensips.cfg @@ -0,0 +1,559 @@ +###################################################################### +## Core Parameters +###################################################################### +# chroot= +# group="opensips" +# user="opensips" +# dbversion_table= +disable_core_dump=no +max_while_loops=100 +maxbuffer=262144 +memdump=3 +memlog=2 +# open_files_limit=2048 +server_signature=no +server_header="Server: 2600hz Trunk Store" +user_agent_header="User-Agent: 2600hz Trunk Store" + +###################################################################### +## Core Fork Parameters +###################################################################### +fork=yes +children=8 +tcp_children=8 + +###################################################################### +## Core Logging Parameters +###################################################################### +debug=4 +sip_warning=0 +log_stderror=no +log_facility=LOG_LOCAL0 +log_name="opensips" + +###################################################################### +## Aliases +###################################################################### +auto_aliases=no +alias=localhost +alias=localhost.localdomain + +###################################################################### +## Connectivity +###################################################################### +listen=udp:eth0:5060 +# listen=udp:eth1:5060 +tos=IPTOS_LOWDELAY +# advertised_address=174.129.131.38 +# advertised_port=5060 +mcast_loopback=no +mcast_ttl=1 +mhomed=0 +# tcp_accept_aliases +tcp_connect_timeout=3 +tcp_connection_lifetime=120 +tcp_max_connections=2048 +# tcp_poll_method=select + +###################################################################### +## DNS +###################################################################### +dns=no +dns_retr_time=1 +dns_retr_no=3 +# dns_servers_no=2 +dns_try_ipv6=no +disable_dns_blacklist=yes +disable_dns_failover=no +dns_use_search_list=no +rev_dns=no + +###################################################################### +## SIP +###################################################################### +check_via=0 +#! disable_503_translation=no +disable_stateless_fwd=no +disable_tcp=no +# disable_tls=no +#! reply_to_via=1 + +###################################################################### +## TLS +###################################################################### +# disable_tls=no +# listen=tls:your_IP:5061 +# tls_verify_server=1 +# tls_verify_client=1 +# tls_require_client_certificate=0 +# tls_method=TLSv1 +# tls_certificate="/usr/local/etc/opensips/tls/user/user-cert.pem" +# tls_private_key="/usr/local/etc/opensips/tls/user/user-privkey.pem" +# tls_ca_list="/usr/local/etc/opensips/tls/user/user-calist.pem" + +###################################################################### +## Destination Blacklist +###################################################################### +# dst_blacklist=gw:{( tcp , 192.168.2.100 , 5060 , "" ),( any , 192.168.2.101 , 0 , "" )} +# dst_blacklist=net_filter2:{ !( any , 192.168.30.0/255.255.255.0 , 0 , "" )} + +###################################################################### +## Attribute Value Pairs +###################################################################### +# avp_aliases="uuid=I:660;email=s:email_addr;fwd=i:753" + +###################################################################### +## Module Loading +###################################################################### +mpath="/usr/local/lib64/opensips/modules/" +loadmodule "memcached.so" +loadmodule "signaling.so" +loadmodule "sl.so" +loadmodule "tm.so" +loadmodule "maxfwd.so" +loadmodule "rr.so" +loadmodule "path.so" +loadmodule "uri.so" +loadmodule "textops.so" +loadmodule "usrloc.so" +loadmodule "nathelper.so" +loadmodule "dispatcher.so" +loadmodule "mi_fifo.so" +# loadmodule "mi_datagram.so" +# loadmodule "xlog.so" + +###################################################################### +## Memcached Module Parameters +###################################################################### +modparam("memcached", "server", "callid_hash = 127.0.0.1:11211") + +###################################################################### +## Stateless UA Module Parameters +###################################################################### +modparam("sl", "enable_stats", 1) + +###################################################################### +## SIP Transaction UA Module Parameters +###################################################################### +modparam("tm", "fr_timer", 5) +# modparam("tm", "fr_inv_timer", 60) +# modparam("tm", "wt_timer", 5) +# modparam("tm", "delete_timer", 2) +# modparam("tm", "T1_timer", 500) +# modparam("tm", "T2_timer", 4000) +# modparam("tm", "ruri_matching", 1) +# modparam("tm", "via1_matching", 1) +# modparam("tm", "unix_tx_timeout", 2) +# modparam("tm", "restart_fr_on_each_reply", 1) +# modparam("tm", "fr_timer_avp", "$avp(i:24)") +# modparam("tm", "fr_inv_timer_avp", "$avp(i:25)") +# modparam("tm", "tw_append", +# "test: ua=$hdr(User-Agent) ;avp=$avp(i:10);$rb;time=$Ts") +# modparam("tm", "pass_provisional_replies", 0) +# modparam("tm", "syn_branch", 1) +# modparam("tm", "onreply_avp_mode", 0) +# modparam("tm", "disable_6xx_block", 0) +# modparam("tm", "enable_stats", 1) +# modparam("tm", "minor_branch_flag", 3) + +###################################################################### +## Max Forward Module Parameters +###################################################################### +modparam("maxfwd", "max_limit", 30) + +###################################################################### +## Record Route Module Parameters +###################################################################### +modparam("rr", "enable_full_lr", 1) +modparam("rr", "append_fromtag", 1) +modparam("rr", "enable_double_rr", 0) +modparam("rr", "add_username", 0) + +###################################################################### +## Path Module Parameters +###################################################################### +modparam("path", "use_received", 1) + +###################################################################### +## URI Module Parameters +###################################################################### +# modparam("uri", "aaa_url", "radius:/etc/radiusclient-ng/radiusclient.conf") +modparam("uri", "use_sip_uri_host", 0) +modparam("uri", "use_uri_table", 0) +modparam("uri", "service_type", 10) +modparam("uri", "use_domain", 1) +modparam("uri", "use_uri_table", 0) +# modparam("uri", "db_url", "mysql://username:password@localhost/opensips") +# modparam("uri", "db_table", "uri") +# modparam("uri", "user_column", "username") +# modparam("uri", "domain_column", "domain") +# modparam("uri", "uriuser_column", "uri_user") + +###################################################################### +## User Location Module Parameters +###################################################################### +modparam("usrloc", "nat_bflag", 6) +modparam("usrloc", "use_domain", 1) +modparam("usrloc", "desc_time_order", 0) +modparam("usrloc", "timer_interval", 60) +modparam("usrloc", "matching_mode", 0) +modparam("usrloc", "cseq_delay", 20) +modparam("usrloc", "hash_size", 9) +modparam("usrloc", "db_mode", 0) +# modparam("usrloc", "db_url", "dbdriver://username:password@dbhost/dbname") +modparam("usrloc", "fetch_rows", 2000) +modparam("usrloc", "user_column", "username") +modparam("usrloc", "domain_column", "domain") +modparam("usrloc", "contact_column", "contact") +modparam("usrloc", "expires_column", "expires") +modparam("usrloc", "q_column", "q") +modparam("usrloc", "callid_column", "callid") +modparam("usrloc", "cseq_column", "cseq") +modparam("usrloc", "methods_column", "methods") +modparam("usrloc", "flags_column", "flags") +modparam("usrloc", "cflags_column", "cflags") +modparam("usrloc", "user_agent_column", "user_agent") +modparam("usrloc", "received_column", "received") +modparam("usrloc", "socket_column", "socket") +modparam("usrloc", "path_column", "path") + +###################################################################### +## Nathelper Module Parameters +###################################################################### +# modparam("nathelper", "rtpproxy_sock", "udp:127.0.0.1:7890") +modparam("nathelper", "natping_interval", 30) +modparam("nathelper", "ping_nated_only", 1) +# modparam("nathelper", "natping_processes", 3) +modparam("nathelper", "sipping_bflag", 7) +modparam("nathelper", "sipping_from", "sip:sipcheck@184.106.172.9 ") +# modparam("nathelper", "sipping_method", "INFO") + +###################################################################### +## Dispatcher Module Parameters +###################################################################### +modparam("dispatcher", "list_file", "/usr/local/etc/opensips/dispatcher.list") +modparam("dispatcher", "flags", 2) +modparam("dispatcher", "use_default", 0) +modparam("dispatcher", "force_dst", 1) +modparam("dispatcher", "dst_avp", "$avp(i:271)") +modparam("dispatcher", "attrs_avp", "$avp(i:272)") +modparam("dispatcher", "grp_avp", "$avp(i:273)") +modparam("dispatcher", "cnt_avp", "$avp(i:274)") +modparam("dispatcher", "hash_pvar", "$avp(i:273)") +# modparam("dispatcher", "setid_pvar", "$var(setid)") +modparam("dispatcher", "ds_ping_method", "OPTIONS") +modparam("dispatcher", "ds_ping_from", "sip:sipcheck@184.106.172.9:5060") +modparam("dispatcher", "ds_ping_interval", 10) +# modparam("dispatcher", "ds_ping_sock", "udp:10.80.25.168:5080") +modparam("dispatcher", "ds_probing_threshhold", 3) +modparam("dispatcher", "ds_probing_mode", 0) +modparam("dispatcher", "options_reply_codes", "501, 403, 404, 400") + +###################################################################### +## MI-FIFO Module Parameters +###################################################################### +modparam("mi_fifo", "fifo_name", "/tmp/opensips_fifo") + +###################################################################### +## MI-Datagram Module Parameters +###################################################################### +# modparam("mi_datagram", "socket_name", "udp:10.180.180.230:8889") +# modparam("mi_datagram", "children_count", 1) +# modparam("mi_datagram", "unix_socket_mode", 0600) +# modparam("mi_datagram", "unix_socket_group", "root") +# modparam("mi_datagram", "unix_socket_user", "root") +# modparam("mi_datagram", "socket_timeout", 2000) +# modparam("mi_datagram", "reply_indent", "\t") + +###################################################################### +## XLog Module Parameters +###################################################################### +# modparam("xlog", "buf_size", 4096) +# modparam("xlog", "force_color", 0) + +###################################################################### +## Multiple Module Parameters +###################################################################### + + +###################################################################### +## Main Request Routing +###################################################################### +route +{ + if (!mf_process_maxfwd_header("10")) + { + xlog("L_WARN", "To many hops to [$ou] from [$si:$sp]"); + + sl_send_reply("483", "We refuse to process this endless imbroglio"); + + exit; + } + + xlog("L_INFO", "Received [$rm] [$ou] from [$si:$sp]"); + xlog("L_DBG", " From: [$fu]"); + xlog("L_DBG", " To: [$tu]"); + + if (is_method("OPTIONS")) + { + xlog("L_NOTICE", " Method [$rm] is not supported, sending 503 to [$si:$sp]"); + + sl_send_reply("503", "Rawr!!"); + + exit; + } + + t_on_reply("1"); + + if (nat_uac_test("18")) + { + xlog("L_INFO", " Source port is different from the port in Via, force rport"); + + force_rport(); + + fix_nated_contact(); + + if (has_body("application/sdp")) + { + xlog("L_INFO", " Fixing nated SDP, rewritting media and origin with [$si]"); + + fix_nated_sdp("10"); + } + + # If this leads to a sucessfull register then flag 5 will cause nat=yes to be append to the contact + # and (when appropriate) the use of the nat_compensator reply branch + setflag(5); + } + + if (has_totag()) + { + if (subst_uri('/(sip:.*);nat=yes/\1/')) + { + xlog("L_INFO", " Set reply branch for NAT compensation on this message in the existing dialog"); + + t_on_reply("nat_compensator"); + } + + # sequential request withing a dialog should + # take the path determined by record-routing + if (loose_route()) + { + if (is_method("INVITE")) + { + # even if in most of the cases is useless, do RR for + # re-INVITEs alos, as some buggy clients do change route set + # during the dialog. + xlog("L_INFO", " Record route for loosely routed INVITE on an existing dialog"); + + #record_route(); + } + + # route it out to whatever destination was set by loose_route() + # in $du (destination URI). + route(1); + } + else + { + if ( is_method("ACK") ) + { + if ( t_check_trans() ) + { + # non loose-route, but stateful ACK; must be an ACK after + # a 487 or e.g. 404 from upstream server + xlog("L_INFO", " Forwarding a stateful ACK for a known dialog"); + + t_relay(); + + exit; + } + else + { + # ACK without matching transaction -> + # ignore and discard + xlog("L_NOTICE", " Recieved ACK from [$si:$sp] for unknown dialog, ignoring"); + + exit; + } + } + + xlog("L_WARN", " Recieved [$rm] for a dialog but the RR is invalid, sending 486 to [$si:$sp]"); + + sl_send_reply("486", "PC Load Letter"); + } + + exit; + } + + # CANCEL processing + if (is_method("CANCEL")) + { + # If this cancel is part of a transaction + # then pass it along to concerned parties + if (t_check_trans()) + { + t_relay(); + } + + exit; + } + + # If this is a retransmission it will break/stop the script + # and do standard processing of the message + t_check_trans(); + + # Since it is possible to suppress a second provisional response, the first one can be sent pre-emptively + sl_send_reply("100", "Thinking about it..."); + + # preloaded route checking + if (loose_route()) + { + if (!is_method("ACK")) + { + xlog("L_WARN", " Attempt to route with preloaded Route's [$fu/$tu/$ru/$ci] from [$si:$sp]"); + + sl_send_reply("403", "Please leave the routing up to us"); + + exit; + } + } + + if (is_method("REGISTER")) + { + if (!add_path_received()) + { + xlog("L_ERR", " Unable to add path for [$rm] [$tu] from [$si:$sp], sending 503"); + + sl_send_reply("503", "Internal path befuddlement"); + + exit; + } + } + + # is not from media servers + if (!ds_is_in_list("$si", "$sp", "1")) + { + if(cache_fetch("memcached_callid_hash", "$ci", $avp(i:55))) + { + $rd = $avp(i:55); + + xlog("L_INFO", " Reconized call-id [$ci] as belonging to media server [$rd]"); + } + else + { + xlog("L_INFO", " Selecting domain from set 1 using round-robin"); + + ds_select_domain("1", "4"); + + xlog("L_INFO", " Selecting domain from set 1 using round-robin [$rd]"); + + t_on_failure("1"); + } + + append_hf("X-AUTH-IP: $si\r\n"); + + if (isflagset(5)) + { + xlog("L_INFO", " This contact is behind NAT, appending nat=yes to the Contact header"); + + # "nat=yes" is added to help with in-dialog re-INVITE, UPDATE, etc. + search_append('Contact:.*sip:[^>[:cntrl:]]*', ';nat=yes'); + } + } + + # record routing + if (!is_method("REGISTER|MESSAGE")) + { + # Record the route that this request has taken + # so we remain in the signaling path + xlog("L_INFO", " Adding record route to this message"); + + record_route(); + } + + route(1); +} + +route[1] +{ + if (!t_relay()) + { + xlog("L_ERR", " Unable to relay [$rm] [$ru] to [$du], sending 500"); + + sl_reply_error(); + } + + xlog("L_INFO", " Sent [$rm] [$ru] to [$rd]"); + + exit; +} + +onreply_route[1] +{ + if (t_check_status("(407)|(401)")) + { + cache_store("memcached_callid_hash", "$ci ", "$si", 60); + + xlog("L_INFO", " Stored call-id [$ci] as belonging to media server [$si]"); + } +} + +onreply_route[nat_compensator] +{ + xlog("L_INFO ", " Compensating reply from NATed message [$rs] [$rr]"); + + if (t_check_status("(407)|(401)")) + { + cache_store("memcached_callid_hash", "$ci ", "$si", 60); + + xlog("L_INFO", " Stored call-id [$ci] for NATed reply as belonging to media server [$si]"); + } + + if (has_body("application/sdp")) + { + xlog("L_INFO", " Fixing nated reply SDP, rewritting media and origin with [$si]"); + + fix_nated_sdp("10"); + } + + if (is_present_hf("Contact")) + { + xlog("L_INFO", " Fixing nated reply contact header"); + + fix_nated_contact(); + #search_append('Contact:.*sip:[^>[:cntrl:]]*', ';nat=yes'); + } +} + +failure_route[1] +{ + if (t_was_cancelled()) + { + exit; + } + + if (t_check_status("(408)|(5[0-9][0-9])")) + { + xlog("L_ERR", " Media server [$rd] did not reply, disabling"); + + ds_mark_dst(); + + if (ds_next_domain()) + { + xlog("L_ERR", " Hunting for avaliable media server..."); + + xlog("L_INFO", " Sent [$rm] [$ru] to [$rd]"); + + t_relay(); + + exit; + } + } + else if (isbflagset(16) && t_check_status("[34][0-9][0-9]")) + { + xlog("L_INFO", " Failed to route call from carrier, sending 486"); + + t_reply("486", "The ratio of people to cake is too big"); + } + + exit; +}