154 Commits

Author SHA1 Message Date
HoneyryderChuck
e3dd766e99 [ruby/resolv] refactoring class-hash to be ractor-safe
mutable constants can't be shared across ractors; this changes that design to define the required variables as constants on the Resource class, which makes them reachable using ractors; the ClassHash is kept in order not to break integrations relying on its existence, but under the hood it's doing the same thing

https://github.com/ruby/resolv/commit/639c01dc7f
2025-04-10 15:58:04 +00:00
HoneyryderChuck
54a85caed4 [ruby/resolv] config read from file should return frozen data!
https://github.com/ruby/resolv/commit/afb57f40a1
2025-04-10 15:58:03 +00:00
Hiroshi SHIBATA
10d06b9a72 [ruby/resolv] Load win32/resolv with rake test
https://github.com/ruby/resolv/commit/3ecfce3626
2025-02-04 04:55:16 +00:00
Charles Oliver Nutter
b1d5d1666e [ruby/resolv] Check for Windows in JRuby-compatible way
https://github.com/ruby/resolv/commit/de95f557b0
2025-01-21 08:03:42 +00:00
Nobuyoshi Nakada
d3bd8df2b8 [ruby/resolv] Use port number 0 for ephemeral port if save
On platforms where ephemeral port randomization is implemented, the
same randomization is not needed in the ruby library layer.

Fixes https://github.com/ruby/resolv/pull/63.

https://github.com/ruby/resolv/commit/45e1b563c0
2025-01-21 07:58:34 +00:00
Jeremy Evans
f0f9e2f50c
[ruby/resolv] Allow setting default Resolv::DNS config in Resolv.new
If a positional argument is provided, the use_ipv6 keyword
option is ignored:

```ruby
Resolv.new([Resolv::DNS.new], use_ipv6: false)
```

Issue a warning in this case.

Currently, you have to pass a positional hash argument to set
the DNS config.  However, after support for the use_ipv6 keyword
argument is removed, you will be able to pass either a positional
hash or keyword arguments.  Code that was just specifying the
use_ipv6 keyword optional will still work correctly in that case.

https://github.com/ruby/resolv/commit/5ff9dda991
2024-12-13 10:54:48 +09:00
Hiroshi SHIBATA
43faf09bb9 [ruby/resolv] Bump up v0.6.0
https://github.com/ruby/resolv/commit/cb4b335034
2024-12-13 01:13:12 +00:00
David Rodríguez
ebb80c26b3 [ruby/resolv] Securerandom should be always available
https://github.com/ruby/resolv/commit/324c355eb7
2024-12-10 10:08:49 +00:00
Hiroshi SHIBATA
a6ad6f350d [ruby/resolv] Bump up v0.5.0
https://github.com/ruby/resolv/commit/c4837aae9b
2024-11-11 03:07:12 +00:00
Hiroshi SHIBATA
638b4468b8 Call Resolv::DNS::Config#lazy_initialize explicitly if that instance is not initialized 2024-10-08 15:52:49 +09:00
Sadiq Saif
1b3f18afce each_address should now resolve for AAAA first
AAAA over A is standards track behaviour as per RFC 6724.
2024-10-03 15:04:46 +09:00
Kasumi Hanazuki
094e53360d [ruby/resolv] Reuse open TCP connection
[RFC7766] Section 5 recommends stub resolvers to reuse open TCP
connections to a nameserver.

[RFC7766]: https://datatracker.ietf.org/doc/html/rfc7766

https://github.com/ruby/resolv/commit/9bf1b08f5c
2024-08-13 21:09:08 +00:00
Igor Pstyga
4be9b72fbb [ruby/resolv] Fix TCP fallback with multiple nameservers
Under the following conditions the exception
`Resolv::DNS::Requester::RequestError: host/port don't match` is raised:
- Multiple nameservers are configured for Resolv::DNS
- A nameserver falls back from UDP to TCP
- TCP request hits Resolv::DNS timeout
- Resolv::DNS retries the next nameserver

More details here https://bugs.ruby-lang.org/issues/8285

https://github.com/ruby/resolv/commit/7d524df80e

