sd-network: move link_get_type_string()
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user