Add support for AAAA records
This commit is contained in:
parent
56c09edd37
commit
0a22b62ef0
11
ldap.go
11
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
|
||||
|
7
setup.go
7
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())
|
||||
}
|
||||
|
4
sync.go
4
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)),
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user