Skip to content

Commit

Permalink
properly populate route_type for certain routes
Browse files Browse the repository at this point in the history
Reported by Ben Newlin in ticket #1846
  • Loading branch information
razvancrainea committed Oct 9, 2019
1 parent a37642a commit 2ae5120
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 2 deletions.
5 changes: 5 additions & 0 deletions modules/b2b_entities/dlg.c
Expand Up @@ -2118,6 +2118,7 @@ void b2b_tm_cback(struct cell *t, b2b_table htable, struct tmcb_params *ps)
HASHHEX response;
str *new_hdr;
char status_buf[INT2STR_MAX_LEN];
int old_route_type;

to_hdr_parsed.param_lst = from_hdr_parsed.param_lst = NULL;

Expand Down Expand Up @@ -2429,7 +2430,9 @@ void b2b_tm_cback(struct cell *t, b2b_table htable, struct tmcb_params *ps)
/* run the b2b route */
if(reply_routeid > 0) {
msg->flags = t->uac[0].br_flags;
swap_route_type(old_route_type, ONREPLY_ROUTE);
run_top_route(sroutes->request[reply_routeid].a, msg);
set_route_type(old_route_type);
b2b_apply_lumps(msg);
}
goto b2b_route;
Expand Down Expand Up @@ -2769,7 +2772,9 @@ void b2b_tm_cback(struct cell *t, b2b_table htable, struct tmcb_params *ps)
/* run the b2b route */
if(reply_routeid > 0) {
msg->flags = t->uac[0].br_flags;
swap_route_type(old_route_type, ONREPLY_ROUTE);
run_top_route(sroutes->request[reply_routeid].a, msg);
set_route_type(old_route_type);
if (msg != FAKED_REPLY) b2b_apply_lumps(msg);
}

Expand Down
3 changes: 3 additions & 0 deletions modules/event_route/event_route.c
Expand Up @@ -337,8 +337,11 @@ int event_route_param_get(struct sip_msg *msg, pv_param_t *ip,
void route_run(struct action* a, struct sip_msg* msg,
evi_params_t *params, str *event)
{
int old_route_type;
route_params_push_level(params, event, event_route_param_get);
swap_route_type(old_route_type, EVENT_ROUTE);
run_top_route(a, msg);
set_route_type(old_route_type);
route_params_pop_level();
}

Expand Down
10 changes: 10 additions & 0 deletions modules/tm/t_reply.c
Expand Up @@ -562,6 +562,7 @@ static inline int run_failure_handlers(struct cell *t)
struct sip_msg *shmem_msg;
struct ua_client *uac;
int on_failure;
int old_route_type;

shmem_msg = t->uas.request;
uac = &t->uac[picked_branch];
Expand Down Expand Up @@ -601,7 +602,9 @@ static inline int run_failure_handlers(struct cell *t)
on_failure = t->on_negative;
t->on_negative=0;
/* run a reply_route action if some was marked */
swap_route_type(old_route_type, FAILURE_ROUTE);
run_top_route(sroutes->failure[on_failure].a, &faked_req);
set_route_type(old_route_type);
}

/* restore original environment and free the fake msg */
Expand Down Expand Up @@ -1491,6 +1494,7 @@ int reply_received( struct sip_msg *p_msg )
struct cell *t;
struct usr_avp **backup_list;
unsigned int has_reply_route;
int old_route_type;

set_t(T_UNDEFINED);

Expand Down Expand Up @@ -1569,26 +1573,32 @@ int reply_received( struct sip_msg *p_msg )
/* transfer transaction flag to branch context */
p_msg->flags = t->uas.request ? t->uas.request->flags : 0;
setb0flags( p_msg, t->uac[branch].br_flags);

swap_route_type(old_route_type, BRANCH_ROUTE);
/* run block - first per branch and then global one */
if ( t->uac[branch].on_reply &&
(run_top_route(sroutes->onreply[t->uac[branch].on_reply].a,p_msg)
&ACT_FL_DROP) && (msg_status<200) ) {
set_route_type(old_route_type);
if (onreply_avp_mode) {
UNLOCK_REPLIES( t );
set_avp_list( backup_list );
}
LM_DBG("dropping provisional reply %d\n", msg_status);
goto done;
}
set_route_type(ONREPLY_ROUTE);
if(t->on_reply && (run_top_route(sroutes->onreply[t->on_reply].a,p_msg)
&ACT_FL_DROP) && (msg_status<200) ) {
set_route_type(old_route_type);
if (onreply_avp_mode) {
UNLOCK_REPLIES( t );
set_avp_list( backup_list );
}
LM_DBG("dropping provisional reply %d\n", msg_status);
goto done;
}
set_route_type(old_route_type);
/* transfer current message context back to t */
t->uac[branch].br_flags = getb0flags(p_msg);
if (t->uas.request)
Expand Down
5 changes: 4 additions & 1 deletion receive.c
Expand Up @@ -102,7 +102,7 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info,
static context_p ctx = NULL;
struct sip_msg* msg;
struct timeval start;
int rc;
int rc, old_route_type;
char *tmp;
str in_buff;

Expand Down Expand Up @@ -246,15 +246,18 @@ int receive_msg(char* buf, unsigned int len, struct receive_info* rcv_info,
goto end; /* drop the reply */
}

swap_route_type(old_route_type, ONREPLY_ROUTE);
/* exec the onreply routing script */
if (rc & SCB_RUN_TOP_ROUTE && sroutes->onreply[DEFAULT_RT].a &&
(run_top_route(sroutes->onreply[DEFAULT_RT].a,msg) & ACT_FL_DROP)
&& msg->REPLY_STATUS < 200) {
set_route_type(old_route_type);

LM_DBG("dropping provisional reply %d\n", msg->REPLY_STATUS);
update_stat( drp_rpls, 1);
goto end; /* drop the message */
} else {
set_route_type(old_route_type);
/* send the msg */
forward_reply(msg);
/* TODO - TX reply stat */
Expand Down
7 changes: 6 additions & 1 deletion route.c
Expand Up @@ -950,6 +950,7 @@ int eval_expr(struct expr* e, struct sip_msg* msg, pv_value_t *val)
int run_startup_route(void)
{
struct sip_msg req;
int ret, old_route_type;

memset(&req, 0, sizeof(struct sip_msg));
req.first_line.type = SIP_REQUEST;
Expand All @@ -961,8 +962,12 @@ int run_startup_route(void)
req.rcv.src_ip.af = AF_INET;
req.rcv.dst_ip.af = AF_INET;

swap_route_type(old_route_type, STARTUP_ROUTE);
/* run the route */
return run_top_route( sroutes->startup.a, &req);
ret = run_top_route( sroutes->startup.a, &req);
set_route_type(old_route_type);

return ret;
}


Expand Down
3 changes: 3 additions & 0 deletions timer.c
Expand Up @@ -233,6 +233,7 @@ void route_timer_f(unsigned int ticks, void* param)
{
struct action* a = (struct action*)param;
static struct sip_msg* req= NULL;
int old_route_type;

if(req == NULL)
{
Expand All @@ -257,7 +258,9 @@ void route_timer_f(unsigned int ticks, void* param)
return;
}

swap_route_type(old_route_type, TIMER_ROUTE);
run_top_route(a, req);
set_route_type(old_route_type);

/* clean whatever extra structures were added by script functions */
free_sip_msg(req);
Expand Down

0 comments on commit 2ae5120

Please sign in to comment.