2 * Copyright (C) 2008 Martin Willi
3 * Hochschule fuer Technik Rapperswil
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 #include "load_tester_config.h"
20 typedef struct private_load_tester_config_t private_load_tester_config_t
;
23 * Private data of an load_tester_config_t object
25 struct private_load_tester_config_t
{
30 load_tester_config_t
public;
63 * Authentication method(s) to use/expect from initiator
68 * Authentication method(s) use/expected from responder
73 * Initiator ID to enforce
78 * Responder ID to enforce
83 * IKE_SA rekeying delay
88 * CHILD_SA rekeying delay
98 * incremental numbering of generated configs
103 * Dynamic source port, if used
109 * Generate auth config from string
111 static void generate_auth_cfg(private_load_tester_config_t
*this, char *str
,
112 peer_cfg_t
*peer_cfg
, bool local
, int num
)
114 enumerator_t
*enumerator
;
116 identification_t
*id
;
122 enumerator
= enumerator_create_token(str
, "|", " ");
123 while (enumerator
->enumerate(enumerator
, &str
))
126 auth
= auth_cfg_create();
129 if (this->initiator_id
)
131 if ((local
&& num
) || (!local
&& !num
))
133 snprintf(buf
, sizeof(buf
), this->initiator_id
, num
, rnd
);
134 id
= identification_create_from_string(buf
);
137 if (this->responder_id
)
139 if ((local
&& !num
) || (!local
&& num
))
141 snprintf(buf
, sizeof(buf
), this->responder_id
, num
, rnd
);
142 id
= identification_create_from_string(buf
);
146 if (streq(str
, "psk"))
147 { /* PSK authentication, use FQDNs */
148 class = AUTH_CLASS_PSK
;
151 if ((local
&& !num
) || (!local
&& num
))
153 id
= identification_create_from_string("srv.strongswan.org");
157 snprintf(buf
, sizeof(buf
), "c%d-r%d.strongswan.org",
159 id
= identification_create_from_string(buf
);
163 id
= identification_create_from_string("*.strongswan.org");
167 else if (strneq(str
, "eap", strlen("eap")))
168 { /* EAP authentication, use a NAI */
169 class = AUTH_CLASS_EAP
;
170 if (*(str
+ strlen("eap")) == '-')
172 type
= eap_type_from_string(str
+ strlen("eap-"));
175 auth
->add(auth
, AUTH_RULE_EAP_TYPE
, type
);
182 snprintf(buf
, sizeof(buf
), "1%.10d%.4d@strongswan.org",
184 id
= identification_create_from_string(buf
);
188 id
= identification_create_from_encoding(ID_ANY
, chunk_empty
);
194 if (!streq(str
, "pubkey"))
196 DBG1(DBG_CFG
, "invalid authentication: '%s', fallback to pubkey",
199 /* certificate authentication, use distinguished names */
200 class = AUTH_CLASS_PUBKEY
;
203 if ((local
&& !num
) || (!local
&& num
))
205 id
= identification_create_from_string(
206 "CN=srv, OU=load-test, O=strongSwan");
210 snprintf(buf
, sizeof(buf
),
211 "CN=c%d-r%d, OU=load-test, O=strongSwan", num
, rnd
);
212 id
= identification_create_from_string(buf
);
216 id
= identification_create_from_string(
217 "CN=*, OU=load-test, O=strongSwan");
221 auth
->add(auth
, AUTH_RULE_AUTH_CLASS
, class);
222 auth
->add(auth
, AUTH_RULE_IDENTITY
, id
);
223 peer_cfg
->add_auth_cfg(peer_cfg
, auth
, local
);
225 enumerator
->destroy(enumerator
);
229 * Generate a new initiator config, num = 0 for responder config
231 static peer_cfg_t
* generate_config(private_load_tester_config_t
*this, uint num
)
234 child_cfg_t
*child_cfg
;
235 peer_cfg_t
*peer_cfg
;
236 traffic_selector_t
*ts
;
237 proposal_t
*proposal
;
238 lifetime_cfg_t lifetime
= {
240 .life
= this->child_rekey
* 2,
241 .rekey
= this->child_rekey
,
246 if (this->port
&& num
)
248 ike_cfg
= ike_cfg_create(FALSE
, FALSE
,
249 this->local
, this->port
+ num
- 1, this->remote
, IKEV2_NATT_PORT
);
253 ike_cfg
= ike_cfg_create(FALSE
, FALSE
,
254 this->local
, IKEV2_UDP_PORT
, this->remote
, IKEV2_UDP_PORT
);
256 ike_cfg
->add_proposal(ike_cfg
, this->proposal
->clone(this->proposal
));
257 peer_cfg
= peer_cfg_create("load-test", IKEV2
, ike_cfg
,
258 CERT_SEND_IF_ASKED
, UNIQUE_NO
, 1, /* keytries */
259 this->ike_rekey
, 0, /* rekey, reauth */
260 0, this->ike_rekey
, /* jitter, overtime */
261 FALSE
, FALSE
, /* mobike, aggressive mode */
262 this->dpd_delay
, /* dpddelay */
263 this->vip ?
this->vip
->clone(this->vip
) : NULL
,
264 this->pool
, FALSE
, NULL
, NULL
);
267 generate_auth_cfg(this, this->initiator_auth
, peer_cfg
, TRUE
, num
);
268 generate_auth_cfg(this, this->responder_auth
, peer_cfg
, FALSE
, num
);
272 generate_auth_cfg(this, this->responder_auth
, peer_cfg
, TRUE
, num
);
273 generate_auth_cfg(this, this->initiator_auth
, peer_cfg
, FALSE
, num
);
276 child_cfg
= child_cfg_create("load-test", &lifetime
, NULL
, TRUE
, MODE_TUNNEL
,
277 ACTION_NONE
, ACTION_NONE
, ACTION_NONE
, FALSE
,
278 0, 0, NULL
, NULL
, 0);
279 proposal
= proposal_create_from_string(PROTO_ESP
, "aes128-sha1");
280 child_cfg
->add_proposal(child_cfg
, proposal
);
281 ts
= traffic_selector_create_dynamic(0, 0, 65535);
282 child_cfg
->add_traffic_selector(child_cfg
, TRUE
, ts
);
283 ts
= traffic_selector_create_dynamic(0, 0, 65535);
284 child_cfg
->add_traffic_selector(child_cfg
, FALSE
, ts
);
285 peer_cfg
->add_child_cfg(peer_cfg
, child_cfg
);
289 METHOD(backend_t
, create_peer_cfg_enumerator
, enumerator_t
*,
290 private_load_tester_config_t
*this,
291 identification_t
*me
, identification_t
*other
)
293 return enumerator_create_single(this->peer_cfg
, NULL
);
296 METHOD(backend_t
, create_ike_cfg_enumerator
, enumerator_t
*,
297 private_load_tester_config_t
*this, host_t
*me
, host_t
*other
)
301 ike_cfg
= this->peer_cfg
->get_ike_cfg(this->peer_cfg
);
302 return enumerator_create_single(ike_cfg
, NULL
);
305 METHOD(backend_t
, get_peer_cfg_by_name
, peer_cfg_t
*,
306 private_load_tester_config_t
*this, char *name
)
308 if (streq(name
, "load-test"))
310 return generate_config(this, this->num
++);
315 METHOD(load_tester_config_t
, destroy
, void,
316 private_load_tester_config_t
*this)
318 this->peer_cfg
->destroy(this->peer_cfg
);
319 DESTROY_IF(this->proposal
);
320 DESTROY_IF(this->vip
);
325 * Described in header.
327 load_tester_config_t
*load_tester_config_create()
329 private_load_tester_config_t
*this;
334 .create_peer_cfg_enumerator
= _create_peer_cfg_enumerator
,
335 .create_ike_cfg_enumerator
= _create_ike_cfg_enumerator
,
336 .get_peer_cfg_by_name
= _get_peer_cfg_by_name
,
343 if (lib
->settings
->get_bool(lib
->settings
,
344 "%s.plugins.load-tester.request_virtual_ip", FALSE
, charon
->name
))
346 this->vip
= host_create_from_string("0.0.0.0", 0);
348 this->pool
= lib
->settings
->get_str(lib
->settings
,
349 "%s.plugins.load-tester.pool", NULL
, charon
->name
);
350 this->remote
= lib
->settings
->get_str(lib
->settings
,
351 "%s.plugins.load-tester.remote", "127.0.0.1", charon
->name
);
352 this->local
= lib
->settings
->get_str(lib
->settings
,
353 "%s.plugins.load-tester.local", "0.0.0.0", charon
->name
);
355 this->proposal
= proposal_create_from_string(PROTO_IKE
,
356 lib
->settings
->get_str(lib
->settings
,
357 "%s.plugins.load-tester.proposal", "aes128-sha1-modp768",
361 this->proposal
= proposal_create_from_string(PROTO_IKE
,
362 "aes128-sha1-modp768");
364 this->ike_rekey
= lib
->settings
->get_int(lib
->settings
,
365 "%s.plugins.load-tester.ike_rekey", 0, charon
->name
);
366 this->child_rekey
= lib
->settings
->get_int(lib
->settings
,
367 "%s.plugins.load-tester.child_rekey", 600, charon
->name
);
368 this->dpd_delay
= lib
->settings
->get_int(lib
->settings
,
369 "%s.plugins.load-tester.dpd_delay", 0, charon
->name
);
371 this->initiator_auth
= lib
->settings
->get_str(lib
->settings
,
372 "%s.plugins.load-tester.initiator_auth", "pubkey", charon
->name
);
373 this->responder_auth
= lib
->settings
->get_str(lib
->settings
,
374 "%s.plugins.load-tester.responder_auth", "pubkey", charon
->name
);
375 this->initiator_id
= lib
->settings
->get_str(lib
->settings
,
376 "%s.plugins.load-tester.initiator_id", NULL
, charon
->name
);
377 this->responder_id
= lib
->settings
->get_str(lib
->settings
,
378 "%s.plugins.load-tester.responder_id", NULL
, charon
->name
);
380 this->port
= lib
->settings
->get_int(lib
->settings
,
381 "%s.plugins.load-tester.dynamic_port", 0, charon
->name
);
383 this->peer_cfg
= generate_config(this, 0);
385 return &this->public;