chiark / gitweb /
adns_reverse_submit function for easy in-addr queries.
[adns.git] / src / reply.c
index 0ee134a4f9956b0a3067d56e358ee6e85105c58a..4b3d74fa6b5ad6427f3f064da00c0ee0ceb5220f 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
  */
 
 #include <stdlib.h>
-#include <string.h>
 
 #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;
@@ -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) {
+      if (qu->state != query_tcpsent) continue;
+    } else {
+      if (qu->state != query_tosend) continue;
+      if (!(qu->udpsent & (1<<serv))) continue;
+    }
     break;
   }
   if (!qu) {
@@ -161,7 +171,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,
@@ -184,10 +203,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++;
@@ -307,7 +322,6 @@ void adns__procdgram(adns_state ads, const byte *dgram, int dglen,
     LIST_LINK_TAIL(ads->childw,qu);
     return;
   }
-
   adns__query_done(qu);
   return;
 
@@ -321,7 +335,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 +349,7 @@ 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;
   adns__reset_preserved(qu);
-  adns__query_udp(qu,now);
+  adns__query_send(qu,now);
 }