4 * @brief Class for identification of an IKE_SA
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
26 #include "ike_sa_id.h"
29 #include "utils/allocator.h"
32 * Private data of an ike_sa_id object
34 typedef struct private_ike_sa_id_s private_ike_sa_id_t
;
36 struct private_ike_sa_id_s
{
38 * Public part of a ike_sa_id object
48 u_int64_t initiator_spi
;
53 u_int64_t responder_spi
;
56 * Role for specific IKE_SA
64 * @brief implements function set_responder_spi of ike_sa_id_t
66 static status_t
set_responder_spi (private_ike_sa_id_t
*this, u_int64_t responder_spi
)
68 this->responder_spi
= responder_spi
;
72 static status_t
set_initiator_spi(private_ike_sa_id_t
*this, u_int64_t initiator_spi
)
74 this->initiator_spi
= initiator_spi
;
79 * @brief implements function initiator_spi_is_set of ike_sa_id_t
81 static bool initiator_spi_is_set (private_ike_sa_id_t
*this)
83 return (this->initiator_spi
!= 0);
87 * @brief implements function responder_spi_is_set of ike_sa_id_t
89 static bool responder_spi_is_set (private_ike_sa_id_t
*this)
91 return (this->responder_spi
!= 0);
95 * @brief implements function equals of ike_sa_id_t
97 static status_t
equals (private_ike_sa_id_t
*this,private_ike_sa_id_t
*other
, bool *are_equal
)
99 if ((this == NULL
)||(other
== NULL
))
103 if ((this->is_initiator
== other
->is_initiator
) &&
104 (this->initiator_spi
== other
->initiator_spi
) &&
105 (this->responder_spi
== other
->responder_spi
))
108 /* private_ike_sa_id's are equal */
113 /* private_ike_sa_id's are not equal */
121 * @brief implements function replace_values of ike_sa_id_t
123 status_t
replace_values (private_ike_sa_id_t
*this, private_ike_sa_id_t
*other
)
125 if ((this == NULL
) || (other
== NULL
))
130 this->initiator_spi
= other
->initiator_spi
;
131 this->responder_spi
= other
->responder_spi
;
132 this->is_initiator
= other
->is_initiator
;
138 * @brief implements function ike_sa_id_t.get_values
140 static status_t
get_values(private_ike_sa_id_t
*this, u_int64_t
*initiator
, u_int64_t
*responder
, bool *is_initiator
)
142 memcpy(initiator
, &(this->initiator_spi
), sizeof(this->initiator_spi
));
143 memcpy(responder
, &(this->responder_spi
), sizeof(this->responder_spi
));
145 *is_initiator
= this->is_initiator
;
152 * @brief implements function clone of ike_sa_id_t
154 static status_t
clone (private_ike_sa_id_t
*this, ike_sa_id_t
**clone_of_this
)
156 *clone_of_this
= ike_sa_id_create(this->initiator_spi
, this->responder_spi
, this->is_initiator
);
158 return (*clone_of_this
== NULL
) ? OUT_OF_RES
: SUCCESS
;
162 * @brief implements function destroy of ike_sa_id_t
164 static status_t
destroy (private_ike_sa_id_t
*this)
166 allocator_free(this);
171 * Described in Header-File
173 ike_sa_id_t
* ike_sa_id_create(u_int64_t initiator_spi
, u_int64_t responder_spi
, bool is_initiator
)
175 private_ike_sa_id_t
*this = allocator_alloc_thing(private_ike_sa_id_t
);
181 /* Public functions */
182 this->public.set_responder_spi
= (status_t(*)(ike_sa_id_t
*,u_int64_t
)) set_responder_spi
;
183 this->public.set_initiator_spi
= (status_t(*)(ike_sa_id_t
*,u_int64_t
)) set_initiator_spi
;
184 this->public.responder_spi_is_set
= (bool(*)(ike_sa_id_t
*)) responder_spi_is_set
;
185 this->public.initiator_spi_is_set
= (bool(*)(ike_sa_id_t
*)) initiator_spi_is_set
;
186 this->public.equals
= (status_t(*)(ike_sa_id_t
*,ike_sa_id_t
*,bool*)) equals
;
187 this->public.replace_values
= (status_t(*)(ike_sa_id_t
*,ike_sa_id_t
*)) replace_values
;
188 this->public.get_values
= (status_t(*)(ike_sa_id_t
*,u_int64_t
*,u_int64_t
*,bool*)) get_values
;
189 this->public.clone
= (status_t(*)(ike_sa_id_t
*,ike_sa_id_t
**)) clone
;
190 this->public.destroy
= (status_t(*)(ike_sa_id_t
*))destroy
;
193 this->initiator_spi
= initiator_spi
;
194 this->responder_spi
= responder_spi
;
195 this->is_initiator
= is_initiator
;
197 return (&this->public);