summaryrefslogtreecommitdiff
path: root/dns/cilent.go
diff options
context:
space:
mode:
authorMike Crute <mike@crute.us>2020-08-11 05:11:29 +0000
committerMike Crute <mike@crute.us>2020-08-11 05:30:28 +0000
commit52eb9dc9fc1e0472aea4fd5bd0bb7ea259431d41 (patch)
tree98dd05b7aaee29e692bd42d4873c84d6d53abe6e /dns/cilent.go
parentd7fec42036b331a8966efcc85e59b8dafea725ae (diff)
downloadgo_ddns_manager-52eb9dc9fc1e0472aea4fd5bd0bb7ea259431d41.tar.bz2
go_ddns_manager-52eb9dc9fc1e0472aea4fd5bd0bb7ea259431d41.tar.xz
go_ddns_manager-52eb9dc9fc1e0472aea4fd5bd0bb7ea259431d41.zip
Do not do ddns update if ip is same
Diffstat (limited to 'dns/cilent.go')
-rw-r--r--dns/cilent.go81
1 files changed, 0 insertions, 81 deletions
diff --git a/dns/cilent.go b/dns/cilent.go
deleted file mode 100644
index 6efe1b5..0000000
--- a/dns/cilent.go
+++ /dev/null
@@ -1,81 +0,0 @@
1package dns
2
3import (
4 "fmt"
5
6 "github.com/miekg/dns"
7
8 "code.crute.me/mcrute/go_ddns_manager/bind"
9)
10
11type DNSClient struct {
12 Server string
13}
14
15type DNSTransaction struct {
16 zone *bind.Zone
17 key *bind.Key
18 msg *dns.Msg
19}
20
21func (t *DNSTransaction) Upsert(rrs ...RR) *DNSTransaction {
22 t.RemoveAll(rrs...).Insert(rrs...)
23 return t
24}
25
26func (t *DNSTransaction) Insert(rrs ...RR) *DNSTransaction {
27 t.msg.Insert(toRRSet(t.zone, rrs...))
28 return t
29}
30
31func (t *DNSTransaction) Remove(rrs ...RR) *DNSTransaction {
32 t.msg.Remove(toRRSet(t.zone, rrs...))
33 return t
34}
35
36func (t *DNSTransaction) RemoveAll(rrs ...RR) *DNSTransaction {
37 t.msg.RemoveRRset(toRRSet(t.zone, rrs...))
38 return t
39}
40
41func (c *DNSClient) AXFR(zone *bind.Zone) (chan *dns.Envelope, error) {
42 k := zone.Keys()[0]
43 t := &dns.Transfer{TsigSecret: k.AsMap()} // Always uses tcp
44
45 m := &dns.Msg{}
46 m.SetAxfr(zone.Name)
47 k.Sign(m)
48
49 return t.In(m, fmt.Sprintf("%s:53", c.Server))
50}
51
52func (c *DNSClient) StartUpdate(zone *bind.Zone) *DNSTransaction {
53 m := &dns.Msg{}
54 m.SetUpdate(zone.Name)
55
56 return &DNSTransaction{
57 zone: zone,
58 key: zone.Keys()[0],
59 msg: m,
60 }
61}
62
63func (c *DNSClient) SendUpdate(t *DNSTransaction) error {
64 udp := &dns.Client{Net: "udp", TsigSecret: t.key.AsMap()}
65 tcp := &dns.Client{Net: "tcp", TsigSecret: t.key.AsMap()}
66
67 t.msg.SetEdns0(4096, false)
68 t.key.Sign(t.msg)
69
70 in, _, err := udp.Exchange(t.msg, c.Server)
71 if in != nil && in.Truncated {
72 // If the TCP request succeeds, the err will reset to nil
73 in, _, err = tcp.Exchange(t.msg, c.Server)
74 }
75
76 if err != nil {
77 return err
78 }
79
80 return nil
81}