2 src/client/client.h | 2 +
3 src/client/display.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++-
4 src/client/show.c | 44 ++++++++++++++++++++++++++++++++++++++
5 src/lib/atoms/port.c | 7 ++++++
7 5 files changed, 112 insertions(+), 1 deletion(-)
9 --- a/src/client/client.h
10 +++ b/src/client/client.h
11 @@ -115,6 +115,8 @@ char* totag(const char *);
12 #define DISPLAY_DETAILS 3
13 void display_interfaces(lldpctl_conn_t *, struct writer *,
14 struct cmd_env *, int, int);
15 +void display_local_interfaces(lldpctl_conn_t *, struct writer *,
16 + struct cmd_env *, int, int);
17 void display_interface(lldpctl_conn_t *, struct writer *, int,
18 lldpctl_atom_t *, lldpctl_atom_t *, int, int);
19 void display_local_chassis(lldpctl_conn_t *, struct writer *,
20 --- a/src/client/display.c
21 +++ b/src/client/display.c
22 @@ -344,12 +344,23 @@ display_port(struct writer *w, lldpctl_a
23 tag_datatag(w, "descr", "PortDescr",
24 lldpctl_atom_get_str(port, lldpctl_k_port_descr));
26 + tag_datatag(w, "ttl", "Ttl",
27 + lldpctl_atom_get_str(port, lldpctl_k_port_ttl));
30 if (details == DISPLAY_DETAILS) {
31 tag_datatag(w, "mfs", "MFS",
32 lldpctl_atom_get_str(port, lldpctl_k_port_dot3_mfs));
33 - tag_datatag(w, "aggregation", "Port is aggregated. PortAggregID",
35 + long int lag_id = lldpctl_atom_get_int(port,
36 + lldpctl_k_port_dot3_aggregid);
37 + tag_start(w, "link-aggregation", "LinkAgg");
38 + tag_attr(w, "supported", "supported", "yes");
39 + tag_attr(w, "enabled", "enabled",
40 + (lag_id > 0)?"yes":"no");
41 + tag_datatag(w, "aggregation", "PortAggregID",
42 lldpctl_atom_get_str(port, lldpctl_k_port_dot3_aggregid));
45 long int autoneg_support, autoneg_enabled, autoneg_advertised;
46 autoneg_support = lldpctl_atom_get_int(port,
47 @@ -663,6 +674,52 @@ display_interfaces(lldpctl_conn_t *conn,
48 lldpctl_atom_dec_ref(port);
54 + * Display information about local interfaces.
56 + * @param conn Connection to lldpd.
58 + * @param hidden Whatever to show hidden ports.
59 + * @param env Environment from which we may find the list of ports.
60 + * @param details Level of details we need (DISPLAY_*).
63 +display_local_interfaces(lldpctl_conn_t *conn, struct writer *w,
64 + struct cmd_env *env,
65 + int hidden, int details)
67 + lldpctl_atom_t *iface;
68 + int protocol = LLDPD_MODE_MAX;
69 + const char *proto_str;
71 + /* user might have specified protocol to filter display results */
72 + proto_str = cmdenv_get(env, "protocol");
75 + log_debug("display", "filter protocol: %s ", proto_str);
78 + for (lldpctl_map_t *protocol_map =
79 + lldpctl_key_get_map(lldpctl_k_port_protocol);
80 + protocol_map->string;
82 + if (!strcasecmp(proto_str, protocol_map->string)) {
83 + protocol = protocol_map->value;
89 + tag_start(w, "lldp", "LLDP interfaces");
90 + while ((iface = cmd_iterate_on_interfaces(conn, env))) {
91 + lldpctl_atom_t *port;
92 + port = lldpctl_get_port(iface);
93 + display_interface(conn, w, hidden, iface, port, details, protocol);
94 + lldpctl_atom_dec_ref(port);
100 --- a/src/client/show.c
101 +++ b/src/client/show.c
102 @@ -48,6 +48,35 @@ cmd_show_neighbors(struct lldpctl_conn_t
108 + * The environment will contain the following keys:
109 + * - C{ports} list of ports we want to restrict showing.
110 + * - C{hidden} if we should show hidden ports.
111 + * - C{summary} if we want to show only a summary
112 + * - C{detailed} for a detailed overview
115 +cmd_show_interfaces(struct lldpctl_conn_t *conn, struct writer *w,
116 + struct cmd_env *env, void *arg)
118 + log_debug("lldpctl", "show interfaces data (%s) %s hidden interfaces",
119 + cmdenv_get(env, "summary")?"summary":
120 + cmdenv_get(env, "detailed")?"detailed":
121 + "normal", cmdenv_get(env, "hidden")?"with":"without");
122 + if (cmdenv_get(env, "ports"))
123 + log_debug("lldpctl", "restrict to the following ports: %s",
124 + cmdenv_get(env, "ports"));
126 + display_local_interfaces(conn, w, env, !!cmdenv_get(env, "hidden"),
127 + cmdenv_get(env, "summary")?DISPLAY_BRIEF:
128 + cmdenv_get(env, "detailed")?DISPLAY_DETAILS:
137 * The environment will contain the following keys:
138 @@ -269,6 +298,12 @@ register_commands_show(struct cmd_node *
139 "Show neighbors data",
142 + struct cmd_node *interfaces = commands_new(
145 + "Show interfaces data",
148 struct cmd_node *chassis = commands_new(
151 @@ -289,6 +324,15 @@ register_commands_show(struct cmd_node *
153 register_common_commands(neighbors, 1);
155 + /* Interfaces data */
156 + commands_new(interfaces,
158 + "Show interfaces data",
159 + NULL, cmd_show_interfaces, NULL);
161 + cmd_restrict_ports(interfaces);
162 + register_common_commands(interfaces, 0);
165 commands_new(chassis,
167 --- a/src/lib/atoms/port.c
168 +++ b/src/lib/atoms/port.c
172 #include <arpa/inet.h>
177 @@ -544,6 +545,7 @@ _lldpctl_atom_get_int_port(lldpctl_atom_
178 (struct _lldpctl_atom_port_t *)atom;
179 struct lldpd_port *port = p->port;
180 struct lldpd_hardware *hardware = p->hardware;
181 + time_t now = time(NULL);
183 /* Local port only */
184 if (hardware != NULL) {
185 @@ -585,6 +587,11 @@ _lldpctl_atom_get_int_port(lldpctl_atom_
186 return port->p_id_subtype;
187 case lldpctl_k_port_hidden:
188 return port->p_hidden_in;
189 + case lldpctl_k_port_ttl:
190 + if (port->p_lastupdate > 0)
191 + return (port->p_chassis->c_ttl - (now - port->p_lastupdate));
193 + return port->p_chassis->c_ttl;
195 case lldpctl_k_port_dot3_mfs:
197 --- a/src/lib/lldpctl.h
198 +++ b/src/lib/lldpctl.h
199 @@ -674,6 +674,7 @@ typedef enum {
200 lldpctl_k_port_hidden, /**< `(I)` Is this port hidden (or should it be displayed?)? */
201 lldpctl_k_port_status, /**< `(IS,WO)` Operational status of this (local) port */
202 lldpctl_k_port_chassis, /**< `(A)` Chassis associated to the port */
203 + lldpctl_k_port_ttl, /**< `(I)` The port ttl. */
205 lldpctl_k_port_dot3_mfs = 1300, /**< `(I)` MFS */
206 lldpctl_k_port_dot3_aggregid, /**< `(I)` Port aggregation ID */