mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-10 06:23:44 +02:00
commit
14b6dbb5d6
6 changed files with 45 additions and 26 deletions
|
@ -43,11 +43,13 @@ impl<const FREQ: i64> Default for AtomicIntervalGate<FREQ> {
|
|||
|
||||
impl<const FREQ: i64> AtomicIntervalGate<FREQ> {
|
||||
#[inline(always)]
|
||||
#[allow(unused)]
|
||||
pub fn new(initial_ts: i64) -> Self {
|
||||
Self(AtomicI64::new(initial_ts))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[allow(unused)]
|
||||
pub fn gate(&self, mut time: i64) -> bool {
|
||||
let prev_time = self.0.load(Ordering::Acquire);
|
||||
if (time - prev_time) < FREQ {
|
||||
|
|
|
@ -37,11 +37,14 @@ type sockaddr_storage = libc::sockaddr_storage;
|
|||
#[cfg(not(windows))]
|
||||
type in6_addr = libc::in6_addr;
|
||||
|
||||
#[cfg(not(windows))]
|
||||
pub const AF_INET: u8 = libc::AF_INET as u8;
|
||||
#[cfg(all(not(target_os = "windows"), not(target_os = "linux")))]
|
||||
type INetType = u8;
|
||||
|
||||
#[cfg(not(windows))]
|
||||
pub const AF_INET6: u8 = libc::AF_INET6 as u8;
|
||||
#[cfg(target_os = "linux")]
|
||||
type InetType = u16;
|
||||
|
||||
pub const AF_INET: InetType = libc::AF_INET as InetType;
|
||||
pub const AF_INET6: InetType = libc::AF_INET6 as InetType;
|
||||
|
||||
#[repr(u8)]
|
||||
pub enum IpScope {
|
||||
|
@ -391,9 +394,6 @@ impl<'de> Deserialize<'de> for InetAddress {
|
|||
}
|
||||
|
||||
impl InetAddress {
|
||||
pub const AF_INET: u8 = AF_INET;
|
||||
pub const AF_INET6: u8 = AF_INET6;
|
||||
|
||||
/// Get a new zero/nil InetAddress.
|
||||
#[inline(always)]
|
||||
pub fn new() -> InetAddress {
|
||||
|
@ -460,13 +460,13 @@ impl InetAddress {
|
|||
/// Check if this is an IPv4 address.
|
||||
#[inline(always)]
|
||||
pub fn is_ipv4(&self) -> bool {
|
||||
unsafe { self.sa.sa_family as u8 == AF_INET }
|
||||
unsafe { self.sa.sa_family == AF_INET }
|
||||
}
|
||||
|
||||
/// Check if this is an IPv6 address.
|
||||
#[inline(always)]
|
||||
pub fn is_ipv6(&self) -> bool {
|
||||
unsafe { self.sa.sa_family as u8 == AF_INET6 }
|
||||
unsafe { self.sa.sa_family == AF_INET6 }
|
||||
}
|
||||
|
||||
/// Check if this is either an IPv4 or an IPv6 address.
|
||||
|
@ -488,7 +488,7 @@ impl InetAddress {
|
|||
#[inline(always)]
|
||||
pub fn c_sockaddr(&self) -> (*const (), usize) {
|
||||
unsafe {
|
||||
match self.sa.sa_family as u8 {
|
||||
match self.sa.sa_family {
|
||||
AF_INET => ((&self.sin as *const sockaddr_in).cast(), size_of::<sockaddr_in>()),
|
||||
AF_INET6 => ((&self.sin6 as *const sockaddr_in6).cast(), size_of::<sockaddr_in6>()),
|
||||
_ => (null(), 0),
|
||||
|
@ -500,7 +500,7 @@ impl InetAddress {
|
|||
/// Whether this is IPv4 or IPv6 is inferred from the size of ip[], which must be
|
||||
/// either 4 or 16 bytes. The family (AF_INET or AF_INET6) is returned, or zero on
|
||||
/// failure.
|
||||
pub fn set(&mut self, ip: &[u8], port: u16) -> u8 {
|
||||
pub fn set(&mut self, ip: &[u8], port: u16) -> InetType {
|
||||
self.zero();
|
||||
let port = port.to_be();
|
||||
unsafe {
|
||||
|
@ -523,7 +523,7 @@ impl InetAddress {
|
|||
/// Get raw IP bytes, with length dependent on address family (4 or 16).
|
||||
pub fn ip_bytes(&self) -> &[u8] {
|
||||
unsafe {
|
||||
match self.sa.sa_family as u8 {
|
||||
match self.sa.sa_family as InetType {
|
||||
AF_INET => &*(&self.sin.sin_addr.s_addr as *const u32).cast::<[u8; 4]>(),
|
||||
AF_INET6 => &*(&self.sin6.sin6_addr as *const in6_addr).cast::<[u8; 16]>(),
|
||||
_ => &[],
|
||||
|
@ -545,7 +545,7 @@ impl InetAddress {
|
|||
/// Get the IP port for this InetAddress.
|
||||
pub fn port(&self) -> u16 {
|
||||
unsafe {
|
||||
u16::from_be(match self.sa.sa_family as u8 {
|
||||
u16::from_be(match self.sa.sa_family as InetType {
|
||||
AF_INET => self.sin.sin_port as u16,
|
||||
AF_INET6 => self.sin6.sin6_port as u16,
|
||||
_ => 0,
|
||||
|
@ -560,7 +560,7 @@ impl InetAddress {
|
|||
pub fn set_port(&mut self, port: u16) {
|
||||
let port = port.to_be();
|
||||
unsafe {
|
||||
match self.sa.sa_family as u8 {
|
||||
match self.sa.sa_family as InetType {
|
||||
AF_INET => self.sin.sin_port = port,
|
||||
AF_INET6 => self.sin6.sin6_port = port,
|
||||
_ => {}
|
||||
|
@ -575,7 +575,7 @@ impl InetAddress {
|
|||
unsafe {
|
||||
if self.sa.sa_family == cidr.sa.sa_family {
|
||||
let mut cidr_bits = cidr.port() as u32;
|
||||
match self.sa.sa_family as u8 {
|
||||
match self.sa.sa_family as InetType {
|
||||
AF_INET => {
|
||||
if cidr_bits <= 32 {
|
||||
let discard_bits = 32 - cidr_bits;
|
||||
|
@ -612,7 +612,7 @@ impl InetAddress {
|
|||
/// Get this IP address's scope as per RFC documents and what is advertised via BGP.
|
||||
pub fn scope(&self) -> IpScope {
|
||||
unsafe {
|
||||
match self.sa.sa_family as u8 {
|
||||
match self.sa.sa_family as InetType {
|
||||
AF_INET => {
|
||||
let ip = self.sin.sin_addr.s_addr as u32;
|
||||
let class_a = (ip >> 24) as u8;
|
||||
|
@ -737,7 +737,7 @@ impl InetAddress {
|
|||
/// Get only the IP portion of this address as a string.
|
||||
pub fn to_ip_string(&self) -> String {
|
||||
unsafe {
|
||||
match self.sa.sa_family as u8 {
|
||||
match self.sa.sa_family as InetType {
|
||||
AF_INET => {
|
||||
let ip = &*(&self.sin.sin_addr.s_addr as *const u32).cast::<[u8; 4]>();
|
||||
format!("{}.{}.{}.{}", ip[0], ip[1], ip[2], ip[3])
|
||||
|
@ -754,7 +754,7 @@ impl Marshalable for InetAddress {
|
|||
|
||||
fn marshal<const BL: usize>(&self, buf: &mut Buffer<BL>) -> std::io::Result<()> {
|
||||
unsafe {
|
||||
match self.sa.sa_family as u8 {
|
||||
match self.sa.sa_family as InetType {
|
||||
AF_INET => {
|
||||
let b = buf.append_bytes_fixed_get_mut::<7>()?;
|
||||
b[0] = 4;
|
||||
|
@ -794,7 +794,7 @@ impl ToString for InetAddress {
|
|||
fn to_string(&self) -> String {
|
||||
unsafe {
|
||||
let mut s = self.to_ip_string();
|
||||
match self.sa.sa_family as u8 {
|
||||
match self.sa.sa_family as InetType {
|
||||
AF_INET => {
|
||||
s.push('/');
|
||||
s.push_str(u16::from_be(self.sin.sin_port as u16).to_string().as_str())
|
||||
|
@ -858,7 +858,7 @@ impl PartialEq for InetAddress {
|
|||
fn eq(&self, other: &Self) -> bool {
|
||||
unsafe {
|
||||
if self.sa.sa_family == other.sa.sa_family {
|
||||
match self.sa.sa_family as u8 {
|
||||
match self.sa.sa_family as InetType {
|
||||
AF_INET => self.sin.sin_port == other.sin.sin_port && self.sin.sin_addr.s_addr == other.sin.sin_addr.s_addr,
|
||||
AF_INET6 => {
|
||||
if self.sin6.sin6_port == other.sin6.sin6_port {
|
||||
|
@ -891,7 +891,7 @@ impl Ord for InetAddress {
|
|||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
unsafe {
|
||||
if self.sa.sa_family == other.sa.sa_family {
|
||||
match self.sa.sa_family as u8 {
|
||||
match self.sa.sa_family as InetType {
|
||||
0 => Ordering::Equal,
|
||||
AF_INET => {
|
||||
let ip_ordering = u32::from_be(self.sin.sin_addr.s_addr as u32).cmp(&u32::from_be(other.sin.sin_addr.s_addr as u32));
|
||||
|
@ -917,17 +917,17 @@ impl Ord for InetAddress {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
match self.sa.sa_family as u8 {
|
||||
match self.sa.sa_family as InetType {
|
||||
0 => Ordering::Less,
|
||||
AF_INET => {
|
||||
if other.sa.sa_family as u8 == AF_INET6 {
|
||||
if other.sa.sa_family as InetType == AF_INET6 {
|
||||
Ordering::Less
|
||||
} else {
|
||||
self.sa.sa_family.cmp(&other.sa.sa_family)
|
||||
}
|
||||
}
|
||||
AF_INET6 => {
|
||||
if other.sa.sa_family as u8 == AF_INET {
|
||||
if other.sa.sa_family as InetType == AF_INET {
|
||||
Ordering::Greater
|
||||
} else {
|
||||
self.sa.sa_family.cmp(&other.sa.sa_family)
|
||||
|
@ -947,7 +947,8 @@ impl Hash for InetAddress {
|
|||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
unsafe {
|
||||
state.write_u8(self.sa.sa_family as u8);
|
||||
match self.sa.sa_family as u8 {
|
||||
|
||||
match self.sa.sa_family as InetType {
|
||||
AF_INET => {
|
||||
state.write_u16(self.sin.sin_port as u16);
|
||||
state.write_u32(self.sin.sin_addr.s_addr as u32);
|
||||
|
|
|
@ -381,6 +381,7 @@ impl<SI: SystemInterface> Peer<SI> {
|
|||
///
|
||||
/// This will go directly if there is an active path, or otherwise indirectly
|
||||
/// via a root or some other route.
|
||||
#[allow(unused)]
|
||||
pub(crate) async fn send(&self, si: &SI, node: &Node<SI>, time_ticks: i64, packet: &PacketBuffer) -> bool {
|
||||
if let Some(path) = self.path(node) {
|
||||
if self.internal_send(si, &path.endpoint, Some(&path.local_socket), Some(&path.local_interface), if path.endpoint.requires_fragmentation() { UDP_DEFAULT_MTU } else { usize::MAX }, packet).await {
|
||||
|
@ -529,8 +530,10 @@ impl<SI: SystemInterface> Peer<SI> {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
async fn handle_incoming_hello(&self, si: &SI, node: &Node<SI>, time_ticks: i64, source_path: &Arc<Path<SI>>, payload: &PacketBuffer) {}
|
||||
|
||||
#[allow(unused)]
|
||||
async fn handle_incoming_error<PH: InnerProtocolInterface>(&self, si: &SI, ph: &PH, node: &Node<SI>, time_ticks: i64, source_path: &Arc<Path<SI>>, forward_secrecy: bool, extended_authentication: bool, payload: &PacketBuffer) {
|
||||
let mut cursor: usize = 1;
|
||||
if let Ok(error_header) = payload.read_struct::<message_component_structs::ErrorHeader>(&mut cursor) {
|
||||
|
@ -546,7 +549,8 @@ impl<SI: SystemInterface> Peer<SI> {
|
|||
}
|
||||
}
|
||||
|
||||
async fn handle_incoming_ok<PH: InnerProtocolInterface>(&self, si: &SI, ph: &PH, node: &Node<SI>, time_ticks: i64, source_path: &Arc<Path<SI>>, mut path_is_known: bool, forward_secrecy: bool, extended_authentication: bool, payload: &PacketBuffer) {
|
||||
#[allow(unused)]
|
||||
async fn handle_incoming_ok<PH: InnerProtocolInterface>(&self, si: &SI, ph: &PH, node: &Node<SI>, time_ticks: i64, source_path: &Arc<Path<SI>>, path_is_known: bool, forward_secrecy: bool, extended_authentication: bool, payload: &PacketBuffer) {
|
||||
let mut cursor: usize = 1;
|
||||
if let Ok(ok_header) = payload.read_struct::<message_component_structs::OkHeader>(&mut cursor) {
|
||||
let in_re_message_id = u64::from_ne_bytes(ok_header.in_re_message_id);
|
||||
|
@ -603,14 +607,19 @@ impl<SI: SystemInterface> Peer<SI> {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
async fn handle_incoming_whois(&self, si: &SI, node: &Node<SI>, time_ticks: i64, source_path: &Arc<Path<SI>>, payload: &PacketBuffer) {}
|
||||
|
||||
#[allow(unused)]
|
||||
async fn handle_incoming_rendezvous(&self, si: &SI, node: &Node<SI>, time_ticks: i64, source_path: &Arc<Path<SI>>, payload: &PacketBuffer) {}
|
||||
|
||||
#[allow(unused)]
|
||||
async fn handle_incoming_echo(&self, si: &SI, node: &Node<SI>, time_ticks: i64, source_path: &Arc<Path<SI>>, payload: &PacketBuffer) {}
|
||||
|
||||
#[allow(unused)]
|
||||
async fn handle_incoming_push_direct_paths(&self, si: &SI, node: &Node<SI>, time_ticks: i64, source_path: &Arc<Path<SI>>, payload: &PacketBuffer) {}
|
||||
|
||||
#[allow(unused)]
|
||||
async fn handle_incoming_user_message(&self, si: &SI, node: &Node<SI>, time_ticks: i64, source_path: &Arc<Path<SI>>, payload: &PacketBuffer) {}
|
||||
}
|
||||
|
||||
|
|
|
@ -45,6 +45,7 @@ impl SymmetricSecret {
|
|||
/// An ephemeral symmetric secret with usage timers and counters.
|
||||
pub(crate) struct EphemeralSymmetricSecret {
|
||||
pub secret: SymmetricSecret,
|
||||
#[allow(unused)]
|
||||
pub encrypt_uses: AtomicUsize,
|
||||
}
|
||||
|
||||
|
|
|
@ -53,11 +53,13 @@ impl WhoisQueue {
|
|||
}
|
||||
|
||||
/// Remove a WHOIS request from the queue and call the supplied function for all queued packets.
|
||||
#[allow(unused)]
|
||||
pub fn response_received_get_packets<F: FnMut(&mut QueuedPacket)>(&self, address: Address, packet_handler: F) {
|
||||
let mut qi = self.0.lock().remove(&address);
|
||||
let _ = qi.map(|mut qi| qi.packet_queue.iter_mut().for_each(packet_handler));
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
fn send_whois<SI: SystemInterface>(&self, node: &Node<SI>, si: &SI, targets: &[Address]) {
|
||||
todo!()
|
||||
}
|
||||
|
|
|
@ -12,10 +12,12 @@ pub struct Switch {}
|
|||
|
||||
#[async_trait]
|
||||
impl InnerProtocolInterface for Switch {
|
||||
#[allow(unused)]
|
||||
async fn handle_packet<SI: SystemInterface>(&self, peer: &Peer<SI>, source_path: &Path<SI>, forward_secrecy: bool, extended_authentication: bool, verb: u8, payload: &PacketBuffer) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
async fn handle_error<SI: SystemInterface>(
|
||||
&self,
|
||||
peer: &Peer<SI>,
|
||||
|
@ -31,10 +33,12 @@ impl InnerProtocolInterface for Switch {
|
|||
false
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
async fn handle_ok<SI: SystemInterface>(&self, peer: &Peer<SI>, source_path: &Path<SI>, forward_secrecy: bool, extended_authentication: bool, in_re_verb: u8, in_re_message_id: u64, payload: &PacketBuffer, cursor: &mut usize) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
fn has_trust_relationship(&self, id: &Identity) -> bool {
|
||||
true
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue