2017-02-07 16:53:16 -05:00
|
|
|
package rewrite
|
|
|
|
|
|
|
|
|
|
import (
|
2017-09-14 09:36:06 +01:00
|
|
|
"github.com/coredns/coredns/plugin"
|
2017-03-06 16:32:17 -05:00
|
|
|
|
2017-02-07 16:53:16 -05:00
|
|
|
"github.com/miekg/dns"
|
|
|
|
|
)
|
|
|
|
|
|
2017-03-06 16:32:17 -05:00
|
|
|
type nameRule struct {
|
2017-02-07 16:53:16 -05:00
|
|
|
From, To string
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-06 16:32:17 -05:00
|
|
|
func newNameRule(from, to string) (Rule, error) {
|
2017-09-14 09:36:06 +01:00
|
|
|
return &nameRule{plugin.Name(from).Normalize(), plugin.Name(to).Normalize()}, nil
|
2017-02-07 16:53:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Rewrite rewrites the the current request.
|
2017-08-24 09:34:07 -07:00
|
|
|
func (rule *nameRule) Rewrite(w dns.ResponseWriter, r *dns.Msg) Result {
|
2017-02-07 16:53:16 -05:00
|
|
|
if rule.From == r.Question[0].Name {
|
|
|
|
|
r.Question[0].Name = rule.To
|
|
|
|
|
return RewriteDone
|
|
|
|
|
}
|
|
|
|
|
return RewriteIgnored
|
|
|
|
|
}
|
2017-09-20 13:06:53 -07:00
|
|
|
|
|
|
|
|
// Mode returns the processing mode
|
|
|
|
|
func (rule *nameRule) Mode() string {
|
|
|
|
|
return Stop
|
|
|
|
|
}
|