[Twisted-Python] DNSServerBoss.getAnswers with non-authoritative requests

Neil Blakey-Milner nbm at mithrandr.moria.org
Fri Oct 25 03:04:13 MDT 2002


Hi,

Since I've just guessed how the DNS Server stuff works in twisted, I may
be doing something stupid.

Example program:

from twisted.protocols import dns
from twisted.names.dns import DNSServerBoss, DNSServerFactory, SimpleDomain
from twisted.internet import reactor

a = DNSServerFactory()
s = SimpleDomain("example.net", "192.168.8.26")
a.boss.addDomain("example.net", s)
a.boss.createBothFactories()
a.boss.startListeningBoth(53)
reactor.run()


This works great for example.net:

(nbm at pike) /home/nbm> host example.net 127.0.0.1
Using domain server 127.0.0.1:
example.net has address 192.168.8.26
example.net mail is handled (pri=5) by example.net

This works non-great for other domains - it just sits there, slowly
timing out for each query made (due to 'search' or 'domain' in
resolv.conf).

Traceback makes it obvious where the problem is:

  File "/usr/local/lib/python2.2/site-packages/twisted/names/dns.py",
line 370, in getAnswers
    name = string.split(name, '.', 1)[1]
exceptions.IndexError: list index out of range

Ok, that's easy, and that's the first patch
(twisted.names.dns.py-noerror.patch).

Once applied, it still doesn't quite work:

(nbm at pike) /home/nbm> host example.org 127.0.0.1
Using domain server 127.0.0.1:
There is an entry for this host, but it doesn't have a Mail Exchanger record.

Second patch (no idea if this is what DNS is supposed to do) makes that
more like I expect it to return:

(nbm at pike) /home/nbm> host example.org 127.0.0.1
Using domain server 127.0.0.1:
Host not found.

I'll probably look into what is the correct response, but not soon.  I'm
not sure how the multiple-queries bit factors into it either.

Neil
-- 
Neil Blakey-Milner
nbm at mithrandr.moria.org
-------------- next part --------------
Index: dns.py
===================================================================
RCS file: /cvs/Twisted/twisted/names/dns.py,v
retrieving revision 1.37
diff -u -r1.37 dns.py
--- dns.py	2 Oct 2002 05:55:19 -0000	1.37
+++ dns.py	25 Oct 2002 08:43:15 -0000
@@ -367,7 +367,10 @@
                 continue # internet
             name = query.name.name
             while name and not self.domains.has_key(name):
-                name = string.split(name, '.', 1)[1]
+                try:
+                    name = string.split(name, '.', 1)[1]
+                except IndexError:
+                    name = None
             if not name:
                 continue
             self.domains[name].getAnswers(message, query.name.name, query.type)
-------------- next part --------------
Index: dns.py
===================================================================
RCS file: /cvs/Twisted/twisted/names/dns.py,v
retrieving revision 1.37
diff -u -r1.37 dns.py
--- dns.py	2 Oct 2002 05:55:19 -0000	1.37
+++ dns.py	25 Oct 2002 08:47:01 -0000
@@ -367,8 +367,12 @@
                 continue # internet
             name = query.name.name
             while name and not self.domains.has_key(name):
-                name = string.split(name, '.', 1)[1]
+                try:
+                    name = string.split(name, '.', 1)[1]
+                except IndexError:
+                    name = None
             if not name:
+                message.rCode = dns.ENAME
                 continue
             self.domains[name].getAnswers(message, query.name.name, query.type)
         protocol.writeMessage(message)


More information about the Twisted-Python mailing list