Message EDNS Options

EDNS allows for larger messages and also provides an extension mechanism for the protocol. EDNS options are typed data, and are treated much like Rdata. For example, if dnsython encouters the EDNS ECS option code when parsing a DNS wire format message, it will create a dns.edns.ECSOption object to represent it.

dns.edns.NSID = <OptionType.NSID: 3>

An enumeration.

dns.edns.DAU = <OptionType.DAU: 5>

An enumeration.

dns.edns.DHU = <OptionType.DHU: 6>

An enumeration.

dns.edns.N3U = <OptionType.N3U: 7>

An enumeration.

dns.edns.ECS = <OptionType.ECS: 8>

An enumeration.

dns.edns.EXPIRE = <OptionType.EXPIRE: 9>

An enumeration.

dns.edns.COOKIE = <OptionType.COOKIE: 10>

An enumeration.

dns.edns.KEEPALIVE = <OptionType.KEEPALIVE: 11>

An enumeration.

dns.edns.PADDING = <OptionType.PADDING: 12>

An enumeration.

dns.edns.CHAIN = <OptionType.CHAIN: 13>

An enumeration.

class dns.edns.Option(otype)[source]

Base class for all EDNS option types.

Initialize an option.

otype, an int, is the option type.

classmethod from_wire_parser(otype, parser)[source]

Build an EDNS option object from wire format.

otype, an int, is the option type.

parser, a dns.wire.Parser, the parser, which should be restructed to the option length.

Returns a dns.edns.Option.

to_wire(file=None)[source]

Convert an option to wire format.

Returns a bytes or None.

class dns.edns.GenericOption(otype, data)[source]

Generic Option Class

This class is used for EDNS option types for which we have no better implementation.

classmethod from_wire_parser(otype, parser)[source]

Build an EDNS option object from wire format.

otype, an int, is the option type.

parser, a dns.wire.Parser, the parser, which should be restructed to the option length.

Returns a dns.edns.Option.

to_wire(file=None)[source]

Convert an option to wire format.

Returns a bytes or None.

class dns.edns.ECSOption(address, srclen=None, scopelen=0)[source]

EDNS Client Subnet (ECS, RFC7871)

address, a str, is the client address information.

srclen, an int, the source prefix length, which is the leftmost number of bits of the address to be used for the lookup. The default is 24 for IPv4 and 56 for IPv6.

scopelen, an int, the scope prefix length. This value must be 0 in queries, and should be set in responses.

static from_text(text)[source]

Convert a string into a dns.edns.ECSOption

text, a str, the text form of the option.

Returns a dns.edns.ECSOption.

Examples:

>>> import dns.edns
>>>
>>> # basic example
>>> dns.edns.ECSOption.from_text('1.2.3.4/24')
>>>
>>> # also understands scope
>>> dns.edns.ECSOption.from_text('1.2.3.4/24/32')
>>>
>>> # IPv6
>>> dns.edns.ECSOption.from_text('2001:4b98::1/64/64')
>>>
>>> # it understands results from `dns.edns.ECSOption.to_text()`
>>> dns.edns.ECSOption.from_text('ECS 1.2.3.4/24/32')
classmethod from_wire_parser(otype, parser)[source]

Build an EDNS option object from wire format.

otype, an int, is the option type.

parser, a dns.wire.Parser, the parser, which should be restructed to the option length.

Returns a dns.edns.Option.

to_wire(file=None)[source]

Convert an option to wire format.

Returns a bytes or None.

dns.edns.get_option_class(otype)[source]

Return the class for the specified option type.

The GenericOption class is used if a more specific class is not known.

dns.edns.option_from_wire_parser(otype, parser)[source]

Build an EDNS option object from wire format.

otype, an int, is the option type.

parser, a dns.wire.Parser, the parser, which should be restricted to the option length.

Returns an instance of a subclass of dns.edns.Option.

dns.edns.option_from_wire(otype, wire, current, olen)[source]

Build an EDNS option object from wire format.

otype, an int, is the option type.

wire, a bytes, is the wire-format message.

current, an int, is the offset in wire of the beginning of the rdata.

olen, an int, is the length of the wire-format option data

Returns an instance of a subclass of dns.edns.Option.

dns.edns.register_type(implementation, otype)[source]

Register the implementation of an option type.

implementation, a class, is a subclass of dns.edns.Option.

otype, an int, is the option type.