disable MOBIKE in load-tester
[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 <signal.h>
21
22 #include <daemon.h>
23 #include <processing/jobs/delete_ike_sa_job.h>
24
25 typedef struct private_load_tester_listener_t private_load_tester_listener_t;
26
27 /**
28 * Private data of an load_tester_listener_t object
29 */
30 struct private_load_tester_listener_t {
31 /**
32 * Public part
33 */
34 load_tester_listener_t public;
35
36 /**
37 * Delete IKE_SA after it has been established
38 */
39 bool delete_after_established;
40
41 /**
42 * Number of established SAs
43 */
44 u_int established;
45
46 /**
47 * Shutdown the daemon if we have established this SA count
48 */
49 u_int shutdown_on;
50 };
51
52 /**
53 * Implementation of listener_t.ike_state_change
54 */
55 static bool ike_state_change(private_load_tester_listener_t *this,
56 ike_sa_t *ike_sa, ike_sa_state_t state)
57 {
58 if (state == IKE_ESTABLISHED)
59 {
60 ike_sa_id_t *id = ike_sa->get_id(ike_sa);
61
62 if (this->delete_after_established)
63 {
64 charon->processor->queue_job(charon->processor,
65 (job_t*)delete_ike_sa_job_create(id, TRUE));
66 }
67
68 if (id->is_initiator(id))
69 {
70 if (this->shutdown_on == ++this->established)
71 {
72 DBG1(DBG_CFG, "load-test complete, raising SIGTERM");
73 pthread_kill(charon->main_thread_id, SIGTERM);
74 }
75 }
76 }
77 return TRUE;
78 }
79
80 /**
81 * Implementation of load_tester_listener_t.destroy
82 */
83 static void destroy(private_load_tester_listener_t *this)
84 {
85 free(this);
86 }
87
88 load_tester_listener_t *load_tester_listener_create(u_int shutdown_on)
89 {
90 private_load_tester_listener_t *this = malloc_thing(private_load_tester_listener_t);
91
92 memset(&this->public.listener, 0, sizeof(listener_t));
93 this->public.listener.ike_state_change = (void*)ike_state_change;
94 this->public.destroy = (void(*) (load_tester_listener_t*))destroy;
95
96 this->delete_after_established = lib->settings->get_bool(lib->settings,
97 "charon.plugins.load_tester.delete_after_established", FALSE);
98
99 this->shutdown_on = shutdown_on;
100 this->established = 0;
101
102 return &this->public;
103 }
104