aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Willi <martin@revosec.ch>2010-06-24 15:44:28 +0200
committerMartin Willi <martin@revosec.ch>2010-06-24 15:46:28 +0200
commit1e723d739cf53978443e4784e81ae12d0965adb7 (patch)
tree37150fd17bb433c14ffd498b8743150facb4ae4f
parentc0914c457b7da4637c07068ad172c0f16b34c924 (diff)
downloadstrongswan-1e723d739cf53978443e4784e81ae12d0965adb7.tar.bz2
strongswan-1e723d739cf53978443e4784e81ae12d0965adb7.tar.xz
Support the subnet attribute in the attr plugin
-rw-r--r--src/libhydra/plugins/attr/attr_provider.c32
1 files changed, 30 insertions, 2 deletions
diff --git a/src/libhydra/plugins/attr/attr_provider.c b/src/libhydra/plugins/attr/attr_provider.c
index 9d6daa892..cd504e03f 100644
--- a/src/libhydra/plugins/attr/attr_provider.c
+++ b/src/libhydra/plugins/attr/attr_provider.c
@@ -148,6 +148,7 @@ static struct {
{"dhcp", INTERNAL_IP4_DHCP, INTERNAL_IP6_DHCP},
{"netmask", INTERNAL_IP4_NETMASK, INTERNAL_IP6_NETMASK},
{"server", INTERNAL_IP4_SERVER, INTERNAL_IP6_SERVER},
+ {"subnet", INTERNAL_IP4_SUBNET, INTERNAL_IP6_SUBNET},
};
/**
@@ -165,12 +166,19 @@ static void load_entries(private_attr_provider_t *this)
configuration_attribute_type_t type;
attribute_entry_t *entry;
host_t *host;
- int i;
+ char *pos;
+ int i, mask = -1;
type = atoi(key);
tokens = enumerator_create_token(value, ",", " ");
while (tokens->enumerate(tokens, &token))
{
+ pos = strchr(token, '/');
+ if (pos)
+ {
+ *(pos++) = '\0';
+ mask = atoi(pos);
+ }
host = host_create_from_string(token, 0);
if (!host)
{
@@ -201,7 +209,27 @@ static void load_entries(private_attr_provider_t *this)
}
entry = malloc_thing(attribute_entry_t);
entry->type = type;
- entry->value = chunk_clone(host->get_address(host));
+ if (mask == -1)
+ {
+ entry->value = chunk_clone(host->get_address(host));
+ }
+ else
+ {
+ if (host->get_family(host) == AF_INET)
+ { /* IPv4 attributes contain a subnet mask */
+ u_int32_t netmask;
+
+ mask = 32 - mask;
+ netmask = htonl((0xFFFFFFFF >> mask) << mask);
+ entry->value = chunk_cat("cc", host->get_address(host),
+ chunk_from_thing(netmask));
+ }
+ else
+ { /* IPv6 addresses the prefix only */
+ entry->value = chunk_cat("cc", host->get_address(host),
+ chunk_from_chars(mask));
+ }
+ }
host->destroy(host);
this->attributes->insert_last(this->attributes, entry);
}