ebe0c2df4a31734f5fa35eb5bff8efa2ef0f9b09
[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_int8_t u8;
102 u_int32_t u32;
103 u_int16_t u16;
104 chunk_t chnk;
105 host_t *host;
106 identification_t *id;
107 ike_sa_id_t *ike_sa_id;
108 char *str;
109 };
110
111 /**
112 * Abstracted message passed between nodes in a HA cluster.
113 */
114 struct ha_sync_message_t {
115
116 /**
117 * Get the type of the message.
118 *
119 * @return message type
120 */
121 ha_sync_message_type_t (*get_type)(ha_sync_message_t *this);
122
123 /**
124 * Add an attribute to a message.
125 *
126 * @param attribute attribute type to add
127 * @param ... attribute specific data
128 */
129 void (*add_attribute)(ha_sync_message_t *this,
130 ha_sync_message_attribute_t attribute, ...);
131
132 /**
133 * Create an enumerator over all attributes in a message.
134 *
135 * @return enumerator over attribute, ha_sync_message_value_t
136 */
137 enumerator_t* (*create_attribute_enumerator)(ha_sync_message_t *this);
138
139 /**
140 * Get the message in a encoded form.
141 *
142 * @return chunk pointing to internal data
143 */
144 chunk_t (*get_encoding)(ha_sync_message_t *this);
145
146 /**
147 * Destroy a ha_sync_message_t.
148 */
149 void (*destroy)(ha_sync_message_t *this);
150 };
151
152 /**
153 * Create a new ha_sync_message instance, ready for adding attributes
154 *
155 * @param version protocol version to create a message from
156 * @param type type of the message
157 */
158 ha_sync_message_t *ha_sync_message_create(ha_sync_message_type_t type);
159
160 /**
161 * Create a ha_sync_message from encoded data.
162 *
163 * @param data encoded message data
164 */
165 ha_sync_message_t *ha_sync_message_parse(chunk_t data);
166
167 #endif /* HA_SYNC_MESSAGE_ @}*/