route {
# stop forwarding at 10 hops to prevent infinite loops
if (!mf_process_maxfwd_header("10")) {
log(1, "LOG: Too many hops\n");
sl_send_reply("483", "Too many hops");
break;
};
# prevents private ip space from being used
if (search("^(Contact|m): .*@(192\.168\.|10\.|172\.16)")) {
if (method=="REGISTER") {
log(1, "LOG: Someone trying to register from private IP\n");
sl_send_reply("479", "Please don't use private IP addresses" );
break;
};
};
if (!(uri==myself)) {
route(4);
break;
}
# separate the destination r-uri from the set of proxies that must be traversed
loose_route();
# Local Calls route to telica first
if ( uri=~"sip:(1?786|1?305|1?754|1?561|1?954|1?772|1?877|1?888|1?800|1?866|1?700|1?[1-9]11)" ) {
route(2);
break;
} else {
route(3);
break;
};
} /* end of initial routing logic */
route[2] {
# add a record_route to make sure the gw doesnt bounce it back
record_route();
if (src_ip==216.106.190.31) {
rewritehostport("216.106.183.2:5060");
append_hf("P-hint: GATEWAY\r\n");
};
if (src_ip==216.106.183.2) {
rewritehostport("216.106.190.31");
append_hf("P-hint: FROM-GATEWAY\r\n");
};
if (!t_relay()) {
sl_reply_error();
break;
};
}
route[3] {
# add a record_route to make sure the gw doesnt bounce it back
record_route();
if (src_ip==216.106.190.31) {
rewritehostport("216.106.184.238:5060");
append_hf("P-hint: GATEWAY\r\n");
};
if (src_ip==216.106.184.238) {
rewritehostport("216.106.190.31");
append_hf("P-hint: FROM-GATEWAY\r\n");
};
if (!t_relay()) {
sl_reply_error();
break;
};
}
route[4] {
if (!src_ip==216.106.183.2 | !src_ip==216.106.190.31 | !src_ip==216.106.184.238) {
log(1, "LOG: Spoofed from attempt\n");
sl_send_reply("403", "Use From=id next time");
break;
};
if(!t_relay()) {
sl_reply_error();
};
}