2
0
Эх сурвалжийг харах

Fixing improper blacklisting of destinations because of non-INVITE timeouts.
Two new module parameters are introduced:

- blst_methods_add:
bitmap of method types that can trigger blacklisting
(only INVITE by default)

- blst_methods_lookup:
bitmap of method types that are looked up in the blacklist
(everything except BYE by default)

closes SER-331

Miklos Tirpak 18 жил өмнө
parent
commit
e9ae889126

+ 57 - 0
modules/tm/doc/params.xml

@@ -370,4 +370,61 @@ modparam("tm", "blst_503_max_timeout", 604800)
 	</example>
     </section>
 
+    <section id="blst_methods_add">
+	<title><varname>blst_methods_add</varname> (unsigned integer)</title>
+	<para>
+		Bitmap of method types that trigger blacklisting on
+		transaction timeouts. (This setting has no
+		effect on blacklisting because of send failures.)
+	</para>
+	<para>
+		The following values are associated to the request methods:
+		INVITE=1, CANCEL=2, ACK=4 (not retransmitted, thus, never
+		times-out), BYE=8, INFO=16, REGISTER=32, SUBSCRIBE=64,
+		NOTIFY=126, OTHER=256 (all the unknown types).
+		Check parser/msg_parser.h for farther details.
+	</para>
+	<para>
+		Change the value carefully, because requests not having
+		provisional response (everything but INVITE) can easily
+		cause the next hop to be inserted into the blacklist
+		by mistake. For exmaple the next hop is a proxy, it is alive,
+		but waiting for the response of the UAS, and has higher
+		fr_timer value.
+	</para>
+	<para>
+		The default value is 1, only INVITEs trigger blacklisting
+	</para>
+	<example>
+	    <title>Set <varname>blst_methods_add</varname> parameter</title>
+	    <programlisting>
+...
+# INVITEs and REGISTERs trigger blacklisting
+modparam("tm", "blst_methods_add", 33)
+...
+	    </programlisting>
+	</example>
+    </section>
+
+    <section id="blst_methods_lookup">
+	<title><varname>blst_methods_lookup</varname> (unsigned integer)</title>
+	<para>
+		Bitmap of method types that are looked-up in the blacklist
+		before statefull forwarding.
+		See also <varname>blst_methods_add</varname>
+	</para>
+	<para>
+		The default value is 4294967287, every method type except BYE.
+		(We try to deliver BYEs no matter what)
+	</para>
+	<example>
+	    <title>Set <varname>blst_methods_lookup</varname> parameter</title>
+	    <programlisting>
+...
+# lookup only INVITEs
+modparam("tm", "blst_methods_lookup", 1)
+...
+	    </programlisting>
+	</example>
+    </section>
 </section>

+ 4 - 1
modules/tm/t_fwd.c

@@ -690,7 +690,10 @@ int t_send_branch( struct cell *t, int branch, struct sip_msg* p_msg ,
 		return -1; /* drop, try next branch */
 	}
 #ifdef USE_DST_BLACKLIST
-	if (use_dst_blacklist){
+	if (use_dst_blacklist
+		&& p_msg
+		&& (p_msg->REQ_METHOD & tm_blst_methods_lookup)
+	){
 		if (dst_is_blacklisted(&uac->request.dst, p_msg)){
 			su2ip_addr(&ip, &uac->request.dst.to);
 			DBG("t_send_branch: blacklisted destination: %s:%d (%d)\n",

+ 4 - 0
modules/tm/t_reply.c

@@ -145,6 +145,10 @@ int tm_blst_503_min=0; /* in s */
 /* maximum 503 blacklist time */
 int tm_blst_503_max=3600; /* in s */
 
+/* backlist only INVITE timeouts by default */
+unsigned int tm_blst_methods_add=METHOD_INVITE;
+/* look-up the blacklist for every method except BYE by default */
+unsigned int tm_blst_methods_lookup=~METHOD_BYE;
 
 /* are we processing original or shmemed request ? */
 enum route_mode rmode=MODE_REQUEST;

+ 2 - 0
modules/tm/t_reply.h

@@ -44,6 +44,8 @@ extern int tm_blst_503;
 extern int tm_blst_503_default;  /* in s */
 extern int tm_blst_503_min;      /* in s */
 extern int tm_blst_503_max;      /* in s */
+extern unsigned int tm_blst_methods_add;
+extern unsigned int tm_blst_methods_lookup;
 
 /* reply processing status */
 enum rps {

+ 6 - 2
modules/tm/timer.c

@@ -455,9 +455,13 @@ inline static void final_response_handler(	struct retr_buf* r_buf,
 			(t->uac[r_buf->branch].last_received==0)){
 		/* no reply received */
 #ifdef USE_DST_BLACKLIST
-		if (use_dst_blacklist)
+		if (use_dst_blacklist
+        		&& r_buf->my_T
+			&& r_buf->my_T->uas.request
+			&& (r_buf->my_T->uas.request->REQ_METHOD & tm_blst_methods_add)
+		)
 			dst_blacklist_add( BLST_ERR_TIMEOUT, &r_buf->dst,
-				(r_buf->my_T)?r_buf->my_T->uas.request:NULL);
+						r_buf->my_T->uas.request);
 #endif
 #ifdef USE_DNS_FAILOVER
 		/* if this is an invite, the destination resolves to more ips, and

+ 2 - 0
modules/tm/tm.c

@@ -364,6 +364,8 @@ static param_export_t params[]={
 	{"blst_503_def_timeout",PARAM_INT, &tm_blst_503_default                  },
 	{"blst_503_min_timeout",PARAM_INT, &tm_blst_503_min                      },
 	{"blst_503_max_timeout",PARAM_INT, &tm_blst_503_max                      },
+	{"blst_methods_add",    PARAM_INT, &tm_blst_methods_add                  },
+	{"blst_methods_lookup", PARAM_INT, &tm_blst_methods_lookup               },
 	{0,0,0}
 };