2 * @file ike_sa_manager.c
4 * @brief Implementation of ike_sa_mananger_t.
9 * Copyright (C) 2005-2006 Martin Willi
10 * Copyright (C) 2005 Jan Hutter
11 * Hochschule fuer Technik Rapperswil
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>.
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
27 #include "ike_sa_manager.h"
30 #include <sa/ike_sa_id.h>
32 #include <utils/linked_list.h>
34 typedef struct entry_t entry_t
;
37 * An entry in the linked list, contains IKE_SA, locking and lookup data.
42 * Number of threads waiting for this ike_sa_t object.
47 * Condvar where threads can wait until ike_sa_t object is free for use again.
49 pthread_cond_t condvar
;
52 * Is this ike_sa currently checked out?
57 * Does this SA drives out new threads?
59 bool driveout_new_threads
;
62 * Does this SA drives out waiting threads?
64 bool driveout_waiting_threads
;
67 * Identifiaction of an IKE_SA (SPIs).
69 ike_sa_id_t
*ike_sa_id
;
72 * The contained ike_sa_t object.
78 * Implementation of entry_t.destroy.
80 static status_t
entry_destroy(entry_t
*this)
82 /* also destroy IKE SA */
83 this->ike_sa
->destroy(this->ike_sa
);
84 this->ike_sa_id
->destroy(this->ike_sa_id
);
90 * Creates a new entry for the ike_sa_t list.
92 static entry_t
*entry_create(ike_sa_id_t
*ike_sa_id
)
94 entry_t
*this = malloc_thing(entry_t
);
96 this->waiting_threads
= 0;
97 pthread_cond_init(&(this->condvar
), NULL
);
99 /* we set checkout flag when we really give it out */
100 this->checked_out
= FALSE
;
101 this->driveout_new_threads
= FALSE
;
102 this->driveout_waiting_threads
= FALSE
;
104 /* ike_sa_id is always cloned */
105 this->ike_sa_id
= ike_sa_id
->clone(ike_sa_id
);
107 /* create new ike_sa */
108 this->ike_sa
= ike_sa_create(ike_sa_id
);
114 typedef struct private_ike_sa_manager_t private_ike_sa_manager_t
;
117 * Additional private members of ike_sa_manager_t.
119 struct private_ike_sa_manager_t
{
121 * Public interface of ike_sa_manager_t.
123 ike_sa_manager_t
public;
126 * Lock for exclusivly accessing the manager.
128 pthread_mutex_t mutex
;
131 * Linked list with entries for the ike_sa_t objects.
133 linked_list_t
*ike_sa_list
;
136 * A randomizer, to get random SPIs for our side
138 randomizer_t
*randomizer
;
142 * Implementation of private_ike_sa_manager_t.get_entry_by_id.
144 static status_t
get_entry_by_id(private_ike_sa_manager_t
*this, ike_sa_id_t
*ike_sa_id
, entry_t
**entry
)
146 linked_list_t
*list
= this->ike_sa_list
;
147 iterator_t
*iterator
;
151 /* create iterator over list of ike_sa's */
152 iterator
= list
->create_iterator(list
, TRUE
);
157 while (iterator
->iterate(iterator
, (void**)¤t
))
159 if (current
->ike_sa_id
->equals(current
->ike_sa_id
, ike_sa_id
))
161 DBG2(SIG_DBG_MGR
, "found entry by both SPIs");
166 if (ike_sa_id
->get_responder_spi(ike_sa_id
) == 0 ||
167 current
->ike_sa_id
->get_responder_spi(current
->ike_sa_id
) == 0)
169 /* seems to be a half ready ike_sa */
170 if ((current
->ike_sa_id
->get_initiator_spi(current
->ike_sa_id
) ==
171 ike_sa_id
->get_initiator_spi(ike_sa_id
)) &&
172 (current
->ike_sa_id
->is_initiator(ike_sa_id
) ==
173 ike_sa_id
->is_initiator(current
->ike_sa_id
)))
175 DBG2(SIG_DBG_MGR
, "found entry by initiator SPI");
183 iterator
->destroy(iterator
);
188 * Implementation of private_ike_sa_manager_t.get_entry_by_sa.
190 static status_t
get_entry_by_sa(private_ike_sa_manager_t
*this, ike_sa_t
*ike_sa
, entry_t
**entry
)
192 linked_list_t
*list
= this->ike_sa_list
;
193 iterator_t
*iterator
;
197 iterator
= list
->create_iterator(list
, TRUE
);
202 while (iterator
->iterate(iterator
, (void**)¤t
))
204 /* only pointers are compared */
205 if (current
->ike_sa
== ike_sa
)
207 DBG2(SIG_DBG_MGR
, "found entry by pointer");
213 iterator
->destroy(iterator
);
219 * Implementation of private_ike_sa_manager_s.delete_entry.
221 static status_t
delete_entry(private_ike_sa_manager_t
*this, entry_t
*entry
)
223 linked_list_t
*list
= this->ike_sa_list
;
224 iterator_t
*iterator
;
228 iterator
= list
->create_iterator(list
, TRUE
);
232 while (iterator
->iterate(iterator
, (void**)¤t
))
234 if (current
== entry
)
236 /* mark it, so now new threads can get this entry */
237 entry
->driveout_new_threads
= TRUE
;
238 /* wait until all workers have done their work */
239 while (entry
->waiting_threads
)
242 pthread_cond_broadcast(&(entry
->condvar
));
243 /* they will wake us again when their work is done */
244 pthread_cond_wait(&(entry
->condvar
), &(this->mutex
));
247 DBG2(SIG_DBG_MGR
, "found entry by pointer, deleting it");
248 iterator
->remove(iterator
);
249 entry_destroy(entry
);
254 iterator
->destroy(iterator
);
259 * Wait until no other thread is using an IKE_SA, return FALSE if entry not
262 static bool wait_for_entry(private_ike_sa_manager_t
*this, entry_t
*entry
)
264 if (entry
->driveout_new_threads
)
266 /* we are not allowed to get this */
269 while (entry
->checked_out
&& !entry
->driveout_waiting_threads
)
271 /* so wait until we can get it for us.
272 * we register us as waiting. */
273 entry
->waiting_threads
++;
274 pthread_cond_wait(&(entry
->condvar
), &(this->mutex
));
275 entry
->waiting_threads
--;
277 /* hm, a deletion request forbids us to get this SA, get next one */
278 if (entry
->driveout_waiting_threads
)
280 /* we must signal here, others may be waiting on it, too */
281 pthread_cond_signal(&(entry
->condvar
));
288 * Implementation of private_ike_sa_manager_t.get_next_spi.
290 static u_int64_t
get_next_spi(private_ike_sa_manager_t
*this)
294 this->randomizer
->get_pseudo_random_bytes(this->randomizer
, 8, (u_int8_t
*)&spi
);
300 * Implementation of of ike_sa_manager.checkout_by_id.
302 static ike_sa_t
* checkout_by_id(private_ike_sa_manager_t
*this,
305 identification_t
*my_id
,
306 identification_t
*other_id
)
308 iterator_t
*iterator
;
310 ike_sa_t
*ike_sa
= NULL
;
312 pthread_mutex_lock(&(this->mutex
));
314 iterator
= this->ike_sa_list
->create_iterator(this->ike_sa_list
, TRUE
);
315 while (iterator
->iterate(iterator
, (void**)&entry
))
317 identification_t
*found_my_id
, *found_other_id
;
318 host_t
*found_my_host
, *found_other_host
;
321 if (!wait_for_entry(this, entry
))
326 found_my_id
= entry
->ike_sa
->get_my_id(entry
->ike_sa
);
327 found_other_id
= entry
->ike_sa
->get_other_id(entry
->ike_sa
);
328 found_my_host
= entry
->ike_sa
->get_my_host(entry
->ike_sa
);
329 found_other_host
= entry
->ike_sa
->get_other_host(entry
->ike_sa
);
331 if (found_my_id
->get_type(found_my_id
) == ID_ANY
&&
332 found_other_id
->get_type(found_other_id
) == ID_ANY
)
334 /* IKE_SA has no IDs yet, so we can't use it */
338 /* compare ID and hosts. Supplied ID may contain wildcards, and IP
340 if ((found_my_host
->is_anyaddr(found_my_host
) ||
341 my_host
->ip_equals(my_host
, found_my_host
)) &&
342 (found_other_host
->is_anyaddr(found_other_host
) ||
343 other_host
->ip_equals(other_host
, found_other_host
)) &&
344 found_my_id
->matches(found_my_id
, my_id
, &wc
) &&
345 found_other_id
->matches(found_other_id
, other_id
, &wc
))
347 /* looks good, we take this one */
348 DBG2(SIG_DBG_MGR
, "found an existing IKE_SA for %H[%D]...%H[%D]",
349 my_host
, other_host
, my_id
, other_id
);
350 entry
->checked_out
= TRUE
;
351 ike_sa
= entry
->ike_sa
;
354 iterator
->destroy(iterator
);
358 u_int64_t initiator_spi
;
360 ike_sa_id_t
*new_ike_sa_id
;
362 initiator_spi
= get_next_spi(this);
363 new_ike_sa_id
= ike_sa_id_create(0, 0, TRUE
);
364 new_ike_sa_id
->set_initiator_spi(new_ike_sa_id
, initiator_spi
);
367 new_entry
= entry_create(new_ike_sa_id
);
368 DBG2(SIG_DBG_MGR
, "created IKE_SA: %J", new_ike_sa_id
);
369 new_ike_sa_id
->destroy(new_ike_sa_id
);
371 this->ike_sa_list
->insert_last(this->ike_sa_list
, new_entry
);
373 /* check ike_sa out */
374 DBG2(SIG_DBG_MGR
, "new IKE_SA created for IDs [%D]...[%D]", my_id
, other_id
);
375 new_entry
->checked_out
= TRUE
;
376 ike_sa
= new_entry
->ike_sa
;
378 pthread_mutex_unlock(&(this->mutex
));
379 charon
->bus
->set_sa(charon
->bus
, ike_sa
);
384 * Implementation of of ike_sa_manager.checkout.
386 static ike_sa_t
* checkout(private_ike_sa_manager_t
*this, ike_sa_id_t
*ike_sa_id
)
388 bool responder_spi_set
;
389 bool initiator_spi_set
;
390 bool original_initiator
;
391 ike_sa_t
*ike_sa
= NULL
;
393 DBG2(SIG_DBG_MGR
, "checkout IKE_SA: %J", ike_sa_id
);
395 DBG2(SIG_DBG_MGR
, "%d IKE_SAs in manager",
396 this->ike_sa_list
->get_count(this->ike_sa_list
));
398 /* each access is locked */
399 pthread_mutex_lock(&(this->mutex
));
401 responder_spi_set
= ike_sa_id
->get_responder_spi(ike_sa_id
);
402 initiator_spi_set
= ike_sa_id
->get_initiator_spi(ike_sa_id
);
403 original_initiator
= ike_sa_id
->is_initiator(ike_sa_id
);
405 if ((initiator_spi_set
&& responder_spi_set
) ||
406 ((initiator_spi_set
&& !responder_spi_set
) && (original_initiator
)))
408 /* we SHOULD have an IKE_SA for these SPIs in the list,
409 * if not, we can't handle the request...
412 /* look for the entry */
413 if (get_entry_by_id(this, ike_sa_id
, &entry
) == SUCCESS
)
415 if (wait_for_entry(this, entry
))
417 DBG2(SIG_DBG_MGR
, "IKE_SA successfully checked out");
418 /* ok, this IKE_SA is finally ours */
419 entry
->checked_out
= TRUE
;
420 ike_sa
= entry
->ike_sa
;
424 DBG2(SIG_DBG_MGR
, "IKE_SA found, but not allowed to check it out");
429 DBG2(SIG_DBG_MGR
, "IKE_SA not stored in list");
430 /* looks like there is no such IKE_SA, better luck next time... */
433 else if ((initiator_spi_set
&& !responder_spi_set
) && (!original_initiator
))
435 /* an IKE_SA_INIT from an another endpoint,
436 * he is the initiator.
437 * For simplicity, we do NOT check for retransmitted
438 * IKE_SA_INIT-Requests here, so EVERY single IKE_SA_INIT-
439 * Request (even a retransmitted one) will result in a
440 * IKE_SA. This could be improved...
442 u_int64_t responder_spi
;
445 /* set SPIs, we are the responder */
446 responder_spi
= get_next_spi(this);
448 /* we also set arguments spi, so its still valid */
449 ike_sa_id
->set_responder_spi(ike_sa_id
, responder_spi
);
452 new_entry
= entry_create(ike_sa_id
);
454 this->ike_sa_list
->insert_last(this->ike_sa_list
, new_entry
);
456 /* check ike_sa out */
457 DBG2(SIG_DBG_MGR
, "IKE_SA added to list of known IKE_SAs");
458 new_entry
->checked_out
= TRUE
;
459 ike_sa
= new_entry
->ike_sa
;
461 else if (!initiator_spi_set
&& !responder_spi_set
&& original_initiator
)
463 /* checkout of a new and unused IKE_SA, used for rekeying */
466 ike_sa_id
->set_initiator_spi(ike_sa_id
, get_next_spi(this));
468 new_entry
= entry_create(ike_sa_id
);
469 DBG2(SIG_DBG_MGR
, "created IKE_SA: %J", ike_sa_id
);
471 this->ike_sa_list
->insert_last(this->ike_sa_list
, new_entry
);
473 /* check ike_sa out */
474 new_entry
->checked_out
= TRUE
;
475 ike_sa
= new_entry
->ike_sa
;
479 /* responder set, initiator not: here is something seriously wrong! */
480 DBG2(SIG_DBG_MGR
, "invalid IKE_SA SPIs");
483 pthread_mutex_unlock(&(this->mutex
));
485 charon
->bus
->set_sa(charon
->bus
, ike_sa
);
490 * Implementation of of ike_sa_manager.checkout_by_child.
492 static ike_sa_t
* checkout_by_child(private_ike_sa_manager_t
*this,
495 iterator_t
*iterator
;
497 ike_sa_t
*ike_sa
= NULL
;
499 pthread_mutex_lock(&(this->mutex
));
501 iterator
= this->ike_sa_list
->create_iterator(this->ike_sa_list
, TRUE
);
502 while (iterator
->iterate(iterator
, (void**)&entry
))
504 if (wait_for_entry(this, entry
))
506 /* ok, access is exclusive for us, check for child */
507 if (entry
->ike_sa
->has_child_sa(entry
->ike_sa
, reqid
))
510 entry
->checked_out
= TRUE
;
511 ike_sa
= entry
->ike_sa
;
516 iterator
->destroy(iterator
);
517 pthread_mutex_unlock(&(this->mutex
));
519 charon
->bus
->set_sa(charon
->bus
, ike_sa
);
524 * Iterator hook for iterate, gets ike_sas instead of entries
526 static void* iterator_hook(void *value
)
528 return ((entry_t
*)value
)->ike_sa
;
532 * Implementation of ike_sa_manager_t.create_iterator.
534 static iterator_t
*create_iterator(private_ike_sa_manager_t
* this)
536 iterator_t
*iterator
= this->ike_sa_list
->create_iterator_locked(
537 this->ike_sa_list
, &this->mutex
);
538 /* register hook to iterator over ike_sas, not entries */
539 iterator
->set_iterator_hook(iterator
, iterator_hook
);
544 * Implementation of ike_sa_manager_t.checkin.
546 static status_t
checkin(private_ike_sa_manager_t
*this, ike_sa_t
*ike_sa
)
548 /* to check the SA back in, we look for the pointer of the ike_sa
550 * We can't search by SPI's since the MAY have changed (e.g. on reception
551 * of a IKE_SA_INIT response). Updating of the SPI MAY be necessary...
555 ike_sa_id_t
*ike_sa_id
;
557 ike_sa_id
= ike_sa
->get_id(ike_sa
);
559 DBG2(SIG_DBG_MGR
, "checkin IKE_SA: %J", ike_sa_id
);
561 pthread_mutex_lock(&(this->mutex
));
563 /* look for the entry */
564 if (get_entry_by_sa(this, ike_sa
, &entry
) == SUCCESS
)
566 /* ike_sa_id must be updated */
567 entry
->ike_sa_id
->replace_values(entry
->ike_sa_id
, ike_sa
->get_id(ike_sa
));
568 /* signal waiting threads */
569 entry
->checked_out
= FALSE
;
570 DBG2(SIG_DBG_MGR
, "check-in of IKE_SA successful.");
571 pthread_cond_signal(&(entry
->condvar
));
576 DBG2(SIG_DBG_MGR
, "tried to check in nonexisting IKE_SA");
577 /* this SA is no more, this REALLY should not happen */
581 DBG2(SIG_DBG_MGR
, "%d IKE_SAs in manager now",
582 this->ike_sa_list
->get_count(this->ike_sa_list
));
583 pthread_mutex_unlock(&(this->mutex
));
585 charon
->bus
->set_sa(charon
->bus
, NULL
);
591 * Implementation of ike_sa_manager_t.checkin_and_destroy.
593 static status_t
checkin_and_destroy(private_ike_sa_manager_t
*this, ike_sa_t
*ike_sa
)
595 /* deletion is a bit complex, we must garant that no thread is waiting for
597 * We take this SA from the list, and start signaling while threads
598 * are in the condvar.
602 ike_sa_id_t
*ike_sa_id
;
604 ike_sa_id
= ike_sa
->get_id(ike_sa
);
605 DBG2(SIG_DBG_MGR
, "checkin and destroy IKE_SA: %J", ike_sa_id
);
607 pthread_mutex_lock(&(this->mutex
));
609 if (get_entry_by_sa(this, ike_sa
, &entry
) == SUCCESS
)
611 /* drive out waiting threads, as we are in hurry */
612 entry
->driveout_waiting_threads
= TRUE
;
614 delete_entry(this, entry
);
616 DBG2(SIG_DBG_MGR
, "check-in and destroy of IKE_SA successful");
621 DBG2(SIG_DBG_MGR
, "tried to check-in and delete nonexisting IKE_SA");
625 pthread_mutex_unlock(&(this->mutex
));
626 charon
->bus
->set_sa(charon
->bus
, ike_sa
);
631 * Implementation of ike_sa_manager_t.delete.
633 static status_t
delete_(private_ike_sa_manager_t
*this, ike_sa_id_t
*ike_sa_id
)
635 /* deletion is a bit complex, we must garant that no thread is waiting for
637 * We take this SA from the list, and start signaling while threads
638 * are in the condvar.
643 DBG2(SIG_DBG_MGR
, "delete IKE_SA: %J", ike_sa_id
);
645 pthread_mutex_lock(&(this->mutex
));
647 if (get_entry_by_id(this, ike_sa_id
, &entry
) == SUCCESS
)
649 /* we try a delete. If it succeeds, our job is done here. The
650 * other peer will reply, and the IKE SA gets the finally deleted...
652 if (entry
->ike_sa
->delete(entry
->ike_sa
) == SUCCESS
)
654 DBG2(SIG_DBG_MGR
, "initiated delete for IKE_SA");
656 /* but if the IKE SA is not in a state where the deletion is
657 * negotiated with the other peer, we can destroy the IKE SA on our own.
667 DBG2(SIG_DBG_MGR
, "tried to delete nonexisting IKE_SA");
671 pthread_mutex_unlock(&(this->mutex
));
676 * Implementation of ike_sa_manager_t.delete_by_name.
678 static status_t
delete_by_name(private_ike_sa_manager_t
*this, char *name
)
680 iterator_t
*iterator
;
681 iterator_t
*child_iter
;
683 size_t name_len
= strlen(name
);
685 pthread_mutex_lock(&(this->mutex
));
687 iterator
= this->ike_sa_list
->create_iterator(this->ike_sa_list
, TRUE
);
688 while (iterator
->iterate(iterator
, (void**)&entry
))
690 if (wait_for_entry(this, entry
))
693 * name{x} matches completely
694 * name{} matches by name
695 * name matches by name
700 child_sa_t
*child_sa
;
702 ike_name
= entry
->ike_sa
->get_name(entry
->ike_sa
);
703 /* check if "name{x}" matches completely */
704 if (strcmp(name
, ike_name
) == 0)
708 /* check if name is in form of "name{}" and matches to ike_name */
709 else if (name_len
> 1 &&
710 name
[name_len
- 2] == '{' && name
[name_len
- 1] == '}' &&
711 strlen(ike_name
) > name_len
&&
712 ike_name
[name_len
- 2] == '{' &&
713 strncmp(name
, ike_name
, name_len
- 2) == 0)
717 /* finally, check if name is "name" and matches ike_name */
718 else if (name_len
== strchr(ike_name
, '{') - ike_name
&&
719 strncmp(name
, ike_name
, name_len
) == 0)
726 if (entry
->ike_sa
->delete(entry
->ike_sa
) == DESTROY_ME
)
728 delete_entry(this, entry
);
729 iterator
->reset(iterator
);
731 /* no need to check children, as we delete all */
735 /* and now the same game for all children. delete child_sa if:
736 * name[x] matches completely
737 * name[] matches by name
738 * name matches by name
740 child_iter
= entry
->ike_sa
->create_child_sa_iterator(entry
->ike_sa
);
741 while (child_iter
->iterate(child_iter
, (void**)&child_sa
))
743 /* skip ROUTED children, they have their "unroute" command */
744 if (child_sa
->get_state(child_sa
) == CHILD_ROUTED
)
749 child_name
= child_sa
->get_name(child_sa
);
751 /* check if "name[x]" matches completely */
752 if (strcmp(name
, child_name
) == 0)
756 /* check if name is in form of "name[]" and matches to child_name */
757 else if (name_len
> 1 &&
758 name
[name_len
- 2] == '[' && name
[name_len
- 1] == ']' &&
759 strlen(child_name
) > name_len
&&
760 child_name
[name_len
- 2] == '[' &&
761 strncmp(name
, child_name
, name_len
- 2) == 0)
765 /* finally, check if name is "name" and matches child_name */
766 else if (name_len
== strchr(child_name
, '[') - child_name
&&
767 strncmp(name
, child_name
, name_len
) == 0)
773 if (entry
->ike_sa
->delete_child_sa(entry
->ike_sa
,
774 child_sa
->get_protocol(child_sa
),
775 child_sa
->get_spi(child_sa
, TRUE
)) == DESTROY_ME
)
777 /* when a fatal error occurs, we are responsible to
778 * remove the IKE_SA */
779 delete_entry(this, entry
);
780 iterator
->reset(iterator
);
785 child_iter
->destroy(child_iter
);
788 iterator
->destroy(iterator
);
789 pthread_mutex_unlock(&(this->mutex
));
795 * Implementation of ike_sa_manager_t.destroy.
797 static void destroy(private_ike_sa_manager_t
*this)
799 /* destroy all list entries */
800 linked_list_t
*list
= this->ike_sa_list
;
801 iterator_t
*iterator
;
804 pthread_mutex_lock(&(this->mutex
));
805 DBG2(SIG_DBG_MGR
, "going to destroy IKE_SA manager and all managed IKE_SA's");
806 /* Step 1: drive out all waiting threads */
807 DBG2(SIG_DBG_MGR
, "set driveout flags for all stored IKE_SA's");
808 iterator
= list
->create_iterator(list
, TRUE
);
809 while (iterator
->iterate(iterator
, (void**)&entry
))
811 /* do not accept new threads, drive out waiting threads */
812 entry
->driveout_new_threads
= TRUE
;
813 entry
->driveout_waiting_threads
= TRUE
;
815 DBG2(SIG_DBG_MGR
, "wait for all threads to leave IKE_SA's");
816 /* Step 2: wait until all are gone */
817 iterator
->reset(iterator
);
818 while (iterator
->iterate(iterator
, (void**)&entry
))
820 while (entry
->waiting_threads
)
823 pthread_cond_broadcast(&(entry
->condvar
));
824 /* go sleeping until they are gone */
825 pthread_cond_wait(&(entry
->condvar
), &(this->mutex
));
828 DBG2(SIG_DBG_MGR
, "delete all IKE_SA's");
829 /* Step 3: initiate deletion of all IKE_SAs */
830 iterator
->reset(iterator
);
831 while (iterator
->iterate(iterator
, (void**)&entry
))
833 entry
->ike_sa
->delete(entry
->ike_sa
);
835 iterator
->destroy(iterator
);
837 DBG2(SIG_DBG_MGR
, "destroy all entries");
838 /* Step 4: destroy all entries */
839 list
->destroy_function(list
, (void*)entry_destroy
);
840 pthread_mutex_unlock(&(this->mutex
));
842 this->randomizer
->destroy(this->randomizer
);
848 * Described in header.
850 ike_sa_manager_t
*ike_sa_manager_create()
852 private_ike_sa_manager_t
*this = malloc_thing(private_ike_sa_manager_t
);
854 /* assign public functions */
855 this->public.destroy
= (void(*)(ike_sa_manager_t
*))destroy
;
856 this->public.checkout_by_id
= (ike_sa_t
*(*)(ike_sa_manager_t
*,host_t
*,host_t
*,identification_t
*,identification_t
*))checkout_by_id
;
857 this->public.checkout
= (ike_sa_t
*(*)(ike_sa_manager_t
*, ike_sa_id_t
*))checkout
;
858 this->public.checkout_by_child
= (ike_sa_t
*(*)(ike_sa_manager_t
*,u_int32_t
))checkout_by_child
;
859 this->public.create_iterator
= (iterator_t
*(*)(ike_sa_manager_t
*))create_iterator
;
860 this->public.checkin
= (status_t(*)(ike_sa_manager_t
*,ike_sa_t
*))checkin
;
861 this->public.delete = (status_t(*)(ike_sa_manager_t
*,ike_sa_id_t
*))delete_
;
862 this->public.delete_by_name
= (status_t(*)(ike_sa_manager_t
*,char*))delete_by_name
;
863 this->public.checkin_and_destroy
= (status_t(*)(ike_sa_manager_t
*,ike_sa_t
*))checkin_and_destroy
;
865 /* initialize private variables */
866 this->ike_sa_list
= linked_list_create();
867 pthread_mutex_init(&(this->mutex
), NULL
);
868 this->randomizer
= randomizer_create();
870 return (ike_sa_manager_t
*)this;