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

Support for outbound interface selection #306

Closed
slashbeast opened this issue Feb 22, 2023 · 5 comments · Fixed by #307
Closed

Support for outbound interface selection #306

slashbeast opened this issue Feb 22, 2023 · 5 comments · Fixed by #307

Comments

@slashbeast
Copy link

Hi,

Would it be possible to add support for selecting outbound interface, much like curl's --interface option?

This would be useful on systems with multiple gateways, like multi WAN where there's more than single default gateway based on source address or when one uses opt-in VPN connections.

In my very case I have multiple wireguard VPNs connected at the same time with default gateway set in each separated routing tables, and simple set of ip rule add from $VPN1_IP table $VPN1_TABLE, that I use to test access to cloud resources from different physical location around the world. This is currently not possible directly with xh and requires me to have set of tinyproxy running in background each with different bind interface for xh to go via desired route. Would be great if I could just use --interface instead.

@ducaale
Copy link
Owner

ducaale commented Feb 22, 2023

What value would you like to pass to --interface? from cURL docs, I see that it accepts either interface name, IP address or host name.

We can add support for --interface <ip-address> by making use of reqwests's hyper's set_local_address. However, --interface <interface-name> is yet to be supported by hyper-rs. See hyperium/hyper#3076 and seanmonstar/reqwest#1336

@slashbeast
Copy link
Author

I am okay with any of those. If I had option to choose I'd go with interface name, but setting the outbound local IP also works for me. iproute2 does have --json output so I can hack some script that I could use like xh --interface $(if-to-ip wg-relay4) .... that would just go over JSON from ip --json address show to figure out what local IP has the given interface, and return the IP.

The GNU wget also only supports binding to IP via --bind-address and have no smarts to specify interface instead, I think this is fully sufficient feature, though in this case perhaps --bind-address makes more sense than --interface as the switch unless you want later to add the interface selection, once those are supported by hyper bindings.

@ducaale
Copy link
Owner

ducaale commented Feb 25, 2023

I am leaning more towards mimicking cURL and only having the --interface option.

I can hack some script that I could use like xh --interface $(if-to-ip wg-relay4) .... that would just go over JSON from ip --json address show to figure out what local IP has the given interface, and return the IP.

Actually, we could let xh handle the interface to local IP mapping. Of course, this is a temporary solution since some users will sooner or later run into seanmonstar/reqwest#1336.

@ducaale
Copy link
Owner

ducaale commented Feb 25, 2023

@slashbeast I would like to know if #307 works for your use case (CI is failing due to MSRV policy which we can ignore for now)

$ cargo run -- --interface wg-relay4 https://ipinfo.io/ip

@slashbeast
Copy link
Author

All good, the build out of interface-option works exactly as I would expect curl --interface to work. Thanks for the feature!

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

Successfully merging a pull request may close this issue.

2 participants