#include <stdio.h>#include <stdlib.h>#include <sys/types.h>#include <regex.h>#include <math.h>#include "../../mem/mem.h"#include "../../mem/shm_mem.h"#include "../../sr_module.h"#include "../../dprint.h"#include "../../timer.h"#include "../../ut.h"#include "../../locking.h"#include "../../mod_fix.h"#include "../../data_lump.h"#include "../../data_lump_rpl.h"#include "../../statistics.h"#include "../sl/sl_api.h"

Go to the source code of this file.
Data Structures | |
| struct | pipe |
| struct | pipe_params |
| struct | rl_queue |
| struct | rl_queue_params |
| struct | str_map |
Defines | |
| #define | LOCK_GET lock_get |
| #define | LOCK_RELEASE lock_release |
| #define | MAX_PIPES 16 |
| #define | MAX_QUEUES 10 |
| #define | RL_TIMER_INTERVAL 10 |
| #define | RXL(m, str, i) (m)[i].rm_eo - (m)[i].rm_so |
| #define | RXLS(m, str, i) (m)[i].rm_eo - (m)[i].rm_so, (str) + (m)[i].rm_so |
| #define | RXS(m, str, i) (str) + (m)[i].rm_so |
Typedefs | |
| typedef struct pipe_params | pipe_params_t |
| typedef struct pipe | pipe_t |
| typedef struct rl_queue_params | rl_queue_params_t |
| typedef struct rl_queue | rl_queue_t |
| typedef struct str_map | str_map_t |
Enumerations | |
| enum | { PIPE_ALGO_NOP = 0, PIPE_ALGO_RED, PIPE_ALGO_TAILDROP, PIPE_ALGO_FEEDBACK, PIPE_ALGO_NETWORK } |
| enum | { LOAD_SOURCE_CPU, LOAD_SOURCE_EXTERNAL } |
Functions | |
| static int | add_pipe_params (modparam_t, void *) |
| static int | add_queue_params (modparam_t, void *) |
| static int | check_feedback_setpoints (int modparam) |
| void | destroy (void) |
| static void | do_update_load (void) |
| static int | find_queue (struct sip_msg *msg, int *queue) |
| static int | get_cpuload (double *load) |
| static int | init_params (void) |
| struct mi_root * | mi_get_pid (struct mi_root *cmd_tree, void *param) |
| struct mi_root * | mi_get_pipes (struct mi_root *cmd_tree, void *param) |
| struct mi_root * | mi_get_queues (struct mi_root *cmd_tree, void *param) |
| struct mi_root * | mi_push_load (struct mi_root *cmd_tree, void *param) |
| struct mi_root * | mi_set_dbg (struct mi_root *cmd_tree, void *param) |
| struct mi_root * | mi_set_pid (struct mi_root *cmd_tree, void *param) |
| struct mi_root * | mi_set_pipe (struct mi_root *cmd_tree, void *param) |
| struct mi_root * | mi_set_queue (struct mi_root *cmd_tree, void *param) |
| struct mi_root * | mi_stats (struct mi_root *cmd_tree, void *param) |
| static int | mod_init (void) |
| static int | parse_pipe_params (char *line, pipe_params_t *params) |
| static int | parse_queue_params (char *line, rl_queue_params_t *params) |
| static int | pipe_push (struct sip_msg *msg, int id) |
| static int | rl_check (struct sip_msg *msg, int forced_pipe) |
| static int | rl_drop (struct sip_msg *msg, unsigned int low, unsigned int high) |
| static void | rl_timer (unsigned int, void *) |
| static int | str_cmp (const str *a, const str *b) |
| static int | str_cpy (str *dest, str *src) |
| static int | str_i_cmp (const str *a, const str *b) |
| static int | str_map_int (const str_map_t *map, int key, str *ret) |
| static int | str_map_str (const str_map_t *map, const str *key, int *ret) |
| static void | update_cpu_load (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 (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 *) |
Variables | |
| str_map_t | algo_names [] |
| static int | cfg_setpoint |
| static cmd_export_t | cmds [] |
| static int * | drop_rate |
| struct module_exports | exports |
| int | hash [100] |
| static double | int_err = 0.0 |
| static double | last_err = 0.0 |
| static int * | load_source |
| static int | load_source_mp = LOAD_SOURCE_CPU |
| static double * | load_value |
| static mi_export_t | mi_cmds [] |
| static int * | network_load_value |
| static int * | nqueues |
| static int | nqueues_mp = 0 |
| static param_export_t | params [] |
| static int | params_inited = 0 |
| static double * | pid_kd |
| static double * | pid_ki |
| static double * | pid_kp |
| static double * | pid_setpoint |
| static regex_t | pipe_params_regex |
| static pipe_t | pipes [MAX_PIPES] |
| str | queue_other = str_init("*") |
| static regex_t | queue_params_regex |
| static rl_queue_t | queues [MAX_QUEUES] |
| static str * | rl_dbg_str = NULL |
| static int | rl_drop_code = 503 |
| static str | rl_drop_reason = str_init("Server Unavailable") |
| gen_lock_t * | rl_lock |
| struct sl_binds | slb |
| str_map_t | source_names [] |
| static int | timer_interval = RL_TIMER_INTERVAL |
| #define LOCK_GET lock_get |
Definition at line 179 of file ratelimit.c.
Referenced by mi_get_pid(), mi_get_pipes(), mi_get_queues(), mi_push_load(), mi_set_dbg(), mi_set_pid(), mi_set_pipe(), mi_set_queue(), mi_stats(), rl_check(), and rl_timer().
| #define LOCK_RELEASE lock_release |
Definition at line 180 of file ratelimit.c.
Referenced by mi_get_pid(), mi_get_pipes(), mi_get_queues(), mi_push_load(), mi_set_dbg(), mi_set_pid(), mi_set_pipe(), mi_set_queue(), mi_stats(), rl_check(), and rl_timer().
| #define MAX_PIPES 16 |
| #define MAX_QUEUES 10 |
Definition at line 54 of file ratelimit.c.
Referenced by add_queue_params(), mi_get_queues(), and mi_set_queue().
| #define RL_TIMER_INTERVAL 10 |
Definition at line 59 of file ratelimit.c.
| #define RXL | ( | m, | |||
| str, | |||||
| i | ) | (m)[i].rm_eo - (m)[i].rm_so |
Definition at line 62 of file ratelimit.c.
Referenced by parse_pipe_params(), and parse_queue_params().
Definition at line 61 of file ratelimit.c.
Referenced by parse_pipe_params(), and parse_queue_params().
Definition at line 63 of file ratelimit.c.
Referenced by parse_pipe_params(), and parse_queue_params().
| typedef struct pipe_params pipe_params_t |
| typedef struct rl_queue_params rl_queue_params_t |
| typedef struct rl_queue rl_queue_t |
| anonymous enum |
Definition at line 84 of file ratelimit.c.
| anonymous enum |
| static int add_pipe_params | ( | modparam_t | type, | |
| void * | val | |||
| ) | [static] |
Definition at line 1068 of file ratelimit.c.
References pipe_params::algo, pipe::algo_mp, check_feedback_setpoints(), pipe_params::limit, pipe::limit_mp, LM_ERR, pipe_params::no, and parse_pipe_params().
| static int add_queue_params | ( | modparam_t | type, | |
| void * | val | |||
| ) | [static] |
Definition at line 1088 of file ratelimit.c.
References LM_ERR, MAX_QUEUES, rl_queue_params::method, rl_queue::method_mp, nqueues_mp, parse_queue_params(), rl_queue_params::pipe, and rl_queue::pipe_mp.
| static int check_feedback_setpoints | ( | int | modparam | ) | [static] |
checks that all FEEDBACK pipes use the same setpoint cpu load. also sets (common) cfg_setpoint value
| modparam | 1 to check modparam (static) fields, 0 to use shm ones |
Definition at line 1042 of file ratelimit.c.
References cfg_setpoint, pipe::limit, pipe::limit_mp, LM_ERR, and PIPE_ALGO_FEEDBACK.
Referenced by add_pipe_params(), and mi_set_pipe().
| void destroy | ( | void | ) |
| static void do_update_load | ( | void | ) | [static] |
Definition at line 378 of file ratelimit.c.
References drop_rate, load_value, and pid_setpoint.
Referenced by mi_push_load(), and update_cpu_load().
| static int find_queue | ( | struct sip_msg * | msg, | |
| int * | queue | |||
| ) | [static] |
finds the queue associated with the message's method (expects rl_lock to be taken)
Definition at line 780 of file ratelimit.c.
References sip_msg::first_line, LM_INFO, msg_start::request, str_i_cmp(), and msg_start::u.
Referenced by rl_check().
| static int get_cpuload | ( | double * | load | ) | [static] |
| static int init_params | ( | void | ) | [static] |
compiles regexes for parsing modparams and clears the pipes and queues
Definition at line 958 of file ratelimit.c.
References LM_ERR, params_inited, pipe_params_regex, and queue_params_regex.
Referenced by parse_pipe_params(), and parse_queue_params().
Definition at line 1415 of file ratelimit.c.
References add_mi_node_child(), addf_mi_attr(), free_mi_tree(), init_mi_tree(), LM_ERR, LOCK_GET, LOCK_RELEASE, MI_OK_LEN, MI_OK_S, mi_root::node, NULL, pid_kd, pid_ki, pid_kp, and rl_lock.
Definition at line 1217 of file ratelimit.c.
References add_mi_attr(), add_mi_node_child(), free_mi_tree(), init_mi_tree(), int2str(), len, LM_ERR, LOCK_GET, LOCK_RELEASE, MI_DUP_VALUE, MI_OK_LEN, MI_OK_S, mi_root::node, NULL, PIPE_ALGO_NOP, rl_lock, and str_map_int().
Definition at line 1320 of file ratelimit.c.
References add_mi_attr(), add_mi_node_child(), free_mi_tree(), init_mi_tree(), int2str(), len, LM_ERR, LOCK_GET, LOCK_RELEASE, MAX_QUEUES, MI_DUP_VALUE, MI_OK_LEN, MI_OK_S, mi_root::node, NULL, rl_lock, and s.
Definition at line 1484 of file ratelimit.c.
References do_update_load(), init_mi_tree(), mi_node::kids, _str::len, LM_ERR, load_value, LOCK_GET, LOCK_RELEASE, MI_BAD_PARM_LEN, MI_BAD_PARM_S, MI_MISSING_PARM_LEN, MI_MISSING_PARM_S, MI_OK_LEN, MI_OK_S, mi_root::node, NULL, rl_lock, _str::s, and mi_node::value.
Definition at line 1512 of file ratelimit.c.
References init_mi_tree(), mi_node::kids, _str::len, LM_ERR, LOCK_GET, LOCK_RELEASE, MI_BAD_PARM_LEN, MI_BAD_PARM_S, MI_MISSING_PARM_LEN, MI_MISSING_PARM_S, MI_OK_LEN, MI_OK_S, mi_root::node, NULL, rl_lock, _str::s, shm_free, shm_malloc(), strno2int(), and mi_node::value.
Definition at line 1449 of file ratelimit.c.
References init_mi_tree(), mi_node::kids, _str::len, LOCK_GET, LOCK_RELEASE, MI_BAD_PARM_LEN, MI_BAD_PARM_S, MI_MISSING_PARM_LEN, MI_MISSING_PARM_S, MI_OK_LEN, MI_OK_S, mi_node::next, mi_root::node, NULL, pid_kd, pid_ki, pid_kp, rl_lock, _str::s, and mi_node::value.
Definition at line 1270 of file ratelimit.c.
References pipe::algo, cfg_setpoint, check_feedback_setpoints(), init_mi_tree(), mi_node::kids, _str::len, pipe::limit, LM_DBG, LM_ERR, LOCK_GET, LOCK_RELEASE, MI_BAD_PARM_LEN, MI_BAD_PARM_S, MI_MISSING_PARM_LEN, MI_MISSING_PARM_S, MI_OK_LEN, MI_OK_S, mi_node::next, mi_root::node, NULL, pid_setpoint, rl_lock, _str::s, str_map_str(), strno2int(), and mi_node::value.
Definition at line 1366 of file ratelimit.c.
References init_mi_tree(), mi_node::kids, _str::len, LM_ERR, LOCK_GET, LOCK_RELEASE, MAX_QUEUES, rl_queue::method, MI_BAD_PARM_LEN, MI_BAD_PARM_S, MI_MISSING_PARM_LEN, MI_MISSING_PARM_S, MI_OK_LEN, MI_OK_S, mi_node::next, mi_root::node, NULL, rl_queue::pipe, rl_lock, _str::s, shm_free, str_cpy(), strno2int(), and mi_node::value.
Definition at line 1168 of file ratelimit.c.
References add_mi_attr(), add_mi_node_child(), drop_rate, free_mi_tree(), init_mi_tree(), int2str(), len, LM_ERR, LOCK_GET, LOCK_RELEASE, MI_DUP_VALUE, MI_OK_LEN, MI_OK_S, mi_root::node, NULL, PIPE_ALGO_NOP, and rl_lock.
| static int mod_init | ( | void | ) | [static] |
module functions
Definition at line 427 of file ratelimit.c.
References pipe::algo, pipe::algo_mp, cfg_setpoint, counter, pipe::counter, drop_rate, pipe::last_counter, _str::len, pipe::limit, pipe::limit_mp, LM_ERR, pipe::load, load_sl_api(), load_source, load_source_mp, load_value, MAX_PIPES, rl_queue::method, rl_queue::method_mp, network_load_value, nqueues, nqueues_mp, NULL, pid_kd, pid_ki, pid_kp, pid_setpoint, rl_queue::pipe, rl_queue::pipe_mp, pkg_free, register_timer_process(), rl_lock, rl_timer(), _str::s, shm_malloc(), slb, str_cpy(), timer_interval, and TIMER_PROC_INIT_FLAG.
| static int parse_pipe_params | ( | char * | line, | |
| pipe_params_t * | params | |||
| ) | [static] |
parses a "pipe_no:algorithm:bandwidth" line
Definition at line 978 of file ratelimit.c.
References pipe_params::algo, init_params(), _str::len, pipe_params::limit, LM_DBG, LM_ERR, pipe_params::no, params_inited, pipe_params_regex, RXL, RXLS, RXS, _str::s, and str_map_str().
Referenced by add_pipe_params().
| static int parse_queue_params | ( | char * | line, | |
| rl_queue_params_t * | params | |||
| ) | [static] |
parses a "pipe_no:method" line
Definition at line 1007 of file ratelimit.c.
References init_params(), _str::len, len, LM_DBG, LM_ERR, rl_queue_params::method, params_inited, rl_queue_params::pipe, pkg_malloc, queue_params_regex, RXL, RXLS, RXS, and _str::s.
Referenced by add_queue_params().
| static int pipe_push | ( | struct sip_msg * | msg, | |
| int | id | |||
| ) | [static] |
runs the pipe's algorithm (expects rl_lock to be taken), TODO revert to "return" instead of "ret ="
Definition at line 817 of file ratelimit.c.
References pipe::counter, drop_rate, pipe::limit, LM_ERR, pipe::load, PIPE_ALGO_FEEDBACK, PIPE_ALGO_NETWORK, PIPE_ALGO_NOP, PIPE_ALGO_RED, PIPE_ALGO_TAILDROP, and timer_interval.
Referenced by rl_check().
| static int rl_check | ( | struct sip_msg * | msg, | |
| int | forced_pipe | |||
| ) | [static] |
runs the current request through the queues
| msg | ||
| forced_pipe | is >= 0 if a specific pipe should be used, < 0 otherwise |
Definition at line 857 of file ratelimit.c.
References pipe::algo, pipe::counter, find_queue(), sip_msg::first_line, _str::len, pipe::limit, LM_DBG, pipe::load, load_value, LOCK_GET, LOCK_RELEASE, network_load_value, rl_queue::pipe, pipe_push(), msg_start::request, rl_lock, _str::s, and msg_start::u.
Referenced by w_rl_check_default(), w_rl_check_forced(), and w_rl_check_forced_pipe().
| static int rl_drop | ( | struct sip_msg * | msg, | |
| unsigned int | low, | |||
| unsigned int | high | |||
| ) | [static] |
Definition at line 684 of file ratelimit.c.
References add_lump_rpl(), _str::len, LM_DBG, LM_ERR, LUMP_RPL_HDR, pkg_free, pkg_malloc, rl_drop_code, _str::s, sl_binds::send_reply, slb, and snprintf.
Referenced by w_rl_drop(), w_rl_drop_default(), and w_rl_drop_forced().
| static void rl_timer | ( | unsigned int | ticks, | |
| void * | param | |||
| ) | [static] |
Definition at line 1116 of file ratelimit.c.
References pipe::counter, get_total_bytes_waiting(), int2str(), pipe::last_counter, _str::len, len, pipe::limit, LM_WARN, pipe::load, load_source, LOAD_SOURCE_CPU, LOCK_GET, LOCK_RELEASE, network_load_value, PIPE_ALGO_NETWORK, rl_lock, _str::s, timer_interval, and update_cpu_load().
Referenced by mod_init().
Definition at line 763 of file ratelimit.c.
References _str::len, and _str::s.
Referenced by str_map_str().
strcpy for str's (does not allocate the str structure but only the .s member)
Definition at line 311 of file ratelimit.c.
References _str::len, LM_ERR, _str::s, and shm_malloc().
Referenced by mi_set_queue(), and mod_init().
Definition at line 768 of file ratelimit.c.
References _str::len, and _str::s.
Referenced by find_queue().
converts a mapped int to a str
Definition at line 296 of file ratelimit.c.
References str_map::id, LM_DBG, _str::s, and str_map::str.
Referenced by mi_get_pipes().
converts a mapped str to an int
Definition at line 281 of file ratelimit.c.
References str_map::id, _str::len, LM_DBG, _str::s, str_map::str, and str_cmp().
Referenced by mi_set_pipe(), and parse_pipe_params().
| static void update_cpu_load | ( | void | ) | [static] |
Definition at line 418 of file ratelimit.c.
References do_update_load(), get_cpuload(), and load_value.
Referenced by rl_timer().
| static int w_rl_check_default | ( | struct sip_msg * | msg, | |
| char * | p1, | |||
| char * | p2 | |||
| ) | [static] |
| static int w_rl_check_forced | ( | struct sip_msg * | msg, | |
| char * | p1, | |||
| char * | p2 | |||
| ) | [static] |
Definition at line 890 of file ratelimit.c.
References _pv_value::flags, _str::len, LM_DBG, LM_ERR, pv_get_spec_value(), PV_VAL_INT, PV_VAL_STR, _pv_value::ri, rl_check(), _pv_value::rs, _str::s, and str2int().
| static int w_rl_check_forced_pipe | ( | struct sip_msg * | msg, | |
| char * | p1, | |||
| char * | p2 | |||
| ) | [static] |
| static int w_rl_drop | ( | struct sip_msg * | msg, | |
| char * | p1, | |||
| char * | p2 | |||
| ) | [static] |
| static int w_rl_drop_default | ( | struct sip_msg * | msg, | |
| char * | p1, | |||
| char * | p2 | |||
| ) | [static] |
| static int w_rl_drop_forced | ( | struct sip_msg * | msg, | |
| char * | p1, | |||
| char * | p2 | |||
| ) | [static] |
Definition at line 92 of file ratelimit.c.
int cfg_setpoint [static] |
Definition at line 175 of file ratelimit.c.
Referenced by check_feedback_setpoints(), mi_set_pipe(), and mod_init().
cmd_export_t cmds[] [static] |
Definition at line 215 of file ratelimit.c.
int* drop_rate [static] |
Definition at line 146 of file ratelimit.c.
Referenced by do_update_load(), mi_stats(), mod_init(), and pipe_push().
| struct module_exports exports |
module exports
Definition at line 261 of file ratelimit.c.
| int hash[100] |
Definition at line 804 of file ratelimit.c.
double int_err = 0.0 [static] |
Definition at line 372 of file ratelimit.c.
double last_err = 0.0 [static] |
Definition at line 373 of file ratelimit.c.
int* load_source [static] |
int load_source_mp = LOAD_SOURCE_CPU [static] |
double* load_value [static] |
Definition at line 144 of file ratelimit.c.
Referenced by do_update_load(), mi_push_load(), mod_init(), rl_check(), and update_cpu_load().
mi_export_t mi_cmds[] [static] |
Definition at line 247 of file ratelimit.c.
int* network_load_value [static] |
int* nqueues [static] |
int nqueues_mp = 0 [static] |
param_export_t params[] [static] |
Definition at line 225 of file ratelimit.c.
int params_inited = 0 [static] |
Definition at line 195 of file ratelimit.c.
Referenced by init_params(), parse_pipe_params(), and parse_queue_params().
double * pid_kd [static] |
Definition at line 145 of file ratelimit.c.
Referenced by mi_get_pid(), mi_set_pid(), and mod_init().
double * pid_ki [static] |
Definition at line 145 of file ratelimit.c.
Referenced by mi_get_pid(), mi_set_pid(), and mod_init().
double* pid_kp [static] |
Definition at line 145 of file ratelimit.c.
Referenced by mi_get_pid(), mi_set_pid(), and mod_init().
double * pid_setpoint [static] |
Definition at line 145 of file ratelimit.c.
Referenced by do_update_load(), mi_set_pipe(), and mod_init().
regex_t pipe_params_regex [static] |
Definition at line 165 of file ratelimit.c.
| str queue_other = str_init("*") |
Definition at line 773 of file ratelimit.c.
regex_t queue_params_regex [static] |
rl_queue_t queues[MAX_QUEUES] [static] |
Definition at line 166 of file ratelimit.c.
str* rl_dbg_str = NULL [static] |
Definition at line 171 of file ratelimit.c.
int rl_drop_code = 503 [static] |
str rl_drop_reason = str_init("Server Unavailable") [static] |
Definition at line 119 of file ratelimit.c.
| gen_lock_t* rl_lock |
Definition at line 142 of file ratelimit.c.
Referenced by mi_get_pid(), mi_get_pipes(), mi_get_queues(), mi_push_load(), mi_set_dbg(), mi_set_pid(), mi_set_pipe(), mi_set_queue(), mi_stats(), mod_init(), rl_check(), and rl_timer().
SL binds
Definition at line 66 of file ratelimit.c.
Initial value:
{
{str_init("cpu"), LOAD_SOURCE_CPU},
{str_init("external"), LOAD_SOURCE_EXTERNAL},
{{0, 0}, 0},
}
Definition at line 112 of file ratelimit.c.
int timer_interval = RL_TIMER_INTERVAL [static] |
1.5.6