vici: Add support for ike_sa and child_sa updown notifications
Useful for monitoring and management purposes. Signed-off-by: Timo Teräs <[email protected]>
This commit is contained in:
@@ -13,6 +13,28 @@
|
|||||||
* for more details.
|
* for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2014 Timo Teräs <[email protected]>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
#include "vici_plugin.h"
|
#include "vici_plugin.h"
|
||||||
#include "vici_dispatcher.h"
|
#include "vici_dispatcher.h"
|
||||||
#include "vici_query.h"
|
#include "vici_query.h"
|
||||||
@@ -106,12 +128,14 @@ static bool register_vici(private_vici_plugin_t *this,
|
|||||||
charon->attributes->add_provider(charon->attributes,
|
charon->attributes->add_provider(charon->attributes,
|
||||||
&this->attrs->provider);
|
&this->attrs->provider);
|
||||||
charon->bus->add_logger(charon->bus, &this->logger->logger);
|
charon->bus->add_logger(charon->bus, &this->logger->logger);
|
||||||
|
charon->bus->add_listener(charon->bus, &this->query->listener);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
charon->bus->remove_listener(charon->bus, &this->query->listener);
|
||||||
charon->bus->remove_logger(charon->bus, &this->logger->logger);
|
charon->bus->remove_logger(charon->bus, &this->logger->logger);
|
||||||
charon->attributes->remove_provider(charon->attributes,
|
charon->attributes->remove_provider(charon->attributes,
|
||||||
&this->attrs->provider);
|
&this->attrs->provider);
|
||||||
|
|||||||
@@ -13,6 +13,28 @@
|
|||||||
* for more details.
|
* for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2014 Timo Teräs <[email protected]>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
#include "vici_query.h"
|
#include "vici_query.h"
|
||||||
#include "vici_builder.h"
|
#include "vici_builder.h"
|
||||||
|
|
||||||
@@ -1008,6 +1030,8 @@ static void manage_commands(private_vici_query_t *this, bool reg)
|
|||||||
this->dispatcher->manage_event(this->dispatcher, "list-policy", reg);
|
this->dispatcher->manage_event(this->dispatcher, "list-policy", reg);
|
||||||
this->dispatcher->manage_event(this->dispatcher, "list-conn", reg);
|
this->dispatcher->manage_event(this->dispatcher, "list-conn", reg);
|
||||||
this->dispatcher->manage_event(this->dispatcher, "list-cert", reg);
|
this->dispatcher->manage_event(this->dispatcher, "list-cert", reg);
|
||||||
|
this->dispatcher->manage_event(this->dispatcher, "ike-updown", reg);
|
||||||
|
this->dispatcher->manage_event(this->dispatcher, "child-updown", reg);
|
||||||
manage_command(this, "list-sas", list_sas, reg);
|
manage_command(this, "list-sas", list_sas, reg);
|
||||||
manage_command(this, "list-policies", list_policies, reg);
|
manage_command(this, "list-policies", list_policies, reg);
|
||||||
manage_command(this, "list-conns", list_conns, reg);
|
manage_command(this, "list-conns", list_conns, reg);
|
||||||
@@ -1016,6 +1040,63 @@ static void manage_commands(private_vici_query_t *this, bool reg)
|
|||||||
manage_command(this, "stats", stats, reg);
|
manage_command(this, "stats", stats, reg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
METHOD(listener_t, ike_updown, bool,
|
||||||
|
private_vici_query_t *this, ike_sa_t *ike_sa, bool up)
|
||||||
|
{
|
||||||
|
vici_builder_t *b;
|
||||||
|
time_t now;
|
||||||
|
|
||||||
|
if (!this->dispatcher->has_event_listeners(this->dispatcher, "ike-updown"))
|
||||||
|
{
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
now = time_monotonic(NULL);
|
||||||
|
|
||||||
|
b = vici_builder_create();
|
||||||
|
b->begin_section(b, ike_sa->get_name(ike_sa));
|
||||||
|
list_ike(this, b, ike_sa, now);
|
||||||
|
b->begin_section(b, "child-sas");
|
||||||
|
b->end_section(b);
|
||||||
|
b->end_section(b);
|
||||||
|
|
||||||
|
this->dispatcher->raise_event(this->dispatcher,
|
||||||
|
"ike-updown", 0, b->finalize(b));
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
METHOD(listener_t, child_updown, bool,
|
||||||
|
private_vici_query_t *this, ike_sa_t *ike_sa, child_sa_t *child_sa, bool up)
|
||||||
|
{
|
||||||
|
vici_builder_t *b;
|
||||||
|
time_t now;
|
||||||
|
|
||||||
|
if (!this->dispatcher->has_event_listeners(this->dispatcher, "child-updown"))
|
||||||
|
{
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
now = time_monotonic(NULL);
|
||||||
|
b = vici_builder_create();
|
||||||
|
|
||||||
|
b->begin_section(b, ike_sa->get_name(ike_sa));
|
||||||
|
list_ike(this, b, ike_sa, now);
|
||||||
|
b->begin_section(b, "child-sas");
|
||||||
|
|
||||||
|
b->begin_section(b, child_sa->get_name(child_sa));
|
||||||
|
list_child(this, b, child_sa, now);
|
||||||
|
b->end_section(b);
|
||||||
|
|
||||||
|
b->end_section(b);
|
||||||
|
b->end_section(b);
|
||||||
|
|
||||||
|
this->dispatcher->raise_event(this->dispatcher,
|
||||||
|
"child-updown", 0, b->finalize(b));
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
METHOD(vici_query_t, destroy, void,
|
METHOD(vici_query_t, destroy, void,
|
||||||
private_vici_query_t *this)
|
private_vici_query_t *this)
|
||||||
{
|
{
|
||||||
@@ -1032,6 +1113,10 @@ vici_query_t *vici_query_create(vici_dispatcher_t *dispatcher)
|
|||||||
|
|
||||||
INIT(this,
|
INIT(this,
|
||||||
.public = {
|
.public = {
|
||||||
|
.listener = {
|
||||||
|
.ike_updown = _ike_updown,
|
||||||
|
.child_updown = _child_updown,
|
||||||
|
},
|
||||||
.destroy = _destroy,
|
.destroy = _destroy,
|
||||||
},
|
},
|
||||||
.dispatcher = dispatcher,
|
.dispatcher = dispatcher,
|
||||||
|
|||||||
@@ -13,11 +13,34 @@
|
|||||||
* for more details.
|
* for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2014 Timo Teräs <[email protected]>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @defgroup vici_query vici_query
|
* @defgroup vici_query vici_query
|
||||||
* @{ @ingroup vici
|
* @{ @ingroup vici
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <bus/listeners/listener.h>
|
||||||
#include "vici_dispatcher.h"
|
#include "vici_dispatcher.h"
|
||||||
|
|
||||||
#ifndef VICI_QUERY_H_
|
#ifndef VICI_QUERY_H_
|
||||||
@@ -30,6 +53,11 @@ typedef struct vici_query_t vici_query_t;
|
|||||||
*/
|
*/
|
||||||
struct vici_query_t {
|
struct vici_query_t {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements listener_t.
|
||||||
|
*/
|
||||||
|
listener_t listener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroy a vici_query_t.
|
* Destroy a vici_query_t.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user