]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev-builtin-net_id: make names_netdevsim() self-contained
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 27 Sep 2022 07:55:09 +0000 (16:55 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 29 Jul 2023 13:14:24 +0000 (22:14 +0900)
It is not necessary to store its partial result into NetNames.

No functional changes, just refactoring.

src/udev/udev-builtin-net_id.c

index 8a53323077b2bfe803598e6356e0330590d55200..31202567a2e463b2a7a4bc9fbb08ccd2a6e08433 100644 (file)
@@ -49,7 +49,6 @@ typedef enum NetNameType {
         NET_USB,
         NET_BCMA,
         NET_XENVIF,
-        NET_NETDEVSIM,
 } NetNameType;
 
 typedef struct NetNames {
@@ -64,7 +63,6 @@ typedef struct NetNames {
         char usb_ports[ALTIFNAMSIZ];
         char bcma_core[ALTIFNAMSIZ];
         char xen_slot[ALTIFNAMSIZ];
-        char netdevsim_path[ALTIFNAMSIZ];
 } NetNames;
 
 typedef struct LinkInfo {
@@ -1037,21 +1035,19 @@ static int names_mac(sd_device *dev, const char *prefix, bool test) {
         return 0;
 }
 
-static int names_netdevsim(sd_device *dev, const LinkInfo *info, NetNames *names) {
+static int names_netdevsim(sd_device *dev, const char *prefix, bool test) {
         sd_device *netdevsimdev;
-        const char *sysname;
+        const char *sysname, *phys_port_name;
         unsigned addr;
         int r;
 
-        if (!naming_scheme_has(NAMING_NETDEVSIM))
-                return 0;
-
         assert(dev);
-        assert(info);
-        assert(names);
+        assert(prefix);
 
-        if (isempty(info->phys_port_name))
-                return -EINVAL;
+        /* get netdevsim path names */
+
+        if (!naming_scheme_has(NAMING_NETDEVSIM))
+                return 0;
 
         r = sd_device_get_parent_with_subsystem_devtype(dev, "netdevsim", NULL, &netdevsimdev);
         if (r < 0)
@@ -1063,11 +1059,17 @@ static int names_netdevsim(sd_device *dev, const LinkInfo *info, NetNames *names
         if (sscanf(sysname, "netdevsim%u", &addr) != 1)
                 return -EINVAL;
 
-        if (!snprintf_ok(names->netdevsim_path, sizeof(names->netdevsim_path), "i%un%s", addr, info->phys_port_name))
-                return -ENOBUFS;
-
-        names->type = NET_NETDEVSIM;
+        r = sd_device_get_sysattr_value(dev, "phys_port_name", &phys_port_name);
+        if (r < 0)
+                return r;
+        if (isempty(phys_port_name))
+                return -EOPNOTSUPP;
 
+        char str[ALTIFNAMSIZ];
+        if (snprintf_ok(str, sizeof str, "%si%un%s", prefix, addr, phys_port_name))
+                udev_builtin_add_property(dev, test, "ID_NET_NAME_PATH", str);
+        log_device_debug(dev, "Netdevsim identifier: address=%u, port_name=%s %s %s",
+                         addr, phys_port_name, special_glyph(SPECIAL_GLYPH_ARROW_RIGHT), str + strlen(prefix));
         return 0;
 }
 
@@ -1224,16 +1226,7 @@ static int builtin_net_id(UdevEvent *event, int argc, char *argv[], bool test) {
         (void) names_ccw(dev, prefix, test);
         (void) names_vio(dev, prefix, test);
         (void) names_platform(dev, prefix, test);
-
-        /* get netdevsim path names */
-        if (names_netdevsim(dev, &info, &names) >= 0 && names.type == NET_NETDEVSIM) {
-                char str[ALTIFNAMSIZ];
-
-                if (snprintf_ok(str, sizeof str, "%s%s", prefix, names.netdevsim_path))
-                        udev_builtin_add_property(dev, test, "ID_NET_NAME_PATH", str);
-
-                return 0;
-        }
+        (void) names_netdevsim(dev, prefix, test);
 
         /* get xen vif "slot" based names. */
         if (names_xen(dev, &names) >= 0 && names.type == NET_XENVIF) {