]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
add cached EDE strings
authorTCY16 <tom@nlnetlabs.nl>
Wed, 21 Sep 2022 09:21:33 +0000 (11:21 +0200)
committerTCY16 <tom@nlnetlabs.nl>
Wed, 21 Sep 2022 09:21:33 +0000 (11:21 +0200)
daemon/worker.c
iterator/iterator.c
util/data/msgreply.c
util/data/msgreply.h
validator/validator.c

index bbe9d07afc83cd94b906331a1d605efb0139f35d..3f94b22d30638c4616990f2ae9591040563b1b6e 100644 (file)
@@ -484,11 +484,18 @@ answer_norec_from_cache(struct worker* worker, struct query_info* qinfo,
                                msg->rep, LDNS_RCODE_SERVFAIL, edns, repinfo, worker->scratchpad,
                                worker->env.now_tv))
                                        return 0;
-                       /* TODO store the reason for the bogus reply in cache
-                        * and implement in here instead of the hardcoded EDE */
+                       /* Attached the cached EDE (RFC8914) */
                        if (worker->env.cfg->ede) {
-                               EDNS_OPT_LIST_APPEND_EDE(&edns->opt_list_out,
-                                       worker->scratchpad, msg->rep->reason_bogus, "");
+                               size_t reason_bogus_str_len = 0;
+                               char* reason_bogus_str = msg->rep->reason_bogus_str;
+
+                               if (reason_bogus_str) {
+                                       reason_bogus_str_len = strlen(reason_bogus_str);
+                               }
+
+                               edns_opt_list_append(&edns->opt_list_out,
+                                       msg->rep->reason_bogus, reason_bogus_str_len,
+                                       reason_bogus_str, worker->scratchpad);
                        }
                        error_encode(repinfo->c->buffer, LDNS_RCODE_SERVFAIL, 
                                &msg->qinfo, id, flags, edns);
@@ -660,11 +667,18 @@ answer_from_cache(struct worker* worker, struct query_info* qinfo,
                        LDNS_RCODE_SERVFAIL, edns, repinfo, worker->scratchpad,
                        worker->env.now_tv))
                        goto bail_out;
-               /* TODO store the reason for the bogus reply in cache
-                * and implement in here instead of the hardcoded EDE */
+               /* Attached the cached EDE (RFC8914) */
                if (worker->env.cfg->ede) {
-                       EDNS_OPT_LIST_APPEND_EDE(&edns->opt_list_out,
-                               worker->scratchpad, rep->reason_bogus, "");
+                       size_t reason_bogus_str_len = 0;
+                       char* reason_bogus_str = rep->reason_bogus_str;
+
+                       if (reason_bogus_str) {
+                               reason_bogus_str_len = strlen(reason_bogus_str);
+                       }
+
+                       edns_opt_list_append(&edns->opt_list_out,
+                               rep->reason_bogus, reason_bogus_str_len,
+                               reason_bogus_str, worker->scratchpad);
                }
                error_encode(repinfo->c->buffer, LDNS_RCODE_SERVFAIL,
                        qinfo, id, flags, edns);
index 25e5cfee46453533be20e6b5e9fcf0798a31d181..07f1cc26bc9e7375824fce67f06ba4768594bc26 100644 (file)
@@ -373,6 +373,7 @@ error_response_cache(struct module_qstate* qstate, int id, int rcode)
                err.serve_expired_ttl = NORR_TTL;
                /* do not waste time trying to validate this servfail */
                err.security = sec_status_indeterminate;
+               err.reason_bogus_str = NULL;
                verbose(VERB_ALGO, "store error response in message cache");
                iter_dns_store(qstate->env, &qstate->qinfo, &err, 0, 0, 0, NULL,
                        qstate->query_flags, qstate->qstarttime);
