updated copyright information
[strongswan.git] / src / 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-2006 Martin Willi
10 * Copyright (C) 2005 Jan Hutter
11 * Hochschule fuer Technik Rapperswil
12 *
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>.
17 *
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
21 * for more details.
22 */
23
24 #ifndef IKE_SA_MANAGER_H_
25 #define IKE_SA_MANAGER_H_
26
27 #include <types.h>
28 #include <sa/ike_sa.h>
29 #include <utils/logger.h>
30
31
32 typedef struct ike_sa_manager_t ike_sa_manager_t;
33
34 /**
35 * @brief The IKE_SA-Manager is responsible for managing all initiated and responded IKE_SA's.
36 *
37 * To avoid access from multiple threads, IKE_SAs must be checked out from
38 * the manager, and checked in after usage.
39 * The manager also handles deletion of SAs.
40 *
41 * @todo checking of double-checkouts from the same threads would be nice.
42 * This could be done by comparing thread-ids via pthread_self()...
43 *
44 * @todo Managing of ike_sa_t objects in a hash table instead of linked list.
45 *
46 * @b Constructors:
47 * - ike_sa_manager_create()
48 *
49 * @ingroup sa
50 */
51 struct ike_sa_manager_t {
52 /**
53 * @brief Checkout an IKE_SA, create it when necesarry.
54 *
55 * Checks out a SA by its ID. An SA will be created, when:
56 * - Responder SPI is not set (when received an IKE_SA_INIT from initiator)
57 * Management of SPIs is the managers job, he will set it.
58 * This function blocks until SA is available for checkout.
59 *
60 * @warning checking out two times without checking in will
61 * result in a deadlock!
62 *
63 * @param this the manager object
64 * @param[in/out] ike_sa_id the SA identifier, will be updated
65 * @param[out] ike_sa checked out SA
66 * @returns
67 * - SUCCESS if checkout successful
68 * - NOT_FOUND when no such SA is available
69 * - CREATED if a new IKE_SA got created
70 */
71 status_t (*checkout) (ike_sa_manager_t* this, ike_sa_id_t *sa_id, ike_sa_t **ike_sa);
72
73 /**
74 * @brief Create and checkout an IKE_SA as original initator.
75 *
76 * Creates and checks out a SA as initiator.
77 * Management of SPIs is the managers job, he will set it.
78 *
79 * @param this the manager object
80 * @param[out] ike_sa checked out SA
81 */
82 void (*create_and_checkout) (ike_sa_manager_t* this,ike_sa_t **ike_sa);
83
84 /**
85 * @brief Check out an IKE_SA by protocol and SPI of one of its CHILD_SA.
86 *
87 * The kernel sends us expire messages for IPsec SAs. To fullfill
88 * this request, we must check out the IKE SA which contains the
89 * CHILD_SA the kernel wants to modify.
90 *
91 * @param this the manager object
92 * @param protocol protocol of the CHILD_SA
93 * @param spi SPI of the CHILD_SA
94 * @param[out] ike_sa checked out SA
95 * @return
96 * - NOT_FOUND, if no IKE SA with such a child found
97 * - SUCCESS, if ike_sa set
98 */
99 status_t (*checkout_by_child) (ike_sa_manager_t* this, protocol_id_t protocol,
100 u_int32_t spi, ike_sa_t **ike_sa);
101
102 /**
103 * @brief Get a list of all IKE_SA SAs currently set up.
104 *
105 * The resulting list with all IDs must be destroyd by
106 * the caller. There is no guarantee an ike_sa with the
107 * corrensponding ID really exists, since it may be deleted
108 * in the meantime by another thread.
109 *
110 * @param this the manager object
111 * @return a list with ike_sa_id_t s
112 */
113 linked_list_t *(*get_ike_sa_list) (ike_sa_manager_t* this);
114
115 /**
116 * @brief Get a list of all IKE_SA SAs currently set up specified
117 * by the connections name.
118 *
119 * @param this the manager object
120 * @return a list with ike_sa_id_t s
121 */
122 linked_list_t *(*get_ike_sa_list_by_name) (ike_sa_manager_t* this, const char *name);
123
124 /**
125 * @brief Log the status of the IKE_SA's in the manager.
126 *
127 * A informational log is done to the supplied logger. If logger is
128 * NULL, an internal logger is used. If a name is supplied,
129 * only connections with the matching name will be logged.
130 *
131 * @param this the manager object
132 * @param logger logger to do the log, or NULL
133 * @param name name of a connection, or NULL
134 */
135 void (*log_status) (ike_sa_manager_t* this, logger_t* logger, char* name);
136
137 /**
138 * @brief Checkin the SA after usage.
139 *
140 * @warning the SA pointer MUST NOT be used after checkin!
141 * The SA must be checked out again!
142 *
143 * @param this the manager object
144 * @param[in/out] ike_sa_id the SA identifier, will be updated
145 * @param[out] ike_sa checked out SA
146 * @returns
147 * - SUCCESS if checked in
148 * - NOT_FOUND when not found (shouldn't happen!)
149 */
150 status_t (*checkin) (ike_sa_manager_t* this, ike_sa_t *ike_sa);
151
152 /**
153 * @brief Delete a SA, which was not checked out.
154 *
155 * If the state allows it, the IKE SA is destroyed immediately. If it is
156 * in the state ike_sa_established or further, a delete message
157 * is sent to the remote peer, which has to be acknowledged.
158 *
159 * @warning do not use this when the SA is already checked out, this will
160 * deadlock!
161 *
162 * @param this the manager object
163 * @param[in/out] ike_sa_id the SA identifier
164 * @returns
165 * - SUCCESS if found
166 * - NOT_FOUND when no such SA is available
167 */
168 status_t (*delete) (ike_sa_manager_t* this, ike_sa_id_t *ike_sa_id);
169
170 /**
171 * @brief Destroy a checked out SA.
172 *
173 * The IKE SA is destroyed without notification of the remote peer.
174 * Use this only if the other peer doesn't respond or behaves not
175 * as predicted.
176 * Checking in and destruction is an atomic operation (for the IKE_SA),
177 * so this can be called if the SA is in a "unclean" state, without the
178 * risk that another thread can get the SA.
179 *
180 * @param this the manager object
181 * @param ike_sa SA to delete
182 * @returns
183 * - SUCCESS if found
184 * - NOT_FOUND when no such SA is available
185 */
186 status_t (*checkin_and_destroy) (ike_sa_manager_t* this, ike_sa_t *ike_sa);
187
188 /**
189 * @brief Destroys the manager with all associated SAs.
190 *
191 * Threads will be driven out, so all SAs can be deleted cleanly.
192 *
193 * @param this the manager object
194 */
195 void (*destroy) (ike_sa_manager_t *this);
196 };
197
198 /**
199 * @brief Create a manager.
200 *
201 * @returns ike_sa_manager_t object
202 *
203 * @ingroup sa
204 */
205 ike_sa_manager_t *ike_sa_manager_create(void);
206
207 #endif /*IKE_SA_MANAGER_H_*/