From 095cb46acf0714c30650559a0fb0fe259b5a3e03 Mon Sep 17 00:00:00 2001
From: Marek Vavrusa <marek.vavrusa@nic.cz>
Date: Thu, 16 May 2013 10:54:16 +0200
Subject: [PATCH] Do not compress root labels.

When a fqdn name consists of a single label, it is unneccesary to
to attempt to compress it.

Change-Id: I6368553bb28c5983405007894c6708b42c700f80
---
 src/libknot/packet/response.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/libknot/packet/response.c b/src/libknot/packet/response.c
index 50ed1833a1..e048d65afc 100644
--- a/src/libknot/packet/response.c
+++ b/src/libknot/packet/response.c
@@ -87,6 +87,15 @@ int knot_response_compress_dname(const knot_dname_t *dname, knot_compr_t *compr,
 		return KNOT_EINVAL;
 	}
 
+	/* Do not compress small dnames. */
+	uint8_t *name = dname->name;
+	if (dname->size <= 2) {
+                if (dname->size > max)
+                        return KNOT_ESPACE;
+                memcpy(dst, name, dname->size);
+                return dname->size;
+	}
+
 	/* Align and compare name and pointer in the compression table. */
 	unsigned i = 0;
 	unsigned lbcount = 0;
@@ -108,7 +117,6 @@ int knot_response_compress_dname(const knot_dname_t *dname, knot_compr_t *compr,
 	}
 
 	/* Write non-matching prefix. */
-	uint8_t *name = dname->name;
 	unsigned written = 0;
 	for (unsigned j = match.lbcount; j < dname->label_count; ++j) {
 		if (written + *name + 1 > max)
-- 
GitLab