Skip to content
This repository was archived by the owner on May 25, 2023. It is now read-only.

Commit d57edf1

Browse files
moreatijosharian
authored andcommitted
Add RFC references for IP.Is<Property>() methods
These helped me to cross reference inet.af/netaddr, net.IP, and github.com/mellowdrifter/bogons for #151. Signed-off-by: Alex Willmer <[email protected]>
1 parent 9ee55bc commit d57edf1

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

netaddr.go

+16
Original file line numberDiff line numberDiff line change
@@ -537,9 +537,13 @@ func (ip IP) WithZone(zone string) IP {
537537
// IsLinkLocalUnicast reports whether ip is a link-local unicast address.
538538
// If ip is the zero value, it will return false.
539539
func (ip IP) IsLinkLocalUnicast() bool {
540+
// Dynamic Configuration of IPv4 Link-Local Addresses
541+
// https://datatracker.ietf.org/doc/html/rfc3927#section-2.1
540542
if ip.Is4() {
541543
return ip.v4(0) == 169 && ip.v4(1) == 254
542544
}
545+
// IP Version 6 Addressing Architecture (2.5.6 Link-Local IPv6 Unicast Addresses)
546+
// https://datatracker.ietf.org/doc/html/rfc4291#section-2.5.6
543547
if ip.Is6() {
544548
return ip.v6u16(0) == 0xfe80
545549
}
@@ -549,9 +553,13 @@ func (ip IP) IsLinkLocalUnicast() bool {
549553
// IsLoopback reports whether ip is a loopback address. If ip is the zero value,
550554
// it will return false.
551555
func (ip IP) IsLoopback() bool {
556+
// Requirements for Internet Hosts -- Communication Layers (3.2.1.3 Addressing)
557+
// https://datatracker.ietf.org/doc/html/rfc1122#section-3.2.1.3
552558
if ip.Is4() {
553559
return ip.v4(0) == 127
554560
}
561+
// IP Version 6 Addressing Architecture (2.5.3 The Loopback Address)
562+
// https://datatracker.ietf.org/doc/html/rfc4291#section-2.5.3
555563
if ip.Is6() {
556564
return ip.addr.hi == 0 && ip.addr.lo == 1
557565
}
@@ -561,6 +569,8 @@ func (ip IP) IsLoopback() bool {
561569
// IsMulticast reports whether ip is a multicast address. If ip is the zero
562570
// value, it will return false.
563571
func (ip IP) IsMulticast() bool {
572+
// Host Extensions for IP Multicasting (4. HOST GROUP ADDRESSES)
573+
// https://datatracker.ietf.org/doc/html/rfc1112#section-4
564574
if ip.Is4() {
565575
return ip.v4(0)&0xf0 == 0xe0
566576
}
@@ -574,6 +584,8 @@ func (ip IP) IsMulticast() bool {
574584
// multicast address. If ip is the zero value or an IPv4 address, it will return
575585
// false.
576586
func (ip IP) IsInterfaceLocalMulticast() bool {
587+
// IPv6 Addressing Architecture (2.7.1. Pre-Defined Multicast Addresses)
588+
// https://datatracker.ietf.org/doc/html/rfc4291#section-2.7.1
577589
if ip.Is6() {
578590
return ip.v6u16(0)&0xff0f == 0xff01
579591
}
@@ -583,9 +595,13 @@ func (ip IP) IsInterfaceLocalMulticast() bool {
583595
// IsLinkLocalMulticast reports whether ip is a link-local multicast address.
584596
// If ip is the zero value, it will return false.
585597
func (ip IP) IsLinkLocalMulticast() bool {
598+
// IPv4 Multicast Guidelines (4. Local Network Control Block (224.0.0/24))
599+
// https://datatracker.ietf.org/doc/html/rfc5771#section-4
586600
if ip.Is4() {
587601
return ip.v4(0) == 224 && ip.v4(1) == 0 && ip.v4(2) == 0
588602
}
603+
// IPv6 Addressing Architecture (2.7.1. Pre-Defined Multicast Addresses)
604+
// https://datatracker.ietf.org/doc/html/rfc4291#section-2.7.1
589605
if ip.Is6() {
590606
return ip.v6u16(0)&0xff0f == 0xff02
591607
}

0 commit comments

Comments
 (0)