Skip to content

Commit c8458a3

Browse files
committed
tm: proper matching of transaction for auto-CANCEL handling
1 parent 2d6dbf7 commit c8458a3

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

modules/tm/cluster.c

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ int tm_reply_replicate(struct sip_msg *msg)
508508
return 1;
509509
}
510510

511-
static int tm_existing_trans(struct sip_msg *msg)
511+
static int tm_existing_ack_trans(struct sip_msg *msg)
512512
{
513513
struct cell *t = get_t();
514514
if (t == T_UNDEFINED) {
@@ -525,6 +525,28 @@ static int tm_existing_trans(struct sip_msg *msg)
525525
return 0;
526526
}
527527

528+
static int tm_existing_invite_trans(struct sip_msg *msg)
529+
{
530+
struct cell *t = get_cancelled_t();
531+
if (t == T_UNDEFINED) {
532+
/* parse needed hdrs*/
533+
if (check_transaction_quadruple(msg)==0) {
534+
LM_ERR("too few headers\n");
535+
return 0; /*drop request!*/
536+
}
537+
if (!msg->hash_index)
538+
msg->hash_index = tm_hash(msg->callid->body,get_cseq(msg)->number);
539+
/* performe lookup */
540+
t = t_lookupOriginalT(msg);
541+
}
542+
if (t) {
543+
LM_DBG("transaction already present here, no need to replicate\n");
544+
return 1;
545+
}
546+
return 0;
547+
}
548+
549+
528550
/**
529551
* Replicates a message within a cluster
530552
* Returns:
@@ -550,7 +572,9 @@ int tm_anycast_replicate(struct sip_msg *msg)
550572
LM_DBG("message already replicated, shouldn't have got here\n");
551573
return -2;
552574
}
553-
if (tm_existing_trans(msg))
575+
if (msg->REQ_METHOD == METHOD_CANCEL && tm_existing_invite_trans(msg))
576+
return -1;
577+
if (msg->REQ_METHOD == METHOD_ACK && tm_existing_ack_trans(msg))
554578
return -1;
555579

556580
/* we are currently doing auto-CANCEL only for 3261 transactions */
@@ -571,7 +595,7 @@ int tm_anycast_cancel(struct sip_msg *msg)
571595
if (!tm_repl_auto_cancel || !tm_repl_cluster)
572596
return -1;
573597

574-
if (!tm_existing_trans(msg))
598+
if (!tm_existing_invite_trans(msg))
575599
return tm_replicate_cancel(msg)? 0: -2;
576600
else if (t_relay_to(msg, NULL, 0) < 0) {
577601
LM_ERR("cannot handle auto-CANCEL here - send to script!\n");

0 commit comments

Comments
 (0)