2 * @file ike_sa_manager.c
4 * @brief Implementation of ike_sa_mananger_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
26 #include "ike_sa_manager.h"
29 #include <sa/ike_sa_id.h>
30 #include <utils/logger.h>
31 #include <utils/logger_manager.h>
32 #include <utils/linked_list.h>
34 typedef struct ike_sa_entry_t ike_sa_entry_t
;
37 * An entry in the linked list, contains IKE_SA, locking and lookup data.
39 struct ike_sa_entry_t
{
41 * Destructor, also destroys associated ike_sa_t object.
43 status_t (*destroy
) (ike_sa_entry_t
*this);
46 * Number of threads waiting for this ike_sa_t object.
51 * Condvar where threads can wait until ike_sa_t object is free for use again.
53 pthread_cond_t condvar
;
56 * Is this ike_sa currently checked out?
61 * Does this SA drives out new threads?
63 bool driveout_new_threads
;
66 * Does this SA drives out waiting threads?
68 bool driveout_waiting_threads
;
71 * Identifiaction of an IKE_SA (SPIs).
73 ike_sa_id_t
*ike_sa_id
;
76 * The contained ike_sa_t object.
82 * Implementation of ike_sa_entry_t.destroy.
84 static status_t
ike_sa_entry_destroy(ike_sa_entry_t
*this)
86 /* also destroy IKE SA */
87 this->ike_sa
->destroy(this->ike_sa
);
88 this->ike_sa_id
->destroy(this->ike_sa_id
);
94 * @brief Creates a new entry for the ike_sa_t list.
96 * This constructor additionaly creates a new and empty SA.
98 * @param ike_sa_id The associated ike_sa_id_t, will be cloned
99 * @return ike_sa_entry_t object
101 static ike_sa_entry_t
*ike_sa_entry_create(ike_sa_id_t
*ike_sa_id
)
103 ike_sa_entry_t
*this = malloc_thing(ike_sa_entry_t
);
105 /* destroy function */
106 this->destroy
= ike_sa_entry_destroy
;
108 this->waiting_threads
= 0;
109 pthread_cond_init(&(this->condvar
), NULL
);
111 /* we set checkout flag when we really give it out */
112 this->checked_out
= FALSE
;
113 this->driveout_new_threads
= FALSE
;
114 this->driveout_waiting_threads
= FALSE
;
116 /* ike_sa_id is always cloned */
117 this->ike_sa_id
= ike_sa_id
->clone(ike_sa_id
);
119 /* create new ike_sa */
120 this->ike_sa
= ike_sa_create(ike_sa_id
);
126 typedef struct private_ike_sa_manager_t private_ike_sa_manager_t
;
129 * Additional private members of ike_sa_manager_t.
131 struct private_ike_sa_manager_t
{
133 * Public interface of ike_sa_manager_t.
135 ike_sa_manager_t
public;
138 * @brief Get next spi.
140 * We give out SPIs incremental starting at 1.
142 * @param this the ike_sa_manager
143 * @return the next spi
145 u_int64_t (*get_next_spi
) (private_ike_sa_manager_t
*this);
148 * @brief Find the ike_sa_entry_t object in the list by SPIs.
150 * This function simply iterates over the linked list. A hash-table
151 * would be more efficient when storing a lot of IKE_SAs...
153 * @param this calling object
154 * @param ike_sa_id id of the ike_sa, containing SPIs
155 * @param[out] entry pointer to set to the found entry
157 * - SUCCESS when found,
158 * - NOT_FOUND when no such ike_sa_id in list
160 status_t (*get_entry_by_id
) (private_ike_sa_manager_t
*this, ike_sa_id_t
*ike_sa_id
, ike_sa_entry_t
**entry
);
163 * @brief Find the ike_sa_entry_t in the list by pointer to SA.
165 * This function simply iterates over the linked list. A hash-table
166 * would be more efficient when storing a lot of IKE_SAs...
168 * @param this calling object
169 * @param ike_sa pointer to the ike_sa
170 * @param[out] entry pointer to set to the found entry
172 * - SUCCESS when found,
173 * - NOT_FOUND when no such ike_sa_id in list
175 status_t (*get_entry_by_sa
) (private_ike_sa_manager_t
*this, ike_sa_t
*ike_sa
, ike_sa_entry_t
**entry
);
178 * @brief Felete an entry from the linked list.
180 * @param this calling object
181 * @param entry entry to delete
183 * - SUCCESS when found,
184 * - NOT_FOUND when no such ike_sa_id in list
186 status_t (*delete_entry
) (private_ike_sa_manager_t
*this, ike_sa_entry_t
*entry
);
189 * Lock for exclusivly accessing the manager.
191 pthread_mutex_t mutex
;
194 * Logger used for this IKE SA Manager.
199 * Linked list with entries for the ike_sa_t objects.
201 linked_list_t
*ike_sa_list
;
204 * A randomizer, to get random SPIs for our side
206 randomizer_t
*randomizer
;
210 * Implementation of private_ike_sa_manager_t.get_entry_by_id.
212 static status_t
get_entry_by_id(private_ike_sa_manager_t
*this, ike_sa_id_t
*ike_sa_id
, ike_sa_entry_t
**entry
)
214 linked_list_t
*list
= this->ike_sa_list
;
215 iterator_t
*iterator
;
218 /* create iterator over list of ike_sa's */
219 iterator
= list
->create_iterator(list
, TRUE
);
224 while (iterator
->has_next(iterator
))
226 ike_sa_entry_t
*current
;
228 iterator
->current(iterator
, (void**)¤t
);
229 if (current
->ike_sa_id
->get_responder_spi(current
->ike_sa_id
) == 0)
231 /* seems to be a half ready ike_sa */
232 if ((current
->ike_sa_id
->get_initiator_spi(current
->ike_sa_id
) == ike_sa_id
->get_initiator_spi(ike_sa_id
))
233 && (ike_sa_id
->is_initiator(ike_sa_id
) == current
->ike_sa_id
->is_initiator(current
->ike_sa_id
)))
235 this->logger
->log(this->logger
,CONTROL
| LEVEL2
,"Found entry by initiator spi %d",ike_sa_id
->get_initiator_spi(ike_sa_id
));
241 else if (ike_sa_id
->get_responder_spi(ike_sa_id
) == 0)
243 if ((current
->ike_sa_id
->get_initiator_spi(current
->ike_sa_id
) == ike_sa_id
->get_initiator_spi(ike_sa_id
))
244 && (ike_sa_id
->is_initiator(ike_sa_id
) == current
->ike_sa_id
->is_initiator(current
->ike_sa_id
)))
246 this->logger
->log(this->logger
,CONTROL
| LEVEL2
,"Found entry by initiator spi %d",ike_sa_id
->get_initiator_spi(ike_sa_id
));
252 if (current
->ike_sa_id
->equals(current
->ike_sa_id
, ike_sa_id
))
254 this->logger
->log(this->logger
,CONTROL
| LEVEL2
,"Found entry by full ID");
261 iterator
->destroy(iterator
);
266 * Implementation of private_ike_sa_manager_t.get_entry_by_sa.
268 static status_t
get_entry_by_sa(private_ike_sa_manager_t
*this, ike_sa_t
*ike_sa
, ike_sa_entry_t
**entry
)
270 linked_list_t
*list
= this->ike_sa_list
;
271 iterator_t
*iterator
;
274 iterator
= list
->create_iterator(list
, TRUE
);
279 while (iterator
->has_next(iterator
))
281 ike_sa_entry_t
*current
;
282 iterator
->current(iterator
, (void**)¤t
);
283 /* only pointers are compared */
284 if (current
->ike_sa
== ike_sa
)
286 this->logger
->log(this->logger
,CONTROL
| LEVEL2
,"Found entry by pointer");
292 iterator
->destroy(iterator
);
298 * Implementation of private_ike_sa_manager_s.delete_entry.
300 static status_t
delete_entry(private_ike_sa_manager_t
*this, ike_sa_entry_t
*entry
)
302 linked_list_t
*list
= this->ike_sa_list
;
303 iterator_t
*iterator
;
306 iterator
= list
->create_iterator(list
, TRUE
);
310 while (iterator
->has_next(iterator
))
312 ike_sa_entry_t
*current
;
313 iterator
->current(iterator
, (void**)¤t
);
314 if (current
== entry
)
316 this->logger
->log(this->logger
,CONTROL
| LEVEL2
,"Found entry by pointer. Going to delete it.");
317 iterator
->remove(iterator
);
318 entry
->destroy(entry
);
323 iterator
->destroy(iterator
);
329 * Implementation of private_ike_sa_manager_t.get_next_spi.
331 static u_int64_t
get_next_spi(private_ike_sa_manager_t
*this)
335 this->randomizer
->get_pseudo_random_bytes(this->randomizer
, 8, (u_int8_t
*)&spi
);
341 * Implementation of of ike_sa_manager.create_and_checkout.
343 static void create_and_checkout(private_ike_sa_manager_t
*this,ike_sa_t
**ike_sa
)
345 u_int64_t initiator_spi
;
346 ike_sa_entry_t
*new_ike_sa_entry
;
347 ike_sa_id_t
*new_ike_sa_id
;
349 initiator_spi
= this->get_next_spi(this);
350 new_ike_sa_id
= ike_sa_id_create(0, 0, TRUE
);
351 new_ike_sa_id
->set_initiator_spi(new_ike_sa_id
, initiator_spi
);
354 new_ike_sa_entry
= ike_sa_entry_create(new_ike_sa_id
);
355 new_ike_sa_id
->destroy(new_ike_sa_id
);
357 /* each access is locked */
358 pthread_mutex_lock(&(this->mutex
));
360 this->ike_sa_list
->insert_last(this->ike_sa_list
, new_ike_sa_entry
);
362 /* check ike_sa out */
363 this->logger
->log(this->logger
,CONTROL
| LEVEL1
,"New IKE_SA created and added to list of known IKE_SA's");
364 new_ike_sa_entry
->checked_out
= TRUE
;
365 *ike_sa
= new_ike_sa_entry
->ike_sa
;
367 pthread_mutex_unlock(&(this->mutex
));
371 * Implementation of of ike_sa_manager.checkout.
373 static status_t
checkout(private_ike_sa_manager_t
*this, ike_sa_id_t
*ike_sa_id
, ike_sa_t
**ike_sa
)
375 bool responder_spi_set
;
376 bool initiator_spi_set
;
377 bool original_initiator
;
380 /* each access is locked */
381 pthread_mutex_lock(&(this->mutex
));
383 responder_spi_set
= (FALSE
!= ike_sa_id
->get_responder_spi(ike_sa_id
));
384 initiator_spi_set
= (FALSE
!= ike_sa_id
->get_initiator_spi(ike_sa_id
));
385 original_initiator
= ike_sa_id
->is_initiator(ike_sa_id
);
387 if ((initiator_spi_set
&& responder_spi_set
) ||
388 ((initiator_spi_set
&& !responder_spi_set
) && (original_initiator
)))
390 /* we SHOULD have an IKE_SA for these SPIs in the list,
391 * if not, we can't handle the request...
393 ike_sa_entry_t
*entry
;
394 /* look for the entry */
395 if (this->get_entry_by_id(this, ike_sa_id
, &entry
) == SUCCESS
)
397 /* can we give this ike_sa out to new requesters?*/
398 if (entry
->driveout_new_threads
)
400 this->logger
->log(this->logger
,CONTROL
|LEVEL1
,"Drive out new thread for existing IKE_SA");
406 /* is this IKE_SA already checked out ??
407 * are we welcome to get this SA ? */
408 while (entry
->checked_out
&& !entry
->driveout_waiting_threads
)
410 /* so wait until we can get it for us.
411 * we register us as waiting.
413 entry
->waiting_threads
++;
414 pthread_cond_wait(&(entry
->condvar
), &(this->mutex
));
415 entry
->waiting_threads
--;
418 /* hm, a deletion request forbids us to get this SA, go home */
419 if (entry
->driveout_waiting_threads
)
421 /* we must signal here, others are interested that we leave */
422 pthread_cond_signal(&(entry
->condvar
));
423 this->logger
->log(this->logger
,CONTROL
|LEVEL1
,"Drive out waiting thread for existing IKE_SA");
428 this->logger
->log(this->logger
,CONTROL
|LEVEL2
,"IKE SA successfully checked out");
429 /* ok, this IKE_SA is finally ours */
430 entry
->checked_out
= TRUE
;
431 *ike_sa
= entry
->ike_sa
;
432 /* DON'T use return, we must unlock the mutex! */
439 this->logger
->log(this->logger
,ERROR
| LEVEL1
,"IKE SA not stored in known IKE_SA list");
440 /* looks like there is no such IKE_SA, better luck next time... */
441 /* DON'T use return, we must unlock the mutex! */
445 else if ((initiator_spi_set
&& !responder_spi_set
) && (!original_initiator
))
447 /* an IKE_SA_INIT from an another endpoint,
448 * he is the initiator.
449 * For simplicity, we do NOT check for retransmitted
450 * IKE_SA_INIT-Requests here, so EVERY single IKE_SA_INIT-
451 * Request (even a retransmitted one) will result in a
452 * IKE_SA. This could be improved...
454 u_int64_t responder_spi
;
455 ike_sa_entry_t
*new_ike_sa_entry
;
458 /* set SPIs, we are the responder */
459 responder_spi
= this->get_next_spi(this);
461 /* we also set arguments spi, so its still valid */
462 ike_sa_id
->set_responder_spi(ike_sa_id
, responder_spi
);
465 new_ike_sa_entry
= ike_sa_entry_create(ike_sa_id
);
467 this->ike_sa_list
->insert_last(this->ike_sa_list
, new_ike_sa_entry
);
469 /* check ike_sa out */
470 this->logger
->log(this->logger
,CONTROL
| LEVEL1
,"IKE_SA added to list of known IKE_SA's");
471 new_ike_sa_entry
->checked_out
= TRUE
;
472 *ike_sa
= new_ike_sa_entry
->ike_sa
;
478 /* responder set, initiator not: here is something seriously wrong! */
479 this->logger
->log(this->logger
,ERROR
| LEVEL1
, "Invalid IKE_SA SPI's");
480 /* DON'T use return, we must unlock the mutex! */
481 retval
= INVALID_ARG
;
484 pthread_mutex_unlock(&(this->mutex
));
485 /* OK, unlocked... */
490 * Implementation of of ike_sa_manager.checkout_by_hosts.
492 static status_t
checkout_by_hosts(private_ike_sa_manager_t
*this, host_t
*me
, host_t
*other
, ike_sa_t
**ike_sa
)
494 iterator_t
*iterator
;
495 ike_sa_id_t
*ike_sa_id
= NULL
;
497 pthread_mutex_lock(&(this->mutex
));
499 iterator
= this->ike_sa_list
->create_iterator(this->ike_sa_list
, TRUE
);
500 while (iterator
->has_next(iterator
))
502 ike_sa_entry_t
*current
;
503 host_t
*sa_me
, *sa_other
;
505 iterator
->current(iterator
, (void**)¤t
);
506 sa_me
= current
->ike_sa
->get_my_host(current
->ike_sa
);
507 sa_other
= current
->ike_sa
->get_other_host(current
->ike_sa
);
509 /* one end may be default/any, but not both */
510 if (me
->is_default_route(me
))
512 if (other
->is_default_route(other
))
516 if (other
->equals(other
, sa_other
))
519 ike_sa_id
= current
->ike_sa_id
;
522 else if (other
->is_default_route(other
))
524 if (me
->equals(me
, sa_me
))
527 ike_sa_id
= current
->ike_sa_id
;
532 if (me
->equals(me
, sa_me
) && other
->equals(other
, sa_other
))
535 ike_sa_id
= current
->ike_sa_id
;
539 iterator
->destroy(iterator
);
540 pthread_mutex_unlock(&(this->mutex
));
544 /* checkout is done in the checkout function, since its rather complex */
545 return checkout(this, ike_sa_id
, ike_sa
);
551 * Implementation of ike_sa_manager_t.get_ike_sa_list.
553 linked_list_t
*get_ike_sa_list(private_ike_sa_manager_t
* this)
556 iterator_t
*iterator
;
558 pthread_mutex_lock(&(this->mutex
));
560 list
= linked_list_create();
561 iterator
= this->ike_sa_list
->create_iterator(this->ike_sa_list
, TRUE
);
562 while (iterator
->has_next(iterator
))
564 ike_sa_entry_t
*entry
;
565 iterator
->current(iterator
, (void**)&entry
);
566 list
->insert_last(list
, (void*)entry
->ike_sa_id
->clone(entry
->ike_sa_id
));
568 iterator
->destroy(iterator
);
570 pthread_mutex_unlock(&(this->mutex
));
575 * Implementation of ike_sa_manager_t.get_ike_sa_list_by_name.
577 linked_list_t
*get_ike_sa_list_by_name(private_ike_sa_manager_t
* this, const char *name
)
580 iterator_t
*iterator
;
582 pthread_mutex_lock(&(this->mutex
));
584 list
= linked_list_create();
585 iterator
= this->ike_sa_list
->create_iterator(this->ike_sa_list
, TRUE
);
586 while (iterator
->has_next(iterator
))
588 ike_sa_entry_t
*entry
;
589 connection_t
*connection
;
591 iterator
->current(iterator
, (void**)&entry
);
592 connection
= entry
->ike_sa
->get_connection(entry
->ike_sa
);
593 if (strcmp(name
, connection
->get_name(connection
)) == 0)
595 list
->insert_last(list
, (void*)entry
->ike_sa_id
->clone(entry
->ike_sa_id
));
598 iterator
->destroy(iterator
);
600 pthread_mutex_unlock(&(this->mutex
));
605 * Implementation of ike_sa_manager_t.log_status.
607 static void log_status(private_ike_sa_manager_t
* this, logger_t
* logger
, char* name
)
609 iterator_t
*iterator
;
611 pthread_mutex_lock(&(this->mutex
));
613 iterator
= this->ike_sa_list
->create_iterator(this->ike_sa_list
, TRUE
);
614 while (iterator
->has_next(iterator
))
616 ike_sa_entry_t
*entry
;
617 iterator
->current(iterator
, (void**)&entry
);
618 entry
->ike_sa
->log_status(entry
->ike_sa
, logger
, name
);
620 iterator
->destroy(iterator
);
622 pthread_mutex_unlock(&(this->mutex
));
626 * Implementation of ike_sa_manager_t.checkin.
628 static status_t
checkin(private_ike_sa_manager_t
*this, ike_sa_t
*ike_sa
)
630 /* to check the SA back in, we look for the pointer of the ike_sa
632 * We can't search by SPI's since the MAY have changed (e.g. on reception
633 * of a IKE_SA_INIT response). Updating of the SPI MAY be necessary...
636 ike_sa_entry_t
*entry
;
638 pthread_mutex_lock(&(this->mutex
));
640 /* look for the entry */
641 if (this->get_entry_by_sa(this, ike_sa
, &entry
) == SUCCESS
)
643 /* ike_sa_id must be updated */
644 entry
->ike_sa_id
->replace_values(entry
->ike_sa_id
, ike_sa
->get_id(ike_sa
));
645 /* signal waiting threads */
646 entry
->checked_out
= FALSE
;
647 this->logger
->log(this->logger
,CONTROL
| LEVEL1
,"Checkin of IKE_SA successful.");
648 pthread_cond_signal(&(entry
->condvar
));
653 this->logger
->log(this->logger
,ERROR
,"Fatal Error: Tried to checkin nonexisting IKE_SA");
654 /* this SA is no more, this REALLY should not happen */
657 pthread_mutex_unlock(&(this->mutex
));
663 * Implementation of ike_sa_manager_t.checkin_and_delete.
665 static status_t
checkin_and_delete(private_ike_sa_manager_t
*this, ike_sa_t
*ike_sa
)
667 /* deletion is a bit complex, we must garant that no thread is waiting for
669 * We take this SA from the list, and start signaling while threads
670 * are in the condvar.
672 ike_sa_entry_t
*entry
;
675 pthread_mutex_lock(&(this->mutex
));
677 if (this->get_entry_by_sa(this, ike_sa
, &entry
) == SUCCESS
)
679 /* mark it, so now new threads can acquire this SA */
680 entry
->driveout_new_threads
= TRUE
;
681 /* additionaly, drive out waiting threads */
682 entry
->driveout_waiting_threads
= TRUE
;
684 /* wait until all workers have done their work */
685 while (entry
->waiting_threads
> 0)
687 /* let the other threads do some work*/
688 pthread_cond_signal(&(entry
->condvar
));
689 /* and the nice thing, they will wake us again when their work is done */
690 pthread_cond_wait(&(entry
->condvar
), &(this->mutex
));
692 /* ok, we are alone now, no threads waiting in the entry's condvar */
693 this->delete_entry(this, entry
);
694 this->logger
->log(this->logger
,CONTROL
| LEVEL1
,"Checkin and delete of IKE_SA successful");
699 this->logger
->log(this->logger
,ERROR
,"Fatal Error: Tried to checkin and delete nonexisting IKE_SA");
703 pthread_mutex_unlock(&(this->mutex
));
708 * Implementation of ike_sa_manager_t.delete.
710 static status_t
delete(private_ike_sa_manager_t
*this, ike_sa_id_t
*ike_sa_id
)
712 /* deletion is a bit complex, we must garant that no thread is waiting for
714 * We take this SA from the list, and start signaling while threads
715 * are in the condvar.
717 ike_sa_entry_t
*entry
;
720 pthread_mutex_lock(&(this->mutex
));
722 if (this->get_entry_by_id(this, ike_sa_id
, &entry
) == SUCCESS
)
724 /* mark it, so now new threads can acquire this SA */
725 entry
->driveout_new_threads
= TRUE
;
727 /* wait until all workers have done their work */
728 while (entry
->waiting_threads
)
731 pthread_cond_signal(&(entry
->condvar
));
732 /* and the nice thing, they will wake us again when their work is done */
733 pthread_cond_wait(&(entry
->condvar
), &(this->mutex
));
735 /* ok, we are alone now, no threads waiting in the entry's condvar */
736 this->delete_entry(this, entry
);
737 this->logger
->log(this->logger
,CONTROL
| LEVEL1
,"Delete of IKE_SA successful");
742 this->logger
->log(this->logger
,ERROR
,"Fatal Error: Tried to delete nonexisting IKE_SA");
746 pthread_mutex_unlock(&(this->mutex
));
751 * Implementation of ike_sa_manager_t.destroy.
753 static void destroy(private_ike_sa_manager_t
*this)
755 /* destroy all list entries */
756 linked_list_t
*list
= this->ike_sa_list
;
757 iterator_t
*iterator
;
758 ike_sa_entry_t
*entry
;
760 pthread_mutex_lock(&(this->mutex
));
762 this->logger
->log(this->logger
,CONTROL
| LEVEL1
,"Going to destroy IKE_SA manager and all managed IKE_SA's");
764 /* Step 1: drive out all waiting threads */
765 iterator
= list
->create_iterator(list
, TRUE
);
767 this->logger
->log(this->logger
,CONTROL
| LEVEL2
,"Set driveout flags for all stored IKE_SA's");
768 while (iterator
->has_next(iterator
))
770 iterator
->current(iterator
, (void**)&entry
);
771 /* do not accept new threads, drive out waiting threads */
772 entry
->driveout_new_threads
= TRUE
;
773 entry
->driveout_waiting_threads
= TRUE
;
776 this->logger
->log(this->logger
,CONTROL
| LEVEL2
,"Wait for all threads to leave IKE_SA's");
777 /* Step 2: wait until all are gone */
778 iterator
->reset(iterator
);
779 while (iterator
->has_next(iterator
))
781 iterator
->current(iterator
, (void**)&entry
);
782 while (entry
->waiting_threads
)
785 pthread_cond_signal(&(entry
->condvar
));
786 /* go sleeping until they are gone */
787 pthread_cond_wait(&(entry
->condvar
), &(this->mutex
));
790 this->logger
->log(this->logger
,CONTROL
| LEVEL2
,"Delete all IKE_SA's");
791 /* Step 3: delete all entries */
792 iterator
->destroy(iterator
);
794 while (list
->get_count(list
) > 0)
796 list
->get_first(list
, (void**)&entry
);
797 this->delete_entry(this, entry
);
800 this->logger
->log(this->logger
,CONTROL
| LEVEL2
,"IKE_SA's deleted");
801 pthread_mutex_unlock(&(this->mutex
));
803 this->randomizer
->destroy(this->randomizer
);
809 * Described in header.
811 ike_sa_manager_t
*ike_sa_manager_create()
813 private_ike_sa_manager_t
*this = malloc_thing(private_ike_sa_manager_t
);
815 /* assign public functions */
816 this->public.destroy
= (void(*)(ike_sa_manager_t
*))destroy
;
817 this->public.create_and_checkout
= (void(*)(ike_sa_manager_t
*,ike_sa_t
**))create_and_checkout
;
818 this->public.checkout
= (status_t(*)(ike_sa_manager_t
*, ike_sa_id_t
*,ike_sa_t
**))checkout
;
819 this->public.checkout_by_hosts
= (status_t(*)(ike_sa_manager_t
*,host_t
*,host_t
*,ike_sa_t
**))checkout_by_hosts
;
820 this->public.get_ike_sa_list
= (linked_list_t
*(*)(ike_sa_manager_t
*))get_ike_sa_list
;
821 this->public.get_ike_sa_list_by_name
= (linked_list_t
*(*)(ike_sa_manager_t
*,const char*))get_ike_sa_list_by_name
;
822 this->public.log_status
= (void(*)(ike_sa_manager_t
*,logger_t
*,char*))log_status
;
823 this->public.checkin
= (status_t(*)(ike_sa_manager_t
*,ike_sa_t
*))checkin
;
824 this->public.delete = (status_t(*)(ike_sa_manager_t
*,ike_sa_id_t
*))delete;
825 this->public.checkin_and_delete
= (status_t(*)(ike_sa_manager_t
*,ike_sa_t
*))checkin_and_delete
;
827 /* initialize private functions */
828 this->get_next_spi
= get_next_spi
;
829 this->get_entry_by_sa
= get_entry_by_sa
;
830 this->get_entry_by_id
= get_entry_by_id
;
831 this->delete_entry
= delete_entry
;
833 /* initialize private variables */
834 this->logger
= logger_manager
->get_logger(logger_manager
, IKE_SA_MANAGER
);
836 this->ike_sa_list
= linked_list_create();
838 pthread_mutex_init(&(this->mutex
), NULL
);
840 this->randomizer
= randomizer_create();
842 return (ike_sa_manager_t
*)this;