use arcbox_error::CommonError;
use thiserror::Error;
pub type Result<T> = std::result::Result<T, NetError>;
#[derive(Debug, Error)]
pub enum NetError {
#[error(transparent)]
Common(#[from] CommonError),
#[error("interface error: {0}")]
Interface(String),
#[error("address allocation error: {0}")]
AddressAllocation(String),
#[error("port forwarding error: {0}")]
PortForward(String),
#[error("DNS error: {0}")]
Dns(String),
#[error("DHCP error: {0}")]
Dhcp(String),
#[error("backend error: {0}")]
Backend(String),
#[error("netlink error: {0}")]
Netlink(String),
#[error("bridge error: {0}")]
Bridge(String),
#[error("TAP error: {0}")]
Tap(String),
#[error("firewall error: {0}")]
Firewall(String),
#[error("NAT error: {0}")]
Nat(String),
#[error("datapath error: {0}")]
Datapath(String),
#[error("ring buffer error: {0}")]
RingBuffer(String),
#[error("packet pool error: {0}")]
PacketPool(String),
#[error("connection tracking error: {0}")]
ConnTrack(String),
#[error("checksum error: {0}")]
Checksum(String),
#[error("mDNS error: {0}")]
Mdns(String),
}
impl From<std::io::Error> for NetError {
fn from(err: std::io::Error) -> Self {
Self::Common(CommonError::from(err))
}
}
impl NetError {
#[must_use]
pub fn config(msg: impl Into<String>) -> Self {
Self::Common(CommonError::config(msg))
}
#[must_use]
pub fn io(err: std::io::Error) -> Self {
Self::Common(CommonError::from(err))
}
}