Browse code

pike: removed mi command

- use rpc command pike.top (aliased as pike.list)

Daniel-Constantin Mierla authored on 02/01/2017 08:34:35
Showing 6 changed files
... ...
@@ -1,16 +1,14 @@
1 1
 #
2 2
 # pike module makefile
3 3
 #
4
-# 
4
+#
5 5
 # WARNING: do not run this directly, it should be run by the master Makefile
6 6
 
7 7
 include ../../Makefile.defs
8 8
 auto_gen=
9 9
 NAME=pike.so
10
-LIBS= 
10
+LIBS=
11 11
 
12 12
 DEFS+=-DKAMAILIO_MOD_INTERFACE
13 13
 
14
-SERLIBPATH=../../lib
15
-SER_LIBS+=$(SERLIBPATH)/kmi/kmi
16 14
 include ../../Makefile.modules
... ...
@@ -10,14 +10,14 @@
10 10
 <!-- Module User's Guide -->
11 11
 
12 12
 <chapter>
13
-	
13
+
14 14
 	<title>&adminguide;</title>
15
-	
15
+
16 16
 	<section>
17 17
 	<title>Overview</title>
18 18
 	<para>
19 19
 		The pike module keeps trace of all (or selected ones) incoming request's IP
20
-		source and blocks the ones that exceed the limit. 
20
+		source and blocks the ones that exceed the limit.
21 21
 		It works simultaneously for IPv4 and IPv6 addresses.
22 22
 	</para>
23 23
 	<para>
... ...
@@ -44,7 +44,7 @@
44 44
 	<section>
45 45
 		<title>External Libraries or Applications</title>
46 46
 		<para>
47
-		The following libraries or applications must be installed before 
47
+		The following libraries or applications must be installed before
48 48
 		running &kamailio; with this module loaded:
49 49
 			<itemizedlist>
50 50
 			<listitem>
... ...
@@ -63,12 +63,12 @@
63 63
 		<para>
64 64
 		Time period in seconds used for sampling (or the sampling accuracy).
65 65
 		The smaller the better, but slower. If you want to detect peeks, use
66
-		a small one. To limit the access (like total number of requests on a 
67
-		long period of time) to a proxy resource (a gateway for example), use 
66
+		a small one. To limit the access (like total number of requests on a
67
+		long period of time) to a proxy resource (a gateway for example), use
68 68
 		a bigger value of this parameter.
69 69
 		</para>
70 70
 		<para>
71
-		IMPORTANT: a too small value may lead to performance penalties due 
71
+		IMPORTANT: a too small value may lead to performance penalties due
72 72
 		to timer process overloading.
73 73
 		</para>
74 74
 		<para>
... ...
@@ -89,8 +89,8 @@ modparam("pike", "sampling_time_unit", 10)
89 89
 		<title><varname>reqs_density_per_unit</varname> (integer)</title>
90 90
 		<para>
91 91
 		How many requests should be allowed per <varname>sampling_time_unit</varname>
