Browse code

core: execute onsend_route for replies before sending out

- control execution of onsend_route block for replies via parameter
onsend_route_reply

Lucian Balaceanu authored on 12/10/2014 08:28:29
Showing 6 changed files
... ...
@@ -495,7 +495,7 @@ LATENCY_LIMIT_DB		latency_limit_db
495 495
 LATENCY_LIMIT_ACTION	latency_limit_action
496 496
 
497 497
 MSG_TIME	msg_time
498
-
498
+ONSEND_RT_REPLY		"onsend_route_reply"
499 499
 CFG_DESCRIPTION		"description"|"descr"|"desc"
500 500
 
501 501
 LOADMODULE	loadmodule
... ...
@@ -938,6 +938,7 @@ IMPORTFILE      "import_file"
938 938
 <INITIAL>{MAX_RECURSIVE_LEVEL}  { count(); yylval.strval=yytext; return MAX_RECURSIVE_LEVEL;}
939 939
 <INITIAL>{LATENCY_LOG}  { count(); yylval.strval=yytext; return LATENCY_LOG;}
940 940
 <INITIAL>{MSG_TIME}  { count(); yylval.strval=yytext; return MSG_TIME;}
941
+<INITIAL>{ONSEND_RT_REPLY}	{ count(); yylval.strval=yytext; return ONSEND_RT_REPLY; }
941 942
 <INITIAL>{LATENCY_LIMIT_DB}  { count(); yylval.strval=yytext; return LATENCY_LIMIT_DB;}
942 943
 <INITIAL>{LATENCY_LIMIT_ACTION}  { count(); yylval.strval=yytext; return LATENCY_LIMIT_ACTION;}
943 944
 <INITIAL>{CFG_DESCRIPTION}	{ count(); yylval.strval=yytext; return CFG_DESCRIPTION; }
... ...
@@ -547,6 +547,7 @@ extern char *default_routename;
547 547
 %token LATENCY_LIMIT_DB
548 548
 %token LATENCY_LIMIT_ACTION
549 549
 %token MSG_TIME
550
+%token ONSEND_RT_REPLY
550 551
 
551 552
 %token FLAGS_DECL
552 553
 %token AVPFLAGS_DECL
... ...
@@ -1579,6 +1580,8 @@ assign_stm:
1579 1579
 	| LATENCY_LIMIT_ACTION EQUAL error  { yyerror("number  expected"); }
1580 1580
     | MSG_TIME EQUAL NUMBER { sr_msg_time=$3; }
1581 1581
 	| MSG_TIME EQUAL error  { yyerror("number  expected"); }
1582
+	| ONSEND_RT_REPLY EQUAL NUMBER { onsend_route_reply=$3; }
1583
+	| ONSEND_RT_REPLY EQUAL error { yyerror("int value expected"); }
1582 1584
 	| UDP_MTU EQUAL NUMBER { default_core_cfg.udp_mtu=$3; }
1583 1585
 	| UDP_MTU EQUAL error { yyerror("number expected"); }
1584 1586
 	| FORCE_RPORT EQUAL NUMBER 
... ...
@@ -758,6 +758,7 @@ static int do_forward_reply(struct sip_msg* msg, int mode)
758 758
 	struct dest_info dst;
759 759
 	unsigned int new_len;
760 760
 	int r;
761
+	struct ip_addr ip;
761 762
 #ifdef USE_TCP
762 763
 	char* s;
763 764
 	int len;
... ...
@@ -836,11 +837,6 @@ static int do_forward_reply(struct sip_msg* msg, int mode)
836 836
 
837 837
 	apply_force_send_socket(&dst, msg);
838 838
 
839
-	if (msg_send(&dst, new_buf, new_len)<0)
840
-	{
841
-		STATS_RPL_FWD_DROP();
842
-		goto error;
843
-	}
844 839
 	/* call onsend_route */
845 840
 	if(dst.send_sock == NULL) {
846 841
 		dst.send_sock=get_send_socket(msg, &dst.to, dst.proto);
... ...
@@ -849,7 +845,21 @@ static int do_forward_reply(struct sip_msg* msg, int mode)
849 849
 			goto done;
850 850
 		}
851 851
 	}
852
-	run_onsend(msg, &dst, new_buf, new_len);
852
+	if (onsend_route_enabled(SIP_REPLY)){
853
+		if (run_onsend(msg, &dst, new_buf, new_len)==0){
854
+			su2ip_addr(&ip, &(dst.to));
855
+			LOG(L_ERR, "forward_reply: reply to %s:%d(%d) dropped"
856
+					" (onsend_route)\n", ip_addr2a(&ip),
857
+						su_getport(&(dst.to)), dst.proto);
858
+			goto error; /* error ? */
859
+		}
860
+	}
861
+
862
+	if (msg_send(&dst, new_buf, new_len)<0)
863
+	{
864
+		STATS_RPL_FWD_DROP();
865
+		goto error;
866
+	}
853 867
 
854 868
 	done:
855 869
 #ifdef STATS
... ...
@@ -198,6 +198,9 @@ extern int open_files_limit;
198 198
 extern int shm_force_alloc;
199 199
 extern int mlock_pages;
200 200
 
201
+/* execute onsend_route for replies */
202
+extern int onsend_route_reply;
203
+
201 204
 /* real time stuff */
202 205
 extern int real_time;
203 206
 extern int rt_prio;
... ...
@@ -427,6 +427,9 @@ int server_id = 0; /* Configurable unique ID of the server */
427 427
 /* set timeval for each received sip message */
428 428
 int sr_msg_time = 1;
429 429
 
430
+/* onsend_route is executed for replies*/
431
+int onsend_route_reply = 0;
432
+
430 433
 /* more config stuff */
431 434
 int disable_core_dump=0; /* by default enabled */
432 435
 int open_files_limit=-1; /* don't touch it by default */
... ...
@@ -104,5 +104,6 @@ static inline int run_onsend(struct sip_msg* orig_msg, struct dest_info* dst,
104 104
 	return ret;
105 105
 }
106 106
 
107
+#define onsend_route_enabled(rtype) (onsend_rt.rlist[DEFAULT_RT]?((rtype==SIP_REPLY)?onsend_route_reply:1):0)
107 108
 
108 109
 #endif