network/address: make Address= in [Network] support an empty string

Closes #30485.
This commit is contained in:
Yu Watanabe 2023-12-21 04:08:53 +09:00
parent b993e7e72e
commit a61738b3a6
2 changed files with 11 additions and 2 deletions

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

View 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();