Skip to content

Commit

Permalink
tm: run TMCB_REQUEST_BUILT before sending msg
Browse files Browse the repository at this point in the history
Althought this was initially documented as being ran before sending the
message out, this callback has been moved *after* the message is sent.
Therefore it can generate some concurrency issues in the dialog, when a
reply is received faster than the outgoing leg would have been updated.

(cherry picked from commit ef680f6)
  • Loading branch information
razvancrainea committed May 21, 2019
1 parent 9453866 commit 07672d4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
10 changes: 8 additions & 2 deletions modules/tm/t_cancel.c
Expand Up @@ -109,13 +109,19 @@ void cancel_branch( struct cell *t, int branch )
* to deal with it */
crb->activ_type=TYPE_LOCAL_CANCEL;

if ( has_tran_tmcbs( t, TMCB_REQUEST_BUILT) ) {
set_extra_tmcb_params( &crb->buffer, &crb->dst);
run_trans_callbacks( TMCB_REQUEST_BUILT,
t, t->uas.request, 0, 0);
}

LM_DBG("sending cancel...\n");
if (t->uac[branch].br_flags & tcp_no_new_conn_bflag)
tcp_no_new_conn = 1;
if (SEND_BUFFER( crb )==0) {
if ( has_tran_tmcbs( t, TMCB_REQUEST_BUILT|TMCB_MSG_SENT_OUT) ) {
if ( has_tran_tmcbs( t, TMCB_MSG_SENT_OUT) ) {
set_extra_tmcb_params( &crb->buffer, &crb->dst);
run_trans_callbacks( TMCB_REQUEST_BUILT|TMCB_MSG_SENT_OUT,
run_trans_callbacks( TMCB_MSG_SENT_OUT,
t, t->uas.request, 0, 0);
}
}
Expand Down
12 changes: 10 additions & 2 deletions modules/tm/t_fwd.c
Expand Up @@ -794,6 +794,14 @@ int t_forward_nonack( struct cell *t, struct sip_msg* p_msg ,
if (t->uac[i].br_flags & tcp_no_new_conn_bflag)
tcp_no_new_conn = 1;

/* successfully sent out -> run callbacks */
if ( has_tran_tmcbs( t, TMCB_REQUEST_BUILT) ) {
set_extra_tmcb_params( &t->uac[i].request.buffer,
&t->uac[i].request.dst);
run_trans_callbacks( TMCB_REQUEST_BUILT, t,
p_msg, 0, 0);
}

do {
if (check_blacklists( t->uac[i].request.dst.proto,
&t->uac[i].request.dst.to,
Expand Down Expand Up @@ -840,10 +848,10 @@ int t_forward_nonack( struct cell *t, struct sip_msg* p_msg ,
set_kr(REQ_FWDED);

/* successfully sent out -> run callbacks */
if ( has_tran_tmcbs( t, TMCB_REQUEST_BUILT|TMCB_MSG_SENT_OUT) ) {
if ( has_tran_tmcbs( t, TMCB_MSG_SENT_OUT) ) {
set_extra_tmcb_params( &t->uac[i].request.buffer,
&t->uac[i].request.dst);
run_trans_callbacks( TMCB_REQUEST_BUILT|TMCB_MSG_SENT_OUT, t,
run_trans_callbacks( TMCB_MSG_SENT_OUT, t,
p_msg, 0, 0);
}

Expand Down
3 changes: 3 additions & 0 deletions modules/tm/t_hooks.h
Expand Up @@ -166,6 +166,9 @@ struct cell;
* It may be a request (out request, out CANCEL, out ACK) or a
* reply (relaied reply, locally generated reply).
*
* TMCB_REQUEST_BUILT -- triggered just before a message has been built and
* is about to be sent out.
*
* IMPORTANT NOTES:
*
* 1) that callbacks MUST be installed before forking
Expand Down

0 comments on commit 07672d4

Please sign in to comment.