Browse code

Merge 0b351170023ea88e3d6b613f119554bea5c99607 into da0178673f9a47600329fff2c3105e0fbfbd78f7

vlitvinov authored on 09/08/2022 14:17:19 • GitHub committed on 09/08/2022 14:17:19
Showing 4 changed files
... ...
@@ -76,6 +76,7 @@ struct cfg_group_tm	default_tm_cfg = {
76 76
 	500,	/* default_code */
77 77
 	1,	/* reparse_invite */
78 78
 
79
+	0,	/* tm_dns_failover_branch_failure -- if 1 in case 503 will be executed branch_failure route*/
79 80
 	0,	/* tm_blst_503 -- if 1 blocklist 503 sources, using tm_blst_503_min,
80 81
 		 * tm_blst_503_max, tm_blst_503_default and the Retry-After header
81 82
 		 * in the 503 reply */
... ...
@@ -167,6 +168,8 @@ cfg_def_t	tm_cfg_def[] = {
167 168
 		"if set to 1, the CANCEL and negative ACK requests are "
168 169
 		"constructed from the INVITE message which was sent out "
169 170
 		"instead of building them from the received request"},
171
+	{"dns_failover_branch_failure",		CFG_VAR_INT | CFG_ATOMIC,	0, 1, 0, 0,
172
+		"if set to 1, branch_failure route will be executed in case 503 reply"},
170 173
 	{"blst_503",		CFG_VAR_INT | CFG_ATOMIC,	0, 1, 0, 0,
171 174
 		"if set to 1, blocklist 503 SIP response sources"},
172 175
 	{"blst_503_def_timeout",	CFG_VAR_INT | CFG_ATOMIC,	0, 0, 0, 0,
... ...
@@ -117,6 +117,7 @@ struct cfg_group_tm {
117 117
 	int	unmatched_cancel;
118 118
 	int	default_code;
119 119
 	int	reparse_invite;
120
+	int	tm_dns_failover_branch_failure;
120 121
 	int	tm_blst_503;
121 122
 	int	tm_blst_503_default;
122 123
 	int	tm_blst_503_min;
... ...
@@ -2330,8 +2330,8 @@ int reply_received( struct sip_msg  *p_msg )
2330 2330
 	sr_xavp_t **backup_xavis;
2331 2331
 	int replies_locked = 0;
2332 2332
 #ifdef USE_DNS_FAILOVER
2333
-	int branch_ret;
2334
-	int prev_branch;
2333
+	int branch_ret = -1;
2334
+	int prev_branch = -1;
2335 2335
 	int failover_continue = 0;
2336 2336
 #endif
2337 2337
 #ifdef USE_DST_BLOCKLIST
... ...
@@ -2494,8 +2494,33 @@ int reply_received( struct sip_msg  *p_msg )
2494 2494
 	 * corresponding branch had it set on send */
2495 2495
 	p_msg->fwd_send_flags.blst_imask|=
2496 2496
 		uac->request.dst.send_flags.blst_imask & BLST_503;
2497
+#ifdef USE_DNS_FAILOVER
2498
+	/* if this is a 503 reply, and the destination resolves to more ips,
2499
+	 *  add another branch/uac.
2500
+	 *  This code is out of LOCK_REPLIES() to minimize the time the
2501
+	 *  reply lock is held (the lock won't be held while sending the
2502
+	 *   message)*/
2503
+
2504
+
2505
+	failover_continue = (failover_reply_codes_str.s!=NULL && failover_reply_codes_str.len>0 &&
2506
+						t_failover_check_reply_code(msg_status));
2507
+
2508
+	if (cfg_get(core, core_cfg, use_dns_failover) && (msg_status==503 || failover_continue)) {
2509
+		branch_ret=add_uac_dns_fallback(t, t->uas.request,
2510
+											uac, !replies_locked);
2511
+		prev_branch=-1;
2512
+		while((branch_ret>=0) &&(branch_ret!=prev_branch)){
2513
+			prev_branch=branch_ret;
2514
+			branch_ret=t_send_branch(t, branch_ret, t->uas.request , 0, 1);
2515
+		}
2516
+	}
2517
+#endif
2497 2518
 	/* processing of on_reply block */
2498
-	if (onreply_route || sr_event_enabled(SREV_SIP_REPLY_OUT)) {
2519
+	if ((onreply_route || sr_event_enabled(SREV_SIP_REPLY_OUT))
2520
+#ifdef USE_DNS_FAILOVER
2521
+		&& (cfg_get(tm, tm_cfg, tm_dns_failover_branch_failure) ? (branch_ret<0) : 1 )
2522
+#endif
2523
+	) {
2499 2524
 		set_route_type(TM_ONREPLY_ROUTE);
2500 2525
 		/* transfer transaction flag to message context */
2501 2526
 		if (t->uas.request) {
... ...
@@ -2641,27 +2666,6 @@ int reply_received( struct sip_msg  *p_msg )
2641 2666
 			}
2642 2667
 		}
2643 2668
 #endif /* USE_DST_BLOCKLIST */
2644
-#ifdef USE_DNS_FAILOVER
2645
-		/* if this is a 503 reply, and the destination resolves to more ips,
2646
-		 *  add another branch/uac.
2647
-		 *  This code is out of LOCK_REPLIES() to minimize the time the
2648
-		 *  reply lock is held (the lock won't be held while sending the
2649
-		 *   message)*/
2650
-
2651
-
2652
-		failover_continue = (failover_reply_codes_str.s!=NULL && failover_reply_codes_str.len>0 &&
2653
-							t_failover_check_reply_code(msg_status));
2654
-
2655
-		if (cfg_get(core, core_cfg, use_dns_failover) && (msg_status==503 || failover_continue)) {
2656
-			branch_ret=add_uac_dns_fallback(t, t->uas.request,
2657
-												uac, !replies_locked);
2658
-			prev_branch=-1;
2659
-			while((branch_ret>=0) &&(branch_ret!=prev_branch)){
2660
-				prev_branch=branch_ret;
2661
-				branch_ret=t_send_branch(t, branch_ret, t->uas.request , 0, 1);
2662
-			}
2663
-		}
2664
-#endif
2665 2669
 
2666 2670
 	if (t->flags & T_ASYNC_SUSPENDED) {
2667 2671
 		LM_DBG("Reply for suspended transaction, done.\n");
... ...
@@ -467,6 +467,8 @@ static param_export_t params[]={
467 467
 	{"default_reason",      PARAM_STRING, &default_tm_cfg.default_reason     },
468 468
 	{"reparse_invite",      PARAM_INT, &default_tm_cfg.reparse_invite        },
469 469
 	{"ac_extra_hdrs",       PARAM_STR, &default_tm_cfg.ac_extra_hdrs         },
470
+	{"dns_failover_branch_failure", PARAM_INT,
471
+		&default_tm_cfg.tm_dns_failover_branch_failure},
470 472
 	{"blst_503",            PARAM_INT, &default_tm_cfg.tm_blst_503           },
471 473
 	{"blst_503_def_timeout",PARAM_INT, &default_tm_cfg.tm_blst_503_default   },
472 474
 	{"blst_503_min_timeout",PARAM_INT, &default_tm_cfg.tm_blst_503_min       },