Reverse zones: name hosts from other views' records; search and bulk dismiss for long lists
A reverse zone's fill (and fill-ptr, the missing-PTR counts) names an address no record of its own view uses from another view's record, so an internal reverse zone can give the PTR of a host only external has an AAAA for; New reverse zone with a view chosen lists those addresses, marked. Automatic suggestions stay per view. For hundreds of addresses: the New reverse zone list has a search; on the Zones page the public addresses fold away, have a search, show 25 at a time and Dismiss these N dismisses everything a search found in one change (reverse.dismiss takes prefixes; --dismiss takes several). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
304c89dba4
commit
bfab83da6e
11 files changed
+239
-41
No files matched your search
+79
-16
@@ -21,6 +21,7 @@ type addrUse struct {
|
||||
addr netip.Addr
|
||||
name string // the owner name, absolute
|
||||
apex bool
|
||||
view string // another view's record (fillAddresses), else ""
|
||||
}
|
||||
|
||||
// forwardAddresses returns the addresses of the enabled A and AAAA
|
||||
@@ -46,19 +47,51 @@ func forwardAddresses(st *model.State, viewID int64) []addrUse {
|
||||
return out
|
||||
}
|
||||
|
||||
// fillAddresses returns a view's addresses (forwardAddresses), then those
|
||||
// of the other views' records that none of its own records use, marked
|
||||
// with their view: a reverse zone in the internal view can name a host
|
||||
// only the external view has a record for.
|
||||
func fillAddresses(st *model.State, viewID int64) []addrUse {
|
||||
out := forwardAddresses(st, viewID)
|
||||
if len(st.Views) == 0 {
|
||||
return out
|
||||
}
|
||||
own := map[netip.Addr]bool{}
|
||||
for _, u := range out {
|
||||
own[u.addr] = true
|
||||
}
|
||||
for _, v := range st.OrderedViews() {
|
||||
if v.ID == viewID {
|
||||
continue
|
||||
}
|
||||
for _, u := range forwardAddresses(st, v.ID) {
|
||||
if !own[u.addr] {
|
||||
u.view = v.Name
|
||||
out = append(out, u)
|
||||
}
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// PTRFill is a PTR record filling a reverse zone would add.
|
||||
type PTRFill struct {
|
||||
Address string `json:"address"`
|
||||
Name string `json:"name"` // the PTR owner name
|
||||
Target string `json:"target"` // the host name it gives
|
||||
Others []string `json:"others,omitempty"` // other names with this address
|
||||
// From is the view whose record names the host, when the zone's own
|
||||
// view has none for the address.
|
||||
From string `json:"from,omitempty"`
|
||||
}
|
||||
|
||||
// PTRFills returns the PTR records a reverse zone named zoneName in a view
|
||||
// lacks for the addresses of the view's A and AAAA records: one per
|
||||
// address, naming its mail or name server host when it is one, otherwise
|
||||
// a host rather than the domain itself, then the shortest name.
|
||||
// existing are the zone's records (none for a new zone).
|
||||
// a host rather than the domain itself, then the shortest name. An
|
||||
// address no record of the view uses is named from another view's
|
||||
// records (fillAddresses), marked From. existing are the zone's records
|
||||
// (none for a new zone).
|
||||
func PTRFills(st *model.State, viewID int64, zoneName string, existing []*model.Record) []PTRFill {
|
||||
prefix, ok := dnsname.PrefixFromReverse(zoneName)
|
||||
if !ok {
|
||||
@@ -73,7 +106,7 @@ func PTRFills(st *model.State, viewID int64, zoneName string, existing []*model.
|
||||
servers := serverNames(st, viewID)
|
||||
byAddr := map[netip.Addr][]addrUse{}
|
||||
var order []netip.Addr
|
||||
for _, u := range forwardAddresses(st, viewID) {
|
||||
for _, u := range fillAddresses(st, viewID) {
|
||||
if !prefix.Contains(u.addr) {
|
||||
continue
|
||||
}
|
||||
@@ -110,9 +143,11 @@ func PTRFills(st *model.State, viewID int64, zoneName string, existing []*model.
|
||||
}
|
||||
return strings.Compare(x.name, y.name)
|
||||
})
|
||||
f := PTRFill{Address: a.String(), Name: owner, Target: uses[0].name}
|
||||
f := PTRFill{Address: a.String(), Name: owner, Target: uses[0].name, From: uses[0].view}
|
||||
for _, u := range uses[1:] {
|
||||
f.Others = append(f.Others, u.name)
|
||||
if u.name != f.Target {
|
||||
f.Others = append(f.Others, u.name)
|
||||
}
|
||||
}
|
||||
out = append(out, f)
|
||||
}
|
||||
@@ -143,6 +178,9 @@ func serverNames(st *model.State, viewID int64) map[string]bool {
|
||||
func fillWarnings(fills []PTRFill) []string {
|
||||
var out []string
|
||||
for _, f := range fills {
|
||||
if f.From != "" {
|
||||
out = append(out, fmt.Sprintf("%s: only view %s has a record for it, so its PTR record gives %s from there", f.Address, f.From, dnsname.Display(f.Target)))
|
||||
}
|
||||
if len(f.Others) > 0 {
|
||||
out = append(out, fmt.Sprintf("%s has several names: its PTR record gives %s (not %s); change it if you prefer another", f.Address, dnsname.Display(f.Target), strings.Join(displayAll(f.Others), ", ")))
|
||||
}
|
||||
@@ -296,7 +334,9 @@ type ReverseOptions struct {
|
||||
// All includes what isn't suggested unasked, marked Hidden: public
|
||||
// views, views with suggestions off, dismissed networks.
|
||||
All bool
|
||||
// View narrows it to one view (by name; "" all).
|
||||
// View narrows it to one view (by name; "" all). With All, the view
|
||||
// also gets the addresses only other views' records use, marked
|
||||
// Hidden "records in VIEW": a reverse zone there can name them.
|
||||
View string
|
||||
}
|
||||
|
||||
@@ -340,7 +380,11 @@ func ReverseCandidates(st *model.State, exposures []validate.Exposure, local []n
|
||||
out := []ReverseSuggestion{}
|
||||
for _, sc := range scopes {
|
||||
seen := map[netip.Prefix]bool{}
|
||||
for _, u := range forwardAddresses(st, sc.id) {
|
||||
addrs := forwardAddresses(st, sc.id)
|
||||
if opt.All && opt.View != "" {
|
||||
addrs = fillAddresses(st, sc.id)
|
||||
}
|
||||
for _, u := range addrs {
|
||||
a := u.addr
|
||||
if a.IsLoopback() || a.IsLinkLocalUnicast() || a.IsUnspecified() || a.IsMulticast() {
|
||||
continue
|
||||
@@ -350,6 +394,9 @@ func ReverseCandidates(st *model.State, exposures []validate.Exposure, local []n
|
||||
}
|
||||
p, group, why := suggestedPrefix(a, local)
|
||||
hidden := sc.hidden
|
||||
if hidden == "" && u.view != "" {
|
||||
hidden = "records in " + u.view
|
||||
}
|
||||
if seen[p] {
|
||||
continue
|
||||
}
|
||||
@@ -424,11 +471,23 @@ func (x *expander) reverseDismiss(req Request, dismiss bool) ([]model.Op, error)
|
||||
if err := decode(req.Data, &in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
p, err := netip.ParsePrefix(strings.TrimSpace(in.Prefix))
|
||||
if err != nil {
|
||||
return nil, errf(KindBadRequest, "prefix: %v", err)
|
||||
raw := in.Prefixes
|
||||
if in.Prefix != "" {
|
||||
raw = append(raw, in.Prefix)
|
||||
}
|
||||
if len(raw) == 0 {
|
||||
return nil, errf(KindBadRequest, "give the network (prefix) of the suggestion")
|
||||
}
|
||||
var prefixes []string
|
||||
for _, r := range raw {
|
||||
p, err := netip.ParsePrefix(strings.TrimSpace(r))
|
||||
if err != nil {
|
||||
return nil, errf(KindBadRequest, "prefix: %v", err)
|
||||
}
|
||||
if s := p.Masked().String(); !slices.Contains(prefixes, s) {
|
||||
prefixes = append(prefixes, s)
|
||||
}
|
||||
}
|
||||
p = p.Masked()
|
||||
var v *model.View
|
||||
switch {
|
||||
case in.ViewID != 0:
|
||||
@@ -446,16 +505,20 @@ func (x *expander) reverseDismiss(req Request, dismiss bool) ([]model.Op, error)
|
||||
if v != nil {
|
||||
list, where = v.DismissedReverse, "view "+v.Name
|
||||
}
|
||||
out := slices.DeleteFunc(slices.Clone(list), func(s string) bool { return s == p.String() })
|
||||
summary := "dismiss the reverse zone suggestion for " + p.String() + " in " + where
|
||||
out := slices.DeleteFunc(slices.Clone(list), func(s string) bool { return slices.Contains(prefixes, s) })
|
||||
what := prefixes[0]
|
||||
if len(prefixes) > 1 {
|
||||
what = fmt.Sprintf("%d networks (%s, …)", len(prefixes), prefixes[0])
|
||||
}
|
||||
summary := "dismiss the reverse zone suggestion for " + what + " in " + where
|
||||
if dismiss {
|
||||
out = append(out, p.String())
|
||||
out = append(out, prefixes...)
|
||||
slices.Sort(out)
|
||||
} else {
|
||||
if len(out) == len(list) {
|
||||
return nil, errf(KindConflict, "%s isn't dismissed in %s", p, where)
|
||||
return nil, errf(KindConflict, "%s isn't dismissed in %s", what, where)
|
||||
}
|
||||
summary = "suggest a reverse zone for " + p.String() + " in " + where + " again"
|
||||
summary = "suggest a reverse zone for " + what + " in " + where + " again"
|
||||
}
|
||||
if out == nil {
|
||||
out = []string{}
|
||||
|
||||
Reference in new issue
Block a user