mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-10 01:17:44 +03:00
Merge pull request #21736 from yuwata/network-cleanups-for-drop-foreign-configs
network: cleanups for dropping foreign configs
This commit is contained in:
commit
75e1378c0d
@ -728,6 +728,10 @@ bool link_address_is_dynamic(const Link *link, const Address *address) {
|
||||
if (route->source != NETWORK_CONFIG_SOURCE_FOREIGN)
|
||||
continue;
|
||||
|
||||
/* The route is not assigned yet, or already removed. Ignoring. */
|
||||
if (!route_exists(route))
|
||||
continue;
|
||||
|
||||
if (route->protocol != RTPROT_DHCP)
|
||||
continue;
|
||||
|
||||
@ -840,6 +844,10 @@ int link_drop_foreign_addresses(Link *link) {
|
||||
assert(link);
|
||||
assert(link->network);
|
||||
|
||||
/* Keep all addresses when KeepConfiguration=yes. */
|
||||
if (link->network->keep_configuration == KEEP_CONFIGURATION_YES)
|
||||
return 0;
|
||||
|
||||
/* First, mark all addresses. */
|
||||
SET_FOREACH(address, link->addresses) {
|
||||
/* We consider IPv6LL addresses to be managed by the kernel, or dropped in link_drop_ipv6ll_addresses() */
|
||||
@ -854,10 +862,9 @@ int link_drop_foreign_addresses(Link *link) {
|
||||
if (!address_exists(address))
|
||||
continue;
|
||||
|
||||
if (link_address_is_dynamic(link, address)) {
|
||||
if (link->network && FLAGS_SET(link->network->keep_configuration, KEEP_CONFIGURATION_DHCP))
|
||||
continue;
|
||||
} else if (link->network && FLAGS_SET(link->network->keep_configuration, KEEP_CONFIGURATION_STATIC))
|
||||
/* link_address_is_dynamic() is slightly heavy. Let's call the function only when KeepConfiguration= is set. */
|
||||
if (IN_SET(link->network->keep_configuration, KEEP_CONFIGURATION_DHCP, KEEP_CONFIGURATION_STATIC) &&
|
||||
link_address_is_dynamic(link, address) == (link->network->keep_configuration == KEEP_CONFIGURATION_DHCP))
|
||||
continue;
|
||||
|
||||
address_mark(address);
|
||||
@ -895,8 +902,11 @@ int link_drop_addresses(Link *link) {
|
||||
if (!address_exists(address))
|
||||
continue;
|
||||
|
||||
/* We consider IPv6LL addresses to be managed by the kernel, or dropped in link_drop_ipv6ll_addresses() */
|
||||
if (address->family == AF_INET6 && in6_addr_is_link_local(&address->in_addr.in6))
|
||||
/* Do not drop IPv6LL addresses assigned by the kernel here. They will be dropped in
|
||||
* link_drop_ipv6ll_addresses() if IPv6LL addressing is disabled. */
|
||||
if (address->source == NETWORK_CONFIG_SOURCE_FOREIGN &&
|
||||
address->family == AF_INET6 &&
|
||||
in6_addr_is_link_local(&address->in_addr.in6))
|
||||
continue;
|
||||
|
||||
k = address_remove(address);
|
||||
|
@ -893,6 +893,7 @@ int link_drop_foreign_routes(Link *link) {
|
||||
|
||||
assert(link);
|
||||
assert(link->manager);
|
||||
assert(link->network);
|
||||
|
||||
SET_FOREACH(route, link->routes) {
|
||||
/* do not touch routes managed by the kernel */
|
||||
@ -907,11 +908,11 @@ int link_drop_foreign_routes(Link *link) {
|
||||
if (!route_exists(route))
|
||||
continue;
|
||||
|
||||
if (route->protocol == RTPROT_STATIC && link->network &&
|
||||
if (route->protocol == RTPROT_STATIC &&
|
||||
FLAGS_SET(link->network->keep_configuration, KEEP_CONFIGURATION_STATIC))
|
||||
continue;
|
||||
|
||||
if (route->protocol == RTPROT_DHCP && link->network &&
|
||||
if (route->protocol == RTPROT_DHCP &&
|
||||
FLAGS_SET(link->network->keep_configuration, KEEP_CONFIGURATION_DHCP))
|
||||
continue;
|
||||
|
||||
|
@ -4588,12 +4588,11 @@ class NetworkdDHCPClientTests(unittest.TestCase, Utilities):
|
||||
print(output)
|
||||
self.assertRegex(output, r'192.168.5.*')
|
||||
|
||||
output = check_output(*networkctl_cmd, '-n', '0', 'status', 'veth99', env=env)
|
||||
print(output)
|
||||
self.assertRegex(output, r'192.168.5.*')
|
||||
with open(os.path.join(network_unit_file_path, 'dhcp-client-keep-configuration-dhcp.network'), mode='a') as f:
|
||||
f.write('[Network]\nDHCP=no\n')
|
||||
|
||||
start_networkd(3)
|
||||
self.wait_online(['veth-peer:routable'])
|
||||
start_networkd()
|
||||
self.wait_online(['veth99:routable', 'veth-peer:routable'])
|
||||
|
||||
print('Still the lease address should be kept after networkd restarted')
|
||||
output = check_output('ip address show dev veth99 scope global')
|
||||
|
Loading…
Reference in New Issue
Block a user