resolved: notice route-only domain updates

SetLinkDomains() tracks whether the configured search domain list changed
so it can skip redundant persistence. The route_only flag is part of the
D-Bus API and is persisted as a ~ prefix, but flipping an existing domain
between search and route-only only updated in-memory state and left
changed false. The method then skipped link_save_user() and
manager_write_resolv_conf(), leaving stale state until restart.

Reproduced on Ubuntu with systemd 259:

  sudo resolvectl domain enp1s0 route-only-repro.test
  sudo resolvectl domain enp1s0 '~route-only-repro.test'
  resolvectl domain enp1s0
  grep '^DOMAINS=' /run/systemd/resolve/netif/$(cat /sys/class/net/enp1s0/ifindex)
  grep -H route-only-repro.test /run/systemd/resolve/*.conf

Before, resolvectl showed ~route-only-repro.test, but the persisted state
file still showed DOMAINS=route-only-repro.test, and the generated
resolv.conf files still contained search route-only-repro.test.

After this change, the state file is updated to
DOMAINS=~route-only-repro.test and the generated resolv.conf files are
refreshed so the route-only domain is not emitted as a search domain.

Follow-up for: cbf23f3853
This commit is contained in:
dongshengyuan
2026-08-12 18:51:34 +09:00
committed by Yu Watanabe
parent 40315add91
commit 628e8304cc
2 changed files with 14 additions and 1 deletions
+10
View File
@@ -280,6 +280,16 @@ manual_testcase_01_resolvectl() {
resolvectl domain hoge "hoge.example.com"
assert_in 'hoge.example.com' "$(resolvectl domain hoge)"
assert_not_in '~.' "$(resolvectl domain hoge)"
local hoge_state
hoge_state="/run/systemd/resolve/netif/$(cat /sys/class/net/hoge/ifindex)"
resolvectl domain hoge "route-only-change.example.com"
assert_in "DOMAINS=route-only-change.example.com" "$(cat "$hoge_state")"
assert_in "route-only-change.example.com" "$(cat /run/systemd/resolve/resolv.conf /run/systemd/resolve/stub-resolv.conf)"
resolvectl domain hoge "~route-only-change.example.com"
assert_in "DOMAINS=~route-only-change.example.com" "$(cat "$hoge_state")"
assert_not_in "route-only-change.example.com" "$(cat /run/systemd/resolve/resolv.conf /run/systemd/resolve/stub-resolv.conf)"
echo -e "nameserver 10.0.2.1\ndomain test-domain.example.com" | SYSTEMD_INVOKED_AS=resolvconf resolvectl -x -a hoge
assert_in 'test-domain.example.com' "$(resolvectl domain hoge)"
assert_in '~.' "$(resolvectl domain hoge)"