summaryrefslogtreecommitdiff
path: root/lib/dns
diff options
context:
space:
mode:
Diffstat (limited to 'lib/dns')
-rw-r--r--lib/dns/Makefile.in9
-rw-r--r--lib/dns/dynamic_db.c366
-rw-r--r--lib/dns/include/dns/Makefile.in2
-rw-r--r--lib/dns/include/dns/dynamic_db.h50
-rw-r--r--lib/dns/include/dns/log.h1
-rw-r--r--lib/dns/include/dns/types.h1
-rw-r--r--lib/dns/log.c1
7 files changed, 427 insertions, 3 deletions
diff --git a/lib/dns/Makefile.in b/lib/dns/Makefile.in
index c0f7b442..5bf850ae 100644
--- a/lib/dns/Makefile.in
+++ b/lib/dns/Makefile.in
@@ -62,7 +62,7 @@ DNSOBJS = acache.@O@ acl.@O@ adb.@O@ byaddr.@O@ \
cache.@O@ callbacks.@O@ clientinfo.@O@ compress.@O@ \
db.@O@ dbiterator.@O@ dbtable.@O@ diff.@O@ dispatch.@O@ \
dlz.@O@ dns64.@O@ dnssec.@O@ ds.@O@ forward.@O@ iptable.@O@ \
- journal.@O@ keydata.@O@ keytable.@O@ \
+ dynamic_db.@O@ journal.@O@ keydata.@O@ keytable.@O@ \
lib.@O@ log.@O@ lookup.@O@ \
master.@O@ masterdump.@O@ message.@O@ \
name.@O@ ncache.@O@ nsec.@O@ nsec3.@O@ order.@O@ peer.@O@ \
@@ -92,7 +92,7 @@ DNSSRCS = acache.c acl.c adb.c byaddr.c \
cache.c callbacks.c clientinfo.c compress.c \
db.c dbiterator.c dbtable.c diff.c dispatch.c \
dlz.c dns64.c dnssec.c ds.c forward.c iptable.c journal.c \
- keydata.c keytable.c lib.c log.c lookup.c \
+ dynamic_db.c keydata.c keytable.c lib.c log.c lookup.c \
master.c masterdump.c message.c \
name.c ncache.c nsec.c nsec3.c order.c peer.c portlist.c \
rbt.c rbtdb.c rbtdb64.c rcode.c rdata.c rdatalist.c \
@@ -125,6 +125,11 @@ version.@O@: version.c
-DLIBAGE=${LIBAGE} \
-c ${srcdir}/version.c
+dynamic_db.@O@: dynamic_db.c
+ ${LIBTOOL_MODE_COMPILE} ${CC} ${ALL_CFLAGS} \
+ -DDYNDB_LIBDIR=\"@libdir@/bind/\" \
+ -c ${srcdir}/dynamic_db.c
+
libdns.@SA@: ${OBJS}
${AR} ${ARFLAGS} $@ ${OBJS}
${RANLIB} $@
diff --git a/lib/dns/dynamic_db.c b/lib/dns/dynamic_db.c
new file mode 100644
index 00000000..bf831617
--- /dev/null
+++ b/lib/dns/dynamic_db.c
@@ -0,0 +1,366 @@
+/*
+ * Copyright (C) 2008-2011 Red Hat, Inc.
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND Red Hat DISCLAIMS ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS. IN NO EVENT SHALL Red Hat BE LIABLE FOR ANY SPECIAL, DIRECT,
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+ * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+
+
+#include <config.h>
+
+#include <isc/buffer.h>
+#include <isc/mem.h>
+#include <isc/mutex.h>
+#include <isc/once.h>
+#include <isc/result.h>
+#include <isc/region.h>
+#include <isc/task.h>
+#include <isc/types.h>
+#include <isc/util.h>
+
+#include <dns/dynamic_db.h>
+#include <dns/log.h>
+#include <dns/types.h>
+#include <dns/view.h>
+#include <dns/zone.h>
+
+#include <string.h>
+
+#if HAVE_DLFCN_H
+#include <dlfcn.h>
+#endif
+
+#ifndef DYNDB_LIBDIR
+#define DYNDB_LIBDIR ""
+#endif
+
+#define CHECK(op) \
+ do { result = (op); \
+ if (result != ISC_R_SUCCESS) goto cleanup; \
+ } while (0)
+
+
+typedef isc_result_t (*register_func_t)(isc_mem_t *mctx, const char *name,
+ const char * const *argv,
+ const dns_dyndb_arguments_t *dyndb_args);
+typedef void (*destroy_func_t)(void);
+
+typedef struct dyndb_implementation dyndb_implementation_t;
+
+struct dyndb_implementation {
+ isc_mem_t *mctx;
+ void *handle;
+ register_func_t register_function;
+ destroy_func_t destroy_function;
+ LINK(dyndb_implementation_t) link;
+};
+
+struct dns_dyndb_arguments {
+ dns_view_t *view;
+ dns_zonemgr_t *zmgr;
+ isc_task_t *task;
+ isc_timermgr_t *timermgr;
+};
+
+/* List of implementations. Locked by dyndb_lock. */
+static LIST(dyndb_implementation_t) dyndb_implementations;
+/* Locks dyndb_implementations. */
+static isc_mutex_t dyndb_lock;
+static isc_once_t once = ISC_ONCE_INIT;
+
+static void
+dyndb_initialize(void) {
+ RUNTIME_CHECK(isc_mutex_init(&dyndb_lock) == ISC_R_SUCCESS);
+ INIT_LIST(dyndb_implementations);
+}
+
+
+#if HAVE_DLFCN_H
+static isc_result_t
+load_symbol(void *handle, const char *symbol_name, void **symbolp)
+{
+ const char *errmsg;
+ void *symbol;
+
+ REQUIRE(handle != NULL);
+ REQUIRE(symbolp != NULL && *symbolp == NULL);
+
+ symbol = dlsym(handle, symbol_name);
+ if (symbol == NULL) {
+ errmsg = dlerror();
+ if (errmsg == NULL)
+ errmsg = "returned function pointer is NULL";
+ isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
+ DNS_LOGMODULE_DYNDB, ISC_LOG_ERROR,
+ "failed to lookup symbol %s: %s",
+ symbol_name, errmsg);
+ return ISC_R_FAILURE;
+ }
+ dlerror();
+
+ *symbolp = symbol;
+
+ return ISC_R_SUCCESS;
+}
+
+static isc_result_t
+load_library(isc_mem_t *mctx, const char *filename, dyndb_implementation_t **impp)
+{
+ isc_result_t result;
+ size_t module_size;
+ isc_buffer_t *module_buf = NULL;
+ isc_region_t module_region;
+ void *handle = NULL;
+ dyndb_implementation_t *imp;
+ register_func_t register_function = NULL;
+ destroy_func_t destroy_function = NULL;
+
+ REQUIRE(impp != NULL && *impp == NULL);
+
+ /* Build up the full path. */
+ module_size = strlen(DYNDB_LIBDIR) + strlen(filename) + 1;
+ CHECK(isc_buffer_allocate(mctx, &module_buf, module_size));
+ isc_buffer_putstr(module_buf, DYNDB_LIBDIR);
+ isc_buffer_putstr(module_buf, filename);
+ isc_buffer_putuint8(module_buf, 0);
+ isc_buffer_region(module_buf, &module_region);
+
+ handle = dlopen((char *)module_region.base, RTLD_LAZY);
+ if (handle == NULL) {
+ isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE,
+ DNS_LOGMODULE_DYNDB, ISC_LOG_ERROR,
+ "failed to dynamically load driver '%s': %s",
+ filename, dlerror());
+ result = ISC_R_FAILURE;
+ goto cleanup;
+ }
+ dlerror();
+
+ CHECK(load_symbol(handle, "dynamic_driver_init",
+ (void **)&register_function));
+ CHECK(load_symbol(handle, "dynamic_driver_destroy",
+ (void **)&destroy_function));
+
+ imp = isc_mem_get(mctx, sizeof(dyndb_implementation_t));
+ if (imp == NULL) {
+ result = ISC_R_NOMEMORY;
+ goto cleanup;
+ }
+
+ imp->mctx = NULL;
+ isc_mem_attach(mctx, &imp->mctx);
+ imp->handle = handle;
+ imp->register_function = register_function;
+ imp->destroy_function = destroy_function;
+ INIT_LINK(imp, link);
+
+ *impp = imp;
+
+cleanup:
+ if (result != ISC_R_SUCCESS && handle != NULL)
+ dlclose(handle);
+ if (module_buf != NULL)
+ isc_buffer_free(&module_buf);
+
+ return result;
+}
+
+static void
+unload_library(dyndb_implementation_t **impp)
+{
+ dyndb_implementation_t *imp;
+
+ REQUIRE(impp != NULL && *impp != NULL);
+
+ imp = *impp;
+
+ isc_mem_putanddetach(&imp->mctx, imp, sizeof(dyndb_implementation_t));
+
+ *impp = NULL;
+}
+
+#else /* HAVE_DLFCN_H */
+static isc_result_t
+load_library(isc_mem_t *mctx, const char *filename, dyndb_implementation_t **impp)
+{
+ UNUSED(mctx);
+ UNUSED(filename);
+ UNUSED(impp);
+
+ isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DYNDB,
+ ISC_LOG_ERROR,
+ "dynamic database support is not implemented")
+
+ return ISC_R_NOTIMPLEMENTED;
+}
+
+static void
+unload_library(dyndb_implementation_t **impp)
+{
+ dyndb_implementation_t *imp;
+
+ REQUIRE(impp != NULL && *impp != NULL);
+
+ imp = *impp;
+
+ isc_mem_putanddetach(&imp->mctx, imp, sizeof(dyndb_implementation_t));
+
+ *impp = NULL;
+}
+#endif /* HAVE_DLFCN_H */
+
+isc_result_t
+dns_dynamic_db_load(const char *libname, const char *name, isc_mem_t *mctx,
+ const char * const *argv,
+ const dns_dyndb_arguments_t *dyndb_args)
+{
+ isc_result_t result;
+ dyndb_implementation_t *implementation = NULL;
+
+ RUNTIME_CHECK(isc_once_do(&once, dyndb_initialize) == ISC_R_SUCCESS);
+
+ CHECK(load_library(mctx, libname, &implementation));
+ CHECK(implementation->register_function(mctx, name, argv, dyndb_args));
+
+ LOCK(&dyndb_lock);
+ APPEND(dyndb_implementations, implementation, link);
+ UNLOCK(&dyndb_lock);
+
+ return ISC_R_SUCCESS;
+
+cleanup:
+ if (implementation != NULL)
+ unload_library(&implementation);
+
+ return result;
+}
+
+void
+dns_dynamic_db_cleanup(isc_boolean_t exiting)
+{
+ dyndb_implementation_t *elem;
+ dyndb_implementation_t *prev;
+
+ RUNTIME_CHECK(isc_once_do(&once, dyndb_initialize) == ISC_R_SUCCESS);
+
+ LOCK(&dyndb_lock);
+ elem = TAIL(dyndb_implementations);
+ while (elem != NULL) {
+ prev = PREV(elem, link);
+ UNLINK(dyndb_implementations, elem, link);
+ elem->destroy_function();
+ unload_library(&elem);
+ elem = prev;
+ }
+ UNLOCK(&dyndb_lock);
+
+ if (exiting == ISC_TRUE)
+ isc_mutex_destroy(&dyndb_lock);
+}
+
+dns_dyndb_arguments_t *
+dns_dyndb_arguments_create(isc_mem_t *mctx)
+{
+ dns_dyndb_arguments_t *args;
+
+ args = isc_mem_get(mctx, sizeof(*args));
+ if (args != NULL)
+ memset(args, 0, sizeof(*args));
+
+ return args;
+}
+
+void
+dns_dyndb_arguments_destroy(isc_mem_t *mctx, dns_dyndb_arguments_t *args)
+{
+ REQUIRE(args != NULL);
+
+ dns_dyndb_set_view(args, NULL);
+ dns_dyndb_set_zonemgr(args, NULL);
+ dns_dyndb_set_task(args, NULL);
+ dns_dyndb_set_timermgr(args, NULL);
+
+ isc_mem_put(mctx, args, sizeof(*args));
+}
+
+void
+dns_dyndb_set_view(dns_dyndb_arguments_t *args, dns_view_t *view)
+{
+ REQUIRE(args != NULL);
+
+ if (args->view != NULL)
+ dns_view_detach(&args->view);
+ if (view != NULL)
+ dns_view_attach(view, &args->view);
+}
+
+dns_view_t *
+dns_dyndb_get_view(dns_dyndb_arguments_t *args)
+{
+ REQUIRE(args != NULL);
+
+ return args->view;
+}
+
+void
+dns_dyndb_set_zonemgr(dns_dyndb_arguments_t *args, dns_zonemgr_t *zmgr)
+{
+ REQUIRE(args != NULL);
+
+ if (args->zmgr != NULL)
+ dns_zonemgr_detach(&args->zmgr);
+ if (zmgr != NULL)
+ dns_zonemgr_attach(zmgr, &args->zmgr);
+}
+
+dns_zonemgr_t *
+dns_dyndb_get_zonemgr(dns_dyndb_arguments_t *args)
+{
+ REQUIRE(args != NULL);
+
+ return args->zmgr;
+}
+
+void
+dns_dyndb_set_task(dns_dyndb_arguments_t *args, isc_task_t *task)
+{
+ REQUIRE(args != NULL);
+
+ if (args->task != NULL)
+ isc_task_detach(&args->task);
+ if (task != NULL)
+ isc_task_attach(task, &args->task);
+}
+
+isc_task_t *
+dns_dyndb_get_task(dns_dyndb_arguments_t *args)
+{
+ REQUIRE(args != NULL);
+
+ return args->task;
+}
+
+void
+dns_dyndb_set_timermgr(dns_dyndb_arguments_t *args, isc_timermgr_t *timermgr)
+{
+ REQUIRE(args != NULL);
+
+ args->timermgr = timermgr;
+}
+
+isc_timermgr_t *
+dns_dyndb_get_timermgr(dns_dyndb_arguments_t *args)
+{
+ REQUIRE(args != NULL);
+
+ return args->timermgr;
+}
diff --git a/lib/dns/include/dns/Makefile.in b/lib/dns/include/dns/Makefile.in
index f2ca095e..47015381 100644
--- a/lib/dns/include/dns/Makefile.in
+++ b/lib/dns/include/dns/Makefile.in
@@ -22,7 +22,7 @@ top_srcdir = @top_srcdir@
@BIND9_VERSION@
HEADERS = acl.h adb.h byaddr.h cache.h callbacks.h cert.h compress.h \
- clientinfo.h db.h dbiterator.h dbtable.h diff.h dispatch.h \
+ clientinfo.h db.h dbiterator.h dbtable.h diff.h dispatch.h dynamic_db.h \
dlz.h dnssec.h ds.h events.h fixedname.h iptable.h journal.h \
keyflags.h keytable.h keyvalues.h lib.h log.h \
master.h masterdump.h message.h name.h ncache.h nsec.h \
diff --git a/lib/dns/include/dns/dynamic_db.h b/lib/dns/include/dns/dynamic_db.h
new file mode 100644
index 00000000..673ad4bc
--- /dev/null
+++ b/lib/dns/include/dns/dynamic_db.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2008-2011 Red Hat, Inc.
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND Red Hat DISCLAIMS ALL WARRANTIES WITH
+ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+ * AND FITNESS. IN NO EVENT SHALL Red Hat BE LIABLE FOR ANY SPECIAL, DIRECT,
+ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+ * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+
+
+#ifndef DYNAMIC_DB_H
+#define DYNAMIC_DB_H
+
+#include <isc/types.h>
+
+#include <dns/types.h>
+
+/*
+ * TODO:
+ * Reformat the prototypes.
+ * Add annotated comments.
+ */
+
+isc_result_t dns_dynamic_db_load(const char *libname, const char *name,
+ isc_mem_t *mctx, const char * const *argv,
+ const dns_dyndb_arguments_t *dyndb_args);
+
+void dns_dynamic_db_cleanup(isc_boolean_t exiting);
+
+dns_dyndb_arguments_t *dns_dyndb_arguments_create(isc_mem_t *mctx);
+void dns_dyndb_arguments_destroy(isc_mem_t *mctx, dns_dyndb_arguments_t *args);
+
+void dns_dyndb_set_view(dns_dyndb_arguments_t *args, dns_view_t *view);
+dns_view_t *dns_dyndb_get_view(dns_dyndb_arguments_t *args);
+void dns_dyndb_set_zonemgr(dns_dyndb_arguments_t *args, dns_zonemgr_t *zmgr);
+dns_zonemgr_t *dns_dyndb_get_zonemgr(dns_dyndb_arguments_t *args);
+void dns_dyndb_set_task(dns_dyndb_arguments_t *args, isc_task_t *task);
+isc_task_t *dns_dyndb_get_task(dns_dyndb_arguments_t *args);
+void dns_dyndb_set_timermgr(dns_dyndb_arguments_t *args,
+ isc_timermgr_t *timermgr);
+isc_timermgr_t *dns_dyndb_get_timermgr(dns_dyndb_arguments_t *args);
+
+#endif
diff --git a/lib/dns/include/dns/log.h b/lib/dns/include/dns/log.h
index e8c8c105..a3b7e5a7 100644
--- a/lib/dns/include/dns/log.h
+++ b/lib/dns/include/dns/log.h
@@ -77,6 +77,7 @@ LIBDNS_EXTERNAL_DATA extern isc_logmodule_t dns_modules[];
#define DNS_LOGMODULE_DLZ (&dns_modules[26])
#define DNS_LOGMODULE_DNSSEC (&dns_modules[27])
#define DNS_LOGMODULE_CRYPTO (&dns_modules[28])
+#define DNS_LOGMODULE_DYNDB (&dns_modules[29])
ISC_LANG_BEGINDECLS
diff --git a/lib/dns/include/dns/types.h b/lib/dns/include/dns/types.h
index 76167c2f..f5e39d45 100644
--- a/lib/dns/include/dns/types.h
+++ b/lib/dns/include/dns/types.h
@@ -60,6 +60,7 @@ typedef struct dns_dbtable dns_dbtable_t;
typedef void dns_dbversion_t;
typedef struct dns_dlzimplementation dns_dlzimplementation_t;
typedef struct dns_dlzdb dns_dlzdb_t;
+typedef struct dns_dyndb_arguments dns_dyndb_arguments_t;
typedef struct dns_sdlzimplementation dns_sdlzimplementation_t;
typedef struct dns_decompress dns_decompress_t;
typedef struct dns_dispatch dns_dispatch_t;
diff --git a/lib/dns/log.c b/lib/dns/log.c
index 75e0d79b..b5c8b057 100644
--- a/lib/dns/log.c
+++ b/lib/dns/log.c
@@ -83,6 +83,7 @@ LIBDNS_EXTERNAL_DATA isc_logmodule_t dns_modules[] = {
{ "dns/dlz", 0 },
{ "dns/dnssec", 0 },
{ "dns/crypto", 0 },
+ { "dns/dynamic_db", 0 },
{ NULL, 0 }
};