*ret = triple_timestamp_by_clock(&n->timestamp, clock);
return 0;
}
+
+int lldp_neighbor_build_json(sd_lldp_neighbor *n, JsonVariant **ret) {
+ const char *chassis_id = NULL, *port_id = NULL, *port_description = NULL,
+ *system_name = NULL, *system_description = NULL;
+ uint16_t cc = 0;
+ bool valid_cc;
+
+ assert(n);
+ assert(ret);
+
+ (void) sd_lldp_neighbor_get_chassis_id_as_string(n, &chassis_id);
+ (void) sd_lldp_neighbor_get_port_id_as_string(n, &port_id);
+ (void) sd_lldp_neighbor_get_port_description(n, &port_description);
+ (void) sd_lldp_neighbor_get_system_name(n, &system_name);
+ (void) sd_lldp_neighbor_get_system_description(n, &system_description);
+
+ valid_cc = sd_lldp_neighbor_get_enabled_capabilities(n, &cc);
+
+ return json_build(ret, JSON_BUILD_OBJECT(
+ JSON_BUILD_PAIR_STRING_NON_EMPTY("ChassisID", chassis_id),
+ JSON_BUILD_PAIR_BYTE_ARRAY("RawChassisID", n->id.chassis_id, n->id.chassis_id_size),
+ JSON_BUILD_PAIR_STRING_NON_EMPTY("PortID", port_id),
+ JSON_BUILD_PAIR_BYTE_ARRAY("RawPortID", n->id.port_id, n->id.port_id_size),
+ JSON_BUILD_PAIR_STRING_NON_EMPTY("PortDescription", port_description),
+ JSON_BUILD_PAIR_STRING_NON_EMPTY("SystemName", system_name),
+ JSON_BUILD_PAIR_STRING_NON_EMPTY("SystemDescription", system_description),
+ JSON_BUILD_PAIR_CONDITION(valid_cc, "EnabledCapabilities", JSON_BUILD_UNSIGNED(cc))));
+}
#include "sd-lldp-rx.h"
#include "hash-funcs.h"
+#include "json.h"
#include "lldp-rx-internal.h"
#include "time-util.h"
int lldp_neighbor_parse(sd_lldp_neighbor *n);
void lldp_neighbor_start_ttl(sd_lldp_neighbor *n);
bool lldp_neighbor_equal(const sd_lldp_neighbor *a, const sd_lldp_neighbor *b);
+int lldp_neighbor_build_json(sd_lldp_neighbor *n, JsonVariant **ret);
#include "sd-lldp-rx.h"
#include "hashmap.h"
+#include "json.h"
#include "network-common.h"
#include "prioq.h"
const char* lldp_rx_event_to_string(sd_lldp_rx_event_t e) _const_;
sd_lldp_rx_event_t lldp_rx_event_from_string(const char *s) _pure_;
+int lldp_rx_build_neighbors_json(sd_lldp_rx *lldp_rx, JsonVariant **ret);
+
#define log_lldp_rx_errno(lldp_rx, error, fmt, ...) \
log_interface_prefix_full_errno( \
"LLDP Rx: ", \
#include "ether-addr-util.h"
#include "event-util.h"
#include "fd-util.h"
+#include "json.h"
#include "lldp-neighbor.h"
#include "lldp-network.h"
#include "lldp-rx-internal.h"
return k;
}
+int lldp_rx_build_neighbors_json(sd_lldp_rx *lldp_rx, JsonVariant **ret) {
+ _cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
+ int r;
+
+ assert(lldp_rx);
+ assert(ret);
+
+ sd_lldp_neighbor *n;
+ HASHMAP_FOREACH(n, lldp_rx->neighbor_by_id) {
+ _cleanup_(json_variant_unrefp) JsonVariant *w = NULL;
+
+ r = lldp_neighbor_build_json(n, &w);
+ if (r < 0)
+ return r;
+
+ r = json_variant_append_array(&v, w);
+ if (r < 0)
+ return r;
+ }
+
+ *ret = TAKE_PTR(v);
+ return 0;
+}
+
int sd_lldp_rx_set_neighbors_max(sd_lldp_rx *lldp_rx, uint64_t m) {
assert_return(lldp_rx, -EINVAL);
assert_return(m > 0, -EINVAL);