added fake_kernel option to make dummy kernel implementation optional
[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;
92
93 this->public.backend.create_peer_cfg_enumerator = (enumerator_t*(*)(backend_t*, identification_t *me, identification_t *other))create_peer_cfg_enumerator;
94 this->public.backend.create_ike_cfg_enumerator = (enumerator_t*(*)(backend_t*, host_t *me, host_t *other))create_ike_cfg_enumerator;
95 this->public.backend.get_peer_cfg_by_name = (peer_cfg_t* (*)(backend_t*,char*))get_peer_cfg_by_name;
96 this->public.destroy = (void(*)(load_tester_config_t*))destroy;
97
98 remote = lib->settings->get_str(lib->settings,
99 "charon.plugins.load_tester.remote", "127.0.0.1");
100 ike_cfg = ike_cfg_create(TRUE, FALSE, "0.0.0.0", remote);
101 proposal = proposal_create_from_string(PROTO_IKE,
102 lib->settings->get_str(lib->settings,
103 "charon.plugins.load_tester.proposal", "aes128-sha1-modp768"));
104 if (!proposal)
105 { /* fallback */
106 proposal = proposal_create_from_string(PROTO_IKE, "aes128-sha1-modp768");
107 }
108 ike_cfg->add_proposal(ike_cfg, proposal);
109 this->peer_cfg = peer_cfg_create("load-test", 2, ike_cfg,
110 identification_create_from_string("load-test@strongswan.org"),
111 identification_create_from_string("load-test@strongswan.org"),
112 CERT_SEND_IF_ASKED, UNIQUE_NO, 1, 0, 0, /* keytries, rekey, reauth */
113 0, 0, TRUE, 60, /* jitter, overtime, mobike, dpddelay */
114 NULL, NULL, FALSE, NULL, NULL); /* vip, pool, mediation */
115 auth = this->peer_cfg->get_auth(this->peer_cfg);
116 class = AUTH_CLASS_PUBKEY;
117 auth->add_item(auth, AUTHN_AUTH_CLASS, &class);
118 child_cfg = child_cfg_create("load-test", 600, 400, 100, NULL, TRUE,
119 MODE_TUNNEL, ACTION_NONE, ACTION_NONE, FALSE);
120 proposal = proposal_create_from_string(PROTO_ESP, "aes128-sha1");
121 child_cfg->add_proposal(child_cfg, proposal);
122 ts = traffic_selector_create_dynamic(0, 0, 65535);
123 child_cfg->add_traffic_selector(child_cfg, TRUE, ts);
124 ts = traffic_selector_create_dynamic(0, 0, 65535);
125 child_cfg->add_traffic_selector(child_cfg, FALSE, ts);
126 this->peer_cfg->add_child_cfg(this->peer_cfg, child_cfg);
127
128 return &this->public;
129 }
130