v1.17.0
ADDED: * netx: ** docs updated ** added NOTES.adoc for more extensive info that doesn't need to be in the library docs ** Addr4in6Compat() ** Addr4in6Mapped() ** Addr4in6Mapped() ** HasSubnet() ** IP4MapPfx4to6() ** IP4MapPfx6to4() ** IPSetCombined() ** IPSetFrom() ** IPSetFromNative() ** IsAddr4Compat() ** IsPublic() ** MustIPSetCombined() ** MustIPSetFrom() ** MustIPSetFromNative() ** Pfx4in6Compat() (untested) ** Pfx4in6Mapped() (untested) ** UnmapAddr() ** UnmapPfx() ** Better support in other functions for IPv4-Compatible/IPv4-Mapped addressing
This commit is contained in:
+45
-3
@@ -1,10 +1,52 @@
|
||||
package netx
|
||||
|
||||
import (
|
||||
`net/netip`
|
||||
"net/netip"
|
||||
|
||||
"go4.org/netipx"
|
||||
)
|
||||
|
||||
const (
|
||||
ip4in6Legacy96 string = "::"
|
||||
ip4in6Modern96 string = "::ffff:"
|
||||
)
|
||||
|
||||
var (
|
||||
ip4In6Legacy netip.Prefix = netip.MustParsePrefix("::/96")
|
||||
ip4In6Modern netip.Prefix = netip.MustParsePrefix("::ffff:0:0/96")
|
||||
// IPv4 documentation prefixes (RFC 5737)
|
||||
ipDoc4pfxs []netip.Prefix = []netip.Prefix{
|
||||
netip.MustParsePrefix("192.0.2.0/24"),
|
||||
netip.MustParsePrefix("198.51.100.0/24"),
|
||||
netip.MustParsePrefix("203.0.113.0/24"),
|
||||
}
|
||||
ipDoc4 *netipx.IPSet = MustIPSetFromNative(nil, ipDoc4pfxs, nil)
|
||||
// IPv6 documentation prefixes (RFC 3849, RFC 9637)
|
||||
ipDoc6pfxs []netip.Prefix = []netip.Prefix{
|
||||
netip.MustParsePrefix("2001:db8::/32"),
|
||||
netip.MustParsePrefix("3fff::/20"),
|
||||
}
|
||||
ipDoc6 *netipx.IPSet = MustIPSetFromNative(nil, ipDoc6pfxs, nil)
|
||||
// combined documentation prefixes
|
||||
ipDoc *netipx.IPSet = MustIPSetCombined(
|
||||
[]*netipx.IPSet{
|
||||
ipDoc4,
|
||||
ipDoc6,
|
||||
},
|
||||
)
|
||||
|
||||
// CGNAT/LSN (RFC 6598)
|
||||
cgnat4 netip.Prefix = netip.MustParsePrefix("100.64.0.0/10")
|
||||
|
||||
// IPv4-Compatible IPv6 Address, RFC 4291 § 2.5.5.1
|
||||
ip4in6Legacy netip.Prefix = netip.MustParsePrefix(ip4in6Legacy96 + "/96")
|
||||
// IPv4-Mapped IPv6 Address, RFC 4291 § 2.5.5.2
|
||||
ip4in6Modern netip.Prefix = netip.MustParsePrefix(ip4in6Modern96 + "0:0/96")
|
||||
// both
|
||||
ip4in6 *netipx.IPSet = MustIPSetFromNative(
|
||||
nil,
|
||||
[]netip.Prefix{
|
||||
ip4in6Legacy,
|
||||
ip4in6Modern,
|
||||
},
|
||||
nil,
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user