Module: kamailio Branch: master Commit: 44c5d1c02e87024e075c5417838d2d33bcba35c8 URL: https://github.com/kamailio/kamailio/commit/44c5d1c02e87024e075c5417838d2d33...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2016-01-24T13:23:07+01:00
dispatcher: rpc command dispatcher.ping_active
- manage global pinging state (send or not the keepalive to destinations) - kamcmd dispatcher.ping_active 0 - don't send keepalive requests - kamcmd dispatcher.ping_active 1 - send keepalive requests - default value is 1
---
Modified: modules/dispatcher/dispatch.c Modified: modules/dispatcher/dispatch.h Modified: modules/dispatcher/dispatcher.c
---
Diff: https://github.com/kamailio/kamailio/commit/44c5d1c02e87024e075c5417838d2d33... Patch: https://github.com/kamailio/kamailio/commit/44c5d1c02e87024e075c5417838d2d33...
---
diff --git a/modules/dispatcher/dispatch.c b/modules/dispatcher/dispatch.c index 3638a9c..6921aae 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;
@@ -94,6 +95,43 @@ int ds_reinit_rweight_on_state_change(int old_state, int new_state, ds_set_t *ds /** * */ +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; +} + +/** + * + */ int ds_hash_load_init(unsigned int htsize, int expire, int initexpire) { if(_dsht_load != NULL) @@ -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 56da6c7..856a88e 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 f960297..51d1955 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} };