make number of throttle buckets configurable

This commit is contained in:
Brendan O'Dea 2004-10-29 04:01:11 +00:00
parent d4330a0b42
commit 7ecd8a42e5
4 changed files with 38 additions and 54 deletions

View file

@ -4,7 +4,7 @@
// Copyright (c) 2002 FireBrick (Andrews & Arnold Ltd / Watchfront Ltd) - GPL licenced // Copyright (c) 2002 FireBrick (Andrews & Arnold Ltd / Watchfront Ltd) - GPL licenced
// vim: sw=8 ts=8 // 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 <arpa/inet.h> #include <arpa/inet.h>
#include <assert.h> #include <assert.h>
@ -101,13 +101,14 @@ struct config_descriptt config_values[] = {
CONFIG("save_state", save_state, BOOL), CONFIG("save_state", save_state, BOOL),
CONFIG("primary_radius", radiusserver[0], IP), CONFIG("primary_radius", radiusserver[0], IP),
CONFIG("secondary_radius", radiusserver[1], IP), CONFIG("secondary_radius", radiusserver[1], IP),
CONFIG("primary_radius_port",radiusport[0], SHORT), CONFIG("primary_radius_port", radiusport[0], SHORT),
CONFIG("secondary_radius_port",radiusport[1], SHORT), CONFIG("secondary_radius_port", radiusport[1], SHORT),
CONFIG("radius_accounting", radius_accounting, BOOL), CONFIG("radius_accounting", radius_accounting, BOOL),
CONFIG("radius_secret", radiussecret, STRING), CONFIG("radius_secret", radiussecret, STRING),
CONFIG("bind_address", bind_address, IP), CONFIG("bind_address", bind_address, IP),
CONFIG("send_garp", send_garp, BOOL), CONFIG("send_garp", send_garp, BOOL),
CONFIG("throttle_speed", rl_rate, UNSIGNED_LONG), CONFIG("throttle_speed", rl_rate, UNSIGNED_LONG),
CONFIG("throttle_buckets", num_tbfs, INT),
CONFIG("accounting_dir", accounting_dir, STRING), CONFIG("accounting_dir", accounting_dir, STRING),
CONFIG("setuid", target_uid, INT), CONFIG("setuid", target_uid, INT),
CONFIG("dump_speed", dump_speed, BOOL), CONFIG("dump_speed", dump_speed, BOOL),
@ -2477,8 +2478,11 @@ void initdata(int optdebug, char *optconfig)
} }
memset(config, 0, sizeof(struct configt)); memset(config, 0, sizeof(struct configt));
time(&config->start_time); time(&config->start_time);
config->debug = optdebug;
strncpy(config->config_file, optconfig, strlen(optconfig)); 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))) if (!(tunnel = shared_malloc(sizeof(tunnelt) * MAXTUNNEL)))
{ {
log(0, 0, 0, 0, "Error doing malloc for tunnels: %s\n", strerror(errno)); 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(); initplugins();
initdata(optdebug, optconfig); initdata(optdebug, optconfig);
init_tbf();
init_cli(hostname);
read_config_file(); 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, "L2TPNS version " VERSION "\n");
log(0, 0, 0, 0, "Copyright (c) 2003, 2004 Optus Internet Engineering\n"); log(0, 0, 0, 0, "Copyright (c) 2003, 2004 Optus Internet Engineering\n");

View file

@ -1,5 +1,5 @@
// L2TPNS Global Stuff // 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__ #ifndef __L2TPNS_H__
#define __L2TPNS_H__ #define __L2TPNS_H__
@ -43,7 +43,18 @@
#define BUSY_WAIT_TIMEOUT 3000 // 5 minutes in 1/10th seconds to wait for radius to cleanup on shutdown #define BUSY_WAIT_TIMEOUT 3000 // 5 minutes in 1/10th seconds to wait for radius to cleanup on shutdown
// Constants // Constants
#include "config.h" #ifndef ETCDIR
#define ETCDIR "/etc/l2tpns"
#endif
#ifndef LIBDIR
#define LIBDIR "/usr/lib/l2tpns"
#endif
#ifndef STATEDIR
#define STATEDIR "/var/lib/l2tpns"
#endif
#ifndef PLUGINDIR #ifndef PLUGINDIR
#define PLUGINDIR LIBDIR // Plugins #define PLUGINDIR LIBDIR // Plugins
#endif #endif
@ -52,14 +63,14 @@
#define PLUGINCONF ETCDIR // Plugin config dir #define PLUGINCONF ETCDIR // Plugin config dir
#endif #endif
#ifndef DATADIR
#define DATADIR "/tmp"
#endif
#ifndef FLASHDIR #ifndef FLASHDIR
#define FLASHDIR ETCDIR #define FLASHDIR ETCDIR
#endif #endif
#ifndef DATADIR
#define DATADIR STATEDIR
#endif
#define TUNDEVICE "/dev/net/tun" #define TUNDEVICE "/dev/net/tun"
#define STATEFILE DATADIR "/state.dump" // State dump file #define STATEFILE DATADIR "/state.dump" // State dump file
#define CONFIGFILE FLASHDIR "/startup-config" // Configuration file #define CONFIGFILE FLASHDIR "/startup-config" // Configuration file
@ -408,7 +419,9 @@ struct configt
ipt default_dns1, default_dns2; 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; int save_state;
char accounting_dir[128]; char accounting_dir[128];
ipt bind_address; ipt bind_address;
@ -448,7 +461,6 @@ struct configt
char bgp_peer[2][64]; char bgp_peer[2][64];
u16 bgp_peer_as[2]; u16 bgp_peer_as[2];
#endif #endif
char hostname[256]; // our hostname - set to gethostname() by default
}; };
struct config_descriptt struct config_descriptt

