mirror of
https://github.com/tailscale/tailscale.git
synced 2025-01-08 09:07:44 +00:00
net/dns/resolver: set maxDoHInFlight to 1000 on iOS 15+.
Signed-off-by: Maisem Ali <maisem@tailscale.com>
This commit is contained in:
parent
2662a1c98c
commit
7817ab6b20
@ -28,7 +28,7 @@ func New() *tailcfg.Hostinfo {
|
|||||||
IPNVersion: version.Long,
|
IPNVersion: version.Long,
|
||||||
Hostname: hostname,
|
Hostname: hostname,
|
||||||
OS: version.OS(),
|
OS: version.OS(),
|
||||||
OSVersion: getOSVersion(),
|
OSVersion: GetOSVersion(),
|
||||||
Package: packageType(),
|
Package: packageType(),
|
||||||
GoArch: runtime.GOARCH,
|
GoArch: runtime.GOARCH,
|
||||||
DeviceModel: deviceModel(),
|
DeviceModel: deviceModel(),
|
||||||
@ -37,7 +37,8 @@ func New() *tailcfg.Hostinfo {
|
|||||||
|
|
||||||
var osVersion func() string // non-nil on some platforms
|
var osVersion func() string // non-nil on some platforms
|
||||||
|
|
||||||
func getOSVersion() string {
|
// GetOSVersion returns the OSVersion of current host if available.
|
||||||
|
func GetOSVersion() string {
|
||||||
if s, _ := osVersionAtomic.Load().(string); s != "" {
|
if s, _ := osVersionAtomic.Load().(string); s != "" {
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
@ -17,12 +17,14 @@
|
|||||||
"net/http"
|
"net/http"
|
||||||
"runtime"
|
"runtime"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
dns "golang.org/x/net/dns/dnsmessage"
|
dns "golang.org/x/net/dns/dnsmessage"
|
||||||
"inet.af/netaddr"
|
"inet.af/netaddr"
|
||||||
|
"tailscale.com/hostinfo"
|
||||||
"tailscale.com/net/netns"
|
"tailscale.com/net/netns"
|
||||||
"tailscale.com/types/dnstype"
|
"tailscale.com/types/dnstype"
|
||||||
"tailscale.com/types/logger"
|
"tailscale.com/types/logger"
|
||||||
@ -179,19 +181,37 @@ func init() {
|
|||||||
rand.Seed(time.Now().UnixNano())
|
rand.Seed(time.Now().UnixNano())
|
||||||
}
|
}
|
||||||
|
|
||||||
func newForwarder(logf logger.Logf, responses chan packet, linkMon *monitor.Mon, linkSel ForwardLinkSelector) *forwarder {
|
func maxDoHInFlight(goos string) int {
|
||||||
maxDoHInFlight := 1000 // effectively unlimited
|
if goos != "ios" {
|
||||||
if runtime.GOOS == "ios" {
|
return 1000 // effectively unlimited
|
||||||
// No HTTP/2 on iOS yet (for size reasons), so DoH is
|
|
||||||
// pricier.
|
|
||||||
maxDoHInFlight = 10
|
|
||||||
}
|
}
|
||||||
|
// iOS < 15 limits the memory to 15MB for NetworkExtensions.
|
||||||
|
// iOS >= 15 gives us 50MB.
|
||||||
|
// See: https://tailscale.com/blog/go-linker/
|
||||||
|
ver := hostinfo.GetOSVersion()
|
||||||
|
if ver == "" {
|
||||||
|
// Unknown iOS version, be cautious.
|
||||||
|
return 10
|
||||||
|
}
|
||||||
|
idx := strings.Index(ver, ".")
|
||||||
|
if idx == -1 {
|
||||||
|
// Unknown iOS version, be cautious.
|
||||||
|
return 10
|
||||||
|
}
|
||||||
|
major := ver[:idx]
|
||||||
|
if m, err := strconv.Atoi(major); err != nil || m < 15 {
|
||||||
|
return 10
|
||||||
|
}
|
||||||
|
return 1000
|
||||||
|
}
|
||||||
|
|
||||||
|
func newForwarder(logf logger.Logf, responses chan packet, linkMon *monitor.Mon, linkSel ForwardLinkSelector) *forwarder {
|
||||||
f := &forwarder{
|
f := &forwarder{
|
||||||
logf: logger.WithPrefix(logf, "forward: "),
|
logf: logger.WithPrefix(logf, "forward: "),
|
||||||
linkMon: linkMon,
|
linkMon: linkMon,
|
||||||
linkSel: linkSel,
|
linkSel: linkSel,
|
||||||
responses: responses,
|
responses: responses,
|
||||||
dohSem: make(chan struct{}, maxDoHInFlight),
|
dohSem: make(chan struct{}, maxDoHInFlight(runtime.GOOS)),
|
||||||
}
|
}
|
||||||
f.ctx, f.ctxCancel = context.WithCancel(context.Background())
|
f.ctx, f.ctxCancel = context.WithCancel(context.Background())
|
||||||
return f
|
return f
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
dns "golang.org/x/net/dns/dnsmessage"
|
dns "golang.org/x/net/dns/dnsmessage"
|
||||||
|
"tailscale.com/hostinfo"
|
||||||
"tailscale.com/types/dnstype"
|
"tailscale.com/types/dnstype"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -140,3 +141,30 @@ func TestGetRCode(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMaxDoHInFlight(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
goos string
|
||||||
|
ver string
|
||||||
|
want int
|
||||||
|
}{
|
||||||
|
{"ios", "", 10},
|
||||||
|
{"ios", "1532", 10},
|
||||||
|
{"ios", "9.3.2", 10},
|
||||||
|
{"ios", "14.3.2", 10},
|
||||||
|
{"ios", "15.3.2", 1000},
|
||||||
|
{"ios", "20.3.2", 1000},
|
||||||
|
{"android", "", 1000},
|
||||||
|
{"darwin", "", 1000},
|
||||||
|
{"linux", "", 1000},
|
||||||
|
}
|
||||||
|
for _, tc := range tests {
|
||||||
|
t.Run(fmt.Sprintf("%s-%s", tc.goos, tc.ver), func(t *testing.T) {
|
||||||
|
hostinfo.SetOSVersion(tc.ver)
|
||||||
|
got := maxDoHInFlight(tc.goos)
|
||||||
|
if got != tc.want {
|
||||||
|
t.Errorf("got %d; want %d", got, tc.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user