- add connection names to connections
- stroke status / ipsec status shows them - added statusall for stroke - added status by connection name - some tests repaired, more to come
This commit is contained in:
@@ -20,6 +20,8 @@
|
||||
* for more details.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "connection.h"
|
||||
|
||||
#include <utils/linked_list.h>
|
||||
@@ -48,6 +50,11 @@ struct private_connection_t {
|
||||
*/
|
||||
connection_t public;
|
||||
|
||||
/**
|
||||
* Name of the connection
|
||||
*/
|
||||
char *name;
|
||||
|
||||
/**
|
||||
* ID of us
|
||||
*/
|
||||
@@ -79,6 +86,14 @@ struct private_connection_t {
|
||||
linked_list_t *proposals;
|
||||
};
|
||||
|
||||
/**
|
||||
* Implementation of connection_t.get_name.
|
||||
*/
|
||||
static char *get_name (private_connection_t *this)
|
||||
{
|
||||
return this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of connection_t.get_my_id.
|
||||
*/
|
||||
@@ -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;
|
||||
|
||||
@@ -185,6 +185,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.
|
||||
*
|
||||
@@ -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);
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
* for more details.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "local_connection_store.h"
|
||||
|
||||
#include <utils/linked_list.h>
|
||||
@@ -158,10 +160,33 @@ static connection_t *get_connection_by_ids(private_local_connection_store_t *thi
|
||||
return found;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user