X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=adns.git;a=blobdiff_plain;f=src%2Freply.c;h=246d52d44fe0a796018b0b15666be9710909fbe6;hp=ab7c8ff4aadbc37c6cdb589baf43b49aa384cc88;hb=914a5ff5342e43d8a2378b1f0f65057ef084fe20;hpb=660d7d3b4af029c3e86fdfe1ac078815c41ed79e diff --git a/src/reply.c b/src/reply.c index ab7c8ff..246d52d 100644 --- a/src/reply.c +++ b/src/reply.c @@ -3,7 +3,12 @@ * - main handling and parsing routine for received datagrams */ /* - * This file is part of adns, which is Copyright (C) 1997-1999 Ian Jackson + * This file is + * Copyright (C) 1997-1999 Ian Jackson + * + * It is part of adns, which is + * Copyright (C) 1997-1999 Ian Jackson + * Copyright (C) 1999 Tony Finch * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,12 +26,11 @@ */ #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; @@ -81,7 +85,7 @@ void adns__procdgram(adns_state ads, const byte *dgram, int dglen, qdcount); return; } - for (qu= ads->timew.head; qu; qu= nqu) { + for (qu= viatcp ? ads->tcpw.head : ads->udpw.head; qu; qu= nqu) { nqu= qu->next; if (qu->id != id) continue; if (dglen < qu->query_dglen) continue; @@ -89,6 +93,12 @@ void adns__procdgram(adns_state ads, const byte *dgram, int dglen, dgram+DNS_HDRSIZE, qu->query_dglen-DNS_HDRSIZE)) continue; + if (viatcp) { + assert(qu->state == query_tcpw); + } else { + assert(qu->state == query_tosend); + if (!(qu->udpsent & (1<query_dglen; arstart= -1; - LIST_UNLINK(ads->timew,qu); + if (viatcp) LIST_UNLINK(ads->tcpw,qu); + else LIST_UNLINK(ads->udpw,qu); /* We're definitely going to do something with this query now */ switch (rcode) { @@ -161,7 +172,16 @@ void adns__procdgram(adns_state ads, const byte *dgram, int dglen, 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,"allegedly canonical name %s is actually alias for %s", + qu->answer->cname, + adns__diag_domain(ads,serv,qu, &qu->vb, dgram,dglen,rdstart)); + adns__query_fail(qu,adns_s_prohibitedcname); + return; + } 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, @@ -170,7 +190,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); @@ -184,10 +204,6 @@ void adns__procdgram(adns_state ads, const byte *dgram, int dglen, * 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++; @@ -303,11 +319,10 @@ void adns__procdgram(adns_state ads, const byte *dgram, int dglen, /* This may have generated some child queries ... */ if (qu->children.head) { - qu->state= query_child; + qu->state= query_childw; LIST_LINK_TAIL(ads->childw,qu); return; } - adns__query_done(qu); return; @@ -321,7 +336,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, @@ -336,6 +350,8 @@ 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_tcpw) qu->state= query_tosend; + qu->retries= 0; + adns__reset_preserved(qu); + adns__query_send(qu,now); }