return r;
}
-int link_drop_addresses(Link *link) {
+int link_drop_managed_addresses(Link *link) {
Address *address;
int k, r = 0;
assert(link);
SET_FOREACH(address, link->addresses) {
- /* Ignore addresses not assigned yet or already removing. */
- if (!address_exists(address))
+ /* Do not touch addresses managed by kernel or other tools. */
+ if (address->source == NETWORK_CONFIG_SOURCE_FOREIGN)
continue;
- /* 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))
+ /* Ignore addresses not assigned yet or already removing. */
+ if (!address_exists(address))
continue;
k = address_remove(address);
DEFINE_SECTION_CLEANUP_FUNCTIONS(Address, address_free);
-int link_drop_addresses(Link *link);
+int link_drop_managed_addresses(Link *link);
int link_drop_foreign_addresses(Link *link);
int link_drop_ipv6ll_addresses(Link *link);
void link_foreignize_addresses(Link *link);
return r;
}
-static int link_drop_config(Link *link) {
+static int link_drop_managed_config(Link *link) {
int k, r;
assert(link);
assert(link->manager);
- r = link_drop_routes(link);
+ r = link_drop_managed_routes(link);
- k = link_drop_nexthops(link);
+ k = link_drop_managed_nexthops(link);
if (k < 0 && r >= 0)
r = k;
- k = link_drop_addresses(link);
+ k = link_drop_managed_addresses(link);
if (k < 0 && r >= 0)
r = k;
- k = link_drop_neighbors(link);
+ k = link_drop_managed_neighbors(link);
if (k < 0 && r >= 0)
r = k;
- k = link_drop_routing_policy_rules(link);
+ k = link_drop_managed_routing_policy_rules(link);
if (k < 0 && r >= 0)
r = k;
* link_drop_foreign_config() in link_configure(). */
link_foreignize_config(link);
else {
- r = link_drop_config(link);
+ /* Remove all managed configs. Note, foreign configs are removed in later by
+ * link_configure() -> link_drop_foreign_config() if the link is managed by us. */
+ r = link_drop_managed_config(link);
if (r < 0)
return r;
}
if (r < 0)
ret = r;
- r = link_drop_config(link);
+ r = link_drop_managed_config(link);
if (r < 0 && ret >= 0)
ret = r;
return r;
}
-int link_drop_neighbors(Link *link) {
+int link_drop_managed_neighbors(Link *link) {
Neighbor *neighbor;
int k, r = 0;
assert(link);
SET_FOREACH(neighbor, link->neighbors) {
+ /* Do not touch nexthops managed by kernel or other tools. */
+ if (neighbor->source == NETWORK_CONFIG_SOURCE_FOREIGN)
+ continue;
+
/* Ignore neighbors not assigned yet or already removing. */
if (!neighbor_exists(neighbor))
continue;
void network_drop_invalid_neighbors(Network *network);
-int link_drop_neighbors(Link *link);
+int link_drop_managed_neighbors(Link *link);
int link_drop_foreign_neighbors(Link *link);
void link_foreignize_neighbors(Link *link);
if (nexthop->protocol == RTPROT_KERNEL)
continue;
- /* When 'foreign' is true, do not remove nexthops we configured. */
- if (foreign && nexthop->source != NETWORK_CONFIG_SOURCE_FOREIGN)
+ /* When 'foreign' is true, mark only foreign nexthops, and vice versa. */
+ if (foreign != (nexthop->source == NETWORK_CONFIG_SOURCE_FOREIGN))
continue;
/* Ignore nexthops not assigned yet or already removed. */
}
}
-static int manager_drop_nexthops(Manager *manager) {
+static int manager_drop_marked_nexthops(Manager *manager) {
NextHop *nexthop;
int k, r = 0;
manager_mark_nexthops(link->manager, /* foreign = */ true, NULL);
- k = manager_drop_nexthops(link->manager);
+ k = manager_drop_marked_nexthops(link->manager);
if (k < 0 && r >= 0)
r = k;
return r;
}
-int link_drop_nexthops(Link *link) {
+int link_drop_managed_nexthops(Link *link) {
NextHop *nexthop;
int k, r = 0;
if (nexthop->protocol == RTPROT_KERNEL)
continue;
+ /* Do not touch addresses managed by kernel or other tools. */
+ if (nexthop->source == NETWORK_CONFIG_SOURCE_FOREIGN)
+ continue;
+
/* Ignore nexthops not assigned yet or already removing. */
if (!nexthop_exists(nexthop))
continue;
manager_mark_nexthops(link->manager, /* foreign = */ false, link);
- k = manager_drop_nexthops(link->manager);
+ k = manager_drop_marked_nexthops(link->manager);
if (k < 0 && r >= 0)
r = k;
void network_drop_invalid_nexthops(Network *network);
-int link_drop_nexthops(Link *link);
+int link_drop_managed_nexthops(Link *link);
int link_drop_foreign_nexthops(Link *link);
void link_foreignize_nexthops(Link *link);
if (route->protocol == RTPROT_KERNEL)
continue;
- /* When 'foreign' is true, do not remove routes we configured. */
- if (foreign && route->source != NETWORK_CONFIG_SOURCE_FOREIGN)
+ /* When 'foreign' is true, mark only foreign routes, and vice versa. */
+ if (foreign != (route->source == NETWORK_CONFIG_SOURCE_FOREIGN))
continue;
/* Do not touch dynamic routes. They will removed by dhcp_pd_prefix_lost() */
}
}
-static int manager_drop_routes(Manager *manager) {
+static int manager_drop_marked_routes(Manager *manager) {
Route *route;
int k, r = 0;
manager_mark_routes(link->manager, /* foreign = */ true, NULL);
- k = manager_drop_routes(link->manager);
+ k = manager_drop_marked_routes(link->manager);
if (k < 0 && r >= 0)
r = k;
return r;
}
-int link_drop_routes(Link *link) {
+int link_drop_managed_routes(Link *link) {
Route *route;
int k, r = 0;
if (route_by_kernel(route))
continue;
+ /* Do not touch routes managed by kernel or other tools. */
+ if (route->source == NETWORK_CONFIG_SOURCE_FOREIGN)
+ continue;
+
if (!route_exists(route))
continue;
manager_mark_routes(link->manager, /* foreign = */ false, link);
- k = manager_drop_routes(link->manager);
+ k = manager_drop_marked_routes(link->manager);
if (k < 0 && r >= 0)
r = k;
int route_get(Manager *manager, Link *link, const Route *in, Route **ret);
-int link_drop_routes(Link *link);
+int link_drop_managed_routes(Link *link);
int link_drop_foreign_routes(Link *link);
void link_foreignize_routes(Link *link);
if (rule->protocol == RTPROT_KERNEL)
continue;
- /* When 'foreign' is true, do not remove rules we configured. */
- if (foreign && rule->source != NETWORK_CONFIG_SOURCE_FOREIGN)
+ /* When 'foreign' is true, mark only foreign rules, and vice versa. */
+ if (foreign != (rule->source == NETWORK_CONFIG_SOURCE_FOREIGN))
continue;
/* Ignore rules not assigned yet or already removing. */
static inline int manager_drop_foreign_routing_policy_rules(Manager *m) {
return manager_drop_routing_policy_rules_internal(m, true, NULL);
}
-static inline int link_drop_routing_policy_rules(Link *link) {
+static inline int link_drop_managed_routing_policy_rules(Link *link) {
assert(link);
return manager_drop_routing_policy_rules_internal(link->manager, false, link);
}
print(output)
self.assertRegex(output, 'NO-CARRIER')
self.assertNotRegex(output, '192.168.0.15/24')
- self.assertNotRegex(output, '192.168.0.16/24')
+ self.assertRegex(output, '192.168.0.16/24') # foreign address is kept
print('### ip -6 route list table all dev bridge99')
output = check_output('ip -6 route list table all dev bridge99')