diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2021-11-13 08:45:28 +0900 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2021-11-13 08:53:33 +0900 |
commit | 57ae8cd8125d46455f5bc46cd8166f2a9fff6b5f (patch) | |
tree | 66c501bf35af30554be9e99e20d67edf11241080 /src/network/networkctl.c | |
parent | 0881991c3236a894378167ea9006dbf15a56ba58 (diff) | |
download | systemd-57ae8cd8125d46455f5bc46cd8166f2a9fff6b5f.tar.gz |
networkctl: introduce dump_hw_address()
Diffstat (limited to 'src/network/networkctl.c')
-rw-r--r-- | src/network/networkctl.c | 54 |
1 files changed, 34 insertions, 20 deletions
diff --git a/src/network/networkctl.c b/src/network/networkctl.c index b47cd8cd7b..abf8e234b0 100644 --- a/src/network/networkctl.c +++ b/src/network/networkctl.c @@ -347,7 +347,7 @@ typedef struct LinkInfo { char *ssid; struct ether_addr bssid; - bool has_mac_address:1; + bool has_hw_address:1; bool has_permanent_mac_address:1; bool has_tx_queues:1; bool has_rx_queues:1; @@ -552,7 +552,7 @@ static int decode_link(sd_netlink_message *m, LinkInfo *info, char **patterns, b info->ifindex = ifindex; info->alternative_names = TAKE_PTR(altnames); - info->has_mac_address = + info->has_hw_address = netlink_message_read_hw_addr(m, IFLA_ADDRESS, &info->hw_address) >= 0 && info->hw_address.length > 0; @@ -1457,6 +1457,34 @@ static int dump_statistics(Table *table, const LinkInfo *info) { return 0; } +static int dump_hw_address(Table *table, sd_hwdb *hwdb, const char *field, const struct hw_addr_data *addr) { + _cleanup_free_ char *description = NULL; + int r; + + assert(table); + assert(field); + assert(addr); + + if (addr->length == ETH_ALEN) + (void) ieee_oui(hwdb, &addr->ether, &description); + + r = table_add_many(table, + TABLE_EMPTY, + TABLE_STRING, field); + if (r < 0) + return table_log_add_error(r); + + r = table_add_cell_stringf(table, NULL, "%s%s%s%s", + HW_ADDR_TO_STR(addr), + description ? " (" : "", + strempty(description), + description ? ")" : ""); + if (r < 0) + return table_log_add_error(r); + + return 0; +} + static OutputFlags get_output_flags(void) { return arg_all * OUTPUT_SHOW_ALL | @@ -1676,24 +1704,10 @@ static int link_status_one( return table_log_add_error(r); } - if (info->has_mac_address) { - _cleanup_free_ char *description = NULL; - - if (info->hw_address.length == ETH_ALEN) - (void) ieee_oui(hwdb, &info->hw_address.ether, &description); - - r = table_add_many(table, - TABLE_EMPTY, - TABLE_STRING, "HW Address:"); - if (r < 0) - return table_log_add_error(r); - r = table_add_cell_stringf(table, NULL, "%s%s%s%s", - HW_ADDR_TO_STR(&info->hw_address), - description ? " (" : "", - strempty(description), - description ? ")" : ""); + if (info->has_hw_address) { + r = dump_hw_address(table, hwdb, "Hardware Address:", &info->hw_address); if (r < 0) - return table_log_add_error(r); + return r; } if (info->has_permanent_mac_address) { @@ -1703,7 +1717,7 @@ static int link_status_one( r = table_add_many(table, TABLE_EMPTY, - TABLE_STRING, "HW Permanent Address:"); + TABLE_STRING, "Permanent Hardware Address:"); if (r < 0) return table_log_add_error(r); r = table_add_cell_stringf(table, NULL, "%s%s%s%s", |