Skip to content

Commit

Permalink
⬆Upgrade hickory (mokeyish#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
mokeyish authored Mar 1, 2024
1 parent 9ce9fde commit 0054b8a
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 72 deletions.
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ license = "GPL-v3.0"
readme = "README.md"

[package.metadata.patch]
crates = ["hickory-server", "hickory-proto"]
# crates = ["hickory-server", "hickory-proto"]

[features]

Expand Down Expand Up @@ -66,8 +66,8 @@ experimental-phf = [
[patch.crates-io]
# rustls = { git = "https://github.com/mokeyish/rustls.git", branch = "patched_main"}
# hickory-resolver = { git = "https://github.com/hickory-dns/hickory-dns.git", rev = "41b6e33"}
hickory-server = { path = "./target/patch/hickory-server-0.24.0" }
hickory-proto = { path = "./target/patch/hickory-proto-0.24.0" }
# hickory-server = { path = "./target/patch/hickory-server-0.24.0" }
# hickory-proto = { path = "./target/patch/hickory-proto-0.24.0" }
# rustls-native-certs = { git = "https://github.com/mokeyish/rustls-native-certs.git" }
hostname = { git = "https://github.com/mokeyish/hostname.git", branch = "dev" }
# enum_dispatch = { git = "https://gitlab.com/mokeyish/enum_dispatch.git", branch = "master"}
Expand Down Expand Up @@ -125,12 +125,12 @@ tracing-subscriber = { version = "0.3", features = [
# tracing-appender = "0.2"

# hickory dns
hickory-proto = { version = "0.24", features = ["serde-config"]}
hickory-resolver = { version = "0.24", features = [
hickory-proto = { git = "https://github.com/mokeyish/hickory-dns.git", rev = "18302fe", version = "0.24", features = ["serde-config"]}
hickory-resolver = { git = "https://github.com/mokeyish/hickory-dns.git", rev = "18302fe", version = "0.24", features = [
"serde-config",
"system-config",
] }
hickory-server = { version = "0.24", features = ["resolver"], optional = true }
hickory-server = { git = "https://github.com/mokeyish/hickory-dns.git", rev = "18302fe", version = "0.24", features = ["resolver"], optional = true }

# ssl
webpki-roots = "0.25.2"
Expand Down
15 changes: 10 additions & 5 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@


build: apply-patch
build: init
cargo build -r

# Run tests
test: apply-patch
test: init
cargo test

# Run clippy
clippy: apply-patch
clippy: init
cargo clippy --fix --all

# Check the format
fmt: apply-patch
fmt: init
cargo fmt --all

# cleanup the workspace
clean:
cargo clean

apply-patch: init
cargo patch-crate
cargo patch-crate -f

# Initialize all tools needed
init:
@cargo install patch-crate -q
# @cargo patch-crate

12 changes: 0 additions & 12 deletions patches/hickory-proto+0.24.0.patch

This file was deleted.

36 changes: 0 additions & 36 deletions patches/hickory-server+0.24.0.patch

This file was deleted.

18 changes: 17 additions & 1 deletion src/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::config::ServerOpts;
use crate::dns_conf::RuntimeConfig;

pub use crate::libdns::proto::{
error::ProtoErrorKind,
op,
rr::{self, rdata::SOA, Name, RData, Record, RecordType},
};
Expand Down Expand Up @@ -296,6 +297,8 @@ mod request {

mod response {

use hickory_proto::op;

use crate::dns_client::MAX_TTL;
use crate::libdns::proto::{
op::{Header, Message, Query},
Expand Down Expand Up @@ -333,10 +336,23 @@ mod response {
R: IntoIterator<Item = Record, IntoIter = I>,
I: Iterator<Item = Record>,
{
use op::message::{update_header_counts, HeaderCounts};
let mut message = Message::new();
message.add_query(query.clone());
message.add_answers(records);
message.update_counts();

let header = update_header_counts(
message.header(),
message.truncated(),
HeaderCounts {
query_count: message.queries().len(),
answer_count: message.answers().len(),
nameserver_count: message.name_servers().len(),
additional_count: message.additionals().len(),
},
);

message.set_header(header);

Self {
message,
Expand Down
15 changes: 10 additions & 5 deletions src/dns_error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::dns::DnsResponse;
use crate::libdns::proto::{error::ProtoError, op::ResponseCode};
use crate::libdns::resolver::error::{ResolveError, ResolveErrorKind};
use hickory_proto::error::ProtoErrorKind;
use std::{io, sync::Arc};
use thiserror::Error;

Expand All @@ -15,9 +16,13 @@ pub enum LookupError {
/// There was an error performing the lookup
#[error("Error performing lookup: {0}")]
ResponseCode(ResponseCode),
/// An error got returned by the hickory-proto crate
#[error("proto error: {0}")]
Proto(#[from] ProtoError),
/// Resolve Error
#[error("Forward resolution error: {0}")]
ResolveError(#[from] ResolveError),

/// Recursive Resolver Error
#[cfg(feature = "hickory-recursor")]
#[cfg_attr(docsrs, doc(cfg(feature = "recursor")))]
Expand All @@ -39,8 +44,8 @@ impl LookupError {
}

pub fn as_soa(&self) -> Option<DnsResponse> {
if let Self::ResolveError(err) = self {
if let ResolveErrorKind::NoRecordsFound {
if let Self::Proto(err) = self {
if let ProtoErrorKind::NoRecordsFound {
query,
soa: Some(record),
..
Expand All @@ -62,9 +67,9 @@ impl From<ResponseCode> for LookupError {
}
}

impl From<ProtoError> for LookupError {
fn from(value: ProtoError) -> Self {
Self::ResolveError(value.into())
impl From<ProtoErrorKind> for LookupError {
fn from(value: ProtoErrorKind) -> Self {
Self::Proto(value.into())
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/dns_mw.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use std::{borrow::Borrow, sync::Arc};

use crate::libdns::proto::{
error::ProtoErrorKind,
op::{Query, ResponseCode},
rr::{rdata::SOA, IntoName, Record, RecordType},
};

use crate::libdns::resolver::error::ResolveErrorKind;

use crate::{
config::ServerOpts,
dns::{DefaultSOA, DnsContext, DnsError, DnsRequest, DnsResponse},
Expand Down Expand Up @@ -122,7 +121,7 @@ impl MiddlewareDefaultHandler<DnsContext, DnsRequest, DnsResponse, DnsError> for
ctx.cfg().rr_ttl().unwrap_or_default() as u32,
SOA::default_soa(),
);
Err(ResolveErrorKind::NoRecordsFound {
Err(ProtoErrorKind::NoRecordsFound {
query: req.query().original().to_owned().into(),
soa: Some(Box::new(soa)),
negative_ttl: None,
Expand Down
8 changes: 4 additions & 4 deletions src/dns_mw_ns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl Middleware<DnsContext, DnsRequest, DnsResponse, DnsError> for NameServerMid
Some(ns) => ns,
None => {
error!("no available nameserver found for {}", name);
return Err(ResolveErrorKind::NoConnections.into());
return Err(ProtoErrorKind::NoConnections.into());
}
};

Expand Down Expand Up @@ -195,7 +195,7 @@ async fn lookup_ip(
.collect::<Vec<_>>();

if tasks.is_empty() {
return Err(ResolveErrorKind::NoConnections.into());
return Err(ProtoErrorKind::NoConnections.into());
}

let ping_duration = |fut: Pin<
Expand Down Expand Up @@ -376,7 +376,7 @@ async fn lookup_ip(
} else {
match last_res {
Some(res) => res,
None => Err(ResolveErrorKind::NoConnections.into()),
None => Err(ProtoErrorKind::NoConnections.into()),
}
}
}
Expand Down Expand Up @@ -444,7 +444,7 @@ async fn per_nameserver_lookup_ip(
.collect::<Vec<_>>();

if answers.is_empty() {
return Err(ResolveErrorKind::NoRecordsFound {
return Err(ProtoErrorKind::NoRecordsFound {
query: Box::new(query),
soa: None,
negative_ttl: None,
Expand Down

0 comments on commit 0054b8a

Please sign in to comment.