net/interfaces: quiet PAC detection logging in no-PAC case, add benchmark

This commit is contained in:
Brad Fitzpatrick 2020-10-01 22:02:39 -07:00
parent 38dda1ea9e
commit cab3eb995f
2 changed files with 34 additions and 8 deletions

View File

@ -168,16 +168,25 @@ func DefaultRouteInterface() (string, error) {
func getPACWindows() string {
var res *uint16
r, _, err := detectAutoProxyConfigURL.Call(
r, _, e := detectAutoProxyConfigURL.Call(
winHTTP_AUTO_DETECT_TYPE_DHCP|winHTTP_AUTO_DETECT_TYPE_DNS_A,
uintptr(unsafe.Pointer(&res)),
)
var got string
if res != nil {
got = windows.UTF16PtrToString(res)
globalFree.Call(uintptr(unsafe.Pointer(res)))
} else {
log.Printf("getPACWindows: r=%v, err=%#v", r, err)
if r == 1 {
if res == nil {
log.Printf("getPACWindows: unexpected success with nil result")
return ""
}
defer globalFree.Call(uintptr(unsafe.Pointer(res)))
return windows.UTF16PtrToString(res)
}
return got
const (
ERROR_WINHTTP_AUTODETECTION_FAILED = 12180
)
if e == syscall.Errno(ERROR_WINHTTP_AUTODETECTION_FAILED) {
// Common case on networks without advertised PAC.
return ""
}
log.Printf("getPACWindows: %T=%v", e, e) // syscall.Errno=0x....
return ""
}

View File

@ -0,0 +1,17 @@
// Copyright (c) 2020 Tailscale Inc & AUTHORS All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package interfaces
import "testing"
func BenchmarkGetPACWindows(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
v := getPACWindows()
if i == 0 {
b.Logf("Got: %q", v)
}
}
}