Update the doc overview and release note.
[pti/rtp.git] / meta-stx / recipes-daemons / lldpd / files / lldpd-interface-show.patch
1 ---
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 ++++++
6  src/lib/lldpctl.h    |    1 
7  5 files changed, 112 insertions(+), 1 deletion(-)
8
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));
25  
26 +       tag_datatag(w, "ttl", "Ttl",
27 +           lldpctl_atom_get_str(port, lldpctl_k_port_ttl));
28 +
29         /* Dot3 */
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",
34 +
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));
43 +               tag_end(w);
44  
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);
49         }
50         tag_end(w);
51 +}
52 +
53 +/**
54 + * Display information about local interfaces.
55 + *
56 + * @param conn       Connection to lldpd.
57 + * @param w          Writer.
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_*).
61 + */
62 +void
63 +display_local_interfaces(lldpctl_conn_t *conn, struct writer *w,
64 +    struct cmd_env *env,
65 +    int hidden, int details)
66 +{
67 +       lldpctl_atom_t *iface;
68 +       int protocol = LLDPD_MODE_MAX;
69 +       const char *proto_str;
70 +
71 +       /* user might have specified protocol to filter display results */
72 +       proto_str = cmdenv_get(env, "protocol");
73 +
74 +       if (proto_str) {
75 +               log_debug("display", "filter protocol: %s ", proto_str);
76 +
77 +               protocol = 0;
78 +               for (lldpctl_map_t *protocol_map =
79 +                        lldpctl_key_get_map(lldpctl_k_port_protocol);
80 +                    protocol_map->string;
81 +                    protocol_map++) {
82 +                       if (!strcasecmp(proto_str, protocol_map->string)) {
83 +                               protocol = protocol_map->value;
84 +                               break;
85 +                       }
86 +               }
87 +       }
88 +
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);
95 +       }
96 +       tag_end(w);
97  }
98  
99  void
100 --- a/src/client/show.c
101 +++ b/src/client/show.c
102 @@ -48,6 +48,35 @@ cmd_show_neighbors(struct lldpctl_conn_t
103  }
104  
105  /**
106 + * Show interfaces.
107 + *
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
113 + */
114 +static int
115 +cmd_show_interfaces(struct lldpctl_conn_t *conn, struct writer *w,
116 +    struct cmd_env *env, void *arg)
117 +{
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"));
125 +
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:
129 +           DISPLAY_NORMAL);
130 +
131 +       return 1;
132 +}
133 +
134 +/**
135   * Show chassis.
136   *
137   * The environment will contain the following keys:
138 @@ -269,6 +298,12 @@ register_commands_show(struct cmd_node *
139                 "Show neighbors data",
140                 NULL, NULL, NULL);
141  
142 +       struct cmd_node *interfaces = commands_new(
143 +               show,
144 +               "interfaces",
145 +               "Show interfaces data",
146 +               NULL, NULL, NULL);
147 +
148         struct cmd_node *chassis = commands_new(
149                 show,
150                 "chassis",
151 @@ -289,6 +324,15 @@ register_commands_show(struct cmd_node *
152  
153         register_common_commands(neighbors, 1);
154  
155 +       /* Interfaces data */
156 +       commands_new(interfaces,
157 +           NEWLINE,
158 +           "Show interfaces data",
159 +           NULL, cmd_show_interfaces, NULL);
160 +
161 +       cmd_restrict_ports(interfaces);
162 +       register_common_commands(interfaces, 0);
163 +
164         /* Chassis data */
165         commands_new(chassis,
166             NEWLINE,
167 --- a/src/lib/atoms/port.c
168 +++ b/src/lib/atoms/port.c
169 @@ -19,6 +19,7 @@
170  #include <stdarg.h>
171  #include <string.h>
172  #include <arpa/inet.h>
173 +#include <time.h>
174  
175  #include "lldpctl.h"
176  #include "../log.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);
182  
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));
192 +               else
193 +                       return port->p_chassis->c_ttl;
194  #ifdef ENABLE_DOT3
195         case lldpctl_k_port_dot3_mfs:
196                 if (port->p_mfs > 0)
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. */
204  
205         lldpctl_k_port_dot3_mfs = 1300,    /**< `(I)` MFS */
206         lldpctl_k_port_dot3_aggregid,   /**< `(I)` Port aggregation ID */