2 * Copyright (C) 2008 Martin Willi
4 * Copyright (C) secunet Security Networks AG
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 #include "ha_plugin.h"
20 #include "ha_socket.h"
21 #include "ha_tunnel.h"
22 #include "ha_dispatcher.h"
23 #include "ha_segments.h"
26 #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 initialize_plugin(private_ha_plugin_t
*this)
105 char *local
, *remote
, *secret
;
107 bool fifo
, monitor
, resync
;
109 local
= lib
->settings
->get_str(lib
->settings
,
110 "%s.plugins.ha.local", NULL
, lib
->ns
);
111 remote
= lib
->settings
->get_str(lib
->settings
,
112 "%s.plugins.ha.remote", NULL
, lib
->ns
);
113 secret
= lib
->settings
->get_str(lib
->settings
,
114 "%s.plugins.ha.secret", NULL
, lib
->ns
);
115 fifo
= lib
->settings
->get_bool(lib
->settings
,
116 "%s.plugins.ha.fifo_interface", TRUE
, lib
->ns
);
117 monitor
= lib
->settings
->get_bool(lib
->settings
,
118 "%s.plugins.ha.monitor", TRUE
, lib
->ns
);
119 resync
= lib
->settings
->get_bool(lib
->settings
,
120 "%s.plugins.ha.resync", TRUE
, lib
->ns
);
121 count
= min(SEGMENTS_MAX
, lib
->settings
->get_int(lib
->settings
,
122 "%s.plugins.ha.segment_count", 1, lib
->ns
));
123 if (!local
|| !remote
)
125 DBG1(DBG_CFG
, "HA config misses local/remote address");
131 this->tunnel
= ha_tunnel_create(local
, remote
, secret
);
133 this->socket
= ha_socket_create(local
, remote
);
138 this->kernel
= ha_kernel_create(count
);
139 this->segments
= ha_segments_create(this->socket
, this->kernel
, this->tunnel
,
140 count
, strcmp(local
, remote
) > 0, monitor
);
141 this->cache
= ha_cache_create(this->kernel
, this->socket
, this->tunnel
,
145 this->ctl
= ha_ctl_create(this->segments
, this->cache
);
147 this->attr
= ha_attribute_create(this->kernel
, this->segments
);
148 this->dispatcher
= ha_dispatcher_create(this->socket
, this->segments
,
149 this->cache
, this->kernel
, this->attr
);
150 this->ike
= ha_ike_create(this->socket
, this->tunnel
, this->cache
);
151 this->child
= ha_child_create(this->socket
, this->tunnel
, this->segments
,
157 * Initialize plugin and register listener
159 static bool plugin_cb(private_ha_plugin_t
*this,
160 plugin_feature_t
*feature
, bool reg
, void *cb_data
)
164 if (!initialize_plugin(this))
168 charon
->bus
->add_listener(charon
->bus
, &this->segments
->listener
);
169 charon
->bus
->add_listener(charon
->bus
, &this->ike
->listener
);
170 charon
->bus
->add_listener(charon
->bus
, &this->child
->listener
);
171 charon
->attributes
->add_provider(charon
->attributes
,
172 &this->attr
->provider
);
176 charon
->attributes
->remove_provider(charon
->attributes
,
177 &this->attr
->provider
);
178 charon
->bus
->remove_listener(charon
->bus
, &this->segments
->listener
);
179 charon
->bus
->remove_listener(charon
->bus
, &this->ike
->listener
);
180 charon
->bus
->remove_listener(charon
->bus
, &this->child
->listener
);
185 METHOD(plugin_t
, get_features
, int,
186 private_ha_plugin_t
*this, plugin_feature_t
*features
[])
188 static plugin_feature_t f
[] = {
189 PLUGIN_CALLBACK((plugin_feature_callback_t
)plugin_cb
, NULL
),
190 PLUGIN_PROVIDE(CUSTOM
, "ha"),
191 PLUGIN_SDEPEND(CUSTOM
, "kernel-ipsec"),
197 METHOD(plugin_t
, destroy
, void,
198 private_ha_plugin_t
*this)
200 DESTROY_IF(this->ctl
);
201 DESTROY_IF(this->ike
);
202 DESTROY_IF(this->child
);
203 DESTROY_IF(this->dispatcher
);
204 DESTROY_IF(this->attr
);
205 DESTROY_IF(this->cache
);
206 DESTROY_IF(this->segments
);
207 DESTROY_IF(this->kernel
);
208 DESTROY_IF(this->socket
);
209 DESTROY_IF(this->tunnel
);
216 plugin_t
*ha_plugin_create()
218 private_ha_plugin_t
*this;
220 if (!lib
->caps
->keep(lib
->caps
, CAP_CHOWN
))
221 { /* required to chown(2) control socket, ha_kernel also needs it at
223 DBG1(DBG_CFG
, "ha plugin requires CAP_CHOWN capability");
230 .get_name
= _get_name
,
231 .get_features
= _get_features
,
237 return &this->public.plugin
;