Keep a name that became static when Unbound restarts

The names of DHCP clients are removed from a new Unbound by name, which
also removed the record the configuration now publishes under it (a
client name that became a reservation). Forget what an earlier Unbound
had instead.
This commit is contained in:
2026-11-27 15:13:45 +01:00
parent b1d181a1dd
commit 7cf8cb62a2
2 changed files with 42 additions and 1 deletions
+20 -1
View File
@@ -204,6 +204,7 @@ func syncDynamic(ctl controller, published, want map[string]DynRecord, fresh boo
// dynStatus is what the daemon leaves for the web UI.
type dynStatus struct {
Pid string `json:"pid,omitempty"` // of the Unbound that has Published
Published []DynRecord `json:"published"`
Skipped []DynSkip `json:"skipped"`
Updated time.Time `json:"updated"`
@@ -264,6 +265,18 @@ func parseUnboundPID(status string) (string, error) {
return "", fmt.Errorf("no pid in unbound-control status")
}
// stillThere is what an earlier run published that the running Unbound still
// has: all of it if it is the same Unbound, nothing if it is a new one. A new
// Unbound has none of it, and removing it by name would remove what the
// configuration publishes under that name now (a client name that became a
// DHCP reservation: the restart that brought the reservation is this case).
func stillThere(published map[string]DynRecord, publishedPid, currentPid string) map[string]DynRecord {
if publishedPid != "" && publishedPid == currentPid {
return published
}
return map[string]DynRecord{}
}
// leasesDNS is `router-webui leases-dns`.
func leasesDNS(args []string) {
fs := flag.NewFlagSet("leases-dns", flag.ExitOnError)
@@ -286,7 +299,9 @@ func leasesDNS(args []string) {
// What a previous run published is removed first: the daemon may have
// been restarted while Unbound kept its data.
published := map[string]DynRecord{}
publishedPid := ""
if st, ok := readDynStatus(*run); ok {
publishedPid = st.Pid
for _, r := range st.Published {
published[r.Name] = r
}
@@ -302,6 +317,10 @@ func leasesDNS(args []string) {
} else {
if cur != pid {
fresh = true // a new Unbound has none of it
if pid != "" {
publishedPid = pid
}
published = stillThere(published, publishedPid, cur)
}
var now map[string]DynRecord
if now, err = syncDynamic(ctl, published, want, fresh); err == nil {
@@ -309,7 +328,7 @@ func leasesDNS(args []string) {
}
published = now
}
status := dynStatus{Published: recordsOf(published), Skipped: skipped, Updated: time.Now()}
status := dynStatus{Pid: pid, Published: recordsOf(published), Skipped: skipped, Updated: time.Now()}
if err != nil {
status.Error = err.Error()
if status.Error != lastErr {