From b0daf867c25b33acb2cc7caa0e27c799e3d39961 Mon Sep 17 00:00:00 2001 From: Wouter Wijngaards Date: Fri, 17 Aug 2018 14:17:48 +0000 Subject: [PATCH] and the error looks good. git-svn-id: file:///svn/unbound/trunk@4860 be551aaa-1e26-0410-a405-d3ace91eadb9 --- iterator/iterator.c | 7 ++++--- services/mesh.c | 18 +++++------------- util/config_file.c | 27 ++++++++++++++++++++++++++- util/config_file.h | 12 ++++++++++-- validator/val_kcache.c | 2 +- validator/validator.c | 2 +- 6 files changed, 47 insertions(+), 21 deletions(-) diff --git a/iterator/iterator.c b/iterator/iterator.c index db7cdf539..52cfe7af6 100644 --- a/iterator/iterator.c +++ b/iterator/iterator.c @@ -1853,7 +1853,8 @@ processLastResort(struct module_qstate* qstate, struct iter_qstate* iq, iq->qchase.qclass, NULL)) { /* fail -- no more targets, no more hope of targets, no hope * of a response. */ - errinf(qstate, "all the configured stub or forward servers failed"); + errinf(qstate, "all the configured stub or forward servers failed,"); + errinf_dname(qstate, "at zone", iq->dp->name); verbose(VERB_QUERY, "configured stub or forward servers failed -- returning SERVFAIL"); return error_response_cache(qstate, id, LDNS_RCODE_SERVFAIL); } @@ -1990,8 +1991,8 @@ processLastResort(struct module_qstate* qstate, struct iter_qstate* iq, iq->deleg_msg?iq->deleg_msg->rep: (iq->response?iq->response->rep:NULL)); - errinf(qstate, "all servers for this domain failed"); - errinf_dname(qstate, ", at zonecut", iq->dp->name); + errinf(qstate, "all servers for this domain failed,"); + errinf_dname(qstate, "at zone", iq->dp->name); verbose(VERB_QUERY, "out of query targets -- returning SERVFAIL"); /* fail -- no more targets, no more hope of targets, no hope * of a response. */ diff --git a/services/mesh.c b/services/mesh.c index 38f9d99f8..536293a2f 100644 --- a/services/mesh.c +++ b/services/mesh.c @@ -980,7 +980,7 @@ mesh_do_callback(struct mesh_state* m, int rcode, struct reply_info* rep, rcode = LDNS_RCODE_SERVFAIL; if(!rcode && (rep->security == sec_status_bogus || rep->security == sec_status_secure_sentinel_fail)) { - if(!(reason = errinf_to_str(&m->s))) + if(!(reason = errinf_to_str_bogus(&m->s))) rcode = LDNS_RCODE_SERVFAIL; } /* send the reply */ @@ -1157,18 +1157,10 @@ void mesh_query_done(struct mesh_state* mstate) mstate->s.return_msg->rep:NULL); if(mstate->s.return_rcode == LDNS_RCODE_SERVFAIL || (rep && FLAGS_GET_RCODE(rep->flags) == LDNS_RCODE_SERVFAIL)) { - char* err = errinf_to_str(&mstate->s); - if(err) { - char nm[255+1]; - char* tp = sldns_wire2str_type(mstate->s.qinfo.qtype); - char* cl = sldns_wire2str_class(mstate->s.qinfo.qclass); - dname_str(mstate->s.qinfo.qname, nm); - log_err("query %s %s %s SERVFAIL with reason: %s", - nm, tp?tp:"t", cl?cl:"c", err); - free(err); - free(tp); - free(cl); - } + char* err = errinf_to_str_servfail(&mstate->s); + if(err) + log_err("%s", err); + free(err); } for(r = mstate->reply_list; r; r = r->next) { /* if a response-ip address block has been stored the diff --git a/util/config_file.c b/util/config_file.c index a2efbd87d..03296c878 100644 --- a/util/config_file.c +++ b/util/config_file.c @@ -2233,7 +2233,7 @@ void errinf_origin(struct module_qstate* qstate, struct sock_list *origin) } } -char* errinf_to_str(struct module_qstate* qstate) +char* errinf_to_str_bogus(struct module_qstate* qstate) { char buf[20480]; char* p = buf; @@ -2258,6 +2258,31 @@ char* errinf_to_str(struct module_qstate* qstate) return p; } +char* errinf_to_str_servfail(struct module_qstate* qstate) +{ + char buf[20480]; + char* p = buf; + size_t left = sizeof(buf); + struct config_strlist* s; + char dname[LDNS_MAX_DOMAINLEN+1]; + char t[16], c[16]; + sldns_wire2str_type_buf(qstate->qinfo.qtype, t, sizeof(t)); + sldns_wire2str_class_buf(qstate->qinfo.qclass, c, sizeof(c)); + dname_str(qstate->qinfo.qname, dname); + snprintf(p, left, "SERVFAIL <%s %s %s>:", dname, t, c); + left -= strlen(p); p += strlen(p); + if(!qstate->errinf) + snprintf(p, left, " misc failure"); + else for(s=qstate->errinf; s; s=s->next) { + snprintf(p, left, " %s", s->str); + left -= strlen(p); p += strlen(p); + } + p = strdup(buf); + if(!p) + log_err("malloc failure in errinf_to_str"); + return p; +} + void errinf_rrset(struct module_qstate* qstate, struct ub_packed_rrset_key *rr) { char buf[1024]; diff --git a/util/config_file.h b/util/config_file.h index 0f188e624..64794705b 100644 --- a/util/config_file.h +++ b/util/config_file.h @@ -1078,12 +1078,20 @@ void errinf_dname(struct module_qstate* qstate, const char* str, uint8_t* dname); /** - * Create error info in string + * Create error info in string. For validation failures. * @param qstate: query state. * @return string or NULL on malloc failure (already logged). * This string is malloced and has to be freed by caller. */ -char* errinf_to_str(struct module_qstate* qstate); +char* errinf_to_str_bogus(struct module_qstate* qstate); + +/** + * Create error info in string. For other servfails. + * @param qstate: query state. + * @return string or NULL on malloc failure (already logged). + * This string is malloced and has to be freed by caller. + */ +char* errinf_to_str_servfail(struct module_qstate* qstate); /** * Used during options parsing diff --git a/validator/val_kcache.c b/validator/val_kcache.c index 22070cc6a..e0b88b6df 100644 --- a/validator/val_kcache.c +++ b/validator/val_kcache.c @@ -89,7 +89,7 @@ key_cache_insert(struct key_cache* kcache, struct key_entry_key* kkey, if(key_entry_isbad(k) && qstate->errinf && qstate->env->cfg->val_log_level >= 2) { /* on malloc failure there is simply no reason string */ - key_entry_set_reason(k, errinf_to_str(qstate)); + key_entry_set_reason(k, errinf_to_str_bogus(qstate)); } key_entry_hash(k); slabhash_insert(kcache->slab, k->entry.hash, &k->entry, diff --git a/validator/validator.c b/validator/validator.c index 7b1ebc7b7..2f13dc005 100644 --- a/validator/validator.c +++ b/validator/validator.c @@ -2241,7 +2241,7 @@ processFinished(struct module_qstate* qstate, struct val_qstate* vq, log_query_info(0, "validation failure", &qstate->qinfo); else { - char* err = errinf_to_str(qstate); + char* err = errinf_to_str_bogus(qstate); if(err) log_info("%s", err); free(err); } -- 2.47.3