Compare commits

..

4 Commits

Author SHA1 Message Date
amery 49632d4cb6 WIP
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-08-25 17:12:08 +00:00
amery 829f301719 zones: change WriteEnv() to not fake gateways
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-08-25 17:12:08 +00:00
amery 2a07b1f21f zones: add Zone.SetGateway() to set one by ID
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-08-25 17:12:08 +00:00
amery c390f45081 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:12:02 +00:00
3 changed files with 33 additions and 28 deletions
+1 -1
View File
@@ -58,7 +58,7 @@ func (m *Machine) SetGateway(enabled bool) error {
}
ri.Enabled = enabled
return m.SyncWireguardConfig(0)
return m.syncRingConfig(0)
}
func (m *Machine) getPeerByName(name string) (*Machine, bool) {
+32 -4
View File
@@ -262,10 +262,9 @@ func (m *Machine) RemoveWireguardConfig(ring int) error {
return err
}
// SyncWireguardConfig updates all wgN.conf files for the specified
// ring
func (m *Machine) SyncWireguardConfig(ring int) error {
return m.zone.SyncWireguardConfig(ring)
func (*Machine) syncRingConfig(_ int) error {
// _, err := m.getRingNodes(ring)
return nil
}
func (m *Machine) createRingInfo(ring int, enabled bool) (*RingInfo, error) {
@@ -287,3 +286,32 @@ 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
@@ -1,23 +0,0 @@
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
}