nmcontrol icon indicating copy to clipboard operation
nmcontrol copied to clipboard

Can't recursively resolve nameservers

Open haasn opened this issue 11 years ago • 5 comments

If I have a nameserver entry like {"ns": "ns.example.bit"} then nmcontrol doesn't try to resolve this .bit address internally, it just fails.

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

haasn avatar Apr 18 '14 07:04 haasn

Top level domain lookups work, e.g.:

brian@aquitard:~$ nslookup -debug flightless.bit. localhost 
Server:         localhost
Address:        127.0.0.1#53

------------
    QUESTIONS:
        flightless.bit, type = A, class = IN
    ANSWERS:
    ->  flightless.bit
        internet address = 59.167.180.195
        ttl = 300
    AUTHORITY RECORDS:
    ADDITIONAL RECORDS:
------------
Name:   flightless.bit
Address: 59.167.180.195

but subdomain lookups don't work:

brian@aquitard:~$ nslookup -debug flightless.bit. localhost 
Server:         localhost
Address:        127.0.0.1#53

------------
    QUESTIONS:
        flightless.bit, type = A, class = IN
    ANSWERS:
    ->  flightless.bit
        internet address = 59.167.180.195
        ttl = 300
    AUTHORITY RECORDS:
    ADDITIONAL RECORDS:
------------
Name:   flightless.bit
Address: 59.167.180.195

The debug output generated by the first, working, query (flightless.bit):

Lookup: {'query': '', 'domain': 'flightless.bit', 'src_addr': ('127.0.0.1', 46293), 'qtype': 1, 'qclass': 1}
Resolving : flightless.bit getIp4
BackendDataNamecoin: ['name_show', 'd/flightless']
Processing import for {u'ns': [u'featherby.microcomaustralia.com.au']}
Possible domains : [[]]
Fetching ip for flightless.bit in sub-domain []
* result:  {"ip": ["ns"]}
Resolving : flightless.bit getNS
BackendDataNamecoin: ['name_show', 'd/flightless']
Processing import for {u'ns': [u'featherby.microcomaustralia.com.au']}
Possible domains : [[]]
Fetching ns for flightless.bit in sub-domain []
* result:  {"ns": ["featherby.microcomaustralia.com.au"]}
Resolving : flightless.bit getTranslate
BackendDataNamecoin: ['name_show', 'd/flightless']
Processing import for {u'ns': [u'featherby.microcomaustralia.com.au']}
Possible domains : [[]]
Fetching translate for flightless.bit in sub-domain []
* result:  {}
Fetching IP Address for:  flightless.bit with NS Server: featherby.microcomaustralia.com.au
* result:  [{'name': 'flightless.bit', 'data': '59.167.180.195', 'typename': 'A', 'classstr': 'IN', 'ttl': 86400, 'type': 1, 'class': 1, 'rdlength': 4}]

The domain lookup by the second (failing) query (www.flightless.bit):

Lookup: {'query': '', 'domain': 'www.flightless.bit', 'src_addr': ('127.0.0.1', 37162), 'qtype': 1, 'qclass': 1}
Resolving : www.flightless.bit getIp4
BackendDataNamecoin: ['name_show', 'd/flightless']
Processing import for {u'ns': [u'featherby.microcomaustralia.com.au']}
Possible domains : [['www'], ['*']]
* result:  {}
Lookup: {'query': '', 'domain': 'www.flightless.bit', 'src_addr': ('127.0.0.1', 54900), 'qtype': 1, 'qclass': 1}
Resolving : www.flightless.bit getIp4
BackendDataNamecoin: ['name_show', 'd/flightless']
Processing import for {u'ns': [u'featherby.microcomaustralia.com.au']}
Possible domains : [['www'], ['*']]
* result:  {}

Proof the nameserver has both these records:

brian@aquitard:~$ nslookup -debug flightless.bit. featherby.microcomaustralia.com.au
Server:         featherby.microcomaustralia.com.au
Address:        59.167.180.197#53

------------
    QUESTIONS:
        flightless.bit, type = A, class = IN
    ANSWERS:
    ->  flightless.bit
        internet address = 59.167.180.195
        ttl = 86400
    AUTHORITY RECORDS:
    ->  flightless.bit
        nameserver = featherby.microcomaustralia.com.au.
        ttl = 86400
    ADDITIONAL RECORDS:
    ->  featherby.microcomaustralia.com.au
        internet address = 59.167.180.197
        ttl = 86400
    ->  featherby.microcomaustralia.com.au
        has AAAA address 2001:44b8:4112:8a04::5
        ttl = 86400
