ruby/ext/socket
KJ Tsanaktsidis 25711e7063 Partially revert "Set AI_ADDRCONFIG when making getaddrinfo(3) calls"
This _partially_ reverts commit
d2ba8ea54a, but for UDP sockets only.

With TCP sockets (and other things which use `rsock_init_inetsock`), the
order of operations is to call `getaddrinfo(3)` with AF_UNSPEC, look at
the returned addresses, pick one, and then call `socket(2)` with the
family for that address (i.e. AF_INET or AF_INET6).

With UDP sockets, however, this is reversed; `UDPSocket.new` takes an
address family as an argument, and then calls `socket(2)` with that
family. A subsequent call to UDPSocket#connect will then call
`getaddrinfo(3)` with that family.

The problem here is that...

* If you are in a networking situation that _only_ has loopback addrs,
* And you want to look up a name like "localhost" (or NULL)
* And you pass AF_INET or AF_INET6 as the ai_family argument to
  getaddrinfo(3),
* And you pass AI_ADDRCONFIG to the hints argument as well,

then glibc on Linux will not return an address. This is because
AI_ADDRCONFIG is supposed to return addresses for families we actually
have an address for and could conceivably connect to, but also is
documented to explicitly ignore localhost in that situation.

It honestly doesn't make a ton of sense to pass AI_ADDRCONFIG if you're
explicitly passing the address family anyway, because you're not looking
for "an address for this name we can connect to"; you're looking for "an
IPv(4|6) address for this name". And the original glibc bug that
d2ba8ea5 was supposed to work around was related to parallel issuance of
A and AAAA queries, which of course won't happen if an address family is
explicitly specified.

So, we fix this by not passing AI_ADDRCONFIG for calls to
`rsock_addrinfo` that we also pass an explicit family to (i.e. for
UDPsocket).

[Bug #20048]
2023-12-12 20:05:21 +11:00
..
lib Remove require 'io/wait' where it's no longer necessary. (#6932) 2022-12-15 11:37:01 +13:00
.document
addrinfo.h Expand tabs [ci skip] 2022-07-21 09:42:04 -07:00
ancdata.c BasicSocket#recv* return nil rather than an empty packet 2023-08-30 10:07:18 +02:00
basicsocket.c Try nil as default for 'default timeout'. (#6509) 2022-10-08 14:02:34 +13:00
constants.c Expand tabs [ci skip] 2022-07-21 09:42:04 -07:00
depend Change the semantics of rb_postponed_job_register 2023-12-10 15:00:37 +09:00
extconf.rb Set AI_ADDRCONFIG when making getaddrinfo(3) calls for outgoing conns (#7295) 2023-12-07 17:55:15 +09:00
getaddrinfo.c Don't check for null pointer in calls to free 2023-06-30 09:13:31 -04:00
getnameinfo.c Expand tabs [ci skip] 2022-07-21 09:42:04 -07:00
ifaddr.c Expand tabs [ci skip] 2022-07-21 09:42:04 -07:00
init.c Adjust indent [ci skip] 2023-11-30 13:32:53 +09:00
ipsocket.c Set AI_ADDRCONFIG when making getaddrinfo(3) calls for outgoing conns (#7295) 2023-12-07 17:55:15 +09:00
mkconstants.rb sockopt adding Linux constants, SO_INCOMING_CPU/SO_INCOMING_NAPI_ID. 2022-09-21 17:15:54 +09:00
option.c Add support for sockaddr_un on Windows. (#6513) 2022-11-17 14:50:25 -08:00
raddrinfo.c Rename rsock_raise_socket_error to rsock_raise_resolution_error 2023-11-30 13:27:19 +09:00
rubysocket.h Rename rsock_raise_socket_error to rsock_raise_resolution_error 2023-11-30 13:27:19 +09:00
socket.c Rename rsock_raise_socket_error to rsock_raise_resolution_error 2023-11-30 13:27:19 +09:00
sockport.h
sockssocket.c Expand tabs [ci skip] 2022-07-21 09:42:04 -07:00
tcpserver.c Expand tabs [ci skip] 2022-07-21 09:42:04 -07:00
tcpsocket.c Expand tabs [ci skip] 2022-07-21 09:42:04 -07:00
udpsocket.c Partially revert "Set AI_ADDRCONFIG when making getaddrinfo(3) calls" 2023-12-12 20:05:21 +11:00
unixserver.c Add support for sockaddr_un on Windows. (#6513) 2022-11-17 14:50:25 -08:00
unixsocket.c fix typo in comments / autodoc 2023-01-16 08:00:03 +09:00