Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add iOS support #1244

Merged
merged 63 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from 61 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
7f7e101
starting engine by passing file descriptor on engine start
pascal-fischer Aug 9, 2023
6743054
inject logger that does not compile
pascal-fischer Aug 17, 2023
8653c32
logger and first client
pascal-fischer Sep 21, 2023
cdbe9c4
Merge branch 'main' into local/engine-restart
pascal-fischer Sep 21, 2023
e733cdc
first working connection
pascal-fischer Sep 25, 2023
8b8e4bb
support for routes and working connection
pascal-fischer Oct 5, 2023
ec8eb76
small refactor for better code quality in swift
pascal-fischer Oct 6, 2023
91b45ea
Merge remote-tracking branch 'origin/main' into local/engine-restart
pascal-fischer Oct 6, 2023
7f958e9
trying to add DNS
pascal-fischer Oct 9, 2023
c4c59ed
fix
pascal-fischer Oct 9, 2023
de46393
updated
pascal-fischer Oct 23, 2023
79f60b8
fix route deletion
pascal-fischer Oct 27, 2023
64084ca
trying to bind the DNS resolver dialer to an interface
pascal-fischer Nov 3, 2023
65052e5
use dns.Client.Exchange
mlsmaycon Nov 3, 2023
e193df3
fix metadata send on startup
pascal-fischer Nov 4, 2023
5632d22
switching between client to query upstream
pascal-fischer Nov 6, 2023
1c23a0e
fix panic on no dns response
pascal-fischer Nov 7, 2023
0e7a67c
merge main
pascal-fischer Nov 7, 2023
2b249ab
fix after merge changes
pascal-fischer Nov 7, 2023
0a8249e
add engine ready listener
pascal-fischer Nov 8, 2023
a37c946
replace engine listener with connection listener
pascal-fischer Nov 9, 2023
b230021
disable relay connection for iOS until proxy is refactored into bind
pascal-fischer Nov 16, 2023
5f96c56
Merge branch 'main' into feature/add-ios-support
pascal-fischer Dec 6, 2023
ad1cf38
Extract private upstream for iOS and fix function headers for other OS
pascal-fischer Dec 6, 2023
e03c07a
Update mock Server
pascal-fischer Dec 6, 2023
975e8e8
Fix dns server and upstream tests
pascal-fischer Dec 6, 2023
71f1cf8
Fix engine null pointer with mobile dependencies for other OS
pascal-fischer Dec 6, 2023
0f7343d
Revert back to disabling upstream on no response
pascal-fischer Dec 6, 2023
5f3f5dc
Fix some of the remarks from the linter
pascal-fischer Dec 6, 2023
d6d2e64
Fix linter
pascal-fischer Dec 6, 2023
f854ec9
re-arrange duration calculation
pascal-fischer Dec 6, 2023
c88e813
revert exported HostDNSConfig
pascal-fischer Dec 6, 2023
148a537
remove unused engine listener
pascal-fischer Dec 6, 2023
ca9ea29
remove development logs
pascal-fischer Dec 6, 2023
52be5de
refactor dns code and interface name propagation
pascal-fischer Dec 8, 2023
ecfac9d
clean dns server test
pascal-fischer Dec 8, 2023
6d9fd4b
disable upstream deactivation for iOS
pascal-fischer Dec 8, 2023
a567d90
Merge branch 'main' into feature/add-ios-support
pascal-fischer Dec 8, 2023
c35c2fb
remove files after merge
pascal-fischer Dec 8, 2023
0103984
fix dns server darwin
pascal-fischer Dec 8, 2023
9f6c3da
fix server mock
pascal-fischer Dec 8, 2023
cbb1f0e
fix build flags
pascal-fischer Dec 8, 2023
6e86dad
move service listen back to initialize
pascal-fischer Dec 8, 2023
d69d4cf
add wgInterface to hostManager initialization on android
pascal-fischer Dec 8, 2023
4d5760c
fix typo and remove unused function
pascal-fischer Dec 8, 2023
ed06c0c
extract upstream exchange for ios and rest
pascal-fischer Dec 8, 2023
fd40be5
remove todo
pascal-fischer Dec 8, 2023
284ec54
separate upstream logic to ios file
pascal-fischer Dec 11, 2023
974e845
Fix upstream test
pascal-fischer Dec 11, 2023
d6b5f05
use interface and embedded struct for upstream
pascal-fischer Dec 11, 2023
3acdf79
set properly upstream client
pascal-fischer Dec 11, 2023
680f21e
remove placeholder
pascal-fischer Dec 11, 2023
e86153a
remove ios specific attributes
pascal-fischer Dec 11, 2023
d91f2e2
fix upstream test
pascal-fischer Dec 11, 2023
1a00ffd
Merge pull request #1375 from netbirdio/upstream-embeded-struct
pascal-fischer Dec 11, 2023
cc15f06
merge ipc parser and wg configurer for mobile
pascal-fischer Dec 11, 2023
bacc322
fix build annotation
pascal-fischer Dec 11, 2023
0df30be
Merge branch 'main' into feature/add-ios-support
pascal-fischer Dec 14, 2023
5b4e847
use json for DNS settings handover through gomobile
pascal-fischer Dec 14, 2023
8827c52
add logs for DNS json string
pascal-fischer Dec 14, 2023
2265515
bring back check on ios for private upstream
pascal-fischer Dec 14, 2023
d08ef29
remove wrong (and unused) line
pascal-fischer Dec 15, 2023
077d0b9
fix wrongly updated comments on DNSSetting export
pascal-fischer Dec 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions client/internal/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ func RunClientMobile(ctx context.Context, config *Config, statusRecorder *peer.S
return runClient(ctx, config, statusRecorder, mobileDependency)
}

func RunClientiOS(ctx context.Context, config *Config, statusRecorder *peer.Status, fileDescriptor int32, networkChangeListener listener.NetworkChangeListener, dnsManager dns.IosDnsManager) error {
mobileDependency := MobileDependency{
FileDescriptor: fileDescriptor,
NetworkChangeListener: networkChangeListener,
DnsManager: dnsManager,
}
return runClient(ctx, config, statusRecorder, mobileDependency)
}

func runClient(ctx context.Context, config *Config, statusRecorder *peer.Status, mobileDependency MobileDependency) error {
log.Infof("starting NetBird client version %s", version.NetbirdVersion())

Expand Down
32 changes: 16 additions & 16 deletions client/internal/dns/file_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand All @@ -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
}

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -177,7 +177,7 @@ func originalDNSConfigs(resolvconfFile string) (searchDomains, nameServers, othe
continue
}

if strings.HasPrefix(line, "domain") {
if strings.HasPrefix(line, "Domain") {
continue
}

Expand Down Expand Up @@ -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))
Expand All @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions client/internal/dns/file_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand All @@ -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)
}
}

Expand All @@ -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)
}
}

Expand All @@ -37,15 +37,15 @@ 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"}
originDomains = []string{getLongLine()}

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)
}
}

Expand Down
50 changes: 25 additions & 25 deletions client/internal/dns/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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,
})
}

Expand Down
2 changes: 1 addition & 1 deletion client/internal/dns/host_android.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
36 changes: 19 additions & 17 deletions client/internal/dns/host_darwin.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build !ios

package dns

import (
Expand Down Expand Up @@ -42,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
}
Expand All @@ -56,30 +58,30 @@ 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 (
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, 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 {
Expand All @@ -88,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 {
Expand All @@ -108,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))
Expand Down Expand Up @@ -141,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{}{}

Expand All @@ -154,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{}{}

Expand All @@ -176,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
}
Expand Down
Loading
Loading