Module: kamailio Branch: 6.0 Commit: 835a3b60607db381b3941b308f00c0469fcaf021 URL: https://github.com/kamailio/kamailio/commit/835a3b60607db381b3941b308f00c046...
Author: Xenofon Karamanos xk@gilawa.com Committer: Xenofon Karamanos 22965395+xkaraman@users.noreply.github.com Date: 2025-06-18T08:39:21Z
tm: Generate local_request for CANCEL only if locally initiated
- Introduce new flag F_CANCEL_LOCAL
(cherry picked from commit 49ffcebdf6cbf8ce2e4e2e55d9197b906f74ff95)
---
Modified: src/modules/tm/t_cancel.c Modified: src/modules/tm/t_cancel.h
---
Diff: https://github.com/kamailio/kamailio/commit/835a3b60607db381b3941b308f00c046... Patch: https://github.com/kamailio/kamailio/commit/835a3b60607db381b3941b308f00c046...
---
diff --git a/src/modules/tm/t_cancel.c b/src/modules/tm/t_cancel.c index d4f1be0eaca..e3114c70d0e 100644 --- a/src/modules/tm/t_cancel.c +++ b/src/modules/tm/t_cancel.c @@ -338,44 +338,47 @@ int cancel_branch(struct cell *t, int branch, sip_msg_t *cancel_msg,
LM_DBG("sending cancel...\n");
- rt = -1; - if(tm_event_callback.s == NULL || tm_event_callback.len <= 0) { - rt = route_lookup(&event_rt, evname.s); - if(rt < 0 || event_rt.rlist[rt] == NULL) { - LM_DBG("tm:local-request not found\n"); - } - } else { - keng = sr_kemi_eng_get(); - if(keng == NULL) { - LM_DBG("event callback (%s) set, but no cfg engine\n", - tm_event_callback.s); + if(flags & F_CANCEL_LOCAL) { + /* Call event */ + rt = -1; + if(tm_event_callback.s == NULL || tm_event_callback.len <= 0) { + rt = route_lookup(&event_rt, evname.s); + if(rt < 0 || event_rt.rlist[rt] == NULL) { + LM_DBG("tm:local-request not found\n"); + } + } else { + keng = sr_kemi_eng_get(); + if(keng == NULL) { + LM_DBG("event callback (%s) set, but no cfg engine\n", + tm_event_callback.s); + } } - }
- // /* Check if msg is null */ - if(build_sip_msg_from_buf(&msg, crb->buffer, crb->buffer_len, 0) < 0) { - LM_ERR("fail to parse msg\n"); - } - - /* Call event */ - backup_rt = get_route_type(); - set_route_type(REQUEST_ROUTE); - init_run_actions_ctx(&ctx); - if(rt >= 0) { - LM_DBG("tm:local-request found [%d]\n", rt); - run_top_route(event_rt.rlist[rt], &msg, 0); - } else { - if(keng != NULL) { + /* Check if msg is null */ + if(build_sip_msg_from_buf(&msg, crb->buffer, crb->buffer_len, 0) < 0) { + LM_ERR("fail to parse msg\n"); + }
- if(sr_kemi_route( - keng, &msg, EVENT_ROUTE, &tm_event_callback, &evname) - < 0) { - LM_ERR("error running event route kemi callback\n"); + /* Call event */ + backup_rt = get_route_type(); + set_route_type(REQUEST_ROUTE); + init_run_actions_ctx(&ctx); + if(rt >= 0) { + LM_DBG("tm:local-request found [%d]\n", rt); + run_top_route(event_rt.rlist[rt], &msg, 0); + } else { + if(keng != NULL) { + + if(sr_kemi_route( + keng, &msg, EVENT_ROUTE, &tm_event_callback, &evname) + < 0) { + LM_ERR("error running event route kemi callback\n"); + } } } + set_route_type(backup_rt); + free_sip_msg(&msg); } - set_route_type(backup_rt); - free_sip_msg(&msg);
if(SEND_BUFFER(crb) >= 0) { if(unlikely(has_tran_tmcbs(t, TMCB_REQUEST_OUT))) @@ -429,7 +432,7 @@ void rpc_cancel(rpc_t *rpc, void *c) prepare_to_cancel(trans, &cancel_data.cancel_bitmap, 0); /* tell tm to cancel the call */ DBG("Now calling cancel_uacs\n"); - i = cancel_uacs(trans, &cancel_data, 0); /* don't fake 487s, + i = cancel_uacs(trans, &cancel_data, F_CANCEL_LOCAL); /* don't fake 487s, just wait for timeout */
/* t_lookup_callid REF`d the transaction for us, we must UNREF here! */ diff --git a/src/modules/tm/t_cancel.h b/src/modules/tm/t_cancel.h index b80a6dba77b..d5042edd97d 100644 --- a/src/modules/tm/t_cancel.h +++ b/src/modules/tm/t_cancel.h @@ -65,6 +65,8 @@ and F_CANCE_B_KILL take precedence */ #define F_CANCEL_UNREF 16 /* unref the trans after canceling */
+#define F_CANCEL_LOCAL 32 /* cancel is locally generated */ +
void prepare_to_cancel(struct cell *t, branch_bm_t *cancel_bm, branch_bm_t s); int cancel_uacs(struct cell *t, struct cancel_info *cancel_data, int flags);