mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-07-27 04:32:51 +02:00
Reorganize some stuff, add bindings needed in service.
This commit is contained in:
parent
b7d7e8eb40
commit
29fa689f0b
16 changed files with 152 additions and 36 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -37,6 +37,7 @@ node_modules
|
||||||
*.vcxproj.backup
|
*.vcxproj.backup
|
||||||
/*.db
|
/*.db
|
||||||
/*.opendb
|
/*.opendb
|
||||||
/rust-zerotier-core/src/bindings/capi.rs
|
/rust-zerotier-core/src/capi.rs
|
||||||
/rust-zerotier-core/target
|
/rust-zerotier-core/target
|
||||||
/rust-zerotier-service/target
|
/rust-zerotier-service/target
|
||||||
|
/rust-zerotier-service/src/osdep.rs
|
||||||
|
|
5
Makefile
5
Makefile
|
@ -30,9 +30,10 @@ clean: FORCE
|
||||||
distclean: FORCE
|
distclean: FORCE
|
||||||
rm -rf ${BUILDDIR}
|
rm -rf ${BUILDDIR}
|
||||||
|
|
||||||
rust-zerotier-core-bindgen: FORCE
|
rust-bindgen: FORCE
|
||||||
cargo install bindgen
|
cargo install bindgen
|
||||||
rm -f rust-zerotier-core/src/bindings/capi.rs
|
rm -f rust-zerotier-core/src/bindings/capi.rs
|
||||||
bindgen --no-doc-comments --no-layout-tests --no-derive-debug core/zerotier.h >rust-zerotier-core/src/bindings/capi.rs
|
bindgen --no-doc-comments --no-layout-tests --no-derive-debug core/zerotier.h >rust-zerotier-core/src/capi.rs
|
||||||
|
bindgen --no-doc-comments --no-layout-tests --no-derive-debug osdep/rust-osdep.h >rust-zerotier-service/src/osdep.rs
|
||||||
|
|
||||||
FORCE:
|
FORCE:
|
||||||
|
|
|
@ -225,6 +225,7 @@ int main(int argc,char **argv)
|
||||||
const char *mac = argv[2];
|
const char *mac = argv[2];
|
||||||
const char *mtu = argv[3];
|
const char *mtu = argv[3];
|
||||||
const char *metric = argv[4];
|
const char *metric = argv[4];
|
||||||
|
int i = NDRV_SETDMXSPEC;
|
||||||
|
|
||||||
s_ndrvfd = socket(AF_NDRV,SOCK_RAW,0);
|
s_ndrvfd = socket(AF_NDRV,SOCK_RAW,0);
|
||||||
if (s_ndrvfd < 0) {
|
if (s_ndrvfd < 0) {
|
||||||
|
|
36
osdep/rust-osdep.h
Normal file
36
osdep/rust-osdep.h
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
#ifdef __APPLE__
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <sys/signal.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
|
#include <sys/select.h>
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
#include <sys/uio.h>
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <sys/sysctl.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <net/bpf.h>
|
||||||
|
#include <net/route.h>
|
||||||
|
#include <net/if.h>
|
||||||
|
#include <net/if_arp.h>
|
||||||
|
#include <net/if_dl.h>
|
||||||
|
#include <net/if_media.h>
|
||||||
|
#include <net/ndrv.h>
|
||||||
|
#include <netinet/in_var.h>
|
||||||
|
#include <netinet/icmp6.h>
|
||||||
|
#include <netinet6/in6_var.h>
|
||||||
|
#include <netinet6/nd6.h>
|
||||||
|
#include <ifaddrs.h>
|
||||||
|
#endif
|
|
@ -29,6 +29,7 @@ impl From<u64> for Address {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<&str> for Address {
|
impl From<&str> for Address {
|
||||||
|
#[inline(always)]
|
||||||
fn from(s: &str) -> Address {
|
fn from(s: &str) -> Address {
|
||||||
Address(u64::from_str_radix(s, 16).unwrap_or(0))
|
Address(u64::from_str_radix(s, 16).unwrap_or(0))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c)2013-2020 ZeroTier, Inc.
|
|
||||||
*
|
|
||||||
* Use of this software is governed by the Business Source License included
|
|
||||||
* in the LICENSE.TXT file in the project's root directory.
|
|
||||||
*
|
|
||||||
* Change Date: 2025-01-01
|
|
||||||
*
|
|
||||||
* On the date above, in accordance with the Business Source License, use
|
|
||||||
* of this software will be governed by version 2.0 of the Apache License.
|
|
||||||
*/
|
|
||||||
/****/
|
|
||||||
|
|
||||||
#[allow(non_snake_case,non_upper_case_globals,non_camel_case_types,dead_code,improper_ctypes)]
|
|
||||||
pub mod capi;
|
|
|
@ -70,6 +70,7 @@ impl Buffer {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for Buffer {
|
impl Drop for Buffer {
|
||||||
|
#[inline(always)]
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
// NOTE: in node.rs std::mem::forget() is used to prevent this from
|
// NOTE: in node.rs std::mem::forget() is used to prevent this from
|
||||||
// being called on buffers that have been returned via one of the
|
// being called on buffers that have been returned via one of the
|
||||||
|
|
|
@ -145,6 +145,7 @@ impl PartialEq for Identity {
|
||||||
impl Eq for Identity {}
|
impl Eq for Identity {}
|
||||||
|
|
||||||
impl Clone for Identity {
|
impl Clone for Identity {
|
||||||
|
#[inline(always)]
|
||||||
fn clone(&self) -> Identity {
|
fn clone(&self) -> Identity {
|
||||||
unsafe {
|
unsafe {
|
||||||
return Identity::new_from_capi(ztcore::ZT_Identity_clone(self.capi), true);
|
return Identity::new_from_capi(ztcore::ZT_Identity_clone(self.capi), true);
|
||||||
|
@ -153,6 +154,7 @@ impl Clone for Identity {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for Identity {
|
impl Drop for Identity {
|
||||||
|
#[inline(always)]
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
if self.requires_delete {
|
if self.requires_delete {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
|
@ -11,16 +11,16 @@
|
||||||
*/
|
*/
|
||||||
/****/
|
/****/
|
||||||
|
|
||||||
|
use std::cmp::Ordering;
|
||||||
use std::ffi::CString;
|
use std::ffi::CString;
|
||||||
use std::mem::{MaybeUninit, transmute};
|
use std::mem::{MaybeUninit, transmute};
|
||||||
|
use std::os::raw::{c_uint, c_void};
|
||||||
|
|
||||||
use num_derive::{FromPrimitive, ToPrimitive};
|
use num_derive::{FromPrimitive, ToPrimitive};
|
||||||
use num_traits::FromPrimitive;
|
use num_traits::FromPrimitive;
|
||||||
|
|
||||||
use crate::*;
|
use crate::*;
|
||||||
use crate::bindings::capi as ztcore;
|
use crate::bindings::capi as ztcore;
|
||||||
use std::os::raw::{c_void, c_uint};
|
|
||||||
use std::cmp::Ordering;
|
|
||||||
|
|
||||||
// WARNING: here be dragons! This defines an opaque blob in Rust that shadows
|
// WARNING: here be dragons! This defines an opaque blob in Rust that shadows
|
||||||
// and is of the exact size as an opaque blob in C that shadows and is the
|
// and is of the exact size as an opaque blob in C that shadows and is the
|
||||||
|
|
|
@ -14,7 +14,8 @@
|
||||||
use std::os::raw::{c_char, c_int};
|
use std::os::raw::{c_char, c_int};
|
||||||
use num_derive::{FromPrimitive, ToPrimitive};
|
use num_derive::{FromPrimitive, ToPrimitive};
|
||||||
|
|
||||||
mod bindings;
|
#[allow(non_snake_case,non_upper_case_globals,non_camel_case_types,dead_code,improper_ctypes)]
|
||||||
|
mod capi;
|
||||||
|
|
||||||
mod identity;
|
mod identity;
|
||||||
mod address;
|
mod address;
|
||||||
|
@ -31,8 +32,9 @@ mod mac;
|
||||||
mod buffer;
|
mod buffer;
|
||||||
mod portableatomici64;
|
mod portableatomici64;
|
||||||
mod virtualnetworkconfig;
|
mod virtualnetworkconfig;
|
||||||
|
mod multicastgroup;
|
||||||
|
|
||||||
use bindings::capi as ztcore;
|
use crate::capi as ztcore;
|
||||||
|
|
||||||
pub use identity::*;
|
pub use identity::*;
|
||||||
pub use address::Address;
|
pub use address::Address;
|
||||||
|
@ -49,34 +51,45 @@ pub use mac::MAC;
|
||||||
pub use buffer::Buffer;
|
pub use buffer::Buffer;
|
||||||
pub use portableatomici64::PortableAtomicI64;
|
pub use portableatomici64::PortableAtomicI64;
|
||||||
pub use virtualnetworkconfig::*;
|
pub use virtualnetworkconfig::*;
|
||||||
|
pub use multicastgroup::MulticastGroup;
|
||||||
|
|
||||||
|
/// Recommended minimum thread stack size for ZeroTier threads.
|
||||||
pub const RECOMMENDED_THREAD_STACK_SIZE: usize = 262144;
|
pub const RECOMMENDED_THREAD_STACK_SIZE: usize = 262144;
|
||||||
|
|
||||||
|
/// Default TCP and UDP port for ZeroTier.
|
||||||
pub const DEFAULT_PORT: u16 = ztcore::ZT_DEFAULT_PORT as u16;
|
pub const DEFAULT_PORT: u16 = ztcore::ZT_DEFAULT_PORT as u16;
|
||||||
|
|
||||||
|
/// Size of a ZeroTier core "Buffer" in bytes.
|
||||||
pub const BUF_SIZE: u32 = ztcore::ZT_BUF_SIZE;
|
pub const BUF_SIZE: u32 = ztcore::ZT_BUF_SIZE;
|
||||||
|
|
||||||
|
/// Minimum physical MTU.
|
||||||
pub const MIN_MTU: u32 = ztcore::ZT_MIN_MTU;
|
pub const MIN_MTU: u32 = ztcore::ZT_MIN_MTU;
|
||||||
|
|
||||||
|
/// Maximum physical MTU.
|
||||||
pub const MAX_MTU: u32 = ztcore::ZT_MAX_MTU;
|
pub const MAX_MTU: u32 = ztcore::ZT_MAX_MTU;
|
||||||
|
|
||||||
|
/// Default physica UDP MTU (not including IP or UDP headers).
|
||||||
pub const DEFAULT_UDP_MTU: u32 = ztcore::ZT_DEFAULT_UDP_MTU;
|
pub const DEFAULT_UDP_MTU: u32 = ztcore::ZT_DEFAULT_UDP_MTU;
|
||||||
|
|
||||||
|
/// Maximum UDP MTU (we never actually get this high).
|
||||||
pub const MAX_UDP_MTU: u32 = ztcore::ZT_MAX_UDP_MTU;
|
pub const MAX_UDP_MTU: u32 = ztcore::ZT_MAX_UDP_MTU;
|
||||||
|
|
||||||
#[allow(non_snake_case,non_upper_case_globals)]
|
#[allow(non_snake_case,non_upper_case_globals)]
|
||||||
pub mod RulePacketCharacteristicFlags {
|
pub mod RulePacketCharacteristicFlags {
|
||||||
pub const Inbound: u64 = crate::bindings::capi::ZT_RULE_PACKET_CHARACTERISTICS_INBOUND as u64;
|
pub const Inbound: u64 = crate::capi::ZT_RULE_PACKET_CHARACTERISTICS_INBOUND as u64;
|
||||||
pub const Multicast: u64 = crate::bindings::capi::ZT_RULE_PACKET_CHARACTERISTICS_MULTICAST as u64;
|
pub const Multicast: u64 = crate::capi::ZT_RULE_PACKET_CHARACTERISTICS_MULTICAST as u64;
|
||||||
pub const Broadcast: u64 = crate::bindings::capi::ZT_RULE_PACKET_CHARACTERISTICS_BROADCAST as u64;
|
pub const Broadcast: u64 = crate::capi::ZT_RULE_PACKET_CHARACTERISTICS_BROADCAST as u64;
|
||||||
pub const SenderIpAuthenticated: u64 = crate::bindings::capi::ZT_RULE_PACKET_CHARACTERISTICS_SENDER_IP_AUTHENTICATED as u64;
|
pub const SenderIpAuthenticated: u64 = crate::capi::ZT_RULE_PACKET_CHARACTERISTICS_SENDER_IP_AUTHENTICATED as u64;
|
||||||
pub const SenderMacAuthenticated: u64 = crate::bindings::capi::ZT_RULE_PACKET_CHARACTERISTICS_SENDER_MAC_AUTHENTICATED as u64;
|
pub const SenderMacAuthenticated: u64 = crate::capi::ZT_RULE_PACKET_CHARACTERISTICS_SENDER_MAC_AUTHENTICATED as u64;
|
||||||
pub const TcpFlagNS: u64 = crate::bindings::capi::ZT_RULE_PACKET_CHARACTERISTICS_TCP_NS as u64;
|
pub const TcpFlagNS: u64 = crate::capi::ZT_RULE_PACKET_CHARACTERISTICS_TCP_NS as u64;
|
||||||
pub const TcpFlagCWR: u64 = crate::bindings::capi::ZT_RULE_PACKET_CHARACTERISTICS_TCP_CWR as u64;
|
pub const TcpFlagCWR: u64 = crate::capi::ZT_RULE_PACKET_CHARACTERISTICS_TCP_CWR as u64;
|
||||||
pub const TcpFlagECE: u64 = crate::bindings::capi::ZT_RULE_PACKET_CHARACTERISTICS_TCP_ECE as u64;
|
pub const TcpFlagECE: u64 = crate::capi::ZT_RULE_PACKET_CHARACTERISTICS_TCP_ECE as u64;
|
||||||
pub const TcpFlagURG: u64 = crate::bindings::capi::ZT_RULE_PACKET_CHARACTERISTICS_TCP_URG as u64;
|
pub const TcpFlagURG: u64 = crate::capi::ZT_RULE_PACKET_CHARACTERISTICS_TCP_URG as u64;
|
||||||
pub const TcpFlagACK: u64 = crate::bindings::capi::ZT_RULE_PACKET_CHARACTERISTICS_TCP_ACK as u64;
|
pub const TcpFlagACK: u64 = crate::capi::ZT_RULE_PACKET_CHARACTERISTICS_TCP_ACK as u64;
|
||||||
pub const TcpFlagPSH: u64 = crate::bindings::capi::ZT_RULE_PACKET_CHARACTERISTICS_TCP_PSH as u64;
|
pub const TcpFlagPSH: u64 = crate::capi::ZT_RULE_PACKET_CHARACTERISTICS_TCP_PSH as u64;
|
||||||
pub const TcpFlagRST: u64 = crate::bindings::capi::ZT_RULE_PACKET_CHARACTERISTICS_TCP_RST as u64;
|
pub const TcpFlagRST: u64 = crate::capi::ZT_RULE_PACKET_CHARACTERISTICS_TCP_RST as u64;
|
||||||
pub const TcpFlagSYN: u64 = crate::bindings::capi::ZT_RULE_PACKET_CHARACTERISTICS_TCP_SYN as u64;
|
pub const TcpFlagSYN: u64 = crate::capi::ZT_RULE_PACKET_CHARACTERISTICS_TCP_SYN as u64;
|
||||||
pub const TcpFlagFIN: u64 = crate::bindings::capi::ZT_RULE_PACKET_CHARACTERISTICS_TCP_FIN as u64;
|
pub const TcpFlagFIN: u64 = crate::capi::ZT_RULE_PACKET_CHARACTERISTICS_TCP_FIN as u64;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(FromPrimitive, ToPrimitive, PartialEq, Eq)]
|
#[derive(FromPrimitive, ToPrimitive, PartialEq, Eq)]
|
||||||
|
|
|
@ -70,6 +70,7 @@ impl Locator {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for Locator {
|
impl Drop for Locator {
|
||||||
|
#[inline(always)]
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
if self.requires_delete {
|
if self.requires_delete {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -80,6 +81,7 @@ impl Drop for Locator {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Clone for Locator {
|
impl Clone for Locator {
|
||||||
|
#[inline(always)]
|
||||||
fn clone(&self) -> Locator {
|
fn clone(&self) -> Locator {
|
||||||
Locator::new_from_string(self.to_string().as_str()).ok().unwrap()
|
Locator::new_from_string(self.to_string().as_str()).ok().unwrap()
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
*/
|
*/
|
||||||
/****/
|
/****/
|
||||||
|
|
||||||
|
use std::cmp::Ordering;
|
||||||
|
|
||||||
pub struct MAC(pub u64);
|
pub struct MAC(pub u64);
|
||||||
|
|
||||||
impl ToString for MAC {
|
impl ToString for MAC {
|
||||||
|
@ -47,6 +49,20 @@ impl PartialEq for MAC {
|
||||||
|
|
||||||
impl Eq for MAC {}
|
impl Eq for MAC {}
|
||||||
|
|
||||||
|
impl Ord for MAC {
|
||||||
|
#[inline(always)]
|
||||||
|
fn cmp(&self, other: &Self) -> Ordering {
|
||||||
|
self.0.cmp(&other.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PartialOrd for MAC {
|
||||||
|
#[inline(always)]
|
||||||
|
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||||
|
Some(self.0.cmp(&other.0))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Clone for MAC {
|
impl Clone for MAC {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn clone(&self) -> Self {
|
fn clone(&self) -> Self {
|
||||||
|
|
26
rust-zerotier-core/src/multicastgroup.rs
Normal file
26
rust-zerotier-core/src/multicastgroup.rs
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
use crate::MAC;
|
||||||
|
use std::cmp::Ordering;
|
||||||
|
|
||||||
|
#[derive(Clone, PartialEq, Eq)]
|
||||||
|
pub struct MulticastGroup {
|
||||||
|
pub mac: MAC,
|
||||||
|
pub adi: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Ord for MulticastGroup {
|
||||||
|
#[inline(always)]
|
||||||
|
fn cmp(&self, other: &Self) -> Ordering {
|
||||||
|
let o1 = self.mac.0.cmp(&other.mac.0);
|
||||||
|
if o1 == Ordering::Equal {
|
||||||
|
return self.adi.cmp(&other.adi);
|
||||||
|
}
|
||||||
|
o1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PartialOrd for MulticastGroup {
|
||||||
|
#[inline(always)]
|
||||||
|
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||||
|
Some(self.cmp(other))
|
||||||
|
}
|
||||||
|
}
|
|
@ -17,6 +17,10 @@ mod physicallink;
|
||||||
mod log;
|
mod log;
|
||||||
mod store;
|
mod store;
|
||||||
mod network;
|
mod network;
|
||||||
|
mod vnp;
|
||||||
|
|
||||||
|
#[allow(non_snake_case,non_upper_case_globals,non_camel_case_types,dead_code,improper_ctypes)]
|
||||||
|
mod osdep;
|
||||||
|
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
|
10
rust-zerotier-service/src/vnp/mac_feth_tap.rs
Normal file
10
rust-zerotier-service/src/vnp/mac_feth_tap.rs
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
use crate::vnp::Port;
|
||||||
|
|
||||||
|
pub struct MacFethTap {
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MacFethTap {
|
||||||
|
pub fn new() -> MacFethTap {
|
||||||
|
MacFethTap{}
|
||||||
|
}
|
||||||
|
}
|
17
rust-zerotier-service/src/vnp/mod.rs
Normal file
17
rust-zerotier-service/src/vnp/mod.rs
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
// VNP = virtual network port, a.k.a. tun/tap device driver interface.
|
||||||
|
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
mod mac_feth_tap;
|
||||||
|
|
||||||
|
pub trait Port {
|
||||||
|
fn set_enabled(&self, enabled: bool);
|
||||||
|
fn is_enabled(&self, ) -> bool;
|
||||||
|
fn set_ips(&self, zerotier_core::InetAddress: &ip);
|
||||||
|
fn ips(&self) -> Vec<zerotier_core::InetAddress>;
|
||||||
|
fn device_name(&self) -> String;
|
||||||
|
fn routing_device_name(&self) -> String;
|
||||||
|
fn set_friendly_name(&self, friendly_name: &str);
|
||||||
|
fn friendly_name(&self) -> String;
|
||||||
|
fn get_multicast_groups(&self) -> std::collections::BTreeSet<zerotier_core::MulticastGroup>;
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue