]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
modules/hints: NODATA answers also for non-address queries
authorVladimír Čunát <vladimir.cunat@nic.cz>
Wed, 20 May 2020 12:30:15 +0000 (14:30 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Mon, 25 May 2020 13:32:49 +0000 (15:32 +0200)
Apparently the original implementation in 14de9110 didn't think of this.
Noticed by Fantomas:
https://forum.turris.cz/t/kresd-returns-nxdomain-for-local-mx-records/12991

NEWS
modules/hints/hints.c

diff --git a/NEWS b/NEWS
index bf44bb2e342567fa7a46f8f4aa37d76697047bcb..6a4a6fc8d6db0dcd468d6f5a0dd61ac12a6f1389 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,11 @@
+Knot Resolver 5.x.y (2020-0m-dd)
+================================
+
+Bugfixes
+--------
+- hints module: NODATA answers also for non-address queries (!1005)
+
+
 Knot Resolver 5.1.1 (2020-05-19)
 ================================
 
index 7473a34c780011898160686840418930e6a708f0..cf85449c3725ae541427c0c603a41922abf5b642 100644 (file)
@@ -106,10 +106,18 @@ static int satisfy_forward(/*const*/ struct hints_data *data,
        knot_dname_t *qname = knot_dname_copy(qry->sname, &pkt->mm);
        knot_rrset_t rr;
        knot_rrset_init(&rr, qname, qry->stype, qry->sclass, data->ttl);
-       size_t family_len = sizeof(struct in_addr);
-       if (rr.type == KNOT_RRTYPE_AAAA) {
+
+       size_t family_len;
+       switch (rr.type) {
+       case KNOT_RRTYPE_A:
+               family_len = sizeof(struct in_addr);
+               break;
+       case KNOT_RRTYPE_AAAA:
                family_len = sizeof(struct in6_addr);
-       }
+               break;
+       default:
+               goto finish;
+       };
 
        /* Append address records from hints */
        uint8_t *addr = pack_head(*addr_set);
@@ -121,7 +129,7 @@ static int satisfy_forward(/*const*/ struct hints_data *data,
                }
                addr = pack_obj_next(addr);
        }
-
+finish:
        return put_answer(pkt, qry, &rr, data->use_nodata);
 }
 
@@ -137,20 +145,19 @@ static int query(kr_layer_t *ctx, knot_pkt_t *pkt)
        if (!data) { /* No valid file. */
                return ctx->state;
        }
+       /* We can optimize for early return like this: */
+       if (!data->use_nodata && qry->stype != KNOT_RRTYPE_A
+           && qry->stype != KNOT_RRTYPE_AAAA && qry->stype != KNOT_RRTYPE_PTR) {
+               return ctx->state;
+       }
        /* FIXME: putting directly into packet breaks ordering in case the hint
         * is applied after a CNAME jump. */
-       switch(qry->stype) {
-       case KNOT_RRTYPE_A:
-       case KNOT_RRTYPE_AAAA: /* Find forward record hints */
-               if (satisfy_forward(data, pkt, qry) != 0)
-                       return ctx->state;
-               break;
-       case KNOT_RRTYPE_PTR: /* Find PTR record */
+       if (knot_dname_in_bailiwick(qry->sname, (const uint8_t *)"\4arpa\0") >= 0) {
                if (satisfy_reverse(data, pkt, qry) != 0)
                        return ctx->state;
-               break;
-       default:
-               return ctx->state; /* Ignore */
+       } else {
+               if (satisfy_forward(data, pkt, qry) != 0)
+                       return ctx->state;
        }
 
        VERBOSE_MSG(qry, "<= answered from hints\n");