Skip to content

Commit

Permalink
add IPv4 link-local address to private ranges detector, update list
Browse files Browse the repository at this point in the history
169.254.0.0/16 is this new range is the same as fe80::/10 for IPv6.

Also, add comments to each entry according to provided link and replace
192.0.0.0/24 with more specific prefixes according to standard.
  • Loading branch information
paskal committed Aug 4, 2024
1 parent a087e36 commit 81b535a
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions realip/real.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,22 @@ type ipRange struct {
end net.IP
}

// privateRanges contains the list of private and special-use IP ranges.
// reference: https://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml
var privateRanges = []ipRange{
// IPv4 Private Ranges
{start: net.ParseIP("10.0.0.0"), end: net.ParseIP("10.255.255.255")},
{start: net.ParseIP("100.64.0.0"), end: net.ParseIP("100.127.255.255")},
{start: net.ParseIP("172.16.0.0"), end: net.ParseIP("172.31.255.255")},
{start: net.ParseIP("192.0.0.0"), end: net.ParseIP("192.0.0.255")},
{start: net.ParseIP("192.168.0.0"), end: net.ParseIP("192.168.255.255")},
// IPv4 Link-Local
{start: net.ParseIP("169.254.0.0"), end: net.ParseIP("169.254.255.255")},
// IPv4 Shared Address Space (RFC 6598)
{start: net.ParseIP("100.64.0.0"), end: net.ParseIP("100.127.255.255")},
// IPv4 Benchmarking (RFC 2544)
{start: net.ParseIP("198.18.0.0"), end: net.ParseIP("198.19.255.255")},
{start: net.ParseIP("::1"), end: net.ParseIP("::1")},
// IPv6 Unique Local Addresses (ULA)
{start: net.ParseIP("fc00::"), end: net.ParseIP("fdff:ffff:ffff:ffff:ffff:ffff:ffff:ffff")},
// IPv6 Link-local Addresses
{start: net.ParseIP("fe80::"), end: net.ParseIP("febf:ffff:ffff:ffff:ffff:ffff:ffff:ffff")},
}

Expand Down

0 comments on commit 81b535a

Please sign in to comment.