---------------------
PatchSet 4121 
Date: 2007/03/25 13:18:51
Author: amosjeffries
Branch: squid3-ipv6
Tag: (none) 
Log:
Backed out all old macro conversion changes to rfc1035 library.
 - DNS lookups somewhere are creating a Malformed DNS packet
   'new' code here has major logic flaws, so its coming out for a while.

Members: 
	NOTES-IPv6:1.1.2.5->1.1.2.6 
	include/rfc1035.h:1.2.8.3->1.2.8.4 
	lib/rfc1035.c:1.5.2.12->1.5.2.13 

Index: squid3/NOTES-IPv6
===================================================================
RCS file: /cvsroot/squid-sf//squid3/Attic/NOTES-IPv6,v
retrieving revision 1.1.2.5
retrieving revision 1.1.2.6
diff -u -r1.1.2.5 -r1.1.2.6
--- squid3/NOTES-IPv6	5 Mar 2007 11:27:00 -0000	1.1.2.5
+++ squid3/NOTES-IPv6	25 Mar 2007 13:18:51 -0000	1.1.2.6
@@ -1,15 +1,27 @@
-$Id: NOTES-IPv6,v 1.1.2.5 2007/03/05 11:27:00 amosjeffries Exp $
+$Id: NOTES-IPv6,v 1.1.2.6 2007/03/25 13:18:51 amosjeffries Exp $
+
+KNOWN BUGS:
+
+1)
+'(110) Connecton Timeout' on request.
+CAUSE: Malformed DNS Packet sent by squid. Located using wireshark which shows a single-byte of DNS packet.
+
+ Code location for this bug is still unknown.
+
+
+2)
+ApplyMask
+  - produces a strange IPA through NtoA in debug trace.
+  - appears to be strange input from hostent
+
 
 TODO:
 
 1.0	Complete coding of IPAddress.cc (marked TODO or FIXME in comments)
 
-1.1	Migrate code to using IPAddress object over any other method of struct storage
-
-2.1	Find and Fix Request Denied Error (due to DNS timeout) in IPv4 build.
+1.1	Complete testing of IPAddress object individual methods and operations.
 
-2.2	Compile Errors:
-		from "./configure --enable-ipv6 && make"
+1.2	Migrate code to using IPAddress object over any other method of struct storage
 
 3	Determin what plumbing can still be passed up immediately to simplify
 
Index: squid3/include/rfc1035.h
===================================================================
RCS file: /cvsroot/squid-sf//squid3/include/rfc1035.h,v
retrieving revision 1.2.8.3
retrieving revision 1.2.8.4
diff -u -r1.2.8.3 -r1.2.8.4
--- squid3/include/rfc1035.h	5 Jan 2007 16:57:38 -0000	1.2.8.3
+++ squid3/include/rfc1035.h	25 Mar 2007 13:19:08 -0000	1.2.8.4
@@ -1,5 +1,5 @@
 /*
- * $Id: rfc1035.h,v 1.2.8.3 2007/01/05 16:57:38 hno Exp $
+ * $Id: rfc1035.h,v 1.2.8.4 2007/03/25 13:19:08 amosjeffries Exp $
  *
  * AUTHOR: Duane Wessels
  *
@@ -85,13 +85,6 @@
     size_t sz,
     unsigned short qid,
     rfc1035_query * query);
-
-SQUIDCEXTERN ssize_t rfc1035BuildAAAAQuery(const char *hostname,
-    char *buf,
-    size_t sz,
-    unsigned short qid,
-    rfc1035_query * query);
-
 SQUIDCEXTERN ssize_t rfc1035BuildPTRQuery(const struct IN_ADDR,
     char *buf,
     size_t sz,
@@ -107,7 +100,6 @@
 SQUIDCEXTERN const char *rfc1035_error_message;
 
 #define RFC1035_TYPE_A 1
-#define RFC1035_TYPE_AAAA 28
 #define RFC1035_TYPE_CNAME 5
 #define RFC1035_TYPE_PTR 12
 #define RFC1035_CLASS_IN 1
Index: squid3/lib/rfc1035.c
===================================================================
RCS file: /cvsroot/squid-sf//squid3/lib/rfc1035.c,v
retrieving revision 1.5.2.12
retrieving revision 1.5.2.13
diff -u -r1.5.2.12 -r1.5.2.13
--- squid3/lib/rfc1035.c	19 Mar 2007 11:44:17 -0000	1.5.2.12
+++ squid3/lib/rfc1035.c	25 Mar 2007 13:19:09 -0000	1.5.2.13
@@ -1,6 +1,6 @@
 
 /*
- * $Id: rfc1035.c,v 1.5.2.12 2007/03/19 11:44:17 amosjeffries Exp $
+ * $Id: rfc1035.c,v 1.5.2.13 2007/03/25 13:19:09 amosjeffries Exp $
  *
  * Low level DNS protocol routines
  * AUTHOR: Duane Wessels
@@ -63,6 +63,9 @@
 #if HAVE_NETINET_IN_H
 #include <netinet/in.h>
 #endif
+#if HAVE_ARPA_INET_H
+#include <arpa/inet.h>
+#endif
 #if HAVE_STRINGS_H
 #include <strings.h>
 #endif
@@ -70,11 +73,6 @@
 #include "rfc1035.h"
 #include "snprintf.h"
 
-/* FIXME INET6 : 19 Mar 2007
- *     Due to compiler options (gcc rather than g++) this file cannot include IPAddress.h
- *     Nor can any code inside it presently use the IPAddress c++ objects.
- */
-
 #define RFC1035_MAXLABELSZ 63
 #define rfc1035_unpack_error 15
 
