Browse code

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

Daniel-Constantin Mierla authored on 24/01/2016 12:23:07
Showing 3 changed files
... ...
@@ -70,6 +70,7 @@ static int _ds_table_version = DS_TABLE_VERSION;
70 70
 
71 71
 static ds_ht_t *_dsht_load = NULL;
72 72
 
73
+static int *_ds_ping_active = NULL;
73 74
 
74 75
 extern int ds_force_dst;
75 76
 
... ...
@@ -91,6 +92,43 @@ void destroy_list(int);
91 92
 void shuffle_uint100array(unsigned int* arr);
92 93
 int ds_reinit_rweight_on_state_change(int old_state, int new_state, ds_set_t *dset);
93 94
 
95
+/**
96
+ *
97
+ */
98
+int ds_ping_active_init(void)
99
+{
100
+	if(_ds_ping_active!=NULL)
101
+		return 0;
102
+	_ds_ping_active = (int*)shm_malloc(sizeof(int));
103
+	if(_ds_ping_active==NULL) {
104
+		LM_ERR("no more shared memory\n");
105
+		return -1;
106
+	}
107
+	*_ds_ping_active = 1;
108
+	return 0;
109
+}
110
+
111
+/**
112
+ *
113
+ */
114
+int ds_ping_active_get(void)
115
+{
116
+	if(_ds_ping_active!=NULL)
117
+		return -1;
118
+	return *_ds_ping_active;
119
+}
120
+
121
+/**
122
+ *
123
+ */
124
+int ds_ping_active_set(int v)
125
+{
126
+	if(_ds_ping_active!=NULL)
127
+		return -1;
128
+	*_ds_ping_active = v;
129
+	return 0;
130
+}
131
+
94 132
 /**
95 133
  *
96 134
  */
... ...
@@ -2812,6 +2850,11 @@ void ds_check_timer(unsigned int ticks, void* param)
2812 2850
 		return;
2813 2851
 	}
2814 2852
 
2853
+	if(_ds_ping_active!=NULL && *_ds_ping_active==0)
2854
+	{
2855
+		LM_DBG("pinging destinations is inactive by admin\n");
2856
+		return;
2857
+	}
2815 2858
 	/* Iterate over the groups and the entries of each group: */
2816 2859
 	for(list = _ds_list; list!= NULL; list= list->next)
2817 2860
 	{
... ...
@@ -183,5 +183,10 @@ typedef struct _ds_set
183 183
 
184 184
 ds_set_t *ds_get_list(void);
185 185
 int ds_get_list_nr(void);
186
+
187
+int ds_ping_active_init(void);
188
+int ds_ping_active_get(void);
189
+int ds_ping_active_set(int v);
190
+
186 191
 #endif
187 192
 
... ...
@@ -286,6 +286,10 @@ static int mod_init(void)
286 286
 		LM_ERR("failed to register MI commands\n");
287 287
 		return -1;
288 288
 	}
289
+	if(ds_ping_active_init()<0) {
290
+		return -1;
291
+	}
292
+
289 293
 	if(ds_init_rpc()<0)
290 294
 	{
291 295
 		LM_ERR("failed to register RPC commands\n");
... ...
@@ -1318,6 +1322,54 @@ static void dispatcher_rpc_set_state(rpc_t* rpc, void* ctx)
1318 1322
 }
1319 1323
 
1320 1324
 
1325
+static const char* dispatcher_rpc_ping_active_doc[2] = {
1326
+	"Manage setting on/off the pinging (keepalive) of destinations",
1327
+	0
1328
+};
1329
+
1330
+
1331
+/*
1332
+ * RPC command to set the state of a destination address
1333
+ */
1334
+static void dispatcher_rpc_ping_active(rpc_t* rpc, void* ctx)
1335
+{
1336
+	int state;
1337
+	int ostate;
1338
+	void *th;
1339
+
1340
+	if(rpc->scan(ctx, "*d", &state)!=1) {
1341
+		state = -1;
1342
+	}
1343
+	ostate = ds_ping_active_get();
1344
+	/* add entry node */
1345
+	if (rpc->add(ctx, "{", &th) < 0) {
1346
+		rpc->fault(ctx, 500, "Internal error root reply");
1347
+		return;
1348
+	}
1349
+	if(state==-1) {
1350
+		if(rpc->struct_add(th, "d",
1351
+				"OldPingState", ostate)<0)
1352
+		{
1353
+			rpc->fault(ctx, 500, "Internal error reply structure");
1354
+			return;
1355
+		}
1356
+		return;
1357
+	}
1358
+
1359
+	if(ds_ping_active_set(state)<0) {
1360
+		rpc->fault(ctx, 500, "Ping State Update Failed");
1361
+		return;
1362
+	}
1363
+	if(rpc->struct_add(th, "dd",
1364
+				"NewPingState", state,
1365
+				"OldPingState", ostate)<0)
1366
+	{
1367
+		rpc->fault(ctx, 500, "Internal error reply structure");
1368
+		return;
1369
+	}
1370
+	return;
1371
+}
1372
+
1321 1373
 rpc_export_t dispatcher_rpc_cmds[] = {
1322 1374
 	{"dispatcher.reload", dispatcher_rpc_reload,
1323 1375
 		dispatcher_rpc_reload_doc, 0},
... ...
@@ -1325,6 +1377,8 @@ rpc_export_t dispatcher_rpc_cmds[] = {
1325 1377
 		dispatcher_rpc_list_doc,   0},
1326 1378
 	{"dispatcher.set_state",   dispatcher_rpc_set_state,
1327 1379
 		dispatcher_rpc_set_state_doc,   0},
1380
+	{"dispatcher.ping_active",   dispatcher_rpc_ping_active,
1381
+		dispatcher_rpc_ping_active_doc, 0},
1328 1382
 	{0, 0, 0, 0}
1329 1383
 };
1330 1384