return 0;
}
-int link_drop_foreign_addresses(Link *link) {
+int link_drop_unmanaged_addresses(Link *link) {
Address *address;
int r = 0;
if (link->flags & IFF_LOOPBACK && in_addr_is_localhost_one(address->family, &address->in_addr) > 0)
continue;
- /* Ignore addresses we configured. */
- if (address->source != NETWORK_CONFIG_SOURCE_FOREIGN)
- continue;
-
/* Ignore addresses not assigned yet or already removing. */
if (!address_exists(address))
continue;
- /* 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;
+ if (address->source == NETWORK_CONFIG_SOURCE_FOREIGN) {
+ if (link->network->keep_configuration == KEEP_CONFIGURATION_YES)
+ continue;
+
+ /* link_address_is_dynamic() is slightly heavy. Let's call the function only when
+ * KeepConfiguration=dhcp or static. */
+ 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;
+
+ } else if (address->source != NETWORK_CONFIG_SOURCE_STATIC)
+ continue; /* Ignore dynamically configurad addresses. */
address_mark(address);
}
return r;
}
-void link_foreignize_addresses(Link *link) {
- Address *address;
-
- assert(link);
-
- SET_FOREACH(address, link->addresses)
- address->source = NETWORK_CONFIG_SOURCE_FOREIGN;
-}
-
int address_configure_handler_internal(sd_netlink *rtnl, sd_netlink_message *m, Link *link, const char *error_msg) {
int r;
DEFINE_SECTION_CLEANUP_FUNCTIONS(Address, address_unref);
int link_drop_static_addresses(Link *link);
-int link_drop_foreign_addresses(Link *link);
+int link_drop_unmanaged_addresses(Link *link);
int link_drop_ipv6ll_addresses(Link *link);
-void link_foreignize_addresses(Link *link);
bool link_address_is_dynamic(const Link *link, const Address *address);
int link_get_address_full(
/* If the request is already called, but its reply is not received, then we need to
* drop the configuration (e.g. address) here. Note, if the configuration is known,
- * it will be handled later by link_drop_foreign_addresses() or so. */
+ * it will be handled later by link_drop_unmanaged_addresses() or so. */
if (req->waiting_reply && link->state != LINK_STATE_LINGER)
switch (req->type) {
case REQUEST_TYPE_ADDRESS: {
return link_unref(link);
}
-static int link_drop_foreign_config(Link *link) {
+static int link_drop_unmanaged_config(Link *link) {
int r;
assert(link);
+ assert(link->state == LINK_STATE_CONFIGURING);
assert(link->manager);
- /* Drop foreign config, but ignore unmanaged, loopback, or critical interfaces. We do not want
- * to remove loopback address or addresses used for root NFS. */
-
- if (IN_SET(link->state, LINK_STATE_UNMANAGED, LINK_STATE_PENDING, LINK_STATE_INITIALIZED))
- return 0;
- if (FLAGS_SET(link->flags, IFF_LOOPBACK))
- return 0;
- if (link->network->keep_configuration == KEEP_CONFIGURATION_YES)
- return 0;
-
- r = link_drop_foreign_routes(link);
-
- RET_GATHER(r, link_drop_foreign_nexthops(link));
- RET_GATHER(r, link_drop_foreign_addresses(link));
- RET_GATHER(r, link_drop_foreign_neighbors(link));
- RET_GATHER(r, manager_drop_foreign_routing_policy_rules(link->manager));
+ r = link_drop_unmanaged_routes(link);
+ RET_GATHER(r, link_drop_unmanaged_nexthops(link));
+ RET_GATHER(r, link_drop_unmanaged_addresses(link));
+ RET_GATHER(r, link_drop_unmanaged_neighbors(link));
+ RET_GATHER(r, link_drop_unmanaged_routing_policy_rules(link));
return r;
}
-static int link_drop_managed_config(Link *link) {
+static int link_drop_static_config(Link *link) {
int r;
assert(link);
return r;
}
-static void link_foreignize_config(Link *link) {
- assert(link);
- assert(link->manager);
-
- link_foreignize_routes(link);
- link_foreignize_nexthops(link);
- link_foreignize_addresses(link);
- link_foreignize_neighbors(link);
- link_foreignize_routing_policy_rules(link);
-}
-
static int link_configure(Link *link) {
int r;
if (r < 0)
return r;
- r = link_drop_foreign_config(link);
+ r = link_drop_unmanaged_config(link);
if (r < 0)
return r;
(void) link_stop_engines(link, /* may_keep_dhcp = */ false);
(void) link_drop_requests(link);
- (void) link_drop_managed_config(link);
+ (void) link_drop_static_config(link);
/* The bound_to map depends on .network file, hence it needs to be freed. But, do not free the
* bound_by map. Otherwise, if a link enters unmanaged state below, then its carrier state will
if (r < 0)
return r;
- if (!FLAGS_SET(flags, LINK_RECONFIGURE_UNCONDITIONALLY) && network->keep_configuration != KEEP_CONFIGURATION_YES)
- /* When a new/updated .network file is assigned, first make all configs (addresses,
- * routes, and so on) foreign, and then drop unnecessary configs later by
- * link_drop_foreign_config() in link_configure().
- * Note, when KeepConfiguration=yes, link_drop_foreign_config() does nothing. Hence,
- * here we need to drop the configs such as addresses, routes, and so on configured by
- * the previously assigned .network file. */
- link_foreignize_config(link);
- else {
- /* 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 (FLAGS_SET(flags, LINK_RECONFIGURE_UNCONDITIONALLY)) {
+ /* Remove all static configurations. Note, dynamic configurations are dropped by
+ * link_stop_engines(), and foreign configurations will be removed later by
+ * link_configure() -> link_drop_unmanaged_config(). */
+ r = link_drop_static_config(link);
if (r < 0)
return r;
}
return ret;
RET_GATHER(ret, link_stop_engines(link, false));
- RET_GATHER(ret, link_drop_managed_config(link));
+ RET_GATHER(ret, link_drop_static_config(link));
return ret;
}
return 0;
}
-int link_drop_foreign_neighbors(Link *link) {
+int link_drop_unmanaged_neighbors(Link *link) {
Neighbor *neighbor;
int r = 0;
/* First, mark all neighbors. */
SET_FOREACH(neighbor, link->neighbors) {
- /* Do not remove neighbors we configured. */
- if (neighbor->source != NETWORK_CONFIG_SOURCE_FOREIGN)
- continue;
-
/* Ignore neighbors not assigned yet or already removing. */
if (!neighbor_exists(neighbor))
continue;
+ /* Ignore foreign neighbors when KeepConfiguration=yes or static. */
+ if (neighbor->source == NETWORK_CONFIG_SOURCE_FOREIGN &&
+ FLAGS_SET(link->network->keep_configuration, KEEP_CONFIGURATION_STATIC))
+ continue;
+
neighbor_mark(neighbor);
}
neighbor_unmark(existing);
}
+ /* Finally, remove all marked neighbors. */
SET_FOREACH(neighbor, link->neighbors) {
if (!neighbor_is_marked(neighbor))
continue;
return r;
}
-void link_foreignize_neighbors(Link *link) {
- Neighbor *neighbor;
-
- assert(link);
-
- SET_FOREACH(neighbor, link->neighbors)
- neighbor->source = NETWORK_CONFIG_SOURCE_FOREIGN;
-}
-
int manager_rtnl_process_neighbor(sd_netlink *rtnl, sd_netlink_message *message, Manager *m) {
_cleanup_(neighbor_unrefp) Neighbor *tmp = NULL;
Neighbor *neighbor = NULL;
int network_drop_invalid_neighbors(Network *network);
int link_drop_static_neighbors(Link *link);
-int link_drop_foreign_neighbors(Link *link);
-void link_foreignize_neighbors(Link *link);
+int link_drop_unmanaged_neighbors(Link *link);
int link_request_static_neighbors(Link *link);
return true;
}
-static void link_mark_nexthops(Link *link, bool foreign) {
+int link_drop_nexthops(Link *link, bool only_static) {
NextHop *nexthop;
Link *other;
+ int r = 0;
assert(link);
assert(link->manager);
if (nexthop->protocol == RTPROT_KERNEL)
continue;
- /* When 'foreign' is true, mark only foreign nexthops, and vice versa. */
- if (nexthop->source != (foreign ? NETWORK_CONFIG_SOURCE_FOREIGN : NETWORK_CONFIG_SOURCE_STATIC))
- continue;
-
/* Ignore nexthops not assigned yet or already removed. */
if (!nexthop_exists(nexthop))
continue;
+ if (only_static) {
+ if (nexthop->source != NETWORK_CONFIG_SOURCE_STATIC)
+ continue;
+ } else {
+ /* Do not mark foreign nexthop when KeepConfiguration= is enabled. */
+ if (nexthop->source == NETWORK_CONFIG_SOURCE_FOREIGN &&
+ link->network &&
+ FLAGS_SET(link->network->keep_configuration, KEEP_CONFIGURATION_STATIC))
+ continue;
+ }
+
/* Ignore nexthops bound to other links. */
if (nexthop->ifindex > 0 && nexthop->ifindex != link->ifindex)
continue;
/* Then, unmark all nexthops requested by active links. */
HASHMAP_FOREACH(other, link->manager->links_by_index) {
- if (!foreign && other == link)
+ if (only_static && other == link)
continue;
if (!IN_SET(other->state, LINK_STATE_CONFIGURING, LINK_STATE_CONFIGURED))
nexthop_unmark(existing);
}
}
-}
-
-int link_drop_nexthops(Link *link, bool foreign) {
- NextHop *nexthop;
- int r = 0;
-
- assert(link);
- assert(link->manager);
-
- link_mark_nexthops(link, foreign);
+ /* Finally, remove all marked nexthops. */
HASHMAP_FOREACH(nexthop, link->manager->nexthops_by_id) {
if (!nexthop_is_marked(nexthop))
continue;
return r;
}
-void link_foreignize_nexthops(Link *link) {
- NextHop *nexthop;
-
- assert(link);
- assert(link->manager);
-
- link_mark_nexthops(link, /* foreign = */ false);
-
- HASHMAP_FOREACH(nexthop, link->manager->nexthops_by_id) {
- if (!nexthop_is_marked(nexthop))
- continue;
-
- nexthop->source = NETWORK_CONFIG_SOURCE_FOREIGN;
- }
-}
-
static int nexthop_update_group(NextHop *nexthop, sd_netlink_message *message) {
_cleanup_hashmap_free_free_ Hashmap *h = NULL;
_cleanup_free_ struct nexthop_grp *group = NULL;
int network_drop_invalid_nexthops(Network *network);
-int link_drop_nexthops(Link *link, bool foreign);
-static inline int link_drop_foreign_nexthops(Link *link) {
- return link_drop_nexthops(link, /* foreign = */ true);
+int link_drop_nexthops(Link *link, bool only_static);
+static inline int link_drop_unmanaged_nexthops(Link *link) {
+ return link_drop_nexthops(link, /* only_static = */ false);
}
static inline int link_drop_static_nexthops(Link *link) {
- return link_drop_nexthops(link, /* foreign = */ false);
+ return link_drop_nexthops(link, /* only_static = */ true);
}
-void link_foreignize_nexthops(Link *link);
int link_request_static_nexthops(Link *link, bool only_ipv4);
return 1;
}
-static int link_mark_routes(Link *link, bool foreign) {
+int link_drop_routes(Link *link, bool only_static) {
Route *route;
Link *other;
- int r;
+ int r = 0;
assert(link);
assert(link->manager);
if (route_by_kernel(route))
continue;
- /* When 'foreign' is true, mark only foreign routes, and vice versa.
- * Note, do not touch dynamic routes. They will removed by when e.g. lease is lost. */
- if (route->source != (foreign ? NETWORK_CONFIG_SOURCE_FOREIGN : NETWORK_CONFIG_SOURCE_STATIC))
- continue;
-
/* Ignore routes not assigned yet or already removed. */
if (!route_exists(route))
continue;
- if (link->network) {
- if (route->protocol == RTPROT_STATIC &&
- FLAGS_SET(link->network->keep_configuration, KEEP_CONFIGURATION_STATIC))
+ if (only_static) {
+ if (route->source != NETWORK_CONFIG_SOURCE_STATIC)
continue;
-
- if (route->protocol == RTPROT_DHCP &&
- FLAGS_SET(link->network->keep_configuration, KEEP_CONFIGURATION_DHCP))
+ } else {
+ /* Ignore dynamically assigned routes. */
+ if (!IN_SET(route->source, NETWORK_CONFIG_SOURCE_FOREIGN, NETWORK_CONFIG_SOURCE_STATIC))
continue;
+
+ if (route->source == NETWORK_CONFIG_SOURCE_FOREIGN && link->network) {
+ if (route->protocol == RTPROT_STATIC &&
+ FLAGS_SET(link->network->keep_configuration, KEEP_CONFIGURATION_STATIC))
+ continue;
+
+ if (IN_SET(route->protocol, RTPROT_DHCP, RTPROT_RA, RTPROT_REDIRECT) &&
+ FLAGS_SET(link->network->keep_configuration, KEEP_CONFIGURATION_DHCP))
+ continue;
+ }
}
- /* When we mark foreign routes, do not mark routes assigned to other interfaces.
+ /* When we also mark foreign routes, do not mark routes assigned to other interfaces.
* Otherwise, routes assigned to unmanaged interfaces will be dropped.
* Note, route_get_link() does not provide assigned link for routes with an unreachable type
* or IPv4 multipath routes. So, the current implementation does not support managing such
* routes by other daemon or so, unless ManageForeignRoutes=no. */
- if (foreign) {
+ if (!only_static) {
Link *route_link;
if (route_get_link(link->manager, route, &route_link) >= 0 && route_link != link)
/* Then, unmark all routes requested by active links. */
HASHMAP_FOREACH(other, link->manager->links_by_index) {
- if (!foreign && other == link)
+ if (only_static && other == link)
continue;
if (!IN_SET(other->state, LINK_STATE_CONFIGURING, LINK_STATE_CONFIGURED))
}
}
- return 0;
-}
-
-int link_drop_routes(Link *link, bool foreign) {
- Route *route;
- int r;
-
- assert(link);
- assert(link->manager);
-
- r = link_mark_routes(link, foreign);
- if (r < 0)
- return r;
-
+ /* Finally, remove all marked routes. */
SET_FOREACH(route, link->manager->routes) {
if (!route_is_marked(route))
continue;
return r;
}
-int link_foreignize_routes(Link *link) {
- Route *route;
- int r;
-
- assert(link);
- assert(link->manager);
-
- r = link_mark_routes(link, /* foreign = */ false);
- if (r < 0)
- return r;
-
- SET_FOREACH(route, link->manager->routes) {
- if (!route_is_marked(route))
- continue;
-
- route->source = NETWORK_CONFIG_SOURCE_FOREIGN;
- }
-
- return 0;
-}
-
int network_add_ipv4ll_route(Network *network) {
_cleanup_(route_unref_or_set_invalidp) Route *route = NULL;
unsigned section_line;
bool route_can_update(const Route *existing, const Route *requesting);
-int link_drop_routes(Link *link, bool foreign);
+int link_drop_routes(Link *link, bool only_static);
static inline int link_drop_static_routes(Link *link) {
- return link_drop_routes(link, false);
-}
-static inline int link_drop_foreign_routes(Link *link) {
return link_drop_routes(link, true);
}
-int link_foreignize_routes(Link *link);
+static inline int link_drop_unmanaged_routes(Link *link) {
+ return link_drop_routes(link, false);
+}
int link_request_route(
Link *link,
routing_policy_rule_unmark(existing);
}
-static void manager_mark_routing_policy_rules(Manager *m, bool foreign, const Link *except) {
+int link_drop_routing_policy_rules(Link *link, bool only_static) {
RoutingPolicyRule *rule;
- Link *link;
+ int r = 0;
- assert(m);
+ assert(link);
+ assert(link->manager);
/* First, mark all existing rules. */
- SET_FOREACH(rule, m->rules) {
+ SET_FOREACH(rule, link->manager->rules) {
/* Do not touch rules managed by kernel. */
if (rule->protocol == RTPROT_KERNEL)
continue;
- /* When 'foreign' is true, mark only foreign rules, and vice versa. */
- if (rule->source != (foreign ? NETWORK_CONFIG_SOURCE_FOREIGN : NETWORK_CONFIG_SOURCE_STATIC))
- continue;
+ if (only_static) {
+ /* When 'only_static' is true, mark only static rules. */
+ if (rule->source != NETWORK_CONFIG_SOURCE_STATIC)
+ continue;
+ } else {
+ /* Do not mark foreign rules when KeepConfiguration= is enabled. */
+ if (rule->source == NETWORK_CONFIG_SOURCE_FOREIGN &&
+ link->network &&
+ FLAGS_SET(link->network->keep_configuration, KEEP_CONFIGURATION_STATIC))
+ continue;
+ }
/* Ignore rules not assigned yet or already removing. */
if (!routing_policy_rule_exists(rule))
}
/* Then, unmark all rules requested by active links. */
- HASHMAP_FOREACH(link, m->links_by_index) {
- if (link == except)
+ Link *other;
+ HASHMAP_FOREACH(other, link->manager->links_by_index) {
+ if (only_static && other == link)
continue;
- if (!IN_SET(link->state, LINK_STATE_CONFIGURING, LINK_STATE_CONFIGURED))
+ if (!IN_SET(other->state, LINK_STATE_CONFIGURING, LINK_STATE_CONFIGURED))
continue;
- HASHMAP_FOREACH(rule, link->network->rules_by_section) {
+ HASHMAP_FOREACH(rule, other->network->rules_by_section) {
if (IN_SET(rule->family, AF_INET, AF_INET6))
- manager_unmark_routing_policy_rule(m, rule, rule->family);
+ manager_unmark_routing_policy_rule(link->manager, rule, rule->family);
else {
assert(rule->address_family == ADDRESS_FAMILY_YES);
- manager_unmark_routing_policy_rule(m, rule, AF_INET);
- manager_unmark_routing_policy_rule(m, rule, AF_INET6);
+ manager_unmark_routing_policy_rule(link->manager, rule, AF_INET);
+ manager_unmark_routing_policy_rule(link->manager, rule, AF_INET6);
}
}
}
-}
-
-int manager_drop_routing_policy_rules_internal(Manager *m, bool foreign, const Link *except) {
- RoutingPolicyRule *rule;
- int r = 0;
-
- assert(m);
- manager_mark_routing_policy_rules(m, foreign, except);
-
- SET_FOREACH(rule, m->rules) {
+ /* Finally, remove all marked rules. */
+ SET_FOREACH(rule, link->manager->rules) {
if (!routing_policy_rule_is_marked(rule))
continue;
- RET_GATHER(r, routing_policy_rule_remove(rule, m));
+ RET_GATHER(r, routing_policy_rule_remove(rule, link->manager));
}
return r;
}
-void link_foreignize_routing_policy_rules(Link *link) {
- RoutingPolicyRule *rule;
-
- assert(link);
- assert(link->manager);
-
- manager_mark_routing_policy_rules(link->manager, /* foreign = */ false, link);
-
- SET_FOREACH(rule, link->manager->rules) {
- if (!routing_policy_rule_is_marked(rule))
- continue;
-
- rule->source = NETWORK_CONFIG_SOURCE_FOREIGN;
- }
-}
-
static int routing_policy_rule_process_request(Request *req, Link *link, RoutingPolicyRule *rule) {
RoutingPolicyRule *existing;
int r;
int link_request_static_routing_policy_rules(Link *link);
int manager_rtnl_process_rule(sd_netlink *rtnl, sd_netlink_message *message, Manager *m);
-int manager_drop_routing_policy_rules_internal(Manager *m, bool foreign, const Link *except);
-static inline int manager_drop_foreign_routing_policy_rules(Manager *m) {
- return manager_drop_routing_policy_rules_internal(m, true, NULL);
+
+int link_drop_routing_policy_rules(Link *link, bool only_static);
+static inline int link_drop_unmanaged_routing_policy_rules(Link *link) {
+ return link_drop_routing_policy_rules(link, false);
}
static inline int link_drop_static_routing_policy_rules(Link *link) {
- assert(link);
- return manager_drop_routing_policy_rules_internal(link->manager, false, link);
+ return link_drop_routing_policy_rules(link, true);
}
-void link_foreignize_routing_policy_rules(Link *link);
DEFINE_NETWORK_CONFIG_STATE_FUNCTIONS(RoutingPolicyRule, routing_policy_rule);