reuse reqid when a ROUTED child_sa gets INSTALLED
[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 the responder
56 * 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 * @returns
66 * - checked out IKE_SA if found
67 * - NULL, if no such IKE_SA available
68 */
69 ike_sa_t* (*checkout) (ike_sa_manager_t* this, ike_sa_id_t *sa_id);
70
71 /**
72 * @brief Checkout an existing IKE_SA by hosts and identifications.
73 *
74 * Allows the lookup of an IKE_SA by user IDs and hosts. It returns the
75 * first found occurence, if there are multiple candidates. Supplied IDs
76 * may contain wildcards, hosts may be %any.
77 * If no IKE_SA is found, a new one is created.
78 *
79 * @param this the manager object
80 * @param my_host address of our host
81 * @param other_id address of remote host
82 * @param my_id ID used by us
83 * @param other_id ID used by remote
84 * @return checked out/created IKE_SA
85 */
86 ike_sa_t* (*checkout_by_id) (ike_sa_manager_t* this,
87 host_t *my_host, host_t* other_host,
88 identification_t *my_id,
89 identification_t *other_id);
90
91 /**
92 * @brief Check out an IKE_SA by protocol and SPI of one of its CHILD_SA.
93 *
94 * The kernel sends us expire messages for IPsec SAs. To fullfill
95 * this request, we must check out the IKE SA which contains the
96 * CHILD_SA the kernel wants to modify.
97 *
98 * @param this the manager object
99 * @param reqid reqid of the CHILD_SA
100 * @return
101 * - checked out IKE_SA, if found
102 * - NULL, if not found
103 */
104 ike_sa_t* (*checkout_by_child) (ike_sa_manager_t* this, u_int32_t reqid);
105
106 /**
107 * @brief Get a list of all IKE_SA SAs currently set up.
108 *
109 * The resulting list with all IDs must be destroyed by
110 * the caller. There is no guarantee an ike_sa with the
111 * corrensponding ID really exists, since it may be deleted
112 * in the meantime by another thread.
113 *
114 * @param this the manager object
115 * @return a list with ike_sa_id_t s
116 */
117 linked_list_t *(*get_ike_sa_list) (ike_sa_manager_t* this);
118
119 /**
120 * @brief Get a list of all IKE_SA SAs currently set up specified
121 * by the connections name.
122 *
123 * @param this the manager object
124 * @return a list with ike_sa_id_t s
125 */
126 linked_list_t *(*get_ike_sa_list_by_name) (ike_sa_manager_t* this, const char *name);
127
128 /**
129 * @brief Log the status of the IKE_SA's in the manager.
130 *
131 * A informational log is done to the supplied logger. If logger is
132 * NULL, an internal logger is used. If a name is supplied,
133 * only connections with the matching name will be logged.
134 *
135 * @param this the manager object
136 * @param logger logger to do the log, or NULL
137 * @param name name of a connection, or NULL
138 */
139 void (*log_status) (ike_sa_manager_t* this, logger_t* logger, char* name);
140
141 /**
142 * @brief Checkin the SA after usage.
143 *
144 * @warning the SA pointer MUST NOT be used after checkin!
145 * The SA must be checked out again!
146 *
147 * @param this the manager object
148 * @param[in/out] ike_sa_id the SA identifier, will be updated
149 * @param[out] ike_sa checked out SA
150 * @returns
151 * - SUCCESS if checked in
152 * - NOT_FOUND when not found (shouldn't happen!)
153 */
154 status_t (*checkin) (ike_sa_manager_t* this, ike_sa_t *ike_sa);
155
156 /**
157 * @brief Delete a SA, which was not checked out.
158 *
159 * If the state allows it, the IKE SA is destroyed immediately. If it is
160 * in the state ESTABLSIHED, a delete message
161 * is sent to the remote peer, which has to be acknowledged.
162 *
163 * @warning do not use this when the SA is already checked out, this will
164 * deadlock!
165 *
166 * @param this the manager object
167 * @param[in/out] ike_sa_id the SA identifier
168 * @returns
169 * - SUCCESS if found
170 * - NOT_FOUND when no such SA is available
171 */
172 status_t (*delete) (ike_sa_manager_t* this, ike_sa_id_t *ike_sa_id);
173
174 /**
175 * @brief Destroy a checked out SA.
176 *
177 * The IKE SA is destroyed without notification of the remote peer.
178 * Use this only if the other peer doesn't respond or behaves not
179 * as predicted.
180 * Checking in and destruction is an atomic operation (for the IKE_SA),
181 * so this can be called if the SA is in a "unclean" state, without the
182 * risk that another thread can get the SA.
183 *
184 * @param this the manager object
185 * @param ike_sa SA to delete
186 * @returns
187 * - SUCCESS if found
188 * - NOT_FOUND when no such SA is available
189 */
190 status_t (*checkin_and_destroy) (ike_sa_manager_t* this, ike_sa_t *ike_sa);
191
192 /**
193 * @brief Destroys the manager with all associated SAs.
194 *
195 * Threads will be driven out, so all SAs can be deleted cleanly.
196 *
197 * @param this the manager object
198 */
199 void (*destroy) (ike_sa_manager_t *this);
200 };
201
202 /**
203 * @brief Create a manager.
204 *
205 * @returns ike_sa_manager_t object
206 *
207 * @ingroup sa
208 */
209 ike_sa_manager_t *ike_sa_manager_create(void);
210
211 #endif /*IKE_SA_MANAGER_H_*/