blob: 8e890134afefce92665f09f4028069f3db698289 [file] [log] [blame]
Tomáš Pecka5e070252022-05-20 20:41:21 +02001From de6ad887e413ee3e66e368f707e08ea84aa72a91 Mon Sep 17 00:00:00 2001
Tomáš Peckaae301762021-10-13 10:50:37 +02002From: Tomas Pecka <peckato1@users.noreply.github.com>
3Date: Wed, 15 Sep 2021 14:30:19 +0200
4Subject: [PATCH 8/9] networkctl: allow format LLDP capabilities string without
5 dots
6
7Allows formatting the LLDP capabilities string without the dots
8representing "not enabled" (just omit them).
9---
10 src/network/networkctl.c | 15 +++++++++------
11 1 file changed, 9 insertions(+), 6 deletions(-)
12
13diff --git a/src/network/networkctl.c b/src/network/networkctl.c
Václav Kubernát8cd61562021-12-08 13:27:31 +010014index a10f3f3fc7..9fbeed6908 100644
Tomáš Peckaae301762021-10-13 10:50:37 +020015--- a/src/network/networkctl.c
16+++ b/src/network/networkctl.c
Václav Kubernát8cd61562021-12-08 13:27:31 +010017@@ -2431,21 +2431,24 @@ static int link_status(int argc, char *argv[], void *userdata) {
Tomáš Peckaae301762021-10-13 10:50:37 +020018 return 0;
19 }
20
21-static char *lldp_capabilities_to_string(uint16_t x) {
22+static char *lldp_capabilities_to_string(uint16_t x, bool dots) {
23 static const char characters[] = {
24 'o', 'p', 'b', 'w', 'r', 't', 'd', 'a', 'c', 's', 'm',
25 };
26 char *ret;
27- unsigned i;
28+ unsigned i, j;
29
30 ret = new(char, ELEMENTSOF(characters) + 1);
31 if (!ret)
32 return NULL;
33
34- for (i = 0; i < ELEMENTSOF(characters); i++)
35- ret[i] = (x & (1U << i)) ? characters[i] : '.';
36+ for (i = 0, j = 0; i < ELEMENTSOF(characters); i++)
37+ if (x & (1U << i))
38+ ret[j++] = characters[i];
39+ else if (dots)
40+ ret[j++] = '.';
41
42- ret[i] = 0;
43+ ret[j] = 0;
44 return ret;
45 }
46
Václav Kubernát8cd61562021-12-08 13:27:31 +010047@@ -2537,7 +2540,7 @@ static int lldp_neighbors_varlink_reply(Varlink *link, JsonVariant *parameters,
Tomáš Peckaae301762021-10-13 10:50:37 +020048 return r;
49
50 if (udata->table) {
51- capabilities = lldp_capabilities_to_string(entry.capabilities);
52+ capabilities = lldp_capabilities_to_string(entry.capabilities, true);
53
54 r = table_add_many(udata->table,
55 TABLE_STRING, udata->link_name,
56--
Tomáš Pecka5e070252022-05-20 20:41:21 +0200572.35.1
Tomáš Peckaae301762021-10-13 10:50:37 +020058