From 8554895b956e8e3cec3581c7e27a736f446f6d4a Mon Sep 17 00:00:00 2001 From: Martin Willi Date: Mon, 8 Oct 2012 10:31:36 +0200 Subject: [PATCH] Add a stub for IKE event counters in stroke --- src/libcharon/plugins/stroke/Makefile.am | 1 + src/libcharon/plugins/stroke/stroke_counter.c | 52 +++++++++++++++++++++++++++ src/libcharon/plugins/stroke/stroke_counter.h | 49 +++++++++++++++++++++++++ src/libcharon/plugins/stroke/stroke_socket.c | 10 ++++++ 4 files changed, 112 insertions(+) create mode 100644 src/libcharon/plugins/stroke/stroke_counter.c create mode 100644 src/libcharon/plugins/stroke/stroke_counter.h diff --git a/src/libcharon/plugins/stroke/Makefile.am b/src/libcharon/plugins/stroke/Makefile.am index cebcd98..39b3e79 100644 --- a/src/libcharon/plugins/stroke/Makefile.am +++ b/src/libcharon/plugins/stroke/Makefile.am @@ -22,6 +22,7 @@ libstrongswan_stroke_la_SOURCES = \ stroke_ca.h stroke_ca.c \ stroke_attribute.h stroke_attribute.c \ stroke_handler.h stroke_handler.c \ + stroke_counter.h stroke_counter.c \ stroke_list.h stroke_list.c libstrongswan_stroke_la_LDFLAGS = -module -avoid-version diff --git a/src/libcharon/plugins/stroke/stroke_counter.c b/src/libcharon/plugins/stroke/stroke_counter.c new file mode 100644 index 0000000..db0c4d9 --- /dev/null +++ b/src/libcharon/plugins/stroke/stroke_counter.c @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2012 Martin Willi + * Copyright (C) 2012 revosec AG + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. See . + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +#include "stroke_counter.h" + +typedef struct private_stroke_counter_t private_stroke_counter_t; + +/** + * Private data of an stroke_counter_t object. + */ +struct private_stroke_counter_t { + + /** + * Public stroke_counter_t interface. + */ + stroke_counter_t public; + +}; + +METHOD(stroke_counter_t, destroy, void, + private_stroke_counter_t *this) +{ + free(this); +} + +/** + * See header + */ +stroke_counter_t *stroke_counter_create() +{ + private_stroke_counter_t *this; + + INIT(this, + .public = { + .destroy = _destroy, + }, + ); + + return &this->public; +} diff --git a/src/libcharon/plugins/stroke/stroke_counter.h b/src/libcharon/plugins/stroke/stroke_counter.h new file mode 100644 index 0000000..1f95553 --- /dev/null +++ b/src/libcharon/plugins/stroke/stroke_counter.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2012 Martin Willi + * Copyright (C) 2012 revosec AG + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. See . + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +/** + * @defgroup stroke_counter stroke_counter + * @{ @ingroup stroke + */ + +#ifndef STROKE_COUNTER_H_ +#define STROKE_COUNTER_H_ + +#include + +typedef struct stroke_counter_t stroke_counter_t; + +/** + * Collection of counter values for different IKE events. + */ +struct stroke_counter_t { + + /** + * Implements listener_t. + */ + listener_t listener; + + /** + * Destroy a stroke_counter_t. + */ + void (*destroy)(stroke_counter_t *this); +}; + +/** + * Create a stroke_counter instance. + */ +stroke_counter_t *stroke_counter_create(); + +#endif /** STROKE_COUNTER_H_ @}*/ diff --git a/src/libcharon/plugins/stroke/stroke_socket.c b/src/libcharon/plugins/stroke/stroke_socket.c index 28ebfac..777378a 100644 --- a/src/libcharon/plugins/stroke/stroke_socket.c +++ b/src/libcharon/plugins/stroke/stroke_socket.c @@ -39,6 +39,7 @@ #include "stroke_attribute.h" #include "stroke_handler.h" #include "stroke_list.h" +#include "stroke_counter.h" /** * To avoid clogging the thread pool with (blocking) jobs, we limit the number @@ -123,6 +124,11 @@ struct private_stroke_socket_t { * status information logging */ stroke_list_t *list; + + /** + * Counter values for IKE events + */ + stroke_counter_t *counter; }; /** @@ -781,6 +787,7 @@ METHOD(stroke_socket_t, destroy, void, charon->backends->remove_backend(charon->backends, &this->config->backend); hydra->attributes->remove_provider(hydra->attributes, &this->attribute->provider); hydra->attributes->remove_handler(hydra->attributes, &this->handler->handler); + charon->bus->remove_listener(charon->bus, &this->counter->listener); this->cred->destroy(this->cred); this->ca->destroy(this->ca); this->config->destroy(this->config); @@ -788,6 +795,7 @@ METHOD(stroke_socket_t, destroy, void, this->handler->destroy(this->handler); this->control->destroy(this->control); this->list->destroy(this->list); + this->counter->destroy(this->counter); free(this); } @@ -817,6 +825,7 @@ stroke_socket_t *stroke_socket_create() this->config = stroke_config_create(this->ca, this->cred, this->attribute); this->control = stroke_control_create(); this->list = stroke_list_create(this->attribute); + this->counter = stroke_counter_create(); this->mutex = mutex_create(MUTEX_TYPE_DEFAULT); this->condvar = condvar_create(CONDVAR_TYPE_DEFAULT); @@ -830,6 +839,7 @@ stroke_socket_t *stroke_socket_create() charon->backends->add_backend(charon->backends, &this->config->backend); hydra->attributes->add_provider(hydra->attributes, &this->attribute->provider); hydra->attributes->add_handler(hydra->attributes, &this->handler->handler); + charon->bus->add_listener(charon->bus, &this->counter->listener); lib->processor->queue_job(lib->processor, (job_t*)callback_job_create_with_prio((callback_job_cb_t)receive, this, -- 2.7.4