From c520cb1446b2bab4d5dbc942aaae44f34458850a Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Wed, 29 Feb 2012 23:14:41 +0100 Subject: [PATCH] lldpd: do not stay stuck in the receive loop On some corner case conditions, we can stay stuck in the receive loop because we did not send packets for more than 30 seconds. In this case, we keep reset the timeout to 30 seconds and we cannot exit the loop (since the first condition to exit the loop is to have reached the timeout). Therefore, we invert the condition. If we have stay too long in the loop, just exit. We know for sure that we will hit lldpd_send_all() soon and get back to a sane state. Also, in receive only state, we are also stuck in the loop. This forbids us to update data about local chassis and interfaces. We also fix this. --- CHANGELOG | 6 ++++++ src/lldpd.c | 8 +++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index da95107e..3d8ed5f0 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -10,6 +10,12 @@ lldpd (0.6) * Fixes: + Several small SNMP fixes (discovered by unit tests). +lldpd (0.5.7) + * Fixes: + + Configure issue with NetSNMP and some linkers + + Fix infinite loop for the receive part: on certain conditions, + lldpd will stop sending packets and stop updating local data. + lldpd (0.5.6) * Features: + Send and receive native VLAN TLV with CDP diff --git a/src/lldpd.c b/src/lldpd.c index ba72c207..e1d603ae 100644 --- a/src/lldpd.c +++ b/src/lldpd.c @@ -756,7 +756,9 @@ lldpd_recv_all(struct lldpd *cfg) do { tv.tv_sec = cfg->g_delay - (time(NULL) - cfg->g_lastsent); if (tv.tv_sec < 0) - tv.tv_sec = LLDPD_TX_DELAY; + /* We did not send packets in a long time, + just give up receive for now. */ + break; if (tv.tv_sec >= cfg->g_delay) tv.tv_sec = cfg->g_delay; tv.tv_usec = 0; @@ -859,6 +861,7 @@ lldpd_send_all(struct lldpd *cfg) int i, sent; cfg->g_lastsent = time(NULL); + if (cfg->g_receiveonly) return; TAILQ_FOREACH(hardware, &cfg->g_hardware, h_entries) { /* Ignore if interface is down */ if ((hardware->h_flags & IFF_RUNNING) == 0) @@ -1039,8 +1042,7 @@ lldpd_loop(struct lldpd *cfg) lldpd_update_localports(cfg); lldpd_cleanup(cfg); lldpd_update_localchassis(cfg); - if (!cfg->g_receiveonly) - lldpd_send_all(cfg); + lldpd_send_all(cfg); lldpd_recv_all(cfg); } -- 2.39.5