aboutsummaryrefslogtreecommitdiff
path: root/plugin/file/notify.go
diff options
context:
space:
mode:
authorGravatar Yong Tang <yong.tang.github@outlook.com> 2020-07-08 09:00:26 -0700
committerGravatar GitHub <noreply@github.com> 2020-07-08 09:00:26 -0700
commit614d08cba29ed4904d11008e795c081c4f392b77 (patch)
treee4601abda23ec9d18e2929433c260a37928e1344 /plugin/file/notify.go
parent68f1dd5ddf0451cc3a1b24a72c2965b8d896ffba (diff)
downloadcoredns-614d08cba29ed4904d11008e795c081c4f392b77.tar.gz
coredns-614d08cba29ed4904d11008e795c081c4f392b77.tar.zst
coredns-614d08cba29ed4904d11008e795c081c4f392b77.zip
Revert "Implement notifies for transfer plugin (#3972)" (#3995)
This reverts commit 68f1dd5ddf0451cc3a1b24a72c2965b8d896ffba. Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
Diffstat (limited to 'plugin/file/notify.go')
-rw-r--r--plugin/file/notify.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/plugin/file/notify.go b/plugin/file/notify.go
index 7d4e35cc3..83d73ee6f 100644
--- a/plugin/file/notify.go
+++ b/plugin/file/notify.go
@@ -1,8 +1,10 @@
package file
import (
+ "fmt"
"net"
+ "github.com/coredns/coredns/plugin/pkg/rcode"
"github.com/coredns/coredns/request"
"github.com/miekg/dns"
@@ -31,3 +33,48 @@ func (z *Zone) isNotify(state request.Request) bool {
}
return false
}
+
+// Notify will send notifies to all configured TransferTo IP addresses.
+func (z *Zone) Notify() {
+ go notify(z.origin, z.TransferTo)
+}
+
+// notify sends notifies to the configured remote servers. It will try up to three times
+// before giving up on a specific remote. We will sequentially loop through "to"
+// until they all have replied (or have 3 failed attempts).
+func notify(zone string, to []string) error {
+ m := new(dns.Msg)
+ m.SetNotify(zone)
+ c := new(dns.Client)
+
+ for _, t := range to {
+ if t == "*" {
+ continue
+ }
+ if err := notifyAddr(c, m, t); err != nil {
+ log.Error(err.Error())
+ }
+ }
+ log.Infof("Sent notifies for zone %q to %v", zone, to)
+ return nil
+}
+
+func notifyAddr(c *dns.Client, m *dns.Msg, s string) error {
+ var err error
+
+ code := dns.RcodeServerFailure
+ for i := 0; i < 3; i++ {
+ ret, _, err := c.Exchange(m, s)
+ if err != nil {
+ continue
+ }
+ code = ret.Rcode
+ if code == dns.RcodeSuccess {
+ return nil
+ }
+ }
+ if err != nil {
+ return fmt.Errorf("notify for zone %q was not accepted by %q: %q", m.Question[0].Name, s, err)
+ }
+ return fmt.Errorf("notify for zone %q was not accepted by %q: rcode was %q", m.Question[0].Name, s, rcode.ToString(code))
+}