1 From 0e355867f211a922c5b21ddbbb073eb2c35430b9 Mon Sep 17 00:00:00 2001
2 From: "Sar Ashki, Babak" <Babak.SarAshki@windriver.com>
3 Date: Mon, 24 Feb 2020 06:01:03 -0800
4 Subject: [PATCH] lldpd client add show interfaces cmd from upstream
6 commit a54f6012efff77c966f533b8ef35b8627e3c8212
8 src/client/client.h | 2 +
9 src/client/display.c | 99 ++++++++++++++++++++++++++++++++++-------
10 src/client/lldpcli.8.in | 20 +++++++++
11 src/client/show.c | 44 ++++++++++++++++++
12 src/daemon/lldpd.c | 1 +
13 5 files changed, 151 insertions(+), 15 deletions(-)
15 diff --git a/src/client/client.h b/src/client/client.h
16 index e3ee352..8da3e3f 100644
17 --- a/src/client/client.h
18 +++ b/src/client/client.h
19 @@ -131,6 +131,8 @@ void display_interfaces_stats(lldpctl_conn_t *, struct writer *,
21 void display_interface_stats(lldpctl_conn_t *, struct writer *,
23 +void display_local_interfaces(lldpctl_conn_t *, struct writer *,
24 + struct cmd_env *, int, int);
28 diff --git a/src/client/display.c b/src/client/display.c
29 index cbd0e31..2769890 100644
30 --- a/src/client/display.c
31 +++ b/src/client/display.c
32 @@ -349,7 +349,8 @@ display_port(struct writer *w, lldpctl_atom_t *port, int details)
34 tag_datatag(w, "descr", "PortDescr",
35 lldpctl_atom_get_str(port, lldpctl_k_port_descr));
38 + lldpctl_atom_get_int(port, lldpctl_k_port_ttl) > 0)
39 tag_datatag(w, "ttl", "TTL",
40 lldpctl_atom_get_str(port, lldpctl_k_port_ttl));
42 @@ -473,6 +474,38 @@ display_port(struct writer *w, lldpctl_atom_t *port, int details)
47 +display_local_ttl(struct writer *w, lldpctl_conn_t *conn, int details)
51 + long int tx_interval;
53 + lldpctl_atom_t *configuration;
54 + configuration = lldpctl_get_configuration(conn);
55 + if (!configuration) {
56 + log_warnx("lldpctl", "not able to get configuration. %s",
57 + lldpctl_last_strerror(conn));
61 + tx_hold = lldpctl_atom_get_int(configuration, lldpctl_k_config_tx_hold);
62 + tx_interval = lldpctl_atom_get_int(configuration, lldpctl_k_config_tx_interval);
64 + if (asprintf(&ttl, "%lu", tx_hold*tx_interval) == -1) {
65 + log_warnx("lldpctl", "not enough memory to build TTL.");
69 + tag_start(w, "ttl", "TTL");
70 + tag_attr(w, "ttl", "", ttl);
74 + lldpctl_atom_dec_ref(configuration);
79 display_vlans(struct writer *w, lldpctl_atom_t *port)
81 @@ -582,43 +615,51 @@ display_local_chassis(lldpctl_conn_t *conn, struct writer *w,
84 display_interface(lldpctl_conn_t *conn, struct writer *w, int hidden,
85 - lldpctl_atom_t *iface, lldpctl_atom_t *neighbor, int details, int protocol)
86 + lldpctl_atom_t *iface, lldpctl_atom_t *port, int details, int protocol)
91 - lldpctl_atom_get_int(neighbor, lldpctl_k_port_hidden))
92 + lldpctl_atom_get_int(port, lldpctl_k_port_hidden))
95 /* user might have specified protocol to filter on display */
96 if ((protocol != LLDPD_MODE_MAX) &&
97 - (protocol != lldpctl_atom_get_int(neighbor, lldpctl_k_port_protocol)))
98 + (protocol != lldpctl_atom_get_int(port, lldpctl_k_port_protocol)))
101 - lldpctl_atom_t *chassis = lldpctl_atom_get(neighbor, lldpctl_k_port_chassis);
102 + /* Infer local / remote port from the port index (remote == 0) */
103 + local = lldpctl_atom_get_int(port, lldpctl_k_port_index)>0?1:0;
105 + lldpctl_atom_t *chassis = lldpctl_atom_get(port, lldpctl_k_port_chassis);
107 tag_start(w, "interface", "Interface");
108 tag_attr(w, "name", "",
109 lldpctl_atom_get_str(iface, lldpctl_k_interface_name));
110 tag_attr(w, "via" , "via",
111 - lldpctl_atom_get_str(neighbor, lldpctl_k_port_protocol));
112 + lldpctl_atom_get_str(port, lldpctl_k_port_protocol));
113 if (details > DISPLAY_BRIEF) {
114 - tag_attr(w, "rid" , "RID",
115 - lldpctl_atom_get_str(chassis, lldpctl_k_chassis_index));
117 + tag_attr(w, "rid" , "RID",
118 + lldpctl_atom_get_str(chassis, lldpctl_k_chassis_index));
119 tag_attr(w, "age" , "Time",
120 - display_age(lldpctl_atom_get_int(neighbor, lldpctl_k_port_age)));
121 + display_age(lldpctl_atom_get_int(port, lldpctl_k_port_age)));
124 display_chassis(w, chassis, details);
125 - display_port(w, neighbor, details);
126 + display_port(w, port, details);
127 + if (details && local)
128 + display_local_ttl(w, conn, details);
129 if (details == DISPLAY_DETAILS) {
130 - display_vlans(w, neighbor);
131 - display_ppvids(w, neighbor);
132 - display_pids(w, neighbor);
133 - display_med(w, neighbor, chassis);
134 + display_vlans(w, port);
135 + display_ppvids(w, port);
136 + display_pids(w, port);
137 + display_med(w, port, chassis);
140 lldpctl_atom_dec_ref(chassis);
142 - display_custom_tlvs(w, neighbor);
143 + display_custom_tlvs(w, port);
147 @@ -675,6 +716,34 @@ display_interfaces(lldpctl_conn_t *conn, struct writer *w,
153 + * Display information about local interfaces.
155 + * @param conn Connection to lldpd.
157 + * @param hidden Whatever to show hidden ports.
158 + * @param env Environment from which we may find the list of ports.
159 + * @param details Level of details we need (DISPLAY_*).
162 +display_local_interfaces(lldpctl_conn_t *conn, struct writer *w,
163 + struct cmd_env *env,
164 + int hidden, int details)
166 + lldpctl_atom_t *iface;
167 + int protocol = LLDPD_MODE_MAX;
169 + tag_start(w, "lldp", "LLDP interfaces");
170 + while ((iface = cmd_iterate_on_interfaces(conn, env))) {
171 + lldpctl_atom_t *port;
172 + port = lldpctl_get_port(iface);
173 + display_interface(conn, w, hidden, iface, port, details, protocol);
174 + lldpctl_atom_dec_ref(port);
180 display_stat(struct writer *w, const char *tag, const char *descr,
181 long unsigned int cnt)
182 diff --git a/src/client/lldpcli.8.in b/src/client/lldpcli.8.in
183 index 1a20fa8..8a4123e 100644
184 --- a/src/client/lldpcli.8.in
185 +++ b/src/client/lldpcli.8.in
186 @@ -134,6 +134,26 @@ one or several ports, the information displayed is limited to the
191 +.Op ports Ar ethX Op ,...
192 +.Op Cd details | summary
194 +.Bd -ragged -offset XXXXXX
195 +Display information about each local interface known by
199 +only the name and the port description of each local interface will be
200 +displayed. On the other hand, with
202 +all available information will be displayed, giving a verbose
205 +also display local ports hidden by the smart filter. When specifying
206 +one or several ports, the information displayed is limited to the
207 +given list of ports.
211 .Op Cd details | summary
212 .Bd -ragged -offset XXXXXX
213 diff --git a/src/client/show.c b/src/client/show.c
214 index fa704b8..8ba8acb 100644
215 --- a/src/client/show.c
216 +++ b/src/client/show.c
217 @@ -48,6 +48,35 @@ cmd_show_neighbors(struct lldpctl_conn_t *conn, struct writer *w,
224 + * The environment will contain the following keys:
225 + * - C{ports} list of ports we want to restrict showing.
226 + * - C{hidden} if we should show hidden ports.
227 + * - C{summary} if we want to show only a summary
228 + * - C{detailed} for a detailed overview
231 +cmd_show_interfaces(struct lldpctl_conn_t *conn, struct writer *w,
232 + struct cmd_env *env, void *arg)
234 + log_debug("lldpctl", "show interfaces data (%s) %s hidden interfaces",
235 + cmdenv_get(env, "summary")?"summary":
236 + cmdenv_get(env, "detailed")?"detailed":
237 + "normal", cmdenv_get(env, "hidden")?"with":"without");
238 + if (cmdenv_get(env, "ports"))
239 + log_debug("lldpctl", "restrict to the following ports: %s",
240 + cmdenv_get(env, "ports"));
242 + display_local_interfaces(conn, w, env, !!cmdenv_get(env, "hidden"),
243 + cmdenv_get(env, "summary")?DISPLAY_BRIEF:
244 + cmdenv_get(env, "detailed")?DISPLAY_DETAILS:
253 @@ -286,6 +315,12 @@ register_commands_show(struct cmd_node *root)
254 "Show neighbors data",
257 + struct cmd_node *interfaces = commands_new(
260 + "Show interfaces data",
263 struct cmd_node *chassis = commands_new(
266 @@ -306,6 +341,15 @@ register_commands_show(struct cmd_node *root)
268 register_common_commands(neighbors, 1);
270 + /* Interfaces data */
271 + commands_new(interfaces,
273 + "Show interfaces data",
274 + NULL, cmd_show_interfaces, NULL);
276 + cmd_restrict_ports(interfaces);
277 + register_common_commands(interfaces, 0);
280 commands_new(chassis,
282 diff --git a/src/daemon/lldpd.c b/src/daemon/lldpd.c
283 index 97df38e..8ce38a9 100644
284 --- a/src/daemon/lldpd.c
285 +++ b/src/daemon/lldpd.c
286 @@ -1037,6 +1037,7 @@ lldpd_send(struct lldpd_hardware *hardware)
287 cfg->g_protocols[i].name);
288 cfg->g_protocols[i].send(cfg,
290 + hardware->h_lport.p_protocol = cfg->g_protocols[i].mode;