Co-authored-by: Julian Mehnle <julian@mehnle.net>
2024-08-13 21:09:08 +00:00
Hiroshi SHIBATA
0985e58790 [ruby/resolv] Bump up 0.4.0
https://github.com/ruby/resolv/commit/44ae1e8531
2024-03-19 02:16:51 +00:00
Kasumi Hanazuki
2508a79699 [ruby/resolv] Implement CAA resource record
This patch implements handling of CAA resource records defined by [RFC8659].

- There are no known deployment of CAA records outside of IN (Internet),
  but the RFC does not state that CAA records are class-specific.
  Thus `CAA` class is defined as a class-independent RRType.
- `CAA` class stores `flags` field (a 1-octet bitset) as an Integer.
  In this way it's easier to ensure the encoded RR is in the valid wire format.

[RFC8659]: https://datatracker.ietf.org/doc/html/rfc8659

https://github.com/ruby/resolv/commit/cfc4de75e3

Co-authored-by: aeris <aeris@imirhil.fr>
2024-02-29 20:55:26 +00:00
Nobuyoshi Nakada
012a0b9125 [ruby/resolv] Simplify adding new entries
https://github.com/ruby/resolv/commit/081b8df705
2024-02-25 04:39:22 +00:00
Nobuyoshi Nakada
30b99868f9 [ruby/resolv] Treat hostname as same as aliases
https://github.com/ruby/resolv/commit/fa812d6454
2024-02-25 04:39:22 +00:00
David Rodríguez
df941aa90d [ruby/resolv] Fix typo
https://github.com/ruby/resolv/commit/5dfdcfb7c7
2023-12-25 21:12:49 +09:00
Hiroshi SHIBATA
5f5f8dbbb6 [ruby/resolv] Bump up 0.3.0
https://github.com/ruby/resolv/commit/22153c2a45
2023-12-13 15:11:21 +09:00
Jeremy Evans
87c3deacf4 [ruby/resolv] Support a :use_ipv6 option to Resolv#initialize
When set, supports returning IPv6 results even if there is no
public IPv6 address for the system.

Implements Ruby Feature #14922

https://github.com/ruby/resolv/commit/09d141de38
2023-11-25 11:40:08 -08:00
Jeremy Evans
7276d4b4e8 [ruby/resolv] Support a :raise_timeout_errors option to raise timeouts as Resolv::ResolvError
This allows to differentiate a timeout from an NXDOMAIN response.

