]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
networkctl: show permanent mac address if it is not used now 14448/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 7 Jan 2019 11:16:20 +0000 (20:16 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 8 Jan 2020 08:54:59 +0000 (17:54 +0900)
src/network/networkctl.c

index 668ec1045d7a49f3739119c56a3a1818535e8f61..244fb0848cbab22edb59010628d2adee52b6d789 100644 (file)
@@ -134,6 +134,7 @@ typedef struct LinkInfo {
         int ifindex;
         unsigned short iftype;
         struct ether_addr mac_address;
+        struct ether_addr permanent_mac_address;
         uint32_t mtu;
         uint32_t min_mtu;
         uint32_t max_mtu;
@@ -173,6 +174,7 @@ typedef struct LinkInfo {
         struct ether_addr bssid;
 
         bool has_mac_address:1;
+        bool has_permanent_mac_address:1;
         bool has_tx_queues:1;
         bool has_rx_queues:1;
         bool has_stats64:1;
@@ -318,6 +320,12 @@ static int decode_link(sd_netlink_message *m, LinkInfo *info, char **patterns) {
                 sd_netlink_message_read_ether_addr(m, IFLA_ADDRESS, &info->mac_address) >= 0 &&
                 memcmp(&info->mac_address, &ETHER_ADDR_NULL, sizeof(struct ether_addr)) != 0;
 
+        _cleanup_close_ int fd = -1;
+        info->has_permanent_mac_address =
+                ethtool_get_permanent_macaddr(&fd, info->name, &info->permanent_mac_address) >= 0 &&
+                memcmp(&info->permanent_mac_address, &ETHER_ADDR_NULL, sizeof(struct ether_addr)) != 0 &&
+                memcmp(&info->permanent_mac_address, &info->mac_address, sizeof(struct ether_addr)) != 0;
+
         (void) sd_netlink_message_read_u32(m, IFLA_MTU, &info->mtu);
         (void) sd_netlink_message_read_u32(m, IFLA_MIN_MTU, &info->min_mtu);
         (void) sd_netlink_message_read_u32(m, IFLA_MAX_MTU, &info->max_mtu);
@@ -1228,6 +1236,26 @@ static int link_status_one(
                         return r;
         }
 
+        if (info->has_permanent_mac_address) {
+                _cleanup_free_ char *description = NULL;
+                char ea[ETHER_ADDR_TO_STRING_MAX];
+
+                (void) ieee_oui(hwdb, &info->permanent_mac_address, &description);
+
+                r = table_add_many(table,
+                                   TABLE_EMPTY,
+                                   TABLE_STRING, "HW Permanent Address:");
+                if (r < 0)
+                        return r;
+                r = table_add_cell_stringf(table, NULL, "%s%s%s%s",
+                                           ether_addr_to_string(&info->permanent_mac_address, ea),
+                                           description ? " (" : "",
+                                           strempty(description),
+                                           description ? ")" : "");
+                if (r < 0)
+                        return r;
+        }
+
         if (info->mtu > 0) {
                 char min_str[DECIMAL_STR_MAX(uint32_t)], max_str[DECIMAL_STR_MAX(uint32_t)];