2 Commits
Author SHA1 Message Date
nils 2aa70630d4 Release 0.13.8 2026-11-27 15:13:45 +01:00
nils 7cf8cb62a2 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.
2026-11-27 15:13:45 +01:00
3 changed files with 43 additions and 2 deletions
+1 -1
View File
@@ -1 +1 @@
0.13.7 0.13.8
+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. // dynStatus is what the daemon leaves for the web UI.
type dynStatus struct { type dynStatus struct {
Pid string `json:"pid,omitempty"` // of the Unbound that has Published
Published []DynRecord `json:"published"` Published []DynRecord `json:"published"`
Skipped []DynSkip `json:"skipped"` Skipped []DynSkip `json:"skipped"`
Updated time.Time `json:"updated"` Updated time.Time `json:"updated"`
@@ -264,6 +265,18 @@ func parseUnboundPID(status string) (string, error) {
return "", fmt.Errorf("no pid in unbound-control status") 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`. // leasesDNS is `router-webui leases-dns`.
func leasesDNS(args []string) { func leasesDNS(args []string) {
fs := flag.NewFlagSet("leases-dns", flag.ExitOnError) 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 // What a previous run published is removed first: the daemon may have
// been restarted while Unbound kept its data. // been restarted while Unbound kept its data.
published := map[string]DynRecord{} published := map[string]DynRecord{}
publishedPid := ""
if st, ok := readDynStatus(*run); ok { if st, ok := readDynStatus(*run); ok {
publishedPid = st.Pid
for _, r := range st.Published { for _, r := range st.Published {
published[r.Name] = r published[r.Name] = r
} }
@@ -302,6 +317,10 @@ func leasesDNS(args []string) {
} else { } else {
if cur != pid { if cur != pid {
fresh = true // a new Unbound has none of it fresh = true // a new Unbound has none of it
if pid != "" {
publishedPid = pid
}
published = stillThere(published, publishedPid, cur)
} }
var now map[string]DynRecord var now map[string]DynRecord
if now, err = syncDynamic(ctl, published, want, fresh); err == nil { if now, err = syncDynamic(ctl, published, want, fresh); err == nil {
@@ -309,7 +328,7 @@ func leasesDNS(args []string) {
} }
published = now 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 { if err != nil {
status.Error = err.Error() status.Error = err.Error()
if status.Error != lastErr { if status.Error != lastErr {
+22
View File
@@ -150,6 +150,28 @@ func TestSyncDynamic(t *testing.T) {
} }
} }
// A client name that became a DHCP reservation: the restart that brought the
// reservation must not remove the configuration's record by removing what an
// earlier Unbound was given.
func TestNewUnboundForgetsWhatTheOldOneHad(t *testing.T) {
hv1 := DynRecord{Name: "hv1.home.example.org", Address: "192.168.1.21"}
old := map[string]DynRecord{hv1.Name: hv1}
if got := stillThere(old, "100", "200"); len(got) != 0 {
t.Errorf("a new Unbound still has %v", got)
}
if got := stillThere(old, "", "200"); len(got) != 0 {
t.Errorf("an unknown Unbound still has %v", got)
}
if got := stillThere(old, "200", "200"); len(got) != 1 {
t.Errorf("the same Unbound lost %v", got)
}
// So the fresh sync sends nothing for it: the static record stays.
ctl := &fakeCtl{}
if _, err := syncDynamic(ctl, stillThere(old, "100", "200"), nil, true); err != nil || len(ctl.cmds) != 0 {
t.Errorf("removed after a restart: %v %v", ctl.cmds, err)
}
}
func TestParseUnboundPID(t *testing.T) { func TestParseUnboundPID(t *testing.T) {
out := "version: 1.26.1\nverbosity: 1\nthreads: 1\nuptime: 0 seconds\nunbound (pid 1458081) is running...\n" out := "version: 1.26.1\nverbosity: 1\nthreads: 1\nuptime: 0 seconds\nunbound (pid 1458081) is running...\n"
if pid, err := parseUnboundPID(out); err != nil || pid != "1458081" { if pid, err := parseUnboundPID(out); err != nil || pid != "1458081" {