fix: xtransport: Check 'fallback_resolver'

And also DefaultFallbackResolver.

As far a I could see, value needs to have port defined
too. dns.Exchange does seem to use address as such.
This commit is contained in:
Markus Linnala 2019-10-20 21:35:25 +03:00 committed by Frank Denis
parent 890dcca270
commit d14d78e648
2 changed files with 20 additions and 1 deletions

View File

@ -11,6 +11,7 @@ import (
"os"
"path"
"path/filepath"
"strconv"
"strings"
"time"
@ -272,11 +273,14 @@ func ConfigLoad(proxy *Proxy, svcFlag *string) error {
proxy.xTransport = NewXTransport()
proxy.xTransport.tlsDisableSessionTickets = config.TLSDisableSessionTickets
proxy.xTransport.tlsCipherSuite = config.TLSCipherSuite
proxy.xTransport.fallbackResolver = config.FallbackResolver
proxy.xTransport.mainProto = proxy.mainProto
if len(config.FallbackResolver) > 0 {
if err := CheckResolver(config.FallbackResolver); err != nil {
dlog.Fatalf("fallback_resolver [%v]", err)
}
proxy.xTransport.ignoreSystemDNS = config.IgnoreSystemDNS
}
proxy.xTransport.fallbackResolver = config.FallbackResolver
proxy.xTransport.useIPv4 = config.SourceIPv4
proxy.xTransport.useIPv6 = config.SourceIPv6
proxy.xTransport.keepAlive = time.Duration(config.KeepAlive) * time.Second
@ -690,3 +694,15 @@ func cdLocal() {
}
os.Chdir(filepath.Dir(exeFileName))
}
func CheckResolver(resolver string) error {
host, port := ExtractHostAndPort(resolver, -1)
if ip := ParseIP(host); ip == nil {
return fmt.Errorf("Host does not parse as IP '%s'", resolver)
} else if port == -1 {
return fmt.Errorf("Port missing '%s'", resolver)
} else if _, err := strconv.ParseUint(strconv.Itoa(port), 10, 16); err != nil {
return fmt.Errorf("Port does not parse '%s' [%v]", resolver, err)
}
return nil
}

View File

@ -53,6 +53,9 @@ type XTransport struct {
}
func NewXTransport() *XTransport {
if err := CheckResolver(DefaultFallbackResolver); err != nil {
panic("DefaultFallbackResolver does not parse")
}
xTransport := XTransport{
cachedIPs: CachedIPs{cache: make(map[string]string)},
keepAlive: DefaultKeepAlive,