trust_dns_proto::op::message

Struct Message

Source
pub struct Message { /* private fields */ }
Expand description

The basic request and response datastructure, used for all DNS protocols.

RFC 1035, DOMAIN NAMES - IMPLEMENTATION AND SPECIFICATION, November 1987

4.1. Format

All communications inside of the domain protocol are carried in a single
format called a message.  The top level format of message is divided
into 5 sections (some of which are empty in certain cases) shown below:

    +--------------------------+
    |        Header            |
    +--------------------------+
    |  Question / Zone         | the question for the name server
    +--------------------------+
    |   Answer  / Prerequisite | RRs answering the question
    +--------------------------+
    | Authority / Update       | RRs pointing toward an authority
    +--------------------------+
    |      Additional          | RRs holding additional information
    +--------------------------+

The header section is always present.  The header includes fields that
specify which of the remaining sections are present, and also specify
whether the message is a query or a response, a standard query or some
other opcode, etc.

The names of the sections after the header are derived from their use in
standard queries.  The question section contains fields that describe a
question to a name server.  These fields are a query type (QTYPE), a
query class (QCLASS), and a query domain name (QNAME).  The last three
sections have the same format: a possibly empty list of concatenated
resource records (RRs).  The answer section contains RRs that answer the
question; the authority section contains RRs that point toward an
authoritative name server; the additional records section contains RRs
which relate to the query, but are not strictly answers for the
question.

By default Message is a Query. Use the Message::as_update() to create and update, or Message::new_update()

Implementations§

Source§

impl Message

Source

pub fn new() -> Self

Returns a new “empty” Message

Source

pub fn error_msg(id: u16, op_code: OpCode, response_code: ResponseCode) -> Self

Returns a Message constructed with error details to return to a client

§Arguments
  • id - message id should match the request message id
  • op_code - operation of the request
  • response_code - the error code for the response
Source

pub fn truncate(&self) -> Self

Truncates a Message, this blindly removes all response fields and sets truncated to true

Source

pub fn set_header(&mut self, header: Header) -> &mut Self

Sets the Header with provided

Source

pub fn set_id(&mut self, id: u16) -> &mut Self

see Header::set_id

Source

pub fn set_message_type(&mut self, message_type: MessageType) -> &mut Self

see Header::set_message_type

Source

pub fn set_op_code(&mut self, op_code: OpCode) -> &mut Self

see Header::set_op_code

Source

pub fn set_authoritative(&mut self, authoritative: bool) -> &mut Self

see Header::set_authoritative

Source

pub fn set_truncated(&mut self, truncated: bool) -> &mut Self

see Header::set_truncated

Source

pub fn set_recursion_desired(&mut self, recursion_desired: bool) -> &mut Self

see Header::set_recursion_desired

Source

pub fn set_recursion_available( &mut self, recursion_available: bool, ) -> &mut Self

see Header::set_recursion_available

Source

pub fn set_authentic_data(&mut self, authentic_data: bool) -> &mut Self

see Header::set_authentic_data

Source

pub fn set_checking_disabled(&mut self, checking_disabled: bool) -> &mut Self

see Header::set_checking_disabled

Source

pub fn set_response_code(&mut self, response_code: ResponseCode) -> &mut Self

see Header::set_response_code

Source

pub fn add_query(&mut self, query: Query) -> &mut Self

Add a query to the Message, either the query response from the server, or the request Query.

Source

pub fn add_queries<Q, I>(&mut self, queries: Q) -> &mut Self
where Q: IntoIterator<Item = Query, IntoIter = I>, I: Iterator<Item = Query>,

Adds an iterator over a set of Queries to be added to the message

Source

pub fn add_answer(&mut self, record: Record) -> &mut Self

Add an answer to the Message

Source

pub fn add_answers<R, I>(&mut self, records: R) -> &mut Self
where R: IntoIterator<Item = Record, IntoIter = I>, I: Iterator<Item = Record>,

Add all the records from the iterator to the answers section of the Message

Source

pub fn insert_answers(&mut self, records: Vec<Record>)

Sets the answers to the specified set of Records.

§Panics

Will panic if answer records are already associated to the message.

Source

pub fn add_name_server(&mut self, record: Record) -> &mut Self

Add a name server record to the Message

Source

pub fn add_name_servers<R, I>(&mut self, records: R) -> &mut Self
where R: IntoIterator<Item = Record, IntoIter = I>, I: Iterator<Item = Record>,

