Reverse zones made easy: suggested, filled, in the right view, PTRs kept in step
Missing reverse zones are suggested for the private views' A and AAAA records (/24 for private IPv4, /32 for a public address, /48 for IPv6) and created filled with PTR records (jarl zone suggest-reverse, the Zones page). zone create --fill and zone fill-ptr add the PTRs a reverse zone lacks; a reverse zone created without a view goes to the private view using its addresses. Per zone, auto_ptr keeps the PTR records of A and AAAA records in step on every change (database version 12). Zone commands take a network. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a3b054cc86
commit
aa4b004a14
27 files changed
+1173
-38
No files matched your search
@@ -469,3 +469,47 @@ func BestZone(name string, zones []string) string {
|
||||
}
|
||||
return best
|
||||
}
|
||||
|
||||
// PrefixFromReverse returns the network a reverse zone answers for:
|
||||
// 10.0.10.in-addr.arpa. is 10.0.10.0/24, a /32 zone a single address, and
|
||||
// an ip6.arpa zone of 12 nibbles a /48. False for names that aren't whole
|
||||
// octets or nibbles (classless delegations such as 0-63.1.0.10.in-addr.arpa.).
|
||||
func PrefixFromReverse(zone string) (netip.Prefix, bool) {
|
||||
zone = strings.ToLower(Fqdn(zone))
|
||||
switch {
|
||||
case strings.HasSuffix(zone, ".in-addr.arpa."):
|
||||
labels := strings.Split(strings.TrimSuffix(zone, ".in-addr.arpa."), ".")
|
||||
if len(labels) > 4 {
|
||||
return netip.Prefix{}, false
|
||||
}
|
||||
var b [4]byte
|
||||
for i, l := range labels {
|
||||
v, err := strconv.Atoi(l)
|
||||
if err != nil || v < 0 || v > 255 || strconv.Itoa(v) != l {
|
||||
return netip.Prefix{}, false
|
||||
}
|
||||
b[len(labels)-1-i] = byte(v)
|
||||
}
|
||||
return netip.PrefixFrom(netip.AddrFrom4(b), 8*len(labels)), true
|
||||
case strings.HasSuffix(zone, ".ip6.arpa."):
|
||||
labels := strings.Split(strings.TrimSuffix(zone, ".ip6.arpa."), ".")
|
||||
if len(labels) > 32 {
|
||||
return netip.Prefix{}, false
|
||||
}
|
||||
var b [16]byte
|
||||
for i, l := range labels {
|
||||
v := strings.IndexByte("0123456789abcdef", l[0])
|
||||
if len(l) != 1 || v < 0 {
|
||||
return netip.Prefix{}, false
|
||||
}
|
||||
n := len(labels) - 1 - i // nibble position from the left
|
||||
if n%2 == 0 {
|
||||
b[n/2] |= byte(v) << 4
|
||||
} else {
|
||||
b[n/2] |= byte(v)
|
||||
}
|
||||
}
|
||||
return netip.PrefixFrom(netip.AddrFrom16(b), 4*len(labels)), true
|
||||
}
|
||||
return netip.Prefix{}, false
|
||||
}
|
||||
Reference in new issue
Block a user