]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
wait-online: check received interface name
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 31 Oct 2022 01:25:50 +0000 (10:25 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 1 Nov 2022 13:37:08 +0000 (22:37 +0900)
src/network/wait-online/link.c

index f379578355ca35c9975b03deafefef4b9dc509f4..287a91648d14da12caeff6fdebb93a94234c0f3e 100644 (file)
@@ -64,6 +64,7 @@ Link *link_free(Link *l) {
  }
 
 static int link_update_name(Link *l, sd_netlink_message *m) {
+        char ifname_from_index[IF_NAMESIZE];
         const char *ifname;
         int r;
 
@@ -81,6 +82,18 @@ static int link_update_name(Link *l, sd_netlink_message *m) {
         if (streq(ifname, l->ifname))
                 return 0;
 
+        /* The kernel sometimes sends wrong ifname change. Let's confirm the received name. */
+        r = format_ifname(l->ifindex, ifname_from_index);
+        if (r < 0)
+                return r;
+
+        if (!streq(ifname, ifname_from_index)) {
+                log_link_debug(l, "New interface name '%s' received from the kernel does not correspond "
+                               "with the name currently configured on the actual interface '%s'. Ignoring.",
+                               ifname, ifname_from_index);
+                return 0;
+        }
+
         hashmap_remove(l->manager->links_by_name, l->ifname);
 
         r = free_and_strdup(&l->ifname, ifname);