package websource import "net/netip" // blocked are the ranges no public egress address, and no fetch target, // is ever in: this host, private, shared (CGNAT and the tailnet, // 100.64.0.0/10), link-local and metadata, reserved, documentation, // benchmark and transition ranges. The one list for the egress relay, the // Research fetcher and the site inventory's addresses. var blocked = func() []netip.Prefix { var out []netip.Prefix for _, s := range []string{ "0.0.0.0/8", "10.0.0.0/8", "100.64.0.0/10", "127.0.0.0/8", "169.254.0.0/16", "172.16.0.0/12", "192.0.0.0/24", "192.0.2.0/24", "192.88.99.0/24", "192.168.0.0/16", "198.18.0.0/15", "198.51.100.0/24", "203.0.113.0/24", "224.0.0.0/4", "240.0.0.0/4", "2001::/23", "2001:db8::/32", "2002::/16", "3fff::/20", } { out = append(out, netip.MustParsePrefix(s)) } return out }() var publicV6 = netip.MustParsePrefix("2000::/3") // PublicAddress reports a globally routed unicast address, outside every // private, shared, reserved, documentation and transition range. An // IPv4-mapped address is judged as the IPv4 address it maps. func PublicAddress(a netip.Addr) bool { a = a.Unmap() if !a.IsValid() || a.Zone() != "" || !a.IsGlobalUnicast() || a.IsPrivate() || a.IsLoopback() || a.IsLinkLocalUnicast() { return false } if a.Is6() && !publicV6.Contains(a) { return false } for _, p := range blocked { if p.Contains(a) { return false } } return true }