------------
Name:   flightless.bit
Address: 59.167.180.195

brian@aquitard:~$ nslookup -debug www.flightless.bit. featherby.microcomaustralia.com.au
Server:         featherby.microcomaustralia.com.au
Address:        59.167.180.197#53

------------
    QUESTIONS:
        www.flightless.bit, type = A, class = IN
    ANSWERS:
    ->  www.flightless.bit
        internet address = 59.167.180.195
        ttl = 86400
    AUTHORITY RECORDS:
    ->  flightless.bit
        nameserver = featherby.microcomaustralia.com.au.
        ttl = 86400
    ADDITIONAL RECORDS:
    ->  featherby.microcomaustralia.com.au
        internet address = 59.167.180.197
        ttl = 86400
    ->  featherby.microcomaustralia.com.au
        has AAAA address 2001:44b8:4112:8a04::5
        ttl = 86400
------------
Name:   www.flightless.bit
Address: 59.167.180.195

brianmay avatar Jun 26 '14 23:06 brianmay

To get this to work with NMControl "as currently written" (as opposed to what may or may not be decided in #28), what is absolute minimum required. Would the following work?

{"ns": "ns.example.bit", 'map': "ns"}

or:

{"ns": "ns.example.bit", 'map': { '*': "ns" }

or do I need to repeat the ns server again?

{"ns": "ns.example.bit", 'map': { "*": { "ns": "ns.example.bit" }

Will this work with 4th level domains?

brianmay avatar Jun 27 '14 04:06 brianmay

I expect that you would need to repeat the ns server as in your last example. If I were writing the spec, I would make that syntax (with the asterisk) work for 4th/5th/etc. level domains as well. I'm not 100% certain whether NMControl in its current state does so. (If you try it, please let us know whether it works.) In the event that it doesn't do so (which may or may not be the case), I think any changes to that behavior would have to wait until we decide what to do about #28 , but you could possibly work around it in the meantime by nesting more "map" and "ns" fields until you have the desired number of levels.

Hope this helps.

JeremyRand avatar Jun 27 '14 05:06 JeremyRand

3rd level now working. 4th level lookup generates an exception. No time to look into this now though:

Fetching IP Address for:  meow.www.flightless.bit with NS Server: featherby.microcomaustralia.com.au
* result:  []
Traceback (most recent call last):
  File "/home/brian/tree/bitcoin/nmcontrol/lib/dnsServer/__init__.py", line 94, in serve
    rcode, an_resource_records = source_instance.get_response(query, ".".join(question), qtype, qclass, src_addr)
  File "/home/brian/tree/bitcoin/nmcontrol/lib/dnsServer/namecoindns.py", line 99, in get_response
    answers = app['services']['dns'].lookup({"query":query, "domain":domain, "qtype":qtype, "qclass":qclass, "src_addr":src_addr})
  File "/home/brian/tree/bitcoin/nmcontrol/service/serviceDNS.py", line 39, in lookup
    return app['plugins']['domain'].lookup(qdict)
  File "/home/brian/tree/bitcoin/nmcontrol/plugin/pluginNamespaceDomain.py", line 182, in lookup
    return self._bitLookup(qdict)
  File "/home/brian/tree/bitcoin/nmcontrol/plugin/pluginNamespaceDomain.py", line 209, in _bitLookup
    answers = app['plugins']['dns'].getIp4(qdict["domain"])
  File "/home/brian/tree/bitcoin/nmcontrol/plugin/pluginDns.py", line 97, in getIp4
    result = '["'+self._getIPv4FromNS(domain)+'"]'
  File "/home/brian/tree/bitcoin/nmcontrol/plugin/pluginDns.py", line 180, in _getIPv4FromNS
    return app['services']['dns']._lookup(domain, 1 , server)[0]['data']
IndexError: list index out of range

It seems like it might be working, however, the DNS server doesn't have this name, and probably returned an error, which is causing a confusing exception from nmcontrol.

brianmay avatar Jun 27 '14 06:06 brianmay

Thanks for checking. I haven't done anything myself with the DNS server querying code in NMControl, but I'll see whether I'm able to make that error less confusing. I might not be able to work on that one for a while though.

JeremyRand avatar Jun 27 '14 07:06 JeremyRand