diff --git a/.cargo/config b/.cargo/config index 7885b5964..7b920f9fe 100644 --- a/.cargo/config +++ b/.cargo/config @@ -4,4 +4,4 @@ rustflags = ["--cfg", "tokio_unstable"] [env] BORING_BSSL_SOURCE_PATH = { value = "deps/boringssl/src", relative = true} -RUST_LOG= { value = "clash=trace" } \ No newline at end of file +RUST_LOG = { value = "clash=trace" } \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 23bc30482..50ef0146a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4133,7 +4133,7 @@ checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" [[package]] name = "tun" version = "0.5.5" -source = "git+https://github.com/Watfaq/rust-tun.git?rev=5c0702b#5c0702bb0d0b2b605fdfdbd98bccff9951ad197d" +source = "git+https://github.com/Watfaq/rust-tun.git?rev=28936b6#28936b689871d31555e5691bd86fb2c4cefd394c" dependencies = [ "byteorder", "bytes", diff --git a/clash/tests/data/config/rules.yaml b/clash/tests/data/config/rules.yaml index f466897c6..57deb77bf 100644 --- a/clash/tests/data/config/rules.yaml +++ b/clash/tests/data/config/rules.yaml @@ -4,7 +4,7 @@ socks-port: 8889 mixed-port: 8899 tun: - enable: false + enable: true device-id: "dev://utun1989" dns: diff --git a/clash_lib/Cargo.toml b/clash_lib/Cargo.toml index 8dfc4a6e0..e65a9c175 100644 --- a/clash_lib/Cargo.toml +++ b/clash_lib/Cargo.toml @@ -59,7 +59,7 @@ axum = { version = "0.6.20", features = ["ws"] } tower-http = { version = "0.4.0", features = ["fs", "trace", "cors"] } chrono = { version = "0.4.26", features = ["serde"] } -tun = { git = "https://github.com/Watfaq/rust-tun.git", rev = "5c0702b", features = ["async"] } +tun = { git = "https://github.com/Watfaq/rust-tun.git", rev = "28936b6", features = ["async"] } netstack-lwip = { git = "https://github.com/Watfaq/netstack-lwip.git", rev = "8c8c0b0" } boringtun = { version = "0.6.0", features = ["device"] } diff --git a/clash_lib/src/app/dispatcher/dispatcher.rs b/clash_lib/src/app/dispatcher/dispatcher.rs index 042a89166..41f2efbdf 100644 --- a/clash_lib/src/app/dispatcher/dispatcher.rs +++ b/clash_lib/src/app/dispatcher/dispatcher.rs @@ -193,6 +193,7 @@ impl Dispatcher { let (remote_receiver_w, mut remote_receiver_r) = tokio::sync::mpsc::channel(32); let s = sess.clone(); + let ss = sess.clone(); let t1 = tokio::spawn(async move { while let Some(packet) = local_r.next().await { let mut sess = sess.clone(); @@ -340,8 +341,11 @@ impl Dispatcher { }, }; } + + trace!("UDP session local -> remote finished for {}", ss); }); + let ss = s.clone(); let t2 = tokio::spawn(async move { while let Some(packet) = remote_receiver_r.recv().await { match local_w.send(packet.clone()).await { @@ -354,6 +358,7 @@ impl Dispatcher { } } } + trace!("UDP session remote -> local finished for {}", ss); }); let (close_sender, close_receiver) = tokio::sync::oneshot::channel::(); diff --git a/clash_lib/src/app/dns/server/mod.rs b/clash_lib/src/app/dns/server/mod.rs index cdabda4f3..4549e45d0 100644 --- a/clash_lib/src/app/dns/server/mod.rs +++ b/clash_lib/src/app/dns/server/mod.rs @@ -132,6 +132,10 @@ impl RequestHandler for DnsHandler { static DEFAULT_DNS_SERVER_TIMEOUT: Duration = Duration::from_secs(5); pub async fn get_dns_listener(cfg: Config, resolver: ThreadSafeDNSResolver) -> Option { + if !cfg.enable { + return None; + } + let h = DnsHandler { resolver }; let mut s = ServerFuture::new(h); diff --git a/clash_lib/src/app/logging.rs b/clash_lib/src/app/logging.rs index a7fadbb25..557dd7109 100644 --- a/clash_lib/src/app/logging.rs +++ b/clash_lib/src/app/logging.rs @@ -99,7 +99,6 @@ pub fn setup_logging(level: LogLevel, collector: EventCollector) -> anyhow::Resu }; let subscriber = tracing_subscriber::registry() - .with(ios_os_log) .with(jaeger) .with(filter) .with(collector) @@ -110,7 +109,8 @@ pub fn setup_logging(level: LogLevel, collector: EventCollector) -> anyhow::Resu .with_file(true) .with_line_number(true) .with_writer(std::io::stdout), - ); + ) + .with(ios_os_log); let v = tracing::subscriber::set_global_default(subscriber) .map_err(|x| anyhow!("setup logging error: {}", x))?; diff --git a/clash_lib/src/app/outbound/manager.rs b/clash_lib/src/app/outbound/manager.rs index 73fd7eedb..e198c0182 100644 --- a/clash_lib/src/app/outbound/manager.rs +++ b/clash_lib/src/app/outbound/manager.rs @@ -2,6 +2,7 @@ use anyhow::Result; use erased_serde::Serialize; use http::Uri; use std::collections::HashMap; +use std::path::PathBuf; use std::sync::Arc; use std::time::Duration; use tokio::sync::{Mutex, RwLock}; @@ -591,7 +592,12 @@ impl OutboundManager { provider_registry.insert(name, Arc::new(RwLock::new(provider))); } OutboundProxyProviderDef::File(file) => { - let vehicle = file_vehicle::Vehicle::new(&file.path); + let vehicle = file_vehicle::Vehicle::new( + PathBuf::from(cwd.clone()) + .join(&file.path) + .to_str() + .unwrap(), + ); let hc = HealthCheck::new( vec![], file.health_check.url, @@ -616,14 +622,11 @@ impl OutboundManager { for p in provider_registry.values() { info!("initializing provider {}", p.read().await.name()); - match p.write().await.initialize().await { + let p = p.write().await; + match p.initialize().await { Ok(_) => {} Err(err) => { - error!( - "failed to initialize proxy provider {}: {}", - p.read().await.name(), - err - ); + error!("failed to initialize proxy provider {}: {}", p.name(), err); } } } diff --git a/clash_lib/src/app/router/mod.rs b/clash_lib/src/app/router/mod.rs index 5a02d84ee..8743cb67d 100644 --- a/clash_lib/src/app/router/mod.rs +++ b/clash_lib/src/app/router/mod.rs @@ -12,6 +12,7 @@ use crate::session::{Session, SocksAddr}; use crate::app::router::rules::final_::Final; use std::collections::HashMap; +use std::path::PathBuf; use std::sync::Arc; use std::time::Duration; @@ -133,7 +134,12 @@ impl Router { rule_provider_registry.insert(name, Arc::new(provider)); } RuleProviderDef::File(file) => { - let vehicle = file_vehicle::Vehicle::new(&file.path); + let vehicle = file_vehicle::Vehicle::new( + PathBuf::from(cwd.clone()) + .join(&file.path) + .to_str() + .unwrap(), + ); let provider = RuleProviderImpl::new( name.clone(), diff --git a/clash_lib/src/proxy/tun/inbound.rs b/clash_lib/src/proxy/tun/inbound.rs index 30fda2740..d4b42d5b5 100644 --- a/clash_lib/src/proxy/tun/inbound.rs +++ b/clash_lib/src/proxy/tun/inbound.rs @@ -110,6 +110,7 @@ async fn handle_inbound_datagram( } } } + closer.send(0).ok(); }); } @@ -120,6 +121,7 @@ pub fn get_runner( resolver: ThreadSafeDNSResolver, ) -> Result, Error> { if !cfg.enable { + trace!("tun is disabled"); return Ok(None); }