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

Protocol not available (os error 92) when using IPv4 #63

Closed
bugnano opened this issue Sep 23, 2023 · 5 comments
Closed

Protocol not available (os error 92) when using IPv4 #63

bugnano opened this issue Sep 23, 2023 · 5 comments
Assignees

Comments

@bugnano
Copy link

bugnano commented Sep 23, 2023

I'm trying to implement the code sample described in #50 , so I'm using this code:

    let addrs_iter = (host, port).to_socket_addrs()?;

            let endpoints = addrs_iter
                .map(|bind_address| {
                    info!("bind_address: {:?}", bind_address);
                    info!("is_ipv4: {:?}", bind_address.is_ipv4());
                    info!("is_ipv6: {:?}", bind_address.is_ipv6());

                    let config = ServerConfig::builder()
                        .with_bind_address(bind_address, false)
                        .with_certificate(Certificate::load(&certfile, &keyfile)?)
                        .keep_alive_interval(Some(Duration::from_secs(3)))
                        .build();

                    Endpoint::server(config)
                })
                .collect::<Result<Vec<Endpoint<Server>>, std::io::Error>>()

host is set to "localhost" and port is set to 4433.

The IPv6 part binds fine, but the IPv4 part errors out with:

2023-09-23T07:41:03.618411Z  INFO wtransport_native: bind_address: 127.0.0.1:4433
2023-09-23T07:41:03.618422Z  INFO wtransport_native: is_ipv4: true
2023-09-23T07:41:03.618427Z  INFO wtransport_native: is_ipv6: false
2023-09-23T07:41:03.619096Z ERROR wtransport_native: "Protocol not available (os error 92)"

I tried changing the IPV6ONLY flag from false to true, but it didn't change anything.

I also tried to set host to ::1, and it works fine by binding only to IPv6 localhost, an I also tried to set host to 127.0.0.1, and it errors out with the same error.

My OS is Fedora 38 x86_64, if that could help.

btw. IPv4 localhost UDP binding is supported on my OS, the output of ss -ulpen also reports:

udp        UNCONN      0           0                   127.0.0.54:53                     0.0.0.0:*          uid:193 ino:23014 sk:1 cgroup:/system.slice/systemd-resolved.service <->               

Which has noting to do with wtransport, but shows that it's possible to bind an UDP socket to 127.0.0.1 on my system

@BiagioFesta
Copy link
Owner

A new release has been just published (really a few seconds ago :) ): https://github.com/BiagioFesta/wtransport/releases/tag/0.1.5

Can you please try with the latest release?

Please also note that the API has been slightly changed (also thanks to your suggestions), so now there are 2 methods if you need to bind a "custom" address:

Please let me know if the latest version fixes the issue and if you have any feedback on the new API

@bugnano
Copy link
Author

bugnano commented Sep 23, 2023

Now compilation fails, because in the closure

Certificate::load(&certfile, &keyfile)?

may return an error of type wtransport::tls::CertificateLoadError, while

Endpoint::server(config)

may return an error of type std::io::Error, so I cannot collect anymore to a type of std::io::Error.

@BiagioFesta
Copy link
Owner

Anyway, FYI: the issue was because of old API was allowing specifying only_ipv6 also for ipv4 address.

.with_bind_address(bind_address, false)

fails when bind_address is ipv4 address, because false tries to force dual-stack (which is not available, hence the "protocol not available" error)

The new API is more robust and does not allow "bad" combo at compile time

@BiagioFesta
Copy link
Owner

may return an error of type wtransport::tls::CertificateLoadError [...]

Yeah that was also an improvement in the API. Configuration builder had an .unwrap() in old wtransport version. Now, the validation of content of certificate is properly checked.

That required another error specification tho (which is not i/o, but validation on content).

In order to solve the compilation error is pretty easy I guess. It depends on your application, but, for instance, you can map the error

@BiagioFesta BiagioFesta self-assigned this Sep 23, 2023
@bugnano
Copy link
Author

bugnano commented Sep 23, 2023

Awesome, the new version works well, great job😀

@bugnano bugnano closed this as completed Sep 23, 2023
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