Skip to content

Commit

Permalink
Do not inherit nothing (from prev branches) in failure route.
Browse files Browse the repository at this point in the history
Reset all per-branch values before entering failure route - provide a fresh start for creating the new branches.
  • Loading branch information
bogdan-iancu committed Jan 14, 2020
1 parent 0390ec9 commit f73abff
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
3 changes: 1 addition & 2 deletions modules/tm/async.c
Expand Up @@ -104,8 +104,7 @@ int t_resume_async(int fd, void *param)
if (!fake_req( &faked_req /* the fake msg to be built*/,
t->uas.request, /* the template msg saved in transaction */
&t->uas, /*the UAS side of the transaction*/
&uac, /* the fake UAC */
1 /* copy dst_uri too */)
&uac /* the fake UAC */)
) {
LM_ERR("fake_req failed\n");
return 0;
Expand Down
2 changes: 1 addition & 1 deletion modules/tm/t_fwd.c
Expand Up @@ -1013,7 +1013,7 @@ int t_inject_branch( struct cell *t, struct sip_msg *msg, int flags)
return -2;
}

if (!fake_req( &faked_req, t->uas.request, &t->uas, NULL, 0)) {
if (!fake_req( &faked_req, t->uas.request, &t->uas, NULL)) {
LM_ERR("fake_req failed\n");
return -1;
}
Expand Down
33 changes: 19 additions & 14 deletions modules/tm/t_msgbuilder.h
Expand Up @@ -190,7 +190,7 @@ static inline int fix_fake_req_headers(struct sip_msg *req)


static inline int fake_req(struct sip_msg *faked_req, struct sip_msg *shm_msg,
struct ua_server *uas, struct ua_client *uac, int inherit_br_data)
struct ua_server *uas, struct ua_client *uac)
{
/* on_negative_reply faked msg now copied from shmem msg (as opposed
* to zero-ing) -- more "read-only" actions (exec in particular) will
Expand All @@ -208,8 +208,11 @@ static inline int fake_req(struct sip_msg *faked_req, struct sip_msg *shm_msg,

faked_req->msg_flags |= FL_TM_FAKE_REQ;

/* new_uri can change -- make a private copy */
if (uac) {

/* duplicate some values into private mem
* so that they can be visible and changed at script level */
/* RURI / new URI */
faked_req->new_uri.s=pkg_malloc( uac->uri.len+1 );
if (!faked_req->new_uri.s) {
LM_ERR("no uri/pkg mem\n");
Expand All @@ -218,13 +221,6 @@ static inline int fake_req(struct sip_msg *faked_req, struct sip_msg *shm_msg,
faked_req->new_uri.len = uac->uri.len;
memcpy( faked_req->new_uri.s, uac->uri.s, uac->uri.len);
faked_req->new_uri.s[faked_req->new_uri.len]=0;
} else {
faked_req->new_uri.s = NULL;
faked_req->new_uri.len = 0;
}
faked_req->parsed_uri_ok = 0;

if (inherit_br_data) {

/* duplicate the dst_uri and path_vec into private mem
* so that they can be visible and changed at script level */
Expand All @@ -245,6 +241,11 @@ static inline int fake_req(struct sip_msg *faked_req, struct sip_msg *shm_msg,
memcpy(faked_req->path_vec.s, uac->path_vec.s, uac->path_vec.len);
}

/* set the branch flags from the elected branch */
setb0flags( faked_req, uac->br_flags);
/* Q and force_send_socket values were already copied
* as part of the sip_msg struct */

/* duplicate advertised address and port from UAC into
* private mem so that they can be changed at script level */
if (uac->adv_address.s) {
Expand Down Expand Up @@ -272,16 +273,23 @@ static inline int fake_req(struct sip_msg *faked_req, struct sip_msg *shm_msg,
faked_req->set_global_port.len = 0;
}

/* Q value was already copied as part of the sip_msg struct */
} else {

/* reset new URI value */
faked_req->new_uri.s = NULL;
faked_req->new_uri.len = 0;

/* reset DST URI, PATH vector and Q value */
faked_req->dst_uri.s = NULL;
faked_req->dst_uri.len = 0;
faked_req->path_vec.s = NULL;
faked_req->path_vec.len = 0;
faked_req->ruri_q = Q_UNSPECIFIED;

/* reset force_send_socket and the per-branch flags */
faked_req->force_send_socket = NULL;
setb0flags( faked_req, 0);

/* duplicate advertised address and port from SIP MSG into
* private mem so that they can be changed at script level */
if (shm_msg->set_global_address.s) {
Expand Down Expand Up @@ -318,11 +326,8 @@ static inline int fake_req(struct sip_msg *faked_req, struct sip_msg *shm_msg,
goto out4;
}

/* set as flags the global flags and the branch flags from the
* elected branch */
/* set as flags the global flags */
faked_req->flags = uas->request->flags;
if (uac)
setb0flags( faked_req, uac->br_flags);

return 1;
out4:
Expand Down
4 changes: 2 additions & 2 deletions modules/tm/t_reply.c
Expand Up @@ -581,7 +581,7 @@ static inline int run_failure_handlers(struct cell *t)
return 1;
}

if (!fake_req(&faked_req, shmem_msg, &t->uas, uac, 0/*no dst_uri*/)) {
if (!fake_req(&faked_req, shmem_msg, &t->uas, NULL)) {
LM_ERR("fake_req failed\n");
return 0;
}
Expand Down Expand Up @@ -693,7 +693,7 @@ static inline int do_dns_failover(struct cell *t)
}
shmem_msg = t->uas.request;

if (!fake_req(&faked_req, shmem_msg, &t->uas, uac, 1/*with dst_uri*/)) {
if (!fake_req(&faked_req, shmem_msg, &t->uas, uac)) {
LM_ERR("fake_req failed\n");
return -1;
}
Expand Down

0 comments on commit f73abff

Please sign in to comment.