2008-10-16 11:48:18 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2008 Martin Willi
|
2018-05-23 14:04:50 +00:00
|
|
|
* HSR Hochschule fuer Technik Rapperswil
|
2008-10-16 11:48:18 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "updown_plugin.h"
|
2008-11-17 09:29:27 +00:00
|
|
|
#include "updown_listener.h"
|
2012-07-31 13:21:11 +00:00
|
|
|
#include "updown_handler.h"
|
2008-10-16 11:48:18 +00:00
|
|
|
|
|
|
|
#include <daemon.h>
|
|
|
|
|
|
|
|
typedef struct private_updown_plugin_t private_updown_plugin_t;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* private data of updown plugin
|
|
|
|
*/
|
|
|
|
struct private_updown_plugin_t {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* implements plugin interface
|
|
|
|
*/
|
|
|
|
updown_plugin_t public;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-10-16 11:48:18 +00:00
|
|
|
/**
|
|
|
|
* Listener interface, listens to CHILD_SA state changes
|
|
|
|
*/
|
2008-11-17 09:29:27 +00:00
|
|
|
updown_listener_t *listener;
|
2012-07-31 13:21:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Attribute handler, to pass DNS servers to updown
|
|
|
|
*/
|
|
|
|
updown_handler_t *handler;
|
2008-10-16 11:48:18 +00:00
|
|
|
};
|
|
|
|
|
2011-04-11 16:54:18 +00:00
|
|
|
METHOD(plugin_t, get_name, char*,
|
|
|
|
private_updown_plugin_t *this)
|
|
|
|
{
|
|
|
|
return "updown";
|
|
|
|
}
|
|
|
|
|
2013-06-08 08:47:38 +00:00
|
|
|
/**
|
|
|
|
* Register listener
|
|
|
|
*/
|
|
|
|
static bool plugin_cb(private_updown_plugin_t *this,
|
|
|
|
plugin_feature_t *feature, bool reg, void *cb_data)
|
2008-10-16 11:48:18 +00:00
|
|
|
{
|
2013-06-08 08:47:38 +00:00
|
|
|
if (reg)
|
2012-07-31 13:21:11 +00:00
|
|
|
{
|
2013-06-08 08:47:38 +00:00
|
|
|
if (lib->settings->get_bool(lib->settings,
|
2014-01-22 14:18:58 +00:00
|
|
|
"%s.plugins.updown.dns_handler", FALSE, lib->ns))
|
2013-06-08 08:47:38 +00:00
|
|
|
{
|
|
|
|
this->handler = updown_handler_create();
|
2014-11-04 13:45:34 +00:00
|
|
|
charon->attributes->add_handler(charon->attributes,
|
|
|
|
&this->handler->handler);
|
2013-06-08 08:47:38 +00:00
|
|
|
}
|
|
|
|
this->listener = updown_listener_create(this->handler);
|
|
|
|
charon->bus->add_listener(charon->bus, &this->listener->listener);
|
2012-07-31 13:21:11 +00:00
|
|
|
}
|
2013-06-08 08:47:38 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
charon->bus->remove_listener(charon->bus, &this->listener->listener);
|
|
|
|
this->listener->destroy(this->listener);
|
|
|
|
if (this->handler)
|
|
|
|
{
|
|
|
|
this->handler->destroy(this->handler);
|
2014-11-04 13:45:34 +00:00
|
|
|
charon->attributes->remove_handler(charon->attributes,
|
|
|
|
&this->handler->handler);
|
2013-06-08 08:47:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
METHOD(plugin_t, get_features, int,
|
|
|
|
private_updown_plugin_t *this, plugin_feature_t *features[])
|
|
|
|
{
|
|
|
|
static plugin_feature_t f[] = {
|
|
|
|
PLUGIN_CALLBACK((plugin_feature_callback_t)plugin_cb, NULL),
|
|
|
|
PLUGIN_PROVIDE(CUSTOM, "updown"),
|
|
|
|
};
|
|
|
|
*features = f;
|
|
|
|
return countof(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
METHOD(plugin_t, destroy, void,
|
|
|
|
private_updown_plugin_t *this)
|
|
|
|
{
|
2008-10-16 11:48:18 +00:00
|
|
|
free(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* see header file
|
|
|
|
*/
|
2010-02-23 15:20:38 +00:00
|
|
|
plugin_t *updown_plugin_create()
|
2008-10-16 11:48:18 +00:00
|
|
|
{
|
2011-04-11 14:41:25 +00:00
|
|
|
private_updown_plugin_t *this;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2011-04-11 14:41:25 +00:00
|
|
|
INIT(this,
|
|
|
|
.public = {
|
|
|
|
.plugin = {
|
2011-04-11 16:54:18 +00:00
|
|
|
.get_name = _get_name,
|
2013-06-08 08:47:38 +00:00
|
|
|
.get_features = _get_features,
|
2011-04-11 14:41:25 +00:00
|
|
|
.destroy = _destroy,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2008-10-16 11:48:18 +00:00
|
|
|
return &this->public.plugin;
|
|
|
|
}
|