Browse code

core, lib, modules: restructured source code tree

- new folder src/ to hold the source code for main project applications
- main.c is in src/
- all core files are subfolder are in src/core/
- modules are in src/modules/
- libs are in src/lib/
- application Makefiles are in src/
- application binary is built in src/ (src/kamailio)

Daniel-Constantin Mierla authored on 07/12/2016 11:03:51
Showing 1 changed files
1 1
deleted file mode 100644
... ...
@@ -1,687 +0,0 @@
1
-/*
2
- * pipelimit module
3
- *
4
- * Copyright (C) 2006 Hendrik Scholz <hscholz@raisdorf.net>
5
- * Copyright (C) 2008 Ovidiu Sas <osas@voipembedded.com>
6
- * Copyright (C) 2009 Daniel-Constantin Mierla (asipto.com)
7
- *
8
- * This file is part of Kamailio, a free SIP server.
9
- *
10
- * Kamailio is free software; you can redistribute it and/or modify
11
- * it under the terms of the GNU General Public License as published by
12
- * the Free Software Foundation; either version 2 of the License, or
13
- * (at your option) any later version
14
- *
15
- * Kamailio is distributed in the hope that it will be useful,
16
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
- * GNU General Public License for more details.
19
- *
20
- * You should have received a copy of the GNU General Public License 
21
- * along with this program; if not, write to the Free Software 
22
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
23
- */
24
-
25
-/*! \file
26
- * \ingroup pipelimit
27
- * \brief pipelimit :: pl_ht
28
- */
29
-
30
-#include <stdio.h>
31
-#include <string.h>
32
-#include <stdlib.h>
33
-
34
-#include "../../dprint.h"
35
-#include "../../ut.h"
36
-#include "../../str.h"
37
-#include "../../hashes.h"
38
-#include "../../mem/shm_mem.h"
39
-#include "../../lib/kmi/mi.h"
40
-#include "../../rpc_lookup.h"
41
-
42
-#include "pl_ht.h"
43
-
44
-static rlp_htable_t *_pl_pipes_ht = NULL;
45
-
46
-str_map_t algo_names[] = {
47
-	{str_init("NOP"),	PIPE_ALGO_NOP},
48
-	{str_init("RED"),	PIPE_ALGO_RED},
49
-	{str_init("TAILDROP"),	PIPE_ALGO_TAILDROP},
50
-	{str_init("FEEDBACK"),	PIPE_ALGO_FEEDBACK},
51
-	{str_init("NETWORK"),	PIPE_ALGO_NETWORK},
52
-	{{0, 0},		0},
53
-};
54
-
55
-
56
-int pl_init_htable(unsigned int hsize)
57
-{
58
-	int i;
59
-
60
-	if(_pl_pipes_ht!=NULL)
61
-		return -1;
62
-
63
-	_pl_pipes_ht = (rlp_htable_t*)shm_malloc(sizeof(rlp_htable_t));
64
-	if(_pl_pipes_ht==NULL)
65
-	{
66
-		LM_ERR("no more shm\n");
67
-		return -1;
68
-	}
69
-	memset(_pl_pipes_ht, 0, sizeof(rlp_htable_t));
70
-	_pl_pipes_ht->htsize = hsize;
71
-
72
-	_pl_pipes_ht->slots =
73
-			(rlp_slot_t*)shm_malloc(_pl_pipes_ht->htsize*sizeof(rlp_slot_t));
74
-	if(_pl_pipes_ht->slots==NULL)
75
-	{
76
-		LM_ERR("no more shm.\n");
77
-		shm_free(_pl_pipes_ht);
78
-		return -1;
79
-	}
80
-	memset(_pl_pipes_ht->slots, 0, _pl_pipes_ht->htsize*sizeof(rlp_slot_t));
81
-
82
-	for(i=0; i<_pl_pipes_ht->htsize; i++)
83
-	{
84
-		if(lock_init(&_pl_pipes_ht->slots[i].lock)==0)
85
-		{
86
-			LM_ERR("cannot initialize lock[%d]\n", i);
87
-			i--;
88
-			while(i>=0)
89
-			{
90
-				lock_destroy(&_pl_pipes_ht->slots[i].lock);
91
-				i--;
92
-			}
93
-			shm_free(_pl_pipes_ht->slots);
94
-			shm_free(_pl_pipes_ht);
95
-			return -1;
96
-
97
-		}
98
-	}
99
-
100
-	return 0;
101
-}
102
-
103
-
104
-void pl_pipe_free(pl_pipe_t *it)
105
-{
106
-	return;
107
-}
108
-
109
-int pl_destroy_htable(void)
110
-{
111
-	int i;
112
-	pl_pipe_t *it;
113
-	pl_pipe_t *it0;
114
-
115
-	if(_pl_pipes_ht==NULL)
116
-		return -1;
117
-
118
-	for(i=0; i<_pl_pipes_ht->htsize; i++)
119
-	{
120
-		/* free entries */
121
-		it = _pl_pipes_ht->slots[i].first;
122
-		while(it)
123
-		{
124
-			it0 = it;
125
-			it = it->next;
126
-			pl_pipe_free(it0);
127
-		}
128
-		/* free locks */
129
-		lock_destroy(&_pl_pipes_ht->slots[i].lock);
130
-	}
131
-	shm_free(_pl_pipes_ht->slots);
132
-	shm_free(_pl_pipes_ht);
133
-	_pl_pipes_ht = NULL;
134
-	return 0;
135
-}
136
-
137
-#define pl_compute_hash(_s)        get_hash1_raw((_s)->s,(_s)->len)
138
-#define pl_get_entry(_h,_size)    (_h)&((_size)-1)
139
-
140
-int pl_pipe_add(str *pipeid, str *algorithm, int limit)
141
-{
142
-	unsigned int cellid;
143
-	unsigned int idx;
144
-	pl_pipe_t *it, *prev, *cell;
145
-	
146
-	if(_pl_pipes_ht==NULL)
147
-		return -1;
148
-
149
-	cellid = pl_compute_hash(pipeid);
150
-	idx = pl_get_entry(cellid, _pl_pipes_ht->htsize);
151
-
152
-	lock_get(&_pl_pipes_ht->slots[idx].lock);
153
-	it = _pl_pipes_ht->slots[idx].first;
154
-	prev = NULL;
155
-	while(it!=NULL && it->cellid < cellid)
156
-	{
157
-		prev = it;
158
-		it = it->next;
159
-	}
160
-	while(it!=NULL && it->cellid == cellid)
161
-	{
162
-		if(pipeid->len==it->name.len 
163
-				&& strncmp(pipeid->s, it->name.s, pipeid->len)==0)
164
-		{
165
-			 lock_release(&_pl_pipes_ht->slots[idx].lock);
166
-			 return 1;
167
-		}
168
-		prev = it;
169
-		it = it->next;
170
-	}
171
-
172
-	cell =
173
-		(pl_pipe_t*)shm_malloc(sizeof(pl_pipe_t)+(1+pipeid->len)*sizeof(char));
174
-	if(cell == NULL)
175
-	{
176
-		lock_release(&_pl_pipes_ht->slots[idx].lock);
177
-		LM_ERR("cannot create new cell.\n");
178
-		return -1;
179
-	}
180
-	memset(cell, 0, sizeof(pl_pipe_t)+(1+pipeid->len)*sizeof(char));
181
-	
182
-	cell->name.s = (char*)cell + sizeof(pl_pipe_t);
183
-	strncpy(cell->name.s, pipeid->s, pipeid->len);
184
-	cell->name.len = pipeid->len;
185
-	cell->name.s[cell->name.len] = '\0';
186
-	cell->cellid = cellid;
187
-	cell->limit = limit;
188
-	if (str_map_str(algo_names, algorithm, &cell->algo))
189
-	{
190
-		lock_release(&_pl_pipes_ht->slots[idx].lock);
191
-		shm_free(cell);
192
-		LM_ERR("cannot find algorithm [%.*s].\n", algorithm->len,
193
-				algorithm->s);
194
-		return -1;
195
-	}
196
-
197
-	if(prev==NULL)
198
-	{
199
-		if(_pl_pipes_ht->slots[idx].first!=NULL)
200
-		{
201
-			cell->next = _pl_pipes_ht->slots[idx].first;
202
-			_pl_pipes_ht->slots[idx].first->prev = cell;
203
-		}
204
-		_pl_pipes_ht->slots[idx].first = cell;
205
-	} else {
206
-		cell->next = prev->next;
207
-		cell->prev = prev;
208
-		if(prev->next)
209
-			prev->next->prev = cell;
210
-		prev->next = cell;
211
-	}
212
-	_pl_pipes_ht->slots[idx].ssize++;
213
-	lock_release(&_pl_pipes_ht->slots[idx].lock);
214
-
215
-	return 0;
216
-}
217
-
218
-pl_pipe_t* pl_pipe_get(str *pipeid, int mode)
219
-{
220
-	unsigned int cellid;
221
-	unsigned int idx;
222
-	pl_pipe_t *it;
223
-	
224
-	if(_pl_pipes_ht==NULL)
225
-		return NULL;
226
-
227
-	cellid = pl_compute_hash(pipeid);
228
-	idx = pl_get_entry(cellid, _pl_pipes_ht->htsize);
229
-
230
-	lock_get(&_pl_pipes_ht->slots[idx].lock);
231
-	it = _pl_pipes_ht->slots[idx].first;
232
-	while(it!=NULL && it->cellid < cellid)
233
-	{
234
-		it = it->next;
235
-	}
236
-	while(it!=NULL && it->cellid == cellid)
237
-	{
238
-		if(pipeid->len==it->name.len 
239
-				&& strncmp(pipeid->s, it->name.s, pipeid->len)==0)
240
-		{
241
-			 if(mode==0) lock_release(&_pl_pipes_ht->slots[idx].lock);
242
-			 return it;
243
-		}
244
-		it = it->next;
245
-	}
246
-	lock_release(&_pl_pipes_ht->slots[idx].lock);
247
-	return NULL;
248
-}
249
-
250
-void pl_pipe_release(str *pipeid)
251
-{
252
-	unsigned int cellid;
253
-	unsigned int idx;
254
-
255
-	if(_pl_pipes_ht==NULL)
256
-		return;
257
-
258
-	cellid = pl_compute_hash(pipeid);
259
-	idx = pl_get_entry(cellid, _pl_pipes_ht->htsize);
260
-
261
-	lock_release(&_pl_pipes_ht->slots[idx].lock);
262
-}
263
-
264
-
265
-int pl_print_pipes(void)
266
-{
267
-	int i;
268
-	pl_pipe_t *it;
269
-
270
-	if(_pl_pipes_ht==NULL)
271
-		return -1;
272
-
273
-	for(i=0; i<_pl_pipes_ht->htsize; i++)
274
-	{
275
-		lock_get(&_pl_pipes_ht->slots[i].lock);
276
-		it = _pl_pipes_ht->slots[i].first;
277
-		while(it)
278
-		{
279
-			LM_DBG("+++ pipe: %.*s [%u/%d]\n", it->name.len, it->name.s,
280
-					it->cellid, i);
281
-			LM_DBG("+++ ++++ algo: %d\n", it->algo);
282
-			LM_DBG("+++ ++++ limit: %d\n", it->limit);
283
-			LM_DBG("+++ ++++ counter: %d\n", it->counter);
284
-			LM_DBG("+++ ++++ last_counter: %d\n", it->last_counter);
285
-			LM_DBG("+++ ++++ load: %d\n", it->load);
286
-			it = it->next;
287
-		}
288
-		lock_release(&_pl_pipes_ht->slots[i].lock);
289
-	}
290
-	return 0;
291
-}
292
-
293
-int pl_pipe_check_feedback_setpoints(int *cfgsp)
294
-{
295
-	int i, sp;
296
-	pl_pipe_t *it;
297
-
298
-	if(_pl_pipes_ht==NULL)
299
-		return -1;
300
-
301
-	for(i=0; i<_pl_pipes_ht->htsize; i++)
302
-	{
303
-		lock_get(&_pl_pipes_ht->slots[i].lock);
304
-		it = _pl_pipes_ht->slots[i].first;
305
-		while(it)
306
-		{
307
-			if (it->algo == PIPE_ALGO_FEEDBACK) {
308
-				sp = it->limit;
309
-
310
-				if (sp < 0 || sp > 100) {
311
-					LM_ERR("FEEDBACK cpu load must be >=0 and <= 100 [%.*s]\n",
312
-							 it->name.len, it->name.s);
313
-					lock_release(&_pl_pipes_ht->slots[i].lock);
314
-					return -1;
315
-				} else if (*cfgsp == -1) {
316
-					*cfgsp = sp;
317
-				} else if (sp != *cfgsp) {
318
-					LM_ERR("pipe %.*s: FEEDBACK cpu load values must "
319
-						"be equal for all pipes\n",  it->name.len, it->name.s);
320
-					lock_release(&_pl_pipes_ht->slots[i].lock);
321
-					return -1;
322
-				}
323
-			}
324
-			it = it->next;
325
-		}
326
-		lock_release(&_pl_pipes_ht->slots[i].lock);
327
-	}
328
-	return 0;
329
-}
330
-
331
-void pl_pipe_timer_update(int interval, int netload)
332
-{
333
-	int i;
334
-	pl_pipe_t *it;
335
-
336
-	if(_pl_pipes_ht==NULL)
337
-		return;
338
-
339
-	for(i=0; i<_pl_pipes_ht->htsize; i++)
340
-	{
341
-		lock_get(&_pl_pipes_ht->slots[i].lock);
342
-		it = _pl_pipes_ht->slots[i].first;
343
-		while(it)
344
-		{
345
-			if (it->algo != PIPE_ALGO_NOP) {
346
-				if( it->algo == PIPE_ALGO_NETWORK ) {
347
-					it->load = ( netload > it->limit ) ? 1 : -1;
348
-				} else if (it->limit && interval) {
349
-					it->load = it->counter / (it->limit * interval);
350
-				}
351
-				it->last_counter = it->counter;
352
-				it->counter = 0;
353
-			}
354
-
355
-			it = it->next;
356
-		}
357
-		lock_release(&_pl_pipes_ht->slots[i].lock);
358
-	}
359
-}
360
-
361
-extern int _pl_cfg_setpoint;
362
-extern double *_pl_pid_setpoint;
363
-
364
-/**
365
- * checks that all FEEDBACK pipes use the same setpoint 
366
- * cpu load. also sets (common) cfg_setpoint value
367
- * \param	modparam 1 to check modparam (static) fields, 0 to use shm ones
368
- *
369
- * \return	0 if ok, -1 on error
370
- */
371
-static int check_feedback_setpoints(int modparam)
372
-{
373
-	_pl_cfg_setpoint = -1;
374
-	return pl_pipe_check_feedback_setpoints(&_pl_cfg_setpoint);
375
-}
376
-
377
-
378
-/*
379
- * MI functions
380
- *
381
- * mi_stats() dumps the current config/statistics
382
- * mi_{invite|register|subscribe}() set the limits
383
- */
384
-
385
-/* mi function implementations */
386
-struct mi_root* mi_stats(struct mi_root* cmd_tree, void* param)
387
-{
388
-	struct mi_root *rpl_tree;
389
-	struct mi_node *node=NULL, *rpl=NULL;
390
-	struct mi_attr* attr;
391
-	char* p;
392
-	int i, len;
393
-	pl_pipe_t *it;
394
-
395
-	rpl_tree = init_mi_tree( 200, MI_OK_S, MI_OK_LEN);
396
-	if (rpl_tree==0)
397
-		return 0;
398
-	rpl = &rpl_tree->node;
399
-
400
-	for(i=0; i<_pl_pipes_ht->htsize; i++)
401
-	{
402
-		lock_get(&_pl_pipes_ht->slots[i].lock);
403
-		it = _pl_pipes_ht->slots[i].first;
404
-		while(it)
405
-		{
406
-			if (it->algo != PIPE_ALGO_NOP) {
407
-				node = add_mi_node_child(rpl, 0, "PIPE", 4, 0, 0);
408
-				if(node == NULL)
409
-				{
410
-					lock_release(&_pl_pipes_ht->slots[i].lock);
411
-					goto error;
412
-				}
413
-
414
-				attr = add_mi_attr(node, MI_DUP_VALUE, "id", 2, it->name.s,
415
-						it->name.len);
416
-				if(attr == NULL)
417
-				{
418
-					lock_release(&_pl_pipes_ht->slots[i].lock);
419
-					goto error;
420
-				}
421
-
422
-				p = int2str((unsigned long)(it->load), &len);
423
-				attr = add_mi_attr(node, MI_DUP_VALUE, "load", 4, p, len);
424
-				if(attr == NULL)
425
-				{
426
-					lock_release(&_pl_pipes_ht->slots[i].lock);
427
-					goto error;
428
-				}
429
-
430
-				p = int2str((unsigned long)(it->last_counter), &len);
431
-				attr = add_mi_attr(node, MI_DUP_VALUE, "counter", 7, p, len);
432
-				if(attr == NULL)
433
-				{
434
-					lock_release(&_pl_pipes_ht->slots[i].lock);
435
-					goto error;
436
-				}
437
-			}
438
-			it = it->next;
439
-		}
440
-		lock_release(&_pl_pipes_ht->slots[i].lock);
441
-	}
442
-
443
-#if 0
444
-	p = int2str((unsigned long)(*drop_rate), &len);
445
-	node = add_mi_node_child(rpl, MI_DUP_VALUE, "DROP_RATE", 9, p, len);
446
-#endif
447
-
448
-	return rpl_tree;
449
-error:
450
-	LM_ERR("Unable to create reply\n");
451
-	free_mi_tree(rpl_tree); 
452
-	return 0;
453
-}
454
-
455
-struct mi_root* mi_get_pipes(struct mi_root* cmd_tree, void* param)
456
-{
457
-	struct mi_root *rpl_tree;
458
-	struct mi_node *node=NULL, *rpl=NULL;
459
-	struct mi_attr* attr;
460
-	str algo;
461
-	char* p;
462
-	int i, len;
463
-	pl_pipe_t *it;
464
-
465
-	rpl_tree = init_mi_tree( 200, MI_OK_S, MI_OK_LEN);
466
-	if (rpl_tree==0)
467
-		return 0;
468
-	rpl = &rpl_tree->node;
469
-
470
-	for(i=0; i<_pl_pipes_ht->htsize; i++)
471
-	{
472
-		lock_get(&_pl_pipes_ht->slots[i].lock);
473
-		it = _pl_pipes_ht->slots[i].first;
474
-		while(it)
475
-		{
476
-			if (it->algo != PIPE_ALGO_NOP) {
477
-				node = add_mi_node_child(rpl, 0, "PIPE", 4, 0, 0);
478
-				if(node == NULL)
479
-				{
480
-					lock_release(&_pl_pipes_ht->slots[i].lock);
481
-					goto error;
482
-				}
483
-
484
-				attr = add_mi_attr(node, MI_DUP_VALUE, "id" , 2, it->name.s,
485
-						it->name.len);
486
-				if(attr == NULL)
487
-				{
488
-					lock_release(&_pl_pipes_ht->slots[i].lock);
489
-					goto error;
490
-				}
491
-
492
-				if (str_map_int(algo_names, it->algo, &algo))
493
-				{
494
-					lock_release(&_pl_pipes_ht->slots[i].lock);
495
-					goto error;
496
-				}
497
-				attr = add_mi_attr(node, 0, "algorithm", 9, algo.s, algo.len);
498
-				if(attr == NULL)
499
-				{
500
-					lock_release(&_pl_pipes_ht->slots[i].lock);
501
-					goto error;
502
-				}
503
-
504
-				p = int2str((unsigned long)(it->limit), &len);
505
-				attr = add_mi_attr(node, MI_DUP_VALUE, "limit", 5, p, len);
506
-				if(attr == NULL)
507
-				{
508
-					lock_release(&_pl_pipes_ht->slots[i].lock);
509
-					goto error;
510
-				}
511
-
512
-				p = int2str((unsigned long)(it->counter), &len);
513
-				attr = add_mi_attr(node, MI_DUP_VALUE, "counter", 7, p, len);
514
-				if(attr == NULL)
515
-				{
516
-					lock_release(&_pl_pipes_ht->slots[i].lock);
517
-					goto error;
518
-				}
519
-			}
520
-			it = it->next;
521
-		}
522
-		lock_release(&_pl_pipes_ht->slots[i].lock);
523
-	}
524
-	return rpl_tree;
525
-error:
526
-	LM_ERR("Unable to create reply\n");
527
-	free_mi_tree(rpl_tree); 
528
-	return 0;
529
-}
530
-
531
-struct mi_root* mi_set_pipe(struct mi_root* cmd_tree, void* param)
532
-{
533
-	struct mi_node *node;
534
-	unsigned int algo_id, limit = 0;
535
-	pl_pipe_t *it;
536
-	str pipeid;
537
-
538
-	node = cmd_tree->node.kids;
539
-	if (node == NULL)
540
-		return init_mi_tree( 400, MI_MISSING_PARM_S, MI_MISSING_PARM_LEN);
541
-	if ( !node->value.s || !node->value.len)
542
-		goto error;
543
-	pipeid = node->value;
544
-	
545
-	node = node->next;
546
-	if ( !node || !node->value.s || !node->value.len)
547
-		goto error;
548
-	if (str_map_str(algo_names, &(node->value), (int*)&algo_id)) {
549
-		LM_ERR("unknown algorithm: '%.*s'\n", node->value.len, node->value.s);
550
-		goto error;
551
-	}
552
-	
553
-	node = node->next;
554
-	if ( !node || !node->value.s || !node->value.len || strno2int(&node->value,&limit)<0)
555
-		goto error;
556
-
557
-	LM_DBG("set_pipe: %.*s:%d:%d\n", pipeid.len, pipeid.s, algo_id, limit);
558
-
559
-	it = pl_pipe_get(&pipeid, 1);
560
-	if (it==NULL) {
561
-		LM_ERR("no pipe: %.*s\n", pipeid.len, pipeid.s);
562
-		goto error;
563
-	}
564
-
565
-	it->algo = algo_id;
566
-	it->limit = limit;
567
-
568
-	pl_pipe_release(&pipeid);
569
-
570
-	if (check_feedback_setpoints(0)) {
571
-		LM_ERR("feedback limits don't match\n");
572
-		goto error;
573
-	} else {
574
-		*_pl_pid_setpoint = 0.01 * (double)_pl_cfg_setpoint;
575
-	}
576
-
577
-	return init_mi_tree( 200, MI_OK_S, MI_OK_LEN);
578
-error:
579
-	return init_mi_tree( 400, MI_BAD_PARM_S, MI_BAD_PARM_LEN);
580
-}
581
-
582
-void rpl_pipe_lock(int slot)
583
-{
584
-	lock_get(&_pl_pipes_ht->slots[slot].lock);
585
-}
586
-
587
-void rpl_pipe_release(int slot)
588
-{
589
-	lock_release(&_pl_pipes_ht->slots[slot].lock);
590
-}
591
-
592
-
593
-/* rpc function implementations */
594
-void rpc_pl_stats(rpc_t *rpc, void *c)
595
-{
596
-	int i;
597
-	pl_pipe_t *it;
598
-
599
-	for(i=0; i<_pl_pipes_ht->htsize; i++)
600
-	{
601
-		lock_get(&_pl_pipes_ht->slots[i].lock);
602
-		it = _pl_pipes_ht->slots[i].first;
603
-		while(it)
604
-		{
605
-			if (it->algo != PIPE_ALGO_NOP) {
606
-				if (rpc->rpl_printf(c, "PIPE: id=%.*s load=%d counter=%d",
607
-					it->name.len, it->name.s,
608
-					it->load, it->last_counter) < 0)
609
-				{
610
-					lock_release(&_pl_pipes_ht->slots[i].lock);
611
-					return;
612
-				}
613
-			}
614
-			it = it->next;
615
-		}
616
-		lock_release(&_pl_pipes_ht->slots[i].lock);
617
-	}
618
-}
619
-
620
-void rpc_pl_get_pipes(rpc_t *rpc, void *c)
621
-{
622
-	int i;
623
-	str algo;
624
-	pl_pipe_t *it;
625
-
626
-	for(i=0; i<_pl_pipes_ht->htsize; i++)
627
-	{
628
-		lock_get(&_pl_pipes_ht->slots[i].lock);
629
-		it = _pl_pipes_ht->slots[i].first;
630
-		while(it)
631
-		{
632
-			if (it->algo != PIPE_ALGO_NOP) {
633
-				if (str_map_int(algo_names, it->algo, &algo))
634
-				{
635
-					lock_release(&_pl_pipes_ht->slots[i].lock);
636
-					return;
637
-				}
638
-				if (rpc->rpl_printf(c, "PIPE: id=%.*s algorithm=%.*s limit=%d counter=%d",
639
-					it->name.len, it->name.s, algo.len, algo.s,
640
-					it->limit, it->counter) < 0)
641
-				{
642
-					lock_release(&_pl_pipes_ht->slots[i].lock);
643
-					return;
644
-				}
645
-			}
646
-			it = it->next;
647
-		}
648
-		lock_release(&_pl_pipes_ht->slots[i].lock);
649
-	}
650
-}
651
-
652
-void rpc_pl_set_pipe(rpc_t *rpc, void *c)
653
-{
654
-	unsigned int algo_id, limit = 0;
655
-	pl_pipe_t *it;
656
-	str pipeid, algo_str;
657
-
658
-	if (rpc->scan(c, "SSd", &pipeid, &algo_str, &limit) < 3) return;
659
-
660
-	if (str_map_str(algo_names, &algo_str, (int*)&algo_id)) {
661
-		LM_ERR("unknown algorithm: '%.*s'\n", algo_str.len, algo_str.s);
662
-		rpc->fault(c, 400, "Unknown algorithm");
663
-		return;
664
-	}
665
-
666
-	LM_DBG("set_pipe: %.*s:%d:%d\n", pipeid.len, pipeid.s, algo_id, limit);
667
-
668
-	it = pl_pipe_get(&pipeid, 1);
669
-	if (it==NULL) {
670
-		LM_ERR("no pipe: %.*s\n", pipeid.len, pipeid.s);
671
-		rpc->fault(c, 400, "Unknown pipe id %.*s", pipeid.len, pipeid.s);
672
-		return;
673
-	}
674
-
675
-	it->algo = algo_id;
676
-	it->limit = limit;
677
-	pl_pipe_release(&pipeid);
678
-
679
-	if (check_feedback_setpoints(0)) {
680
-		LM_ERR("feedback limits don't match\n");
681
-		rpc->fault(c, 400, "Feedback limits don't match");
682
-		return;
683
-	} else {
684
-		*_pl_pid_setpoint = 0.01 * (double)_pl_cfg_setpoint;
685
-	}
686
-}
687
-
Browse code

