diff options
| author | Bob Halley <halley@nominum.com> | 2012-04-08 12:10:44 +0100 |
|---|---|---|
| committer | Bob Halley <halley@nominum.com> | 2012-04-08 12:10:44 +0100 |
| commit | cc59c1ed92027ba82e6807e01f28b9b8cb8a120f (patch) | |
| tree | cc46251229dc7a5c151997f652d526843d39cb1e | |
| parent | ee78c1c86171cad49dd3962d39e74f19c9b8ea20 (diff) | |
| download | dnspython-cc59c1ed92027ba82e6807e01f28b9b8cb8a120f.tar.gz | |
try TCP if UDP response is truncated
| -rw-r--r-- | ChangeLog | 6 | ||||
| -rw-r--r-- | dns/resolver.py | 18 |
2 files changed, 24 insertions, 0 deletions
@@ -1,3 +1,9 @@ +2012-04-08 Bob Halley <halley@dnspython.org> + + * dns/resolver.py (Resolver.query): Switch to TCP when a UDP + response is truncated. Handle nameservers that serve on UDP + but not TCP. + 2012-04-07 Bob Halley <halley@dnspython.org> * dns/zone.py (from_xfr): dns.zone.from_xfr() now takes a diff --git a/dns/resolver.py b/dns/resolver.py index c6214ca..9f9b438 100644 --- a/dns/resolver.py +++ b/dns/resolver.py @@ -23,6 +23,7 @@ import sys import time import dns.exception +import dns.flags import dns.ipv4 import dns.ipv6 import dns.message @@ -772,6 +773,13 @@ class Resolver(object): response = dns.query.udp(request, nameserver, timeout, self.port, source=source) + if response.flags & dns.flags.TC: + # Response truncated; retry with TCP. + timeout = self._compute_timeout(start) + response = dns.query.tcp(request, nameserver, + timeout, self.port, + source=source) + except (socket.error, dns.exception.Timeout): # # Communication failure or timeout. Go to the @@ -794,6 +802,16 @@ class Resolver(object): nameservers.remove(nameserver) response = None continue + except EOFError: + # + # We're using TCP and they hung up on us. + # Probably they don't support TCP (though + # they're supposed to!). Take it out of the + # mix and continue. + # + nameservers.remove(nameserver) + response = None + continue rcode = response.rcode() if rcode == dns.rcode.NOERROR or \ rcode == dns.rcode.NXDOMAIN: |
