1 /* -*- mode: c; c-file-style: "openbsd" -*- */
3 * Copyright (c) 2008 Vincent Bernat <bernat@luffy.cx>
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24 #include <sys/types.h>
25 #include <sys/socket.h>
27 #include <arpa/inet.h>
34 display_cap(struct writer
* w
, lldpctl_atom_t
*chassis
, u_int8_t bit
, char *symbol
)
36 if (lldpctl_atom_get_int(chassis
, lldpctl_k_chassis_cap_available
) & bit
) {
37 tag_start(w
, "capability", "Capability");
38 tag_attr (w
, "type", "", symbol
);
39 tag_attr (w
, "enabled", "",
40 (lldpctl_atom_get_int(chassis
, lldpctl_k_chassis_cap_enabled
) & bit
)?
47 display_med_capability(struct writer
*w
, long int available
, int cap
,
50 if (available
& cap
) {
51 tag_start(w
, "capability", "Capability");
52 tag_attr(w
, "type", "", symbol
);
58 display_med(struct writer
*w
, lldpctl_atom_t
*port
)
60 lldpctl_atom_t
*medpolicies
, *medpolicy
;
61 lldpctl_atom_t
*medlocations
, *medlocation
;
62 lldpctl_atom_t
*caelements
, *caelement
;
63 long int cap
= lldpctl_atom_get_int(port
, lldpctl_k_chassis_med_cap
);
66 if (lldpctl_atom_get_int(port
, lldpctl_k_chassis_med_type
) <= 0)
69 tag_start(w
, "lldp-med", "LLDP-MED");
71 tag_datatag(w
, "device-type", "Device Type",
72 lldpctl_atom_get_str(port
, lldpctl_k_chassis_med_type
));
74 display_med_capability(w
, cap
, LLDP_MED_CAP_CAP
, "Capabilities");
75 display_med_capability(w
, cap
, LLDP_MED_CAP_POLICY
, "Policy");
76 display_med_capability(w
, cap
, LLDP_MED_CAP_LOCATION
, "Location");
77 display_med_capability(w
, cap
, LLDP_MED_CAP_MDI_PSE
, "MDI/PSE");
78 display_med_capability(w
, cap
, LLDP_MED_CAP_MDI_PD
, "MDI/PD");
79 display_med_capability(w
, cap
, LLDP_MED_CAP_IV
, "Inventory");
81 /* LLDP MED policies */
82 medpolicies
= lldpctl_atom_get(port
, lldpctl_k_port_med_policies
);
83 lldpctl_atom_foreach(medpolicies
, medpolicy
) {
84 if (lldpctl_atom_get_int(medpolicy
,
85 lldpctl_k_med_policy_type
) <= 0) continue;
87 tag_start(w
, "policy", "LLDP-MED Network Policy for");
88 tag_attr(w
, "apptype", "", lldpctl_atom_get_str(medpolicy
, lldpctl_k_med_policy_type
));
89 tag_attr(w
, "defined", "Defined",
90 (lldpctl_atom_get_int(medpolicy
,
91 lldpctl_k_med_policy_unknown
) > 0)?"no":"yes");
93 if (lldpctl_atom_get_int(medpolicy
,
94 lldpctl_k_med_policy_tagged
) > 0) {
95 int vid
= lldpctl_atom_get_int(medpolicy
,
96 lldpctl_k_med_policy_vid
);
97 tag_start(w
, "vlan", "VLAN");
99 tag_attr(w
, "vid", "", "priority");
100 } else if (vid
== 4095) {
101 tag_attr(w
, "vid", "", "reserved");
103 tag_attr(w
, "vid", "",
104 lldpctl_atom_get_str(medpolicy
,
105 lldpctl_k_med_policy_vid
));
110 tag_datatag(w
, "priority", "Priority",
111 lldpctl_atom_get_str(medpolicy
,
112 lldpctl_k_med_policy_priority
));
113 tag_datatag(w
, "dscp", "DSCP Value",
114 lldpctl_atom_get_str(medpolicy
,
115 lldpctl_k_med_policy_dscp
));
119 lldpctl_atom_dec_ref(medpolicies
);
121 /* LLDP MED locations */
122 medlocations
= lldpctl_atom_get(port
, lldpctl_k_port_med_locations
);
123 lldpctl_atom_foreach(medlocations
, medlocation
) {
124 int format
= lldpctl_atom_get_int(medlocation
,
125 lldpctl_k_med_location_format
);
126 if (format
<= 0) continue;
127 tag_start(w
, "location", "LLDP-MED Location Identification");
128 tag_attr(w
, "type", "Type",
129 lldpctl_atom_get_str(medlocation
,
130 lldpctl_k_med_location_format
));
133 case LLDP_MED_LOCFORMAT_COORD
:
134 tag_attr(w
, "geoid", "Geoid",
135 lldpctl_atom_get_str(medlocation
,
136 lldpctl_k_med_location_geoid
));
137 tag_datatag(w
, "lat", "Latitude",
138 lldpctl_atom_get_str(medlocation
,
139 lldpctl_k_med_location_latitude
));
140 tag_datatag(w
, "lon", "Longitude",
141 lldpctl_atom_get_str(medlocation
,
142 lldpctl_k_med_location_longitude
));
143 tag_start(w
, "altitude", "Altitude");
144 tag_attr(w
, "unit", "", lldpctl_atom_get_str(medlocation
,
145 lldpctl_k_med_location_altitude_unit
));
146 tag_data(w
, lldpctl_atom_get_str(medlocation
,
147 lldpctl_k_med_location_altitude
));
150 case LLDP_MED_LOCFORMAT_CIVIC
:
151 tag_datatag(w
, "country", "Country",
152 lldpctl_atom_get_str(medlocation
,
153 lldpctl_k_med_location_country
));
154 caelements
= lldpctl_atom_get(medlocation
,
155 lldpctl_k_med_location_ca_elements
);
156 lldpctl_atom_foreach(caelements
, caelement
) {
157 type
= lldpctl_atom_get_str(caelement
,
158 lldpctl_k_med_civicaddress_type
);
159 tag_datatag(w
, totag(type
), type
,
160 lldpctl_atom_get_str(caelement
,
161 lldpctl_k_med_civicaddress_value
));
163 lldpctl_atom_dec_ref(caelements
);
165 case LLDP_MED_LOCFORMAT_ELIN
:
166 tag_datatag(w
, "ecs", "ECS ELIN",
167 lldpctl_atom_get_str(medlocation
,
168 lldpctl_k_med_location_elin
));
174 lldpctl_atom_dec_ref(medlocations
);
177 if (lldpctl_atom_get_int(port
, lldpctl_k_med_power_type
) > 0) {
178 tag_start(w
, "poe", "Extended Power-over-Ethernet");
180 tag_datatag(w
, "device-type", "Power Type & Source",
181 lldpctl_atom_get_str(port
, lldpctl_k_med_power_type
));
182 tag_datatag(w
, "source", "Power Source",
183 lldpctl_atom_get_str(port
, lldpctl_k_med_power_source
));
184 tag_datatag(w
, "priority", "Power priority",
185 lldpctl_atom_get_str(port
, lldpctl_k_med_power_priority
));
186 tag_datatag(w
, "power", "Power Value",
187 lldpctl_atom_get_str(port
, lldpctl_k_med_power_val
));
190 /* LLDP MED inventory */
192 const char *hw
= lldpctl_atom_get_str(port
,
193 lldpctl_k_chassis_med_inventory_hw
);
194 const char *sw
= lldpctl_atom_get_str(port
,
195 lldpctl_k_chassis_med_inventory_sw
);
196 const char *fw
= lldpctl_atom_get_str(port
,
197 lldpctl_k_chassis_med_inventory_fw
);
198 const char *sn
= lldpctl_atom_get_str(port
,
199 lldpctl_k_chassis_med_inventory_sn
);
200 const char *manuf
= lldpctl_atom_get_str(port
,
201 lldpctl_k_chassis_med_inventory_manuf
);
202 const char *model
= lldpctl_atom_get_str(port
,
203 lldpctl_k_chassis_med_inventory_model
);
204 const char *asset
= lldpctl_atom_get_str(port
,
205 lldpctl_k_chassis_med_inventory_asset
);
206 if (!(hw
|| sw
|| fw
|| sn
||
207 manuf
|| model
|| asset
)) break;
209 tag_start(w
, "inventory", "Inventory");
210 tag_datatag(w
, "hardware", "Hardware Revision", hw
);
211 tag_datatag(w
, "software", "Software Revision", sw
);
212 tag_datatag(w
, "firmware", "Firmware Revision", fw
);
213 tag_datatag(w
, "serial", "Serial Number", sn
);
214 tag_datatag(w
, "manufacturer", "Manufacturer", manuf
);
215 tag_datatag(w
, "model", "Model", model
);
216 tag_datatag(w
, "asset", "Asset ID", asset
);
224 display_chassis(struct writer
* w
, lldpctl_atom_t
* neighbor
, int details
)
226 lldpctl_atom_t
*mgmts
, *mgmt
;
228 tag_start(w
, "chassis", "Chassis");
229 tag_start(w
, "id", "ChassisID");
230 tag_attr (w
, "type", "",
231 lldpctl_atom_get_str(neighbor
,
232 lldpctl_k_chassis_id_subtype
));
233 tag_data(w
, lldpctl_atom_get_str(neighbor
,
234 lldpctl_k_chassis_id
));
236 tag_datatag(w
, "name", "SysName",
237 lldpctl_atom_get_str(neighbor
, lldpctl_k_chassis_name
));
238 if (details
== DISPLAY_BRIEF
) {
242 tag_datatag(w
, "descr", "SysDescr",
243 lldpctl_atom_get_str(neighbor
, lldpctl_k_chassis_descr
));
245 /* Management addresses */
246 mgmts
= lldpctl_atom_get(neighbor
, lldpctl_k_chassis_mgmt
);
247 lldpctl_atom_foreach(mgmts
, mgmt
) {
248 tag_datatag(w
, "mgmt-ip", "MgmtIP",
249 lldpctl_atom_get_str(mgmt
, lldpctl_k_mgmt_ip
));
251 lldpctl_atom_dec_ref(mgmts
);
254 display_cap(w
, neighbor
, LLDP_CAP_OTHER
, "Other");
255 display_cap(w
, neighbor
, LLDP_CAP_REPEATER
, "Repeater");
256 display_cap(w
, neighbor
, LLDP_CAP_BRIDGE
, "Bridge");
257 display_cap(w
, neighbor
, LLDP_CAP_ROUTER
, "Router");
258 display_cap(w
, neighbor
, LLDP_CAP_WLAN
, "Wlan");
259 display_cap(w
, neighbor
, LLDP_CAP_TELEPHONE
, "Tel");
260 display_cap(w
, neighbor
, LLDP_CAP_DOCSIS
, "Docsis");
261 display_cap(w
, neighbor
, LLDP_CAP_STATION
, "Station");
267 display_autoneg(struct writer
* w
, int advertised
, int bithd
, int bitfd
, char *desc
)
269 if (!((advertised
& bithd
) ||
270 (advertised
& bitfd
)))
273 tag_start(w
, "advertised", "Adv");
274 tag_attr(w
, "type", "", desc
);
275 if (bitfd
!= bithd
) {
276 tag_attr(w
, "hd", "HD", (advertised
& bithd
)?"yes":"no");
277 tag_attr(w
, "fd", "FD", (advertised
& bitfd
)?"yes":"no");
283 display_port(struct writer
*w
, lldpctl_atom_t
*port
, int details
)
285 tag_start(w
, "port", "Port");
286 tag_start(w
, "id", "PortID");
287 tag_attr (w
, "type", "",
288 lldpctl_atom_get_str(port
, lldpctl_k_port_id_subtype
));
289 tag_data(w
, lldpctl_atom_get_str(port
, lldpctl_k_port_id
));
292 tag_datatag(w
, "descr", "PortDescr",
293 lldpctl_atom_get_str(port
, lldpctl_k_port_descr
));
296 if (details
== DISPLAY_DETAILS
) {
297 tag_datatag(w
, "mfs", "MFS",
298 lldpctl_atom_get_str(port
, lldpctl_k_port_dot3_mfs
));
299 tag_datatag(w
, "aggregation", " Port is aggregated. PortAggregID",
300 lldpctl_atom_get_str(port
, lldpctl_k_port_dot3_aggregid
));
302 long int autoneg_support
, autoneg_enabled
, autoneg_advertised
;
303 autoneg_support
= lldpctl_atom_get_int(port
,
304 lldpctl_k_port_dot3_autoneg_support
);
305 autoneg_enabled
= lldpctl_atom_get_int(port
,
306 lldpctl_k_port_dot3_autoneg_enabled
);
307 autoneg_advertised
= lldpctl_atom_get_int(port
,
308 lldpctl_k_port_dot3_autoneg_advertised
);
309 if (autoneg_support
> 0 || autoneg_enabled
> 0) {
310 tag_start(w
, "auto-negotiation", "PMD autoneg");
311 tag_attr (w
, "supported", "supported",
312 (autoneg_support
> 0)?"yes":"no");
313 tag_attr (w
, "enabled", "enabled",
314 (autoneg_enabled
> 0)?"yes":"no");
316 if (autoneg_enabled
> 0) {
317 if (autoneg_advertised
< 0)
318 autoneg_advertised
= 0;
319 display_autoneg(w
, autoneg_advertised
,
320 LLDP_DOT3_LINK_AUTONEG_10BASE_T
,
321 LLDP_DOT3_LINK_AUTONEG_10BASET_FD
,
323 display_autoneg(w
, autoneg_advertised
,
324 LLDP_DOT3_LINK_AUTONEG_100BASE_TX
,
325 LLDP_DOT3_LINK_AUTONEG_100BASE_TXFD
,
327 display_autoneg(w
, autoneg_advertised
,
328 LLDP_DOT3_LINK_AUTONEG_100BASE_T2
,
329 LLDP_DOT3_LINK_AUTONEG_100BASE_T2FD
,
331 display_autoneg(w
, autoneg_advertised
,
332 LLDP_DOT3_LINK_AUTONEG_100BASE_T4
,
333 LLDP_DOT3_LINK_AUTONEG_100BASE_T4
,
335 display_autoneg(w
, autoneg_advertised
,
336 LLDP_DOT3_LINK_AUTONEG_1000BASE_X
,
337 LLDP_DOT3_LINK_AUTONEG_1000BASE_XFD
,
339 display_autoneg(w
, autoneg_advertised
,
340 LLDP_DOT3_LINK_AUTONEG_1000BASE_T
,
341 LLDP_DOT3_LINK_AUTONEG_1000BASE_TFD
,
344 tag_datatag(w
, "current", "MAU oper type",
345 lldpctl_atom_get_str(port
, lldpctl_k_port_dot3_mautype
));
349 lldpctl_atom_t
*dot3_power
= lldpctl_atom_get(port
,
350 lldpctl_k_port_dot3_power
);
351 int devicetype
= lldpctl_atom_get_int(dot3_power
,
352 lldpctl_k_dot3_power_devicetype
);
353 if (devicetype
> 0) {
354 tag_start(w
, "power", "MDI Power");
355 tag_attr(w
, "supported", "supported",
356 (lldpctl_atom_get_int(dot3_power
,
357 lldpctl_k_dot3_power_supported
) > 0)?"yes":"no");
358 tag_attr(w
, "enabled", "enabled",
359 (lldpctl_atom_get_int(dot3_power
,
360 lldpctl_k_dot3_power_enabled
) > 0)?"yes":"no");
361 tag_attr(w
, "paircontrol", "pair control",
362 (lldpctl_atom_get_int(dot3_power
,
363 lldpctl_k_dot3_power_paircontrol
) > 0)?"yes":"no");
364 tag_start(w
, "device-type", "Device type");
365 tag_data(w
, lldpctl_atom_get_str(dot3_power
,
366 lldpctl_k_dot3_power_devicetype
));;
368 tag_start(w
, "pairs", "Power pairs");
369 tag_data(w
, lldpctl_atom_get_str(dot3_power
,
370 lldpctl_k_dot3_power_pairs
));
372 tag_start(w
, "class", "Class");
373 tag_data(w
, lldpctl_atom_get_str(dot3_power
,
374 lldpctl_k_dot3_power_class
));
378 if (lldpctl_atom_get_int(dot3_power
,
379 lldpctl_k_dot3_power_type
) > LLDP_DOT3_POWER_8023AT_OFF
) {
380 tag_start(w
, "power-type", "Power type");
381 tag_data(w
, lldpctl_atom_get_str(dot3_power
,
382 lldpctl_k_dot3_power_type
));
385 tag_start(w
, "source", "Power Source");
386 tag_data(w
, lldpctl_atom_get_str(dot3_power
,
387 lldpctl_k_dot3_power_source
));
390 tag_start(w
, "priority", "Power Priority");
391 tag_data(w
, lldpctl_atom_get_str(dot3_power
,
392 lldpctl_k_dot3_power_priority
));
395 tag_start(w
, "requested", "PD requested power Value");
396 tag_data(w
, lldpctl_atom_get_str(dot3_power
,
397 lldpctl_k_dot3_power_requested
));
400 tag_start(w
, "allocated", "PSE allocated power Value");
401 tag_data(w
, lldpctl_atom_get_str(dot3_power
,
402 lldpctl_k_dot3_power_allocated
));
408 lldpctl_atom_dec_ref(dot3_power
);
415 display_vlans(struct writer
*w
, lldpctl_atom_t
*port
)
417 lldpctl_atom_t
*vlans
, *vlan
;
421 pvid
= lldpctl_atom_get_int(port
,
422 lldpctl_k_port_vlan_pvid
);
424 vlans
= lldpctl_atom_get(port
, lldpctl_k_port_vlans
);
425 lldpctl_atom_foreach(vlans
, vlan
) {
426 vid
= lldpctl_atom_get_int(vlan
,
431 tag_start(w
, "vlan", "VLAN");
432 tag_attr(w
, "vlan-id", "",
433 lldpctl_atom_get_str(vlan
, lldpctl_k_vlan_id
));
435 tag_attr(w
, "pvid", "pvid", "yes");
436 tag_data(w
, lldpctl_atom_get_str(vlan
,
437 lldpctl_k_vlan_name
));
440 lldpctl_atom_dec_ref(vlans
);
442 if (!foundpvid
&& pvid
> 0) {
443 tag_start(w
, "vlan", "VLAN");
444 tag_attr(w
, "vlan-id", "",
445 lldpctl_atom_get_str(port
,
446 lldpctl_k_port_vlan_pvid
));
447 tag_attr(w
, "pvid", "pvid", "yes");
453 display_ppvids(struct writer
*w
, lldpctl_atom_t
*port
)
455 lldpctl_atom_t
*ppvids
, *ppvid
;
456 ppvids
= lldpctl_atom_get(port
, lldpctl_k_port_ppvids
);
457 lldpctl_atom_foreach(ppvids
, ppvid
) {
458 int status
= lldpctl_atom_get_int(ppvid
,
459 lldpctl_k_ppvid_status
);
460 tag_start(w
, "ppvid", "PPVID");
461 if (lldpctl_atom_get_int(ppvid
,
462 lldpctl_k_ppvid_id
) > 0)
463 tag_attr(w
, "value", "",
464 lldpctl_atom_get_str(ppvid
,
465 lldpctl_k_ppvid_id
));
466 tag_attr(w
, "supported", "supported",
467 (status
& LLDP_PPVID_CAP_SUPPORTED
)?"yes":"no");
468 tag_attr(w
, "enabled", "enabled",
469 (status
& LLDP_PPVID_CAP_ENABLED
)?"yes":"no");
472 lldpctl_atom_dec_ref(ppvids
);
476 display_pids(struct writer
*w
, lldpctl_atom_t
*port
)
478 lldpctl_atom_t
*pids
, *pid
;
479 pids
= lldpctl_atom_get(port
, lldpctl_k_port_pis
);
480 lldpctl_atom_foreach(pids
, pid
) {
481 const char *pi
= lldpctl_atom_get_str(pid
, lldpctl_k_pi_id
);
482 if (pi
&& strlen(pi
) > 0)
483 tag_datatag(w
, "pi", "PI", pi
);
485 lldpctl_atom_dec_ref(pids
);
489 display_age(time_t lastchange
)
491 static char sage
[30];
492 int age
= (int)(time(NULL
) - lastchange
);
493 if (snprintf(sage
, sizeof(sage
),
494 "%d day%s, %02d:%02d:%02d",
496 (age
/ (60*60*24) > 1)?"s":"",
497 (age
/ (60*60)) % 24,
499 age
% 60) >= sizeof(sage
))
506 display_interface(lldpctl_conn_t
*conn
, struct writer
*w
, int hidden
,
507 lldpctl_atom_t
*iface
, lldpctl_atom_t
*neighbor
, int details
)
510 lldpctl_atom_get_int(neighbor
, lldpctl_k_port_hidden
))
513 tag_start(w
, "interface", "Interface");
514 tag_attr(w
, "name", "",
515 lldpctl_atom_get_str(iface
, lldpctl_k_interface_name
));
516 tag_attr(w
, "via" , "via",
517 lldpctl_atom_get_str(neighbor
, lldpctl_k_port_protocol
));
518 if (details
> DISPLAY_BRIEF
) {
519 tag_attr(w
, "rid" , "RID",
520 lldpctl_atom_get_str(neighbor
, lldpctl_k_chassis_index
));
521 tag_attr(w
, "age" , "Time",
522 display_age(lldpctl_atom_get_int(neighbor
, lldpctl_k_port_age
)));
525 display_chassis(w
, neighbor
, details
);
526 display_port(w
, neighbor
, details
);
527 if (details
== DISPLAY_DETAILS
) {
528 display_vlans(w
, neighbor
);
529 display_ppvids(w
, neighbor
);
530 display_pids(w
, neighbor
);
531 display_med(w
, neighbor
);
538 * Display information about interfaces.
540 * @param conn Connection to lldpd.
542 * @param hidden Whatever to show hidden ports.
543 * @param env Environment from which we may find the list of ports.
544 * @param details Level of details we need (DISPLAY_*).
547 display_interfaces(lldpctl_conn_t
*conn
, struct writer
*w
,
549 int hidden
, int details
)
551 lldpctl_atom_t
*iface
;
553 tag_start(w
, "lldp", "LLDP neighbors");
554 while ((iface
= cmd_iterate_on_interfaces(conn
, env
))) {
555 lldpctl_atom_t
*port
;
556 lldpctl_atom_t
*neighbors
;
557 lldpctl_atom_t
*neighbor
;
558 port
= lldpctl_get_port(iface
);
559 neighbors
= lldpctl_atom_get(port
, lldpctl_k_port_neighbors
);
560 lldpctl_atom_foreach(neighbors
, neighbor
) {
561 display_interface(conn
, w
, hidden
, iface
, neighbor
, details
);
563 lldpctl_atom_dec_ref(neighbors
);
564 lldpctl_atom_dec_ref(port
);
570 display_stat(struct writer
*w
, const char *tag
, const char *descr
,
571 long unsigned int cnt
)
575 tag_start(w
, tag
, descr
);
576 snprintf(buf
, sizeof(buf
), "%lu", cnt
);
577 tag_attr(w
, tag
, "", buf
);
582 display_interface_stats(lldpctl_conn_t
*conn
, struct writer
*w
,
583 lldpctl_atom_t
*port
)
585 tag_start(w
, "interface", "Interface");
586 tag_attr(w
, "name", "",
587 lldpctl_atom_get_str(port
, lldpctl_k_port_name
));
589 display_stat(w
, "tx", "Transmitted",
590 lldpctl_atom_get_int(port
, lldpctl_k_tx_cnt
));
591 display_stat(w
, "rx", "Received",
592 lldpctl_atom_get_int(port
, lldpctl_k_rx_cnt
));
594 display_stat(w
, "rx_discarded_cnt", "Discarded",
595 lldpctl_atom_get_int(port
,
596 lldpctl_k_rx_discarded_cnt
));
598 display_stat(w
, "rx_unrecognized_cnt", "Unrecognized",
599 lldpctl_atom_get_int(port
,
600 lldpctl_k_rx_unrecognized_cnt
));
602 display_stat(w
, "ageout_cnt", "Ageout",
603 lldpctl_atom_get_int(port
,
604 lldpctl_k_ageout_cnt
));
606 display_stat(w
, "insert_cnt", "Inserted",
607 lldpctl_atom_get_int(port
,
608 lldpctl_k_insert_cnt
));
610 display_stat(w
, "delete_cnt", "Deleted",
611 lldpctl_atom_get_int(port
,
612 lldpctl_k_delete_cnt
));
618 * Display interface stats
620 * @param conn Connection to lldpd.
622 * @param hidden Whatever to show hidden ports.
623 * @param env Environment from which we may find the list of ports.
624 * @param details Level of details we need (DISPLAY_*).
627 display_interfaces_stats(lldpctl_conn_t
*conn
, struct writer
*w
,
630 lldpctl_atom_t
*iface
;
632 u_int64_t h_tx_cnt
= 0;
633 u_int64_t h_rx_cnt
= 0;
634 u_int64_t h_rx_discarded_cnt
= 0;
635 u_int64_t h_rx_unrecognized_cnt
= 0;
636 u_int64_t h_ageout_cnt
= 0;
637 u_int64_t h_insert_cnt
= 0;
638 u_int64_t h_delete_cnt
= 0;
640 if (cmdenv_get(env
, "summary"))
643 tag_start(w
, "lldp", (summary
? "LLDP Global statistics" :
645 while ((iface
= cmd_iterate_on_interfaces(conn
, env
))) {
646 lldpctl_atom_t
*port
;
647 port
= lldpctl_get_port(iface
);
649 display_interface_stats(conn
, w
, port
);
651 h_tx_cnt
+= lldpctl_atom_get_int(port
,
653 h_rx_cnt
+= lldpctl_atom_get_int(port
,
655 h_rx_discarded_cnt
+= lldpctl_atom_get_int(port
,
656 lldpctl_k_rx_discarded_cnt
);
657 h_rx_unrecognized_cnt
+= lldpctl_atom_get_int(port
,
658 lldpctl_k_rx_unrecognized_cnt
);
659 h_ageout_cnt
+= lldpctl_atom_get_int(port
,
660 lldpctl_k_ageout_cnt
);
661 h_insert_cnt
+= lldpctl_atom_get_int(port
,
662 lldpctl_k_insert_cnt
);
663 h_delete_cnt
+= lldpctl_atom_get_int(port
,
664 lldpctl_k_delete_cnt
);
669 tag_start(w
, "summary", "Summary of stats");
670 display_stat(w
, "tx", "Transmitted", h_tx_cnt
);
671 display_stat(w
, "rx", "Received", h_rx_cnt
);
672 display_stat(w
, "rx_discarded_cnt", "Discarded",
675 display_stat(w
, "rx_unrecognized_cnt", "Unrecognized",
676 h_rx_unrecognized_cnt
);
678 display_stat(w
, "ageout_cnt", "Ageout", h_ageout_cnt
);
680 display_stat(w
, "insert_cnt", "Inserted", h_insert_cnt
);
682 display_stat(w
, "delete_cnt", "Deleted", h_delete_cnt
);
690 if (str
== NULL
|| strlen(str
) == 0) return "(none)";
695 display_configuration(lldpctl_conn_t
*conn
, struct writer
*w
)
697 lldpctl_atom_t
*configuration
;
699 configuration
= lldpctl_get_configuration(conn
);
700 if (!configuration
) {
701 log_warnx("lldpctl", "not able to get configuration. %s",
702 lldpctl_last_strerror(conn
));
706 tag_start(w
, "configuration", "Global configuration");
707 tag_start(w
, "config", "Configuration");
709 tag_datatag(w
, "tx-delay", "Transmit delay",
710 lldpctl_atom_get_str(configuration
, lldpctl_k_config_tx_interval
));
711 tag_datatag(w
, "tx-hold", "Transmit hold",
712 lldpctl_atom_get_str(configuration
, lldpctl_k_config_tx_hold
));
713 tag_datatag(w
, "rx-only", "Receive mode",
714 lldpctl_atom_get_int(configuration
, lldpctl_k_config_receiveonly
)?
716 tag_datatag(w
, "mgmt-pattern", "Pattern for management addresses",
717 N(lldpctl_atom_get_str(configuration
, lldpctl_k_config_mgmt_pattern
)));
718 tag_datatag(w
, "iface-pattern", "Interface pattern",
719 N(lldpctl_atom_get_str(configuration
, lldpctl_k_config_iface_pattern
)));
720 tag_datatag(w
, "cid-pattern", "Interface pattern for chassis ID",
721 N(lldpctl_atom_get_str(configuration
, lldpctl_k_config_cid_pattern
)));
722 tag_datatag(w
, "description", "Override description with",
723 N(lldpctl_atom_get_str(configuration
, lldpctl_k_config_description
)));
724 tag_datatag(w
, "platform", "Override platform with",
725 N(lldpctl_atom_get_str(configuration
, lldpctl_k_config_platform
)));
726 tag_datatag(w
, "hostname", "Override system name with",
727 N(lldpctl_atom_get_str(configuration
, lldpctl_k_config_hostname
)));
728 tag_datatag(w
, "advertise-version", "Advertise version",
729 lldpctl_atom_get_int(configuration
, lldpctl_k_config_advertise_version
)?
731 tag_datatag(w
, "ifdescr-update", "Update interface descriptions",
732 lldpctl_atom_get_int(configuration
, lldpctl_k_config_ifdescr_update
)?
734 tag_datatag(w
, "lldpmed-no-inventory", "Disable LLDP-MED inventory",
735 (lldpctl_atom_get_int(configuration
, lldpctl_k_config_lldpmed_noinventory
) == 0)?
737 tag_datatag(w
, "lldpmed-faststart", "LLDP-MED fast start mechanism",
738 (lldpctl_atom_get_int(configuration
, lldpctl_k_config_fast_start_enabled
) == 0)?
740 tag_datatag(w
, "lldpmed-faststart-interval", "LLDP-MED fast start interval",
741 N(lldpctl_atom_get_str(configuration
, lldpctl_k_config_fast_start_interval
)));
742 tag_datatag(w
, "bond-slave-src-mac-type",
743 "Source MAC for LLDP frames on bond slaves",
744 lldpctl_atom_get_str(configuration
,
745 lldpctl_k_config_bond_slave_src_mac_type
));
750 lldpctl_atom_dec_ref(configuration
);