Propagate segment manipulation to cluster node
[strongswan.git] / src / charon / plugins / ha_sync / ha_sync_plugin.c
1 /*
2 * Copyright (C) 2008 Martin Willi
3 * Hochschule fuer Technik Rapperswil
4 *
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>.
9 *
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
13 * for more details.
14 */
15
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"
24
25 #include <daemon.h>
26 #include <config/child_cfg.h>
27
28 typedef struct private_ha_sync_plugin_t private_ha_sync_plugin_t;
29
30 /**
31 * private data of ha_sync plugin
32 */
33 struct private_ha_sync_plugin_t {
34
35 /**
36 * implements plugin interface
37 */
38 ha_sync_plugin_t public;
39
40 /**
41 * Communication socket
42 */
43 ha_sync_socket_t *socket;
44
45 /**
46 * Tunnel securing sync messages.
47 */
48 ha_sync_tunnel_t *tunnel;
49
50 /**
51 * IKE_SA synchronization
52 */
53 ha_sync_ike_t *ike;
54
55 /**
56 * CHILD_SA synchronization
57 */
58 ha_sync_child_t *child;
59
60 /**
61 * Dispatcher to process incoming messages
62 */
63 ha_sync_dispatcher_t *dispatcher;
64
65 /**
66 * Active/Passive segment management
67 */
68 ha_sync_segments_t *segments;
69
70 /**
71 * Segment control interface via FIFO
72 */
73 ha_sync_ctl_t *ctl;
74 };
75
76 /**
77 * Implementation of plugin_t.destroy
78 */
79 static void destroy(private_ha_sync_plugin_t *this)
80 {
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);
90 free(this);
91 }
92
93 /*
94 * see header file
95 */
96 plugin_t *plugin_create()
97 {
98 private_ha_sync_plugin_t *this;
99 char *local, *remote, *secret;
100 bool fifo;
101
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)
111 {
112 DBG1(DBG_CFG, "HA sync config misses local/remote address");
113 return NULL;
114 }
115
116 this = malloc_thing(private_ha_sync_plugin_t);
117
118 this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
119 this->tunnel = NULL;
120 this->ctl = NULL;
121
122 this->socket = ha_sync_socket_create(local, remote);
123 if (!this->socket)
124 {
125 free(this);
126 return NULL;
127 }
128 this->segments = ha_sync_segments_create(this->socket);
129 if (secret)
130 {
131 this->tunnel = ha_sync_tunnel_create(secret, local, remote);
132 }
133 if (fifo)
134 {
135 this->ctl = ha_sync_ctl_create(this->segments);
136 }
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);
142
143 return &this->public.plugin;
144 }
145