diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2020-02-27 21:56:36 +0900 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-03-02 08:52:18 +0100 |
commit | ef62949a23a2d6dc722659cc527f6e0006135dc9 (patch) | |
tree | 1419f37b0e27d5e52ca29882135f46522f7eeb41 /src/libsystemd-network | |
parent | ed87ce1d5d93e10fb712e3839606248a7d20a1ce (diff) | |
download | systemd-ef62949a23a2d6dc722659cc527f6e0006135dc9.tar.gz |
network: make Type=ether match based on iftype
This makes Type= can match the type shown in networkctl.
Closes #14952.
Diffstat (limited to 'src/libsystemd-network')
-rw-r--r-- | src/libsystemd-network/network-internal.c | 30 | ||||
-rw-r--r-- | src/libsystemd-network/network-internal.h | 2 |
2 files changed, 29 insertions, 3 deletions
diff --git a/src/libsystemd-network/network-internal.c b/src/libsystemd-network/network-internal.c index 0bf0b0e552..13a0a5d929 100644 --- a/src/libsystemd-network/network-internal.c +++ b/src/libsystemd-network/network-internal.c @@ -8,6 +8,7 @@ #include "sd-ndisc.h" #include "alloc-util.h" +#include "arphrd-list.h" #include "condition.h" #include "conf-parser.h" #include "device-util.h" @@ -166,6 +167,27 @@ 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, @@ -176,6 +198,7 @@ bool net_match_config(Set *match_mac, char * const *match_wifi_iftype, char * const *match_ssid, Set *match_bssid, + unsigned short iftype, sd_device *device, const struct ether_addr *dev_mac, const struct ether_addr *dev_permanent_mac, @@ -185,13 +208,14 @@ bool net_match_config(Set *match_mac, const char *ssid, const struct ether_addr *bssid) { - const char *dev_path = NULL, *dev_driver = NULL, *dev_type = NULL, *mac_str; + const char *dev_path = NULL, *dev_driver = NULL, *mac_str; + _cleanup_free_ char *dev_type; + + dev_type = link_get_type_string(iftype, device); if (device) { (void) sd_device_get_property_value(device, "ID_PATH", &dev_path); (void) sd_device_get_property_value(device, "ID_NET_DRIVER", &dev_driver); - (void) sd_device_get_devtype(device, &dev_type); - if (!dev_name) (void) sd_device_get_sysname(device, &dev_name); if (!dev_mac && diff --git a/src/libsystemd-network/network-internal.h b/src/libsystemd-network/network-internal.h index dff6c8831a..593bad2230 100644 --- a/src/libsystemd-network/network-internal.h +++ b/src/libsystemd-network/network-internal.h @@ -15,6 +15,7 @@ #define LINK_BRIDGE_PORT_PRIORITY_INVALID 128 #define LINK_BRIDGE_PORT_PRIORITY_MAX 63 +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_path, @@ -25,6 +26,7 @@ bool net_match_config(Set *match_mac, char * const *match_wifi_iftype, char * const *match_ssid, Set *match_bssid, + unsigned short iftype, sd_device *device, const struct ether_addr *dev_mac, const struct ether_addr *dev_permanent_mac, |