Skip to main content

Message

Struct Message 

#[non_exhaustive]
pub struct Message { pub metadata: Metadata, pub queries: Vec<Query>, pub answers: Vec<Record>, pub authorities: Vec<Record>, pub additionals: Vec<Record>, pub signature: Option<Box<Record<TSIG>>>, pub edns: Option<Edns>, }
Expand description

The basic request and response data structure, 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()

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§metadata: Metadata

Metadata from the message header

§queries: Vec<Query>

Query name and other query parameters

§answers: Vec<Record>

Records which directly answer the query

§authorities: Vec<Record>

Records with describe other authoritative servers

May optionally carry the SOA record for the authoritative data in the answer section.

§additionals: Vec<Record>

Records which may be helpful in using the records in the other sections

§signature: Option<Box<Record<TSIG>>>

TSIG signature for the message, if any

§edns: Option<Edns>

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 OPT pseudo-RR

Implementations§

§

impl Message

pub fn query() -> Message

Returns a new “empty” Message

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

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

pub fn response(id: u16, op_code: OpCode) -> Message

Returns a new Message with MessageType::Response and the given header contents

pub fn new(id: u16, message_type: MessageType, op_code: OpCode) -> Message

Create a new Message with the given header contents

pub fn truncate(&self) -> Message

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

pub fn maybe_strip_dnssec_records(self, query_has_dnssec_ok: bool) -> Message

Strip DNSSEC records per RFC 4035 section 3.2.1

Removes DNSSEC records that don’t match the query type from all sections when the DNSSEC OK bit is not set in the original query.

Uses the first query in the message to determine the query type. If there are no queries, returns the message unchanged.

The query_has_dnssec_ok is a required parameter because the dnssec_ok bit in the query might be different from the bit in the response. See discussion in #3340

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

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

pub fn add_queries<Q, I>(&mut self, queries: Q) -> &mut Message
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

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

Add a record to the Answer section.

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

Add all the records from the iterator to the Answer section of the message.

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

Sets the Answer section to the specified set of records.

§Panics

Will panic if the Answer section is already non-empty.

pub fn add_authority(&mut self, record: Record) -> &mut Message

Add a record to the Authority section.

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

Add all the records from the Iterator to the Authority section of the message.

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

Sets the Authority section to the specified set of records.

§Panics

Will panic if the Authority section is already non-empty.

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

Add a record to the Additional section.

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

Add all the records from the iterator to the Additional section of the message.

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.

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

Add the EDNS OPT pseudo-RR to the Message

pub fn into_response(self) -> Message

Returns a clone of the Message with the message type set to Response.

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

Consume the message, returning an iterator over records from all sections

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

All sections chained

pub fn max_payload(&self) -> u16

§Return value

the max payload value as it’s defined in the EDNS OPT pseudo-RR.

pub fn version(&self) -> u8

§Return value

the version as defined in the EDNS record

pub fn signature(&self) -> Option<&Record<TSIG>>

§Return value

the signature over the message, if any

pub fn take_signature(&mut self) -> Option<Box<Record<TSIG>>>

Remove signatures from the Message

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

Attempts to read the specified number of Querys

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

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 a Record<TSIG> if applicable.

A Record<TSIG> record is only valid when found in the additional data section. Further, it must always be the last record in that section. It is not possible to have multiple TSIG records.

RFC 8945 §5.1 says: “This TSIG record MUST be the only TSIG RR in the message and MUST be the last record in the additional data section.”

pub fn from_vec(buffer: &[u8]) -> Result<Message, DecodeError>

Decodes a message from the buffer.

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

Encodes the Message into a buffer

Methods from Deref<Target = Metadata>§

pub fn flags(&self) -> Flags

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

Trait Implementations§

§

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

§

fn read(decoder: &mut BinDecoder<'r>) -> Result<Message, DecodeError>

Read the type from the stream
§

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

Returns the object in binary form
§

impl BinEncodable for Message

§

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

Write the type to the stream
§

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

Returns the object in binary form
§

impl Clone for Message

§

fn clone(&self) -> Message

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

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

Performs copy-assignment from source. Read more
§

impl Debug for Message

§

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

Formats the value using the given formatter. Read more
§

impl Deref for Message

§

type Target = Metadata

The resulting type after dereferencing.
§

fn deref(&self) -> &<Message as Deref>::Target

Dereferences the value.
§

impl<'de> Deserialize<'de> for Message

§

fn deserialize<__D>( __deserializer: __D, ) -> Result<Message, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
§

impl Display for Message

§

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

Formats the value using the given formatter. Read more
§

impl From<DnsResponse> for Message

§

fn from(response: DnsResponse) -> Message

Converts to this type from the input type.
§

impl From<Message> for DnsRequest

§

fn from(message: Message) -> DnsRequest

Converts to this type from the input type.
§

impl PartialEq for Message

§

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.
§

impl Serialize for Message

§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
§

impl UpdateMessage for Message

to reduce errors in using the Message struct as an Update, this will do the call throughs to properly do that.

§

fn id(&self) -> u16

see Header::id
§

fn add_zone(&mut self, query: Query)

Adds the zone section, i.e. name.example.com would be example.com
§

fn add_pre_requisite(&mut self, record: Record)

Add the pre-requisite records Read more
§

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

Add all the Records from the Iterator to the pre-requisites section
§

fn add_update(&mut self, record: Record)

Add the Record to be updated
§

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

Add the Records from the Iterator to the updates section
§

fn add_additional(&mut self, record: Record)

Add Records to the additional Section of the UpdateMessage
§

fn zones(&self) -> &[Query]

Returns the Zones to be updated, generally should only be one.
§

fn prerequisites(&self) -> &[Record]

Returns the pre-requisites
§

fn updates(&self) -> &[Record]

Returns the records to be updated
§

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

Returns the additional records
§

fn signature(&self) -> Option<&Record<TSIG>>

Return the message’s signature (if any) Read more
§

impl Eq for Message

§

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
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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, dest: *mut u8)

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

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
§

impl<T> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
§

impl<T> Instrument for T

§

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

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

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<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> IntoRequest<T> for T

§

fn into_request(self) -> Request<T>

Wrap the input message T in a rama_grpc::Request
§

impl<L> LayerExt<L> for L

§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
§

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

§

fn rama_from(value: T) -> U

§

impl<T, U, CrateMarker> RamaInto<U, CrateMarker> for T
where U: RamaFrom<T, CrateMarker>,

§

fn rama_into(self) -> U

§

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

§

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

§

fn rama_try_from(value: T) -> Result<U, <U as RamaTryFrom<T>>::Error>

§

impl<T, U, CrateMarker> RamaTryInto<U, CrateMarker> for T
where U: RamaTryFrom<T, CrateMarker>,

§

type Error = <U as RamaTryFrom<T, CrateMarker>>::Error

§

fn rama_try_into(self) -> Result<U, <U as RamaTryFrom<T, CrateMarker>>::Error>

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> Same for T

Source§

type Output = T

Should always be Self
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
§

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

§

fn to_smolstr(&self) -> SmolStr

Source§

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

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
§

impl<T> ToStringFallible for T
where T: Display,

§

fn try_to_string(&self) -> Result<String, TryReserveError>

ToString::to_string, but without panic on OOM.

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.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,