summaryrefslogtreecommitdiffstats
path: root/usr.sbin/nsd/answer.c
diff options
context:
space:
mode:
authorjakob <jakob@openbsd.org>2012-01-29 11:15:31 +0000
committerjakob <jakob@openbsd.org>2012-01-29 11:15:31 +0000
commit0c2b6c0218aabaae3b9cce365f168e402a7e0480 (patch)
treef390b4c5a446f6333378413df1a06d3abf1bea82 /usr.sbin/nsd/answer.c
parentSwap the keycodes of the two swapped keys of Apple ISO keyboards. (diff)
downloadwireguard-openbsd-0c2b6c0218aabaae3b9cce365f168e402a7e0480.tar.xz
wireguard-openbsd-0c2b6c0218aabaae3b9cce365f168e402a7e0480.zip
NSD v3.2.9
Diffstat (limited to 'usr.sbin/nsd/answer.c')
-rw-r--r--usr.sbin/nsd/answer.c27
1 files changed, 23 insertions, 4 deletions
diff --git a/usr.sbin/nsd/answer.c b/usr.sbin/nsd/answer.c
index 0633f6083c9..853288189da 100644
--- a/usr.sbin/nsd/answer.c
+++ b/usr.sbin/nsd/answer.c
@@ -62,6 +62,13 @@ encode_answer(query_type *q, const answer_type *answer)
uint16_t counts[RR_SECTION_COUNT];
rr_section_type section;
size_t i;
+ int minimal_respsize = IPV4_MINIMAL_RESPONSE_SIZE;
+ int done = 0;
+
+#if defined(INET6) && defined(MINIMAL_RESPONSES)
+ if (q->addr.ss_family == AF_INET6)
+ minimal_respsize = IPV6_MINIMAL_RESPONSE_SIZE;
+#endif
for (section = ANSWER_SECTION; section < RR_SECTION_COUNT; ++section) {
counts[section] = 0;
@@ -69,21 +76,33 @@ encode_answer(query_type *q, const answer_type *answer)
for (section = ANSWER_SECTION;
!TC(q->packet) && section < RR_SECTION_COUNT;
- ++section)
- {
+ ++section) {
+
for (i = 0; !TC(q->packet) && i < answer->rrset_count; ++i) {
if (answer->section[i] == section) {
counts[section] += packet_encode_rrset(
q,
answer->domains[i],
answer->rrsets[i],
- section);
+ section, minimal_respsize, &done);
}
}
+#ifdef MINIMAL_RESPONSES
+ /**
+ * done is set prematurely, because the minimal response size
+ * has been reached. No need to try adding RRsets in following
+ * sections.
+ */
+ if (done) {
+ break;
+ }
+#endif
}
ANCOUNT_SET(q->packet, counts[ANSWER_SECTION]);
- NSCOUNT_SET(q->packet, counts[AUTHORITY_SECTION]);
+ NSCOUNT_SET(q->packet,
+ counts[AUTHORITY_SECTION]
+ + counts[OPTIONAL_AUTHORITY_SECTION]);
ARCOUNT_SET(q->packet,
counts[ADDITIONAL_A_SECTION]
+ counts[ADDITIONAL_AAAA_SECTION]