- finish functionality of ike_sa_manager
[strongswan.git] / Source / charon / ike_sa_manager.h
1 /**
2 * @file ike_sa_manager.h
3 *
4 * @brief Central point for managing IKE-SAs (creation, locking, deleting...)
5 *
6 */
7
8 /*
9 * Copyright (C) 2005 Jan Hutter, Martin Willi
10 * Hochschule fuer Technik Rapperswil
11 *
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>.
16 *
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
20 * for more details.
21 */
22
23 #ifndef IKE_SA_MANAGER_H_
24 #define IKE_SA_MANAGER_H_
25
26 #include "types.h"
27 #include "ike_sa.h"
28
29
30 /**
31 * @brief The IKE_SA-Manager manages the IKE_SAs ;-).
32 *
33 * To avoid access from multiple threads, IKE_SAs must be checked out from
34 * the manager, and checked back in after usage.
35 * The manager also handles deletion of SAs.
36 *
37 * @todo checking of double-checkouts from the same threads would be nice.
38 * This could be by comparing thread-ids via pthread_self()...
39 *
40 */
41 typedef struct ike_sa_manager_s ike_sa_manager_t;
42 struct ike_sa_manager_s {
43 /**
44 * @brief Checkout an IKE_SA, create it when necesarry
45 *
46 * Checks out a SA by its ID. An SA will be created, when:
47 * - Responder SPI is not set (when received an IKE_SA_INIT from initiator)
48 * - Both SPIs are not set (for initiating IKE_SA_INIT)
49 * Management of SPIs is the managers job, he will set it.
50 * This function blocks until SA is available for checkout.
51 *
52 * @warning checking out two times without checking in will
53 * result in a deadlock!
54 *
55 * @param ike_sa_manager the manager object
56 * @param ike_sa_id[in/out] the SA identifier, will be updated
57 * @param ike_sa[out] checked out SA
58 * @returns SUCCESS if checkout successful
59 * NOT_FOUND when no such SA is available
60 */
61 status_t (*checkout) (ike_sa_manager_t* ike_sa_manager, ike_sa_id_t *sa_id, ike_sa_t **ike_sa);
62 /**
63 * @brief Checkin the SA after usage
64 *
65 * @warning the pointer MUST NOT be used after checkin! The SA must be checked
66 * out again!
67 *
68 * @param ike_sa_manager the manager object
69 * @param ike_sa_id[in/out] the SA identifier, will be updated
70 * @param ike_sa[out] checked out SA
71 * @returns SUCCESS if checked in
72 * NOT_FOUND when not found (shouldn't happen!)
73 */
74 status_t (*checkin) (ike_sa_manager_t* ike_sa_manager, ike_sa_t *ike_sa);
75 /**
76 * @brief delete a SA, wich was not checked out
77 *
78 * @warning do not use this when the SA is already checked out, this will
79 * deadlock!
80 *
81 * @param ike_sa_manager the manager object
82 * @param ike_sa_id[in/out] the SA identifier
83 * @returns SUCCESS if found
84 * NOT_FOUND when no such SA is available
85 */
86 status_t (*delete) (ike_sa_manager_t* ike_sa_manager, ike_sa_id_t *ike_sa_id);
87 /**
88 * @brief delete a checked out SA
89 *
90 * @param ike_sa_manager the manager object
91 * @param ike_sa SA to delete
92 * @returns SUCCESS if found
93 * NOT_FOUND when no such SA is available
94 */
95 status_t (*checkin_and_delete) (ike_sa_manager_t* ike_sa_manager, ike_sa_t *ike_sa);
96
97 /**
98 * @brief Destroys the manager with all associated SAs
99 *
100 * Threads will be driven out, so all SAs can be deleted cleanly
101 *
102 * @param ike_sa_manager the manager object
103 * @returns SUCCESS if succeeded, FAILED otherwise
104 */
105 status_t (*destroy) (ike_sa_manager_t *ike_sa_manager);
106 };
107
108 /**
109 * @brief Create a manager
110 *
111 * @returns the manager
112 */
113 ike_sa_manager_t *ike_sa_manager_create();
114
115 #endif /*IKE_SA_MANAGER_H_*/