Compare commits

..

1 Commits

Author SHA1 Message Date
amery 4345a17d9a Merge pull request 'cluster: fix wg0.conf generator' (#54) from pr-amery-wg0.conf into main
Reviewed-on: #54
2024-07-24 19:31:22 +02:00
+5 -19
View File
@@ -6,7 +6,6 @@ import (
"net/netip" "net/netip"
"strconv" "strconv"
"darvaza.org/core"
"git.jpi.io/amery/jpictl/pkg/rings" "git.jpi.io/amery/jpictl/pkg/rings"
"git.jpi.io/amery/jpictl/pkg/wireguard" "git.jpi.io/amery/jpictl/pkg/wireguard"
) )
@@ -226,28 +225,17 @@ func (r *Ring) setRingZeroAllowedIPs(rp *RingPeer) {
rp.AllowCIDR(rp.Address, 32) rp.AllowCIDR(rp.Address, 32)
} }
// revive:disable:cognitive-complexity
func (r *Ring) setRingOneGatewayAllowedIPs(rp *RingPeer) { func (r *Ring) setRingOneGatewayAllowedIPs(rp *RingPeer) {
// revive:enable:cognitive-complexity
regionID, zoneID, _, _ := r.Decode(rp.Address) regionID, zoneID, _, _ := r.Decode(rp.Address)
// peer // peer
rp.AllowCIDR(rp.Address, 32) rp.AllowCIDR(rp.Address, 32)
// ring1 gateways connect to all other ring1 networks // ring1 gateways connect to all other ring1 networks
m, ok := r.ZoneIterator.(RegionIterator) r.ForEachZone(func(z *Zone) bool {
if !ok { if !z.Is(regionID, zoneID) {
panic("Cannot iterate Region from Zone") subnet := z.RingOnePrefix()
} rp.AllowSubnet(subnet)
m.ForEachRegion(func(r2 *Region) bool {
if r2.IsPrimary() {
r.ForEachZone(func(z *Zone) bool {
if !z.Is(regionID, zoneID) {
subnet := z.RingOnePrefix()
rp.AllowSubnet(subnet)
}
return false
})
} }
return false return false
}) })
@@ -328,9 +316,7 @@ func (rp *RingPeer) AllowCIDR(addr netip.Addr, bits int) {
// AllowSubnet allows an IP range via this peer // AllowSubnet allows an IP range via this peer
func (rp *RingPeer) AllowSubnet(subnet netip.Prefix) { func (rp *RingPeer) AllowSubnet(subnet netip.Prefix) {
if !core.SliceContains(rp.PeerConfig.AllowedIPs, subnet) { rp.PeerConfig.AllowedIPs = append(rp.PeerConfig.AllowedIPs, subnet)
rp.PeerConfig.AllowedIPs = append(rp.PeerConfig.AllowedIPs, subnet)
}
} }
// NewRing composes a new Ring for Wireguard setup // NewRing composes a new Ring for Wireguard setup