From 23a443e0dbb077fa3c7a961b8dc3e07d63ea48a9 Mon Sep 17 00:00:00 2001 From: Alex Giurgiu Date: Tue, 17 Sep 2024 13:37:28 +0300 Subject: [PATCH] fixed network cleanup --- apic/apic.go | 1 + internal/wireguard/link_darwin.go | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/apic/apic.go b/apic/apic.go index c08dd5a..10b2c42 100644 --- a/apic/apic.go +++ b/apic/apic.go @@ -85,6 +85,7 @@ func StartGRPCServer(dataPath string, version string, protosClient *protosc.Prot log.Info("stopping gRPC server") srv.GracefulStop() if protosClient.NetworkManager != nil { + log.Info("bringing down network") err = protosClient.NetworkManager.Down() if err != nil { log.Error(err) diff --git a/internal/wireguard/link_darwin.go b/internal/wireguard/link_darwin.go index 500c68a..e798e6c 100644 --- a/internal/wireguard/link_darwin.go +++ b/internal/wireguard/link_darwin.go @@ -340,8 +340,14 @@ func (m *linkMngr) CreateLink(name string) (Link, error) { } func (m *linkMngr) DelLink(name string) error { + interfaceFile := fmt.Sprintf("%s/%s.name", m.interfacesDir, name) lnk, err := m.GetLink(name) if err != nil { + // remove the .name file + err = os.Remove(interfaceFile) + if err != nil { + return fmt.Errorf("could not delete link '%s': %w", name, err) + } return err } @@ -351,14 +357,20 @@ func (m *linkMngr) DelLink(name string) error { cmd := exec.Command(sudoPath, rmPath, "-f", link.interfaceSockFile) output, err := cmd.CombinedOutput() if err != nil { + // remove the .name file + err = os.Remove(interfaceFile) + if err != nil { + return fmt.Errorf("could not delete link '%s': %w", name, err) + } return fmt.Errorf("failed to delete link '%s': \n---- output ----\n%s-------------------", name, string(output)) } // remove the .name file - err = os.Remove(link.interfaceNameFile) + err = os.Remove(interfaceFile) if err != nil { return fmt.Errorf("could not delete link '%s': %w", name, err) } + return nil }