Skip to content

Commit

Permalink
- Fix to use the now cached EDE, if any, for CD_bit queries.
Browse files Browse the repository at this point in the history
  • Loading branch information
gthess committed Aug 1, 2023
1 parent 8aec671 commit 2cc9563
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
27 changes: 24 additions & 3 deletions daemon/worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,8 @@ answer_norec_from_cache(struct worker* worker, struct query_info* qinfo,
uint16_t udpsize = edns->udp_size;
int secure = 0;
time_t timenow = *worker->env.now;
int must_validate = (!(flags&BIT_CD) || worker->env.cfg->ignore_cd)
int has_cd_bit = (flags&BIT_CD);
int must_validate = (!has_cd_bit || worker->env.cfg->ignore_cd)
&& worker->env.need_to_validate;
struct dns_msg *msg = NULL;
struct delegpt *dp;
Expand Down Expand Up @@ -546,6 +547,16 @@ answer_norec_from_cache(struct worker* worker, struct query_info* qinfo,
worker->env.now_tv))
return 0;
msg->rep->flags |= BIT_QR|BIT_RA;
/* Attach the cached EDE (RFC8914) if CD bit is set and the answer is
* bogus. */
if(worker->env.cfg->ede && has_cd_bit &&
(check_delegation_secure(msg->rep) == sec_status_bogus ||
check_delegation_secure(msg->rep) == sec_status_secure_sentinel_fail) &&
msg->rep->reason_bogus != LDNS_EDE_NONE) {
edns_opt_list_append_ede(&edns->opt_list_out,
worker->scratchpad, msg->rep->reason_bogus,
msg->rep->reason_bogus_str);
}
if(!reply_info_answer_encode(&msg->qinfo, msg->rep, id, flags,
repinfo->c->buffer, 0, 1, worker->scratchpad,
udpsize, edns, (int)(edns->bits & EDNS_DO), secure)) {
Expand Down Expand Up @@ -636,7 +647,8 @@ answer_from_cache(struct worker* worker, struct query_info* qinfo,
uint16_t udpsize = edns->udp_size;
struct reply_info* encode_rep = rep;
struct reply_info* partial_rep = *partial_repp;
int must_validate = (!(flags&BIT_CD) || worker->env.cfg->ignore_cd)
int has_cd_bit = (flags&BIT_CD);
int must_validate = (!has_cd_bit || worker->env.cfg->ignore_cd)
&& worker->env.need_to_validate;
*partial_repp = NULL; /* avoid accidental further pass */

Expand Down Expand Up @@ -763,11 +775,20 @@ answer_from_cache(struct worker* worker, struct query_info* qinfo,
goto bail_out;
}
} else {
if (*is_expired_answer == 1 &&
if(*is_expired_answer == 1 &&
worker->env.cfg->ede_serve_expired && worker->env.cfg->ede) {
EDNS_OPT_LIST_APPEND_EDE(&edns->opt_list_out,
worker->scratchpad, LDNS_EDE_STALE_ANSWER, "");
}
/* Attach the cached EDE (RFC8914) if CD bit is set and the
* answer is bogus. */
if(*is_secure_answer == 0 &&
worker->env.cfg->ede && has_cd_bit &&
encode_rep->reason_bogus != LDNS_EDE_NONE) {
edns_opt_list_append_ede(&edns->opt_list_out,
worker->scratchpad, encode_rep->reason_bogus,
encode_rep->reason_bogus_str);
}
if(!reply_info_answer_encode(qinfo, encode_rep, id, flags,
repinfo->c->buffer, timenow, 1, worker->scratchpad,
udpsize, edns, (int)(edns->bits & EDNS_DO),
Expand Down
1 change: 1 addition & 0 deletions doc/Changelog
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
altogether) before giving up on attaching EDE options.
- More braces and formatting for Fix for EDNS EDE size calculation to
avoid future bugs.
- Fix to use the now cached EDE, if any, for CD_bit queries.

1 August 2023: Wouter
- Fix for EDNS EDE size calculation.
Expand Down
17 changes: 16 additions & 1 deletion testdata/ede.tdir/ede.test
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,20 @@ then
exit 1
fi

# TODO EDE with CD bit set (EDE but no SERVFAIL) for a cached answer
# EDE with CD bit set (EDE but no SERVFAIL) for a cached answer
# Same test as above
dig @127.0.0.1 -p $UNBOUND_PORT cd.dnskey-failures.test +cd > cd_bit_ede.txt

if ! grep -q -e "NXDOMAIN" cd_bit_ede.txt
then
echo "No NXDOMAIN reply with CD bit set for cached answer"
cat cd_bit_ede.txt
exit 1
fi
if ! grep -q -e "OPT=15: 00 09" -e "EDE: 9" cd_bit_ede.txt
then
echo "No EDE attached with CD bit set for cached answer"
cat cd_bit_ede.txt
exit 1
fi
# TODO DNSSEC indeterminate when implemented

0 comments on commit 2cc9563

Please sign in to comment.