From eafaa55e63562ce0ba4a2ba2aec6acd305e60d50 Mon Sep 17 00:00:00 2001 From: zonyitoo Date: Tue, 10 Oct 2023 19:52:27 +0800 Subject: [PATCH] fix(local): local-tun Device::name now returns Result --- crates/shadowsocks-service/src/local/tun/mod.rs | 6 +++++- .../src/local/tun/sys/unix/apple/macos.rs | 13 +++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/crates/shadowsocks-service/src/local/tun/mod.rs b/crates/shadowsocks-service/src/local/tun/mod.rs index 0860e21a..aa18581d 100644 --- a/crates/shadowsocks-service/src/local/tun/mod.rs +++ b/crates/shadowsocks-service/src/local/tun/mod.rs @@ -143,7 +143,11 @@ impl Tun { info!( "shadowsocks tun device {}, mode {}", - self.device.get_ref().name(), + self.device + .get_ref() + .name() + .or_else(|r| Ok::<_, ()>(r.to_string())) + .unwrap(), self.mode, ); diff --git a/crates/shadowsocks-service/src/local/tun/sys/unix/apple/macos.rs b/crates/shadowsocks-service/src/local/tun/sys/unix/apple/macos.rs index c31b9855..4698554f 100644 --- a/crates/shadowsocks-service/src/local/tun/sys/unix/apple/macos.rs +++ b/crates/shadowsocks-service/src/local/tun/sys/unix/apple/macos.rs @@ -1,12 +1,11 @@ use std::{ ffi::CStr, io::{self, ErrorKind}, - mem, - ptr, + mem, ptr, }; use log::{error, trace}; -use tun::{platform::Device as TunDevice, Device}; +use tun::{platform::Device as TunDevice, Device, Error as TunError}; /// These numbers are used by reliable protocols for determining /// retransmission behavior and are included in the routing structure. @@ -75,7 +74,13 @@ pub async fn set_route_configuration(device: &TunDevice) -> io::Result<()> { } }; - let tun_name = device.name(); + let tun_name = match device.name() { + Ok(n) => n, + Err(err) => match err { + TunError::Io(err) => return Err(err), + e => return Err(io::Error::new(ErrorKind::Other, e)), + }, + }; // routing packets that saddr & daddr are in the subnet of the Tun interface //