42
tbf.c
View file

@ -1,13 +1,8 @@
// L2TPNS: token bucket filters // L2TPNS: token bucket filters
char const *cvs_id_tbf = "$Id: tbf.c,v 1.7 2004-10-28 03:26:41 bodea Exp $"; char const *cvs_id_tbf = "$Id: tbf.c,v 1.8 2004-10-29 04:01:11 bodea Exp $";
#define _GNU_SOURCE
#include <string.h> #include <string.h>
#include <unistd.h>
#include <sys/mman.h>
#include "l2tpns.h" #include "l2tpns.h"
#include "util.h" #include "util.h"
#include "tbf.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); 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; return;
filter_list_size = MAXTBFS; filter_list_size = num_tbfs;
filter_list[0].sid = -1; // Reserved. 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; int i;
static int p = 0; 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) if (!filter_list)
return 0; // Couldn't alloc memory! return 0; // Couldn't alloc memory!
// again:
for (i = 0 ; i < filter_list_size ; ++i, p = (p+1)%filter_list_size ) { for (i = 0 ; i < filter_list_size ; ++i, p = (p+1)%filter_list_size ) {
if (filter_list[p].sid) if (filter_list[p].sid)
continue; continue;
@ -123,33 +116,8 @@ int new_tbf(int sid, int max_credit, int rate, void (*f)(sessionidt, u8 *, int))
return p; 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); log(0,0,0,0, "Ran out of token bucket filters! Sess %d will be un-throttled\n", sid);
return 0; return 0;
#endif
} }
// //

2
tbf.h
View file

@ -33,7 +33,7 @@ typedef struct {
char packets[TBF_MAX_QUEUE][TBF_MAX_SIZE]; char packets[TBF_MAX_QUEUE][TBF_MAX_SIZE];
} tbft; } tbft;
void init_tbf(void); void init_tbf(int num_tbfs);
int tbf_run_timer(void); int tbf_run_timer(void);
int tbf_queue_packet(int tbf_id, char * data, int size); 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)); int new_tbf(int sid, int max_credit, int rate, void (*f)(sessionidt, u8 *, int));