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 dnspython encounters 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
- dns.edns.DAU = OptionType.DAU
- dns.edns.DHU = OptionType.DHU
- dns.edns.N3U = OptionType.N3U
- dns.edns.ECS = OptionType.ECS
- dns.edns.EXPIRE = OptionType.EXPIRE
- dns.edns.COOKIE = OptionType.COOKIE
- dns.edns.KEEPALIVE = OptionType.KEEPALIVE
- dns.edns.PADDING = OptionType.PADDING
- dns.edns.CHAIN = OptionType.CHAIN
- class dns.edns.Option(otype: OptionType | str)[source]
Base class for all EDNS option types.
Initialize an option.
otype, a
dns.edns.OptionType
, is the option type.- classmethod from_wire_parser(otype: OptionType, parser: Parser) Option [source]
Build an EDNS option object from wire format.
otype, a
dns.edns.OptionType
, 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_generic() GenericOption [source]
Creates a dns.edns.GenericOption equivalent of this rdata.
Returns a
dns.edns.GenericOption
.
- class dns.edns.GenericOption(otype: OptionType | str, data: bytes | str)[source]
Generic Option Class
This class is used for EDNS option types for which we have no better implementation.
Initialize an option.
otype, a
dns.edns.OptionType
, is the option type.- classmethod from_wire_parser(otype: OptionType | str, parser: Parser) Option [source]
Build an EDNS option object from wire format.
otype, a
dns.edns.OptionType
, 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_generic() GenericOption [source]
Creates a dns.edns.GenericOption equivalent of this rdata.
Returns a
dns.edns.GenericOption
.
- class dns.edns.ECSOption(address: str, srclen: int | None = None, scopelen: int = 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: str) Option [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')
- class dns.edns.EDEOption(code: EDECode | str, text: str | None = None)[source]
Extended DNS Error (EDE, RFC8914)
code, a
dns.edns.EDECode
orstr
, the info code of the extended error.text, a
str
orNone
, specifying additional information about the error.
- class dns.edns.NSIDOption(nsid: bytes)[source]
Initialize an option.
otype, a
dns.edns.OptionType
, is the option type.
- class dns.edns.CookieOption(client: bytes, server: bytes)[source]
Initialize an option.
otype, a
dns.edns.OptionType
, is the option type.
- class dns.edns.ReportChannelOption(agent_domain: Name)[source]
Initialize an option.
otype, a
dns.edns.OptionType
, is the option type.
- dns.edns.get_option_class(otype: OptionType) Any [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: OptionType | str, parser: Parser) Option [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: OptionType | str, wire: bytes, current: int, olen: int) Option [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 dataReturns an instance of a subclass of
dns.edns.Option
.