- changed memory allocator functions to own allocator calls
[strongswan.git] / Source / charon / ike_sa.c
1 /**
2 * @file ike_sa.c
3 *
4 * @brief Class ike_sa_t. An object of this type is managed by an
5 * ike_sa_manager_t-object and represents an IKE_SA
6 *
7 */
8
9 /*
10 * Copyright (C) 2005 Jan Hutter, Martin Willi
11 * Hochschule fuer Technik Rapperswil
12 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
17 *
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * for more details.
22 */
23
24 #include "types.h"
25 #include "linked_list.h"
26 #include "ike_sa.h"
27
28
29 /**
30 * States in which a IKE_SA can actually be
31 */
32 typedef enum ike_sa_state_e ike_sa_state_t;
33
34 enum ike_sa_state_e{
35
36 /**
37 * IKE_SA is is not in a state
38 */
39 NO_STATE,
40
41 /**
42 * A IKE_SA_INIT-message was sent: role initiator
43 */
44 IKE_SA_INIT_REQUESTED,
45
46 /**
47 * A IKE_SA_INIT-message was replied: role responder
48 */
49 IKE_SA_INIT_RESPONDED,
50
51 /**
52 * An IKE_AUTH-message was sent after a successful
53 * IKE_SA_INIT-exchange: role initiator
54 */
55 IKE_AUTH_REQUESTED,
56
57 /**
58 * An IKE_AUTH-message was replied: role responder.
59 * In this state, all the informations for an IKE_SA
60 * and one CHILD_SA are known.
61 */
62 IKE_SA_INITIALIZED
63 };
64
65
66 /**
67 * Private data of an message_t object
68 */
69 typedef struct private_ike_sa_s private_ike_sa_t;
70
71 struct private_ike_sa_s {
72
73 /**
74 * Public part of a ike_sa_t object
75 */
76 ike_sa_t public;
77
78
79 /* Private values */
80 /**
81 * Identifier for the current IKE_SA
82 */
83 ike_sa_id_t *ike_sa_id;
84
85 /**
86 * Linked List containing the child sa's of the current IKE_SA
87 */
88 linked_list_t *child_sas;
89
90 /**
91 * Current state of the IKE_SA
92 */
93 ike_sa_state_t current_state;
94 };
95
96 /**
97 * @brief implements function process_message of private_ike_sa_t
98 */
99 static status_t process_message (private_ike_sa_t *this, message_t *message)
100 {
101 /* @TODO Add Message Processing here */
102 return SUCCESS;
103 }
104
105 /**
106 * @brief implements function process_configuration of private_ike_sa_t
107 */
108 static status_t process_configuration (private_ike_sa_t *this,configuration_t *configuration)
109 {
110 /*
111 * @TODO Add configuration processing here
112 */
113 return SUCCESS;
114 }
115
116 /**
117 * @brief implements function private_ike_sa_t.get_id
118 */
119 static ike_sa_id_t* get_id(private_ike_sa_t *this)
120 {
121 return this->ike_sa_id;
122 }
123
124 /**
125 * @brief implements function destroy of private_ike_sa_t
126 */
127 static status_t destroy (private_ike_sa_t *this)
128 {
129 if (this == NULL)
130 {
131 return FAILED;
132 }
133
134 this->ike_sa_id->destroy(this->ike_sa_id);
135
136 this->child_sas->destroy(this->child_sas);
137
138 allocator_free(this);
139
140 return SUCCESS;
141 }
142
143 /*
144 * Described in Header
145 */
146 ike_sa_t * ike_sa_create(ike_sa_id_t *ike_sa_id)
147 {
148 private_ike_sa_t *this = allocator_alloc_thing(private_ike_sa_t, "private_ike_sa_t");
149 if (this == NULL)
150 {
151 return NULL;
152 }
153
154
155 /* Public functions */
156 this->public.process_message = (status_t(*)(ike_sa_t*, message_t*)) process_message;
157 this->public.process_configuration = (status_t(*)(ike_sa_t*, configuration_t*)) process_configuration;
158 this->public.get_id = (ike_sa_id_t*(*)(ike_sa_t*)) get_id;
159 this->public.destroy = (status_t(*)(ike_sa_t*))destroy;
160
161
162 /* initialize private fields */
163 if (ike_sa_id->clone(ike_sa_id,&(this->ike_sa_id)) != SUCCESS)
164 {
165 allocator_free(this);
166 return NULL;
167 }
168
169 this->child_sas = linked_list_create();
170 if (this->child_sas == NULL)
171 {
172 this->ike_sa_id->destroy(this->ike_sa_id);
173 allocator_free(this);
174 return NULL;
175 }
176
177 /* at creation time, IKE_SA isn't in a specific state */
178 this->current_state = NO_STATE;
179
180 return (&this->public);
181 }