add a callback to allow plugins to fetch values from the running config

This commit is contained in:
bodea 2004-11-09 08:05:01 +00:00
parent 4deca21d7b
commit 72346a7226
10 changed files with 60 additions and 25 deletions

View file

@ -1,7 +1,8 @@
? Brendan O'Dea <bod@optusnet.com.au> 2.0.5 * Tue Nov 9 2004 Brendan O'Dea <bod@optusnet.com.au> 2.0.5
- Handle routing properly in lone-master case - Handle routing properly in lone-master case
- Fix intercepts: don't double-snoop throttled customers, ensure - Fix intercepts: don't double-snoop throttled customers, ensure
byte/packet counts are only updated once byte/packet counts are only updated once
- Add a callback to allow plugins to fetch values from the running config
* Mon Nov 8 2004 Brendan O'Dea <bod@optusnet.com.au> 2.0.4 * Mon Nov 8 2004 Brendan O'Dea <bod@optusnet.com.au> 2.0.4
- Added setrxspeed plugin - Added setrxspeed plugin

View file

@ -4,9 +4,9 @@
/* set up intercept based on RADIUS reply */ /* set up intercept based on RADIUS reply */
char const *cvs_id = "$Id: autosnoop.c,v 1.6 2004/11/09 06:02:37 bodea Exp $"; char const *cvs_id = "$Id: autosnoop.c,v 1.7 2004/11/09 08:05:02 bodea Exp $";
int __plugin_api_version = 1; int __plugin_api_version = PLUGIN_API_VERSION;
struct pluginfuncs *p; struct pluginfuncs *p;
int plugin_radius_response(struct param_radius_response *data) int plugin_radius_response(struct param_radius_response *data)

View file

