mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-14 16:33:44 +02:00
Merge pull request #5 from zerotier/cleanups
various cleanups to get the full project closer to compiling
This commit is contained in:
commit
bf297632fb
16 changed files with 71 additions and 30 deletions
2
Makefile
2
Makefile
|
@ -1,7 +1,7 @@
|
|||
all:
|
||||
|
||||
clean: FORCE
|
||||
rm -rf zerotier-core-crypto/target zerotier-network-hypervisor/target zerotier-system-service/target syncwhole/target aes-gmac-siv/target iblt/target
|
||||
for i in */Cargo.toml; do cd $$(dirname $$i); cargo clean || exit 1; cd ..; done
|
||||
|
||||
test:
|
||||
for i in */Cargo.toml; do cd $$(dirname $$i); cargo test || exit 1; cd ..; done
|
||||
|
|
|
@ -19,6 +19,8 @@ dashmap = "^4"
|
|||
parking_lot = "^0"
|
||||
lazy_static = "^1"
|
||||
highway = "^0"
|
||||
serde = "^1"
|
||||
serde_json = "^1"
|
||||
|
||||
[target."cfg(not(windows))".dependencies]
|
||||
libc = "^0"
|
||||
|
|
|
@ -10,12 +10,14 @@ use std::hash::{Hash, Hasher};
|
|||
use std::num::NonZeroU64;
|
||||
use std::str::FromStr;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::error::InvalidFormatError;
|
||||
use crate::util::buffer::Buffer;
|
||||
use crate::util::hex::HEX_CHARS;
|
||||
use crate::vl1::protocol::{ADDRESS_RESERVED_PREFIX, ADDRESS_SIZE};
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
|
||||
#[repr(transparent)]
|
||||
pub struct Address(NonZeroU64);
|
||||
|
||||
|
|
|
@ -17,6 +17,8 @@ use std::str::FromStr;
|
|||
|
||||
use lazy_static::lazy_static;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use zerotier_core_crypto::c25519::*;
|
||||
use zerotier_core_crypto::hash::{hmac_sha512, SHA384, SHA384_HASH_SIZE, SHA512, SHA512_HASH_SIZE};
|
||||
use zerotier_core_crypto::hex;
|
||||
|
@ -74,6 +76,9 @@ pub struct Identity {
|
|||
pub fingerprint: [u8; SHA512_HASH_SIZE],
|
||||
}
|
||||
|
||||
#[derive(Eq, PartialEq, Clone, Debug, Ord, PartialOrd, Deserialize, Serialize)]
|
||||
pub struct NetworkId(pub u64);
|
||||
|
||||
#[inline(always)]
|
||||
fn concat_arrays_2<const A: usize, const B: usize, const S: usize>(a: &[u8; A], b: &[u8; B]) -> [u8; S] {
|
||||
assert_eq!(A + B, S);
|
||||
|
|
|
@ -21,6 +21,7 @@ pub(crate) mod peer;
|
|||
#[allow(unused)]
|
||||
pub(crate) mod protocol;
|
||||
pub(crate) mod symmetricsecret;
|
||||
pub(crate) mod system_interface;
|
||||
pub(crate) mod whoisqueue;
|
||||
|
||||
pub use address::Address;
|
||||
|
@ -32,5 +33,6 @@ pub use mac::MAC;
|
|||
pub use node::{Node, SystemInterface};
|
||||
pub use path::Path;
|
||||
pub use peer::Peer;
|
||||
pub use system_interface::VL1SystemInterface;
|
||||
|
||||
pub use protocol::{PACKET_FRAGMENT_COUNT_MAX, PACKET_SIZE_MAX};
|
||||
|
|
17
zerotier-network-hypervisor/src/vl1/system_interface.rs
Normal file
17
zerotier-network-hypervisor/src/vl1/system_interface.rs
Normal file
|
@ -0,0 +1,17 @@
|
|||
use super::{Endpoint, Identity};
|
||||
use std::num::NonZeroI64;
|
||||
|
||||
pub trait VL1SystemInterface {
|
||||
fn event_node_is_up(&self);
|
||||
fn event_node_is_down(&self);
|
||||
fn event_identity_collision(&self);
|
||||
fn event_online_status_change(&self, online: bool);
|
||||
fn event_user_message(&self, source: &Identity, message_type: u64, message: &[u8]);
|
||||
fn load_node_identity(&self) -> Option<Vec<u8>>;
|
||||
fn save_node_identity(&self, _: &Identity, public: &[u8], secret: &[u8]);
|
||||
fn wire_send(&self, endpoint: &Endpoint, local_socket: Option<NonZeroI64>, local_interface: Option<NonZeroI64>, data: &[&[u8]], packet_ttl: u8) -> bool;
|
||||
fn check_path(&self, id: &Identity, endpoint: &Endpoint, local_socket: Option<NonZeroI64>, local_interface: Option<NonZeroI64>) -> bool;
|
||||
fn get_path_hints(&self, id: &Identity) -> Option<&[(&Endpoint, Option<NonZeroI64>, Option<NonZeroI64>)]>;
|
||||
fn time_ticks(&self) -> i64;
|
||||
fn time_clock(&self) -> i64;
|
||||
}
|
4
zerotier-system-service/Cargo.lock
generated
4
zerotier-system-service/Cargo.lock
generated
|
@ -2179,6 +2179,8 @@ dependencies = [
|
|||
"libc",
|
||||
"lz4_flex",
|
||||
"parking_lot",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"winapi",
|
||||
"zerotier-core-crypto",
|
||||
]
|
||||
|
@ -2191,11 +2193,13 @@ dependencies = [
|
|||
"clap",
|
||||
"colored",
|
||||
"digest_auth",
|
||||
"hex",
|
||||
"libc",
|
||||
"mach",
|
||||
"num-traits",
|
||||
"num_cpus",
|
||||
"parking_lot",
|
||||
"rand 0.7.3",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"smol",
|
||||
|
|
|
@ -25,6 +25,8 @@ smol = "^1"
|
|||
tide = { version = "^0", features = ["h1-server"], default-features = false }
|
||||
digest_auth = "^0"
|
||||
chrono = "^0"
|
||||
hex = "^0"
|
||||
rand = "^0"
|
||||
|
||||
[target."cfg(windows)".dependencies]
|
||||
winapi = { version = "^0", features = ["handleapi", "ws2ipdef", "ws2tcpip"] }
|
||||
|
|
|
@ -21,8 +21,8 @@ use std::sync::Arc;
|
|||
|
||||
use num_traits::cast::AsPrimitive;
|
||||
|
||||
use crate::debug;
|
||||
use zerotier_network_hypervisor::vl1::InetAddress;
|
||||
//use crate::debug;
|
||||
use zerotier_network_hypervisor::vl1::{InetAddress, InetAddressFamily};
|
||||
use zerotier_network_hypervisor::{PacketBuffer, PacketBufferPool};
|
||||
|
||||
const FAST_UDP_SOCKET_MAX_THREADS: usize = 4;
|
||||
|
@ -224,7 +224,7 @@ impl FastUDPSocket {
|
|||
let packet_buffer_pool_copy = packet_buffer_pool.clone();
|
||||
s.threads.push(
|
||||
std::thread::Builder::new()
|
||||
.stack_size(zerotier_core::RECOMMENDED_THREAD_STACK_SIZE)
|
||||
//.stack_size(zerotier_core::RECOMMENDED_THREAD_STACK_SIZE)
|
||||
.spawn(move || {
|
||||
let mut from_address = InetAddress::new();
|
||||
while thread_run.load(Ordering::Relaxed) {
|
||||
|
@ -255,7 +255,7 @@ impl FastUDPSocket {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn send(&self, to_address: &InetAddress, data: &[u8], packet_ttl: i32) {
|
||||
pub fn send(&self, to_address: &InetAddress, data: &[&[u8]], packet_ttl: u8) {
|
||||
debug_assert!(!self.sockets.is_empty());
|
||||
fast_udp_socket_sendto(unsafe { self.sockets.get_unchecked(0) }, to_address, data, packet_ttl);
|
||||
}
|
||||
|
@ -279,7 +279,7 @@ impl Drop for FastUDPSocket {
|
|||
self.thread_run.store(false, Ordering::Relaxed);
|
||||
for s in self.sockets.iter() {
|
||||
unsafe {
|
||||
libc::sendto(s.get().as_(), tmp.as_ptr().cast(), 0, 0, (&self.bind_address as *const InetAddress).cast(), std::mem::size_of::<InetAddress>() as osdep::socklen_t);
|
||||
libc::sendto(s.get().as_(), tmp.as_ptr().cast(), 0, 0, (&self.bind_address as *const InetAddress).cast(), std::mem::size_of::<InetAddress>() as libc::socklen_t);
|
||||
}
|
||||
}
|
||||
for s in self.sockets.iter() {
|
||||
|
@ -308,7 +308,7 @@ mod tests {
|
|||
#[test]
|
||||
fn test_udp_bind_and_transfer() {
|
||||
{
|
||||
let pool = Arc::new(PacketBufferPool::new(64, PacketBufferFactory));
|
||||
let pool = Arc::new(PacketBufferPool::new(64, PacketBufferFactory::new()));
|
||||
|
||||
let ba0 = InetAddress::new_from_string("127.0.0.1/23333");
|
||||
assert!(ba0.is_some());
|
||||
|
@ -334,8 +334,8 @@ mod tests {
|
|||
|
||||
let data_bytes = [0_u8; 1024];
|
||||
loop {
|
||||
s0.send(&ba1, &data_bytes, 0);
|
||||
s1.send(&ba0, &data_bytes, 0);
|
||||
s0.send(&ba1, &[&data_bytes], 0);
|
||||
s1.send(&ba0, &[&data_bytes], 0);
|
||||
if cnt0.load(Ordering::Relaxed) > 10000 && cnt1.load(Ordering::Relaxed) > 10000 {
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ use std::collections::BTreeMap;
|
|||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use zerotier_network_hypervisor::vl1::identity::NetworkId;
|
||||
use zerotier_network_hypervisor::vl1::{Address, InetAddress};
|
||||
|
||||
pub const UNASSIGNED_PRIVILEGED_PORTS: [u16; 299] = [
|
||||
|
@ -21,6 +22,8 @@ pub const UNASSIGNED_PRIVILEGED_PORTS: [u16; 299] = [
|
|||
1009, 1023,
|
||||
];
|
||||
|
||||
pub const DEFAULT_PORT: u16 = 9993;
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq)]
|
||||
#[serde(default)]
|
||||
pub struct LocalConfigPhysicalPathConfig {
|
||||
|
@ -129,7 +132,7 @@ impl Default for LocalConfigSettings {
|
|||
}
|
||||
|
||||
LocalConfigSettings {
|
||||
primary_port: zerotier_core::DEFAULT_PORT,
|
||||
primary_port: DEFAULT_PORT,
|
||||
port_mapping: true,
|
||||
log: LocalConfigLogSettings::default(),
|
||||
interface_prefix_blacklist: bl,
|
||||
|
|
|
@ -64,7 +64,7 @@ impl Log {
|
|||
|
||||
fn log_internal(&mut self, pfx: &str, s: &str) {
|
||||
if !s.is_empty() {
|
||||
let log_line = format!("{}[{}] {}{}\n", l.prefix.as_str(), chrono::Local::now().format("%Y-%m-%d %H:%M:%S").to_string(), pfx, s);
|
||||
let log_line = format!("{}[{}] {}{}\n", self.prefix.as_str(), chrono::Local::now().format("%Y-%m-%d %H:%M:%S").to_string(), pfx, s);
|
||||
if !self.path.is_empty() {
|
||||
if self.file.is_none() {
|
||||
let f = OpenOptions::new().read(true).write(true).create(true).open(self.path.as_str());
|
||||
|
|
|
@ -19,7 +19,7 @@ use zerotier_network_hypervisor::{Interface, NetworkHypervisor};
|
|||
|
||||
use crate::localconfig::LocalConfig;
|
||||
use crate::log::Log;
|
||||
use crate::store::{platform_default_home_path, StateObjectType, Store};
|
||||
use crate::store::{StateObjectType, Store};
|
||||
use crate::utils::{ms_monotonic, ms_since_epoch};
|
||||
use crate::GlobalCommandLineFlags;
|
||||
|
||||
|
@ -105,7 +105,7 @@ impl VL1SystemInterface for ServiceInterface {
|
|||
|
||||
impl SwitchInterface for ServiceInterface {}
|
||||
|
||||
impl Interface for ServiceInterface {}
|
||||
//impl Interface for ServiceInterface {}
|
||||
|
||||
pub fn run(global_cli_flags: &GlobalCommandLineFlags) -> i32 {
|
||||
let store = Store::new(global_cli_flags.base_path.as_str(), &global_cli_flags.auth_token_path_override, &global_cli_flags.auth_token_override);
|
||||
|
|
|
@ -12,10 +12,10 @@ use std::path::{Path, PathBuf};
|
|||
use std::str::FromStr;
|
||||
use std::sync::Mutex;
|
||||
|
||||
use zerotier_core::{NetworkId, StateObjectType};
|
||||
|
||||
use crate::localconfig::LocalConfig;
|
||||
|
||||
use zerotier_network_hypervisor::vl1::identity::NetworkId;
|
||||
|
||||
const ZEROTIER_PID: &'static str = "zerotier.pid";
|
||||
const ZEROTIER_URI: &'static str = "zerotier.uri";
|
||||
const LOCAL_CONF: &'static str = "local.conf";
|
||||
|
@ -128,7 +128,7 @@ impl Store {
|
|||
if token2.is_empty() {
|
||||
if generate_if_missing {
|
||||
let mut rb = [0_u8; 32];
|
||||
unsafe { crate::osdep::getSecureRandom(rb.as_mut_ptr().cast(), 64) };
|
||||
unsafe { rb.fill_with(rand::random) };
|
||||
token.reserve(rb.len());
|
||||
for b in rb.iter() {
|
||||
if *b > 127_u8 {
|
||||
|
@ -234,7 +234,7 @@ impl Store {
|
|||
}
|
||||
|
||||
pub fn write_pid(&self) -> std::io::Result<()> {
|
||||
let pid = unsafe { crate::osdep::getpid() }.to_string();
|
||||
let pid = unsafe { libc::getpid() }.to_string();
|
||||
self.write_file(ZEROTIER_PID, pid.as_bytes())
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ use std::fs::File;
|
|||
use std::io::Read;
|
||||
use std::path::Path;
|
||||
use std::str::FromStr;
|
||||
use std::time::UNIX_EPOCH;
|
||||
|
||||
use serde::de::DeserializeOwned;
|
||||
use serde::Serialize;
|
||||
|
@ -18,10 +19,10 @@ use serde::Serialize;
|
|||
use zerotier_core_crypto::hex;
|
||||
use zerotier_network_hypervisor::vl1::Identity;
|
||||
|
||||
use crate::osdep;
|
||||
//use crate::osdep;
|
||||
|
||||
pub fn ms_since_epoch() -> i64 {
|
||||
std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_millis() as i64
|
||||
std::time::SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_millis() as i64
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "macos", target_os = "ios"))]
|
||||
|
@ -39,7 +40,9 @@ pub fn ms_monotonic() -> i64 {
|
|||
}
|
||||
|
||||
#[cfg(not(any(target_os = "macos", target_os = "ios")))]
|
||||
pub fn ms_monotonic() -> i64 {}
|
||||
pub fn ms_monotonic() -> i64 {
|
||||
std::time::SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_millis() as i64
|
||||
}
|
||||
|
||||
pub fn parse_bool(v: &str) -> Result<bool, String> {
|
||||
if !v.is_empty() {
|
||||
|
@ -104,20 +107,20 @@ pub fn parse_cli_identity(input: &str, validate: bool) -> Result<Identity, Strin
|
|||
pub fn create_http_auth_nonce(timestamp: i64) -> String {
|
||||
let mut nonce_plaintext: [u64; 2] = [timestamp as u64, timestamp as u64];
|
||||
unsafe {
|
||||
osdep::encryptHttpAuthNonce(nonce_plaintext.as_mut_ptr().cast());
|
||||
hex::encode(*nonce_plaintext.as_ptr().cast::<[u8; 16]>())
|
||||
//osdep::encryptHttpAuthNonce(nonce_plaintext.as_mut_ptr().cast());
|
||||
hex::to_string(&nonce_plaintext.as_ptr().cast::<[u8]>())
|
||||
}
|
||||
}
|
||||
|
||||
/// Decrypt HTTP auth nonce encrypted by this process and return the timestamp.
|
||||
/// This returns zero if the input was not valid.
|
||||
pub fn decrypt_http_auth_nonce(nonce: &str) -> i64 {
|
||||
let nonce = hex::decode(nonce.trim());
|
||||
let nonce = hex::from_string(nonce.trim());
|
||||
if !nonce.is_err() {
|
||||
let mut nonce = nonce.unwrap();
|
||||
if nonce.len() == 16 {
|
||||
unsafe {
|
||||
osdep::decryptHttpAuthNonce(nonce.as_mut_ptr().cast());
|
||||
//osdep::decryptHttpAuthNonce(nonce.as_mut_ptr().cast());
|
||||
let nonce = *nonce.as_ptr().cast::<[u64; 2]>();
|
||||
if nonce[0] == nonce[1] {
|
||||
return nonce[0] as i64;
|
||||
|
|
|
@ -59,6 +59,6 @@ pub fn get_l2_multicast_subscriptions(dev: &str) -> HashSet<MAC> {
|
|||
/// Linux stores this stuff in /proc and it needs to be fetched from there.
|
||||
#[cfg(target_os = "linux")]
|
||||
pub fn get_l2_multicast_subscriptions(dev: &str) -> HashSet<MAC> {
|
||||
let mut groups: HashSet<MulticastGroup> = HashSet::new();
|
||||
let mut groups: HashSet<MAC> = HashSet::new();
|
||||
groups
|
||||
}
|
||||
|
|
|
@ -6,19 +6,20 @@
|
|||
* https://www.zerotier.com/
|
||||
*/
|
||||
|
||||
use zerotier_network_hypervisor::vl1::{InetAddress, MAC};
|
||||
use zerotier_network_hypervisor::vl2::MulticastGroup;
|
||||
|
||||
/// Virtual network interface
|
||||
pub trait VNIC {
|
||||
/// Add a new IPv4 or IPv6 address to this interface, returning true on success.
|
||||
fn add_ip(&self, ip: &zerotier_core::InetAddress) -> bool;
|
||||
fn add_ip(&self, ip: &InetAddress) -> bool;
|
||||
|
||||
/// Remove an IPv4 or IPv6 address, returning true on success.
|
||||
/// Nothing happens if the address is not found.
|
||||
fn remove_ip(&self, ip: &zerotier_core::InetAddress) -> bool;
|
||||
fn remove_ip(&self, ip: &InetAddress) -> bool;
|
||||
|
||||
/// Enumerate all IPs on this interface including ones assigned outside ZeroTier.
|
||||
fn ips(&self) -> Vec<zerotier_core::InetAddress>;
|
||||
fn ips(&self) -> Vec<InetAddress>;
|
||||
|
||||
/// Get the OS-specific device name for this interface, e.g. zt## or tap##.
|
||||
fn device_name(&self) -> String;
|
||||
|
@ -30,5 +31,5 @@ pub trait VNIC {
|
|||
fn get_multicast_groups(&self) -> std::collections::BTreeSet<MulticastGroup>;
|
||||
|
||||
/// Inject an Ethernet frame into this port.
|
||||
fn put(&self, source_mac: &zerotier_core::MAC, dest_mac: &zerotier_core::MAC, ethertype: u16, vlan_id: u16, data: *const u8, len: usize) -> bool;
|
||||
fn put(&self, source_mac: &MAC, dest_mac: &MAC, ethertype: u16, vlan_id: u16, data: *const u8, len: usize) -> bool;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue