move overide rr into func
This commit is contained in:
parent
f6b13f423a
commit
81ce0257c4
@ -3,12 +3,9 @@ package override
|
|||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
clog "github.com/coredns/coredns/plugin/pkg/log"
|
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
)
|
)
|
||||||
|
|
||||||
var log = clog.NewWithPlugin("overide")
|
|
||||||
|
|
||||||
type Rule struct {
|
type Rule struct {
|
||||||
Search net.IP
|
Search net.IP
|
||||||
Override net.IP
|
Override net.IP
|
||||||
@ -22,6 +19,18 @@ type ResponseWrapper struct {
|
|||||||
func (r *ResponseWrapper) WriteMsg(res *dns.Msg) error {
|
func (r *ResponseWrapper) WriteMsg(res *dns.Msg) error {
|
||||||
for _, r := range r.Rules {
|
for _, r := range r.Rules {
|
||||||
for _, rr := range res.Answer {
|
for _, rr := range res.Answer {
|
||||||
|
overideRR(r, rr)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, rr := range res.Extra {
|
||||||
|
overideRR(r, rr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return r.ResponseWriter.WriteMsg(res)
|
||||||
|
}
|
||||||
|
|
||||||
|
func overideRR(r Rule, rr dns.RR) {
|
||||||
if rr.Header().Rrtype == dns.TypeA {
|
if rr.Header().Rrtype == dns.TypeA {
|
||||||
a := rr.(*dns.A)
|
a := rr.(*dns.A)
|
||||||
if a.A.Equal(r.Search) {
|
if a.A.Equal(r.Search) {
|
||||||
@ -33,10 +42,6 @@ func (r *ResponseWrapper) WriteMsg(res *dns.Msg) error {
|
|||||||
a.AAAA = r.Override
|
a.AAAA = r.Override
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return r.ResponseWriter.WriteMsg(res)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *ResponseWrapper) Write(buf []byte) (int, error) {
|
func (r *ResponseWrapper) Write(buf []byte) (int, error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user