Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Requesting A and AAAA records in single DNS query

I'm working on a DNS query implementation in C and interested in requesting both A and AAAA (IPv4 and IPv6) records in a single query packet, but I'm not getting any responses from the nameserver when I put the two queries together in one packet like this. I've tried sending the query to several different nameservers (both local and 8.8.8.8) with no luck. Is this something that does not work, or is it likely that my query packet is malformed?

My basic algorithm for appending the AAAA query (to an existing A request packet) is to increase the QDCOUNT field in the packet header, then append an RR query with TYPE set to AAAA and NAME as a pointer to the hostname in the existing A query (bytes 0xC0 0x0C for an offset of 12 bytes from the beginning of the packet). Does this sound correct?

FYI, everything works fine with just the A query in the packet.

Edit: Apparently my queries were all slightly malformed (I was not aware that queries unlike answers do not have TTL and RDLENGTH/RDATA fields). Upon fixing this, I'm getting back RCODE=1 format error replies which acknowledge the presence of the 2 queries. Does this mean multiple queries per packet are just not supported?

Edit 2: Here's a hexdump of a lookup for www.google.com:

d8 32 01 00 00 02 00 00 00 00 00 00 03 77 77 77 06 67 6f 6f 67 6c 65 03 63 6f 6d 00 00 01 00 01 c0 0c 00 1c 00 01

I don't see anything wrong with it.

like image 773
R.. GitHub STOP HELPING ICE Avatar asked Nov 02 '10 21:11

R.. GitHub STOP HELPING ICE


People also ask

What is A and AAAA in DNS?

A and AAAA records are equally important when it comes to resolving DNS. The difference lies in that A records is used to resolve a hostname which corresponds to an IPv4 address, while AAAA records are used to resolve a domain name which corresponds to an IPv6 address.

What information is sent through A and AAAA DNS records?

An AAAA record is used to find the IP address of a computer connected to the internet from a name. The AAAA record is conceptually similar to the A record, but it allows you to specify the IPv6 address of the server, rather than the IPv4.

What is DNS query type AAAA?

What is a DNS AAAA record? DNS AAAA records match a domain name to an IPv6 address. DNS AAAA records are exactly like DNS A records, except that they store a domain's IPv6 address instead of its IPv4 address. IPv6 is the latest version of the Internet Protocol (IP).


1 Answers

I'm not aware of any nameservers that support multiple questions in a single query.

There's potential for ambiguity in such a query, since there are per-packet flags (such as AA) which could apply to only one of the questions. If you ask two questions and the server is authoritative for only one of the domains, should the server set the flag or not? I suspect issues such as these have deterred implementors.

There have been a number of proposals to solve the problem you're talking about (such as this proposal to introduce a QTYPE that combines A and AAAA, and Paul Vixie's repeated attempts to introduce an EDNS form of multiple questions), but at present programs supporting both IPv4 and 6 tend to perform two separate queries, either AAAA followed (after a timeout) by A, or both simultaneously.

I suppose there's also the "all" QTYPE, but it can return a lot more data than you need.

Edit: from query.c in the BIND source:

   dns_message_currentname(message, DNS_SECTION_QUESTION,          &client->query.qname);    client->query.origqname = client->query.qname;    result = dns_message_nextname(message, DNS_SECTION_QUESTION);    if (result != ISC_R_NOMORE) {      if (result == ISC_R_SUCCESS) {        /*         * There's more than one QNAME in the question         * section.         */        query_error(client, DNS_R_FORMERR, __LINE__);      } else        query_error(client, result, __LINE__);      return;    } 

Edit: also, from resolver.c in the BIND source:

    /*      * XXXRTH  Currently we support only one question.      */     if (message->counts[DNS_SECTION_QUESTION] != 1) {             log_formerr(fctx, "too many questions");             return (DNS_R_FORMERR);     } 
like image 134
SimonJ Avatar answered Sep 27 '22 20:09

SimonJ