From: bodea Date: Fri, 29 Oct 2004 04:01:11 +0000 (+0000) Subject: make number of throttle buckets configurable X-Git-Tag: release_2_0_3~18 X-Git-Url: http://git.sameswireless.fr/l2tpns.git/commitdiff_plain/2f1b71cd7452cddfb456fd1a8df472893716a6d3?ds=inline make number of throttle buckets configurable --- diff --git a/l2tpns.c b/l2tpns.c index 5c84a4f..3918529 100644 --- a/l2tpns.c +++ b/l2tpns.c @@ -4,7 +4,7 @@ // Copyright (c) 2002 FireBrick (Andrews & Arnold Ltd / Watchfront Ltd) - GPL licenced // vim: sw=8 ts=8 -char const *cvs_id_l2tpns = "$Id: l2tpns.c,v 1.33 2004/10/28 03:58:38 bodea Exp $"; +char const *cvs_id_l2tpns = "$Id: l2tpns.c,v 1.34 2004/10/29 04:01:11 bodea Exp $"; #include #include @@ -101,13 +101,14 @@ struct config_descriptt config_values[] = { CONFIG("save_state", save_state, BOOL), CONFIG("primary_radius", radiusserver[0], IP), CONFIG("secondary_radius", radiusserver[1], IP), - CONFIG("primary_radius_port",radiusport[0], SHORT), - CONFIG("secondary_radius_port",radiusport[1], SHORT), + CONFIG("primary_radius_port", radiusport[0], SHORT), + CONFIG("secondary_radius_port", radiusport[1], SHORT), CONFIG("radius_accounting", radius_accounting, BOOL), CONFIG("radius_secret", radiussecret, STRING), CONFIG("bind_address", bind_address, IP), CONFIG("send_garp", send_garp, BOOL), CONFIG("throttle_speed", rl_rate, UNSIGNED_LONG), + CONFIG("throttle_buckets", num_tbfs, INT), CONFIG("accounting_dir", accounting_dir, STRING), CONFIG("setuid", target_uid, INT), CONFIG("dump_speed", dump_speed, BOOL), @@ -2477,8 +2478,11 @@ void initdata(int optdebug, char *optconfig) } memset(config, 0, sizeof(struct configt)); time(&config->start_time); - config->debug = optdebug; strncpy(config->config_file, optconfig, strlen(optconfig)); + config->debug = optdebug; + config->num_tbfs = MAXTBFS; + config->rl_rate = 28; // 28kbps + if (!(tunnel = shared_malloc(sizeof(tunnelt) * MAXTUNNEL))) { log(0, 0, 0, 0, "Error doing malloc for tunnels: %s\n", strerror(errno)); @@ -2960,9 +2964,9 @@ int main(int argc, char *argv[]) initplugins(); initdata(optdebug, optconfig); - init_tbf(); - init_cli(hostname); read_config_file(); + init_tbf(config->num_tbfs); + init_cli(hostname); log(0, 0, 0, 0, "L2TPNS version " VERSION "\n"); log(0, 0, 0, 0, "Copyright (c) 2003, 2004 Optus Internet Engineering\n"); diff --git a/l2tpns.h b/l2tpns.h index 927eb45..d84be52 100644 --- a/l2tpns.h +++ b/l2tpns.h @@ -1,5 +1,5 @@ // L2TPNS Global Stuff -// $Id: l2tpns.h,v 1.23 2004/10/28 03:58:51 bodea Exp $ +// $Id: l2tpns.h,v 1.24 2004/10/29 04:01:11 bodea Exp $ #ifndef __L2TPNS_H__ #define __L2TPNS_H__ @@ -43,23 +43,34 @@ #define BUSY_WAIT_TIMEOUT 3000 // 5 minutes in 1/10th seconds to wait for radius to cleanup on shutdown // Constants -#include "config.h" -#ifndef PLUGINDIR -#define PLUGINDIR LIBDIR // Plugins +#ifndef ETCDIR +#define ETCDIR "/etc/l2tpns" #endif -#ifndef PLUGINCONF -#define PLUGINCONF ETCDIR // Plugin config dir +#ifndef LIBDIR +#define LIBDIR "/usr/lib/l2tpns" #endif -#ifndef DATADIR -#define DATADIR "/tmp" +#ifndef STATEDIR +#define STATEDIR "/var/lib/l2tpns" +#endif + +#ifndef PLUGINDIR +#define PLUGINDIR LIBDIR // Plugins +#endif + +#ifndef PLUGINCONF +#define PLUGINCONF ETCDIR // Plugin config dir #endif #ifndef FLASHDIR #define FLASHDIR ETCDIR #endif +#ifndef DATADIR +#define DATADIR STATEDIR +#endif + #define TUNDEVICE "/dev/net/tun" #define STATEFILE DATADIR "/state.dump" // State dump file #define CONFIGFILE FLASHDIR "/startup-config" // Configuration file @@ -408,7 +419,9 @@ struct configt ipt default_dns1, default_dns2; - unsigned long rl_rate; + unsigned long rl_rate; // throttle rate + int num_tbfs; // number of throttle buckets + int save_state; char accounting_dir[128]; ipt bind_address; @@ -448,7 +461,6 @@ struct configt char bgp_peer[2][64]; u16 bgp_peer_as[2]; #endif - char hostname[256]; // our hostname - set to gethostname() by default }; struct config_descriptt diff --git a/tbf.c b/tbf.c index e5d7e99..9482006 100644 --- a/tbf.c +++ b/tbf.c @@ -1,13 +1,8 @@ // L2TPNS: token bucket filters -char const *cvs_id_tbf = "$Id: tbf.c,v 1.7 2004/10/28 03:26:41 bodea Exp $"; - -#define _GNU_SOURCE +char const *cvs_id_tbf = "$Id: tbf.c,v 1.8 2004/10/29 04:01:11 bodea Exp $"; #include -#include -#include - #include "l2tpns.h" #include "util.h" #include "tbf.h" @@ -19,12 +14,12 @@ static int timer_chain = -1; // Head of timer chain. static void tbf_run_queue(int tbf_id); -void init_tbf(void) +void init_tbf(int num_tbfs) { - if (!(filter_list = shared_malloc(sizeof(*filter_list) * MAXTBFS))) + if (!(filter_list = shared_malloc(sizeof(*filter_list) * num_tbfs))) return; - filter_list_size = MAXTBFS; + filter_list_size = num_tbfs; filter_list[0].sid = -1; // Reserved. } // @@ -101,13 +96,11 @@ int new_tbf(int sid, int max_credit, int rate, void (*f)(sessionidt, u8 *, int)) int i; static int p = 0; - log(3,0,0,0, "Allocating new TBF (sess %d, rate %d, helper %p)\n", sid, rate, f); + log(4,0,0,0, "Allocating new TBF (sess %d, rate %d, helper %p)\n", sid, rate, f); if (!filter_list) return 0; // Couldn't alloc memory! -// again: - for (i = 0 ; i < filter_list_size ; ++i, p = (p+1)%filter_list_size ) { if (filter_list[p].sid) continue; @@ -123,33 +116,8 @@ int new_tbf(int sid, int max_credit, int rate, void (*f)(sessionidt, u8 *, int)) return p; } -#if 0 - // All allocated filters are used! Increase the size of the allocated - // filters. - - { - int new_size = filter_list_size * 2; - tbft *new = mremap(filter_list, filter_list_size * sizeof(*new), new_size * sizeof(*new), MREMAP_MAYMOVE); - - if (new == MAP_FAILED) - { - log(0,0,0,0, "Ran out of token bucket filters and mremap failed! Sess %d will be un-throttled\n", sid); - return 0; - } - - i = filter_list_size; - filter_list_size = new_size; - filter_list = new; - } - - for (; i < filter_list_size; ++i) - filter_list[i].sid = 0; - - goto again; -#else log(0,0,0,0, "Ran out of token bucket filters! Sess %d will be un-throttled\n", sid); return 0; -#endif } // diff --git a/tbf.h b/tbf.h index 7a6df12..bad2c37 100644 --- a/tbf.h +++ b/tbf.h @@ -33,7 +33,7 @@ typedef struct { char packets[TBF_MAX_QUEUE][TBF_MAX_SIZE]; } tbft; -void init_tbf(void); +void init_tbf(int num_tbfs); int tbf_run_timer(void); int tbf_queue_packet(int tbf_id, char * data, int size); int new_tbf(int sid, int max_credit, int rate, void (*f)(sessionidt, u8 *, int));