Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions client/internal/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ func (c *ConnectClient) RunOniOS(
fileDescriptor int32,
networkChangeListener listener.NetworkChangeListener,
dnsManager dns.IosDnsManager,
dnsAddresses []netip.AddrPort,
stateFilePath string,
) error {
// Set GC percent to 5% to reduce memory usage as iOS only allows 50MB of memory for the extension.
Expand All @@ -120,6 +121,7 @@ func (c *ConnectClient) RunOniOS(
FileDescriptor: fileDescriptor,
NetworkChangeListener: networkChangeListener,
DnsManager: dnsManager,
HostDNSAddresses: dnsAddresses,
StateFilePath: stateFilePath,
}
return c.run(mobileDependency, nil, "")
Expand Down
5 changes: 5 additions & 0 deletions client/internal/dns/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,16 @@ func NewDefaultServerIos(
ctx context.Context,
wgInterface WGIface,
iosDnsManager IosDnsManager,
hostsDnsList []netip.AddrPort,
statusRecorder *peer.Status,
disableSys bool,
) *DefaultServer {
log.Debugf("iOS host dns address list is: %v", hostsDnsList)
ds := newDefaultServer(ctx, wgInterface, NewServiceViaMemory(wgInterface), statusRecorder, nil, disableSys)
ds.iosDnsManager = iosDnsManager
ds.hostsDNSHolder.set(hostsDnsList)
ds.permanent = true
ds.addHostRootZone()
return ds
Comment on lines +193 to 199
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Root fallback handler is created too early for route-aware upstream routing.

At Line 198, addHostRootZone() runs before the engine injects SetRouteChecker(...). The handler snapshots s.routeMatch at creation, so it can stay nil and skip selected-route matching.

🔧 Proposed fix (outside this hunk, in SetRouteChecker)
func (s *DefaultServer) SetRouteChecker(f func(netip.Addr) bool) {
	s.mux.Lock()
	defer s.mux.Unlock()
	s.routeMatch = f
+	if s.permanent {
+		s.deregisterHandler([]string{nbdns.RootZone}, PriorityDefault)
+		s.addHostRootZone()
+	}
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@client/internal/dns/server.go` around lines 193 - 199, The root-zone handler
is being created too early because addHostRootZone() is called immediately after
newDefaultServer(...) and thus captures a nil s.routeMatch before
SetRouteChecker(...) is injected; remove the immediate call to addHostRootZone()
here and instead invoke addHostRootZone() from SetRouteChecker (or make
addHostRootZone lazy/refreshable) so the handler is created after the server's
routeMatch is set; update references to ds (the server returned by
newDefaultServer) to ensure addHostRootZone uses the populated routeMatch when
called.

}

Expand Down
2 changes: 1 addition & 1 deletion client/internal/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -1800,7 +1800,7 @@ func (e *Engine) newDnsServer(dnsConfig *nbdns.Config) (dns.Server, error) {
return dnsServer, nil

case "ios":
dnsServer := dns.NewDefaultServerIos(e.ctx, e.wgInterface, e.mobileDep.DnsManager, e.statusRecorder, e.config.DisableDNS)
dnsServer := dns.NewDefaultServerIos(e.ctx, e.wgInterface, e.mobileDep.DnsManager, e.mobileDep.HostDNSAddresses, e.statusRecorder, e.config.DisableDNS)
return dnsServer, nil

default:
Expand Down
1 change: 0 additions & 1 deletion client/internal/routemanager/notifier/notifier_ios.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ func (n *Notifier) OnNewPrefixes(prefixes []netip.Prefix) {
n.currentPrefixes = newNets
n.notify()
}

func (n *Notifier) notify() {
n.listenerMux.Lock()
defer n.listenerMux.Unlock()
Expand Down
6 changes: 5 additions & 1 deletion client/ios/NetBirdSDK/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,11 @@ func (c *Client) Run(fd int32, interfaceName string, envList *EnvList) error {
cfg.WgIface = interfaceName

c.connectClient = internal.NewConnectClient(ctx, cfg, c.recorder)
return c.connectClient.RunOniOS(fd, c.networkChangeListener, c.dnsManager, c.stateFile)
hostDNS := []netip.AddrPort{
netip.MustParseAddrPort("9.9.9.9:53"),
netip.MustParseAddrPort("149.112.112.112:53"),
}
return c.connectClient.RunOniOS(fd, c.networkChangeListener, c.dnsManager, hostDNS, c.stateFile)
Comment on lines +164 to +168
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Add IPv6 fallback resolvers for iOS host DNS.

Line 164 configures only IPv4 upstreams. On IPv6-only networks, fallback DNS can fail and leave unmatched queries unresolved.

🔧 Proposed fix
  hostDNS := []netip.AddrPort{
    netip.MustParseAddrPort("1.1.1.1:53"),
    netip.MustParseAddrPort("1.0.0.1:53"),
+   netip.MustParseAddrPort("[2606:4700:4700::1111]:53"),
+   netip.MustParseAddrPort("[2606:4700:4700::1001]:53"),
  }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@client/ios/NetBirdSDK/client.go` around lines 164 - 168, The hostDNS list for
iOS only includes IPv4 resolvers which breaks DNS on IPv6-only networks; update
the hostDNS construction used when calling c.connectClient.RunOniOS to include
IPv6 fallback addresses (e.g., parse and append IPv6 resolver AddrPort entries
like [2606:4700:4700::1111]:53 and [2606:4700:4700::1001]:53) using
netip.MustParseAddrPort so both v4 and v6 upstreams are provided to
c.dnsManager; ensure the variable name hostDNS and the call
c.connectClient.RunOniOS(fd, c.networkChangeListener, c.dnsManager, hostDNS,
c.stateFile) remain unchanged.

}

// Stop the internal client and free the resources
Expand Down
Loading