chiark / gitweb /
+ * Many memory leaks fixed.
[adns.git] / src / reply.c
index 4dec0e3f661fb8a0b616ee85da6d2b0e206db950..246d52d44fe0a796018b0b15666be9710909fbe6 100644 (file)
@@ -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 <ian@davenant.greenend.org.uk>
+ *
+ *  It is part of adns, which is
+ *    Copyright (C) 1997-1999 Ian Jackson <ian@davenant.greenend.org.uk>
+ *    Copyright (C) 1999 Tony Finch <dot@dotat.at>
  *  
  *  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,7 +26,6 @@
  */
 
 #include <stdlib.h>
-#include <string.h>
 
 #include "internal.h"
     
@@ -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;
@@ -90,9 +94,9 @@ void adns__procdgram(adns_state ads, const byte *dgram, int dglen,
               qu->query_dglen-DNS_HDRSIZE))
       continue;
     if (viatcp) {
-      if (qu->state != query_tcpsent) continue;
+      assert(qu->state == query_tcpw);
     } else {
-      if (qu->state != query_tosend) continue;
+      assert(qu->state == query_tosend);
       if (!(qu->udpsent & (1<<serv))) continue;
     }
     break;
@@ -109,7 +113,8 @@ void adns__procdgram(adns_state ads, const byte *dgram, int dglen,
   anstart= qu->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) {
@@ -168,9 +173,11 @@ void adns__procdgram(adns_state ads, const byte *dgram, int dglen,
        adns__query_fail(qu,adns_s_prohibitedcname);
        return;
       } 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);
+       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));
@@ -312,7 +319,7 @@ 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;
   }
@@ -343,7 +350,8 @@ void adns__procdgram(adns_state ads, const byte *dgram, int dglen,
     memcpy(newquery,qu->vb.buf,qu->vb.used);
   }
   
-  if (qu->state == query_tcpsent) qu->state= query_tosend;
+  if (qu->state == query_tcpw) qu->state= query_tosend;
+  qu->retries= 0;
   adns__reset_preserved(qu);
   adns__query_send(qu,now);
 }