chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
bus-proxy: make sure sure eavesdrop= XML attributes are properly handled
[elogind.git]
/
src
/
libsystemd-network
/
sd-lldp.c
diff --git
a/src/libsystemd-network/sd-lldp.c
b/src/libsystemd-network/sd-lldp.c
index 45881e5f64a1a98ca889caa564f0ae0c7292051a..19ef2ccdbda76466d665e340d1645e1cb6f129e3 100644
(file)
--- a/
src/libsystemd-network/sd-lldp.c
+++ b/
src/libsystemd-network/sd-lldp.c
@@
-32,6
+32,7
@@
#include "prioq.h"
#include "strv.h"
#include "lldp-internal.h"
#include "prioq.h"
#include "strv.h"
#include "lldp-internal.h"
+#include "lldp-util.h"
#include "ether-addr-util.h"
typedef enum LLDPAgentRXState {
#include "ether-addr-util.h"
typedef enum LLDPAgentRXState {
@@
-47,7
+48,7
@@
typedef enum LLDPAgentRXState {
} LLDPAgentRXState;
/* Section 10.5.2.2 Reception counters */
} LLDPAgentRXState;
/* Section 10.5.2.2 Reception counters */
-struct lldp_agent_statitics {
+struct lldp_agent_stati
s
tics {
uint64_t stats_ageouts_total;
uint64_t stats_frames_discarded_total;
uint64_t stats_frames_in_errors_total;
uint64_t stats_ageouts_total;
uint64_t stats_frames_discarded_total;
uint64_t stats_frames_in_errors_total;
@@
-67,7
+68,7
@@
struct sd_lldp {
void *userdata;
LLDPAgentRXState rx_state;
void *userdata;
LLDPAgentRXState rx_state;
- lldp_agent_stati
tics stati
tics;
+ lldp_agent_stati
stics statis
tics;
};
static unsigned long chassis_id_hash_func(const void *p,
};
static unsigned long chassis_id_hash_func(const void *p,
@@
-133,7
+134,7
@@
static int lldp_receive_frame(sd_lldp *lldp, tlv_packet *tlv) {
hashmap_size(lldp->neighbour_mib),
prioq_size(lldp->by_expiry));
hashmap_size(lldp->neighbour_mib),
prioq_size(lldp->by_expiry));
- lldp->statitics.stats_frames_in_total ++;
+ lldp->stati
s
tics.stats_frames_in_total ++;
return 0;
return 0;
@@
-338,8
+339,8
@@
int lldp_handle_packet(tlv_packet *tlv, uint16_t length) {
lldp_set_state(lldp, LLDP_AGENT_RX_WAIT_FOR_FRAME);
if (malformed) {
lldp_set_state(lldp, LLDP_AGENT_RX_WAIT_FOR_FRAME);
if (malformed) {
- lldp->statitics.stats_frames_discarded_total ++;
- lldp->statitics.stats_frames_in_errors_total ++;
+ lldp->stati
s
tics.stats_frames_discarded_total ++;
+ lldp->stati
s
tics.stats_frames_in_errors_total ++;
}
tlv_packet_free(tlv);
}
tlv_packet_free(tlv);
@@
-403,7
+404,7
@@
static void lldp_mib_delete_objects(sd_lldp *lldp) {
lldp_neighbour_port_remove_and_free(p);
lldp_neighbour_port_remove_and_free(p);
- lldp->statitics.stats_ageouts_total ++;
+ lldp->stati
s
tics.stats_ageouts_total ++;
}
}
}
}
@@
-428,7
+429,6
@@
static void lldp_mib_objects_flush(sd_lldp *lldp) {
}
int sd_lldp_save(sd_lldp *lldp, const char *lldp_file) {
}
int sd_lldp_save(sd_lldp *lldp, const char *lldp_file) {
- _cleanup_free_ char *s = NULL, *t = NULL, *k = NULL;
_cleanup_free_ char *temp_path = NULL;
_cleanup_fclose_ FILE *f = NULL;
uint8_t *mac, *port_id, type;
_cleanup_free_ char *temp_path = NULL;
_cleanup_fclose_ FILE *f = NULL;
uint8_t *mac, *port_id, type;
@@
-451,13
+451,13
@@
int sd_lldp_save(sd_lldp *lldp, const char *lldp_file) {
HASHMAP_FOREACH(c, lldp->neighbour_mib, i) {
LIST_FOREACH(port, p, c->ports) {
HASHMAP_FOREACH(c, lldp->neighbour_mib, i) {
LIST_FOREACH(port, p, c->ports) {
+ _cleanup_free_ char *s = NULL;
+ char *k, *t;
r = lldp_read_chassis_id(p->packet, &type, &length, &mac);
if (r < 0)
continue;
r = lldp_read_chassis_id(p->packet, &type, &length, &mac);
if (r < 0)
continue;
- memzero(buf, LINE_MAX);
-
sprintf(buf, "'_Chassis=%02x:%02x:%02x:%02x:%02x:%02x' '_CType=%d' ",
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], type);
sprintf(buf, "'_Chassis=%02x:%02x:%02x:%02x:%02x:%02x' '_CType=%d' ",
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], type);
@@
-466,56
+466,43
@@
int sd_lldp_save(sd_lldp *lldp, const char *lldp_file) {
return -ENOMEM;
r = lldp_read_port_id(p->packet, &type, &length, &port_id);
return -ENOMEM;
r = lldp_read_port_id(p->packet, &type, &length, &port_id);
- if (r < 0) {
- free(s);
+ if (r < 0)
continue;
continue;
- }
- memzero(buf, LINE_MAX);
if (type != LLDP_PORT_SUBTYPE_MAC_ADDRESS) {
if (type != LLDP_PORT_SUBTYPE_MAC_ADDRESS) {
-
k = strndup((char *) port_id, length -1);
if (!k)
return -ENOMEM;
sprintf(buf, "'_Port=%s' '_PType=%d' ", k , type);
k = strndup((char *) port_id, length -1);
if (!k)
return -ENOMEM;
sprintf(buf, "'_Port=%s' '_PType=%d' ", k , type);
-
- t = strappend(s, buf);
-
free(k);
} else {
free(k);
} else {
-
mac = port_id;
mac = port_id;
-
sprintf(buf, "'_Port=%02x:%02x:%02x:%02x:%02x:%02x' '_PType=%d' ",
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], type);
sprintf(buf, "'_Port=%02x:%02x:%02x:%02x:%02x:%02x' '_PType=%d' ",
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], type);
-
- t = strappend(s, buf);
}
}
- if (!t)
+ k = strappend(s, buf);
+ if (!k)
return -ENOMEM;
free(s);
return -ENOMEM;
free(s);
- s =
t
;
+ s =
k
;
time = now(CLOCK_BOOTTIME);
/* Don't write expired packets */
time = now(CLOCK_BOOTTIME);
/* Don't write expired packets */
- if(time - p->until <= 0) {
- free(s);
+ if (time - p->until <= 0)
continue;
continue;
- }
- memzero(buf, LINE_MAX);
- sprintf(buf, "'_TTL=%lu' ", p->until);
+ sprintf(buf, "'_TTL="USEC_FMT"' ", p->until);
-
t
= strappend(s, buf);
- if (!
t
)
+
k
= strappend(s, buf);
+ if (!
k
)
return -ENOMEM;
free(s);
return -ENOMEM;
free(s);
- s =
t
;
+ s =
k
;
r = lldp_read_system_name(p->packet, &length, &k);
if (r < 0)
r = lldp_read_system_name(p->packet, &length, &k);
if (r < 0)
@@
-526,6
+513,7
@@
int sd_lldp_save(sd_lldp *lldp, const char *lldp_file) {
return -ENOMEM;
k = strjoin(s, "'_NAME=", t, "' ", NULL);
return -ENOMEM;
k = strjoin(s, "'_NAME=", t, "' ", NULL);
+ free(t);
}
if (!k)
}
if (!k)
@@
-534,28
+522,22
@@
int sd_lldp_save(sd_lldp *lldp, const char *lldp_file) {
free(s);
s = k;
free(s);
s = k;
- memzero(buf, LINE_MAX);
-
(void)lldp_read_system_capability(p->packet, &data);
sprintf(buf, "'_CAP=%x'", data);
(void)lldp_read_system_capability(p->packet, &data);
sprintf(buf, "'_CAP=%x'", data);
-
t
= strappend(s, buf);
- if (!
t
)
+
k
= strappend(s, buf);
+ if (!
k
)
return -ENOMEM;
return -ENOMEM;
- fprintf(f, "%s\n", t);
-
free(s);
free(s);
- free(t);
+ s = k;
+
+ fprintf(f, "%s\n", s);
}
}
r = 0;
}
}
r = 0;
- s = NULL;
- t = NULL;
- k = NULL;
-
fflush(f);
if (ferror(f) || rename(temp_path, lldp_file) < 0) {
fflush(f);
if (ferror(f) || rename(temp_path, lldp_file) < 0) {
@@
-668,10
+650,10
@@
void sd_lldp_free(sd_lldp *lldp) {
}
int sd_lldp_new(int ifindex,
}
int sd_lldp_new(int ifindex,
- char *ifname,
- struct ether_addr *mac,
+ c
onst c
har *ifname,
+
const
struct ether_addr *mac,
sd_lldp **ret) {
sd_lldp **ret) {
- _cleanup_
sd_
lldp_free_ sd_lldp *lldp = NULL;
+ _cleanup_lldp_free_ sd_lldp *lldp = NULL;
int r;
assert_return(ret, -EINVAL);
int r;
assert_return(ret, -EINVAL);