summaryrefslogtreecommitdiffstats
path: root/src/libsystemd/sd-network
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2020-10-28 16:14:22 +0100
committerYu Watanabe <watanabe.yu+github@gmail.com>2020-10-29 06:23:49 +0100
commit1929ed0e5897222422fc6e5c1d7b17ec9c1e36af (patch)
tree28be8e8e372103ffe659406e399894cc586dcf01 /src/libsystemd/sd-network
parentlibsystemd-network: move config_parse_hwaddr() and config_parse_hwaddrs() (diff)
downloadsystemd-1929ed0e5897222422fc6e5c1d7b17ec9c1e36af.tar.xz
systemd-1929ed0e5897222422fc6e5c1d7b17ec9c1e36af.zip
sd-network: move link_get_type_string()
Diffstat (limited to 'src/libsystemd/sd-network')
-rw-r--r--src/libsystemd/sd-network/network-util.c21
-rw-r--r--src/libsystemd/sd-network/network-util.h3
2 files changed, 24 insertions, 0 deletions
diff --git a/src/libsystemd/sd-network/network-util.c b/src/libsystemd/sd-network/network-util.c
index 0addabe10a..f3d6061578 100644
--- a/src/libsystemd/sd-network/network-util.c
+++ b/src/libsystemd/sd-network/network-util.c
@@ -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);
+}
diff --git a/src/libsystemd/sd-network/network-util.h b/src/libsystemd/sd-network/network-util.h
index 425d192f64..1422a57279 100644
--- a/src/libsystemd/sd-network/network-util.h
+++ b/src/libsystemd/sd-network/network-util.h
@@ -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);