initial support for IPv6 (more testing needed)
socket works (without v6 filter)
traffic selector handle IPv4/v4 cleanly
improvements in traffic selector code
kernel interface accepts v6 traffic selectors and hosts
host_t class has full IPv6 support
This commit is contained in:
@@ -889,42 +889,37 @@ static void ts2subnet(traffic_selector_t* ts,
|
||||
/* there is no way to do this cleanly, as the address range may
|
||||
* be anything else but a subnet. We use from_addr as subnet
|
||||
* and try to calculate a usable subnet mask.
|
||||
*/
|
||||
chunk_t chunk;
|
||||
*/
|
||||
int byte, bit;
|
||||
bool found = FALSE;
|
||||
chunk_t from, to;
|
||||
size_t size = (ts->get_type(ts) == TS_IPV4_ADDR_RANGE) ? 4 : 16;
|
||||
|
||||
chunk = ts->get_from_address(ts);
|
||||
memcpy(net, chunk.ptr, chunk.len);
|
||||
from = ts->get_from_address(ts);
|
||||
to = ts->get_to_address(ts);
|
||||
|
||||
switch (ts->get_type(ts))
|
||||
*mask = (size * 8);
|
||||
/* go trough all bits of the addresses, beginning in the front.
|
||||
* As longer as they equal, the subnet gets larger */
|
||||
for (byte = 0; byte < size; byte++)
|
||||
{
|
||||
case TS_IPV4_ADDR_RANGE:
|
||||
for (bit = 7; bit >= 0; bit--)
|
||||
{
|
||||
u_int32_t from, to, bit;
|
||||
|
||||
from = *(u_int32_t*)chunk.ptr;
|
||||
chunk_free(&chunk);
|
||||
chunk = ts->get_to_address(ts);
|
||||
to = *(u_int32_t*)chunk.ptr;
|
||||
chunk_free(&chunk);
|
||||
for (bit = 0; bit < 32; bit++)
|
||||
if ((1<<bit & from.ptr[byte]) != (1<<bit & to.ptr[byte]))
|
||||
{
|
||||
if ((1<<bit & from) != (1<<bit & to))
|
||||
{
|
||||
*mask = bit;
|
||||
return;
|
||||
}
|
||||
*mask = ((7 - bit) + (byte * 8));
|
||||
found = TRUE;
|
||||
break;
|
||||
}
|
||||
*mask = 32;
|
||||
return;
|
||||
}
|
||||
case TS_IPV6_ADDR_RANGE:
|
||||
default:
|
||||
if (found)
|
||||
{
|
||||
/* TODO: IPV6 support */
|
||||
*mask = 0;
|
||||
return;
|
||||
break;
|
||||
}
|
||||
}
|
||||
memcpy(net, from.ptr, from.len);
|
||||
chunk_free(&from);
|
||||
chunk_free(&to);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1075,6 +1070,7 @@ static status_t add_policy(private_kernel_interface_t *this,
|
||||
tmpl->id.proto = (protocol == PROTO_AH) ? KERNEL_AH : KERNEL_ESP;
|
||||
tmpl->aalgos = tmpl->ealgos = tmpl->calgos = ~0;
|
||||
tmpl->mode = TRUE;
|
||||
tmpl->family = src->get_family(src);
|
||||
|
||||
host2xfrm(src, &tmpl->saddr);
|
||||
host2xfrm(dst, &tmpl->id.daddr);
|
||||
|
||||
@@ -76,8 +76,7 @@ static void send_packets(private_sender_t * this)
|
||||
status = charon->socket->send(charon->socket, current_packet);
|
||||
if (status != SUCCESS)
|
||||
{
|
||||
this->logger->log(this->logger, ERROR, "Sending failed, socket returned %s",
|
||||
mapping_find(status_m, status));
|
||||
this->logger->log(this->logger, ERROR, "Sending packet failed");
|
||||
}
|
||||
current_packet->destroy(current_packet);
|
||||
}
|
||||
|
||||
@@ -186,21 +186,38 @@ static void stroke_add_conn(private_stroke_t *this, stroke_msg_t *msg)
|
||||
pop_string(msg, &msg->add_conn.algorithms.ike);
|
||||
pop_string(msg, &msg->add_conn.algorithms.esp);
|
||||
|
||||
this->logger->log(this->logger, CONTROL, "received stroke: add connection \"%s\"", msg->add_conn.name);
|
||||
|
||||
this->logger->log(this->logger, CONTROL,
|
||||
"received stroke: add connection \"%s\"", msg->add_conn.name);
|
||||
|
||||
this->logger->log(this->logger, CONTROL|LEVEL2, "conn %s", msg->add_conn.name);
|
||||
this->logger->log(this->logger, CONTROL|LEVEL2, " right=%s", msg->add_conn.me.address);
|
||||
this->logger->log(this->logger, CONTROL|LEVEL2, " left=%s", msg->add_conn.other.address);
|
||||
this->logger->log(this->logger, CONTROL|LEVEL2, " rightsubnet=%s", msg->add_conn.me.subnet);
|
||||
this->logger->log(this->logger, CONTROL|LEVEL2, " leftsubnet=%s", msg->add_conn.other.subnet);
|
||||
this->logger->log(this->logger, CONTROL|LEVEL2, " rightid=%s", msg->add_conn.me.id);
|
||||
this->logger->log(this->logger, CONTROL|LEVEL2, " leftid=%s", msg->add_conn.other.id);
|
||||
this->logger->log(this->logger, CONTROL|LEVEL2, " rightcert=%s", msg->add_conn.me.cert);
|
||||
this->logger->log(this->logger, CONTROL|LEVEL2, " leftcert=%s", msg->add_conn.other.cert);
|
||||
this->logger->log(this->logger, CONTROL|LEVEL2, " rightca=%s", msg->add_conn.me.ca);
|
||||
this->logger->log(this->logger, CONTROL|LEVEL2, " leftca=%s", msg->add_conn.other.ca);
|
||||
this->logger->log(this->logger, CONTROL|LEVEL2, " ike=%s", msg->add_conn.algorithms.ike);
|
||||
this->logger->log(this->logger, CONTROL|LEVEL2, " esp=%s", msg->add_conn.algorithms.esp);
|
||||
|
||||
my_host = msg->add_conn.me.address?
|
||||
host_create(AF_INET, msg->add_conn.me.address, IKE_PORT) : NULL;
|
||||
host_create_from_string(msg->add_conn.me.address, IKE_PORT) : NULL;
|
||||
if (my_host == NULL)
|
||||
{
|
||||
this->stroke_logger->log(this->stroke_logger, ERROR, "invalid host: %s", msg->add_conn.me.address);
|
||||
this->stroke_logger->log(this->stroke_logger, ERROR,
|
||||
"invalid host: %s", msg->add_conn.me.address);
|
||||
return;
|
||||
}
|
||||
|
||||
other_host = msg->add_conn.other.address ?
|
||||
host_create(AF_INET, msg->add_conn.other.address, IKE_PORT) : NULL;
|
||||
host_create_from_string(msg->add_conn.other.address, IKE_PORT) : NULL;
|
||||
if (other_host == NULL)
|
||||
{
|
||||
this->stroke_logger->log(this->stroke_logger, ERROR, "invalid host: %s", msg->add_conn.other.address);
|
||||
this->stroke_logger->log(this->stroke_logger, ERROR,
|
||||
"invalid host: %s", msg->add_conn.other.address);
|
||||
my_host->destroy(my_host);
|
||||
return;
|
||||
}
|
||||
@@ -210,7 +227,8 @@ static void stroke_add_conn(private_stroke_t *this, stroke_msg_t *msg)
|
||||
stroke_end_t tmp_end;
|
||||
host_t *tmp_host;
|
||||
|
||||
this->stroke_logger->log(this->stroke_logger, CONTROL|LEVEL1, "left is other host, swapping ends");
|
||||
this->stroke_logger->log(this->stroke_logger, CONTROL|LEVEL1,
|
||||
"left is other host, swapping ends");
|
||||
|
||||
tmp_host = my_host;
|
||||
my_host = other_host;
|
||||
@@ -222,40 +240,45 @@ static void stroke_add_conn(private_stroke_t *this, stroke_msg_t *msg)
|
||||
}
|
||||
else if (!charon->socket->is_local_address(charon->socket, my_host))
|
||||
{
|
||||
this->stroke_logger->log(this->stroke_logger, ERROR, "left nor right host is our side, aborting");
|
||||
this->stroke_logger->log(this->stroke_logger, ERROR,
|
||||
"left nor right host is our side, aborting");
|
||||
goto destroy_hosts;
|
||||
}
|
||||
|
||||
my_id = identification_create_from_string(msg->add_conn.me.id ?
|
||||
msg->add_conn.me.id : msg->add_conn.me.address);
|
||||
msg->add_conn.me.id : msg->add_conn.me.address);
|
||||
if (my_id == NULL)
|
||||
{
|
||||
this->stroke_logger->log(this->stroke_logger, ERROR, "invalid id: %s", msg->add_conn.me.id);
|
||||
this->stroke_logger->log(this->stroke_logger, ERROR,
|
||||
"invalid id: %s", msg->add_conn.me.id);
|
||||
goto destroy_hosts;
|
||||
}
|
||||
|
||||
other_id = identification_create_from_string(msg->add_conn.other.id ?
|
||||
msg->add_conn.other.id : msg->add_conn.other.address);
|
||||
msg->add_conn.other.id : msg->add_conn.other.address);
|
||||
if (other_id == NULL)
|
||||
{
|
||||
this->stroke_logger->log(this->stroke_logger, ERROR, "invalid id: %s", msg->add_conn.other.id);
|
||||
this->stroke_logger->log(this->stroke_logger, ERROR,
|
||||
"invalid id: %s", msg->add_conn.other.id);
|
||||
my_id->destroy(my_id);
|
||||
goto destroy_hosts;
|
||||
}
|
||||
|
||||
my_subnet = host_create(AF_INET, msg->add_conn.me.subnet ?
|
||||
msg->add_conn.me.subnet : msg->add_conn.me.address, IKE_PORT);
|
||||
my_subnet = host_create_from_string(msg->add_conn.me.subnet ?
|
||||
msg->add_conn.me.subnet : msg->add_conn.me.address, IKE_PORT);
|
||||
if (my_subnet == NULL)
|
||||
{
|
||||
this->stroke_logger->log(this->stroke_logger, ERROR, "invalid subnet: %s", msg->add_conn.me.subnet);
|
||||
this->stroke_logger->log(this->stroke_logger, ERROR,
|
||||
"invalid subnet: %s", msg->add_conn.me.subnet);
|
||||
goto destroy_ids;
|
||||
}
|
||||
|
||||
other_subnet = host_create(AF_INET, msg->add_conn.other.subnet ?
|
||||
msg->add_conn.other.subnet : msg->add_conn.other.address, IKE_PORT);
|
||||
other_subnet = host_create_from_string(msg->add_conn.other.subnet ?
|
||||
msg->add_conn.other.subnet : msg->add_conn.other.address, IKE_PORT);
|
||||
if (other_subnet == NULL)
|
||||
{
|
||||
this->stroke_logger->log(this->stroke_logger, ERROR, "invalid subnet: %s", msg->add_conn.me.subnet);
|
||||
this->stroke_logger->log(this->stroke_logger, ERROR,
|
||||
"invalid subnet: %s", msg->add_conn.me.subnet);
|
||||
my_subnet->destroy(my_subnet);
|
||||
goto destroy_ids;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user