[sr-dev] git:master: core: execute onsend_route for replies before sending out
Daniel-Constantin Mierla
miconda at gmail.com
Sun Oct 12 10:30:01 CEST 2014
Module: sip-router
Branch: master
Commit: 214b161e644c2d7468d9ac3ea13ad0be5196d143
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=214b161e644c2d7468d9ac3ea13ad0be5196d143
Author: Lucian Balaceanu <lucian.balaceanu at 1and1.ro>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: Sun Oct 12 10:28:29 2014 +0200
core: execute onsend_route for replies before sending out
- control execution of onsend_route block for replies via parameter
onsend_route_reply
---
cfg.lex | 3 ++-
cfg.y | 3 +++
forward.c | 22 ++++++++++++++++------
globals.h | 3 +++
main.c | 3 +++
onsend.h | 1 +
6 files changed, 28 insertions(+), 7 deletions(-)
diff --git a/cfg.lex b/cfg.lex
index 10766b2..1d5e40a 100644
--- a/cfg.lex
+++ b/cfg.lex
@@ -495,7 +495,7 @@ LATENCY_LIMIT_DB latency_limit_db
LATENCY_LIMIT_ACTION latency_limit_action
MSG_TIME msg_time
-
+ONSEND_RT_REPLY "onsend_route_reply"
CFG_DESCRIPTION "description"|"descr"|"desc"
LOADMODULE loadmodule
@@ -938,6 +938,7 @@ IMPORTFILE "import_file"
<INITIAL>{MAX_RECURSIVE_LEVEL} { count(); yylval.strval=yytext; return MAX_RECURSIVE_LEVEL;}
<INITIAL>{LATENCY_LOG} { count(); yylval.strval=yytext; return LATENCY_LOG;}
<INITIAL>{MSG_TIME} { count(); yylval.strval=yytext; return MSG_TIME;}
+<INITIAL>{ONSEND_RT_REPLY} { count(); yylval.strval=yytext; return ONSEND_RT_REPLY; }
<INITIAL>{LATENCY_LIMIT_DB} { count(); yylval.strval=yytext; return LATENCY_LIMIT_DB;}
<INITIAL>{LATENCY_LIMIT_ACTION} { count(); yylval.strval=yytext; return LATENCY_LIMIT_ACTION;}
<INITIAL>{CFG_DESCRIPTION} { count(); yylval.strval=yytext; return CFG_DESCRIPTION; }
diff --git a/cfg.y b/cfg.y
index 2e7a6b4..6a85292 100644
--- a/cfg.y
+++ b/cfg.y
@@ -547,6 +547,7 @@ extern char *default_routename;
%token LATENCY_LIMIT_DB
%token LATENCY_LIMIT_ACTION
%token MSG_TIME
+%token ONSEND_RT_REPLY
%token FLAGS_DECL
%token AVPFLAGS_DECL
@@ -1579,6 +1580,8 @@ assign_stm:
| LATENCY_LIMIT_ACTION EQUAL error { yyerror("number expected"); }
| MSG_TIME EQUAL NUMBER { sr_msg_time=$3; }
| MSG_TIME EQUAL error { yyerror("number expected"); }
+ | ONSEND_RT_REPLY EQUAL NUMBER { onsend_route_reply=$3; }
+ | ONSEND_RT_REPLY EQUAL error { yyerror("int value expected"); }
| UDP_MTU EQUAL NUMBER { default_core_cfg.udp_mtu=$3; }
| UDP_MTU EQUAL error { yyerror("number expected"); }
| FORCE_RPORT EQUAL NUMBER
diff --git a/forward.c b/forward.c
index 3d50988..81e39fe 100644
--- a/forward.c
+++ b/forward.c
@@ -758,6 +758,7 @@ static int do_forward_reply(struct sip_msg* msg, int mode)
struct dest_info dst;
unsigned int new_len;
int r;
+ struct ip_addr ip;
#ifdef USE_TCP
char* s;
int len;
@@ -836,11 +837,6 @@ static int do_forward_reply(struct sip_msg* msg, int mode)
apply_force_send_socket(&dst, msg);
- if (msg_send(&dst, new_buf, new_len)<0)
- {
- STATS_RPL_FWD_DROP();
- goto error;
- }
/* call onsend_route */
if(dst.send_sock == NULL) {
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)
goto done;
}
}
- run_onsend(msg, &dst, new_buf, new_len);
+ if (onsend_route_enabled(SIP_REPLY)){
+ if (run_onsend(msg, &dst, new_buf, new_len)==0){
+ su2ip_addr(&ip, &(dst.to));
+ LOG(L_ERR, "forward_reply: reply to %s:%d(%d) dropped"
+ " (onsend_route)\n", ip_addr2a(&ip),
+ su_getport(&(dst.to)), dst.proto);
+ goto error; /* error ? */
+ }
+ }
+
+ if (msg_send(&dst, new_buf, new_len)<0)
+ {
+ STATS_RPL_FWD_DROP();
+ goto error;
+ }
done:
#ifdef STATS
diff --git a/globals.h b/globals.h
index 76e7f35..0a62d3e 100644
--- a/globals.h
+++ b/globals.h
@@ -198,6 +198,9 @@ extern int open_files_limit;
extern int shm_force_alloc;
extern int mlock_pages;
+/* execute onsend_route for replies */
+extern int onsend_route_reply;
+
/* real time stuff */
extern int real_time;
extern int rt_prio;
diff --git a/main.c b/main.c
index dabac0b..5aebc79 100644
--- a/main.c
+++ b/main.c
@@ -427,6 +427,9 @@ int server_id = 0; /* Configurable unique ID of the server */
/* set timeval for each received sip message */
int sr_msg_time = 1;
+/* onsend_route is executed for replies*/
+int onsend_route_reply = 0;
+
/* more config stuff */
int disable_core_dump=0; /* by default enabled */
int open_files_limit=-1; /* don't touch it by default */
diff --git a/onsend.h b/onsend.h
index 0b2eb08..a8a4e6e 100644
--- a/onsend.h
+++ b/onsend.h
@@ -104,5 +104,6 @@ static inline int run_onsend(struct sip_msg* orig_msg, struct dest_info* dst,
return ret;
}
+#define onsend_route_enabled(rtype) (onsend_rt.rlist[DEFAULT_RT]?((rtype==SIP_REPLY)?onsend_route_reply:1):0)
#endif
More information about the sr-dev
mailing list