Add any plugin (#2801)
* Add any plugin This adds the any plugin, a plain copy of coredns/any documented here https://coredns.io/explugins/any/ as an external plugin. Fixes: #2785 Signed-off-by: Miek Gieben <miek@miek.nl> * Stickler bot nit Signed-off-by: Miek Gieben <miek@miek.nl>
This commit is contained in:
parent
4f7fb98284
commit
39bc2af509
8 changed files with 129 additions and 0 deletions
|
@ -26,6 +26,7 @@ var Directives = []string{
|
||||||
"errors",
|
"errors",
|
||||||
"log",
|
"log",
|
||||||
"dnstap",
|
"dnstap",
|
||||||
|
"any",
|
||||||
"chaos",
|
"chaos",
|
||||||
"loadbalance",
|
"loadbalance",
|
||||||
"cache",
|
"cache",
|
||||||
|
|
|
@ -4,6 +4,7 @@ package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
// Include all plugins.
|
// Include all plugins.
|
||||||
|
_ "github.com/coredns/coredns/plugin/any"
|
||||||
_ "github.com/coredns/coredns/plugin/auto"
|
_ "github.com/coredns/coredns/plugin/auto"
|
||||||
_ "github.com/coredns/coredns/plugin/autopath"
|
_ "github.com/coredns/coredns/plugin/autopath"
|
||||||
_ "github.com/coredns/coredns/plugin/bind"
|
_ "github.com/coredns/coredns/plugin/bind"
|
||||||
|
|
|
@ -35,6 +35,7 @@ prometheus:metrics
|
||||||
errors:errors
|
errors:errors
|
||||||
log:log
|
log:log
|
||||||
dnstap:dnstap
|
dnstap:dnstap
|
||||||
|
any:any
|
||||||
chaos:chaos
|
chaos:chaos
|
||||||
loadbalance:loadbalance
|
loadbalance:loadbalance
|
||||||
cache:cache
|
cache:cache
|
||||||
|
|
4
plugin/any/OWNERS
Normal file
4
plugin/any/OWNERS
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
reviewers:
|
||||||
|
- miekg
|
||||||
|
approvers:
|
||||||
|
- miekg
|
36
plugin/any/README.md
Normal file
36
plugin/any/README.md
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
|
||||||
|
# any
|
||||||
|
|
||||||
|
## Name
|
||||||
|
|
||||||
|
*any* - give a minimal response to ANY queries.
|
||||||
|
|
||||||
|
## Description
|
||||||
|
|
||||||
|
*any* basically blocks ANY queries by responding to them with a short HINFO reply. See [RFC
|
||||||
|
8482](https://tools.ietf.org/html/rfc8482) for details.
|
||||||
|
|
||||||
|
## Syntax
|
||||||
|
|
||||||
|
~~~ txt
|
||||||
|
any
|
||||||
|
~~~
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
~~~ corefile
|
||||||
|
example.org {
|
||||||
|
whoami
|
||||||
|
any
|
||||||
|
}
|
||||||
|
~~~
|
||||||
|
|
||||||
|
A `dig +nocmd ANY example.org +noall +answer` now returns:
|
||||||
|
|
||||||
|
~~~ txt
|
||||||
|
example.org. 8482 IN HINFO "ANY obsoleted" "See RFC 8482"
|
||||||
|
~~~
|
||||||
|
|
||||||
|
## Also See
|
||||||
|
|
||||||
|
[RFC 8482](https://tools.ietf.org/html/rfc8482).
|
32
plugin/any/any.go
Normal file
32
plugin/any/any.go
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
package any
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/coredns/coredns/plugin"
|
||||||
|
|
||||||
|
"github.com/miekg/dns"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Any is a plugin that returns a HINFO reply to ANY queries.
|
||||||
|
type Any struct {
|
||||||
|
Next plugin.Handler
|
||||||
|
}
|
||||||
|
|
||||||
|
// ServeDNS implements the plugin.Handler interface.
|
||||||
|
func (a Any) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
||||||
|
if r.Question[0].Qtype != dns.TypeANY {
|
||||||
|
return plugin.NextOrFailure(a.Name(), a.Next, ctx, w, r)
|
||||||
|
}
|
||||||
|
|
||||||
|
m := new(dns.Msg)
|
||||||
|
m.SetReply(r)
|
||||||
|
hdr := dns.RR_Header{Name: r.Question[0].Name, Ttl: 8482, Class: dns.ClassINET, Rrtype: dns.TypeHINFO}
|
||||||
|
m.Answer = []dns.RR{&dns.HINFO{Hdr: hdr, Cpu: "ANY obsoleted", Os: "See RFC 8482"}}
|
||||||
|
|
||||||
|
w.WriteMsg(m)
|
||||||
|
return 0, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Name implements the Handler interface.
|
||||||
|
func (a Any) Name() string { return "any" }
|
28
plugin/any/any_test.go
Normal file
28
plugin/any/any_test.go
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
package any
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/coredns/coredns/plugin/pkg/dnstest"
|
||||||
|
"github.com/coredns/coredns/plugin/test"
|
||||||
|
|
||||||
|
"github.com/miekg/dns"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestAny(t *testing.T) {
|
||||||
|
req := new(dns.Msg)
|
||||||
|
req.SetQuestion("example.org.", dns.TypeANY)
|
||||||
|
a := &Any{}
|
||||||
|
|
||||||
|
rec := dnstest.NewRecorder(&test.ResponseWriter{})
|
||||||
|
_, err := a.ServeDNS(context.TODO(), rec, req)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Expected no error, but got %q", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if rec.Msg.Answer[0].(*dns.HINFO).Cpu != "ANY obsoleted" {
|
||||||
|
t.Errorf("Expected HINFO, but got %q", rec.Msg.Answer[0].(*dns.HINFO).Cpu)
|
||||||
|
}
|
||||||
|
}
|
26
plugin/any/setup.go
Normal file
26
plugin/any/setup.go
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
package any
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/coredns/coredns/core/dnsserver"
|
||||||
|
"github.com/coredns/coredns/plugin"
|
||||||
|
|
||||||
|
"github.com/mholt/caddy"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
caddy.RegisterPlugin("any", caddy.Plugin{
|
||||||
|
ServerType: "dns",
|
||||||
|
Action: setup,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func setup(c *caddy.Controller) error {
|
||||||
|
a := Any{}
|
||||||
|
|
||||||
|
dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler {
|
||||||
|
a.Next = next
|
||||||
|
return a
|
||||||
|
})
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue