From aa7b436c8a02f84805c7dba7c9cbe5f99e315b13 Mon Sep 17 00:00:00 2001 From: Semih Baskan Date: Fri, 20 Nov 2026 17:50:03 +0000 Subject: [PATCH 1/2] https-dns-proxy: keep an empty server backup on restart When the dnsmasq instance has no server entries, the first start stores a single empty doh_backup_server element. A second start without a stop in between (restart, reload, a config change from LuCI) gets an empty string from uci_get and treats that as no backup. It then copies the current server list, the canary entries and the proxy listeners, into doh_backup_server. The next stop restores them into the dnsmasq server list, so dnsmasq keeps forwarding to the stopped listeners and keeps answering the canary domains locally. Test whether doh_backup_server exists, as the restore side already does, so an empty backup stays empty. Add a test that creates the backup twice without a restore and checks that the restore leaves no server entries. Signed-off-by: Semih Baskan --- files/etc/init.d/https-dns-proxy | 2 +- tests/run_tests.sh | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/files/etc/init.d/https-dns-proxy b/files/etc/init.d/https-dns-proxy index 2f67194..b246562 100755 --- a/files/etc/init.d/https-dns-proxy +++ b/files/etc/init.d/https-dns-proxy @@ -559,7 +559,7 @@ dhcp_backup() { fi uci_set 'dhcp' "$cfg" 'noresolv' 1 fi - if [ -z "$(uci_get 'dhcp' "$cfg" 'doh_backup_server')" ]; then + if ! uci_get 'dhcp' "$cfg" 'doh_backup_server' >/dev/null 2>&1; then if [ -z "$(uci_get 'dhcp' "$cfg" 'server')" ]; then uci_add_list 'dhcp' "$cfg" 'doh_backup_server' "" fi diff --git a/tests/run_tests.sh b/tests/run_tests.sh index 9711ebf..8146b5e 100644 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -458,6 +458,20 @@ assert_rc "dhcp_backup restore: server 8.8.8.8 restored" 0 $? val="$(uci_get "dhcp" "cfg01" "doh_backup_server")" assert_eq "dhcp_backup restore: backup marker removed" "" "$val" +# Test: no servers originally, then a second create without a restore +# (reload or restart runs start_service again) +rm -f "$__uci_store"/* +uci_set "dhcp" "cfg01" ".type" "dnsmasq" +uci_set "dhcp" "cfg01" "port" "53" + +dhcp_backup 'create' +dnsmasq_doh_server "cfg01" 'add' '127.0.0.1' '5053' +dhcp_backup 'create' +dhcp_backup 'restore' + +val="$(uci_get "dhcp" "cfg01" "server")" +assert_eq "dhcp_backup restore: no DoH server left after a second create" "" "$val" + printf "\n##\n## 05: dhcp_backup with noresolv states\n##\n\n" # Test: noresolv was not set originally → backup stores -1 From 1d3a62db7694820a39da8494205f4b5d7aaf0ea2 Mon Sep 17 00:00:00 2001 From: Semih Baskan Date: Fri, 20 Nov 2026 17:50:31 +0000 Subject: [PATCH 2/2] https-dns-proxy: remove canary entries that were turned off The start adds the canary entries to the dnsmasq server list, but unlike the proxy listeners it does not record them in doh_server. The stop removes them only for the canary options that are on at that moment. When canary_domains_icloud or canary_domains_mozilla is turned off while the service runs, the next stop leaves those entries in place and dnsmasq keeps answering the canary domains locally. Record the canary entries in doh_server as well, like the listeners, so the stop removes everything the start added. The loop over the enabled canary domains on the remove side stays, for entries that older versions added. Add a test that turns the canary domains off between start and stop, with the user's own canary entry in the original server list, and checks that the stop leaves only that entry. Signed-off-by: Semih Baskan --- files/etc/init.d/https-dns-proxy | 1 + tests/run_tests.sh | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/files/etc/init.d/https-dns-proxy b/files/etc/init.d/https-dns-proxy index b246562..7d8ea6c 100755 --- a/files/etc/init.d/https-dns-proxy +++ b/files/etc/init.d/https-dns-proxy @@ -524,6 +524,7 @@ dnsmasq_doh_server() { if [ -n "$force_dns" ]; then for i in $canaryDomains; do uci_add_list_if_new 'dhcp' "$cfg" 'server' "/${i}/" + uci_add_list_if_new 'dhcp' "$cfg" 'doh_server' "/${i}/" done fi case $address in diff --git a/tests/run_tests.sh b/tests/run_tests.sh index 8146b5e..dadd5d1 100644 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -472,6 +472,23 @@ dhcp_backup 'restore' val="$(uci_get "dhcp" "cfg01" "server")" assert_eq "dhcp_backup restore: no DoH server left after a second create" "" "$val" +# Test: canary domains turned off between create and restore, with the +# user's own canary entry in the original server list +rm -f "$__uci_store"/* +uci_set "dhcp" "cfg01" ".type" "dnsmasq" +uci_set "dhcp" "cfg01" "server" "/use-application-dns.net/" +force_dns="1" +canaryDomains="mask.icloud.com use-application-dns.net" + +dhcp_backup 'create' +dnsmasq_doh_server "cfg01" 'add' '127.0.0.1' '5053' +canaryDomains="" +dhcp_backup 'restore' +force_dns="" + +val="$(uci_get "dhcp" "cfg01" "server")" +assert_eq "dhcp_backup restore: canary entries removed after canary domains were turned off, user's entry kept" "/use-application-dns.net/" "$val" + printf "\n##\n## 05: dhcp_backup with noresolv states\n##\n\n" # Test: noresolv was not set originally → backup stores -1