aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/charon/config/backends/local_backend.c30
-rw-r--r--src/charon/config/backends/local_backend.h9
-rw-r--r--src/charon/config/cfg_store.c18
-rw-r--r--src/charon/config/cfg_store.h9
-rwxr-xr-xsrc/charon/control/stroke_interface.c15
5 files changed, 40 insertions, 41 deletions
diff --git a/src/charon/config/backends/local_backend.c b/src/charon/config/backends/local_backend.c
index e3449fef6..be6fc923b 100644
--- a/src/charon/config/backends/local_backend.c
+++ b/src/charon/config/backends/local_backend.c
@@ -171,20 +171,38 @@ static peer_cfg_t *get_peer_cfg(private_local_backend_t *this,
static peer_cfg_t *get_peer_cfg_by_name(private_local_backend_t *this,
char *name)
{
- iterator_t *iterator;
+ iterator_t *i1, *i2;
peer_cfg_t *current, *found = NULL;
+ child_cfg_t *child;
- iterator = this->cfgs->create_iterator(this->cfgs, TRUE);
- while (iterator->iterate(iterator, (void**)&current))
+ i1 = this->cfgs->create_iterator(this->cfgs, TRUE);
+ while (i1->iterate(i1, (void**)&current))
{
+ /* compare peer_cfgs name first */
if (streq(current->get_name(current), name))
{
found = current;
found->get_ref(found);
break;
}
+ /* compare all child_cfg names otherwise */
+ i2 = current->create_child_cfg_iterator(current);
+ while (i2->iterate(i2, (void**)&child))
+ {
+ if (streq(child->get_name(child), name))
+ {
+ found = current;
+ found->get_ref(found);
+ break;
+ }
+ }
+ i2->destroy(i2);
+ if (found)
+ {
+ break;
+ }
}
- iterator->destroy(iterator);
+ i1->destroy(i1);
return found;
}
@@ -224,8 +242,8 @@ local_backend_t *local_backend_create(void)
this->public.backend.get_ike_cfg = (ike_cfg_t*(*)(backend_t*, host_t *, host_t *))get_ike_cfg;
this->public.backend.get_peer_cfg = (peer_cfg_t*(*)(backend_t*, identification_t *, identification_t *))get_peer_cfg;
- this->public.backend.get_peer_cfg_by_name = (peer_cfg_t*(*)(backend_t*, char *))get_peer_cfg_by_name;
- this->public.create_peer_cfg_iterator = (iterator_t*(*)(local_backend_t*))create_peer_cfg_iterator;
+ this->public.create_peer_cfg_iterator = (iterator_t*(*)(local_backend_t*))create_peer_cfg_iterator;
+ this->public.get_peer_cfg_by_name = (peer_cfg_t*(*)(local_backend_t*, char *))get_peer_cfg_by_name;
this->public.add_peer_cfg = (void(*)(local_backend_t*, peer_cfg_t *))add_peer_cfg;
this->public.destroy = (void(*)(local_backend_t*))destroy;
diff --git a/src/charon/config/backends/local_backend.h b/src/charon/config/backends/local_backend.h
index 041725ae4..97c43b233 100644
--- a/src/charon/config/backends/local_backend.h
+++ b/src/charon/config/backends/local_backend.h
@@ -55,6 +55,15 @@ struct local_backend_t {
void (*add_peer_cfg)(local_backend_t *this, peer_cfg_t *config);
/**
+ * @brief Get a peer_config identified by name, or a name of its child_cfgs.
+ *
+ * @param this calling object
+ * @param name name of the peer config
+ * @return matching peer_config, or NULL if none found
+ */
+ peer_cfg_t *(*get_peer_cfg_by_name)(local_backend_t *this, char *name);
+
+ /**
* @brief Create an iterator over all peer configs.
*
* @param this calling object
diff --git a/src/charon/config/cfg_store.c b/src/charon/config/cfg_store.c
index e06780a94..ef945da90 100644
--- a/src/charon/config/cfg_store.c
+++ b/src/charon/config/cfg_store.c
@@ -89,23 +89,6 @@ static peer_cfg_t *get_peer_cfg(private_cfg_store_t *this,
}
/**
- * implements cfg_store_t.get_peer_by_name.
- */
-static peer_cfg_t *get_peer_cfg_by_name(private_cfg_store_t *this, char *name)
-{
- backend_t *backend;
- peer_cfg_t *config = NULL;
- iterator_t *iterator = this->backends->create_iterator_locked(
- this->backends, &this->mutex);
- while (config == NULL && iterator->iterate(iterator, (void**)&backend))
- {
- config = backend->get_peer_cfg_by_name(backend, name);
- }
- iterator->destroy(iterator);
- return config;
-}
-
-/**
* implements cfg_store_t.register_backend.
*/
static void register_backend(private_cfg_store_t *this, backend_t *backend)
@@ -152,7 +135,6 @@ cfg_store_t *cfg_store_create()
this->public.get_ike_cfg = (ike_cfg_t*(*)(cfg_store_t*, host_t *, host_t *))get_ike_cfg;
this->public.get_peer_cfg = (peer_cfg_t*(*)(cfg_store_t*, identification_t *, identification_t *))get_peer_cfg;
- this->public.get_peer_cfg_by_name = (peer_cfg_t*(*)(cfg_store_t*, char *name))get_peer_cfg_by_name;
this->public.register_backend = (void(*)(cfg_store_t*, backend_t *))register_backend;
this->public.unregister_backend = (void(*)(cfg_store_t*, backend_t *))unregister_backend;
this->public.destroy = (void(*)(cfg_store_t*))destroy;
diff --git a/src/charon/config/cfg_store.h b/src/charon/config/cfg_store.h
index 0a0b5f3e1..04a4301bf 100644
--- a/src/charon/config/cfg_store.h
+++ b/src/charon/config/cfg_store.h
@@ -91,15 +91,6 @@ struct cfg_store_t {
identification_t *other_id);
/**
- * @brief Get a peer_config identified by its name.
- *
- * @param this calling object
- * @param name name of the peer config
- * @return matching peer_config, or NULL if none found
- */
- peer_cfg_t *(*get_peer_cfg_by_name)(cfg_store_t *this, char *name);
-
- /**
* @brief Register a backend to be queried by the calls above.
*
* The backend first added is the most preferred.
diff --git a/src/charon/control/stroke_interface.c b/src/charon/control/stroke_interface.c
index ef9238658..51e6c6dc1 100755
--- a/src/charon/control/stroke_interface.c
+++ b/src/charon/control/stroke_interface.c
@@ -617,7 +617,7 @@ static void stroke_del_conn(private_stroke_interface_t *this,
/**
* get the child_cfg with the same name as the peer cfg
*/
-static child_cfg_t* get_child_from_peer(peer_cfg_t *peer_cfg)
+static child_cfg_t* get_child_from_peer(peer_cfg_t *peer_cfg, char *name)
{
child_cfg_t *current, *found = NULL;
iterator_t *iterator;
@@ -625,7 +625,7 @@ static child_cfg_t* get_child_from_peer(peer_cfg_t *peer_cfg)
iterator = peer_cfg->create_child_cfg_iterator(peer_cfg);
while (iterator->iterate(iterator, (void**)&current))
{
- if (streq(current->get_name(current), peer_cfg->get_name(peer_cfg)))
+ if (streq(current->get_name(current), name))
{
found = current;
found->get_ref(found);
@@ -651,8 +651,8 @@ static void stroke_initiate(private_stroke_interface_t *this,
pop_string(msg, &(msg->initiate.name));
DBG1(DBG_CFG, "received stroke: initiate '%s'", msg->initiate.name);
- peer_cfg = charon->cfg_store->get_peer_cfg_by_name(charon->cfg_store,
- msg->initiate.name);
+ peer_cfg = this->backend->get_peer_cfg_by_name(this->backend,
+ msg->initiate.name);
if (peer_cfg == NULL)
{
if (msg->output_verbosity >= 0)
@@ -669,7 +669,7 @@ static void stroke_initiate(private_stroke_interface_t *this,
return;
}
- child_cfg = get_child_from_peer(peer_cfg);
+ child_cfg = get_child_from_peer(peer_cfg, msg->initiate.name);
if (child_cfg == NULL)
{
if (msg->output_verbosity >= 0)
@@ -743,8 +743,7 @@ static void stroke_route(private_stroke_interface_t *this,
DBG1(DBG_CFG, "received stroke: %s '%s'",
route ? "route" : "unroute", msg->route.name);
- peer_cfg = charon->cfg_store->get_peer_cfg_by_name(charon->cfg_store,
- msg->route.name);
+ peer_cfg = this->backend->get_peer_cfg_by_name(this->backend, msg->route.name);
if (peer_cfg == NULL)
{
fprintf(out, "no config named '%s'\n", msg->route.name);
@@ -756,7 +755,7 @@ static void stroke_route(private_stroke_interface_t *this,
return;
}
- child_cfg = get_child_from_peer(peer_cfg);
+ child_cfg = get_child_from_peer(peer_cfg, msg->route.name);
if (child_cfg == NULL)
{
fprintf(out, "no child config named '%s'\n", msg->route.name);