diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2024-04-15 09:16:13 +0200 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2024-04-19 03:23:00 +0200 |
commit | 9646ffe2cacb5dccf1fcb8bcc54bf0d315bd0000 (patch) | |
tree | 8cb84a36d2c02e1067f7adf45d7e2bd1a9bc2739 | |
parent | network: introduce link_get_use_domains() (diff) | |
download | systemd-9646ffe2cacb5dccf1fcb8bcc54bf0d315bd0000.tar.xz systemd-9646ffe2cacb5dccf1fcb8bcc54bf0d315bd0000.zip |
network: introduce link_get_use_dns()
No functional change, just refactoring.
-rw-r--r-- | src/network/networkd-dhcp-server.c | 2 | ||||
-rw-r--r-- | src/network/networkd-dhcp4.c | 2 | ||||
-rw-r--r-- | src/network/networkd-dhcp6.c | 2 | ||||
-rw-r--r-- | src/network/networkd-dns.c | 88 | ||||
-rw-r--r-- | src/network/networkd-dns.h | 1 | ||||
-rw-r--r-- | src/network/networkd-json.c | 6 | ||||
-rw-r--r-- | src/network/networkd-ndisc.c | 2 | ||||
-rw-r--r-- | src/network/networkd-network-gperf.gperf | 8 | ||||
-rw-r--r-- | src/network/networkd-network.c | 7 | ||||
-rw-r--r-- | src/network/networkd-network.h | 9 | ||||
-rw-r--r-- | src/network/networkd-state-file.c | 12 |
11 files changed, 63 insertions, 76 deletions
diff --git a/src/network/networkd-dhcp-server.c b/src/network/networkd-dhcp-server.c index b1953545ed..6b9dcd6fe6 100644 --- a/src/network/networkd-dhcp-server.c +++ b/src/network/networkd-dhcp-server.c @@ -342,7 +342,7 @@ static int link_push_uplink_to_dhcp_server( addresses[n_addresses++] = ia; } - use_dhcp_lease_data = link->network->dhcp_use_dns; + use_dhcp_lease_data = link_get_use_dns(link, NETWORK_CONFIG_SOURCE_DHCP4); break; case SD_DHCP_LEASE_NTP: { diff --git a/src/network/networkd-dhcp4.c b/src/network/networkd-dhcp4.c index 89622e6cfc..e02b9257f8 100644 --- a/src/network/networkd-dhcp4.c +++ b/src/network/networkd-dhcp4.c @@ -728,7 +728,7 @@ static int dhcp4_request_routes_to_dns(Link *link) { assert(link->dhcp_lease); assert(link->network); - if (!link->network->dhcp_use_dns || + if (!link_get_use_dns(link, NETWORK_CONFIG_SOURCE_DHCP4) || !link->network->dhcp_routes_to_dns) return 0; diff --git a/src/network/networkd-dhcp6.c b/src/network/networkd-dhcp6.c index bf7d3c7e8e..426d2de235 100644 --- a/src/network/networkd-dhcp6.c +++ b/src/network/networkd-dhcp6.c @@ -633,7 +633,7 @@ static int dhcp6_configure(Link *link) { return log_link_debug_errno(link, r, "DHCPv6 CLIENT: Failed to set MUD URL: %m"); } - if (link->network->dhcp6_use_dns) { + if (link_get_use_dns(link, NETWORK_CONFIG_SOURCE_DHCP6)) { r = sd_dhcp6_client_set_request_option(client, SD_DHCP6_OPTION_DNS_SERVER); if (r < 0) return log_link_debug_errno(link, r, "DHCPv6 CLIENT: Failed to request DNS servers: %m"); diff --git a/src/network/networkd-dns.c b/src/network/networkd-dns.c index eb01f4758e..150ce62482 100644 --- a/src/network/networkd-dns.c +++ b/src/network/networkd-dns.c @@ -53,6 +53,43 @@ UseDomains link_get_use_domains(Link *link, NetworkConfigSource proto) { return USE_DOMAINS_NO; } +bool link_get_use_dns(Link *link, NetworkConfigSource proto) { + int n, c; + + assert(link); + + if (!link->network) + return false; + + switch (proto) { + case NETWORK_CONFIG_SOURCE_DHCP4: + n = link->network->dhcp_use_dns; + c = link->network->compat_dhcp_use_dns; + break; + case NETWORK_CONFIG_SOURCE_DHCP6: + n = link->network->dhcp6_use_dns; + c = link->network->compat_dhcp_use_dns; + break; + case NETWORK_CONFIG_SOURCE_NDISC: + n = link->network->ndisc_use_dns; + c = -1; + break; + default: + assert_not_reached(); + } + + /* If per-network and per-protocol setting is specified, use it. */ + if (n >= 0) + return n; + + /* If compat setting is specified, use it. */ + if (c >= 0) + return c; + + /* Otherwise, defaults to yes. */ + return true; +} + int config_parse_domains( const char *unit, const char *filename, @@ -243,57 +280,6 @@ int config_parse_dnssec_negative_trust_anchors( } } -int config_parse_dhcp_use_dns( - const char* unit, - const char *filename, - unsigned line, - const char *section, - unsigned section_line, - const char *lvalue, - int ltype, - const char *rvalue, - void *data, - void *userdata) { - - Network *network = userdata; - int r; - - assert(filename); - assert(lvalue); - assert(IN_SET(ltype, AF_UNSPEC, AF_INET, AF_INET6)); - assert(rvalue); - assert(data); - - r = parse_boolean(rvalue); - if (r < 0) { - log_syntax(unit, LOG_WARNING, filename, line, r, - "Failed to parse UseDNS=%s, ignoring assignment: %m", rvalue); - return 0; - } - - switch (ltype) { - case AF_INET: - network->dhcp_use_dns = r; - network->dhcp_use_dns_set = true; - break; - case AF_INET6: - network->dhcp6_use_dns = r; - network->dhcp6_use_dns_set = true; - break; - case AF_UNSPEC: - /* For backward compatibility. */ - if (!network->dhcp_use_dns_set) - network->dhcp_use_dns = r; - if (!network->dhcp6_use_dns_set) - network->dhcp6_use_dns = r; - break; - default: - assert_not_reached(); - } - - return 0; -} - static const char* const use_domains_table[_USE_DOMAINS_MAX] = { [USE_DOMAINS_NO] = "no", [USE_DOMAINS_ROUTE] = "route", diff --git a/src/network/networkd-dns.h b/src/network/networkd-dns.h index c1b3429b8b..915cb32fb1 100644 --- a/src/network/networkd-dns.h +++ b/src/network/networkd-dns.h @@ -16,6 +16,7 @@ typedef enum UseDomains { } UseDomains; UseDomains link_get_use_domains(Link *link, NetworkConfigSource proto); +bool link_get_use_dns(Link *link, NetworkConfigSource proto); const char* use_domains_to_string(UseDomains p) _const_; UseDomains use_domains_from_string(const char *s) _pure_; diff --git a/src/network/networkd-json.c b/src/network/networkd-json.c index 4fd75f4bfe..d9eeaff122 100644 --- a/src/network/networkd-json.c +++ b/src/network/networkd-json.c @@ -448,7 +448,7 @@ static int dns_append_json(Link *link, JsonVariant **v) { return r; } - if (link->dhcp_lease && link->network->dhcp_use_dns) { + if (link->dhcp_lease && link_get_use_dns(link, NETWORK_CONFIG_SOURCE_DHCP4)) { const struct in_addr *dns; union in_addr_union s; int n_dns; @@ -469,7 +469,7 @@ static int dns_append_json(Link *link, JsonVariant **v) { } } - if (link->dhcp6_lease && link->network->dhcp6_use_dns) { + if (link->dhcp6_lease && link_get_use_dns(link, NETWORK_CONFIG_SOURCE_DHCP6)) { const struct in6_addr *dns; union in_addr_union s; int n_dns; @@ -490,7 +490,7 @@ static int dns_append_json(Link *link, JsonVariant **v) { } } - if (link->network->ndisc_use_dns) { + if (link_get_use_dns(link, NETWORK_CONFIG_SOURCE_NDISC)) { NDiscRDNSS *a; SET_FOREACH(a, link->ndisc_rdnss) { diff --git a/src/network/networkd-ndisc.c b/src/network/networkd-ndisc.c index c7d7fc7efc..92ff7c71f3 100644 --- a/src/network/networkd-ndisc.c +++ b/src/network/networkd-ndisc.c @@ -1409,7 +1409,7 @@ static int ndisc_router_process_rdnss(Link *link, sd_ndisc_router *rt) { assert(link->network); assert(rt); - if (!link->network->ndisc_use_dns) + if (!link_get_use_dns(link, NETWORK_CONFIG_SOURCE_NDISC)) return 0; r = sd_ndisc_router_get_sender_address(rt, &router); diff --git a/src/network/networkd-network-gperf.gperf b/src/network/networkd-network-gperf.gperf index ef60797f2e..f5a6debc0a 100644 --- a/src/network/networkd-network-gperf.gperf +++ b/src/network/networkd-network-gperf.gperf @@ -222,7 +222,7 @@ NextHop.Blackhole, config_parse_nexthop_blackhole, NextHop.Group, config_parse_nexthop_group, 0, 0 DHCPv4.RequestAddress, config_parse_in_addr_non_null, AF_INET, offsetof(Network, dhcp_request_address) DHCPv4.ClientIdentifier, config_parse_dhcp_client_identifier, 0, offsetof(Network, dhcp_client_identifier) -DHCPv4.UseDNS, config_parse_dhcp_use_dns, AF_INET, 0 +DHCPv4.UseDNS, config_parse_tristate, 0, offsetof(Network, dhcp_use_dns) DHCPv4.RoutesToDNS, config_parse_bool, 0, offsetof(Network, dhcp_routes_to_dns) DHCPv4.UseNTP, config_parse_dhcp_use_ntp, AF_INET, 0 DHCPv4.RoutesToNTP, config_parse_bool, 0, offsetof(Network, dhcp_routes_to_ntp) @@ -271,7 +271,7 @@ DHCPv4.NFTSet, config_parse_nft_set, DHCPv4.RapidCommit, config_parse_tristate, 0, offsetof(Network, dhcp_use_rapid_commit) DHCPv6.UseAddress, config_parse_bool, 0, offsetof(Network, dhcp6_use_address) DHCPv6.UseDelegatedPrefix, config_parse_bool, 0, offsetof(Network, dhcp6_use_pd_prefix) -DHCPv6.UseDNS, config_parse_dhcp_use_dns, AF_INET6, 0 +DHCPv6.UseDNS, config_parse_tristate, 0, offsetof(Network, dhcp6_use_dns) DHCPv6.UseHostname, config_parse_bool, 0, offsetof(Network, dhcp6_use_hostname) DHCPv6.UseDomains, config_parse_use_domains, 0, offsetof(Network, dhcp6_use_domains) DHCPv6.UseNTP, config_parse_dhcp_use_ntp, AF_INET6, 0 @@ -299,7 +299,7 @@ IPv6AcceptRA.UseRoutePrefix, config_parse_bool, IPv6AcceptRA.UseAutonomousPrefix, config_parse_bool, 0, offsetof(Network, ndisc_use_autonomous_prefix) IPv6AcceptRA.UseOnLinkPrefix, config_parse_bool, 0, offsetof(Network, ndisc_use_onlink_prefix) IPv6AcceptRA.UsePREF64, config_parse_bool, 0, offsetof(Network, ndisc_use_pref64) -IPv6AcceptRA.UseDNS, config_parse_bool, 0, offsetof(Network, ndisc_use_dns) +IPv6AcceptRA.UseDNS, config_parse_tristate, 0, offsetof(Network, ndisc_use_dns) IPv6AcceptRA.UseDomains, config_parse_use_domains, 0, offsetof(Network, ndisc_use_domains) IPv6AcceptRA.UseMTU, config_parse_bool, 0, offsetof(Network, ndisc_use_mtu) IPv6AcceptRA.UseHopLimit, config_parse_bool, 0, offsetof(Network, ndisc_use_hop_limit) @@ -588,7 +588,7 @@ IPv6PrefixDelegation.Domains, config_parse_radv_search_domains, IPv6PrefixDelegation.DNSLifetimeSec, config_parse_sec, 0, offsetof(Network, router_dns_lifetime_usec) DHCPv4.BlackList, config_parse_in_addr_prefixes, AF_INET, offsetof(Network, dhcp_deny_listed_ip) DHCP.ClientIdentifier, config_parse_dhcp_client_identifier, 0, offsetof(Network, dhcp_client_identifier) -DHCP.UseDNS, config_parse_dhcp_use_dns, AF_UNSPEC, 0 +DHCP.UseDNS, config_parse_tristate, 0, offsetof(Network, compat_dhcp_use_dns) DHCP.UseNTP, config_parse_dhcp_use_ntp, AF_UNSPEC, 0 DHCP.UseMTU, config_parse_bool, 0, offsetof(Network, dhcp_use_mtu) DHCP.UseHostname, config_parse_bool, 0, offsetof(Network, dhcp_use_hostname) diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c index f270142d55..979d770f68 100644 --- a/src/network/networkd-network.c +++ b/src/network/networkd-network.c @@ -381,6 +381,7 @@ int network_load_one(Manager *manager, OrderedHashmap **networks, const char *fi .keep_configuration = manager->keep_configuration, .compat_dhcp_use_domains = _USE_DOMAINS_INVALID, + .compat_dhcp_use_dns = -1, .dhcp_duid.type = _DUID_TYPE_INVALID, .dhcp_critical = -1, @@ -388,7 +389,7 @@ int network_load_one(Manager *manager, OrderedHashmap **networks, const char *fi .dhcp_routes_to_ntp = true, .dhcp_use_sip = true, .dhcp_use_captive_portal = true, - .dhcp_use_dns = true, + .dhcp_use_dns = -1, .dhcp_routes_to_dns = true, .dhcp_use_domains = _USE_DOMAINS_INVALID, .dhcp_use_hostname = true, @@ -406,7 +407,7 @@ int network_load_one(Manager *manager, OrderedHashmap **networks, const char *fi .dhcp6_use_address = true, .dhcp6_use_pd_prefix = true, - .dhcp6_use_dns = true, + .dhcp6_use_dns = -1, .dhcp6_use_domains = _USE_DOMAINS_INVALID, .dhcp6_use_hostname = true, .dhcp6_use_ntp = true, @@ -480,7 +481,7 @@ int network_load_one(Manager *manager, OrderedHashmap **networks, const char *fi .ndisc = -1, .ndisc_use_redirect = true, - .ndisc_use_dns = true, + .ndisc_use_dns = -1, .ndisc_use_gateway = true, .ndisc_use_captive_portal = true, .ndisc_use_route_prefix = true, diff --git a/src/network/networkd-network.h b/src/network/networkd-network.h index 6fc2eddf00..0f1621d831 100644 --- a/src/network/networkd-network.h +++ b/src/network/networkd-network.h @@ -115,6 +115,7 @@ struct Network { /* For backward compatibility, only applied to DHCPv4 and DHCPv6. */ UseDomains compat_dhcp_use_domains; + int compat_dhcp_use_dns; /* DHCP Client Support */ AddressFamily dhcp; @@ -147,8 +148,7 @@ struct Network { int dhcp_broadcast; int dhcp_ipv6_only_mode; int dhcp_use_rapid_commit; - bool dhcp_use_dns; - bool dhcp_use_dns_set; + int dhcp_use_dns; bool dhcp_routes_to_dns; bool dhcp_use_ntp; bool dhcp_use_ntp_set; @@ -180,8 +180,7 @@ struct Network { bool dhcp6_use_pd_prefix; bool dhcp6_send_hostname; bool dhcp6_send_hostname_set; - bool dhcp6_use_dns; - bool dhcp6_use_dns_set; + int dhcp6_use_dns; bool dhcp6_use_hostname; bool dhcp6_use_ntp; bool dhcp6_use_ntp_set; @@ -340,7 +339,7 @@ struct Network { /* NDisc support */ int ndisc; bool ndisc_use_redirect; - bool ndisc_use_dns; + int ndisc_use_dns; bool ndisc_use_gateway; bool ndisc_use_route_prefix; bool ndisc_use_autonomous_prefix; diff --git a/src/network/networkd-state-file.c b/src/network/networkd-state-file.c index 182b985cac..b217b9cc44 100644 --- a/src/network/networkd-state-file.c +++ b/src/network/networkd-state-file.c @@ -101,7 +101,7 @@ static int link_put_dns(Link *link, OrderedSet **s) { if (r < 0) return r; - if (link->dhcp_lease && link->network->dhcp_use_dns) { + if (link->dhcp_lease && link_get_use_dns(link, NETWORK_CONFIG_SOURCE_DHCP4)) { const struct in_addr *addresses; r = sd_dhcp_lease_get_dns(link->dhcp_lease, &addresses); @@ -112,7 +112,7 @@ static int link_put_dns(Link *link, OrderedSet **s) { } } - if (link->dhcp6_lease && link->network->dhcp6_use_dns) { + if (link->dhcp6_lease && link_get_use_dns(link, NETWORK_CONFIG_SOURCE_DHCP6)) { const struct in6_addr *addresses; r = sd_dhcp6_lease_get_dns(link->dhcp6_lease, &addresses); @@ -123,7 +123,7 @@ static int link_put_dns(Link *link, OrderedSet **s) { } } - if (link->network->ndisc_use_dns) { + if (link_get_use_dns(link, NETWORK_CONFIG_SOURCE_NDISC)) { NDiscRDNSS *a; SET_FOREACH(a, link->ndisc_rdnss) { @@ -666,14 +666,14 @@ static int link_save(Link *link) { serialize_addresses(f, NULL, &space, NULL, link->dhcp_lease, - link->network->dhcp_use_dns, + link_get_use_dns(link, NETWORK_CONFIG_SOURCE_DHCP4), SD_DHCP_LEASE_DNS, link->dhcp6_lease, - link->network->dhcp6_use_dns, + link_get_use_dns(link, NETWORK_CONFIG_SOURCE_DHCP6), sd_dhcp6_lease_get_dns, NULL); - if (link->network->ndisc_use_dns) { + if (link_get_use_dns(link, NETWORK_CONFIG_SOURCE_NDISC)) { NDiscRDNSS *dd; SET_FOREACH(dd, link->ndisc_rdnss) |