Compare commits

..

5 Commits

Author SHA1 Message Date
amery 2525026e2d WIP
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-08-25 17:41:04 +00:00
amery 051e441a68 zones: change WriteEnv() to not fake gateways
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-08-25 17:41:04 +00:00
amery 3013303ece zones: add Zone.SetGateway() to set one by ID
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-08-25 17:41:04 +00:00
amery ff2cbdc3c5 zones: set first node of a Zone as ring0 gateway if it doesn't have one already
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-08-25 17:41:04 +00:00
amery b9e98ca322 zones: Zone.PruneWireguardConfig()
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-08-25 17:41:04 +00:00
3 changed files with 28 additions and 33 deletions
+1 -1
View File
@@ -58,7 +58,7 @@ func (m *Machine) SetGateway(enabled bool) error {
}
ri.Enabled = enabled
return m.syncRingConfig(0)
return m.SyncWireguardConfig(0)
}
func (m *Machine) getPeerByName(name string) (*Machine, bool) {
+4 -32
View File
@@ -262,9 +262,10 @@ func (m *Machine) RemoveWireguardConfig(ring int) error {
return err
}
func (*Machine) syncRingConfig(_ int) error {
// _, err := m.getRingNodes(ring)
return nil
// SyncWireguardConfig updates all wgN.conf files for the specified
// ring
func (m *Machine) SyncWireguardConfig(ring int) error {
return m.zone.SyncWireguardConfig(ring)
}
func (m *Machine) createRingInfo(ring int, enabled bool) (*RingInfo, error) {
@@ -286,32 +287,3 @@ func (m *Machine) createRingInfo(ring int, enabled bool) (*RingInfo, error) {
return ri, nil
}
func (m *Machine) writeRingInfo(ri *RingInfo) error {
var err error
if m == nil || ri == nil {
return fs.ErrInvalid
}
err = m.WriteWireguardKeys(ri.Ring)
if err != nil {
return err
}
if !ri.Enabled {
return m.RemoveWireguardConfig(ri.Ring)
}
return m.writeRingInfoConf(ri.Ring, ri.Keys.PrivateKey)
}
func (m *Machine) writeRingInfoConf(ring int, _ wireguard.PrivateKey) error {
f, err := m.CreateTruncFile("wg%v.conf", ring)
if err != nil {
return err
}
defer f.Close()
return nil
}
+23
View File
@@ -0,0 +1,23 @@
package zones
// SyncWireguardConfig updates all wgN.conf files for the specified
// ring
func (z *Zone) SyncWireguardConfig(ring int) error {
return z.PruneWireguardConfig(ring)
}
// PruneWireguardConfig removes wgN.conf files of machines with
// the corresponding ring disabled.
func (z *Zone) PruneWireguardConfig(ring int) error {
var err error
z.ForEachMachine(func(p *Machine) bool {
_, ok := p.getRingInfo(ring)
if !ok {
err = p.RemoveWireguardConfig(ring)
}
return err != nil
})
return err
}