Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
ssrlive authored Nov 30, 2024
2 parents 974cab5 + 8d3c6c6 commit ca0d0a6
Show file tree
Hide file tree
Showing 12 changed files with 107 additions and 28 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/freebsd.yml
Original file line number Diff line number Diff line change
@@ -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
33 changes: 32 additions & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
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
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

<a href="https://github.com/meh/rust-tun/graphs/contributors">
<img src="https://contrib.rocks/image?repo=meh/rust-tun" />
</a>
12 changes: 6 additions & 6 deletions src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl ToAddress for str {
}
}

impl<'a> ToAddress for &'a str {
impl ToAddress for &str {
fn to_address(&self) -> Result<IpAddr> {
(*self).to_address()
}
Expand All @@ -63,7 +63,7 @@ impl ToAddress for String {
}
}

impl<'a> ToAddress for &'a String {
impl ToAddress for &String {
fn to_address(&self) -> Result<IpAddr> {
self.as_str().to_address()
}
Expand All @@ -75,7 +75,7 @@ impl ToAddress for Ipv4Addr {
}
}

impl<'a> ToAddress for &'a Ipv4Addr {
impl ToAddress for &Ipv4Addr {
fn to_address(&self) -> Result<IpAddr> {
(*self).to_address()
}
Expand All @@ -87,7 +87,7 @@ impl ToAddress for IpAddr {
}
}

impl<'a> ToAddress for &'a IpAddr {
impl ToAddress for &IpAddr {
fn to_address(&self) -> Result<IpAddr> {
(*self).to_address()
}
Expand All @@ -99,7 +99,7 @@ impl ToAddress for SocketAddrV4 {
}
}

impl<'a> ToAddress for &'a SocketAddrV4 {
impl ToAddress for &SocketAddrV4 {
fn to_address(&self) -> Result<IpAddr> {
(*self).to_address()
}
Expand All @@ -111,7 +111,7 @@ impl ToAddress for SocketAddr {
}
}

impl<'a> ToAddress for &'a SocketAddr {
impl ToAddress for &SocketAddr {
fn to_address(&self) -> Result<IpAddr> {
(*self).to_address()
}
Expand Down
4 changes: 2 additions & 2 deletions src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<S: AsRef<str>>(&mut self, tun_name: S) -> &mut Self {
Expand Down Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions src/platform/freebsd/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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:?}");
Expand Down Expand Up @@ -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)?;
Expand All @@ -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)?;
Expand Down Expand Up @@ -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)?;
Expand Down
2 changes: 1 addition & 1 deletion src/platform/freebsd/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions src/platform/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion src/platform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 2 additions & 5 deletions src/platform/posix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/platform/posix/sockaddr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(
src_addr: T,
src_port: u16,
Expand Down
2 changes: 1 addition & 1 deletion src/platform/windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit ca0d0a6

Please sign in to comment.