]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: use newly loaded Network object if a referenced NetDev object is updated 34933/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 28 Oct 2024 13:39:15 +0000 (22:39 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 30 Oct 2024 15:58:47 +0000 (00:58 +0900)
Even if .network file is not updated, referenced NetDev object may be
different. In that case, let's use the newly loaded Network object.

src/network/networkd-network.c

index 82c6d20dec766f0c8dbd106ff4b1677a31cf76f5..9cd683e9bc8c4b986c2f713bdeb1e4c66d9b4b4e 100644 (file)
@@ -617,6 +617,28 @@ int network_load(Manager *manager, OrderedHashmap **ret) {
         return 0;
 }
 
+static bool network_netdev_equal(Network *a, Network *b) {
+        assert(a);
+        assert(b);
+
+        if (a->batadv != b->batadv ||
+            a->bridge != b->bridge ||
+            a->bond != b->bond ||
+            a->vrf != b->vrf ||
+            a->xfrm != b->xfrm)
+                return false;
+
+        if (hashmap_size(a->stacked_netdevs) != hashmap_size(b->stacked_netdevs))
+                return false;
+
+        NetDev *n;
+        HASHMAP_FOREACH(n, a->stacked_netdevs)
+                if (hashmap_get(b->stacked_netdevs, n->ifname) != n)
+                        return false;
+
+        return true;
+}
+
 int network_reload(Manager *manager) {
         OrderedHashmap *new_networks = NULL;
         Network *n, *old;
@@ -631,15 +653,21 @@ int network_reload(Manager *manager) {
         ORDERED_HASHMAP_FOREACH(n, new_networks) {
                 r = network_get_by_name(manager, n->name, &old);
                 if (r < 0) {
-                        log_debug("Found new .network file: %s", n->filename);
+                        log_debug("%s: Found new .network file.", n->filename);
                         continue;
                 }
 
                 if (!stats_by_path_equal(n->stats_by_path, old->stats_by_path)) {
-                        log_debug("Found updated .network file: %s", n->filename);
+                        log_debug("%s: Found updated .network file.", n->filename);
+                        continue;
+                }
+
+                if (!network_netdev_equal(n, old)) {
+                        log_debug("%s: Detected update of referenced .netdev file(s).", n->filename);
                         continue;
                 }
 
+                /* Nothing updated, use the existing Network object, and drop the new one. */
                 r = ordered_hashmap_replace(new_networks, old->name, old);
                 if (r < 0)
                         goto failure;