X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Freply.c;h=61fee52fee8cd77c74c607bbc9187206555b7dda;hb=33ae0dddfdde95bedb160eae8059ba1a271cf7ea;hp=c37bb4069683038b858fb99cd070f89f5c775472;hpb=a719a4bedec2bc512b7f95f7446e02f6662ebbc7;p=adns.git diff --git a/src/reply.c b/src/reply.c index c37bb40..61fee52 100644 --- a/src/reply.c +++ b/src/reply.c @@ -21,18 +21,18 @@ */ #include -#include #include "internal.h" void adns__procdgram(adns_state ads, const byte *dgram, int dglen, - int serv, struct timeval now) { + int serv, int viatcp, struct timeval now) { int cbyte, rrstart, wantedrrs, rri, foundsoa, foundns, cname_here; int id, f1, f2, qdcount, ancount, nscount, arcount; int flg_ra, flg_rd, flg_tc, flg_qr, opcode; int rrtype, rrclass, rdlength, rdstart; int anstart, nsstart, arstart; int ownermatched, l, nrrs; + unsigned long ttl, soattl; const typeinfo *typei; adns_query qu, nqu; dns_rcode rcode; @@ -88,6 +88,12 @@ void adns__procdgram(adns_state ads, const byte *dgram, int dglen, dgram+DNS_HDRSIZE, qu->query_dglen-DNS_HDRSIZE)) continue; + if (viatcp) { + if (qu->state != query_tcpsent) continue; + } else { + if (qu->state != query_tosend) continue; + if (!(qu->udpsent & (1<typei->type & adns__rrt_typemask) != adns_r_cname) { if (qu->flags & adns_qf_cname_forbid) { adns__query_fail(qu,adns_s_prohibitedcname); return; - } else if (!qu->cname_dgram) { /* Ignore second and subsequent CNAMEs */ + } else if (qu->cname_dgram) { /* Ignore second and subsequent CNAME(s) */ + adns__debug(ads,serv,qu,"ignoring duplicate CNAME (%s, as well as %s)", + adns__diag_domain(ads,serv,qu, &qu->vb, dgram,dglen,rdstart), + qu->answer->cname); + } else if (wantedrrs) { /* Ignore CNAME(s) after RR(s). */ + adns__debug(ads,serv,qu,"ignoring CNAME (to %s) coexisting with RR", + adns__diag_domain(ads,serv,qu, &qu->vb, dgram,dglen,rdstart)); + } else { qu->cname_begin= rdstart; qu->cname_dglen= dglen; st= adns__parse_domain(ads,serv,qu, &qu->vb, @@ -169,7 +182,7 @@ void adns__procdgram(adns_state ads, const byte *dgram, int dglen, if (!qu->vb.used) goto x_truncated; if (st) { adns__query_fail(qu,st); return; } l= strlen(qu->vb.buf)+1; - qu->answer->cname= adns__alloc_interim(qu,l); + qu->answer->cname= adns__alloc_preserved(qu,l); if (!qu->answer->cname) { adns__query_fail(qu,adns_s_nomemory); return; } qu->cname_dgram= adns__alloc_mine(qu,dglen); @@ -177,15 +190,12 @@ void adns__procdgram(adns_state ads, const byte *dgram, int dglen, memcpy(qu->answer->cname,qu->vb.buf,l); cname_here= 1; + adns__update_expires(qu,ttl,now); /* If we find the answer section truncated after this point we restart * the query at the CNAME; if beforehand then we obviously have to use * TCP. If there is no truncation we can use the whole answer if * it contains the relevant info. */ - } else { - adns__debug(ads,serv,qu,"ignoring duplicate CNAME (%s, as well as %s)", - adns__diag_domain(ads,serv,qu, &qu->vb, dgram,dglen,rdstart), - qu->answer->cname); } } else if (rrtype == (qu->typei->type & adns__rrt_typemask)) { wantedrrs++; @@ -203,18 +213,13 @@ void adns__procdgram(adns_state ads, const byte *dgram, int dglen, if (!wantedrrs) { /* Oops, NODATA or NXDOMAIN or perhaps a referral (which would be a problem) */ - - if (rcode == rcode_nxdomain) { - adns__query_fail(qu,adns_s_nxdomain); - return; - } /* RFC2308: NODATA has _either_ a SOA _or_ _no_ NS records in authority section */ - foundsoa= 0; foundns= 0; + foundsoa= 0; soattl= 0; foundns= 0; for (rri= 0; rriflags & adns_qf_search) { + adns__search_next(ads,qu,now); + } else { + adns__query_fail(qu,adns_s_nxdomain); + } + return; + } if (foundsoa || !foundns) { /* Aha ! A NODATA response, good. */ + adns__update_expires(qu,soattl,now); adns__query_fail(qu,adns_s_nodata); return; } @@ -275,13 +293,14 @@ void adns__procdgram(adns_state ads, const byte *dgram, int dglen, for (rri=0, nrrs=0; rritypei->type & adns__rrt_typemask) || !ownermatched) continue; + adns__update_expires(qu,ttl,now); st= typei->parse(&pai, rdstart,rdstart+rdlength, rrsdata+nrrs*typei->rrsz); if (st) { adns__query_fail(qu,st); return; } if (rdstart==-1) goto x_truncated; @@ -296,7 +315,6 @@ void adns__procdgram(adns_state ads, const byte *dgram, int dglen, LIST_LINK_TAIL(ads->childw,qu); return; } - adns__query_done(qu); return; @@ -310,7 +328,6 @@ void adns__procdgram(adns_state ads, const byte *dgram, int dglen, qu->flags |= adns_qf_usevc; x_restartquery: - if (qu->cname_dgram) { st= adns__mkquery_frdgram(qu->ads,&qu->vb,&qu->id, qu->cname_dgram, qu->cname_dglen, qu->cname_begin, @@ -325,6 +342,7 @@ void adns__procdgram(adns_state ads, const byte *dgram, int dglen, memcpy(newquery,qu->vb.buf,qu->vb.used); } - adns__reset_cnameonly(qu); - adns__query_udp(qu,now); + if (qu->state == query_tcpsent) qu->state= query_tosend; + adns__reset_preserved(qu); + adns__query_send(qu,now); }