@@ -3737,6 +3738,9 @@ processFinished(struct module_qstate* qstate, struct iter_qstate* iq,
        /* make sure QR flag is on */
        iq->response->rep->flags |= BIT_QR;
 
+       /* explicitly set the EDE string size to 0 */
+       iq->response->rep->reason_bogus_str_size = 0;
+
        /* we have finished processing this query */
        qstate->ext_state[id] = module_finished;
 
index 59d7b957d4df79ac1cdfa88be6e8d614a761abaa..9c0d8565fe1bddf5ec33fdeaf3e883ab4a0999bf 100644 (file)
@@ -117,12 +117,16 @@ construct_reply_info_base(struct regional* region, uint16_t flags, size_t qd,
        rep->ar_numrrsets = ar;
        rep->rrset_count = total;
        rep->security = sec;
-       /* veryify that we set the EDE to none by setting it explicitly */
+       /* verify that we set the EDE to none by setting it explicitly */
        if (reason_bogus != LDNS_EDE_NONE) {
                rep->reason_bogus = reason_bogus;
        } else {
                rep->reason_bogus = LDNS_EDE_NONE;
        }
+       /* only allocated and used on copy @TODO verify this */
+       rep->reason_bogus_str = NULL;
+       rep->reason_bogus_str_size = 0;
+
        rep->authoritative = 0;
        /* array starts after the refs */
        if(region)
@@ -585,6 +589,7 @@ reply_info_parsedelete(struct reply_info* rep, struct alloc_cache* alloc)
        for(i=0; i<rep->rrset_count; i++) {
                ub_packed_rrset_parsedelete(rep->rrsets[i], alloc);
        }
+       // @TODO free reason_bogus_str
        free(rep);
 }
 
@@ -753,6 +758,19 @@ reply_info_copy(struct reply_info* rep, struct alloc_cache* alloc,
                rep->rrset_count, rep->security, rep->reason_bogus);
        if(!cp)
                return NULL;
+
+       if (rep->reason_bogus_str_size > 0 && rep->reason_bogus_str) {
+               cp->reason_bogus_str = malloc(sizeof(char) * (rep->reason_bogus_str_size + 1));
+
+               if (!(cp->reason_bogus_str)) {
+                       // @TODO add this?
+                       // if(!region)
+                       //      reply_info_parsedelete(cp, alloc);
+                       return NULL;
+               }
+               memcpy(cp->reason_bogus_str, rep->reason_bogus_str, rep->reason_bogus_str_size+1);
+       }
+
        /* allocate ub_key structures special or not */
        if(!reply_info_alloc_rrset_keys(cp, alloc, region)) {
                if(!region)
index cca0d6c496a16cd1a8b10a5a67f4d95dabb7c90b..c3ca39f09f436d618e2420ed9c43a7e6be71e12c 100644 (file)
@@ -173,6 +173,17 @@ struct reply_info {
         */
        sldns_ede_code reason_bogus;
 
+        /**
+         * EDE (rfc8914) text string with human-readable reason for DNSSEC
+         * bogus status. Used for caching the EDE.
+         */
+        char* reason_bogus_str;
+
+        /**
+         * EDE (rfc8914) text string size.
+         */
+        size_t reason_bogus_str_size;
+
        /**
         * Number of RRsets in each section.
         * The answer section. Add up the RRs in every RRset to calculate
index 1723afefe353e4643ad5ed2d4b7c3751c6a4c597..44e4932928838b6585eeae371febc9ce202ad533 100644 (file)
@@ -2151,9 +2151,16 @@ processFinished(struct module_qstate* qstate, struct val_qstate* vq,
                                log_query_info(NO_VERBOSE, "validation failure",
                                        &qstate->qinfo);
                        else {
-                               char* err = errinf_to_str_bogus(qstate);
-                               if(err) log_info("%s", err);
-                               free(err);
+                               char* err_str = errinf_to_str_bogus(qstate);
+                               if(err_str) {
+                                       size_t err_str_len = strlen(err_str);
+
+                                       /* allocate space and store the error string and it's size*/
+                                       vq->orig_msg->rep->reason_bogus_str = malloc(sizeof(char) * (err_str_len + 1));
+                                       memcpy(vq->orig_msg->rep->reason_bogus_str, err_str, err_str_len + 1);
+                                       vq->orig_msg->rep->reason_bogus_str_size = err_str_len;
+                               }
+                               free(err_str);
                        }
                }
                /*
@@ -2195,6 +2202,7 @@ processFinished(struct module_qstate* qstate, struct val_qstate* vq,
                        }
                }
        }
+
        /* store results in cache */
        if(qstate->query_flags&BIT_RD) {
                /* if secure, this will override cache anyway, no need