Merge branch 'main' into debug-google-workspace

This commit is contained in:
Maycon Santos 2024-02-19 15:26:58 +01:00
commit 5f41e2bd13
4 changed files with 26 additions and 8 deletions

View File

@ -46,24 +46,32 @@ func (u *upstreamResolverIOS) exchange(ctx context.Context, upstream string, r *
if err != nil { if err != nil {
log.Errorf("error while parsing upstream host: %s", err) 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) upstreamIP := net.ParseIP(upstreamHost)
if u.lNet.Contains(upstreamIP) || net.IP.IsPrivate(upstreamIP) { if u.lNet.Contains(upstreamIP) || net.IP.IsPrivate(upstreamIP) {
log.Debugf("using private client to query upstream: %s", upstream) 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 // getClientPrivate returns a new DNS client bound to the local IP address of the Netbird interface
// This method is needed for iOS // This method is needed for iOS
func (u *upstreamResolverIOS) getClientPrivate() *dns.Client { func (u *upstreamResolverIOS) getClientPrivate(dialTimeout time.Duration) *dns.Client {
dialer := &net.Dialer{ dialer := &net.Dialer{
LocalAddr: &net.UDPAddr{ LocalAddr: &net.UDPAddr{
IP: u.lIP, IP: u.lIP,
Port: 0, // Let the OS pick a free port Port: 0, // Let the OS pick a free port
}, },
Timeout: upstreamTimeout, Timeout: dialTimeout,
Control: func(network, address string, c syscall.RawConn) error { Control: func(network, address string, c syscall.RawConn) error {
var operr error var operr error
fn := func(s uintptr) { fn := func(s uintptr) {

View File

@ -904,7 +904,7 @@ components:
nameservers: nameservers:
description: Nameserver list description: Nameserver list
minLength: 1 minLength: 1
maxLength: 2 maxLength: 3
type: array type: array
items: items:
$ref: '#/components/schemas/Nameserver' $ref: '#/components/schemas/Nameserver'

View File

@ -255,8 +255,8 @@ func validateNSGroupName(name, nsGroupID string, nsGroupMap map[string]*nbdns.Na
func validateNSList(list []nbdns.NameServer) error { func validateNSList(list []nbdns.NameServer) error {
nsListLenght := len(list) nsListLenght := len(list)
if nsListLenght == 0 || nsListLenght > 2 { if nsListLenght == 0 || nsListLenght > 3 {
return status.Errorf(status.InvalidArgument, "the list of nameservers should be 1 or 2, got %d", len(list)) return status.Errorf(status.InvalidArgument, "the list of nameservers should be 1 or 3, got %d", len(list))
} }
return nil return nil
} }

View File

@ -216,7 +216,7 @@ func TestCreateNameServerGroup(t *testing.T) {
shouldCreate: false, 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{ inputArgs: input{
name: "super", name: "super",
description: "super", description: "super",
@ -238,6 +238,11 @@ func TestCreateNameServerGroup(t *testing.T) {
NSType: nbdns.UDPNameServerType, NSType: nbdns.UDPNameServerType,
Port: nbdns.DefaultDNSPort, Port: nbdns.DefaultDNSPort,
}, },
{
IP: netip.MustParseAddr("1.1.4.4"),
NSType: nbdns.UDPNameServerType,
Port: nbdns.DefaultDNSPort,
},
}, },
enabled: true, enabled: true,
}, },
@ -457,6 +462,11 @@ func TestSaveNameServerGroup(t *testing.T) {
NSType: nbdns.UDPNameServerType, NSType: nbdns.UDPNameServerType,
Port: nbdns.DefaultDNSPort, Port: nbdns.DefaultDNSPort,
}, },
{
IP: netip.MustParseAddr("1.1.4.4"),
NSType: nbdns.UDPNameServerType,
Port: nbdns.DefaultDNSPort,
},
} }
invalidID := "doesntExist" invalidID := "doesntExist"
validName := "12345678901234567890qw" validName := "12345678901234567890qw"