dnsforward -- if given addresses without ports, assign default ports
This commit is contained in:
parent
8316d39b42
commit
9d87ae95e6
|
@ -7,6 +7,7 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -172,16 +173,31 @@ func GetUpstream(address string) (Upstream, error) {
|
||||||
}
|
}
|
||||||
switch url.Scheme {
|
switch url.Scheme {
|
||||||
case "dns":
|
case "dns":
|
||||||
return &plainDNS{Address: address}, nil
|
if url.Port() == "" {
|
||||||
|
url.Host += ":53"
|
||||||
|
}
|
||||||
|
return &plainDNS{Address: url.String()}, nil
|
||||||
case "tls":
|
case "tls":
|
||||||
return &dnsOverTLS{Address: address}, nil
|
if url.Port() == "" {
|
||||||
|
url.Host += ":853"
|
||||||
|
}
|
||||||
|
return &dnsOverTLS{Address: url.String()}, nil
|
||||||
case "https":
|
case "https":
|
||||||
return &dnsOverHTTPS{Address: address}, nil
|
return &dnsOverHTTPS{Address: url.String()}, nil
|
||||||
default:
|
default:
|
||||||
return &plainDNS{Address: address}, nil
|
// assume it's plain DNS
|
||||||
|
if url.Port() == "" {
|
||||||
|
url.Host += ":53"
|
||||||
|
}
|
||||||
|
return &plainDNS{Address: url.String()}, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// we don't have scheme in the url, so it's just a plain DNS host:port
|
// we don't have scheme in the url, so it's just a plain DNS host:port
|
||||||
|
_, _, err := net.SplitHostPort(address)
|
||||||
|
if err != nil {
|
||||||
|
// doesn't have port, default to 53
|
||||||
|
address = net.JoinHostPort(address, "53")
|
||||||
|
}
|
||||||
return &plainDNS{Address: address}, nil
|
return &plainDNS{Address: address}, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue