diff options
author | Tobias Brunner <tobias@strongswan.org> | 2012-09-10 15:17:17 +0200 |
---|---|---|
committer | Tobias Brunner <tobias@strongswan.org> | 2012-09-10 15:17:17 +0200 |
commit | 4065e2504c9939cf823c661eaef33ffeb530f9da (patch) | |
tree | c7e1a9caa40efe2d2b2d2162247733db8f02683e /src | |
parent | 383c174a79682e461534d4846f6ab4cf6ff356f8 (diff) | |
download | strongswan-4065e2504c9939cf823c661eaef33ffeb530f9da.tar.bz2 strongswan-4065e2504c9939cf823c661eaef33ffeb530f9da.tar.xz |
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).
Diffstat (limited to 'src')
-rw-r--r-- | src/libhydra/plugins/attr/attr_provider.c | 52 |
1 files changed, 25 insertions, 27 deletions
diff --git a/src/libhydra/plugins/attr/attr_provider.c b/src/libhydra/plugins/attr/attr_provider.c index 673c72116..c1c3cd895 100644 --- a/src/libhydra/plugins/attr/attr_provider.c +++ b/src/libhydra/plugins/attr/attr_provider.c @@ -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; |