some cleanups
[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 typedef struct ike_sa_manager_t ike_sa_manager_t;
28
29 #include <library.h>
30 #include <sa/ike_sa.h>
31
32 /**
33 * @brief The IKE_SA-Manager is responsible for managing all initiated and responded IKE_SA's.
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 * @todo Managing of ike_sa_t objects in a hash table instead of linked list.
43 *
44 * @b Constructors:
45 * - ike_sa_manager_create()
46 *
47 * @ingroup sa
48 */
49 struct ike_sa_manager_t {
50 /**
51 * @brief Checkout an IKE_SA, create it when necesarry.
52 *
53 * Checks out a SA by its ID. An SA will be created, when the responder
54 * SPI is not set (when received an IKE_SA_INIT from initiator).
55 * Management of SPIs is the managers job, he will set it.
56 * This function blocks until SA is available for checkout.
57 *
58 * @warning checking out two times without checking in will
59 * result in a deadlock!
60 *
61 * @param this the manager object
62 * @param ike_sa_id the SA identifier, will be updated
63 * @returns
64 * - checked out IKE_SA if found
65 * - NULL, if no such IKE_SA available
66 */
67 ike_sa_t* (*checkout) (ike_sa_manager_t* this, ike_sa_id_t *sa_id);
68
69 /**
70 * @brief Checkout an existing IKE_SA by hosts and identifications.
71 *
72 * Allows the lookup of an IKE_SA by user IDs and hosts. It returns the
73 * first found occurence, if there are multiple candidates. Supplied IDs
74 * may contain wildcards, hosts may be %any.
75 * If no IKE_SA is found, a new one is created. This is also the case when
76 * the found IKE_SA is in the DELETING state.
77 *
78 * @param this the manager object
79 * @param my_host address of our host
80 * @param other_id address of remote host
81 * @param my_id ID used by us
82 * @param other_id ID used by remote
83 * @return checked out/created IKE_SA
84 */
85 ike_sa_t* (*checkout_by_peer) (ike_sa_manager_t* this,
86 host_t *my_host, host_t* other_host,
87 identification_t *my_id,
88 identification_t *other_id);
89
90 /**
91 * @brief Check out an IKE_SA a unique ID.
92 *
93 * Every IKE_SA and every CHILD_SA is uniquely identified by an ID.
94 * These checkout function uses, depending
95 * on the child parameter, the unique ID of the IKE_SA or the reqid
96 * of one of a IKE_SAs CHILD_SA.
97 *
98 * @param this the manager object
99 * @param id unique ID of the object
100 * @param child TRUE to use CHILD, FALSE to use IKE_SA
101 * @return
102 * - checked out IKE_SA, if found
103 * - NULL, if not found
104 */
105 ike_sa_t* (*checkout_by_id) (ike_sa_manager_t* this, u_int32_t id,
106 bool child);
107
108 /**
109 * @brief Check out an IKE_SA by the policy/connection name.
110 *
111 * Check out the IKE_SA by the connections name or by a CHILD_SAs policy
112 * name.
113 *
114 * @param this the manager object
115 * @param name name of the connection/policy
116 * @param child TRUE to use policy name, FALSE to use conn name
117 * @return
118 * - checked out IKE_SA, if found
119 * - NULL, if not found
120 */
121 ike_sa_t* (*checkout_by_name) (ike_sa_manager_t* this, char *name,
122 bool child);
123
124 /**
125 * @brief Create an iterator over all stored IKE_SAs.
126 *
127 * The avoid synchronization issues, the iterator locks access
128 * to the manager exclusively, until it gets destroyed.
129 * This iterator is for reading only! Writing will corrupt the manager.
130 *
131 * @param this the manager object
132 * @return iterator over all IKE_SAs.
133 */
134 iterator_t *(*create_iterator) (ike_sa_manager_t* this);
135
136 /**
137 * @brief Checkin the SA after usage.
138 *
139 * @warning the SA pointer MUST NOT be used after checkin!
140 * The SA must be checked out again!
141 *
142 * @param this the manager object
143 * @param ike_sa_id the SA identifier, will be updated
144 * @param ike_sa checked out SA
145 * @returns
146 * - SUCCESS if checked in
147 * - NOT_FOUND when not found (shouldn't happen!)
148 */
149 status_t (*checkin) (ike_sa_manager_t* this, ike_sa_t *ike_sa);
150
151 /**
152 * @brief Destroy a checked out SA.
153 *
154 * The IKE SA is destroyed without notification of the remote peer.
155 * Use this only if the other peer doesn't respond or behaves not
156 * as predicted.
157 * Checking in and destruction is an atomic operation (for the IKE_SA),
158 * so this can be called if the SA is in a "unclean" state, without the
159 * risk that another thread can get the SA.
160 *
161 * @param this the manager object
162 * @param ike_sa SA to delete
163 * @returns
164 * - SUCCESS if found
165 * - NOT_FOUND when no such SA is available
166 */
167 status_t (*checkin_and_destroy) (ike_sa_manager_t* this, ike_sa_t *ike_sa);
168
169 /**
170 * @brief Destroys the manager with all associated SAs.
171 *
172 * Threads will be driven out, so all SAs can be deleted cleanly.
173 *
174 * @param this the manager object
175 */
176 void (*destroy) (ike_sa_manager_t *this);
177 };
178
179 /**
180 * @brief Create a manager.
181 *
182 * @returns ike_sa_manager_t object
183 *
184 * @ingroup sa
185 */
186 ike_sa_manager_t *ike_sa_manager_create(void);
187
188 #endif /*IKE_SA_MANAGER_H_*/