]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: dhcp-server: introduce special value DNS=_server_address
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 1 Feb 2022 07:20:33 +0000 (16:20 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 1 Feb 2022 20:01:53 +0000 (05:01 +0900)
Closes #15026.

man/systemd.network.xml
src/network/networkd-dhcp-server.c

index 44be11de1966c35199e6294cb8e9cfcf7e3ccd8a..71f5219363ee7814927e3e8f6e65649b572436bc 100644 (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>
index 0ec72d71f33b7b066d152d7a21c58073f8b37ff6..ced077944c8e2f845c44b5241952367e4e69ccf4 100644 (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))