func (p *Proxy) handleDNSRequest(d *DNSContext) error {
	d.StartTime = time.Now()
	p.logDNSMessage(d.Req)

	// ratelimit based on IP only, protects CPU cycles and outbound connections
	if d.Proto == ProtoUDP && p.isRatelimited(d.Addr) {
		log.Tracef("Ratelimiting %v based on IP only", d.Addr)
		return nil // do nothing, don't reply, we got ratelimited
	}

	if len(d.Req.Question) != 1 {
		log.Printf("got invalid number of questions: %v", len(d.Req.Question))
		d.Res = p.genServerFailure(d.Req)
	}

	// refuse ANY requests (anti-DDOS measure)
	if p.RefuseAny && len(d.Req.Question) > 0 && d.Req.Question[0].Qtype == dns.TypeANY {
		log.Tracef("Refusing type=ANY request")
		d.Res = p.genNotImpl(d.Req)
	}

	var err error

	if d.Res == nil {
		if (len(p.upstreamsWithRtt) == 0 && !p.AllServers) || (len(p.Upstreams) == 0 && p.AllServers) {
			panic("SHOULD NOT HAPPEN: no default upstreams specified")
		}

		// execute the DNS request
		// if there is a custom middleware configured, use it
		if p.Handler != nil {
			err = p.Handler(p, d)
		} else {
			err = p.Resolve(d)
		}

		if err != nil {
			err = errorx.Decorate(err, "talking to dnsUpstream failed")
		}
	}

	p.logDNSMessage(d.Res)
	p.respond(d)
	return err
}
// handleDNSRequest processes the incoming packet bytes and returns with an optional response packet.
handleDNSRequest processes the incoming packet bytes and returns with an optional response packet.
// handleDNSRequest processes the incoming packet bytes and returns with an optional response packet .
func (p *Proxy) handleDNSRequest(d *DNSContext) error {
	d.StartTime = time.Now()
	p.logDNSMessage(d.Req)
	if d.Proto == ProtoUDP && p.isRatelimited(d.Addr) {
		log.Tracef("Ratelimiting %v based on IP only", d.Addr)
		return nil 
	}
	if len(d.Req.Question) != 1 {
		log.Printf("got invalid number of questions: %v", len(d.Req.Question))
		d.Res = p.genServerFailure(d.Req)
	}
	if p.RefuseAny && len(d.Req.Question) > 0 && d.Req.Question[0].Qtype == dns.TypeANY {
		log.Tracef("Refusing type=ANY request")
		d.Res = p.genNotImpl(d.Req)
	}
	var err error
	if d.Res == nil {
		if (len(p.upstreamsWithRtt) == 0 && !p.AllServers) || (len(p.Upstreams) == 0 && p.AllServers) {
			panic("SHOULD NOT HAPPEN: no default upstreams specified")
		}
		if p.Handler != nil {
			err = p.Handler(p, d)
		} else {
			err = p.Resolve(d)
		}
		if err != nil {
			err = errorx.Decorate(err, "talking to dnsUpstream failed")
		}
	}
	p.logDNSMessage(d.Res)
	p.respond(d)
	return err
}
func ( p * Proxy ) handleDNSRequest ( d * DNSContext ) error { d . StartTime = time . Now ( ) p . logDNSMessage ( d . Req ) if d . Proto == ProtoUDP && p . isRatelimited ( d . Addr ) { log . Tracef ( " " , d . Addr ) return nil } if len ( d . Req . Question ) != 1 { log . Printf ( " " , len ( d . Req . Question ) ) d . Res = p . genServerFailure ( d . Req ) } if p . RefuseAny && len ( d . Req . Question ) > 0 && d . Req . Question [ 0 ] . Qtype == dns . TypeANY { log . Tracef ( " " ) d . Res = p . genNotImpl ( d . Req ) } var err error if d . Res == nil { if ( len ( p . upstreamsWithRtt ) == 0 && ! p . AllServers ) || ( len ( p . Upstreams ) == 0 && p . AllServers ) { panic ( " " ) } if p . Handler != nil { err = p . Handler ( p , d ) } else { err = p . Resolve ( d ) } if err != nil { err = errorx . Decorate ( err , " " ) } } p . logDNSMessage ( d . Res ) p . respond ( d ) return err }
handleDNSRequest processes the incoming packet bytes and returns with an optional response packet.
handleDNSRequest processes the incoming packet bytes and returns with an optional response packet .
// ratelimit based on IP only, protects CPU cycles and outbound connections // do nothing, don't reply, we got ratelimited // refuse ANY requests (anti-DDOS measure) // execute the DNS request // if there is a custom middleware configured, use it