92
-		before blocking all the incoming request from that IP. Practically, the 
93
-		blocking limit is between ( let's have x=reqs_density_per_unit) x 
92
+		before blocking all the incoming request from that IP. Practically, the
93
+		blocking limit is between ( let's have x=reqs_density_per_unit) x
94 94
 		and 3*x for IPv4 addresses and between x and 8*x for IPv6 addresses.
95 95
 		</para>
96 96
 		<para>
... ...
@@ -110,7 +110,7 @@ modparam("pike", "reqs_density_per_unit", 30)
110 110
 	<section id="pike.p.remove_latency">
111 111
 		<title><varname>remove_latency</varname> (integer)</title>
112 112
 		<para>
113
-		Speciies for how long the IP address will be kept in memory after the last 
113
+		Speciies for how long the IP address will be kept in memory after the last
114 114
 		request from that IP address. It's a sort of timeout value, in seconds.
115 115
 		Note that it is not the duration to keep the IP in state 'blocked'. An
116 116
 		IP is unblocked next occurence of 'sampling_time_unit' that does not
... ...
@@ -162,7 +162,7 @@ modparam("pike", "pike_log_level", -1)
162 162
 		<function moreinfo="none">pike_check_req()</function>
163 163
 		</title>
164 164
 		<para>
165
-		Process the source IP of the current request and return false if 
165
+		Process the source IP of the current request and return false if
166 166
 		the IP was exceeding the blocking limit.
167 167
 		</para>
168 168
 		<para>
... ...
@@ -170,7 +170,7 @@ modparam("pike", "pike_log_level", -1)
170 170
 		<itemizedlist>
171 171
 			<listitem>
172 172
 			<para>
173
-				<emphasis>1 (true)</emphasis> - IP is not to be blocked or 
173
+				<emphasis>1 (true)</emphasis> - IP is not to be blocked or
174 174
 				internal error occurred.
175 175
 			</para>
176 176
 			<warning>
... ...
@@ -186,7 +186,7 @@ modparam("pike", "pike_log_level", -1)
186 186
 			</listitem>
187 187
 			<listitem>
188 188
 			<para>
189
-				<emphasis>-2 (false)</emphasis> - IP is detected as a new 
189
+				<emphasis>-2 (false)</emphasis> - IP is detected as a new
190 190
 				source of flooding - first time detection
191 191
 			</para>
192 192
 			</listitem>
... ...
@@ -207,24 +207,26 @@ if (!pike_check_req()) { exit; };
207 207
 	</section>
208 208
 
209 209
 	<section>
210
-	<title>MI Commands</title>
211
-	<section id="pike.m.pike_list">
210
+	<title>RPC Commands</title>
211
+	<section id="pike.rpc.top">
212 212
 		<title>
213
-		<function moreinfo="none">pike_list</function>
213
+		<function moreinfo="none">pike.top</function>
214 214
 		</title>
215 215
 		<para>
216
-		Lists the nodes in the pike tree.
216
+		Lists nodes in the pike tree.
217 217
 		</para>
218 218
 		<para>
219
-		Name: <emphasis>pike_list</emphasis>
219
+		Name: <emphasis>pike.top</emphasis>
220 220
 		</para>
221
-		<para>Parameters: <emphasis>none</emphasis></para>
221
+		<para>Parameters: <emphasis>filter</emphasis> (optional) - it can be
222
+		"ALL", "HOT" or "WARM". If missing, the "HOT" nodes are listed.</para>
222 223
  		<para>
223
-		MI FIFO Command Format:
224
+		RPC Command Example:
224 225
 		</para>
225 226
 		<programlisting  format="linespecific">
226
-		:pike_list:_reply_fifo_file_
227
-		_empty_line_
227
+...
228
+&kamcmd; pike.top
229
+...
228 230
 		</programlisting>
229 231
 	</section>
230 232
 	</section>
... ...
@@ -38,7 +38,6 @@
38 38
 #include "../../core/kemi.h"
39 39
 #include "ip_tree.h"
40 40
 #include "timer.h"
41
-#include "pike_mi.h"
42 41
 #include "pike_funcs.h"
43 42
 #include "../../core/rpc_lookup.h"
44 43
 #include "pike_rpc.h"
... ...
@@ -77,19 +76,13 @@ static param_export_t params[]={
77 76
 };
78 77
 
79 78
 
80
-static mi_export_t mi_cmds [] = {
81
-	{MI_PIKE_LIST, mi_pike_list,   MI_NO_INPUT_FLAG,  0,  0 },
82
-	{0,0,0,0,0}
83
-};
84
-
85
-
86 79
 struct module_exports exports= {
87 80
 	"pike",
88 81
 	DEFAULT_DLFLAGS, /* dlopen flags */
89 82
 	cmds,
90 83
 	params,
91 84
 	0,           /* exported statistics */
92
-	mi_cmds,     /* exported MI functions */
85
+	0,           /* exported MI functions */
93 86
 	0,           /* exported pseudo-variables */
94 87
 	0,           /* extra processes */
95 88
 	pike_init,   /* module initialization function */
... ...
@@ -105,11 +98,6 @@ static int pike_init(void)
105 98
 {
106 99
 	LOG(L_INFO, "PIKE - initializing\n");
107 100
 
108
-	if(register_mi_mod(exports.name, mi_cmds)!=0)
109
-	{
110
-		LM_ERR("failed to register MI commands\n");
111
-		return -1;
112
-	}
113 101
 	if (rpc_register_array(pike_rpc_methods)!=0) {
114 102
 		LM_ERR("failed to register RPC commands\n");
115 103
 		return -1;
116 104
deleted file mode 100644
... ...
@@ -1,118 +0,0 @@
1
-/*
2
- * Header file for PIKE MI functions
3
- *
4
- * Copyright (C) 2006 Voice Sistem SRL
5
- *
6
- * This file is part of Kamailio, a free SIP server.
7
- *
8
- * Kamailio is free software; you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License as published by
10
- * the Free Software Foundation; either version 2 of the License, or
11
- * (at your option) any later version
12
- *
13
- * Kamailio is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
- * GNU General Public License for more details.
17
- *
18
- * You should have received a copy of the GNU General Public License
19
- * along with this program; if not, write to the Free Software
20
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21
- *
22
- */
23
-
24
-#include "ip_tree.h"
25
-#include "pike_mi.h"
26
-
27
-#define IPv6_LEN 16
28
-#define IPv4_LEN 4
29
-#define MAX_IP_LEN IPv6_LEN
30
-
31
-
32
-static struct ip_node *ip_stack[MAX_IP_LEN];
33
-
34
-
35
-static inline void print_ip_stack( int level, struct mi_node *node)
36
-{
37
-	if (level==IPv6_LEN) {
38
-		/* IPv6 */
39
-		addf_mi_node_child( node, 0, 0, 0,
40
-			"%x%x:%x%x:%x%x:%x%x:%x%x:%x%x:%x%x:%x%x",
41
-			ip_stack[0]->byte,  ip_stack[1]->byte,
42
-			ip_stack[2]->byte,  ip_stack[3]->byte,
43
-			ip_stack[4]->byte,  ip_stack[5]->byte,
44
-			ip_stack[6]->byte,  ip_stack[7]->byte,
45
-			ip_stack[8]->byte,  ip_stack[9]->byte,
46
-			ip_stack[10]->byte, ip_stack[11]->byte,
47
-			ip_stack[12]->byte, ip_stack[13]->byte,
48
-			ip_stack[14]->byte, ip_stack[15]->byte );
49
-	} else if (level==IPv4_LEN) {
50
-		/* IPv4 */
51
-		addf_mi_node_child( node, 0, 0, 0, "%d.%d.%d.%d",
52
-			ip_stack[0]->byte,
53
-			ip_stack[1]->byte,
54
-			ip_stack[2]->byte,
55
-			ip_stack[3]->byte );
56
-	} else {
57
-		LM_CRIT("leaf node at depth %d!!!\n", level);
58
-		return;
59
-	}
60
-}
61
-
62
-
63
-static void print_red_ips( struct ip_node *ip, int level, struct mi_node *node)
64
-{
65
-	struct ip_node *foo;
66
-
67
-	if (level==MAX_IP_LEN) {
68
-		LM_CRIT("tree deeper than %d!!!\n", MAX_IP_LEN);
69
-		return;
70
-	}
71
-	ip_stack[level] = ip;
72
-
73
-	/* is the node marked red? */
74
-	if ( ip->flags&NODE_ISRED_FLAG)
75
-		print_ip_stack(level+1,node);
76
-
77
-	/* go through all kids */
78
-	foo = ip->kids;
79
-	while(foo){
80
-		print_red_ips( foo, level+1, node);
81
-		foo = foo->next;
82
-	}
83
-
84
-}
85
-
86
-
87
-
88
-/*
89
- * Syntax of "pike_list" :
90
- * no nodes
91
-*/
92
-struct mi_root* mi_pike_list(struct mi_root* cmd_tree, void* param)
93
-{
94
-	struct mi_root* rpl_tree;
95
-	struct ip_node *ip;
96
-	int i;
97
-
98
-	rpl_tree = init_mi_tree( 200, MI_OK_S, MI_OK_LEN);
99
-	if (rpl_tree==0)
100
-		return 0;
101
-
102
-	for( i=0 ; i<MAX_IP_BRANCHES ; i++ ) {
103
-
104
-		if (get_tree_branch(i)==0)
105
-			continue;
106
-
107
-		lock_tree_branch(i);
108
-
109
-		if ( (ip=get_tree_branch(i))!=NULL )
110
-			print_red_ips( ip, 0, &rpl_tree->node );
111
-
112
-		unlock_tree_branch(i);
113
-	}
114
-
115
-	return rpl_tree;
116
-}
117
-
118
-
119 0
deleted file mode 100644
... ...
@@ -1,36 +0,0 @@
1
-/*
2
- * Header file for PIKE MI functions
3
- *
4
- * Copyright (C) 2006 Voice Sistem SRL
5
- *
6
- * This file is part of Kamailio, a free SIP server.
7
- *
8
- * Kamailio is free software; you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License as published by
10
- * the Free Software Foundation; either version 2 of the License, or
11
- * (at your option) any later version
12
- *
13
- * Kamailio is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
- * GNU General Public License for more details.
17
- *
18
- * You should have received a copy of the GNU General Public License
19
- * along with this program; if not, write to the Free Software
20
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21
- *
22
- */
23
-
24
-
25
-#ifndef _PIKE_MI_H_
26
-#define _PIKE_MI_H_
27
-
28
-#include "../../lib/kmi/mi.h"
29
-
30
-#define MI_PIKE_LIST      "pike_list"
31
-
32
-struct mi_root* mi_pike_list(struct mi_root* cmd_tree, void* param);
33
-
34
-#endif
35
-
36
-
... ...
@@ -191,5 +191,6 @@ static const char* pike_top_doc[] = {
191 191
 
192 192
 rpc_export_t pike_rpc_methods[] = {
193 193
 	{"pike.top",   pike_top,     pike_top_doc, 0},
194
+	{"pike.list",  pike_top,     pike_top_doc, 0},
194 195
 	{0, 0, 0, 0}
195 196
 };