objects in source documentation renamed from xy-object to xy object
[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 "allocator.h"
25 #include "types.h"
26 #include "linked_list.h"
27 #include "ike_sa.h"
28
29
30 /**
31 * States in which a IKE_SA can actually be
32 */
33 typedef enum ike_sa_state_e ike_sa_state_t;
34
35 enum ike_sa_state_e{
36
37 /**
38 * IKE_SA is is not in a state
39 */
40 NO_STATE,
41
42 /**
43 * A IKE_SA_INIT-message was sent: role initiator
44 */
45 IKE_SA_INIT_REQUESTED,
46
47 /**
48 * A IKE_SA_INIT-message was replied: role responder
49 */
50 IKE_SA_INIT_RESPONDED,
51
52 /**
53 * An IKE_AUTH-message was sent after a successful
54 * IKE_SA_INIT-exchange: role initiator
55 */
56 IKE_AUTH_REQUESTED,
57
58 /**
59 * An IKE_AUTH-message was replied: role responder.
60 * In this state, all the informations for an IKE_SA
61 * and one CHILD_SA are known.
62 */
63 IKE_SA_INITIALIZED
64 };
65
66
67 /**
68 * Private data of an message_t object
69 */
70 typedef struct private_ike_sa_s private_ike_sa_t;
71
72 struct private_ike_sa_s {
73
74 /**
75 * Public part of a ike_sa_t object
76 */
77 ike_sa_t public;
78
79
80 /* Private values */
81 /**
82 * Identifier for the current IKE_SA
83 */
84 ike_sa_id_t *ike_sa_id;
85
86 /**
87 * Linked List containing the child sa's of the current IKE_SA
88 */
89 linked_list_t *child_sas;
90
91 /**
92 * Current state of the IKE_SA
93 */
94 ike_sa_state_t current_state;
95 };
96
97 /**
98 * @brief implements function process_message of private_ike_sa_t
99 */
100 static status_t process_message (private_ike_sa_t *this, message_t *message)
101 {
102 /* @TODO Add Message Processing here */
103 return SUCCESS;
104 }
105
106 /**
107 * @brief implements function process_configuration of private_ike_sa_t
108 */
109 static status_t process_configuration (private_ike_sa_t *this,configuration_t *configuration)
110 {
111 /*
112 * @TODO Add configuration processing here
113 */
114 return SUCCESS;
115 }
116
117 /**
118 * @brief implements function private_ike_sa_t.get_id
119 */
120 static ike_sa_id_t* get_id(private_ike_sa_t *this)
121 {
122 return this->ike_sa_id;
123 }
124
125 /**
126 * @brief implements function destroy of private_ike_sa_t
127 */
128 static status_t destroy (private_ike_sa_t *this)
129 {
130 if (this == NULL)
131 {
132 return FAILED;
133 }
134
135 this->ike_sa_id->destroy(this->ike_sa_id);
136
137 this->child_sas->destroy(this->child_sas);
138
139 allocator_free(this);
140
141 return SUCCESS;
142 }
143
144 /*
145 * Described in Header
146 */
147 ike_sa_t * ike_sa_create(ike_sa_id_t *ike_sa_id)
148 {
149 private_ike_sa_t *this = allocator_alloc_thing(private_ike_sa_t);
150 if (this == NULL)
151 {
152 return NULL;
153 }
154
155
156 /* Public functions */
157 this->public.process_message = (status_t(*)(ike_sa_t*, message_t*)) process_message;
158 this->public.process_configuration = (status_t(*)(ike_sa_t*, configuration_t*)) process_configuration;
159 this->public.get_id = (ike_sa_id_t*(*)(ike_sa_t*)) get_id;
160 this->public.destroy = (status_t(*)(ike_sa_t*))destroy;
161
162
163 /* initialize private fields */
164 if (ike_sa_id->clone(ike_sa_id,&(this->ike_sa_id)) != SUCCESS)
165 {
166 allocator_free(this);
167 return NULL;
168 }
169
170 this->child_sas = linked_list_create();
171 if (this->child_sas == NULL)
172 {
173 this->ike_sa_id->destroy(this->ike_sa_id);
174 allocator_free(this);
175 return NULL;
176 }
177
178 /* at creation time, IKE_SA isn't in a specific state */
179 this->current_state = NO_STATE;
180
181 return (&this->public);
182 }