From 09e18ffdbbf803f613a9d388c7a5f9a7bb1a019f Mon Sep 17 00:00:00 2001 From: Wouter Wijngaards Date: Fri, 8 Feb 2008 12:24:01 +0000 Subject: [PATCH] fixup validator classification of root referrals. git-svn-id: file:///svn/unbound/trunk@936 be551aaa-1e26-0410-a405-d3ace91eadb9 --- doc/Changelog | 2 ++ validator/val_utils.c | 13 ++++++++++--- validator/val_utils.h | 4 +++- validator/validator.c | 14 +++++++------- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/doc/Changelog b/doc/Changelog index ff85eb9a9..e978906b8 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -2,6 +2,8 @@ - test program for multiple queries over a TCP channel. - tpkg test for stream tcp queries. - unbound replies to multiple TCP queries on a TCP channel. + - fixup misclassification of root referral with NS in answer + when validating a nonrec query. 7 February 2008: Wouter - moved up all current level 2 to be level 3. And 3 to 4. diff --git a/validator/val_utils.c b/validator/val_utils.c index 79cd5f4be..f95e8014a 100644 --- a/validator/val_utils.c +++ b/validator/val_utils.c @@ -53,8 +53,8 @@ #include "util/regional.h" enum val_classification -val_classify_response(uint16_t query_flags, struct query_info* qinf, - struct reply_info* rep, size_t skip) +val_classify_response(uint16_t query_flags, struct query_info* origqinf, + struct query_info* qinf, struct reply_info* rep, size_t skip) { int rcode = (int)FLAGS_GET_RCODE(rep->flags); size_t i; @@ -82,7 +82,14 @@ val_classify_response(uint16_t query_flags, struct query_info* qinf, } return saw_ns?VAL_CLASS_REFERRAL:VAL_CLASS_NODATA; } - + /* root referral where NS set is in the answer section */ + if(!(query_flags&BIT_RD) && rep->ns_numrrsets == 0 && + rep->an_numrrsets == 1 && rcode == LDNS_RCODE_NOERROR && + ntohs(rep->rrsets[0]->rk.type) == LDNS_RR_TYPE_NS && + query_dname_compare(rep->rrsets[0]->rk.dname, + origqinf->qname) != 0) + return VAL_CLASS_REFERRAL; + /* dump bad messages */ if(rcode != LDNS_RCODE_NOERROR) return VAL_CLASS_UNKNOWN; diff --git a/validator/val_utils.h b/validator/val_utils.h index 415e8fbfd..db1a77a67 100644 --- a/validator/val_utils.h +++ b/validator/val_utils.h @@ -80,6 +80,7 @@ enum val_classification { /** * Given a response, classify ANSWER responses into a subtype. * @param query_flags: query flags for the original query. + * @param origqinf: query info. The original query name. * @param qinf: query info. The chased query name. * @param rep: response. The original response. * @param skip: offset into the original response answer section. @@ -88,7 +89,8 @@ enum val_classification { * Then, another CNAME type, CNAME_NOANSWER or POSITIVE are possible. */ enum val_classification val_classify_response(uint16_t query_flags, - struct query_info* qinf, struct reply_info* rep, size_t skip); + struct query_info* origqinf, struct query_info* qinf, + struct reply_info* rep, size_t skip); /** * Given a response, determine the name of the "signer". This is primarily diff --git a/validator/validator.c b/validator/validator.c index 2f2e0115a..2e719f562 100644 --- a/validator/validator.c +++ b/validator/validator.c @@ -1090,8 +1090,8 @@ processInit(struct module_qstate* qstate, struct val_qstate* vq, uint8_t* lookup_name; size_t lookup_len; enum val_classification subtype = val_classify_response( - qstate->query_flags, &vq->qchase, vq->orig_msg->rep, - vq->rrset_skip); + qstate->query_flags, &qstate->qinfo, &vq->qchase, + vq->orig_msg->rep, vq->rrset_skip); verbose(VERB_ALGO, "validator classification %s", val_classification_to_string(subtype)); if(subtype == VAL_CLASS_REFERRAL && @@ -1388,8 +1388,8 @@ processValidate(struct module_qstate* qstate, struct val_qstate* vq, return 1; } - subtype = val_classify_response(qstate->query_flags, &vq->qchase, - vq->orig_msg->rep, vq->rrset_skip); + subtype = val_classify_response(qstate->query_flags, &qstate->qinfo, + &vq->qchase, vq->orig_msg->rep, vq->rrset_skip); switch(subtype) { case VAL_CLASS_POSITIVE: verbose(VERB_ALGO, "Validating a positive response"); @@ -1478,8 +1478,8 @@ processFinished(struct module_qstate* qstate, struct val_qstate* vq, struct val_env* ve, int id) { enum val_classification subtype = val_classify_response( - qstate->query_flags, &vq->qchase, vq->orig_msg->rep, - vq->rrset_skip); + qstate->query_flags, &qstate->qinfo, &vq->qchase, + vq->orig_msg->rep, vq->rrset_skip); /* store overall validation result in orig_msg */ if(vq->rrset_skip == 0) @@ -1787,7 +1787,7 @@ ds_response_to_ke(struct module_qstate* qstate, struct val_qstate* vq, goto return_bogus; } - subtype = val_classify_response(BIT_RD, qinfo, msg->rep, 0); + subtype = val_classify_response(BIT_RD, qinfo, qinfo, msg->rep, 0); if(subtype == VAL_CLASS_POSITIVE) { struct ub_packed_rrset_key* ds; enum sec_status sec; -- 2.47.2