|
|
|
@ -118,21 +118,31 @@ func (m *Machine) tryApplyWireguardConfig(ring int) error {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (m *Machine) applyWireguardConfig(ring int, wg *wireguard.Config) error { |
|
|
|
|
func (m *Machine) applyWireguardConfigNode(ring int, wg *wireguard.Config) error { |
|
|
|
|
addr := wg.GetAddress() |
|
|
|
|
zoneID, nodeID, ok := Rings[ring].Decode(addr) |
|
|
|
|
if !ok { |
|
|
|
|
return fmt.Errorf("%s: invalid address", addr) |
|
|
|
|
} |
|
|
|
|
if !core.IsZero(addr) { |
|
|
|
|
zoneID, nodeID, ok := Rings[ring].Decode(addr) |
|
|
|
|
if !ok { |
|
|
|
|
return fmt.Errorf("%s: invalid address", addr) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if err := m.applyZoneNodeID(zoneID, nodeID); err != nil { |
|
|
|
|
return core.Wrap(err, "%s: invalid address", addr) |
|
|
|
|
if err := m.applyZoneNodeID(zoneID, nodeID); err != nil { |
|
|
|
|
return core.Wrap(err, "%s: invalid address", addr) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if err := m.applyWireguardInterfaceConfig(ring, wg.Interface); err != nil { |
|
|
|
|
return core.Wrap(err, "interface") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (m *Machine) applyWireguardConfig(ring int, wg *wireguard.Config) error { |
|
|
|
|
if err := m.applyWireguardConfigNode(ring, wg); err != nil { |
|
|
|
|
return err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for _, peer := range wg.Peer { |
|
|
|
|
err := m.applyWireguardPeerConfig(ring, peer) |
|
|
|
|
switch { |
|
|
|
@ -230,6 +240,23 @@ func (m *Machine) applyZoneNodeID(zoneID, nodeID int) error {
|
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (m *Machine) setRingDefaults(ri *RingInfo) error { |
|
|
|
|
if ri.Keys.PrivateKey.IsZero() { |
|
|
|
|
m.info(). |
|
|
|
|
WithField("subsystem", "wireguard"). |
|
|
|
|
WithField("node", m.Name). |
|
|
|
|
WithField("ring", ri.Ring). |
|
|
|
|
Print("generating key pair") |
|
|
|
|
|
|
|
|
|
kp, err := wireguard.NewKeyPair() |
|
|
|
|
if err != nil { |
|
|
|
|
return err |
|
|
|
|
} |
|
|
|
|
ri.Keys = kp |
|
|
|
|
} |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// RemoveWireguardConfig deletes wgN.conf from the machine's
|
|
|
|
|
// config directory.
|
|
|
|
|
func (m *Machine) RemoveWireguardConfig(ring int) error { |
|
|
|
|