a00f37e4fb4dab491ce829e7734fccbc18229ee6
[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 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:
54 * - Responder 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 ike_sa_manager the manager object
62 * @param ike_sa_id[in/out] the SA identifier, will be updated
63 * @param ike_sa[out] checked out SA
64 * @returns
65 * - SUCCESS if checkout successful
66 * - NOT_FOUND when no such SA is available
67 * - CREATED if a new IKE_SA got created
68 */
69 status_t (*checkout) (ike_sa_manager_t* ike_sa_manager, ike_sa_id_t *sa_id, ike_sa_t **ike_sa);
70
71 /**
72 * @brief Create and checkout an IKE_SA as original initator.
73 *
74 * Creates and checks out a SA as initiator.
75 * Management of SPIs is the managers job, he will set it.
76 *
77 * @param ike_sa_manager the manager object
78 * @param ike_sa[out] checked out SA
79 */
80 void (*create_and_checkout) (ike_sa_manager_t* ike_sa_manager,ike_sa_t **ike_sa);
81
82 /**
83 * @brief Check out an IKE_SA, defined be the two peers.
84 *
85 * Checking out an IKE_SA by their peer addresses may be necessary
86 * for kernel traps, status querying and so on... one of the hosts
87 * may be 0.0.0.0 (defaultroute/any), but not both.
88 *
89 * @param ike_sa_manager the manager object
90 * @param me host on local side
91 * @param other host on remote side
92 * @param ike_sa[out] checked out SA
93 * @return
94 * - NOT_FOUND, if no such SA found
95 * - SUCCESS, if SA found and ike_sa set appropriatly
96 */
97 status_t (*checkout_by_hosts) (ike_sa_manager_t* ike_sa_manager, host_t *me, host_t *other, ike_sa_t **ike_sa);
98
99 /**
100 * @brief Get a list of all IKE_SA SAs currently set up.
101 *
102 * The resulting list with all IDs must be destroyd by
103 * the caller. There is no guarantee an ike_sa with the
104 * corrensponding ID really exists, since it may be deleted
105 * in the meantime by another thread.
106 *
107 * @param ike_sa_manager the manager object
108 * @return a list with ike_sa_id_t s
109 */
110 linked_list_t *(*get_ike_sa_list) (ike_sa_manager_t* ike_sa_manager);
111
112 /**
113 * @brief Checkin the SA after usage.
114 *
115 * @warning the SA pointer MUST NOT be used after checkin!
116 * The SA must be checked out again!
117 *
118 * @param ike_sa_manager the manager object
119 * @param ike_sa_id[in/out] the SA identifier, will be updated
120 * @param ike_sa[out] checked out SA
121 * @returns
122 * - SUCCESS if checked in
123 * - NOT_FOUND when not found (shouldn't happen!)
124 */
125 status_t (*checkin) (ike_sa_manager_t* ike_sa_manager, ike_sa_t *ike_sa);
126
127 /**
128 * @brief Delete a SA, which was not checked out.
129 *
130 * @warning do not use this when the SA is already checked out, this will
131 * deadlock!
132 *
133 * @param ike_sa_manager the manager object
134 * @param ike_sa_id[in/out] the SA identifier
135 * @returns
136 * - SUCCESS if found
137 * - NOT_FOUND when no such SA is available
138 */
139 status_t (*delete) (ike_sa_manager_t* ike_sa_manager, ike_sa_id_t *ike_sa_id);
140
141 /**
142 * @brief Delete a checked out SA.
143 *
144 * @param ike_sa_manager the manager object
145 * @param ike_sa SA to delete
146 * @returns
147 * - SUCCESS if found
148 * - NOT_FOUND when no such SA is available
149 */
150 status_t (*checkin_and_delete) (ike_sa_manager_t* ike_sa_manager, ike_sa_t *ike_sa);
151
152 /**
153 * @brief Destroys the manager with all associated SAs.
154 *
155 * Threads will be driven out, so all SAs can be deleted cleanly.
156 *
157 * @param ike_sa_manager the manager object
158 */
159 void (*destroy) (ike_sa_manager_t *ike_sa_manager);
160 };
161
162 /**
163 * @brief Create a manager.
164 *
165 * @returns ike_sa_manager_t object
166 *
167 * @ingroup sa
168 */
169 ike_sa_manager_t *ike_sa_manager_create();
170
171 #endif /*IKE_SA_MANAGER_H_*/