Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a3e3cde4c4 | |||
| a4a10d0226 |
@@ -0,0 +1,49 @@
|
|||||||
|
package zones
|
||||||
|
|
||||||
|
import "net/netip"
|
||||||
|
|
||||||
|
// ParseRingZeroAddress extracts zone and node ID from a wg0 [netip.Addr]
|
||||||
|
func ParseRingZeroAddress(addr netip.Addr) (zoneID int, nodeID int, ok bool) {
|
||||||
|
if addr.IsValid() {
|
||||||
|
a4 := addr.As4()
|
||||||
|
|
||||||
|
if a4[0] == 10 && a4[1] == 0 {
|
||||||
|
return int(a4[2]), int(a4[3]), true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0, 0, false
|
||||||
|
}
|
||||||
|
|
||||||
|
// RingZeroAddress returns a wg0 IP address
|
||||||
|
func RingZeroAddress(zoneID, nodeID int) netip.Addr {
|
||||||
|
c := zoneID
|
||||||
|
d := nodeID
|
||||||
|
|
||||||
|
return netip.AddrFrom4([4]byte{
|
||||||
|
10, 0, uint8(c), uint8(d),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// ParseRingOneAddress extracts zone and node ID from a wg1 [netip.Addr]
|
||||||
|
func ParseRingOneAddress(addr netip.Addr) (zoneID int, nodeID int, ok bool) {
|
||||||
|
if addr.IsValid() {
|
||||||
|
a4 := addr.As4()
|
||||||
|
|
||||||
|
if a4[0] == 10 && a4[2] == 0 {
|
||||||
|
zoneID = int(a4[1] >> 4)
|
||||||
|
nodeID = int(a4[3])
|
||||||
|
return zoneID, nodeID, true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0, 0, false
|
||||||
|
}
|
||||||
|
|
||||||
|
// RingOneAddress returns a wg1 IP address
|
||||||
|
func RingOneAddress(zoneID, nodeID int) netip.Addr {
|
||||||
|
b := zoneID << 4
|
||||||
|
d := nodeID
|
||||||
|
|
||||||
|
return netip.AddrFrom4([4]byte{
|
||||||
|
10, uint8(b), 0, uint8(d),
|
||||||
|
})
|
||||||
|
}
|
||||||
+12
-12
@@ -26,7 +26,17 @@ func (m *Zones) scan() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return m.scanMachines()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Zones) scanMachines() error {
|
||||||
|
var err error
|
||||||
|
m.ForEachMachine(func(p *Machine) {
|
||||||
|
if err == nil {
|
||||||
|
err = p.scan()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (z *Zone) scan() error {
|
func (z *Zone) scan() error {
|
||||||
@@ -47,15 +57,5 @@ func (z *Zone) scan() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return z.scanMachines()
|
return nil
|
||||||
}
|
|
||||||
|
|
||||||
func (z *Zone) scanMachines() error {
|
|
||||||
var err error
|
|
||||||
z.zones.ForEachMachine(func(m *Machine) {
|
|
||||||
if err == nil {
|
|
||||||
err = m.scan()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user