Moved attr plugin from libcharon to libhydra.
authorTobias Brunner <tobias@strongswan.org>
Wed, 31 Mar 2010 11:55:12 +0000 (13:55 +0200)
committerTobias Brunner <tobias@strongswan.org>
Tue, 6 Apr 2010 10:47:40 +0000 (12:47 +0200)
13 files changed:
configure.in
src/libcharon/Makefile.am
src/libcharon/plugins/attr/Makefile.am [deleted file]
src/libcharon/plugins/attr/attr_plugin.c [deleted file]
src/libcharon/plugins/attr/attr_plugin.h [deleted file]
src/libcharon/plugins/attr/attr_provider.c [deleted file]
src/libcharon/plugins/attr/attr_provider.h [deleted file]
src/libhydra/Makefile.am
src/libhydra/plugins/attr/Makefile.am [new file with mode: 0644]
src/libhydra/plugins/attr/attr_plugin.c [new file with mode: 0644]
src/libhydra/plugins/attr/attr_plugin.h [new file with mode: 0644]
src/libhydra/plugins/attr/attr_provider.c [new file with mode: 0644]
src/libhydra/plugins/attr/attr_provider.h [new file with mode: 0644]

index eed4cbc..47d56b4 100644 (file)
@@ -745,6 +745,10 @@ if test x$gmp = xtrue; then
        libstrongswan_plugins=${libstrongswan_plugins}" gmp"
        pluto_plugins=${pluto_plugins}" gmp"
 fi
+if test x$attr = xtrue; then
+       libhydra_plugins=${libhydra_plugins}" attr"
+       pluto_plugins=${pluto_plugins}" attr"
+fi
 if test x$attr_sql = xtrue -o x$sql = xtrue; then
        libhydra_plugins=${libhydra_plugins}" attr-sql"
        pluto_plugins=${pluto_plugins}" attr-sql"
