strongswan/src/libcharon/plugins/ha/ha_plugin.c

185 lines
4.6 KiB
C
Raw Normal View History

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"
#include "ha_cache.h"
#include "ha_attribute.h"
2008-10-24 08:06:22 +00:00
#include <daemon.h>
#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
/**
* Communication socket
*/
2009-09-29 10:56:10 +00:00
ha_socket_t *socket;
/**
* Tunnel securing sync messages.
*/
2009-09-29 10:56:10 +00:00
ha_tunnel_t *tunnel;
/**
* IKE_SA synchronization
*/
2009-09-29 10:56:10 +00:00
ha_ike_t *ike;
/**
* CHILD_SA synchronization
2008-10-24 08:06:22 +00:00
*/
2009-09-29 10:56:10 +00:00
ha_child_t *child;
/**
* Dispatcher to process incoming messages
*/
2009-09-29 10:56:10 +00:00
ha_dispatcher_t *dispatcher;
/**
* Active/Passive segment management
*/
2009-09-29 10:56:10 +00:00
ha_segments_t *segments;
/**
* Interface to control segments at kernel level
*/
2009-09-29 10:56:10 +00:00
ha_kernel_t *kernel;
/**
* Segment control interface via FIFO
*/
2009-09-29 10:56:10 +00:00
ha_ctl_t *ctl;
/**
* Message cache for resynchronization
*/
ha_cache_t *cache;
/**
* Attribute provider
*/
ha_attribute_t *attr;
2008-10-24 08:06:22 +00:00
};
METHOD(plugin_t, destroy, void,
private_ha_plugin_t *this)
2008-10-24 08:06:22 +00:00
{
DESTROY_IF(this->ctl);
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);
this->ike->destroy(this->ike);
this->child->destroy(this->child);
this->dispatcher->destroy(this->dispatcher);
this->attr->destroy(this->attr);
this->cache->destroy(this->cache);
this->segments->destroy(this->segments);
this->kernel->destroy(this->kernel);
this->socket->destroy(this->socket);
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;
char *local, *remote, *secret;
u_int count;
bool fifo, monitor, resync;
local = lib->settings->get_str(lib->settings,
2009-09-29 10:56:10 +00:00
"charon.plugins.ha.local", NULL);
remote = lib->settings->get_str(lib->settings,
2009-09-29 10:56:10 +00:00
"charon.plugins.ha.remote", NULL);
secret = lib->settings->get_str(lib->settings,
2009-09-29 10:56:10 +00:00
"charon.plugins.ha.secret", NULL);
fifo = lib->settings->get_bool(lib->settings,
"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);
count = min(SEGMENTS_MAX, lib->settings->get_int(lib->settings,
2009-09-29 10:56:10 +00:00
"charon.plugins.ha.segment_count", 1));
if (!local || !remote)
{
2009-09-29 10:56:10 +00:00
DBG1(DBG_CFG, "HA config misses local/remote address");
return NULL;
}
INIT(this,
.public = {
.plugin = {
.destroy = _destroy,
},
},
);
2008-10-24 08:06:22 +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);
if (!this->socket)
{
DESTROY_IF(this->tunnel);
free(this);
return NULL;
}
this->kernel = ha_kernel_create(count);
this->segments = ha_segments_create(this->socket, this->kernel, this->tunnel,
count, strcmp(local, remote) > 0, monitor);
this->cache = ha_cache_create(this->kernel, this->socket, resync, count);
if (fifo)
{
this->ctl = ha_ctl_create(this->segments, this->cache);
}
this->attr = ha_attribute_create(this->kernel, this->segments);
this->dispatcher = ha_dispatcher_create(this->socket, this->segments,
this->cache, this->kernel, this->attr);
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);
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);
2008-10-24 08:06:22 +00:00
return &this->public.plugin;
}