traffic-selector: Allow calling set_address() for any traffic selector
Users may check is_host(), is_dynamic() or includes() before calling this if restrictions are required (most actually already do).
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2013 Tobias Brunner
|
||||
* Copyright (C) 2007-2017 Tobias Brunner
|
||||
* Copyright (C) 2005-2007 Martin Willi
|
||||
* Copyright (C) 2005 Jan Hutter
|
||||
* Hochschule fuer Technik Rapperswil
|
||||
@@ -550,10 +550,8 @@ METHOD(traffic_selector_t, is_dynamic, bool,
|
||||
METHOD(traffic_selector_t, set_address, void,
|
||||
private_traffic_selector_t *this, host_t *host)
|
||||
{
|
||||
if (is_host(this, NULL))
|
||||
{
|
||||
this->type = host->get_family(host) == AF_INET ?
|
||||
TS_IPV4_ADDR_RANGE : TS_IPV6_ADDR_RANGE;
|
||||
this->type = host->get_family(host) == AF_INET ? TS_IPV4_ADDR_RANGE
|
||||
: TS_IPV6_ADDR_RANGE;
|
||||
|
||||
if (host->is_anyaddr(host))
|
||||
{
|
||||
@@ -570,7 +568,6 @@ METHOD(traffic_selector_t, set_address, void,
|
||||
}
|
||||
this->dynamic = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
METHOD(traffic_selector_t, is_contained_in, bool,
|
||||
private_traffic_selector_t *this, traffic_selector_t *other)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2007-2013 Tobias Brunner
|
||||
* Copyright (C) 2007-2017 Tobias Brunner
|
||||
* Copyright (C) 2005-2006 Martin Willi
|
||||
* Copyright (C) 2005 Jan Hutter
|
||||
* Hochschule fuer Technik Rapperswil
|
||||
@@ -158,27 +158,37 @@ struct traffic_selector_t {
|
||||
* Traffic selector may describe the end of *-to-host tunnel. In this
|
||||
* case, the address range is a single address equal to the hosts
|
||||
* peer address.
|
||||
* If host is NULL, the traffic selector is checked if it is a single host,
|
||||
* but not a specific one.
|
||||
*
|
||||
* @param host host_t specifying the address range
|
||||
* If host is specified, the traffic selector must equal that specific
|
||||
* IP address. If it is not specified, TRUE is also returned for dynamic
|
||||
* traffic selectors.
|
||||
*
|
||||
* @param host IP address to check for, or NULL
|
||||
* @return TRUE if TS is for a single host
|
||||
*/
|
||||
bool (*is_host)(traffic_selector_t *this, host_t* host);
|
||||
|
||||
/**
|
||||
* Check if a traffic selector has been created by create_dynamic().
|
||||
* Check if this traffic selector was created by
|
||||
* traffic_selector_create_dynamic() but no address has yet been set with
|
||||
* set_address().
|
||||
*
|
||||
* @return TRUE if TS is dynamic
|
||||
*/
|
||||
bool (*is_dynamic)(traffic_selector_t *this);
|
||||
|
||||
/**
|
||||
* Update the address of a traffic selector.
|
||||
* Set the traffic selector to the given IP address.
|
||||
*
|
||||
* Update the address range of a traffic selector, if it is
|
||||
* constructed with the traffic_selector_create_dynamic().
|
||||
* If host is %any or %any6 the traffic selector gets set to 0.0.0.0/0 or
|
||||
* ::/0, respectively.
|
||||
*
|
||||
* @param host host_t specifying the address
|
||||
* Checking is_host(), is_dynamic() or includes() might be appropriate
|
||||
* before calling this.
|
||||
*
|
||||
* is_dynamic() will return FALSE after calling this.
|
||||
*
|
||||
* @param host target IP address
|
||||
*/
|
||||
void (*set_address)(traffic_selector_t *this, host_t* host);
|
||||
|
||||
@@ -191,12 +201,12 @@ struct traffic_selector_t {
|
||||
bool (*equals)(traffic_selector_t *this, traffic_selector_t *other);
|
||||
|
||||
/**
|
||||
* Check if a traffic selector is contained completly in another.
|
||||
* Check if a traffic selector is contained completely in another.
|
||||
*
|
||||
* contains() allows to check if multiple traffic selectors are redundant.
|
||||
*
|
||||
* @param other ts that contains this
|
||||
* @return TRUE if other contains this completly, FALSE otherwise
|
||||
* @return TRUE if other contains this completely, FALSE otherwise
|
||||
*/
|
||||
bool (*is_contained_in)(traffic_selector_t *this, traffic_selector_t *other);
|
||||
|
||||
|
||||
@@ -511,16 +511,24 @@ struct {
|
||||
char *host;
|
||||
char *after;
|
||||
} set_address_tests[] = {
|
||||
{ "0.0.0.0/0", "192.168.1.2", "0.0.0.0/0" },
|
||||
{ "::/0", "fec2::1", "::/0" },
|
||||
{ "0.0.0.0/0", "192.168.1.2", "192.168.1.2/32" },
|
||||
{ "::/0", "fec2::1", "fec2::1/128" },
|
||||
{ "192.168.1.2/32", "192.168.1.1", "192.168.1.1/32" },
|
||||
{ "192.168.1.0/24", "192.168.1.1", "192.168.1.1/32" },
|
||||
{ "192.168.1.2/32", "fec2::1", "fec2::1/128" },
|
||||
{ "192.168.1.0/24", "fec2::1", "fec2::1/128" },
|
||||
{ "192.168.1.2/32", "%any", "0.0.0.0/0" },
|
||||
{ "192.168.1.0/24", "%any", "0.0.0.0/0" },
|
||||
{ "192.168.1.2/32", "%any6", "::/0" },
|
||||
{ "192.168.1.0/24", "%any6", "::/0" },
|
||||
{ "fec2::1/128", "192.168.1.1", "192.168.1.1/32" },
|
||||
{ "fec2::/64", "192.168.1.1", "192.168.1.1/32" },
|
||||
{ "fec2::1/128", "fec2::2", "fec2::2/128" },
|
||||
{ "fec2::/64", "fec2::2", "fec2::2/128" },
|
||||
{ "fec2::1/128", "%any", "0.0.0.0/0" },
|
||||
{ "fec2::/64", "%any", "0.0.0.0/0" },
|
||||
{ "fec2::1/128", "%any6", "::/0" },
|
||||
{ "fec2::/64", "%any6", "::/0" },
|
||||
{ NULL, "192.168.1.1", "192.168.1.1/32" },
|
||||
{ NULL, "fec2::1", "fec2::1/128" },
|
||||
{ NULL, "%any", "0.0.0.0/0" },
|
||||
|
||||
Reference in New Issue
Block a user