]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network/address: make Address= in [Network] support an empty string
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 20 Dec 2023 19:08:53 +0000 (04:08 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 20 Dec 2023 19:08:53 +0000 (04:08 +0900)
Closes #30485.

man/systemd.network.xml
src/network/networkd-address.c

index 7dc447d0a7f84b690bf4a3044edb7bac0679e7a7..b587573a5f6b007b7c07633de8a4800170df1e51 100644 (file)
@@ -662,6 +662,9 @@ Table=1234</programlisting></para>
           number of dynamically created network interfaces with the same network configuration and
           automatic address range assignment.</para>
 
+          <para>If an empty string is specified, then the all previous assignments in both [Network] and
+          [Address] sections are cleared.</para>
+
           <xi:include href="version-info.xml" xpointer="v211"/>
         </listitem>
       </varlistentry>
index e3bdc66c587efe5731f460864b2030513f647a17..ad49793a1689dede01b33a86c6acd6d6745524fd 100644 (file)
@@ -1994,10 +1994,16 @@ int config_parse_address(
         assert(rvalue);
         assert(data);
 
-        if (streq(section, "Network"))
+        if (streq(section, "Network")) {
+                if (isempty(rvalue)) {
+                        /* If an empty string specified in [Network] section, clear previously assigned addresses. */
+                        network->addresses_by_section = ordered_hashmap_free_with_destructor(network->addresses_by_section, address_free);
+                        return 0;
+                }
+
                 /* we are not in an Address section, so use line number instead. */
                 r = address_new_static(network, filename, line, &n);
-        else
+        else
                 r = address_new_static(network, filename, section_line, &n);
         if (r == -ENOMEM)
                 return log_oom();