added delete_after_established option
[strongswan.git] / src / charon / plugins / load_tester / load_tester_listener.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_listener.h"
19
20 #include <daemon.h>
21 #include <processing/jobs/delete_ike_sa_job.h>
22
23 typedef struct private_load_tester_listener_t private_load_tester_listener_t;
24
25 /**
26 * Private data of an load_tester_listener_t object
27 */
28 struct private_load_tester_listener_t {
29 /**
30 * Public part
31 */
32 load_tester_listener_t public;
33
34 /**
35 * Delete IKE_SA after it has been established
36 */
37 bool delete_after_established;
38 };
39
40 /**
41 * Implementation of listener_t.ike_state_change
42 */
43 static bool ike_state_change(private_load_tester_listener_t *this,
44 ike_sa_t *ike_sa, ike_sa_state_t state)
45 {
46 if (this->delete_after_established && state == IKE_ESTABLISHED)
47 {
48 charon->processor->queue_job(charon->processor,
49 (job_t*)delete_ike_sa_job_create(ike_sa->get_id(ike_sa), TRUE));
50 }
51 return TRUE;
52 }
53
54 /**
55 * Implementation of load_tester_listener_t.destroy
56 */
57 static void destroy(private_load_tester_listener_t *this)
58 {
59 free(this);
60 }
61
62 load_tester_listener_t *load_tester_listener_create()
63 {
64 private_load_tester_listener_t *this = malloc_thing(private_load_tester_listener_t);
65
66 memset(&this->public.listener, 0, sizeof(listener_t));
67 this->public.listener.ike_state_change = (void*)ike_state_change;
68 this->public.destroy = (void(*) (load_tester_listener_t*))destroy;
69
70 this->delete_after_established = lib->settings->get_bool(lib->settings,
71 "charon.plugins.load_tester.delete_after_established", FALSE);
72
73 return &this->public;
74 }
75