diff --git a/client/internal/dns/file_linux.go b/client/internal/dns/file_linux.go index 81b16459bc9..e21612ba1cf 100644 --- a/client/internal/dns/file_linux.go +++ b/client/internal/dns/file_linux.go @@ -35,21 +35,21 @@ 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 { backupFileExist = true } - if !config.routeAll { + if !config.RouteAll { if backupFileExist { err = f.restore() if err != nil { return fmt.Errorf("unable to configure DNS for this peer using file manager without a Primary nameserver group. Restoring the original file return err: %s", err) } } - return fmt.Errorf("unable to configure DNS for this peer using file manager without a nameserver group with all domains configured") + return fmt.Errorf("unable to configure DNS for this peer using file manager without a nameserver group with all Domains configured") } if !backupFileExist { @@ -70,7 +70,7 @@ func (f *fileConfigurator) applyDNSConfig(config hostDNSConfig) error { buf := prepareResolvConfContent( searchDomainList, - append([]string{config.serverIP}, nameServers...), + append([]string{config.ServerIP}, nameServers...), others) log.Debugf("creating managed file %s", defaultResolvConfPath) @@ -83,7 +83,7 @@ func (f *fileConfigurator) applyDNSConfig(config hostDNSConfig) error { return fmt.Errorf("got an creating resolver file %s. Error: %s", defaultResolvConfPath, err) } - log.Infof("created a NetBird managed %s file with your DNS settings. Added %d search domains. Search list: %s", defaultResolvConfPath, len(searchDomainList), searchDomainList) + log.Infof("created a NetBird managed %s file with your DNS settings. Added %d search Domains. Search list: %s", defaultResolvConfPath, len(searchDomainList), searchDomainList) return nil } @@ -138,14 +138,14 @@ 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 { + for _, dConf := range config.Domains { + if dConf.MatchOnly || dConf.Disabled { continue } - listOfDomains = append(listOfDomains, dConf.domain) + listOfDomains = append(listOfDomains, dConf.Domain) } return listOfDomains } @@ -177,7 +177,7 @@ func originalDNSConfigs(resolvconfFile string) (searchDomains, nameServers, othe continue } - if strings.HasPrefix(line, "domain") { + if strings.HasPrefix(line, "Domain") { continue } @@ -214,7 +214,7 @@ func originalDNSConfigs(resolvconfFile string) (searchDomains, nameServers, othe return } -// merge search domains lists and cut off the list if it is too long +// merge search Domains lists and cut off the list if it is too long func mergeSearchDomains(searchDomains []string, originalSearchDomains []string) []string { lineSize := len("search") searchDomainsList := make([]string, 0, len(searchDomains)+len(originalSearchDomains)) @@ -225,23 +225,23 @@ func mergeSearchDomains(searchDomains []string, originalSearchDomains []string) return searchDomainsList } -// validateAndFillSearchDomains checks if the search domains list is not too long and if the line is not too long +// validateAndFillSearchDomains checks if the search Domains list is not too long and if the line is not too long // extend s slice with vs elements // return with the number of characters in the searchDomains line func validateAndFillSearchDomains(initialLineChars int, s *[]string, vs []string) int { for _, sd := range vs { tmpCharsNumber := initialLineChars + 1 + len(sd) if tmpCharsNumber > fileMaxLineCharsLimit { - // lets log all skipped domains - log.Infof("search list line is larger than %d characters. Skipping append of %s domain", fileMaxLineCharsLimit, sd) + // lets log all skipped Domains + log.Infof("search list line is larger than %d characters. Skipping append of %s Domain", fileMaxLineCharsLimit, sd) continue } initialLineChars = tmpCharsNumber if len(*s) >= fileMaxNumberOfSearchDomains { - // lets log all skipped domains - log.Infof("already appended %d domains to search list. Skipping append of %s domain", fileMaxNumberOfSearchDomains, sd) + // lets log all skipped Domains + log.Infof("already appended %d Domains to search list. Skipping append of %s Domain", fileMaxNumberOfSearchDomains, sd) continue } *s = append(*s, sd) diff --git a/client/internal/dns/file_linux_test.go b/client/internal/dns/file_linux_test.go index 369a47ef4c8..f87999fe4c1 100644 --- a/client/internal/dns/file_linux_test.go +++ b/client/internal/dns/file_linux_test.go @@ -10,7 +10,7 @@ func Test_mergeSearchDomains(t *testing.T) { originDomains := []string{"a", "b"} mergedDomains := mergeSearchDomains(searchDomains, originDomains) if len(mergedDomains) != 4 { - t.Errorf("invalid len of result domains: %d, want: %d", len(mergedDomains), 4) + t.Errorf("invalid len of result Domains: %d, want: %d", len(mergedDomains), 4) } } @@ -19,7 +19,7 @@ func Test_mergeSearchTooMuchDomains(t *testing.T) { originDomains := []string{"h", "i"} mergedDomains := mergeSearchDomains(searchDomains, originDomains) if len(mergedDomains) != 6 { - t.Errorf("invalid len of result domains: %d, want: %d", len(mergedDomains), 6) + t.Errorf("invalid len of result Domains: %d, want: %d", len(mergedDomains), 6) } } @@ -28,7 +28,7 @@ func Test_mergeSearchTooMuchDomainsInOrigin(t *testing.T) { originDomains := []string{"c", "d", "e", "f", "g"} mergedDomains := mergeSearchDomains(searchDomains, originDomains) if len(mergedDomains) != 6 { - t.Errorf("invalid len of result domains: %d, want: %d", len(mergedDomains), 6) + t.Errorf("invalid len of result Domains: %d, want: %d", len(mergedDomains), 6) } } @@ -37,7 +37,7 @@ func Test_mergeSearchTooLongDomain(t *testing.T) { originDomains := []string{"b"} mergedDomains := mergeSearchDomains(searchDomains, originDomains) if len(mergedDomains) != 1 { - t.Errorf("invalid len of result domains: %d, want: %d", len(mergedDomains), 1) + t.Errorf("invalid len of result Domains: %d, want: %d", len(mergedDomains), 1) } searchDomains = []string{"b"} @@ -45,7 +45,7 @@ func Test_mergeSearchTooLongDomain(t *testing.T) { mergedDomains = mergeSearchDomains(searchDomains, originDomains) if len(mergedDomains) != 1 { - t.Errorf("invalid len of result domains: %d, want: %d", len(mergedDomains), 1) + t.Errorf("invalid len of result Domains: %d, want: %d", len(mergedDomains), 1) } } diff --git a/client/internal/dns/host.go b/client/internal/dns/host.go index 4fd164c45b1..ee50b39d0ba 100644 --- a/client/internal/dns/host.go +++ b/client/internal/dns/host.go @@ -8,31 +8,31 @@ import ( ) type hostManager interface { - applyDNSConfig(config hostDNSConfig) error + applyDNSConfig(config HostDNSConfig) error restoreHostDNS() error supportCustomPort() bool } -type hostDNSConfig struct { - domains []domainConfig - routeAll bool - serverIP string - serverPort int +type HostDNSConfig struct { + Domains []DomainConfig `json:"domains"` + RouteAll bool `json:"routeAll"` + ServerIP string `json:"serverIP"` + ServerPort int `json:"serverPort"` } -type domainConfig struct { - disabled bool - domain string - matchOnly bool +type DomainConfig struct { + Disabled bool `json:"disabled"` + Domain string `json:"domain"` + MatchOnly bool `json:"matchOnly"` } 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,38 +55,38 @@ 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{ - routeAll: false, - serverIP: ip, - serverPort: port, +func dnsConfigToHostDNSConfig(dnsConfig nbdns.Config, ip string, port int) HostDNSConfig { + config := HostDNSConfig{ + RouteAll: false, + ServerIP: ip, + ServerPort: port, } for _, nsConfig := range dnsConfig.NameServerGroups { if len(nsConfig.NameServers) == 0 { continue } if nsConfig.Primary { - config.routeAll = true + config.RouteAll = true } for _, domain := range nsConfig.Domains { - config.domains = append(config.domains, domainConfig{ - domain: strings.TrimSuffix(domain, "."), - matchOnly: !nsConfig.SearchDomainsEnabled, + config.Domains = append(config.Domains, DomainConfig{ + Domain: strings.TrimSuffix(domain, "."), + MatchOnly: !nsConfig.SearchDomainsEnabled, }) } } for _, customZone := range dnsConfig.CustomZones { - config.domains = append(config.domains, domainConfig{ - domain: strings.TrimSuffix(customZone.Domain, "."), - matchOnly: false, + config.Domains = append(config.Domains, DomainConfig{ + Domain: strings.TrimSuffix(customZone.Domain, "."), + MatchOnly: false, }) } diff --git a/client/internal/dns/host_android.go b/client/internal/dns/host_android.go index 4ab7b32d883..169cc7c4726 100644 --- a/client/internal/dns/host_android.go +++ b/client/internal/dns/host_android.go @@ -7,7 +7,7 @@ func newHostManager(wgInterface WGIface) (hostManager, error) { 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 3713b2e18e7..303deb5e4a5 100644 --- a/client/internal/dns/host_darwin.go +++ b/client/internal/dns/host_darwin.go @@ -44,11 +44,11 @@ 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 { - err = s.addDNSSetupForAll(config.serverIP, config.serverPort) + if config.RouteAll { + err = s.addDNSSetupForAll(config.ServerIP, config.ServerPort) if err != nil { return err } @@ -58,7 +58,7 @@ func (s *systemConfigurator) applyDNSConfig(config hostDNSConfig) error { return err } s.primaryServiceID = "" - log.Infof("removed %s:%d as main DNS resolver for this peer", config.serverIP, config.serverPort) + log.Infof("removed %s:%d as main DNS resolver for this peer", config.ServerIP, config.ServerPort) } var ( @@ -66,22 +66,22 @@ func (s *systemConfigurator) applyDNSConfig(config hostDNSConfig) error { matchDomains []string ) - for _, dConf := range config.domains { - if dConf.disabled { + for _, dConf := range config.Domains { + if dConf.Disabled { continue } - if dConf.matchOnly { - matchDomains = append(matchDomains, dConf.domain) + if dConf.MatchOnly { + matchDomains = append(matchDomains, dConf.Domain) continue } - searchDomains = append(searchDomains, dConf.domain) + searchDomains = append(searchDomains, dConf.Domain) } matchKey := getKeyWithInput(netbirdDNSStateKeyFormat, matchSuffix) if len(matchDomains) != 0 { - err = s.addMatchDomains(matchKey, strings.Join(matchDomains, " "), config.serverIP, config.serverPort) + err = s.addMatchDomains(matchKey, strings.Join(matchDomains, " "), config.ServerIP, config.ServerPort) } else { - log.Infof("removing match domains from the system") + log.Infof("removing match Domains from the system") err = s.removeKeyFromSystemConfig(matchKey) } if err != nil { @@ -90,9 +90,9 @@ func (s *systemConfigurator) applyDNSConfig(config hostDNSConfig) error { searchKey := getKeyWithInput(netbirdDNSStateKeyFormat, searchSuffix) if len(searchDomains) != 0 { - err = s.addSearchDomains(searchKey, strings.Join(searchDomains, " "), config.serverIP, config.serverPort) + err = s.addSearchDomains(searchKey, strings.Join(searchDomains, " "), config.ServerIP, config.ServerPort) } else { - log.Infof("removing search domains from the system") + log.Infof("removing search Domains from the system") err = s.removeKeyFromSystemConfig(searchKey) } if err != nil { @@ -110,7 +110,7 @@ func (s *systemConfigurator) restoreHostDNS() error { if strings.Contains(key, matchSuffix) { keyType = "match" } - log.Infof("removing %s domains from system", keyType) + log.Infof("removing %s Domains from system", keyType) } if s.primaryServiceID != "" { lines += buildRemoveKeyOperation(getKeyWithInput(primaryServiceSetupKeyFormat, s.primaryServiceID)) @@ -143,7 +143,7 @@ func (s *systemConfigurator) addSearchDomains(key, domains string, ip string, po return err } - log.Infof("added %d search domains to the state. Domain list: %s", len(strings.Split(domains, " ")), domains) + log.Infof("added %d search Domains to the state. Domain list: %s", len(strings.Split(domains, " ")), domains) s.createdKeys[key] = struct{}{} @@ -156,7 +156,7 @@ func (s *systemConfigurator) addMatchDomains(key, domains, dnsServer string, por return err } - log.Infof("added %d match domains to the state. Domain list: %s", len(strings.Split(domains, " ")), domains) + log.Infof("added %d match Domains to the state. Domain list: %s", len(strings.Split(domains, " ")), domains) s.createdKeys[key] = struct{}{} @@ -178,7 +178,7 @@ func (s *systemConfigurator) addDNSState(state, domains, dnsServer string, port _, err := runSystemConfigCommand(stdinCommands) if err != nil { - return fmt.Errorf("got error while applying state for domains %s, error: %s", domains, err) + return fmt.Errorf("got error while applying state for Domains %s, error: %s", domains, err) } return nil } diff --git a/client/internal/dns/host_ios.go b/client/internal/dns/host_ios.go index 0eec4979286..969a54513af 100644 --- a/client/internal/dns/host_ios.go +++ b/client/internal/dns/host_ios.go @@ -1,13 +1,13 @@ package dns import ( - "strconv" - "strings" + "encoding/json" + "fmt" ) type iosHostManager struct { dnsManager IosDnsManager - config hostDNSConfig + config HostDNSConfig } func newHostManager(dnsManager IosDnsManager) (hostManager, error) { @@ -16,23 +16,12 @@ func newHostManager(dnsManager IosDnsManager) (hostManager, error) { }, nil } -func (a iosHostManager) applyDNSConfig(config hostDNSConfig) error { - var configAsString []string - configAsString = append(configAsString, config.serverIP) - configAsString = append(configAsString, strconv.Itoa(config.serverPort)) - configAsString = append(configAsString, strconv.FormatBool(config.routeAll)) - var domainConfigAsString []string - for _, domain := range config.domains { - var domainAsString []string - domainAsString = append(domainAsString, strconv.FormatBool(domain.disabled)) - domainAsString = append(domainAsString, domain.domain) - domainAsString = append(domainAsString, strconv.FormatBool(domain.matchOnly)) - domainConfigAsString = append(domainConfigAsString, strings.Join(domainAsString, "|")) +func (a iosHostManager) applyDNSConfig(config HostDNSConfig) error { + jsonData, err := json.Marshal(config) + if err != nil { + return err } - domainConfig := strings.Join(domainConfigAsString, ";") - configAsString = append(configAsString, domainConfig) - outputString := strings.Join(configAsString, ",") - a.dnsManager.ApplyDns(outputString) + a.dnsManager.ApplyDns(fmt.Sprint(jsonData)) return nil } diff --git a/client/internal/dns/host_windows.go b/client/internal/dns/host_windows.go index 3814be00b7f..7a8f8e6166e 100644 --- a/client/internal/dns/host_windows.go +++ b/client/internal/dns/host_windows.go @@ -43,10 +43,10 @@ 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) + if config.RouteAll { + err = r.addDNSSetupForAll(config.ServerIP) if err != nil { return err } @@ -56,7 +56,7 @@ func (r *registryConfigurator) applyDNSConfig(config hostDNSConfig) error { return err } r.routingAll = false - log.Infof("removed %s as main DNS forwarder for this peer", config.serverIP) + log.Infof("removed %s as main DNS forwarder for this peer", config.ServerIP) } var ( @@ -64,18 +64,18 @@ func (r *registryConfigurator) applyDNSConfig(config hostDNSConfig) error { matchDomains []string ) - for _, dConf := range config.domains { - if dConf.disabled { + for _, dConf := range config.Domains { + if dConf.Disabled { continue } - if !dConf.matchOnly { - searchDomains = append(searchDomains, dConf.domain) + if !dConf.MatchOnly { + searchDomains = append(searchDomains, dConf.Domain) } - matchDomains = append(matchDomains, "."+dConf.domain) + matchDomains = append(matchDomains, "."+dConf.Domain) } if len(matchDomains) != 0 { - err = r.addDNSMatchPolicy(matchDomains, config.serverIP) + err = r.addDNSMatchPolicy(matchDomains, config.ServerIP) } else { err = removeRegistryKeyFromDNSPolicyConfig(dnsPolicyConfigMatchPath) } @@ -135,7 +135,7 @@ func (r *registryConfigurator) addDNSMatchPolicy(domains []string, ip string) er return fmt.Errorf("unable to set registry value for %s, error: %s", dnsPolicyConfigConfigOptionsKey, err) } - log.Infof("added %d match domains to the state. Domain list: %s", len(domains), domains) + log.Infof("added %d match Domains to the state. Domain list: %s", len(domains), domains) return nil } @@ -152,10 +152,10 @@ func (r *registryConfigurator) restoreHostDNS() error { func (r *registryConfigurator) updateSearchDomains(domains []string) error { err := r.setInterfaceRegistryKeyStringValue(interfaceConfigSearchListKey, strings.Join(domains, ",")) if err != nil { - return fmt.Errorf("adding search domain failed with error: %s", err) + return fmt.Errorf("adding search Domain failed with error: %s", err) } - log.Infof("updated the search domains in the registry with %d domains. Domain list: %s", len(domains), domains) + log.Infof("updated the search Domains in the registry with %d Domains. Domain list: %s", len(domains), domains) return nil } diff --git a/client/internal/dns/local_test.go b/client/internal/dns/local_test.go index db69d9ad86d..2110c63e76c 100644 --- a/client/internal/dns/local_test.go +++ b/client/internal/dns/local_test.go @@ -1,10 +1,12 @@ package dns import ( - "github.com/miekg/dns" - nbdns "github.com/netbirdio/netbird/dns" "strings" "testing" + + "github.com/miekg/dns" + + nbdns "github.com/netbirdio/netbird/dns" ) func TestLocalResolver_ServeDNS(t *testing.T) { @@ -73,7 +75,7 @@ func TestLocalResolver_ServeDNS(t *testing.T) { answerString := responseMSG.Answer[0].String() if !strings.Contains(answerString, testCase.inputRecord.Name) { - t.Fatalf("answer doesn't contain the same domain name: \nWant: %s\nGot:%s", testCase.name, answerString) + t.Fatalf("answer doesn't contain the same Domain name: \nWant: %s\nGot:%s", testCase.name, answerString) } if !strings.Contains(answerString, dns.Type(testCase.inputRecord.Type).String()) { t.Fatalf("answer doesn't contain the correct type: \nWant: %s\nGot:%s", dns.Type(testCase.inputRecord.Type).String(), answerString) diff --git a/client/internal/dns/network_manager_linux.go b/client/internal/dns/network_manager_linux.go index bd83f2da921..6b190143916 100644 --- a/client/internal/dns/network_manager_linux.go +++ b/client/internal/dns/network_manager_linux.go @@ -94,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) @@ -102,7 +102,7 @@ func (n *networkManagerDbusConfigurator) applyDNSConfig(config hostDNSConfig) er connSettings.cleanDeprecatedSettings() - dnsIP, err := netip.ParseAddr(config.serverIP) + dnsIP, err := netip.ParseAddr(config.ServerIP) if err != nil { return fmt.Errorf("unable to parse ip address, error: %s", err) } @@ -112,40 +112,40 @@ func (n *networkManagerDbusConfigurator) applyDNSConfig(config hostDNSConfig) er searchDomains []string matchDomains []string ) - for _, dConf := range config.domains { - if dConf.disabled { + for _, dConf := range config.Domains { + if dConf.Disabled { continue } - if dConf.matchOnly { - matchDomains = append(matchDomains, "~."+dns.Fqdn(dConf.domain)) + if dConf.MatchOnly { + matchDomains = append(matchDomains, "~."+dns.Fqdn(dConf.Domain)) continue } - searchDomains = append(searchDomains, dns.Fqdn(dConf.domain)) + searchDomains = append(searchDomains, dns.Fqdn(dConf.Domain)) } newDomainList := append(searchDomains, matchDomains...) //nolint:gocritic priority := networkManagerDbusSearchDomainOnlyPriority switch { - case config.routeAll: + case config.RouteAll: priority = networkManagerDbusPrimaryDNSPriority newDomainList = append(newDomainList, "~.") if !n.routingAll { - log.Infof("configured %s:%d as main DNS forwarder for this peer", config.serverIP, config.serverPort) + log.Infof("configured %s:%d as main DNS forwarder for this peer", config.ServerIP, config.ServerPort) } case len(matchDomains) > 0: priority = networkManagerDbusWithMatchDomainPriority } if priority != networkManagerDbusPrimaryDNSPriority && n.routingAll { - log.Infof("removing %s:%d as main DNS forwarder for this peer", config.serverIP, config.serverPort) + log.Infof("removing %s:%d as main DNS forwarder for this peer", config.ServerIP, config.ServerPort) n.routingAll = false } connSettings[networkManagerDbusIPv4Key][networkManagerDbusDNSPriorityKey] = dbus.MakeVariant(priority) connSettings[networkManagerDbusIPv4Key][networkManagerDbusDNSSearchKey] = dbus.MakeVariant(newDomainList) - log.Infof("adding %d search domains and %d match domains. Search list: %s , Match list: %s", len(searchDomains), len(matchDomains), searchDomains, matchDomains) + log.Infof("adding %d search Domains and %d match Domains. Search list: %s , Match list: %s", len(searchDomains), len(matchDomains), searchDomains, matchDomains) err = n.reApplyConnectionSettings(connSettings, configVersion) if err != nil { return fmt.Errorf("got an error while reapplying the connection with new settings, error: %s", err) diff --git a/client/internal/dns/resolvconf_linux.go b/client/internal/dns/resolvconf_linux.go index 1ae2de3dde3..dfe4c00f7be 100644 --- a/client/internal/dns/resolvconf_linux.go +++ b/client/internal/dns/resolvconf_linux.go @@ -39,14 +39,14 @@ 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 { + if !config.RouteAll { err = r.restoreHostDNS() if err != nil { log.Error(err) } - return fmt.Errorf("unable to configure DNS for this peer using resolvconf manager without a nameserver group with all domains configured") + return fmt.Errorf("unable to configure DNS for this peer using resolvconf manager without a nameserver group with all Domains configured") } searchDomainList := searchDomains(config) @@ -54,7 +54,7 @@ func (r *resolvconf) applyDNSConfig(config hostDNSConfig) error { buf := prepareResolvConfContent( searchDomainList, - append([]string{config.serverIP}, r.originalNameServers...), + append([]string{config.ServerIP}, r.originalNameServers...), r.othersConfigs) err = r.applyConfig(buf) @@ -62,7 +62,7 @@ func (r *resolvconf) applyDNSConfig(config hostDNSConfig) error { return err } - log.Infof("added %d search domains. Search list: %s", len(searchDomainList), searchDomainList) + log.Infof("added %d search Domains. Search list: %s", len(searchDomainList), searchDomainList) return nil } diff --git a/client/internal/dns/server.go b/client/internal/dns/server.go index e788d0e8797..d1bc8e29362 100644 --- a/client/internal/dns/server.go +++ b/client/internal/dns/server.go @@ -48,7 +48,7 @@ type DefaultServer struct { hostManager hostManager updateSerial uint64 previousConfigHash uint64 - currentConfig hostDNSConfig + currentConfig HostDNSConfig // permanent related properties permanent bool @@ -236,20 +236,20 @@ func (s *DefaultServer) UpdateDNSServer(serial uint64, update nbdns.Config) erro func (s *DefaultServer) SearchDomains() []string { var searchDomains []string - for _, dConf := range s.currentConfig.domains { - if dConf.disabled { + for _, dConf := range s.currentConfig.Domains { + if dConf.Disabled { continue } - if dConf.matchOnly { + if dConf.MatchOnly { continue } - searchDomains = append(searchDomains, dConf.domain) + searchDomains = append(searchDomains, dConf.Domain) } return searchDomains } func (s *DefaultServer) applyConfiguration(update nbdns.Config) error { - // is the service should be disabled, we stop the listener or fake resolver + // is the service should be Disabled, we stop the listener or fake resolver // and proceed with a regular update to clean up the handlers and records if update.ServiceEnable { _ = s.service.Listen() @@ -275,7 +275,7 @@ func (s *DefaultServer) applyConfiguration(update nbdns.Config) error { if s.service.RuntimePort() != 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://docs.netbird.io/how-to/manage-dns-in-your-network#local-resolver") - hostUpdate.routeAll = false + hostUpdate.RouteAll = false } if err = s.hostManager.applyDNSConfig(hostUpdate); err != nil { @@ -344,7 +344,7 @@ func (s *DefaultServer) buildUpstreamHandlerUpdate(nameServerGroups []*nbdns.Nam continue } - // when upstream fails to resolve domain several times over all it servers + // when upstream fails to resolve Domain several times over all it servers // it will calls this hook to exclude self from the configuration and // reapply DNS settings, but it not touch the original configuration and serial number // because it is temporal deactivation until next try @@ -364,13 +364,13 @@ func (s *DefaultServer) buildUpstreamHandlerUpdate(nameServerGroups []*nbdns.Nam if len(nsGroup.Domains) == 0 { handler.stop() - return nil, fmt.Errorf("received a non primary nameserver group with an empty domain list") + return nil, fmt.Errorf("received a non primary nameserver group with an empty Domain list") } for _, domain := range nsGroup.Domains { if domain == "" { handler.stop() - return nil, fmt.Errorf("received a nameserver group with an empty domain element") + return nil, fmt.Errorf("received a nameserver group with an empty Domain element") } muxUpdates = append(muxUpdates, muxUpdate{ domain: domain, @@ -461,14 +461,14 @@ func (s *DefaultServer) upstreamCallbacks( } if nsGroup.Primary { removeIndex[nbdns.RootZone] = -1 - s.currentConfig.routeAll = false + s.currentConfig.RouteAll = false } - for i, item := range s.currentConfig.domains { - if _, found := removeIndex[item.domain]; found { - s.currentConfig.domains[i].disabled = true - s.service.DeregisterMux(item.domain) - removeIndex[item.domain] = i + for i, item := range s.currentConfig.Domains { + if _, found := removeIndex[item.Domain]; found { + s.currentConfig.Domains[i].Disabled = true + s.service.DeregisterMux(item.Domain) + removeIndex[item.Domain] = i } } if err := s.hostManager.applyDNSConfig(s.currentConfig); err != nil { @@ -480,21 +480,21 @@ func (s *DefaultServer) upstreamCallbacks( defer s.mux.Unlock() for domain, i := range removeIndex { - if i == -1 || i >= len(s.currentConfig.domains) || s.currentConfig.domains[i].domain != domain { + if i == -1 || i >= len(s.currentConfig.Domains) || s.currentConfig.Domains[i].Domain != domain { continue } - s.currentConfig.domains[i].disabled = false + s.currentConfig.Domains[i].Disabled = false s.service.RegisterMux(domain, handler) } l := log.WithField("nameservers", nsGroup.NameServers) - l.Debug("reactivate temporary disabled nameserver group") + l.Debug("reactivate temporary Disabled nameserver group") if nsGroup.Primary { - s.currentConfig.routeAll = true + s.currentConfig.RouteAll = true } if err := s.hostManager.applyDNSConfig(s.currentConfig); err != nil { - l.WithError(err).Error("reactivate temporary disabled nameserver group, DNS update apply") + l.WithError(err).Error("reactivate temporary Disabled nameserver group, DNS update apply") } } return diff --git a/client/internal/dns/server_test.go b/client/internal/dns/server_test.go index 875a1a46f95..49ec105bb55 100644 --- a/client/internal/dns/server_test.go +++ b/client/internal/dns/server_test.go @@ -527,8 +527,8 @@ func TestDNSServerUpstreamDeactivateCallback(t *testing.T) { registeredMap: make(registrationMap), }, hostManager: hostManager, - currentConfig: hostDNSConfig{ - domains: []domainConfig{ + currentConfig: HostDNSConfig{ + Domains: []DomainConfig{ {false, "domain0", false}, {false, "domain1", false}, {false, "domain2", false}, @@ -537,13 +537,13 @@ 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 { + for _, item := range config.Domains { + if item.Disabled { continue } - domains = append(domains, item.domain) + domains = append(domains, item.Domain) } domainsUpdate = strings.Join(domains, ",") return nil @@ -559,29 +559,29 @@ func TestDNSServerUpstreamDeactivateCallback(t *testing.T) { deactivate() expected := "domain0,domain2" domains := []string{} - for _, item := range server.currentConfig.domains { - if item.disabled { + for _, item := range server.currentConfig.Domains { + if item.Disabled { continue } - domains = append(domains, item.domain) + domains = append(domains, item.Domain) } got := strings.Join(domains, ",") if expected != got { - t.Errorf("expected domains list: %q, got %q", expected, got) + t.Errorf("expected Domains list: %q, got %q", expected, got) } reactivate() expected = "domain0,domain1,domain2" domains = []string{} - for _, item := range server.currentConfig.domains { - if item.disabled { + for _, item := range server.currentConfig.Domains { + if item.Disabled { continue } - domains = append(domains, item.domain) + domains = append(domains, item.Domain) } got = strings.Join(domains, ",") if expected != got { - t.Errorf("expected domains list: %q, got %q", expected, domainsUpdate) + t.Errorf("expected Domains list: %q, got %q", expected, domainsUpdate) } } diff --git a/client/internal/dns/service_listener.go b/client/internal/dns/service_listener.go index 232f6ebc257..aad1cf4f1d4 100644 --- a/client/internal/dns/service_listener.go +++ b/client/internal/dns/service_listener.go @@ -173,7 +173,7 @@ func (s *serviceViaListener) evalListenAddress() (string, int, error) { } // shouldApplyPortFwd decides whether to apply eBPF program to capture DNS traffic on port 53. -// This is needed because on some operating systems if we start a DNS server not on a default port 53, the domain name +// This is needed because on some operating systems if we start a DNS server not on a default port 53, the Domain name // resolution won't work. // So, in case we are running on Linux and picked a non-default port (53) we should fall back to the eBPF solution that will capture // traffic on port 53 and forward it to a local DNS server running on 5053. diff --git a/client/internal/dns/systemd_linux.go b/client/internal/dns/systemd_linux.go index 0358b0251f2..715d96f602c 100644 --- a/client/internal/dns/systemd_linux.go +++ b/client/internal/dns/systemd_linux.go @@ -81,8 +81,8 @@ func (s *systemdDbusConfigurator) supportCustomPort() bool { return true } -func (s *systemdDbusConfigurator) applyDNSConfig(config hostDNSConfig) error { - parsedIP, err := netip.ParseAddr(config.serverIP) +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) } @@ -93,7 +93,7 @@ func (s *systemdDbusConfigurator) applyDNSConfig(config hostDNSConfig) error { } err = s.callLinkMethod(systemdDbusSetDNSMethodSuffix, []systemdDbusDNSInput{defaultLinkInput}) if err != nil { - return fmt.Errorf("setting the interface DNS server %s:%d failed with error: %s", config.serverIP, config.serverPort, err) + return fmt.Errorf("setting the interface DNS server %s:%d failed with error: %s", config.ServerIP, config.ServerPort, err) } var ( @@ -101,24 +101,24 @@ func (s *systemdDbusConfigurator) applyDNSConfig(config hostDNSConfig) error { matchDomains []string domainsInput []systemdDbusLinkDomainsInput ) - for _, dConf := range config.domains { - if dConf.disabled { + for _, dConf := range config.Domains { + if dConf.Disabled { continue } domainsInput = append(domainsInput, systemdDbusLinkDomainsInput{ - Domain: dns.Fqdn(dConf.domain), - MatchOnly: dConf.matchOnly, + Domain: dns.Fqdn(dConf.Domain), + MatchOnly: dConf.MatchOnly, }) - if dConf.matchOnly { - matchDomains = append(matchDomains, dConf.domain) + if dConf.MatchOnly { + matchDomains = append(matchDomains, dConf.Domain) continue } - searchDomains = append(searchDomains, dConf.domain) + searchDomains = append(searchDomains, dConf.Domain) } - if config.routeAll { - log.Infof("configured %s:%d as main DNS forwarder for this peer", config.serverIP, config.serverPort) + if config.RouteAll { + log.Infof("configured %s:%d as main DNS forwarder for this peer", config.ServerIP, config.ServerPort) err = s.callLinkMethod(systemdDbusSetDefaultRouteMethodSuffix, true) if err != nil { return fmt.Errorf("setting link as default dns router, failed with error: %s", err) @@ -129,10 +129,10 @@ func (s *systemdDbusConfigurator) applyDNSConfig(config hostDNSConfig) error { }) s.routingAll = true } else if s.routingAll { - log.Infof("removing %s:%d as main DNS forwarder for this peer", config.serverIP, config.serverPort) + log.Infof("removing %s:%d as main DNS forwarder for this peer", config.ServerIP, config.ServerPort) } - log.Infof("adding %d search domains and %d match domains. Search list: %s , Match list: %s", len(searchDomains), len(matchDomains), searchDomains, matchDomains) + log.Infof("adding %d search Domains and %d match Domains. Search list: %s , Match list: %s", len(searchDomains), len(matchDomains), searchDomains, matchDomains) err = s.setDomainsForInterface(domainsInput) if err != nil { log.Error(err) @@ -143,7 +143,7 @@ func (s *systemdDbusConfigurator) applyDNSConfig(config hostDNSConfig) error { func (s *systemdDbusConfigurator) setDomainsForInterface(domainsInput []systemdDbusLinkDomainsInput) error { err := s.callLinkMethod(systemdDbusSetDomainsMethodSuffix, domainsInput) if err != nil { - return fmt.Errorf("setting domains configuration failed with error: %s", err) + return fmt.Errorf("setting Domains configuration failed with error: %s", err) } return s.flushCaches() } diff --git a/client/internal/dns/upstream.go b/client/internal/dns/upstream.go index 786d79e7762..a716e0f24fa 100644 --- a/client/internal/dns/upstream.go +++ b/client/internal/dns/upstream.go @@ -136,7 +136,7 @@ func (u *upstreamResolverBase) checkUpstreamFails() { default: // todo test the deactivation logic, it seems to affect the client if runtime.GOOS != "ios" { - log.Warnf("upstream resolving is disabled for %v", reactivatePeriod) + log.Warnf("upstream resolving is Disabled for %v", reactivatePeriod) u.deactivate() u.disabled = true go u.waitUntilResponse() diff --git a/client/internal/dns/upstream_test.go b/client/internal/dns/upstream_test.go index f404c95d2ab..6e4962d30bd 100644 --- a/client/internal/dns/upstream_test.go +++ b/client/internal/dns/upstream_test.go @@ -148,7 +148,7 @@ func TestUpstreamResolver_DeactivationReactivation(t *testing.T) { } if !resolver.disabled { - t.Errorf("resolver should be disabled") + t.Errorf("resolver should be Disabled") return }