aboutsummaryrefslogtreecommitdiff
path: root/plugin/rewrite/name.go
diff options
context:
space:
mode:
Diffstat (limited to 'plugin/rewrite/name.go')
-rw-r--r--plugin/rewrite/name.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/plugin/rewrite/name.go b/plugin/rewrite/name.go
new file mode 100644
index 000000000..189133542
--- /dev/null
+++ b/plugin/rewrite/name.go
@@ -0,0 +1,24 @@
+package rewrite
+
+import (
+ "github.com/coredns/coredns/plugin"
+
+ "github.com/miekg/dns"
+)
+
+type nameRule struct {
+ From, To string
+}
+
+func newNameRule(from, to string) (Rule, error) {
+ return &nameRule{plugin.Name(from).Normalize(), plugin.Name(to).Normalize()}, nil
+}
+
+// Rewrite rewrites the the current request.
+func (rule *nameRule) Rewrite(w dns.ResponseWriter, r *dns.Msg) Result {
+ if rule.From == r.Question[0].Name {
+ r.Question[0].Name = rule.To
+ return RewriteDone
+ }
+ return RewriteIgnored
+}