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"
|
2008-10-24 08:06:22 +00:00
|
|
|
|
|
|
|
#include <daemon.h>
|
|
|
|
#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;
|
2008-10-24 08:06:22 +00:00
|
|
|
};
|
|
|
|
|
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);
|
2009-09-22 15:10:25 +00:00
|
|
|
charon->bus->remove_listener(charon->bus, &this->segments->listener);
|
2008-11-12 13:28:18 +00:00
|
|
|
charon->bus->remove_listener(charon->bus, &this->ike->listener);
|
2008-10-24 12:42:06 +00:00
|
|
|
charon->bus->remove_listener(charon->bus, &this->child->listener);
|
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-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,
|
2009-09-29 10:56:10 +00:00
|
|
|
"charon.plugins.ha.local", NULL);
|
2009-09-15 12:52:56 +00:00
|
|
|
remote = lib->settings->get_str(lib->settings,
|
2009-09-29 10:56:10 +00:00
|
|
|
"charon.plugins.ha.remote", NULL);
|
2009-09-15 12:52:56 +00:00
|
|
|
secret = lib->settings->get_str(lib->settings,
|
2009-09-29 10:56:10 +00:00
|
|
|
"charon.plugins.ha.secret", NULL);
|
2009-09-15 12:52:56 +00:00
|
|
|
fifo = lib->settings->get_bool(lib->settings,
|
2009-09-30 14:23:58 +00:00
|
|
|
"charon.plugins.ha.fifo_interface", TRUE);
|
|
|
|
monitor = lib->settings->get_bool(lib->settings,
|
|
|
|
"charon.plugins.ha.monitor", TRUE);
|
|
|
|
resync = lib->settings->get_bool(lib->settings,
|
|
|
|
"charon.plugins.ha.resync", TRUE);
|
2009-09-22 12:53:03 +00:00
|
|
|
count = min(SEGMENTS_MAX, lib->settings->get_int(lib->settings,
|
2009-09-29 10:56:10 +00:00
|
|
|
"charon.plugins.ha.segment_count", 1));
|
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;
|
|
|
|
}
|
|
|
|
|
2010-07-22 09:42:22 +00:00
|
|
|
INIT(this,
|
|
|
|
.public.plugin.destroy = _destroy,
|
|
|
|
);
|
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-22 16:54:35 +00:00
|
|
|
this->dispatcher = ha_dispatcher_create(this->socket, this->segments,
|
|
|
|
this->cache);
|
|
|
|
this->ike = ha_ike_create(this->socket, this->tunnel, this->cache);
|
|
|
|
this->child = ha_child_create(this->socket, this->tunnel, this->cache);
|
2009-09-22 15:10:25 +00:00
|
|
|
charon->bus->add_listener(charon->bus, &this->segments->listener);
|
2009-09-15 12:52:56 +00:00
|
|
|
charon->bus->add_listener(charon->bus, &this->ike->listener);
|
|
|
|
charon->bus->add_listener(charon->bus, &this->child->listener);
|
2008-10-24 08:06:22 +00:00
|
|
|
|
|
|
|
return &this->public.plugin;
|
|
|
|
}
|
|
|
|
|