cmd/cli: ignore un-usable interfaces on darwin

So multi interfaces config won't emit un-necessary errors if the network
cable adapters are not being used on MacOS.
This commit is contained in:
Cuong Manh Le
2024-03-06 15:05:08 +07:00
committed by Cuong Manh Le
parent a9672dfff5
commit 8c7c3901e8
5 changed files with 30 additions and 2 deletions
+13
View File
@@ -6,6 +6,7 @@ import (
"fmt"
"net"
"os/exec"
"strings"
"github.com/Control-D-Inc/ctrld/internal/resolvconffile"
)
@@ -30,6 +31,18 @@ func deAllocateIP(ip string) error {
return nil
}
// setDnsIgnoreUnusableInterface likes setDNS, but return a nil error if the interface is not usable.
func setDnsIgnoreUnusableInterface(iface *net.Interface, nameservers []string) error {
if err := setDNS(iface, nameservers); err != nil {
// TODO: investiate whether we can detect this without relying on error message.
if strings.Contains(err.Error(), " is not a recognized network service") {
return nil
}
return err
}
return nil
}
// set the dns server for the provided network interface
// networksetup -setdnsservers Wi-Fi 8.8.8.8 1.1.1.1
// TODO(cuonglm): use system API