4b88ff72c24a867044f149fb127661c8a2966892
[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, char *name)
66 {
67 return this->peer_cfg->get_ref(this->peer_cfg);;
68 }
69
70 /**
71 * Implementation of load_tester_config_t.destroy.
72 */
73 static void destroy(private_load_tester_config_t *this)
74 {
75 this->peer_cfg->destroy(this->peer_cfg);
76 free(this);
77 }
78
79 /**
80 * Described in header.
81 */
82 load_tester_config_t *load_tester_config_create()
83 {
84 private_load_tester_config_t *this = malloc_thing(private_load_tester_config_t);
85 ike_cfg_t *ike_cfg;
86 child_cfg_t *child_cfg;
87 proposal_t *proposal;
88 traffic_selector_t *ts;
89 auth_info_t *auth;
90 auth_class_t class;
91 char *remote, *pool;
92 host_t *vip = NULL;
93
94 this->public.backend.create_peer_cfg_enumerator = (enumerator_t*(*)(backend_t*, identification_t *me, identification_t *other))create_peer_cfg_enumerator;
95 this->public.backend.create_ike_cfg_enumerator = (enumerator_t*(*)(backend_t*, host_t *me, host_t *other))create_ike_cfg_enumerator;
96 this->public.backend.get_peer_cfg_by_name = (peer_cfg_t* (*)(backend_t*,char*))get_peer_cfg_by_name;
97 this->public.destroy = (void(*)(load_tester_config_t*))destroy;
98
99 if (lib->settings->get_bool(lib->settings,
100 "charon.plugins.load_tester.request_virtual_ip", FALSE))
101 {
102 vip = host_create_from_string("0.0.0.0", 0);
103 }
104 pool = lib->settings->get_str(lib->settings,
105 "charon.plugins.load_tester.pool", NULL);
106 remote = lib->settings->get_str(lib->settings,
107 "charon.plugins.load_tester.remote", "127.0.0.1");
108 ike_cfg = ike_cfg_create(TRUE, FALSE, "0.0.0.0", remote);
109 proposal = proposal_create_from_string(PROTO_IKE,
110 lib->settings->get_str(lib->settings,
111 "charon.plugins.load_tester.proposal", "aes128-sha1-modp768"));
112 if (!proposal)
113 { /* fallback */
114 proposal = proposal_create_from_string(PROTO_IKE, "aes128-sha1-modp768");
115 }
116 ike_cfg->add_proposal(ike_cfg, proposal);
117 this->peer_cfg = peer_cfg_create("load-test", 2, ike_cfg,
118 identification_create_from_string("load-test@strongswan.org"),
119 identification_create_from_string("load-test@strongswan.org"),
120 CERT_SEND_IF_ASKED, UNIQUE_NO, 1, 0, 0, /* keytries, rekey, reauth */
121 0, 0, TRUE, 60, /* jitter, overtime, mobike, dpddelay */
122 vip, pool, FALSE, NULL, NULL);
123 auth = this->peer_cfg->get_auth(this->peer_cfg);
124 class = AUTH_CLASS_PUBKEY;
125 auth->add_item(auth, AUTHN_AUTH_CLASS, &class);
126 child_cfg = child_cfg_create("load-test", 600, 400, 100, NULL, TRUE,
127 MODE_TUNNEL, ACTION_NONE, ACTION_NONE, FALSE);
128 proposal = proposal_create_from_string(PROTO_ESP, "aes128-sha1");
129 child_cfg->add_proposal(child_cfg, proposal);
130 ts = traffic_selector_create_dynamic(0, 0, 65535);
131 child_cfg->add_traffic_selector(child_cfg, TRUE, ts);
132 ts = traffic_selector_create_dynamic(0, 0, 65535);
133 child_cfg->add_traffic_selector(child_cfg, FALSE, ts);
134 this->peer_cfg->add_child_cfg(this->peer_cfg, child_cfg);
135
136 return &this->public;
137 }
138