decathorpe/mitmproxy_wireguard

Binding on both IPv4 and IPv6 does not work

ItsShadowCone opened this issue · 3 comments

Leaving the host empty defaults to binding to both 0.0.0.0 and ::1. However, rust's UDPSocket doesn't bind to both, it binds to the first successful.

Happens here: https://github.com/decathorpe/mitmproxy_wireguard/blob/main/src/server.rs#L125..L135
Documentation here: https://doc.rust-lang.org/std/net/struct.UdpSocket.html#method.bind

Best fix is probably to just support a single listen address, since multiple listen sockets opens another can of worms.

Oh, I could swear that I read the documentation when I changed this ... (i.e. here b168977 ), but you're right, tokio's UdpSocket binds to the first successful one, so the change I made in that commit was just wrong.

What should be default to if the argument is empty, though? Probably 0.0.0.0? Defaulting to IPv6 doesn't seem like a good idea.

Uh...... either this https://stackoverflow.com/a/1618259, but that's probably effort (dunno if tokio supports it out of the box) (i.e. supply [::1, 0.0.0.0] to the bind + the relevant options to allow ipv4 on the ipv6 bind (if it's successful), and take it from there..... supports ipv4 and ipv6 if possible, and should fall back to ipv4 if ipv6 is disabled)

or just 0.0.0.0, but make it obvious in the log output.

or just don't offer a default, only two examples (for 0.0.0.0 and ::1).