From 5a215d4b32cd9ae1ed57a0f1b7737954de004c7b Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Sat, 10 May 2014 17:57:08 +0200 Subject: [PATCH] lldp: support for shutdown LLDPU We just accept 0 as a valid TTL and let the expiration mechanism do its work. We ensure that we can handle those 0 TTL and avoid underflow. Closes #5. --- NEWS | 2 ++ src/daemon/event.c | 6 +++++- src/daemon/lldp.c | 5 +++-- src/lldpd-structs.c | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/NEWS b/NEWS index bfe394fc..1199f5a0 100644 --- a/NEWS +++ b/NEWS @@ -9,6 +9,8 @@ lldpd (0.7.9) * Fixes: + Fix `configure system bond-slave-src-mac-type local`. Also use it as default. + * Features: + + Add support for shutdown LLDPU lldpd (0.7.8) * Fixes: diff --git a/src/daemon/event.c b/src/daemon/event.c index 8c5c3b4a..45919371 100644 --- a/src/daemon/event.c +++ b/src/daemon/event.c @@ -692,8 +692,12 @@ levent_schedule_cleanup(struct lldpd *cfg) struct lldpd_port *port; TAILQ_FOREACH(hardware, &cfg->g_hardware, h_entries) { TAILQ_FOREACH(port, &hardware->h_rports, p_entries) { + if (now + port->p_chassis->c_ttl >= port->p_lastupdate) { + tv.tv_sec = 0; + break; + } next = port->p_chassis->c_ttl - (now - port->p_lastupdate); - if (next >= 0 && next < tv.tv_sec) + if (next < tv.tv_sec) tv.tv_sec = next; } } diff --git a/src/daemon/lldp.c b/src/daemon/lldp.c index 5727bd73..d564c57f 100644 --- a/src/daemon/lldp.c +++ b/src/daemon/lldp.c @@ -483,7 +483,7 @@ lldp_decode(struct lldpd *cfg, char *frame, int s, const char dot3[] = LLDP_TLV_ORG_DOT3; const char med[] = LLDP_TLV_ORG_MED; char orgid[3]; - int length, gotend = 0; + int length, gotend = 0, ttl_received = 0; int tlv_size, tlv_type, tlv_subtype; u_int8_t *pos, *tlv; char *b; @@ -593,6 +593,7 @@ lldp_decode(struct lldpd *cfg, char *frame, int s, case LLDP_TLV_TTL: CHECK_TLV_SIZE(2, "TTL"); chassis->c_ttl = PEEK_UINT16; + ttl_received = 1; break; case LLDP_TLV_PORT_DESCR: case LLDP_TLV_SYSTEM_NAME: @@ -1008,7 +1009,7 @@ lldp_decode(struct lldpd *cfg, char *frame, int s, /* Some random check */ if ((chassis->c_id == NULL) || (port->p_id == NULL) || - (chassis->c_ttl == 0) || + (!ttl_received) || (gotend == 0)) { log_warnx("lldp", "some mandatory tlv are missing for frame received on %s", hardware->h_ifname); diff --git a/src/lldpd-structs.c b/src/lldpd-structs.c index 71d28087..63a824bf 100644 --- a/src/lldpd-structs.c +++ b/src/lldpd-structs.c @@ -124,7 +124,7 @@ lldpd_remote_cleanup(struct lldpd_hardware *hardware, port_next = TAILQ_NEXT(port, p_entries); del = all; if (!all && expire && - (now - port->p_lastupdate >= port->p_chassis->c_ttl)) { + (now >= port->p_lastupdate + port->p_chassis->c_ttl)) { hardware->h_ageout_cnt++; hardware->h_delete_cnt++; del = 1; -- 2.39.5