Skip to content

Add IPAddr#globally_reachable? predicate - #144

Open
jonasporto wants to merge 1 commit into
ruby:masterfrom
jonasporto:globally-reachable
Open

jonasporto wants to merge 1 commit into
ruby:masterfrom
jonasporto:globally-reachable

Conversation

@jonasporto

Copy link
Copy Markdown

Summary

Adds IPAddr#globally_reachable?, which reports the "Globally Reachable" column of the IANA Special-Purpose Address Registries (RFC 8190), as discussed in #80:

Both were read on 2026-11-21 (each registry says it was last updated 2025-10-09). The rows are kept in two frozen private tables, one per family, with each block written next to its row so the tables can be checked against the registries line by line.

Behaviour

IPAddr.new("8.8.8.8").globally_reachable?               # => true
IPAddr.new("10.0.0.1").globally_reachable?              # => false
IPAddr.new("192.0.0.9").globally_reachable?             # => true  (192.0.0.9/32 is True inside 192.0.0.0/24)
IPAddr.new("192.0.0.1").globally_reachable?             # => false
IPAddr.new("2001:1::1").globally_reachable?             # => true  (inside 2001::/23, which is False)
IPAddr.new("2002:a00:1::").globally_reachable?          # => false (6to4, N/A)
IPAddr.new("::ffff:8.8.8.8").globally_reachable?        # => true  (judged as 8.8.8.8)
IPAddr.new("8.0.0.0/8").globally_reachable?             # => true
IPAddr.new("10.0.0.0/7").globally_reachable?            # => false (contains 10.0.0.0/8)

Rules

Two points the thread did not cover, both easy to change if you prefer otherwise:

  1. Two rows were terminated and have no value in the column: 192.88.99.0/24 (6to4 Relay Anycast, 2015-03) and 2001:10::/28 (ORCHID, 2014-03). They are left out of the tables, so 192.88.99.1 is true, 192.88.99.2/32 (a current False row) is false, and 2001:10::/28 takes the value of 2001::/23 (false).
  2. Multicast (224.0.0.0/4, ff00::/8) is in neither registry, so 224.0.0.1 and ff02::1 return true here. That is the registry's answer, and the same one Python's ipaddress.is_global gives. If you would rather have false for anything multicast? covers, I can add that.

Tests

test_globally_reachable? in test/test_ipaddr.rb:

  • every registry row: the block itself, its first address and its last address, against the row's value;
  • the True exceptions and the addresses around them (192.0.0.8/30, 2001:1::/126, 2001:1::4);
  • addresses just outside the blocks' edges, and a public control per family (8.8.8.8, 2001:4860:4860::8888);
  • supernets (0.0.0.0/0, 10.0.0.0/7, 128.0.0.0/1, ::/0, 2000::/3, fc00::/6);
  • IPv4-mapped addresses and networks, and addresses with 0xffff in group 5 that are not mapped;
  • the other forms that carry an IPv4 address (NAT64, 6to4, Teredo).

bundle exec rake test passes on Ruby 3.2, 3.4 and 4.0:

43 tests, 805 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications

Implements #80.

Add a predicate for the "Globally Reachable" column of the IANA IPv4
and IPv6 Special-Purpose Address Registries, as read on 2026-11-21.
The most specific registry block decides, so 192.0.0.9 and 192.0.0.10
are globally reachable while the rest of 192.0.0.0/24 is not. Blocks
marked N/A (6to4, Teredo) are not globally reachable, IPv4-mapped
addresses are judged as their IPv4 address, and a network is globally
reachable only when every address in it is.

Implements ruby#80.
@jonasporto
jonasporto requested a review from knu as a code owner November 21, 2026 14:38

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant