Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,32 @@ resolver = "3"
members = [".", "./macros"]

[workspace.package]
version = "0.12.0"
edition = "2021"
authors = ["NLnet Labs <dns-team@nlnetlabs.nl>"]

version = "0.12.0"
# The MSRV is at least 4 versions behind stable (about half a year).
rust-version = "1.87.0"
edition = "2024"

homepage = "https://nlnetlabs.nl/projects/domain/"
repository = "https://github.com/nlnetlabs/domain/"
keywords = ["DNS", "domain"]
license = "BSD-3-Clause"

# The MSRV is at least 4 versions behind stable (about half a year).
rust-version = "1.87.0"

[package]
name = "domain"
description = "A DNS library for Rust."
authors.workspace = true

version.workspace = true
rust-version.workspace = true
edition.workspace = true
authors.workspace = true

homepage.workspace = true
repository.workspace = true
rust-version.workspace = true
keywords.workspace = true
license.workspace = true

description = "A DNS library for Rust."
documentation = "https://docs.rs/domain"
readme = "README.md"

Expand Down
4 changes: 3 additions & 1 deletion examples/ixfr-client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ async fn main() {
let qname = Name::<Vec<u8>>::from_str(&args[2]).unwrap();
let soa_serial: u32 = args[3].parse().unwrap();

eprintln!("Requesting IXFR from {server_addr} for zone {qname} from serial {soa_serial}");
eprintln!(
"Requesting IXFR from {server_addr} for zone {qname} from serial {soa_serial}"
);

let tcp_conn = TcpStream::connect(server_addr).await.unwrap();
let (tcp, transport) = stream::Connection::<
Expand Down
14 changes: 10 additions & 4 deletions examples/keyset.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Demonstrate the use of key sets.
use domain::base::iana::SecurityAlgorithm;
use domain::base::Name;
use domain::base::iana::SecurityAlgorithm;
use domain::dnssec::sign::keys::keyset::{
Action, Available, Error, KeySet, KeyType, RollType, UnixTime,
};
Expand Down Expand Up @@ -97,7 +97,9 @@ keyset example-keyset.json status
return;
}

eprintln!("Unknown command '{command}'. Valid commands are: init, addkey, deletekey, start, propagation1-complete, cache-expired1, propagation2-complete, cache-expired2, done, actions, and status");
eprintln!(
"Unknown command '{command}'. Valid commands are: init, addkey, deletekey, start, propagation1-complete, cache-expired1, propagation2-complete, cache-expired2, done, actions, and status"
);
exit(1);
}

