Skip to main content

ip_nlroute/
error.rs

1#[cfg(all(target_os = "linux", feature = "netlink"))]
2use neli::{err::RouterError, types::Buffer};
3use thiserror::Error;
4
5#[derive(Debug, Error)]
6pub enum Error {
7    #[error("I/O error")]
8    Io(#[from] std::io::Error),
9    #[cfg(all(target_os = "linux", feature = "netlink"))]
10    #[error("netlink socket error")]
11    NetlinkSocket(#[from] neli::err::SocketError),
12    #[cfg(all(target_os = "linux", feature = "netlink"))]
13    #[error("failed to build address message")]
14    IfaddrMsgBuilder(#[from] neli::rtnl::IfaddrmsgBuilderError),
15    #[cfg(all(target_os = "linux", feature = "netlink"))]
16    #[error("failed to build route message")]
17    RtMsgBuilder(#[from] neli::rtnl::RtmsgBuilderError),
18    #[cfg(all(target_os = "linux", feature = "netlink"))]
19    #[error("netlink router error")]
20    NlRouter(#[from] RouterError<u16, Buffer>),
21    #[error("failed to send netlink request")]
22    Send(#[source] Box<dyn std::error::Error + Send + Sync>),
23    #[error("failed to receive netlink response")]
24    Receive(#[source] Box<dyn std::error::Error + Send + Sync>),
25    #[error("unexpected netlink message type: expected {expected}, got {actual}")]
26    UnexpectedNlType { expected: String, actual: String },
27    #[error("failed to deserialise {what}")]
28    Deserialise {
29        what: &'static str,
30        #[source]
31        source: Box<dyn std::error::Error + Send + Sync>,
32    },
33    #[cfg(all(target_os = "linux", feature = "netlink"))]
34    #[error("failed to resolve interface '{ifname}'")]
35    InterfaceLookup {
36        ifname: String,
37        #[source]
38        source: nix::errno::Errno,
39    },
40    #[cfg(all(target_os = "linux", feature = "netlink"))]
41    #[error("failed to resolve interface index '{ifindex}'")]
42    IfIndexLookup {
43        ifindex: u32,
44        #[source]
45        source: nix::errno::Errno,
46    },
47    #[error("Expected exactly 1 {what}, found {len}")]
48    ExpectedExactlyOne { what: &'static str, len: usize },
49    #[error("Response contained invalid data: {reason}")]
50    InvalidDataInResponse { reason: &'static str },
51    #[error("Not implemented")]
52    NotImplemented,
53}