@ -4,9 +4,9 @@
/* set up throttling based on RADIUS reply */ /* set up throttling based on RADIUS reply */
char const *cvs_id = "$Id: autothrottle.c,v 1.7 2004/11/05 04:55:26 bodea Exp $"; char const *cvs_id = "$Id: autothrottle.c,v 1.8 2004/11/09 08:05:02 bodea Exp $";
int __plugin_api_version = 1; int __plugin_api_version = PLUGIN_API_VERSION;
struct pluginfuncs *p; struct pluginfuncs *p;
#define THROTTLE_KEY "lcp:interface-config" #define THROTTLE_KEY "lcp:interface-config"
@ -64,8 +64,18 @@ int plugin_radius_response(struct param_radius_response *data)
{ {
if (strcmp(data->value, "yes") == 0) if (strcmp(data->value, "yes") == 0)
{ {
p->log(3, 0, p->get_id_by_session(data->s), data->s->tunnel, " Throttling user\n"); unsigned long *rate = p->getconfig("throttle_speed", UNSIGNED_LONG);
data->s->throttle_in = data->s->throttle_out = config->rl_rate; if (rate)
{
if (*rate)
p->log(3, 0, p->get_id_by_session(data->s), data->s->tunnel, " Throttling user to %dkb/s\n", *rate);
else
p->log(3, 0, p->get_id_by_session(data->s), data->s->tunnel, " Not throttling user (throttle_speed=0)\n");
data->s->throttle_in = data->s->throttle_out = *rate;
}
else
p->log(1, 0, p->get_id_by_session(data->s), data->s->tunnel, "Not throttling user (can't get throttle_speed)\n");
} }
else if (strcmp(data->value, "no") == 0) else if (strcmp(data->value, "no") == 0)
{ {

View file

@ -9,9 +9,9 @@
/* walled garden */ /* walled garden */
char const *cvs_id = "$Id: garden.c,v 1.11 2004/11/05 04:55:27 bodea Exp $"; char const *cvs_id = "$Id: garden.c,v 1.12 2004/11/09 08:05:02 bodea Exp $";
int __plugin_api_version = 1; int __plugin_api_version = PLUGIN_API_VERSION;
static struct pluginfuncs *p = 0; static struct pluginfuncs *p = 0;
static int iam_master = 0; // We're all slaves! Slaves I tell you! static int iam_master = 0; // We're all slaves! Slaves I tell you!

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.46 2004/11/09 05:42:53 bodea Exp $"; char const *cvs_id_l2tpns = "$Id: l2tpns.c,v 1.47 2004/11/09 08:05:02 bodea Exp $";
#include <arpa/inet.h> #include <arpa/inet.h>
#include <assert.h> #include <assert.h>
@ -3469,6 +3469,7 @@ void update_config()
{ {
if (strcmp(config->plugins[i], config->old_plugins[i]) == 0) if (strcmp(config->plugins[i], config->old_plugins[i]) == 0)
continue; continue;
if (*config->plugins[i]) if (*config->plugins[i])
{ {
// Plugin added // Plugin added
@ -3761,6 +3762,29 @@ static void *open_plugin(char *plugin_name, int load)
return dlopen(path, RTLD_NOW); return dlopen(path, RTLD_NOW);
} }
// plugin callback to get a config value
static void *getconfig(char *key, enum config_typet type)
{
int i;
for (i = 0; config_values[i].key; i++)
{
if (!strcmp(config_values[i].key, key))
{
if (config_values[i].type == type)
return ((void *) config) + config_values[i].offset;
LOG(1, 0, 0, 0, "plugin requested config item \"%s\" expecting type %d, have type %d\n",
key, type, config_values[i].type);
return 0;
}
}
LOG(1, 0, 0, 0, "plugin requested unknown config item \"%s\"\n", key);
return 0;
}
void add_plugin(char *plugin_name) void add_plugin(char *plugin_name)
{ {
static struct pluginfuncs funcs = { static struct pluginfuncs funcs = {
@ -3773,6 +3797,7 @@ void add_plugin(char *plugin_name)
sessionkill, sessionkill,
radiusnew, radiusnew,
radiussend, radiussend,
getconfig,
}; };
void *p = open_plugin(plugin_name, 1); void *p = open_plugin(plugin_name, 1);

View file

@ -1,5 +1,5 @@
// L2TPNS Global Stuff // L2TPNS Global Stuff
// $Id: l2tpns.h,v 1.30 2004/11/05 04:55:27 bodea Exp $ // $Id: l2tpns.h,v 1.31 2004/11/09 08:05:02 bodea Exp $
#ifndef __L2TPNS_H__ #ifndef __L2TPNS_H__
#define __L2TPNS_H__ #define __L2TPNS_H__
@ -466,12 +466,13 @@ struct configt
#endif #endif
}; };
enum config_typet { INT, STRING, UNSIGNED_LONG, SHORT, BOOL, IP, MAC };
struct config_descriptt struct config_descriptt
{ {
char *key; char *key;
int offset; int offset;
int size; int size;
enum { INT, STRING, UNSIGNED_LONG, SHORT, BOOL, IP, MAC } type; enum config_typet type;
}; };
// arp.c // arp.c

View file

@ -1,6 +1,6 @@
Summary: A high-speed clustered L2TP LNS Summary: A high-speed clustered L2TP LNS
Name: l2tpns Name: l2tpns
Version: 2.0.4 Version: 2.0.5
Release: 1 Release: 1
Copyright: GPL Copyright: GPL
Group: System Environment/Daemons Group: System Environment/Daemons
@ -41,8 +41,11 @@ rm -rf %{buildroot}
%attr(755,root,root) /usr/lib/l2tpns %attr(755,root,root) /usr/lib/l2tpns
%changelog %changelog
* Tue Nov 9 2004 Brendan O'Dea <bod@optusnet.com.au> 2.0.5
- 2.0.5 release, see /usr/share/doc/l2tpns-2.0.5/Changes
* Mon Nov 8 2004 Brendan O'Dea <bod@optusnet.com.au> 2.0.4 * Mon Nov 8 2004 Brendan O'Dea <bod@optusnet.com.au> 2.0.4
- 2.0.4 release, see /usr/share/doc/l2tpns-2.0.4/Changes - 2.0.4 release
* Wed Nov 3 2004 Brendan O'Dea <bod@optusnet.com.au> 2.0.3 * Wed Nov 3 2004 Brendan O'Dea <bod@optusnet.com.au> 2.0.3
- 2.0.3 release - 2.0.3 release

View file

@ -1,7 +1,7 @@
#ifndef __PLUGIN_H__ #ifndef __PLUGIN_H__
#define __PLUGIN_H__ #define __PLUGIN_H__
#define PLUGIN_API_VERSION 1 #define PLUGIN_API_VERSION 2
#define MAX_PLUGIN_TYPES 30 #define MAX_PLUGIN_TYPES 30
enum enum
@ -34,6 +34,7 @@ struct pluginfuncs
void (*sessionkill)(sessionidt s, char *reason); void (*sessionkill)(sessionidt s, char *reason);
u16 (*radiusnew)(sessionidt s); u16 (*radiusnew)(sessionidt s);
void (*radiussend)(u16 r, u8 state); void (*radiussend)(u16 r, u8 state);
void *(*getconfig)(char *key, enum config_typet type);
}; };
struct param_pre_auth struct param_pre_auth
@ -76,12 +77,6 @@ struct param_timer
time_t time_now; time_t time_now;
}; };
struct param_config
{
char *key;
char *value;
};
struct param_control struct param_control
{ {
char *buf; char *buf;

View file

@ -4,9 +4,9 @@
/* fudge up session rx speed if not set */ /* fudge up session rx speed if not set */
char const *cvs_id = "$Id: setrxspeed.c,v 1.1 2004/11/05 02:38:59 bodea Exp $"; char const *cvs_id = "$Id: setrxspeed.c,v 1.2 2004/11/09 08:05:03 bodea Exp $";
int __plugin_api_version = 1; int __plugin_api_version = PLUGIN_API_VERSION;
static struct pluginfuncs *p = 0; static struct pluginfuncs *p = 0;
int plugin_post_auth(struct param_post_auth *data) int plugin_post_auth(struct param_post_auth *data)

View file

@ -4,9 +4,9 @@
/* strip domain part of username before sending RADIUS requests */ /* strip domain part of username before sending RADIUS requests */
char const *cvs_id = "$Id: stripdomain.c,v 1.4 2004/11/05 04:55:27 bodea Exp $"; char const *cvs_id = "$Id: stripdomain.c,v 1.5 2004/11/09 08:05:03 bodea Exp $";
int __plugin_api_version = 1; int __plugin_api_version = PLUGIN_API_VERSION;
static struct pluginfuncs *p = 0; static struct pluginfuncs *p = 0;
int plugin_pre_auth(struct param_pre_auth *data) int plugin_pre_auth(struct param_pre_auth *data)