Module: kamailio Branch: master Commit: 6d03698be380cbbe14e451933c1a9a9d66f4b92e URL: https://github.com/kamailio/kamailio/commit/6d03698be380cbbe14e451933c1a9a9d66f4b92e
Author: Daniel-Constantin Mierla <[email protected]> Committer: Daniel-Constantin Mierla <[email protected]> Date: 2025-12-15T10:21:23+01:00 tm: option to create a completely new branch for local 200ok-ack --- Modified: src/modules/tm/t_msgbuilder.c Modified: src/modules/tm/t_msgbuilder.h --- Diff: https://github.com/kamailio/kamailio/commit/6d03698be380cbbe14e451933c1a9a9d66f4b92e.diff Patch: https://github.com/kamailio/kamailio/commit/6d03698be380cbbe14e451933c1a9a9d66f4b92e.patch --- diff --git a/src/modules/tm/t_msgbuilder.c b/src/modules/tm/t_msgbuilder.c index 7cb8a644581..b8fa2f968c6 100644 --- a/src/modules/tm/t_msgbuilder.c +++ b/src/modules/tm/t_msgbuilder.c @@ -1322,7 +1322,7 @@ char *build_dlg_ack(struct sip_msg *rpl, struct cell *Trans, } /* via */ - if(!t_calc_branch_ack(Trans, branch, branch_buf, &branch_len)) + if(!t_calc_branch_ack(Trans, rpl, branch, branch_buf, &branch_len)) goto error; branch_str.s = branch_buf; branch_str.len = branch_len; @@ -1813,6 +1813,51 @@ char *build_uac_req(str *method, str *headers, str *body, dlg_t *dialog, return 0; } +int t_via_local_branch_val(sip_msg_t *msg, char *sval, char *md5b) +{ + int i = 0; + int n = 0; + str src[6]; + + for(i = 0; i < MD5_LEN; i++) { + md5b[i] = '0'; + } + + if(parse_headers(msg, + HDR_VIA_F | HDR_FROM_F | HDR_TO_F | HDR_CALLID_F | HDR_CSEQ_F, + 0) < 0 + || parse_from_header(msg) < 0 || msg->from == NULL + || msg->from->parsed == NULL || msg->to == NULL + || msg->callid == NULL || msg->cseq == NULL) { + LM_ERR("invalid message\n"); + return -1; + } + + src[n] = get_from(msg)->tag_value; + n++; + if(get_to(msg)->tag_value.s != NULL && get_to(msg)->tag_value.len > 0) { + src[n] = get_to(msg)->tag_value; + n++; + } + src[n] = msg->callid->body; + n++; + if(sval != NULL) { + src[n].s = sval; + src[n].len = strlen(sval); + n++; + } + src[n] = get_cseq(msg)->number; + n++; + + if(msg->via1 != NULL && msg->via1->branch != NULL) { + src[n] = msg->via1->branch->value; + n++; + } + + MD5StringArray(md5b, src, n); + + return 0; +} int t_calc_branch(struct cell *t, int b, char *branch, int *branch_len) { @@ -1820,33 +1865,43 @@ int t_calc_branch(struct cell *t, int b, char *branch, int *branch_len) t->hash_index, 0, t->md5, NULL, b, branch, branch_len); } -int t_calc_branch_ack(struct cell *t, int b, char *branch, int *branch_len) +int t_calc_branch_ack( + struct cell *t, sip_msg_t *rpl, int b, char *branch, int *branch_len) { char md5b[MD5_LEN + 1]; int i = 0; int k = 0; - if(tm_local_ack_branch_mode != 1) { + if(tm_local_ack_branch_mode == 0) { return branch_builder( t->hash_index, 0, t->md5, NULL, b, branch, branch_len); } - memcpy(md5b, t->md5, MD5_LEN); - md5b[MD5_LEN] = '\0'; - for(k = 0; k < 4; k++) { - i = MD5_LEN - 1 - k; - if(md5b[i] >= '0' && md5b[i] < '9') { - md5b[i] = md5b[i] + 1; - } else if(md5b[i] == '9') { - md5b[i] = '0'; - } else if(md5b[i] >= 'a' && md5b[i] < 'z') { - md5b[i] = md5b[i] + 1; - } else if(md5b[i] == 'z') { - md5b[i] = 'a'; - } else if(md5b[i] >= 'A' && md5b[i] < 'Z') { - md5b[i] = md5b[i] + 1; - } else if(md5b[i] == 'z') { - md5b[i] = 'A'; + if(tm_local_ack_branch_mode == 2) { + if(t_via_local_branch_val(rpl, "ACK", md5b) == 0) { + k = 1; + } + } + + if(k == 0) { + /* tm_local_ack_branch_mode != 2 or t_via_local_branch_val() failed */ + memcpy(md5b, t->md5, MD5_LEN); + md5b[MD5_LEN] = '\0'; + for(k = 0; k < 4; k++) { + i = MD5_LEN - 1 - k; + if(md5b[i] >= '0' && md5b[i] < '9') { + md5b[i] = md5b[i] + 1; + } else if(md5b[i] == '9') { + md5b[i] = '0'; + } else if(md5b[i] >= 'a' && md5b[i] < 'z') { + md5b[i] = md5b[i] + 1; + } else if(md5b[i] == 'z') { + md5b[i] = 'a'; + } else if(md5b[i] >= 'A' && md5b[i] < 'Z') { + md5b[i] = md5b[i] + 1; + } else if(md5b[i] == 'z') { + md5b[i] = 'A'; + } } } diff --git a/src/modules/tm/t_msgbuilder.h b/src/modules/tm/t_msgbuilder.h index aefc103ae2e..103fb8ceec8 100644 --- a/src/modules/tm/t_msgbuilder.h +++ b/src/modules/tm/t_msgbuilder.h @@ -71,7 +71,8 @@ char *build_uac_req(str *method, str *headers, str *body, dlg_t *dialog, int t_calc_branch(struct cell *t, int b, char *branch, int *branch_len); -int t_calc_branch_ack(struct cell *t, int b, char *branch, int *branch_len); +int t_calc_branch_ack( + struct cell *t, sip_msg_t *rpl, int b, char *branch, int *branch_len); /* exported minimum functions for use in t_cancel */ char *print_callid_mini(char *target, str callid); _______________________________________________ Kamailio - Development Mailing List -- [email protected] To unsubscribe send an email to [email protected] Important: keep the mailing list in the recipients, do not reply only to the sender!
