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_sync_plugin.h"
17 #include "ha_sync_ike.h"
18 #include "ha_sync_child.h"
19 #include "ha_sync_socket.h"
20 #include "ha_sync_tunnel.h"
21 #include "ha_sync_dispatcher.h"
22 #include "ha_sync_segments.h"
23 #include "ha_sync_ctl.h"
26 #include <config/child_cfg.h>
28 typedef struct private_ha_sync_plugin_t private_ha_sync_plugin_t
;
31 * private data of ha_sync plugin
33 struct private_ha_sync_plugin_t
{
36 * implements plugin interface
38 ha_sync_plugin_t
public;
41 * Communication socket
43 ha_sync_socket_t
*socket
;
46 * Tunnel securing sync messages.
48 ha_sync_tunnel_t
*tunnel
;
51 * IKE_SA synchronization
56 * CHILD_SA synchronization
58 ha_sync_child_t
*child
;
61 * Dispatcher to process incoming messages
63 ha_sync_dispatcher_t
*dispatcher
;
66 * Active/Passive segment management
68 ha_sync_segments_t
*segments
;
71 * Segment control interface via FIFO
77 * Implementation of plugin_t.destroy
79 static void destroy(private_ha_sync_plugin_t
*this)
81 DESTROY_IF(this->ctl
);
82 charon
->bus
->remove_listener(charon
->bus
, &this->ike
->listener
);
83 charon
->bus
->remove_listener(charon
->bus
, &this->child
->listener
);
84 this->ike
->destroy(this->ike
);
85 this->child
->destroy(this->child
);
86 this->dispatcher
->destroy(this->dispatcher
);
87 this->segments
->destroy(this->segments
);
88 this->socket
->destroy(this->socket
);
89 DESTROY_IF(this->tunnel
);
96 plugin_t
*plugin_create()
98 private_ha_sync_plugin_t
*this;
99 char *local
, *remote
, *secret
;
102 local
= lib
->settings
->get_str(lib
->settings
,
103 "charon.plugins.ha_sync.local", NULL
);
104 remote
= lib
->settings
->get_str(lib
->settings
,
105 "charon.plugins.ha_sync.remote", NULL
);
106 secret
= lib
->settings
->get_str(lib
->settings
,
107 "charon.plugins.ha_sync.secret", NULL
);
108 fifo
= lib
->settings
->get_bool(lib
->settings
,
109 "charon.plugins.ha_sync.fifo_interface", FALSE
);
110 if (!local
|| !remote
)
112 DBG1(DBG_CFG
, "HA sync config misses local/remote address");
116 this = malloc_thing(private_ha_sync_plugin_t
);
118 this->public.plugin
.destroy
= (void(*)(plugin_t
*))destroy
;
122 this->socket
= ha_sync_socket_create(local
, remote
);
128 this->segments
= ha_sync_segments_create(this->socket
);
131 this->tunnel
= ha_sync_tunnel_create(secret
, local
, remote
);
135 this->ctl
= ha_sync_ctl_create(this->segments
);
137 this->dispatcher
= ha_sync_dispatcher_create(this->socket
, this->segments
);
138 this->ike
= ha_sync_ike_create(this->socket
, this->tunnel
);
139 this->child
= ha_sync_child_create(this->socket
, this->tunnel
);
140 charon
->bus
->add_listener(charon
->bus
, &this->ike
->listener
);
141 charon
->bus
->add_listener(charon
->bus
, &this->child
->listener
);
143 return &this->public.plugin
;