Expand Down Expand Up @@ -508,7 +510,9 @@ fn report_actions(actions: Result<Vec<Action>, Error>, ks: &KeySet) {
}
}
Action::UpdateDsRrset => {
println!("\tUpdate the DS records at the parent to contain just the following keys:");
println!(
"\tUpdate the DS records at the parent to contain just the following keys:"
);
let keys = ks.keys();
for (pubref, key) in keys {
let status = match key.keytype() {
Expand All @@ -523,7 +527,9 @@ fn report_actions(actions: Result<Vec<Action>, Error>, ks: &KeySet) {
}
}
Action::CreateCdsRrset => {
println!("\tCreate CDS and CDNSKEY RRsets with the following keys:");
println!(
"\tCreate CDS and CDNSKEY RRsets with the following keys:"
);
let keys = ks.keys();
for (pubref, key) in keys {
let status = match key.keytype() {
Expand Down
6 changes: 5 additions & 1 deletion examples/query-zone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ fn main() {
let zone_answer = if let Some(zone) = zones.find_zone(&qname, qclass) {
// Query the built zone for the requested records.
if verbosity != Verbosity::Quiet {
println!("Querying zone {} class {} for qname {qname} with qtype {qtype}...", zone.apex_name(), zone.class());
println!(
"Querying zone {} class {} for qname {qname} with qtype {qtype}...",
zone.apex_name(),
zone.class()
);
}
zone.read().query(qname.clone(), qtype).unwrap()
} else {
Expand Down
12 changes: 9 additions & 3 deletions examples/read-zone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ fn main() {
let zone_files: Vec<_> = args.collect();

if zone_files.is_empty() {
eprintln!("Usage: {prog_name} <path/to/zonefile/to/read> [<more>, <zone>, <files>, <to>, <read>, ...]");
eprintln!(
"Usage: {prog_name} <path/to/zonefile/to/read> [<more>, <zone>, <files>, <to>, <read>, ...]"
);
exit(2);
}

Expand Down Expand Up @@ -47,9 +49,13 @@ fn main() {
"\nThe last record read was:\n{record}."
);
} else {
eprintln!("\nThe last record read was:\n{last_entry:#?}.");
eprintln!(
"\nThe last record read was:\n{last_entry:#?}."
);
}
eprintln!("\nTry commenting out the line after that record with a leading ; (semi-colon) character.")
eprintln!(
"\nTry commenting out the line after that record with a leading ; (semi-colon) character."
)
}
exit(1);
}
Expand Down
2 changes: 1 addition & 1 deletion examples/resolv-sync.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use domain::base::name::Name;
use domain::base::Rtype;
use domain::base::name::Name;
use domain::rdata::AllRecordData;
use domain::resolv::StubResolver;
use std::env;
Expand Down
20 changes: 14 additions & 6 deletions examples/serve-zone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
//!
//! dig @127.0.0.1 -p 8053 AXFR example.com

use core::future::{ready, Future};
use core::future::{Future, ready};
use core::pin::Pin;
use core::str::FromStr;

Expand All @@ -28,8 +28,8 @@ use std::time::Duration;

use domain::rdata::{Soa, ZoneRecordData};
use octseq::Octets;
use rand::distr::Alphanumeric;
use rand::RngExt;
use rand::distr::Alphanumeric;
use tokio::net::{TcpListener, UdpSocket};
use tracing_subscriber::EnvFilter;

Expand Down Expand Up @@ -186,11 +186,17 @@ async fn main() {
eprintln!("Try:");
eprintln!(" dig @127.0.0.1 -p 8053 example.com");
eprintln!(" dig @127.0.0.1 -p 8053 example.com AXFR");
eprintln!(" dig @127.0.0.1 -p 8053 -y hmac-sha256:demo-key:zlCZbVJPIhobIs1gJNQfrsS3xCxxsR9pMUrGwG8OgG8= example.com AXFR");
eprintln!(
" dig @127.0.0.1 -p 8053 -y hmac-sha256:demo-key:zlCZbVJPIhobIs1gJNQfrsS3xCxxsR9pMUrGwG8OgG8= example.com AXFR"
);
eprintln!(" dig @127.0.0.1 -p 8053 +opcode=notify example.com SOA");
eprintln!(" cargo run --example ixfr-client --all-features -- 127.0.0.1:8053 example.com 2020080302");
eprintln!(
" cargo run --example ixfr-client --all-features -- 127.0.0.1:8053 example.com 2020080302"
);
eprintln!();
eprintln!("Tip: set env var RUST_LOG=info (or debug or trace) for more log output.");
eprintln!(
"Tip: set env var RUST_LOG=info (or debug or trace) for more log output."
);

// Print some status information every 5 seconds
tokio::spawn(async move {
Expand Down Expand Up @@ -309,7 +315,9 @@ impl Notifiable for DemoNotifyTarget {
) -> Pin<
Box<dyn Future<Output = Result<(), NotifyError>> + Sync + Send + '_>,
> {
eprintln!("Notify received from {source} of change to zone {apex_name} in class {class} with serial {serial:?}");
eprintln!(
"Notify received from {source} of change to zone {apex_name} in class {class} with serial {serial:?}"
);

let res = match apex_name.to_string().to_lowercase().as_str() {
"example.com" => Ok(()),
Expand Down
26 changes: 17 additions & 9 deletions examples/server-transports.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use core::fmt;
use core::future::{ready, Future, Ready};
use core::future::{Future, Ready, ready};
use core::sync::atomic::{AtomicBool, AtomicU8, Ordering};
use core::task::{Context, Poll};
use core::time::Duration;
Expand All @@ -13,13 +13,13 @@ use std::sync::Arc;
use std::sync::RwLock;
use std::vec::Vec;

use futures_util::stream::{once, Empty, Once, Stream};
use futures_util::stream::{Empty, Once, Stream, once};
use octseq::{FreezeBuilder, Octets};
use tokio::net::{TcpListener, TcpSocket, TcpStream, UdpSocket};
use tokio::sync::mpsc::unbounded_channel;
use tokio::time::Instant;
use tokio_rustls::rustls;
use tokio_rustls::TlsAcceptor;
use tokio_rustls::rustls;
use tokio_stream::wrappers::UnboundedReceiverStream;
use tokio_tfo::{TfoListener, TfoStream};
use tracing_subscriber::EnvFilter;
Expand All @@ -44,7 +44,7 @@ use domain::net::server::service::{
use domain::net::server::sock::AsyncAccept;
use domain::net::server::stream::StreamServer;
use domain::net::server::util::{mk_builder_for_target, service_fn};
use domain::rdata::{Soa, A};
use domain::rdata::{A, Soa};

//----------- mk_answer() ----------------------------------------------------

Expand Down Expand Up @@ -241,7 +241,9 @@ fn name_to_ip(

if out_answer.is_none() {
let builder = mk_builder_for_target();
eprintln!("Refusing request, only requests for A records in IPv4 dotted quad format are accepted by this service.");
eprintln!(
"Refusing request, only requests for A records in IPv4 dotted quad format are accepted by this service."
);
out_answer = Some(
builder
.start_answer(request.message(), Rcode::REFUSED)
Expand Down Expand Up @@ -447,16 +449,22 @@ pub struct Stats {

impl std::fmt::Display for Stats {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "# Reqs={} [UDP={}, IPv4={}, IPv6={}] Bytes [rx={}, tx={}] Speed [fastest={}, slowest={}]",
write!(
f,
"# Reqs={} [UDP={}, IPv4={}, IPv6={}] Bytes [rx={}, tx={}] Speed [fastest={}, slowest={}]",
self.num_reqs,
self.num_udp,
self.num_ipv4,
self.num_ipv6,
self.num_req_bytes,
self.num_resp_bytes,
self.fastest_req.map(|v| format!("{}μs", v.as_micros())).unwrap_or_else(|| "-".to_string()),
self.slowest_req.map(|v| format!("{}ms", v.as_millis())).unwrap_or_else(|| "-".to_string()),
)
self.fastest_req
.map(|v| format!("{}μs", v.as_micros()))
.unwrap_or_else(|| "-".to_string()),
self.slowest_req
.map(|v| format!("{}ms", v.as_millis()))
.unwrap_or_else(|| "-".to_string()),
)
}
}

Expand Down
8 changes: 5 additions & 3 deletions macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
[package]
name = "domain-macros"
description = "Procedural macros for the `domain` crate."
authors.workspace = true

version.workspace = true
rust-version.workspace = true
edition.workspace = true
authors.workspace = true

homepage.workspace = true
repository.workspace = true
rust-version.workspace = true
keywords.workspace = true
license.workspace = true

description = "Procedural macros for the `domain` crate."
documentation = "https://docs.rs/domain-macros"

[lib]
Expand Down
4 changes: 2 additions & 2 deletions macros/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
use std::ops::Deref;

use proc_macro2::TokenStream;
use quote::{quote, ToTokens};
use syn::{spanned::Spanned, Field, Fields, Ident, Index, Member, Token};
use quote::{ToTokens, quote};
use syn::{Field, Fields, Ident, Index, Member, Token, spanned::Spanned};

//----------- Struct ---------------------------------------------------------

Expand Down
8 changes: 4 additions & 4 deletions macros/src/impls.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//! Helpers for generating `impl` blocks.

use proc_macro2::{Span, TokenStream};
use quote::{format_ident, quote, ToTokens};
use quote::{ToTokens, format_ident, quote};
use syn::{
punctuated::Punctuated, visit::Visit, ConstParam, GenericArgument,
GenericParam, Ident, Lifetime, LifetimeParam, Token, TypeParam,
TypeParamBound, WhereClause, WherePredicate,
ConstParam, GenericArgument, GenericParam, Ident, Lifetime,
LifetimeParam, Token, TypeParam, TypeParamBound, WhereClause,
WherePredicate, punctuated::Punctuated, visit::Visit,
};

//----------- ImplSkeleton ---------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use proc_macro as pm;
use proc_macro2::TokenStream;
use quote::{format_ident, ToTokens};
use quote::{ToTokens, format_ident};
use syn::{Error, Ident, Result};

mod impls;
Expand Down
20 changes: 14 additions & 6 deletions macros/src/repr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

use proc_macro2::Span;
use syn::{
punctuated::Punctuated, spanned::Spanned, Attribute, Error, LitInt, Meta,
Token,
Attribute, Error, LitInt, Meta, Token, punctuated::Punctuated,
spanned::Spanned,
};

//----------- Repr -----------------------------------------------------------
Expand Down Expand Up @@ -50,8 +50,12 @@ impl Repr {
}

Meta::Path(p) if p.is_ident("Rust") => {
return Err(Error::new_spanned(p,
format!("repr(Rust) is not stable, cannot derive {bound} for it")));
return Err(Error::new_spanned(
p,
format!(
"repr(Rust) is not stable, cannot derive {bound} for it"
),
));
}

Meta::Path(p) if p.is_ident("packed") => {
Expand All @@ -66,8 +70,12 @@ impl Repr {
let lit: LitInt = syn::parse2(meta.tokens)?;
let n: usize = lit.base10_parse()?;
if n != 1 {
return Err(Error::new(span,
format!("'Self' must be unaligned to derive {bound}")));
return Err(Error::new(
span,
format!(
"'Self' must be unaligned to derive {bound}"
),
));
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/base/charstr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ impl CharStr<[u8]> {
#[must_use]
pub unsafe fn from_slice_unchecked(slice: &[u8]) -> &Self {
// SAFETY: Charstr has repr(transparent)
mem::transmute(slice)
unsafe { mem::transmute(slice) }
}

/// Creates a character string from a mutable slice without checking.
Expand All @@ -195,7 +195,7 @@ impl CharStr<[u8]> {
/// long. Otherwise, the behaviour is undefined.
unsafe fn from_slice_mut_unchecked(slice: &mut [u8]) -> &mut Self {
// SAFETY: Charstr has repr(transparent)
mem::transmute(slice)
unsafe { mem::transmute(slice) }
}

/// Checks whether an octets slice contains a correct character string.
Expand Down Expand Up @@ -1242,7 +1242,7 @@ mod test {

#[test]
fn from_str() {
use std::str::{from_utf8, FromStr};
use std::str::{FromStr, from_utf8};

type Cs = CharStr<Vec<u8>>;

Expand Down Expand Up @@ -1350,7 +1350,7 @@ mod test {
#[cfg(feature = "serde")]
#[test]
fn ser_de() {
use serde_test::{assert_tokens, Configure, Token};
use serde_test::{Configure, Token, assert_tokens};

assert_tokens(
&CharStr::from_octets(Vec::from(b"fo\x12 bar".as_ref()))
Expand Down
Loading
Loading