]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: do not remove rule when it is requested by existing links
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 22 Feb 2019 04:32:47 +0000 (13:32 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 27 Feb 2019 01:59:10 +0000 (10:59 +0900)
Otherwise, the first link once removes all saved rules in the foreign
rule database, and the second or later links create again...

src/network/networkd-routing-policy-rule.c

index 3941245733fc393e744d7ac395dee8e8a357d793..ae94272781e29223cca010c9acd1d0d8744cb1c4 100644 (file)
@@ -1234,6 +1234,26 @@ int routing_policy_load_rules(const char *state_file, Set **rules) {
         return 0;
 }
 
+static bool manager_links_have_routing_policy_rule(Manager *m, RoutingPolicyRule *rule) {
+        RoutingPolicyRule *link_rule;
+        Iterator i;
+        Link *link;
+
+        assert(m);
+        assert(rule);
+
+        HASHMAP_FOREACH(link, m->links, i) {
+                if (!link->network)
+                        continue;
+
+                LIST_FOREACH(rules, link_rule, link->network->rules)
+                        if (routing_policy_rule_compare_func(link_rule, rule) == 0)
+                                return true;
+        }
+
+        return false;
+}
+
 void routing_policy_rule_purge(Manager *m, Link *link) {
         RoutingPolicyRule *rule, *existing;
         Iterator i;
@@ -1247,6 +1267,12 @@ void routing_policy_rule_purge(Manager *m, Link *link) {
                 if (!existing)
                         continue; /* Saved rule does not exist anymore. */
 
+                if (manager_links_have_routing_policy_rule(m, existing))
+                        continue; /* Existing links have the saved rule. */
+
+                /* Existing links do not have the saved rule. Let's drop the rule now, and re-configure it
+                 * later when it is requested. */
+
                 r = routing_policy_rule_remove(existing, link, NULL);
                 if (r < 0) {
                         log_warning_errno(r, "Could not remove routing policy rules: %m");