@@ -411,7 +409,6 @@
 	}
 	break;
     case RFC1035_TYPE_A:
-    case RFC1035_TYPE_AAAA:
     default:
 	RR->rdata = xmalloc(rdlength);
 	memcpy(RR->rdata, buf + (*off), rdlength);
@@ -628,17 +625,17 @@
 }
 
 /*
- * rfc1035BuildHostQuery()
+ * rfc1035BuildAQuery()
  * 
- * Builds a message buffer with a QUESTION to lookup records
+ * Builds a message buffer with a QUESTION to lookup A records
  * for a hostname.  Caller must allocate 'buf' which should
  * probably be at least 512 octets.  The 'szp' initially
  * specifies the size of the buffer, on return it contains
  * the size of the message (i.e. how much to write).
  * Returns the size of the query
  */
-static ssize_t
-rfc1035BuildHostQuery(const char *hostname, char *buf, size_t sz, unsigned short qid, rfc1035_query * query, int qtype, int qclass)
+ssize_t
+rfc1035BuildAQuery(const char *hostname, char *buf, size_t sz, unsigned short qid, rfc1035_query * query)
 {
     static rfc1035_message h;
     size_t offset = 0;
@@ -655,25 +652,14 @@
 	RFC1035_TYPE_A,
 	RFC1035_CLASS_IN);
     if (query) {
-	query->qtype = qtype;
-	query->qclass = qclass;
+	query->qtype = RFC1035_TYPE_A;
+	query->qclass = RFC1035_CLASS_IN;
 	xstrncpy(query->name, hostname, sizeof(query->name));
     }
     assert(offset <= sz);
     return offset;
 }
 
