diff --git a/configure.ac b/configure.ac
index faac214..e5ab91d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -53,6 +53,18 @@ AC_TRY_COMPILE([
 [CFLAGS="$SAVED_CFLAGS"
  AC_MSG_RESULT([no])])
 
+# Check if build chain supports -std=gnu11
+AC_MSG_CHECKING([for -std=gnu11 compiler flag])
+SAVED_CFLAGS="$CFLAGS"
+CFLAGS="-std=gnu11 -Werror"
+AC_TRY_COMPILE([
+	extern int fdef(void);
+],[],
+[AC_MSG_RESULT([yes])
+ CFLAGS="$SAVED_CFLAGS -std=gnu11"],
+[CFLAGS="$SAVED_CFLAGS"
+ AC_MSG_RESULT([no])])
+
 # Get CFLAGS from isc-config.sh
 AC_ARG_VAR([BIND9_CFLAGS],
            [C compiler flags for bind9, overriding isc-config.sh])
@@ -98,6 +110,7 @@ AC_RUN_IFELSE([AC_LANG_PROGRAM([
 #include <dns/version.h>
 ],[ printf("%d\n", dns_libinterface) ])], [
     LIBDNS_VERSION_MAJOR=`./conftest$ac_exeext`
+    AC_MSG_RESULT([$LIBDNS_VERSION_MAJOR])
     AC_DEFINE_UNQUOTED([LIBDNS_VERSION_MAJOR], [$LIBDNS_VERSION_MAJOR],
     [Define libdns version])], [
     AC_RUN_IFELSE([AC_LANG_PROGRAM([[
@@ -111,9 +124,24 @@ AC_RUN_IFELSE([AC_LANG_PROGRAM([
 	return !(scanned == 3 && major == 9);
     ]])], [
     LIBDNS_VERSION_MAJOR=`./conftest$ac_exeext`
+    AC_MSG_RESULT([$LIBDNS_VERSION_MAJOR])
     AC_DEFINE_UNQUOTED([LIBDNS_VERSION_MAJOR], [$LIBDNS_VERSION_MAJOR],
     [Define libdns version])],
-    [AC_MSG_ERROR([Can't obtain libdns version.])])
+    [
+	LIBDNS_PATH="${libdir}/libdns.so"
+	if test -L "$LIBDNS_PATH" ; then
+		LIBDNS_VERSION_MAJOR=$(ls -l "$LIBDNS_PATH" | sed -e 's/^.*->\s*libdns-9\.\([[0-9]]\+\)\.\([[0-9]]\+\).*\.so/\1 \2/' -e t -e d | xargs printf "%02d%02d")
+	else
+		AC_MSG_ERROR([Can't obtain libdns version1.])
+	fi
+	if test -z "$LIBDNS_VERSION_MAJOR" || test "$LIBDNS_VERSION_MAJOR" -lt 1200; then
+		AC_MSG_ERROR([Can't obtain libdns version ($LIBDNS_VERSION_MAJOR).])
+	else
+		AC_DEFINE_UNQUOTED([LIBDNS_VERSION_MAJOR], [$LIBDNS_VERSION_MAJOR],
+    			[Define libdns version])
+		AC_MSG_RESULT([$LIBDNS_VERSION_MAJOR])
+	fi
+    ])
 ], [AC_MSG_ERROR([Cross compiling is not supported.])]
 )
 
@@ -137,6 +165,10 @@ AC_CHECK_LIB([dns], [dns_db_setservestalettl],
   [AC_DEFINE([HAVE_DNS_SERVESTALE], 1, [Define if dns library provides dns_db_setservestalettl])]
 )
 
+AC_CHECK_LIB([dns], [dns_result_totext],
+  [AC_DEFINE([HAVE_DNS_RESULT_TOTEXT], 1, [Define if dns library provides dns_result_totext])]
+)
+
 dnl Older autoconf (2.59, for example) doesn't define docdir
 [[ ! -n "$docdir" ]] && docdir='${datadir}/doc/${PACKAGE_TARNAME}'
 AC_SUBST([docdir])
diff --git a/src/acl.c b/src/acl.c
index ba89abc..8f5f33f 100644
--- a/src/acl.c
+++ b/src/acl.c
@@ -66,6 +66,10 @@ const enum_txt_assoc_t acl_type_txts[] = {
 		}							\
 	} while (0)
 
+#if LIBDNS_VERSION_MAJOR < 1700
+typedef dns_rdatatype_t dns_ssuruletype_t;
+#endif
+
 static isc_result_t ATTR_NONNULLS ATTR_CHECKRESULT
 get_mode(const cfg_obj_t *obj, bool *value)
 {
@@ -184,14 +188,14 @@ count_list_elements(const cfg_obj_t *list)
 }
 
 static isc_result_t ATTR_NONNULLS ATTR_CHECKRESULT
-get_types(isc_mem_t *mctx, const cfg_obj_t *obj, dns_rdatatype_t **typesp,
+get_types(isc_mem_t *mctx, const cfg_obj_t *obj, dns_ssuruletype_t **typesp,
 	  unsigned int *np)
 {
 	isc_result_t result = ISC_R_SUCCESS;
 	unsigned int i;
 	unsigned int n = 0;
 	const cfg_listelt_t *el;
-	dns_rdatatype_t *types = NULL;
+	dns_ssuruletype_t *types = NULL;
 
 	REQUIRE(obj != NULL);
 	REQUIRE(typesp != NULL && *typesp == NULL);
@@ -201,7 +205,7 @@ get_types(isc_mem_t *mctx, const cfg_obj_t *obj, dns_rdatatype_t **typesp,
 
 	n = count_list_elements(obj);
 	if (n > 0) {
-		types = isc_mem_get(mctx, n * sizeof(dns_rdatatype_t));
+		types = isc_mem_get(mctx, n * sizeof(dns_ssuruletype_t));
 	}
 	i = 0;
 	for (el = cfg_list_first(obj); el != NULL; el = cfg_list_next(el)) {
@@ -216,7 +220,12 @@ get_types(isc_mem_t *mctx, const cfg_obj_t *obj, dns_rdatatype_t **typesp,
 		DE_CONST(str, r.base);
 		r.length = strlen(str);
 
+#if LIBDNS_VERSION_MAJOR < 1700
 		result = dns_rdatatype_fromtext(&types[i++], &r);
+#else
+		types[i].max = 0;
+		result = dns_rdatatype_fromtext(&types[i++].type, &r);
+#endif
 		if (result != ISC_R_SUCCESS) {
 			log_error("'%s' is not a valid type", str);
 			goto cleanup;
@@ -229,7 +238,7 @@ get_types(isc_mem_t *mctx, const cfg_obj_t *obj, dns_rdatatype_t **typesp,
 	return result;
 
 cleanup:
-	SAFE_MEM_PUT(mctx, types, n * sizeof(dns_rdatatype_t));
+	SAFE_MEM_PUT(mctx, types, n * sizeof(dns_ssuruletype_t));
 
 	return result;
 }
@@ -281,14 +290,18 @@ acl_configure_zone_ssutable(const char *policy_str, dns_zone_t *zone)
 		goto cleanup;
 	}
 
+#if LIBDNS_VERSION_MAJOR >= 1700
+	dns_ssutable_create(mctx, &table);
+#else
 	CHECK(dns_ssutable_create(mctx, &table));
+#endif
 
 	for (el = cfg_list_first(policy); el != NULL; el = cfg_list_next(el)) {
 		const cfg_obj_t *stmt;
 		bool grant;
 		unsigned int match_type;
 		dns_fixedname_t fname, fident;
-		dns_rdatatype_t *types;
+		dns_ssuruletype_t *types;
 		unsigned int n;
 
 		types = NULL;
@@ -303,9 +316,14 @@ acl_configure_zone_ssutable(const char *policy_str, dns_zone_t *zone)
 		result = get_fixed_name(stmt, "name", &fname);
 		if (result == ISC_R_NOTFOUND &&
 		    match_type == dns_ssumatchtype_subdomain) {
+#if LIBDNS_VERSION_MAJOR >= 1700
+			dns_name_copy(dns_zone_getorigin(zone),
+				      dns_fixedname_initname(&fname));
+#else
 			CHECK(dns_name_copy(dns_zone_getorigin(zone),
 					    dns_fixedname_initname(&fname),
 					    &fname.buffer));
+#endif
 		}
 		else if (result != ISC_R_SUCCESS)
 			goto cleanup;
@@ -324,13 +342,22 @@ acl_configure_zone_ssutable(const char *policy_str, dns_zone_t *zone)
 			CLEANUP_WITH(DNS_R_BADNAME);
 		}
 
+#if LIBDNS_VERSION_MAJOR >= 1700
+		result = ISC_R_SUCCESS;
+		dns_ssutable_addrule(table, grant,
+				     dns_fixedname_name(&fident),
+				     match_type,
+				     dns_fixedname_name(&fname),
+				     n, types);
+#else
 		result = dns_ssutable_addrule(table, grant,
 					      dns_fixedname_name(&fident),
 					      match_type,
 					      dns_fixedname_name(&fname),
 					      n, types);
+#endif
 
-		SAFE_MEM_PUT(mctx, types, n * sizeof(dns_rdatatype_t));
+		SAFE_MEM_PUT(mctx, types, n * sizeof(dns_ssuruletype_t));
 		if (result != ISC_R_SUCCESS)
 			goto cleanup;
 
diff --git a/src/empty_zones.c b/src/empty_zones.c
index e3e4545..03f16fc 100644
--- a/src/empty_zones.c
+++ b/src/empty_zones.c
@@ -15,6 +15,8 @@
 
 #if LIBDNS_VERSION_MAJOR < 1600
 #define dns_name_copynf(src, dst) dns_name_copy((src), (dst), NULL)
+#elif LIBDNS_VERSION_MAJOR >= 1714
+#define dns_name_copynf(src, dst) dns_name_copy((src), (dst))
 #endif
 
 /**
diff --git a/src/ldap_convert.c b/src/ldap_convert.c
index dc6e32b..f8e4fba 100644
--- a/src/ldap_convert.c
+++ b/src/ldap_convert.c
@@ -29,6 +29,8 @@
 
 #if LIBDNS_VERSION_MAJOR < 1600
 #define dns_name_copynf(src, dst) dns_name_copy((src), (dst), NULL)
+#elif LIBDNS_VERSION_MAJOR >= 1714
+#define dns_name_copynf(src, dst) dns_name_copy((src), (dst))
 #endif
 
 /**
diff --git a/src/ldap_driver.c b/src/ldap_driver.c
index e9f1005..a8f01b6 100644
--- a/src/ldap_driver.c
+++ b/src/ldap_driver.c
@@ -11,11 +11,13 @@
 #include <isc/buffer.h>
 #include <isc/commandline.h>
 #include <isc/hash.h>
-#include <isc/lib.h>
 #include <isc/mem.h>
 #include <isc/once.h>
 #include <isc/refcount.h>
 #include <isc/util.h>
+#if LIBDNS_VERSION_MAJOR < 1617
+#include <isc/lib.h>
+#endif
 
 #include <dns/db.h>
 #include <dns/diff.h>
@@ -238,6 +240,7 @@ endload(dns_db_t *db, dns_rdatacallbacks_t *callbacks) {
 	return ISC_R_SUCCESS;
 }
 
+#if LIBDNS_VERSION_MAJOR < 1719
 static isc_result_t
 serialize(dns_db_t *db, dns_dbversion_t *version, FILE *file)
 {
@@ -247,6 +250,7 @@ serialize(dns_db_t *db, dns_dbversion_t *version, FILE *file)
 
 	return dns_db_serialize(ldapdb->rbtdb, version, file);
 }
+#endif
 
 /* !!! This could be required for optimizations (like on-disk cache). */
 static isc_result_t
@@ -635,6 +639,7 @@ issecure(dns_db_t *db)
 	return dns_db_issecure(ldapdb->rbtdb);
 }
 
+#if LIBDNS_VERSION_MAJOR < 1721
 static unsigned int
 nodecount(dns_db_t *db)
 {
@@ -644,6 +649,17 @@ nodecount(dns_db_t *db)
 
 	return dns_db_nodecount(ldapdb->rbtdb);
 }
+#else
+static unsigned int
+nodecount(dns_db_t *db, dns_dbtree_t tree)
+{
+	ldapdb_t *ldapdb = (ldapdb_t *) db;
+
+	REQUIRE(VALID_LDAPDB(ldapdb));
+
+	return dns_db_nodecount(ldapdb->rbtdb, tree);
+}
+#endif
 
 /**
  * Return TRUE, because database does not need to be loaded from disk
@@ -896,7 +912,7 @@ getservestalettl(dns_db_t *db, dns_ttl_t *ttl) {
 }
 #endif
 
-#if LIBDNS_VERSION_MAJOR >= 1606
+#if LIBDNS_VERSION_MAJOR >= 1606 && LIBDNS_VERSION_MAJOR < 1720
 /* Used for cache size adjustments, called by dns_cache_setcachesize.
  * Just proxy to rbtdb implementation. */
 static isc_result_t
@@ -914,7 +930,9 @@ static dns_dbmethods_t ldapdb_methods = {
 	detach,
 	beginload,
 	endload,
+#if LIBDNS_VERSION_MAJOR < 1719
 	serialize, /* see dns_db_serialize(), implementation is not mandatory */
+#endif
 	dump,
 	currentversion,
 	newversion,
@@ -966,7 +984,7 @@ static dns_dbmethods_t ldapdb_methods = {
 #if LIBDNS_VERSION_MAJOR >= 1600
 	NULL, /* setgluecachestats */
 #endif
-#if LIBDNS_VERSION_MAJOR >= 1606
+#if LIBDNS_VERSION_MAJOR >= 1606 && LIBDNS_VERSION_MAJOR < 1720
 	adjusthashsize, /* adjusthashsize */
 #endif
 };
diff --git a/src/ldap_helper.c b/src/ldap_helper.c
index 97a1859..7ea3df9 100644
--- a/src/ldap_helper.c
+++ b/src/ldap_helper.c
@@ -5,6 +5,7 @@
 #include "dyndb-config.h"
 #define HAVE_TLS 1
 #define HAVE_THREAD_LOCAL 1
+#include <threads.h>
 
 #include <dns/dyndb.h>
 #include <dns/diff.h>
@@ -3760,7 +3761,7 @@ static void ATTR_NONNULLS
 update_zone(isc_task_t *task, isc_event_t *event)
 {
 	ldap_syncreplevent_t *pevent = (ldap_syncreplevent_t *)event;
-	isc_result_t result ;
+	isc_result_t result = ISC_R_SUCCESS;
 	ldap_instance_t *inst = pevent->inst;
 	isc_mem_t *mctx;
 	dns_name_t prevname;
diff --git a/src/mldap.c b/src/mldap.c
index 3a76153..2c41d5d 100644
--- a/src/mldap.c
+++ b/src/mldap.c
@@ -44,6 +44,9 @@
 #else
 /* BIND 9.16+ */
 #define REFCOUNT_CAST(n) ((isc_refcount_t) (n))
+#if LIBDNS_VERSION_MAJOR >= 1714
+#define dns_name_copynf(src, dst) dns_name_copy((src), (dst))
+#endif
 #endif
 
 /* name "ldap.uuid." */
@@ -495,7 +498,7 @@ mldap_iter_deadnodes_next(mldapdb_t *mldap, metadb_iter_t **iterp,
 	isc_result_t result;
 	dns_dbnode_t *rbt_node = NULL;
 	metadb_iter_t *iter = NULL;
-	uint32_t node_generation;
+	uint32_t node_generation = 0;
 	uint32_t cur_generation;
 	metadb_node_t metadb_node;
 	DECLARE_BUFFERED_NAME(name);
diff --git a/src/str.h b/src/str.h
index a4061c0..e716361 100644
--- a/src/str.h
+++ b/src/str.h
@@ -17,7 +17,7 @@
 #define _STR_MEM_FLARG_PASS	, file, line
 #else
 #define _STR_MEM_FILELINE
-#define _STR_MEM_FLAG
+#define _STR_MEM_FLARG
 #define _STR_MEM_FLARG_PASS
 #endif
 
diff --git a/src/syncptr.c b/src/syncptr.c
index 8824679..7d6047d 100644
--- a/src/syncptr.c
+++ b/src/syncptr.c
@@ -34,6 +34,8 @@
 
 #if LIBDNS_VERSION_MAJOR < 1600
 #define dns_name_copynf(src, dst) dns_name_copy((src), (dst), NULL)
+#elif LIBDNS_VERSION_MAJOR >= 1714
+#define dns_name_copynf(src, dst) dns_name_copy((src), (dst))
 #endif
 
 /*
diff --git a/src/syncrepl.c b/src/syncrepl.c
index 3baeb78..0bee09a 100644
--- a/src/syncrepl.c
+++ b/src/syncrepl.c
@@ -129,7 +129,7 @@ void
 finish(isc_task_t *task, isc_event_t *event) {
 	isc_result_t result = ISC_R_SUCCESS;
 	sync_barrierev_t *bev = NULL;
-	sync_state_t new_state;
+	sync_state_t new_state = sync_configinit;
 
 	REQUIRE(event != NULL);
 	UNUSED(task);
@@ -496,8 +496,8 @@ isc_result_t
 sync_barrier_wait(sync_ctx_t *sctx, ldap_instance_t *inst) {
 	isc_event_t *ev = NULL;
 	sync_barrierev_t *bev = NULL;
-	sync_state_t barrier_state;
-	sync_state_t final_state;
+	sync_state_t barrier_state = sync_configinit;
+	sync_state_t final_state = sync_configinit;
 	task_element_t *taskel = NULL;
 	task_element_t *next_taskel = NULL;
 
diff --git a/src/util.h b/src/util.h
index 7a8555b..f4b08f9 100644
--- a/src/util.h
+++ b/src/util.h
@@ -15,9 +15,14 @@
 #include <dns/result.h>
 
 #include "log.h"
+#include "dyndb-config.h"
 
 extern bool verbose_checks; /* from settings.c */
 
+#ifndef HAVE_DNS_RESULT_TOTEXT
+#define dns_result_totext isc_result_totext
+#endif
+
 #define CLEANUP_WITH(result_code)				\
 	do {							\
 		result = (result_code);				\
