udev-builtin-net_id: ignore firmware_node/sun == 0
authorEtienne Champetier <e.champetier@ateme.com>
Thu, 22 Aug 2024 20:30:56 +0000 (16:30 -0400)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 23 Aug 2024 00:30:49 +0000 (09:30 +0900)
Since ID_NET_NAME_SLOT was introduced we ignore slot == 0
https://github.com/systemd/systemd/blob/0035597a30d120f70df2dd7da3d6128fb8ba6051/src/udev/udev-builtin-net_id.c#L139

Qemu sets _SUN to PCI_SLOT() for all NICs, so _SUN is not unique.
https://gitlab.com/qemu-project/qemu/-/issues/2530

In my tests with libvirt I can only set 'slot="0x00"' in interface definition,
so all NICs end up with _SUN == 0, and this commit is enough to avoid the issue.

Fixes 0a4ecc54cb9f2d3418b970c51bfadb69c34ae9eb

src/udev/udev-builtin-net_id.c

index 5094b953734cb812d5d4961e89926e0c1f305381..f88fa0f71dd974cd6de199f367740c3dab619aec 100644 (file)
@@ -577,10 +577,14 @@ static int get_device_firmware_node_sun(sd_device *dev, uint32_t *ret) {
         if (r < 0)
                 return log_device_debug_errno(dev, r, "Failed to read firmware_node/sun, ignoring: %m");
 
-        r = safe_atou32(attr, ret);
+        uint32_t sun;
+        r = safe_atou32(attr, &sun);
         if (r < 0)
                 return log_device_warning_errno(dev, r, "Failed to parse firmware_node/sun '%s', ignoring: %m", attr);
+        if (sun == 0)
+                return log_device_debug_errno(dev, SYNTHETIC_ERRNO(EINVAL), "firmware_node/sun == 0, ignoring: %m");
 
+        *ret = sun;
         return 0;
 }