Skip to content

extra multicast/unicast predicates#114

Open
HoneyryderChuck wants to merge 1 commit into
ruby:masterfrom
HoneyryderChuck:multicast-predicates
Open

extra multicast/unicast predicates#114
HoneyryderChuck wants to merge 1 commit into
ruby:masterfrom
HoneyryderChuck:multicast-predicates

Conversation

@HoneyryderChuck

Copy link
Copy Markdown

This adds the following predicate methods to IPAddr objects:

  • #multicast?: whether the ip address is multicast
  • #link_local_multicast?: whether the ip address is a link-local multicast
  • #global_unicast?: whetther the ip address is a global unicast

it also alias IPAddr#link_local? as IPAddr#link_local_unicast?, which is more accurate (whether the original should be deprecated is probably a separate discussion).

The motivation for adding these methods was to upstream these predicates from cel which have a broader meaning in the context of IP addressing, and maybe be applied in other contexts.

This adds the following predicate methods to IPAddr objects:

* `#multicast?`: whether the ip address is multicast
* `#link_local_multicast?`: whether the ip address is a link-local
  multicast
* `#global_unicast?`: whetther the ip address is a global unicast

it also alias `IPAddr#link_local?` as `IPAddr#link_local_unicast?`,
which is more accurate (whether the original should be deprecated is
probably a separate discussion).
@HoneyryderChuck HoneyryderChuck requested a review from knu as a code owner June 22, 2026 12:17
@taketo1113

Copy link
Copy Markdown
Collaborator

@HoneyryderChuck What use cases do you have in mind for link_local_multicast? and global_unicast? ?

In particular, I'm not sure about the behavior of global_unicast? for IPv4.

According to RFC 4291, all IPv6 addresses except Unspecified (::/128), Loopback, Multicast, and Link-Local Unicast are defined as Global Unicast addresses:
https://datatracker.ietf.org/doc/html/rfc4291#section-2.4

However, there is no corresponding definition of "Global Unicast" for IPv4, so IPAddr would need to define what "Global Unicast" means for IPv4.

In the current implementation of this pull request, IPv4 addresses that are not globally reachable, such as Private addresses (e.g. 10.0.0.1) and Shared Address Space (e.g. 100.64.0.1), still return true.

IPAddr.new("10.0.0.1").global_unicast?
# => true

Is this behavior intentional? If so, could you explain the rationale behind it?

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.

2 participants