Moved host_t and host_resolver_t to a new networking subfolder
[strongswan.git] / src / libcharon / plugins / ha / ha_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
16 /**
17 * @defgroup ha_message ha_message
18 * @{ @ingroup ha
19 */
20
21 #ifndef HA_MESSAGE_H_
22 #define HA_MESSAGE_H_
23
24 #include <library.h>
25 #include <networking/host.h>
26 #include <utils/identification.h>
27 #include <sa/ike_sa_id.h>
28 #include <selectors/traffic_selector.h>
29
30 /**
31 * Protocol version of this implementation
32 */
33 #define HA_MESSAGE_VERSION 3
34
35 typedef struct ha_message_t ha_message_t;
36 typedef enum ha_message_type_t ha_message_type_t;
37 typedef enum ha_message_attribute_t ha_message_attribute_t;
38 typedef union ha_message_value_t ha_message_value_t;
39
40 /**
41 * Type of a HA message
42 */
43 enum ha_message_type_t {
44 /** add a completely new IKE_SA */
45 HA_IKE_ADD = 1,
46 /** update an existing IKE_SA (identities, address update, ...) */
47 HA_IKE_UPDATE,
48 /** update initiator message id */
49 HA_IKE_MID_INITIATOR,
50 /** update responder message id */
51 HA_IKE_MID_RESPONDER,
52 /** delete an existing IKE_SA */
53 HA_IKE_DELETE,
54 /** add a new CHILD_SA */
55 HA_CHILD_ADD,
56 /** delete an existing CHILD_SA */
57 HA_CHILD_DELETE,
58 /** segments the sending node is giving up */
59 HA_SEGMENT_DROP,
60 /** segments the sending node is taking over */
61 HA_SEGMENT_TAKE,
62 /** status with the segments the sending node is currently serving */
63 HA_STATUS,
64 /** segments the receiving node is requested to resync */
65 HA_RESYNC,
66 /** IV synchronization for IKEv1 Main/Aggressive mode */
67 HA_IKE_IV,
68 };
69
70 /**
71 * Enum names for message types
72 */
73 extern enum_name_t *ha_message_type_names;
74
75 /**
76 * Type of attributes contained in a message
77 */
78 enum ha_message_attribute_t {
79 /** ike_sa_id_t*, to identify IKE_SA */
80 HA_IKE_ID = 1,
81 /** ike_sa_id_t*, identifies IKE_SA which gets rekeyed */
82 HA_IKE_REKEY_ID,
83 /** identification_t*, local identity */
84 HA_LOCAL_ID,
85 /** identification_t*, remote identity */
86 HA_REMOTE_ID,
87 /** identification_t*, remote EAP identity */
88 HA_REMOTE_EAP_ID,
89 /** host_t*, local address */
90 HA_LOCAL_ADDR,
91 /** host_t*, remote address */
92 HA_REMOTE_ADDR,
93 /** char*, name of configuration */
94 HA_CONFIG_NAME,
95 /** u_int32_t, bitset of ike_condition_t */
96 HA_CONDITIONS,
97 /** u_int32_t, bitset of ike_extension_t */
98 HA_EXTENSIONS,
99 /** host_t*, local virtual IP */
100 HA_LOCAL_VIP,
101 /** host_t*, remote virtual IP */
102 HA_REMOTE_VIP,
103 /** host_t*, known peer addresses (used for MOBIKE) */
104 HA_PEER_ADDR,
105 /** u_int8_t, initiator of an exchange, TRUE for local */
106 HA_INITIATOR,
107 /** chunk_t, initiators nonce */
108 HA_NONCE_I,
109 /** chunk_t, responders nonce */
110 HA_NONCE_R,
111 /** chunk_t, diffie hellman shared secret */
112 HA_SECRET,
113 /** chunk_t, SKd of old SA if rekeying */
114 HA_OLD_SKD,
115 /** u_int16_t, pseudo random function */
116 HA_ALG_PRF,
117 /** u_int16_t, old pseudo random function if rekeying */
118 HA_ALG_OLD_PRF,
119 /** u_int16_t, encryption algorithm */
120 HA_ALG_ENCR,
121 /** u_int16_t, encryption key size in bytes */
122 HA_ALG_ENCR_LEN,
123 /** u_int16_t, integrity protection algorithm */
124 HA_ALG_INTEG,
125 /** u_int8_t, IPsec mode, TUNNEL|TRANSPORT|... */
126 HA_IPSEC_MODE,
127 /** u_int8_t, IPComp protocol */
128 HA_IPCOMP,
129 /** u_int32_t, inbound security parameter index */
130 HA_INBOUND_SPI,
131 /** u_int32_t, outbound security parameter index */
132 HA_OUTBOUND_SPI,
133 /** u_int16_t, inbound security parameter index */
134 HA_INBOUND_CPI,
135 /** u_int16_t, outbound security parameter index */
136 HA_OUTBOUND_CPI,
137 /** traffic_selector_t*, local traffic selector */
138 HA_LOCAL_TS,
139 /** traffic_selector_t*, remote traffic selector */
140 HA_REMOTE_TS,
141 /** u_int32_t, message ID */
142 HA_MID,
143 /** u_int16_t, HA segment */
144 HA_SEGMENT,
145 /** u_int16_t, Extended Sequence numbers */
146 HA_ESN,
147 /** u_int8_t, IKE version */
148 HA_IKE_VERSION,
149 /** chunk_t, own DH public value */
150 HA_LOCAL_DH,
151 /** chunk_t, remote DH public value */
152 HA_REMOTE_DH,
153 /** chunk_t, shared secret for IKEv1 key derivation */
154 HA_PSK,
155 /** chunk_t, IV for next IKEv1 message */
156 HA_IV,
157 };
158
159 /**
160 * Union to enumerate typed attributes in a message
161 */
162 union ha_message_value_t {
163 u_int8_t u8;
164 u_int16_t u16;
165 u_int32_t u32;
166 char *str;
167 chunk_t chunk;
168 ike_sa_id_t *ike_sa_id;
169 identification_t *id;
170 host_t *host;
171 traffic_selector_t *ts;
172 };
173
174 /**
175 * Abstracted message passed between nodes in a HA cluster.
176 */
177 struct ha_message_t {
178
179 /**
180 * Get the type of the message.
181 *
182 * @return message type
183 */
184 ha_message_type_t (*get_type)(ha_message_t *this);
185
186 /**
187 * Add an attribute to a message.
188 *
189 * @param attribute attribute type to add
190 * @param ... attribute specific data
191 */
192 void (*add_attribute)(ha_message_t *this,
193 ha_message_attribute_t attribute, ...);
194
195 /**
196 * Create an enumerator over all attributes in a message.
197 *
198 * @return enumerator over attribute, ha_message_value_t
199 */
200 enumerator_t* (*create_attribute_enumerator)(ha_message_t *this);
201
202 /**
203 * Get the message in a encoded form.
204 *
205 * @return chunk pointing to internal data
206 */
207 chunk_t (*get_encoding)(ha_message_t *this);
208
209 /**
210 * Destroy a ha_message_t.
211 */
212 void (*destroy)(ha_message_t *this);
213 };
214
215 /**
216 * Create a new ha_message instance, ready for adding attributes
217 *
218 * @param type type of the message
219 */
220 ha_message_t *ha_message_create(ha_message_type_t type);
221
222 /**
223 * Create a ha_message from encoded data.
224 *
225 * @param data encoded message data
226 */
227 ha_message_t *ha_message_parse(chunk_t data);
228
229 #endif /** HA_MESSAGE_ @}*/