From: Bob Halley Date: Fri, 22 Sep 2006 21:35:45 +0000 (+0000) Subject: add reasonable defaults for Message.use_edns(); add Message.want_dnssec() X-Git-Tag: v1.5.0~21 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=062ed651c85edbfe5db8c7c63738f634324e8ef3;p=thirdparty%2Fdnspython.git add reasonable defaults for Message.use_edns(); add Message.want_dnssec() --- diff --git a/ChangeLog b/ChangeLog index 25512f64..a16ad69c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2006-09-22 Bob Halley + + * dns/message.py (Message.use_edns): add reasonable defaults for + the ednsflags, payload, and request_payload parameters. + + * dns/message.py (Message.want_dnssec): add convenience method for + enabling/disabling the "DNSSEC desired" flag in requests. + 2006-08-17 Bob Halley * dns/resolver.py (Resolver.read_resolv_conf): If /etc/resolv.conf diff --git a/dns/message.py b/dns/message.py index 0995299c..32c5454e 100644 --- a/dns/message.py +++ b/dns/message.py @@ -449,25 +449,48 @@ class Message(object): self.tsig_error = tsig_error self.other_data = other_data - def use_edns(self, edns, ednsflags, payload, request_payload=0): + def use_edns(self, edns=0, ednsflags=0, payload=1280, request_payload=None): """Configure EDNS behavior. - @param edns: The EDNS level to use. Specifying None or -1 means - 'do not use EDNS'. + @param edns: The EDNS level to use. Specifying None or a -1 means + 'do not use EDNS', and in this case the other parameters are ignored. @type edns: int or None @param ednsflags: EDNS flag values. @type ednsflags: int @param payload: The EDNS sender's payload field, which is the maximum size of UDP datagram the sender can handle. @type payload: int + @param request_payload: The EDNS payload size to use when sending + this message. If not specified, defaults to the value of payload. + @type request_payload: int or None @see: RFC 2671 """ if edns is None: edns = -1 + if request_payload is None: + request_payload = payload + if edns < 0: + ednsflags = 0 + payload = 0 + request_payload = 0 self.edns = edns self.ednsflags = ednsflags self.payload = payload self.request_payload = request_payload + def want_dnssec(self, wanted=True): + """Enable or disable DNSSEC in requests. + @param wanted: Is DNSSEC desired? If True, EDNS is enabled if + required, and then the DO bit is set. If False, the DO bit is + cleared if EDNS is enabled. + @type wanted: bool + """ + if wanted: + if self.edns < 0: + self.use_edns() + self.ednsflags |= dns.flags.DO + elif self.edns >= 0: + self.ednsflags &= ~dns.flags.DO + def rcode(self): """Return the rcode. @rtype: int