Browse code

- removed old fifo commands - they were used only for debug purposes and had no value in a usage scenario - add new MI function 'pike_list' - returns all IP addresses marked as flooding source.

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@1306 689a6050-402a-0410-94f2-e92a70836424

Bogdan-Andrei Iancu authored on 05/12/2006 17:31:36
Showing 6 changed files
... ...
@@ -137,8 +137,6 @@ int init_ip_tree(int maximum_hits)
137 137
 	for(i=0;i<MAX_IP_BRANCHES;i++) {
138 138
 		root->entries[i].node = 0;
139 139
 		root->entries[i].lock_idx = i % size;
140
-		/*DBG("DEBUG:pike:pike_ip_tree: branch %d takes lock index %d\n",
141
-			i, root->entries[i].lock_idx);*/
142 140
 	}
143 141
 
144 142
 	root->max_hits = maximum_hits;
... ...
@@ -333,6 +331,11 @@ struct ip_node* mark_node(unsigned char *ip,int ip_len,
333 331
 }
334 332
 
335 333
 
334
+int is_red_leaf(struct ip_node *node)
335
+{
336
+	return is_hot_leaf( node );
337
+}
338
+
336 339
 
337 340
 /* remove and destroy a IP node along with its subtree */
338 341
 void remove_node(struct ip_node *node)
... ...
@@ -359,49 +362,3 @@ void remove_node(struct ip_node *node)
359 362
 	destroy_ip_node(node);
360 363
 }
361 364
 
362
-
363
-
364
-void print_node(struct ip_node *node,int sp, FILE *f)
365
-{
366
-	struct ip_node *foo;
367
-
368
-	/* print current node */
369
-	if (!f) {
370
-		DBG("[l%d] node %p; brh=%d byte=%d flags=%d, hits={%d,%d} , "
371
-			"leaf_hits={%d,%d]\n",
372
-			sp, node, node->branch, node->byte, node->flags,
373
-			node->hits[PREV_POS],node->hits[CURR_POS],
374
-			node->leaf_hits[PREV_POS],node->leaf_hits[CURR_POS]);
375
-	} else {
376
-		fprintf(f,"[l%d] node %p; brh=%d byte=%d flags=%d, hits={%d,%d} , "
377
-			"leaf_hits={%d,%d]\n",
378
-			sp, node, node->branch, node->byte, node->flags,
379
-			node->hits[PREV_POS],node->hits[CURR_POS],
380
-			node->leaf_hits[PREV_POS],node->leaf_hits[CURR_POS]);
381
-	}
382
-
383
-	/* print all the kids */
384
-	foo = node->kids;
385
-	while(foo){
386
-		print_node(foo,sp+1,f);
387
-		foo = foo->next;
388
-	}
389
-}
390
-
391
-
392
-
393
-void print_tree(  FILE *f )
394
-{
395
-	int i;
396
-
397
-	DBG("DEBUG:pike:print_tree: printing IP tree\n");
398
-	for(i=0;i<MAX_IP_BRANCHES;i++) {
399
-		if (prv_get_tree_branch(i)==0)
400
-			continue;
401
-		prv_lock_tree_branch(i);
402
-		if (prv_get_tree_branch(i))
403
-			print_node( prv_get_tree_branch(i), 0, f);
404
-		prv_unlock_tree_branch(i);
405
-	}
406
-}
407
-
... ...
@@ -81,13 +81,12 @@ struct ip_tree
81 81
 		(unsigned long)(&((struct ip_node*)0)->timer_ll)))
82 82
 
83 83
 
84
-int   init_ip_tree(int);
85
-void  destroy_ip_tree();
84
+int    init_ip_tree(int);
85
+void   destroy_ip_tree();
86 86
 struct ip_node* mark_node( unsigned char *ip, int ip_len,
87
-		struct ip_node **father, unsigned char *flag);
88
-void  remove_node(struct ip_node *node);
89
-
90
-void print_tree( FILE *f);
87
+			struct ip_node **father, unsigned char *flag);
88
+void   remove_node(struct ip_node *node);
89
+int    is_red_leaf(struct ip_node *node);
91 90
 
92 91
 void lock_tree_branch(unsigned char b);
93 92
 void unlock_tree_branch(unsigned char b);
... ...
@@ -43,11 +43,10 @@
43 43
 #include "../../mem/shm_mem.h"
44 44
 #include "../../timer.h"
45 45
 #include "../../locking.h"
46
-#include "../../fifo_server.h"
47 46
 #include "ip_tree.h"
48 47
 #include "timer.h"
48
+#include "pike_mi.h"
49 49
 #include "pike_funcs.h"
50
-#include "pike_fifo.h"
51 50
 
52 51
 MODULE_VERSION
53 52
 
... ...
@@ -81,13 +80,19 @@ static param_export_t params[]={
81 80
 };
82 81
 
83 82
 
