Use the proper types for comma separated attributes read from strongswan.conf

Attributes of different address families previously were mapped to
the same attribute type (the one derived from the address family of the
first address).
This commit is contained in:
Tobias Brunner 2012-09-10 15:17:17 +02:00
parent 383c174a79
commit 4065e2504c

View File

@ -145,11 +145,13 @@ static void add_legacy_entry(private_attr_provider_t *this, char *key, int nr,
/**
* Key to attribute type mappings, for v4 and v6 attributes
*/
static struct {
typedef struct {
char *name;
configuration_attribute_type_t v4;
configuration_attribute_type_t v6;
} keys[] = {
} attribute_type_key_t;
static attribute_type_key_t keys[] = {
{"address", INTERNAL_IP4_ADDRESS, INTERNAL_IP6_ADDRESS},
{"dns", INTERNAL_IP4_DNS, INTERNAL_IP6_DNS},
{"nbns", INTERNAL_IP4_NBNS, INTERNAL_IP6_NBNS},
@ -181,12 +183,29 @@ static void load_entries(private_attr_provider_t *this)
while (enumerator->enumerate(enumerator, &key, &value))
{
configuration_attribute_type_t type;
attribute_type_key_t *mapped = NULL;
attribute_entry_t *entry;
host_t *host;
char *pos;
int i, mask = -1;
int i, mask = -1, family;
type = atoi(key);
if (!type)
{
for (i = 0; i < countof(keys); i++)
{
if (streq(key, keys[i].name))
{
mapped = &keys[i];
break;
}
}
if (!mapped)
{
DBG1(DBG_CFG, "mapping attribute type %s failed", key);
continue;
}
}
tokens = enumerator_create_token(value, ",", " ");
while (tokens->enumerate(tokens, &token))
{
@ -202,37 +221,16 @@ static void load_entries(private_attr_provider_t *this)
DBG1(DBG_CFG, "invalid host in key %s: %s", key, token);
continue;
}
if (!type)
{
for (i = 0; i < countof(keys); i++)
{
if (streq(key, keys[i].name))
{
if (host->get_family(host) == AF_INET)
{
type = keys[i].v4;
}
else
{
type = keys[i].v6;
}
}
}
if (!type)
{
DBG1(DBG_CFG, "mapping attribute type %s failed", key);
break;
}
}
family = host->get_family(host);
entry = malloc_thing(attribute_entry_t);
entry->type = type;
entry->type = type ?: (family == AF_INET ? mapped->v4 : mapped->v6);
if (mask == -1)
{
entry->value = chunk_clone(host->get_address(host));
}
else
{
if (host->get_family(host) == AF_INET)
if (family == AF_INET)
{ /* IPv4 attributes contain a subnet mask */
u_int32_t netmask;