]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-network: move link_get_type_string()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 28 Oct 2020 15:14:22 +0000 (00:14 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 29 Oct 2020 05:23:49 +0000 (14:23 +0900)
src/libsystemd-network/network-internal.c
src/libsystemd-network/network-internal.h
src/libsystemd/sd-network/network-util.c
src/libsystemd/sd-network/network-util.h
src/network/networkctl.c

index 1b4358e1399dfd840e678acd791fdddecb8062c0..cb6cff2a97530be24f61a00ecb1e58bfeabaf4c0 100644 (file)
@@ -8,7 +8,6 @@
 #include "sd-ndisc.h"
 
 #include "alloc-util.h"
-#include "arphrd-list.h"
 #include "condition.h"
 #include "conf-parser.h"
 #include "device-util.h"
@@ -18,6 +17,7 @@
 #include "hexdecoct.h"
 #include "log.h"
 #include "network-internal.h"
+#include "network-util.h"
 #include "parse-util.h"
 #include "siphash24.h"
 #include "socket-util.h"
@@ -166,27 +166,6 @@ static const char *const wifi_iftype_table[NL80211_IFTYPE_MAX+1] = {
 
 DEFINE_PRIVATE_STRING_TABLE_LOOKUP_TO_STRING(wifi_iftype, enum nl80211_iftype);
 
-char *link_get_type_string(unsigned short iftype, sd_device *device) {
-        const char *t, *devtype;
-        char *p;
-
-        if (device &&
-            sd_device_get_devtype(device, &devtype) >= 0 &&
-            !isempty(devtype))
-                return strdup(devtype);
-
-        t = arphrd_to_name(iftype);
-        if (!t)
-                return NULL;
-
-        p = strdup(t);
-        if (!p)
-                return NULL;
-
-        ascii_strlower(p);
-        return p;
-}
-
 bool net_match_config(Set *match_mac,
                       Set *match_permanent_mac,
                       char * const *match_paths,
@@ -211,7 +190,7 @@ bool net_match_config(Set *match_mac,
         _cleanup_free_ char *dev_iftype_str;
         const char *dev_path = NULL;
 
-        dev_iftype_str = link_get_type_string(dev_iftype, device);
+        dev_iftype_str = link_get_type_string(device, dev_iftype);
 
         if (device) {
                 const char *mac_str;
index c5530770fd3fe6d0e5685b6746a73d0c32f06a74..90fd2fb2aa35e98012bc2c920441f8dbfb316892 100644 (file)
@@ -11,7 +11,6 @@
 #include "set.h"
 #include "strv.h"
 
-char *link_get_type_string(unsigned short iftype, sd_device *device);
 bool net_match_config(Set *match_mac,
                       Set *match_permanent_mac,
                       char * const *match_paths,
index 0addabe10a2496338e2f9a4182604cb96b0b8a3a..f3d6061578eed3a11f9e59e5dd5f028a1bd0a358 100644 (file)
@@ -1,6 +1,7 @@
 /* SPDX-License-Identifier: LGPL-2.1+ */
 
 #include "alloc-util.h"
+#include "arphrd-list.h"
 #include "fd-util.h"
 #include "network-util.h"
 #include "string-table.h"
@@ -103,3 +104,23 @@ int parse_operational_state_range(const char *str, LinkOperationalStateRange *ou
 
         return 0;
 }
+
+char *link_get_type_string(sd_device *device, unsigned short iftype) {
+        const char *t;
+        char *p;
+
+        if (device &&
+            sd_device_get_devtype(device, &t) >= 0 &&
+            !isempty(t))
+                return strdup(t);
+
+        t = arphrd_to_name(iftype);
+        if (!t)
+                return NULL;
+
+        p = strdup(t);
+        if (!p)
+                return NULL;
+
+        return ascii_strlower(p);
+}
index 425d192f6402a6dc6bdea3d1f98be73427718a71..1422a572790836cb879b40c23e0daa45295e1121 100644 (file)
@@ -1,6 +1,7 @@
 /* SPDX-License-Identifier: LGPL-2.1+ */
 #pragma once
 
+#include "sd-device.h"
 #include "sd-network.h"
 
 #include "macro.h"
@@ -58,3 +59,5 @@ typedef struct LinkOperationalStateRange {
                                                                    LINK_OPERSTATE_ROUTABLE }
 
 int parse_operational_state_range(const char *str, LinkOperationalStateRange *out);
+
+char *link_get_type_string(sd_device *device, unsigned short iftype);
index 86e53e6da426647b94f4dea6e226a376f20face5..476bb0e58de2dd9735bce8aa48afd83136c3977c 100644 (file)
@@ -44,6 +44,7 @@
 #include "main-func.h"
 #include "netlink-util.h"
 #include "network-internal.h"
+#include "network-util.h"
 #include "pager.h"
 #include "parse-util.h"
 #include "pretty-print.h"
@@ -703,7 +704,7 @@ static int list_links(int argc, char *argv[], void *userdata) {
                         setup_state = strdup("unmanaged");
                 setup_state_to_color(setup_state, &on_color_setup, &off_color_setup);
 
-                t = link_get_type_string(links[i].iftype, links[i].sd_device);
+                t = link_get_type_string(links[i].sd_device, links[i].iftype);
 
                 r = table_add_many(table,
                                    TABLE_INT, links[i].ifindex,
@@ -1427,7 +1428,7 @@ static int link_status_one(
                         (void) sd_device_get_property_value(info->sd_device, "ID_MODEL", &model);
         }
 
-        t = link_get_type_string(info->iftype, info->sd_device);
+        t = link_get_type_string(info->sd_device, info->iftype);
 
         (void) sd_network_link_get_network_file(info->ifindex, &network);