Skip to content

Commit

Permalink
fixed network cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
nustiueudinastea committed Sep 17, 2024
1 parent 0ab23e2 commit 23a443e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions apic/apic.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 13 additions & 1 deletion internal/wireguard/link_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down

0 comments on commit 23a443e

Please sign in to comment.