]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
lldp: export opaque TLV type and accessor functions
authorBeniamino Galvani <bgalvani@redhat.com>
Fri, 10 Jul 2015 16:43:12 +0000 (18:43 +0200)
committerBeniamino Galvani <bgalvani@redhat.com>
Fri, 2 Oct 2015 15:39:12 +0000 (17:39 +0200)
Export struct tlv_packet as a public opaque sd_lldp_packet type and
make its accessor functions public.

src/libsystemd-network/lldp-internal.c
src/libsystemd-network/lldp-internal.h
src/libsystemd-network/lldp-network.c
src/libsystemd-network/lldp-tlv.c
src/libsystemd-network/lldp-tlv.h
src/libsystemd-network/sd-lldp.c
src/libsystemd-network/test-lldp.c
src/systemd/sd-lldp.h

index 76958059467dd7856ea65e25a4bbf1b54e5e39e9..762a1d2895a113cee3dfc3401e3c55fa77acb3f8 100644 (file)
@@ -21,6 +21,7 @@
 ***/
 
 #include "lldp-internal.h"
+#include "sd-lldp.h"
 
 /* We store maximum 1K chassis entries */
 #define LLDP_MIB_MAX_CHASSIS 1024
 /* Maximum Ports can be attached to any chassis */
 #define LLDP_MIB_MAX_PORT_PER_CHASSIS 32
 
