ethtool-util: introduce ethtool_get_permanent_hw_addr()

And replaces all ethtool_get_permanent_macaddr() with it.
This commit is contained in:
Yu Watanabe
2021-11-13 08:53:33 +09:00
parent 57ae8cd812
commit ed9fa69f1c
6 changed files with 31 additions and 45 deletions
+9 -23
View File
@@ -273,7 +273,7 @@ typedef struct LinkInfo {
int ifindex;
unsigned short iftype;
struct hw_addr_data hw_address;
struct ether_addr permanent_mac_address;
struct hw_addr_data permanent_hw_address;
uint32_t master;
uint32_t mtu;
uint32_t min_mtu;
@@ -348,7 +348,7 @@ typedef struct LinkInfo {
struct ether_addr bssid;
bool has_hw_address:1;
bool has_permanent_mac_address:1;
bool has_permanent_hw_address:1;
bool has_tx_queues:1;
bool has_rx_queues:1;
bool has_stats64:1;
@@ -556,11 +556,10 @@ static int decode_link(sd_netlink_message *m, LinkInfo *info, char **patterns, b
netlink_message_read_hw_addr(m, IFLA_ADDRESS, &info->hw_address) >= 0 &&
info->hw_address.length > 0;
info->has_permanent_mac_address =
ethtool_get_permanent_macaddr(NULL, info->name, &info->permanent_mac_address) >= 0 &&
!ether_addr_is_null(&info->permanent_mac_address) &&
(info->hw_address.length != sizeof(struct ether_addr) ||
memcmp(&info->permanent_mac_address, info->hw_address.bytes, sizeof(struct ether_addr)) != 0);
info->has_permanent_hw_address =
ethtool_get_permanent_hw_addr(NULL, info->name, &info->permanent_hw_address) >= 0 &&
!hw_addr_is_null(&info->permanent_hw_address) &&
!hw_addr_equal(&info->permanent_hw_address, &info->hw_address);
(void) sd_netlink_message_read_u32(m, IFLA_MTU, &info->mtu);
(void) sd_netlink_message_read_u32(m, IFLA_MIN_MTU, &info->min_mtu);
@@ -1710,23 +1709,10 @@ static int link_status_one(
return r;
}
if (info->has_permanent_mac_address) {
_cleanup_free_ char *description = NULL;
(void) ieee_oui(hwdb, &info->permanent_mac_address, &description);
r = table_add_many(table,
TABLE_EMPTY,
TABLE_STRING, "Permanent Hardware Address:");
if (info->has_permanent_hw_address) {
r = dump_hw_address(table, hwdb, "Permanent Hardware Address:", &info->permanent_hw_address);
if (r < 0)
return table_log_add_error(r);
r = table_add_cell_stringf(table, NULL, "%s%s%s%s",
ETHER_ADDR_TO_STR(&info->permanent_mac_address),
description ? " (" : "",
strempty(description),
description ? ")" : "");
if (r < 0)
return table_log_add_error(r);
return r;
}
if (info->mtu > 0) {
+4 -4
View File
@@ -1196,8 +1196,8 @@ static int link_get_network(Link *link, Network **ret) {
r = net_match_config(
&network->match,
link->sd_device,
&link->hw_addr.ether,
&link->permanent_mac,
link->hw_addr.length == ETH_ALEN ? &link->hw_addr.ether : NULL,
link->permanent_hw_addr.length == ETH_ALEN ? &link->permanent_hw_addr.ether : NULL,
link->driver,
link->iftype,
link->ifname,
@@ -2400,9 +2400,9 @@ static int link_new(Manager *manager, sd_netlink_message *message, Link **ret) {
if (r < 0)
return log_link_debug_errno(link, r, "Failed to manage link by its interface name: %m");
r = ethtool_get_permanent_macaddr(&manager->ethtool_fd, link->ifname, &link->permanent_mac);
r = ethtool_get_permanent_hw_addr(&manager->ethtool_fd, link->ifname, &link->permanent_hw_addr);
if (r < 0)
log_link_debug_errno(link, r, "Permanent MAC address not found for new device, continuing without: %m");
log_link_debug_errno(link, r, "Permanent hardware address not found, continuing without: %m");
r = ethtool_get_driver(&manager->ethtool_fd, link->ifname, &link->driver);
if (r < 0)
+1 -1
View File
@@ -55,7 +55,7 @@ typedef struct Link {
char *state_file;
struct hw_addr_data hw_addr;
struct hw_addr_data bcast_addr;
struct ether_addr permanent_mac;
struct hw_addr_data permanent_hw_addr;
struct in6_addr ipv6ll_address;
uint32_t mtu;
uint32_t min_mtu;