From 95f612417ae9c268f3bd92930b3a1dfff106cae2 Mon Sep 17 00:00:00 2001 From: Daniel-Constantin Mierla Date: Mon, 2 Jan 2017 09:34:35 +0100 Subject: [PATCH] pike: removed mi command - use rpc command pike.top (aliased as pike.list) --- src/modules/pike/Makefile | 6 +- src/modules/pike/doc/pike_admin.xml | 46 +++++------ src/modules/pike/pike.c | 14 +--- src/modules/pike/pike_mi.c | 118 ---------------------------- src/modules/pike/pike_mi.h | 36 --------- src/modules/pike/pike_rpc.c | 1 + 6 files changed, 28 insertions(+), 193 deletions(-) delete mode 100644 src/modules/pike/pike_mi.c delete mode 100644 src/modules/pike/pike_mi.h diff --git a/src/modules/pike/Makefile b/src/modules/pike/Makefile index f417449fd65..9350db4f780 100644 --- a/src/modules/pike/Makefile +++ b/src/modules/pike/Makefile @@ -1,16 +1,14 @@ # # pike module makefile # -# +# # WARNING: do not run this directly, it should be run by the master Makefile include ../../Makefile.defs auto_gen= NAME=pike.so -LIBS= +LIBS= DEFS+=-DKAMAILIO_MOD_INTERFACE -SERLIBPATH=../../lib -SER_LIBS+=$(SERLIBPATH)/kmi/kmi include ../../Makefile.modules diff --git a/src/modules/pike/doc/pike_admin.xml b/src/modules/pike/doc/pike_admin.xml index e82e5caa578..fdc329b040c 100644 --- a/src/modules/pike/doc/pike_admin.xml +++ b/src/modules/pike/doc/pike_admin.xml @@ -10,14 +10,14 @@ - + &adminguide; - +
Overview The pike module keeps trace of all (or selected ones) incoming request's IP - source and blocks the ones that exceed the limit. + source and blocks the ones that exceed the limit. It works simultaneously for IPv4 and IPv6 addresses. @@ -44,7 +44,7 @@
External Libraries or Applications - The following libraries or applications must be installed before + The following libraries or applications must be installed before running &kamailio; with this module loaded: @@ -63,12 +63,12 @@ Time period in seconds used for sampling (or the sampling accuracy). The smaller the better, but slower. If you want to detect peeks, use - a small one. To limit the access (like total number of requests on a - long period of time) to a proxy resource (a gateway for example), use + a small one. To limit the access (like total number of requests on a + long period of time) to a proxy resource (a gateway for example), use a bigger value of this parameter. - IMPORTANT: a too small value may lead to performance penalties due + IMPORTANT: a too small value may lead to performance penalties due to timer process overloading. @@ -89,8 +89,8 @@ modparam("pike", "sampling_time_unit", 10) <varname>reqs_density_per_unit</varname> (integer) How many requests should be allowed per sampling_time_unit - before blocking all the incoming request from that IP. Practically, the - blocking limit is between ( let's have x=reqs_density_per_unit) x + before blocking all the incoming request from that IP. Practically, the + blocking limit is between ( let's have x=reqs_density_per_unit) x and 3*x for IPv4 addresses and between x and 8*x for IPv6 addresses. @@ -110,7 +110,7 @@ modparam("pike", "reqs_density_per_unit", 30)
<varname>remove_latency</varname> (integer) - Speciies for how long the IP address will be kept in memory after the last + Speciies for how long the IP address will be kept in memory after the last request from that IP address. It's a sort of timeout value, in seconds. Note that it is not the duration to keep the IP in state 'blocked'. An IP is unblocked next occurence of 'sampling_time_unit' that does not @@ -162,7 +162,7 @@ modparam("pike", "pike_log_level", -1) pike_check_req() - Process the source IP of the current request and return false if + Process the source IP of the current request and return false if the IP was exceeding the blocking limit. @@ -170,7 +170,7 @@ modparam("pike", "pike_log_level", -1) - 1 (true) - IP is not to be blocked or + 1 (true) - IP is not to be blocked or internal error occurred. @@ -186,7 +186,7 @@ modparam("pike", "pike_log_level", -1) - -2 (false) - IP is detected as a new + -2 (false) - IP is detected as a new source of flooding - first time detection @@ -207,24 +207,26 @@ if (!pike_check_req()) { exit; };
- MI Commands -
+ RPC Commands +
- <function moreinfo="none">pike_list</function> + <function moreinfo="none">pike.top</function> - Lists the nodes in the pike tree. + Lists nodes in the pike tree. - Name: pike_list + Name: pike.top - Parameters: none + Parameters: filter (optional) - it can be + "ALL", "HOT" or "WARM". If missing, the "HOT" nodes are listed. - MI FIFO Command Format: + RPC Command Example: - :pike_list:_reply_fifo_file_ - _empty_line_ +... +&kamcmd; pike.top +...
diff --git a/src/modules/pike/pike.c b/src/modules/pike/pike.c index fa2629622c1..2e6f765691f 100644 --- a/src/modules/pike/pike.c +++ b/src/modules/pike/pike.c @@ -38,7 +38,6 @@ #include "../../core/kemi.h" #include "ip_tree.h" #include "timer.h" -#include "pike_mi.h" #include "pike_funcs.h" #include "../../core/rpc_lookup.h" #include "pike_rpc.h" @@ -77,19 +76,13 @@ static param_export_t params[]={ }; -static mi_export_t mi_cmds [] = { - {MI_PIKE_LIST, mi_pike_list, MI_NO_INPUT_FLAG, 0, 0 }, - {0,0,0,0,0} -}; - - struct module_exports exports= { "pike", DEFAULT_DLFLAGS, /* dlopen flags */ cmds, params, 0, /* exported statistics */ - mi_cmds, /* exported MI functions */ + 0, /* exported MI functions */ 0, /* exported pseudo-variables */ 0, /* extra processes */ pike_init, /* module initialization function */ @@ -105,11 +98,6 @@ static int pike_init(void) { LOG(L_INFO, "PIKE - initializing\n"); - if(register_mi_mod(exports.name, mi_cmds)!=0) - { - LM_ERR("failed to register MI commands\n"); - return -1; - } if (rpc_register_array(pike_rpc_methods)!=0) { LM_ERR("failed to register RPC commands\n"); return -1; diff --git a/src/modules/pike/pike_mi.c b/src/modules/pike/pike_mi.c deleted file mode 100644 index 2d3ccc05fc5..00000000000 --- a/src/modules/pike/pike_mi.c +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Header file for PIKE MI functions - * - * Copyright (C) 2006 Voice Sistem SRL - * - * This file is part of Kamailio, a free SIP server. - * - * Kamailio is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version - * - * Kamailio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#include "ip_tree.h" -#include "pike_mi.h" - -#define IPv6_LEN 16 -#define IPv4_LEN 4 -#define MAX_IP_LEN IPv6_LEN - - -static struct ip_node *ip_stack[MAX_IP_LEN]; - - -static inline void print_ip_stack( int level, struct mi_node *node) -{ - if (level==IPv6_LEN) { - /* IPv6 */ - addf_mi_node_child( node, 0, 0, 0, - "%x%x:%x%x:%x%x:%x%x:%x%x:%x%x:%x%x:%x%x", - ip_stack[0]->byte, ip_stack[1]->byte, - ip_stack[2]->byte, ip_stack[3]->byte, - ip_stack[4]->byte, ip_stack[5]->byte, - ip_stack[6]->byte, ip_stack[7]->byte, - ip_stack[8]->byte, ip_stack[9]->byte, - ip_stack[10]->byte, ip_stack[11]->byte, - ip_stack[12]->byte, ip_stack[13]->byte, - ip_stack[14]->byte, ip_stack[15]->byte ); - } else if (level==IPv4_LEN) { - /* IPv4 */ - addf_mi_node_child( node, 0, 0, 0, "%d.%d.%d.%d", - ip_stack[0]->byte, - ip_stack[1]->byte, - ip_stack[2]->byte, - ip_stack[3]->byte ); - } else { - LM_CRIT("leaf node at depth %d!!!\n", level); - return; - } -} - - -static void print_red_ips( struct ip_node *ip, int level, struct mi_node *node) -{ - struct ip_node *foo; - - if (level==MAX_IP_LEN) { - LM_CRIT("tree deeper than %d!!!\n", MAX_IP_LEN); - return; - } - ip_stack[level] = ip; - - /* is the node marked red? */ - if ( ip->flags&NODE_ISRED_FLAG) - print_ip_stack(level+1,node); - - /* go through all kids */ - foo = ip->kids; - while(foo){ - print_red_ips( foo, level+1, node); - foo = foo->next; - } - -} - - - -/* - * Syntax of "pike_list" : - * no nodes -*/ -struct mi_root* mi_pike_list(struct mi_root* cmd_tree, void* param) -{ - struct mi_root* rpl_tree; - struct ip_node *ip; - int i; - - rpl_tree = init_mi_tree( 200, MI_OK_S, MI_OK_LEN); - if (rpl_tree==0) - return 0; - - for( i=0 ; inode ); - - unlock_tree_branch(i); - } - - return rpl_tree; -} - - diff --git a/src/modules/pike/pike_mi.h b/src/modules/pike/pike_mi.h deleted file mode 100644 index a9361ab33e1..00000000000 --- a/src/modules/pike/pike_mi.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Header file for PIKE MI functions - * - * Copyright (C) 2006 Voice Sistem SRL - * - * This file is part of Kamailio, a free SIP server. - * - * Kamailio is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version - * - * Kamailio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - - -#ifndef _PIKE_MI_H_ -#define _PIKE_MI_H_ - -#include "../../lib/kmi/mi.h" - -#define MI_PIKE_LIST "pike_list" - -struct mi_root* mi_pike_list(struct mi_root* cmd_tree, void* param); - -#endif - - diff --git a/src/modules/pike/pike_rpc.c b/src/modules/pike/pike_rpc.c index 105679b1faa..58312a018e7 100644 --- a/src/modules/pike/pike_rpc.c +++ b/src/modules/pike/pike_rpc.c @@ -191,5 +191,6 @@ static const char* pike_top_doc[] = { rpc_export_t pike_rpc_methods[] = { {"pike.top", pike_top, pike_top_doc, 0}, + {"pike.list", pike_top, pike_top_doc, 0}, {0, 0, 0, 0} };