]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
Show reason when returning EDE_DNSSEC_BOGUS
authorTom Carpay <tom@nlnetlabs.nl>
Mon, 16 Aug 2021 13:26:55 +0000 (13:26 +0000)
committerTom Carpay <tom@nlnetlabs.nl>
Mon, 16 Aug 2021 13:36:45 +0000 (13:36 +0000)
services/mesh.c
util/data/msgreply.c
util/data/msgreply.h

index 7252413be294c6d6e73398f10a4b5556e261f857..c0050bd25251a84e660533c15467e8ecb578f17c 100644 (file)
@@ -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);
index 00272fd1c64ec8d234e35d0a353f52ad06f4b49a..9e64b139b226c4de7eea44c4250245ec698e0657 100644 (file)
@@ -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)
 {
index 715f1cf64cd8eca5be51f2201cb5c78a064000dc..09f6997c3756120740e63febab58adf6f191a0a1 100644 (file)
@@ -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