Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ibigbug committed Dec 26, 2023
1 parent 4c1e111 commit 4f686fe
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 7 deletions.
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion clash_lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ tun = { git = "https://github.com/Watfaq/rust-tun.git", rev = "8f7568190f1200d3e
netstack-lwip = { git = "https://github.com/Watfaq/netstack-lwip.git", rev = "2817bf82740e04bbee6b7bf1165f55657a6ed163" }

boringtun = { version = "0.6.0" }
smoltcp = { version = "0.10", default-features = false, features = ["std", "log", "medium-ip", "proto-ipv4", "proto-ipv6", "socket-udp", "socket-tcp"] }
smoltcp = { path = "../../../gallery/smoltcp", version = "0.10", default-features = false, features = ["std", "log", "medium-ip", "proto-ipv4", "proto-ipv6", "socket-udp", "socket-tcp"] }


serde = { version = "1.0", features=["derive"] }
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions clash_lib/src/proxy/tun/lwip/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pub mod datagram;
pub mod inbound;

pub use netstack_lwip as netstack;
8 changes: 4 additions & 4 deletions clash_lib/src/proxy/tun/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub mod inbound;
pub use netstack_lwip as netstack;
mod datagram;
pub use inbound::get_runner as get_tun_runner;
mod lwip;
mod smoltcp;

pub use lwip::inbound::get_runner as get_tun_runner;
42 changes: 42 additions & 0 deletions clash_lib/src/proxy/tun/smoltcp/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use std::sync::Arc;

use url::Url;

use crate::{
app::{dispatcher::Dispatcher, dns::ThreadSafeDNSResolver},
config::internal::config::TunConfig,
Error, Runner,
};

pub fn get_runner(
cfg: TunConfig,
dispatcher: Arc<Dispatcher>,
resolver: ThreadSafeDNSResolver,
) -> Result<Option<Runner>, Error> {
let device_id = cfg.device_id;

let u =
Url::parse(&device_id).map_err(|x| Error::InvalidConfig(format!("tun device {}", x)))?;

let device = match u.scheme() {
"fd" => {
let fd = u
.host()
.expect("tun fd must be provided")
.to_string()
.parse()
.map_err(|x| Error::InvalidConfig(format!("tun fd {}", x)))?;
TunTapInterface::from_fd(fd)?
}
"dev" => {
let dev = u.host().expect("tun dev must be provided").to_string();
tun_cfg.name(dev);
}
_ => {
return Err(Error::InvalidConfig(format!(
"invalid device id: {}",
device_id
)));
}
};
}

0 comments on commit 4f686fe

Please sign in to comment.