From f119082e7a1ccfbf50c30a99819b6e303cdf09a1 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Mon, 29 Jan 2018 21:01:46 +0100 Subject: [PATCH] networkd: simplify and display all devtypes Every place the kernel actually calls SET_NETDEV_DEVTYPE, it's adding a piece of information that looks useful and relevant for us to use. So let's use it when it's there. The previous matching based on the corresponding ARPHRD didn't really make much sense. The more sensible logic for getting a textual representation of the link type is to see if the kernel supplies a devtype. If it does, great. If not, then we can fall back on the ARPHRD, as before. Signed-off-by: Jason A. Donenfeld --- src/network/networkctl.c | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/src/network/networkctl.c b/src/network/networkctl.c index 6ce00df..8a08304 100644 --- a/src/network/networkctl.c +++ b/src/network/networkctl.c @@ -63,28 +63,11 @@ static int link_get_type_string(unsigned short iftype, sd_device *d, char **ret) assert(ret); if (d) { - const char *devtype = NULL, *id = NULL; + const char *devtype = NULL; (void) sd_device_get_devtype(d, &devtype); - - /* WLANs have iftype ARPHRD_ETHER, but we want - * to show a more useful type string for - * them */ - if (iftype == ARPHRD_ETHER) { - if (streq_ptr(devtype, "wlan")) - id = "wlan"; - else if (streq_ptr(devtype, "wwan")) - id = "wwan"; - } - - /* Likewise, WireGuard has iftype ARPHRD_NONE, - * since it's layer 3, but we of course want - * something more useful than that. */ - if (iftype == ARPHRD_NONE && streq_ptr(devtype, "wireguard")) - id = "wireguard"; - - if (id) { - p = strdup(id); + if (!isempty(devtype)) { + p = strdup(devtype); if (!p) return -ENOMEM; -- 2.7.4