aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock3
-rw-r--r--Cargo.toml1
-rw-r--r--src/main.rs88
3 files changed, 71 insertions, 21 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 0938586..ce7efb4 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1,6 +1,6 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
-version = 3
+version = 4
[[package]]
name = "addr2line"
@@ -616,7 +616,6 @@ dependencies = [
"rsdsl_netlinklib",
"serde_json",
"signal-hook",
- "thiserror",
]
[[package]]
diff --git a/Cargo.toml b/Cargo.toml
index 62f67d4..975aebc 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -14,4 +14,3 @@ rsdsl_dhcp4d = { git = "https://github.com/rsdsl/dhcp4d.git" }
rsdsl_netlinklib = { git = "https://github.com/rsdsl/netlinklib.git" }
serde_json = "1.0"
signal-hook = "0.3.17"
-thiserror = "1.0"
diff --git a/src/main.rs b/src/main.rs
index 1439a7b..1a38f47 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -5,8 +5,8 @@ use std::io::{self, BufRead, BufReader};
use std::net::{self, IpAddr, SocketAddr, ToSocketAddrs, UdpSocket};
use std::str::FromStr;
use std::sync::{Arc, RwLock};
-use std::thread;
use std::time::{Duration, SystemTime};
+use std::{fmt, thread};
use bytes::Bytes;
use dns_message_parser::question::{QType, Question};
@@ -19,7 +19,6 @@ use signal_hook::{
consts::{SIGUSR1, SIGUSR2},
iterator::Signals,
};
-use thiserror::Error;
const UPSTREAM_PRIMARY: &str = "[2620:fe::fe]:53";
const UPSTREAM_SECONDARY: &str = "9.9.9.9:53";
@@ -28,28 +27,81 @@ const UPSTREAM_TIMEOUT: Duration = Duration::from_secs(3);
type ForwardHosts = Arc<RwLock<HashMap<String, IpAddr>>>;
type ReverseHosts = Arc<RwLock<HashMap<IpAddr, String>>>;
-#[derive(Debug, Error)]
+#[derive(Debug)]
pub enum Error {
- #[error("hosts entry missing address column: {0}")]
NoAddrColumn(String),
- #[error("failed to send whole packet (expected {0}, got {1})")]
PartialSend(usize, usize),
- #[error("network address parse error: {0}")]
- AddrParse(#[from] net::AddrParseError),
- #[error("io error: {0}")]
- Io(#[from] io::Error),
-
- #[error("dns_message_parser decode error: {0}")]
- DnsDecode(#[from] dns_message_parser::DecodeError),
- #[error("dns_message_parser encode error: {0}")]
- DnsEncode(#[from] dns_message_parser::EncodeError),
- #[error("serde_json error: {0}")]
- SerdeJson(#[from] serde_json::Error),
- #[error("hickory_proto error: {0}")]
- HickoryProto(#[from] hickory_proto::error::ProtoError),
+ AddrParse(net::AddrParseError),
+ Io(io::Error),
+
+ DnsDecode(dns_message_parser::DecodeError),
+ DnsEncode(dns_message_parser::EncodeError),
+ SerdeJson(serde_json::Error),
+ HickoryProto(hickory_proto::error::ProtoError),
+}
+
+impl fmt::Display for Error {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ match self {
+ Self::NoAddrColumn(entry) => {
+ write!(f, "hosts entry missing address column: {}", entry)?
+ }
+ Self::PartialSend(want, got) => write!(
+ f,
+ "failed to send whole packet (expected {}, got {})",
+ want, got
+ )?,
+ Self::AddrParse(e) => write!(f, "network address parse error: {}", e)?,
+ Self::Io(e) => write!(f, "io error: {}", e)?,
+ Self::DnsDecode(e) => write!(f, "dns_message_parser decode error: {}", e)?,
+ Self::DnsEncode(e) => write!(f, "dns_message_parser encode error: {}", e)?,
+ Self::SerdeJson(e) => write!(f, "serde_json error: {}", e)?,
+ Self::HickoryProto(e) => write!(f, "hickory_proto error: {}", e)?,
+ }
+
+ Ok(())
+ }
+}
+
+impl From<net::AddrParseError> for Error {
+ fn from(e: net::AddrParseError) -> Error {
+ Error::AddrParse(e)
+ }
+}
+
+impl From<io::Error> for Error {
+ fn from(e: io::Error) -> Error {
+ Error::Io(e)
+ }
}
+impl From<dns_message_parser::DecodeError> for Error {
+ fn from(e: dns_message_parser::DecodeError) -> Error {
+ Error::DnsDecode(e)
+ }
+}
+
+impl From<dns_message_parser::EncodeError> for Error {
+ fn from(e: dns_message_parser::EncodeError) -> Error {
+ Error::DnsEncode(e)
+ }
+}
+
+impl From<serde_json::Error> for Error {
+ fn from(e: serde_json::Error) -> Error {
+ Error::SerdeJson(e)
+ }
+}
+
+impl From<hickory_proto::error::ProtoError> for Error {
+ fn from(e: hickory_proto::error::ProtoError) -> Error {
+ Error::HickoryProto(e)
+ }
+}
+
+impl std::error::Error for Error {}
+
pub type Result<T> = std::result::Result<T, Error>;
fn refresh_leases(cache: Arc<RwLock<Vec<Lease>>>) -> Result<()> {