2 * Copyright (C) 2005-2006 Martin Willi
3 * Copyright (C) 2005 Jan Hutter
4 * Hochschule fuer Technik Rapperswil
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 #include "ike_sa_id.h"
24 typedef struct private_ike_sa_id_t private_ike_sa_id_t
;
27 * Private data of an ike_sa_id_t object.
29 struct private_ike_sa_id_t
{
31 * Public interface of ike_sa_id_t.
38 u_int64_t initiator_spi
;
43 u_int64_t responder_spi
;
46 * Role for specific IKE_SA.
48 bool is_initiator_flag
;
52 * Implementation of ike_sa_id_t.set_responder_spi.
54 static void set_responder_spi (private_ike_sa_id_t
*this, u_int64_t responder_spi
)
56 this->responder_spi
= responder_spi
;
60 * Implementation of ike_sa_id_t.set_initiator_spi.
62 static void set_initiator_spi(private_ike_sa_id_t
*this, u_int64_t initiator_spi
)
64 this->initiator_spi
= initiator_spi
;
68 * Implementation of ike_sa_id_t.get_initiator_spi.
70 static u_int64_t
get_initiator_spi (private_ike_sa_id_t
*this)
72 return this->initiator_spi
;
76 * Implementation of ike_sa_id_t.get_responder_spi.
78 static u_int64_t
get_responder_spi (private_ike_sa_id_t
*this)
80 return this->responder_spi
;
84 * Implementation of ike_sa_id_t.equals.
86 static bool equals (private_ike_sa_id_t
*this, private_ike_sa_id_t
*other
)
92 if ((this->is_initiator_flag
== other
->is_initiator_flag
) &&
93 (this->initiator_spi
== other
->initiator_spi
) &&
94 (this->responder_spi
== other
->responder_spi
))
96 /* private_ike_sa_id's are equal */
101 /* private_ike_sa_id's are not equal */
107 * Implementation of ike_sa_id_t.replace_values.
109 static void replace_values(private_ike_sa_id_t
*this, private_ike_sa_id_t
*other
)
111 this->initiator_spi
= other
->initiator_spi
;
112 this->responder_spi
= other
->responder_spi
;
113 this->is_initiator_flag
= other
->is_initiator_flag
;
117 * Implementation of ike_sa_id_t.is_initiator.
119 static bool is_initiator(private_ike_sa_id_t
*this)
121 return this->is_initiator_flag
;
125 * Implementation of ike_sa_id_t.switch_initiator.
127 static bool switch_initiator(private_ike_sa_id_t
*this)
129 if (this->is_initiator_flag
)
131 this->is_initiator_flag
= FALSE
;
135 this->is_initiator_flag
= TRUE
;
137 return this->is_initiator_flag
;
141 * Implementation of ike_sa_id_t.clone.
143 static ike_sa_id_t
* clone_(private_ike_sa_id_t
*this)
145 return ike_sa_id_create(this->initiator_spi
, this->responder_spi
, this->is_initiator_flag
);
149 * Implementation of ike_sa_id_t.destroy.
151 static void destroy(private_ike_sa_id_t
*this)
157 * Described in header.
159 ike_sa_id_t
* ike_sa_id_create(u_int64_t initiator_spi
, u_int64_t responder_spi
, bool is_initiator_flag
)
161 private_ike_sa_id_t
*this = malloc_thing(private_ike_sa_id_t
);
163 /* public functions */
164 this->public.set_responder_spi
= (void(*)(ike_sa_id_t
*,u_int64_t
)) set_responder_spi
;
165 this->public.set_initiator_spi
= (void(*)(ike_sa_id_t
*,u_int64_t
)) set_initiator_spi
;
166 this->public.get_responder_spi
= (u_int64_t(*)(ike_sa_id_t
*)) get_responder_spi
;
167 this->public.get_initiator_spi
= (u_int64_t(*)(ike_sa_id_t
*)) get_initiator_spi
;
168 this->public.equals
= (bool(*)(ike_sa_id_t
*,ike_sa_id_t
*)) equals
;
169 this->public.replace_values
= (void(*)(ike_sa_id_t
*,ike_sa_id_t
*)) replace_values
;
170 this->public.is_initiator
= (bool(*)(ike_sa_id_t
*)) is_initiator
;
171 this->public.switch_initiator
= (bool(*)(ike_sa_id_t
*)) switch_initiator
;
172 this->public.clone
= (ike_sa_id_t
*(*)(ike_sa_id_t
*)) clone_
;
173 this->public.destroy
= (void(*)(ike_sa_id_t
*))destroy
;
176 this->initiator_spi
= initiator_spi
;
177 this->responder_spi
= responder_spi
;
178 this->is_initiator_flag
= is_initiator_flag
;
180 return &this->public;