From 0afd73850983d8d4d20f0519e3c1808dabc3f2f1 Mon Sep 17 00:00:00 2001 From: Viktor Liu Date: Fri, 16 Feb 2024 14:37:47 +0100 Subject: [PATCH 1/2] Make sure the iOS dialer does not get overwritten (#1585) * Make sure our iOS dialer does not get overwritten * set dial timeout for both clients on ios --------- Co-authored-by: Pascal Fischer --- client/internal/dns/upstream_ios.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/client/internal/dns/upstream_ios.go b/client/internal/dns/upstream_ios.go index bce940ec6..33937d8d8 100644 --- a/client/internal/dns/upstream_ios.go +++ b/client/internal/dns/upstream_ios.go @@ -46,24 +46,32 @@ func (u *upstreamResolverIOS) exchange(ctx context.Context, upstream string, r * if err != nil { log.Errorf("error while parsing upstream host: %s", err) } + + timeout := upstreamTimeout + if deadline, ok := ctx.Deadline(); ok { + timeout = time.Until(deadline) + } + client.DialTimeout = timeout + upstreamIP := net.ParseIP(upstreamHost) if u.lNet.Contains(upstreamIP) || net.IP.IsPrivate(upstreamIP) { log.Debugf("using private client to query upstream: %s", upstream) - client = u.getClientPrivate() + client = u.getClientPrivate(timeout) } - return client.ExchangeContext(ctx, r, upstream) + // Cannot use client.ExchangeContext because it overwrites our Dialer + return client.Exchange(r, upstream) } // getClientPrivate returns a new DNS client bound to the local IP address of the Netbird interface // This method is needed for iOS -func (u *upstreamResolverIOS) getClientPrivate() *dns.Client { +func (u *upstreamResolverIOS) getClientPrivate(dialTimeout time.Duration) *dns.Client { dialer := &net.Dialer{ LocalAddr: &net.UDPAddr{ IP: u.lIP, Port: 0, // Let the OS pick a free port }, - Timeout: upstreamTimeout, + Timeout: dialTimeout, Control: func(network, address string, c syscall.RawConn) error { var operr error fn := func(s uintptr) { From cb3408a10ba9d60d0defed1c48fb269bb9d50246 Mon Sep 17 00:00:00 2001 From: Maycon Santos Date: Mon, 19 Feb 2024 14:29:20 +0100 Subject: [PATCH 2/2] Allow adding 3 nameserver addresses (#1588) --- management/server/http/api/openapi.yml | 2 +- management/server/nameserver.go | 4 ++-- management/server/nameserver_test.go | 12 +++++++++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/management/server/http/api/openapi.yml b/management/server/http/api/openapi.yml index 1f49a67b7..3bcc3279a 100644 --- a/management/server/http/api/openapi.yml +++ b/management/server/http/api/openapi.yml @@ -904,7 +904,7 @@ components: nameservers: description: Nameserver list minLength: 1 - maxLength: 2 + maxLength: 3 type: array items: $ref: '#/components/schemas/Nameserver' diff --git a/management/server/nameserver.go b/management/server/nameserver.go index ee1453ea4..e521805c8 100644 --- a/management/server/nameserver.go +++ b/management/server/nameserver.go @@ -255,8 +255,8 @@ func validateNSGroupName(name, nsGroupID string, nsGroupMap map[string]*nbdns.Na func validateNSList(list []nbdns.NameServer) error { nsListLenght := len(list) - if nsListLenght == 0 || nsListLenght > 2 { - return status.Errorf(status.InvalidArgument, "the list of nameservers should be 1 or 2, got %d", len(list)) + if nsListLenght == 0 || nsListLenght > 3 { + return status.Errorf(status.InvalidArgument, "the list of nameservers should be 1 or 3, got %d", len(list)) } return nil } diff --git a/management/server/nameserver_test.go b/management/server/nameserver_test.go index ba9826f31..4e7210562 100644 --- a/management/server/nameserver_test.go +++ b/management/server/nameserver_test.go @@ -216,7 +216,7 @@ func TestCreateNameServerGroup(t *testing.T) { shouldCreate: false, }, { - name: "Create A NS Group With More Than 2 Nameservers Should Fail", + name: "Create A NS Group With More Than 3 Nameservers Should Fail", inputArgs: input{ name: "super", description: "super", @@ -238,6 +238,11 @@ func TestCreateNameServerGroup(t *testing.T) { NSType: nbdns.UDPNameServerType, Port: nbdns.DefaultDNSPort, }, + { + IP: netip.MustParseAddr("1.1.4.4"), + NSType: nbdns.UDPNameServerType, + Port: nbdns.DefaultDNSPort, + }, }, enabled: true, }, @@ -457,6 +462,11 @@ func TestSaveNameServerGroup(t *testing.T) { NSType: nbdns.UDPNameServerType, Port: nbdns.DefaultDNSPort, }, + { + IP: netip.MustParseAddr("1.1.4.4"), + NSType: nbdns.UDPNameServerType, + Port: nbdns.DefaultDNSPort, + }, } invalidID := "doesntExist" validName := "12345678901234567890qw"