openresty / lua-resty-dns

DNS resolver for the nginx lua module
324 stars 107 forks source link

how does the r:query parameter option:qtype? #43

Closed zhangcunli closed 5 years ago

zhangcunli commented 5 years ago
local answers, err = r:query(hostname, {qtype = r.TYPE_A})
Why the answer.type still have cname_type?
zhangcunli commented 5 years ago

@agentzh

agentzh commented 5 years ago

@zhangcunli I don't quite understand your issue. The whole library has no such thing as "cname_type":

agentzh@glass ~/git/lua-resty-dns 1 (master)$ grep cname_type -r .
agentzh@glass ~/git/lua-resty-dns 1 (master)$
Tieske commented 5 years ago

@zhangcunli when you request an A record from the DNS server, but it doesn't have an A record, it might still reply with a CNAME record if that is available, usually in the additional section you'll find the records that the CNAME points to again.

This is pretty standard DNS behaviour.

Here's a typical example (redacted):

thijs$ dig thuis.tieske.nl

; <<>> DiG 9.10.6 <<>> thuis.tieske.nl
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 10909
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;thuis.tieske.nl.   IN  A

;; ANSWER SECTION:
thuis.tieske.nl. 616    IN  CNAME   tieske.duckdns.org.
tieske.duckdns.org. 59  IN  A   192.168.0.0

;; Query time: 179 msec
;; SERVER: 192.168.50.1#53(192.168.50.1)
;; WHEN: Thu May 16 17:11:39 CEST 2019
;; MSG SIZE  rcvd: 101

thijs$
Tieske commented 5 years ago

@zhangcunli please close if answered