pipelimit: fix spelling error

Victor Seva authored on 29/05/2015 10:46:42
Showing 1 changed files
... ...
@@ -83,7 +83,7 @@ int pl_init_htable(unsigned int hsize)
83 83
 	{
84 84
 		if(lock_init(&_pl_pipes_ht->slots[i].lock)==0)
85 85
 		{
86
-			LM_ERR("cannot initalize lock[%d]\n", i);
86
+			LM_ERR("cannot initialize lock[%d]\n", i);
87 87
 			i--;
88 88
 			while(i>=0)
89 89
 			{
Browse code

pipelimit Remove SVN ID and fix doxygen

Olle E. Johansson authored on 11/01/2015 13:53:12
Showing 1 changed files
... ...
@@ -1,6 +1,4 @@
1 1
 /*
2
- * $Id$
3
- *
4 2
  * pipelimit module
5 3
  *
6 4
  * Copyright (C) 2006 Hendrik Scholz <hscholz@raisdorf.net>
Browse code

pipelimit: fix dynamic pipe limit check

- proper add and check at the same time

Daniel-Constantin Mierla authored on 17/10/2014 07:40:33
Showing 1 changed files
... ...
@@ -240,7 +240,7 @@ pl_pipe_t* pl_pipe_get(str *pipeid, int mode)
240 240
 		if(pipeid->len==it->name.len 
241 241
 				&& strncmp(pipeid->s, it->name.s, pipeid->len)==0)
242 242
 		{
243
-			 /* lock_release(&_pl_pipes_ht->slots[idx].lock);*/
243
+			 if(mode==0) lock_release(&_pl_pipes_ht->slots[idx].lock);
244 244
 			 return it;
245 245
 		}
246 246
 		it = it->next;
Browse code

pipelimit: rpc commands updated to use rpl_printf()

Daniel-Constantin Mierla authored on 01/09/2014 17:24:55
Showing 1 changed files
... ...
@@ -605,7 +605,7 @@ void rpc_pl_stats(rpc_t *rpc, void *c)
605 605
 		while(it)
606 606
 		{
607 607
 			if (it->algo != PIPE_ALGO_NOP) {
608
-				if (rpc->printf(c, "PIPE: id=%.*s load=%d counter=%d",
608
+				if (rpc->rpl_printf(c, "PIPE: id=%.*s load=%d counter=%d",
609 609
 					it->name.len, it->name.s,
610 610
 					it->load, it->last_counter) < 0)
611 611
 				{
... ...
@@ -637,7 +637,7 @@ void rpc_pl_get_pipes(rpc_t *rpc, void *c)
637 637
 					lock_release(&_pl_pipes_ht->slots[i].lock);
638 638
 					return;
639 639
 				}
640
-				if (rpc->printf(c, "PIPE: id=%.*s algorithm=%.*s limit=%d counter=%d",
640
+				if (rpc->rpl_printf(c, "PIPE: id=%.*s algorithm=%.*s limit=%d counter=%d",
641 641
 					it->name.len, it->name.s, algo.len, algo.s,
642 642
 					it->limit, it->counter) < 0)
643 643
 				{
Browse code

all: updated FSF address in GPL text

Anthony Messina authored on 04/07/2014 09:36:37 • Daniel-Constantin Mierla committed on 04/07/2014 09:37:36
Showing 1 changed files
... ...
@@ -21,7 +21,7 @@
21 21
  *
22 22
  * You should have received a copy of the GNU General Public License 
23 23
  * along with this program; if not, write to the Free Software 
24
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
25 25
  */
26 26
 
27 27
 /*! \file
Browse code

pipelimit: moved log messages out of lock

- free allocated cell if the algorithm is invalid

Daniel-Constantin Mierla authored on 29/04/2014 19:59:53
Showing 1 changed files
... ...
@@ -175,8 +175,8 @@ int pl_pipe_add(str *pipeid, str *algorithm, int limit)
175 175
 		(pl_pipe_t*)shm_malloc(sizeof(pl_pipe_t)+(1+pipeid->len)*sizeof(char));
176 176
 	if(cell == NULL)
177 177
 	{
178
-		LM_ERR("cannot create new cell.\n");
179 178
 		lock_release(&_pl_pipes_ht->slots[idx].lock);
179
+		LM_ERR("cannot create new cell.\n");
180 180
 		return -1;
181 181
 	}
182 182
 	memset(cell, 0, sizeof(pl_pipe_t)+(1+pipeid->len)*sizeof(char));
... ...
@@ -189,9 +189,10 @@ int pl_pipe_add(str *pipeid, str *algorithm, int limit)
189 189
 	cell->limit = limit;
190 190
 	if (str_map_str(algo_names, algorithm, &cell->algo))
191 191
 	{
192
+		lock_release(&_pl_pipes_ht->slots[idx].lock);
193
+		shm_free(cell);
192 194
 		LM_ERR("cannot find algorithm [%.*s].\n", algorithm->len,
193 195
 				algorithm->s);
194
-		lock_release(&_pl_pipes_ht->slots[idx].lock);
195 196
 		return -1;
196 197
 	}
197 198
 
Browse code

pipelimit: avoid double locking when changing pipe via rpc

Daniel-Constantin Mierla authored on 11/07/2013 12:36:02
Showing 1 changed files
... ...
@@ -675,16 +675,14 @@ void rpc_pl_set_pipe(rpc_t *rpc, void *c)
675 675
 
676 676
 	it->algo = algo_id;
677 677
 	it->limit = limit;
678
+	pl_pipe_release(&pipeid);
678 679
 
679 680
 	if (check_feedback_setpoints(0)) {
680
-		pl_pipe_release(&pipeid);
681 681
 		LM_ERR("feedback limits don't match\n");
682 682
 		rpc->fault(c, 400, "Feedback limits don't match");
683 683
 		return;
684 684
 	} else {
685 685
 		*_pl_pid_setpoint = 0.01 * (double)_pl_cfg_setpoint;
686 686
 	}
687
-
688
-	pl_pipe_release(&pipeid);
689 687
 }
690 688
 
Browse code

pipelimit: avoid double locking when changing pipe via mi

- reported by Krischan Udelhoven, FS#315

Daniel-Constantin Mierla authored on 11/07/2013 12:32:48
Showing 1 changed files
... ...
@@ -566,16 +566,15 @@ struct mi_root* mi_set_pipe(struct mi_root* cmd_tree, void* param)
566 566
 	it->algo = algo_id;
567 567
 	it->limit = limit;
568 568
 
569
+	pl_pipe_release(&pipeid);
570
+
569 571
 	if (check_feedback_setpoints(0)) {
570
-		pl_pipe_release(&pipeid);
571 572
 		LM_ERR("feedback limits don't match\n");
572 573
 		goto error;
573 574
 	} else {
574 575
 		*_pl_pid_setpoint = 0.01 * (double)_pl_cfg_setpoint;
575 576
 	}
576 577
 
577
-	pl_pipe_release(&pipeid);
578
-
579 578
 	return init_mi_tree( 200, MI_OK_S, MI_OK_LEN);
580 579
 error:
581 580
 	return init_mi_tree( 400, MI_BAD_PARM_S, MI_BAD_PARM_LEN);
Browse code

modules/pipelimit: check correctly for all arguments in mi_set_pipe

Vicente Hernando authored on 10/04/2013 11:55:57
Showing 1 changed files
... ...
@@ -544,7 +544,7 @@ struct mi_root* mi_set_pipe(struct mi_root* cmd_tree, void* param)
544 544
 	pipeid = node->value;
545 545
 	
546 546
 	node = node->next;
547
-	if ( !node->value.s || !node->value.len)
547
+	if ( !node || !node->value.s || !node->value.len)
548 548
 		goto error;
549 549
 	if (str_map_str(algo_names, &(node->value), (int*)&algo_id)) {
550 550
 		LM_ERR("unknown algorithm: '%.*s'\n", node->value.len, node->value.s);
... ...
@@ -552,7 +552,7 @@ struct mi_root* mi_set_pipe(struct mi_root* cmd_tree, void* param)
552 552
 	}
553 553
 	
554 554
 	node = node->next;
555
-	if ( !node->value.s || !node->value.len || strno2int(&node->value,&limit)<0)
555
+	if ( !node || !node->value.s || !node->value.len || strno2int(&node->value,&limit)<0)
556 556
 		goto error;
557 557
 
558 558
 	LM_DBG("set_pipe: %.*s:%d:%d\n", pipeid.len, pipeid.s, algo_id, limit);
Browse code

pipelimit: implemented support for RPC commands

Ovidiu Sas authored on 05/01/2013 02:34:50
Showing 1 changed files
... ...
@@ -39,6 +39,7 @@
39 39
 #include "../../hashes.h"
40 40
 #include "../../mem/shm_mem.h"
41 41
 #include "../../lib/kmi/mi.h"
42
+#include "../../rpc_lookup.h"
42 43
 
43 44
 #include "pl_ht.h"
44 45
 
... ...
@@ -591,3 +592,100 @@ void rpl_pipe_release(int slot)
591 592
 }
592 593
 
593 594
 
595
+/* rpc function implementations */
596
+void rpc_pl_stats(rpc_t *rpc, void *c)
597
+{
598
+	int i;
599
+	pl_pipe_t *it;
600
+
601
+	for(i=0; i<_pl_pipes_ht->htsize; i++)
602
+	{
603
+		lock_get(&_pl_pipes_ht->slots[i].lock);
604
+		it = _pl_pipes_ht->slots[i].first;
605
+		while(it)
606
+		{
607
+			if (it->algo != PIPE_ALGO_NOP) {
608
+				if (rpc->printf(c, "PIPE: id=%.*s load=%d counter=%d",
609
+					it->name.len, it->name.s,
610
+					it->load, it->last_counter) < 0)
611
+				{
612
+					lock_release(&_pl_pipes_ht->slots[i].lock);
613
+					return;
614
+				}
615
+			}
616
+			it = it->next;
617
+		}
618
+		lock_release(&_pl_pipes_ht->slots[i].lock);
619
+	}
620
+}
621
+
622
+void rpc_pl_get_pipes(rpc_t *rpc, void *c)
623
+{
624
+	int i;
625
+	str algo;
626
+	pl_pipe_t *it;
627
+
628
+	for(i=0; i<_pl_pipes_ht->htsize; i++)
629
+	{
630
+		lock_get(&_pl_pipes_ht->slots[i].lock);
631
+		it = _pl_pipes_ht->slots[i].first;
632
+		while(it)
633
+		{
634
+			if (it->algo != PIPE_ALGO_NOP) {
635
+				if (str_map_int(algo_names, it->algo, &algo))
636
+				{
637
+					lock_release(&_pl_pipes_ht->slots[i].lock);
638
+					return;
639
+				}
640
+				if (rpc->printf(c, "PIPE: id=%.*s algorithm=%.*s limit=%d counter=%d",
641
+					it->name.len, it->name.s, algo.len, algo.s,
642
+					it->limit, it->counter) < 0)
643
+				{
644
+					lock_release(&_pl_pipes_ht->slots[i].lock);
645
+					return;
646
+				}
647
+			}
648
+			it = it->next;
649
+		}
650
+		lock_release(&_pl_pipes_ht->slots[i].lock);
651
+	}
652
+}
653
+
654
+void rpc_pl_set_pipe(rpc_t *rpc, void *c)
655
+{
656
+	unsigned int algo_id, limit = 0;
657
+	pl_pipe_t *it;
658
+	str pipeid, algo_str;
659
+
660
+	if (rpc->scan(c, "SSd", &pipeid, &algo_str, &limit) < 3) return;
661
+
662
+	if (str_map_str(algo_names, &algo_str, (int*)&algo_id)) {
663
+		LM_ERR("unknown algorithm: '%.*s'\n", algo_str.len, algo_str.s);