Skip to content

Commit 8f29eec

Browse files
Make sure the iOS dialer does not get overwritten (netbirdio#1585)
* Make sure our iOS dialer does not get overwritten * set dial timeout for both clients on ios --------- Co-authored-by: Pascal Fischer <pascal@netbird.io>
1 parent b2ac947 commit 8f29eec

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

client/internal/dns/upstream_ios.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,32 @@ func (u *upstreamResolverIOS) exchange(ctx context.Context, upstream string, r *
4646
if err != nil {
4747
log.Errorf("error while parsing upstream host: %s", err)
4848
}
49+
50+
timeout := upstreamTimeout
51+
if deadline, ok := ctx.Deadline(); ok {
52+
timeout = time.Until(deadline)
53+
}
54+
client.DialTimeout = timeout
55+
4956
upstreamIP := net.ParseIP(upstreamHost)
5057
if u.lNet.Contains(upstreamIP) || net.IP.IsPrivate(upstreamIP) {
5158
log.Debugf("using private client to query upstream: %s", upstream)
52-
client = u.getClientPrivate()
59+
client = u.getClientPrivate(timeout)
5360
}
5461

55-
return client.ExchangeContext(ctx, r, upstream)
62+
// Cannot use client.ExchangeContext because it overwrites our Dialer
63+
return client.Exchange(r, upstream)
5664
}
5765

5866
// getClientPrivate returns a new DNS client bound to the local IP address of the Netbird interface
5967
// This method is needed for iOS
60-
func (u *upstreamResolverIOS) getClientPrivate() *dns.Client {
68+
func (u *upstreamResolverIOS) getClientPrivate(dialTimeout time.Duration) *dns.Client {
6169
dialer := &net.Dialer{
6270
LocalAddr: &net.UDPAddr{
6371
IP: u.lIP,
6472
Port: 0, // Let the OS pick a free port
6573
},
66-
Timeout: upstreamTimeout,
74+
Timeout: dialTimeout,
6775
Control: func(network, address string, c syscall.RawConn) error {
6876
var operr error
6977
fn := func(s uintptr) {

0 commit comments

Comments
 (0)