Skip to content

Commit

Permalink
Add IPv6 AAAA record support to PiHole provider
Browse files Browse the repository at this point in the history
  • Loading branch information
PseudoResonance committed Mar 20, 2024
1 parent d07a03c commit 7db0451
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
15 changes: 13 additions & 2 deletions provider/pihole/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,24 @@ func (p *piholeClient) listRecords(ctx context.Context, rtype string) ([]*endpoi
if !ok {
return out, nil
}
loop:
for _, rec := range data {
name := rec[0]
target := rec[1]
if !p.cfg.DomainFilter.Match(name) {
log.Debugf("Skipping %s that does not match domain filter", name)
continue
}
switch rtype {
case endpoint.RecordTypeA:
if strings.Contains(target, ":") {
continue loop
}
case endpoint.RecordTypeAAAA:
if strings.Contains(target, ".") {
continue loop
}
}
out = append(out, &endpoint.Endpoint{
DNSName: name,
Targets: []string{target},
Expand Down Expand Up @@ -180,7 +191,7 @@ func (p *piholeClient) cnameRecordsScript() string {

func (p *piholeClient) urlForRecordType(rtype string) (string, error) {
switch rtype {
case endpoint.RecordTypeA:
case endpoint.RecordTypeA, endpoint.RecordTypeAAAA:
return p.aRecordsScript(), nil
case endpoint.RecordTypeCNAME:
return p.cnameRecordsScript(), nil
Expand Down Expand Up @@ -287,7 +298,7 @@ func (p *piholeClient) newDNSActionForm(action string, ep *endpoint.Endpoint) *u
form.Add("action", action)
form.Add("domain", ep.DNSName)
switch ep.RecordType {
case endpoint.RecordTypeA:
case endpoint.RecordTypeA, endpoint.RecordTypeAAAA:
form.Add("ip", ep.Targets[0])
case endpoint.RecordTypeCNAME:
form.Add("target", ep.Targets[0])
Expand Down
5 changes: 5 additions & 0 deletions provider/pihole/pihole.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,15 @@ func (p *PiholeProvider) Records(ctx context.Context) ([]*endpoint.Endpoint, err
if err != nil {
return nil, err
}
aaaaRecords, err := p.api.listRecords(ctx, endpoint.RecordTypeAAAA)
if err != nil {
return nil, err
}
cnameRecords, err := p.api.listRecords(ctx, endpoint.RecordTypeCNAME)
if err != nil {
return nil, err
}
aRecords = append(aRecords, aaaaRecords...)
return append(aRecords, cnameRecords...), nil
}

Expand Down

0 comments on commit 7db0451

Please sign in to comment.