shadowsocks-rust
shadowsocks-rust copied to clipboard
Tun cannot be configured with raw fd
I have configured utun manually and now basically turning it into raw file descriptor. But then SS creates a new tunnel device configured to 10.0.0.1 ignoring the tun_device_fd setting.
let tun_fd = my_tun_device.as_raw_fd();
let mut local_config = LocalConfig::new(ProtocolType::Tun);
local_config.mode = Mode::TcpAndUdp;
local_config.tun_device_fd = Some(tun_fd);
let server_addr = ServerAddr::SocketAddr(SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::LOCALHOST, 10069,)));
let mut server_config = ServerConfig::new(server_addr, "", CipherKind::NONE);
server_config.set_mode(Mode::TcpAndUdp);
let local_instance_config = LocalInstanceConfig::with_local_config(local_config);
let server_instance_config = ServerInstanceConfig::with_server_config(server_config);
let mut ss_config = Config::new(ConfigType::Local);
ss_config.local = vec![local_instance_config];
ss_config.server = vec![server_instance_config];
ss_config.dns = DnsConfig::System;
shadowsocks_service::run_local(ss_config).await
tun_device_fd was passed correctly to the builder:
https://github.com/shadowsocks/shadowsocks-rust/blob/65eb758ad426250f358a647ec99baab8fea722d8/crates/shadowsocks-service/src/local/mod.rs#L428-L429
which will be set to the tun_config:
https://github.com/shadowsocks/shadowsocks-rust/blob/65eb758ad426250f358a647ec99baab8fea722d8/crates/shadowsocks-service/src/local/tun/mod.rs#L70-L73
So the problem is: why tun didn't use the provided raw_fd?
Just look through https://github.com/meh/rust-tun/tree/master/src/platform , I realized that only iOS supports the raw_fd configuration. :(
@zonyitoo darn that explains a lot! Thanks for digging. tun crate seems to be quite out of date and there aren’t any viable alternatives from what I know. Perhaps I will patch it one day. Lotta other things on my radar these days.
https://github.com/tun2proxy/rust-tun/blob/209c8c190eace34a9db729edfd7e6be30e8a3461/src/platform/android/device.rs#L46-L49
Just switched to tun2, and it supports Android, macOS now.