So I'm writing a custom DNS resolution implementation for an internet research tool, and I need to know the specifics of DNS caching while doing an iterative lookup.
For example, let's take a hypothetical DNS resolution of www.example.org with a CNAME alias dyna.examples.org:
Query a root server for www.example.org
Get the IP address of the .org TLD nameserver, with a TTL of 48 hours
Query the .org nameserver
Get the IP address of example.org authoritative nameserver, with a TTL of 1 hour
Query the example.org nameserver
Get the CNAME alias for www.example.org, which is dyna.examples.org, with a TTL of 24 hours
Requery root server for dyna.examples.org
Get the IP address of the .org TLD nameserver, with a TTL for 48 hours
Query the .org nameserver
Get the IP address of examples.org authoritative nameserver, with a TTL of 1 hour
Query the examples.org nameserver
Get the final IP address for the DNS lookup, with a TTL of 3 minutes.
So there's the obvious redundant requery of the root server, when we should clearly just query the .org TLD nameserver, but that's all within a single lookup so that's obvious enough. My question is if a user is trying to access www.example.org either >3 minutes, then >1 hour, then >24 hours later, and so on, which parts of our query do we reuse?
My guess would be that when a user tries to access www.example.org:
after 3 minutes: repeat step 11
after 1 hour: repeat step 9. We don't repeat step 3 because our CNAME alias answer is still valid.
after 24 hours: repeat step 3, as step 6 and step 4 have expired.
after 48 hours: repeat step 1
Are there any cases during DNS resolution that I would want to discard a resource record even if its TTL has not yet expired?