From: Liviu Chircu <liviu@opensips.org>
Date: Thu, 24 May 2018 18:23:28 +0300
Subject: [PATCH] path: Fix "use_path_received" in double-Path scenarios
Due to the fact that run_rr_callbacks() returns the 2nd Route (Path)
header field value when previously having done protocol switching (thus
having inserted two Path headers), the "use_path_received" feature of
the path module would not work -- it wouldn't set the $du at all.
The reason for this is that add_path_received() appends its ";received="
to inside Path #1 (the outbound path of the registration / the inbound
path of future requests) when doing double-Path recording.
This patch simply moves the ";received=" append operation performed by
add_path_received() into Path #2 (inbound path of registration /
outbound path of future requests), and adapts other code that needs it
(e.g. save("location", "p1v")) to properly be able to fetch it.
Reported by @futsystems
Fixes #1358
(cherry picked from commit 71c7d75f66c8f0dc4ce411fd97d2dc867b39ce8d)
(cherry picked from commit 109f7dace65d8e0c87c9a025e8f434768fd52b5f)
diff --git a/modules/path/path.c b/modules/path/path.c
index f96b10150..9baccf74f 100644
--- a/modules/path/path.c
+++ b/modules/path/path.c
@@ -80,14 +80,16 @@ static int build_path(struct sip_msg* _m, struct lump* l, struct lump* l2,
memcpy(prefix + prefix_len - 1, "@", 1);
}
- suffix_len = PATH_LR_PARAM_LEN + (recv ? PATH_RC_PARAM_LEN : 0);
+ suffix_len = PATH_LR_PARAM_LEN +
+ (recv && (!enable_double_path || _inbound == INBOUND) ?
+ PATH_RC_PARAM_LEN : 0);
suffix = pkg_malloc(suffix_len);
if (!suffix) {
LM_ERR("no pkg memory left for suffix\n");
goto out1;
}
memcpy(suffix, PATH_LR_PARAM, PATH_LR_PARAM_LEN);
- if(recv)
+ if(recv && (!enable_double_path || _inbound == INBOUND))
memcpy(suffix+PATH_LR_PARAM_LEN, PATH_RC_PARAM, PATH_RC_PARAM_LEN);
crlf = pkg_malloc(PATH_CRLF_LEN);
@@ -120,7 +122,7 @@ static int build_path(struct sip_msg* _m, struct lump* l, struct lump* l2,
}
l2 = insert_new_lump_before(l2, suffix, suffix_len, 0);
if (!l2) goto out3;
- if (recv) {
+ if (recv && (!enable_double_path || _inbound == INBOUND)) {
/* TODO: agranig: optimize this one! */
src_ip = ip_addr2a(&_m->rcv.src_ip);
rcv_addr.s = pkg_malloc(4 + IP_ADDR_MAX_STR_SIZE + 7 +
@@ -227,7 +229,7 @@ static int prepend_path(struct sip_msg* _m, str *user, int recv)
LM_ERR("failed to insert conditional lump\n");
return -5;
}
- if (build_path(_m, l, l2, user, 0, INBOUND) < 0) {
+ if (build_path(_m, l, l2, user, recv, INBOUND) < 0) {
LM_ERR("failed to insert inbound Path");
return -6;
}
diff --git a/modules/registrar/path.c b/modules/registrar/path.c
index 02ff6833d..61fb13cb0 100644
--- a/modules/registrar/path.c
+++ b/modules/registrar/path.c
@@ -93,6 +93,22 @@ int build_path_vector(struct sip_msg *_m, str *path, str *received,
param_hooks_t hooks;
param_t *params;
+ if (parse_params(&(puri.params),CLASS_URI,&hooks,¶ms)!=0){
+ LM_ERR("failed to parse parameters of first hop\n");
+ goto error;
+ }
+
+ /* we have a double-Path OpenSIPS in front of us - skip 1st Path */
+ if (hooks.uri.r2 && route->next) {
+ if (parse_uri(route->next->nameaddr.uri.s,
+ route->next->nameaddr.uri.len, &puri) < 0) {
+ LM_ERR("failed to parse the 2nd Path URI\n");
+ goto error;
+ }
+ }
+
+ free_params(params);
+
if (parse_params(&(puri.params),CLASS_CONTACT,&hooks,¶ms)!=0){
LM_ERR("failed to parse parameters of first hop\n");
goto error;