From fc47974ef4b7eb61539acf8831789f59d807ad0d Mon Sep 17 00:00:00 2001
From: Lubos Slovak <lubos.slovak@nic.cz>
Date: Thu, 4 Aug 2011 14:29:02 +0200
Subject: [PATCH] Reorganized libknot

---
 Knot.files                                    | 78 ++++++++--------
 libknot/Makefile.am                           | 90 +++++++++----------
 libknot/consts.h                              |  2 +-
 libknot/dname.c                               | 10 +--
 libknot/edns.c                                |  6 +-
 libknot/edns.h                                |  2 +-
 libknot/hash/cuckoo-hash-table.c              |  4 +-
 libknot/hash/universal-system.c               |  2 +-
 libknot/libknot.h                             | 18 ++--
 libknot/{ => nameserver}/name-server.c        | 16 ++--
 libknot/{ => nameserver}/name-server.h        |  5 +-
 libknot/nsec3.c                               | 10 +--
 libknot/{ => packet}/packet.c                 | 10 +--
 libknot/{ => packet}/packet.h                 |  1 -
 libknot/{ => packet}/query.c                  |  6 +-
 libknot/{ => packet}/query.h                  |  2 +-
 libknot/{ => packet}/response.c               | 14 +--
 libknot/{ => packet}/response.h               |  0
 libknot/{ => packet}/response2.c              | 12 +--
 libknot/{ => packet}/response2.h              |  2 +-
 libknot/rdata.c                               | 10 +--
 libknot/rdata.h                               |  2 +-
 libknot/rrset.c                               |  4 +-
 libknot/{ => updates}/changesets.c            |  4 +-
 libknot/{ => updates}/changesets.h            |  0
 libknot/{ => updates}/xfr-in.c                | 16 ++--
 libknot/{ => updates}/xfr-in.h                |  8 +-
 libknot/{ => util}/debug.c                    |  4 +-
 libknot/{ => util}/debug.h                    |  6 +-
 libknot/{ => util}/descriptor.c               |  0
 libknot/{ => util}/descriptor.h               |  0
 libknot/{ => util}/error.c                    |  4 +-
 libknot/{ => util}/error.h                    |  0
 libknot/{ => util}/tolower.c                  |  2 +-
 libknot/{ => util}/tolower.h                  |  0
 libknot/{ => util}/utils.c                    |  2 +-
 libknot/{ => util}/utils.h                    |  0
 libknot/{ => util}/wire.h                     |  2 +-
 libknot/{ => zone}/dname-table.c              |  4 +-
 libknot/{ => zone}/dname-table.h              |  0
 libknot/{ => zone}/node.c                     |  6 +-
 libknot/{ => zone}/node.h                     |  0
 libknot/{ => zone}/zone-contents.c            |  6 +-
 libknot/{ => zone}/zone-contents.h            |  4 +-
 libknot/{ => zone}/zone-tree.c                |  4 +-
 libknot/{ => zone}/zone-tree.h                |  2 +-
 libknot/{ => zone}/zone.c                     | 14 +--
 libknot/{ => zone}/zone.h                     |  6 +-
 libknot/{ => zone}/zonedb.c                   | 10 +--
 libknot/{ => zone}/zonedb.h                   |  4 +-
 src/knot/conf/conf.h                          |  2 +-
 src/knot/server/notify.c                      | 10 +--
 src/knot/server/notify.h                      |  8 +-
 src/knot/server/server.c                      |  6 +-
 src/knot/server/server.h                      |  4 +-
 src/knot/server/tcp-handler.c                 |  4 +-
 src/knot/server/udp-handler.c                 |  6 +-
 src/knot/server/xfr-handler.c                 |  6 +-
 src/knot/server/xfr-handler.h                 |  2 +-
 src/knot/server/zones.c                       | 16 ++--
 src/knot/server/zones.h                       |  8 +-
 src/knot/zone/zone-dump-text.h                |  4 +-
 src/knot/zone/zone-dump.c                     |  4 +-
 src/knot/zone/zone-dump.h                     |  2 +-
 src/knot/zone/zone-load.c                     |  2 +-
 src/knot/zone/zone-load.h                     |  2 +-
 src/tests/libknot/libknot/dname_table_tests.c |  4 +-
 src/tests/libknot/libknot/dname_tests.c       |  2 +-
 src/tests/libknot/libknot/node_tests.c        |  4 +-
 src/tests/libknot/libknot/nsec3_tests.c       |  4 +-
 src/tests/libknot/libknot/packet_tests.c      |  6 +-
 src/tests/libknot/libknot/query_tests.c       |  8 +-
 src/tests/libknot/libknot/rdata_tests.c       |  6 +-
 src/tests/libknot/libknot/response2_tests.c   |  8 +-
 src/tests/libknot/libknot/response_tests.c    |  6 +-
 src/tests/libknot/libknot/rrset_tests.c       |  8 +-
 src/tests/libknot/libknot/zone_tests.c        |  8 +-
 .../realdata/libknot/node_tests_realdata.c    |  4 +-
 .../realdata/libknot/packet_tests_realdata.c  |  6 +-
 .../realdata/libknot/rdata_tests_realdata.c   |  6 +-
 .../libknot/response2_tests_realdata.c        |  6 +-
 .../libknot/response_tests_realdata.c         |  4 +-
 .../realdata/libknot/rrset_tests_realdata.c   |  8 +-
 .../realdata/libknot/zone_tests_realdata.c    |  6 +-
 .../realdata/libknot_tests_loader_realdata.c  |  2 +-
 src/zcompile/parser-descriptor.h              |  2 +-
 src/zcompile/parser-util.c                    |  4 +-
 src/zcompile/parser-util.h                    |  2 +-
 src/zcompile/tests/zcompile_tests.c           |  4 +-
 src/zcompile/zcompile.h                       |  8 +-
 src/zcompile/zparser.y                        |  2 +-
 91 files changed, 313 insertions(+), 315 deletions(-)
 rename libknot/{ => nameserver}/name-server.c (99%)
 rename libknot/{ => nameserver}/name-server.h (99%)
 rename libknot/{ => packet}/packet.c (99%)
 rename libknot/{ => packet}/packet.h (99%)
 rename libknot/{ => packet}/query.c (97%)
 rename libknot/{ => packet}/query.h (98%)
 rename libknot/{ => packet}/response.c (99%)
 rename libknot/{ => packet}/response.h (100%)
 rename libknot/{ => packet}/response2.c (99%)
 rename libknot/{ => packet}/response2.h (99%)
 rename libknot/{ => updates}/changesets.c (99%)
 rename libknot/{ => updates}/changesets.h (100%)
 rename libknot/{ => updates}/xfr-in.c (99%)
 rename libknot/{ => updates}/xfr-in.h (97%)
 rename libknot/{ => util}/debug.c (99%)
 rename libknot/{ => util}/debug.h (98%)
 rename libknot/{ => util}/descriptor.c (100%)
 rename libknot/{ => util}/descriptor.h (100%)
 rename libknot/{ => util}/error.c (97%)
 rename libknot/{ => util}/error.h (100%)
 rename libknot/{ => util}/tolower.c (99%)
 rename libknot/{ => util}/tolower.h (100%)
 rename libknot/{ => util}/utils.c (99%)
 rename libknot/{ => util}/utils.h (100%)
 rename libknot/{ => util}/wire.h (99%)
 rename libknot/{ => zone}/dname-table.c (99%)
 rename libknot/{ => zone}/dname-table.h (100%)
 rename libknot/{ => zone}/node.c (99%)
 rename libknot/{ => zone}/node.h (100%)
 rename libknot/{ => zone}/zone-contents.c (99%)
 rename libknot/{ => zone}/zone-contents.h (99%)
 rename libknot/{ => zone}/zone-tree.c (99%)
 rename libknot/{ => zone}/zone-tree.h (99%)
 rename libknot/{ => zone}/zone.c (96%)
 rename libknot/{ => zone}/zone.h (97%)
 rename libknot/{ => zone}/zonedb.c (98%)
 rename libknot/{ => zone}/zonedb.h (98%)

diff --git a/Knot.files b/Knot.files
index 9eaabd1629..65c64a1e26 100644
--- a/Knot.files
+++ b/Knot.files
@@ -6,62 +6,62 @@ Doxyfile.devel
 configure.ac
 tests/querytcp.c
 libknot/Makefile.am
+libknot/libknot.h
 libknot/common.h
 libknot/dname.h
 libknot/dname.c
 libknot/rrset.h
 libknot/rrset.c
-libknot/error.c
-libknot/error.h
 libknot/rdata.h
 libknot/rdata.c
-libknot/node.h
-libknot/node.c
-libknot/consts.h
-libknot/descriptor.h
-libknot/descriptor.c
-libknot/zone.h
-libknot/zone.c
-libknot/packet.h
-libknot/packet.c
-libknot/query.h
-libknot/query.c
-libknot/response2.h
-libknot/response2.c
-libknot/response.h
-libknot/wire.h
-libknot/response.c
 libknot/edns.h
 libknot/edns.c
