From c88e8139c795cc57149e282fc93e391d5a51e117 Mon Sep 17 00:00:00 2001 From: Pascal Fischer Date: Wed, 6 Dec 2023 16:13:31 +0100 Subject: [PATCH] revert exported HostDNSConfig --- client/internal/dns/file_linux.go | 4 ++-- client/internal/dns/host.go | 14 +++++++------- client/internal/dns/host_android.go | 2 +- client/internal/dns/host_darwin.go | 2 +- client/internal/dns/host_ios.go | 4 ++-- client/internal/dns/host_windows.go | 2 +- client/internal/dns/network_manager_linux.go | 5 +++-- client/internal/dns/resolvconf_linux.go | 2 +- client/internal/dns/server.go | 6 +++--- client/internal/dns/server_test.go | 4 ++-- client/internal/dns/systemd_linux.go | 2 +- 11 files changed, 24 insertions(+), 23 deletions(-) diff --git a/client/internal/dns/file_linux.go b/client/internal/dns/file_linux.go index 5a2ef9da9..81b16459b 100644 --- a/client/internal/dns/file_linux.go +++ b/client/internal/dns/file_linux.go @@ -35,7 +35,7 @@ func (f *fileConfigurator) supportCustomPort() bool { return false } -func (f *fileConfigurator) applyDNSConfig(config HostDNSConfig) error { +func (f *fileConfigurator) applyDNSConfig(config hostDNSConfig) error { backupFileExist := false _, err := os.Stat(fileDefaultResolvConfBackupLocation) if err == nil { @@ -138,7 +138,7 @@ func prepareResolvConfContent(searchDomains, nameServers, others []string) bytes return buf } -func searchDomains(config HostDNSConfig) []string { +func searchDomains(config hostDNSConfig) []string { listOfDomains := make([]string, 0) for _, dConf := range config.domains { if dConf.matchOnly || dConf.disabled { diff --git a/client/internal/dns/host.go b/client/internal/dns/host.go index 34a0769a2..05460c13c 100644 --- a/client/internal/dns/host.go +++ b/client/internal/dns/host.go @@ -8,12 +8,12 @@ import ( ) type hostManager interface { - applyDNSConfig(config HostDNSConfig) error + applyDNSConfig(config hostDNSConfig) error restoreHostDNS() error supportCustomPort() bool } -type HostDNSConfig struct { +type hostDNSConfig struct { domains []domainConfig routeAll bool serverIP string @@ -27,12 +27,12 @@ type domainConfig struct { } type mockHostConfigurator struct { - applyDNSConfigFunc func(config HostDNSConfig) error + applyDNSConfigFunc func(config hostDNSConfig) error restoreHostDNSFunc func() error supportCustomPortFunc func() bool } -func (m *mockHostConfigurator) applyDNSConfig(config HostDNSConfig) error { +func (m *mockHostConfigurator) applyDNSConfig(config hostDNSConfig) error { if m.applyDNSConfigFunc != nil { return m.applyDNSConfigFunc(config) } @@ -55,14 +55,14 @@ func (m *mockHostConfigurator) supportCustomPort() bool { func newNoopHostMocker() hostManager { return &mockHostConfigurator{ - applyDNSConfigFunc: func(config HostDNSConfig) error { return nil }, + applyDNSConfigFunc: func(config hostDNSConfig) error { return nil }, restoreHostDNSFunc: func() error { return nil }, supportCustomPortFunc: func() bool { return true }, } } -func dnsConfigToHostDNSConfig(dnsConfig nbdns.Config, ip string, port int) HostDNSConfig { - config := HostDNSConfig{ +func dnsConfigTohostDNSConfig(dnsConfig nbdns.Config, ip string, port int) hostDNSConfig { + config := hostDNSConfig{ routeAll: false, serverIP: ip, serverPort: port, diff --git a/client/internal/dns/host_android.go b/client/internal/dns/host_android.go index 624d42dfb..3bd72aa87 100644 --- a/client/internal/dns/host_android.go +++ b/client/internal/dns/host_android.go @@ -7,7 +7,7 @@ func newHostManager(wgInterface WGIface, dnsManager IosDnsManager) (hostManager, return &androidHostManager{}, nil } -func (a androidHostManager) applyDNSConfig(config HostDNSConfig) error { +func (a androidHostManager) applyDNSConfig(config hostDNSConfig) error { return nil } diff --git a/client/internal/dns/host_darwin.go b/client/internal/dns/host_darwin.go index a3ab9e6d3..2acb29fc8 100644 --- a/client/internal/dns/host_darwin.go +++ b/client/internal/dns/host_darwin.go @@ -44,7 +44,7 @@ func (s *systemConfigurator) supportCustomPort() bool { return true } -func (s *systemConfigurator) applyDNSConfig(config HostDNSConfig) error { +func (s *systemConfigurator) applyDNSConfig(config hostDNSConfig) error { var err error if config.routeAll { diff --git a/client/internal/dns/host_ios.go b/client/internal/dns/host_ios.go index fa143dc7a..7659d458a 100644 --- a/client/internal/dns/host_ios.go +++ b/client/internal/dns/host_ios.go @@ -9,7 +9,7 @@ import ( type iosHostManager struct { dnsManager IosDnsManager - config HostDNSConfig + config hostDNSConfig } func newHostManager(wgInterface WGIface, dnsManager IosDnsManager) (hostManager, error) { @@ -18,7 +18,7 @@ func newHostManager(wgInterface WGIface, dnsManager IosDnsManager) (hostManager, }, nil } -func (a iosHostManager) applyDNSConfig(config HostDNSConfig) error { +func (a iosHostManager) applyDNSConfig(config hostDNSConfig) error { var configAsString []string configAsString = append(configAsString, config.serverIP) configAsString = append(configAsString, strconv.Itoa(config.serverPort)) diff --git a/client/internal/dns/host_windows.go b/client/internal/dns/host_windows.go index 52da1a0b1..c7ad5e46e 100644 --- a/client/internal/dns/host_windows.go +++ b/client/internal/dns/host_windows.go @@ -43,7 +43,7 @@ func (s *registryConfigurator) supportCustomPort() bool { return false } -func (r *registryConfigurator) applyDNSConfig(config HostDNSConfig) error { +func (r *registryConfigurator) applyDNSConfig(config hostDNSConfig) error { var err error if config.routeAll { err = r.addDNSSetupForAll(config.serverIP) diff --git a/client/internal/dns/network_manager_linux.go b/client/internal/dns/network_manager_linux.go index 548c6b8fd..bd83f2da9 100644 --- a/client/internal/dns/network_manager_linux.go +++ b/client/internal/dns/network_manager_linux.go @@ -12,8 +12,9 @@ import ( "github.com/godbus/dbus/v5" "github.com/hashicorp/go-version" "github.com/miekg/dns" - nbversion "github.com/netbirdio/netbird/version" log "github.com/sirupsen/logrus" + + nbversion "github.com/netbirdio/netbird/version" ) const ( @@ -93,7 +94,7 @@ func (n *networkManagerDbusConfigurator) supportCustomPort() bool { return false } -func (n *networkManagerDbusConfigurator) applyDNSConfig(config HostDNSConfig) error { +func (n *networkManagerDbusConfigurator) applyDNSConfig(config hostDNSConfig) error { connSettings, configVersion, err := n.getAppliedConnectionSettings() if err != nil { return fmt.Errorf("got an error while retrieving the applied connection settings, error: %s", err) diff --git a/client/internal/dns/resolvconf_linux.go b/client/internal/dns/resolvconf_linux.go index 9bde4b15a..1ae2de3dd 100644 --- a/client/internal/dns/resolvconf_linux.go +++ b/client/internal/dns/resolvconf_linux.go @@ -39,7 +39,7 @@ func (r *resolvconf) supportCustomPort() bool { return false } -func (r *resolvconf) applyDNSConfig(config HostDNSConfig) error { +func (r *resolvconf) applyDNSConfig(config hostDNSConfig) error { var err error if !config.routeAll { err = r.restoreHostDNS() diff --git a/client/internal/dns/server.go b/client/internal/dns/server.go index 1aa65ef18..732b43c74 100644 --- a/client/internal/dns/server.go +++ b/client/internal/dns/server.go @@ -49,7 +49,7 @@ type DefaultServer struct { hostManager hostManager updateSerial uint64 previousConfigHash uint64 - currentConfig HostDNSConfig + currentConfig hostDNSConfig // permanent related properties permanent bool @@ -101,7 +101,7 @@ func NewDefaultServerPermanentUpstream(ctx context.Context, wgInterface WGIface, ds.permanent = true ds.hostsDnsList = hostsDnsList ds.addHostRootZone() - ds.currentConfig = dnsConfigToHostDNSConfig(config, ds.service.RuntimeIP(), ds.service.RuntimePort()) + ds.currentConfig = dnsConfigTohostDNSConfig(config, ds.service.RuntimeIP(), ds.service.RuntimePort()) ds.searchDomainNotifier = newNotifier(ds.SearchDomains()) ds.searchDomainNotifier.setListener(listener) setServerDns(ds) @@ -271,7 +271,7 @@ func (s *DefaultServer) applyConfiguration(update nbdns.Config) error { s.updateMux(muxUpdates) s.updateLocalResolver(localRecords) - s.currentConfig = dnsConfigToHostDNSConfig(update, s.service.RuntimeIP(), s.service.RuntimePort()) + s.currentConfig = dnsConfigTohostDNSConfig(update, s.service.RuntimeIP(), s.service.RuntimePort()) hostUpdate := s.currentConfig if s.service.RuntimePort() != defaultPort && !s.hostManager.supportCustomPort() { diff --git a/client/internal/dns/server_test.go b/client/internal/dns/server_test.go index 57dff07bd..ce7a799f1 100644 --- a/client/internal/dns/server_test.go +++ b/client/internal/dns/server_test.go @@ -527,7 +527,7 @@ func TestDNSServerUpstreamDeactivateCallback(t *testing.T) { registeredMap: make(registrationMap), }, hostManager: hostManager, - currentConfig: HostDNSConfig{ + currentConfig: hostDNSConfig{ domains: []domainConfig{ {false, "domain0", false}, {false, "domain1", false}, @@ -537,7 +537,7 @@ func TestDNSServerUpstreamDeactivateCallback(t *testing.T) { } var domainsUpdate string - hostManager.applyDNSConfigFunc = func(config HostDNSConfig) error { + hostManager.applyDNSConfigFunc = func(config hostDNSConfig) error { domains := []string{} for _, item := range config.domains { if item.disabled { diff --git a/client/internal/dns/systemd_linux.go b/client/internal/dns/systemd_linux.go index 354ade2e4..0358b0251 100644 --- a/client/internal/dns/systemd_linux.go +++ b/client/internal/dns/systemd_linux.go @@ -81,7 +81,7 @@ func (s *systemdDbusConfigurator) supportCustomPort() bool { return true } -func (s *systemdDbusConfigurator) applyDNSConfig(config HostDNSConfig) error { +func (s *systemdDbusConfigurator) applyDNSConfig(config hostDNSConfig) error { parsedIP, err := netip.ParseAddr(config.serverIP) if err != nil { return fmt.Errorf("unable to parse ip address, error: %s", err)