diff --git a/clients/networkmanager/iputils.cpp b/clients/networkmanager/iputils.cpp index bac6729..257a272 100644 --- a/clients/networkmanager/iputils.cpp +++ b/clients/networkmanager/iputils.cpp @@ -197,8 +197,11 @@ Form form(const Settings& settings) } } - // The switch stands for both families; IPv4's decides when they differ. - form.automaticDns = !toBool(value(group(settings, ipv4Setting), "ignore-auto-dns")); + // The switch stands for both families; IPv4's decides when they differ, + // unless IPv4 takes no name servers and so keeps a value nothing writes. + const std::string& dnsFamily = + configurable(form.ipv4Method) || !configurable(form.ipv6Method) ? ipv4Setting : ipv6Setting; + form.automaticDns = !toBool(value(group(settings, dnsFamily), "ignore-auto-dns")); form.dns = text::join(dnsServers(settings), ", "); return form; } diff --git a/clients/networkmanager/tests/iputils_test.cpp b/clients/networkmanager/tests/iputils_test.cpp index 06dd222..652bc0c 100644 --- a/clients/networkmanager/tests/iputils_test.cpp +++ b/clients/networkmanager/tests/iputils_test.cpp @@ -264,6 +264,30 @@ TEST(IpUtils, WritesNameServers) EXPECT_FALSE(toBool(value(cleared->at("ipv4"), "ignore-auto-dns"))); } +TEST(IpUtils, AutomaticDnsOfAnIpv6OnlyProfile) +{ + Settings existing = automaticProfile(); + existing["ipv4"] = {{"method", Variant(std::string("disabled"))}}; + ip::Form form = ip::form(existing); + EXPECT_TRUE(form.automaticDns); + form.automaticDns = false; + form.dns = "2606:4700::1111"; + + bool changed = false; + std::string error; + const auto profile = ip::settings(form, existing, &changed, &error); + ASSERT_TRUE(profile) << error; + EXPECT_TRUE(toBool(value(profile->at("ipv6"), "ignore-auto-dns"))); + + // Read back, the switch is off as saved, and another server keeps it off. + form = ip::form(*profile); + EXPECT_FALSE(form.automaticDns); + form.dns = "2001:4860:4860::8888"; + const auto edited = ip::settings(form, *profile, &changed, &error); + ASSERT_TRUE(edited) << error; + EXPECT_TRUE(toBool(value(edited->at("ipv6"), "ignore-auto-dns"))); +} + TEST(IpUtils, WritesDnsDataWhereItCameFrom) { Settings existing = automaticProfile();