-int lldp_read_chassis_id(tlv_packet *tlv,
-                         uint8_t *type,
-                         uint8_t **data,
-                         uint16_t *length) {
+int sd_lldp_packet_read_chassis_id(tlv_packet *tlv,
+                                   uint8_t *type,
+                                   uint8_t **data,
+                                   uint16_t *length) {
         uint8_t subtype;
         int r;
 
@@ -67,10 +68,10 @@ int lldp_read_chassis_id(tlv_packet *tlv,
         return r;
 }
 
-int lldp_read_port_id(tlv_packet *tlv,
-                      uint8_t *type,
-                      uint8_t **data,
-                      uint16_t *length) {
+int sd_lldp_packet_read_port_id(tlv_packet *tlv,
+                                uint8_t *type,
+                                uint8_t **data,
+                                uint16_t *length) {
         uint8_t subtype;
         char *s;
         int r;
@@ -119,7 +120,7 @@ int lldp_read_port_id(tlv_packet *tlv,
         return r;
 }
 
-int lldp_read_ttl(tlv_packet *tlv, uint16_t *ttl) {
+int sd_lldp_packet_read_ttl(tlv_packet *tlv, uint16_t *ttl) {
         int r;
 
         assert_return(tlv, -EINVAL);
@@ -136,9 +137,9 @@ int lldp_read_ttl(tlv_packet *tlv, uint16_t *ttl) {
         return r;
 }
 
-int lldp_read_system_name(tlv_packet *tlv,
-                          char **data,
-                          uint16_t *length) {
+int sd_lldp_packet_read_system_name(tlv_packet *tlv,
+                                    char **data,
+                                    uint16_t *length) {
         char *s;
         int r;
 
@@ -160,9 +161,9 @@ int lldp_read_system_name(tlv_packet *tlv,
         return r;
 }
 
-int lldp_read_system_description(tlv_packet *tlv,
-                                 char **data,
-                                 uint16_t *length) {
+int sd_lldp_packet_read_system_description(tlv_packet *tlv,
+                                           char **data,
+                                           uint16_t *length) {
         char *s;
         int r;
 
@@ -184,9 +185,9 @@ int lldp_read_system_description(tlv_packet *tlv,
         return r;
 }
 
-int lldp_read_port_description(tlv_packet *tlv,
-                               char **data,
-                               uint16_t *length) {
+int sd_lldp_packet_read_port_description(tlv_packet *tlv,
+                                         char **data,
+                                         uint16_t *length) {
         char *s;
         int r;
 
@@ -208,7 +209,7 @@ int lldp_read_port_description(tlv_packet *tlv,
         return r;
 }
 
-int lldp_read_system_capability(tlv_packet *tlv, uint16_t *data) {
+int sd_lldp_packet_read_system_capability(tlv_packet *tlv, uint16_t *data) {
         int r;
 
         assert_return(tlv, -EINVAL);
@@ -244,7 +245,7 @@ int lldp_mib_update_objects(lldp_chassis *c, tlv_packet *tlv) {
         assert_return(c, -EINVAL);
         assert_return(tlv, -EINVAL);
 
-        r = lldp_read_port_id(tlv, &type, &data, &length);
+        r = sd_lldp_packet_read_port_id(tlv, &type, &data, &length);
         if (r < 0)
                 return r;
 
@@ -253,13 +254,13 @@ int lldp_mib_update_objects(lldp_chassis *c, tlv_packet *tlv) {
 
                 if ((p->type == type && p->length == length && !memcmp(p->data, data, p->length))) {
 
-                        r = lldp_read_ttl(tlv, &ttl);
+                        r = sd_lldp_packet_read_ttl(tlv, &ttl);
                         if (r < 0)
                                 return r;
 
                         p->until = ttl * USEC_PER_SEC + now(clock_boottime_or_monotonic());
 
-                        tlv_packet_unref(p->packet);
+                        sd_lldp_packet_unref(p->packet);
                         p->packet = tlv;
 
                         prioq_reshuffle(p->c->by_expiry, p, &p->prioq_idx);
@@ -281,7 +282,7 @@ int lldp_mib_remove_objects(lldp_chassis *c, tlv_packet *tlv) {
         assert_return(c, -EINVAL);
         assert_return(tlv, -EINVAL);
 
-        r = lldp_read_port_id(tlv, &type, &data, &length);
+        r = sd_lldp_packet_read_port_id(tlv, &type, &data, &length);
         if (r < 0)
                 return r;
 
@@ -312,11 +313,11 @@ int lldp_mib_add_objects(Prioq *by_expiry,
         assert_return(neighbour_mib, -EINVAL);
         assert_return(tlv, -EINVAL);
 
-        r = lldp_read_chassis_id(tlv, &subtype, &data, &length);
+        r = sd_lldp_packet_read_chassis_id(tlv, &subtype, &data, &length);
         if (r < 0)
                 goto drop;
 
-        r = lldp_read_ttl(tlv, &ttl);
+        r = sd_lldp_packet_read_ttl(tlv, &ttl);
         if (r < 0)
                 goto drop;
 
@@ -401,7 +402,7 @@ int lldp_mib_add_objects(Prioq *by_expiry,
         return 0;
 
  drop:
-        tlv_packet_unref(tlv);
+        sd_lldp_packet_unref(tlv);
 
         if (new_chassis)
                 hashmap_remove(neighbour_mib, &c->chassis_id);
@@ -435,7 +436,7 @@ void lldp_neighbour_port_free(lldp_neighbour_port *p) {
         if(!p)
                 return;
 
-        tlv_packet_unref(p->packet);
+        sd_lldp_packet_unref(p->packet);
 
         free(p->data);
         free(p);
@@ -452,11 +453,11 @@ int lldp_neighbour_port_new(lldp_chassis *c,
 
         assert(tlv);
 
-        r = lldp_read_port_id(tlv, &type, &data, &length);
+        r = sd_lldp_packet_read_port_id(tlv, &type, &data, &length);
         if (r < 0)
                 return r;
 
-        r = lldp_read_ttl(tlv, &ttl);
+        r = sd_lldp_packet_read_ttl(tlv, &ttl);
         if (r < 0)
                 return r;
 
@@ -505,7 +506,7 @@ int lldp_chassis_new(tlv_packet *tlv,
 
         assert(tlv);
 
-        r = lldp_read_chassis_id(tlv, &type, &data, &length);
+        r = sd_lldp_packet_read_chassis_id(tlv, &type, &data, &length);
         if (r < 0)
                 return r;
 
index c61080828bda228fdf5a5a1a583edb47f5fac032..774562e171645a21feb769c2851e45fc6e9e7484 100644 (file)
@@ -86,13 +86,5 @@ int lldp_mib_update_objects(lldp_chassis *c, tlv_packet *tlv);
 int lldp_mib_add_objects(Prioq *by_expiry, Hashmap *neighbour_mib, tlv_packet *tlv);
 int lldp_mib_remove_objects(lldp_chassis *c, tlv_packet *tlv);
 
-int lldp_read_chassis_id(tlv_packet *tlv, uint8_t *type, uint8_t **data, uint16_t *length);
-int lldp_read_port_id(tlv_packet *tlv, uint8_t *type, uint8_t **data, uint16_t *length);
-int lldp_read_ttl(tlv_packet *tlv, uint16_t *ttl);
-int lldp_read_system_name(tlv_packet *tlv, char **data, uint16_t *length);
-int lldp_read_system_description(tlv_packet *tlv, char **data, uint16_t *length);
-int lldp_read_system_capability(tlv_packet *tlv, uint16_t *data);
-int lldp_read_port_description(tlv_packet *tlv, char **data, uint16_t *length);
-
 int lldp_handle_packet(tlv_packet *m, uint16_t length);
 #define log_lldp(fmt, ...) log_internal(LOG_DEBUG, 0, __FILE__, __LINE__, __func__, "LLDP: " fmt, ##__VA_ARGS__)
index 664d2f7867dabe0f19eba90a21f554409987e734..1c6dcae14d758afd40e57c0dfc43374e9257fdb7 100644 (file)
@@ -84,7 +84,7 @@ int lldp_network_bind_raw_socket(int ifindex) {
 }
 
 int lldp_receive_packet(sd_event_source *s, int fd, uint32_t revents, void *userdata) {
-        _cleanup_tlv_packet_free_ tlv_packet *packet = NULL;
+        _cleanup_lldp_packet_unref_ tlv_packet *packet = NULL;
         tlv_packet *p;
         uint16_t length;
         int r;
index 1370d217f4cfe54a087d8228b22d038893a84008..700da2fde7b4e55ca5ccec3de338d23ec8ee82e0 100644 (file)
@@ -61,7 +61,7 @@ int tlv_packet_new(tlv_packet **ret) {
         return 0;
 }
 
-tlv_packet *tlv_packet_ref(tlv_packet *m) {
+tlv_packet *sd_lldp_packet_ref(tlv_packet *m) {
 
         if (!m)
                 return NULL;
@@ -72,7 +72,7 @@ tlv_packet *tlv_packet_ref(tlv_packet *m) {
         return m;
 }
 
-tlv_packet *tlv_packet_unref(tlv_packet *m) {
+tlv_packet *sd_lldp_packet_unref(tlv_packet *m) {
         tlv_section *s, *n;
 
         if (!m)
index f682997031f97a7fc8a872ccc49a1b62374e9cc7..19509d3589f507b09f1840817cc911a4509b08ee 100644 (file)
@@ -28,6 +28,8 @@
 #include "lldp.h"
 #include "list.h"
 
+#include "sd-lldp.h"
+
 typedef struct tlv_packet tlv_packet;
 typedef struct tlv_section tlv_section;
 
@@ -63,11 +65,9 @@ struct tlv_packet {
 };
 
 int tlv_packet_new(tlv_packet **ret);
-tlv_packet *tlv_packet_ref(tlv_packet *m);
-tlv_packet *tlv_packet_unref(tlv_packet *m);
 
-DEFINE_TRIVIAL_CLEANUP_FUNC(tlv_packet*, tlv_packet_unref);
-#define _cleanup_tlv_packet_free_ _cleanup_(tlv_packet_unrefp)
+DEFINE_TRIVIAL_CLEANUP_FUNC(sd_lldp_packet*, sd_lldp_packet_unref);
+#define _cleanup_lldp_packet_unref_ _cleanup_(sd_lldp_packet_unrefp)
 
 int lldp_tlv_packet_open_container(tlv_packet *m, uint16_t type);
 int lldp_tlv_packet_close_container(tlv_packet *m);
index 5a03ab444873cb1f58ecc33b07a447ee74737135..2b788e78cd1cbc37ea46bc21468e053956029d93 100644 (file)
@@ -338,7 +338,7 @@ int lldp_handle_packet(tlv_packet *tlv, uint16_t length) {
                 lldp->statistics.stats_frames_in_errors_total ++;
         }
 
-        tlv_packet_unref(tlv);
+        sd_lldp_packet_unref(tlv);
 
         return 0;
 }
@@ -455,7 +455,7 @@ int sd_lldp_save(sd_lldp *lldp, const char *lldp_file) {
                         _cleanup_free_ char *s = NULL;
                         char *k, *t;
 
-                        r = lldp_read_chassis_id(p->packet, &type, &mac, &length);
+                        r = sd_lldp_packet_read_chassis_id(p->packet, &type, &mac, &length);
                         if (r < 0)
                                 continue;
 
@@ -468,7 +468,7 @@ int sd_lldp_save(sd_lldp *lldp, const char *lldp_file) {
                                 goto fail;
                         }
 
-                        r = lldp_read_port_id(p->packet, &type, &port_id, &length);
+                        r = sd_lldp_packet_read_port_id(p->packet, &type, &port_id, &length);
                         if (r < 0)
                                 continue;
 
@@ -513,7 +513,7 @@ int sd_lldp_save(sd_lldp *lldp, const char *lldp_file) {
                         free(s);
                         s = k;
 
-                        r = lldp_read_system_name(p->packet, &k, &length);
+                        r = sd_lldp_packet_read_system_name(p->packet, &k, &length);
                         if (r < 0)
                                 k = strappend(s, "'_NAME=N/A' ");
                         else {
@@ -535,7 +535,7 @@ int sd_lldp_save(sd_lldp *lldp, const char *lldp_file) {
                         free(s);
                         s = k;
 
-                        (void) lldp_read_system_capability(p->packet, &data);
+                        (void) sd_lldp_packet_read_system_capability(p->packet, &data);
 
                         sprintf(buf, "'_CAP=%x'", data);
 
index 06545aee59e56cae67c9aaafe77e04a2c1d4d202..26f64347a74ffcf3aece6484eacebbbb39ae0d93 100644 (file)
@@ -38,7 +38,7 @@ static struct ether_addr mac_addr = {
 };
 
 static int lldp_build_tlv_packet(tlv_packet **ret) {
-        _cleanup_tlv_packet_free_ tlv_packet *m = NULL;
+        _cleanup_lldp_packet_unref_ tlv_packet *m = NULL;
         const uint8_t lldp_dst[] = LLDP_MULTICAST_ADDR;
         struct ether_header ether = {
                 .ether_type = htons(ETHERTYPE_LLDP),
@@ -216,7 +216,7 @@ static int lldp_parse_tlv_packet(tlv_packet *m, int len) {
 }
 
 int main(int argc, char *argv[]) {
-        _cleanup_tlv_packet_free_ tlv_packet *tlv = NULL;
+        _cleanup_lldp_packet_unref_ tlv_packet *tlv = NULL;
 
         /* form a packet */
         lldp_build_tlv_packet(&tlv);
index 0680e526b0982f00779e9c31471878925113cfae..efa76dacf7045f721fe72663b1c747bb406f78da 100644 (file)
@@ -29,6 +29,7 @@ enum {
 };
 
 typedef struct sd_lldp sd_lldp;
+typedef struct tlv_packet sd_lldp_packet;
 
 typedef void (*sd_lldp_cb_t)(sd_lldp *lldp, int event, void *userdata);
 
@@ -43,3 +44,14 @@ int sd_lldp_detach_event(sd_lldp *lldp);
 
 int sd_lldp_set_callback(sd_lldp *lldp, sd_lldp_cb_t cb, void *userdata);
 int sd_lldp_save(sd_lldp *lldp, const char *file);
+
+int sd_lldp_packet_read_chassis_id(sd_lldp_packet *tlv, uint8_t *type, uint8_t **data, uint16_t *length);
+int sd_lldp_packet_read_port_id(sd_lldp_packet *tlv, uint8_t *type, uint8_t **data, uint16_t *length);
+int sd_lldp_packet_read_ttl(sd_lldp_packet *tlv, uint16_t *ttl);
+int sd_lldp_packet_read_system_name(sd_lldp_packet *tlv, char **data, uint16_t *length);
+int sd_lldp_packet_read_system_description(sd_lldp_packet *tlv, char **data, uint16_t *length);
+int sd_lldp_packet_read_system_capability(sd_lldp_packet *tlv, uint16_t *data);
+int sd_lldp_packet_read_port_description(sd_lldp_packet *tlv, char **data, uint16_t *length);
+
+sd_lldp_packet *sd_lldp_packet_ref(sd_lldp_packet *tlv);
+sd_lldp_packet *sd_lldp_packet_unref(sd_lldp_packet *tlv);