network: introduce network- and protocol-independent default for UseDomains=

Follow-up for fb57300743.

Prompted by #32273.
This commit is contained in:
Yu Watanabe 2024-04-15 14:55:18 +09:00
parent 5c81de98fc
commit 418f2dc755
10 changed files with 87 additions and 18 deletions

View file

@ -159,6 +159,43 @@
<xi:include href="version-info.xml" xpointer="v254"/>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>UseDomains=</varname></term>
<listitem>
<para>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
<option>route</option>. See the same setting in
<citerefentry><refentrytitle>systemd.network</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
Defaults to <literal>no</literal>.</para>
<xi:include href="version-info.xml" xpointer="v256"/>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1>
<title>[IPv6AcceptRA] Section Options</title>
<para>This section configures the default setting of the Neighbor Discovery. The following options are
available in the [IPv6AcceptRA] section:</para>
<variablelist class='network-directives'>
<varlistentry>
<term><varname>UseDomains=</varname></term>
<listitem>
<para>Specifies the network-independent default value for the same setting in the [IPv6AcceptRA]
section in
<citerefentry><refentrytitle>systemd.network</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
Takes a boolean, or the special value <option>route</option>. When unspecified, the value specified
in the [Network] section in
<citerefentry><refentrytitle>networkd.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
which defaults to <literal>no</literal>, will be used.</para>
<xi:include href="version-info.xml" xpointer="v256"/>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
@ -260,11 +297,9 @@ DUIDRawData=00:00:ab:11:f9:2a:c2:77:29:f9:5c:00</programlisting>
<varlistentry>
<term><varname>UseDomains=</varname></term>
<listitem><para>Specifies the default value for per-network <varname>UseDomains=</varname>.
Takes a boolean. See for details in
<citerefentry><refentrytitle>systemd.network</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
Defaults to <literal>no</literal>.</para>
<listitem>
<para>Same as the one in the [IPv6AcceptRA] section, but applied for DHCPv4 protocol.</para>
<xi:include href="version-info.xml" xpointer="v256"/>
</listitem>
</varlistentry>
@ -310,12 +345,9 @@ DUIDRawData=00:00:ab:11:f9:2a:c2:77:29:f9:5c:00</programlisting>
<variablelist class='network-directives'>
<varlistentry>
<term><varname>PersistLeases=</varname></term>
<term><varname>UseDomains=</varname></term>
<listitem>
<para>Specifies the default value for per-network <varname>PersistLeases=</varname>.
Takes a boolean. See for details in
<citerefentry><refentrytitle>systemd.network</refentrytitle><manvolnum>5</manvolnum></citerefentry>.
Defaults to <literal>yes</literal>.</para>
<para>Same as the one in the [IPv6AcceptRA] section, but applied for DHCPv4 protocol.</para>
<xi:include href="version-info.xml" xpointer="v256"/>
</listitem>

View file

@ -747,6 +747,17 @@ Table=1234</programlisting></para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>UseDomains=</varname></term>
<listitem>
<para>Specifies the protocol-independent default value for the same settins in
[IPv6AcceptRA], [DHCPv4], and [DHCPv6] sections below. Takes a boolean, or the special value
<option>route</option>. See also the same setting in [DHCPv4] below. Defaults to unset.</para>
<xi:include href="version-info.xml" xpointer="v256"/>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>Domains=</varname></term>
<listitem>
@ -2571,9 +2582,15 @@ NFTSet=prefix:netdev:filter:eth_ipv4_prefix</programlisting>
effect of the <option>Domains=</option> setting. If set to <option>route</option>, 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 <option>Domains=</option> setting when the argument is prefixed with
<literal>~</literal>. When unspecified, the value specified in the same setting in
<citerefentry><refentrytitle>networkd.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
which defaults to <literal>no</literal>, will be used.</para>
<literal>~</literal>.</para>
<para>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
<citerefentry><refentrytitle>networkd.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>
will be used. When it is unspecified, the value specified in the same setting in the [Network]
section in
<citerefentry><refentrytitle>networkd.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>
will be used. When none of them are specified, defaults to <literal>no</literal>.</para>
<para>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

View file

@ -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) {

View file

@ -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)

View file

@ -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,

View file

@ -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;

View file

@ -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)

View file

@ -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,

View file

@ -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;

View file

@ -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