Moving charon to libcharon.

This commit is contained in:
Tobias Brunner
2010-03-19 13:34:52 +01:00
parent 7c11d10eb8
commit 08c5572602
480 changed files with 0 additions and 0 deletions
@@ -0,0 +1,20 @@
INCLUDES = -I$(top_srcdir)/src/libstrongswan -I$(top_srcdir)/src/charon
AM_CFLAGS = -rdynamic
if MONOLITHIC
noinst_LTLIBRARIES = libstrongswan-load-tester.la
else
plugin_LTLIBRARIES = libstrongswan-load-tester.la
endif
libstrongswan_load_tester_la_SOURCES = \
load_tester_plugin.c load_tester_plugin.h \
load_tester_config.c load_tester_config.h \
load_tester_creds.c load_tester_creds.h \
load_tester_ipsec.c load_tester_ipsec.h \
load_tester_listener.c load_tester_listener.h \
load_tester_diffie_hellman.c load_tester_diffie_hellman.h
libstrongswan_load_tester_la_LDFLAGS = -module -avoid-version
@@ -0,0 +1,333 @@
/*
* Copyright (C) 2008 Martin Willi
* Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#include "load_tester_config.h"
#include <daemon.h>
typedef struct private_load_tester_config_t private_load_tester_config_t;
/**
* Private data of an load_tester_config_t object
*/
struct private_load_tester_config_t {
/**
* Public part
*/
load_tester_config_t public;
/**
* peer config
*/
peer_cfg_t *peer_cfg;
/**
* virtual IP, if any
*/
host_t *vip;
/**
* Remote address
*/
char *remote;
/**
* IP address pool
*/
char *pool;
/**
* IKE proposal
*/
proposal_t *proposal;
/**
* Authentication method(s) to use/expect from initiator
*/
char *initiator_auth;
/**
* Authentication method(s) use/expected from responder
*/
char *responder_auth;
/**
* IKE_SA rekeying delay
*/
u_int ike_rekey;
/**
* CHILD_SA rekeying delay
*/
u_int child_rekey;
/**
* incremental numbering of generated configs
*/
u_int num;
/**
* Dynamic source port, if used
*/
u_int16_t port;
};
/**
* Generate auth config from string
*/
static void generate_auth_cfg(private_load_tester_config_t *this, char *str,
peer_cfg_t *peer_cfg, bool local, int num)
{
enumerator_t *enumerator;
auth_cfg_t *auth;
identification_t *id;
auth_class_t class;
eap_type_t type;
char buf[128];
int rnd = 0;
enumerator = enumerator_create_token(str, "|", " ");
while (enumerator->enumerate(enumerator, &str))
{
auth = auth_cfg_create();
rnd++;
if (streq(str, "psk"))
{ /* PSK authentication, use FQDNs */
class = AUTH_CLASS_PSK;
if ((local && !num) || (!local && num))
{
id = identification_create_from_string("srv.strongswan.org");
}
else if (local)
{
snprintf(buf, sizeof(buf), "c%d-r%d.strongswan.org", num, rnd);
id = identification_create_from_string(buf);
}
else
{
id = identification_create_from_string("*.strongswan.org");
}
}
else if (strneq(str, "eap", strlen("eap")))
{ /* EAP authentication, use a NAI */
class = AUTH_CLASS_EAP;
if (*(str + strlen("eap")) == '-')
{
type = eap_type_from_string(str + strlen("eap-"));
if (type)
{
auth->add(auth, AUTH_RULE_EAP_TYPE, type);
}
}
if (local && num)
{
snprintf(buf, sizeof(buf), "1%.10d%[email protected]", num, rnd);
id = identification_create_from_string(buf);
}
else
{
id = identification_create_from_encoding(ID_ANY, chunk_empty);
}
}
else
{
if (!streq(str, "pubkey"))
{
DBG1(DBG_CFG, "invalid authentication: '%s', fallback to pubkey",
str);
}
/* certificate authentication, use distinguished names */
class = AUTH_CLASS_PUBKEY;
if ((local && !num) || (!local && num))
{
id = identification_create_from_string(
"CN=srv, OU=load-test, O=strongSwan");
}
else if (local)
{
snprintf(buf, sizeof(buf),
"CN=c%d-r%d, OU=load-test, O=strongSwan", num, rnd);
id = identification_create_from_string(buf);
}
else
{
id = identification_create_from_string(
"CN=*, OU=load-test, O=strongSwan");
}
}
auth->add(auth, AUTH_RULE_AUTH_CLASS, class);
auth->add(auth, AUTH_RULE_IDENTITY, id);
peer_cfg->add_auth_cfg(peer_cfg, auth, local);
}
enumerator->destroy(enumerator);
}
/**
* Generate a new initiator config, num = 0 for responder config
*/
static peer_cfg_t* generate_config(private_load_tester_config_t *this, uint num)
{
ike_cfg_t *ike_cfg;
child_cfg_t *child_cfg;
peer_cfg_t *peer_cfg;
traffic_selector_t *ts;
proposal_t *proposal;
lifetime_cfg_t lifetime = {
.time = {
.life = this->child_rekey * 2,
.rekey = this->child_rekey,
.jitter = 0
}
};
if (this->port && num)
{
ike_cfg = ike_cfg_create(FALSE, FALSE,
"0.0.0.0", this->port + num - 1, this->remote, IKEV2_NATT_PORT);
}
else
{
ike_cfg = ike_cfg_create(FALSE, FALSE,
"0.0.0.0", IKEV2_UDP_PORT, this->remote, IKEV2_UDP_PORT);
}
ike_cfg->add_proposal(ike_cfg, this->proposal->clone(this->proposal));
peer_cfg = peer_cfg_create("load-test", 2, ike_cfg,
CERT_SEND_IF_ASKED, UNIQUE_NO, 1, /* keytries */
this->ike_rekey, 0, /* rekey, reauth */
0, this->ike_rekey, /* jitter, overtime */
FALSE, 0, /* mobike, dpddelay */
this->vip ? this->vip->clone(this->vip) : NULL,
this->pool, FALSE, NULL, NULL);
if (num)
{ /* initiator */
generate_auth_cfg(this, this->initiator_auth, peer_cfg, TRUE, num);
generate_auth_cfg(this, this->responder_auth, peer_cfg, FALSE, num);
}
else
{ /* responder */
generate_auth_cfg(this, this->responder_auth, peer_cfg, TRUE, num);
generate_auth_cfg(this, this->initiator_auth, peer_cfg, FALSE, num);
}
child_cfg = child_cfg_create("load-test", &lifetime, NULL, TRUE,
MODE_TUNNEL, ACTION_NONE, ACTION_NONE, FALSE, 0);
proposal = proposal_create_from_string(PROTO_ESP, "aes128-sha1");
child_cfg->add_proposal(child_cfg, proposal);
ts = traffic_selector_create_dynamic(0, 0, 65535);
child_cfg->add_traffic_selector(child_cfg, TRUE, ts);
ts = traffic_selector_create_dynamic(0, 0, 65535);
child_cfg->add_traffic_selector(child_cfg, FALSE, ts);
peer_cfg->add_child_cfg(peer_cfg, child_cfg);
return peer_cfg;
}
/**
* Implementation of backend_t.create_peer_cfg_enumerator.
*/
static enumerator_t* create_peer_cfg_enumerator(private_load_tester_config_t *this,
identification_t *me,
identification_t *other)
{
return enumerator_create_single(this->peer_cfg, NULL);
}
/**
* Implementation of backend_t.create_ike_cfg_enumerator.
*/
static enumerator_t* create_ike_cfg_enumerator(private_load_tester_config_t *this,
host_t *me, host_t *other)
{
ike_cfg_t *ike_cfg;
ike_cfg = this->peer_cfg->get_ike_cfg(this->peer_cfg);
return enumerator_create_single(ike_cfg, NULL);
}
/**
* implements backend_t.get_peer_cfg_by_name.
*/
static peer_cfg_t *get_peer_cfg_by_name(private_load_tester_config_t *this,
char *name)
{
if (streq(name, "load-test"))
{
return generate_config(this, this->num++);
}
return NULL;
}
/**
* Implementation of load_tester_config_t.destroy.
*/
static void destroy(private_load_tester_config_t *this)
{
this->peer_cfg->destroy(this->peer_cfg);
DESTROY_IF(this->proposal);
DESTROY_IF(this->vip);
free(this);
}
/**
* Described in header.
*/
load_tester_config_t *load_tester_config_create()
{
private_load_tester_config_t *this = malloc_thing(private_load_tester_config_t);
this->public.backend.create_peer_cfg_enumerator = (enumerator_t*(*)(backend_t*, identification_t *me, identification_t *other))create_peer_cfg_enumerator;
this->public.backend.create_ike_cfg_enumerator = (enumerator_t*(*)(backend_t*, host_t *me, host_t *other))create_ike_cfg_enumerator;
this->public.backend.get_peer_cfg_by_name = (peer_cfg_t* (*)(backend_t*,char*))get_peer_cfg_by_name;
this->public.destroy = (void(*)(load_tester_config_t*))destroy;
this->vip = NULL;
if (lib->settings->get_bool(lib->settings,
"charon.plugins.load-tester.request_virtual_ip", FALSE))
{
this->vip = host_create_from_string("0.0.0.0", 0);
}
this->pool = lib->settings->get_str(lib->settings,
"charon.plugins.load-tester.pool", NULL);
this->remote = lib->settings->get_str(lib->settings,
"charon.plugins.load-tester.remote", "127.0.0.1");
this->proposal = proposal_create_from_string(PROTO_IKE,
lib->settings->get_str(lib->settings,
"charon.plugins.load-tester.proposal", "aes128-sha1-modp768"));
if (!this->proposal)
{ /* fallback */
this->proposal = proposal_create_from_string(PROTO_IKE,
"aes128-sha1-modp768");
}
this->ike_rekey = lib->settings->get_int(lib->settings,
"charon.plugins.load-tester.ike_rekey", 0);
this->child_rekey = lib->settings->get_int(lib->settings,
"charon.plugins.load-tester.child_rekey", 600);
this->initiator_auth = lib->settings->get_str(lib->settings,
"charon.plugins.load-tester.initiator_auth", "pubkey");
this->responder_auth = lib->settings->get_str(lib->settings,
"charon.plugins.load-tester.responder_auth", "pubkey");
this->port = lib->settings->get_int(lib->settings,
"charon.plugins.load-tester.dynamic_port", 0);
this->num = 1;
this->peer_cfg = generate_config(this, 0);
return &this->public;
}
@@ -0,0 +1,51 @@
/*
* Copyright (C) 2008 Martin Willi
* Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
/**
* @defgroup load_tester_config_t load_tester_config
* @{ @ingroup load_tester
*/
#ifndef LOAD_TESTER_CONFIG_H_
#define LOAD_TESTER_CONFIG_H_
#include <config/backend.h>
typedef struct load_tester_config_t load_tester_config_t;
/**
* Provide configurations for load testing.
*/
struct load_tester_config_t {
/**
* Implements backend_t interface
*/
backend_t backend;
/**
* Destroy the backend.
*/
void (*destroy)(load_tester_config_t *this);
};
/**
* Create a configuration backend for load testing.
*
* @return configuration backend
*/
load_tester_config_t *load_tester_config_create();
#endif /** LOAD_TESTER_CONFIG_H_ @}*/
@@ -0,0 +1,313 @@
/*
* Copyright (C) 2008 Martin Willi
* Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#include "load_tester_creds.h"
#include <time.h>
#include <daemon.h>
#include <credentials/keys/shared_key.h>
#include <credentials/certificates/x509.h>
#include <utils/identification.h>
typedef struct private_load_tester_creds_t private_load_tester_creds_t;
/**
* Private data of an load_tester_creds_t object
*/
struct private_load_tester_creds_t {
/**
* Public part
*/
load_tester_creds_t public;
/**
* Private key to create signatures
*/
private_key_t *private;
/**
* CA certificate, to issue/verify peer certificates
*/
certificate_t *ca;
/**
* serial number to issue certificates
*/
u_int32_t serial;
/**
* Preshared key
*/
shared_key_t *shared;
};
/**
* 1024-bit RSA key:
-----BEGIN RSA PRIVATE KEY-----
MIICXQIBAAKBgQDQXr7poAPYZLxmTCqR51STGRuk9Hc5SWtTcs6b2RzpnP8EVRLx
JEVxOKE9Mw6n7mD1pNrupCpnpGRdLAV5VznTPhSQ6k7ppJJrxosRYg0pHTZqBUEC
7nQFwAe10g8q0UnM1wa4lJzGxDH78d21cVweJgbkxAeyriS0jhNs7gO5nQIDAQAB
AoGACVACtkxJf7VY2jWTPXwaQoy/uIqYfX3zhwI9i6eTbDlxCE+JDi/xzpKaWjLa
99RmjvP0OPArWQB239ck03x7gAm2obutosGbqbKzJZS5cyIayzyW9djZDHBdt9Ho
quKB39aspWit3xPzkrr+QeIkiggtmBKALTBxTwxAU+P6euECQQD4IPdrzKbCrO79
LKvoPrQQtTjL6ogag9rI9n2ZuoK3/XVybh2byOXT8tA5G5jSz9Ac8XeVOsnH9gT5
3WXeaLOFAkEA1vrm/hVSEasp5eATgQ7ig9CF+GGKqhTwXp/uOSl/h3IRmStu5J0C
9AkYyx0bn3j5R8iUEX/C00KSE1kQNh4NOQJAVOsLYlRG2idPH0xThQc4nuM2jes1
K0Xm8ZISSDNhm1BeCoyPC4rExTW7d1/vfG5svgsRrvvQpOOYrl7MB0Lz9QJBALhg
AWJiyLsskEd90Vx7dpvUaEHo7jMGuEx/X6GYzK5Oj3dNP9NEMfc4IhJ5SWqRJ0KA
bTVA3MexLXT4iqXPSkkCQQDSjLhBwvEnSuW4ElIMzBwLbu7573z2gzU82Mj6trrw
Osoox/vmcepT1Wjy4AvPZHgxp7vEXNSeS+M5L29QNTp8
-----END RSA PRIVATE KEY-----
*/
static char private[] = {
0x30,0x82,0x02,0x5d,0x02,0x01,0x00,0x02,0x81,0x81,0x00,0xd0,0x5e,0xbe,0xe9,0xa0,
0x03,0xd8,0x64,0xbc,0x66,0x4c,0x2a,0x91,0xe7,0x54,0x93,0x19,0x1b,0xa4,0xf4,0x77,
0x39,0x49,0x6b,0x53,0x72,0xce,0x9b,0xd9,0x1c,0xe9,0x9c,0xff,0x04,0x55,0x12,0xf1,
0x24,0x45,0x71,0x38,0xa1,0x3d,0x33,0x0e,0xa7,0xee,0x60,0xf5,0xa4,0xda,0xee,0xa4,
0x2a,0x67,0xa4,0x64,0x5d,0x2c,0x05,0x79,0x57,0x39,0xd3,0x3e,0x14,0x90,0xea,0x4e,
0xe9,0xa4,0x92,0x6b,0xc6,0x8b,0x11,0x62,0x0d,0x29,0x1d,0x36,0x6a,0x05,0x41,0x02,
0xee,0x74,0x05,0xc0,0x07,0xb5,0xd2,0x0f,0x2a,0xd1,0x49,0xcc,0xd7,0x06,0xb8,0x94,
0x9c,0xc6,0xc4,0x31,0xfb,0xf1,0xdd,0xb5,0x71,0x5c,0x1e,0x26,0x06,0xe4,0xc4,0x07,
0xb2,0xae,0x24,0xb4,0x8e,0x13,0x6c,0xee,0x03,0xb9,0x9d,0x02,0x03,0x01,0x00,0x01,
0x02,0x81,0x80,0x09,0x50,0x02,0xb6,0x4c,0x49,0x7f,0xb5,0x58,0xda,0x35,0x93,0x3d,
0x7c,0x1a,0x42,0x8c,0xbf,0xb8,0x8a,0x98,0x7d,0x7d,0xf3,0x87,0x02,0x3d,0x8b,0xa7,
0x93,0x6c,0x39,0x71,0x08,0x4f,0x89,0x0e,0x2f,0xf1,0xce,0x92,0x9a,0x5a,0x32,0xda,
0xf7,0xd4,0x66,0x8e,0xf3,0xf4,0x38,0xf0,0x2b,0x59,0x00,0x76,0xdf,0xd7,0x24,0xd3,
0x7c,0x7b,0x80,0x09,0xb6,0xa1,0xbb,0xad,0xa2,0xc1,0x9b,0xa9,0xb2,0xb3,0x25,0x94,
0xb9,0x73,0x22,0x1a,0xcb,0x3c,0x96,0xf5,0xd8,0xd9,0x0c,0x70,0x5d,0xb7,0xd1,0xe8,
0xaa,0xe2,0x81,0xdf,0xd6,0xac,0xa5,0x68,0xad,0xdf,0x13,0xf3,0x92,0xba,0xfe,0x41,
0xe2,0x24,0x8a,0x08,0x2d,0x98,0x12,0x80,0x2d,0x30,0x71,0x4f,0x0c,0x40,0x53,0xe3,
0xfa,0x7a,0xe1,0x02,0x41,0x00,0xf8,0x20,0xf7,0x6b,0xcc,0xa6,0xc2,0xac,0xee,0xfd,
0x2c,0xab,0xe8,0x3e,0xb4,0x10,0xb5,0x38,0xcb,0xea,0x88,0x1a,0x83,0xda,0xc8,0xf6,
0x7d,0x99,0xba,0x82,0xb7,0xfd,0x75,0x72,0x6e,0x1d,0x9b,0xc8,0xe5,0xd3,0xf2,0xd0,
0x39,0x1b,0x98,0xd2,0xcf,0xd0,0x1c,0xf1,0x77,0x95,0x3a,0xc9,0xc7,0xf6,0x04,0xf9,
0xdd,0x65,0xde,0x68,0xb3,0x85,0x02,0x41,0x00,0xd6,0xfa,0xe6,0xfe,0x15,0x52,0x11,
0xab,0x29,0xe5,0xe0,0x13,0x81,0x0e,0xe2,0x83,0xd0,0x85,0xf8,0x61,0x8a,0xaa,0x14,
0xf0,0x5e,0x9f,0xee,0x39,0x29,0x7f,0x87,0x72,0x11,0x99,0x2b,0x6e,0xe4,0x9d,0x02,
0xf4,0x09,0x18,0xcb,0x1d,0x1b,0x9f,0x78,0xf9,0x47,0xc8,0x94,0x11,0x7f,0xc2,0xd3,
0x42,0x92,0x13,0x59,0x10,0x36,0x1e,0x0d,0x39,0x02,0x40,0x54,0xeb,0x0b,0x62,0x54,
0x46,0xda,0x27,0x4f,0x1f,0x4c,0x53,0x85,0x07,0x38,0x9e,0xe3,0x36,0x8d,0xeb,0x35,
0x2b,0x45,0xe6,0xf1,0x92,0x12,0x48,0x33,0x61,0x9b,0x50,0x5e,0x0a,0x8c,0x8f,0x0b,
0x8a,0xc4,0xc5,0x35,0xbb,0x77,0x5f,0xef,0x7c,0x6e,0x6c,0xbe,0x0b,0x11,0xae,0xfb,
0xd0,0xa4,0xe3,0x98,0xae,0x5e,0xcc,0x07,0x42,0xf3,0xf5,0x02,0x41,0x00,0xb8,0x60,
0x01,0x62,0x62,0xc8,0xbb,0x2c,0x90,0x47,0x7d,0xd1,0x5c,0x7b,0x76,0x9b,0xd4,0x68,
0x41,0xe8,0xee,0x33,0x06,0xb8,0x4c,0x7f,0x5f,0xa1,0x98,0xcc,0xae,0x4e,0x8f,0x77,
0x4d,0x3f,0xd3,0x44,0x31,0xf7,0x38,0x22,0x12,0x79,0x49,0x6a,0x91,0x27,0x42,0x80,
0x6d,0x35,0x40,0xdc,0xc7,0xb1,0x2d,0x74,0xf8,0x8a,0xa5,0xcf,0x4a,0x49,0x02,0x41,
0x00,0xd2,0x8c,0xb8,0x41,0xc2,0xf1,0x27,0x4a,0xe5,0xb8,0x12,0x52,0x0c,0xcc,0x1c,
0x0b,0x6e,0xee,0xf9,0xef,0x7c,0xf6,0x83,0x35,0x3c,0xd8,0xc8,0xfa,0xb6,0xba,0xf0,
0x3a,0xca,0x28,0xc7,0xfb,0xe6,0x71,0xea,0x53,0xd5,0x68,0xf2,0xe0,0x0b,0xcf,0x64,
0x78,0x31,0xa7,0xbb,0xc4,0x5c,0xd4,0x9e,0x4b,0xe3,0x39,0x2f,0x6f,0x50,0x35,0x3a,
0x7c,
};
/**
* And an associated self-signed certificate
-----BEGIN CERTIFICATE-----
MIIB9DCCAV2gAwIBAgIBADANBgkqhkiG9w0BAQUFADA3MQwwCgYDVQQDEwNzcnYx
EjAQBgNVBAsTCWxvYWQtdGVzdDETMBEGA1UEChMKc3Ryb25nU3dhbjAeFw0wODEy
MDgxODU4NDhaFw0xODEyMDYxODU4NDhaMDcxDDAKBgNVBAMTA3NydjESMBAGA1UE
CxMJbG9hZC10ZXN0MRMwEQYDVQQKEwpzdHJvbmdTd2FuMIGfMA0GCSqGSIb3DQEB
AQUAA4GNADCBiQKBgQDQXr7poAPYZLxmTCqR51STGRuk9Hc5SWtTcs6b2RzpnP8E
VRLxJEVxOKE9Mw6n7mD1pNrupCpnpGRdLAV5VznTPhSQ6k7ppJJrxosRYg0pHTZq
BUEC7nQFwAe10g8q0UnM1wa4lJzGxDH78d21cVweJgbkxAeyriS0jhNs7gO5nQID
AQABoxAwDjAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBBQUAA4GBAF39Xedyk2wj
qOcaaZ7ypb8RDlLvS0uaJMVtLtIhtb2weMMlgdmOnKXEYrJL2/mbp14Fhe+XYME9
nZLAnmUnX8bQWCsQlajb7YGE8w6QDMwXUVgSXTMhRl+PRX2CMIUzU21h1EIx65Po
CwMLbJ7vQqwPHXRitDmNkEOK9H+vRnDf
-----END CERTIFICATE-----
*/
char cert[] = {
0x30,0x82,0x01,0xf4,0x30,0x82,0x01,0x5d,0xa0,0x03,0x02,0x01,0x02,0x02,0x01,0x00,
0x30,0x0d,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x05,0x05,0x00,0x30,
0x37,0x31,0x0c,0x30,0x0a,0x06,0x03,0x55,0x04,0x03,0x13,0x03,0x73,0x72,0x76,0x31,
0x12,0x30,0x10,0x06,0x03,0x55,0x04,0x0b,0x13,0x09,0x6c,0x6f,0x61,0x64,0x2d,0x74,
0x65,0x73,0x74,0x31,0x13,0x30,0x11,0x06,0x03,0x55,0x04,0x0a,0x13,0x0a,0x73,0x74,
0x72,0x6f,0x6e,0x67,0x53,0x77,0x61,0x6e,0x30,0x1e,0x17,0x0d,0x30,0x38,0x31,0x32,
0x30,0x38,0x31,0x38,0x35,0x38,0x34,0x38,0x5a,0x17,0x0d,0x31,0x38,0x31,0x32,0x30,
0x36,0x31,0x38,0x35,0x38,0x34,0x38,0x5a,0x30,0x37,0x31,0x0c,0x30,0x0a,0x06,0x03,
0x55,0x04,0x03,0x13,0x03,0x73,0x72,0x76,0x31,0x12,0x30,0x10,0x06,0x03,0x55,0x04,
0x0b,0x13,0x09,0x6c,0x6f,0x61,0x64,0x2d,0x74,0x65,0x73,0x74,0x31,0x13,0x30,0x11,
0x06,0x03,0x55,0x04,0x0a,0x13,0x0a,0x73,0x74,0x72,0x6f,0x6e,0x67,0x53,0x77,0x61,
0x6e,0x30,0x81,0x9f,0x30,0x0d,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,
0x01,0x05,0x00,0x03,0x81,0x8d,0x00,0x30,0x81,0x89,0x02,0x81,0x81,0x00,0xd0,0x5e,
0xbe,0xe9,0xa0,0x03,0xd8,0x64,0xbc,0x66,0x4c,0x2a,0x91,0xe7,0x54,0x93,0x19,0x1b,
0xa4,0xf4,0x77,0x39,0x49,0x6b,0x53,0x72,0xce,0x9b,0xd9,0x1c,0xe9,0x9c,0xff,0x04,
0x55,0x12,0xf1,0x24,0x45,0x71,0x38,0xa1,0x3d,0x33,0x0e,0xa7,0xee,0x60,0xf5,0xa4,
0xda,0xee,0xa4,0x2a,0x67,0xa4,0x64,0x5d,0x2c,0x05,0x79,0x57,0x39,0xd3,0x3e,0x14,
0x90,0xea,0x4e,0xe9,0xa4,0x92,0x6b,0xc6,0x8b,0x11,0x62,0x0d,0x29,0x1d,0x36,0x6a,
0x05,0x41,0x02,0xee,0x74,0x05,0xc0,0x07,0xb5,0xd2,0x0f,0x2a,0xd1,0x49,0xcc,0xd7,
0x06,0xb8,0x94,0x9c,0xc6,0xc4,0x31,0xfb,0xf1,0xdd,0xb5,0x71,0x5c,0x1e,0x26,0x06,
0xe4,0xc4,0x07,0xb2,0xae,0x24,0xb4,0x8e,0x13,0x6c,0xee,0x03,0xb9,0x9d,0x02,0x03,
0x01,0x00,0x01,0xa3,0x10,0x30,0x0e,0x30,0x0c,0x06,0x03,0x55,0x1d,0x13,0x04,0x05,
0x30,0x03,0x01,0x01,0xff,0x30,0x0d,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,
0x01,0x05,0x05,0x00,0x03,0x81,0x81,0x00,0x5d,0xfd,0x5d,0xe7,0x72,0x93,0x6c,0x23,
0xa8,0xe7,0x1a,0x69,0x9e,0xf2,0xa5,0xbf,0x11,0x0e,0x52,0xef,0x4b,0x4b,0x9a,0x24,
0xc5,0x6d,0x2e,0xd2,0x21,0xb5,0xbd,0xb0,0x78,0xc3,0x25,0x81,0xd9,0x8e,0x9c,0xa5,
0xc4,0x62,0xb2,0x4b,0xdb,0xf9,0x9b,0xa7,0x5e,0x05,0x85,0xef,0x97,0x60,0xc1,0x3d,
0x9d,0x92,0xc0,0x9e,0x65,0x27,0x5f,0xc6,0xd0,0x58,0x2b,0x10,0x95,0xa8,0xdb,0xed,
0x81,0x84,0xf3,0x0e,0x90,0x0c,0xcc,0x17,0x51,0x58,0x12,0x5d,0x33,0x21,0x46,0x5f,
0x8f,0x45,0x7d,0x82,0x30,0x85,0x33,0x53,0x6d,0x61,0xd4,0x42,0x31,0xeb,0x93,0xe8,
0x0b,0x03,0x0b,0x6c,0x9e,0xef,0x42,0xac,0x0f,0x1d,0x74,0x62,0xb4,0x39,0x8d,0x90,
0x43,0x8a,0xf4,0x7f,0xaf,0x46,0x70,0xdf,
};
/**
* A preshared key
*/
static char psk[] = {
0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08
};
/**
* Implements credential_set_t.create_private_enumerator
*/
static enumerator_t* create_private_enumerator(private_load_tester_creds_t *this,
key_type_t type, identification_t *id)
{
if (this->private == NULL)
{
return NULL;
}
if (type != KEY_ANY && type != KEY_RSA)
{
return NULL;
}
if (id)
{
if (!this->private->has_fingerprint(this->private, id->get_encoding(id)))
{
return NULL;
}
}
return enumerator_create_single(this->private, NULL);
}
/**
* Implements credential_set_t.create_cert_enumerator
*/
static enumerator_t* create_cert_enumerator(private_load_tester_creds_t *this,
certificate_type_t cert, key_type_t key,
identification_t *id, bool trusted)
{
certificate_t *peer_cert;
public_key_t *peer_key, *ca_key;
u_int32_t serial;
time_t now;
if (this->ca == NULL)
{
return NULL;
}
if (cert != CERT_ANY && cert != CERT_X509)
{
return NULL;
}
if (key != KEY_ANY && key != KEY_RSA)
{
return NULL;
}
if (!id)
{
return enumerator_create_single(this->ca, NULL);
}
ca_key = this->ca->get_public_key(this->ca);
if (ca_key)
{
if (ca_key->has_fingerprint(ca_key, id->get_encoding(id)))
{
ca_key->destroy(ca_key);
return enumerator_create_single(this->ca, NULL);
}
ca_key->destroy(ca_key);
}
if (this->ca->has_subject(this->ca, id))
{
return enumerator_create_single(this->ca, NULL);
}
if (!trusted)
{
/* peer certificate, generate on demand */
serial = htonl(++this->serial);
now = time(NULL);
peer_key = this->private->get_public_key(this->private);
peer_cert = lib->creds->create(lib->creds, CRED_CERTIFICATE, CERT_X509,
BUILD_SIGNING_KEY, this->private,
BUILD_SIGNING_CERT, this->ca,
BUILD_PUBLIC_KEY, peer_key,
BUILD_SUBJECT, id,
BUILD_NOT_BEFORE_TIME, now - 60 * 60 * 24,
BUILD_NOT_AFTER_TIME, now + 60 * 60 * 24,
BUILD_SERIAL, chunk_from_thing(serial),
BUILD_END);
peer_key->destroy(peer_key);
if (peer_cert)
{
return enumerator_create_single(peer_cert, (void*)peer_cert->destroy);
}
}
return NULL;
}
/**
* Implements credential_set_t.create_shared_enumerator
*/
static enumerator_t* create_shared_enumerator(private_load_tester_creds_t *this,
shared_key_type_t type, identification_t *me,
identification_t *other)
{
return enumerator_create_single(this->shared, NULL);
}
/**
* Implementation of load_tester_creds_t.destroy
*/
static void destroy(private_load_tester_creds_t *this)
{
DESTROY_IF(this->private);
DESTROY_IF(this->ca);
this->shared->destroy(this->shared);
free(this);
}
load_tester_creds_t *load_tester_creds_create()
{
private_load_tester_creds_t *this = malloc_thing(private_load_tester_creds_t);
this->public.credential_set.create_shared_enumerator = (enumerator_t*(*)(credential_set_t*, shared_key_type_t, identification_t*, identification_t*))create_shared_enumerator;
this->public.credential_set.create_private_enumerator = (enumerator_t*(*) (credential_set_t*, key_type_t, identification_t*))create_private_enumerator;
this->public.credential_set.create_cert_enumerator = (enumerator_t*(*) (credential_set_t*, certificate_type_t, key_type_t,identification_t *, bool))create_cert_enumerator;
this->public.credential_set.create_cdp_enumerator = (enumerator_t*(*) (credential_set_t *,certificate_type_t, identification_t *))return_null;
this->public.credential_set.cache_cert = (void (*)(credential_set_t *, certificate_t *))nop;
this->public.destroy = (void(*) (load_tester_creds_t*))destroy;
this->private = lib->creds->create(lib->creds, CRED_PRIVATE_KEY, KEY_RSA,
BUILD_BLOB_ASN1_DER, chunk_create(private, sizeof(private)),
BUILD_END);
this->ca = lib->creds->create(lib->creds, CRED_CERTIFICATE, CERT_X509,
BUILD_BLOB_ASN1_DER, chunk_create(cert, sizeof(cert)),
BUILD_X509_FLAG, X509_CA,
BUILD_END);
this->shared = shared_key_create(SHARED_IKE,
chunk_clone(chunk_create(psk, sizeof(psk))));
this->serial = 0;
return &this->public;
}
@@ -0,0 +1,51 @@
/*
* Copyright (C) 2008 Martin Willi
* Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
/**
* @defgroup load_tester_creds_t load_tester_creds
* @{ @ingroup load_tester
*/
#ifndef LOAD_TESTER_CREDS_H_
#define LOAD_TESTER_CREDS_H_
#include <credentials/credential_set.h>
typedef struct load_tester_creds_t load_tester_creds_t;
/**
* Provide hard-coded credentials for load testing.
*/
struct load_tester_creds_t {
/**
* Implements credential set interface.
*/
credential_set_t credential_set;
/**
* Destroy the backend.
*/
void (*destroy)(load_tester_creds_t *this);
};
/**
* Create a credential set for load testing.
*
* @return credential set
*/
load_tester_creds_t *load_tester_creds_create();
#endif /** LOAD_TESTER_CREDS_H_ @}*/
@@ -0,0 +1,67 @@
/*
* Copyright (C) 2008 Martin Willi
* Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#include "load_tester_diffie_hellman.h"
/**
* Implementation of gmp_diffie_hellman_t.get_my_public_value.
*/
static void get_my_public_value(load_tester_diffie_hellman_t *this,
chunk_t *value)
{
*value = chunk_empty;
}
/**
* Implementation of gmp_diffie_hellman_t.get_shared_secret.
*/
static status_t get_shared_secret(load_tester_diffie_hellman_t *this,
chunk_t *secret)
{
*secret = chunk_empty;
return SUCCESS;
}
/**
* Implementation of gmp_diffie_hellman_t.get_dh_group.
*/
static diffie_hellman_group_t get_dh_group(load_tester_diffie_hellman_t *this)
{
return MODP_NULL;
}
/**
* See header
*/
load_tester_diffie_hellman_t *load_tester_diffie_hellman_create(
diffie_hellman_group_t group)
{
load_tester_diffie_hellman_t *this;
if (group != MODP_NULL)
{
return NULL;
}
this = malloc_thing(load_tester_diffie_hellman_t);
this->dh.get_shared_secret = (status_t (*)(diffie_hellman_t *, chunk_t *))get_shared_secret;
this->dh.set_other_public_value = (void (*)(diffie_hellman_t *, chunk_t ))nop;
this->dh.get_my_public_value = (void (*)(diffie_hellman_t *, chunk_t *))get_my_public_value;
this->dh.get_dh_group = (diffie_hellman_group_t (*)(diffie_hellman_t *))get_dh_group;
this->dh.destroy = (void (*)(diffie_hellman_t *))free;
return this;
}
@@ -0,0 +1,48 @@
/*
* Copyright (C) 2008 Martin Willi
* Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
/**
* @defgroup load_tester_diffie_hellman load_tester_diffie_hellman
* @{ @ingroup load_tester
*/
#ifndef LOAD_TESTER_DIFFIE_HELLMAN_H_
#define LOAD_TESTER_DIFFIE_HELLMAN_H_
#include <crypto/diffie_hellman.h>
typedef struct load_tester_diffie_hellman_t load_tester_diffie_hellman_t;
/**
* A NULL Diffie Hellman implementation to avoid calculation overhead in tests.
*/
struct load_tester_diffie_hellman_t {
/**
* Implements diffie_hellman_t interface.
*/
diffie_hellman_t dh;
};
/**
* Creates a new gmp_diffie_hellman_t object.
*
* @param group Diffie Hellman group, supports MODP_NULL only
* @return gmp_diffie_hellman_t object
*/
load_tester_diffie_hellman_t *load_tester_diffie_hellman_create(
diffie_hellman_group_t group);
#endif /** LOAD_TESTER_DIFFIE_HELLMAN_H_ @}*/
@@ -0,0 +1,176 @@
/*
* Copyright (C) 2008 Martin Willi
* Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#include "load_tester_ipsec.h"
#include <time.h>
typedef struct private_load_tester_ipsec_t private_load_tester_ipsec_t;
/**
* Private variables and functions of kernel_pfkey class.
*/
struct private_load_tester_ipsec_t {
/**
* Public interface.
*/
load_tester_ipsec_t public;
/**
* faked SPI counter
*/
u_int32_t spi;
};
/**
* Implementation of kernel_interface_t.get_spi.
*/
static status_t get_spi(private_load_tester_ipsec_t *this,
host_t *src, host_t *dst,
protocol_id_t protocol, u_int32_t reqid,
u_int32_t *spi)
{
*spi = ++this->spi;
return SUCCESS;
}
/**
* Implementation of kernel_interface_t.get_cpi.
*/
static status_t get_cpi(private_load_tester_ipsec_t *this,
host_t *src, host_t *dst,
u_int32_t reqid, u_int16_t *cpi)
{
return FAILED;
}
/**
* Implementation of kernel_interface_t.add_sa.
*/
static status_t add_sa(private_load_tester_ipsec_t *this,
host_t *src, host_t *dst, u_int32_t spi,
protocol_id_t protocol, u_int32_t reqid,
lifetime_cfg_t *lifetime,
u_int16_t enc_alg, chunk_t enc_key,
u_int16_t int_alg, chunk_t int_key,
ipsec_mode_t mode, u_int16_t ipcomp, u_int16_t cpi,
bool encap, bool inbound, traffic_selector_t *src_ts,
traffic_selector_t *dst_ts)
{
return SUCCESS;
}
/**
* Implementation of kernel_interface_t.update_sa.
*/
static status_t update_sa(private_load_tester_ipsec_t *this,
u_int32_t spi, protocol_id_t protocol, u_int16_t cpi,
host_t *src, host_t *dst,
host_t *new_src, host_t *new_dst,
bool encap, bool new_encap)
{
return SUCCESS;
}
/**
* Implementation of kernel_interface_t.query_sa.
*/
static status_t query_sa(private_load_tester_ipsec_t *this, host_t *src,
host_t *dst, u_int32_t spi, protocol_id_t protocol,
u_int64_t *bytes)
{
return NOT_SUPPORTED;
}
/**
* Implementation of kernel_interface_t.del_sa.
*/
static status_t del_sa(private_load_tester_ipsec_t *this, host_t *src,
host_t *dst, u_int32_t spi, protocol_id_t protocol,
u_int16_t cpi)
{
return SUCCESS;
}
/**
* Implementation of kernel_interface_t.add_policy.
*/
static status_t add_policy(private_load_tester_ipsec_t *this,
host_t *src, host_t *dst,
traffic_selector_t *src_ts,
traffic_selector_t *dst_ts,
policy_dir_t direction, u_int32_t spi,
protocol_id_t protocol, u_int32_t reqid,
ipsec_mode_t mode, u_int16_t ipcomp, u_int16_t cpi,
bool routed)
{
return SUCCESS;
}
/**
* Implementation of kernel_interface_t.query_policy.
*/
static status_t query_policy(private_load_tester_ipsec_t *this,
traffic_selector_t *src_ts,
traffic_selector_t *dst_ts,
policy_dir_t direction, u_int32_t *use_time)
{
*use_time = time_monotonic(NULL);
return SUCCESS;
}
/**
* Implementation of kernel_interface_t.del_policy.
*/
static status_t del_policy(private_load_tester_ipsec_t *this,
traffic_selector_t *src_ts,
traffic_selector_t *dst_ts,
policy_dir_t direction, bool unrouted)
{
return SUCCESS;
}
/**
* Implementation of kernel_interface_t.destroy.
*/
static void destroy(private_load_tester_ipsec_t *this)
{
free(this);
}
/*
* Described in header.
*/
load_tester_ipsec_t *load_tester_ipsec_create()
{
private_load_tester_ipsec_t *this = malloc_thing(private_load_tester_ipsec_t);
/* public functions */
this->public.interface.get_spi = (status_t(*)(kernel_ipsec_t*,host_t*,host_t*,protocol_id_t,u_int32_t,u_int32_t*))get_spi;
this->public.interface.get_cpi = (status_t(*)(kernel_ipsec_t*,host_t*,host_t*,u_int32_t,u_int16_t*))get_cpi;
this->public.interface.add_sa = (status_t(*)(kernel_ipsec_t *,host_t*,host_t*,u_int32_t,protocol_id_t,u_int32_t,lifetime_cfg_t*,u_int16_t,chunk_t,u_int16_t,chunk_t,ipsec_mode_t,u_int16_t,u_int16_t,bool,bool,traffic_selector_t*,traffic_selector_t*))add_sa;
this->public.interface.update_sa = (status_t(*)(kernel_ipsec_t*,u_int32_t,protocol_id_t,u_int16_t,host_t*,host_t*,host_t*,host_t*,bool,bool))update_sa;
this->public.interface.query_sa = (status_t(*)(kernel_ipsec_t*,host_t*,host_t*,u_int32_t,protocol_id_t,u_int64_t*))query_sa;
this->public.interface.del_sa = (status_t(*)(kernel_ipsec_t*,host_t*,host_t*,u_int32_t,protocol_id_t,u_int16_t))del_sa;
this->public.interface.add_policy = (status_t(*)(kernel_ipsec_t *this,host_t *, host_t *,traffic_selector_t *,traffic_selector_t *,policy_dir_t, u_int32_t,protocol_id_t, u_int32_t,ipsec_mode_t, u_int16_t, u_int16_t,bool))add_policy;
this->public.interface.query_policy = (status_t(*)(kernel_ipsec_t*,traffic_selector_t*,traffic_selector_t*,policy_dir_t,u_int32_t*))query_policy;
this->public.interface.del_policy = (status_t(*)(kernel_ipsec_t*,traffic_selector_t*,traffic_selector_t*,policy_dir_t,bool))del_policy;
this->public.interface.destroy = (void(*)(kernel_ipsec_t*)) destroy;
this->spi = 0;
return &this->public;
}
@@ -0,0 +1,46 @@
/*
* Copyright (C) 2008 Martin Willi
* Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
/**
* @defgroup load_tester_ipsec_i load_tester_ipsec
* @{ @ingroup load_tester
*/
#ifndef LOAD_TESTER_IPSEC_H_
#define LOAD_TESTER_IPSEC_H_
#include <kernel/kernel_ipsec.h>
typedef struct load_tester_ipsec_t load_tester_ipsec_t;
/**
* Implementation of a fake kernel ipsec interface for load testing.
*/
struct load_tester_ipsec_t {
/**
* Implements kernel_ipsec_t interface
*/
kernel_ipsec_t interface;
};
/**
* Create a faked kernel ipsec interface instance.
*
* @return kernel_load_tester_ipsec_t instance
*/
load_tester_ipsec_t *load_tester_ipsec_create();
#endif /** LOAD_TESTER_IPSEC_H_ @}*/
@@ -0,0 +1,102 @@
/*
* Copyright (C) 2008 Martin Willi
* Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#include "load_tester_listener.h"
#include <signal.h>
#include <daemon.h>
#include <processing/jobs/delete_ike_sa_job.h>
typedef struct private_load_tester_listener_t private_load_tester_listener_t;
/**
* Private data of an load_tester_listener_t object
*/
struct private_load_tester_listener_t {
/**
* Public part
*/
load_tester_listener_t public;
/**
* Delete IKE_SA after it has been established
*/
bool delete_after_established;
/**
* Number of established SAs
*/
u_int established;
/**
* Shutdown the daemon if we have established this SA count
*/
u_int shutdown_on;
};
/**
* Implementation of listener_t.ike_state_change
*/
static bool ike_state_change(private_load_tester_listener_t *this,
ike_sa_t *ike_sa, ike_sa_state_t state)
{
if (state == IKE_ESTABLISHED)
{
ike_sa_id_t *id = ike_sa->get_id(ike_sa);
if (this->delete_after_established)
{
charon->processor->queue_job(charon->processor,
(job_t*)delete_ike_sa_job_create(id, TRUE));
}
if (id->is_initiator(id))
{
if (this->shutdown_on == ++this->established)
{
DBG1(DBG_CFG, "load-test complete, raising SIGTERM");
kill(0, SIGTERM);
}
}
}
return TRUE;
}
/**
* Implementation of load_tester_listener_t.destroy
*/
static void destroy(private_load_tester_listener_t *this)
{
free(this);
}
load_tester_listener_t *load_tester_listener_create(u_int shutdown_on)
{
private_load_tester_listener_t *this = malloc_thing(private_load_tester_listener_t);
memset(&this->public.listener, 0, sizeof(listener_t));
this->public.listener.ike_state_change = (void*)ike_state_change;
this->public.destroy = (void(*) (load_tester_listener_t*))destroy;
this->delete_after_established = lib->settings->get_bool(lib->settings,
"charon.plugins.load-tester.delete_after_established", FALSE);
this->shutdown_on = shutdown_on;
this->established = 0;
return &this->public;
}
@@ -0,0 +1,52 @@
/*
* Copyright (C) 2008 Martin Willi
* Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
/**
* @defgroup load_tester_listener_t load_tester_listener
* @{ @ingroup load_tester
*/
#ifndef LOAD_TESTER_LISTENER_H_
#define LOAD_TESTER_LISTENER_H_
#include <bus/bus.h>
typedef struct load_tester_listener_t load_tester_listener_t;
/**
* Provide hard-coded credentials for load testing.
*/
struct load_tester_listener_t {
/**
* Implements listener set interface.
*/
listener_t listener;
/**
* Destroy the backend.
*/
void (*destroy)(load_tester_listener_t *this);
};
/**
* Create a listener to handle special events during load test
*
* @param shutdown_on shut down the daemon after this many SAs are established
* @return listener
*/
load_tester_listener_t *load_tester_listener_create(u_int shutdown_on);
#endif /** LOAD_TESTER_LISTENER_H_ @}*/
@@ -0,0 +1,230 @@
/*
* Copyright (C) 2008 Martin Willi
* Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
#include "load_tester_plugin.h"
#include "load_tester_config.h"
#include "load_tester_creds.h"
#include "load_tester_ipsec.h"
#include "load_tester_listener.h"
#include "load_tester_diffie_hellman.h"
#include <unistd.h>
#include <daemon.h>
#include <processing/jobs/callback_job.h>
#include <threading/condvar.h>
#include <threading/mutex.h>
typedef struct private_load_tester_plugin_t private_load_tester_plugin_t;
/**
* private data of load_tester plugin
*/
struct private_load_tester_plugin_t {
/**
* implements plugin interface
*/
load_tester_plugin_t public;
/**
* load_tester configuration backend
*/
load_tester_config_t *config;
/**
* load_tester credential set implementation
*/
load_tester_creds_t *creds;
/**
* event handler, listens on bus
*/
load_tester_listener_t *listener;
/**
* number of iterations per thread
*/
int iterations;
/**
* number desired initiator threads
*/
int initiators;
/**
* currenly running initiators
*/
int running;
/**
* delay between initiations, in ms
*/
int delay;
/**
* mutex to lock running field
*/
mutex_t *mutex;
/**
* condvar to wait for initiators
*/
condvar_t *condvar;
};
/**
* Begin the load test
*/
static job_requeue_t do_load_test(private_load_tester_plugin_t *this)
{
int i, s = 0, ms = 0;
this->mutex->lock(this->mutex);
if (!this->running)
{
this->running = this->initiators;
}
this->mutex->unlock(this->mutex);
if (this->delay)
{
s = this->delay / 1000;
ms = this->delay % 1000;
}
for (i = 0; this->iterations == 0 || i < this->iterations; i++)
{
peer_cfg_t *peer_cfg;
child_cfg_t *child_cfg = NULL;
enumerator_t *enumerator;
peer_cfg = charon->backends->get_peer_cfg_by_name(charon->backends,
"load-test");
if (!peer_cfg)
{
break;
}
enumerator = peer_cfg->create_child_cfg_enumerator(peer_cfg);
if (!enumerator->enumerate(enumerator, &child_cfg))
{
enumerator->destroy(enumerator);
break;
}
enumerator->destroy(enumerator);
charon->controller->initiate(charon->controller,
peer_cfg, child_cfg->get_ref(child_cfg),
NULL, NULL);
if (s)
{
sleep(s);
}
if (ms)
{
usleep(ms * 1000);
}
}
this->mutex->lock(this->mutex);
this->running--;
this->mutex->unlock(this->mutex);
this->condvar->signal(this->condvar);
return JOB_REQUEUE_NONE;
}
/**
* Implementation of plugin_t.destroy
*/
static void destroy(private_load_tester_plugin_t *this)
{
this->iterations = -1;
this->mutex->lock(this->mutex);
while (this->running)
{
this->condvar->wait(this->condvar, this->mutex);
}
this->mutex->unlock(this->mutex);
charon->kernel_interface->remove_ipsec_interface(charon->kernel_interface,
(kernel_ipsec_constructor_t)load_tester_ipsec_create);
charon->backends->remove_backend(charon->backends, &this->config->backend);
charon->credentials->remove_set(charon->credentials, &this->creds->credential_set);
charon->bus->remove_listener(charon->bus, &this->listener->listener);
this->config->destroy(this->config);
this->creds->destroy(this->creds);
this->listener->destroy(this->listener);
lib->crypto->remove_dh(lib->crypto,
(dh_constructor_t)load_tester_diffie_hellman_create);
this->mutex->destroy(this->mutex);
this->condvar->destroy(this->condvar);
free(this);
}
/*
* see header file
*/
plugin_t *load_tester_plugin_create()
{
private_load_tester_plugin_t *this;
u_int i, shutdown_on = 0;
if (!lib->settings->get_bool(lib->settings,
"charon.plugins.load-tester.enable", FALSE))
{
DBG1(DBG_CFG, "disabling load-tester plugin, not configured");
return NULL;
}
this = malloc_thing(private_load_tester_plugin_t);
this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
lib->crypto->add_dh(lib->crypto, MODP_NULL,
(dh_constructor_t)load_tester_diffie_hellman_create);
this->delay = lib->settings->get_int(lib->settings,
"charon.plugins.load-tester.delay", 0);
this->iterations = lib->settings->get_int(lib->settings,
"charon.plugins.load-tester.iterations", 1);
this->initiators = lib->settings->get_int(lib->settings,
"charon.plugins.load-tester.initiators", 0);
if (lib->settings->get_bool(lib->settings,
"charon.plugins.load-tester.shutdown_when_complete", 0))
{
shutdown_on = this->iterations * this->initiators;
}
this->mutex = mutex_create(MUTEX_TYPE_DEFAULT);
this->condvar = condvar_create(CONDVAR_TYPE_DEFAULT);
this->config = load_tester_config_create();
this->creds = load_tester_creds_create();
this->listener = load_tester_listener_create(shutdown_on);
charon->backends->add_backend(charon->backends, &this->config->backend);
charon->credentials->add_set(charon->credentials, &this->creds->credential_set);
charon->bus->add_listener(charon->bus, &this->listener->listener);
if (lib->settings->get_bool(lib->settings,
"charon.plugins.load-tester.fake_kernel", FALSE))
{
charon->kernel_interface->add_ipsec_interface(charon->kernel_interface,
(kernel_ipsec_constructor_t)load_tester_ipsec_create);
}
this->running = 0;
for (i = 0; i < this->initiators; i++)
{
charon->processor->queue_job(charon->processor,
(job_t*)callback_job_create((callback_job_cb_t)do_load_test,
this, NULL, NULL));
}
return &this->public.plugin;
}
@@ -0,0 +1,44 @@
/*
* Copyright (C) 2008 Martin Willi
* Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*/
/**
* @defgroup load_tester load_tester
* @ingroup cplugins
*
* @defgroup load_tester_plugin load_tester_plugin
* @{ @ingroup load_tester
*/
#ifndef LOAD_TESTER_PLUGIN_H_
#define LOAD_TESTER_PLUGIN_H_
#include <plugins/plugin.h>
typedef struct load_tester_plugin_t load_tester_plugin_t;
/**
* Load tester plugin to inspect system core under high load.
*
* This plugin
*/
struct load_tester_plugin_t {
/**
* implements plugin interface
*/
plugin_t plugin;
};
#endif /** LOAD_TESTER_PLUGIN_H_ @}*/