[sr-dev] git:alexh/for4.0: modules/tm: Remember per-branch onreply_route and onfailure_route settings
Alex Hermann
alex at speakup.nl
Tue Jan 8 13:00:02 CET 2013
Module: sip-router
Branch: alexh/for4.0
Commit: b695cc4b6f0a3711edf05e4195fae60f4eeeb151
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=b695cc4b6f0a3711edf05e4195fae60f4eeeb151
Author: Alex Hermann <alex at speakup.nl>
Committer: Alex Hermann <alex at speakup.nl>
Date: Thu Oct 11 18:28:34 2012 +0200
modules/tm: Remember per-branch onreply_route and onfailure_route settings
The onreply and onfailure routes were set only per transaction. This means
that when the onreply and/or failure route is changed in failure route (serial
forking), late replies to earlier branches would use the new onreply and
failure route instead of the routes set for them.
This commit copies the transaction's onreply and failure routes to the branch,
so the route set when the request is sent out is always chosen, no matter
how late the reply arrives.
Because the per-branch setting is copied after running onbranch_route, it is
now also possible to set the routes per-branch instead of per-transaction.
---
modules/tm/h_table.h | 4 ++++
modules/tm/t_fwd.c | 6 +++++-
modules/tm/t_reply.c | 18 +++++++++---------
3 files changed, 18 insertions(+), 10 deletions(-)
diff --git a/modules/tm/h_table.h b/modules/tm/h_table.h
index 8294001..f30bd45 100644
--- a/modules/tm/h_table.h
+++ b/modules/tm/h_table.h
@@ -247,6 +247,10 @@ typedef struct ua_client
*/
struct retr_buf *local_ack;
#endif
+ /* the route to take if no final positive reply arrived */
+ unsigned short on_failure;
+ /* the onreply_route to be processed if registered to do so */
+ unsigned short on_reply;
}ua_client_type;
diff --git a/modules/tm/t_fwd.c b/modules/tm/t_fwd.c
index 76fb451..9659f6f 100644
--- a/modules/tm/t_fwd.c
+++ b/modules/tm/t_fwd.c
@@ -416,7 +416,11 @@ static int prepare_new_uac( struct cell *t, struct sip_msg *i_req,
} /* else next_hop==0 =>
no dst_uri / empty dst_uri and initial next_hop==0 =>
dst is pre-filled with a valid dst => use the pre-filled dst */
-
+
+ /* Set on_reply and on_negative handlers for this branch to the handlers in the transaction */
+ t->uac[branch].on_reply = t->on_reply;
+ t->uac[branch].on_failure = t->on_failure;
+
/* check if send_sock is ok */
if (t->uac[branch].request.dst.send_sock==0) {
LOG(L_ERR, "ERROR: can't fwd to af %d, proto %d "
diff --git a/modules/tm/t_reply.c b/modules/tm/t_reply.c
index 6fc7ee6..b79200b 100644
--- a/modules/tm/t_reply.c
+++ b/modules/tm/t_reply.c
@@ -986,19 +986,20 @@ int run_failure_handlers(struct cell *t, struct sip_msg *rpl,
struct sip_msg *shmem_msg = t->uas.request;
int on_failure;
+ on_failure = t->uac[picked_branch].on_failure;
+
/* failure_route for a local UAC? */
if (!shmem_msg) {
LOG(L_WARN,"Warning: run_failure_handlers: no UAC support (%d, %d) \n",
- t->on_failure, t->tmcb_hl.reg_types);
+ on_failure, t->tmcb_hl.reg_types);
return 0;
}
/* don't start faking anything if we don't have to */
- if (unlikely(!t->on_failure && !has_tran_tmcbs( t, TMCB_ON_FAILURE))) {
+ if (unlikely(!on_failure && !has_tran_tmcbs( t, TMCB_ON_FAILURE))) {
LOG(L_WARN,
- "Warning: run_failure_handlers: no negative handler (%d, %d)\n",
- t->on_failure,
- t->tmcb_hl.reg_types);
+ "Warning: run_failure_handlers: no failure handler (%d, %d)\n",
+ on_failure, t->tmcb_hl.reg_types);
return 1;
}
@@ -1013,11 +1014,10 @@ int run_failure_handlers(struct cell *t, struct sip_msg *rpl,
if (unlikely(has_tran_tmcbs( t, TMCB_ON_FAILURE)) ) {
run_trans_callbacks( TMCB_ON_FAILURE, t, &faked_req, rpl, code);
}
- if (t->on_failure) {
+ if (on_failure) {
/* avoid recursion -- if failure_route forwards, and does not
* set next failure route, failure_route will not be reentered
* on failure */
- on_failure = t->on_failure;
t->on_failure=0;
if (exec_pre_script_cb(&faked_req, FAILURE_CB_TYPE)>0) {
/* run a failure_route action if some was marked */
@@ -1290,7 +1290,7 @@ static enum rps t_should_relay_response( struct cell *Trans , int new_code,
replies_dropped = 0;
/* run ON_FAILURE handlers ( route and callbacks) */
if (unlikely(has_tran_tmcbs( Trans, TMCB_ON_FAILURE_RO|TMCB_ON_FAILURE)
- || Trans->on_failure )) {
+ || Trans->uac[picked_branch].on_failure )) {
extra_flags=
((Trans->uac[picked_branch].request.flags & F_RB_TIMEOUT)?
FL_TIMEOUT:0) |
@@ -2099,7 +2099,7 @@ int reply_received( struct sip_msg *p_msg )
goto done;
}
- onreply_route=t->on_reply;
+ onreply_route=uac->on_reply;
if ( msg_status >= 200 ){
#ifdef TM_ONREPLY_FINAL_DROP_OK
#warning Experimental tm onreply_route final reply DROP support active
More information about the sr-dev
mailing list