cmd/ctrld: add --iface for setting DNS on specific interface

This commit is contained in:
Cuong Manh Le
2023-01-06 00:55:21 +07:00
committed by Cuong Manh Le
parent d5344aea52
commit b00a7c34ee
13 changed files with 473 additions and 45 deletions

View File

@@ -0,0 +1,35 @@
//go:build !js && !windows
package resolvconffile
import (
"net"
"tailscale.com/net/dns/resolvconffile"
)
const resolvconfPath = "/etc/resolv.conf"
func NameServersWithPort() []string {
c, err := resolvconffile.ParseFile(resolvconfPath)
if err != nil {
return nil
}
ns := make([]string, 0, len(c.Nameservers))
for _, nameserver := range c.Nameservers {
ns = append(ns, net.JoinHostPort(nameserver.String(), "53"))
}
return ns
}
func NameServers(_ string) []string {
c, err := resolvconffile.ParseFile(resolvconfPath)
if err != nil {
return nil
}
ns := make([]string, 0, len(c.Nameservers))
for _, nameserver := range c.Nameservers {
ns = append(ns, nameserver.String())
}
return ns
}

View File

@@ -0,0 +1,13 @@
package resolvconffile
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestNameServers(t *testing.T) {
ns := NameServers("")
require.NotNil(t, ns)
t.Log(ns)
}