Module: sip-router Branch: andrei/send_flags Commit: 58cbf7f7e13fa383a76d9f67d38a686ae5e8babe URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=58cbf7f7...
Author: Andrei Pelinescu-Onciul andrei@iptel.org Committer: Andrei Pelinescu-Onciul andrei@iptel.org Date: Tue Sep 15 17:47:33 2009 +0200
core: new close after send and reuse only script functions
Added new script functions for setting send options for the current message or its replies:
- set_forward_no_connect() - the message will be forwarded only if there is already an open connection to the destination. - set_reply_no_connect() - like above but for replies to the current message. - set_forward_close() - hint that after forwarding the current message the connection should be closed. - set reply_close() - like above but for replies.
---
action.c | 17 +++++++++++++++++ cfg.lex | 12 ++++++++++++ cfg.y | 28 ++++++++++++++++++++++++++++ route_struct.h | 6 +++++- 4 files changed, 62 insertions(+), 1 deletions(-)
diff --git a/action.c b/action.c index 352dd90..13a9817 100644 --- a/action.c +++ b/action.c @@ -50,6 +50,7 @@ * 2008-12-03 use lvalues/rvalues for assignments (andrei) * 2008-12-17 added UDP_MTU_TRY_PROTO_T (andrei) * 2009-05-04 switched IF_T to rval_expr (andrei) + * 2009-09-15 added SET_{FWD,RPL}_NO_CONNECT, SET_{FWD,RPL}_CLOSE (andrei) */
@@ -1214,6 +1215,22 @@ match_cleanup: else ret=v; break; + case SET_FWD_NO_CONNECT_T: + msg->fwd_send_flags|= SND_F_FORCE_CON_REUSE; + ret=1; /* continue processing */ + break; + case SET_RPL_NO_CONNECT_T: + msg->rpl_send_flags|= SND_F_FORCE_CON_REUSE; + ret=1; /* continue processing */ + break; + case SET_FWD_CLOSE_T: + msg->fwd_send_flags|= SND_F_CON_CLOSE; + ret=1; /* continue processing */ + break; + case SET_RPL_CLOSE_T: + msg->rpl_send_flags|= SND_F_CON_CLOSE; + ret=1; /* continue processing */ + break; /* default: LOG(L_CRIT, "BUG: do_action: unknown type %d\n", a->type); diff --git a/cfg.lex b/cfg.lex index 9723877..bedf79c 100644 --- a/cfg.lex +++ b/cfg.lex @@ -215,6 +215,10 @@ ELSE "else" SET_ADV_ADDRESS "set_advertised_address" SET_ADV_PORT "set_advertised_port" FORCE_SEND_SOCKET "force_send_socket" +SET_FWD_NO_CONNECT "set_forward_no_connect" +SET_RPL_NO_CONNECT "set_reply_no_connect" +SET_FWD_CLOSE "set_forward_close" +SET_RPL_CLOSE "set_reply_close" SWITCH "switch" CASE "case" DEFAULT "default" @@ -572,6 +576,14 @@ EAT_ABLE [\ \t\b\r] return SET_ADV_PORT; } <INITIAL>{FORCE_SEND_SOCKET} { count(); yylval.strval=yytext; return FORCE_SEND_SOCKET; } +<INITIAL>{SET_FWD_NO_CONNECT} { count(); yylval.strval=yytext; + return SET_FWD_NO_CONNECT; } +<INITIAL>{SET_RPL_NO_CONNECT} { count(); yylval.strval=yytext; + return SET_RPL_NO_CONNECT; } +<INITIAL>{SET_FWD_CLOSE} { count(); yylval.strval=yytext; + return SET_FWD_CLOSE; } +<INITIAL>{SET_RPL_CLOSE} { count(); yylval.strval=yytext; + return SET_RPL_CLOSE; } <INITIAL>{SWITCH} { count(); yylval.strval=yytext; return SWITCH; } <INITIAL>{CASE} { count(); yylval.strval=yytext; return CASE; } <INITIAL>{DEFAULT} { count(); yylval.strval=yytext; return DEFAULT; } diff --git a/cfg.y b/cfg.y index 3344b03..af5335c 100644 --- a/cfg.y +++ b/cfg.y @@ -319,6 +319,10 @@ extern char *finame; %token SET_ADV_ADDRESS %token SET_ADV_PORT %token FORCE_SEND_SOCKET +%token SET_FWD_NO_CONNECT +%token SET_RPL_NO_CONNECT +%token SET_FWD_CLOSE +%token SET_RPL_CLOSE %token SWITCH %token CASE %token DEFAULT @@ -2990,6 +2994,30 @@ cmd: $$=0; yyerror("bad argument, [proto:]host[:port] expected"); } | FORCE_SEND_SOCKET error {$$=0; yyerror("missing '(' or ')' ?"); } + | SET_FWD_NO_CONNECT LPAREN RPAREN { + $$=mk_action(SET_FWD_NO_CONNECT_T, 0); set_cfg_pos($$); + } + | SET_FWD_NO_CONNECT { + $$=mk_action(SET_FWD_NO_CONNECT_T, 0); set_cfg_pos($$); + } + | SET_RPL_NO_CONNECT LPAREN RPAREN { + $$=mk_action(SET_RPL_NO_CONNECT_T, 0); set_cfg_pos($$); + } + | SET_RPL_NO_CONNECT { + $$=mk_action(SET_RPL_NO_CONNECT_T, 0); set_cfg_pos($$); + } + | SET_FWD_CLOSE LPAREN RPAREN { + $$=mk_action(SET_FWD_CLOSE_T, 0); set_cfg_pos($$); + } + | SET_FWD_CLOSE { + $$=mk_action(SET_FWD_CLOSE_T, 0); set_cfg_pos($$); + } + | SET_RPL_CLOSE LPAREN RPAREN { + $$=mk_action(SET_RPL_CLOSE_T, 0); set_cfg_pos($$); + } + | SET_RPL_CLOSE { + $$=mk_action(SET_RPL_CLOSE_T, 0); set_cfg_pos($$); + } | ID {mod_func_action = mk_action(MODULE_T, 2, MODEXP_ST, NULL, NUMBER_ST, 0); } LPAREN func_params RPAREN { mod_func_action->val[0].u.data = diff --git a/route_struct.h b/route_struct.h index 4dc84e9..4894bd5 100644 --- a/route_struct.h +++ b/route_struct.h @@ -106,7 +106,11 @@ enum action_type{ FORCE_SEND_SOCKET_T, ASSIGN_T, ADD_T, - UDP_MTU_TRY_PROTO_T + UDP_MTU_TRY_PROTO_T, + SET_FWD_NO_CONNECT_T, + SET_RPL_NO_CONNECT_T, + SET_FWD_CLOSE_T, + SET_RPL_CLOSE_T }; /* parameter types for actions or types for expression right operands (WARNING right operands only, not working for left operands) */
Andrei Pelinescu-Onciul writes:
Added new script functions for setting send options for the current message or its replies:
- set_forward_no_connect() - the message will be forwarded only if there is already an open connection to the destination.
- set_reply_no_connect() - like above but for replies to the current message.
- set_forward_close() - hint that after forwarding the current message the connection should be closed.
- set reply_close() - like above but for replies.
andrei,
is it easy to specify in config file before i call t_relay that don't try to open a tcp connection if one does not already exist. it is namely pretty useless to try that for registered tcp contacts.
-- juha
Great!
I have documented the new function. http://sip-router.org/wiki/cookbooks/core-cookbook/devel#set_forward_no_conn...
Andrei, please verify if I understood correct and the examples are correct.
I suspect those functions work with TLS too? What about SCTP?
What happens if the functions are called for UDP transport - I hope they will be ignored and do not make noisy log-statements.
regards klaus
Andrei Pelinescu-Onciul schrieb:
Module: sip-router Branch: andrei/send_flags Commit: 58cbf7f7e13fa383a76d9f67d38a686ae5e8babe URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=58cbf7f7...
Author: Andrei Pelinescu-Onciul andrei@iptel.org Committer: Andrei Pelinescu-Onciul andrei@iptel.org Date: Tue Sep 15 17:47:33 2009 +0200
core: new close after send and reuse only script functions
Added new script functions for setting send options for the current message or its replies:
- set_forward_no_connect() - the message will be forwarded only if there is already an open connection to the destination.
- set_reply_no_connect() - like above but for replies to the current message.
- set_forward_close() - hint that after forwarding the current message the connection should be closed.
- set reply_close() - like above but for replies.
action.c | 17 +++++++++++++++++ cfg.lex | 12 ++++++++++++ cfg.y | 28 ++++++++++++++++++++++++++++ route_struct.h | 6 +++++- 4 files changed, 62 insertions(+), 1 deletions(-)
diff --git a/action.c b/action.c index 352dd90..13a9817 100644 --- a/action.c +++ b/action.c @@ -50,6 +50,7 @@
- 2008-12-03 use lvalues/rvalues for assignments (andrei)
- 2008-12-17 added UDP_MTU_TRY_PROTO_T (andrei)
- 2009-05-04 switched IF_T to rval_expr (andrei)
*/
- 2009-09-15 added SET_{FWD,RPL}_NO_CONNECT, SET_{FWD,RPL}_CLOSE (andrei)
@@ -1214,6 +1215,22 @@ match_cleanup: else ret=v; break;
case SET_FWD_NO_CONNECT_T:
msg->fwd_send_flags|= SND_F_FORCE_CON_REUSE;
ret=1; /* continue processing */
break;
case SET_RPL_NO_CONNECT_T:
msg->rpl_send_flags|= SND_F_FORCE_CON_REUSE;
ret=1; /* continue processing */
break;
case SET_FWD_CLOSE_T:
msg->fwd_send_flags|= SND_F_CON_CLOSE;
ret=1; /* continue processing */
break;
case SET_RPL_CLOSE_T:
msg->rpl_send_flags|= SND_F_CON_CLOSE;
ret=1; /* continue processing */
break;
/* default: LOG(L_CRIT, "BUG: do_action: unknown type %d\n", a->type); diff --git a/cfg.lex b/cfg.lex index 9723877..bedf79c 100644 --- a/cfg.lex +++ b/cfg.lex @@ -215,6 +215,10 @@ ELSE "else" SET_ADV_ADDRESS "set_advertised_address" SET_ADV_PORT "set_advertised_port" FORCE_SEND_SOCKET "force_send_socket" +SET_FWD_NO_CONNECT "set_forward_no_connect" +SET_RPL_NO_CONNECT "set_reply_no_connect" +SET_FWD_CLOSE "set_forward_close" +SET_RPL_CLOSE "set_reply_close" SWITCH "switch" CASE "case" DEFAULT "default" @@ -572,6 +576,14 @@ EAT_ABLE [\ \t\b\r] return SET_ADV_PORT; } <INITIAL>{FORCE_SEND_SOCKET} { count(); yylval.strval=yytext; return FORCE_SEND_SOCKET; } +<INITIAL>{SET_FWD_NO_CONNECT} { count(); yylval.strval=yytext;
return SET_FWD_NO_CONNECT; }
+<INITIAL>{SET_RPL_NO_CONNECT} { count(); yylval.strval=yytext;
return SET_RPL_NO_CONNECT; }
+<INITIAL>{SET_FWD_CLOSE} { count(); yylval.strval=yytext;
return SET_FWD_CLOSE; }
+<INITIAL>{SET_RPL_CLOSE} { count(); yylval.strval=yytext;
return SET_RPL_CLOSE; }
<INITIAL>{SWITCH} { count(); yylval.strval=yytext; return SWITCH; } <INITIAL>{CASE} { count(); yylval.strval=yytext; return CASE; } <INITIAL>{DEFAULT} { count(); yylval.strval=yytext; return DEFAULT; } diff --git a/cfg.y b/cfg.y index 3344b03..af5335c 100644 --- a/cfg.y +++ b/cfg.y @@ -319,6 +319,10 @@ extern char *finame; %token SET_ADV_ADDRESS %token SET_ADV_PORT %token FORCE_SEND_SOCKET +%token SET_FWD_NO_CONNECT +%token SET_RPL_NO_CONNECT +%token SET_FWD_CLOSE +%token SET_RPL_CLOSE %token SWITCH %token CASE %token DEFAULT @@ -2990,6 +2994,30 @@ cmd: $$=0; yyerror("bad argument, [proto:]host[:port] expected"); } | FORCE_SEND_SOCKET error {$$=0; yyerror("missing '(' or ')' ?"); }
- | SET_FWD_NO_CONNECT LPAREN RPAREN {
$$=mk_action(SET_FWD_NO_CONNECT_T, 0); set_cfg_pos($$);
- }
- | SET_FWD_NO_CONNECT {
$$=mk_action(SET_FWD_NO_CONNECT_T, 0); set_cfg_pos($$);
- }
- | SET_RPL_NO_CONNECT LPAREN RPAREN {
$$=mk_action(SET_RPL_NO_CONNECT_T, 0); set_cfg_pos($$);
- }
- | SET_RPL_NO_CONNECT {
$$=mk_action(SET_RPL_NO_CONNECT_T, 0); set_cfg_pos($$);
- }
- | SET_FWD_CLOSE LPAREN RPAREN {
$$=mk_action(SET_FWD_CLOSE_T, 0); set_cfg_pos($$);
- }
- | SET_FWD_CLOSE {
$$=mk_action(SET_FWD_CLOSE_T, 0); set_cfg_pos($$);
- }
- | SET_RPL_CLOSE LPAREN RPAREN {
$$=mk_action(SET_RPL_CLOSE_T, 0); set_cfg_pos($$);
- }
- | SET_RPL_CLOSE {
$$=mk_action(SET_RPL_CLOSE_T, 0); set_cfg_pos($$);
- } | ID {mod_func_action = mk_action(MODULE_T, 2, MODEXP_ST, NULL, NUMBER_ST, 0); } LPAREN func_params RPAREN { mod_func_action->val[0].u.data =
diff --git a/route_struct.h b/route_struct.h index 4dc84e9..4894bd5 100644 --- a/route_struct.h +++ b/route_struct.h @@ -106,7 +106,11 @@ enum action_type{ FORCE_SEND_SOCKET_T, ASSIGN_T, ADD_T,
UDP_MTU_TRY_PROTO_T
UDP_MTU_TRY_PROTO_T,
SET_FWD_NO_CONNECT_T,
SET_RPL_NO_CONNECT_T,
SET_FWD_CLOSE_T,
SET_RPL_CLOSE_T
}; /* parameter types for actions or types for expression right operands (WARNING right operands only, not working for left operands) */
sr-dev mailing list sr-dev@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev
On Sep 21, 2009 at 12:16, Klaus Darilion klaus.mailinglists@pernau.at wrote:
Great!
I have documented the new function. http://sip-router.org/wiki/cookbooks/core-cookbook/devel#set_forward_no_conn...
Thanks!
Andrei, please verify if I understood correct and the examples are correct.
Yes, they are correct. There are some differences if you use them in other type of routes. For example in onsend_routes and branch routes, only the set_forward* work and they will apply only to the current message / current branch.
E.g.: onsend_route{ if(to_ip!=10.0.0.0/8){ #only reuse connection for IPs outside the local net set_foward_no_connect(); } }
In a reply route they will apply only to the current reply (so you will see their effect only if the current reply "wins" and it's forwarded).
As you said set_*_close() must be used with care (and in general they should be avoided). Especially dangerous is the combination of set_*_close() and set_*_no_connect() (it works only once, after that no further messages can be forwarded to the same destination). The primary purpose of set_*_close() is for xmlrpc use (work around against the python xmlrpc client bug).
I suspect those functions work with TLS too? What about SCTP?
Yes, they work with TLS. They don't work yet with SCTP (but I'll add support for them to SCTP later).
What happens if the functions are called for UDP transport - I hope they will be ignored and do not make noisy log-statements.
Nothing, they are ignored.
Andrei
Hi Andrei!
I'm still not sure for the correct usage.
If I got it right, set_forward_* is for relaying of messages (regardless if it is a request or reponse) and set_reply_* is for local generated replies (explicit in script or implicit somewhere in a module)
Is this correct?
regards klaus
Andrei Pelinescu-Onciul schrieb:
On Sep 21, 2009 at 12:16, Klaus Darilion klaus.mailinglists@pernau.at wrote:
Great!
I have documented the new function. http://sip-router.org/wiki/cookbooks/core-cookbook/devel#set_forward_no_conn...
Thanks!
Andrei, please verify if I understood correct and the examples are correct.
Yes, they are correct. There are some differences if you use them in other type of routes. For example in onsend_routes and branch routes, only the set_forward* work and they will apply only to the current message / current branch.
E.g.: onsend_route{ if(to_ip!=10.0.0.0/8){ #only reuse connection for IPs outside the local net set_foward_no_connect(); } }
In a reply route they will apply only to the current reply (so you will see their effect only if the current reply "wins" and it's forwarded).
As you said set_*_close() must be used with care (and in general they should be avoided). Especially dangerous is the combination of set_*_close() and set_*_no_connect() (it works only once, after that no further messages can be forwarded to the same destination). The primary purpose of set_*_close() is for xmlrpc use (work around against the python xmlrpc client bug).
I suspect those functions work with TLS too? What about SCTP?
Yes, they work with TLS. They don't work yet with SCTP (but I'll add support for them to SCTP later).
What happens if the functions are called for UDP transport - I hope they will be ignored and do not make noisy log-statements.
Nothing, they are ignored.
Andrei
On Sep 21, 2009 at 14:41, Klaus Darilion klaus.mailinglists@pernau.at wrote:
Hi Andrei!
I'm still not sure for the correct usage.
If I got it right, set_forward_* is for relaying of messages (regardless if it is a request or reponse) and set_reply_* is for local generated replies (explicit in script or implicit somewhere in a module)
set_reply_* is for local generated replies and replies forwarded by tm , but depends in which route you use it:
- normal route, e.g. set_reply_no_connect(); t_relay(); => affects all replies sent back on the transaction (either local or "forwarded") and all local stateless replies (sl_reply()).
- onreply_route: affects the current reply (so the send_flags set in the onreply_route will be used if the reply for which they were set is the winning final reply or it's a provisional reply that is forwarded)
- branch_route: ignored.
- onsend_route: ignored
set_forward_*:
- normal route: affects stateless forwards and tm (for tm it affects all the branches and the possible retransmissions).
- onreply_route[0] (stateless) and stateless reply forwarding: equivalent to set_reply_*() (it's better to use set_rpl_* though)
- onreply_route[!=0] (tm): ignored
- branch_route: affects the current branch (all messages sent on this branch, like possible retransmissions and cancels).
- onsend_route: current message and current branch (like branch route).
Note that right now we have only 2 send flags, that both deal only with connections on tcp/tls (and in the future sctp) and thus they won't affect retransmission because tm doesn't retransmit on them (with the only exception of 2xx local replies). However in the future I will add the possibility to set blacklist flags (e.g. set_no_blst(...) or something like set_blacklist_ignore_503()) and this will do something even on udp.
Andrei
Ok. Thanks. I have extended the documentation: http://sip-router.org/wiki/cookbooks/core-cookbook/devel#set_forward_no_conn...
regards klaus
Andrei Pelinescu-Onciul schrieb:
On Sep 21, 2009 at 14:41, Klaus Darilion klaus.mailinglists@pernau.at wrote:
Hi Andrei!
I'm still not sure for the correct usage.
If I got it right, set_forward_* is for relaying of messages (regardless if it is a request or reponse) and set_reply_* is for local generated replies (explicit in script or implicit somewhere in a module)
set_reply_* is for local generated replies and replies forwarded by tm , but depends in which route you use it:
- normal route, e.g. set_reply_no_connect(); t_relay();
=> affects all replies sent back on the transaction (either local or "forwarded") and all local stateless replies (sl_reply()).
onreply_route: affects the current reply (so the send_flags set in the onreply_route will be used if the reply for which they were set is the winning final reply or it's a provisional reply that is forwarded)
branch_route: ignored.
onsend_route: ignored
set_forward_*:
normal route: affects stateless forwards and tm (for tm it affects all the branches and the possible retransmissions).
onreply_route[0] (stateless) and stateless reply forwarding: equivalent
to set_reply_*() (it's better to use set_rpl_* though)
onreply_route[!=0] (tm): ignored
branch_route: affects the current branch (all messages sent on this branch, like possible retransmissions and cancels).
onsend_route: current message and current branch (like branch route).
Note that right now we have only 2 send flags, that both deal only with connections on tcp/tls (and in the future sctp) and thus they won't affect retransmission because tm doesn't retransmit on them (with the only exception of 2xx local replies). However in the future I will add the possibility to set blacklist flags (e.g. set_no_blst(...) or something like set_blacklist_ignore_503()) and this will do something even on udp.
Andrei
Klaus Darilion writes:
I have documented the new function. http://sip-router.org/wiki/cookbooks/core-cookbook/devel#set_forward_no_conn...
klaus,
you have example:
reply-route[1] { ... set_reply_no_connect(); ... }
should it be onreply_route instead?
-- juha
Juha Heinanen schrieb:
Klaus Darilion writes:
I have documented the new function. http://sip-router.org/wiki/cookbooks/core-cookbook/devel#set_forward_no_conn...
klaus,
you have example:
reply-route[1] { ... set_reply_no_connect(); ... }
should it be onreply_route instead?
of course. Fixed.
thanks klaus