pass cluster master state to plugin_control functions
This commit is contained in:
parent
1045897706
commit
c79eb06333
5 changed files with 54 additions and 51 deletions
14
garden.c
14
garden.c
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
/* walled garden */
|
||||
|
||||
char const *cvs_id = "$Id: garden.c,v 1.15 2004-11-18 05:44:36 bodea Exp $";
|
||||
char const *cvs_id = "$Id: garden.c,v 1.16 2004-11-18 06:41:03 bodea Exp $";
|
||||
|
||||
int plugin_api_version = PLUGIN_API_VERSION;
|
||||
static struct pluginfuncs *p = 0;
|
||||
|
|
@ -77,7 +77,7 @@ int plugin_kill_session(struct param_new_session *data)
|
|||
|
||||
char *plugin_control_help[] = {
|
||||
" garden USER|SID Put user into the walled garden",
|
||||
" ungarden USER|SID Release user from garden",
|
||||
" ungarden SID Release session from garden",
|
||||
0
|
||||
};
|
||||
|
||||
|
|
@ -94,14 +94,10 @@ int plugin_control(struct param_control *data)
|
|||
if (strcmp(data->argv[0], "garden") && strcmp(data->argv[0], "ungarden"))
|
||||
return PLUGIN_RET_OK; // not for us
|
||||
|
||||
flag = data->argv[0][0] != 'u';
|
||||
if (!iam_master)
|
||||
return PLUGIN_RET_NOTMASTER;
|
||||
|
||||
if (!iam_master) // All garden processing happens on the master.
|
||||
{
|
||||
data->response = NSCTL_RES_ERR;
|
||||
data->additional = "must be run on the cluster master";
|
||||
return PLUGIN_RET_STOP;
|
||||
}
|
||||
flag = data->argv[0][0] != 'u';
|
||||
|
||||
if (data->argc != 2)
|
||||
{
|
||||
|
|
|
|||
46
l2tpns.c
46
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.52 2004-11-17 15:08:19 bodea Exp $";
|
||||
char const *cvs_id_l2tpns = "$Id: l2tpns.c,v 1.53 2004-11-18 06:41:03 bodea Exp $";
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <assert.h>
|
||||
|
|
@ -3859,17 +3859,20 @@ static int remove_plugin(char *plugin_name)
|
|||
int run_plugins(int plugin_type, void *data)
|
||||
{
|
||||
int (*func)(void *data);
|
||||
if (!plugins[plugin_type] || plugin_type > max_plugin_functions) return 1;
|
||||
|
||||
if (!plugins[plugin_type] || plugin_type > max_plugin_functions)
|
||||
return PLUGIN_RET_ERROR;
|
||||
|
||||
ll_reset(plugins[plugin_type]);
|
||||
while ((func = ll_next(plugins[plugin_type])))
|
||||
{
|
||||
int rc;
|
||||
rc = func(data);
|
||||
if (rc == PLUGIN_RET_STOP) return 1;
|
||||
if (rc == PLUGIN_RET_ERROR) return 0;
|
||||
int r = func(data);
|
||||
|
||||
if (r != PLUGIN_RET_OK)
|
||||
return r; // stop here
|
||||
}
|
||||
return 1;
|
||||
|
||||
return PLUGIN_RET_OK;
|
||||
}
|
||||
|
||||
static void plugins_done()
|
||||
|
|
@ -3966,8 +3969,17 @@ static void processcontrol(u8 * buf, int len, struct sockaddr_in *addr, int alen
|
|||
|
||||
case NSCTL_REQ_CONTROL:
|
||||
{
|
||||
struct param_control param = { request.argc, request.argv, 0, NULL };
|
||||
if (!run_plugins(PLUGIN_CONTROL, ¶m))
|
||||
struct param_control param = {
|
||||
config->cluster_iam_master,
|
||||
request.argc,
|
||||
request.argv,
|
||||
0,
|
||||
NULL,
|
||||
};
|
||||
|
||||
int r = run_plugins(PLUGIN_CONTROL, ¶m);
|
||||
|
||||
if (r == PLUGIN_RET_ERROR)
|
||||
{
|
||||
response.type = NSCTL_RES_ERR;
|
||||
response.argc = 1;
|
||||
|
|
@ -3975,6 +3987,22 @@ static void processcontrol(u8 * buf, int len, struct sockaddr_in *addr, int alen
|
|||
? param.additional
|
||||
: "error returned by plugin";
|
||||
}
|
||||
else if (r == PLUGIN_RET_NOTMASTER)
|
||||
{
|
||||
static char msg[] = "must be run on master: 000.000.000.000";
|
||||
|
||||
response.type = NSCTL_RES_ERR;
|
||||
response.argc = 1;
|
||||
if (config->cluster_master_address)
|
||||
{
|
||||
strcpy(msg + 23, inet_toa(config->cluster_master_address));
|
||||
response.argv[0] = msg;
|
||||
}
|
||||
else
|
||||
{
|
||||
response.argv[0] = "must be run on master: none elected";
|
||||
}
|
||||
}
|
||||
else if (!(param.response & NSCTL_RESPONSE))
|
||||
{
|
||||
response.type = NSCTL_RES_ERR;
|
||||
|
|
|
|||
5
plugin.h
5
plugin.h
|
|
@ -21,7 +21,8 @@ enum
|
|||
|
||||
#define PLUGIN_RET_ERROR 0
|
||||
#define PLUGIN_RET_OK 1
|
||||
#define PLUGIN_RET_STOP 2
|
||||
#define PLUGIN_RET_STOP 2
|
||||
#define PLUGIN_RET_NOTMASTER 3
|
||||
|
||||
struct pluginfuncs
|
||||
{
|
||||
|
|
@ -81,8 +82,10 @@ struct param_timer
|
|||
|
||||
struct param_control
|
||||
{
|
||||
int iam_master;
|
||||
int argc;
|
||||
char **argv;
|
||||
// output
|
||||
int response;
|
||||
char *additional;
|
||||
};
|
||||
|
|
|
|||
20
snoopctl.c
20
snoopctl.c
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
/* snoop control */
|
||||
|
||||
char const *cvs_id = "$Id: snoopctl.c,v 1.2 2004-11-18 05:44:36 bodea Exp $";
|
||||
char const *cvs_id = "$Id: snoopctl.c,v 1.3 2004-11-18 06:41:03 bodea Exp $";
|
||||
|
||||
int plugin_api_version = PLUGIN_API_VERSION;
|
||||
static struct pluginfuncs *p = 0;
|
||||
|
|
@ -16,8 +16,6 @@ char *plugin_control_help[] = {
|
|||
0
|
||||
};
|
||||
|
||||
static int iam_master = 0;
|
||||
|
||||
int plugin_init(struct pluginfuncs *funcs)
|
||||
{
|
||||
if (!funcs)
|
||||
|
|
@ -27,12 +25,6 @@ int plugin_init(struct pluginfuncs *funcs)
|
|||
return 1;
|
||||
}
|
||||
|
||||
int plugin_become_master(void)
|
||||
{
|
||||
iam_master = 1;
|
||||
return PLUGIN_RET_OK;
|
||||
}
|
||||
|
||||
int plugin_control(struct param_control *data)
|
||||
{
|
||||
sessionidt session;
|
||||
|
|
@ -46,14 +38,10 @@ int plugin_control(struct param_control *data)
|
|||
if (strcmp(data->argv[0], "snoop") && strcmp(data->argv[0], "unsnoop"))
|
||||
return PLUGIN_RET_OK; // not for us
|
||||
|
||||
flag = data->argv[0][0] != 'u';
|
||||
if (!data->iam_master)
|
||||
return PLUGIN_RET_NOTMASTER;
|
||||
|
||||
if (!iam_master)
|
||||
{
|
||||
data->response = NSCTL_RES_ERR;
|
||||
data->additional = "must be run on the cluster master";
|
||||
return PLUGIN_RET_STOP;
|
||||
}
|
||||
flag = data->argv[0][0] != 'u';
|
||||
|
||||
if (flag)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
/* throttle control */
|
||||
|
||||
char const *cvs_id = "$Id: throttlectl.c,v 1.2 2004-11-18 05:44:36 bodea Exp $";
|
||||
char const *cvs_id = "$Id: throttlectl.c,v 1.3 2004-11-18 06:41:03 bodea Exp $";
|
||||
|
||||
int plugin_api_version = PLUGIN_API_VERSION;
|
||||
static struct pluginfuncs *p = 0;
|
||||
|
|
@ -16,8 +16,6 @@ char *plugin_control_help[] = {
|
|||
0
|
||||
};
|
||||
|
||||
static int iam_master = 0;
|
||||
|
||||
int plugin_init(struct pluginfuncs *funcs)
|
||||
{
|
||||
if (!funcs)
|
||||
|
|
@ -27,12 +25,6 @@ int plugin_init(struct pluginfuncs *funcs)
|
|||
return 1;
|
||||
}
|
||||
|
||||
int plugin_become_master(void)
|
||||
{
|
||||
iam_master = 1;
|
||||
return PLUGIN_RET_OK;
|
||||
}
|
||||
|
||||
int plugin_control(struct param_control *data)
|
||||
{
|
||||
sessionidt session;
|
||||
|
|
@ -49,14 +41,10 @@ int plugin_control(struct param_control *data)
|
|||
&& strcmp(data->argv[0], "unthrottle"))
|
||||
return PLUGIN_RET_OK; // not for us
|
||||
|
||||
flag = data->argv[0][0] != 'g';
|
||||
if (!data->iam_master)
|
||||
return PLUGIN_RET_NOTMASTER;
|
||||
|
||||
if (!iam_master)
|
||||
{
|
||||
data->response = NSCTL_RES_ERR;
|
||||
data->additional = "must be run on the cluster master";
|
||||
return PLUGIN_RET_STOP;
|
||||
}
|
||||
flag = data->argv[0][0] != 'g';
|
||||
|
||||
if (flag)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue