2 * Copyright (C) 2008 Martin Willi
3 * Hochschule fuer Technik Rapperswil
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 #include "ha_plugin.h"
19 #include "ha_socket.h"
20 #include "ha_tunnel.h"
21 #include "ha_dispatcher.h"
22 #include "ha_segments.h"
26 #include <config/child_cfg.h>
28 typedef struct private_ha_plugin_t private_ha_plugin_t
;
31 * private data of ha plugin
33 struct private_ha_plugin_t
{
36 * implements plugin interface
41 * Communication socket
46 * Tunnel securing sync messages.
51 * IKE_SA synchronization
56 * CHILD_SA synchronization
61 * Dispatcher to process incoming messages
63 ha_dispatcher_t
*dispatcher
;
66 * Active/Passive segment management
68 ha_segments_t
*segments
;
71 * Interface to control segments at kernel level
76 * Segment control interface via FIFO
82 * Implementation of plugin_t.destroy
84 static void destroy(private_ha_plugin_t
*this)
86 DESTROY_IF(this->ctl
);
87 charon
->bus
->remove_listener(charon
->bus
, &this->segments
->listener
);
88 charon
->bus
->remove_listener(charon
->bus
, &this->ike
->listener
);
89 charon
->bus
->remove_listener(charon
->bus
, &this->child
->listener
);
90 this->ike
->destroy(this->ike
);
91 this->child
->destroy(this->child
);
92 this->dispatcher
->destroy(this->dispatcher
);
93 this->segments
->destroy(this->segments
);
94 this->kernel
->destroy(this->kernel
);
95 this->socket
->destroy(this->socket
);
96 DESTROY_IF(this->tunnel
);
103 plugin_t
*plugin_create()
105 private_ha_plugin_t
*this;
106 char *local
, *remote
, *secret
;
110 local
= lib
->settings
->get_str(lib
->settings
,
111 "charon.plugins.ha.local", NULL
);
112 remote
= lib
->settings
->get_str(lib
->settings
,
113 "charon.plugins.ha.remote", NULL
);
114 secret
= lib
->settings
->get_str(lib
->settings
,
115 "charon.plugins.ha.secret", NULL
);
116 fifo
= lib
->settings
->get_bool(lib
->settings
,
117 "charon.plugins.ha.fifo_interface", FALSE
);
118 count
= min(SEGMENTS_MAX
, lib
->settings
->get_int(lib
->settings
,
119 "charon.plugins.ha.segment_count", 1));
120 if (!local
|| !remote
)
122 DBG1(DBG_CFG
, "HA config misses local/remote address");
126 this = malloc_thing(private_ha_plugin_t
);
128 this->public.plugin
.destroy
= (void(*)(plugin_t
*))destroy
;
132 this->socket
= ha_socket_create(local
, remote
);
138 this->kernel
= ha_kernel_create(count
);
141 this->socket
->destroy(this->socket
);
148 this->tunnel
= ha_tunnel_create(local
, remote
, secret
);
150 this->segments
= ha_segments_create(this->socket
, this->kernel
,
151 this->tunnel
, local
, remote
, count
);
154 this->ctl
= ha_ctl_create(this->segments
);
156 this->dispatcher
= ha_dispatcher_create(this->socket
, this->segments
);
157 this->ike
= ha_ike_create(this->socket
, this->tunnel
);
158 this->child
= ha_child_create(this->socket
, this->tunnel
);
159 charon
->bus
->add_listener(charon
->bus
, &this->segments
->listener
);
160 charon
->bus
->add_listener(charon
->bus
, &this->ike
->listener
);
161 charon
->bus
->add_listener(charon
->bus
, &this->child
->listener
);
163 return &this->public.plugin
;