aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstrongswan/plugins/unbound
diff options
context:
space:
mode:
authorReto Guadagnini <rguadagn@hsr.ch>2012-04-10 17:05:06 +0200
committerTobias Brunner <tobias@strongswan.org>2013-02-19 11:57:21 +0100
commitcfd07978d0a8ba6efa2dc12bb3c54a83b284a81f (patch)
treebd3553fe4fee19f04135ffce782ae0242189376d /src/libstrongswan/plugins/unbound
parent5a4126b4900901f6fa3ea618db5789dc224c42dd (diff)
downloadstrongswan-cfd07978d0a8ba6efa2dc12bb3c54a83b284a81f.tar.bz2
strongswan-cfd07978d0a8ba6efa2dc12bb3c54a83b284a81f.tar.xz
unbound: Implementation of query method of unbound_resolver_t
Diffstat (limited to 'src/libstrongswan/plugins/unbound')
-rw-r--r--src/libstrongswan/plugins/unbound/unbound_resolver.c69
-rw-r--r--src/libstrongswan/plugins/unbound/unbound_resolver.h2
2 files changed, 64 insertions, 7 deletions
diff --git a/src/libstrongswan/plugins/unbound/unbound_resolver.c b/src/libstrongswan/plugins/unbound/unbound_resolver.c
index 817067d1c..8c6a7d141 100644
--- a/src/libstrongswan/plugins/unbound/unbound_resolver.c
+++ b/src/libstrongswan/plugins/unbound/unbound_resolver.c
@@ -13,12 +13,16 @@
* for more details.
*/
+#include <unbound.h>
+#include <errno.h>
+#include <ldns/ldns.h>
#include <string.h>
#include <library.h>
#include <utils/debug.h>
#include "unbound_resolver.h"
+#include "unbound_response.h"
typedef struct private_resolver_t private_resolver_t;
@@ -31,6 +35,11 @@ struct private_resolver_t {
* Public data
*/
resolver_t public;
+
+ /**
+ * private unbound resolver handle (unbound context)
+ */
+ struct ub_ctx *ctx;
};
/**
@@ -40,8 +49,27 @@ METHOD(resolver_t, query, resolver_response_t*,
private_resolver_t *this, char *domain, rr_class_t rr_class,
rr_type_t rr_type)
{
- /* TODO: Implement */
- return NULL;
+ unbound_response_t *response = NULL;
+ struct ub_result *result = NULL;
+ int ub_retval;
+
+ ub_retval = ub_resolve(this->ctx, domain, rr_type, rr_class, &result);
+ if (ub_retval)
+ {
+ DBG1(DBG_LIB, "unbound resolver error: %s", ub_strerror(ub_retval));
+ ub_resolve_free(result);
+ return NULL;
+ }
+
+ response = unbound_response_create_frm_libub_response(result);
+ if (!response)
+ {
+ DBG1(DBG_LIB, "unbound_resolver: Could not create response.");
+ ub_resolve_free(result);
+ return NULL;
+ }
+ ub_resolve_free(result);
+ return (resolver_response_t*)response;
}
/**
@@ -50,15 +78,17 @@ METHOD(resolver_t, query, resolver_response_t*,
METHOD(resolver_t, destroy, void,
private_resolver_t *this)
{
+ ub_ctx_delete(this->ctx);
free(this);
}
/*
* Described in header.
*/
-resolver_t *unbound_resolver_create()
+resolver_t *unbound_resolver_create(char *resolv_conf, char *ta_file)
{
private_resolver_t *this;
+ int ub_retval = 0;
INIT(this,
.public = {
@@ -67,8 +97,35 @@ resolver_t *unbound_resolver_create()
},
);
- /* TODO: Implement */
- destroy(this);
- return NULL;
+ DBG1(DBG_LIB, "creating an unbound_resolver instance");
+
+ this->ctx = ub_ctx_create();
+ if (!this->ctx)
+ {
+ DBG1(DBG_LIB, "failed to create an unbound resolver context");
+ _destroy(this);
+ return NULL;
+ }
+
+ ub_retval = ub_ctx_resolvconf(this->ctx, resolv_conf);
+ if (ub_retval)
+ {
+ DBG1(DBG_LIB, "failed to read the resolver configuration file. "
+ "Unbound error: %s. errno says: %s", ub_strerror(ub_retval),
+ strerror(errno));
+ _destroy(this);
+ return NULL;
+ }
+
+ ub_retval = ub_ctx_add_ta_file(this->ctx, ta_file);
+ if (ub_retval)
+ {
+ DBG1(DBG_LIB, "failed to load trusted anchors from file %s. "
+ "Unbound error: %s. errno says: %s",
+ ta_file, ub_strerror(ub_retval), strerror(errno));
+ }
+
+ DBG1(DBG_LIB, "unbound resolver instance created");
+ return &this->public;
}
diff --git a/src/libstrongswan/plugins/unbound/unbound_resolver.h b/src/libstrongswan/plugins/unbound/unbound_resolver.h
index 659906c74..17ac6010d 100644
--- a/src/libstrongswan/plugins/unbound/unbound_resolver.h
+++ b/src/libstrongswan/plugins/unbound/unbound_resolver.h
@@ -24,6 +24,6 @@
/**
* Create a resolver_t instance.
*/
-resolver_t *unbound_resolver_create();
+resolver_t *unbound_resolver_create(char *resolv_conf, char *ta_file);
#endif /** LIBunbound_RESOLVER_H_ @}*/