TT#70962 [pv_headers]: fix fork scenario

* add some more debug
* tm fix from upstream, see https://github.com/kamailio/kamailio/issues/2141

(cherry picked from commit f80b4491c8)
Change-Id: I6bee5ade5f4cdb2c2ead15a9762ef280c3e3b1e1
changes/95/35695/1
Victor Seva 7 years ago
parent 48d6163c5a
commit b0d359964d

@ -54,3 +54,4 @@ sipwise/sca-fix-memleaks.patch
sipwise/presence_dfks_null_ptr_fixes.patch
sipwise/db_redis_eval_fix.patch
sipwise/fix_lcr_rate_wrong_id.patch
upstream/tm-execute-TMCB_REQUEST_FWDED-cb-as-BRANCH_ROUTE-whe.patch

@ -2,13 +2,14 @@ From: Sipwise Development Team <support@sipwise.com>
Date: Mon, 18 Nov 2019 10:36:39 +0100
Subject: add_pv_headers_module
Change-Id: I9f7efd8872a815b86ced8a06f663a10c5f327dcf
---
src/Makefile.groups | 2 +-
src/modules/pv_headers/Makefile | 12 +
src/modules/pv_headers/README | 488 +++++++++
src/modules/pv_headers/pv_headers.c | 2074 +++++++++++++++++++++++++++++++++++
src/modules/pv_headers/pv_headers.c | 2069 +++++++++++++++++++++++++++++++++++
src/modules/pv_headers/pv_headers.h | 30 +
5 files changed, 2605 insertions(+), 1 deletion(-)
5 files changed, 2600 insertions(+), 1 deletion(-)
create mode 100644 src/modules/pv_headers/Makefile
create mode 100644 src/modules/pv_headers/README
create mode 100644 src/modules/pv_headers/pv_headers.c
@ -541,10 +542,10 @@ index 0000000..30bd1da
+ $var(test) = $x_rr;
diff --git a/src/modules/pv_headers/pv_headers.c b/src/modules/pv_headers/pv_headers.c
new file mode 100644
index 0000000..49e32b3
index 0000000..79e91e6
--- /dev/null
+++ b/src/modules/pv_headers/pv_headers.c
@@ -0,0 +1,2074 @@
@@ -0,0 +1,2069 @@
+/*
+ * pv_headers
+ *
@ -794,24 +795,19 @@ index 0000000..49e32b3
+{
+ struct sip_msg *msg = NULL;
+
+ switch (type) {
+ case TMCB_RESPONSE_IN:
+ msg = params->rpl;
+ if (msg != NULL && msg != FAKED_REPLY) {
+ pv_reset_headers(msg, NULL, NULL);
+ pv_collect_headers(msg, "1", NULL);
+ }
+ return;
+ case TMCB_REQUEST_FWDED:
+ msg = params->req;
+ break;
+ case TMCB_ON_BRANCH_FAILURE:
+ case TMCB_RESPONSE_FWDED:
+ msg = params->rpl;
+ break;
+ default:
+ LM_ERR("unknown callback: %d\n", type);
+ return;
+ if (type & TMCB_RESPONSE_IN) {
+ msg = params->rpl;
+ if (msg != NULL && msg != FAKED_REPLY) {
+ pv_reset_headers(msg, NULL, NULL);
+ pv_collect_headers(msg, "1", NULL);
+ }
+ } else if (type & TMCB_REQUEST_FWDED) {
+ msg = params->req;
+ } else if (type &(TMCB_ON_BRANCH_FAILURE|TMCB_RESPONSE_FWDED)) {
+ msg = params->rpl;
+ } else {
+ LM_ERR("unknown callback: %d\n", type);
+ return;
+ }
+
+ if (msg != NULL && msg != FAKED_REPLY)
@ -824,16 +820,14 @@ index 0000000..49e32b3
+{
+ int cbs = TMCB_REQUEST_FWDED | TMCB_RESPONSE_FWDED | TMCB_RESPONSE_IN | TMCB_ON_BRANCH_FAILURE;
+
+ switch (flags) {
+ case PRE_SCRIPT_CB|REQUEST_CB:
+ if (tmb.register_tmcb( msg, 0, cbs, handle_tm_t, 0, 0) <=0) {
+ LM_ERR("cannot register TM callbacks\n");
+ return -1;
+ }
+ pv_collect_headers(msg, "1", NULL);
+ break;
+ default:
+ LM_ERR("unknown callback: %d\n", flags);
+ if (flags & (PRE_SCRIPT_CB|REQUEST_CB)) {
+ if (tmb.register_tmcb( msg, 0, cbs, handle_tm_t, 0, 0) <=0) {
+ LM_ERR("cannot register TM callbacks\n");
+ return -1;
+ }
+ pv_collect_headers(msg, "1", NULL);
+ } else {
+ LM_ERR("unknown callback: %d\n", flags);
+ }
+
+ return 1;
@ -850,7 +844,7 @@ index 0000000..49e32b3
+ int br_idx;
+
+ pv_get_branch_index(msg, &br_idx);
+
+ LM_DBG("br_idx: %d\n", br_idx);
+ if (!(is_auto && strcmp(is_auto, "1") == 0) &&
+ ((msg->first_line.type == SIP_REPLY && isflagset(msg, FL_PV_HDRS_COLLECTED) == 1) ||
+ (msg->first_line.type != SIP_REPLY && isbflagset(br_idx, FL_PV_HDRS_COLLECTED) == 1))) {
@ -921,7 +915,7 @@ index 0000000..49e32b3
+ struct str_hash_table rm_hdrs;
+ int from_cnt = 0, to_cnt = 0;
+ str br_xname = STR_NULL;
+ int br_idx;
+ int br_idx, keys_count;
+
+ rm_hdrs.size = 0;
+
@ -950,7 +944,6 @@ index 0000000..49e32b3
+ LM_ERR("missing xavp %s, run pv_collect_headers() first\n", xavp_name.s);
+ goto err;
+ }
+
+ if (xavp->val.type != SR_XTYPE_XAVP) {
+ LM_ERR("not xavp child type %s\n" , xavp_name.s);
+ goto err;
@ -960,11 +953,13 @@ index 0000000..49e32b3
+ LM_ERR("invalid xavp structure: %s\n", xavp_name.s);
+ goto err;
+ }
+
+ if (str_hash_alloc(&rm_hdrs, pv_xavp_keys_count(&sub)) < 0) {
+ keys_count = pv_xavp_keys_count(&sub);
+ if (str_hash_alloc(&rm_hdrs, keys_count) < 0) {
+ LM_ERR("memory allocation error\n");
+ goto err;
+ }
+ LM_DBG("xavp->name:%.*s br_xname:%.*s keys_count: %d\n",
+ xavp->name.len, xavp->name.s, br_xname.len, br_xname.s, keys_count);
+ str_hash_init(&rm_hdrs);
+
+ do {
@ -1230,7 +1225,8 @@ index 0000000..49e32b3
+ if (pv_str_new(&br_xname, header_name_size) < 0)
+ return -1;
+ pv_get_branch_xname(msg, xname, &br_xname);
+
+ LM_DBG("br_xname: %.*s name: %.*s\n",
+ br_xname.len, br_xname.s, name->len, name->s);
+ memset(&xval, 0, sizeof(sr_xval_t));
+ if (data == NULL || SR_XTYPE_NULL) {
+ xval.type = SR_XTYPE_NULL;
@ -1703,7 +1699,7 @@ index 0000000..49e32b3
+ if (idx < 0)
+ return -1;
+ }
+
+ LM_DBG("xavp name: %.s\n", name->len, name->s);
+ if (xavp_set_value(name, idx, val, start) == NULL)
+ return -1;
+

@ -0,0 +1,44 @@
From 7b10327189fc6c1cf1c53fc7c90bed84753ec54b Mon Sep 17 00:00:00 2001
From: Victor Seva <linuxmaniac@torreviejawireless.org>
Date: Thu, 21 Nov 2019 08:15:03 +0100
Subject: [PATCH] tm: execute TMCB_REQUEST_FWDED cb as BRANCH_ROUTE when
necessary
(cherry picked from commit bc40eaa4fe446bffd9f41d5d6b21becd7b7fdc87)
---
src/modules/tm/t_fwd.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/src/modules/tm/t_fwd.c b/src/modules/tm/t_fwd.c
index 2ad86a3f8..99f603403 100644
--- a/src/modules/tm/t_fwd.c
+++ b/src/modules/tm/t_fwd.c
@@ -376,15 +376,19 @@ static int prepare_new_uac( struct cell *t, struct sip_msg *i_req,
goto error03;
}
}
+ /* run the specific callbacks for this transaction */
+ if (unlikely(has_tran_tmcbs(t, TMCB_REQUEST_FWDED)))
+ run_trans_callbacks( TMCB_REQUEST_FWDED , t, i_req, 0,
+ -i_req->REQ_METHOD);
+
tm_ctx_set_branch_index(T_BR_UNDEFINED);
set_route_type(backup_route_type);
+ } else {
+ /* run the specific callbacks for this transaction */
+ if (unlikely(has_tran_tmcbs(t, TMCB_REQUEST_FWDED)))
+ run_trans_callbacks( TMCB_REQUEST_FWDED , t, i_req, 0,
+ -i_req->REQ_METHOD);
}
-
- /* run the specific callbacks for this transaction */
- if (unlikely(has_tran_tmcbs(t, TMCB_REQUEST_FWDED)))
- run_trans_callbacks( TMCB_REQUEST_FWDED , t, i_req, 0,
- -i_req->REQ_METHOD);
-
if (likely( !(flags & UAC_DNS_FAILOVER_F) && i_req->dst_uri.s &&
i_req->dst_uri.len)){
/* no dns failover and non-empty dst_uri => use it as dst
--
2.20.1
Loading…
Cancel
Save