-libknot/utils.h
-libknot/utils.c
-libknot/zonedb.h
-libknot/zonedb.c
-libknot/debug.h
-libknot/debug.c
-libknot/libknot.h
-libknot/tolower.h
-libknot/tolower.c
 libknot/nsec3.h
 libknot/nsec3.c
-libknot/changesets.h
-libknot/changesets.c
-libknot/zone-contents.c
-libknot/zone-contents.h
-libknot/zone-tree.h
-libknot/zone-tree.c
-libknot/xfr-in.h
-libknot/xfr-in.c
-libknot/name-server.c
-libknot/name-server.h
-libknot/dname-table.h
-libknot/dname-table.c
+libknot/consts.h
 libknot/hash/cuckoo-hash-table.c
 libknot/hash/cuckoo-hash-table.h
 libknot/hash/hash-functions.c
 libknot/hash/hash-functions.h
 libknot/hash/universal-system.c
 libknot/hash/universal-system.h
+libknot/nameserver/name-server.c
+libknot/nameserver/name-server.h
+libknot/packet/packet.h
+libknot/packet/packet.c
+libknot/packet/query.h
+libknot/packet/query.c
+libknot/packet/response2.h
+libknot/packet/response2.c
+libknot/packet/response.h
+libknot/packet/response.c
+libknot/updates/changesets.h
+libknot/updates/changesets.c
+libknot/updates/xfr-in.h
+libknot/updates/xfr-in.c
+libknot/util/wire.h
+libknot/util/debug.h
+libknot/util/debug.c
+libknot/util/tolower.h
+libknot/util/tolower.c
+libknot/util/utils.h
+libknot/util/utils.c
+libknot/util/descriptor.h
+libknot/util/descriptor.c
+libknot/util/error.c
+libknot/util/error.h
+libknot/zone/zonedb.h
+libknot/zone/zonedb.c
+libknot/zone/node.h
+libknot/zone/node.c
+libknot/zone/zone.h
+libknot/zone/zone.c
+libknot/zone/zone-contents.c
+libknot/zone/zone-contents.h
+libknot/zone/zone-tree.h
+libknot/zone/zone-tree.c
+libknot/zone/dname-table.h
+libknot/zone/dname-table.c
 src/Makefile.am
 src/common/slab/malloc.c
 src/common/slab/malloc.h
diff --git a/libknot/Makefile.am b/libknot/Makefile.am
index b449f5a138..2afb6bbf39 100644
--- a/libknot/Makefile.am
+++ b/libknot/Makefile.am
@@ -43,59 +43,59 @@ libknot_common_SOURCES = \
 	common/errors.h				\
 	common/errors.c
 
-libknot_la_SOURCES =			\
-	$(libknot_common_SOURCES)	\
+libknot_la_SOURCES =				\
+	$(libknot_common_SOURCES)		\
+	util/error.c				\
+	util/utils.c				\
+	util/debug.c				\
+	util/debug.h				\
+	util/utils.h				\
+	util/descriptor.c			\
+	util/tolower.h				\
+	util/tolower.c				\
+	util/descriptor.h			\
+	util/wire.h				\
+	packet/query.c				\
+	packet/response2.c			\
+	packet/response.c			\
+	packet/packet.c				\
+	packet/packet.h				\
+	packet/query.h				\
+	packet/response2.h			\
+	packet/response.h			\
+	zone/zone.c				\
+	zone/zone-contents.c			\
+	zone/zone-tree.c			\
+	zone/zone-tree.h			\
+	zone/node.h				\
+	zone/zone.h				\
+	zone/zone-contents.h			\
+	zone/zonedb.c				\
+	zone/zonedb.h				\
+	zone/node.c				\
+	zone/dname-table.h			\
+	zone/dname-table.c			\
+	hash/hash-functions.c			\
+	hash/cuckoo-hash-table.c		\
+	hash/universal-system.c			\
+	hash/universal-system.h			\
+	hash/cuckoo-hash-table.h		\
+	hash/hash-functions.h			\
+	nameserver/name-server.h		\
+	nameserver/name-server.c		\
+	updates/changesets.h			\
+	updates/changesets.c			\
+	updates/xfr-in.h			\
+	updates/xfr-in.c			\
 	edns.c				\
-	error.c				\
-	utils.c				\
 	rrset.c				\
 	dname.c				\
-	node.c				\
-	packet.c			\
-	query.c				\
-	response2.c			\
-	response.c			\
-	zone.c				\
-	zone-contents.c			\
-	zonedb.c			\
-	debug.c				\
-	zone-tree.c			\
-	zone-tree.h			\
 	rdata.c				\
-	descriptor.c			\
 	nsec3.c				\
-	dname-table.c			\
-	hash/hash-functions.c		\
-	hash/cuckoo-hash-table.c	\
-	hash/universal-system.c		\
-	hash/universal-system.h		\
-	hash/cuckoo-hash-table.h	\
-	hash/hash-functions.h		\
-	zonedb.h			\
 	consts.h			\
-	node.h				\
 	edns.h				\
-	zone.h				\
-	zone-contents.h			\
 	rdata.h				\
-	descriptor.h			\
 	libknot.h			\
-	tolower.h			\
-	tolower.c			\
 	dname.h				\
-	packet.h			\
-	query.h				\
-	response2.h			\
-	response.h			\
 	rrset.h				\
-	utils.h				\
-	wire.h				\
-	debug.h				\
-	nsec3.h				\
-	changesets.h			\
-	changesets.c			\
-	xfr-in.h			\
-	xfr-in.c			\
-	name-server.h			\
-	name-server.c			\
-	dname-table.h
+	nsec3.h				
diff --git a/libknot/consts.h b/libknot/consts.h
index cbf00b55ed..cc9f0c161f 100644
--- a/libknot/consts.h
+++ b/libknot/consts.h
@@ -29,7 +29,7 @@
 #define _KNOT_CONSTS_H_
 
 #include <stdint.h>
