summaryrefslogtreecommitdiff
path: root/src/network/networkctl.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/network/networkctl.c')
-rw-r--r--src/network/networkctl.c61
1 files changed, 43 insertions, 18 deletions
diff --git a/src/network/networkctl.c b/src/network/networkctl.c
index d1aec9a7dc..0679114f74 100644
--- a/src/network/networkctl.c
+++ b/src/network/networkctl.c
@@ -53,14 +53,6 @@ static bool arg_no_pager = false;
static bool arg_legend = true;
static bool arg_all = false;
-static void pager_open_if_enabled(void) {
-
- if (arg_no_pager)
- return;
-
- pager_open(false);
-}
-
static int link_get_type_string(unsigned short iftype, sd_device *d, char **ret) {
const char *t;
char *p;
@@ -300,7 +292,7 @@ static int list_links(int argc, char *argv[], void *userdata) {
if (c < 0)
return c;
- pager_open_if_enabled();
+ pager_open(arg_no_pager, false);
if (arg_legend)
printf("%3s %-16s %-18s %-11s %-10s\n",
@@ -854,7 +846,7 @@ static int link_status(int argc, char *argv[], void *userdata) {
_cleanup_free_ LinkInfo *links = NULL;
int r, c, i;
- pager_open_if_enabled();
+ pager_open(arg_no_pager, false);
r = sd_netlink_open(&rtnl);
if (r < 0)
@@ -901,10 +893,43 @@ static char *lldp_capabilities_to_string(uint16_t x) {
return ret;
}
+static void lldp_capabilities_legend(uint16_t x) {
+ unsigned w, i, cols = columns();
+ static const char* const table[] = {
+ "o - Other",
+ "p - Repeater",
+ "b - Bridge",
+ "w - WLAN Access Point",
+ "r - Router",
+ "t - Telephone",
+ "d - DOCSIS cable device",
+ "a - Station",
+ "c - Customer VLAN",
+ "s - Service VLAN",
+ "m - Two-port MAC Relay (TPMR)",
+ };
+
+ if (x == 0)
+ return;
+
+ printf("\nCapability Flags:\n");
+ for (w = 0, i = 0; i < ELEMENTSOF(table); i++)
+ if (x & (1U << i) || arg_all) {
+ bool newline;
+
+ newline = w + strlen(table[i]) + (w == 0 ? 0 : 2) > cols;
+ if (newline)
+ w = 0;
+ w += printf("%s%s%s", newline ? "\n" : "", w == 0 ? "" : "; ", table[i]);
+ }
+ puts("");
+}
+
static int link_lldp_status(int argc, char *argv[], void *userdata) {
_cleanup_(sd_netlink_unrefp) sd_netlink *rtnl = NULL;
_cleanup_free_ LinkInfo *links = NULL;
int i, r, c, m = 0;
+ uint16_t all = 0;
r = sd_netlink_open(&rtnl);
if (r < 0)
@@ -917,7 +942,7 @@ static int link_lldp_status(int argc, char *argv[], void *userdata) {
if (c < 0)
return c;
- pager_open_if_enabled();
+ pager_open(arg_no_pager, false);
if (arg_legend)
printf("%-16s %-17s %-16s %-11s %-17s %-16s\n",
@@ -982,8 +1007,10 @@ static int link_lldp_status(int argc, char *argv[], void *userdata) {
port_description = pdesc;
}
- if (sd_lldp_neighbor_get_enabled_capabilities(n, &cc) >= 0)
+ if (sd_lldp_neighbor_get_enabled_capabilities(n, &cc) >= 0) {
capabilities = lldp_capabilities_to_string(cc);
+ all |= cc;
+ }
printf("%-16s %-17s %-16s %-11s %-17s %-16s\n",
links[i].name,
@@ -997,12 +1024,10 @@ static int link_lldp_status(int argc, char *argv[], void *userdata) {
}
}
- if (arg_legend)
- printf("\nCapability Flags:\n"
- "o - Other; p - Repeater; b - Bridge; w - WLAN Access Point; r - Router;\n"
- "t - Telephone; d - DOCSIS cable device; a - Station; c - Customer VLAN;\n"
- "s - Service VLAN, m - Two-port MAC Relay (TPMR)\n\n"
- "%i neighbors listed.\n", m);
+ if (arg_legend) {
+ lldp_capabilities_legend(all);
+ printf("\n%i neighbors listed.\n", m);
+ }
return 0;
}