ike-cfg: Add option to prefer supplied proposals over locally configured ones
[strongswan.git] / src / libcharon / config / ike_cfg.h
1 /*
2 * Copyright (C) 2012-2016 Tobias Brunner
3 * Copyright (C) 2005-2007 Martin Willi
4 * Copyright (C) 2005 Jan Hutter
5 * Hochschule fuer Technik Rapperswil
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * for more details.
16 */
17
18 /**
19 * @defgroup ike_cfg ike_cfg
20 * @{ @ingroup config
21 */
22
23 #ifndef IKE_CFG_H_
24 #define IKE_CFG_H_
25
26 typedef enum ike_version_t ike_version_t;
27 typedef enum fragmentation_t fragmentation_t;
28 typedef struct ike_cfg_t ike_cfg_t;
29
30 #include <library.h>
31 #include <networking/host.h>
32 #include <collections/linked_list.h>
33 #include <utils/identification.h>
34 #include <config/proposal.h>
35 #include <crypto/diffie_hellman.h>
36
37 /**
38 * IKE version.
39 */
40 enum ike_version_t {
41 /** any version */
42 IKE_ANY = 0,
43 /** IKE version 1 */
44 IKEV1 = 1,
45 /** IKE version 2 */
46 IKEV2 = 2,
47 };
48
49 /**
50 * Proprietary IKEv1 fragmentation
51 */
52 enum fragmentation_t {
53 /** disable fragmentation */
54 FRAGMENTATION_NO,
55 /** enable fragmentation if supported by peer */
56 FRAGMENTATION_YES,
57 /** force use of fragmentation (even for the first message) */
58 FRAGMENTATION_FORCE,
59 };
60
61 /**
62 * enum strings fro ike_version_t
63 */
64 extern enum_name_t *ike_version_names;
65
66 /**
67 * An ike_cfg_t defines the rules to set up an IKE_SA.
68 *
69 * @see peer_cfg_t to get an overview over the configurations.
70 */
71 struct ike_cfg_t {
72
73 /**
74 * Get the IKE version to use with this configuration.
75 *
76 * @return IKE major version
77 */
78 ike_version_t (*get_version)(ike_cfg_t *this);
79
80 /**
81 * Resolve the local address to use for initiation.
82 *
83 * @param family address family to prefer, or AF_UNSPEC
84 * @return resolved host, NULL on error
85 */
86 host_t* (*resolve_me)(ike_cfg_t *this, int family);
87
88 /**
89 * Resolve the remote address to use for initiation.
90 *
91 * @param family address family to prefer, or AF_UNSPEC
92 * @return resolved host, NULL on error
93 */
94 host_t* (*resolve_other)(ike_cfg_t *this, int family);
95
96 /**
97 * Check how good a host matches to the configured local address.
98 *
99 * @param host host to check match quality
100 * @return quality of the match, 0 if not matching at all
101 */
102 u_int (*match_me)(ike_cfg_t *this, host_t *host);
103
104 /**
105 * Check how good a host matches to the configured remote address.
106 *
107 * @param host host to check match quality
108 * @return quality of the match, 0 if not matching at all
109 */
110 u_int (*match_other)(ike_cfg_t *this, host_t *host);
111
112 /**
113 * Get own address.
114 *
115 * @return string of address/DNS name
116 */
117 char* (*get_my_addr) (ike_cfg_t *this);
118
119 /**
120 * Get peer's address.
121 *
122 * @return string of address/DNS name
123 */
124 char* (*get_other_addr) (ike_cfg_t *this);
125
126 /**
127 * Get the port to use as our source port.
128 *
129 * @return source address port, host order
130 */
131 uint16_t (*get_my_port)(ike_cfg_t *this);
132
133 /**
134 * Get the port to use as destination port.
135 *
136 * @return destination address, host order
137 */
138 uint16_t (*get_other_port)(ike_cfg_t *this);
139
140 /**
141 * Get the DSCP value to use for IKE packets send from connections.
142 *
143 * @return DSCP value
144 */
145 uint8_t (*get_dscp)(ike_cfg_t *this);
146
147 /**
148 * Adds a proposal to the list.
149 *
150 * The first added proposal has the highest priority, the last
151 * added the lowest. It is safe to add NULL as proposal, which has no
152 * effect.
153 *
154 * @param proposal proposal to add, or NULL
155 */
156 void (*add_proposal) (ike_cfg_t *this, proposal_t *proposal);
157
158 /**
159 * Returns a list of all supported proposals.
160 *
161 * Returned list and its proposals must be destroyed after use.
162 *
163 * @return list containing all the proposals
164 */
165 linked_list_t* (*get_proposals) (ike_cfg_t *this);
166
167 /**
168 * Select a proposal from a list of supplied proposals.
169 *
170 * Returned proposal must be destroyed after use.
171 *
172 * @param proposals list of proposals to select from
173 * @param private accept algorithms from a private range
174 * @param prefer_self whether to prefer configured or supplied proposals
175 * @return selected proposal, or NULL if none matches.
176 */
177 proposal_t *(*select_proposal) (ike_cfg_t *this, linked_list_t *proposals,
178 bool private, bool prefer_self);
179
180 /**
181 * Should we send a certificate request in IKE_SA_INIT?
182 *
183 * @return certificate request sending policy
184 */
185 bool (*send_certreq) (ike_cfg_t *this);
186
187 /**
188 * Enforce UDP encapsulation by faking NATD notifies?
189 *
190 * @return TRUE to enforce UDP encapsulation
191 */
192 bool (*force_encap) (ike_cfg_t *this);
193
194 /**
195 * Use proprietary IKEv1 fragmentation
196 *
197 * @return TRUE to use fragmentation
198 */
199 fragmentation_t (*fragmentation) (ike_cfg_t *this);
200
201 /**
202 * Get the DH group to use for IKE_SA setup.
203 *
204 * @return dh group to use for initialization
205 */
206 diffie_hellman_group_t (*get_dh_group)(ike_cfg_t *this);
207
208 /**
209 * Check if two IKE configs are equal.
210 *
211 * @param other other to check for equality
212 * @return TRUE if other equal to this
213 */
214 bool (*equals)(ike_cfg_t *this, ike_cfg_t *other);
215
216 /**
217 * Increase reference count.
218 *
219 * @return reference to this
220 */
221 ike_cfg_t* (*get_ref) (ike_cfg_t *this);
222
223 /**
224 * Destroys a ike_cfg_t object.
225 *
226 * Decrements the internal reference counter and
227 * destroys the ike_cfg when it reaches zero.
228 */
229 void (*destroy) (ike_cfg_t *this);
230 };
231
232 /**
233 * Creates a ike_cfg_t object.
234 *
235 * Supplied hosts become owned by ike_cfg, strings get cloned.
236 *
237 * me and other are comma separated lists of IP addresses, DNS names, IP ranges
238 * or subnets. When initiating, the first non-range/subnet address is used
239 * as address. When responding, a match is performed against all items in the
240 * list.
241 *
242 * @param version IKE major version to use for this config
243 * @param certreq TRUE to send a certificate request
244 * @param force_encap enforce UDP encapsulation by faking NATD notify
245 * @param me address/DNS name of local peer
246 * @param my_port IKE port to use as source, 500 uses IKEv2 port floating
247 * @param other address/DNS name of remote peer
248 * @param other_port IKE port to use as dest, 500 uses IKEv2 port floating
249 * @param fragmentation use IKEv1 fragmentation
250 * @param dscp DSCP value to send IKE packets with
251 * @return ike_cfg_t object.
252 */
253 ike_cfg_t *ike_cfg_create(ike_version_t version, bool certreq, bool force_encap,
254 char *me, uint16_t my_port,
255 char *other, uint16_t other_port,
256 fragmentation_t fragmentation, uint8_t dscp);
257
258 /**
259 * Determine the address family of the local or remtoe address(es). If multiple
260 * families are configured AF_UNSPEC is returned. %any is ignored (%any4|6 are
261 * not though).
262 *
263 * @param this ike config to check
264 * @param local TRUE to check local addresses, FALSE for remote
265 * @return address family of address(es) if distinct
266 */
267 int ike_cfg_get_family(ike_cfg_t *this, bool local);
268
269 #endif /** IKE_CFG_H_ @}*/