83
+static mi_export_t mi_cmds [] = {
84
+	{MI_PIKE_LIST,   mi_pike_list,   0,  0 },
85
+	{0,0,0,0}
86
+};
87
+
88
+
84 89
 struct module_exports exports= {
85 90
 	"pike",
86 91
 	DEFAULT_DLFLAGS, /* dlopen flags */
87 92
 	cmds,
88 93
 	params,
89 94
 	0,           /* exported statistics */
90
-	0,           /* exported MI functions */
95
+	mi_cmds,     /* exported MI functions */
91 96
 	0,           /* exported pseudo-variables */
92 97
 	pike_init,   /* module initialization function */
93 98
 	(response_function) 0,
... ...
@@ -132,22 +137,7 @@ static int pike_init(void)
132 137
 	register_timer( clean_routine , 0, 1 );
133 138
 	register_timer( swap_routine , 0, time_unit );
134 139
 
135
-	/* register fifo commands */
136
-	if (register_fifo_cmd( fifo_print_ip_tree, PIKE_PRINT_IP_TREE, 0)!=1) {
137
-		LOG(L_ERR,"ERROR:pike_init: cannot register fifo cmd %s\n",
138
-			PIKE_PRINT_IP_TREE);
139
-		goto error4;
140
-	}
141
-	/* register fifo commands */
142
-	if (register_fifo_cmd( fifo_print_timer_list, PIKE_PRINT_TIMER, 0)!=1) {
143
-		LOG(L_ERR,"ERROR:pike_init: cannot register fifo cmd %s\n",
144
-			PIKE_PRINT_IP_TREE);
145
-		goto error4;
146
-	}
147
-
148 140
 	return 0;
149
-error4:
150
-	shm_free( timer );
151 141
 error3:
152 142
 	destroy_ip_tree();
153 143
 error2:
154 144
deleted file mode 100644
... ...
@@ -1,94 +0,0 @@
1
-/*
2
- * $Id$
3
- *
4
- * PIKE module
5
- *
6
- * Copyright (C) 2001-2003 FhG Fokus
7
- *
8
- * This file is part of openser, a free SIP server.
9
- *
10
- * openser 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
- * openser 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23
- *
24
- * History:
25
- * --------
26
- *  2004-05-12  created (bogdan)
27
- */
28
-
29
-
30
-
31
-
32
-#include "../../dprint.h"
33
-#include "../../fifo_server.h"
34
-#include "../../locking.h"
35
-#include "pike_fifo.h"
36
-#include "ip_tree.h"
37
-
38
-
39
-extern gen_lock_t*             timer_lock;
40
-extern struct list_link*       timer;
41
-
42
-
43
-int fifo_print_ip_tree( FILE *fifo_stream, char *response_file )
44
-{
45
-	FILE * rpl;
46
-
47
-	/* open the reply fifo */
48
-	rpl = open_reply_pipe( response_file );
49
-	if (rpl==0) {
50
-		LOG(L_ERR,"ERROR:pike:fifo_print_ip_tree: failed to open response "
51
-			"file \"%s\"\n",response_file);
52
-		goto error;
53
-	}
54
-
55
-	print_tree( rpl );
56
-
57
-	fclose(rpl);
58
-	return 0;
59
-error:
60
-	return -1;
61
-}
62
-
63
-
64
-
65
-int fifo_print_timer_list( FILE *fifo_stream, char *response_file )
66
-{
67
-	struct list_link *ll;
68
-	FILE * rpl;
69
-
70
-	/* open the reply fifo */
71
-	rpl = open_reply_pipe( response_file );
72
-	if (rpl==0) {
73
-		LOG(L_ERR,"ERROR:pike:fifo_print_timer_list: failed to open "
74
-			"response file \"%s\"\n",response_file);
75
-		goto error;
76
-	}
77
-
78
-	/* lock and print the list */
79
-	lock_get(timer_lock);
80
-	for ( ll=timer->next ; ll!=timer; ll=ll->next) {
81
-		fprintf(rpl," %p [byte=%d](expires=%d)\n",
82
-			ll, ll2ipnode(ll)->byte, ll2ipnode(ll)->expires);
83
-	}
84
-	lock_release(timer_lock);
85
-
86
-
87
-	fclose(rpl);
88
-	return 0;
89
-error:
90
-	return -1;
91
-
92
-}
93
-
94
-
95 0
deleted file mode 100644
... ...
@@ -1,44 +0,0 @@
1
-/*
2
- * $Id$
3
- *
4
- * PIKE module
5
- *
6
- * Copyright (C) 2001-2003 FhG Fokus
7
- *
8
- * This file is part of openser, a free SIP server.
9
- *
10
- * openser 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
- * openser 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23
- *
24
- * History:
25
- * --------
26
- *  2004-05-12  created (bogdan)
27
- */
28
-
29
-
30
-
31
-
32
-#ifndef _PIKE_FIFO_
33
-#define _PIKE_FIFO_
34
-
35
-#include <stdio.h>
36
-
37
-
38
-#define PIKE_PRINT_IP_TREE  "print_ip_tree"
39
-#define PIKE_PRINT_TIMER    "print_timer_list"
40
-
41
-int fifo_print_ip_tree( FILE *fifo_stream, char *response_file );
42
-int fifo_print_timer_list( FILE *fifo_stream, char *response_file );
43
-
44
-#endif 
... ...
@@ -52,18 +52,6 @@ extern int               timeout;
52 52
 
53 53
 
54 54
 
55
-void print_timer_list(struct list_link *head)
56
-{
57
-	struct list_link *ll;
58
-
59
-	DBG("DEBUG:pike:print_timer_list --->\n");
60
-	for ( ll=head->next ; ll!=head; ll=ll->next) {
61
-		DBG("\t %p [byte=%x](expires=%d)\n",
62
-			ll, ll2ipnode(ll)->byte, ll2ipnode(ll)->expires);
63
-	}
64
-}
65
-
66
-
67 55
 int pike_check_req(struct sip_msg *msg, char *foo, char *bar)
68 56
 {
69 57
 	struct ip_node *node;