ported some hard-to-merge cherries back to trunk :-/
shame, svn, shame: this was ways to complicated we should consider a switch to git...
This commit is contained in:
@@ -406,26 +406,15 @@ static bool equals(private_traffic_selector_t *this, private_traffic_selector_t
|
|||||||
*/
|
*/
|
||||||
static chunk_t get_from_address(private_traffic_selector_t *this)
|
static chunk_t get_from_address(private_traffic_selector_t *this)
|
||||||
{
|
{
|
||||||
chunk_t from = chunk_empty;
|
|
||||||
|
|
||||||
switch (this->type)
|
switch (this->type)
|
||||||
{
|
{
|
||||||
case TS_IPV4_ADDR_RANGE:
|
case TS_IPV4_ADDR_RANGE:
|
||||||
{
|
return chunk_create(this->from, sizeof(this->from4));
|
||||||
from.len = sizeof(this->from4);
|
|
||||||
from.ptr = malloc(from.len);
|
|
||||||
memcpy(from.ptr, this->from4, from.len);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case TS_IPV6_ADDR_RANGE:
|
case TS_IPV6_ADDR_RANGE:
|
||||||
{
|
return chunk_create(this->from, sizeof(this->from6));
|
||||||
from.len = sizeof(this->from6);
|
default:
|
||||||
from.ptr = malloc(from.len);
|
return chunk_empty;
|
||||||
memcpy(from.ptr, this->from6, from.len);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return from;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -433,26 +422,15 @@ static chunk_t get_from_address(private_traffic_selector_t *this)
|
|||||||
*/
|
*/
|
||||||
static chunk_t get_to_address(private_traffic_selector_t *this)
|
static chunk_t get_to_address(private_traffic_selector_t *this)
|
||||||
{
|
{
|
||||||
chunk_t to = chunk_empty;
|
|
||||||
|
|
||||||
switch (this->type)
|
switch (this->type)
|
||||||
{
|
{
|
||||||
case TS_IPV4_ADDR_RANGE:
|
case TS_IPV4_ADDR_RANGE:
|
||||||
{
|
return chunk_create(this->to, sizeof(this->to4));
|
||||||
to.len = sizeof(this->to4);
|
|
||||||
to.ptr = malloc(to.len);
|
|
||||||
memcpy(to.ptr, this->to4, to.len);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case TS_IPV6_ADDR_RANGE:
|
case TS_IPV6_ADDR_RANGE:
|
||||||
{
|
return chunk_create(this->to, sizeof(this->to6));
|
||||||
to.len = sizeof(this->to6);
|
default:
|
||||||
to.ptr = malloc(to.len);
|
return chunk_empty;
|
||||||
memcpy(to.ptr, this->to6, to.len);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return to;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -525,6 +503,14 @@ static bool is_host(private_traffic_selector_t *this, host_t *host)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of traffic_selector_t.is_dynamic
|
||||||
|
*/
|
||||||
|
static bool is_dynamic(private_traffic_selector_t *this)
|
||||||
|
{
|
||||||
|
return this->dynamic;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements traffic_selector_t.set_address.
|
* Implements traffic_selector_t.set_address.
|
||||||
*/
|
*/
|
||||||
@@ -869,6 +855,7 @@ static private_traffic_selector_t *traffic_selector_create(u_int8_t protocol,
|
|||||||
this->public.get_type = (ts_type_t(*)(traffic_selector_t*))get_type;
|
this->public.get_type = (ts_type_t(*)(traffic_selector_t*))get_type;
|
||||||
this->public.get_protocol = (u_int8_t(*)(traffic_selector_t*))get_protocol;
|
this->public.get_protocol = (u_int8_t(*)(traffic_selector_t*))get_protocol;
|
||||||
this->public.is_host = (bool(*)(traffic_selector_t*,host_t*))is_host;
|
this->public.is_host = (bool(*)(traffic_selector_t*,host_t*))is_host;
|
||||||
|
this->public.is_dynamic = (bool(*)(traffic_selector_t*))is_dynamic;
|
||||||
this->public.is_contained_in = (bool(*)(traffic_selector_t*,traffic_selector_t*))is_contained_in;
|
this->public.is_contained_in = (bool(*)(traffic_selector_t*,traffic_selector_t*))is_contained_in;
|
||||||
this->public.includes = (bool(*)(traffic_selector_t*,host_t*))includes;
|
this->public.includes = (bool(*)(traffic_selector_t*,host_t*))includes;
|
||||||
this->public.set_address = (void(*)(traffic_selector_t*,host_t*))set_address;
|
this->public.set_address = (void(*)(traffic_selector_t*,host_t*))set_address;
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ struct traffic_selector_t {
|
|||||||
/**
|
/**
|
||||||
* Get starting address of this ts as a chunk.
|
* Get starting address of this ts as a chunk.
|
||||||
*
|
*
|
||||||
* Chunk is in network order gets allocated.
|
* Chunk is in network and points to internal data.
|
||||||
*
|
*
|
||||||
* @return chunk containing the address
|
* @return chunk containing the address
|
||||||
*/
|
*/
|
||||||
@@ -101,7 +101,7 @@ struct traffic_selector_t {
|
|||||||
/**
|
/**
|
||||||
* Get ending address of this ts as a chunk.
|
* Get ending address of this ts as a chunk.
|
||||||
*
|
*
|
||||||
* Chunk is in network order gets allocated.
|
* Chunk is in network and points to internal data.
|
||||||
*
|
*
|
||||||
* @return chunk containing the address
|
* @return chunk containing the address
|
||||||
*/
|
*/
|
||||||
@@ -154,6 +154,13 @@ struct traffic_selector_t {
|
|||||||
*/
|
*/
|
||||||
bool (*is_host) (traffic_selector_t *this, host_t* host);
|
bool (*is_host) (traffic_selector_t *this, host_t* host);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a traffic selector has been created by create_dynamic().
|
||||||
|
*
|
||||||
|
* @return TRUE if TS is dynamic
|
||||||
|
*/
|
||||||
|
bool (*is_dynamic)(traffic_selector_t *this);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the address of a traffic selector.
|
* Update the address of a traffic selector.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -269,8 +269,8 @@ traffic_selector_substructure_t *traffic_selector_substructure_create_from_traff
|
|||||||
this->ip_protocol_id = traffic_selector->get_protocol(traffic_selector);
|
this->ip_protocol_id = traffic_selector->get_protocol(traffic_selector);
|
||||||
this->start_port = traffic_selector->get_from_port(traffic_selector);
|
this->start_port = traffic_selector->get_from_port(traffic_selector);
|
||||||
this->end_port = traffic_selector->get_to_port(traffic_selector);
|
this->end_port = traffic_selector->get_to_port(traffic_selector);
|
||||||
this->starting_address = traffic_selector->get_from_address(traffic_selector);
|
this->starting_address = chunk_clone(traffic_selector->get_from_address(traffic_selector));
|
||||||
this->ending_address = traffic_selector->get_to_address(traffic_selector);
|
this->ending_address = chunk_clone(traffic_selector->get_to_address(traffic_selector));
|
||||||
|
|
||||||
compute_length(this);
|
compute_length(this);
|
||||||
|
|
||||||
|
|||||||
@@ -35,14 +35,6 @@ database_t *db;
|
|||||||
*/
|
*/
|
||||||
host_t *start = NULL, *end = NULL;
|
host_t *start = NULL, *end = NULL;
|
||||||
|
|
||||||
/**
|
|
||||||
* create a host from a blob
|
|
||||||
*/
|
|
||||||
static host_t *host_create_from_blob(chunk_t blob)
|
|
||||||
{
|
|
||||||
return host_create_from_chunk(blob.len == 4 ? AF_INET : AF_INET6, blob, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* calculate the size of a pool using start and end address chunk
|
* calculate the size of a pool using start and end address chunk
|
||||||
*/
|
*/
|
||||||
@@ -132,8 +124,8 @@ static void status(void)
|
|||||||
found = TRUE;
|
found = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
start = host_create_from_blob(start_chunk);
|
start = host_create_from_chunk(AF_UNSPEC, start_chunk, 0);
|
||||||
end = host_create_from_blob(end_chunk);
|
end = host_create_from_chunk(AF_UNSPEC, end_chunk, 0);
|
||||||
size = get_pool_size(start_chunk, end_chunk);
|
size = get_pool_size(start_chunk, end_chunk);
|
||||||
printf("%8s %15H %15H ", name, start, end);
|
printf("%8s %15H %15H ", name, start, end);
|
||||||
if (timeout)
|
if (timeout)
|
||||||
@@ -541,7 +533,7 @@ static void leases(char *filter, bool utc)
|
|||||||
printf("%-8s %-15s %-7s %-*s %-*s %s\n",
|
printf("%-8s %-15s %-7s %-*s %-*s %s\n",
|
||||||
"name", "address", "status", len, "start", len, "end", "identity");
|
"name", "address", "status", len, "start", len, "end", "identity");
|
||||||
}
|
}
|
||||||
address = host_create_from_blob(address_chunk);
|
address = host_create_from_chunk(AF_UNSPEC, address_chunk, 0);
|
||||||
identity = identification_create_from_encoding(identity_type, identity_chunk);
|
identity = identification_create_from_encoding(identity_type, identity_chunk);
|
||||||
|
|
||||||
printf("%-8s %-15H ", name, address);
|
printf("%-8s %-15H ", name, address);
|
||||||
|
|||||||
@@ -44,22 +44,6 @@ struct private_sql_attribute_t {
|
|||||||
bool history;
|
bool history;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* read a host_t address from the addresses table
|
|
||||||
*/
|
|
||||||
static host_t *host_from_chunk(chunk_t chunk)
|
|
||||||
{
|
|
||||||
switch (chunk.len)
|
|
||||||
{
|
|
||||||
case 4:
|
|
||||||
return host_create_from_chunk(AF_INET, chunk, 0);
|
|
||||||
case 16:
|
|
||||||
return host_create_from_chunk(AF_INET6, chunk, 0);
|
|
||||||
default:
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* lookup/insert an identity
|
* lookup/insert an identity
|
||||||
*/
|
*/
|
||||||
@@ -145,7 +129,7 @@ static host_t *get_address(private_sql_attribute_t *this, char *name,
|
|||||||
"WHERE id = ? AND identity = ? AND released != 0",
|
"WHERE id = ? AND identity = ? AND released != 0",
|
||||||
DB_UINT, now, DB_UINT, id, DB_UINT, identity) > 0)
|
DB_UINT, now, DB_UINT, id, DB_UINT, identity) > 0)
|
||||||
{
|
{
|
||||||
host = host_from_chunk(address);
|
host = host_create_from_chunk(AF_UNSPEC, address, 0);
|
||||||
if (host)
|
if (host)
|
||||||
{
|
{
|
||||||
DBG1(DBG_CFG, "acquired existing lease "
|
DBG1(DBG_CFG, "acquired existing lease "
|
||||||
@@ -177,7 +161,7 @@ static host_t *get_address(private_sql_attribute_t *this, char *name,
|
|||||||
DB_UINT, now, DB_UINT, identity,
|
DB_UINT, now, DB_UINT, identity,
|
||||||
DB_UINT, id, DB_UINT, now - timeout) > 0)
|
DB_UINT, id, DB_UINT, now - timeout) > 0)
|
||||||
{
|
{
|
||||||
host = host_from_chunk(address);
|
host = host_create_from_chunk(AF_UNSPEC, address, 0);
|
||||||
if (host)
|
if (host)
|
||||||
{
|
{
|
||||||
DBG1(DBG_CFG, "acquired new lease "
|
DBG1(DBG_CFG, "acquired new lease "
|
||||||
|
|||||||
@@ -497,6 +497,7 @@ static status_t install(private_child_sa_t *this, proposal_t *proposal,
|
|||||||
|
|
||||||
soft = this->config->get_lifetime(this->config, TRUE);
|
soft = this->config->get_lifetime(this->config, TRUE);
|
||||||
hard = this->config->get_lifetime(this->config, FALSE);
|
hard = this->config->get_lifetime(this->config, FALSE);
|
||||||
|
|
||||||
status = charon->kernel_interface->add_sa(charon->kernel_interface,
|
status = charon->kernel_interface->add_sa(charon->kernel_interface,
|
||||||
src, dst, spi, this->protocol, this->reqid,
|
src, dst, spi, this->protocol, this->reqid,
|
||||||
in ? soft : 0, hard, enc_alg, encr, int_alg, integ,
|
in ? soft : 0, hard, enc_alg, encr, int_alg, integ,
|
||||||
@@ -617,7 +618,6 @@ static status_t add_policies(private_child_sa_t *this,
|
|||||||
this->other_addr, this->my_addr, other_ts, my_ts, POLICY_IN,
|
this->other_addr, this->my_addr, other_ts, my_ts, POLICY_IN,
|
||||||
this->my_spi, this->protocol, this->reqid, mode, this->ipcomp,
|
this->my_spi, this->protocol, this->reqid, mode, this->ipcomp,
|
||||||
this->my_cpi, routed);
|
this->my_cpi, routed);
|
||||||
|
|
||||||
if (mode == MODE_TUNNEL)
|
if (mode == MODE_TUNNEL)
|
||||||
{
|
{
|
||||||
status |= charon->kernel_interface->add_policy(charon->kernel_interface,
|
status |= charon->kernel_interface->add_policy(charon->kernel_interface,
|
||||||
@@ -681,7 +681,6 @@ static status_t update_hosts(private_child_sa_t *this,
|
|||||||
{
|
{
|
||||||
return NOT_SUPPORTED;
|
return NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* update his (responder) SA */
|
/* update his (responder) SA */
|
||||||
if (charon->kernel_interface->update_sa(charon->kernel_interface, this->other_spi,
|
if (charon->kernel_interface->update_sa(charon->kernel_interface, this->other_spi,
|
||||||
this->protocol, this->ipcomp != IPCOMP_NONE ? this->other_cpi : 0,
|
this->protocol, this->ipcomp != IPCOMP_NONE ? this->other_cpi : 0,
|
||||||
@@ -981,4 +980,3 @@ child_sa_t * child_sa_create(host_t *me, host_t* other,
|
|||||||
|
|
||||||
return &this->public;
|
return &this->public;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -504,38 +504,56 @@ host_t *host_create_from_dns(char *string, int af, u_int16_t port)
|
|||||||
*/
|
*/
|
||||||
host_t *host_create_from_chunk(int family, chunk_t address, u_int16_t port)
|
host_t *host_create_from_chunk(int family, chunk_t address, u_int16_t port)
|
||||||
{
|
{
|
||||||
private_host_t *this = host_create_empty();
|
private_host_t *this;
|
||||||
|
|
||||||
|
switch (family)
|
||||||
|
{
|
||||||
|
case AF_INET:
|
||||||
|
if (address.len < IPV4_LEN)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
address.len = IPV4_LEN;
|
||||||
|
break;
|
||||||
|
case AF_INET6:
|
||||||
|
if (address.len < IPV6_LEN)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
address.len = IPV6_LEN;
|
||||||
|
break;
|
||||||
|
case AF_UNSPEC:
|
||||||
|
switch (address.len)
|
||||||
|
{
|
||||||
|
case IPV4_LEN:
|
||||||
|
family = AF_INET;
|
||||||
|
break;
|
||||||
|
case IPV6_LEN:
|
||||||
|
family = AF_INET6;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
this = host_create_empty();
|
||||||
this->address.sa_family = family;
|
this->address.sa_family = family;
|
||||||
switch (family)
|
switch (family)
|
||||||
{
|
{
|
||||||
case AF_INET:
|
case AF_INET:
|
||||||
{
|
memcpy(&this->address4.sin_addr.s_addr, address.ptr, address.len);
|
||||||
if (address.len != IPV4_LEN)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
memcpy(&(this->address4.sin_addr.s_addr), address.ptr, IPV4_LEN);
|
|
||||||
this->address4.sin_port = htons(port);
|
this->address4.sin_port = htons(port);
|
||||||
this->socklen = sizeof(struct sockaddr_in);
|
this->socklen = sizeof(struct sockaddr_in);
|
||||||
return &(this->public);
|
break;
|
||||||
}
|
|
||||||
case AF_INET6:
|
case AF_INET6:
|
||||||
{
|
memcpy(&this->address6.sin6_addr.s6_addr, address.ptr, address.len);
|
||||||
if (address.len != IPV6_LEN)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
memcpy(&(this->address6.sin6_addr.s6_addr), address.ptr, IPV6_LEN);
|
|
||||||
this->address6.sin6_port = htons(port);
|
this->address6.sin6_port = htons(port);
|
||||||
this->socklen = sizeof(struct sockaddr_in6);
|
this->socklen = sizeof(struct sockaddr_in6);
|
||||||
return &this->public;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
free(this);
|
return &this->public;
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -170,7 +170,9 @@ host_t *host_create_from_string(char *string, u_int16_t port);
|
|||||||
host_t *host_create_from_dns(char *string, int family, u_int16_t port);
|
host_t *host_create_from_dns(char *string, int family, u_int16_t port);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor to create a host_t object from an address chunk
|
* Constructor to create a host_t object from an address chunk.
|
||||||
|
*
|
||||||
|
* If family is AF_UNSPEC, it is guessed using address.len.
|
||||||
*
|
*
|
||||||
* @param family Address family, such as AF_INET or AF_INET6
|
* @param family Address family, such as AF_INET or AF_INET6
|
||||||
* @param address address as chunk_t in network order
|
* @param address address as chunk_t in network order
|
||||||
|
|||||||
Reference in New Issue
Block a user