diff --git a/ldap.go b/ldap.go index 36c74da..83b30ac 100644 --- a/ldap.go +++ b/ldap.go @@ -24,13 +24,19 @@ import ( type ldapRecord struct { fqdn string - ip net.IP + ip4 net.IP + ip6 net.IP } func (r *ldapRecord) A() (a *dns.A) { - return &dns.A{Hdr: dns.RR_Header{Name: r.fqdn, Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: 0}, A: r.ip} + return &dns.A{Hdr: dns.RR_Header{Name: r.fqdn, Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: 0}, A: r.ip4} } +func (r *ldapRecord) AAAA() (a *dns.AAAA) { + return &dns.AAAA{Hdr: dns.RR_Header{Name: r.fqdn, Rrtype: dns.TypeAAAA, Class: dns.ClassINET, Ttl: 86400}, AAAA: r.ip6} +} + + // Ldap is an ldap plugin to serve zone entries from a ldap backend. type Ldap struct { Next plugin.Handler @@ -43,6 +49,7 @@ type Ldap struct { SearchRequest *ldap.SearchRequest FqdnAttr string Ip4Attr string + Ip6Attr string ldapURL string pagingLimit uint32 diff --git a/setup.go b/setup.go index 0e5092d..e01cabf 100644 --- a/setup.go +++ b/setup.go @@ -150,6 +150,13 @@ func ParseStanza(c *caddy.Controller) (*Ldap, error) { ldap.SearchRequest.Attributes = append(ldap.SearchRequest.Attributes, c.Val()) ldap.Ip4Attr = c.Val() // ipHostNumber + case "ip6": + if !c.NextArg() { + return nil, c.ArgErr() + } + + ldap.SearchRequest.Attributes = append(ldap.SearchRequest.Attributes, c.Val()) + ldap.Ip6Attr = c.Val() // ipHostNumber default: return nil, c.Errf("unknown attributes property '%s'", c.Val()) } diff --git a/sync.go b/sync.go index e17282b..0533a2a 100644 --- a/sync.go +++ b/sync.go @@ -59,6 +59,7 @@ func (l *Ldap) UpdateZones() error { } for _, lr := range lrpz { + err = zoneFileMap[zn].Insert(lr.AAAA()) err = zoneFileMap[zn].Insert(lr.A()) if err != nil { return fmt.Errorf("updating zones: %w", err) @@ -105,7 +106,8 @@ func (l *Ldap) fetchLdapRecords() (ldapRecords []ldapRecord, err error) { } ldapRecords[i] = ldapRecord{ fqdn: fqdn, - ip: net.ParseIP(searchResult.Entries[i].GetAttributeValue(l.Ip4Attr)), + ip4: net.ParseIP(searchResult.Entries[i].GetAttributeValue(l.Ip4Attr)), + ip6: net.ParseIP(searchResult.Entries[i].GetAttributeValue(l.Ip6Attr)), } }