Add all the records in the Iterator to the name server section of the message

Source

pub fn insert_name_servers(&mut self, records: Vec<Record>)

Sets the name_servers to the specified set of Records.

§Panics

Will panic if name_servers records are already associated to the message.

Source

pub fn add_additional(&mut self, record: Record) -> &mut Self

Add an additional Record to the message

Source

pub fn add_additionals<R, I>(&mut self, records: R) -> &mut Self
where R: IntoIterator<Item = Record, IntoIter = I>, I: Iterator<Item = Record>,

Add all the records from the iterator to the additionals section of the Message

Source

pub fn insert_additionals(&mut self, records: Vec<Record>)

Sets the additional to the specified set of Records.

§Panics

Will panic if additional records are already associated to the message.

Source

pub fn set_edns(&mut self, edns: Edns) -> &mut Self

Add the EDNS section to the Message

Source

pub fn header(&self) -> &Header

Gets the header of the Message

Source

pub fn id(&self) -> u16

see Header::id()

Source

pub fn message_type(&self) -> MessageType

see Header::message_type()

Source

pub fn op_code(&self) -> OpCode

see Header::op_code()

Source

pub fn authoritative(&self) -> bool

see Header::authoritative()

Source

pub fn truncated(&self) -> bool

see Header::truncated()

Source

pub fn recursion_desired(&self) -> bool

see Header::recursion_desired()

Source

pub fn recursion_available(&self) -> bool

see Header::recursion_available()

Source

pub fn authentic_data(&self) -> bool

see Header::authentic_data()

Source

pub fn checking_disabled(&self) -> bool

see Header::checking_disabled()

Source

pub fn response_code(&self) -> ResponseCode

§Return value

The ResponseCode, if this is an EDNS message then this will join the section from the OPT record to create the EDNS ResponseCode

Source

pub fn query(&self) -> Option<&Query>

Returns the query from this Message.

In almost all cases, a Message will only contain one query. This is a convenience function to get the single query. See the alternative queries* methods for the raw set of queries in the Message

Source

pub fn queries(&self) -> &[Query]

Question        Carries the query name and other query parameters.
Source

pub fn queries_mut(&mut self) -> &mut Vec<Query>

Provides mutable access to queries

Source

pub fn take_queries(&mut self) -> Vec<Query>

Removes all the answers from the Message

Source

pub fn answers(&self) -> &[Record]

Answer          Carries RRs which directly answer the query.
Source

pub fn answers_mut(&mut self) -> &mut Vec<Record>

Provides mutable access to answers

Source

pub fn take_answers(&mut self) -> Vec<Record>

Removes all the answers from the Message

Source

pub fn name_servers(&self) -> &[Record]

Authority       Carries RRs which describe other authoritative servers.
                May optionally carry the SOA RR for the authoritative
                data in the answer section.
Source

pub fn name_servers_mut(&mut self) -> &mut Vec<Record>

Provides mutable access to name_servers

Source

pub fn take_name_servers(&mut self) -> Vec<Record>

Remove the name servers from the Message

Source

pub fn additionals(&self) -> &[Record]

Additional      Carries RRs which may be helpful in using the RRs in the
                other sections.
Source

pub fn additionals_mut(&mut self) -> &mut Vec<Record>

Provides mutable access to additionals

Source

pub fn take_additionals(&mut self) -> Vec<Record>

Remove the additional Records from the Message

Source

pub fn all_sections(&self) -> impl Iterator<Item = &Record>

All sections chained

Source

pub fn edns(&self) -> Option<&Edns>

👎Deprecated: Please use extensions()

RFC 6891, EDNS(0) Extensions, April 2013

6.1.1.  Basic Elements

 An OPT pseudo-RR (sometimes called a meta-RR) MAY be added to the
 additional data section of a request.

 The OPT RR has RR type 41.

 If an OPT record is present in a received request, compliant
 responders MUST include an OPT record in their respective responses.

 An OPT record does not carry any DNS data.  It is used only to
 contain control information pertaining to the question-and-answer
 sequence of a specific transaction.  OPT RRs MUST NOT be cached,
 forwarded, or stored in or loaded from Zone Files.

 The OPT RR MAY be placed anywhere within the additional data section.
 When an OPT RR is included within any DNS message, it MUST be the
 only OPT RR in that message.  If a query message with more than one
 OPT RR is received, a FORMERR (RCODE=1) MUST be returned.  The
 placement flexibility for the OPT RR does not override the need for
 the TSIG or SIG(0) RRs to be the last in the additional section
 whenever they are present.