Fixes [Bug #18151]

https://github.com/ruby/resolv/commit/c0e5abab76
2023-11-25 02:24:43 +00:00
Jeremy Evans
974d18fd0c [ruby/resolv] Fix the fallback from UDP to TCP due to message truncation
If truncation is detected, return immediately from decode so that
the UDP connection can be retried with TCP, instead of failing to
decode due to trying to decode a truncated response.

Fixes [Bug #13513]

https://github.com/ruby/resolv/commit/0de996dbca
2023-11-24 19:17:19 +00:00
KJ Tsanaktsidis
02cc9d48f1 [ruby/resolv] Catch EPROTONOSUPPORT as a sign of no IPv6 as well
(https://github.com/ruby/resolv/pull/41)

If IPv6 is disabled inside a freebsd jail, it seems this returns
EPROTONOSUPPORT and not EAFNOSUPPORT. In both cases, we should simply
try some other listed DNS servers.

Fixes [Bug #19928] https://bugs.ruby-lang.org/issues/19928

https://github.com/ruby/resolv/commit/5e2d48708b
2023-11-24 04:06:25 +00:00
Kasumi Hanazuki
e3b485213d [ruby/resolv] Implement dohpath SvcParam
(https://github.com/ruby/resolv/pull/33)

* Implement dohpath SvcParam [RFC 9461]

This patch implements "dohpath" SvcParam proposed in
[draft-ietf-add-svcb-dns-08]. This parameter specifies a URI template
for the :path used in DNS-over-HTTPS requests.

"dohpath" is employed by [DDR], also a to-be-published Proposed Standard
that specifies how to upgrade DNS transport to a more secure one, i.d.,
DNS-over-TLS or DNS-over-HTTPS. DDR is deployed in the public DNS
resolvers including Cloudflare DNS, Google Public DNS, and Quad9.

[RFC 9461]: https://datatracker.ietf.org/doc/rfc9461/
[DDR]: https://datatracker.ietf.org/doc/draft-ietf-add-ddr/

https://github.com/ruby/resolv/commit/da9c023539

Co-authored-by: Sorah Fukumori <her@sorah.jp>
2023-11-24 01:42:08 +00:00
Kasumi Hanazuki
608a518b42 [ruby/resolv] Implement SVCB and HTTPS RRs
(https://github.com/ruby/resolv/pull/32)

* Add MessageDecoder#get_list

This method repeats yielding until all the data upto the current limit
is consumed, and then returns an Array containig the block results.

* Implement SVCB and HTTPS RRs [RFC 9460]

> This patch implements SVCB and HTTPS resource record types defined in
> [RFC 9460].
>
> The RR types are now supported by many server implementations including
> BIND, unbound, PowerDNS, and Knot DNS. Major browsers such as Chrome,
> Edge, and Safari have started to query HTTPS records, with the records
> gradually adopted by websites. Also, SVCB is actually deployed in the
> public DNS resolvers such as Cloudflare DNS and Google Public DNS for
> [DDR].
>
> With such wide adoption, we have plenty of real-world use cases, and
> it is unlikely the wire format will change further in an incompatible
> way. It is time to implement them in the client libraries!
>
> # Rationale for proposed API
>
> ## `Resolv::DNS::Resource::IN::ServiceBinding`
>
> This is an abstract class for SVCB-compatible RR types.
> SVCB-compatible RR types, as defined in the Draft, shares the wire
> format and the semantics of their RDATA fields with SVCB to allow
> implementations to share the processing of these RR types. So we do
> so.
>
> The interface of this class is straightforward: It has three
> attributes `priority`, `target`, and `params`, which correspond the
> RDATA fields SvcPriority, TargetName, and SvcParams, resp.
>
> SVCB RR type is defined specifically within IN class. Thus, this
> class is placed in the `Resolv::DNS::Resource::IN` namespace.
>
> ## `Resolv::DNS::Resource::IN::SVCB`, `Resolv::DNS::Resource::IN::HTTPS`
>
> Just inherits ServiceBinding class.
>
> ## `Resolv::DNS::SvcParam`
>
> This class represents a pair of a SvcParamKey and a SvcParamValue.
> Aligned with the design of `Resolv::DNS::Resource`, each SvcParamKey
> has its own subclass of `Resolv::DNS::SvcParam`.
>
> ## `Resolv::DNS::SvcParam::Generic`
>
> This is an abstract class representing a SvcParamKey that is unknown
> to this library. `Generic.create(key)` dynamically defines its
> subclass for specific `key`. E.g., `Generic.create(667)` will define
> `Generic::Key667`.
>
> This class holds SvcParamValue in its wire format.
>
> SvcParam with an unknown SvcParamKey will be decoded as a subclass of
> this class. Also, users of this library can generate a non-supported
> SvcParam if they know its wire format.
>
> ## `Resolv::DNS::SvcParams`
>
> This is conceptually a set of `SvcParam`s, whose elements have the
> unique SvcParamKeys. It behaves like a set, and for convenience
> provides indexing by SvcParamKey.
>
> - `#initialize(params)` takes an Enumerable of `SvcParam`s as the
>   initial content. If it contains `SvcParam`s with the duplicate key,
>   the one that appears last takes precedence.
> - `#[](key)` fetches the `SvcParam` with the given key. The key can be
>   specified by its name (e.g., `:alpn`) or number (e.g., `1`).
> - `#add(param)` adds a `SvcParam` to the set. If the set already has a
>   `SvcParam` with the same key, it will be replaced.
> - `#delete(key)` deletes a `SvcParam` by its key and returns it. The key
>   can be specified by its name or number.

* Update comments referring to draft-ietf-dnsop-svcb-https-12

Published as RFC 9460. https://datatracker.ietf.org/doc/rfc9460/

[draft-ietf-dnsop-svcb-https-12]: https://datatracker.ietf.org/doc/draft-ietf-dnsop-svcb-https/12/
[RFC 9460]: https://datatracker.ietf.org/doc/rfc9460/
[DDR]: https://datatracker.ietf.org/doc/draft-ietf-add-ddr/

https://github.com/ruby/resolv/commit/b3ced7f039
2023-11-24 01:35:33 +00:00
John Bond
9e24d747ff [ruby/resolv] IPv6: update to_s method to be RFC5952 compliant
(https://github.com/ruby/resolv/pull/25)

* IPv6: update to_s method to be RFC5952 compliant

I noticed that the resolv library does not honour RFC 5952 Section 4.2.2.
in relation to textural representation of ipv6 addresses:

   The symbol "::" MUST NOT be used to shorten just one 16-bit 0 field.
   For example, the representation 2001:db8:0:1:1:1:1:1 is correct, but
   2001:db8::1:1:1:1:1 is not correct.

Fixes https://github.com/ruby/resolv/pull/24

https://github.com/ruby/resolv/commit/5efcd6ed70

Co-authored-by: Sorah Fukumori <sora134@gmail.com>
2023-11-22 10:35:36 +00:00
Nobuyoshi Nakada
7ba37cb7aa [ruby/resolv] Prefer Array#concat over #+= on Array
Fix https://bugs.ruby-lang.org/issues/19621

https://github.com/ruby/resolv/commit/7faaa78847
2023-04-28 11:29:02 +00:00
Hiroshi SHIBATA
652f273308 [ruby/resolv] Expose Resolv::VERSION
https://github.com/ruby/resolv/commit/6ab2385e89
2023-04-14 01:46:38 +00:00
Kasumi Hanazuki
957595f218 [ruby/resolv] Do not compress domain name in SRV RDATA
[RFC2782] prohibits use of name compression for the target host name
in the RDATA of a SRV record.

[RFC2782]: https://datatracker.ietf.org/doc/rfc2782/

Closes: https://github.com/ruby/resolv/issues/29

https://github.com/ruby/resolv/commit/ac85724e17
2023-04-08 14:16:59 +00:00
Jeremy Evans
d494a16ac5 [ruby/resolv] Support more characters in link local addresses
Implements [Feature #17524]

https://github.com/ruby/resolv/commit/993a1a374f
2022-01-12 10:49:57 +09:00
Kazuki Yamaguchi
9edc162583 [ruby/resolv] Fix confusion of received response message
This is a follow up for commit 33fb966197f1 ("Remove sender/message_id
pair after response received in resolv", 2020-09-11).

As the @senders instance variable is also used for tracking transaction
ID allocation, simply removing an entry without releasing the ID would
eventually deplete the ID space and cause
Resolv::DNS.allocate_request_id to hang.

It seems the intention of the code was to check that the received DNS
message is actually the response for the question made within the method
earlier. Let's have it actually do so.

[Bug #12838] https://bugs.ruby-lang.org/issues/12838
[Bug #17748] https://bugs.ruby-lang.org/issues/17748

https://github.com/ruby/resolv/commit/53ca9c9209
2021-05-11 12:37:34 +09:00
Kazuhiro NISHIYAMA
d14397bcc4
fe80 should be case insensitive too 2020-11-09 16:16:30 +09:00
Jeremy Evans
54ac1d7717 Support s390 IPv6 link local addresses 2020-11-07 23:42:02 -08:00
Jeremy Evans
2f12af42f7 Add support for IPv6 link local addresses to resolv
Now that it should work correctly, test that every address returned
by Socket.ip_address_list is resolvable.

Socket works with IPv6 link local addresses, and ipaddr now does
as well, so I think resolv should support them.

Fixes [Bug #17112]
2020-11-07 13:47:45 -08:00
Jeremy Evans
9682db0651 Remove sender/message_id pair after response received in resolv
Once a response for a given DNS request has been received (which
requires a matching message id), the [sender, message_id] pair
should be removed from the list of valid senders.  This makes it
so duplicate responses from the same sender are ignored.

Fixes [Bug #12838]
2020-11-07 13:12:27 -08:00
Jeremy Evans
04b5203a03 Convert ip addresses to canonical form in Resolv::DNS::Requester::UnconnectedUDP#sender
Otherwise, if the IP address given is not in canonical form, it
won't match, and Resolv will ignore it.

Fixes [Bug #16439]
2020-05-29 15:59:27 -07:00
Jeremy Evans
ffd0820ab3 Deprecate taint/trust and related methods, and make the methods no-ops
This removes the related tests, and puts the related specs behind
version guards.  This affects all code in lib, including some
libraries that may want to support older versions of Ruby.
2019-11-18 01:00:25 +02:00
Jeremy Evans
f37cc1c719 Fallback to TCP in resolv if UDP bind raises EACCES
Original patch from Andy Grimm.

Fixes [Bug #10747]
2019-10-21 12:48:38 -07:00
Tanaka Akira
1da3a31a5f Use lowercase letters for IPv6 addresses.
Reported by chucke (Tiago Cardoso).
Patch by jeremyevans0 (Jeremy Evans).
[Bug #14612]
2019-07-30 11:59:54 +09:00
Nobuyoshi Nakada
cd372f8db2
Get rid of LoadError with $DEBUG 2019-07-17 14:45:33 +09:00
Jeremy Evans
6650899248 Make Resolv::DNS#each_name accept Resolv::IPv{4,6} arguments
These arguments were previously documented as supported, but not
actually supported.

Patch from Toru Iwase

Fixes [Bug #15900]
2019-06-08 20:31:12 -07:00
nobu
e667897b46 resolv.rb: remove rangerand
* lib/resolv.rb (Resolv::DNS.rangerand): rand and random_number
  accept a Range.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62672 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-06 03:31:46 +00:00
nobu
e6c0a8f19e resolv.rb: close socket
* lib/resolv.rb (UnconnectedUDP#lazy_initialize): store new
  sockets before binding, so the sockets get closed when the
  requester is closing.

* lib/resolv.rb (ConnectedUDP#lazy_initialize): ditto.

* lib/resolv.rb (UnconnectedUDP#close): synchronize to get rid of
  race condition.

* lib/resolv.rb (ConnectedUDP#close): ditto.

[ruby-core:85901] [Bug #14571]

From: quixoten (Devin Christensen) <quixoten@gmail.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62671 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-03-06 02:48:17 +00:00
nobu
456dc174b6 resolv.rb: NUL hosts
* lib/resolv.rb (Resolv::Hosts::DefaultFileName): fallback to NUL
  device when Win32::Resolv.get_hosts_path() returned nil, to get
  rid of TypeError in lazy_initialize.
  [ruby-core:84907] [Bug #14369]  [Fix GH-1791]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61898 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-18 03:09:39 +00:00
nobu
fa5870b9c4 resolv: use safe navigation operator
* lib/resolv.rb (each_address): use safe navigation operator to
  avoid extra hash lookups, as well as each_name since r56890.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61897 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-18 02:44:50 +00:00
naruse
9e677261a9 Mock fetching data from real DNS [Feature #14340]
This test just tests MDNS#each_address method.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61774 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-11 18:26:49 +00:00
nobu
cdf1b85ae7 Fixed command Injection
* lib/resolv.rb (Resolv::Config.parse_resolv_conf): fixed
  potential command injection by use of Kernel#open.
  [ruby-core:84347] [Bug #14205]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61351 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-20 04:25:01 +00:00
nobu
e7464561b5 Fixed command Injection
* resolv.rb (Resolv::Hosts#lazy_initialize): fixed potential
  command Injection in Hosts::new() by use of Kernel#open.
  [Fix GH-1777] [ruby-core:84347] [Bug #14205]

From: Drigg3r <drigg3r@yandex.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61349 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-20 04:18:31 +00:00
hsbt
db590b5d59 Fixed unexpected behavior of Resolv::MDNS#each_address when given ".local" address.
https://github.com/ruby/ruby/pull/1425

  Patch by @elct9620 [fix GH-1484]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60275 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-21 13:58:31 +00:00
glass
f70827b7cf resolv.rb: remove unnecessary require statement
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59679 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-29 04:58:29 +00:00