From 5288506c90909d140673a0ac427c847af12ffd57 Mon Sep 17 00:00:00 2001 From: Zoltan Papp Date: Tue, 15 Aug 2023 17:01:01 +0200 Subject: [PATCH] Fix runtime/listen port logic --- client/internal/dns/server.go | 6 ++++++ client/internal/dns/service_listener.go | 21 +++++++++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/client/internal/dns/server.go b/client/internal/dns/server.go index db4b6c542..38d0a0bcc 100644 --- a/client/internal/dns/server.go +++ b/client/internal/dns/server.go @@ -235,6 +235,12 @@ func (s *DefaultServer) applyConfiguration(update nbdns.Config) error { s.updateLocalResolver(localRecords) s.currentConfig = dnsConfigToHostDNSConfig(update, s.service.ListenIp(), s.service.ListenPort()) + if s.service.ListenPort() != defaultPort && !s.hostManager.supportCustomPort() { + log.Warnf("the DNS manager of this peer doesn't support custom port. Disabling primary DNS setup. " + + "Learn more at: https://netbird.io/docs/how-to-guides/nameservers#local-resolver") + s.currentConfig.routeAll = false + } + if err = s.hostManager.applyDNSConfig(s.currentConfig); err != nil { log.Error(err) } diff --git a/client/internal/dns/service_listener.go b/client/internal/dns/service_listener.go index c156095a3..1f12f570a 100644 --- a/client/internal/dns/service_listener.go +++ b/client/internal/dns/service_listener.go @@ -45,7 +45,10 @@ func newServiceViaListener(wgIface WGIface, customAddr *netip.AddrPort) *service Handler: mux, UDPSize: 65535, }, - ebpfService: ebpf.GetEbpfManagerInstance(), + } + + if runtime.GOOS == "linux" { + s.ebpfService = ebpf.GetEbpfManagerInstance() } return s } @@ -77,7 +80,7 @@ func (s *serviceViaListener) Listen() error { } }() - if s.runtimePort != defaultPort { + if s.ebpfService != nil && s.runtimePort != defaultPort { err = s.ebpfService.LoadDNSFwd(s.runtimeIP, s.runtimePort) if err != nil { return err @@ -102,9 +105,11 @@ func (s *serviceViaListener) Stop() { log.Errorf("stopping dns server listener returned an error: %v", err) } - err = s.ebpfService.FreeDNSFwd() - if err != nil { - log.Errorf("stopping traffic forwarder returned an error: %v", err) + if s.ebpfService != nil { + err = s.ebpfService.FreeDNSFwd() + if err != nil { + log.Errorf("stopping traffic forwarder returned an error: %v", err) + } } } @@ -117,7 +122,11 @@ func (s *serviceViaListener) DeregisterMux(pattern string) { } func (s *serviceViaListener) ListenPort() int { - return defaultPort + if s.ebpfService != nil { + return defaultPort + } else { + return s.runtimePort + } } func (s *serviceViaListener) ListenIp() string {