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"
25 #include "ha_attribute.h"
29 #include <config/child_cfg.h>
31 typedef struct private_ha_plugin_t private_ha_plugin_t
;
34 * private data of ha plugin
36 struct private_ha_plugin_t
{
39 * implements plugin interface
44 * Communication socket
49 * Tunnel securing sync messages.
54 * IKE_SA synchronization
59 * CHILD_SA synchronization
64 * Dispatcher to process incoming messages
66 ha_dispatcher_t
*dispatcher
;
69 * Active/Passive segment management
71 ha_segments_t
*segments
;
74 * Interface to control segments at kernel level
79 * Segment control interface via FIFO
84 * Message cache for resynchronization
94 METHOD(plugin_t
, get_name
, char*,
95 private_ha_plugin_t
*this)
103 static bool plugin_cb(private_ha_plugin_t
*this,
104 plugin_feature_t
*feature
, bool reg
, void *cb_data
)
108 charon
->bus
->add_listener(charon
->bus
, &this->segments
->listener
);
109 charon
->bus
->add_listener(charon
->bus
, &this->ike
->listener
);
110 charon
->bus
->add_listener(charon
->bus
, &this->child
->listener
);
111 hydra
->attributes
->add_provider(hydra
->attributes
,
112 &this->attr
->provider
);
116 hydra
->attributes
->remove_provider(hydra
->attributes
,
117 &this->attr
->provider
);
118 charon
->bus
->remove_listener(charon
->bus
, &this->segments
->listener
);
119 charon
->bus
->remove_listener(charon
->bus
, &this->ike
->listener
);
120 charon
->bus
->remove_listener(charon
->bus
, &this->child
->listener
);
125 METHOD(plugin_t
, get_features
, int,
126 private_ha_plugin_t
*this, plugin_feature_t
*features
[])
128 static plugin_feature_t f
[] = {
129 PLUGIN_CALLBACK((plugin_feature_callback_t
)plugin_cb
, NULL
),
130 PLUGIN_PROVIDE(CUSTOM
, "ha"),
136 METHOD(plugin_t
, destroy
, void,
137 private_ha_plugin_t
*this)
139 DESTROY_IF(this->ctl
);
140 this->ike
->destroy(this->ike
);
141 this->child
->destroy(this->child
);
142 this->dispatcher
->destroy(this->dispatcher
);
143 this->attr
->destroy(this->attr
);
144 this->cache
->destroy(this->cache
);
145 this->segments
->destroy(this->segments
);
146 this->kernel
->destroy(this->kernel
);
147 this->socket
->destroy(this->socket
);
148 DESTROY_IF(this->tunnel
);
155 plugin_t
*ha_plugin_create()
157 private_ha_plugin_t
*this;
158 char *local
, *remote
, *secret
;
160 bool fifo
, monitor
, resync
;
162 local
= lib
->settings
->get_str(lib
->settings
,
163 "%s.plugins.ha.local", NULL
, charon
->name
);
164 remote
= lib
->settings
->get_str(lib
->settings
,
165 "%s.plugins.ha.remote", NULL
, charon
->name
);
166 secret
= lib
->settings
->get_str(lib
->settings
,
167 "%s.plugins.ha.secret", NULL
, charon
->name
);
168 fifo
= lib
->settings
->get_bool(lib
->settings
,
169 "%s.plugins.ha.fifo_interface", TRUE
, charon
->name
);
170 monitor
= lib
->settings
->get_bool(lib
->settings
,
171 "%s.plugins.ha.monitor", TRUE
, charon
->name
);
172 resync
= lib
->settings
->get_bool(lib
->settings
,
173 "%s.plugins.ha.resync", TRUE
, charon
->name
);
174 count
= min(SEGMENTS_MAX
, lib
->settings
->get_int(lib
->settings
,
175 "%s.plugins.ha.segment_count", 1, charon
->name
));
176 if (!local
|| !remote
)
178 DBG1(DBG_CFG
, "HA config misses local/remote address");
185 .get_name
= _get_name
,
186 .get_features
= _get_features
,
194 this->tunnel
= ha_tunnel_create(local
, remote
, secret
);
196 this->socket
= ha_socket_create(local
, remote
);
199 DESTROY_IF(this->tunnel
);
203 this->kernel
= ha_kernel_create(count
);
204 this->segments
= ha_segments_create(this->socket
, this->kernel
, this->tunnel
,
205 count
, strcmp(local
, remote
) > 0, monitor
);
206 this->cache
= ha_cache_create(this->kernel
, this->socket
, resync
, count
);
209 this->ctl
= ha_ctl_create(this->segments
, this->cache
);
211 this->attr
= ha_attribute_create(this->kernel
, this->segments
);
212 this->dispatcher
= ha_dispatcher_create(this->socket
, this->segments
,
213 this->cache
, this->kernel
, this->attr
);
214 this->ike
= ha_ike_create(this->socket
, this->tunnel
, this->cache
);
215 this->child
= ha_child_create(this->socket
, this->tunnel
, this->segments
,
218 return &this->public.plugin
;