abh / geodns

DNS server with per-client targeted responses
Apache License 2.0
1.37k stars 191 forks source link

use a separate nameserver for subdomain #109

Open nclr opened 6 years ago

nclr commented 6 years ago

This is probably obvious but I have trouble in setting a nameserver for subdomain (geo.< mydomain >.com). My setup is this:

filename: < mydomain >.com

{
    "serial": 1,
    "ttl": 30,
    "max_hosts": 10,
    "data": {
        "": {
            "ns": {
                "ns1.<mydomain>.": "<ip>",
                "ns2.<mydomain>": "<ip>"
            }
        },
        "geo": {
            "ns": [ "ns-876.awsdns-45.net", "ns-1767.awsdns-29.co.uk" ]
        }
    }
}
abh commented 6 years ago

Yeah, that’s totally broken / not implemented! Thank you for noticing and reporting this.

It works if you do a NS lookup (explicitly) on “geo.com” (right?), but the code is completely missing the bits that recognizes the delegation.

Some notes, mostly from memory:

In zones/reader.go the code needs to notice the delegation (search for dns.TypeNS). Given an NS record on “sub” then when looking up “something.foo.sub” it has to figure out that “sub” is a delegation and serve the NS records.

The obviously place to do this would be in server/serve.go somewhere just before we give up and serve NXDOMAIN, but that doesn’t catch lookups (other than NS) on “sub” itself. There’s a check for len(m.Answer) == 0 where this would go, but obviously duplicating this is a sign the code isn’t structured right for putting this in.

I wanted to take out the _country and _status special cases. Taking them out might make the solution more obvious (basically have “no labelMatches” and “we ended up with no answers” branch into “is this a delegation?” before figuring out if it’s an NXDOMAIN or just a NOERROR with a SOA record).

If you work on it, the ‘dev’ branch is much ahead of master at the moment (and will soon get merged in as version 3.0).