* [ruby-core:99539] [Ruby master Bug#17112] Resolv.getaddress fails with IPv6 link-local addresses
@ 2020-08-10 11:55 daniel
2020-08-11 8:34 ` [ruby-core:99552] " daniel
2020-08-24 22:33 ` [ruby-core:99686] " merch-redmine
0 siblings, 2 replies; 3+ messages in thread
From: daniel @ 2020-08-10 11:55 UTC (permalink / raw)
To: ruby-core
Issue #17112 has been reported by daniel-rikowski (Daniel Rikowski).
----------------------------------------
Bug #17112: Resolv.getaddress fails with IPv6 link-local addresses
https://bugs.ruby-lang.org/issues/17112
* Author: daniel-rikowski (Daniel Rikowski)
* Status: Open
* Priority: Normal
* ruby -v: ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x64-mingw32]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
I noticed that I cannot resolve any link-local IPv6 address using `Resolv.getaddress`. For example calling `Resolv.getaddress('fe80::eca4:7b00:ecc5:206c%8')` fails with `Resolv::ResolvError`
Resolving any IPv4 address succeedes, as well as resolving the loopback address `::1`.
After some code digging I noticed that `Resolv::DNS` doesn't even attempt to resolve that IP address. It checks if there is any local IPv6 interface with an IP address which is not a loopback or a link-local address.
```ruby
def each_address(name)
each_resource(name, Resource::IN::A) {|resource| yield resource.address}
if use_ipv6? # <===== false on my system
each_resource(name, Resource::IN::AAAA) {|resource| yield resource.address}
end
end
```
`use_ipv6?` ultimately boils down to this:
```ruby
Socket.ip_address_list.any? {|a| a.ipv6? && !a.ipv6_loopback? && !a.ipv6_linklocal? }
```
In other words if the system doesn't have a "real" IPv6 address, `Resolv.getaddress` cannot resolve link-local addresses. (`::1` is resolved using `Resolv::Hosts` which doesn't perform the same check)
One could argue that IP addresses don't have to be resolved, and I could just perform a regex check and skip `Resolv.getaddress` if I already have an IP address.
Unfortunately that is not possible when using `resolv-replace`. In that case most (all?) of Ruby's address resolving is piped through `Resolv.getaddress`.
(That is how I noticed this bug: The RubyMine test runner uses drb which connects to a process on the same machine using a link-local IPv6 address. Since I'm using `resolv-replace` and I don't have a network interface with a non-loopback non-local-link address I encountered this bug.)
Platform:
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x64-mingw32]
Microsoft Windows [Version 10.0.18363.959]
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 3+ messages in thread
* [ruby-core:99552] [Ruby master Bug#17112] Resolv.getaddress fails with IPv6 link-local addresses
2020-08-10 11:55 [ruby-core:99539] [Ruby master Bug#17112] Resolv.getaddress fails with IPv6 link-local addresses daniel
@ 2020-08-11 8:34 ` daniel
2020-08-24 22:33 ` [ruby-core:99686] " merch-redmine
1 sibling, 0 replies; 3+ messages in thread
From: daniel @ 2020-08-11 8:34 UTC (permalink / raw)
To: ruby-core
Issue #17112 has been updated by daniel-rikowski (Daniel Rikowski).
After some experiments I noticed that changing `use_ipv6?` isn't sufficient.
In `Resolv#each_address` there seems to be a check for IP addresses. In case an IP address is given no actual resolving is performed.
```ruby
if AddressRegex =~ name
yield name
return
end
```
with
```ruby
AddressRegex = /(?:#{IPv4::Regex})|(?:#{IPv6::Regex})/
```
Unfortunately the regex check doesn't catch link-local addresses. It looks like the IPv6 regexes cannot process the zone ID suffix. (i.e. the interface number/name after the percentage sign, e.g. 'fe80::...**%8**' or 'fe80::...**%eth0**')
As a result a regular resolving is attempted which fails (at least on my system)
----------------------------------------
Bug #17112: Resolv.getaddress fails with IPv6 link-local addresses
https://bugs.ruby-lang.org/issues/17112#change-87014
* Author: daniel-rikowski (Daniel Rikowski)
* Status: Open
* Priority: Normal
* ruby -v: ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x64-mingw32]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
I noticed that I cannot resolve any link-local IPv6 address using `Resolv.getaddress`. For example calling `Resolv.getaddress('fe80::eca4:7b00:ecc5:206c%8')` fails with `Resolv::ResolvError`
Resolving any IPv4 address succeedes, as well as resolving the loopback address `::1`.
After some code digging I noticed that `Resolv::DNS` doesn't even attempt to resolve that IP address. It checks if there is any local IPv6 interface with an IP address which is not a loopback or a link-local address.
```ruby
def each_address(name)
each_resource(name, Resource::IN::A) {|resource| yield resource.address}
if use_ipv6? # <===== false on my system
each_resource(name, Resource::IN::AAAA) {|resource| yield resource.address}
end
end
```
`use_ipv6?` ultimately boils down to this:
```ruby
Socket.ip_address_list.any? {|a| a.ipv6? && !a.ipv6_loopback? && !a.ipv6_linklocal? }
```
In other words if the system doesn't have a "real" IPv6 address, `Resolv.getaddress` cannot resolve link-local addresses. (`::1` is resolved using `Resolv::Hosts` which doesn't perform the same check)
One could argue that IP addresses don't have to be resolved, and I could just perform a regex check and skip `Resolv.getaddress` if I already have an IP address.
Unfortunately that is not possible when using `resolv-replace`. In that case most (all?) of Ruby's address resolving is piped through `Resolv.getaddress`.
(That is how I noticed this bug: The RubyMine test runner uses drb which connects to a process on the same machine using a link-local IPv6 address. Since I'm using `resolv-replace` and I don't have a network interface with a non-loopback non-local-link address I encountered this bug.)
Platform:
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x64-mingw32]
Microsoft Windows [Version 10.0.18363.959]
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 3+ messages in thread
* [ruby-core:99686] [Ruby master Bug#17112] Resolv.getaddress fails with IPv6 link-local addresses
2020-08-10 11:55 [ruby-core:99539] [Ruby master Bug#17112] Resolv.getaddress fails with IPv6 link-local addresses daniel
2020-08-11 8:34 ` [ruby-core:99552] " daniel
@ 2020-08-24 22:33 ` merch-redmine
1 sibling, 0 replies; 3+ messages in thread
From: merch-redmine @ 2020-08-24 22:33 UTC (permalink / raw)
To: ruby-core
Issue #17112 has been updated by jeremyevans0 (Jeremy Evans).
Assignee set to akr (Akira Tanaka)
I've added a pull request with a fix for this: https://github.com/ruby/ruby/pull/3452
----------------------------------------
Bug #17112: Resolv.getaddress fails with IPv6 link-local addresses
https://bugs.ruby-lang.org/issues/17112#change-87174
* Author: daniel-rikowski (Daniel Rikowski)
* Status: Open
* Priority: Normal
* Assignee: akr (Akira Tanaka)
* ruby -v: ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x64-mingw32]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
I noticed that I cannot resolve any link-local IPv6 address using `Resolv.getaddress`. For example calling `Resolv.getaddress('fe80::eca4:7b00:ecc5:206c%8')` fails with `Resolv::ResolvError`
Resolving any IPv4 address succeedes, as well as resolving the loopback address `::1`.
After some code digging I noticed that `Resolv::DNS` doesn't even attempt to resolve that IP address. It checks if there is any local IPv6 interface with an IP address which is not a loopback or a link-local address.
```ruby
def each_address(name)
each_resource(name, Resource::IN::A) {|resource| yield resource.address}
if use_ipv6? # <===== false on my system
each_resource(name, Resource::IN::AAAA) {|resource| yield resource.address}
end
end
```
`use_ipv6?` ultimately boils down to this:
```ruby
Socket.ip_address_list.any? {|a| a.ipv6? && !a.ipv6_loopback? && !a.ipv6_linklocal? }
```
In other words if the system doesn't have a "real" IPv6 address, `Resolv.getaddress` cannot resolve link-local addresses. (`::1` is resolved using `Resolv::Hosts` which doesn't perform the same check)
One could argue that IP addresses don't have to be resolved, and I could just perform a regex check and skip `Resolv.getaddress` if I already have an IP address.
Unfortunately that is not possible when using `resolv-replace`. In that case most (all?) of Ruby's address resolving is piped through `Resolv.getaddress`.
(That is how I noticed this bug: The RubyMine test runner uses drb which connects to a process on the same machine using a link-local IPv6 address. Since I'm using `resolv-replace` and I don't have a network interface with a non-loopback non-local-link address I encountered this bug.)
Platform:
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x64-mingw32]
Microsoft Windows [Version 10.0.18363.959]
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-08-24 22:33 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-10 11:55 [ruby-core:99539] [Ruby master Bug#17112] Resolv.getaddress fails with IPv6 link-local addresses daniel
2020-08-11 8:34 ` [ruby-core:99552] " daniel
2020-08-24 22:33 ` [ruby-core:99686] " merch-redmine
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).