Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- request_route {
- # per request initial checks
- route(REQINIT);
- # handle requests within SIP dialogs
- route(WITHINDLG);
- # record routing for dialog forming requests (in case they are routed)
- # - remove preloaded route headers
- remove_hf("Route");
- if (is_method("INVITE")) {
- record_route();
- }
- redis_cmd("redis", "GET dnis:$rU", "r");
- xdbg("***** Redis: GET dnis:$rU => $redis(r=>value)\n");
- if ($redis(r=>value) eq "") {
- sl_send_reply("404","Not here");
- exit;
- }
- $du="sip:" + $rU + "@" + $redis(r=>value);
- $rd=$redis(r=>value);
- forward();
- }
- # Per SIP request initial checks
- route[REQINIT] {
- #!ifdef WITH_ANTIFLOOD
- # flood detection from same IP and traffic ban for a while
- # be sure you exclude checking trusted peers, such as pstn gateways
- # - local host excluded (e.g., loop to self)
- if(src_ip!=myself) {
- if($sht(ipban=>$si)!=$null) {
- # ip is already blocked
- xdbg("request from blocked IP - $rm from $fu (IP:$si:$sp)\n");
- exit;
- }
- if (!pike_check_req()) {
- xlog("L_ALERT","ALERT: pike blocking $rm from $fu (IP:$si:$sp)\n");
- $sht(ipban=>$si) = 1;
- exit;
- }
- }
- #!endif
- 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()) {
- xlog("Malformed SIP message from $si:$sp\n");
- exit;
- }
- if ($rU==$null) {
- # request with no Username in RURI
- sl_send_reply("484","Address Incomplete");
- exit;
- }
- }
- # Handle requests within SIP dialogs
- route[WITHINDLG] {
- if (!has_totag()) return;
- # sequential request withing a dialog should
- # take the path determined by record-routing
- if (loose_route()) {
- if ( is_method("NOTIFY") ) {
- # Add Record-Route for in-dialog NOTIFY as per RFC 6665.
- record_route();
- }
- forward();
- exit;
- }
- if ( is_method("ACK|CANCEL") ) {
- return;
- }
- sl_send_reply("404","Not here");
- exit;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement