summaryrefslogtreecommitdiff
path: root/dns
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
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')
-rw-r--r--dns/client.go (renamed from dns/cilent.go)63
1 files changed, 63 insertions, 0 deletions
diff --git a/dns/cilent.go b/dns/client.go
index 6efe1b5..f322b45 100644
--- a/dns/cilent.go
+++ b/dns/client.go
@@ -49,6 +49,37 @@ func (c *DNSClient) AXFR(zone *bind.Zone) (chan *dns.Envelope, error) {
49 return t.In(m, fmt.Sprintf("%s:53", c.Server)) 49 return t.In(m, fmt.Sprintf("%s:53", c.Server))
50} 50}
51 51
52func (c *DNSClient) ReadRemoteZone(zone *bind.Zone) ([]RR, error) {
53 rrs := []RR{}
54 seenSoa := false
55
56 data, err := c.AXFR(zone)
57 if err != nil {
58 return nil, err
59 }
60
61 for rd := range data {
62 for _, r := range rd.RR {
63 switch dr := FromDNS(r).(type) {
64 case *SOA:
65 // Transfers have 2 SOA records, exclude the last one
66 if !seenSoa {
67 rrs = append(rrs, dr)
68 seenSoa = true
69 }
70 case RR:
71 rrs = append(rrs, dr)
72 default:
73 // This should only be possible if we somehow are
74 // missing generated DNS data types.
75 return nil, fmt.Errorf("Invalid return type")
76 }
77 }
78 }
79
80 return rrs, nil
81}
82
52func (c *DNSClient) StartUpdate(zone *bind.Zone) *DNSTransaction { 83func (c *DNSClient) StartUpdate(zone *bind.Zone) *DNSTransaction {
53 m := &dns.Msg{} 84 m := &dns.Msg{}
54 m.SetUpdate(zone.Name) 85 m.SetUpdate(zone.Name)
@@ -60,6 +91,18 @@ func (c *DNSClient) StartUpdate(zone *bind.Zone) *DNSTransaction {
60 } 91 }
61} 92}
62 93
94func (c *DNSClient) QueryRecursive(zone *bind.Zone, fqdn string, rtype uint16) *DNSTransaction {
95 m := &dns.Msg{}
96 m.RecursionDesired = true
97 m.SetQuestion(fqdn, rtype)
98
99 return &DNSTransaction{
100 zone: zone,
101 key: zone.Keys()[0],
102 msg: m,
103 }
104}
105
63func (c *DNSClient) SendUpdate(t *DNSTransaction) error { 106func (c *DNSClient) SendUpdate(t *DNSTransaction) error {
64 udp := &dns.Client{Net: "udp", TsigSecret: t.key.AsMap()} 107 udp := &dns.Client{Net: "udp", TsigSecret: t.key.AsMap()}
65 tcp := &dns.Client{Net: "tcp", TsigSecret: t.key.AsMap()} 108 tcp := &dns.Client{Net: "tcp", TsigSecret: t.key.AsMap()}
@@ -79,3 +122,23 @@ func (c *DNSClient) SendUpdate(t *DNSTransaction) error {
79 122
80 return nil 123 return nil
81} 124}
125
126func (c *DNSClient) SendQuery(t *DNSTransaction) ([]dns.RR, error) {
127 udp := &dns.Client{Net: "udp", TsigSecret: t.key.AsMap()}
128 tcp := &dns.Client{Net: "tcp", TsigSecret: t.key.AsMap()}
129
130 t.msg.SetEdns0(4096, false)
131 t.key.Sign(t.msg)
132
133 in, _, err := udp.Exchange(t.msg, c.Server)
134 if in != nil && in.Truncated {
135 // If the TCP request succeeds, the err will reset to nil
136 in, _, err = tcp.Exchange(t.msg, c.Server)
137 }
138
139 if err != nil {
140 return nil, err
141 }
142
143 return in.Answer, nil
144}