Add option -no-ecs

This commit is contained in:
Star Brilliant
2017-11-24 22:04:36 +08:00
parent f621d88d99
commit 244af0e631
2 changed files with 8 additions and 2 deletions

View File

@@ -39,16 +39,18 @@ type Client struct {
upstream string
bootstrap string
timeout uint
noECS bool
udpServer *dns.Server
tcpServer *dns.Server
httpClient *http.Client
}
func NewClient(addr, upstream, bootstrap string, timeout uint) (c *Client, err error) {
func NewClient(addr, upstream, bootstrap string, timeout uint, noECS bool) (c *Client, err error) {
c = &Client {
addr: addr,
upstream: upstream,
timeout: timeout,
noECS: noECS,
}
c.udpServer = &dns.Server {
Addr: addr,
@@ -224,6 +226,9 @@ var (
func (c *Client) findClientIP(w dns.ResponseWriter, r *dns.Msg) (ednsClientAddress net.IP, ednsClientNetmask uint8) {
ednsClientNetmask = 255
if c.noECS {
return net.IPv4(0, 0, 0, 0), 0
}
if opt := r.IsEdns0(); opt != nil {
for _, option := range opt.Option {
if option.Option() == dns.EDNS0SUBNET {

View File

@@ -28,9 +28,10 @@ func main() {
upstream := flag.String("upstream", "https://dns.google.com/resolve", "HTTP path for upstream resolver")
bootstrap := flag.String("bootstrap", "", "The bootstrap DNS server to resolve the address of the upstream resolver")
timeout := flag.Uint("timeout", 10, "Timeout for upstream request")
noECS := flag.Bool("no-ecs", false, "Disable EDNS0-Client-Subnet, do not send client's IP address")
flag.Parse()
client, err := NewClient(*addr, *upstream, *bootstrap, *timeout)
client, err := NewClient(*addr, *upstream, *bootstrap, *timeout, *noECS)
if err != nil { log.Fatalln(err) }
_ = client.Start()
}