execute interface hooks if interface settings have changed (#224)

This commit is contained in:
Christoph Haas 2024-04-02 20:51:09 +02:00
parent c17c182926
commit 95e10dcc24
2 changed files with 21 additions and 4 deletions

View File

@ -28,6 +28,7 @@ func (r *WgQuickRepo) ExecuteInterfaceHook(id domain.InterfaceIdentifier, hookCm
return nil return nil
} }
logrus.Tracef("interface %s: executing hook %s", id, hookCmd)
err := r.exec(hookCmd, id) err := r.exec(hookCmd, id)
if err != nil { if err != nil {
return fmt.Errorf("failed to exec hook: %w", err) return fmt.Errorf("failed to exec hook: %w", err)

View File

@ -202,9 +202,6 @@ func (m Manager) RestoreInterfaceState(ctx context.Context, updateDbOnError bool
// try to move interface to stored state // try to move interface to stored state
_, err = m.saveInterface(ctx, &iface, peers) _, err = m.saveInterface(ctx, &iface, peers)
if err != nil {
return err
}
if err != nil { if err != nil {
if updateDbOnError { if updateDbOnError {
// disable interface in database as no physical interface is available // disable interface in database as no physical interface is available
@ -469,7 +466,26 @@ func (m Manager) hasInterfaceStateChanged(ctx context.Context, iface *domain.Int
return false return false
} }
return oldInterface.IsDisabled() != iface.IsDisabled() if oldInterface.IsDisabled() != iface.IsDisabled() {
return true // interface in db has changed
}
wgInterface, err := m.wg.GetInterface(ctx, iface.Identifier)
if err != nil {
return true // interface might not exist - so we assume that there must be a change
}
// compare physical interface settings
if len(wgInterface.Addresses) != len(iface.Addresses) ||
wgInterface.Mtu != iface.Mtu ||
wgInterface.FirewallMark != iface.FirewallMark ||
wgInterface.ListenPort != iface.ListenPort ||
wgInterface.PrivateKey != iface.PrivateKey ||
wgInterface.PublicKey != iface.PublicKey {
return true
}
return false
} }
func (m Manager) handleInterfacePreSaveActions(iface *domain.Interface) error { func (m Manager) handleInterfacePreSaveActions(iface *domain.Interface) error {