]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev-builtin-net_id: introduce device_is_stacked() helper function
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 1 Aug 2023 02:09:25 +0000 (11:09 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 1 Aug 2023 12:34:12 +0000 (21:34 +0900)
Then, we can drop LinkInfo struct.
No functional change, just refactoring.

src/udev/udev-builtin-net_id.c

index 64215834cb7c7772d99ce7f8b7d2cca13358623e..b8b8bfae362138a115da952fa4fa1527816a6a75 100644 (file)
@@ -63,12 +63,6 @@ typedef struct NetNames {
         char bcma_core[ALTIFNAMSIZ];
 } NetNames;
 
-typedef struct LinkInfo {
-        int ifindex;
-        int iflink;
-        int iftype;
-} LinkInfo;
-
 /* skip intermediate virtio devices */
 static sd_device *skip_virtio(sd_device *dev) {
         /* there can only ever be one virtio bus per parent device, so we can
@@ -1287,41 +1281,32 @@ static int get_ifname_prefix(sd_device *dev, const char **ret) {
         }
 }
 
-static int get_link_info(sd_device *dev, LinkInfo *info) {
-        int r;
+static int device_is_stacked(sd_device *dev) {
+        int ifindex, iflink, r;
 
         assert(dev);
-        assert(info);
-
-        r = sd_device_get_ifindex(dev, &info->ifindex);
-        if (r < 0)
-                return r;
 
-        r = device_get_sysattr_int(dev, "iflink", &info->iflink);
+        r = sd_device_get_ifindex(dev, &ifindex);
         if (r < 0)
                 return r;
 
-        r = device_get_sysattr_int(dev, "type", &info->iftype);
+        r = device_get_sysattr_int(dev, "iflink", &iflink);
         if (r < 0)
                 return r;
 
-        return 0;
+        return ifindex != iflink;
 }
 
 static int builtin_net_id(UdevEvent *event, int argc, char *argv[], bool test) {
         sd_device *dev = ASSERT_PTR(ASSERT_PTR(event)->dev);
         const char *prefix;
         NetNames names = {};
-        LinkInfo info = {};
         int r;
 
-        r = get_link_info(dev, &info);
-        if (r < 0)
-                return r;
-
         /* skip stacked devices, like VLANs, ... */
-        if (info.ifindex != info.iflink)
-                return 0;
+        r = device_is_stacked(dev);
+        if (r != 0)
+                return r;
 
         r = get_ifname_prefix(dev, &prefix);
         if (r < 0) {