diff options
author | Beniamino Galvani <bgalvani@redhat.com> | 2015-06-30 10:46:01 +0200 |
---|---|---|
committer | Beniamino Galvani <bgalvani@redhat.com> | 2015-10-02 17:39:22 +0200 |
commit | 7434883c40f3623372044f88cdde3eda49ba9758 (patch) | |
tree | 5ad2215e01c083ce937470cdf12618da928931f8 /src/libsystemd-network/sd-lldp.c | |
parent | b57003ecc3fe92c8074cbc72ee2b7d9cda742271 (diff) |
lldp: add public function to export LLDP TLV packets
Add a public function to get a list of current LLDP neighbours' TLV
packets. The function populates an array of pointers to the opaque
type sd_lldp_packet and returns the number of elements found. Callers
must take care of freeing the array and decreasing the refcount of
elements when done.
Diffstat (limited to 'src/libsystemd-network/sd-lldp.c')
-rw-r--r-- | src/libsystemd-network/sd-lldp.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/libsystemd-network/sd-lldp.c b/src/libsystemd-network/sd-lldp.c index 2b788e78cd..a343370e96 100644 --- a/src/libsystemd-network/sd-lldp.c +++ b/src/libsystemd-network/sd-lldp.c @@ -702,3 +702,35 @@ int sd_lldp_new(int ifindex, return 0; } + +int sd_lldp_get_packets(sd_lldp *lldp, sd_lldp_packet ***tlvs) { + lldp_neighbour_port *p; + lldp_chassis *c; + Iterator iter; + unsigned count = 0, i; + + assert_return(lldp, -EINVAL); + assert_return(tlvs, -EINVAL); + + HASHMAP_FOREACH(c, lldp->neighbour_mib, iter) { + LIST_FOREACH(port, p, c->ports) + count++; + } + + if (!count) { + *tlvs = NULL; + return 0; + } + + *tlvs = new(sd_lldp_packet *, count); + if (!*tlvs) + return -ENOMEM; + + i = 0; + HASHMAP_FOREACH(c, lldp->neighbour_mib, iter) { + LIST_FOREACH(port, p, c->ports) + (*tlvs)[i++] = sd_lldp_packet_ref(p->packet); + } + + return count; +} |