network: dhcp-server: introduce special value DNS=_server_address

Closes #15026.
This commit is contained in:
Yu Watanabe 2022-02-01 16:20:33 +09:00
parent 77e73102dd
commit 5f468b9f57
2 changed files with 29 additions and 17 deletions

View file

@ -2558,18 +2558,20 @@ Token=prefixstable:2002:da8:1::</programlisting></para>
<term><varname>DNS=</varname></term>
<listitem><para><varname>EmitDNS=</varname> takes a boolean. Configures whether the DHCP leases
handed out to clients shall contain DNS server information. Defaults to <literal>yes</literal>. The
DNS servers to pass to clients may be configured with the <varname>DNS=</varname> option, which takes
a list of IPv4 addresses. If the <varname>EmitDNS=</varname> option is enabled but no servers
configured, the servers are automatically propagated from an "uplink" interface that has appropriate
servers set. The "uplink" interface is determined by the default route of the system with the highest
priority. Note that this information is acquired at the time the lease is handed out, and does not
take uplink interfaces into account that acquire DNS server information at a later point. If no
suitable uplink interface is found the DNS server data from <filename>/etc/resolv.conf</filename> is
used. Also, note that the leases are not refreshed if the uplink network configuration changes. To
ensure clients regularly acquire the most current uplink DNS server information, it is thus advisable
to shorten the DHCP lease time via <varname>MaxLeaseTimeSec=</varname> described
above.</para></listitem>
handed out to clients shall contain DNS server information. Defaults to <literal>yes</literal>.
The DNS servers to pass to clients may be configured with the <varname>DNS=</varname> option,
which takes a list of IPv4 addresses, or special value <literal>_server_address</literal> which
will be converted to the address used by the DHCP server. If the <varname>EmitDNS=</varname>
option is enabled but no servers configured, the servers are automatically propagated from an
"uplink" interface that has appropriate servers set. The "uplink" interface is determined by
the default route of the system with the highest priority. Note that this information is
acquired at the time the lease is handed out, and does not take uplink interfaces into account
that acquire DNS server information at a later point. If no suitable uplink interface is found
the DNS server data from <filename>/etc/resolv.conf</filename> is used. Also, note that the
leases are not refreshed if the uplink network configuration changes. To ensure clients
regularly acquire the most current uplink DNS server information, it is thus advisable to
shorten the DHCP lease time via <varname>MaxLeaseTimeSec=</varname> described above.
</para></listitem>
</varlistentry>
<varlistentry>

View file

@ -639,11 +639,21 @@ int config_parse_dhcp_server_emit(
if (r == 0)
return 0;
r = in_addr_from_string(AF_INET, w, &a);
if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r,
"Failed to parse %s= address '%s', ignoring: %m", lvalue, w);
continue;
if (streq(w, "_server_address"))
a = IN_ADDR_NULL; /* null address will be converted to the server address. */
else {
r = in_addr_from_string(AF_INET, w, &a);
if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r,
"Failed to parse %s= address '%s', ignoring: %m", lvalue, w);
continue;
}
if (in4_addr_is_null(&a.in)) {
log_syntax(unit, LOG_WARNING, filename, line, 0,
"Found a null address in %s=, ignoring.", lvalue);
continue;
}
}
if (!GREEDY_REALLOC(emit->addresses, emit->n_addresses + 1))