diff options
author | Mike Crute <mike@crute.us> | 2020-08-11 05:11:29 +0000 |
---|---|---|
committer | Mike Crute <mike@crute.us> | 2020-08-11 05:30:28 +0000 |
commit | 52eb9dc9fc1e0472aea4fd5bd0bb7ea259431d41 (patch) | |
tree | 98dd05b7aaee29e692bd42d4873c84d6d53abe6e /dns/cilent.go | |
parent | d7fec42036b331a8966efcc85e59b8dafea725ae (diff) | |
download | go_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.go | 81 |
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 @@ | |||
1 | package dns | ||
2 | |||
3 | import ( | ||
4 | "fmt" | ||
5 | |||
6 | "github.com/miekg/dns" | ||
7 | |||
8 | "code.crute.me/mcrute/go_ddns_manager/bind" | ||
9 | ) | ||
10 | |||
11 | type DNSClient struct { | ||
12 | Server string | ||
13 | } | ||
14 | |||
15 | type DNSTransaction struct { | ||
16 | zone *bind.Zone | ||
17 | key *bind.Key | ||
18 | msg *dns.Msg | ||
19 | } | ||
20 | |||
21 | func (t *DNSTransaction) Upsert(rrs ...RR) *DNSTransaction { | ||
22 | t.RemoveAll(rrs...).Insert(rrs...) | ||
23 | return t | ||
24 | } | ||
25 | |||
26 | func (t *DNSTransaction) Insert(rrs ...RR) *DNSTransaction { | ||
27 | t.msg.Insert(toRRSet(t.zone, rrs...)) | ||
28 | return t | ||
29 | } | ||
30 | |||
31 | func (t *DNSTransaction) Remove(rrs ...RR) *DNSTransaction { | ||
32 | t.msg.Remove(toRRSet(t.zone, rrs...)) | ||
33 | return t | ||
34 | } | ||
35 | |||
36 | func (t *DNSTransaction) RemoveAll(rrs ...RR) *DNSTransaction { | ||
37 | t.msg.RemoveRRset(toRRSet(t.zone, rrs...)) | ||
38 | return t | ||
39 | } | ||
40 | |||
41 | func (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 | |||
52 | func (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 | |||
63 | func (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 | } | ||