mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-06 12:33:44 +02:00
Merge vl1-service into service for simplicity and because they are parts of the same thing.
This commit is contained in:
parent
1670a3aa31
commit
b97ed1e97a
21 changed files with 89 additions and 103 deletions
|
@ -5,7 +5,6 @@ members = [
|
||||||
"network-hypervisor",
|
"network-hypervisor",
|
||||||
"controller",
|
"controller",
|
||||||
"service",
|
"service",
|
||||||
"vl1-service",
|
|
||||||
"utils",
|
"utils",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ path = "src/main.rs"
|
||||||
zerotier-crypto = { path = "../crypto" }
|
zerotier-crypto = { path = "../crypto" }
|
||||||
zerotier-utils = { path = "../utils", features = ["tokio"] }
|
zerotier-utils = { path = "../utils", features = ["tokio"] }
|
||||||
zerotier-network-hypervisor = { path = "../network-hypervisor" }
|
zerotier-network-hypervisor = { path = "../network-hypervisor" }
|
||||||
zerotier-vl1-service = { path = "../vl1-service" }
|
zerotier-service = { path = "../service" }
|
||||||
async-trait = "^0"
|
async-trait = "^0"
|
||||||
serde = { version = "^1", features = ["derive"], default-features = false }
|
serde = { version = "^1", features = ["derive"], default-features = false }
|
||||||
serde_json = { version = "^1", features = ["std"], default-features = false }
|
serde_json = { version = "^1", features = ["std"], default-features = false }
|
||||||
|
|
|
@ -5,6 +5,11 @@ authors = ["ZeroTier, Inc. <contact@zerotier.com>", "Adam Ierymenko <adam.ieryme
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "MPL-2.0"
|
license = "MPL-2.0"
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
name = "zerotier_service"
|
||||||
|
path = "src/lib.rs"
|
||||||
|
doc = true
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "zerotier"
|
name = "zerotier"
|
||||||
path = "src/main.rs"
|
path = "src/main.rs"
|
||||||
|
@ -13,10 +18,10 @@ path = "src/main.rs"
|
||||||
zerotier-network-hypervisor = { path = "../network-hypervisor" }
|
zerotier-network-hypervisor = { path = "../network-hypervisor" }
|
||||||
zerotier-crypto = { path = "../crypto" }
|
zerotier-crypto = { path = "../crypto" }
|
||||||
zerotier-utils = { path = "../utils", features = ["tokio"] }
|
zerotier-utils = { path = "../utils", features = ["tokio"] }
|
||||||
zerotier-vl1-service = { path = "../vl1-service" }
|
|
||||||
serde = { version = "^1", features = ["derive"], default-features = false }
|
serde = { version = "^1", features = ["derive"], default-features = false }
|
||||||
serde_json = { version = "^1", features = ["std"], default-features = false }
|
serde_json = { version = "^1", features = ["std"], default-features = false }
|
||||||
clap = { version = "^3", features = ["std", "suggestions"], default-features = false }
|
clap = { version = "^3", features = ["std", "suggestions"], default-features = false }
|
||||||
|
num-traits = "^0"
|
||||||
|
|
||||||
[target."cfg(windows)".dependencies]
|
[target."cfg(windows)".dependencies]
|
||||||
winapi = { version = "^0", features = ["handleapi", "ws2ipdef", "ws2tcpip"] }
|
winapi = { version = "^0", features = ["handleapi", "ws2ipdef", "ws2tcpip"] }
|
||||||
|
|
|
@ -1,3 +1,10 @@
|
||||||
// (c) 2020-2022 ZeroTier, Inc. -- currently proprietary pending actual release and licensing. See LICENSE.md.
|
// (c) 2020-2022 ZeroTier, Inc. -- currently proprietary pending actual release and licensing. See LICENSE.md.
|
||||||
|
|
||||||
pub mod rootset;
|
pub mod rootset;
|
||||||
|
|
||||||
|
pub struct Flags {
|
||||||
|
pub json_output: bool,
|
||||||
|
pub base_path: String,
|
||||||
|
pub auth_token_path_override: Option<String>,
|
||||||
|
pub auth_token_override: Option<String>,
|
||||||
|
}
|
||||||
|
|
|
@ -4,10 +4,11 @@ use std::io::Write;
|
||||||
|
|
||||||
use clap::ArgMatches;
|
use clap::ArgMatches;
|
||||||
|
|
||||||
use crate::{exitcode, Flags};
|
use super::Flags;
|
||||||
|
|
||||||
use zerotier_network_hypervisor::vl1::RootSet;
|
use zerotier_network_hypervisor::vl1::RootSet;
|
||||||
|
|
||||||
|
use zerotier_utils::exitcode;
|
||||||
use zerotier_utils::io::{read_limit, DEFAULT_FILE_IO_READ_LIMIT};
|
use zerotier_utils::io::{read_limit, DEFAULT_FILE_IO_READ_LIMIT};
|
||||||
use zerotier_utils::json::to_json_pretty;
|
use zerotier_utils::json::to_json_pretty;
|
||||||
use zerotier_utils::marshalable::Marshalable;
|
use zerotier_utils::marshalable::Marshalable;
|
||||||
|
|
7
service/src/lib.rs
Normal file
7
service/src/lib.rs
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
pub mod cli;
|
||||||
|
pub mod cmdline_help;
|
||||||
|
pub mod localconfig;
|
||||||
|
pub mod sys;
|
||||||
|
pub mod utils;
|
||||||
|
pub mod vl1;
|
||||||
|
pub mod vnic;
|
|
@ -6,7 +6,8 @@ use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use zerotier_network_hypervisor::vl1::{Address, Endpoint};
|
use zerotier_network_hypervisor::vl1::{Address, Endpoint};
|
||||||
use zerotier_network_hypervisor::vl2::NetworkId;
|
use zerotier_network_hypervisor::vl2::NetworkId;
|
||||||
use zerotier_vl1_service::VL1Settings;
|
|
||||||
|
use crate::vl1::VL1Settings;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq)]
|
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq)]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
|
|
|
@ -1,11 +1,5 @@
|
||||||
// (c) 2020-2022 ZeroTier, Inc. -- currently proprietary pending actual release and licensing. See LICENSE.md.
|
// (c) 2020-2022 ZeroTier, Inc. -- currently proprietary pending actual release and licensing. See LICENSE.md.
|
||||||
|
|
||||||
pub mod cli;
|
|
||||||
pub mod cmdline_help;
|
|
||||||
pub mod localconfig;
|
|
||||||
pub mod utils;
|
|
||||||
pub mod vnic;
|
|
||||||
|
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
@ -18,13 +12,17 @@ use clap::{Arg, ArgMatches, Command};
|
||||||
use zerotier_network_hypervisor::vl1::InnerProtocolLayer;
|
use zerotier_network_hypervisor::vl1::InnerProtocolLayer;
|
||||||
use zerotier_network_hypervisor::{VERSION_MAJOR, VERSION_MINOR, VERSION_REVISION};
|
use zerotier_network_hypervisor::{VERSION_MAJOR, VERSION_MINOR, VERSION_REVISION};
|
||||||
use zerotier_utils::exitcode;
|
use zerotier_utils::exitcode;
|
||||||
use zerotier_vl1_service::datadir::DataDir;
|
|
||||||
use zerotier_vl1_service::VL1Service;
|
|
||||||
|
|
||||||
use crate::localconfig::Config;
|
use zerotier_service::cli;
|
||||||
|
use zerotier_service::cli::Flags;
|
||||||
|
use zerotier_service::cmdline_help;
|
||||||
|
use zerotier_service::localconfig::Config;
|
||||||
|
use zerotier_service::utils;
|
||||||
|
use zerotier_service::vl1::datadir::DataDir;
|
||||||
|
use zerotier_service::vl1::{VL1Service, VL1Settings};
|
||||||
|
|
||||||
pub fn print_help() {
|
pub fn print_help() {
|
||||||
let h = crate::cmdline_help::make_cmdline_help();
|
let h = cmdline_help::make_cmdline_help();
|
||||||
let _ = std::io::stdout().write_all(h.as_bytes());
|
let _ = std::io::stdout().write_all(h.as_bytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,13 +36,6 @@ pub fn platform_default_home_path() -> String {
|
||||||
"/var/lib/zerotier".into()
|
"/var/lib/zerotier".into()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Flags {
|
|
||||||
pub json_output: bool,
|
|
||||||
pub base_path: String,
|
|
||||||
pub auth_token_path_override: Option<String>,
|
|
||||||
pub auth_token_override: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn open_datadir(flags: &Flags) -> Arc<DataDir<Config>> {
|
fn open_datadir(flags: &Flags) -> Arc<DataDir<Config>> {
|
||||||
let datadir = DataDir::open(flags.base_path.as_str());
|
let datadir = DataDir::open(flags.base_path.as_str());
|
||||||
if datadir.is_ok() {
|
if datadir.is_ok() {
|
||||||
|
@ -212,7 +203,7 @@ fn main() {
|
||||||
eprintln!("FATAL: error generator or writing identity: {}", e.to_string());
|
eprintln!("FATAL: error generator or writing identity: {}", e.to_string());
|
||||||
exitcode::ERR_IOERR
|
exitcode::ERR_IOERR
|
||||||
} else {
|
} else {
|
||||||
let svc = VL1Service::new(id.unwrap(), test_inner, zerotier_vl1_service::VL1Settings::default());
|
let svc = VL1Service::new(id.unwrap(), test_inner, VL1Settings::default());
|
||||||
if svc.is_ok() {
|
if svc.is_ok() {
|
||||||
let svc = svc.unwrap();
|
let svc = svc.unwrap();
|
||||||
svc.node.init_default_roots();
|
svc.node.init_default_roots();
|
||||||
|
|
|
@ -5,7 +5,7 @@ use std::ptr::{copy_nonoverlapping, null_mut};
|
||||||
|
|
||||||
use zerotier_network_hypervisor::vl1::InetAddress;
|
use zerotier_network_hypervisor::vl1::InetAddress;
|
||||||
|
|
||||||
use crate::localinterface::LocalInterface;
|
use crate::vl1::LocalInterface;
|
||||||
|
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
|
@ -10,7 +10,7 @@ use std::ptr::{null, null_mut};
|
||||||
use std::sync::atomic::{AtomicBool, AtomicI64, Ordering};
|
use std::sync::atomic::{AtomicBool, AtomicI64, Ordering};
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::{Arc, RwLock};
|
||||||
|
|
||||||
use crate::localinterface::LocalInterface;
|
use crate::vl1::LocalInterface;
|
||||||
|
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
use num_traits::AsPrimitive;
|
use num_traits::AsPrimitive;
|
|
@ -21,6 +21,7 @@ pub const CONFIG_FILENAME: &'static str = "local.conf";
|
||||||
const AUTH_TOKEN_DEFAULT_LENGTH: usize = 48;
|
const AUTH_TOKEN_DEFAULT_LENGTH: usize = 48;
|
||||||
const AUTH_TOKEN_POSSIBLE_CHARS: &'static str = "0123456789abcdefghijklmnopqrstuvwxyz";
|
const AUTH_TOKEN_POSSIBLE_CHARS: &'static str = "0123456789abcdefghijklmnopqrstuvwxyz";
|
||||||
|
|
||||||
|
/// ZeroTier home directory interface
|
||||||
pub struct DataDir<Config: PartialEq + Eq + Clone + Send + Sync + Default + Serialize + DeserializeOwned + 'static> {
|
pub struct DataDir<Config: PartialEq + Eq + Clone + Send + Sync + Default + Serialize + DeserializeOwned + 'static> {
|
||||||
pub base_path: PathBuf,
|
pub base_path: PathBuf,
|
||||||
config: RwLock<Arc<Config>>,
|
config: RwLock<Arc<Config>>,
|
|
@ -5,9 +5,7 @@ mod localsocket;
|
||||||
mod vl1service;
|
mod vl1service;
|
||||||
mod vl1settings;
|
mod vl1settings;
|
||||||
|
|
||||||
pub mod constants;
|
|
||||||
pub mod datadir;
|
pub mod datadir;
|
||||||
pub mod sys;
|
|
||||||
|
|
||||||
pub use localinterface::LocalInterface;
|
pub use localinterface::LocalInterface;
|
||||||
pub use localsocket::LocalSocket;
|
pub use localsocket::LocalSocket;
|
|
@ -12,10 +12,8 @@ use zerotier_network_hypervisor::vl1::identity::IdentitySecret;
|
||||||
use zerotier_network_hypervisor::vl1::*;
|
use zerotier_network_hypervisor::vl1::*;
|
||||||
use zerotier_utils::{ms_monotonic, ms_since_epoch};
|
use zerotier_utils::{ms_monotonic, ms_since_epoch};
|
||||||
|
|
||||||
use crate::constants::UNASSIGNED_PRIVILEGED_PORTS;
|
use super::vl1settings::{VL1Settings, UNASSIGNED_PRIVILEGED_PORTS};
|
||||||
use crate::sys::udp::{udp_test_bind, BoundUdpPort, UdpPacketHandler};
|
use crate::sys::udp::{udp_test_bind, BoundUdpPort, UdpPacketHandler};
|
||||||
use crate::vl1settings::VL1Settings;
|
|
||||||
use crate::LocalSocket;
|
|
||||||
|
|
||||||
/// Update UDP bindings every this many seconds.
|
/// Update UDP bindings every this many seconds.
|
||||||
const UPDATE_UDP_BINDINGS_EVERY_SECS: usize = 10;
|
const UPDATE_UDP_BINDINGS_EVERY_SECS: usize = 10;
|
||||||
|
@ -180,7 +178,7 @@ impl<Inner: InnerProtocolLayer + 'static> UdpPacketHandler for VL1Service<Inner>
|
||||||
self.as_ref(),
|
self.as_ref(),
|
||||||
self.inner.as_ref(),
|
self.inner.as_ref(),
|
||||||
&Endpoint::IpUdp(source_address.clone()),
|
&Endpoint::IpUdp(source_address.clone()),
|
||||||
&LocalSocket::new(socket),
|
&super::localsocket::LocalSocket::new(socket),
|
||||||
&socket.interface,
|
&socket.interface,
|
||||||
time_ticks,
|
time_ticks,
|
||||||
packet,
|
packet,
|
||||||
|
@ -189,8 +187,8 @@ impl<Inner: InnerProtocolLayer + 'static> UdpPacketHandler for VL1Service<Inner>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Inner: InnerProtocolLayer + 'static> ApplicationLayer for VL1Service<Inner> {
|
impl<Inner: InnerProtocolLayer + 'static> ApplicationLayer for VL1Service<Inner> {
|
||||||
type LocalSocket = crate::LocalSocket;
|
type LocalSocket = super::localsocket::LocalSocket;
|
||||||
type LocalInterface = crate::LocalInterface;
|
type LocalInterface = super::localinterface::LocalInterface;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn event(&self, event: Event) {
|
fn event(&self, event: Event) {
|
|
@ -1,5 +1,53 @@
|
||||||
// (c) 2020-2022 ZeroTier, Inc. -- currently proprietary pending actual release and licensing. See LICENSE.md.
|
// (c) 2020-2022 ZeroTier, Inc. -- currently proprietary pending actual release and licensing. See LICENSE.md.
|
||||||
|
|
||||||
|
use std::collections::HashSet;
|
||||||
|
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use zerotier_network_hypervisor::vl1::InetAddress;
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq)]
|
||||||
|
#[serde(default)]
|
||||||
|
pub struct VL1Settings {
|
||||||
|
/// Primary ZeroTier port that is always bound, default is 9993.
|
||||||
|
pub fixed_ports: HashSet<u16>,
|
||||||
|
|
||||||
|
/// Number of additional random ports to bind.
|
||||||
|
pub random_port_count: usize,
|
||||||
|
|
||||||
|
/// Enable uPnP, NAT-PMP, and other router port mapping technologies?
|
||||||
|
pub port_mapping: bool,
|
||||||
|
|
||||||
|
/// Interface name prefix blacklist for local bindings (not remote IPs).
|
||||||
|
pub interface_prefix_blacklist: HashSet<String>,
|
||||||
|
|
||||||
|
/// IP/bits CIDR blacklist for local bindings (not remote IPs).
|
||||||
|
pub cidr_blacklist: HashSet<InetAddress>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl VL1Settings {
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
pub const DEFAULT_PREFIX_BLACKLIST: [&'static str; 11] = ["lo", "utun", "gif", "stf", "iptap", "pktap", "feth", "zt", "llw", "anpi", "bridge"];
|
||||||
|
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
pub const DEFAULT_PREFIX_BLACKLIST: [&'static str; 5] = ["lo", "tun", "tap", "ipsec", "zt"];
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
pub const DEFAULT_PREFIX_BLACKLIST: [&'static str; 0] = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for VL1Settings {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
fixed_ports: HashSet::from([9993u16]),
|
||||||
|
random_port_count: 5,
|
||||||
|
port_mapping: true,
|
||||||
|
interface_prefix_blacklist: Self::DEFAULT_PREFIX_BLACKLIST.iter().map(|s| s.to_string()).collect(),
|
||||||
|
cidr_blacklist: HashSet::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A list of unassigned or obsolete ports under 1024 that could possibly be squatted.
|
/// A list of unassigned or obsolete ports under 1024 that could possibly be squatted.
|
||||||
pub const UNASSIGNED_PRIVILEGED_PORTS: [u16; 299] = [
|
pub const UNASSIGNED_PRIVILEGED_PORTS: [u16; 299] = [
|
||||||
4, 6, 8, 10, 12, 14, 15, 16, 26, 28, 30, 32, 34, 36, 40, 60, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 285, 288, 289, 290, 291, 292,
|
4, 6, 8, 10, 12, 14, 15, 16, 26, 28, 30, 32, 34, 36, 40, 60, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 285, 288, 289, 290, 291, 292,
|
|
@ -1,20 +0,0 @@
|
||||||
[package]
|
|
||||||
name = "zerotier-vl1-service"
|
|
||||||
version = "0.1.0"
|
|
||||||
authors = ["ZeroTier, Inc. <contact@zerotier.com>", "Adam Ierymenko <adam.ierymenko@zerotier.com>"]
|
|
||||||
edition = "2021"
|
|
||||||
license = "MPL-2.0"
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
zerotier-network-hypervisor = { path = "../network-hypervisor" }
|
|
||||||
zerotier-crypto = { path = "../crypto" }
|
|
||||||
zerotier-utils = { path = "../utils" }
|
|
||||||
num-traits = "^0"
|
|
||||||
serde = { version = "^1", features = ["derive"], default-features = false }
|
|
||||||
serde_json = { version = "^1", features = ["std"], default-features = false }
|
|
||||||
|
|
||||||
[target."cfg(windows)".dependencies]
|
|
||||||
winapi = { version = "^0", features = ["handleapi", "ws2ipdef", "ws2tcpip"] }
|
|
||||||
|
|
||||||
[target."cfg(not(windows))".dependencies]
|
|
||||||
libc = "^0"
|
|
|
@ -1 +0,0 @@
|
||||||
../rustfmt.toml
|
|
|
@ -1,49 +0,0 @@
|
||||||
// (c) 2020-2022 ZeroTier, Inc. -- currently proprietary pending actual release and licensing. See LICENSE.md.
|
|
||||||
|
|
||||||
use std::collections::HashSet;
|
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
use zerotier_network_hypervisor::vl1::InetAddress;
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq)]
|
|
||||||
#[serde(default)]
|
|
||||||
pub struct VL1Settings {
|
|
||||||
/// Primary ZeroTier port that is always bound, default is 9993.
|
|
||||||
pub fixed_ports: HashSet<u16>,
|
|
||||||
|
|
||||||
/// Number of additional random ports to bind.
|
|
||||||
pub random_port_count: usize,
|
|
||||||
|
|
||||||
/// Enable uPnP, NAT-PMP, and other router port mapping technologies?
|
|
||||||
pub port_mapping: bool,
|
|
||||||
|
|
||||||
/// Interface name prefix blacklist for local bindings (not remote IPs).
|
|
||||||
pub interface_prefix_blacklist: HashSet<String>,
|
|
||||||
|
|
||||||
/// IP/bits CIDR blacklist for local bindings (not remote IPs).
|
|
||||||
pub cidr_blacklist: HashSet<InetAddress>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl VL1Settings {
|
|
||||||
#[cfg(target_os = "macos")]
|
|
||||||
pub const DEFAULT_PREFIX_BLACKLIST: [&'static str; 11] = ["lo", "utun", "gif", "stf", "iptap", "pktap", "feth", "zt", "llw", "anpi", "bridge"];
|
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
|
||||||
pub const DEFAULT_PREFIX_BLACKLIST: [&'static str; 5] = ["lo", "tun", "tap", "ipsec", "zt"];
|
|
||||||
|
|
||||||
#[cfg(windows)]
|
|
||||||
pub const DEFAULT_PREFIX_BLACKLIST: [&'static str; 0] = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for VL1Settings {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
fixed_ports: HashSet::from([9993u16]),
|
|
||||||
random_port_count: 5,
|
|
||||||
port_mapping: true,
|
|
||||||
interface_prefix_blacklist: Self::DEFAULT_PREFIX_BLACKLIST.iter().map(|s| s.to_string()).collect(),
|
|
||||||
cidr_blacklist: HashSet::new(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Add table
Reference in a new issue