-#include "descriptor.h"
+#include "util/descriptor.h"
 
 /*
  * OPCODEs
diff --git a/libknot/dname.c b/libknot/dname.c
index 8ab83fd6f8..d9ded162dc 100644
--- a/libknot/dname.c
+++ b/libknot/dname.c
@@ -22,13 +22,13 @@
 #include <ctype.h>	// tolower()
 
 #include "common.h"
-#include "error.h"
+#include "util/error.h"
 #include "dname.h"
 #include "consts.h"
-#include "tolower.h"
-#include "debug.h"
-#include "utils.h"
-#include "wire.h"
+#include "util/tolower.h"
+#include "util/debug.h"
+#include "util/utils.h"
+#include "util/wire.h"
 
 /*! \todo dnames allocated from TLS cache will be discarded after thread
  *        termination. This shouldn't happpen.
diff --git a/libknot/edns.c b/libknot/edns.c
index 0066806e93..334c29d431 100644
--- a/libknot/edns.c
+++ b/libknot/edns.c
@@ -20,9 +20,9 @@
 
 #include "edns.h"
 #include "common.h"
-#include "descriptor.h"
-#include "debug.h"
-#include "error.h"
+#include "util/descriptor.h"
+#include "util/debug.h"
+#include "util/error.h"
 
 /*! \brief Various EDNS constatns. */
 enum knot_edns_consts {
diff --git a/libknot/edns.h b/libknot/edns.h
index 60b9b7d8c2..4b786cdfac 100644
--- a/libknot/edns.h
+++ b/libknot/edns.h
@@ -29,7 +29,7 @@
 
 #include <stdint.h>
 
-#include "utils.h"
+#include "util/utils.h"
 #include "rrset.h"
 
 /*----------------------------------------------------------------------------*/
diff --git a/libknot/hash/cuckoo-hash-table.c b/libknot/hash/cuckoo-hash-table.c
index 35e70727a1..7fa0fa592a 100644
--- a/libknot/hash/cuckoo-hash-table.c
+++ b/libknot/hash/cuckoo-hash-table.c
@@ -24,9 +24,9 @@
 
 #include <urcu.h>
 
-#include "utils.h"
+#include "util/utils.h"
 #include "common.h"
-#include "debug.h"
+#include "util/debug.h"
 #include "hash/cuckoo-hash-table.h"
 #include "hash/hash-functions.h"
 #include "common/dynamic-array.h"
diff --git a/libknot/hash/universal-system.c b/libknot/hash/universal-system.c
index 4d15018af7..16809f1e08 100644
--- a/libknot/hash/universal-system.c
+++ b/libknot/hash/universal-system.c
@@ -23,7 +23,7 @@
 #include <assert.h>
 
 #include "universal-system.h"
-#include "utils.h"
+#include "util/utils.h"
 
 /*----------------------------------------------------------------------------*/
 
diff --git a/libknot/libknot.h b/libknot/libknot.h
index c0a27ffacc..96f064567c 100644
--- a/libknot/libknot.h
+++ b/libknot/libknot.h
@@ -28,20 +28,20 @@
 #define _KNOT_LIBKNOT_H_
 
 #include "consts.h"
-#include "descriptor.h"
+#include "util/descriptor.h"
 #include "dname.h"
 #include "edns.h"
-#include "node.h"
+#include "zone/node.h"
 #include "nsec3.h"
-#include "wire.h"
+#include "util/wire.h"
 #include "rdata.h"
-#include "response2.h"
+#include "packet/response2.h"
 #include "rrset.h"
-#include "tolower.h"
-#include "utils.h"
-#include "zone.h"
-#include "zonedb.h"
-#include "error.h"
+#include "util/tolower.h"
+#include "util/utils.h"
+#include "zone/zone.h"
+#include "zone/zonedb.h"
+#include "util/error.h"
 
 #endif
 
diff --git a/libknot/name-server.c b/libknot/nameserver/name-server.c
similarity index 99%
rename from libknot/name-server.c
rename to libknot/nameserver/name-server.c
index e7288601a6..c1ca4b5d26 100644
--- a/libknot/name-server.c
+++ b/libknot/nameserver/name-server.c
@@ -21,19 +21,19 @@
 
 #include <urcu.h>
 
-#include "name-server.h"
-#include "xfr-in.h"
+#include "nameserver/name-server.h"
+#include "updates/xfr-in.h"
 
-#include "error.h"
+#include "util/error.h"
 #include "libknot.h"
-#include "debug.h"
-#include "packet.h"
-#include "response2.h"
-#include "query.h"
+#include "util/debug.h"
+#include "packet/packet.h"
+#include "packet/response2.h"
+#include "packet/query.h"
 #include "consts.h"
 // #include "knot/zone/zone-dump-text.h"
 // #include "knot/zone/zone-dump.h"
-#include "changesets.h"
+#include "updates/changesets.h"
 
 /*----------------------------------------------------------------------------*/
 
diff --git a/libknot/name-server.h b/libknot/nameserver/name-server.h
similarity index 99%
rename from libknot/name-server.h
rename to libknot/nameserver/name-server.h
index 75f431adae..2a9120fb46 100644
--- a/libknot/name-server.h
+++ b/libknot/nameserver/name-server.h
@@ -38,11 +38,10 @@
 #include <stdint.h>
 #include <string.h>
 
-#include "zonedb.h"
+#include "zone/zonedb.h"
 #include "edns.h"
-//#include "response.h"
 #include "consts.h"
-#include "packet.h"
+#include "packet/packet.h"
 #include "common/sockaddr.h"
 
 struct conf_t;
diff --git a/libknot/nsec3.c b/libknot/nsec3.c
index 3b30b60cf0..a92b366d47 100644
--- a/libknot/nsec3.c
+++ b/libknot/nsec3.c
@@ -24,11 +24,11 @@
 
 #include "nsec3.h"
 #include "common.h"
-#include "descriptor.h"
-#include "utils.h"
-#include "tolower.h"
-#include "error.h"
-#include "debug.h"
+#include "util/descriptor.h"
+#include "util/utils.h"
+#include "util/tolower.h"
+#include "util/error.h"
+#include "util/debug.h"
 
 /*----------------------------------------------------------------------------*/
 
diff --git a/libknot/packet.c b/libknot/packet/packet.c
similarity index 99%
rename from libknot/packet.c
rename to libknot/packet/packet.c
index dbfce0f0f2..82947355d8 100644
--- a/libknot/packet.c
+++ b/libknot/packet/packet.c
@@ -16,12 +16,12 @@
 
 #include <assert.h>
 
-#include "packet.h"
-#include "error.h"
-#include "debug.h"
+#include "packet/packet.h"
+#include "util/error.h"
+#include "util/debug.h"
 #include "common.h"
-#include "descriptor.h"
-#include "wire.h"
+#include "util/descriptor.h"
+#include "util/wire.h"
 
 /*----------------------------------------------------------------------------*/
 
diff --git a/libknot/packet.h b/libknot/packet/packet.h
similarity index 99%
rename from libknot/packet.h
rename to libknot/packet/packet.h
index 9674b43f92..fd3d55f828 100644
--- a/libknot/packet.h
+++ b/libknot/packet/packet.h
@@ -33,7 +33,6 @@
 #include "dname.h"
 #include "rrset.h"
 #include "edns.h"
-//#include "response.h"
 
 /*----------------------------------------------------------------------------*/
 /*!
diff --git a/libknot/query.c b/libknot/packet/query.c
similarity index 97%
rename from libknot/query.c
rename to libknot/packet/query.c
index 342d07853a..43044c5a7f 100644
--- a/libknot/query.c
+++ b/libknot/packet/query.c
@@ -14,10 +14,10 @@
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "query.h"
+#include "packet/query.h"
 
-#include "error.h"
-#include "wire.h"
+#include "util/error.h"
+#include "util/wire.h"
 
 /*----------------------------------------------------------------------------*/
 
diff --git a/libknot/query.h b/libknot/packet/query.h
similarity index 98%
rename from libknot/query.h
rename to libknot/packet/query.h
index d96804aa83..35a5ba5275 100644
--- a/libknot/query.h
+++ b/libknot/packet/query.h
@@ -30,7 +30,7 @@
 #include <stdint.h>
 #include <string.h>
 
-#include "packet.h"
+#include "packet/packet.h"
 #include "dname.h"
 #include "rrset.h"
 #include "edns.h"
diff --git a/libknot/response.c b/libknot/packet/response.c
similarity index 99%
rename from libknot/response.c
rename to libknot/packet/response.c
index 832f933911..4137a0eba5 100644
--- a/libknot/response.c
+++ b/libknot/packet/response.c
@@ -20,15 +20,15 @@
 #include <assert.h>
 
 #include "common.h"
-#include "response.h"
+#include "packet/response.h"
 #include "rrset.h"
-#include "wire.h"
-#include "descriptor.h"
+#include "util/wire.h"
+#include "util/descriptor.h"
 #include "edns.h"
-#include "utils.h"
-#include "node.h"
-#include "error.h"
-#include "debug.h"
+#include "util/utils.h"
+#include "zone/node.h"
+#include "util/error.h"
+#include "util/debug.h"
 
 /*!
  * \brief Default maximum DNS response size
diff --git a/libknot/response.h b/libknot/packet/response.h
similarity index 100%
rename from libknot/response.h
rename to libknot/packet/response.h
diff --git a/libknot/response2.c b/libknot/packet/response2.c
similarity index 99%
rename from libknot/response2.c
rename to libknot/packet/response2.c
index d44e69e3bd..8ab7759c2f 100644
--- a/libknot/response2.c
+++ b/libknot/packet/response2.c
@@ -16,13 +16,13 @@
 
 #include <stdlib.h>
 
-#include "response2.h"
-#include "wire.h"
-#include "descriptor.h"
+#include "packet/response2.h"
+#include "util/wire.h"
+#include "util/descriptor.h"
 #include "common.h"
-#include "error.h"
-#include "debug.h"
-#include "packet.h"
+#include "util/error.h"
+#include "util/debug.h"
+#include "packet/packet.h"
 
 /*----------------------------------------------------------------------------*/
 /*!
diff --git a/libknot/response2.h b/libknot/packet/response2.h
similarity index 99%
rename from libknot/response2.h
rename to libknot/packet/response2.h
index 6435d3977a..f6cd28d519 100644
--- a/libknot/response2.h
+++ b/libknot/packet/response2.h
@@ -30,7 +30,7 @@
 #include <stdint.h>
 #include <string.h>
 
-#include "packet.h"
+#include "packet/packet.h"
 
 #include "dname.h"
 #include "rrset.h"
diff --git a/libknot/rdata.c b/libknot/rdata.c
index d66c9484ab..1d17674a9a 100644
--- a/libknot/rdata.c
+++ b/libknot/rdata.c
@@ -23,12 +23,12 @@
 
 #include "common.h"
 #include "rdata.h"
-#include "descriptor.h"
+#include "util/descriptor.h"
 #include "dname.h"
-#include "error.h"
-#include "node.h"
-#include "utils.h"
-#include "debug.h"
+#include "util/error.h"
+#include "zone/node.h"
+#include "util/utils.h"
+#include "util/debug.h"
 
 /*----------------------------------------------------------------------------*/
 /* Non-API functions                                                          */
diff --git a/libknot/rdata.h b/libknot/rdata.h
index 1804309ed6..9d3d7eae11 100644
--- a/libknot/rdata.h
+++ b/libknot/rdata.h
@@ -32,7 +32,7 @@
 #include <string.h>
 
 #include "dname.h"
-#include "descriptor.h"
+#include "util/descriptor.h"
 
 /*----------------------------------------------------------------------------*/
 /*!
diff --git a/libknot/rrset.c b/libknot/rrset.c
index 524fe08fa5..41f4e5a1ab 100644
--- a/libknot/rrset.c
+++ b/libknot/rrset.c
@@ -22,8 +22,8 @@
 
 #include "common.h"
 #include "rrset.h"
-#include "descriptor.h"
-#include "error.h"
+#include "util/descriptor.h"
+#include "util/error.h"
 
 /*----------------------------------------------------------------------------*/
 /* Non-API functions                                                          */
diff --git a/libknot/changesets.c b/libknot/updates/changesets.c
similarity index 99%
rename from libknot/changesets.c
rename to libknot/updates/changesets.c
index bc005b57f9..2d26f5e952 100644
--- a/libknot/changesets.c
+++ b/libknot/updates/changesets.c
@@ -18,10 +18,10 @@
 #include <stdlib.h>
 #include <assert.h>
 
-#include "changesets.h"
+#include "updates/changesets.h"
 
 #include "rrset.h"
-#include "error.h"
+#include "util/error.h"
 
 static const size_t KNOT_CHANGESET_COUNT = 5;
 static const size_t KNOT_CHANGESET_STEP = 5;
diff --git a/libknot/changesets.h b/libknot/updates/changesets.h
similarity index 100%
rename from libknot/changesets.h
rename to libknot/updates/changesets.h
diff --git a/libknot/xfr-in.c b/libknot/updates/xfr-in.c
similarity index 99%
rename from libknot/xfr-in.c
rename to libknot/updates/xfr-in.c
index 454d0f0c1d..6fdd6799d3 100644
--- a/libknot/xfr-in.c
+++ b/libknot/updates/xfr-in.c
@@ -17,18 +17,18 @@
 #include <assert.h>
 #include <urcu.h>
 
-#include "xfr-in.h"
+#include "updates/xfr-in.h"
 
-#include "name-server.h"
-#include "debug.h"
+#include "nameserver/name-server.h"
+#include "util/debug.h"
 // #include "knot/zone/zone-dump.h"
 // #include "knot/zone/zone-load.h"
-#include "packet.h"
+#include "packet/packet.h"
 #include "dname.h"
-#include "zone.h"
-#include "query.h"
-#include "error.h"
-#include "changesets.h"
+#include "zone/zone.h"
+#include "packet/query.h"
+#include "util/error.h"
+#include "updates/changesets.h"
 
 /*----------------------------------------------------------------------------*/
 /* Non-API functions                                                          */
diff --git a/libknot/xfr-in.h b/libknot/updates/xfr-in.h
similarity index 97%
rename from libknot/xfr-in.h
rename to libknot/updates/xfr-in.h
index e6ba4f58f0..a350df87b6 100644
--- a/libknot/xfr-in.h
+++ b/libknot/updates/xfr-in.h
@@ -31,10 +31,10 @@
 #include <string.h>
 
 #include "dname.h"
-#include "zone.h"
-#include "packet.h"
-#include "name-server.h"
-#include "changesets.h"
+#include "zone/zone.h"
+#include "packet/packet.h"
+#include "nameserver/name-server.h"
+#include "updates/changesets.h"
 
 /*!
  * \brief Creates normal query for the given zone name and the SOA type.
diff --git a/libknot/debug.c b/libknot/util/debug.c
similarity index 99%
rename from libknot/debug.c
rename to libknot/util/debug.c
index fb59fb2a2e..87eefc2c75 100644
--- a/libknot/debug.c
+++ b/libknot/util/debug.c
@@ -20,8 +20,8 @@
 #include <assert.h>
 #include <stdlib.h>
 
-#include "utils.h"
-#include "debug.h"
+#include "util/utils.h"
+#include "util/debug.h"
 #include "libknot.h"
 #include "common/print.h"
 
diff --git a/libknot/debug.h b/libknot/util/debug.h
similarity index 98%
rename from libknot/debug.h
rename to libknot/util/debug.h
index f2a6916cc8..e660210b41 100644
--- a/libknot/debug.h
+++ b/libknot/util/debug.h
@@ -32,9 +32,9 @@
 #include <stdio.h>
 #include "rdata.h"
 #include "rrset.h"
-#include "node.h"
-#include "zone.h"
-#include "utils.h"
+#include "zone/node.h"
+#include "zone/zone.h"
+#include "util/utils.h"
 #include "common/print.h"
 
 /*!
diff --git a/libknot/descriptor.c b/libknot/util/descriptor.c
similarity index 100%
rename from libknot/descriptor.c
rename to libknot/util/descriptor.c
diff --git a/libknot/descriptor.h b/libknot/util/descriptor.h
similarity index 100%
rename from libknot/descriptor.h
rename to libknot/util/descriptor.h
diff --git a/libknot/error.c b/libknot/util/error.c
similarity index 97%
rename from libknot/error.c
rename to libknot/util/error.c
index 248819dec6..148439a263 100644
--- a/libknot/error.c
+++ b/libknot/util/error.c
@@ -14,8 +14,8 @@
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "error.h"
-#include "utils.h"
+#include "util/error.h"
+#include "util/utils.h"
 
 #include "common/errors.h"
 
diff --git a/libknot/error.h b/libknot/util/error.h
similarity index 100%
rename from libknot/error.h
rename to libknot/util/error.h
diff --git a/libknot/tolower.c b/libknot/util/tolower.c
similarity index 99%
rename from libknot/tolower.c
rename to libknot/util/tolower.c
index f826a4ab8d..eff9231623 100644
--- a/libknot/tolower.c
+++ b/libknot/util/tolower.c
@@ -14,7 +14,7 @@
     along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "tolower.h"
+#include "util/tolower.h"
 
 const uint8_t char_table[CHAR_TABLE_SIZE] = {
 	'\x00',
diff --git a/libknot/tolower.h b/libknot/util/tolower.h
similarity index 100%
rename from libknot/tolower.h
rename to libknot/util/tolower.h
diff --git a/libknot/utils.c b/libknot/util/utils.c
similarity index 99%
rename from libknot/utils.c
rename to libknot/util/utils.c
index c9edf04f56..cf4bf1f0e5 100644
--- a/libknot/utils.c
+++ b/libknot/util/utils.c
@@ -19,7 +19,7 @@
 #include <pthread.h>
 
 #include "common.h"
-#include "utils.h"
+#include "util/utils.h"
 
 /*----------------------------------------------------------------------------*/
 
diff --git a/libknot/utils.h b/libknot/util/utils.h
similarity index 100%
rename from libknot/utils.h
rename to libknot/util/utils.h
diff --git a/libknot/wire.h b/libknot/util/wire.h
similarity index 99%
rename from libknot/wire.h
rename to libknot/util/wire.h
index 3cca4ff393..989102e199 100644
--- a/libknot/wire.h
+++ b/libknot/util/wire.h
@@ -30,7 +30,7 @@
 #include <stdint.h>
 #include <assert.h>
 
-#include "utils.h"
+#include "util/utils.h"
 
 /*! \brief Offset of DNS header fields in wireformat. */
 enum knot_wire_offsets {
diff --git a/libknot/dname-table.c b/libknot/zone/dname-table.c
similarity index 99%
rename from libknot/dname-table.c
rename to libknot/zone/dname-table.c
index b8a8998f83..d7ca96f518 100644
--- a/libknot/dname-table.c
+++ b/libknot/zone/dname-table.c
@@ -19,8 +19,8 @@
 #include <stdlib.h>
 #include <stdio.h>
 
-#include "dname-table.h"
-#include "error.h"
+#include "zone/dname-table.h"
+#include "util/error.h"
 
 /*!< Tree functions. */
 TREE_DEFINE(dname_table_node, avl);
diff --git a/libknot/dname-table.h b/libknot/zone/dname-table.h
similarity index 100%
rename from libknot/dname-table.h
rename to libknot/zone/dname-table.h
diff --git a/libknot/node.c b/libknot/zone/node.c
similarity index 99%
rename from libknot/node.c
rename to libknot/zone/node.c
index 46797cd0b0..f276580d78 100644
--- a/libknot/node.c
+++ b/libknot/zone/node.c
@@ -22,12 +22,12 @@
 #include <urcu.h>
 
 #include "common.h"
-#include "node.h"
+#include "zone/node.h"
 #include "rrset.h"
-#include "error.h"
+#include "util/error.h"
 #include "common/skip-list.h"
 #include "common/tree.h"
-#include "debug.h"
+#include "util/debug.h"
 
 /*----------------------------------------------------------------------------*/
 /* Non-API functions                                                          */
diff --git a/libknot/node.h b/libknot/zone/node.h
similarity index 100%
rename from libknot/node.h
rename to libknot/zone/node.h
diff --git a/libknot/zone-contents.c b/libknot/zone/zone-contents.c
similarity index 99%
rename from libknot/zone-contents.c
rename to libknot/zone/zone-contents.c
index a34a15c82c..5b8ca73065 100644
--- a/libknot/zone-contents.c
+++ b/libknot/zone/zone-contents.c
@@ -16,9 +16,9 @@
 
 #include <assert.h>
 
-#include "zone-contents.h"
-#include "error.h"
-#include "debug.h"
+#include "zone/zone-contents.h"
+#include "util/error.h"
+#include "util/debug.h"
 #include "common/base32hex.h"
 
 /*----------------------------------------------------------------------------*/
diff --git a/libknot/zone-contents.h b/libknot/zone/zone-contents.h
similarity index 99%
rename from libknot/zone-contents.h
rename to libknot/zone/zone-contents.h
index 6489379af9..a586372368 100644
--- a/libknot/zone-contents.h
+++ b/libknot/zone/zone-contents.h
@@ -29,10 +29,10 @@
 
 //#include <time.h>
 
-#include "node.h"
+#include "zone/node.h"
 #include "dname.h"
 #include "nsec3.h"
-#include "dname-table.h"
+#include "zone/dname-table.h"
 #include "common/tree.h"
 #include "hash/cuckoo-hash-table.h"
 
diff --git a/libknot/zone-tree.c b/libknot/zone/zone-tree.c
similarity index 99%
rename from libknot/zone-tree.c
rename to libknot/zone/zone-tree.c
index b3ef55908e..6545bad4bc 100644
--- a/libknot/zone-tree.c
+++ b/libknot/zone/zone-tree.c
@@ -19,8 +19,8 @@
 #include <stdio.h>
 
 #include "zone-tree.h"
-#include "node.h"
-#include "error.h"
+#include "zone/node.h"
+#include "util/error.h"
 
 /*----------------------------------------------------------------------------*/
 /* Non-API functions                                                          */
diff --git a/libknot/zone-tree.h b/libknot/zone/zone-tree.h
similarity index 99%
rename from libknot/zone-tree.h
rename to libknot/zone/zone-tree.h
index f7774e6c97..f7c6b1cf7b 100644
--- a/libknot/zone-tree.h
+++ b/libknot/zone/zone-tree.h
@@ -30,7 +30,7 @@
 #define _KNOT_ZONE_TREE_H_
 
 #include "common/tree.h"
-#include "node.h"
+#include "zone/node.h"
 
 /*----------------------------------------------------------------------------*/
 
diff --git a/libknot/zone.c b/libknot/zone/zone.c
similarity index 96%
rename from libknot/zone.c
rename to libknot/zone/zone.c
index 5708ee0442..d19b2ca18a 100644
--- a/libknot/zone.c
+++ b/libknot/zone/zone.c
@@ -22,19 +22,19 @@
 #include <urcu.h>
 
 #include "common.h"
-#include "zone.h"
-#include "node.h"
+#include "zone/zone.h"
+#include "zone/node.h"
 #include "dname.h"
 #include "consts.h"
-#include "descriptor.h"
+#include "util/descriptor.h"
 #include "nsec3.h"
-#include "error.h"
-#include "debug.h"
-#include "utils.h"
+#include "util/error.h"
+#include "util/debug.h"
+#include "util/utils.h"
 #include "common/tree.h"
 #include "common/base32hex.h"
 #include "hash/cuckoo-hash-table.h"
-#include "zone-contents.h"
+#include "zone/zone-contents.h"
 
 /*----------------------------------------------------------------------------*/
 /* API functions                                                              */
diff --git a/libknot/zone.h b/libknot/zone/zone.h
similarity index 97%
rename from libknot/zone.h
rename to libknot/zone/zone.h
index ee8f95f868..fd12824e13 100644
--- a/libknot/zone.h
+++ b/libknot/zone/zone.h
@@ -29,16 +29,16 @@
 
 #include <time.h>
 
-#include "node.h"
+#include "zone/node.h"
 #include "dname.h"
 #include "nsec3.h"
-#include "dname-table.h"
+#include "zone/dname-table.h"
 #include "common/tree.h"
 #include "hash/cuckoo-hash-table.h"
 
 #include "zone-tree.h"
 
-#include "zone-contents.h"
+#include "zone/zone-contents.h"
 
 /*----------------------------------------------------------------------------*/
 
diff --git a/libknot/zonedb.c b/libknot/zone/zonedb.c
similarity index 98%
rename from libknot/zonedb.c
rename to libknot/zone/zonedb.c
index 1c0bc784f5..9b9392001c 100644
--- a/libknot/zonedb.c
+++ b/libknot/zone/zonedb.c
@@ -21,12 +21,12 @@
 #include <urcu.h>
 
 #include "common.h"
-#include "zone.h"
-#include "zonedb.h"
+#include "zone/zone.h"
+#include "zone/zonedb.h"
 #include "dname.h"
-#include "node.h"
-#include "error.h"
-#include "debug.h"
+#include "zone/node.h"
+#include "util/error.h"
+#include "util/debug.h"
 #include "common/general-tree.h"
 
 /*----------------------------------------------------------------------------*/
diff --git a/libknot/zonedb.h b/libknot/zone/zonedb.h
similarity index 98%
rename from libknot/zonedb.h
rename to libknot/zone/zonedb.h
index 068f4c11af..09edd9f39c 100644
--- a/libknot/zonedb.h
+++ b/libknot/zone/zonedb.h
@@ -31,8 +31,8 @@
 #define _KNOT_ZONEDB_H_
 
 #include "common/general-tree.h"
-#include "zone.h"
-#include "node.h"
+#include "zone/zone.h"
+#include "zone/node.h"
 #include "dname.h"
 
 /*!
diff --git a/src/knot/conf/conf.h b/src/knot/conf/conf.h
index a0211d8f7d..90fddf4672 100644
--- a/src/knot/conf/conf.h
+++ b/src/knot/conf/conf.h
@@ -18,7 +18,7 @@
 
 #include <urcu.h>
 
-#include "libknot/descriptor.h"
+#include "libknot/util/descriptor.h"
 #include "common/lists.h"
 #include "knot/other/log.h"
 
diff --git a/src/knot/server/notify.c b/src/knot/server/notify.c
index 58c78157fa..2ae29332d9 100644
--- a/src/knot/server/notify.c
+++ b/src/knot/server/notify.c
@@ -3,15 +3,15 @@
 #include "knot/server/notify.h"
 
 #include "libknot/dname.h"
-#include "libknot/packet.h"
+#include "libknot/packet/packet.h"
 #include "libknot/rrset.h"
-#include "libknot/response2.h"
-#include "libknot/query.h"
+#include "libknot/packet/response2.h"
+#include "libknot/packet/query.h"
 #include "libknot/consts.h"
 #include "knot/other/error.h"
-#include "libknot/zonedb.h"
+#include "libknot/zone/zonedb.h"
 #include "libknot/common.h"
-#include "libknot/error.h"
+#include "libknot/util/error.h"
 #include "knot/server/zones.h"
 #include "common/acl.h"
 #include "common/evsched.h"
diff --git a/src/knot/server/notify.h b/src/knot/server/notify.h
index 7db91b45ca..330cf7238e 100644
--- a/src/knot/server/notify.h
+++ b/src/knot/server/notify.h
@@ -15,12 +15,12 @@
 #include <stdint.h>
 #include <string.h>
 
-#include "libknot/zone.h"
-#include "libknot/packet.h"
-#include "libknot/zonedb.h"
+#include "libknot/zone/zone.h"
+#include "libknot/packet/packet.h"
+#include "libknot/zone/zonedb.h"
 #include "common/lists.h"
 #include "common/sockaddr.h"
-#include "libknot/name-server.h"
+#include "libknot/nameserver/name-server.h"
 
 /*!
  * \brief Pending NOTIFY event.
diff --git a/src/knot/server/server.c b/src/knot/server/server.c
index 7ca444b308..306ee4ac88 100644
--- a/src/knot/server/server.c
+++ b/src/knot/server/server.c
@@ -13,11 +13,11 @@
 #include "knot/server/udp-handler.h"
 #include "knot/server/tcp-handler.h"
 #include "knot/server/xfr-handler.h"
-#include "libknot/name-server.h"
+#include "libknot/nameserver/name-server.h"
 #include "knot/stat/stat.h"
-#include "libknot/zonedb.h"
+#include "libknot/zone/zonedb.h"
 #include "knot/zone/zone-load.h"
-#include "libknot/debug.h"
+#include "libknot/util/debug.h"
 #include "libknot/dname.h"
 #include "knot/conf/conf.h"
 #include "knot/server/zones.h"
diff --git a/src/knot/server/server.h b/src/knot/server/server.h
index 2e71e17c58..be57b1598c 100644
--- a/src/knot/server/server.h
+++ b/src/knot/server/server.h
@@ -22,11 +22,11 @@
 #define _KNOTDSERVER_H_
 
 #include "knot/common.h"
-#include "libknot/name-server.h"
+#include "libknot/nameserver/name-server.h"
 #include "knot/server/xfr-handler.h"
 #include "knot/server/socket.h"
 #include "knot/server/dthreads.h"
-#include "libknot/zonedb.h"
+#include "libknot/zone/zonedb.h"
 #include "common/evsched.h"
 #include "common/lists.h"
 
diff --git a/src/knot/server/tcp-handler.c b/src/knot/server/tcp-handler.c
index 5a14363482..b4594f4262 100644
--- a/src/knot/server/tcp-handler.c
+++ b/src/knot/server/tcp-handler.c
@@ -16,10 +16,10 @@
 #include "knot/common.h"
 #include "knot/server/tcp-handler.h"
 #include "knot/server/xfr-handler.h"
-#include "libknot/name-server.h"
+#include "libknot/nameserver/name-server.h"
 #include "knot/other/error.h"
 #include "knot/stat/stat.h"
-#include "libknot/wire.h"
+#include "libknot/util/wire.h"
 #include "knot/server/zones.h"
 
 /*! \brief TCP watcher. */
diff --git a/src/knot/server/udp-handler.c b/src/knot/server/udp-handler.c
index 24ce19763b..8e89a4df20 100644
--- a/src/knot/server/udp-handler.c
+++ b/src/knot/server/udp-handler.c
@@ -13,12 +13,12 @@
 #include "knot/common.h"
 #include "knot/other/error.h"
 #include "knot/server/udp-handler.h"
-#include "libknot/name-server.h"
+#include "libknot/nameserver/name-server.h"
 #include "knot/stat/stat.h"
 #include "knot/server/server.h"
-#include "libknot/wire.h"
+#include "libknot/util/wire.h"
 #include "libknot/consts.h"
-#include "libknot/packet.h"
+#include "libknot/packet/packet.h"
 #include "knot/server/zones.h"
 #include "knot/server/notify.h"
 
diff --git a/src/knot/server/xfr-handler.c b/src/knot/server/xfr-handler.c
index 9bf7d8003f..ad5510e9c9 100644
--- a/src/knot/server/xfr-handler.c
+++ b/src/knot/server/xfr-handler.c
@@ -14,13 +14,13 @@
 
 #include "knot/common.h"
 #include "knot/server/xfr-handler.h"
-#include "libknot/name-server.h"
+#include "libknot/nameserver/name-server.h"
 #include "knot/other/error.h"
 #include "knot/server/socket.h"
 #include "knot/server/tcp-handler.h"
-#include "libknot/xfr-in.h"
+#include "libknot/updates/xfr-in.h"
 #include "knot/server/zones.h"
-#include "libknot/error.h"
+#include "libknot/util/error.h"
 
 /*! \brief XFR event wrapper for libev. */
 struct xfr_io_t
diff --git a/src/knot/server/xfr-handler.h b/src/knot/server/xfr-handler.h
index 6f0aebca0d..40dad4caa0 100644
--- a/src/knot/server/xfr-handler.h
+++ b/src/knot/server/xfr-handler.h
@@ -15,7 +15,7 @@
 #include <ev.h>
 
 #include "knot/server/dthreads.h"
-#include "libknot/name-server.h"
+#include "libknot/nameserver/name-server.h"
 #include "common/evqueue.h"
 
 /*!
diff --git a/src/knot/server/zones.c b/src/knot/server/zones.c
index aa8b12181a..55e9529ec5 100644
--- a/src/knot/server/zones.c
+++ b/src/knot/server/zones.c
@@ -1,25 +1,25 @@
 #include <sys/stat.h>
 
 #include "common/lists.h"
-#include "libknot/debug.h"
+#include "libknot/util/debug.h"
 #include "libknot/dname.h"
-#include "libknot/wire.h"
+#include "libknot/util/wire.h"
 #include "knot/zone/zone-dump-text.h"
 #include "knot/zone/zone-load.h"
-#include "libknot/zone.h"
-#include "libknot/zonedb.h"
+#include "libknot/zone/zone.h"
+#include "libknot/zone/zonedb.h"
 #include "knot/conf/conf.h"
 #include "knot/other/debug.h"
 #include "knot/other/error.h"
 #include "knot/other/log.h"
 #include "knot/server/notify.h"
 #include "knot/server/server.h"
-#include "libknot/xfr-in.h"
+#include "libknot/updates/xfr-in.h"
 #include "knot/server/zones.h"
-#include "libknot/error.h"
+#include "libknot/util/error.h"
 #include "knot/zone/zone-dump.h"
-#include "libknot/name-server.h"
-#include "libknot/changesets.h"
+#include "libknot/nameserver/name-server.h"
+#include "libknot/updates/changesets.h"
 
 static const size_t XFRIN_CHANGESET_BINARY_SIZE = 100;
 static const size_t XFRIN_CHANGESET_BINARY_STEP = 100;
diff --git a/src/knot/server/zones.h b/src/knot/server/zones.h
index 804b1638e2..c5a06c2d13 100644
--- a/src/knot/server/zones.h
+++ b/src/knot/server/zones.h
@@ -14,12 +14,12 @@
 
 #include "common/lists.h"
 #include "common/acl.h"
-#include "libknot/name-server.h"
-#include "libknot/zonedb.h"
+#include "libknot/nameserver/name-server.h"
+#include "libknot/zone/zonedb.h"
 #include "knot/conf/conf.h"
 #include "knot/server/journal.h"
-#include "libknot/zone.h"
-#include "libknot/xfr-in.h"
+#include "libknot/zone/zone.h"
+#include "libknot/updates/xfr-in.h"
 
 /* Constants. */
 #define IXFR_DBSYNC_TIMEOUT (60*1000) /*!< Database sync timeout = 60s. */
diff --git a/src/knot/zone/zone-dump-text.h b/src/knot/zone/zone-dump-text.h
index 6572b8e989..4e7605bcdf 100644
--- a/src/knot/zone/zone-dump-text.h
+++ b/src/knot/zone/zone-dump-text.h
@@ -12,8 +12,8 @@
 #ifndef _KNOT_ZONE_DUMP_TEXT_H_
 #define _KNOT_ZONE_DUMP_TEXT_H_
 
-#include "libknot/descriptor.h"
-#include "libknot/zone.h"
+#include "libknot/util/descriptor.h"
+#include "libknot/zone/zone.h"
 
 /*!
  * \brief Dumps given zone to text (BIND-like) file.
diff --git a/src/knot/zone/zone-dump.c b/src/knot/zone/zone-dump.c
index 82c2a90696..0287138096 100644
--- a/src/knot/zone/zone-dump.c
+++ b/src/knot/zone/zone-dump.c
@@ -7,11 +7,11 @@
 #include "libknot/common.h"
 #include "knot/zone/zone-dump.h"
 #include "libknot/libknot.h"
-#include "libknot/debug.h"
+#include "libknot/util/debug.h"
 #include "common/skip-list.h"
 #include "common/base32hex.h"
 #include "common/crc.h"
-#include "libknot/error.h"
+#include "libknot/util/error.h"
 
 #define ZONECHECKS_VERBOSE
 
diff --git a/src/knot/zone/zone-dump.h b/src/knot/zone/zone-dump.h
index 52404cc5cb..0820756852 100644
--- a/src/knot/zone/zone-dump.h
+++ b/src/knot/zone/zone-dump.h
@@ -12,7 +12,7 @@
 #ifndef _KNOT_ZONEDUMP_H_
 #define _KNOT_ZONEDUMP_H_
 
-#include "libknot/zone.h"
+#include "libknot/zone/zone.h"
 
 /*!
  * \brief Zone loader enums.
diff --git a/src/knot/zone/zone-load.c b/src/knot/zone/zone-load.c
index 735f68164e..c84437815d 100644
--- a/src/knot/zone/zone-load.c
+++ b/src/knot/zone/zone-load.c
@@ -12,7 +12,7 @@
 #include "knot/zone/zone-load.h"
 #include "knot/zone/zone-dump.h"
 #include "libknot/libknot.h"
-#include "libknot/debug.h"
+#include "libknot/util/debug.h"
 
 /*!
  * \brief Compares two time_t values.
diff --git a/src/knot/zone/zone-load.h b/src/knot/zone/zone-load.h
index f03884e7c6..58e124c900 100644
--- a/src/knot/zone/zone-load.h
+++ b/src/knot/zone/zone-load.h
@@ -14,7 +14,7 @@
 
 #include <stdio.h>
 
-#include "libknot/zone.h"
+#include "libknot/zone/zone.h"
 
 /*!
  * \brief Zone loader structure.
diff --git a/src/tests/libknot/libknot/dname_table_tests.c b/src/tests/libknot/libknot/dname_table_tests.c
index be768a57cc..d3a0573ed1 100644
--- a/src/tests/libknot/libknot/dname_table_tests.c
+++ b/src/tests/libknot/libknot/dname_table_tests.c
@@ -3,8 +3,8 @@
 #include <assert.h>
 
 #include "dname_table_tests.h"
-#include "libknot/error.h"
-#include "libknot/dname-table.h"
+#include "libknot/util/error.h"
+#include "libknot/zone/dname-table.h"
 /* *test_t structures */
 #include "tests/libknot/realdata/libknot_tests_loader_realdata.h"
 
diff --git a/src/tests/libknot/libknot/dname_tests.c b/src/tests/libknot/libknot/dname_tests.c
index 1b6ba83666..5f9fb094f1 100644
--- a/src/tests/libknot/libknot/dname_tests.c
+++ b/src/tests/libknot/libknot/dname_tests.c
@@ -3,7 +3,7 @@
 
 #include "tests/libknot/libknot/dname_tests.h"
 #include "libknot/dname.h"
-#include "libknot/node.h"
+#include "libknot/zone/node.h"
 
 static int knot_dname_tests_count(int argc, char *argv[]);
 static int knot_dname_tests_run(int argc, char *argv[]);
diff --git a/src/tests/libknot/libknot/node_tests.c b/src/tests/libknot/libknot/node_tests.c
index 793c0829f7..4764224d59 100644
--- a/src/tests/libknot/libknot/node_tests.c
+++ b/src/tests/libknot/libknot/node_tests.c
@@ -1,7 +1,7 @@
 #include "tests/libknot/libknot/node_tests.h"
 #include "libknot/dname.h"
-#include "libknot/node.h"
-#include "libknot/descriptor.h"
+#include "libknot/zone/node.h"
+#include "libknot/util/descriptor.h"
 
 static int knot_node_tests_count(int argc, char *argv[]);
 static int knot_node_tests_run(int argc, char *argv[]);
diff --git a/src/tests/libknot/libknot/nsec3_tests.c b/src/tests/libknot/libknot/nsec3_tests.c
index f217dd88f0..dc03ad1539 100644
--- a/src/tests/libknot/libknot/nsec3_tests.c
+++ b/src/tests/libknot/libknot/nsec3_tests.c
@@ -3,9 +3,9 @@
 #include <assert.h>
 
 #include "libknot/common.h"
-#include "libknot/error.h"
+#include "libknot/util/error.h"
 #include "libknot/nsec3.h"
-#include "libknot/utils.h"
+#include "libknot/util/utils.h"
 #include "common/base32hex.h"
 #include "nsec3_tests.h"
 
diff --git a/src/tests/libknot/libknot/packet_tests.c b/src/tests/libknot/libknot/packet_tests.c
index 963631022a..b5b5fc157c 100644
--- a/src/tests/libknot/libknot/packet_tests.c
+++ b/src/tests/libknot/libknot/packet_tests.c
@@ -4,9 +4,9 @@
 #include <stdint.h>
 
 #include "packet_tests.h"
-#include "libknot/error.h"
-#include "libknot/packet.h"
-#include "libknot/wire.h"
+#include "libknot/util/error.h"
+#include "libknot/packet/packet.h"
+#include "libknot/util/wire.h"
 /* *test_t structures */
 #include "tests/libknot/realdata/libknot_tests_loader_realdata.h"
 
diff --git a/src/tests/libknot/libknot/query_tests.c b/src/tests/libknot/libknot/query_tests.c
index 9b59741ee1..c0793482f7 100644
--- a/src/tests/libknot/libknot/query_tests.c
+++ b/src/tests/libknot/libknot/query_tests.c
@@ -4,10 +4,10 @@
 #include <stdint.h>
 
 #include "packet_tests.h"
-#include "libknot/error.h"
-#include "libknot/packet.h"
-#include "libknot/wire.h"
-#include "libknot/query.h"
+#include "libknot/util/error.h"
+#include "libknot/packet/packet.h"
+#include "libknot/util/wire.h"
+#include "libknot/packet/query.h"
 /* *test_t structures */
 #include "tests/libknot/realdata/libknot_tests_loader_realdata.h"
 
diff --git a/src/tests/libknot/libknot/rdata_tests.c b/src/tests/libknot/libknot/rdata_tests.c
index 94dc380388..c132beba03 100644
--- a/src/tests/libknot/libknot/rdata_tests.c
+++ b/src/tests/libknot/libknot/rdata_tests.c
@@ -4,9 +4,9 @@
 #include "tests/libknot/libknot/rdata_tests.h"
 #include "libknot/common.h"
 #include "libknot/rdata.h"
-#include "libknot/descriptor.h"
-#include "libknot/utils.h"
-#include "libknot/error.h"
+#include "libknot/util/descriptor.h"
+#include "libknot/util/utils.h"
+#include "libknot/util/error.h"
 
 enum { TEST_DOMAINS_OK = 8 };
 
diff --git a/src/tests/libknot/libknot/response2_tests.c b/src/tests/libknot/libknot/response2_tests.c
index d11c1d9918..d76cd1ca39 100644
--- a/src/tests/libknot/libknot/response2_tests.c
+++ b/src/tests/libknot/libknot/response2_tests.c
@@ -6,13 +6,13 @@
 #include "tests/libknot/libknot/response2_tests.h"
 #include "common/lists.h"
 #include "libknot/common.h"
-#include "libknot/error.h"
-#include "libknot/response2.h"
+#include "libknot/util/error.h"
+#include "libknot/packet/response2.h"
 #include "libknot/rdata.h"
 #include "libknot/rrset.h"
 #include "libknot/dname.h"
-#include "libknot/wire.h"
-#include "libknot/descriptor.h"
+#include "libknot/util/wire.h"
+#include "libknot/util/descriptor.h"
 #include "libknot/edns.h"
 
 #ifdef TEST_WITH_LDNS
diff --git a/src/tests/libknot/libknot/response_tests.c b/src/tests/libknot/libknot/response_tests.c
index e2369d17ab..5b6c90476d 100644
--- a/src/tests/libknot/libknot/response_tests.c
+++ b/src/tests/libknot/libknot/response_tests.c
@@ -4,12 +4,12 @@
 //#define RESP_TEST_DEBUG
 #include "tests/libknot/libknot/response_tests.h"
 #include "libknot/common.h"
-#include "libknot/response.h"
+#include "libknot/packet/response.h"
 #include "libknot/rdata.h"
 #include "libknot/rrset.h"
 #include "libknot/dname.h"
-#include "libknot/wire.h"
-#include "libknot/descriptor.h"
+#include "libknot/util/wire.h"
+#include "libknot/util/descriptor.h"
 #include "libknot/edns.h"
 
 #ifdef TEST_WITH_LDNS
diff --git a/src/tests/libknot/libknot/rrset_tests.c b/src/tests/libknot/libknot/rrset_tests.c
index 2050614130..461d80eb3c 100644
--- a/src/tests/libknot/libknot/rrset_tests.c
+++ b/src/tests/libknot/libknot/rrset_tests.c
@@ -2,13 +2,13 @@
 
 #include "tests/libknot/libknot/rrset_tests.h"
 #include "libknot/common.h"
-#include "libknot/descriptor.h"
+#include "libknot/util/descriptor.h"
 #include "libknot/rrset.h"
 #include "libknot/dname.h"
 #include "libknot/rdata.h"
-#include "libknot/utils.h"
-#include "libknot/node.h"
-#include "libknot/debug.h"
+#include "libknot/util/utils.h"
+#include "libknot/zone/node.h"
+#include "libknot/util/debug.h"
 
 static int knot_rrset_tests_count(int argc, char *argv[]);
 static int knot_rrset_tests_run(int argc, char *argv[]);
diff --git a/src/tests/libknot/libknot/zone_tests.c b/src/tests/libknot/libknot/zone_tests.c
index cce6bb5e1d..f418270475 100644
--- a/src/tests/libknot/libknot/zone_tests.c
+++ b/src/tests/libknot/libknot/zone_tests.c
@@ -2,10 +2,10 @@
 
 #include "tests/libknot/libknot/zone_tests.h"
 #include "libknot/common.h"
-#include "libknot/dname-table.h"
-#include "libknot/zone.h"
-#include "libknot/error.h"
-#include "libknot/node.h"
+#include "libknot/zone/dname-table.h"
+#include "libknot/zone/zone.h"
+#include "libknot/util/error.h"
+#include "libknot/zone/node.h"
 
 static int knot_zone_tests_count(int argc, char *argv[]);
 static int knot_zone_tests_run(int argc, char *argv[]);
diff --git a/src/tests/libknot/realdata/libknot/node_tests_realdata.c b/src/tests/libknot/realdata/libknot/node_tests_realdata.c
index 46b8ebbc73..75f595cf39 100644
--- a/src/tests/libknot/realdata/libknot/node_tests_realdata.c
+++ b/src/tests/libknot/realdata/libknot/node_tests_realdata.c
@@ -3,8 +3,8 @@
 #include "tests/libknot/realdata/libknot/node_tests_realdata.h"
 #include "tests/libknot/realdata/libknot_tests_loader_realdata.h"
 #include "libknot/dname.h"
-#include "libknot/node.h"
-#include "libknot/descriptor.h"
+#include "libknot/zone/node.h"
+#include "libknot/util/descriptor.h"
 
 static int knot_node_tests_count(int argc, char *argv[]);
 static int knot_node_tests_run(int argc, char *argv[]);
diff --git a/src/tests/libknot/realdata/libknot/packet_tests_realdata.c b/src/tests/libknot/realdata/libknot/packet_tests_realdata.c
index 0b7e59233a..6770655b66 100644
--- a/src/tests/libknot/realdata/libknot/packet_tests_realdata.c
+++ b/src/tests/libknot/realdata/libknot/packet_tests_realdata.c
@@ -3,9 +3,9 @@
 #include <assert.h>
 
 #include "packet_tests_realdata.h"
-#include "libknot/error.h"
-#include "libknot/packet.h"
-#include "libknot/response2.h"
+#include "libknot/util/error.h"
+#include "libknot/packet/packet.h"
+#include "libknot/packet/response2.h"
 /* *test_t structures */
 #include "tests/libknot/realdata/libknot_tests_loader_realdata.h"
 #ifdef TEST_WITH_LDNS
diff --git a/src/tests/libknot/realdata/libknot/rdata_tests_realdata.c b/src/tests/libknot/realdata/libknot/rdata_tests_realdata.c
index 9e5314246c..19654a7b99 100644
--- a/src/tests/libknot/realdata/libknot/rdata_tests_realdata.c
+++ b/src/tests/libknot/realdata/libknot/rdata_tests_realdata.c
@@ -5,9 +5,9 @@
 #include "tests/libknot/realdata/libknot_tests_loader_realdata.h"
 #include "libknot/common.h"
 #include "libknot/rdata.h"
-#include "libknot/descriptor.h"
-#include "libknot/utils.h"
-#include "libknot/error.h"
+#include "libknot/util/descriptor.h"
+#include "libknot/util/utils.h"
+#include "libknot/util/error.h"
 
 static int knot_rdata_tests_count(int argc, char *argv[]);
 static int knot_rdata_tests_run(int argc, char *argv[]);
diff --git a/src/tests/libknot/realdata/libknot/response2_tests_realdata.c b/src/tests/libknot/realdata/libknot/response2_tests_realdata.c
index 53b6c991d7..d1450a6014 100644
--- a/src/tests/libknot/realdata/libknot/response2_tests_realdata.c
+++ b/src/tests/libknot/realdata/libknot/response2_tests_realdata.c
@@ -3,9 +3,9 @@
 #include <assert.h>
 
 #include "packet_tests_realdata.h"
-#include "libknot/error.h"
-#include "libknot/packet.h"
-#include "libknot/response2.h"
+#include "libknot/util/error.h"
+#include "libknot/packet/packet.h"
+#include "libknot/packet/response2.h"
 /* *test_t structures */
 #include "tests/libknot/realdata/libknot_tests_loader_realdata.h"
 #ifdef TEST_WITH_LDNS
diff --git a/src/tests/libknot/realdata/libknot/response_tests_realdata.c b/src/tests/libknot/realdata/libknot/response_tests_realdata.c
index 88ba921ed9..2892406b28 100644
--- a/src/tests/libknot/realdata/libknot/response_tests_realdata.c
+++ b/src/tests/libknot/realdata/libknot/response_tests_realdata.c
@@ -5,11 +5,11 @@
 #include "tests/libknot/realdata/libknot/response_tests_realdata.h"
 #include "tests/libknot/realdata/libknot_tests_loader_realdata.h"
 #include "libknot/common.h"
-#include "libknot/response.h"
+#include "libknot/packet/response.h"
 #include "libknot/rdata.h"
 #include "libknot/rrset.h"
 #include "libknot/dname.h"
-#include "libknot/descriptor.h"
+#include "libknot/util/descriptor.h"
 #include "libknot/edns.h"
 #include "common/lists.h"
 
diff --git a/src/tests/libknot/realdata/libknot/rrset_tests_realdata.c b/src/tests/libknot/realdata/libknot/rrset_tests_realdata.c
index e3d4f176bd..1b56a36fae 100644
--- a/src/tests/libknot/realdata/libknot/rrset_tests_realdata.c
+++ b/src/tests/libknot/realdata/libknot/rrset_tests_realdata.c
@@ -3,13 +3,13 @@
 #include "tests/libknot/realdata/libknot/rrset_tests_realdata.h"
 #include "tests/libknot/realdata/libknot_tests_loader_realdata.h"
 #include "libknot/common.h"
-#include "libknot/descriptor.h"
+#include "libknot/util/descriptor.h"
 #include "libknot/rrset.h"
 #include "libknot/dname.h"
 #include "libknot/rdata.h"
-#include "libknot/utils.h"
-#include "libknot/node.h"
-#include "libknot/debug.h"
+#include "libknot/util/utils.h"
+#include "libknot/zone/node.h"
+#include "libknot/util/debug.h"
 
 static int knot_rrset_tests_count(int argc, char *argv[]);
 static int knot_rrset_tests_run(int argc, char *argv[]);
diff --git a/src/tests/libknot/realdata/libknot/zone_tests_realdata.c b/src/tests/libknot/realdata/libknot/zone_tests_realdata.c
index b9afa16395..0b813fb82f 100644
--- a/src/tests/libknot/realdata/libknot/zone_tests_realdata.c
+++ b/src/tests/libknot/realdata/libknot/zone_tests_realdata.c
@@ -3,9 +3,9 @@
 #include "tests/libknot/realdata/libknot/zone_tests_realdata.h"
 #include "tests/libknot/realdata/libknot_tests_loader_realdata.h"
 #include "libknot/common.h"
-#include "libknot/zone.h"
-#include "libknot/error.h"
-#include "libknot/node.h"
+#include "libknot/zone/zone.h"
+#include "libknot/util/error.h"
+#include "libknot/zone/node.h"
 
 static int knot_zone_tests_count(int argc, char *argv[]);
 static int knot_zone_tests_run(int argc, char *argv[]);
diff --git a/src/tests/libknot/realdata/libknot_tests_loader_realdata.c b/src/tests/libknot/realdata/libknot_tests_loader_realdata.c
index 1ac9fb7c3d..44cc86327f 100644
--- a/src/tests/libknot/realdata/libknot_tests_loader_realdata.c
+++ b/src/tests/libknot/realdata/libknot_tests_loader_realdata.c
@@ -4,7 +4,7 @@
 
 #include "common/libtap/tap.h"
 #include "tests/libknot/realdata/libknot_tests_loader_realdata.h"
-#include "libknot/descriptor.h"
+#include "libknot/util/descriptor.h"
 
 #include "tests/libknot/realdata/parsed_data.rc"
 #include "tests/libknot/realdata/raw_data.rc"
diff --git a/src/zcompile/parser-descriptor.h b/src/zcompile/parser-descriptor.h
index 51f8d77220..7d46904377 100644
--- a/src/zcompile/parser-descriptor.h
+++ b/src/zcompile/parser-descriptor.h
@@ -15,7 +15,7 @@
 #include <stdint.h>
 #include <stdbool.h>
 
-#include "libknot/utils.h"
+#include "libknot/util/utils.h"
 
 enum parser_mxrdtln {
 	PARSER_MAX_RDATA_ITEMS = 64,
diff --git a/src/zcompile/parser-util.c b/src/zcompile/parser-util.c
index f049788d4f..a44cb6040b 100644
--- a/src/zcompile/parser-util.c
+++ b/src/zcompile/parser-util.c
@@ -29,8 +29,8 @@
 //#include "common.h"
 #include "zcompile/parser-util.h"
 #include "zcompile/zcompile.h"
-#include "libknot/descriptor.h"
-#include "libknot/utils.h"
+#include "libknot/util/descriptor.h"
+#include "libknot/util/utils.h"
 
 #define IP6ADDRLEN	(128/8)
 #define	NS_INT16SZ	2
diff --git a/src/zcompile/parser-util.h b/src/zcompile/parser-util.h
index 5b2605d1c7..7c19860625 100644
--- a/src/zcompile/parser-util.h
+++ b/src/zcompile/parser-util.h
@@ -28,7 +28,7 @@
 #include <netdb.h>
 
 #include "zcompile/zcompile.h"
-#include "libknot/descriptor.h"
+#include "libknot/util/descriptor.h"
 
 int inet_pton4(const char *src, uint8_t *dst);
 int inet_pton6(const char *src, uint8_t *dst);
diff --git a/src/zcompile/tests/zcompile_tests.c b/src/zcompile/tests/zcompile_tests.c
index 2c870d5cf2..b34b948ad0 100644
--- a/src/zcompile/tests/zcompile_tests.c
+++ b/src/zcompile/tests/zcompile_tests.c
@@ -1,9 +1,9 @@
 #include <assert.h>
 
-#include "libknot/zone.h"
+#include "libknot/zone/zone.h"
 #include "knot/zone/zone-load.h"
 #include "libknot/rrset.h"
-#include "libknot/descriptor.h"
+#include "libknot/util/descriptor.h"
 #include "zcompile/zcompile.h"
 
 #ifdef TEST_WITH_LDNS
diff --git a/src/zcompile/zcompile.h b/src/zcompile/zcompile.h
index ec9f4cf1fe..2c4c068cca 100644
--- a/src/zcompile/zcompile.h
+++ b/src/zcompile/zcompile.h
@@ -19,11 +19,11 @@
 
 #include "libknot/dname.h"
 #include "libknot/rrset.h"
-#include "libknot/node.h"
+#include "libknot/zone/node.h"
 #include "libknot/rdata.h"
-#include "libknot/zone.h"
-#include "libknot/dname-table.h"
-#include "libknot/dname-table.h"
+#include "libknot/zone/zone.h"
+#include "libknot/zone/dname-table.h"
+#include "libknot/zone/dname-table.h"
 #include "common/slab/slab.h"
 
 #define MAXRDATALEN	64	/*!< Maximum number of RDATA items. */
diff --git a/src/zcompile/zparser.y b/src/zcompile/zparser.y
index 3650aab7cb..8f14b9d825 100644
--- a/src/zcompile/zparser.y
+++ b/src/zcompile/zparser.y
@@ -23,7 +23,7 @@
 #include "zcompile/parser-util.h"
 
 #include "libknot/dname.h"
-#include "libknot/zone.h"
+#include "libknot/zone/zone.h"
 #include "zcompile/zcompile.h"
 #include "zcompile/parser-descriptor.h"
 #include "zcompile/zcompile-error.h"
-- 
GitLab