aboutsummaryrefslogtreecommitdiff
path: root/plugin/rewrite/name.go
blob: 016ae4debf0bcc5ed0416d72e8a8a29729f41a9d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
}

// Mode returns the processing mode
func (rule *nameRule) Mode() string {
	return Stop
}