changed [4856] to dynamically choose traffic selector family

This commit is contained in:
Martin Willi
2009-02-11 13:09:52 +00:00
parent 8837080353
commit b81d8cd3cc
10 changed files with 29 additions and 34 deletions
+1 -1
View File
@@ -301,7 +301,7 @@ static linked_list_t* get_traffic_selectors(private_child_cfg_t *this, bool loca
else else
{ {
DBG2(DBG_CFG, " config: %R, received: %R => no match", DBG2(DBG_CFG, " config: %R, received: %R => no match",
ts1, ts2); ts1, ts2, selected);
} }
} }
e2->destroy(e2); e2->destroy(e2);
+13 -7
View File
@@ -196,8 +196,7 @@ static int print(FILE *stream, const struct printf_info *info,
memeq(this->from, from, this->type == TS_IPV4_ADDR_RANGE ? 4 : 16) && memeq(this->from, from, this->type == TS_IPV4_ADDR_RANGE ? 4 : 16) &&
memeq(this->to, to, this->type == TS_IPV4_ADDR_RANGE ? 4 : 16)) memeq(this->to, to, this->type == TS_IPV4_ADDR_RANGE ? 4 : 16))
{ {
written += fprintf(stream, "dynamic/%d", written += fprintf(stream, "dynamic");
this->type == TS_IPV4_ADDR_RANGE ? 32 : 128);
} }
else else
{ {
@@ -521,9 +520,17 @@ static void set_address(private_traffic_selector_t *this, host_t *host)
this->type = host->get_family(host) == AF_INET ? this->type = host->get_family(host) == AF_INET ?
TS_IPV4_ADDR_RANGE : TS_IPV6_ADDR_RANGE; TS_IPV4_ADDR_RANGE : TS_IPV6_ADDR_RANGE;
chunk_t from = host->get_address(host); if (host->is_anyaddr(host))
memcpy(this->from, from.ptr, from.len); {
memcpy(this->to, from.ptr, from.len); memset(this->from6, 0x00, sizeof(this->from6));
memset(this->to6, 0xFF, sizeof(this->to6));
}
else
{
chunk_t from = host->get_address(host);
memcpy(this->from, from.ptr, from.len);
memcpy(this->to, from.ptr, from.len);
}
} }
} }
@@ -824,11 +831,10 @@ traffic_selector_t *traffic_selector_create_from_string(
* see header * see header
*/ */
traffic_selector_t *traffic_selector_create_dynamic(u_int8_t protocol, traffic_selector_t *traffic_selector_create_dynamic(u_int8_t protocol,
ts_type_t type,
u_int16_t from_port, u_int16_t to_port) u_int16_t from_port, u_int16_t to_port)
{ {
private_traffic_selector_t *this = traffic_selector_create( private_traffic_selector_t *this = traffic_selector_create(
protocol, type, from_port, to_port); protocol, TS_IPV4_ADDR_RANGE, from_port, to_port);
memset(this->from6, 0, sizeof(this->from6)); memset(this->from6, 0, sizeof(this->from6));
memset(this->to6, 0xFF, sizeof(this->to6)); memset(this->to6, 0xFF, sizeof(this->to6));
-2
View File
@@ -281,7 +281,6 @@ traffic_selector_t *traffic_selector_create_from_subnet(
* *
* *
* @param protocol upper layer protocl to allow * @param protocol upper layer protocl to allow
* @param type type of following addresses, such as TS_IPV4_ADDR_RANGE
* @param from_port start of allowed port range * @param from_port start of allowed port range
* @param to_port end of range * @param to_port end of range
* @return * @return
@@ -289,7 +288,6 @@ traffic_selector_t *traffic_selector_create_from_subnet(
* - NULL if type not supported * - NULL if type not supported
*/ */
traffic_selector_t *traffic_selector_create_dynamic(u_int8_t protocol, traffic_selector_t *traffic_selector_create_dynamic(u_int8_t protocol,
ts_type_t type,
u_int16_t from_port, u_int16_t to_port); u_int16_t from_port, u_int16_t to_port);
/** /**
@@ -109,9 +109,9 @@ static peer_cfg_t* generate_config(private_load_tester_config_t *this, uint num)
MODE_TUNNEL, ACTION_NONE, ACTION_NONE, FALSE); MODE_TUNNEL, ACTION_NONE, ACTION_NONE, FALSE);
proposal = proposal_create_from_string(PROTO_ESP, "aes128-sha1"); proposal = proposal_create_from_string(PROTO_ESP, "aes128-sha1");
child_cfg->add_proposal(child_cfg, proposal); child_cfg->add_proposal(child_cfg, proposal);
ts = traffic_selector_create_dynamic(0, TS_IPV4_ADDR_RANGE, 0, 65535); ts = traffic_selector_create_dynamic(0, 0, 65535);
child_cfg->add_traffic_selector(child_cfg, TRUE, ts); child_cfg->add_traffic_selector(child_cfg, TRUE, ts);
ts = traffic_selector_create_dynamic(0, TS_IPV4_ADDR_RANGE, 0, 65535); ts = traffic_selector_create_dynamic(0, 0, 65535);
child_cfg->add_traffic_selector(child_cfg, FALSE, ts); child_cfg->add_traffic_selector(child_cfg, FALSE, ts);
peer_cfg->add_child_cfg(peer_cfg, child_cfg); peer_cfg->add_child_cfg(peer_cfg, child_cfg);
return peer_cfg; return peer_cfg;
+1 -1
View File
@@ -87,7 +87,7 @@ static traffic_selector_t *ts_from_string(char *str)
return traffic_selector_create_from_subnet(net, netbits, 0, 0); return traffic_selector_create_from_subnet(net, netbits, 0, 0);
} }
} }
return traffic_selector_create_dynamic(0, TS_IPV4_ADDR_RANGE, 0, 65535); return traffic_selector_create_dynamic(0, 0, 65535);
} }
/** /**
+1 -1
View File
@@ -319,7 +319,7 @@ static gboolean connect_(NMVPNPlugin *plugin, NMConnection *connection,
NULL, TRUE, MODE_TUNNEL, /* updown, hostaccess */ NULL, TRUE, MODE_TUNNEL, /* updown, hostaccess */
ACTION_NONE, ACTION_RESTART, ipcomp); ACTION_NONE, ACTION_RESTART, ipcomp);
child_cfg->add_proposal(child_cfg, proposal_create_default(PROTO_ESP)); child_cfg->add_proposal(child_cfg, proposal_create_default(PROTO_ESP));
ts = traffic_selector_create_dynamic(0, TS_IPV4_ADDR_RANGE, 0, 65535); ts = traffic_selector_create_dynamic(0, 0, 65535);
child_cfg->add_traffic_selector(child_cfg, TRUE, ts); child_cfg->add_traffic_selector(child_cfg, TRUE, ts);
ts = traffic_selector_create_from_string(0, TS_IPV4_ADDR_RANGE, ts = traffic_selector_create_from_string(0, TS_IPV4_ADDR_RANGE,
"0.0.0.0", 0, "0.0.0.0", 0,
+1 -1
View File
@@ -78,7 +78,7 @@ static traffic_selector_t *build_traffic_selector(private_sql_config_t *this,
*local = TRUE; *local = TRUE;
/* FALL */ /* FALL */
case TS_REMOTE_DYNAMIC: case TS_REMOTE_DYNAMIC:
ts = traffic_selector_create_dynamic(protocol, type, ts = traffic_selector_create_dynamic(protocol,
start_port, end_port); start_port, end_port);
break; break;
default: default:
@@ -691,10 +691,7 @@ static void add_ts(private_stroke_config_t *this,
if (end->tohost) if (end->tohost)
{ {
bool is_ipv6 = strchr(end->address, ':') || streq(end->address, "%any6");
ts = traffic_selector_create_dynamic(end->protocol, ts = traffic_selector_create_dynamic(end->protocol,
is_ipv6? TS_IPV6_ADDR_RANGE:TS_IPV4_ADDR_RANGE,
end->port ? end->port : 0, end->port ? end->port : 65535); end->port ? end->port : 0, end->port ? end->port : 65535);
child_cfg->add_traffic_selector(child_cfg, local, ts); child_cfg->add_traffic_selector(child_cfg, local, ts);
} }
+1 -1
View File
@@ -131,7 +131,7 @@ static traffic_selector_t *create_ts(char *string)
return traffic_selector_create_from_subnet(net, netbits, 0, 0); return traffic_selector_create_from_subnet(net, netbits, 0, 0);
} }
} }
return traffic_selector_create_dynamic(0, TS_IPV4_ADDR_RANGE, 0, 65535); return traffic_selector_create_dynamic(0, 0, 65535);
} }
/** /**
+8 -14
View File
@@ -625,7 +625,6 @@ static void process_payloads(private_child_create_t *this, message_t *message)
static status_t build_i(private_child_create_t *this, message_t *message) static status_t build_i(private_child_create_t *this, message_t *message)
{ {
host_t *me, *other, *vip; host_t *me, *other, *vip;
bool propose_all = FALSE;
peer_cfg_t *peer_cfg; peer_cfg_t *peer_cfg;
switch (message->get_exchange_type(message)) switch (message->get_exchange_type(message))
@@ -678,23 +677,18 @@ static status_t build_i(private_child_create_t *this, message_t *message)
} }
/* check if we want a virtual IP, but don't have one */ /* check if we want a virtual IP, but don't have one */
if (!this->reqid) peer_cfg = this->ike_sa->get_peer_cfg(this->ike_sa);
vip = peer_cfg->get_virtual_ip(peer_cfg);
if (!this->reqid && vip)
{ {
peer_cfg = this->ike_sa->get_peer_cfg(this->ike_sa); /* propose a 0.0.0.0/0 or ::/0 subnet when we use virtual ip */
vip = peer_cfg->get_virtual_ip(peer_cfg); vip = host_create_any(vip->get_family(vip));
if (vip)
{
propose_all = TRUE;
}
}
if (propose_all)
{ /* propose a 0.0.0.0/0 subnet when we use virtual ip */
this->tsi = this->config->get_traffic_selectors(this->config, TRUE, this->tsi = this->config->get_traffic_selectors(this->config, TRUE,
NULL, NULL); NULL, vip);
vip->destroy(vip);
} }
else else
{ /* but shorten a 0.0.0.0/0 subnet for host2host/we already have a vip */ { /* but narrow it for host2host / if we already have a vip */
this->tsi = this->config->get_traffic_selectors(this->config, TRUE, this->tsi = this->config->get_traffic_selectors(this->config, TRUE,
NULL, me); NULL, me);
} }