#![forbid(unsafe_code)]
pub mod derp;
pub mod dns;
pub mod frame;
pub mod parser;
pub mod peer;
pub mod policy;
pub mod scanner;
pub use derp::{DerpMap, DerpNode, DerpRegion};
pub use dns::DnsConfig;
pub use frame::FrameReader;
pub use parser::{Netmap, Parser};
pub use peer::{Cidr, Cidr4, Peer, PeerTable};
pub use policy::{Destination, FilterRule, Network, PacketPolicy};
pub use scanner::{Scanner, Token};
pub const MAX_PEERS: usize = 32;
pub const MAX_ADDRESSES: usize = 4;
pub const MAX_PRIMARY_ROUTES: usize = 8;
pub const MAX_ALLOWED_IPS: usize = 8;
pub const MAX_ENDPOINTS: usize = 8;
pub const MAX_DERP_REGIONS: usize = 40;
pub const MAX_DERP_NODES: usize = 2;
pub const MAX_DERP_HOSTNAME: usize = 64;
#[cfg(feature = "peer-names")]
pub const MAX_PEER_NAME: usize = 63;
pub const MAX_DNS_DOMAINS: usize = 4;
pub const MAX_DNS_RESOLVERS: usize = 4;
pub const MAX_DNS_NAME: usize = 64;
pub const MAX_STRING: usize = 2 * 1024;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CapacityError {
Peers,
DerpRegions,
Routes,
Addresses,
AllowedIps,
Endpoints,
PacketPolicy,
String,
ParserDepth,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MalformedField {
DerpRegionId,
PacketDestination,
PacketRule,
NodeKey,
DiscoKey,
Address,
AllowedIp,
PolicySource,
PolicyDestination,
HomeDerp,
PeerId,
RemovedPeerId,
DerpPort,
StunPort,
PolicyPort,
PolicyProtocol,
}
impl core::fmt::Display for CapacityError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_str(match self {
Self::Peers => "peer table",
Self::DerpRegions => "DERP region table",
Self::Routes => "route table",
Self::Addresses => "address table",
Self::AllowedIps => "allowed-IP table",
Self::Endpoints => "endpoint table",
Self::PacketPolicy => "packet policy",
Self::String => "JSON string",
Self::ParserDepth => "JSON nesting depth",
})
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Error {
Json,
Full(CapacityError),
Malformed,
MalformedField(MalformedField),
FrameTooLarge,
}
impl core::fmt::Display for Error {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::Json => f.write_str("malformed JSON"),
Self::Full(category) => {
write!(f, "netmap {category} exceeds its configured bound")
}
Self::Malformed => f.write_str("a field could not be parsed"),
Self::MalformedField(field) => write!(f, "malformed {field:?}"),
Self::FrameTooLarge => f.write_str("map frame larger than the reader can hold"),
}
}
}
impl core::error::Error for Error {}