added HA resync option to (re-)integrate nodes to a cluster
[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 * $Id$
16 */
17
18 #include "ha_sync_plugin.h"
19 #include "ha_sync_ike.h"
20 #include "ha_sync_child.h"
21 #include "ha_sync_socket.h"
22 #include "ha_sync_dispatcher.h"
23 #include "ha_sync_segments.h"
24 #include "ha_sync_ctl.h"
25
26 #include <daemon.h>
27 #include <config/child_cfg.h>
28
29 typedef struct private_ha_sync_plugin_t private_ha_sync_plugin_t;
30
31 /**
32 * private data of ha_sync plugin
33 */
34 struct private_ha_sync_plugin_t {
35
36 /**
37 * implements plugin interface
38 */
39 ha_sync_plugin_t public;
40
41 /**
42 * Communication socket
43 */
44 ha_sync_socket_t *socket;
45
46 /**
47 * IKE_SA synchronization
48 */
49 ha_sync_ike_t *ike;
50
51 /**
52 * CHILD_SA synchronization
53 */
54 ha_sync_child_t *child;
55
56 /**
57 * Dispatcher to process incoming messages
58 */
59 ha_sync_dispatcher_t *dispatcher;
60
61 /**
62 * Active/Passive segment management
63 */
64 ha_sync_segments_t *segments;
65
66 /**
67 * Segment control interface via FIFO
68 */
69 ha_sync_ctl_t *ctl;
70 };
71
72 /**
73 * Implementation of plugin_t.destroy
74 */
75 static void destroy(private_ha_sync_plugin_t *this)
76 {
77 charon->bus->remove_listener(charon->bus, &this->ike->listener);
78 charon->bus->remove_listener(charon->bus, &this->child->listener);
79 this->ike->destroy(this->ike);
80 this->child->destroy(this->child);
81 this->dispatcher->destroy(this->dispatcher);
82 this->ctl->destroy(this->ctl);
83 this->segments->destroy(this->segments);
84 this->socket->destroy(this->socket);
85 free(this);
86 }
87
88 /*
89 * see header file
90 */
91 plugin_t *plugin_create()
92 {
93 private_ha_sync_plugin_t *this = malloc_thing(private_ha_sync_plugin_t);
94
95 this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
96
97 this->socket = ha_sync_socket_create();
98 if (!this->socket)
99 {
100 free(this);
101 return NULL;
102 }
103 this->segments = ha_sync_segments_create();
104 this->ctl = ha_sync_ctl_create(this->segments);
105 this->dispatcher = ha_sync_dispatcher_create(this->socket);
106 this->ike = ha_sync_ike_create(this->socket);
107 this->child = ha_sync_child_create(this->socket);
108 charon->bus->add_listener(charon->bus, &this->ike->listener);
109 charon->bus->add_listener(charon->bus, &this->child->listener);
110
111 return &this->public.plugin;
112 }
113