Use narrower type to fix possible panic with IPv6 address argument #6498
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a further cleanup following some discoveries I made when working with your PSK exchange.
As already written during PR #6477, calling
psk-exchange
or more specificallytalpid_tunnel_config_client::request_ephemeral_peer
with an IPv6 resulted in anEAFNOSUPPORT
error.With the current program it never makes sense to pass an
Ipv6Addr
torequest_ephemeral_peer
, since it can't handle an IPv6 connection even if the tunnel configuration service was listening to an IPv6.There are two locations where
request_ephemeral_peer
is called. One of them is intalpid-wireguard/src/lib.rs
, the other one is in thepsk-exchange
example.Since the address is statically set to the IPv4 gateway in the former case, presently the only possible case for problems to happen was if someone entered an IPv6 when using the example.
I already disabled the possibility to enter such an address as part of the linked PR, but it still is a wart and it would not feel right to leave it in this faulty way.
So I had to decide whether to fix the IPv6 connectivity or to disable it.
I modified
talpid-tunnel-config-client/src/lib.rs
andtalpid-tunnel-config-client/examples/psk-exchange
to work with an IPv6 and then calledpsk-exchange
withfc00:bbbb:bbbb:bb01::1
(the IPv6 gateway address) which failed withECONNREFUSED
. This seems to suggest that the tunnel configuration service is not listening to an IPv6 (at least not on that address and on port 1337, which would be the expected location.)I tested
psk-exchange
just as described in my other PR and I did not know how to dedicatedly testtalpid-wireguard/src/lib.rs
but it compiles and the test suite (cargo test -p talpid-wireguard
[it turns out that I did not properly call the tests at first, but I did now and with the patch from #6497 applied]) also finishes successfully. Since the input is static, I don't see any possible problem here.If at some later point you decide to refactor this to support IPv6 it would probably be easiest to look at the passed
IpAddr
, check whether it is IPv4 or IPv6 and create an according socket.Theoretically you could use an IPv6 socket to make IPv4 connections but the socket option
IPV6_V6ONLY
has to be disabled and this would turn into a portability nightmare and also has some security implications, so I'd recommend against it.This change is