diff options
Diffstat (limited to 'Source/charon/config')
-rw-r--r-- | Source/charon/config/connections/connection.c | 20 | ||||
-rw-r--r-- | Source/charon/config/connections/connection.h | 19 | ||||
-rwxr-xr-x | Source/charon/config/connections/connection_store.h | 16 | ||||
-rw-r--r-- | Source/charon/config/connections/local_connection_store.c | 28 | ||||
-rw-r--r-- | Source/charon/config/policies/local_policy_store.c | 11 |
5 files changed, 86 insertions, 8 deletions
diff --git a/Source/charon/config/connections/connection.c b/Source/charon/config/connections/connection.c index d2e50c780..2ce544cc9 100644 --- a/Source/charon/config/connections/connection.c +++ b/Source/charon/config/connections/connection.c @@ -20,6 +20,8 @@ * for more details. */ +#include <string.h> + #include "connection.h" #include <utils/linked_list.h> @@ -49,6 +51,11 @@ struct private_connection_t { connection_t public; /** + * Name of the connection + */ + char *name; + + /** * ID of us */ identification_t *my_id; @@ -80,6 +87,14 @@ struct private_connection_t { }; /** + * Implementation of connection_t.get_name. + */ +static char *get_name (private_connection_t *this) +{ + return this->name; +} + +/** * Implementation of connection_t.get_my_id. */ static identification_t *get_my_id (private_connection_t *this) @@ -253,6 +268,7 @@ static connection_t *clone(private_connection_t *this) iterator_t *iterator; proposal_t *proposal; private_connection_t *clone = (private_connection_t*)connection_create( + this->name, this->my_host->clone(this->my_host), this->other_host->clone(this->other_host), this->my_id->clone(this->my_id), @@ -295,11 +311,12 @@ static void destroy (private_connection_t *this) /** * Described in header. */ -connection_t * connection_create(host_t *my_host, host_t *other_host, identification_t *my_id, identification_t *other_id, auth_method_t auth_method) +connection_t * connection_create(char *name, host_t *my_host, host_t *other_host, identification_t *my_id, identification_t *other_id, auth_method_t auth_method) { private_connection_t *this = malloc_thing(private_connection_t); /* public functions */ + this->public.get_name = (char*(*)(connection_t*))get_name; this->public.get_my_id = (identification_t*(*)(connection_t*))get_my_id; this->public.get_other_id = (identification_t*(*)(connection_t*))get_other_id; this->public.get_my_host = (host_t*(*)(connection_t*))get_my_host; @@ -316,6 +333,7 @@ connection_t * connection_create(host_t *my_host, host_t *other_host, identifica this->public.destroy = (void(*)(connection_t*))destroy; /* private variables */ + this->name = strdup(name); this->my_host = my_host; this->other_host = other_host; this->my_id = my_id; diff --git a/Source/charon/config/connections/connection.h b/Source/charon/config/connections/connection.h index 39b076411..fb960d1a0 100644 --- a/Source/charon/config/connections/connection.h +++ b/Source/charon/config/connections/connection.h @@ -186,6 +186,17 @@ struct connection_t { auth_method_t (*get_auth_method) (connection_t *this); /** + * @brief Get the connection name. + * + * Name must not be freed, since it points to + * internal data. + * + * @param this calling object + * @return name of the connection + */ + char* (*get_name) (connection_t *this); + + /** * @brief Get the DH group to use for connection initialization. * * @param this calling object @@ -225,8 +236,9 @@ struct connection_t { * * Supplied hosts/IDs become owned by connection, so * do not modify or destroy them after a call to - * connection_create(). - * + * connection_create(). Name gets cloned internally. + * + * @param name connection identifier * @param my_host host_t representing local address * @param other_host host_t representing remote address * @param my_id identification_t for me @@ -236,7 +248,8 @@ struct connection_t { * * @ingroup config */ -connection_t * connection_create(host_t *my_host, host_t *other_host, +connection_t * connection_create(char *name, + host_t *my_host, host_t *other_host, identification_t *my_id, identification_t *other_id, auth_method_t auth_method); diff --git a/Source/charon/config/connections/connection_store.h b/Source/charon/config/connections/connection_store.h index f1814a00d..41fd58e42 100755 --- a/Source/charon/config/connections/connection_store.h +++ b/Source/charon/config/connections/connection_store.h @@ -72,7 +72,21 @@ struct connection_store_t { * - NULL otherwise */ connection_t *(*get_connection_by_hosts) (connection_store_t *this, host_t *my_host, host_t *other_host); - + + /** + * @brief Returns a connection identified by its name. + * + * This call is usefull to get a connection identified its + * name, as on an connection setup. + * + * @param this calling object + * @param name name of the connection to get + * @return + * - connection_t, if found + * - NULL otherwise + */ + connection_t *(*get_connection_by_name) (connection_store_t *this, char *name); + /** * @brief Add a connection to the store. * diff --git a/Source/charon/config/connections/local_connection_store.c b/Source/charon/config/connections/local_connection_store.c index 3eee2ba58..3f07f0d21 100644 --- a/Source/charon/config/connections/local_connection_store.c +++ b/Source/charon/config/connections/local_connection_store.c @@ -20,6 +20,8 @@ * for more details. */ +#include <string.h> + #include "local_connection_store.h" #include <utils/linked_list.h> @@ -159,9 +161,32 @@ static connection_t *get_connection_by_ids(private_local_connection_store_t *thi } /** + * Implementation of connection_store_t.get_connection_by_name. + */ +static connection_t *get_connection_by_name(private_local_connection_store_t *this, char *name) +{ + iterator_t *iterator; + connection_t *current, *found = NULL; + + iterator = this->connections->create_iterator(this->connections, TRUE); + while (iterator->has_next(iterator)) + { + iterator->current(iterator, (void**)¤t); + if (strcmp(name, current->get_name(current)) == 0) + { + found = current->clone(current); + break; + } + } + iterator->destroy(iterator); + + return found; +} + +/** * Implementation of connection_store_t.add_connection. */ -status_t add_connection(private_local_connection_store_t *this, connection_t *connection) +static status_t add_connection(private_local_connection_store_t *this, connection_t *connection) { this->connections->insert_last(this->connections, connection); return SUCCESS; @@ -191,6 +216,7 @@ local_connection_store_t * local_connection_store_create() this->public.connection_store.get_connection_by_hosts = (connection_t*(*)(connection_store_t*,host_t*,host_t*))get_connection_by_hosts; this->public.connection_store.get_connection_by_ids = (connection_t*(*)(connection_store_t*,identification_t*,identification_t*))get_connection_by_ids; + this->public.connection_store.get_connection_by_name = (connection_t*(*)(connection_store_t*,char*))get_connection_by_name; this->public.connection_store.add_connection = (status_t(*)(connection_store_t*,connection_t*))add_connection; this->public.connection_store.destroy = (void(*)(connection_store_t*))destroy; diff --git a/Source/charon/config/policies/local_policy_store.c b/Source/charon/config/policies/local_policy_store.c index a03b86a73..7dcdf1728 100644 --- a/Source/charon/config/policies/local_policy_store.c +++ b/Source/charon/config/policies/local_policy_store.c @@ -66,6 +66,9 @@ static policy_t *get_policy(private_local_policy_store_t *this, identification_t iterator_t *iterator; policy_t *current, *found = NULL; + this->logger->log(this->logger, CONTROL|LEVEL0, "Looking for policy for IDs %s - %s", + my_id ? my_id->get_string(my_id) : "%any", + other_id->get_string(other_id)); iterator = this->policies->create_iterator(this->policies, TRUE); while (iterator->has_next(iterator)) { @@ -73,8 +76,12 @@ static policy_t *get_policy(private_local_policy_store_t *this, identification_t identification_t *config_my_id = current->get_my_id(current); identification_t *config_other_id = current->get_other_id(current); + this->logger->log(this->logger, CONTROL|LEVEL0, "Found one for %s - %s", + config_my_id->get_string(config_my_id), + config_other_id->get_string(config_other_id)); + /* check other host first */ - if (config_other_id->belongs_to(config_other_id, other_id)) + if (other_id->belongs_to(other_id, config_other_id)) { /* get it if my_id not specified */ if (my_id == NULL) @@ -82,7 +89,7 @@ static policy_t *get_policy(private_local_policy_store_t *this, identification_t found = current->clone(current); break; } - if (config_my_id->belongs_to(config_my_id, my_id)) + if (my_id->belongs_to(my_id, config_my_id)) { found = current->clone(current); break; |