- code cleaned up
[strongswan.git] / Source / charon / sa / ike_sa_manager.h
1 /**
2 * @file ike_sa_manager.h
3 *
4 * @brief Interface of ike_sa_manager_t.
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 <sa/ike_sa.h>
28
29
30 typedef struct ike_sa_manager_t ike_sa_manager_t;
31
32 /**
33 * @brief The IKE_SA-Manager manages the IKE_SAs ;-).
34 *
35 * To avoid access from multiple threads, IKE_SAs must be checked out from
36 * the manager, and checked in after usage.
37 * The manager also handles deletion of SAs.
38 *
39 * @todo checking of double-checkouts from the same threads would be nice.
40 * This could be done by comparing thread-ids via pthread_self()...
41 *
42 * @b Constructors:
43 * - ike_sa_manager_create()
44 *
45 * @ingroup sa
46 */
47 struct ike_sa_manager_t {
48 /**
49 * @brief Checkout an IKE_SA, create it when necesarry
50 *
51 * Checks out a SA by its ID. An SA will be created, when:
52 * - Responder SPI is not set (when received an IKE_SA_INIT from initiator)
53 * Management of SPIs is the managers job, he will set it.
54 * This function blocks until SA is available for checkout.
55 *
56 * @warning checking out two times without checking in will
57 * result in a deadlock!
58 *
59 * @param ike_sa_manager the manager object
60 * @param ike_sa_id[in/out] the SA identifier, will be updated
61 * @param ike_sa[out] checked out SA
62 * @returns
63 * - SUCCESS if checkout successful
64 * - NOT_FOUND when no such SA is available
65 * - CREATED if a new IKE_SA got created
66 */
67 status_t (*checkout) (ike_sa_manager_t* ike_sa_manager, ike_sa_id_t *sa_id, ike_sa_t **ike_sa);
68
69 /**
70 * @brief Create and checkout an IKE_SA as original initator.
71 *
72 * Creates and checks out a SA as initiator. An SA will be created, when:
73 * Management of SPIs is the managers job, he will set it.
74 *
75 * @warning checking out two times without checking in will
76 * result in a deadlock!
77 *
78 * @param ike_sa_manager the manager object
79 * @param ike_sa[out] checked out SA
80 */
81 void (*create_and_checkout) (ike_sa_manager_t* ike_sa_manager,ike_sa_t **ike_sa);
82
83 /**
84 * @brief Checkin the SA after usage
85 *
86 * @warning the SA pointer MUST NOT be used after checkin!
87 * The SA must be checked out again!
88 *
89 * @param ike_sa_manager the manager object
90 * @param ike_sa_id[in/out] the SA identifier, will be updated
91 * @param ike_sa[out] checked out SA
92 * @returns
93 * - SUCCESS if checked in
94 * - NOT_FOUND when not found (shouldn't happen!)
95 */
96 status_t (*checkin) (ike_sa_manager_t* ike_sa_manager, ike_sa_t *ike_sa);
97 /**
98 * @brief delete a SA, wich was not checked out
99 *
100 * @warning do not use this when the SA is already checked out, this will
101 * deadlock!
102 *
103 * @param ike_sa_manager the manager object
104 * @param ike_sa_id[in/out] the SA identifier
105 * @returns
106 * - SUCCESS if found
107 * - NOT_FOUND when no such SA is available
108 */
109 status_t (*delete) (ike_sa_manager_t* ike_sa_manager, ike_sa_id_t *ike_sa_id);
110
111 /**
112 * @brief delete a checked out SA
113 *
114 * @param ike_sa_manager the manager object
115 * @param ike_sa SA to delete
116 * @returns
117 * - SUCCESS if found
118 * - NOT_FOUND when no such SA is available
119 */
120 status_t (*checkin_and_delete) (ike_sa_manager_t* ike_sa_manager, ike_sa_t *ike_sa);
121
122 /**
123 * @brief Destroys the manager with all associated SAs
124 *
125 * Threads will be driven out, so all SAs can be deleted cleanly
126 *
127 * @param ike_sa_manager the manager object
128 */
129 void (*destroy) (ike_sa_manager_t *ike_sa_manager);
130 };
131
132 /**
133 * @brief Create a manager
134 *
135 * @returns ike_sa_manager_t object
136 *
137 * @ingroup sa
138 */
139 ike_sa_manager_t *ike_sa_manager_create();
140
141 #endif /*IKE_SA_MANAGER_H_*/