Selaa lähdekoodia

tm: make configurable the code and reason for generating timeout response

Daniel-Constantin Mierla 10 kuukautta sitten
vanhempi
commit
bedc4c259e

+ 3 - 3
src/modules/tm/t_fwd.c

@@ -1502,7 +1502,7 @@ int t_send_branch(struct cell *t, int branch, struct sip_msg *p_msg,
 		 *  a higly unlikely, perfectly timed fake reply (to a message
 		 *   we never sent).
 		 * (code=final reply && reply==0 => t_pick_branch won't ever pick it)*/
-		uac->last_received = 408;
+		uac->last_received = _tm_reply_408_code;
 		su2ip_addr(&ip, &uac->request.dst.to);
 		LM_DBG("onsend_route dropped msg. to %s:%d (%d)\n", ip_addr2a(&ip),
 				su_getport(&uac->request.dst.to), uac->request.dst.proto);
@@ -1538,7 +1538,7 @@ int t_send_branch(struct cell *t, int branch, struct sip_msg *p_msg,
 			 *  a higly unlikely, perfectly timed fake reply (to a message
 			 *   we never sent).  (code=final reply && reply==0 =>
 			 *   t_pick_branch won't ever pick it)*/
-			uac->last_received = 408;
+			uac->last_received = _tm_reply_408_code;
 #ifdef USE_DNS_FAILOVER
 			/* if the destination resolves to more ips, add another
 			 *  branch/uac */
@@ -1566,7 +1566,7 @@ int t_send_branch(struct cell *t, int branch, struct sip_msg *p_msg,
 		 *  a highly unlikely, perfectly timed fake reply (to a message
 		 *  we never sent).
 		 * (code=final reply && reply==0 => t_pick_branch won't ever pick it)*/
-		uac->last_received = 408;
+		uac->last_received = _tm_reply_408_code;
 		su2ip_addr(&ip, &uac->request.dst.to);
 		LM_DBG("send to %s:%d (%d) failed\n", ip_addr2a(&ip),
 				su_getport(&uac->request.dst.to), uac->request.dst.proto);

+ 7 - 3
src/modules/tm/t_reply.c

@@ -1401,7 +1401,7 @@ static enum rps t_should_relay_response(struct cell *Trans, int new_code,
 		 *  faked a CANCEL on a non-replied branch don't
 		 * report on it either */
 		if((Trans->uac[branch].last_received == 487)
-				|| (Trans->uac[branch].last_received == 408
+				|| (Trans->uac[branch].last_received == _tm_reply_408_code
 						&& new_code == 487)) {
 			LM_DBG("%d came for a %d branch (ignored)\n", new_code,
 					Trans->uac[branch].last_received);
@@ -1999,8 +1999,12 @@ enum rps relay_reply(struct cell *t, struct sip_msg *p_msg, int branch,
 				/* revert the temporary "store" reply above */
 				t->uac[branch].reply = reply_bak;
 			} else {
-				reason.s = error_text(relayed_code);
-				reason.len = strlen(reason.s);
+				if(relayed_code == _tm_reply_408_code) {
+					reason = _tm_reply_408_reason;
+				} else {
+					reason.s = error_text(relayed_code);
+					reason.len = strlen(reason.s);
+				}
 				buf = build_res_buf_from_sip_req(relayed_code, &reason, to_tag,
 						t->uas.request, &res_len, &bm);
 			}

+ 3 - 0
src/modules/tm/t_reply.h

@@ -58,6 +58,9 @@ extern int faked_reply_prio;
 
 extern int tm_rich_redirect;
 
+extern int _tm_reply_408_code;
+extern str _tm_reply_408_reason;
+
 /* has this to-tag been never seen in previous 200/INVs? */
 int unmatched_totag(struct cell *t, struct sip_msg *ack);
 

+ 1 - 1
src/modules/tm/timer.c

@@ -460,7 +460,7 @@ inline static void final_response_handler(
 		}
 #endif
 	}
-	fake_reply(t, r_buf->branch, 408);
+	fake_reply(t, r_buf->branch, _tm_reply_408_code);
 }
 
 

+ 4 - 0
src/modules/tm/tm.c

@@ -225,6 +225,8 @@ str ulattrs_xavp_name = {NULL, 0};
 str on_sl_reply_name = {NULL, 0};
 int tm_remap_503_500 = 1;
 str _tm_event_callback_lres_sent = {NULL, 0};
+int _tm_reply_408_code = 408;
+str _tm_reply_408_reason = str_init("Request Timeout");
 
 #ifdef USE_DNS_FAILOVER
 str failover_reply_codes_str = {NULL, 0};
@@ -522,6 +524,8 @@ static param_export_t params[] = {
 #ifdef USE_DNS_FAILOVER
 	{"failover_reply_codes", PARAM_STR, &failover_reply_codes_str},
 #endif
+	{"reply_408_code", PARAM_INT, &_tm_reply_408_code},
+	{"reply_408_reason", PARAM_STR, &_tm_reply_408_reason},
 	{0, 0, 0}
 };
 

+ 1 - 1
src/modules/tm/uac.c

@@ -718,7 +718,7 @@ static inline int send_prepared_request_impl(
 	if(run_onsend(p_msg, &uac->request.dst, uac->request.buffer,
 			   uac->request.buffer_len)
 			== 0) {
-		uac->last_received = 408;
+		uac->last_received = _tm_reply_408_code;
 		su2ip_addr(&ip, &uac->request.dst.to);
 		LM_DBG("onsend_route dropped msg. to %s:%d (%d)\n", ip_addr2a(&ip),
 				su_getport(&uac->request.dst.to), uac->request.dst.proto);