Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tun cannot be configured with raw fd #1433

Open
pronebird opened this issue Feb 10, 2024 · 2 comments
Open

Tun cannot be configured with raw fd #1433

pronebird opened this issue Feb 10, 2024 · 2 comments

Comments

@pronebird
Copy link

pronebird commented Feb 10, 2024

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
@zonyitoo
Copy link
Collaborator

tun_device_fd was passed correctly to the builder:

if let Some(fd) = local_config.tun_device_fd {
builder.file_descriptor(fd);

which will be set to the tun_config:

#[cfg(unix)]
pub fn file_descriptor(&mut self, fd: RawFd) {
self.tun_config.raw_fd(fd);
}

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. :(

@pronebird
Copy link
Author

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants