pub mod cert_validator;
pub mod client;
pub mod metrics;
pub mod requests;
pub(crate) mod scion_packet;
pub mod server;
pub mod server_deprecated;
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
use ipnet::{IpNet, Ipv4Net, Ipv6Net};
use scion_proto::address::{EndhostAddr, IsdAsn};
pub(crate) const PATH_SOCK_ADDR_ASSIGNMENT: &str = "/connectrpc.v1.snaptun/assign_socketaddr";
pub(crate) const PATH_UPDATE_TOKEN: &str = "/connectrpc.v1.snaptun/update_token";
pub(crate) const AUTH_HEADER: &str = "Authorization";
pub const IPV4_WILDCARD: IpNet = IpNet::V4(Ipv4Net::new_assert(Ipv4Addr::UNSPECIFIED, 32));
pub const IPV6_WILDCARD: IpNet = IpNet::V6(Ipv6Net::new_assert(Ipv6Addr::UNSPECIFIED, 128));
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct AddressAllocationId {
pub registry_id: u64,
pub alloc_id: String,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct AddressAllocation {
pub id: AddressAllocationId,
pub address: EndhostAddr,
}
pub trait AddressAllocator<Token>: Send + Sync {
fn allocate(
&self,
isd_as: IsdAsn,
prefix: IpNet,
claims: Token,
) -> Result<AddressAllocation, AddressAllocationError>;
fn put_on_hold(&self, id: AddressAllocationId) -> bool;
fn deallocate(&self, id: AddressAllocationId) -> bool;
}
#[derive(Debug, thiserror::Error)]
pub enum AddressAllocationError {
#[error("no address registry for ISD-AS {0}")]
NoAddressManagerForIsdAs(IsdAsn),
#[error("address {0} already registered")]
AddressAlreadyRegistered(EndhostAddr),
#[error("address {0} not in allocation range")]
AddressNotInAllocationRange(IpAddr),
#[error("address {0} not in allocation ISD-AS {1}")]
IaNotInAllocationRange(IsdAsn, IsdAsn),
#[error("no addresses available")]
NoAddressesAvailable,
#[error("prefix allocation rejected")]
AddressAllocationRejected,
}