4 * @brief Implementation of ike_sa_id_t.
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24 #include "ike_sa_id.h"
26 #include <utils/allocator.h>
29 typedef struct private_ike_sa_id_t private_ike_sa_id_t
;
32 * Private data of an ike_sa_id_t object.
34 struct private_ike_sa_id_t
{
36 * Public interface of ike_sa_id_t.
43 u_int64_t initiator_spi
;
48 u_int64_t responder_spi
;
51 * Role for specific IKE_SA.
53 bool is_initiator_flag
;
57 * Implementation of ike_sa_id_t.set_responder_spi.
59 static void set_responder_spi (private_ike_sa_id_t
*this, u_int64_t responder_spi
)
61 this->responder_spi
= responder_spi
;
65 * Implementation of ike_sa_id_t.set_initiator_spi.
67 static void set_initiator_spi(private_ike_sa_id_t
*this, u_int64_t initiator_spi
)
69 this->initiator_spi
= initiator_spi
;
73 * Implementation of ike_sa_id_t.get_initiator_spi.
75 static u_int64_t
get_initiator_spi (private_ike_sa_id_t
*this)
77 return this->initiator_spi
;
81 * Implementation of ike_sa_id_t.get_responder_spi.
83 static u_int64_t
get_responder_spi (private_ike_sa_id_t
*this)
85 return this->responder_spi
;
89 * Implementation of ike_sa_id_t.equals.
91 static bool equals (private_ike_sa_id_t
*this, private_ike_sa_id_t
*other
)
97 if ((this->is_initiator_flag
== other
->is_initiator_flag
) &&
98 (this->initiator_spi
== other
->initiator_spi
) &&
99 (this->responder_spi
== other
->responder_spi
))
101 /* private_ike_sa_id's are equal */
106 /* private_ike_sa_id's are not equal */
112 * Implementation of ike_sa_id_t.replace_values.
114 static void replace_values(private_ike_sa_id_t
*this, private_ike_sa_id_t
*other
)
116 this->initiator_spi
= other
->initiator_spi
;
117 this->responder_spi
= other
->responder_spi
;
118 this->is_initiator_flag
= other
->is_initiator_flag
;
122 * Implementation of ike_sa_id_t.is_initiator.
124 static bool is_initiator(private_ike_sa_id_t
*this)
126 return this->is_initiator_flag
;
130 * Implementation of ike_sa_id_t.switch_initiator.
132 static bool switch_initiator(private_ike_sa_id_t
*this)
134 if (this->is_initiator_flag
)
136 this->is_initiator_flag
= FALSE
;
140 this->is_initiator_flag
= TRUE
;
142 return this->is_initiator_flag
;
146 * Implementation of ike_sa_id_t.clone.
148 static ike_sa_id_t
* clone(private_ike_sa_id_t
*this)
150 return ike_sa_id_create(this->initiator_spi
, this->responder_spi
, this->is_initiator_flag
);
154 * Implementation of ike_sa_id_t.destroy.
156 static void destroy(private_ike_sa_id_t
*this)
158 allocator_free(this);
162 * Described in header.
164 ike_sa_id_t
* ike_sa_id_create(u_int64_t initiator_spi
, u_int64_t responder_spi
, bool is_initiator_flag
)
166 private_ike_sa_id_t
*this = allocator_alloc_thing(private_ike_sa_id_t
);
168 /* public functions */
169 this->public.set_responder_spi
= (void(*)(ike_sa_id_t
*,u_int64_t
)) set_responder_spi
;
170 this->public.set_initiator_spi
= (void(*)(ike_sa_id_t
*,u_int64_t
)) set_initiator_spi
;
171 this->public.get_responder_spi
= (u_int64_t(*)(ike_sa_id_t
*)) get_responder_spi
;
172 this->public.get_initiator_spi
= (u_int64_t(*)(ike_sa_id_t
*)) get_initiator_spi
;
173 this->public.equals
= (bool(*)(ike_sa_id_t
*,ike_sa_id_t
*)) equals
;
174 this->public.replace_values
= (void(*)(ike_sa_id_t
*,ike_sa_id_t
*)) replace_values
;
175 this->public.is_initiator
= (bool(*)(ike_sa_id_t
*)) is_initiator
;
176 this->public.switch_initiator
= (bool(*)(ike_sa_id_t
*)) switch_initiator
;
177 this->public.clone
= (ike_sa_id_t
*(*)(ike_sa_id_t
*)) clone
;
178 this->public.destroy
= (void(*)(ike_sa_id_t
*))destroy
;
181 this->initiator_spi
= initiator_spi
;
182 this->responder_spi
= responder_spi
;
183 this->is_initiator_flag
= is_initiator_flag
;
185 return (&this->public);