Update the doc overview and release note.
[pti/rtp.git] / meta-stx / recipes-daemons / lldpd / files / 0001-lldpd-client-add-show-interfaces-cmd-from-upstream.patch
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
5
6 commit a54f6012efff77c966f533b8ef35b8627e3c8212
7 ---
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(-)
14
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 *,
20      struct cmd_env *);
21  void display_interface_stats(lldpctl_conn_t *, struct writer *,
22      lldpctl_atom_t *);
23 +void display_local_interfaces(lldpctl_conn_t *, struct writer *,
24 +    struct cmd_env *, int, int);
25  
26  
27  
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)
33  
34         tag_datatag(w, "descr", "PortDescr",
35             lldpctl_atom_get_str(port, lldpctl_k_port_descr));
36 -       if (details)
37 +       if (details &&
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));
41  
42 @@ -473,6 +474,38 @@ display_port(struct writer *w, lldpctl_atom_t *port, int details)
43         tag_end(w);
44  }
45  
46 +static void
47 +display_local_ttl(struct writer *w, lldpctl_conn_t *conn, int details)
48 +{
49 +       char *ttl;
50 +       long int tx_hold;
51 +       long int tx_interval;
52 +
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));
58 +               return;
59 +       }
60 +
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);
63 +
64 +       if (asprintf(&ttl, "%lu", tx_hold*tx_interval) == -1) {
65 +               log_warnx("lldpctl", "not enough memory to build TTL.");
66 +               goto end;
67 +       }
68 +
69 +       tag_start(w, "ttl", "TTL");
70 +       tag_attr(w, "ttl", "", ttl);
71 +       tag_end(w);
72 +       free(ttl);
73 +end:
74 +       lldpctl_atom_dec_ref(configuration);
75 +       return;
76 +}
77 +
78  static void
79  display_vlans(struct writer *w, lldpctl_atom_t *port)
80  {
81 @@ -582,43 +615,51 @@ display_local_chassis(lldpctl_conn_t *conn, struct writer *w,
82  
83  void
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)
87  {
88 +       int local = 0;
89 +
90         if (!hidden &&
91 -           lldpctl_atom_get_int(neighbor, lldpctl_k_port_hidden))
92 +           lldpctl_atom_get_int(port, lldpctl_k_port_hidden))
93                 return;
94  
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)))
99             return;
100  
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;
104 +
105 +       lldpctl_atom_t *chassis = lldpctl_atom_get(port, lldpctl_k_port_chassis);
106  
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));
116 +               if (!local)
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)));
122         }
123  
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);
138         }
139  
140         lldpctl_atom_dec_ref(chassis);
141  
142 -       display_custom_tlvs(w, neighbor);
143 +       display_custom_tlvs(w, port);
144  
145         tag_end(w);
146  }
147 @@ -675,6 +716,34 @@ display_interfaces(lldpctl_conn_t *conn, struct writer *w,
148         tag_end(w);
149  }
150  
151 +
152 +/**
153 + * Display information about local interfaces.
154 + *
155 + * @param conn       Connection to lldpd.
156 + * @param w          Writer.
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_*).
160 + */
161 +void
162 +display_local_interfaces(lldpctl_conn_t *conn, struct writer *w,
163 +    struct cmd_env *env,
164 +    int hidden, int details)
165 +{
166 +       lldpctl_atom_t *iface;
167 +       int protocol = LLDPD_MODE_MAX;
168 +
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);
175 +       }
176 +       tag_end(w);
177 + }
178 +
179  void
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
187  given list of ports.
188  .Ed
189  
190 +.Cd show interfaces
191 +.Op ports Ar ethX Op ,...
192 +.Op Cd details | summary
193 +.Op Cd hidden
194 +.Bd -ragged -offset XXXXXX
195 +Display information about each local interface known by
196 +.Xr lldpd 8
197 +daemon. With
198 +.Cd summary ,
199 +only the name and the port description of each local interface will be
200 +displayed. On the other hand, with
201 +.Cd details ,
202 +all available information will be displayed, giving a verbose
203 +view. When using
204 +.Cd hidden ,
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.
208 +.Ed
209 +
210  .Cd show chassis
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,
218         return 1;
219  }
220  
221 +/**
222 + * Show interfaces.
223 + *
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
229 + */
230 +static int
231 +cmd_show_interfaces(struct lldpctl_conn_t *conn, struct writer *w,
232 +    struct cmd_env *env, void *arg)
233 +{
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"));
241 +
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:
245 +           DISPLAY_NORMAL);
246 +
247 +       return 1;
248 +}
249 +
250  /**
251   * Show chassis.
252   *
253 @@ -286,6 +315,12 @@ register_commands_show(struct cmd_node *root)
254                 "Show neighbors data",
255                 NULL, NULL, NULL);
256  
257 +       struct cmd_node *interfaces = commands_new(
258 +               show,
259 +               "interfaces",
260 +               "Show interfaces data",
261 +               NULL, NULL, NULL);
262 +
263         struct cmd_node *chassis = commands_new(
264                 show,
265                 "chassis",
266 @@ -306,6 +341,15 @@ register_commands_show(struct cmd_node *root)
267  
268         register_common_commands(neighbors, 1);
269  
270 +       /* Interfaces data */
271 +       commands_new(interfaces,
272 +           NEWLINE,
273 +           "Show interfaces data",
274 +           NULL, cmd_show_interfaces, NULL);
275 +
276 +       cmd_restrict_ports(interfaces);
277 +       register_common_commands(interfaces, 0);
278 +
279         /* Chassis data */
280         commands_new(chassis,
281             NEWLINE,
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,
289                                     hardware);
290 +                               hardware->h_lport.p_protocol = cfg->g_protocols[i].mode;
291                                 sent++;
292                                 break;
293                         }
294 -- 
295 2.23.0
296