From 6b5f314a3a79353a28a36307eb06fba811cd8d2d Mon Sep 17 00:00:00 2001 From: Tom Carpay Date: Mon, 16 Aug 2021 13:26:55 +0000 Subject: [PATCH] Show reason when returning EDE_DNSSEC_BOGUS --- services/mesh.c | 8 ++++++-- util/data/msgreply.c | 29 +++++++++++++++++++++++++++++ util/data/msgreply.h | 14 +++++++++++++- 3 files changed, 48 insertions(+), 3 deletions(-) diff --git a/services/mesh.c b/services/mesh.c index 7252413be..c0050bd25 100644 --- a/services/mesh.c +++ b/services/mesh.c @@ -1278,8 +1278,12 @@ mesh_send_reply(struct mesh_state* m, int rcode, struct reply_info* rep, (rep->security <= sec_status_bogus || rep->security == sec_status_secure_sentinel_fail)) { - EDNS_OPT_APPEND_EDE(&r->edns, m->s.region, - LDNS_EDE_DNSSEC_BOGUS, ""); + char *reason = m->s.env->cfg->val_log_level >= 2 + ? errinf_to_str_bogus(&m->s) : NULL; + + edns_opt_append_ede(&r->edns, m->s.region, + LDNS_EDE_DNSSEC_BOGUS, reason); + free(reason); } error_encode(r_buffer, rcode, &m->s.qinfo, r->qid, r->qflags, &r->edns); diff --git a/util/data/msgreply.c b/util/data/msgreply.c index 00272fd1c..9e64b139b 100644 --- a/util/data/msgreply.c +++ b/util/data/msgreply.c @@ -988,6 +988,35 @@ int edns_opt_append(struct edns_data* edns, struct regional* region, return 1; } +int edns_opt_append_ede(struct edns_data* edns, struct regional* region, + sldns_ede_code code, const char *txt) +{ + struct edns_option** prevp; + struct edns_option* opt; + size_t txt_len = txt ? strlen(txt) : 0; + + /* allocate new element */ + opt = (struct edns_option*)regional_alloc(region, sizeof(*opt)); + if(!opt) + return 0; + opt->next = NULL; + opt->opt_code = LDNS_EDNS_EDE; + opt->opt_len = txt_len + sizeof(uint16_t); + opt->opt_data = regional_alloc(region, txt_len + sizeof(uint16_t)); + if(!opt->opt_data) + return 0; + sldns_write_uint16(opt->opt_data, (uint16_t)code); + if (txt_len) + strncpy(opt->opt_data + 2, txt, txt_len); + + /* append at end of list */ + prevp = &edns->opt_list; + while(*prevp != NULL) + prevp = &((*prevp)->next); + *prevp = opt; + return 1; +} + int edns_opt_list_append(struct edns_option** list, uint16_t code, size_t len, uint8_t* data, struct regional* region) { diff --git a/util/data/msgreply.h b/util/data/msgreply.h index 715f1cf64..09f6997c3 100644 --- a/util/data/msgreply.h +++ b/util/data/msgreply.h @@ -43,6 +43,7 @@ #define UTIL_DATA_MSGREPLY_H #include "util/storage/lruhash.h" #include "util/data/packed_rrset.h" +#include "sldns/rrdef.h" struct sldns_buffer; struct comm_reply; struct alloc_cache; @@ -531,7 +532,18 @@ int edns_opt_append(struct edns_data* edns, struct regional* region, edns_opt_append((EDNS), (REGION), LDNS_EDNS_EDE, \ sizeof(uint16_t) + sizeof(TXT) - 1, \ (void *)&ede); \ - } while(0); + } while(0) + +/** + * Append edns EDE option to edns options list + * @param edns: the edns data structure to append the edns option to. + * @param region: region to allocate the new edns option. + * @param code: the EDE code. + * @param txt: Additional text for the option + * @return false on failure. + */ +int edns_opt_append_ede(struct edns_data* edns, struct regional* region, + sldns_ede_code code, const char *txt); /** * Append edns option to edns option list -- 2.47.2