diff --git a/modules/dispatcher/dispatch.c b/modules/dispatcher/dispatch.c index 3638a9c8f8a..6921aaed7e4 100644 --- a/modules/dispatcher/dispatch.c +++ b/modules/dispatcher/dispatch.c @@ -70,6 +70,7 @@ static int _ds_table_version = DS_TABLE_VERSION; static ds_ht_t *_dsht_load = NULL; +static int *_ds_ping_active = NULL; extern int ds_force_dst; @@ -91,6 +92,43 @@ void destroy_list(int); void shuffle_uint100array(unsigned int* arr); int ds_reinit_rweight_on_state_change(int old_state, int new_state, ds_set_t *dset); +/** + * + */ +int ds_ping_active_init(void) +{ + if(_ds_ping_active!=NULL) + return 0; + _ds_ping_active = (int*)shm_malloc(sizeof(int)); + if(_ds_ping_active==NULL) { + LM_ERR("no more shared memory\n"); + return -1; + } + *_ds_ping_active = 1; + return 0; +} + +/** + * + */ +int ds_ping_active_get(void) +{ + if(_ds_ping_active!=NULL) + return -1; + return *_ds_ping_active; +} + +/** + * + */ +int ds_ping_active_set(int v) +{ + if(_ds_ping_active!=NULL) + return -1; + *_ds_ping_active = v; + return 0; +} + /** * */ @@ -2812,6 +2850,11 @@ void ds_check_timer(unsigned int ticks, void* param) return; } + if(_ds_ping_active!=NULL && *_ds_ping_active==0) + { + LM_DBG("pinging destinations is inactive by admin\n"); + return; + } /* Iterate over the groups and the entries of each group: */ for(list = _ds_list; list!= NULL; list= list->next) { diff --git a/modules/dispatcher/dispatch.h b/modules/dispatcher/dispatch.h index 56da6c78db1..856a88ec59c 100644 --- a/modules/dispatcher/dispatch.h +++ b/modules/dispatcher/dispatch.h @@ -183,5 +183,10 @@ typedef struct _ds_set ds_set_t *ds_get_list(void); int ds_get_list_nr(void); + +int ds_ping_active_init(void); +int ds_ping_active_get(void); +int ds_ping_active_set(int v); + #endif diff --git a/modules/dispatcher/dispatcher.c b/modules/dispatcher/dispatcher.c index f960297fb48..51d1955bc74 100644 --- a/modules/dispatcher/dispatcher.c +++ b/modules/dispatcher/dispatcher.c @@ -286,6 +286,10 @@ static int mod_init(void) LM_ERR("failed to register MI commands\n"); return -1; } + if(ds_ping_active_init()<0) { + return -1; + } + if(ds_init_rpc()<0) { LM_ERR("failed to register RPC commands\n"); @@ -1318,6 +1322,54 @@ static void dispatcher_rpc_set_state(rpc_t* rpc, void* ctx) } +static const char* dispatcher_rpc_ping_active_doc[2] = { + "Manage setting on/off the pinging (keepalive) of destinations", + 0 +}; + + +/* + * RPC command to set the state of a destination address + */ +static void dispatcher_rpc_ping_active(rpc_t* rpc, void* ctx) +{ + int state; + int ostate; + void *th; + + if(rpc->scan(ctx, "*d", &state)!=1) { + state = -1; + } + ostate = ds_ping_active_get(); + /* add entry node */ + if (rpc->add(ctx, "{", &th) < 0) { + rpc->fault(ctx, 500, "Internal error root reply"); + return; + } + if(state==-1) { + if(rpc->struct_add(th, "d", + "OldPingState", ostate)<0) + { + rpc->fault(ctx, 500, "Internal error reply structure"); + return; + } + return; + } + + if(ds_ping_active_set(state)<0) { + rpc->fault(ctx, 500, "Ping State Update Failed"); + return; + } + if(rpc->struct_add(th, "dd", + "NewPingState", state, + "OldPingState", ostate)<0) + { + rpc->fault(ctx, 500, "Internal error reply structure"); + return; + } + return; +} + rpc_export_t dispatcher_rpc_cmds[] = { {"dispatcher.reload", dispatcher_rpc_reload, dispatcher_rpc_reload_doc, 0}, @@ -1325,6 +1377,8 @@ rpc_export_t dispatcher_rpc_cmds[] = { dispatcher_rpc_list_doc, 0}, {"dispatcher.set_state", dispatcher_rpc_set_state, dispatcher_rpc_set_state_doc, 0}, + {"dispatcher.ping_active", dispatcher_rpc_ping_active, + dispatcher_rpc_ping_active_doc, 0}, {0, 0, 0, 0} };