summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBeniamino Galvani <bgalvani@redhat.com>2015-07-10 18:43:12 +0200
committerBeniamino Galvani <bgalvani@redhat.com>2015-10-02 17:39:12 +0200
commit176c355b43e616b61552566303ad59d5fd910333 (patch)
tree9198ba7be4f24b643ef9c24b8e1d01b421fb4b3b /src
parent97030a86f0137bca52c3cf9b30e5ed3bdf69b2f2 (diff)
lldp: export opaque TLV type and accessor functions
Export struct tlv_packet as a public opaque sd_lldp_packet type and make its accessor functions public.
Diffstat (limited to 'src')
-rw-r--r--src/libsystemd-network/lldp-internal.c61
-rw-r--r--src/libsystemd-network/lldp-internal.h8
-rw-r--r--src/libsystemd-network/lldp-network.c2
-rw-r--r--src/libsystemd-network/lldp-tlv.c4
-rw-r--r--src/libsystemd-network/lldp-tlv.h8
-rw-r--r--src/libsystemd-network/sd-lldp.c10
-rw-r--r--src/libsystemd-network/test-lldp.c4
-rw-r--r--src/systemd/sd-lldp.h12
8 files changed, 57 insertions, 52 deletions
diff --git a/src/libsystemd-network/lldp-internal.c b/src/libsystemd-network/lldp-internal.c
index 7695805946..762a1d2895 100644
--- a/src/libsystemd-network/lldp-internal.c
+++ b/src/libsystemd-network/lldp-internal.c
@@ -21,6 +21,7 @@
***/
#include "lldp-internal.h"
+#include "sd-lldp.h"
/* We store maximum 1K chassis entries */
#define LLDP_MIB_MAX_CHASSIS 1024
@@ -28,10 +29,10 @@
/* 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;
diff --git a/src/libsystemd-network/lldp-internal.h b/src/libsystemd-network/lldp-internal.h
index c61080828b..774562e171 100644
--- a/src/libsystemd-network/lldp-internal.h
+++ b/src/libsystemd-network/lldp-internal.h
@@ -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__)
diff --git a/src/libsystemd-network/lldp-network.c b/src/libsystemd-network/lldp-network.c
index 664d2f7867..1c6dcae14d 100644
--- a/src/libsystemd-network/lldp-network.c
+++ b/src/libsystemd-network/lldp-network.c
@@ -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;
diff --git a/src/libsystemd-network/lldp-tlv.c b/src/libsystemd-network/lldp-tlv.c
index 1370d217f4..700da2fde7 100644
--- a/src/libsystemd-network/lldp-tlv.c
+++ b/src/libsystemd-network/lldp-tlv.c
@@ -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)
diff --git a/src/libsystemd-network/lldp-tlv.h b/src/libsystemd-network/lldp-tlv.h
index f682997031..19509d3589 100644
--- a/src/libsystemd-network/lldp-tlv.h
+++ b/src/libsystemd-network/lldp-tlv.h
@@ -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);
diff --git a/src/libsystemd-network/sd-lldp.c b/src/libsystemd-network/sd-lldp.c
index 5a03ab4448..2b788e78cd 100644
--- a/src/libsystemd-network/sd-lldp.c
+++ b/src/libsystemd-network/sd-lldp.c
@@ -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);
diff --git a/src/libsystemd-network/test-lldp.c b/src/libsystemd-network/test-lldp.c
index 06545aee59..26f64347a7 100644
--- a/src/libsystemd-network/test-lldp.c
+++ b/src/libsystemd-network/test-lldp.c
@@ -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);
diff --git a/src/systemd/sd-lldp.h b/src/systemd/sd-lldp.h
index 0680e526b0..efa76dacf7 100644
--- a/src/systemd/sd-lldp.h
+++ b/src/systemd/sd-lldp.h
@@ -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);