Module: sip-router Branch: master Commit: 9f652c9de2e95671aecae2cdce00fb6c15a265ea URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=9f652c9d...
Author: Ovidiu Sas osas@voipembedded.com Committer: Ovidiu Sas osas@voipembedded.com Date: Fri Jul 2 18:45:22 2010 -0400
modules_k: ratelimit - removing rl_drop functionality
- rl_drop is now obsolete: same functionality can be achieved by invoking: append_to_reply("Retry-After: 5\r\n"); sl_send_reply("503","Limiting"); - sl dependency was also removed and therefore the module can be used in both s and k configurations.
---
modules_k/ratelimit/config.c | 52 ------------------ modules_k/ratelimit/config.h | 41 -------------- modules_k/ratelimit/ratelimit.c | 113 --------------------------------------- 3 files changed, 0 insertions(+), 206 deletions(-)
diff --git a/modules_k/ratelimit/config.c b/modules_k/ratelimit/config.c deleted file mode 100644 index dc6ade1..0000000 --- a/modules_k/ratelimit/config.c +++ /dev/null @@ -1,52 +0,0 @@ -/* - * $Id$ - * - * Copyright (C) 2008 iptelorg GmbH - * - * This file is part of SIP-router, a free SIP server. - * - * SIP-router 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 - * - * SIP-router 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * History - * ------- - * 2008-02-05 adapting tm module for the configuration framework (Miklos) - */ - -/*! - * \file - * \brief TM :: Configuration - * \ingroup tm - */ - - -#include "../../cfg/cfg.h" -#include "../../parser/msg_parser.h" /* method types */ - -#include "config.h" - -struct cfg_group_ratelimit default_ratelimit_cfg = { - DEFAULT_REPLY_CODE, - DEFAULT_REPLY_REASON -}; - -void *ratelimit_cfg = &default_ratelimit_cfg; - -cfg_def_t ratelimit_cfg_def[] = { - {"reply_code", CFG_VAR_INT | CFG_ATOMIC, 400, 699, 0, 0, - "The code of the reply sent by Kamailio while limiting." }, - {"reply_reason", CFG_VAR_STRING, 0, 0, 0, 0, - "The reason of the reply sent by Kamailio while limiting."}, - {0, 0, 0, 0, 0, 0} -}; diff --git a/modules_k/ratelimit/config.h b/modules_k/ratelimit/config.h deleted file mode 100644 index 5ce3e26..0000000 --- a/modules_k/ratelimit/config.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * $Id$ - * - * SIP-router 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/*! - * \file - * \brief Ratelimit :: Configuration - * \ingroup ratelimit - */ - - -#ifndef _RATELIMIT_CONFIG_H -#define _RATELIMIT_CONFIG_H - - -#include "../../cfg/cfg.h" -#include "../../str.h" - - -#define DEFAULT_REPLY_CODE 503 -#define DEFAULT_REPLY_REASON "Server Unavailable" - -struct cfg_group_ratelimit { - unsigned int reply_code; - char* reply_reason; -}; - -extern struct cfg_group_ratelimit default_ratelimit_cfg; -extern void *ratelimit_cfg; -extern cfg_def_t ratelimit_cfg_def[]; - -#endif diff --git a/modules_k/ratelimit/ratelimit.c b/modules_k/ratelimit/ratelimit.c index ed73e32..b949c68 100644 --- a/modules_k/ratelimit/ratelimit.c +++ b/modules_k/ratelimit/ratelimit.c @@ -49,11 +49,9 @@ #include "../../data_lump.h" #include "../../data_lump_rpl.h" #include "../../lib/kcore/statistics.h" -#include "../sl/sl_api.h" #include "../../lib/kcore/km_ut.h" #include "../../rpc_lookup.h"
-#include "config.h"
MODULE_VERSION
@@ -69,9 +67,6 @@ MODULE_VERSION #define RXL(m, str, i) (m)[i].rm_eo - (m)[i].rm_so #define RXS(m, str, i) (str) + (m)[i].rm_so
-/** SL binds */ -struct sl_binds slb; - static inline int str_cmp(const str * a, const str * b); static inline int str_i_cmp(const str * a, const str * b);
@@ -210,9 +205,6 @@ static ticks_t rl_timer_handle(ticks_t, struct timer_ln*, void*); static int w_rl_check_default(struct sip_msg*, char *, char *); static int w_rl_check_forced(struct sip_msg*, char *, char *); static int w_rl_check_forced_pipe(struct sip_msg*, char *, char *); -static int w_rl_drop_default(struct sip_msg*, char *, char *); -static int w_rl_drop_forced(struct sip_msg*, char *, char *); -static int w_rl_drop(struct sip_msg*, char *, char *); static int add_queue_params(modparam_t, void *); static int add_pipe_params(modparam_t, void *); /* RESERVED for future use @@ -225,17 +217,12 @@ static cmd_export_t cmds[]={ {"rl_check", (cmd_function)w_rl_check_forced, 1, fixup_pvar_null, fixup_free_pvar_null, REQUEST_ROUTE|LOCAL_ROUTE}, {"rl_check_pipe", (cmd_function)w_rl_check_forced_pipe, 1, fixup_uint_null, 0, REQUEST_ROUTE|LOCAL_ROUTE}, - {"rl_drop", (cmd_function)w_rl_drop_default, 0, 0, 0, REQUEST_ROUTE|LOCAL_ROUTE}, - {"rl_drop", (cmd_function)w_rl_drop_forced, 1, fixup_uint_null, 0, REQUEST_ROUTE|LOCAL_ROUTE}, - {"rl_drop", (cmd_function)w_rl_drop, 2, fixup_uint_uint, 0, REQUEST_ROUTE|LOCAL_ROUTE}, {0,0,0,0,0,0} }; static param_export_t params[]={ {"timer_interval", INT_PARAM, &timer_interval}, {"queue", STR_PARAM|USE_FUNC_PARAM, (void *)add_queue_params}, {"pipe", STR_PARAM|USE_FUNC_PARAM, (void *)add_pipe_params}, - {"reply_code", INT_PARAM, &default_ratelimit_cfg.reply_code}, - {"reply_reason", STR_PARAM, &default_ratelimit_cfg.reply_reason}, /* RESERVED for future use {"load_source", STR_PARAM|USE_FUNC_PARAM, (void *)set_load_source}, */ @@ -439,12 +426,6 @@ static int mod_init(void) timer_init(rl_timer, rl_timer_handle, 0, F_TIMER_FAST); timer_add(rl_timer, MS_TO_TICKS(1500)); /* Start it after 1500ms */
- /* load the SL API */ - if (load_sl_api(&slb)!=0) { - LM_ERR("failed to load SL API\n"); - return -1; - } - network_load_value = shm_malloc(sizeof(int)); if (network_load_value==NULL) { LM_ERR("oom for network_load_value\n"); @@ -497,13 +478,6 @@ static int mod_init(void) return -1; }
- /* load configurations*/ - if( cfg_declare("ratelimit", ratelimit_cfg_def, &default_ratelimit_cfg, cfg_sizeof(ratelimit), - &ratelimit_cfg )){ - LM_ERR("failed to declare the configuration"); - return -1; - } - *network_load_value = 0; *load_value = 0.0; *load_source = load_source_mp; @@ -685,93 +659,6 @@ static void destroy(void) }
-static int rl_drop(struct sip_msg * msg, unsigned int low, unsigned int high) -{ - str hdr; - int ret; - int drop_code; - str drop_reason; - - LM_DBG("(%d, %d)\n", low, high); - - if (slb.send_reply != 0) { - if ( (drop_code = cfg_get(ratelimit, ratelimit_cfg, reply_code)) == 0 ) - drop_code = DEFAULT_REPLY_CODE; - - if ( (drop_reason.s = cfg_get(ratelimit, ratelimit_cfg, reply_reason)) == 0 ) - drop_reason.s = DEFAULT_REPLY_REASON; - drop_reason.len = strlen(drop_reason.s); - - if (low != 0 && high != 0) { - hdr.s = (char *)pkg_malloc(64); - if (hdr.s == 0) { - LM_ERR("Can't allocate memory for Retry-After header\n"); - return 0; - } - hdr.len = 0; - if (! hdr.s) { - LM_ERR("no memory for hdr\n"); - return 0; - } - - if (high == low) { - hdr.len = snprintf(hdr.s, 63, "Retry-After: %d\r\n", low); - } else { - hdr.len = snprintf(hdr.s, 63, "Retry-After: %d\r\n", - low + rand() % (high - low + 1)); - } - - if (add_lump_rpl(msg, hdr.s, hdr.len, LUMP_RPL_HDR)==0) { - LM_ERR("Can't add header\n"); - pkg_free(hdr.s); - return 0; - } - ret = slb.send_reply(msg, drop_code, &drop_reason); - - pkg_free(hdr.s); - } else { - ret = slb.send_reply(msg, drop_code, &drop_reason); - } - } else { - LM_ERR("Can't send reply\n"); - return 0; - } - return ret; -} - -static int w_rl_drop(struct sip_msg* msg, char *p1, char *p2) -{ - unsigned int low, high; - - low = (unsigned int)(unsigned long)p1; - high = (unsigned int)(unsigned long)p2; - - if (high < low) { - return rl_drop(msg, low, low); - } else { - return rl_drop(msg, low, high); - } -} - -static int w_rl_drop_forced(struct sip_msg* msg, char *p1, char *p2) -{ - unsigned int i; - - if (p1) { - i = (unsigned int)(unsigned long)p1; - LM_DBG("send retry in %d s\n", i); - } else { - i = 5; - LM_DBG("send default retry in %d s\n", i); - } - return rl_drop(msg, i, i); -} - -static int w_rl_drop_default(struct sip_msg* msg, char *p1, char *p2) -{ - return rl_drop(msg, 0, 0); -} - static inline int str_cmp(const str * a , const str * b) { return ! (a->len == b->len && ! strncmp(a->s, b->s, a->len));
On Saturday 03 July 2010, Ovidiu Sas wrote:
modules_k: ratelimit - removing rl_drop functionality
- rl_drop is now obsolete: same functionality can be achieved by invoking: append_to_reply("Retry-After: 5\r\n"); sl_send_reply("503","Limiting");
Hi Ovidiu,
if you like to achive the existing functionality of rl_drop with a random Retry-After, you additionally need to use the $RANDOM PV with from cfgutils with e.g. a modulo operation in the script.
Cheers,
Henning
Hello,
On 7/5/10 12:29 PM, Henning Westerholt wrote:
On Saturday 03 July 2010, Ovidiu Sas wrote:
modules_k: ratelimit - removing rl_drop functionality
- rl_drop is now obsolete: same functionality can be achieved by invoking: append_to_reply("Retry-After: 5\r\n"); sl_send_reply("503","Limiting");
Hi Ovidiu,
if you like to achive the existing functionality of rl_drop with a random Retry-After, you additionally need to use the $RANDOM PV with from cfgutils with e.g. a modulo operation in the script.
do not forget to add notes about these updates in the migration wiki page:
http://sip-router.org/wiki/install/3.0.x-to-3.1.x
Thanks, Daniel
Done.
On Mon, Jul 5, 2010 at 6:32 AM, Daniel-Constantin Mierla miconda@gmail.com wrote:
do not forget to add notes about these updates in the migration wiki page:
http://sip-router.org/wiki/install/3.0.x-to-3.1.x
Thanks, Daniel
Hello Henning,
I will add an example to the README file. My goal was to remove the dependency on the sl module. The ratelimit module is now ready to be migrated from modules_k to modules.
Regards, Ovidiu Sas
On Mon, Jul 5, 2010 at 6:29 AM, Henning Westerholt henning.westerholt@1und1.de wrote:
On Saturday 03 July 2010, Ovidiu Sas wrote:
modules_k: ratelimit - removing rl_drop functionality
- rl_drop is now obsolete: same functionality can be achieved by invoking: append_to_reply("Retry-After: 5\r\n"); sl_send_reply("503","Limiting");
Hi Ovidiu,
if you like to achive the existing functionality of rl_drop with a random Retry-After, you additionally need to use the $RANDOM PV with from cfgutils with e.g. a modulo operation in the script.
Cheers,
Henning