Repository navigation
Add IPAddr#globally_reachable? predicate - #144
Open
jonasporto wants to merge 1 commit into
Open
jonasporto wants to merge 1 commit into
jonasporto wants to merge 1 commit into
Conversation
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.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Rules
Truerows inside192.0.0.0/24and2001::/23win over their enclosing block.N/A(Teredo2001::/32, 6to42002::/16) arefalse.true.trueonly when every address in it is (the rule from Fix false positives in private?/link_local?/multicast?/link_local_multicast? for supernets of the target address blocks #125).::ffff:0:0/96) are judged as the IPv4 address they map, asprivate?and the other predicates do. Global unicast addresses with0xffffin group 5 are not treated as mapped (Fix IPAddr#private?, #link_local? and #loopback? incorrectly matching public IPv6 addresses as IPv4-mapped #106).64:ff9b::/96isTruein the registry, and IPv4-compatible::a.b.c.dis in no block).Two points the thread did not cover, both easy to change if you prefer otherwise:
192.88.99.0/24(6to4 Relay Anycast, 2015-03) and2001:10::/28(ORCHID, 2014-03). They are left out of the tables, so192.88.99.1istrue,192.88.99.2/32(a current False row) isfalse, and2001:10::/28takes the value of2001::/23(false).224.0.0.0/4,ff00::/8) is in neither registry, so224.0.0.1andff02::1returntruehere. That is the registry's answer, and the same one Python'sipaddress.is_globalgives. If you would rather havefalsefor anythingmulticast?covers, I can add that.Tests
test_globally_reachable?intest/test_ipaddr.rb:Trueexceptions and the addresses around them (192.0.0.8/30,2001:1::/126,2001:1::4);8.8.8.8,2001:4860:4860::8888);0.0.0.0/0,10.0.0.0/7,128.0.0.0/1,::/0,2000::/3,fc00::/6);0xffffin group 5 that are not mapped;bundle exec rake testpasses on Ruby 3.2, 3.4 and 4.0:Implements #80.