all: fork tailscale Linux dns manager package

With modification to fit our use case.
This commit is contained in:
Cuong Manh Le
2023-02-03 02:04:30 +07:00
committed by Cuong Manh Le
parent b8772d7b4a
commit 851f9b9742
18 changed files with 2735 additions and 9 deletions

View File

@@ -16,12 +16,16 @@ import (
"github.com/insomniacslk/dhcp/dhcpv4/nclient4"
"github.com/insomniacslk/dhcp/dhcpv6"
"github.com/insomniacslk/dhcp/dhcpv6/client6"
"tailscale.com/net/dns"
"tailscale.com/util/dnsname"
"github.com/Control-D-Inc/ctrld/internal/dns"
"github.com/Control-D-Inc/ctrld/internal/resolvconffile"
)
var logf = func(format string, args ...any) {
mainLog.Debug().Msgf(format, args...)
}
// allocate loopback ip
// sudo ip a add 127.0.0.2/24 dev lo
func allocateIP(ip string) error {
@@ -46,16 +50,12 @@ const maxSetDNSAttempts = 5
// set the dns server for the provided network interface
func setDNS(iface *net.Interface, nameservers []string) error {
logf := func(format string, args ...any) {
mainLog.Debug().Msgf(format, args...)
}
r, err := dns.NewOSConfigurator(logf, iface.Name)
if err != nil {
mainLog.Error().Err(err).Msg("failed to create DNS OS configurator")
return err
}
defer r.Close()
ns := make([]netip.Addr, 0, len(nameservers))
for _, nameserver := range nameservers {
ns = append(ns, netip.MustParseAddr(nameserver))
@@ -80,6 +80,16 @@ func setDNS(iface *net.Interface, nameservers []string) error {
}
func resetDNS(iface *net.Interface) error {
if r, err := dns.NewOSConfigurator(logf, iface.Name); err == nil {
if err := r.Close(); err != nil {
mainLog.Error().Err(err).Msg("failed to rollback DNS setting")
return err
}
if r.Mode() == "direct" {
return nil
}
}
var ns []string
c, err := nclient4.New(iface.Name)
if err != nil {

View File

@@ -1,6 +1,8 @@
package main
import "github.com/kardianos/service"
import (
"github.com/kardianos/service"
)
func (p *prog) preRun() {
if !service.Interactive() {