Load arbitrary (non-host) attributes from strongswan.conf

This allows to e.g. load Cisco-specific attributes that contain FQDNs.
This commit is contained in:
Tobias Brunner
2013-03-19 15:21:30 +01:00
parent 824864f4e0
commit deafaf51f1
+16 -5
View File
@@ -185,6 +185,7 @@ static void load_entries(private_attr_provider_t *this)
configuration_attribute_type_t type; configuration_attribute_type_t type;
attribute_type_key_t *mapped = NULL; attribute_type_key_t *mapped = NULL;
attribute_entry_t *entry; attribute_entry_t *entry;
chunk_t data;
host_t *host; host_t *host;
char *pos; char *pos;
int i, mask = -1, family; int i, mask = -1, family;
@@ -217,16 +218,21 @@ static void load_entries(private_attr_provider_t *this)
} }
host = host_create_from_string(token, 0); host = host_create_from_string(token, 0);
if (!host) if (!host)
{
if (!type)
{ {
DBG1(DBG_CFG, "invalid host in key %s: %s", key, token); DBG1(DBG_CFG, "invalid host in key %s: %s", key, token);
continue; continue;
} }
/* store numeric attributes that are no IP addresses as strings */
data = chunk_clone(chunk_from_str(token));
}
else
{
family = host->get_family(host); family = host->get_family(host);
entry = malloc_thing(attribute_entry_t);
entry->type = type ?: (family == AF_INET ? mapped->v4 : mapped->v6);
if (mask == -1) if (mask == -1)
{ {
entry->value = chunk_clone(host->get_address(host)); data = chunk_clone(host->get_address(host));
} }
else else
{ {
@@ -236,16 +242,21 @@ static void load_entries(private_attr_provider_t *this)
mask = 32 - mask; mask = 32 - mask;
netmask = htonl((0xFFFFFFFF >> mask) << mask); netmask = htonl((0xFFFFFFFF >> mask) << mask);
entry->value = chunk_cat("cc", host->get_address(host), data = chunk_cat("cc", host->get_address(host),
chunk_from_thing(netmask)); chunk_from_thing(netmask));
} }
else else
{ /* IPv6 addresses the prefix only */ { /* IPv6 addresses the prefix only */
entry->value = chunk_cat("cc", host->get_address(host), data = chunk_cat("cc", host->get_address(host),
chunk_from_chars(mask)); chunk_from_chars(mask));
} }
} }
host->destroy(host); host->destroy(host);
}
INIT(entry,
.type = type ?: (family == AF_INET ? mapped->v4 : mapped->v6),
.value = data,
);
DBG2(DBG_CFG, "loaded attribute %N: %#B", DBG2(DBG_CFG, "loaded attribute %N: %#B",
configuration_attribute_type_names, entry->type, &entry->value); configuration_attribute_type_names, entry->type, &entry->value);
this->attributes->insert_last(this->attributes, entry); this->attributes->insert_last(this->attributes, entry);