Skip to content

Commit

Permalink
[drouting] fix solving the script route upon load
Browse files Browse the repository at this point in the history
Do not lookup the name of the route at DB load (as we do not have the proper structure), but do it at runtime.
Closes #1824

(cherry picked from commit 3812dea)
  • Loading branch information
bogdan-iancu committed Sep 19, 2019
1 parent fd2f007 commit 93c36c8
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 29 deletions.
23 changes: 6 additions & 17 deletions modules/drouting/dr_load.c
Expand Up @@ -289,7 +289,6 @@ void dr_update_head_cache(struct head_db *head)
#define INT_VALS_RULE_ID_DRR_COL 0
#define INT_VALS_BLANK_1 1
#define INT_VALS_PRIORITY_DRR_COL 2
#define INT_VALS_SCRIPT_ROUTE_ID 3
#define STR_VALS_GROUP_DRR_COL 0
#define STR_VALS_PREFIX_DRR_COL 1
#define STR_VALS_TIME_DRR_COL 2
Expand Down Expand Up @@ -685,27 +684,17 @@ rt_data_t* dr_load_routing_info(struct head_db *current_partition
int_vals[INT_VALS_RULE_ID_DRR_COL]);
continue;
}
/* lookup for the script route ID */
if ( !VAL_NULL(ROW_VALUES(row)+5) &&
/* set the script route ID */
if ( VAL_NULL(ROW_VALUES(row)+5) ||
((str_vals[STR_VALS_ROUTEID_DRR_COL]=
(char*)VAL_STRING(ROW_VALUES(row)+5))!=NULL ) &&
str_vals[STR_VALS_ROUTEID_DRR_COL][0] ) {
int_vals[INT_VALS_SCRIPT_ROUTE_ID] =
get_script_route_ID_by_name
( str_vals[STR_VALS_ROUTEID_DRR_COL], sroutes->request,
RT_NO);
if (int_vals[INT_VALS_SCRIPT_ROUTE_ID]==-1) {
LM_WARN("route <%s> does not exist\n",
str_vals[STR_VALS_ROUTEID_DRR_COL]);
int_vals[INT_VALS_SCRIPT_ROUTE_ID] = 0;
}
} else {
int_vals[INT_VALS_SCRIPT_ROUTE_ID] = 0;
(char*)VAL_STRING(ROW_VALUES(row)+5))==NULL ) ||
str_vals[STR_VALS_ROUTEID_DRR_COL][0]==0 ) {
str_vals[STR_VALS_ROUTEID_DRR_COL] = NULL;
}
/* build the routing rule */
if ((ri = build_rt_info( int_vals[INT_VALS_RULE_ID_DRR_COL],
int_vals[INT_VALS_PRIORITY_DRR_COL], time_rec,
int_vals[INT_VALS_SCRIPT_ROUTE_ID],
str_vals[STR_VALS_ROUTEID_DRR_COL],
str_vals[STR_VALS_DSTLIST_DRR_COL],
str_vals[STR_VALS_ATTRS_DRR_COL], rdata,
current_partition->malloc,
Expand Down
9 changes: 5 additions & 4 deletions modules/drouting/drouting.c
Expand Up @@ -2583,7 +2583,7 @@ static int do_routing(struct sip_msg* msg, struct head_db *part, int grp,
struct head_db *current_partition=NULL;
unsigned short wl_len;
str username;
int i, j, n;
int i, j, n, rt_idx;
int_str val;
str ruri;
str next_carrier_attrs = {NULL, 0};
Expand Down Expand Up @@ -2773,12 +2773,13 @@ static int do_routing(struct sip_msg* msg, struct head_db *part, int grp,
rule_idx = 0;
}

if (rt_info->route_idx>0 && rt_info->route_idx<RT_NO) {
fret = run_top_route( sroutes->request[rt_info->route_idx].a, msg );
if (rt_info->route_idx && (rt_idx=get_script_route_ID_by_name
(rt_info->route_idx, sroutes->request, RT_NO))!=-1) {
fret = run_top_route( sroutes->request[rt_idx].a, msg );
if (fret&ACT_FL_DROP) {
/* drop the action */
LM_DBG("script route %s drops routing "
"by %d\n", sroutes->request[rt_info->route_idx].name, fret);
"by %d\n", sroutes->request[rt_idx].name, fret);
goto error2;
}
}
Expand Down
2 changes: 1 addition & 1 deletion modules/drouting/prefix_tree.h
Expand Up @@ -129,7 +129,7 @@ typedef struct rt_info_ {
/* timerec says when the rule is on */
tmrec_t *time_rec;
/* script route to be executed */
int route_idx;
char* route_idx;
/* opaque string with rule attributes */
str attrs;
/* array of pointers into the PSTN gw list */
Expand Down
14 changes: 9 additions & 5 deletions modules/drouting/routing.c
Expand Up @@ -308,8 +308,8 @@ build_rt_info(
int id,
int priority,
tmrec_t *trec,
/* script routing table index */
int route_idx,
/* script route name */
char* route_idx,
/* list of destinations indexes */
char* dstlst,
char* attrs,
Expand All @@ -318,9 +318,10 @@ build_rt_info(
osips_free_f ff
)
{
rt_info_t* rt = NULL;;
rt_info_t* rt = NULL;

rt = (rt_info_t*)func_malloc(mf, sizeof(rt_info_t)+(attrs?strlen(attrs):0));
rt = (rt_info_t*)func_malloc(mf, sizeof(rt_info_t) +
(attrs?strlen(attrs):0) + (route_idx?strlen(route_idx)+1:0) );
if (rt==NULL) {
LM_ERR("no more mem(1)\n");
goto err_exit;
Expand All @@ -330,12 +331,15 @@ build_rt_info(
rt->id = id;
rt->priority = priority;
rt->time_rec = trec;
rt->route_idx = route_idx;
if (attrs && strlen(attrs)) {
rt->attrs.s = (char*)(rt+1);
rt->attrs.len = strlen(attrs);
memcpy(rt->attrs.s,attrs,rt->attrs.len);
}
if (route_idx && strlen(route_idx)) {
rt->route_idx = ((char*)(rt+1)) + rt->attrs.len;
strcpy(rt->route_idx, route_idx);
}

if ( dstlst && dstlst[0]!=0 ) {
if (parse_destination_list(rd, dstlst, &rt->pgwl,&rt->pgwa_len,0,mf)!=0){
Expand Down
4 changes: 2 additions & 2 deletions modules/drouting/routing.h
Expand Up @@ -133,8 +133,8 @@ build_rt_info(
int id,
int priority,
tmrec_t* time,
/* ser routing table id */
int route_id,
/* name of the script route */
char* route_idx,
/* list of destinations indexes */
char* dstlst,
char* attr,
Expand Down

0 comments on commit 93c36c8

Please sign in to comment.