-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcall_source.cfg
64 lines (55 loc) · 2.13 KB
/
call_source.cfg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
route[call_source]{
$avp(called_number)=$rU;
$avp(caller_id)=$fU;
$avp(src_ip)=$si;
//check if inbound call
redis_cmd("redis","HMGET did:$avp(called_number) custId carrierId countryId billType channel rtpEngine routingType","r");
if($redis(r=>value[2])!=0){
$avp(custId)=$redis(r=>value[0]);
$avp(carrierId)=$redis(r=>value[1]);
$avp(countryId)=$redis(r=>value[2]);
$avp(billType)=$redis(r=>value[3]);
$avp(didChannels)=$redis(r=>value[4]);
$avp(rtpEngine)=$redis(r=>value[5]);
if($(avp(rtpEngine){s.int})==1){
xlog("L_INFO","Setting rtpEngine for inbound call");
$sht(rtpProxy=>mip_$ci)=1;
}
$avp(routingType)=$redis(r=>value[6]);
$avp(direction)="In";
//validate src for carrier ip
route(validate_carrier_ip);
if(isflagset(SIP_IP_OK)){
xlog("L_INFO","Source is Authorised Carrier $si");
if($avp(routingType))!=0{
route(is_carrier);
}else{
$avp(sip_code)="404";
$avp(sip_reason)="Not Routed";
route(SET_CDR);
acc_db_request("Not Routed", "failed_calls");
sl_send_reply("404","Not Routed");
exit;
}
exit;
}
}
xlog("L_INFO","Forbidden for $si $ua");
sl_send_reply("403", "Forbidden");
exit;
}
route[validate_carrier_ip]{
redis_cmd("redis","SMEMBERS carrierIPs:$avp(carrierId)","r");
$var(count)=$redis(r=>size);
$var(iterate)=0;
while ($(var(count){s.int})>=$null && $var(count)!=""){
$avp((ip_access)[$var(iterate)])=$redis(r=>value[$var(iterate)]);
xlog("L_INFO","ip_access:[$var(iterate)] : $avp((ip_access)[$var(iterate)])");
if (is_in_subnet("$si", "$avp((ip_access)[$var(iterate)])")) {
xlog("L_INFO", "$var(count) is in the subnet $var(count) $var(iterate)\n");
setflag(SIP_IP_OK);
}
$var(count)=$var(count)-1;
$var(iterate)=$var(iterate)+1;
}
}