trap-manager: Uninstall trap policies by name and not reqid

If a trap policy is concurrently uninstalled and reinstalled under a
different name the reqid will be the same so the wrong trap might be
removed.
This commit is contained in:
Tobias Brunner
2018-02-22 11:31:05 +01:00
parent 6f569263a0
commit ca213e1907
6 changed files with 23 additions and 72 deletions
+5 -6
View File
@@ -1,7 +1,7 @@
/*
* Copyright (C) 2011-2015 Tobias Brunner
* Copyright (C) 2011-2017 Tobias Brunner
* Copyright (C) 2009 Martin Willi
* Hochschule fuer Technik Rapperswil
* HSR Hochschule fuer Technik Rapperswil
*
* 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
@@ -347,7 +347,7 @@ METHOD(trap_manager_t, install, uint32_t,
}
METHOD(trap_manager_t, uninstall, bool,
private_trap_manager_t *this, uint32_t reqid)
private_trap_manager_t *this, char *peer, char *child)
{
enumerator_t *enumerator;
entry_t *entry, *found = NULL;
@@ -356,8 +356,8 @@ METHOD(trap_manager_t, uninstall, bool,
enumerator = this->traps->create_enumerator(this->traps);
while (enumerator->enumerate(enumerator, &entry))
{
if (entry->child_sa &&
entry->child_sa->get_reqid(entry->child_sa) == reqid)
if (streq(entry->name, child) &&
(!peer || streq(peer, entry->peer_cfg->get_name(entry->peer_cfg))))
{
this->traps->remove_at(this->traps, enumerator);
found = entry;
@@ -369,7 +369,6 @@ METHOD(trap_manager_t, uninstall, bool,
if (!found)
{
DBG1(DBG_CFG, "trap %d not found to uninstall", reqid);
return FALSE;
}
destroy_entry(found);
+8 -3
View File
@@ -1,6 +1,7 @@
/*
* Copyright (C) 2013-2017 Tobias Brunner
* Copyright (C) 2009 Martin Willi
* Hochschule fuer Technik Rapperswil
* HSR Hochschule fuer Technik Rapperswil
*
* 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
@@ -46,10 +47,14 @@ struct trap_manager_t {
/**
* Uninstall a trap policy.
*
* @param id reqid of CHILD_SA to uninstall, returned by install()
* If no peer configuration name is given the first matching child
* configuration is uninstalled.
*
* @param peer peer configuration name or NULL
* @param child child configuration name
* @return TRUE if uninstalled successfully
*/
bool (*uninstall)(trap_manager_t *this, uint32_t reqid);
bool (*uninstall)(trap_manager_t *this, char *peer, char *child);
/**
* Create an enumerator over all installed traps.