Compare commits

...
7 Commits
Author SHA1 Message Date
lbl 0238d1ab7e Modify the compilation method for the MIPS target platform. 2025-02-21 16:31:48 +08:00
lbl 563aca39aa Use the new version of tun-rs 2025-02-13 17:02:06 +08:00
lbl 274f4df43a upload file 2025-02-06 19:06:13 +08:00
lbl 1fae7c9979 modify component name 2025-02-06 18:15:51 +08:00
lbl 46b37c0753 use v4 2025-02-06 17:56:29 +08:00
lbl f737f591b6 version = "1.2.16" 2025-02-06 16:28:43 +08:00
lbl ebf8337ad7 default tun name use vnt-tun 2025-02-06 16:26:47 +08:00
13 changed files with 153 additions and 99 deletions
+97 -34
View File
@@ -12,6 +12,9 @@ defaults:
run:
# necessary for windows
shell: bash
permissions:
contents: write
packages: write
jobs:
# test:
@@ -78,6 +81,11 @@ jobs:
- TARGET: mips-unknown-linux-musl # openwrt
OS: ubuntu-latest
FEATURES: ring-cipher,wss
# - TARGET: x86_64-unknown-freebsd
# OS: ubuntu-latest
# ARTIFACT_NAME: freebsd-13.2-x86_64
# FEATURES: default
# BSD_VERSION: 13.2
# needs: test
runs-on: ${{ matrix.OS }}
env:
@@ -86,7 +94,7 @@ jobs:
OS: ${{ matrix.OS }}
FEATURES: ${{ matrix.FEATURES }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Init submodules
uses: snickerbockers/submodules-init@v4
- name: Cargo cache
@@ -101,7 +109,38 @@ jobs:
run: echo OPENSSL_SRC_PERL=C:/Strawberry/perl/bin/perl >> $GITHUB_ENV
- name: List
run: find ./
- name: Build NetLink X86_64-FreeBSD
uses: cross-platform-actions/[email protected]
if: ${{ endsWith(matrix.TARGET, 'freebsd') }}
env:
TARGET: ${{ matrix.TARGET }}
with:
operating_system: freebsd
environment_variables: TARGET
architecture: x86-64
version: ${{ matrix.BSD_VERSION }}
shell: bash
memory: 5G
cpu_count: 4
run: |
uname -a
echo $SHELL
pwd
ls -lah
whoami
env | sort
sudo pkg install -y git protobuf
curl --proto 'https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source $HOME/.cargo/env
rustup set auto-self-update disable
rustup install 1.77
rustup default 1.77
export CC=clang
export CXX=clang++
export CARGO_TERM_COLOR=always
cargo build --release --verbose --target $TARGET
- name: Install and configure dependencies
if: ${{ ! endsWith(matrix.TARGET, 'freebsd') }}
run: |
# dependencies are only needed on ubuntu as that's the only place where
# we make cross-compilation
@@ -112,7 +151,8 @@ jobs:
# curl -s musl.cc | grep mipsel
case $TARGET in
mipsel-unknown-linux-musl)
MUSL_URI=mipsel-linux-musl-cross
MUSL_URI=mipsel-linux-muslsf-cross
URL=mipsel-linux-muslsf
;;
aarch64-unknown-linux-musl)
MUSL_URI=aarch64-linux-musl-cross
@@ -122,7 +162,7 @@ jobs:
;;
armv7-unknown-linux-musleabi)
MUSL_URI=armv7m-linux-musleabi-cross
;;
;;
arm-unknown-linux-musleabihf)
MUSL_URI=arm-linux-musleabihf-cross
;;
@@ -130,28 +170,31 @@ jobs:
MUSL_URI=arm-linux-musleabi-cross
;;
mips-unknown-linux-musl)
MUSL_URI=mips-linux-musl-cross
MUSL_URI=mips-linux-muslsf-cross
URL=mips-linux-muslsf
;;
esac
if [[ $TARGET =~ ^mips.*$ ]]; then
# mips平台使用1.71.1版本
rustup install 1.71.1
rustup default 1.71.1
else
rustup install 1.77
rustup default 1.77
fi
if [ -n "$MUSL_URI" ]; then
mkdir -p ./musl_gcc
wget -c https://musl.cc/$MUSL_URI.tgz -P ./musl_gcc/
tar zxf ./musl_gcc/$MUSL_URI.tgz -C ./musl_gcc/
sudo ln -s $(pwd)/musl_gcc/$MUSL_URI/bin/*gcc /usr/bin/
mkdir -p /opt/musl_gcc
wget -c https://musl.cc/$MUSL_URI.tgz -P /opt/musl_gcc/
tar zxf /opt/musl_gcc/$MUSL_URI.tgz -C /opt/musl_gcc/
sudo ln -s /opt/musl_gcc/$MUSL_URI/bin/*gcc /usr/bin/
fi
else
rustup install 1.77
rustup default 1.77
fi
if [[ $TARGET =~ ^mips.*$ ]]; then
cd /opt/musl_gcc/${URL}-cross/lib/gcc/${URL}/11.2.1
cp libgcc_eh.a libunwind.a
rustup toolchain install nightly-x86_64-unknown-linux-gnu
rustup component add rust-src --toolchain nightly-x86_64-unknown-linux-gnu
RUST_LIB_SRC=$HOME/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/
if [[ -f $RUST_LIB_SRC/library/Cargo.lock && ! -f $RUST_LIB_SRC/Cargo.lock ]]; then
cp -f $RUST_LIB_SRC/library/Cargo.lock $RUST_LIB_SRC/Cargo.lock
fi
elif [[ $OS =~ ^windows.*$ ]]; then
# Windows 平台使用 1.77 版本
rustup install 1.77.0
rustup default 1.77.0
fi
rustup -V
@@ -175,11 +218,17 @@ jobs:
linker = "arm-linux-musleabi-gcc"
rustflags = ["-C", "target-feature=+crt-static","-C", "strip=symbols"]
[target.mipsel-unknown-linux-musl]
linker = "mipsel-linux-musl-gcc"
rustflags = ["-C", "target-feature=+crt-static","-C", "strip=symbols"]
linker = "mipsel-linux-muslsf-gcc"
rustflags = ["-C", "target-feature=+crt-static","-C", "strip=symbols","-C", "link-arg=-static",
"-C", "relocation-model=static","-C", "link-arg=-no-pie","--cfg", "compiler_builtins_no_debug",
"-L", "/opt/musl_gcc/mipsel-linux-muslsf-cross/mipsel-linux-muslsf/lib",
"-L", "/opt/musl_gcc/mipsel-linux-muslsf-cross/lib/gcc/mipsel-linux-muslsf/11.2.1"]
[target.mips-unknown-linux-musl]
linker = "mips-linux-musl-gcc"
rustflags = ["-C", "target-feature=+crt-static","-C", "strip=symbols"]
linker = "mips-linux-muslsf-gcc"
rustflags = ["-C", "target-feature=+crt-static","-C", "strip=symbols","-C", "link-arg=-static",
"-C", "relocation-model=static","-C", "link-arg=-no-pie","--cfg", "compiler_builtins_no_debug",
"-L", "/opt/musl_gcc/mips-linux-muslsf-cross/mips-linux-muslsf/lib",
"-L", "/opt/musl_gcc/mips-linux-muslsf-cross/lib/gcc/mips-linux-muslsf/11.2.1"]
[target.x86_64-pc-windows-msvc]
rustflags = ["-C", "target-feature=+crt-static","-C", "strip=symbols"]
[target.i686-pc-windows-msvc]
@@ -192,11 +241,24 @@ jobs:
rustflags = ["-C", "target-feature=+crt-static","-C", "strip=symbols"]
EOF
- name: Install rust target
if: ${{ ! endsWith(matrix.TARGET, 'freebsd') && ! startsWith(matrix.TARGET, 'mips') }}
run: rustup target add $TARGET
- name: Run build vn-link-cli
run: cargo build --package vn-link-cli --release --verbose --target $TARGET --features $FEATURES
if: ${{ ! endsWith(matrix.TARGET, 'freebsd') }}
run: |
if [[ $TARGET =~ ^mips.*$ ]]; then
cargo +nightly build --package vn-link-cli --release --verbose --target $TARGET -Z build-std=std,panic_abort --features $FEATURES
else
cargo build --package vn-link-cli --release --verbose --target $TARGET --features $FEATURES
fi
- name: Run build vnt-cli
run: cargo build --package vnt-cli --release --verbose --target $TARGET --features $FEATURES
if: ${{ ! endsWith(matrix.TARGET, 'freebsd') }}
run: |
if [[ $TARGET =~ ^mips.*$ ]]; then
cargo +nightly build --package vnt-cli --release --verbose --target $TARGET -Z build-std=std,panic_abort --features $FEATURES
else
cargo build --package vnt-cli --release --verbose --target $TARGET --features $FEATURES
fi
- name: List target
run: find ./target
- name: Compress
@@ -220,12 +282,14 @@ jobs:
mv ./README ./artifacts/README.txt
cd ./artifacts
tar -czf vnt-$TARGET-$TAG.tar.gz *
mkdir upload_file
mv vnt-$TARGET-$TAG.tar.gz ./upload_file/
- name: Archive artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: vnt-cli
name: vnt-cli-${{ matrix.TARGET }}
path: |
./artifacts
./artifacts/upload_file
# deploys to github releases on tag
deploy:
if: startsWith(github.ref, 'refs/tags/')
@@ -233,17 +297,16 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Download artifacts
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: vnt-cli
path: ./artifacts
- name: List
run: find ./artifacts
- name: Release
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.YOURTOKEN }}
file: ./artifacts/*.tar.gz
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ./artifacts/**/*.tar.gz
tag: ${{ github.ref }}
overwrite: true
file_glob: true
Generated
+16 -23
View File
@@ -333,7 +333,7 @@ dependencies = [
[[package]]
name = "common"
version = "1.2.15"
version = "1.2.16"
dependencies = [
"anyhow",
"chrono",
@@ -2083,9 +2083,9 @@ dependencies = [
[[package]]
name = "tun-rs"
version = "1.5.0"
version = "2.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53141e64197ff7e758b8152615e50bb4a3b18c970738876e7906d31f242c7d6e"
checksum = "57cff936a4d3a03480e462b2b384dabd5baf64794f10f172965b18e0223d5fc7"
dependencies = [
"bitflags 2.6.0",
"byteorder",
@@ -2102,9 +2102,9 @@ dependencies = [
"nix 0.29.0",
"scopeguard",
"thiserror 2.0.9",
"widestring",
"windows-sys 0.59.0",
"winreg",
"wintun-bindings",
]
[[package]]
@@ -2240,7 +2240,7 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "vn-link"
version = "1.2.15"
version = "1.2.16"
dependencies = [
"anyhow",
"crossbeam-utils",
@@ -2253,7 +2253,7 @@ dependencies = [
[[package]]
name = "vn-link-cli"
version = "1.2.15"
version = "1.2.16"
dependencies = [
"common",
"log",
@@ -2263,7 +2263,7 @@ dependencies = [
[[package]]
name = "vnt"
version = "1.2.15"
version = "1.2.16"
dependencies = [
"aes",
"aes-gcm",
@@ -2312,7 +2312,7 @@ dependencies = [
[[package]]
name = "vnt-cli"
version = "1.2.15"
version = "1.2.16"
dependencies = [
"anyhow",
"chrono",
@@ -2407,6 +2407,12 @@ dependencies = [
"rustix",
]
[[package]]
name = "widestring"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7219d36b6eac893fa81e84ebe06485e7dcbb616177469b142df14f1f4deb1311"
[[package]]
name = "wildmatch"
version = "1.1.0"
@@ -2594,24 +2600,11 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
[[package]]
name = "winreg"
version = "0.52.0"
version = "0.55.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a277a57398d4bfa075df44f501a17cfdf8542d224f0d36095a2adc7aee4ef0a5"
checksum = "cb5a765337c50e9ec252c2069be9bf91c7df47afb103b642ba3a53bf8101be97"
dependencies = [
"cfg-if",
"windows-sys 0.48.0",
]
[[package]]
name = "wintun-bindings"
version = "0.7.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e35d3911efde5ee25586385204127ff6a3f251477dcdd3b222775aaa4d95977"
dependencies = [
"c2rust-bitfields",
"libloading",
"log",
"thiserror 2.0.9",
"windows-sys 0.59.0",
]
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "common"
version = "1.2.15"
version = "1.2.16"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+1 -1
View File
@@ -511,7 +511,7 @@ fn print_usage(program: &str, _opts: Options) {
" --use-channel <p2p> {}",
get_description("--use-channel <p2p>", &language)
);
#[cfg(not(feature = "vn-link-model"))]
#[cfg(feature = "integrated_tun")]
println!(
" --nic <tun0> {}",
get_description("--nic <tun0>", &language)
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "vn-link-cli"
version = "1.2.15"
version = "1.2.16"
edition = "2021"
[dependencies]
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "vn-link"
version = "1.2.15"
version = "1.2.16"
edition = "2021"
[dependencies]
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "vnt-cli"
version = "1.2.15"
version = "1.2.16"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+4 -4
View File
@@ -1,12 +1,12 @@
[package]
name = "vnt"
version = "1.2.15"
version = "1.2.16"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
tun-rs = { version = "1.5.0", optional = true,features = ["experimental"] }
tun-rs = { version = "2", optional = true, features = ["experimental"] }
packet = { path = "./packet" }
bytes = "1.5.0"
log = "0.4.17"
@@ -52,13 +52,13 @@ network-interface = "2.0.0"
futures-util = "0.3.30"
[target.'cfg(target_os = "windows")'.dependencies]
libloading = "0.8.0"
windows-sys = {version = "0.59.0",features = [ "Win32_Foundation",
windows-sys = { version = "0.59.0", features = ["Win32_Foundation",
"Win32_NetworkManagement",
"Win32_NetworkManagement_IpHelper",
"Win32_Networking_WinSock",
"Win32_System_IO",
"Win32_System_Threading",
"Win32_System_WindowsProgramming",]}
"Win32_System_WindowsProgramming", ] }
[build-dependencies]
protobuf-codegen = "=3.2.0"
-2
View File
@@ -12,8 +12,6 @@ use packet::ip::ipv4;
use packet::ip::ipv4::packet::IpV4Packet;
use parking_lot::Mutex;
use protobuf::Message;
#[cfg(feature = "integrated_tun")]
use tun_rs::AbstractDevice;
use crate::channel::context::ChannelContext;
use crate::channel::{Route, RouteKey};
+3 -3
View File
@@ -13,12 +13,12 @@ use parking_lot::Mutex;
use std::collections::HashMap;
use std::net::Ipv4Addr;
use std::sync::Arc;
use tun_rs::platform::Device;
use tun_rs::SyncDevice;
pub(crate) fn start_simple(
stop_manager: StopManager,
context: &ChannelContext,
device: Arc<Device>,
device: Arc<SyncDevice>,
current_device: Arc<AtomicCell<CurrentDeviceInfo>>,
ip_route: ExternalRoute,
#[cfg(feature = "ip_proxy")] ip_proxy_map: Option<IpProxyMap>,
@@ -71,7 +71,7 @@ pub(crate) fn start_simple(
fn start_simple0(
context: &ChannelContext,
device: Arc<Device>,
device: Arc<SyncDevice>,
current_device: Arc<AtomicCell<CurrentDeviceInfo>>,
ip_route: ExternalRoute,
#[cfg(feature = "ip_proxy")] ip_proxy_map: Option<IpProxyMap>,
+4 -4
View File
@@ -8,7 +8,7 @@ use std::collections::HashMap;
use std::net::Ipv4Addr;
use std::sync::Arc;
use std::{io, thread};
use tun_rs::platform::Device;
use tun_rs::SyncDevice;
use crate::channel::context::ChannelContext;
use crate::channel::sender::{send_to_wg, send_to_wg_broadcast};
@@ -26,7 +26,7 @@ use crate::protocol::body::ENCRYPTION_RESERVED;
use crate::protocol::ip_turn_packet::BroadcastPacket;
use crate::protocol::{ip_turn_packet, NetPacket, MAX_TTL};
use crate::util::StopManager;
fn icmp(device_writer: &Device, mut ipv4_packet: IpV4Packet<&mut [u8]>) -> anyhow::Result<()> {
fn icmp(device_writer: &SyncDevice, mut ipv4_packet: IpV4Packet<&mut [u8]>) -> anyhow::Result<()> {
if ipv4_packet.protocol() == Protocol::Icmp {
let mut icmp = IcmpPacket::new(ipv4_packet.payload_mut())?;
if icmp.kind() == Kind::EchoRequest {
@@ -45,7 +45,7 @@ fn icmp(device_writer: &Device, mut ipv4_packet: IpV4Packet<&mut [u8]>) -> anyho
pub fn start(
stop_manager: StopManager,
context: ChannelContext,
device: Arc<Device>,
device: Arc<SyncDevice>,
current_device: Arc<AtomicCell<CurrentDeviceInfo>>,
ip_route: ExternalRoute,
#[cfg(feature = "ip_proxy")] ip_proxy_map: Option<IpProxyMap>,
@@ -158,7 +158,7 @@ pub(crate) fn handle(
buf: &mut [u8],
data_len: usize, //数据总长度=12+ip包长度
extend: &mut [u8],
device_writer: &Device,
device_writer: &SyncDevice,
current_device: CurrentDeviceInfo,
ip_route: &ExternalRoute,
#[cfg(feature = "ip_proxy")] proxy_map: &Option<IpProxyMap>,
+20 -20
View File
@@ -1,8 +1,7 @@
use std::io;
use std::net::Ipv4Addr;
use std::sync::Arc;
use tun_rs::platform::Device;
use tun_rs::AbstractDevice;
use tun_rs::SyncDevice;
use crate::{DeviceConfig, ErrorInfo, ErrorType, VntCallback};
@@ -12,7 +11,7 @@ const DEFAULT_TUN_NAME: &str = "vnt-tun";
pub fn create_device<Call: VntCallback>(
config: DeviceConfig,
call: &Call,
) -> Result<Arc<Device>, ErrorInfo> {
) -> Result<Arc<SyncDevice>, ErrorInfo> {
let device = match create_device0(&config) {
Ok(device) => device,
Err(e) => {
@@ -53,23 +52,25 @@ pub fn create_device<Call: VntCallback>(
Ok(device)
}
fn create_device0(config: &DeviceConfig) -> io::Result<Arc<Device>> {
let mut tun_config = tun_rs::Configuration::default();
let netmask = u32::from_be_bytes(config.virtual_netmask.octets());
tun_config
.address_with_prefix(config.virtual_ip, netmask.count_ones() as u8)
.up();
fn create_device0(config: &DeviceConfig) -> io::Result<Arc<SyncDevice>> {
let mut tun_builder = tun_rs::DeviceBuilder::default();
tun_builder = tun_builder.ipv4(config.virtual_ip, config.virtual_netmask, None);
match &config.device_name {
None => {
#[cfg(any(target_os = "windows", target_os = "linux"))]
{
tun_builder = tun_builder.name(DEFAULT_TUN_NAME);
}
}
Some(name) => {
tun_builder = tun_builder.name(name);
}
}
#[cfg(target_os = "windows")]
{
tun_config.name(
config
.device_name
.clone()
.unwrap_or(DEFAULT_TUN_NAME.to_string()),
);
tun_config.platform_config(|v| {
v.metric(0).ring_capacity(4 * 1024 * 1024);
});
tun_builder = tun_builder.metric(0).ring_capacity(4 * 1024 * 1024);
}
#[cfg(target_os = "linux")]
@@ -83,8 +84,7 @@ fn create_device0(config: &DeviceConfig) -> io::Result<Arc<Device>> {
}
}
tun_config.mtu(config.mtu as u16);
let device = tun_rs::create(&tun_config)?;
let device = tun_builder.mtu(config.mtu as u16).build_sync()?;
Ok(Arc::new(device))
}
+4 -4
View File
@@ -15,16 +15,16 @@ use crate::tun_tap_device::vnt_device::DeviceWrite;
use crate::util::StopManager;
use crossbeam_utils::atomic::AtomicCell;
use parking_lot::Mutex;
use tun_rs::platform::Device;
use tun_rs::SyncDevice;
#[repr(transparent)]
#[derive(Clone, Default)]
pub struct DeviceAdapter {
tun: Arc<Mutex<Option<Arc<Device>>>>,
tun: Arc<Mutex<Option<Arc<SyncDevice>>>>,
}
impl DeviceAdapter {
pub fn insert(&self, device: Arc<Device>) {
pub fn insert(&self, device: Arc<SyncDevice>) {
let r = self.tun.lock().replace(device);
assert!(r.is_none());
}
@@ -116,7 +116,7 @@ impl TunDeviceHelper {
}
}
/// 要保证先stop 再start
pub fn start(&self, device: Arc<Device>, allow_wire_guard: bool) -> io::Result<()> {
pub fn start(&self, device: Arc<SyncDevice>, allow_wire_guard: bool) -> io::Result<()> {
self.device_adapter.insert(device.clone());
let device_stop = DeviceStop::default();
let s = self.device_stop.lock().replace(device_stop.clone());