Skip to content

Commit 10a55fc

Browse files
committed
[dispatcher] fix resetting the persistent_state for default partition
The modparam (as per docs) must change the default partition settings only Fixes #3635, reported by @nikbyte (cherry picked from commit e86b121)
1 parent e82c767 commit 10a55fc

1 file changed

Lines changed: 37 additions & 13 deletions

File tree

modules/dispatcher/dispatcher.c

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ static int mi_child_init(void);
215215

216216
static int set_partition_arguments(unsigned int type, void * val);
217217
static int set_probing_list(unsigned int type, void * val);
218+
static int set_df_persistent_state(unsigned int type, void * val);
218219

219220
static const cmd_export_t cmds[] = {
220221
{"ds_select_dst", (cmd_function)w_ds_select_dst, {
@@ -295,14 +296,14 @@ static const param_export_t params[]={
295296
{"weight_col", STR_PARAM, &ds_dest_weight_col.s},
296297
{"priority_col", STR_PARAM, &ds_dest_prio_col.s},
297298
{"attrs_col", STR_PARAM, &ds_dest_attrs_col.s},
298-
{"description_col", STR_PARAM, &ds_dest_description_col.s},
299-
{"probe_mode_col", STR_PARAM, &ds_dest_probe_mode_col.s},
299+
{"description_col", STR_PARAM, &ds_dest_description_col.s},
300+
{"probe_mode_col", STR_PARAM, &ds_dest_probe_mode_col.s},
300301
{"dst_avp", STR_PARAM, &default_db_head.dst_avp.s},
301302
{"grp_avp", STR_PARAM, &default_db_head.grp_avp.s},
302303
{"cnt_avp", STR_PARAM, &default_db_head.cnt_avp.s},
303304
{"sock_avp", STR_PARAM, &default_db_head.sock_avp.s},
304305
{"attrs_avp", STR_PARAM, &default_db_head.attrs_avp.s},
305-
{"script_attrs_avp", STR_PARAM, &default_db_head.script_attrs_avp.s},
306+
{"script_attrs_avp",STR_PARAM, &default_db_head.script_attrs_avp.s},
306307
{"algo_route", STR_PARAM, &algo_route_param.s},
307308
{"hash_pvar", STR_PARAM, &hash_pvar_param.s},
308309
{"setid_pvar", STR_PARAM, &ds_setid_pvname.s},
@@ -316,10 +317,12 @@ static const param_export_t params[]={
316317
{"ds_probing_mode", INT_PARAM, &ds_probing_mode},
317318
{"options_reply_codes", STR_PARAM, &options_reply_codes_str.s},
318319
{"ds_probing_sock", STR_PARAM, &probing_sock_s.s},
319-
{"ds_probing_list", STR_PARAM|USE_FUNC_PARAM, (void*)set_probing_list},
320+
{"ds_probing_list", STR_PARAM|USE_FUNC_PARAM,
321+
(void*)set_probing_list},
320322
{"ds_define_blacklist", STR_PARAM|USE_FUNC_PARAM, (void*)set_ds_bl},
321-
{"persistent_state", INT_PARAM, &ds_persistent_state},
322-
{"fetch_freeswitch_stats", INT_PARAM, &fetch_freeswitch_stats},
323+
{"persistent_state", INT_PARAM|USE_FUNC_PARAM,
324+
(void*)set_df_persistent_state},
325+
{"fetch_freeswitch_stats",INT_PARAM, &fetch_freeswitch_stats},
323326
{"max_freeswitch_weight", INT_PARAM, &max_freeswitch_weight},
324327
{"cluster_id", INT_PARAM, &ds_cluster_id },
325328
{"cluster_sharing_tag", STR_PARAM, &ds_cluster_shtag },
@@ -554,6 +557,21 @@ static int set_probing_list(unsigned int type, void *val) {
554557
}
555558

556559

560+
/* coverts the persistent state for the default partiton from int to str */
561+
static int set_df_persistent_state(unsigned int type, void * val)
562+
{
563+
if ( (int)(long)val == 0) {
564+
default_db_head.persistent_state.s = "0";
565+
default_db_head.persistent_state.len = 1;
566+
} else {
567+
default_db_head.persistent_state.s = "1";
568+
default_db_head.persistent_state.len = 1;
569+
}
570+
571+
return 0;
572+
}
573+
574+
557575
/* We parse the "partition" argument as: partition_name:arg1=val1; arg2=val2;*/
558576

559577
static int set_partition_arguments(unsigned int type, void *val)
@@ -635,6 +653,8 @@ static int set_partition_arguments(unsigned int type, void *val)
635653

636654
static int partition_init(ds_db_head_t *db_head, ds_partition_t *partition)
637655
{
656+
LM_DBG("initializing partition <%.*s>\n",
657+
db_head->partition_name.len, db_head->partition_name.s);
638658

639659
/* Load stuff from DB. URL cannot be null!*/
640660
if (db_head->db_url.s == NULL){
@@ -759,18 +779,18 @@ static int partition_init(ds_db_head_t *db_head, ds_partition_t *partition)
759779
if (pkg_str_dup(&partition->ping_method, &db_head->ping_method) < 0)
760780
LM_ERR("cannot duplicate ping_method\n");
761781
}
762-
partition->persistent_state = ds_persistent_state;
763-
if (str_strcmp(&db_head->persistent_state, const_str("0")) == 0 ||
764-
str_strcmp(&db_head->persistent_state, const_str("no")) == 0 ||
765-
str_strcmp(&db_head->persistent_state, const_str("off")) == 0)
782+
if (str_strcmp(&db_head->persistent_state, const_str("0")) == 0 ||
783+
str_strcmp(&db_head->persistent_state, const_str("no")) == 0 ||
784+
str_strcmp(&db_head->persistent_state, const_str("off")) == 0)
766785
partition->persistent_state = 0;
767-
else if (str_strcmp(&db_head->persistent_state, const_str("1")) == 0 ||
768-
str_strcmp(&db_head->persistent_state, const_str("yes")) == 0 ||
769-
str_strcmp(&db_head->persistent_state, const_str("on")) == 0)
786+
else if (str_strcmp(&db_head->persistent_state, const_str("1")) == 0 ||
787+
str_strcmp(&db_head->persistent_state, const_str("yes")) == 0 ||
788+
str_strcmp(&db_head->persistent_state, const_str("on")) == 0)
770789
partition->persistent_state = 1;
771790

772791
if (partition->persistent_state)
773792
ds_persistent_state_enable = 1;
793+
774794
return 0;
775795
}
776796

@@ -1025,6 +1045,10 @@ static int mod_init(void)
10251045

10261046
}
10271047

1048+
LM_DBG("options are fetch_freeswitch_stats=%d, "
1049+
"ds_persistent_state_enable=%d\n",
1050+
fetch_freeswitch_stats, ds_persistent_state_enable);
1051+
10281052
/* Register the weight-recalculation timer */
10291053
if (fetch_freeswitch_stats &&
10301054
register_timer("ds-update-weights", ds_update_weights, NULL,

0 commit comments

Comments
 (0)