From f0aa42be0448d59684f9aa46caf7a4354b6b4f72 Mon Sep 17 00:00:00 2001 From: Brendan O'Dea Date: Tue, 10 May 2005 06:44:11 +0000 Subject: [PATCH 1/1] add sessionctl --- Changes | 3 +- Makefile | 13 ++++--- etc/startup-config.default | 3 +- l2tpns.spec | 2 +- plugin.h | 3 +- sessionctl.c | 78 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 92 insertions(+), 10 deletions(-) create mode 100644 sessionctl.c diff --git a/Changes b/Changes index 414cfbb..fda010e 100644 --- a/Changes +++ b/Changes @@ -1,4 +1,4 @@ -* Mon May 9 2005 Brendan O'Dea 2.1.0 +* Tue May 10 2005 Brendan O'Dea 2.1.0 - Add IPv6 support from Jonathan McDowell. - Add CHAP support from Jordan Hrycaj. - Add interim accounting support from Vladislav Bjelic. @@ -60,6 +60,7 @@ master kills all slaves once restarted). - Make "show running-config" a privileged command (contains clear text shared secrets). +- Add sessionctl plugin to provide drop/kill via nsctl. * Fri Dec 17 2004 Brendan O'Dea 2.0.13 - Better cluster master collision resolution: keep a counter of state diff --git a/Makefile b/Makefile index fd33fc0..8515c86 100644 --- a/Makefile +++ b/Makefile @@ -29,8 +29,8 @@ OBJS = arp.o cli.o cluster.o constants.o control.o icmp.o l2tpns.o \ ll.o md5.o ppp.o radius.o tbf.o util.o PROGRAMS = l2tpns nsctl -PLUGINS = garden.so throttlectl.so autothrottle.so snoopctl.so \ - autosnoop.so stripdomain.so setrxspeed.so +PLUGINS = autosnoop.so autothrottle.so garden.so sessionctl.so \ + setrxspeed.so snoopctl.so stripdomain.so throttlectl.so TESTS = generateload bounce @@ -127,10 +127,11 @@ radius.o: radius.c md5.h constants.h l2tpns.h plugin.h util.h tbf.o: tbf.c l2tpns.h util.h tbf.h util.o: util.c l2tpns.h bgp.h bgp.o: bgp.c l2tpns.h bgp.h util.h -garden.so: garden.c l2tpns.h plugin.h control.h -throttlectl.so: throttlectl.c l2tpns.h plugin.h control.h +autosnoop.so: autosnoop.c l2tpns.h plugin.h autothrottle.so: autothrottle.c l2tpns.h plugin.h +garden.so: garden.c l2tpns.h plugin.h control.h +sessionctl.so: sessionctl.c l2tpns.h plugin.h control.h +setrxspeed.so: setrxspeed.c l2tpns.h plugin.h snoopctl.so: snoopctl.c l2tpns.h plugin.h control.h -autosnoop.so: autosnoop.c l2tpns.h plugin.h stripdomain.so: stripdomain.c l2tpns.h plugin.h -setrxspeed.so: setrxspeed.c l2tpns.h plugin.h +throttlectl.so: throttlectl.c l2tpns.h plugin.h control.h diff --git a/etc/startup-config.default b/etc/startup-config.default index 6ec4011..a182c17 100644 --- a/etc/startup-config.default +++ b/etc/startup-config.default @@ -13,8 +13,9 @@ set throttle_speed 64 set accounting_dir "/var/run/l2tpns/acct" set setuid 0 set dump_speed no -load plugin "garden" +load plugin "sessionctl" load plugin "throttlectl" load plugin "autothrottle" load plugin "snoopctl" load plugin "autosnoop" +load plugin "garden" diff --git a/l2tpns.spec b/l2tpns.spec index 64ebd47..e214492 100644 --- a/l2tpns.spec +++ b/l2tpns.spec @@ -43,5 +43,5 @@ rm -rf %{buildroot} %attr(644,root,root) /usr/share/man/man[58]/* %changelog -* Mon May 9 2005 Brendan O'Dea 2.1.0-1 +* Tue May 10 2005 Brendan O'Dea 2.1.0-1 - 2.1.0 release, see /usr/share/doc/l2tpns-2.1.0/Changes diff --git a/plugin.h b/plugin.h index ca0368f..dcae48d 100644 --- a/plugin.h +++ b/plugin.h @@ -1,7 +1,7 @@ #ifndef __PLUGIN_H__ #define __PLUGIN_H__ -#define PLUGIN_API_VERSION 4 +#define PLUGIN_API_VERSION 5 #define MAX_PLUGIN_TYPES 30 enum @@ -35,6 +35,7 @@ struct pluginfuncs uint16_t (*radiusnew)(sessionidt s); void (*radiussend)(uint16_t r, uint8_t state); void *(*getconfig)(char *key, enum config_typet type); + void (*sessionshutdown)(sessionidt s, char *reason, int result, int error); void (*sessionkill)(sessionidt s, char *reason); void (*throttle)(sessionidt s, int rate_in, int rate_out); int (*session_changed)(int sid); diff --git a/sessionctl.c b/sessionctl.c new file mode 100644 index 0000000..a02bcf0 --- /dev/null +++ b/sessionctl.c @@ -0,0 +1,78 @@ +#include +#include "l2tpns.h" +#include "plugin.h" +#include "control.h" + +/* session control */ + +char const *cvs_id = "$Id: sessionctl.c,v 1.1 2005-05-10 06:44:11 bodea Exp $"; + +int plugin_api_version = PLUGIN_API_VERSION; +static struct pluginfuncs *p = 0; + +char *plugin_control_help[] = { + " drop USER|SID [REASON] Shutdown user session", + " kill USER|SID [REASON] Kill user session", + 0 +}; + +int plugin_init(struct pluginfuncs *funcs) +{ + if (!funcs) + return 0; + + p = funcs; + return 1; +} + +int plugin_control(struct param_control *data) +{ + sessionidt session; + sessiont *s = 0; + char *end; + char *reason; + + if (data->argc < 1) + return PLUGIN_RET_OK; + + if (strcmp(data->argv[0], "drop") && strcmp(data->argv[0], "kill")) + return PLUGIN_RET_OK; // not for us + + if (!data->iam_master) + return PLUGIN_RET_NOTMASTER; + + if (data->argc < 2 || data->argc > 3) + { + data->response = NSCTL_RES_ERR; + data->additional = "requires username or session id and optional reason"; + return PLUGIN_RET_STOP; + } + + if (!(session = strtol(data->argv[1], &end, 10)) || *end) + session = p->get_session_by_username(data->argv[1]); + + if (session) + s = p->get_session_by_id(session); + + if (!s || !s->ip) + { + data->response = NSCTL_RES_ERR; + data->additional = "session not found"; + return PLUGIN_RET_STOP; + } + + if (data->argc > 2) + reason = data->argv[2]; + else + reaons = "Requested by administrator."; + + if (data->argv[0][0] == 'd') + p->sessionshutdown(session, reason, 3, 0); + else + p->sessionkill(session, reason); + + data->response = NSCTL_RES_OK; + data->additional = 0; + + return PLUGIN_RET_STOP; +} -- 2.20.1