From: bodea Date: Tue, 9 Nov 2004 08:05:01 +0000 (+0000) Subject: add a callback to allow plugins to fetch values from the running config X-Git-Tag: release_2_0_5~1 X-Git-Url: http://git.sameswireless.fr/l2tpns.git/commitdiff_plain/72346a7226a9f6b67d4f3e3f488914f691070893 add a callback to allow plugins to fetch values from the running config --- diff --git a/Changes b/Changes index 2d1c16f..17bfb80 100644 --- a/Changes +++ b/Changes @@ -1,7 +1,8 @@ -? Brendan O'Dea 2.0.5 +* Tue Nov 9 2004 Brendan O'Dea 2.0.5 - Handle routing properly in lone-master case - Fix intercepts: don't double-snoop throttled customers, ensure 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 2.0.4 - Added setrxspeed plugin diff --git a/autosnoop.c b/autosnoop.c index 797c9b9..2b17b80 100644 --- a/autosnoop.c +++ b/autosnoop.c @@ -4,9 +4,9 @@ /* 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; int plugin_radius_response(struct param_radius_response *data) diff --git a/autothrottle.c b/autothrottle.c index 167dba8..46823c3 100644 --- a/autothrottle.c +++ b/autothrottle.c @@ -4,9 +4,9 @@ /* 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; #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) { - p->log(3, 0, p->get_id_by_session(data->s), data->s->tunnel, " Throttling user\n"); - data->s->throttle_in = data->s->throttle_out = config->rl_rate; + unsigned long *rate = p->getconfig("throttle_speed", UNSIGNED_LONG); + 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) { diff --git a/garden.c b/garden.c index c6b74ec..41e46a2 100644 --- a/garden.c +++ b/garden.c @@ -9,9 +9,9 @@ /* 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 int iam_master = 0; // We're all slaves! Slaves I tell you! diff --git a/l2tpns.c b/l2tpns.c index fb380b9..5171caf 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.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 #include @@ -3469,6 +3469,7 @@ void update_config() { if (strcmp(config->plugins[i], config->old_plugins[i]) == 0) continue; + if (*config->plugins[i]) { // Plugin added @@ -3761,6 +3762,29 @@ static void *open_plugin(char *plugin_name, int load) 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) { static struct pluginfuncs funcs = { @@ -3773,6 +3797,7 @@ void add_plugin(char *plugin_name) sessionkill, radiusnew, radiussend, + getconfig, }; void *p = open_plugin(plugin_name, 1); diff --git a/l2tpns.h b/l2tpns.h index cbd455c..a5a88a0 100644 --- a/l2tpns.h +++ b/l2tpns.h @@ -1,5 +1,5 @@ // 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__ #define __L2TPNS_H__ @@ -466,12 +466,13 @@ struct configt #endif }; +enum config_typet { INT, STRING, UNSIGNED_LONG, SHORT, BOOL, IP, MAC }; struct config_descriptt { char *key; int offset; int size; - enum { INT, STRING, UNSIGNED_LONG, SHORT, BOOL, IP, MAC } type; + enum config_typet type; }; // arp.c diff --git a/l2tpns.spec b/l2tpns.spec index 0f066d9..505d2f4 100644 --- a/l2tpns.spec +++ b/l2tpns.spec @@ -1,6 +1,6 @@ Summary: A high-speed clustered L2TP LNS Name: l2tpns -Version: 2.0.4 +Version: 2.0.5 Release: 1 Copyright: GPL Group: System Environment/Daemons @@ -41,8 +41,11 @@ rm -rf %{buildroot} %attr(755,root,root) /usr/lib/l2tpns %changelog +* Tue Nov 9 2004 Brendan O'Dea 2.0.5 +- 2.0.5 release, see /usr/share/doc/l2tpns-2.0.5/Changes + * Mon Nov 8 2004 Brendan O'Dea 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 2.0.3 - 2.0.3 release diff --git a/plugin.h b/plugin.h index 0f2ed0f..be92047 100644 --- a/plugin.h +++ b/plugin.h @@ -1,7 +1,7 @@ #ifndef __PLUGIN_H__ #define __PLUGIN_H__ -#define PLUGIN_API_VERSION 1 +#define PLUGIN_API_VERSION 2 #define MAX_PLUGIN_TYPES 30 enum @@ -34,6 +34,7 @@ struct pluginfuncs void (*sessionkill)(sessionidt s, char *reason); u16 (*radiusnew)(sessionidt s); void (*radiussend)(u16 r, u8 state); + void *(*getconfig)(char *key, enum config_typet type); }; struct param_pre_auth @@ -76,12 +77,6 @@ struct param_timer time_t time_now; }; -struct param_config -{ - char *key; - char *value; -}; - struct param_control { char *buf; diff --git a/setrxspeed.c b/setrxspeed.c index 2035ca4..49a1a2b 100644 --- a/setrxspeed.c +++ b/setrxspeed.c @@ -4,9 +4,9 @@ /* 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; int plugin_post_auth(struct param_post_auth *data) diff --git a/stripdomain.c b/stripdomain.c index 8701a0c..ad4a39c 100644 --- a/stripdomain.c +++ b/stripdomain.c @@ -4,9 +4,9 @@ /* 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; int plugin_pre_auth(struct param_pre_auth *data)