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 does use the ipv4 address if it doesn't receive the ipv6 address #11564

Closed
JosephTharayil opened this issue Aug 1, 2023 · 2 comments
Closed
Labels
name lookup DNS and related tech

Comments

@JosephTharayil
Copy link

JosephTharayil commented Aug 1, 2023

I did this

Hi Team,

I am using curl 7.79.1 with c-ares 1.17.2.

I use this command "curl -v -m4 https://www.google.com" to test how curl responds in various changes in responses to dns queries made by curl. To do this i am using a very simple dns server which responds to queries which are only "www.google.com" .
The first case is i try to execute the above command what i notice is in this case is that both ipv4 and ipv6 queries are sent from the c-ares library. But if ipv6 is not received before the timeout occurs the command fails even though the ipv4 response is obtained .

curl -v -m4 https://www.google.com

  • STATE: INIT => CONNECT handle 0x563c74ff8998; line 1789 (connection #-5000)

  • Added connection 0. The cache now contains 1 members
    15:29:38.735975 IP 6a5a2727f400.34325 > 10.174.75.167.domain: 63432+ A? www.google.com. (32)
    15:29:38.736177 IP 6a5a2727f400.34325 > 10.174.75.167.domain: 56463+ AAAA? www.google.com. (32)

  • STATE: CONNECT => RESOLVING handle 0x563c74ff8998; line 1835 (connection #0)
    15:29:38.736618 IP 10.174.75.167.domain > 6a5a2727f400.34325: 63432 1/0/0 A 142.250.195.228 (49)*
    15:29:38.736834 IP 10.174.75.167.domain > 6a5a2727f400.34325: 63432* 1/0/0 A 142.250.195.228 (49)

  • Resolving timed out after 4001 milliseconds

  • multi_done

  • The cache now contains 0 members

  • Closing connection 0

  • Expire cleared (transfer 0x563c74ff8998)
    curl: (28) Resolving timed out after 4001 milliseconds

Ok now what i do is i only try to send the ipv4 request using the -4 option but this also doesn't work with this curl version of 7.79.1.

curl -v -m4 -4 https://www.google.com

  • STATE: INIT => CONNECT handle 0x565138d20998; line 1789 (connection #-5000)
  • Added connection 0. The cache now contains 1 members
    15:29:31.722618 IP 6a5a2727f400.38880 > 10.174.75.167.domain: 60498+ A? www.google.com. (32)
    15:29:31.722853 IP 6a5a2727f400.38880 > 10.174.75.167.domain: 50175+ AAAA? www.google.com. (32)
  • STATE: CONNECT => RESOLVING handle 0x565138d20998; line 1835 (connection #0)
    15:29:31.723211 IP 10.174.75.167.domain > 6a5a2727f400.38880: 60498* 1/0/0 A 142.250.195.228 (49)
    15:29:31.723230 IP 10.174.75.167.domain > 6a5a2727f400.38880: 60498* 1/0/0 A 142.250.195.228 (49)
  • Resolving timed out after 4001 milliseconds
  • multi_done
  • The cache now contains 0 members
  • Closing connection 0
  • Expire cleared (transfer 0x565138d20998)
    curl: (28) Resolving timed out after 4001 milliseconds

in this cases also both queries are sent out. Now if i do it just for ipv6 also the similar issue occurs both queries are sent out.

If i changed the curl version to 7.87.0 then the "-4" option works here it only sends the query for ipv4 and doesn't initiate for ipv6 . But even in that version if i execute "-6" option then both ipv4 and ipv6 dns queries are sent out.

Could you help me with this?

I expected the following

curl should return after the timeout and use what ever ip is obtained from the dns query response. To initiate the connection.

curl/libcurl version

root@6a5a2727f400:/# curl -V curl 7.79.1 (x86_64-pc-linux-gnu) libcurl/7.79.1 OpenSSL/1.1.1f c-ares/1.17.2 Release-Date: 2021-09-22 Protocols: dict file ftp ftps gopher gophers http https imap imaps mqtt pop3 pop3s rtsp smb smbs smtp smtps telnet tftp Features: alt-svc AsynchDNS Debug HSTS HTTPS-proxy IPv6 Largefile NTLM NTLM_WB SSL TLS-SRP TrackMemory UnixSockets

operating system

uname -a Linux 6a5a2727f400 5.4.0-136-generic #153~18.04.1-Ubuntu SMP Wed Nov 30 15:47:57 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

@bagder bagder added the name lookup DNS and related tech label Aug 1, 2023
@bagder
Copy link
Member

bagder commented Aug 1, 2023

curl should return after the timeout and use what ever ip is obtained from the dns query response. To initiate the connection.

That's not how name resolving typically works. When we use c-ares, we ask c-ares to resolve the host name and if it returns error that is a failure for us. c-ares should however not consider a partial response as an error, but that's not curl's domain.

even in that version if i execute "-6" option then both ipv4 and ipv6 dns queries are sent out.

While I don't think the man page guarantees this, it looks like an oversight in the code.

bagder added a commit that referenced this issue Aug 1, 2023
Previously it would always do PF_UNSPEC if CURL_IPRESOLVE_V4 is not
used, thus unnecessarily asking for addresses that will not be used.

Reported-by: Joseph Tharayil
Fixes #11564
@bagder bagder closed this as completed in d3142b5 Aug 1, 2023
@JosephTharayil
Copy link
Author

Thanks for the quick response. I tested it with these changes and its working as expected.

ptitSeb pushed a commit to wasix-org/curl that referenced this issue Sep 25, 2023
Previously it would always do PF_UNSPEC if CURL_IPRESOLVE_V4 is not
used, thus unnecessarily asking for addresses that will not be used.

Reported-by: Joseph Tharayil
Fixes curl#11564
Closes curl#11565
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
name lookup DNS and related tech
Development

Successfully merging a pull request may close this issue.

2 participants