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

How to route all traffic to a specified tun device by using this library? #8

Closed
xmh0511 opened this issue Dec 7, 2023 · 6 comments
Closed

Comments

@xmh0511
Copy link

xmh0511 commented Dec 7, 2023

How do I achieve this target by using this crate? Honestly, the documentation is lack, I don't know how to do.

@johnyburd
Copy link
Owner

You might first want to determine the ifindex since the library doesn't currently support specifying interfaces by name #7, for example with this function: https://www.man7.org/linux/man-pages/man3/if_nametoindex.3.html

let tun_ifindex: u32 = 3;

let handle = Handle::new()?;
let route = Route::new("0.0.0.0".parse().unwrap(), 0).with_ifindex(tun_ifindex);
handle.add(&route).await

@xmh0511
Copy link
Author

xmh0511 commented Jan 12, 2024

You might first want to determine the ifindex since the library doesn't currently support specifying interfaces by name #7, for example with this function: https://www.man7.org/linux/man-pages/man3/if_nametoindex.3.html

let tun_ifindex: u32 = 3;

let handle = Handle::new()?;
let route = Route::new("0.0.0.0".parse().unwrap(), 0).with_ifindex(tun_ifindex);
handle.add(&route).await

Thanks. But, what should I do on the Windows platform? IMO, Windows does not have an interface index.

Does with_ifindex still work on the Windows platform when geting if_index with https://microsoft.github.io/windows-docs-rs/doc/windows/Win32/NetworkManagement/IpHelper/fn.if_nametoindex.html

@xmh0511
Copy link
Author

xmh0511 commented Jan 12, 2024

@johnyburd handle.add(&route).await just return the error:

Err(Custom { kind: AlreadyExists, error: "rtm_errno 17" })
index.crates.io-6f17d22bba15001f/net-route-0.2.11/src/platform_impl/macos/macos.rs:254:25:
index out of bounds: the len is 12 but the index is 12
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

@johnyburd
Copy link
Owner

yes Route::with_ifindex is supported on windows.

I'm not able to tell what's wrong in the snipped you posted from macos. I would need a minimum reproduction of the error and perhaps a dump of your routing table.

@xmh0511
Copy link
Author

xmh0511 commented Jan 15, 2024

yes Route::with_ifindex is supported on windows.

I'm not able to tell what's wrong in the snipped you posted from macos. I would need a minimum reproduction of the error and perhaps a dump of your routing table.

It's here #15 (comment)

@johnyburd
Copy link
Owner

Closing in favor of #7

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