§Return value

Optionally returns a reference to EDNS section

Source

pub fn edns_mut(&mut self) -> &mut Edns

👎Deprecated: Please use extensions_mut(). You can chain .get_or_insert_with(Edns::new) to recover original behavior of adding Edns if not present

Optionally returns mutable reference to EDNS section

Source

pub fn extensions(&self) -> &Option<Edns>

Returns reference of Edns section

Source

pub fn extensions_mut(&mut self) -> &mut Option<Edns>

Returns mutable reference of Edns section

Source

pub fn max_payload(&self) -> u16

§Return value

the max payload value as it’s defined in the EDNS section.

Source

pub fn version(&self) -> u8

§Return value

the version as defined in the EDNS record

Source

pub fn sig0(&self) -> &[Record]

RFC 2535, Domain Name System Security Extensions, March 1999

A DNS request may be optionally signed by including one or more SIGs
 at the end of the query. Such SIGs are identified by having a "type
 covered" field of zero. They sign the preceding DNS request message
 including DNS header but not including the IP header or any request
 SIGs at the end and before the request RR counts have been adjusted
 for the inclusions of any request SIG(s).
§Return value

The sig0 and tsig, i.e. signed record, for verifying the sending and package integrity

Source

pub fn signature(&self) -> &[Record]

RFC 2535, Domain Name System Security Extensions, March 1999

A DNS request may be optionally signed by including one or more SIGs
 at the end of the query. Such SIGs are identified by having a "type
 covered" field of zero. They sign the preceding DNS request message
 including DNS header but not including the IP header or any request
 SIGs at the end and before the request RR counts have been adjusted
 for the inclusions of any request SIG(s).
§Return value

The sig0 and tsig, i.e. signed record, for verifying the sending and package integrity

Source

pub fn take_signature(&mut self) -> Vec<Record>

Remove signatures from the Message

Source

