added a dispatcher class to receive HA sync messages
[strongswan.git] / src / charon / plugins / ha_sync / ha_sync_message.h
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 /**
19 * @defgroup ha_sync_message ha_sync_message
20 * @{ @ingroup ha_sync
21 */
22
23 #ifndef HA_SYNC_MESSAGE_H_
24 #define HA_SYNC_MESSAGE_H_
25
26 #include <library.h>
27 #include <utils/host.h>
28 #include <utils/identification.h>
29 #include <sa/ike_sa_id.h>
30
31 /**
32 * Protocol version of this implementation
33 */
34 #define HA_SYNC_MESSAGE_VERSION 1
35
36 typedef struct ha_sync_message_t ha_sync_message_t;
37 typedef enum ha_sync_message_type_t ha_sync_message_type_t;
38 typedef enum ha_sync_message_attribute_t ha_sync_message_attribute_t;
39 typedef union ha_sync_message_value_t ha_sync_message_value_t;
40
41 /**
42 * Type of a sync message
43 */
44 enum ha_sync_message_type_t {
45 /** add a completely new IKE_SA */
46 HA_SYNC_IKE_ADD = 1,
47 /** update an existing IKE_SA (message IDs, address update, ...) */
48 HA_SYNC_IKE_UPDATE,
49 /** delete an existing IKE_SA */
50 HA_SYNC_IKE_DELETE,
51 /** rekeying an existing IKE_SA, transferring CHILD_SAs to a new one */
52 HA_SYNC_IKE_REKEY,
53 /** add a new CHILD_SA */
54 HA_SYNC_CHILD_ADD,
55 /** delete an existing CHILD_SA */
56 HA_SYNC_CHILD_DELETE,
57 };
58
59 /**
60 * Type of attributes contained in a message
61 */
62 enum ha_sync_message_attribute_t {
63 /** ike_sa_id_t*, to identify IKE_SA */
64 HA_SYNC_IKE_ID = 1,
65 /** ike_Sa_id_t*, identifies IKE_SA which gets rekeyed */
66 HA_SYNC_IKE_REKEY_ID,
67 /** identification_t*, local identity */
68 HA_SYNC_LOCAL_ID,
69 /** identification_t*, remote identity */
70 HA_SYNC_REMOTE_ID,
71 /** identification_t*, EAP identity */
72 HA_SYNC_EAP_ID,
73 /** host_t*, local address */
74 HA_SYNC_LOCAL_ADDR,
75 /** host_t*, remote address */
76 HA_SYNC_REMOTE_ADDR,
77 /** char*, name of configuration */
78 HA_SYNC_CONFIG_NAME,
79 /** u_int32_t, bitset of ike_condition_t */
80 HA_SYNC_CONDITIONS,
81 /** u_int32_t, bitset of ike_extension_t */
82 HA_SYNC_EXTENSIONS,
83 /** host_t*, local virtual IP */
84 HA_SYNC_LOCAL_VIP,
85 /** host_t*, remote virtual IP */
86 HA_SYNC_REMOTE_VIP,
87 /** host_t*, additional MOBIKE peer address */
88 HA_SYNC_ADDITIONAL_ADDR,
89 /** chunk_t, initiators nonce */
90 HA_SYNC_NONCE_I,
91 /** chunk_t, responders nonce */
92 HA_SYNC_NONCE_R,
93 /** chunk_t, diffie hellman shared secret */
94 HA_SYNC_SECRET,
95 };
96
97 /**
98 * Union to enumerate typed attributes in a message
99 */
100 union ha_sync_message_value_t {
101 u_int32_t u32;
102 char *str;
103 chunk_t chunk;
104 ike_sa_id_t *ike_sa_id;
105 identification_t *id;
106 host_t *host;
107 };
108
109 /**
110 * Abstracted message passed between nodes in a HA cluster.
111 */
112 struct ha_sync_message_t {
113
114 /**
115 * Get the type of the message.
116 *
117 * @return message type
118 */
119 ha_sync_message_type_t (*get_type)(ha_sync_message_t *this);
120
121 /**
122 * Add an attribute to a message.
123 *
124 * @param attribute attribute type to add
125 * @param ... attribute specific data
126 */
127 void (*add_attribute)(ha_sync_message_t *this,
128 ha_sync_message_attribute_t attribute, ...);
129
130 /**
131 * Create an enumerator over all attributes in a message.
132 *
133 * @return enumerator over attribute, ha_sync_message_value_t
134 */
135 enumerator_t* (*create_attribute_enumerator)(ha_sync_message_t *this);
136
137 /**
138 * Get the message in a encoded form.
139 *
140 * @return chunk pointing to internal data
141 */
142 chunk_t (*get_encoding)(ha_sync_message_t *this);
143
144 /**
145 * Destroy a ha_sync_message_t.
146 */
147 void (*destroy)(ha_sync_message_t *this);
148 };
149
150 /**
151 * Create a new ha_sync_message instance, ready for adding attributes
152 *
153 * @param version protocol version to create a message from
154 * @param type type of the message
155 */
156 ha_sync_message_t *ha_sync_message_create(ha_sync_message_type_t type);
157
158 /**
159 * Create a ha_sync_message from encoded data.
160 *
161 * @param data encoded message data
162 */
163 ha_sync_message_t *ha_sync_message_parse(chunk_t data);
164
165 #endif /* HA_SYNC_MESSAGE_ @}*/