// 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 <arpa/inet.h>
#include <assert.h>
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),
}
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));
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");
// 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__
#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
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;
char bgp_peer[2][64];
u16 bgp_peer_as[2];
#endif
- char hostname[256]; // our hostname - set to gethostname() by default
};
struct config_descriptt
// 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 <string.h>
-#include <unistd.h>
-#include <sys/mman.h>
-
#include "l2tpns.h"
#include "util.h"
#include "tbf.h"
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.
}
//
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;
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
}
//
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));