@@ -904,6 +908,7 @@ AC_OUTPUT(
        src/libstrongswan/plugins/agent/Makefile
        src/libstrongswan/plugins/test_vectors/Makefile
        src/libhydra/Makefile
+       src/libhydra/plugins/attr/Makefile
        src/libhydra/plugins/attr_sql/Makefile
        src/libfreeswan/Makefile
        src/libsimaka/Makefile
@@ -939,7 +944,6 @@ AC_OUTPUT(
        src/libcharon/plugins/android/Makefile
        src/libcharon/plugins/stroke/Makefile
        src/libcharon/plugins/updown/Makefile
-       src/libcharon/plugins/attr/Makefile
        src/libcharon/plugins/dhcp/Makefile
        src/libcharon/plugins/resolve/Makefile
        src/libcharon/plugins/unit_tester/Makefile
index 9ed1ffe..14d3c39 100644 (file)
@@ -245,14 +245,6 @@ if MONOLITHIC
 endif
 endif
 
-if USE_ATTR
-  SUBDIRS += plugins/attr
-  PLUGINS += attr
-if MONOLITHIC
-  libcharon_la_LIBADD += plugins/attr/libstrongswan-attr.la
-endif
-endif
-
 if USE_EAP_IDENTITY
   SUBDIRS += plugins/eap_identity
   PLUGINS += eap-identity
diff --git a/src/libcharon/plugins/attr/Makefile.am b/src/libcharon/plugins/attr/Makefile.am
deleted file mode 100644 (file)
index 7140164..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-
-INCLUDES = -I$(top_srcdir)/src/libstrongswan -I$(top_srcdir)/src/libhydra \
-       -I$(top_srcdir)/src/libcharon
-
-AM_CFLAGS = -rdynamic
-
-if MONOLITHIC
-noinst_LTLIBRARIES = libstrongswan-attr.la
-else
-plugin_LTLIBRARIES = libstrongswan-attr.la
-endif
-
-libstrongswan_attr_la_SOURCES = \
-       attr_plugin.h attr_plugin.c \
-       attr_provider.h attr_provider.c
-
-libstrongswan_attr_la_LDFLAGS = -module -avoid-version
diff --git a/src/libcharon/plugins/attr/attr_plugin.c b/src/libcharon/plugins/attr/attr_plugin.c
deleted file mode 100644 (file)
index 24c00bb..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright (C) 2009 Martin Willi
- * Hochschule fuer Technik Rapperswil
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * for more details.
- */
-
-#include "attr_plugin.h"
-#include "attr_provider.h"
-
-#include <hydra.h>
-
-typedef struct private_attr_plugin_t private_attr_plugin_t;
-
-/**
- * private data of attr plugin
- */
-struct private_attr_plugin_t {
-
-       /**
-        * implements plugin interface
-        */
-       attr_plugin_t public;
-
-       /**
-        * CFG attributes provider
-        */
-       attr_provider_t *provider;
-};
-
-/**
- * Implementation of plugin_t.destroy
- */
-static void destroy(private_attr_plugin_t *this)
-{
-       hydra->attributes->remove_provider(hydra->attributes, &this->provider->provider);
-       this->provider->destroy(this->provider);
-       free(this);
-}
-
-/*
- * see header file
- */
-plugin_t *attr_plugin_create()
-{
-       private_attr_plugin_t *this = malloc_thing(private_attr_plugin_t);
-
-       this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
-
-       this->provider = attr_provider_create();
-       hydra->attributes->add_provider(hydra->attributes, &this->provider->provider);
-
-       return &this->public.plugin;
-}
-
diff --git a/src/libcharon/plugins/attr/attr_plugin.h b/src/libcharon/plugins/attr/attr_plugin.h
deleted file mode 100644 (file)
index 0c6eebf..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (C) 2009 Martin Willi
- * Hochschule fuer Technik Rapperswil
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * for more details.
- */
-
-/**
- * @defgroup attr attr
- * @ingroup cplugins
- *
- * @defgroup attr_plugin attr_plugin
- * @{ @ingroup attr
- */
-
-#ifndef ATTR_PLUGIN_H_
-#define ATTR_PLUGIN_H_
-
-#include <plugins/plugin.h>
-
-typedef struct attr_plugin_t attr_plugin_t;
-
-/**
- * Plugin providing configuration attribute through strongswan.conf.
- */
-struct attr_plugin_t {
-
-       /**
-        * implements plugin interface
-        */
-       plugin_t plugin;
-};
-
-#endif /** ATTR_PLUGIN_H_ @}*/
diff --git a/src/libcharon/plugins/attr/attr_provider.c b/src/libcharon/plugins/attr/attr_provider.c
deleted file mode 100644 (file)
index 548896f..0000000
+++ /dev/null
@@ -1,236 +0,0 @@
-/*
- * Copyright (C) 2009 Martin Willi
- * Hochschule fuer Technik Rapperswil
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * for more details.
- */
-
-#include "attr_provider.h"
-
-#include <time.h>
-
-#include <daemon.h>
-
-#define SERVER_MAX             2
-
-typedef struct private_attr_provider_t private_attr_provider_t;
-typedef struct attribute_entry_t attribute_entry_t;
-
-/**
- * private data of attr_provider
- */
-struct private_attr_provider_t {
-
-       /**
-        * public functions
-        */
-       attr_provider_t public;
-
-       /**
-        * List of attributes, attribute_entry_t
-        */
-       linked_list_t *attributes;
-};
-
-struct attribute_entry_t {
-       /** type of attribute */
-       configuration_attribute_type_t type;
-       /** attribute value */
-       chunk_t value;
-};
-
-/**
- * convert enumerator value from attribute_entry
- */
-static bool attr_enum_filter(void *null, attribute_entry_t **in,
-                       configuration_attribute_type_t *type, void* none, chunk_t *value)
-{
-       *type = (*in)->type;
-       *value = (*in)->value;
-       return TRUE;
-}
-
-/**
- * Implementation of attribute_provider_t.create_attribute_enumerator
- */
-static enumerator_t* create_attribute_enumerator(private_attr_provider_t *this,
-                                                                                       identification_t *id, host_t *vip)
-{
-       if (vip)
-       {
-               return enumerator_create_filter(
-                                               this->attributes->create_enumerator(this->attributes),
-                                               (void*)attr_enum_filter, NULL, NULL);
-       }
-       return enumerator_create_empty();
-}
-
-/**
- * Implementation of attr_provider_t.destroy
- */
-static void destroy(private_attr_provider_t *this)
-{
-       attribute_entry_t *entry;
-
-       while (this->attributes->remove_last(this->attributes,
-                                                                                (void**)&entry) == SUCCESS)
-       {
-               free(entry->value.ptr);
-               free(entry);
-       }
-       this->attributes->destroy(this->attributes);
-       free(this);
-}
-
-/**
- * Add an attribute entry to the list
- */
-static void add_legacy_entry(private_attr_provider_t *this, char *key, int nr,
-                                                        configuration_attribute_type_t type)
-{
-       attribute_entry_t *entry;
-       host_t *host;
-       char *str;
-
-       str = lib->settings->get_str(lib->settings, "charon.%s%d", NULL, key, nr);
-       if (str)
-       {
-               host = host_create_from_string(str, 0);
-               if (host)
-               {
-                       entry = malloc_thing(attribute_entry_t);
-
-                       if (host->get_family(host) == AF_INET6)
-                       {
-                               switch (type)
-                               {
-                                       case INTERNAL_IP4_DNS:
-                                               type = INTERNAL_IP6_DNS;
-                                               break;
-                                       case INTERNAL_IP4_NBNS:
-                                               type = INTERNAL_IP6_NBNS;
-                                               break;
-                                       default:
-                                               break;
-                               }
-                       }
-                       entry->type = type;
-                       entry->value = chunk_clone(host->get_address(host));
-                       host->destroy(host);
-                       this->attributes->insert_last(this->attributes, entry);
-               }
-       }
-}
-
-/**
- * Key to attribute type mappings, for v4 and v6 attributes
- */
-static struct {
-       char *name;
-       configuration_attribute_type_t v4;
-       configuration_attribute_type_t v6;
-} keys[] = {
-       {"address",             INTERNAL_IP4_ADDRESS,   INTERNAL_IP6_ADDRESS},
-       {"dns",                 INTERNAL_IP4_DNS,               INTERNAL_IP6_DNS},
-       {"nbns",                INTERNAL_IP4_NBNS,              INTERNAL_IP6_NBNS},
-       {"dhcp",                INTERNAL_IP4_DHCP,              INTERNAL_IP6_DHCP},
-       {"netmask",             INTERNAL_IP4_NETMASK,   INTERNAL_IP6_NETMASK},
-       {"server",              INTERNAL_IP4_SERVER,    INTERNAL_IP6_SERVER},
-};
-
-/**
- * Load (numerical) entries from the plugins.attr namespace
- */
-static void load_entries(private_attr_provider_t *this)
-{
-       enumerator_t *enumerator, *tokens;
-       char *key, *value, *token;
-
-       enumerator = lib->settings->create_key_value_enumerator(lib->settings,
-                                                                                                               "charon.plugins.attr");
-       while (enumerator->enumerate(enumerator, &key, &value))
-       {
-               configuration_attribute_type_t type;
-               attribute_entry_t *entry;
-               host_t *host;
-               int i;
-
-               type = atoi(key);
-               tokens = enumerator_create_token(value, ",", " ");
-               while (tokens->enumerate(tokens, &token))
-               {
-                       host = host_create_from_string(token, 0);
-                       if (!host)
-                       {
-                               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;
-                               }
-                       }
-                       entry = malloc_thing(attribute_entry_t);
-                       entry->type = type;
-                       entry->value = chunk_clone(host->get_address(host));
-                       host->destroy(host);
-                       this->attributes->insert_last(this->attributes, entry);
-               }
-               tokens->destroy(tokens);
-       }
-       enumerator->destroy(enumerator);
-}
-
-/*
- * see header file
- */
-attr_provider_t *attr_provider_create(database_t *db)
-{
-       private_attr_provider_t *this;
-       int i;
-
-       this = malloc_thing(private_attr_provider_t);
-
-       this->public.provider.acquire_address = (host_t*(*)(attribute_provider_t *this, char*, identification_t *, host_t *))return_null;
-       this->public.provider.release_address = (bool(*)(attribute_provider_t *this, char*,host_t *, identification_t*))return_false;
-       this->public.provider.create_attribute_enumerator = (enumerator_t*(*)(attribute_provider_t*, identification_t *id, host_t *vip))create_attribute_enumerator;
-       this->public.destroy = (void(*)(attr_provider_t*))destroy;
-
-       this->attributes = linked_list_create();
-
-       for (i = 1; i <= SERVER_MAX; i++)
-       {
-               add_legacy_entry(this, "dns", i, INTERNAL_IP4_DNS);
-               add_legacy_entry(this, "nbns", i, INTERNAL_IP4_NBNS);
-       }
-
-       load_entries(this);
-
-       return &this->public;
-}
-
diff --git a/src/libcharon/plugins/attr/attr_provider.h b/src/libcharon/plugins/attr/attr_provider.h
deleted file mode 100644 (file)
index a414667..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (C) 2009 Martin Willi
- * Hochschule fuer Technik Rapperswil
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2 of the License, or (at your
- * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * for more details.
- */
-
-/**
- * @defgroup attr_provider attr_provider
- * @{ @ingroup attr
- */
-
-#ifndef ATTR_PROVIDER_H_
-#define ATTR_PROVIDER_H_
-
-#include <attributes/attribute_provider.h>
-
-typedef struct attr_provider_t attr_provider_t;
-
-/**
- * Provide configuration attributes through static strongswan.conf definition.
- */
-struct attr_provider_t {
-
-       /**
-        * Implements attribute provider interface
-        */
-       attribute_provider_t provider;
-
-       /**
-        * Destroy a attr_provider instance.
-        */
-       void (*destroy)(attr_provider_t *this);
-};
-
-/**
- * Create a attr_provider instance.
- */
-attr_provider_t *attr_provider_create();
-
-#endif /** ATTR_PROVIDER @}*/
index c669b4e..cbf07c7 100644 (file)
@@ -26,6 +26,13 @@ else
 SUBDIRS = .
 endif
 
+if USE_ATTR
+  SUBDIRS += plugins/attr
+if MONOLITHIC
+  libhydra_la_LIBADD += plugins/attr/libstrongswan-attr.la
+endif
+endif
+
 if USE_ATTR_SQL
   SUBDIRS += plugins/attr_sql
 if MONOLITHIC
diff --git a/src/libhydra/plugins/attr/Makefile.am b/src/libhydra/plugins/attr/Makefile.am
new file mode 100644 (file)
index 0000000..7140164
--- /dev/null
@@ -0,0 +1,17 @@
+
+INCLUDES = -I$(top_srcdir)/src/libstrongswan -I$(top_srcdir)/src/libhydra \
+       -I$(top_srcdir)/src/libcharon
+
+AM_CFLAGS = -rdynamic
+
+if MONOLITHIC
+noinst_LTLIBRARIES = libstrongswan-attr.la
+else
+plugin_LTLIBRARIES = libstrongswan-attr.la
+endif
+
+libstrongswan_attr_la_SOURCES = \
+       attr_plugin.h attr_plugin.c \
+       attr_provider.h attr_provider.c
+
+libstrongswan_attr_la_LDFLAGS = -module -avoid-version
diff --git a/src/libhydra/plugins/attr/attr_plugin.c b/src/libhydra/plugins/attr/attr_plugin.c
new file mode 100644 (file)
index 0000000..24c00bb
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2009 Martin Willi
+ * Hochschule fuer Technik Rapperswil
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ */
+
+#include "attr_plugin.h"
+#include "attr_provider.h"
+
+#include <hydra.h>
+
+typedef struct private_attr_plugin_t private_attr_plugin_t;
+
+/**
+ * private data of attr plugin
+ */
+struct private_attr_plugin_t {
+
+       /**
+        * implements plugin interface
+        */
+       attr_plugin_t public;
+
+       /**
+        * CFG attributes provider
+        */
+       attr_provider_t *provider;
+};
+
+/**
+ * Implementation of plugin_t.destroy
+ */
+static void destroy(private_attr_plugin_t *this)
+{
+       hydra->attributes->remove_provider(hydra->attributes, &this->provider->provider);
+       this->provider->destroy(this->provider);
+       free(this);
+}
+
+/*
+ * see header file
+ */
+plugin_t *attr_plugin_create()
+{
+       private_attr_plugin_t *this = malloc_thing(private_attr_plugin_t);
+
+       this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
+
+       this->provider = attr_provider_create();
+       hydra->attributes->add_provider(hydra->attributes, &this->provider->provider);
+
+       return &this->public.plugin;
+}
+
diff --git a/src/libhydra/plugins/attr/attr_plugin.h b/src/libhydra/plugins/attr/attr_plugin.h
new file mode 100644 (file)
index 0000000..29fb338
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2009 Martin Willi
+ * Hochschule fuer Technik Rapperswil
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ */
+
+/**
+ * @defgroup attr attr
+ * @ingroup hplugins
+ *
+ * @defgroup attr_plugin attr_plugin
+ * @{ @ingroup attr
+ */
+
+#ifndef ATTR_PLUGIN_H_
+#define ATTR_PLUGIN_H_
+
+#include <plugins/plugin.h>
+
+typedef struct attr_plugin_t attr_plugin_t;
+
+/**
+ * Plugin providing configuration attribute through strongswan.conf.
+ */
+struct attr_plugin_t {
+
+       /**
+        * implements plugin interface
+        */
+       plugin_t plugin;
+};
+
+#endif /** ATTR_PLUGIN_H_ @}*/
diff --git a/src/libhydra/plugins/attr/attr_provider.c b/src/libhydra/plugins/attr/attr_provider.c
new file mode 100644 (file)
index 0000000..548896f
--- /dev/null
@@ -0,0 +1,236 @@
+/*
+ * Copyright (C) 2009 Martin Willi
+ * Hochschule fuer Technik Rapperswil
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ */
+
+#include "attr_provider.h"
+
+#include <time.h>
+
+#include <daemon.h>
+
+#define SERVER_MAX             2
+
+typedef struct private_attr_provider_t private_attr_provider_t;
+typedef struct attribute_entry_t attribute_entry_t;
+
+/**
+ * private data of attr_provider
+ */
+struct private_attr_provider_t {
+
+       /**
+        * public functions
+        */
+       attr_provider_t public;
+
+       /**
+        * List of attributes, attribute_entry_t
+        */
+       linked_list_t *attributes;
+};
+
+struct attribute_entry_t {
+       /** type of attribute */
+       configuration_attribute_type_t type;
+       /** attribute value */
+       chunk_t value;
+};
+
+/**
+ * convert enumerator value from attribute_entry
+ */
+static bool attr_enum_filter(void *null, attribute_entry_t **in,
+                       configuration_attribute_type_t *type, void* none, chunk_t *value)
+{
+       *type = (*in)->type;
+       *value = (*in)->value;
+       return TRUE;
+}
+
+/**
+ * Implementation of attribute_provider_t.create_attribute_enumerator
+ */
+static enumerator_t* create_attribute_enumerator(private_attr_provider_t *this,
+                                                                                       identification_t *id, host_t *vip)
+{
+       if (vip)
+       {
+               return enumerator_create_filter(
+                                               this->attributes->create_enumerator(this->attributes),
+                                               (void*)attr_enum_filter, NULL, NULL);
+       }
+       return enumerator_create_empty();
+}
+
+/**
+ * Implementation of attr_provider_t.destroy
+ */
+static void destroy(private_attr_provider_t *this)
+{
+       attribute_entry_t *entry;
+
+       while (this->attributes->remove_last(this->attributes,
+                                                                                (void**)&entry) == SUCCESS)
+       {
+               free(entry->value.ptr);
+               free(entry);
+       }
+       this->attributes->destroy(this->attributes);
+       free(this);
+}
+
+/**
+ * Add an attribute entry to the list
+ */
+static void add_legacy_entry(private_attr_provider_t *this, char *key, int nr,
+                                                        configuration_attribute_type_t type)
+{
+       attribute_entry_t *entry;
+       host_t *host;
+       char *str;
+
+       str = lib->settings->get_str(lib->settings, "charon.%s%d", NULL, key, nr);
+       if (str)
+       {
+               host = host_create_from_string(str, 0);
+               if (host)
+               {
+                       entry = malloc_thing(attribute_entry_t);
+
+                       if (host->get_family(host) == AF_INET6)
+                       {
+                               switch (type)
+                               {
+                                       case INTERNAL_IP4_DNS:
+                                               type = INTERNAL_IP6_DNS;
+                                               break;
+                                       case INTERNAL_IP4_NBNS:
+                                               type = INTERNAL_IP6_NBNS;
+                                               break;
+                                       default:
+                                               break;
+                               }
+                       }
+                       entry->type = type;
+                       entry->value = chunk_clone(host->get_address(host));
+                       host->destroy(host);
+                       this->attributes->insert_last(this->attributes, entry);
+               }
+       }
+}
+
+/**
+ * Key to attribute type mappings, for v4 and v6 attributes
+ */
+static struct {
+       char *name;
+       configuration_attribute_type_t v4;
+       configuration_attribute_type_t v6;
+} keys[] = {
+       {"address",             INTERNAL_IP4_ADDRESS,   INTERNAL_IP6_ADDRESS},
+       {"dns",                 INTERNAL_IP4_DNS,               INTERNAL_IP6_DNS},
+       {"nbns",                INTERNAL_IP4_NBNS,              INTERNAL_IP6_NBNS},
+       {"dhcp",                INTERNAL_IP4_DHCP,              INTERNAL_IP6_DHCP},
+       {"netmask",             INTERNAL_IP4_NETMASK,   INTERNAL_IP6_NETMASK},
+       {"server",              INTERNAL_IP4_SERVER,    INTERNAL_IP6_SERVER},
+};
+
+/**
+ * Load (numerical) entries from the plugins.attr namespace
+ */
+static void load_entries(private_attr_provider_t *this)
+{
+       enumerator_t *enumerator, *tokens;
+       char *key, *value, *token;
+
+       enumerator = lib->settings->create_key_value_enumerator(lib->settings,
+                                                                                                               "charon.plugins.attr");
+       while (enumerator->enumerate(enumerator, &key, &value))
+       {
+               configuration_attribute_type_t type;
+               attribute_entry_t *entry;
+               host_t *host;
+               int i;
+
+               type = atoi(key);
+               tokens = enumerator_create_token(value, ",", " ");
+               while (tokens->enumerate(tokens, &token))
+               {
+                       host = host_create_from_string(token, 0);
+                       if (!host)
+                       {
+                               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;
+                               }
+                       }
+                       entry = malloc_thing(attribute_entry_t);
+                       entry->type = type;
+                       entry->value = chunk_clone(host->get_address(host));
+                       host->destroy(host);
+                       this->attributes->insert_last(this->attributes, entry);
+               }
+               tokens->destroy(tokens);
+       }
+       enumerator->destroy(enumerator);
+}
+
+/*
+ * see header file
+ */
+attr_provider_t *attr_provider_create(database_t *db)
+{
+       private_attr_provider_t *this;
+       int i;
+
+       this = malloc_thing(private_attr_provider_t);
+
+       this->public.provider.acquire_address = (host_t*(*)(attribute_provider_t *this, char*, identification_t *, host_t *))return_null;
+       this->public.provider.release_address = (bool(*)(attribute_provider_t *this, char*,host_t *, identification_t*))return_false;
+       this->public.provider.create_attribute_enumerator = (enumerator_t*(*)(attribute_provider_t*, identification_t *id, host_t *vip))create_attribute_enumerator;
+       this->public.destroy = (void(*)(attr_provider_t*))destroy;
+
+       this->attributes = linked_list_create();
+
+       for (i = 1; i <= SERVER_MAX; i++)
+       {
+               add_legacy_entry(this, "dns", i, INTERNAL_IP4_DNS);
+               add_legacy_entry(this, "nbns", i, INTERNAL_IP4_NBNS);
+       }
+
+       load_entries(this);
+
+       return &this->public;
+}
+
diff --git a/src/libhydra/plugins/attr/attr_provider.h b/src/libhydra/plugins/attr/attr_provider.h
new file mode 100644 (file)
index 0000000..a414667
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2009 Martin Willi
+ * Hochschule fuer Technik Rapperswil
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ */
+
+/**
+ * @defgroup attr_provider attr_provider
+ * @{ @ingroup attr
+ */
+
+#ifndef ATTR_PROVIDER_H_
+#define ATTR_PROVIDER_H_
+
+#include <attributes/attribute_provider.h>
+
+typedef struct attr_provider_t attr_provider_t;
+
+/**
+ * Provide configuration attributes through static strongswan.conf definition.
+ */
+struct attr_provider_t {
+
+       /**
+        * Implements attribute provider interface
+        */
+       attribute_provider_t provider;
+
+       /**
+        * Destroy a attr_provider instance.
+        */
+       void (*destroy)(attr_provider_t *this);
+};
+
+/**
+ * Create a attr_provider instance.
+ */
+attr_provider_t *attr_provider_create();
+
+#endif /** ATTR_PROVIDER @}*/