]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
lldp: add public function to export LLDP TLV packets
authorBeniamino Galvani <bgalvani@redhat.com>
Tue, 30 Jun 2015 08:46:01 +0000 (10:46 +0200)
committerBeniamino Galvani <bgalvani@redhat.com>
Fri, 2 Oct 2015 15:39:22 +0000 (17:39 +0200)
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.

src/libsystemd-network/sd-lldp.c
src/systemd/sd-lldp.h

index 2b788e78cd1cbc37ea46bc21468e053956029d93..a343370e96ab0538a8da14f8be765be3225517c5 100644 (file)
@@ -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;
+}
index efa76dacf7045f721fe72663b1c747bb406f78da..e472cbece943f0ba9bd94555fd31cc99dac4dbe3 100644 (file)
@@ -55,3 +55,5 @@ int sd_lldp_packet_read_port_description(sd_lldp_packet *tlv, char **data, uint1
 
 sd_lldp_packet *sd_lldp_packet_ref(sd_lldp_packet *tlv);
 sd_lldp_packet *sd_lldp_packet_unref(sd_lldp_packet *tlv);
+
+int sd_lldp_get_packets(sd_lldp *lldp, sd_lldp_packet ***tlvs);