// addrDetail represents the details of an Addr, like address family and IPv6 zone.
type addrDetail struct {
- IsV6 bool // IPv4 is false, IPv6 is true.
- ZoneV6 string // != "" only if IsV6 is true.
+ isV6 bool // IPv4 is false, IPv6 is true.
+ zoneV6 string // != "" only if IsV6 is true.
}
// z0, z4, and z6noz are sentinel Addr.z values.
var (
z0 unique.Handle[addrDetail]
z4 = unique.Make(addrDetail{})
- z6noz = unique.Make(addrDetail{IsV6: true})
+ z6noz = unique.Make(addrDetail{isV6: true})
)
// IPv6LinkLocalAllNodes returns the IPv6 link-local all nodes multicast
if ip.z == z0 {
return ""
}
- return ip.z.Value().ZoneV6
+ return ip.z.Value().zoneV6
}
// Compare returns an integer comparing two IPs.
ip.z = z6noz
return ip
}
- ip.z = unique.Make(addrDetail{IsV6: true, ZoneV6: zone})
+ ip.z = unique.Make(addrDetail{isV6: true, zoneV6: zone})
return ip
}
// IPv6 with a zone specifier.
{
in: "fd7a:115c:a1e0:ab12:4843:cd96:626b:430b%eth0",
- ip: MkAddr(Mk128(0xfd7a115ca1e0ab12, 0x4843cd96626b430b), unique.Make(AddrDetail{IsV6: true, ZoneV6: "eth0"})),
+ ip: MkAddr(Mk128(0xfd7a115ca1e0ab12, 0x4843cd96626b430b), unique.Make(MakeAddrDetail(true, "eth0"))),
},
// IPv6 with dotted decimal and zone specifier.
{
in: "1:2::ffff:192.168.140.255%eth1",
- ip: MkAddr(Mk128(0x0001000200000000, 0x0000ffffc0a88cff), unique.Make(AddrDetail{IsV6: true, ZoneV6: "eth1"})),
+ ip: MkAddr(Mk128(0x0001000200000000, 0x0000ffffc0a88cff), unique.Make(MakeAddrDetail(true, "eth1"))),
str: "1:2::ffff:c0a8:8cff%eth1",
},
// 4-in-6 with zone
{
in: "::ffff:192.168.140.255%eth1",
- ip: MkAddr(Mk128(0, 0x0000ffffc0a88cff), unique.Make(AddrDetail{IsV6: true, ZoneV6: "eth1"})),
+ ip: MkAddr(Mk128(0, 0x0000ffffc0a88cff), unique.Make(MakeAddrDetail(true, "eth1"))),
str: "::ffff:192.168.140.255%eth1",
},
// IPv6 with capital letters.
}
func BenchmarkParseAddr(b *testing.B) {
- sinkInternValue = unique.Make(AddrDetail{IsV6: true, ZoneV6: "eth1"}) // Pin to not benchmark the intern package
+ sinkInternValue = unique.Make(MakeAddrDetail(true, "eth1")) // Pin to not benchmark the intern package
for _, test := range parseBenchInputs {
b.Run(test.name, func(b *testing.B) {
b.ReportAllocs()