Skip to main content

netcore/
lib.rs

1//! Domain types and capability traits for `jip`.
2//!
3//! Users of this crate get a coherent view of a Linux host's network: L1 kernel
4//! primitives (`Link`, `Addr`, `Route`, `Neighbor`, `Socket`), L2 domain concepts
5//! (`Connection`, `Service`, `Path`, `Flow`), L3 judgments (`Finding`, `Health`),
6//! and L4 capability traits that backends implement.
7//!
8//! There is no I/O in this crate. Backends live in sibling crates.
9
10pub mod connection;
11pub mod diag;
12pub mod dns;
13pub mod link;
14pub mod path;
15pub mod process;
16pub mod service;
17pub mod traits;
18
19#[cfg(any(test, feature = "fixture"))]
20pub mod fixture;
21
22pub use connection::*;
23pub use diag::*;
24pub use dns::*;
25pub use link::*;
26pub use path::*;
27pub use process::*;
28pub use service::*;
29pub use traits::*;
30
31/// Crate-wide error type. Backends wrap their own errors in `Error::Backend`.
32#[derive(Debug, thiserror::Error)]
33pub enum Error {
34    /// An error from a backend (netlink, D-Bus, shell-out, etc.).
35    #[error("backend: {0}")]
36    Backend(String),
37    /// The requested operation is not supported on this platform or by the
38    /// current backend.
39    #[error("unsupported on this platform or by this backend: {0}")]
40    Unsupported(&'static str),
41    /// The operation requires a capability (e.g. `CAP_NET_RAW`) that is absent.
42    #[error("missing capability: {0}")]
43    MissingCapability(&'static str),
44    /// A parsing failure (e.g. malformed JSON from `nft`, unexpected kernel
45    /// attribute layout).
46    #[error("parse error: {0}")]
47    Parse(String),
48    /// A requested resource (interface, route, DNS answer, etc.) was not found.
49    #[error("not found: {0}")]
50    NotFound(String),
51    /// Wrapped `std::io::Error`.
52    #[error("io: {0}")]
53    Io(#[from] std::io::Error),
54}
55
56/// Convenience alias for `Result<T, Error>` throughout the crate.
57pub type Result<T> = std::result::Result<T, Error>;