From 418f2dc75564330d4ff6c86193f4a3c8ffbb1f1b Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Mon, 15 Apr 2024 14:55:18 +0900 Subject: [PATCH] network: introduce network- and protocol-independent default for UseDomains= Follow-up for fb573007430ab0dbe45517b58837d2fa5cfa1a48. Prompted by #32273. --- man/networkd.conf.xml | 52 +++++++++++++++++++----- man/systemd.network.xml | 23 +++++++++-- src/network/networkd-dns.c | 10 +++-- src/network/networkd-gperf.gperf | 2 + src/network/networkd-manager.c | 1 + src/network/networkd-manager.h | 2 + src/network/networkd-network-gperf.gperf | 1 + src/network/networkd-network.c | 3 ++ src/network/networkd-network.h | 3 ++ src/network/networkd.conf | 8 +++- 10 files changed, 87 insertions(+), 18 deletions(-) diff --git a/man/networkd.conf.xml b/man/networkd.conf.xml index 8820fcc507..843636fd4f 100644 --- a/man/networkd.conf.xml +++ b/man/networkd.conf.xml @@ -159,6 +159,43 @@ + + + UseDomains= + + Specifies the network- and protocol-independent default value for the same settins in + [IPv6AcceptRA], [DHCPv4], and [DHCPv6] sections below. Takes a boolean, or the special value + . See the same setting in + systemd.network5. + Defaults to no. + + + + + + + + + [IPv6AcceptRA] Section Options + + This section configures the default setting of the Neighbor Discovery. The following options are + available in the [IPv6AcceptRA] section: + + + + UseDomains= + + Specifies the network-independent default value for the same setting in the [IPv6AcceptRA] + section in + systemd.network5. + Takes a boolean, or the special value . When unspecified, the value specified + in the [Network] section in + networkd.conf5, + which defaults to no, will be used. + + + + @@ -260,11 +297,9 @@ DUIDRawData=00:00:ab:11:f9:2a:c2:77:29:f9:5c:00 UseDomains= - Specifies the default value for per-network UseDomains=. - Takes a boolean. See for details in - systemd.network5. - Defaults to no. - + + Same as the one in the [IPv6AcceptRA] section, but applied for DHCPv4 protocol. + @@ -310,12 +345,9 @@ DUIDRawData=00:00:ab:11:f9:2a:c2:77:29:f9:5c:00 - PersistLeases= + UseDomains= - Specifies the default value for per-network PersistLeases=. - Takes a boolean. See for details in - systemd.network5. - Defaults to yes. + Same as the one in the [IPv6AcceptRA] section, but applied for DHCPv4 protocol. diff --git a/man/systemd.network.xml b/man/systemd.network.xml index 5e8361f69a..916eb5bffe 100644 --- a/man/systemd.network.xml +++ b/man/systemd.network.xml @@ -747,6 +747,17 @@ Table=1234 + + UseDomains= + + Specifies the protocol-independent default value for the same settins in + [IPv6AcceptRA], [DHCPv4], and [DHCPv6] sections below. Takes a boolean, or the special value + . See also the same setting in [DHCPv4] below. Defaults to unset. + + + + + Domains= @@ -2571,9 +2582,15 @@ NFTSet=prefix:netdev:filter:eth_ipv4_prefix effect of the setting. If set to , the domain name received from the DHCP server will be used for routing DNS queries only, but not for searching, similarly to the effect of the setting when the argument is prefixed with - ~. When unspecified, the value specified in the same setting in - networkd.conf5, - which defaults to no, will be used. + ~. + + When unspecified, the value specified in the same setting in the [Network] section will be + used. When it is unspecified, the value specified in the same setting in the [DHCPv4] section in + networkd.conf5 + will be used. When it is unspecified, the value specified in the same setting in the [Network] + section in + networkd.conf5 + will be used. When none of them are specified, defaults to no. It is recommended to enable this option only on trusted networks, as setting this affects resolution of all hostnames, in particular of single-label names. It is generally diff --git a/src/network/networkd-dns.c b/src/network/networkd-dns.c index 150ce62482..7078419d37 100644 --- a/src/network/networkd-dns.c +++ b/src/network/networkd-dns.c @@ -31,7 +31,7 @@ UseDomains link_get_use_domains(Link *link, NetworkConfigSource proto) { case NETWORK_CONFIG_SOURCE_NDISC: n = link->network->ndisc_use_domains; c = _USE_DOMAINS_INVALID; - m = _USE_DOMAINS_INVALID; + m = link->manager->ndisc_use_domains; break; default: assert_not_reached(); @@ -45,12 +45,16 @@ UseDomains link_get_use_domains(Link *link, NetworkConfigSource proto) { if (c >= 0) return c; + /* If per-network but protocol-independent setting is specified, use it. */ + if (link->network->use_domains >= 0) + return link->network->use_domains; + /* If global per-protocol setting is specified, use it. */ if (m >= 0) return m; - /* Otherwise, defaults to no. */ - return USE_DOMAINS_NO; + /* If none of them are specified, use the global protocol-independent value. */ + return link->manager->use_domains; } bool link_get_use_dns(Link *link, NetworkConfigSource proto) { diff --git a/src/network/networkd-gperf.gperf b/src/network/networkd-gperf.gperf index b2d116e98d..f02dfd7a05 100644 --- a/src/network/networkd-gperf.gperf +++ b/src/network/networkd-gperf.gperf @@ -31,6 +31,8 @@ Network.RouteTable, config_parse_route_table_names, Network.IPv4Forwarding, config_parse_tristate, 0, offsetof(Manager, ip_forwarding[0]) Network.IPv6Forwarding, config_parse_tristate, 0, offsetof(Manager, ip_forwarding[1]) Network.IPv6PrivacyExtensions, config_parse_ipv6_privacy_extensions, 0, offsetof(Manager, ipv6_privacy_extensions) +Network.UseDomains, config_parse_use_domains, 0, offsetof(Manager, use_domains) +IPv6AcceptRA.UseDomains, config_parse_use_domains, 0, offsetof(Manager, ndisc_use_domains) DHCPv4.UseDomains, config_parse_use_domains, 0, offsetof(Manager, dhcp_use_domains) DHCPv4.DUIDType, config_parse_duid_type, 0, offsetof(Manager, dhcp_duid) DHCPv4.DUIDRawData, config_parse_duid_rawdata, 0, offsetof(Manager, dhcp_duid) diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c index 2d21c2bca5..4ec4550caf 100644 --- a/src/network/networkd-manager.c +++ b/src/network/networkd-manager.c @@ -601,6 +601,7 @@ int manager_new(Manager **ret, bool test_mode) { .persistent_storage_fd = persistent_storage_open(), .dhcp_use_domains = _USE_DOMAINS_INVALID, .dhcp6_use_domains = _USE_DOMAINS_INVALID, + .ndisc_use_domains = _USE_DOMAINS_INVALID, .dhcp_duid.type = DUID_TYPE_EN, .dhcp6_duid.type = DUID_TYPE_EN, .duid_product_uuid.type = DUID_TYPE_UUID, diff --git a/src/network/networkd-manager.h b/src/network/networkd-manager.h index 31ddbdf617..c14a98fb97 100644 --- a/src/network/networkd-manager.h +++ b/src/network/networkd-manager.h @@ -64,8 +64,10 @@ struct Manager { OrderedSet *address_pools; Set *dhcp_pd_subnet_ids; + UseDomains use_domains; /* default for all protocols */ UseDomains dhcp_use_domains; UseDomains dhcp6_use_domains; + UseDomains ndisc_use_domains; DUID dhcp_duid; DUID dhcp6_duid; diff --git a/src/network/networkd-network-gperf.gperf b/src/network/networkd-network-gperf.gperf index 7084f82f9f..62f11c5c5c 100644 --- a/src/network/networkd-network-gperf.gperf +++ b/src/network/networkd-network-gperf.gperf @@ -118,6 +118,7 @@ Network.EmitLLDP, config_parse_lldp_multicast_mode, Network.Address, config_parse_address, 0, 0 Network.Gateway, config_parse_gateway, 0, 0 Network.Domains, config_parse_domains, 0, 0 +Network.UseDomains, config_parse_use_domains, 0, offsetof(Network, use_domains) Network.DNS, config_parse_dns, 0, 0 Network.DNSDefaultRoute, config_parse_tristate, 0, offsetof(Network, dns_default_route) Network.LLMNR, config_parse_resolve_support, 0, offsetof(Network, llmnr) diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c index 15d5721866..c64091c15a 100644 --- a/src/network/networkd-network.c +++ b/src/network/networkd-network.c @@ -377,6 +377,8 @@ int network_load_one(Manager *manager, OrderedHashmap **networks, const char *fi .keep_configuration = manager->keep_configuration, + .use_domains = _USE_DOMAINS_INVALID, + .compat_dhcp_use_domains = _USE_DOMAINS_INVALID, .compat_dhcp_use_dns = -1, .compat_dhcp_use_ntp = -1, @@ -489,6 +491,7 @@ int network_load_one(Manager *manager, OrderedHashmap **networks, const char *fi .ndisc_use_hop_limit = true, .ndisc_use_reachable_time = true, .ndisc_use_retransmission_time = true, + .ndisc_use_domains = _USE_DOMAINS_INVALID, .ndisc_route_table = RT_TABLE_MAIN, .ndisc_route_metric_high = IPV6RA_ROUTE_METRIC_HIGH, .ndisc_route_metric_medium = IPV6RA_ROUTE_METRIC_MEDIUM, diff --git a/src/network/networkd-network.h b/src/network/networkd-network.h index dd938e525a..c8573e0973 100644 --- a/src/network/networkd-network.h +++ b/src/network/networkd-network.h @@ -113,6 +113,9 @@ struct Network { bool default_route_on_device; AddressFamily ip_masquerade; + /* Protocol independent settings */ + UseDomains use_domains; + /* For backward compatibility, only applied to DHCPv4 and DHCPv6. */ UseDomains compat_dhcp_use_domains; int compat_dhcp_use_dns; diff --git a/src/network/networkd.conf b/src/network/networkd.conf index 828dbb9638..06d436245e 100644 --- a/src/network/networkd.conf +++ b/src/network/networkd.conf @@ -24,16 +24,20 @@ #ManageForeignNextHops=yes #RouteTable= #IPv6PrivacyExtensions=no +#UseDomains=no + +[IPv6AcceptRA] +#UseDomains= [DHCPv4] #DUIDType=vendor #DUIDRawData= -#UseDomains=no +#UseDomains= [DHCPv6] #DUIDType=vendor #DUIDRawData= -#UseDomains=no +#UseDomains= [DHCPServer] #PersistLeases=yes