Advertisement
Guest User

Untitled

a guest
Dec 17th, 2018
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.21 KB | None | 0 0
  1. request_route {
  2.  
  3.     # per request initial checks
  4.     route(REQINIT);
  5.  
  6.     # handle requests within SIP dialogs
  7.     route(WITHINDLG);
  8.  
  9.     # record routing for dialog forming requests (in case they are routed)
  10.     # - remove preloaded route headers
  11.     remove_hf("Route");
  12.     if (is_method("INVITE")) {
  13.       record_route();
  14.     }
  15.  
  16.     redis_cmd("redis", "GET dnis:$rU", "r");
  17.     xdbg("***** Redis: GET dnis:$rU => $redis(r=>value)\n");
  18.     if ($redis(r=>value) eq "") {
  19.       sl_send_reply("404","Not here");
  20.       exit;
  21.     }
  22.  
  23.     $du="sip:" + $rU + "@" + $redis(r=>value);
  24.     $rd=$redis(r=>value);
  25.     forward();
  26. }
  27.  
  28.  
  29. # Per SIP request initial checks
  30. route[REQINIT] {
  31. #!ifdef WITH_ANTIFLOOD
  32.     # flood detection from same IP and traffic ban for a while
  33.     # be sure you exclude checking trusted peers, such as pstn gateways
  34.     # - local host excluded (e.g., loop to self)
  35.     if(src_ip!=myself) {
  36.         if($sht(ipban=>$si)!=$null) {
  37.             # ip is already blocked
  38.             xdbg("request from blocked IP - $rm from $fu (IP:$si:$sp)\n");
  39.             exit;
  40.         }
  41.         if (!pike_check_req()) {
  42.             xlog("L_ALERT","ALERT: pike blocking $rm from $fu (IP:$si:$sp)\n");
  43.             $sht(ipban=>$si) = 1;
  44.             exit;
  45.         }
  46.     }
  47. #!endif
  48.     if($ua =~ "friendly-scanner|sipcli|VaxSIPUserAgent") {
  49.         # silent drop for scanners - uncomment next line if want to reply
  50.         # sl_send_reply("200", "OK");
  51.         exit;
  52.     }
  53.  
  54.     if (!mf_process_maxfwd_header("10")) {
  55.         sl_send_reply("483","Too Many Hops");
  56.         exit;
  57.     }
  58.  
  59.     if(is_method("OPTIONS") && uri==myself && $rU==$null) {
  60.         sl_send_reply("200","Keepalive");
  61.         exit;
  62.     }
  63.  
  64.     if(!sanity_check()) {
  65.         xlog("Malformed SIP message from $si:$sp\n");
  66.         exit;
  67.     }
  68.  
  69.     if ($rU==$null) {
  70.         # request with no Username in RURI
  71.         sl_send_reply("484","Address Incomplete");
  72.         exit;
  73.     }
  74. }
  75.  
  76.  
  77. # Handle requests within SIP dialogs
  78. route[WITHINDLG] {
  79.     if (!has_totag()) return;
  80.  
  81.     # sequential request withing a dialog should
  82.     # take the path determined by record-routing
  83.     if (loose_route()) {
  84.         if ( is_method("NOTIFY") ) {
  85.             # Add Record-Route for in-dialog NOTIFY as per RFC 6665.
  86.             record_route();
  87.         }
  88.         forward();
  89.         exit;
  90.     }
  91.  
  92.     if ( is_method("ACK|CANCEL") ) {
  93.       return;
  94.     }
  95.  
  96.     sl_send_reply("404","Not here");
  97.     exit;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement