Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
dwilkie committed Sep 24, 2024
1 parent afc7355 commit 68b7bd7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
48 changes: 26 additions & 22 deletions components/gateway/client_gateway/opensips.cfg
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
####### Global Parameters #########

/* uncomment the following lines to enable debugging */
debug_mode=no
debug_mode=0

log_level=3
xlog_level=2
log_stderror=yes
log_facility=LOG_LOCAL0

xlog_level=3
stderror_enabled=1
stderror_log_format="json"
syslog_enabled=0
udp_workers=4

/* uncomment the next line to enable the auto temporary blacklisting of
Expand Down Expand Up @@ -132,7 +132,7 @@ loadmodule "proto_udp.so"
# main request routing logic

route{
xlog("L_NOTICE", "Receiving request, method: $rm, source: $si, sdomain: $rd, contact uri: $ct.fields(uri)\n");
xlog("L_NOTICE", "Receiving request, method: $rm, source: $si, sdomain: $rd, contact uri: $ct.fields(uri)");

# https://kb.smartvox.co.uk/opensips/nat-contact-and-via-fixing-in-sip-part-2/
# https://www.cnblogs.com/zhangxianrong/p/14251867.html
Expand All @@ -149,15 +149,15 @@ route{
# OPTIONS requests
# https://opensips.org/html/docs/modules/3.4.x/options.html
if (is_method("OPTIONS")) {
xlog("L_NOTICE", "Received OPTIONS from $fu\n");
xlog("L_NOTICE", "Received OPTIONS from $fu");

options_reply();
exit;
}

if (is_method("REGISTER")) {
if (isflagset("NAT_FLAG")) {
xlog("L_NOTICE", "NATed register\n");
xlog("L_NOTICE", "NATed register");
# https://opensips.org/html/docs/modules/3.4.x/nathelper.html#func_fix_nated_register
# The function creates a URI consisting of the source IP, port, and protocol
# and stores the URI in an Attribute-Value-Pair.
Expand All @@ -181,7 +181,7 @@ route{
}
# store the registration and generate a SIP reply
if (!save("location"))
xlog("failed to register AoR $tu\n");
xlog("failed to register AoR $tu");

exit;
}
Expand Down Expand Up @@ -209,7 +209,7 @@ route{

# validate the sequential request against dialog
if ( $DLG_status!=NULL && !validate_dialog() ) {
xlog("In-Dialog $rm from $si (callid=$ci) is not valid according to dialog\n");
xlog("In-Dialog $rm from $si (callid=$ci) is not valid according to dialog");
fix_route_dialog();
}

Expand Down Expand Up @@ -237,7 +237,7 @@ route{
# INVITE Requests

if (is_domain_local($rd)) {
xlog("L_NOTICE", "Domain is local. INVITE for an inbound call\n");
xlog("L_NOTICE", "Domain is local. INVITE for an inbound call");
setflag("INBOUND_FLAG");

# https://opensips.org/html/docs/modules/3.4.x/nathelper.html#func_nat_uac_test
Expand All @@ -249,7 +249,7 @@ route{
# Note we don't need this check for outbound calls since we
# can assume the contact is correct
if (nat_uac_test("diff-ip-src-contact,diff-port-src-contact")) {
xlog("L_NOTICE", "Fixing nated contact\n ");
xlog("L_NOTICE", "Fixing nated contact");

fix_nated_contact();
}
Expand Down Expand Up @@ -292,7 +292,7 @@ route{

# preloaded route checking
if (loose_route()) {
xlog("L_ERR", "loose_route() returns true for invite!\n");
xlog("L_ERR", "loose_route() returns true for invite!");
xlog("L_ERR", "Attempt to route with preloaded Route's [$fu/$tu/$ru/$ci]");
if (!is_method("ACK"))
send_reply(403,"Preload Route denied");
Expand Down Expand Up @@ -331,13 +331,17 @@ route{
}

if (isflagset("INBOUND_FLAG")) {
xlog("L_NOTICE", "Load balancing request on port $rp\n");
xlog("L_NOTICE", "Starting LB with resources: gw\n");
xlog("L_NOTICE", "Load balancing request on port $rp");
xlog("L_NOTICE", "Starting LB with resources: gw");

if ( !lb_start(1,"gw")) {
if ( lb_start(1,"gw")) {
xlog("L_NOTICE", "Load balancing call to $dd");
$avp(lb_dest) = $dd;
} else {
send_reply(500,"No Destination available");
exit;
}
}

t_on_failure("GW_FAILOVER");
}
Expand All @@ -347,7 +351,7 @@ route{
}

route[RELAY] {
xlog("L_NOTICE", "Engage Media Proxy in $rm\n");
xlog("L_NOTICE", "Engage Media Proxy in $rm");

rtpengine_manage();

Expand All @@ -358,8 +362,8 @@ route[RELAY] {
}

onreply_route[RELAY] {
xlog("L_NOTICE", "On REPLY ROUTE from method: $rm, source: $si, reply status: $rs, contact uri: $ct.fields(uri)\n");
xlog("L_NOTICE", "Engaging Media Proxy\n");
xlog("L_NOTICE", "On REPLY ROUTE from method: $rm, source: $si, reply status: $rs, contact uri: $ct.fields(uri)");
xlog("L_NOTICE", "Engaging Media Proxy");

rtpengine_manage();

Expand All @@ -371,7 +375,7 @@ onreply_route[RELAY] {

# Note: This should only happen on reply from a client behind a NAT.
if (nat_uac_test("diff-ip-src-contact,diff-port-src-contact")) {
xlog("L_NOTICE", "Fixing nated contact\n ");
xlog("L_NOTICE", "Fixing nated contact");

fix_nated_contact();
}
Expand All @@ -384,15 +388,15 @@ failure_route[GW_FAILOVER] {

# failure detection with redirect to next available trunk
if (t_check_status("(408)|([56][0-9][0-9])")) {
xlog("Failed trunk $rd/$du detected \n");
xlog("L_NOTICE", "$T_reply_code-lb-response-error-$avp(lb_dest)");

if ( lb_next() ) {
t_on_failure("GW_FAILOVER");
t_relay();
exit;
}

send_reply(500,"All GW are down");
send_reply(500, "All GW are down");
}
}

Expand Down
2 changes: 1 addition & 1 deletion components/gateway/public_gateway/opensips.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ failure_route[GW_FAILOVER] {

# failure detection with redirect to next available trunk
if (t_check_status("(408)|([56][0-9][0-9])")) {
xlog("L_CRIT", "$T_reply_code-lb-response-error-$avp(lb_dest)");
xlog("L_NOTICE", "$T_reply_code-lb-response-error-$avp(lb_dest)");

if ( lb_next() ) {
t_on_failure("GW_FAILOVER");
Expand Down

0 comments on commit 68b7bd7

Please sign in to comment.