diff --git a/.github/workflows/freebsd.yml b/.github/workflows/freebsd.yml
new file mode 100644
index 00000000..3f8872b8
--- /dev/null
+++ b/.github/workflows/freebsd.yml
@@ -0,0 +1,41 @@
+name: TestFreeBSD
+
+on:
+ [push, pull_request]
+
+concurrency:
+ group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}
+ cancel-in-progress: true
+
+jobs:
+ test:
+ runs-on: ubuntu-latest
+ strategy:
+ matrix:
+ toolchain: ["stable"] # ["nightly", "beta", "stable"] #
+ steps:
+ - uses: actions/checkout@v4
+ - name: Test in FreeBSD
+ id: test
+ uses: vmactions/freebsd-vm@v1
+ with:
+ usesh: true
+ sync: rsync
+ copyback: false
+ prepare: |
+ pkg install -y curl pkgconf glib
+ curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf > install.sh
+ chmod +x install.sh
+ ./install.sh -y --default-toolchain ${{ matrix.toolchain }}
+ run: |
+ . "$HOME/.cargo/env"
+ set -ex
+
+ # Add feature "nightly" if toolchain is nightly
+ if [ "${{ matrix.toolchain }}" = "nightly" ]; then
+ ARGS="$ARGS --features nightly"
+ fi
+
+ RUST_BACKTRACE=1 cargo +${{ matrix.toolchain }} fmt --all -- --check
+ RUST_BACKTRACE=1 cargo +${{ matrix.toolchain }} clippy --all-features -- -D warnings
+ RUST_BACKTRACE=1 cargo +${{ matrix.toolchain }} build --all-features
diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml
index d0922862..a7cc12df 100644
--- a/.github/workflows/rust.yml
+++ b/.github/workflows/rust.yml
@@ -80,7 +80,38 @@ jobs:
cargo lipo --verbose --all-features --features="async tokio/rt-multi-thread"
- name: Abort on error
if: ${{ failure() }}
- run: echo "iOs build job failed" && false
+ run: echo "iOS build job failed" && false
+
+ build_n_test_openharmony:
+ strategy:
+ matrix:
+ target: [aarch64-unknown-linux-ohos, armv7-unknown-linux-ohos, x86_64-unknown-linux-ohos]
+ fail-fast: false
+ runs-on: ubuntu-latest
+
+ steps:
+ - uses: actions/checkout@v4
+ - uses: openharmony-rs/setup-ohos-sdk@v0.2
+ id: setup-ohos
+ with:
+ version: "5.0"
+ - name: Install ohrs and rust compiler for ohos target
+ if: ${{ !cancelled() }}
+ run: |
+ cargo install --locked ohrs
+ rustup target add ${{ matrix.target }}
+ - name: fmt & clippy
+ if: ${{ !cancelled() }}
+ run: |
+ cargo fmt --all -- --check
+ ohrs cargo --disable-target -- clippy --target ${{matrix.target}} --all-features --features="async tokio/rt-multi-thread" -- -D warnings
+ - name: Build
+ if: ${{ !cancelled() }}
+ run: |
+ ohrs cargo --disable-target -- rustc --target ${{matrix.target}} --verbose --all-features --features="async tokio/rt-multi-thread" --lib --crate-type=cdylib
+ - name: Abort on error
+ if: ${{ failure() }}
+ run: echo "OpenHarmony build job failed" && false
semver:
name: Check semver
diff --git a/README.md b/README.md
index b6dc7dc1..51efcda0 100644
--- a/README.md
+++ b/README.md
@@ -124,3 +124,10 @@ Windows
-----
You need to copy the [wintun.dll](https://wintun.net/) file which matches your architecture to
the same directory as your executable and run your program as administrator.
+
+## Contributors ✨
+Thanks goes to these wonderful people:
+
+
+
+
diff --git a/src/address.rs b/src/address.rs
index 5f19d70b..47ec94cb 100644
--- a/src/address.rs
+++ b/src/address.rs
@@ -51,7 +51,7 @@ impl ToAddress for str {
}
}
-impl<'a> ToAddress for &'a str {
+impl ToAddress for &str {
fn to_address(&self) -> Result {
(*self).to_address()
}
@@ -63,7 +63,7 @@ impl ToAddress for String {
}
}
-impl<'a> ToAddress for &'a String {
+impl ToAddress for &String {
fn to_address(&self) -> Result {
self.as_str().to_address()
}
@@ -75,7 +75,7 @@ impl ToAddress for Ipv4Addr {
}
}
-impl<'a> ToAddress for &'a Ipv4Addr {
+impl ToAddress for &Ipv4Addr {
fn to_address(&self) -> Result {
(*self).to_address()
}
@@ -87,7 +87,7 @@ impl ToAddress for IpAddr {
}
}
-impl<'a> ToAddress for &'a IpAddr {
+impl ToAddress for &IpAddr {
fn to_address(&self) -> Result {
(*self).to_address()
}
@@ -99,7 +99,7 @@ impl ToAddress for SocketAddrV4 {
}
}
-impl<'a> ToAddress for &'a SocketAddrV4 {
+impl ToAddress for &SocketAddrV4 {
fn to_address(&self) -> Result {
(*self).to_address()
}
@@ -111,7 +111,7 @@ impl ToAddress for SocketAddr {
}
}
-impl<'a> ToAddress for &'a SocketAddr {
+impl ToAddress for &SocketAddr {
fn to_address(&self) -> Result {
(*self).to_address()
}
diff --git a/src/configuration.rs b/src/configuration.rs
index 32fc6e16..07782ee6 100644
--- a/src/configuration.rs
+++ b/src/configuration.rs
@@ -78,7 +78,7 @@ impl Configuration {
/// Functionally equivalent to `tun_name`
#[deprecated(
- since = "1.1.2",
+ since = "0.7.0",
note = "Since the API `name` may have an easy name conflict when IDE prompts, it is replaced by `tun_name` for better coding experience"
)]
pub fn name>(&mut self, tun_name: S) -> &mut Self {
@@ -144,7 +144,7 @@ impl Configuration {
/// Set the number of queues.
/// Note: The queues must be 1, otherwise will failed.
- #[deprecated(since = "1.0.0", note = "The queues will always be 1.")]
+ #[deprecated(since = "0.7.0", note = "The queues will always be 1.")]
pub fn queues(&mut self, value: usize) -> &mut Self {
self.queues = Some(value);
self
diff --git a/src/platform/freebsd/device.rs b/src/platform/freebsd/device.rs
index cc589442..4a402b7a 100644
--- a/src/platform/freebsd/device.rs
+++ b/src/platform/freebsd/device.rs
@@ -110,7 +110,7 @@ impl Device {
}
use std::io::ErrorKind::AlreadyExists;
let info = "no avaiable file descriptor";
- return Err(Error::Io(std::io::Error::new(AlreadyExists, info).into()));
+ return Err(Error::Io(std::io::Error::new(AlreadyExists, info)));
};
(tun, device_name)
}
@@ -174,7 +174,7 @@ impl Device {
let route = Route {
addr,
netmask: mask,
- dest: dest,
+ dest,
};
if let Err(e) = self.set_route(route) {
log::warn!("{e:?}");
@@ -345,8 +345,8 @@ impl AbstractDevice for Device {
fn set_address(&mut self, value: IpAddr) -> Result<()> {
unsafe {
- let mut req = self.request();
- if let Err(err) = siocdifaddr(self.ctl.as_raw_fd(), &mut req) {
+ let req = self.request();
+ if let Err(err) = siocdifaddr(self.ctl.as_raw_fd(), &req) {
return Err(std::io::Error::from(err).into());
}
let previous = self.route.as_ref().ok_or(Error::InvalidConfig)?;
@@ -372,8 +372,8 @@ impl AbstractDevice for Device {
fn set_destination(&mut self, value: IpAddr) -> Result<()> {
unsafe {
- let mut req = self.request();
- if let Err(err) = siocdifaddr(self.ctl.as_raw_fd(), &mut req) {
+ let req = self.request();
+ if let Err(err) = siocdifaddr(self.ctl.as_raw_fd(), &req) {
return Err(std::io::Error::from(err).into());
}
let previous = self.route.as_ref().ok_or(Error::InvalidConfig)?;
@@ -415,8 +415,8 @@ impl AbstractDevice for Device {
fn set_netmask(&mut self, value: IpAddr) -> Result<()> {
unsafe {
- let mut req = self.request();
- if let Err(err) = siocdifaddr(self.ctl.as_raw_fd(), &mut req) {
+ let req = self.request();
+ if let Err(err) = siocdifaddr(self.ctl.as_raw_fd(), &req) {
return Err(std::io::Error::from(err).into());
}
let previous = self.route.as_ref().ok_or(Error::InvalidConfig)?;
diff --git a/src/platform/freebsd/sys.rs b/src/platform/freebsd/sys.rs
index 00f319c9..c8610372 100644
--- a/src/platform/freebsd/sys.rs
+++ b/src/platform/freebsd/sys.rs
@@ -17,7 +17,7 @@
use libc::{c_char, c_int, c_uint, ifreq, sockaddr, IFNAMSIZ};
use nix::{ioctl_readwrite, ioctl_write_ptr};
-#[allow(non_camel_case_types)]
+#[allow(non_camel_case_types, dead_code)]
#[repr(C)]
#[derive(Copy, Clone)]
pub struct ctl_info {
diff --git a/src/platform/linux/mod.rs b/src/platform/linux/mod.rs
index 76566d99..5c51c7d0 100644
--- a/src/platform/linux/mod.rs
+++ b/src/platform/linux/mod.rs
@@ -53,9 +53,10 @@ impl PlatformConfig {
/// Enable or disable packet information, the first 4 bytes of
/// each packet delivered from/to Linux underlying API is a header with flags and protocol type when enabled.
///
- /// [Note: This configuration just applies to the Linux underlying API and is a no-op on tun(i.e. the packets delivered from/to tun always contain no packet information) -- end note].
+ /// [Note: This configuration just applies to the Linux underlying API and is a no-op on `tun` crate
+ /// (i.e. the packets delivered from/to `tun` crate must always NOT contain packet information) -- end note].
#[deprecated(
- since = "1.0.0",
+ since = "0.7.0",
note = "No effect applies to the packets delivered from/to tun since the packets always contain no header on all platforms."
)]
pub fn packet_information(&mut self, value: bool) -> &mut Self {
diff --git a/src/platform/mod.rs b/src/platform/mod.rs
index 42cab78c..8da9a3ed 100644
--- a/src/platform/mod.rs
+++ b/src/platform/mod.rs
@@ -16,6 +16,8 @@
#[cfg(unix)]
pub(crate) mod posix;
+#[cfg(unix)]
+pub use posix::{Reader, Writer};
#[cfg(all(target_os = "linux", not(target_env = "ohos")))]
pub(crate) mod linux;
@@ -54,7 +56,7 @@ pub use crate::platform::posix::Tun;
#[cfg(target_os = "windows")]
pub(crate) mod windows;
#[cfg(target_os = "windows")]
-pub use self::windows::{create, Device, PlatformConfig, Tun};
+pub use self::windows::{create, Device, PlatformConfig, Reader, Tun, Writer};
#[cfg(test)]
mod test {
diff --git a/src/platform/posix/mod.rs b/src/platform/posix/mod.rs
index 02d44866..86aabb48 100644
--- a/src/platform/posix/mod.rs
+++ b/src/platform/posix/mod.rs
@@ -15,11 +15,8 @@
//! POSIX compliant support.
mod sockaddr;
-#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "macos"))]
-pub(crate) use sockaddr::sockaddr_union;
-
-#[cfg(any(target_os = "linux", target_os = "macos"))]
-pub(crate) use sockaddr::ipaddr_to_sockaddr;
+#[allow(unused_imports)]
+pub(crate) use sockaddr::{ipaddr_to_sockaddr, sockaddr_union};
mod fd;
pub(crate) use self::fd::Fd;
diff --git a/src/platform/posix/sockaddr.rs b/src/platform/posix/sockaddr.rs
index 625dc327..304f9819 100644
--- a/src/platform/posix/sockaddr.rs
+++ b/src/platform/posix/sockaddr.rs
@@ -60,7 +60,7 @@ fn rs_addr_to_sockaddr(addr: std::net::SocketAddr) -> sockaddr_union {
/// # Safety
/// Fill the `addr` with the `src_addr` and `src_port`, the `size` should be the size of overwriting
-#[cfg(any(target_os = "linux", target_os = "macos"))]
+#[allow(dead_code)]
pub(crate) unsafe fn ipaddr_to_sockaddr(
src_addr: T,
src_port: u16,
diff --git a/src/platform/windows/mod.rs b/src/platform/windows/mod.rs
index 7be864f0..dbcdd38b 100644
--- a/src/platform/windows/mod.rs
+++ b/src/platform/windows/mod.rs
@@ -20,7 +20,7 @@ use crate::configuration::Configuration;
use crate::error::Result;
#[cfg(feature = "async")]
pub use device::Driver;
-pub use device::{Device, Tun};
+pub use device::{Device, Reader, Tun, Writer};
use std::ffi::OsString;
/// Windows-only interface configuration.