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

164 lines
4.1 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"
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
/**
* 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;
2008-10-24 08:06:22 +00:00
};
/**
* Implementation of plugin_t.destroy
*/
2009-09-29 10:56:10 +00:00
static void destroy(private_ha_plugin_t *this)
2008-10-24 08:06:22 +00:00
{
DESTROY_IF(this->ctl);
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->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;
}
2009-09-29 10:56:10 +00:00
this = malloc_thing(private_ha_plugin_t);
2008-10-24 08:06:22 +00:00
this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
this->tunnel = NULL;
this->ctl = NULL;
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, resync);
if (fifo)
{
2009-09-29 10:56:10 +00:00
this->ctl = ha_ctl_create(this->segments);
}
2009-09-29 10:56:10 +00:00
this->dispatcher = ha_dispatcher_create(this->socket, this->segments);
this->ike = ha_ike_create(this->socket, this->tunnel);
this->child = ha_child_create(this->socket, this->tunnel);
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);
2008-10-24 08:06:22 +00:00
return &this->public.plugin;
}