-ssize_t
-rfc1035BuildAQuery(const char *hostname, char *buf, size_t sz, unsigned short qid, rfc1035_query * query)
-{
-    return rfc1035BuildHostQuery(hostname, buf, sz, qid, query, RFC1035_TYPE_A, RFC1035_CLASS_IN);
-}
-
-ssize_t
-rfc1035BuildAAAAQuery(const char *hostname, char *buf, size_t sz, unsigned short qid, rfc1035_query * query)
-{
-    return rfc1035BuildHostQuery(hostname, buf, sz, qid, query, RFC1035_TYPE_AAAA, RFC1035_CLASS_IN);
-}
 /*
  * rfc1035BuildPTRQuery()
  * 
@@ -687,83 +673,37 @@
 ssize_t
 rfc1035BuildPTRQuery(const struct IN_ADDR addr, char *buf, size_t sz, unsigned short qid, rfc1035_query * query)
 {
-    /* I know, Magic numbers are yuck. The compiler complains if they aren't there. */
-    /* actual fixed (max) length of rev is 74 including nul terminator. */
-
-    static char rev[75];
-    unsigned int i = 0;
-
-#if INET6
-    char *junk = NULL;
-    const u_char* r = (const u_char*)&addr;
-    char* p = rev;
-
-    if(qid == RFC1035_TYPE_AAAA)
-    {
-        /* RFC1886 says: */
-        /*     4321:0:1:2:3:4:567:89ab */
-        /*     must be sent */
-        /*     b.a.9.8.7.6.5.0.4.0.0.0.3.0.0.0.2.0.0.0.1.0.0.0.0.0.0.0.1.2.3.4.ip6.int. */
-        /* RFC3152 says: */
-        /*     ip6.int is now deprecated TLD, use ip6.arpa instead. */
-
-        /* work from the raw addr field. anything else may have representation changes. */
-        /* The sin6_port and sin6_addr members shall be in network byte order. */
-        /* Compile Err: 'Too many arguments for format. */
-        for(i = 15; i >= 0; i--, p+=4)
-        {
-            snprintf(p, 4, "%x.%x.", ((r[i]>>4)&0xf), (r[i])&0xf);
-        }
-        snprintf(p,10,"ip6.arpa.");
-
-        /* TODO:
-         *     Should also attempt to do the A6 query at some point.
-         *     VERY non-trivial though. And not widely used yet.
-         *     if someone wants it they can ask.
-         */
-    }
-    else if (qid == RFC1035_TYPE_A)
-    {
-/* Compile Err: with in6_addr need to check full str "\x0\x0\x0\x0\xff\xff" */
-// what works for ipv6??        junk = inet6_ntop(addr);
-        junk = inet_ntop(addr);
-	if(strncmp("::ffff:",junk, 6) == 0)
-        {
-            /* Under IPv6 the 29-32 Bytes of in6_addr are network-byte-order IPv4 Addr. */
-            i = (unsigned int) ntohl( 28+r );
-
-#else /* ! INET6 */
-            i = (unsigned int) ntohl(addr.s_addr);
-
-#endif /* INET6 */
-            snprintf(rev, 32, "%u.%u.%u.%u.in-addr.arpa.",
-                i & 255,
-                (i >> 8) & 255,
-                (i >> 16) & 255,
-                (i >> 24) & 255);
-#if INET6
-        }
-        else
-        {
-            /* FIXME debug output. Query Died. */
-            /* "WARNING: IP Address Type of 'A' Does not match Data Content of %s.\n",junk */
-        }
-    }
-    else /* Unknown Input Record Type */
-    {
-        /* FIXME debug output. Query Died. */
-        /* "WARNING: Dropped PTR Query for unknown RR Type.\n" */
+    static rfc1035_message h;
+    size_t offset = 0;
+    static char rev[32];
+    unsigned int i;
+    memset(&h, '\0', sizeof(h));
+    i = (unsigned int) ntohl(addr.s_addr);
+    snprintf(rev, 32, "%u.%u.%u.%u.in-addr.arpa.",
+	i & 255,
+	(i >> 8) & 255,
+	(i >> 16) & 255,
+	(i >> 24) & 255);
+    h.id = qid;
+    h.qr = 0;
+    h.rd = 1;
+    h.opcode = 0;		/* QUERY */
+    h.qdcount = (unsigned int) 1;
+    offset += rfc1035HeaderPack(buf + offset, sz - offset, &h);
+    offset += rfc1035QuestionPack(buf + offset,
+	sz - offset,
+	rev,
+	RFC1035_TYPE_PTR,
+	RFC1035_CLASS_IN);
+    if (query) {
+	query->qtype = RFC1035_TYPE_PTR;
+	query->qclass = RFC1035_CLASS_IN;
+	xstrncpy(query->name, rev, sizeof(query->name));
     }
-
-#endif /* INET6 */
-
-
-    return rfc1035BuildHostQuery(rev, buf, sz, qid, query, RFC1035_TYPE_PTR, RFC1035_CLASS_IN);
+    assert(offset <= sz);
+    return offset;
 }
 
-
-
-
 /*
  * We're going to retry a former query, but we
  * just need a new ID for it.  Lucky for us ID
@@ -810,14 +750,10 @@
 	strtok(input, "\r\n");
 	memset(buf, '\0', 512);
 	sz = 512;
-	if (inet_aton(input, &junk)) {  
+	if (inet_aton(input, &junk)) {
 	    sid = rfc1035BuildPTRQuery(junk, buf, &sz);
 	} else {
-#ifdef INET6
-	    sid = rfc1035BuildAAAAQuery(input, buf, &sz);
-#else
 	    sid = rfc1035BuildAQuery(input, buf, &sz);
-#endif
 	}
 	sendto(s, buf, sz, 0, (struct sockaddr *) &S, sizeof(S));
 	do {
