ServeDNS implements the plugin.Handler interface.
(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
| 31 | |
| 32 | // ServeDNS implements the plugin.Handler interface. |
| 33 | func (l *Loop) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) { |
| 34 | if r.Question[0].Qtype != dns.TypeHINFO { |
| 35 | return plugin.NextOrFailure(l.Name(), l.Next, ctx, w, r) |
| 36 | } |
| 37 | if l.disabled() { |
| 38 | return plugin.NextOrFailure(l.Name(), l.Next, ctx, w, r) |
| 39 | } |
| 40 | |
| 41 | state := request.Request{W: w, Req: r} |
| 42 | |
| 43 | zone := plugin.Zones([]string{l.zone}).Matches(state.Name()) |
| 44 | if zone == "" { |
| 45 | return plugin.NextOrFailure(l.Name(), l.Next, ctx, w, r) |
| 46 | } |
| 47 | |
| 48 | if state.Name() == l.qname { |
| 49 | l.inc() |
| 50 | } |
| 51 | |
| 52 | if l.seen() > 2 { |
| 53 | log.Fatalf(`Loop (%s -> %s) detected for zone %q, see https://coredns.io/plugins/loop#troubleshooting. Query: "HINFO %s"`, state.RemoteAddr(), l.address(), l.zone, l.qname) |
| 54 | } |
| 55 | |
| 56 | return plugin.NextOrFailure(l.Name(), l.Next, ctx, w, r) |
| 57 | } |
| 58 | |
| 59 | // Name implements the plugin.Handler interface. |
| 60 | func (l *Loop) Name() string { return "loop" } |