2008-10-24 08:06:22 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2008 Martin Willi
|
|
|
|
* Hochschule fuer Technik Rapperswil
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2009-09-29 10:56:10 +00:00
|
|
|
#include "ha_plugin.h"
|
|
|
|
#include "ha_ike.h"
|
|
|
|
#include "ha_child.h"
|
|
|
|
#include "ha_socket.h"
|
|
|
|
#include "ha_tunnel.h"
|
|
|
|
#include "ha_dispatcher.h"
|
|
|
|
#include "ha_segments.h"
|
|
|
|
#include "ha_ctl.h"
|
2010-07-22 16:54:35 +00:00
|
|
|
#include "ha_cache.h"
|
2010-07-28 07:51:41 +00:00
|
|
|
#include "ha_attribute.h"
|
2008-10-24 08:06:22 +00:00
|
|
|
|
|
|
|
#include <daemon.h>
|
2010-07-28 07:51:41 +00:00
|
|
|
#include <hydra.h>
|
2008-10-24 08:06:22 +00:00
|
|
|
#include <config/child_cfg.h>
|
|
|
|
|
2009-09-29 10:56:10 +00:00
|
|
|
typedef struct private_ha_plugin_t private_ha_plugin_t;
|
2008-10-24 08:06:22 +00:00
|
|
|
|
|
|
|
/**
|
2009-09-29 10:56:10 +00:00
|
|
|
* private data of ha plugin
|
2008-10-24 08:06:22 +00:00
|
|
|
*/
|
2009-09-29 10:56:10 +00:00
|
|
|
struct private_ha_plugin_t {
|
2008-10-24 08:06:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* implements plugin interface
|
|
|
|
*/
|
2009-09-29 10:56:10 +00:00
|
|
|
ha_plugin_t public;
|
2008-10-24 08:06:22 +00:00
|
|
|
|
|
|
|
/**
|
2008-11-12 13:28:18 +00:00
|
|
|
* Communication socket
|
|
|
|
*/
|
2009-09-29 10:56:10 +00:00
|
|
|
ha_socket_t *socket;
|
2008-11-12 13:28:18 +00:00
|
|
|
|
2009-09-15 12:52:56 +00:00
|
|
|
/**
|
|
|
|
* Tunnel securing sync messages.
|
|
|
|
*/
|
2009-09-29 10:56:10 +00:00
|
|
|
ha_tunnel_t *tunnel;
|
2009-09-15 12:52:56 +00:00
|
|
|
|
2008-11-12 13:28:18 +00:00
|
|
|
/**
|
|
|
|
* IKE_SA synchronization
|
|
|
|
*/
|
2009-09-29 10:56:10 +00:00
|
|
|
ha_ike_t *ike;
|
2008-11-12 13:28:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* CHILD_SA synchronization
|
2008-10-24 08:06:22 +00:00
|
|
|
*/
|
2009-09-29 10:56:10 +00:00
|
|
|
ha_child_t *child;
|
2008-11-13 16:01:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Dispatcher to process incoming messages
|
|
|
|
*/
|
2009-09-29 10:56:10 +00:00
|
|
|
ha_dispatcher_t *dispatcher;
|
2008-11-17 15:58:39 +00:00
|
|
|
|
|
|
|
/**
|
2008-11-28 15:45:17 +00:00
|
|
|
* Active/Passive segment management
|
2008-11-17 15:58:39 +00:00
|
|
|
*/
|
2009-09-29 10:56:10 +00:00
|
|
|
ha_segments_t *segments;
|
2008-11-27 09:57:31 +00:00
|
|
|
|
2009-09-22 13:19:43 +00:00
|
|
|
/**
|
|
|
|
* Interface to control segments at kernel level
|
|
|
|
*/
|
2009-09-29 10:56:10 +00:00
|
|
|
ha_kernel_t *kernel;
|
2009-09-22 13:19:43 +00:00
|
|
|
|
2008-11-27 09:57:31 +00:00
|
|
|
/**
|
|
|
|
* Segment control interface via FIFO
|
|
|
|
*/
|
2009-09-29 10:56:10 +00:00
|
|
|
ha_ctl_t *ctl;
|
2010-07-22 16:54:35 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Message cache for resynchronization
|
|
|
|
*/
|
|
|
|
ha_cache_t *cache;
|
2010-07-28 07:51:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Attribute provider
|
|
|
|
*/
|
|
|
|
ha_attribute_t *attr;
|
2008-10-24 08:06:22 +00:00
|
|
|
};
|
|
|
|
|
2011-04-11 16:54:18 +00:00
|
|
|
METHOD(plugin_t, get_name, char*,
|
|
|
|
private_ha_plugin_t *this)
|
|
|
|
{
|
|
|
|
return "ha";
|
|
|
|
}
|
|
|
|
|
2013-06-07 15:58:12 +00:00
|
|
|
/**
|
|
|
|
* Register listener
|
|
|
|
*/
|
|
|
|
static bool plugin_cb(private_ha_plugin_t *this,
|
|
|
|
plugin_feature_t *feature, bool reg, void *cb_data)
|
|
|
|
{
|
|
|
|
if (reg)
|
|
|
|
{
|
|
|
|
charon->bus->add_listener(charon->bus, &this->segments->listener);
|
|
|
|
charon->bus->add_listener(charon->bus, &this->ike->listener);
|
|
|
|
charon->bus->add_listener(charon->bus, &this->child->listener);
|
|
|
|
hydra->attributes->add_provider(hydra->attributes,
|
|
|
|
&this->attr->provider);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hydra->attributes->remove_provider(hydra->attributes,
|
|
|
|
&this->attr->provider);
|
|
|
|
charon->bus->remove_listener(charon->bus, &this->segments->listener);
|
|
|
|
charon->bus->remove_listener(charon->bus, &this->ike->listener);
|
|
|
|
charon->bus->remove_listener(charon->bus, &this->child->listener);
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
METHOD(plugin_t, get_features, int,
|
|
|
|
private_ha_plugin_t *this, plugin_feature_t *features[])
|
|
|
|
{
|
|
|
|
static plugin_feature_t f[] = {
|
|
|
|
PLUGIN_CALLBACK((plugin_feature_callback_t)plugin_cb, NULL),
|
|
|
|
PLUGIN_PROVIDE(CUSTOM, "ha"),
|
|
|
|
};
|
|
|
|
*features = f;
|
|
|
|
return countof(f);
|
|
|
|
}
|
|
|
|
|
2010-07-22 09:42:22 +00:00
|
|
|
METHOD(plugin_t, destroy, void,
|
|
|
|
private_ha_plugin_t *this)
|
2008-10-24 08:06:22 +00:00
|
|
|
{
|
2009-09-15 12:52:56 +00:00
|
|
|
DESTROY_IF(this->ctl);
|
2008-11-12 13:28:18 +00:00
|
|
|
this->ike->destroy(this->ike);
|
2008-10-24 12:42:06 +00:00
|
|
|
this->child->destroy(this->child);
|
2008-11-13 16:01:06 +00:00
|
|
|
this->dispatcher->destroy(this->dispatcher);
|
2010-07-28 07:51:41 +00:00
|
|
|
this->attr->destroy(this->attr);
|
2010-07-22 16:54:35 +00:00
|
|
|
this->cache->destroy(this->cache);
|
2008-11-28 15:45:17 +00:00
|
|
|
this->segments->destroy(this->segments);
|
2009-09-22 13:19:43 +00:00
|
|
|
this->kernel->destroy(this->kernel);
|
2008-11-12 13:28:18 +00:00
|
|
|
this->socket->destroy(this->socket);
|
2009-09-15 12:52:56 +00:00
|
|
|
DESTROY_IF(this->tunnel);
|
2008-10-24 08:06:22 +00:00
|
|
|
free(this);
|
|
|
|
}
|
|
|
|
|
2010-03-22 10:25:27 +00:00
|
|
|
/**
|
|
|
|
* Plugin constructor
|
2008-10-24 08:06:22 +00:00
|
|
|
*/
|
2010-03-22 10:25:27 +00:00
|
|
|
plugin_t *ha_plugin_create()
|
2008-10-24 08:06:22 +00:00
|
|
|
{
|
2009-09-29 10:56:10 +00:00
|
|
|
private_ha_plugin_t *this;
|
2009-09-29 14:05:46 +00:00
|
|
|
char *local, *remote, *secret;
|
2009-09-22 12:53:03 +00:00
|
|
|
u_int count;
|
2009-09-30 14:23:58 +00:00
|
|
|
bool fifo, monitor, resync;
|
2009-09-15 12:52:56 +00:00
|
|
|
|
|
|
|
local = lib->settings->get_str(lib->settings,
|
2012-04-24 12:10:06 +00:00
|
|
|
"%s.plugins.ha.local", NULL, charon->name);
|
2009-09-15 12:52:56 +00:00
|
|
|
remote = lib->settings->get_str(lib->settings,
|
2012-04-24 12:10:06 +00:00
|
|
|
"%s.plugins.ha.remote", NULL, charon->name);
|
2009-09-15 12:52:56 +00:00
|
|
|
secret = lib->settings->get_str(lib->settings,
|
2012-04-24 12:10:06 +00:00
|
|
|
"%s.plugins.ha.secret", NULL, charon->name);
|
2009-09-15 12:52:56 +00:00
|
|
|
fifo = lib->settings->get_bool(lib->settings,
|
2012-04-24 12:10:06 +00:00
|
|
|
"%s.plugins.ha.fifo_interface", TRUE, charon->name);
|
2009-09-30 14:23:58 +00:00
|
|
|
monitor = lib->settings->get_bool(lib->settings,
|
2012-04-24 12:10:06 +00:00
|
|
|
"%s.plugins.ha.monitor", TRUE, charon->name);
|
2009-09-30 14:23:58 +00:00
|
|
|
resync = lib->settings->get_bool(lib->settings,
|
2012-04-24 12:10:06 +00:00
|
|
|
"%s.plugins.ha.resync", TRUE, charon->name);
|
2009-09-22 12:53:03 +00:00
|
|
|
count = min(SEGMENTS_MAX, lib->settings->get_int(lib->settings,
|
2012-04-24 12:10:06 +00:00
|
|
|
"%s.plugins.ha.segment_count", 1, charon->name));
|
2009-09-15 12:52:56 +00:00
|
|
|
if (!local || !remote)
|
|
|
|
{
|
2009-09-29 10:56:10 +00:00
|
|
|
DBG1(DBG_CFG, "HA config misses local/remote address");
|
2009-09-15 12:52:56 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-06-25 07:03:00 +00:00
|
|
|
if (!lib->caps->keep(lib->caps, CAP_CHOWN))
|
2013-07-08 16:24:43 +00:00
|
|
|
{ /* required to chown(2) control socket, ha_kernel also needs it at
|
|
|
|
* runtime */
|
2013-06-25 07:03:00 +00:00
|
|
|
DBG1(DBG_CFG, "ha plugin requires CAP_CHOWN capability");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-07-22 09:42:22 +00:00
|
|
|
INIT(this,
|
2010-08-18 10:15:03 +00:00
|
|
|
.public = {
|
|
|
|
.plugin = {
|
2011-04-11 16:54:18 +00:00
|
|
|
.get_name = _get_name,
|
2013-06-07 15:58:12 +00:00
|
|
|
.get_features = _get_features,
|
2010-08-18 10:15:03 +00:00
|
|
|
.destroy = _destroy,
|
|
|
|
},
|
|
|
|
},
|
2010-07-22 09:42:22 +00:00
|
|
|
);
|
2008-10-24 08:06:22 +00:00
|
|
|
|
2009-09-30 14:23:58 +00:00
|
|
|
if (secret)
|
|
|
|
{
|
|
|
|
this->tunnel = ha_tunnel_create(local, remote, secret);
|
|
|
|
}
|
2009-09-29 10:56:10 +00:00
|
|
|
this->socket = ha_socket_create(local, remote);
|
2008-11-12 13:28:18 +00:00
|
|
|
if (!this->socket)
|
|
|
|
{
|
2009-09-30 14:23:58 +00:00
|
|
|
DESTROY_IF(this->tunnel);
|
2008-11-12 13:28:18 +00:00
|
|
|
free(this);
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-09-29 14:05:46 +00:00
|
|
|
this->kernel = ha_kernel_create(count);
|
2009-09-30 14:23:58 +00:00
|
|
|
this->segments = ha_segments_create(this->socket, this->kernel, this->tunnel,
|
2010-07-22 16:54:35 +00:00
|
|
|
count, strcmp(local, remote) > 0, monitor);
|
|
|
|
this->cache = ha_cache_create(this->kernel, this->socket, resync, count);
|
2009-09-15 12:52:56 +00:00
|
|
|
if (fifo)
|
2009-09-15 11:53:06 +00:00
|
|
|
{
|
2010-07-22 16:54:35 +00:00
|
|
|
this->ctl = ha_ctl_create(this->segments, this->cache);
|
2009-09-15 11:53:06 +00:00
|
|
|
}
|
2010-07-28 07:51:41 +00:00
|
|
|
this->attr = ha_attribute_create(this->kernel, this->segments);
|
2010-07-22 16:54:35 +00:00
|
|
|
this->dispatcher = ha_dispatcher_create(this->socket, this->segments,
|
2010-07-28 07:51:41 +00:00
|
|
|
this->cache, this->kernel, this->attr);
|
2010-07-22 16:54:35 +00:00
|
|
|
this->ike = ha_ike_create(this->socket, this->tunnel, this->cache);
|
2010-07-26 11:49:35 +00:00
|
|
|
this->child = ha_child_create(this->socket, this->tunnel, this->segments,
|
|
|
|
this->kernel);
|
2008-10-24 08:06:22 +00:00
|
|
|
|
|
|
|
return &this->public.plugin;
|
|
|
|
}
|
|
|
|
|