]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
networkctl: show carrier in green for loopback iface
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 23 Oct 2019 09:10:32 +0000 (11:10 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 23 Oct 2019 09:10:32 +0000 (11:10 +0200)
We don't ever expect anything different, so let's hightlight
that carrier in this case is OK.

src/network/networkctl.c

index 5e8dce0b73c249bad3a10c15f8290eaf68a90ce5..7c8f25ffaee544271b0ea10fc19166aaa2f900ea 100644 (file)
@@ -76,11 +76,12 @@ static char *link_get_type_string(unsigned short iftype, sd_device *d) {
         return p;
 }
 
-static void operational_state_to_color(const char *state, const char **on, const char **off) {
+static void operational_state_to_color(const char *name, const char *state, const char **on, const char **off) {
         assert(on);
         assert(off);
 
-        if (STRPTR_IN_SET(state, "routable", "enslaved")) {
+        if (STRPTR_IN_SET(state, "routable", "enslaved") ||
+            (streq_ptr(name, "lo") && streq_ptr(state, "carrier"))) {
                 *on = ansi_highlight_green();
                 *off = ansi_normal();
         } else if (streq_ptr(state, "degraded")) {
@@ -442,7 +443,7 @@ static int list_links(int argc, char *argv[], void *userdata) {
                 _cleanup_free_ char *t = NULL;
 
                 (void) sd_network_link_get_operational_state(links[i].ifindex, &operational_state);
-                operational_state_to_color(operational_state, &on_color_operational, &off_color_operational);
+                operational_state_to_color(links[i].name, operational_state, &on_color_operational, &off_color_operational);
 
                 r = sd_network_link_get_setup_state(links[i].ifindex, &setup_state);
                 if (r == -ENODATA) /* If there's no info available about this iface, it's unmanaged by networkd */
@@ -1013,7 +1014,7 @@ static int link_status_one(
         assert(info);
 
         (void) sd_network_link_get_operational_state(info->ifindex, &operational_state);
-        operational_state_to_color(operational_state, &on_color_operational, &off_color_operational);
+        operational_state_to_color(info->name, operational_state, &on_color_operational, &off_color_operational);
 
         r = sd_network_link_get_setup_state(info->ifindex, &setup_state);
         if (r == -ENODATA) /* If there's no info available about this iface, it's unmanaged by networkd */
@@ -1368,7 +1369,7 @@ static int system_status(sd_netlink *rtnl, sd_hwdb *hwdb) {
         assert(rtnl);
 
         (void) sd_network_get_operational_state(&operational_state);
-        operational_state_to_color(operational_state, &on_color_operational, &off_color_operational);
+        operational_state_to_color(NULL, operational_state, &on_color_operational, &off_color_operational);
 
         table = table_new("dot", "key", "value");
         if (!table)