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

curl: bind failed with errno 22: Invalid argument when using binding interface for IPv6 link-scope address #14782

Open
adeadman opened this issue Sep 4, 2024 · 0 comments · May be fixed by #15165

Comments

@adeadman
Copy link

adeadman commented Sep 4, 2024

I did this

When using a link-scope ipv6 address (based on hardware address and only addressable from the link neighbours, not globally), I have to specify the interface to bind. After looking at #3993 (which I believe was looking at a related issue), I tried this:

curl --interface eth0 -vg -6 'http://[fe80:928d:xxff:fexx:xxxx]:8080/healthz'

(this is the link-local ipv6 address on the network interface of another machine on the same LAN, which works over IPv4).

I expected the following

It should have successfully bound to the eth0 interface and made the connection, but instead I got the following:

*    Trying [fe80::928d:xxff:fexx:xxxx]:8080...
* Local Interface eth0 is ip fe80::ec4:xxff:fexx:xxx%2 using address family 10
* Name 'fe80::ec4:xxff:fexx:xxx' family 10 resolved to 'fe80::ec4:xxff:fexx:xxx' family 10
* bind failed with errno 22: Invalid argument
* Failed to connect to fe80::928d:xxff:fexx:xxxx port 8080 after 0ms: Failed binding local connection end
* closing connection #0
curl: (45) bind failed with errno 22: Invalid argument

I suspect it is trying to bind to the local interface with an ipv4 socket even though the address and protocol for the remote end is ipv6, but I don't really know (hence why the reference to #3993 ).

I know the connection is working as ping6 -I eth0 fe80::928d:xxff:fexx:xxxx binds and sends/receives the packets.

possible workaround

I can work around this --interface specification by using the interface scope in the URI - this works as expected:

curl -vg -6 'http://[fe80::928d:xxff:fexx:xxxx%eth0]:8080/healthz'
*    Trying [fe80::928d:xxff:fexx:xxxx]:8080...
* Connected to fe80::928d:xxff:fexx:xxxx (fe80::928d:xxff:fexx:xxxx) port 8080
> GET /healthz HTTP/1.1
> Host: [fe80::928d:xxff:fexx:xxxx]:8080
> User-Agent: curl/8.9.1
> Accept: */*
>
* Request completely sent off
< HTTP/1.1 200 OK
< Content-Length: 17
< Content-Type: application/json
< Date: Wed, 04 Sep 2024 11:04:38 GMT
<
{"healthy":true}
* Connection #0 to host fe80::928d:xxff:fexx:xxxx left intact

curl/libcurl version

curl 8.9.1 (x86_64-pc-linux-gnu) libcurl/8.9.1 OpenSSL/1.0.2k-fips zlip/1.2.7 OpenLDAP/2.4.44
Release-Date 2024-07-31
Protocols: dict file ftp ftps gopher gophers http https imap imaps ipfs ipns ldap ldaps mqtt pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
Features: alt-svc AsynchDNS HSTS HTTPS-proxy IPv6 Largefile libz NTLM SSL threadsafe UnixSockets

operating system

Linux hostname 3.10.0-1160.81.1.el7.x86_64 #1 SMP
CentOS Linux release 7.9.2009 (Core)

This is the same with both the system-provided curl and the latest curl that I built from source.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

2 participants