From 5f468b9f579d770bea9d5ec442407c9a7f94c21b Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Tue, 1 Feb 2022 16:20:33 +0900 Subject: [PATCH] network: dhcp-server: introduce special value DNS=_server_address Closes #15026. --- man/systemd.network.xml | 26 ++++++++++++++------------ src/network/networkd-dhcp-server.c | 20 +++++++++++++++----- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/man/systemd.network.xml b/man/systemd.network.xml index 44be11de196..71f5219363e 100644 --- a/man/systemd.network.xml +++ b/man/systemd.network.xml @@ -2558,18 +2558,20 @@ Token=prefixstable:2002:da8:1:: DNS= EmitDNS= takes a boolean. Configures whether the DHCP leases - handed out to clients shall contain DNS server information. Defaults to yes. The - DNS servers to pass to clients may be configured with the DNS= option, which takes - a list of IPv4 addresses. If the EmitDNS= 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 /etc/resolv.conf 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 MaxLeaseTimeSec= described - above. + handed out to clients shall contain DNS server information. Defaults to yes. + The DNS servers to pass to clients may be configured with the DNS= option, + which takes a list of IPv4 addresses, or special value _server_address which + will be converted to the address used by the DHCP server. If the EmitDNS= + 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 /etc/resolv.conf 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 MaxLeaseTimeSec= described above. + diff --git a/src/network/networkd-dhcp-server.c b/src/network/networkd-dhcp-server.c index 0ec72d71f33..ced077944c8 100644 --- a/src/network/networkd-dhcp-server.c +++ b/src/network/networkd-dhcp-server.c @@ -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))