b184ad2b6867eca24d316a960604f0a709bf9750
[strongswan.git] / src / charon / plugins / load_tester / load_tester_config.c
1 /*
2 * Copyright (C) 2008 Martin Willi
3 * Hochschule fuer Technik Rapperswil
4 *
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>.
9 *
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
13 * for more details.
14 *
15 * $Id$
16 */
17
18 #include "load_tester_config.h"
19
20 #include <daemon.h>
21
22 typedef struct private_load_tester_config_t private_load_tester_config_t;
23
24 /**
25 * Private data of an load_tester_config_t object
26 */
27 struct private_load_tester_config_t {
28
29 /**
30 * Public part
31 */
32 load_tester_config_t public;
33
34 /**
35 * peer config
36 */
37 peer_cfg_t *peer_cfg;
38 };
39
40 /**
41 * Implementation of backend_t.create_peer_cfg_enumerator.
42 */
43 static enumerator_t* create_peer_cfg_enumerator(private_load_tester_config_t *this,
44 identification_t *me,
45 identification_t *other)
46 {
47 return enumerator_create_single(this->peer_cfg, NULL);
48 }
49
50 /**
51 * Implementation of backend_t.create_ike_cfg_enumerator.
52 */
53 static enumerator_t* create_ike_cfg_enumerator(private_load_tester_config_t *this,
54 host_t *me, host_t *other)
55 {
56 ike_cfg_t *ike_cfg;
57
58 ike_cfg = this->peer_cfg->get_ike_cfg(this->peer_cfg);
59 return enumerator_create_single(ike_cfg, NULL);
60 }
61
62 /**
63 * implements backend_t.get_peer_cfg_by_name.
64 */
65 static peer_cfg_t *get_peer_cfg_by_name(private_load_tester_config_t *this,
66 char *name)
67 {
68 if (streq(name, "load-test"))
69 {
70 return this->peer_cfg->get_ref(this->peer_cfg);
71 }
72 return NULL;
73 }
74
75 /**
76 * Implementation of load_tester_config_t.destroy.
77 */
78 static void destroy(private_load_tester_config_t *this)
79 {
80 this->peer_cfg->destroy(this->peer_cfg);
81 free(this);
82 }
83
84 /**
85 * Described in header.
86 */
87 load_tester_config_t *load_tester_config_create()
88 {
89 private_load_tester_config_t *this = malloc_thing(private_load_tester_config_t);
90 ike_cfg_t *ike_cfg;
91 child_cfg_t *child_cfg;
92 proposal_t *proposal;
93 traffic_selector_t *ts;
94 auth_info_t *auth;
95 auth_class_t class;
96 char *remote, *pool, *authstr;
97 host_t *vip = NULL;
98
99 this->public.backend.create_peer_cfg_enumerator = (enumerator_t*(*)(backend_t*, identification_t *me, identification_t *other))create_peer_cfg_enumerator;
100 this->public.backend.create_ike_cfg_enumerator = (enumerator_t*(*)(backend_t*, host_t *me, host_t *other))create_ike_cfg_enumerator;
101 this->public.backend.get_peer_cfg_by_name = (peer_cfg_t* (*)(backend_t*,char*))get_peer_cfg_by_name;
102 this->public.destroy = (void(*)(load_tester_config_t*))destroy;
103
104 if (lib->settings->get_bool(lib->settings,
105 "charon.plugins.load_tester.request_virtual_ip", FALSE))
106 {
107 vip = host_create_from_string("0.0.0.0", 0);
108 }
109 pool = lib->settings->get_str(lib->settings,
110 "charon.plugins.load_tester.pool", NULL);
111 remote = lib->settings->get_str(lib->settings,
112 "charon.plugins.load_tester.remote", "127.0.0.1");
113 ike_cfg = ike_cfg_create(TRUE, FALSE, "0.0.0.0", remote);
114 proposal = proposal_create_from_string(PROTO_IKE,
115 lib->settings->get_str(lib->settings,
116 "charon.plugins.load_tester.proposal", "aes128-sha1-modp768"));
117 if (!proposal)
118 { /* fallback */
119 proposal = proposal_create_from_string(PROTO_IKE, "aes128-sha1-modp768");
120 }
121 ike_cfg->add_proposal(ike_cfg, proposal);
122 this->peer_cfg = peer_cfg_create("load-test", 2, ike_cfg,
123 identification_create_from_string("load-test@strongswan.org"),
124 identification_create_from_string("load-test@strongswan.org"),
125 CERT_SEND_IF_ASKED, UNIQUE_NO, 1, 0, 0, /* keytries, rekey, reauth */
126 0, 0, TRUE, 60, /* jitter, overtime, mobike, dpddelay */
127 vip, pool, FALSE, NULL, NULL);
128 auth = this->peer_cfg->get_auth(this->peer_cfg);
129 authstr = lib->settings->get_str(lib->settings,
130 "charon.plugins.load_tester.auth", "pubkey");
131 if (streq(authstr, "psk"))
132 {
133 class = AUTH_CLASS_PSK;
134 }
135 else
136 {
137 class = AUTH_CLASS_PUBKEY;
138 }
139 auth->add_item(auth, AUTHN_AUTH_CLASS, &class);
140 child_cfg = child_cfg_create("load-test", 600, 400, 100, NULL, TRUE,
141 MODE_TUNNEL, ACTION_NONE, ACTION_NONE, FALSE);
142 proposal = proposal_create_from_string(PROTO_ESP, "aes128-sha1");
143 child_cfg->add_proposal(child_cfg, proposal);
144 ts = traffic_selector_create_dynamic(0, 0, 65535);
145 child_cfg->add_traffic_selector(child_cfg, TRUE, ts);
146 ts = traffic_selector_create_dynamic(0, 0, 65535);
147 child_cfg->add_traffic_selector(child_cfg, FALSE, ts);
148 this->peer_cfg->add_child_cfg(this->peer_cfg, child_cfg);
149
150 return &this->public;
151 }
152