pub fn read_queries( decoder: &mut BinDecoder<'_>, count: usize, ) -> ProtoResult<Vec<Query>>

Attempts to read the specified number of Querys

Source

pub fn read_records( decoder: &mut BinDecoder<'_>, count: usize, is_additional: bool, ) -> ProtoResult<(Vec<Record>, Option<Edns>, Vec<Record>)>

Attempts to read the specified number of records

§Returns

This returns a tuple of first standard Records, then a possibly associated Edns, and then finally any optionally associated SIG0 and TSIG records.

Source

pub fn from_vec(buffer: &[u8]) -> ProtoResult<Self>

Decodes a message from the buffer.

Source

pub fn to_vec(&self) -> Result<Vec<u8>, ProtoError>

Encodes the Message into a buffer

Source

pub fn finalize<MF: MessageFinalizer>( &mut self, finalizer: &MF, inception_time: u32, ) -> ProtoResult<Option<MessageVerifier>>

Finalize the message prior to sending.

Subsequent to calling this, the Message should not change.

Source

pub fn into_parts(self) -> MessageParts

Consumes Message and returns into components

Methods from Deref<Target = Header>§

Source

pub fn flags(&self) -> Flags

A method to get all header flags (useful for Display purposes)

Source

pub fn id(&self) -> u16

ID              A 16 bit identifier assigned by the program that
                generates any kind of query.  This identifier is copied
                the corresponding reply and can be used by the requester
                to match up replies to outstanding queries.
Source

pub fn message_type(&self) -> MessageType

QR              A one bit field that specifies whether this message is a
                query (0), or a response (1).
Source

pub fn op_code(&self) -> OpCode

OPCODE          A four bit field that specifies kind of query in this
                message.  This value is set by the originator of a query
                and copied into the response.  The values are: <see super::op_code>
Source

pub fn authoritative(&self) -> bool

AA              Authoritative Answer - this bit is valid in responses,
                and specifies that the responding name server is an
                authority for the domain name in question section.

                Note that the contents of the answer section may have
                multiple owner names because of aliases.  The AA bit
                corresponds to the name which matches the query name, or
                the first owner name in the answer section.
Source

pub fn truncated(&self) -> bool

TC              TrunCation - specifies that this message was truncated
                due to length greater than that permitted on the
                transmission channel.
Source

pub fn recursion_desired(&self) -> bool

RD              Recursion Desired - this bit may be set in a query and
                is copied into the response.  If RD is set, it directs
                the name server to pursue the query recursively.
                Recursive query support is optional.
Source

pub fn recursion_available(&self) -> bool

RA              Recursion Available - this be is set or cleared in a
                response, and denotes whether recursive query support is
                available in the name server.
Source

pub fn authentic_data(&self) -> bool

RFC 4035, DNSSEC Resource Records, March 2005


3.1.6.  The AD and CD Bits in an Authoritative Response

  The CD and AD bits are designed for use in communication between
  security-aware resolvers and security-aware recursive name servers.
  These bits are for the most part not relevant to query processing by
  security-aware authoritative name servers.

  A security-aware name server does not perform signature validation
  for authoritative data during query processing, even when the CD bit
  is clear.  A security-aware name server SHOULD clear the CD bit when
  composing an authoritative response.

  A security-aware name server MUST NOT set the AD bit in a response
  unless the name server considers all RRsets in the Answer and
  Authority sections of the response to be authentic.  A security-aware
  name server's local policy MAY consider data from an authoritative
  zone to be authentic without further validation.  However, the name
  server MUST NOT do so unless the name server obtained the
  authoritative zone via secure means (such as a secure zone transfer
  mechanism) and MUST NOT do so unless this behavior has been
  configured explicitly.

  A security-aware name server that supports recursion MUST follow the
  rules for the CD and AD bits given in Section 3.2 when generating a
  response that involves data obtained via recursion.
Source

pub fn checking_disabled(&self) -> bool

see is_authentic_data()

Source

pub fn response_code(&self) -> ResponseCode

RCODE           Response code - this 4 bit field is set as part of
                responses.  The values have the following
                interpretation: <see super::response_code>
Source

pub fn query_count(&self) -> u16

QDCOUNT         an unsigned 16 bit integer specifying the number of
                entries in the question section.
§Return value

If this is a query, this will return the number of queries in the query section of the

Source

pub fn answer_count(&self) -> u16

ANCOUNT         an unsigned 16 bit integer specifying the number of
                resource records in the answer section.
§Return value

For query responses this is the number of records in the answer section, should be 0 for requests, for updates this is the count of prerequisite records.

Source

pub fn name_server_count(&self) -> u16

for queries this is the nameservers which are authorities for the SOA of the Record for updates this is the update record count

NSCOUNT         an unsigned 16 bit integer specifying the number of name
                server resource records in the authority records
                section.
§Return value

For query responses this is the number of authorities, or nameservers, in the name server section, for updates this is the number of update records being sent.

Source

pub fn additional_count(&self) -> u16

ARCOUNT         an unsigned 16 bit integer specifying the number of
                resource records in the additional records section.
§Return value

This is the additional record section count, this section may include EDNS options.

Trait Implementations§

Source§

impl<'r> BinDecodable<'r> for Message

Source§

fn read(decoder: &mut BinDecoder<'r>) -> ProtoResult<Self>

Read the type from the stream
Source§

fn from_bytes(bytes: &'r [u8]) -> ProtoResult<Self>

Returns the object in binary form
Source§

impl BinEncodable for Message

Source§

fn emit(&self, encoder: &mut BinEncoder<'_>) -> ProtoResult<()>

Write the type to the stream
Source§

fn to_bytes(&self) -> ProtoResult<Vec<u8>>

Returns the object in binary form
Source§

impl Clone for Message

Source§

fn clone(&self) -> Message

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Message

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Message

Source§

fn default() -> Message

Returns the “default value” for a type. Read more
Source§

impl Display for Message

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl From<DnsResponse> for Message

Source§

fn from(response: DnsResponse) -> Self

Converts to this type from the input type.
Source§

impl From<Message> for DnsRequest

Source§

fn from(message: Message) -> Self

Converts to this type from the input type.
Source§

impl From<Message> for DnsResponse

Source§

fn from(message: Message) -> Self

Converts to this type from the input type.
Source§

impl From<Message> for MessageParts

Source§

fn from(msg: Message) -> Self

Converts to this type from the input type.
Source§

impl From<MessageParts> for Message

Source§

fn from(msg: MessageParts) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Message

Source§

fn eq(&self, other: &Message) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Deref for Message

Source§

type Target = Header

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl Eq for Message

Source§

impl StructuralPartialEq for Message

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more