|
|
@ -14,7 +14,7 @@ func RingZeroPrefix(region RegionID, zone ZoneID) (cidr netip.Prefix, err error) |
|
|
|
case !zone.Valid(): |
|
|
|
case !zone.Valid(): |
|
|
|
err = ErrOutOfRange(zone, "zone") |
|
|
|
err = ErrOutOfRange(zone, "zone") |
|
|
|
default: |
|
|
|
default: |
|
|
|
addr := unsafeRingZeroAddress(region, zone, 0) |
|
|
|
addr := UnsafeRingZeroAddress(region, zone, 0) |
|
|
|
cidr = netip.PrefixFrom(addr, RingZeroBits) |
|
|
|
cidr = netip.PrefixFrom(addr, RingZeroBits) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -33,7 +33,7 @@ func RingZeroAddress(region RegionID, zone ZoneID, node NodeID) (addr netip.Addr |
|
|
|
case !node.ValidZero(): |
|
|
|
case !node.ValidZero(): |
|
|
|
err = ErrOutOfRange(node, "node") |
|
|
|
err = ErrOutOfRange(node, "node") |
|
|
|
default: |
|
|
|
default: |
|
|
|
addr = unsafeRingZeroAddress(region, zone, node) |
|
|
|
addr = UnsafeRingZeroAddress(region, zone, node) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return addr, err |
|
|
|
return addr, err |
|
|
@ -52,7 +52,7 @@ func RingOnePrefix(region RegionID, zone ZoneID) (cidr netip.Prefix, err error) |
|
|
|
case !zone.Valid(): |
|
|
|
case !zone.Valid(): |
|
|
|
err = ErrOutOfRange(zone, "zone") |
|
|
|
err = ErrOutOfRange(zone, "zone") |
|
|
|
default: |
|
|
|
default: |
|
|
|
addr := unsafeRingOneAddress(region, zone, 0) |
|
|
|
addr := UnsafeRingOneAddress(region, zone, 0) |
|
|
|
cidr = netip.PrefixFrom(addr, RingOneBits) |
|
|
|
cidr = netip.PrefixFrom(addr, RingOneBits) |
|
|
|
} |
|
|
|
} |
|
|
|
return cidr, err |
|
|
|
return cidr, err |
|
|
@ -71,7 +71,7 @@ func RingOneAddress(region RegionID, zone ZoneID, node NodeID) (addr netip.Addr, |
|
|
|
case !node.Valid(): |
|
|
|
case !node.Valid(): |
|
|
|
err = ErrOutOfRange(node, "node") |
|
|
|
err = ErrOutOfRange(node, "node") |
|
|
|
default: |
|
|
|
default: |
|
|
|
addr = unsafeRingOneAddress(region, zone, node) |
|
|
|
addr = UnsafeRingOneAddress(region, zone, node) |
|
|
|
} |
|
|
|
} |
|
|
|
return addr, err |
|
|
|
return addr, err |
|
|
|
} |
|
|
|
} |
|
|
@ -86,7 +86,7 @@ func RingTwoPrefix(region RegionID) (cidr netip.Prefix, err error) { |
|
|
|
case !region.Valid(): |
|
|
|
case !region.Valid(): |
|
|
|
err = ErrOutOfRange(region, "region") |
|
|
|
err = ErrOutOfRange(region, "region") |
|
|
|
default: |
|
|
|
default: |
|
|
|
addr := unsafeRingTwoAddress(region, 0) |
|
|
|
addr := UnsafeRingTwoAddress(region, 0) |
|
|
|
cidr = netip.PrefixFrom(addr, RingTwoBits) |
|
|
|
cidr = netip.PrefixFrom(addr, RingTwoBits) |
|
|
|
} |
|
|
|
} |
|
|
|
return cidr, err |
|
|
|
return cidr, err |
|
|
@ -101,20 +101,25 @@ func RingThreePrefix(region RegionID) (subnet netip.Prefix, err error) { |
|
|
|
case !region.Valid(): |
|
|
|
case !region.Valid(): |
|
|
|
err = ErrOutOfRange(region, "region") |
|
|
|
err = ErrOutOfRange(region, "region") |
|
|
|
default: |
|
|
|
default: |
|
|
|
addr := unsafeRingThreeAddress(region, 0) |
|
|
|
addr := UnsafeRingThreeAddress(region, 0) |
|
|
|
subnet = netip.PrefixFrom(addr, RingThreeBits) |
|
|
|
subnet = netip.PrefixFrom(addr, RingThreeBits) |
|
|
|
} |
|
|
|
} |
|
|
|
return subnet, err |
|
|
|
return subnet, err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func unsafeRingZeroAddress(region RegionID, zone ZoneID, node NodeID) netip.Addr { |
|
|
|
// UnsafeRingZeroAddress is equivalent ot RingZeroAddress but without validating
|
|
|
|
|
|
|
|
// the input.
|
|
|
|
|
|
|
|
func UnsafeRingZeroAddress(region RegionID, zone ZoneID, node NodeID) netip.Addr { |
|
|
|
r := uint(region) |
|
|
|
r := uint(region) |
|
|
|
z := uint(zone) |
|
|
|
z := uint(zone) |
|
|
|
n := uint(node) |
|
|
|
n := uint(node) |
|
|
|
|
|
|
|
|
|
|
|
return AddrFrom4(10, 0, r<<4+z, n) |
|
|
|
return AddrFrom4(10, 0, r<<4+z, n) |
|
|
|
} |
|
|
|
} |
|
|
|
func unsafeRingOneAddress(region RegionID, zone ZoneID, node NodeID) netip.Addr { |
|
|
|
|
|
|
|
|
|
|
|
// UnsafeRingOneAddress is equivalent ot RingOneAddress but without validating
|
|
|
|
|
|
|
|
// the input.
|
|
|
|
|
|
|
|
func UnsafeRingOneAddress(region RegionID, zone ZoneID, node NodeID) netip.Addr { |
|
|
|
r := uint(region) |
|
|
|
r := uint(region) |
|
|
|
z := uint(zone) |
|
|
|
z := uint(zone) |
|
|
|
n := uint(node) |
|
|
|
n := uint(node) |
|
|
@ -125,7 +130,9 @@ func unsafeRingOneAddress(region RegionID, zone ZoneID, node NodeID) netip.Addr |
|
|
|
return AddrFrom4(10, r, z<<4+n1, n0) |
|
|
|
return AddrFrom4(10, r, z<<4+n1, n0) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func unsafeRingTwoAddress(region RegionID, n uint) netip.Addr { |
|
|
|
// UnsafeRingTwoAddress is equivalent ot RingTwoAddress but without validating
|
|
|
|
|
|
|
|
// the input.
|
|
|
|
|
|
|
|
func UnsafeRingTwoAddress(region RegionID, n uint) netip.Addr { |
|
|
|
r := uint(region) |
|
|
|
r := uint(region) |
|
|
|
|
|
|
|
|
|
|
|
n1 := n >> 8 |
|
|
|
n1 := n >> 8 |
|
|
@ -134,7 +141,9 @@ func unsafeRingTwoAddress(region RegionID, n uint) netip.Addr { |
|
|
|
return AddrFrom4(10, r, n1, n0) |
|
|
|
return AddrFrom4(10, r, n1, n0) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func unsafeRingThreeAddress(region RegionID, n uint) netip.Addr { |
|
|
|
// UnsafeRingThreeAddress is equivalent ot RingThreeAddress but without validating
|
|
|
|
|
|
|
|
// the input.
|
|
|
|
|
|
|
|
func UnsafeRingThreeAddress(region RegionID, n uint) netip.Addr { |
|
|
|
r := uint(region) |
|
|
|
r := uint(region) |
|
|
|
|
|
|
|
|
|
|
|
n2 := n >> 16 |
|
|
|
n2 := n >> 16 |
|
|
|