Struct Message
pub struct Message { /* private fields */ }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()
Implementations§
§impl Message
impl Message
pub fn error_msg(
id: u16,
op_code: OpCode,
response_code: ResponseCode,
) -> 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 idop_code- operation of the requestresponse_code- the error code for the response
pub fn response(id: u16, op_code: OpCode) -> Message
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
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
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
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 set_header(&mut self, header: Header) -> &mut Message
pub fn set_header(&mut self, header: Header) -> &mut Message
Sets the Header
pub fn set_id(&mut self, id: u16) -> &mut Message
pub fn set_id(&mut self, id: u16) -> &mut Message
See Header::set_id()
pub fn set_op_code(&mut self, op_code: OpCode) -> &mut Message
pub fn set_op_code(&mut self, op_code: OpCode) -> &mut Message
pub fn set_truncated(&mut self, truncated: bool) -> &mut Message
pub fn set_truncated(&mut self, truncated: bool) -> &mut Message
pub fn set_recursion_desired(&mut self, recursion_desired: bool) -> &mut Message
pub fn set_recursion_desired(&mut self, recursion_desired: bool) -> &mut Message
pub fn set_recursion_available(
&mut self,
recursion_available: bool,
) -> &mut Message
pub fn set_recursion_available( &mut self, recursion_available: bool, ) -> &mut Message
pub fn set_authentic_data(&mut self, authentic_data: bool) -> &mut Message
pub fn set_authentic_data(&mut self, authentic_data: bool) -> &mut Message
pub fn set_checking_disabled(&mut self, checking_disabled: bool) -> &mut Message
pub fn set_checking_disabled(&mut self, checking_disabled: bool) -> &mut Message
pub fn set_response_code(&mut self, response_code: ResponseCode) -> &mut Message
pub fn set_response_code(&mut self, response_code: ResponseCode) -> &mut Message
pub fn set_query_count(&mut self, query_count: u16) -> &mut Message
pub fn set_query_count(&mut self, query_count: u16) -> &mut Message
this count will be ignored during serialization, where the length of the associated records will be used instead.
pub fn set_answer_count(&mut self, answer_count: u16) -> &mut Message
pub fn set_answer_count(&mut self, answer_count: u16) -> &mut Message
See Header::set_answer_count()
this count will be ignored during serialization, where the length of the associated records will be used instead.
See Header::set_authority_count()
this count will be ignored during serialization, where the length of the associated records will be used instead.
pub fn set_additional_count(&mut self, additional_count: u16) -> &mut Message
pub fn set_additional_count(&mut self, additional_count: u16) -> &mut Message
See Header::set_additional_count()
this count will be ignored during serialization, where the length of the associated records will be used instead.
pub fn add_query(&mut self, query: Query) -> &mut Message
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
pub fn add_queries<Q, I>(&mut self, queries: Q) -> &mut Message
Adds an iterator over a set of Queries to be added to the message
pub fn add_answer(&mut self, record: Record) -> &mut 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
pub fn add_answers<R, I>(&mut self, records: R) -> &mut Message
Add all the records from the iterator to the Answer section of the message.
pub fn insert_answers(&mut self, records: Vec<Record>)
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.
Add a record to the Authority section.
Add all the records from the Iterator to the Authority section of the message.
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
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
pub fn add_additionals<R, I>(&mut self, records: R) -> &mut Message
Add all the records from the iterator to the Additional section of the message.
pub fn insert_additionals(&mut self, records: Vec<Record>)
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 to_response(&self) -> Message
pub fn to_response(&self) -> Message
Returns a clone of the Message with the message type set to Response.
pub fn id(&self) -> u16
pub fn id(&self) -> u16
See Header::id()
pub fn message_type(&self) -> MessageType
pub fn message_type(&self) -> MessageType
pub fn recursion_desired(&self) -> bool
pub fn recursion_desired(&self) -> bool
pub fn recursion_available(&self) -> bool
pub fn recursion_available(&self) -> bool
pub fn authentic_data(&self) -> bool
pub fn authentic_data(&self) -> bool
pub fn checking_disabled(&self) -> bool
pub fn checking_disabled(&self) -> bool
pub fn response_code(&self) -> ResponseCode
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
pub fn queries_mut(&mut self) -> &mut Vec<Query>
pub fn queries_mut(&mut self) -> &mut Vec<Query>
Provides mutable access to queries
pub fn take_queries(&mut self) -> Vec<Query>
pub fn take_queries(&mut self) -> Vec<Query>
Removes all the answers from the Message
pub fn answers_mut(&mut self) -> &mut Vec<Record>
pub fn answers_mut(&mut self) -> &mut Vec<Record>
Provides mutable access to answers
pub fn take_answers(&mut self) -> Vec<Record>
pub fn take_answers(&mut self) -> Vec<Record>
Removes the Answer section records from the message
Authority Carries RRs which describe other authoritative servers.
May optionally carry the SOA RR for the authoritative
data in the answer section.Provides mutable access to authorities
Remove the Authority section records from the message
pub fn additionals(&self) -> &[Record]
pub fn additionals(&self) -> &[Record]
Additional Carries RRs which may be helpful in using the RRs in the
other sections.pub fn additionals_mut(&mut self) -> &mut Vec<Record>
pub fn additionals_mut(&mut self) -> &mut Vec<Record>
Provides mutable access to additionals
pub fn take_additionals(&mut self) -> Vec<Record>
pub fn take_additionals(&mut self) -> Vec<Record>
Remove the Additional section records from the message
pub fn take_all_sections(&mut self) -> impl Iterator<Item = Record>
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>
pub fn all_sections(&self) -> impl Iterator<Item = &Record>
All sections chained
pub fn extensions(&self) -> &Option<Edns>
pub fn extensions(&self) -> &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
pub fn extensions_mut(&mut self) -> &mut Option<Edns>
pub fn extensions_mut(&mut self) -> &mut Option<Edns>
Returns mutable reference of EDNS OPT pseudo-RR
pub fn max_payload(&self) -> u16
pub fn max_payload(&self) -> u16
§Return value
the max payload value as it’s defined in the EDNS OPT pseudo-RR.
pub fn signature(&self) -> Option<&Record<TSIG>>
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>>>
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>
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>>>), ProtoError>
pub fn read_records( decoder: &mut BinDecoder<'_>, count: usize, is_additional: bool, ) -> Result<(Vec<Record>, Option<Edns>, Option<Box<Record<TSIG>>>), ProtoError>
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, ProtoError>
pub fn from_vec(buffer: &[u8]) -> Result<Message, ProtoError>
Decodes a message from the buffer.
pub fn to_vec(&self) -> Result<Vec<u8>, ProtoError>
pub fn to_vec(&self) -> Result<Vec<u8>, ProtoError>
Encodes the Message into a buffer
pub fn into_parts(self) -> MessageParts
pub fn into_parts(self) -> MessageParts
Consumes Message and returns into components
Methods from Deref<Target = Header>§
pub fn id(&self) -> u16
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.pub fn message_type(&self) -> MessageType
pub fn message_type(&self) -> MessageType
QR A one bit field that specifies whether this message is a
query (0), or a response (1).pub fn op_code(&self) -> OpCode
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>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.pub fn truncated(&self) -> bool
pub fn truncated(&self) -> bool
TC TrunCation - specifies that this message was truncated
due to length greater than that permitted on the
transmission channel.pub fn recursion_desired(&self) -> bool
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.pub fn recursion_available(&self) -> bool
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.pub fn authentic_data(&self) -> bool
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.pub fn checking_disabled(&self) -> bool
pub fn checking_disabled(&self) -> bool
see is_authentic_data()
pub fn response_code(&self) -> ResponseCode
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>pub fn query_count(&self) -> u16
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 message, for updates this represents the zone count (must be no more than 1).
pub fn answer_count(&self) -> u16
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.
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 authority section, for updates this is the number of update records being sent.
pub fn additional_count(&self) -> u16
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§
§impl<'r> BinDecodable<'r> for Message
impl<'r> BinDecodable<'r> for Message
§fn read(decoder: &mut BinDecoder<'r>) -> Result<Message, ProtoError>
fn read(decoder: &mut BinDecoder<'r>) -> Result<Message, ProtoError>
§fn from_bytes(bytes: &'r [u8]) -> Result<Self, ProtoError>
fn from_bytes(bytes: &'r [u8]) -> Result<Self, ProtoError>
§impl BinEncodable for Message
impl BinEncodable for Message
§fn emit(&self, encoder: &mut BinEncoder<'_>) -> Result<(), ProtoError>
fn emit(&self, encoder: &mut BinEncoder<'_>) -> Result<(), ProtoError>
§impl<'de> Deserialize<'de> for Message
impl<'de> Deserialize<'de> for Message
§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Message, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Message, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
§impl From<DnsResponse> for Message
impl From<DnsResponse> for Message
§fn from(response: DnsResponse) -> Message
fn from(response: DnsResponse) -> Message
§impl From<Message> for DnsRequest
impl From<Message> for DnsRequest
§fn from(message: Message) -> DnsRequest
fn from(message: Message) -> DnsRequest
§impl From<Message> for MessageParts
impl From<Message> for MessageParts
§fn from(msg: Message) -> MessageParts
fn from(msg: Message) -> MessageParts
§impl From<MessageParts> for Message
impl From<MessageParts> for Message
§fn from(msg: MessageParts) -> Message
fn from(msg: MessageParts) -> Message
§impl Serialize for Message
impl Serialize for Message
§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
§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.
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 add_zone(&mut self, query: Query)
fn add_zone(&mut self, query: Query)
§fn add_pre_requisite(&mut self, record: Record)
fn add_pre_requisite(&mut self, record: Record)
§fn add_pre_requisites<R, I>(&mut self, records: R)
fn add_pre_requisites<R, I>(&mut self, records: R)
§fn add_update(&mut self, record: Record)
fn add_update(&mut self, record: Record)
§fn add_updates<R, I>(&mut self, records: R)
fn add_updates<R, I>(&mut self, records: R)
§fn add_additional(&mut self, record: Record)
fn add_additional(&mut self, record: Record)
§fn prerequisites(&self) -> &[Record]
fn prerequisites(&self) -> &[Record]
§fn additionals(&self) -> &[Record]
fn additionals(&self) -> &[Record]
impl Eq for Message
impl StructuralPartialEq for Message
Auto Trait Implementations§
impl Freeze for Message
impl RefUnwindSafe for Message
impl Send for Message
impl Sync for Message
impl Unpin for Message
impl UnsafeUnpin for Message
impl UnwindSafe for Message
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a rama_grpc::Request§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§fn and<P, B, E>(self, other: P) -> And<T, P>
fn and<P, B, E>(self, other: P) -> And<T, P>
Policy that returns Action::Follow only if self and other return
Action::Follow. Read more§impl<T, U> RamaTryFrom<T> for Uwhere
U: TryFrom<T>,
impl<T, U> RamaTryFrom<T> for Uwhere
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 Twhere
U: RamaTryFrom<T, CrateMarker>,
impl<T, U, CrateMarker> RamaTryInto<U, CrateMarker> for Twhere
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>
§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.