|
|
1.1 misho 1: /*
2: * Copyright (C) 2007 Tobias Brunner
3: * Copyright (C) 2005-2011 Martin Willi
4: * Copyright (C) 2005 Jan Hutter
5: * HSR Hochschule fuer Technik Rapperswil
6: *
7: * This program is free software; you can redistribute it and/or modify it
8: * under the terms of the GNU General Public License as published by the
9: * Free Software Foundation; either version 2 of the License, or (at your
10: * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11: *
12: * This program is distributed in the hope that it will be useful, but
13: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15: * for more details.
16: */
17:
18: /**
19: * @defgroup ike_header ike_header
20: * @{ @ingroup payloads
21: */
22:
23: #ifndef IKE_HEADER_H_
24: #define IKE_HEADER_H_
25:
26: typedef enum exchange_type_t exchange_type_t;
27: typedef struct ike_header_t ike_header_t;
28:
29: #include <library.h>
30: #include <encoding/payloads/payload.h>
31:
32: /**
33: * Major Version of IKEv1 we implement.
34: */
35: #define IKEV1_MAJOR_VERSION 1
36:
37: /**
38: * Minor Version of IKEv1 we implement.
39: */
40: #define IKEV1_MINOR_VERSION 0
41:
42: /**
43: * Major Version of IKEv2 we implement.
44: */
45: #define IKEV2_MAJOR_VERSION 2
46:
47: /**
48: * Minor Version of IKEv2 we implement.
49: */
50: #define IKEV2_MINOR_VERSION 0
51:
52: /**
53: * Length of IKE Header in Bytes.
54: */
55: #define IKE_HEADER_LENGTH 28
56:
57: /**
58: * Different types of IKE-Exchanges.
59: *
60: * See RFC for different types.
61: */
62: enum exchange_type_t{
63:
64: /**
65: * Identity Protection (Main mode).
66: */
67: ID_PROT = 2,
68:
69: /**
70: * Authentication Only.
71: */
72: AUTH_ONLY = 3,
73:
74: /**
75: * Aggressive (Aggressive mode)
76: */
77: AGGRESSIVE = 4,
78:
79: /**
80: * Informational in IKEv1
81: */
82: INFORMATIONAL_V1 = 5,
83:
84: /**
85: * Transaction (ISAKMP Cfg Mode "draft-ietf-ipsec-isakmp-mode-cfg-05")
86: */
87: TRANSACTION = 6,
88:
89: /**
90: * Quick Mode
91: */
92: QUICK_MODE = 32,
93:
94: /**
95: * New Group Mode
96: */
97: NEW_GROUP_MODE = 33,
98:
99: /**
100: * IKE_SA_INIT.
101: */
102: IKE_SA_INIT = 34,
103:
104: /**
105: * IKE_AUTH.
106: */
107: IKE_AUTH = 35,
108:
109: /**
110: * CREATE_CHILD_SA.
111: */
112: CREATE_CHILD_SA = 36,
113:
114: /**
115: * INFORMATIONAL in IKEv2.
116: */
117: INFORMATIONAL = 37,
118:
119: /**
120: * IKE_SESSION_RESUME (RFC 5723).
121: */
122: IKE_SESSION_RESUME = 38,
123:
124: #ifdef ME
125: /**
126: * ME_CONNECT
127: */
128: ME_CONNECT = 240,
129: #endif /* ME */
130:
131: /**
132: * Undefined exchange type, in private space.
133: */
134: EXCHANGE_TYPE_UNDEFINED = 255,
135: };
136:
137: /**
138: * enum name for exchange_type_t
139: */
140: extern enum_name_t *exchange_type_names;
141:
142: /**
143: * An object of this type represents an IKE header of either IKEv1 or IKEv2.
144: */
145: struct ike_header_t {
146: /**
147: * The payload_t interface.
148: */
149: payload_t payload_interface;
150:
151: /**
152: * Get the initiator spi.
153: *
154: * @return initiator_spi
155: */
156: uint64_t (*get_initiator_spi) (ike_header_t *this);
157:
158: /**
159: * Set the initiator spi.
160: *
161: * @param initiator_spi initiator_spi
162: */
163: void (*set_initiator_spi) (ike_header_t *this, uint64_t initiator_spi);
164:
165: /**
166: * Get the responder spi.
167: *
168: * @return responder_spi
169: */
170: uint64_t (*get_responder_spi) (ike_header_t *this);
171:
172: /**
173: * Set the responder spi.
174: *
175: * @param responder_spi responder_spi
176: */
177: void (*set_responder_spi) (ike_header_t *this, uint64_t responder_spi);
178:
179: /**
180: * Get the major version.
181: *
182: * @return major version
183: */
184: uint8_t (*get_maj_version) (ike_header_t *this);
185:
186: /**
187: * Set the major version.
188: *
189: * @param major major version
190: */
191: void (*set_maj_version) (ike_header_t *this, uint8_t major);
192:
193: /**
194: * Get the minor version.
195: *
196: * @return minor version
197: */
198: uint8_t (*get_min_version) (ike_header_t *this);
199:
200: /**
201: * Set the minor version.
202: *
203: * @param minor minor version
204: */
205: void (*set_min_version) (ike_header_t *this, uint8_t minor);
206:
207: /**
208: * Get the response flag.
209: *
210: * @return response flag
211: */
212: bool (*get_response_flag) (ike_header_t *this);
213:
214: /**
215: * Set the response flag-
216: *
217: * @param response response flag
218: */
219: void (*set_response_flag) (ike_header_t *this, bool response);
220:
221: /**
222: * Get "higher version supported"-flag.
223: *
224: * @return version flag
225: */
226: bool (*get_version_flag) (ike_header_t *this);
227:
228: /**
229: * Set the "higher version supported"-flag.
230: *
231: * @param version flag value
232: */
233: void (*set_version_flag)(ike_header_t *this, bool version);
234:
235: /**
236: * Get the initiator flag.
237: *
238: * @return initiator flag
239: */
240: bool (*get_initiator_flag) (ike_header_t *this);
241:
242: /**
243: * Set the initiator flag.
244: *
245: * @param initiator initiator flag
246: */
247: void (*set_initiator_flag) (ike_header_t *this, bool initiator);
248:
249: /**
250: * Get the encryption flag.
251: *
252: * @return encryption flag
253: */
254: bool (*get_encryption_flag) (ike_header_t *this);
255:
256: /**
257: * Set the encryption flag.
258: *
259: * @param encryption encryption flag
260: */
261: void (*set_encryption_flag) (ike_header_t *this, bool encryption);
262:
263: /**
264: * Get the commit flag.
265: *
266: * @return commit flag
267: */
268: bool (*get_commit_flag) (ike_header_t *this);
269:
270: /**
271: * Set the commit flag.
272: *
273: * @param commit commit flag
274: */
275: void (*set_commit_flag) (ike_header_t *this, bool commit);
276:
277: /**
278: * Get the authentication only flag.
279: *
280: * @return authonly flag
281: */
282: bool (*get_authonly_flag) (ike_header_t *this);
283:
284: /**
285: * Set the authentication only flag.
286: *
287: * @param authonly authonly flag
288: */
289: void (*set_authonly_flag) (ike_header_t *this, bool authonly);
290:
291: /**
292: * Get the exchange type.
293: *
294: * @return exchange type
295: */
296: uint8_t (*get_exchange_type) (ike_header_t *this);
297:
298: /**
299: * Set the exchange type.
300: *
301: * @param exchange_type exchange type
302: */
303: void (*set_exchange_type) (ike_header_t *this, uint8_t exchange_type);
304:
305: /**
306: * Get the message id.
307: *
308: * @return message id
309: */
310: uint32_t (*get_message_id) (ike_header_t *this);
311:
312: /**
313: * Set the message id.
314: *
315: * @param initiator_spi message id
316: */
317: void (*set_message_id) (ike_header_t *this, uint32_t message_id);
318:
319: /**
320: * Destroys a ike_header_t object.
321: */
322: void (*destroy) (ike_header_t *this);
323: };
324:
325: /**
326: * Create an empty ike_header_t object.
327: *
328: * @return ike_header_t object
329: */
330: ike_header_t *ike_header_create(void);
331:
332: /**
333: * Create an ike_header_t object for a specific major/minor version
334: *
335: * @return ike_header_t object
336: */
337: ike_header_t *ike_header_create_version(int major, int minor);
338:
339: #endif /** IKE_HEADER_H_ @}*/