It is useful to color in the admin state both to easily spot failed links, but also to quickly
distinguish between links that are fully configured and in degraded mode (only IPv4LL) or in
degraded mode and still waiting for DHCP.
- printf("%3s %-16s %-10s %-10s %-10s\n", "IDX", "LINK", "TYPE", "ADMIN", "OPERATIONAL");
+ printf("%3s %-16s %-10s %-11s %-10s\n", "IDX", "LINK", "TYPE", "ADMIN", "OPERATIONAL");
c = decode_and_sort_links(reply, &links);
if (c < 0)
c = decode_and_sort_links(reply, &links);
if (c < 0)
for (i = 0; i < c; i++) {
_cleanup_free_ char *state = NULL, *operational_state = NULL;
_cleanup_udev_device_unref_ struct udev_device *d = NULL;
for (i = 0; i < c; i++) {
_cleanup_free_ char *state = NULL, *operational_state = NULL;
_cleanup_udev_device_unref_ struct udev_device *d = NULL;
- const char *on_color = "", *off_color = "";
+ const char *on_color_oper = "", *off_color_oper = "",
+ *on_color = "", *off_color = "";
char devid[2 + DECIMAL_STR_MAX(int)];
_cleanup_free_ char *t = NULL;
char devid[2 + DECIMAL_STR_MAX(int)];
_cleanup_free_ char *t = NULL;
link_get_type_string(links[i].iftype, d, &t);
if (streq_ptr(operational_state, "routable")) {
link_get_type_string(links[i].iftype, d, &t);
if (streq_ptr(operational_state, "routable")) {
+ on_color_oper = ansi_highlight_green();
+ off_color_oper = ansi_highlight_off();
+ } else if (streq_ptr(operational_state, "degraded")) {
+ on_color_oper = ansi_highlight_yellow();
+ off_color_oper = ansi_highlight_off();
+ }
+
+ if (streq_ptr(state, "configured")) {
on_color = ansi_highlight_green();
off_color = ansi_highlight_off();
on_color = ansi_highlight_green();
off_color = ansi_highlight_off();
- } else if (streq_ptr(operational_state, "degraded")) {
+ } else if (streq_ptr(state, "configuring")) {
on_color = ansi_highlight_yellow();
off_color = ansi_highlight_off();
on_color = ansi_highlight_yellow();
off_color = ansi_highlight_off();
+ } else if (streq_ptr(state, "failed") ||
+ streq_ptr(state, "linger")) {
+ on_color = ansi_highlight_red();
+ off_color = ansi_highlight_off();
- printf("%3i %-16s %-10s %-10s %s%-10s%s\n", links[i].ifindex, links[i].name, strna(t), strna(state), on_color, strna(operational_state), off_color);
+ printf("%3i %-16s %-10s %s%-11s%s %s%-10s%s\n", links[i].ifindex,
+ links[i].name, strna(t), on_color, strna(state), off_color,
+ on_color_oper, strna(operational_state), off_color_oper);