func (rrl *RRL) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
	state := request.Request{W: w, Req: r}
	zone := plugin.Zones(rrl.Zones).Matches(state.Name())
	if zone == "" {
		return plugin.NextOrFailure(rrl.Name(), rrl.Next, ctx, w, r)
	}
	if rrl.requestsInterval != 0 {
		t := rrl.addrPrefix(state.RemoteAddr())
		b, err := rrl.debit(rrl.requestsInterval, t)
		if b < 0 && err == nil {
			log.Debugf("request rate exceeded from %v (token='%v', balance=%.1f)", state.IP(), t, float64(b)/float64(rrl.requestsInterval))
			RequestsExceeded.WithLabelValues(state.IP()).Add(1)
			if !rrl.reportOnly {
				return dns.RcodeSuccess, errReqRateLimit
			}
		}
	}
	if state.Proto() == "tcp" {
		return plugin.NextOrFailure(rrl.Name(), rrl.Next, ctx, w, r)
	}
	nw := nonwriter.New(w)
	rcode, err := plugin.NextOrFailure(rrl.Name(), rrl.Next, ctx, nw, r)
	if err != nil || nw.Msg == nil {
		return rcode, err
	}
	rtype := responseType(nw.Msg)
	t := rrl.responseToToken(nw, rtype)
	allowance := rrl.allowanceForRtype(rtype)
	if allowance == 0 {
		err = w.WriteMsg(nw.Msg)
		return rcode, err
	}
	b, err := rrl.debit(allowance, t)
	if b < 0 && err == nil {
		log.Debugf("response rate exceeded to %v for \"%v\" %v (token='%v', balance=%.1f)", nw.RemoteAddr().String(), nw.Msg.Question[0].String(), dns.RcodeToString[nw.Msg.Rcode], t, float64(b)/float64(allowance))
		ResponsesExceeded.WithLabelValues(state.IP()).Add(1)
		if !rrl.reportOnly {
			return dns.RcodeSuccess, errRespRateLimit
		}
	}
	if err != nil {
		log.Warningf("%v", err)
	}
	err = w.WriteMsg(nw.Msg)
	return rcode, err
}
ServeDNS implements the Handler interface.
package rrl
import (
	"context"
	"errors"
	"github.com/coredns/coredns/plugin"
	"github.com/coredns/coredns/plugin/pkg/nonwriter"
	"github.com/coredns/coredns/request"
	"github.com/miekg/dns"
)
func (rrl *RRL) Name() string { return "rrl" }