]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: merge link_foreignize_config() and link_drop_foreign_config()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 5 Nov 2024 02:32:33 +0000 (11:32 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 5 Nov 2024 17:05:00 +0000 (02:05 +0900)
When a reconfiguration of an interface is triggered, previously we
call link_foreignize_config(), which sets all static configurations as
foreign, then later call link_drop_foreign_config(), which drops
unnecessary foreign configurations.

This commit merges these two steps into one, link_drop_unmanaged_config(),
which drops unnecessary static and foreign configurations.

Also, this renames link_drop_managed_configs() to
link_drop_static_config(), as it only drops static configurations.
Note that dynamically aquired configurations are dropped by
link_stop_engines().

src/network/networkd-address.c
src/network/networkd-address.h
src/network/networkd-link.c
src/network/networkd-neighbor.c
src/network/networkd-neighbor.h
src/network/networkd-nexthop.c
src/network/networkd-nexthop.h
src/network/networkd-route.c
src/network/networkd-route.h
src/network/networkd-routing-policy-rule.c
src/network/networkd-routing-policy-rule.h

index ca9e825b56ad1c21bc960e8194741e95a271fbd3..a689fa68bd0705cbce5a7b4491959ac775b91f9f 100644 (file)
@@ -1384,7 +1384,7 @@ int link_drop_ipv6ll_addresses(Link *link) {
         return 0;
 }
 
-int link_drop_foreign_addresses(Link *link) {
+int link_drop_unmanaged_addresses(Link *link) {
         Address *address;
         int r = 0;
 
@@ -1401,18 +1401,22 @@ int link_drop_foreign_addresses(Link *link) {
                 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);
         }
@@ -1464,15 +1468,6 @@ int link_drop_static_addresses(Link *link) {
         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;
 
index fc6f33b0f9c09e5ddcfa8fdd916f95e88d472e69..f8d6b6c3a1ec97cf0ef926b448502eace3c7705c 100644 (file)
@@ -113,9 +113,8 @@ bool link_check_addresses_ready(Link *link, NetworkConfigSource source);
 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(
index 40b65c52eeec754a9a419683cfa087ff2d3dd2d1..8bd32976bd8d15737310006e001b2635fabe0b3c 100644 (file)
@@ -1008,7 +1008,7 @@ static int link_drop_requests(Link *link) {
 
                 /* 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: {
@@ -1086,33 +1086,23 @@ static Link *link_drop(Link *link) {
         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);
@@ -1127,17 +1117,6 @@ static int link_drop_managed_config(Link *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;
 
@@ -1252,7 +1231,7 @@ static int link_configure(Link *link) {
         if (r < 0)
                 return r;
 
-        r = link_drop_foreign_config(link);
+        r = link_drop_unmanaged_config(link);
         if (r < 0)
                 return r;
 
@@ -1331,7 +1310,7 @@ static void link_enter_unmanaged(Link *link) {
 
         (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
@@ -1393,18 +1372,11 @@ int link_reconfigure_impl(Link *link, LinkReconfigurationFlag flags) {
         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;
         }
@@ -1791,7 +1763,7 @@ static int link_carrier_lost_impl(Link *link) {
                 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;
 }
index 6bfb6579e1b6feab252c516ab311f9231d0e958c..83275f2fc8dd7db5d7e73ce13a6e5750ffece7dd 100644 (file)
@@ -467,7 +467,7 @@ int neighbor_remove(Neighbor *neighbor, Link *link) {
         return 0;
 }
 
-int link_drop_foreign_neighbors(Link *link) {
+int link_drop_unmanaged_neighbors(Link *link) {
         Neighbor *neighbor;
         int r = 0;
 
@@ -476,14 +476,15 @@ int link_drop_foreign_neighbors(Link *link) {
 
         /* 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);
         }
 
@@ -495,6 +496,7 @@ int link_drop_foreign_neighbors(Link *link) {
                         neighbor_unmark(existing);
         }
 
+        /* Finally, remove all marked neighbors. */
         SET_FOREACH(neighbor, link->neighbors) {
                 if (!neighbor_is_marked(neighbor))
                         continue;
@@ -526,15 +528,6 @@ int link_drop_static_neighbors(Link *link) {
         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;
index c306e407d345c1b9b2112c6fc7b1d2b017c68c84..5dd43a98a0085a01c7318c8f5909dceb8b0b1da8 100644 (file)
@@ -36,8 +36,7 @@ int neighbor_remove(Neighbor *neighbor, Link *link);
 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);
 
index f935831efea914b70b19395e71d4afa13199cf42..e0fa4745ea7f00bfcfcd45793714562fe40411ef 100644 (file)
@@ -856,9 +856,10 @@ static bool nexthop_can_update(const NextHop *assigned_nexthop, const NextHop *r
         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);
@@ -869,14 +870,21 @@ static void link_mark_nexthops(Link *link, bool foreign) {
                 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;
@@ -886,7 +894,7 @@ static void link_mark_nexthops(Link *link, bool foreign) {
 
         /* 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))
@@ -905,17 +913,8 @@ static void link_mark_nexthops(Link *link, bool foreign) {
                         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;
@@ -926,22 +925,6 @@ int link_drop_nexthops(Link *link, bool foreign) {
         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;
index b918bc6ea3cbb4685750a5c6ccdc6d44915fd58a..b6184503f4f7160f8f21199abc0832c8b20fb529 100644 (file)
@@ -53,14 +53,13 @@ int nexthop_remove(NextHop *nexthop, Manager *manager);
 
 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);
 
index 6769e6ce850c2a1e42320a822dac6cf0d8c7bc85..54d8c9f51f54401dfa87070e430def8113a33c6f 100644 (file)
@@ -1439,10 +1439,10 @@ static int link_unmark_route(Link *link, const Route *route, const RouteNextHop
         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);
@@ -1453,31 +1453,35 @@ static int link_mark_routes(Link *link, bool foreign) {
                 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)
@@ -1489,7 +1493,7 @@ static int link_mark_routes(Link *link, bool foreign) {
 
         /* 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))
@@ -1523,20 +1527,7 @@ static int link_mark_routes(Link *link, bool foreign) {
                 }
         }
 
-        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;
@@ -1547,27 +1538,6 @@ int link_drop_routes(Link *link, bool foreign) {
         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;
index b39e7e25d3e20c3083677eea95e02334fb871ca3..b0da5d80c7343326dee38a7fedbd73a4ed0466b8 100644 (file)
@@ -102,14 +102,13 @@ int route_get_request(Manager *manager, const Route *route, Request **ret);
 
 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,
index e2c76616ddf96a50d91e050df5f938401627214b..1a04af63598dc461418313ed6597981e66f39d01 100644 (file)
@@ -800,21 +800,30 @@ static void manager_unmark_routing_policy_rule(Manager *m, const RoutingPolicyRu
         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))
@@ -824,59 +833,36 @@ static void manager_mark_routing_policy_rules(Manager *m, bool foreign, const Li
         }
 
         /* 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;
index 3b106c11d3331993b6b3c31e694d5480ea02aefe..61609930dba89fb399029cd2190844ba485d4560 100644 (file)
@@ -63,15 +63,14 @@ void network_drop_invalid_routing_policy_rules(Network *network);
 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);