-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
don't try to start tunneler in intercept mode unless on linux
- Loading branch information
1 parent
ec06ce2
commit 4fe50f7
Showing
3 changed files
with
92 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
//go:build linux | ||
|
||
package dns | ||
|
||
import ( | ||
"fmt" | ||
"github.com/miekg/dns" | ||
"github.com/sirupsen/logrus" | ||
"net" | ||
"os/exec" | ||
"sync" | ||
"time" | ||
) | ||
|
||
func NewDnsServer(addr string) (Resolver, error) { | ||
log.Infof("starting dns server...") | ||
s := &dns.Server{ | ||
Addr: addr, | ||
Net: "udp", | ||
} | ||
|
||
names := make(map[string]net.IP) | ||
r := &resolver{ | ||
server: s, | ||
names: names, | ||
ips: make(map[string]string), | ||
namesMtx: sync.Mutex{}, | ||
domains: make(map[string]*domainEntry), | ||
domainsMtx: sync.Mutex{}, | ||
} | ||
s.Handler = r | ||
|
||
errChan := make(chan error) | ||
go func() { | ||
errChan <- s.ListenAndServe() | ||
}() | ||
|
||
select { | ||
case err := <-errChan: | ||
if err != nil { | ||
return nil, fmt.Errorf("dns server failed to start: %w", err) | ||
} else { | ||
return nil, fmt.Errorf("dns server stopped prematurely") | ||
} | ||
case <-time.After(2 * time.Second): | ||
log.Infof("dns server running at %s", s.Addr) | ||
} | ||
|
||
const resolverConfigHelp = "ziti-tunnel runs an internal DNS server which must be first in the host's\n" + | ||
"resolver configuration. On systems that use NetManager/dhclient, this can\n" + | ||
"be achieved by adding the following to /etc/dhcp/dhclient.conf:\n" + | ||
"\n" + | ||
" prepend domain-name-servers %s;\n\n" | ||
|
||
err := r.testSystemResolver() | ||
if err != nil { | ||
log.Errorf("system resolver test failed: %s\n\n"+resolverConfigHelp, err, addr) | ||
} | ||
|
||
return r, nil | ||
} | ||
|
||
func flushDnsCaches() { | ||
bin, err := exec.LookPath("systemd-resolve") | ||
arg := "--flush-caches" | ||
if err != nil { | ||
bin, err = exec.LookPath("resolvectl") | ||
if err != nil { | ||
logrus.WithError(err).Warn("unable to find systemd-resolve or resolvectl in path, consider adding a dns flush to your restart process") | ||
return | ||
} | ||
arg = "flush-caches" | ||
} | ||
|
||
cmd := exec.Command(bin, arg) | ||
if err = cmd.Run(); err != nil { | ||
logrus.WithError(err).Warn("unable to flush dns caches, consider adding a dns flush to your restart process") | ||
} else { | ||
logrus.Info("dns caches flushed") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
//go:build !linux | ||
|
||
package dns | ||
|
||
func NewDnsServer(addr string) (Resolver, error) { | ||
return nil, nil | ||
} | ||
|
||
func flushDnsCaches() { | ||
// not implemented | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters