From 475412b3e3c0b442110bd3fa801c1bf59ba455db Mon Sep 17 00:00:00 2001 From: vlitvinov Date: Tue, 5 Dec 2023 00:39:01 +0100 Subject: [PATCH] branch_failure route in case 503 and dns failover --- src/modules/tm/config.c | 3 ++ src/modules/tm/config.h | 1 + src/modules/tm/doc/params.xml | 20 +++++++++++++ src/modules/tm/t_reply.c | 54 ++++++++++++++++++----------------- src/modules/tm/tm.c | 2 ++ 5 files changed, 54 insertions(+), 26 deletions(-) diff --git a/src/modules/tm/config.c b/src/modules/tm/config.c index 3cf4f156528..fea1d82f456 100644 --- a/src/modules/tm/config.c +++ b/src/modules/tm/config.c @@ -76,6 +76,7 @@ struct cfg_group_tm default_tm_cfg = { 500, /* default_code */ 1, /* reparse_invite */ + 0, /* tm_dns_failover_branch_failure -- if 1 in case 503 will be executed branch_failure route*/ 0, /* tm_blst_503 -- if 1 blocklist 503 sources, using tm_blst_503_min, * tm_blst_503_max, tm_blst_503_default and the Retry-After header * in the 503 reply */ @@ -169,6 +170,8 @@ cfg_def_t tm_cfg_def[] = { "if set to 1, the CANCEL and negative ACK requests are " "constructed from the INVITE message which was sent out " "instead of building them from the received request"}, + {"dns_failover_branch_failure", CFG_VAR_INT | CFG_ATOMIC, 0, 1, 0, 0, + "if set to 1, branch_failure route will be executed in case 503 reply"}, {"blst_503", CFG_VAR_INT | CFG_ATOMIC, 0, 1, 0, 0, "if set to 1, blocklist 503 SIP response sources"}, {"blst_503_def_timeout", CFG_VAR_INT | CFG_ATOMIC, 0, 0, 0, 0, diff --git a/src/modules/tm/config.h b/src/modules/tm/config.h index 2c215d2ab41..09903f7241a 100644 --- a/src/modules/tm/config.h +++ b/src/modules/tm/config.h @@ -118,6 +118,7 @@ struct cfg_group_tm int unmatched_cancel; int default_code; int reparse_invite; + int tm_dns_failover_branch_failure; int tm_blst_503; int tm_blst_503_default; int tm_blst_503_min; diff --git a/src/modules/tm/doc/params.xml b/src/modules/tm/doc/params.xml index b8d7a8a3db4..5552beded4e 100644 --- a/src/modules/tm/doc/params.xml +++ b/src/modules/tm/doc/params.xml @@ -1659,6 +1659,26 @@ modparam("tm", "enable_uac_fr", 1) ... modparam("tm", "failover_reply_codes", "code=403;code=488;class=5") ... + + + + +
+ <varname>dns_failover_branch_failure</varname> (int) + + if set to 1, branch_failure route will be executed in case 503 reply + + + + Default value is 0 + + + + Set the <quote>dns_failover_branch_failure</quote> parameter + +... +modparam("tm", "dns_failover_branch_failure", 1) +...
diff --git a/src/modules/tm/t_reply.c b/src/modules/tm/t_reply.c index e9b9df434a5..3a53aca762e 100644 --- a/src/modules/tm/t_reply.c +++ b/src/modules/tm/t_reply.c @@ -2340,8 +2340,8 @@ int reply_received(struct sip_msg *p_msg) sr_xavp_t **backup_xavis; int replies_locked = 0; #ifdef USE_DNS_FAILOVER - int branch_ret; - int prev_branch; + int branch_ret = -1; + int prev_branch = -1; int failover_continue = 0; #endif #ifdef USE_DST_BLOCKLIST @@ -2505,8 +2505,33 @@ int reply_received(struct sip_msg *p_msg) * corresponding branch had it set on send */ p_msg->fwd_send_flags.blst_imask |= uac->request.dst.send_flags.blst_imask & BLST_503; +#ifdef USE_DNS_FAILOVER + /* if this is a 503 reply, and the destination resolves to more ips, + * add another branch/uac. + * This code is out of LOCK_REPLIES() to minimize the time the + * reply lock is held (the lock won't be held while sending the + * message)*/ + + + failover_continue = (failover_reply_codes_str.s!=NULL && failover_reply_codes_str.len>0 && + t_failover_check_reply_code(msg_status)); + + if (cfg_get(core, core_cfg, use_dns_failover) && (msg_status==503 || failover_continue)) { + branch_ret=add_uac_dns_fallback(t, t->uas.request, + uac, !replies_locked); + prev_branch=-1; + while((branch_ret>=0) &&(branch_ret!=prev_branch)){ + prev_branch=branch_ret; + branch_ret=t_send_branch(t, branch_ret, t->uas.request , 0, 1); + } + } +#endif /* processing of on_reply block */ - if(onreply_route || sr_event_enabled(SREV_SIP_REPLY_OUT)) { + if ((onreply_route || sr_event_enabled(SREV_SIP_REPLY_OUT)) +#ifdef USE_DNS_FAILOVER + && (cfg_get(tm, tm_cfg, tm_dns_failover_branch_failure) ? (branch_ret<0) : 1 ) +#endif + ) { set_route_type(TM_ONREPLY_ROUTE); /* transfer transaction flag to message context */ if(t->uas.request) { @@ -2651,29 +2676,6 @@ int reply_received(struct sip_msg *p_msg) } } #endif /* USE_DST_BLOCKLIST */ -#ifdef USE_DNS_FAILOVER - /* if this is a 503 reply, and the destination resolves to more ips, - * add another branch/uac. - * This code is out of LOCK_REPLIES() to minimize the time the - * reply lock is held (the lock won't be held while sending the - * message)*/ - - - failover_continue = (failover_reply_codes_str.s != NULL - && failover_reply_codes_str.len > 0 - && t_failover_check_reply_code(msg_status)); - - if(cfg_get(core, core_cfg, use_dns_failover) - && (msg_status == 503 || failover_continue)) { - branch_ret = - add_uac_dns_fallback(t, t->uas.request, uac, !replies_locked); - prev_branch = -1; - while((branch_ret >= 0) && (branch_ret != prev_branch)) { - prev_branch = branch_ret; - branch_ret = t_send_branch(t, branch_ret, t->uas.request, 0, 1); - } - } -#endif if(t->flags & T_ASYNC_SUSPENDED) { LM_DBG("Reply for suspended transaction, done.\n"); diff --git a/src/modules/tm/tm.c b/src/modules/tm/tm.c index 67b954b03c8..0d41d770cad 100644 --- a/src/modules/tm/tm.c +++ b/src/modules/tm/tm.c @@ -481,6 +481,8 @@ static param_export_t params[] = { {"default_reason", PARAM_STRING, &default_tm_cfg.default_reason}, {"reparse_invite", PARAM_INT, &default_tm_cfg.reparse_invite}, {"ac_extra_hdrs", PARAM_STR, &default_tm_cfg.ac_extra_hdrs}, + {"dns_failover_branch_failure", PARAM_INT, + &default_tm_cfg.tm_dns_failover_branch_failure}, {"blst_503", PARAM_INT, &default_tm_cfg.tm_blst_503}, {"blst_503_def_timeout", PARAM_INT, &default_tm_cfg.tm_blst_503_default},