]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
networkctl: do not show zero maximum MTU
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 30 May 2019 18:30:31 +0000 (03:30 +0900)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 31 May 2019 08:55:07 +0000 (10:55 +0200)
src/network/networkctl.c

index 9461155e10907baf33dea4020ddc6b9becadd919..e769baa804ee23941e72dff84ab23fab907a6d30 100644 (file)
@@ -110,7 +110,6 @@ typedef struct LinkInfo {
         uint32_t rx_queues;
 
         bool has_mac_address:1;
-        bool has_mtu:1;
         bool has_tx_queues:1;
         bool has_rx_queues:1;
 } LinkInfo;
@@ -162,14 +161,9 @@ 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;
 
-        info->has_mtu =
-                sd_netlink_message_read_u32(m, IFLA_MTU, &info->mtu) >= 0 &&
-                info->mtu > 0;
-
-        if (info->has_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);
-        }
+        (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);
 
         info->has_rx_queues =
                 sd_netlink_message_read_u32(m, IFLA_NUM_RX_QUEUES, &info->rx_queues) >= 0 &&
@@ -988,15 +982,27 @@ static int link_status_one(
                         return r;
         }
 
-        if (info->has_mtu) {
+        if (info->mtu > 0) {
+                char min_str[DECIMAL_STR_MAX(uint32_t)], max_str[DECIMAL_STR_MAX(uint32_t)];
+
+                xsprintf(min_str, "%" PRIu32, info->min_mtu);
+                xsprintf(max_str, "%" PRIu32, info->max_mtu);
+
                 r = table_add_cell(table, NULL, TABLE_EMPTY, NULL);
                 if (r < 0)
                         return r;
                 r = table_add_cell_full(table, NULL, TABLE_STRING, "MTU:", SIZE_MAX, SIZE_MAX, 0, 100, 0);
                 if (r < 0)
                         return r;
-                r = table_add_cell_stringf(table, NULL, "%" PRIu32 " (Minimum: %" PRIu32 ", Maximum: %" PRIu32 ")",
-                                          info->mtu, info->min_mtu, info->max_mtu);
+                r = table_add_cell_stringf(table, NULL, "%" PRIu32 "%s%s%s%s%s%s%s",
+                                           info->mtu,
+                                           info->min_mtu > 0 || info->max_mtu > 0 ? " (" : "",
+                                           info->min_mtu > 0 ? "Minimum: " : "",
+                                           info->min_mtu > 0 ? min_str : "",
+                                           info->min_mtu > 0 && info->max_mtu > 0 ? ", " : "",
+                                           info->max_mtu > 0 ? "Maximum: " : "",
+                                           info->max_mtu > 0 ? max_str : "",
+                                           info->min_mtu > 0 || info->max_mtu > 0 ? ")" : "");
                 if (r < 0)
                         return r;
         }