Skip to content

Commit f8a9c07

Browse files
Add IPv6 AAAA record support to PiHole provider
1 parent d07a03c commit f8a9c07

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

provider/pihole/client.go

+13-2
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,24 @@ func (p *piholeClient) listRecords(ctx context.Context, rtype string) ([]*endpoi
145145
if !ok {
146146
return out, nil
147147
}
148+
loop:
148149
for _, rec := range data {
149150
name := rec[0]
150151
target := rec[1]
151152
if !p.cfg.DomainFilter.Match(name) {
152153
log.Debugf("Skipping %s that does not match domain filter", name)
153154
continue
154155
}
156+
switch rtype {
157+
case endpoint.RecordTypeA:
158+
if strings.Contains(target, ":") {
159+
continue loop
160+
}
161+
case endpoint.RecordTypeAAAA:
162+
if strings.Contains(target, ".") {
163+
continue loop
164+
}
165+
}
155166
out = append(out, &endpoint.Endpoint{
156167
DNSName: name,
157168
Targets: []string{target},
@@ -180,7 +191,7 @@ func (p *piholeClient) cnameRecordsScript() string {
180191

181192
func (p *piholeClient) urlForRecordType(rtype string) (string, error) {
182193
switch rtype {
183-
case endpoint.RecordTypeA:
194+
case endpoint.RecordTypeA, endpoint.RecordTypeAAAA:
184195
return p.aRecordsScript(), nil
185196
case endpoint.RecordTypeCNAME:
186197
return p.cnameRecordsScript(), nil
@@ -287,7 +298,7 @@ func (p *piholeClient) newDNSActionForm(action string, ep *endpoint.Endpoint) *u
287298
form.Add("action", action)
288299
form.Add("domain", ep.DNSName)
289300
switch ep.RecordType {
290-
case endpoint.RecordTypeA:
301+
case endpoint.RecordTypeA, endpoint.RecordTypeAAAA:
291302
form.Add("ip", ep.Targets[0])
292303
case endpoint.RecordTypeCNAME:
293304
form.Add("target", ep.Targets[0])

provider/pihole/pihole.go

+5
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,15 @@ func (p *PiholeProvider) Records(ctx context.Context) ([]*endpoint.Endpoint, err
7171
if err != nil {
7272
return nil, err
7373
}
74+
aaaaRecords, err := p.api.listRecords(ctx, endpoint.RecordTypeAAAA)
75+
if err != nil {
76+
return nil, err
77+
}
7478
cnameRecords, err := p.api.listRecords(ctx, endpoint.RecordTypeCNAME)
7579
if err != nil {
7680
return nil, err
7781
}
82+
aRecords = append(aRecords, aaaaRecords...)
7883
return append(aRecords, cnameRecords...), nil
7984
}
8085

0 commit comments

Comments
 (0)