From: Vincent Bernat Date: Wed, 26 Sep 2012 22:21:45 +0000 (+0200) Subject: interfaces: don't block when sending LLDP frames X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fheads%2Fbranch-0.5;p=thirdparty%2Flldpd.git interfaces: don't block when sending LLDP frames It seems that in some situations, sending on a network interface (a virtual one for example) could block. We circumvent this by making the interface non blocking before sending. --- diff --git a/CHANGELOG b/CHANGELOG index 6b40e267..efee53e2 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,7 @@ +lldpd (0.5.8) + * Fixes: + + Don't block when sending LLDP frames. + lldpd (0.5.7) * Fixes: + Configure issue with NetSNMP and some linkers diff --git a/src/interfaces.c b/src/interfaces.c index c35bc840..57d25298 100644 --- a/src/interfaces.c +++ b/src/interfaces.c @@ -132,6 +132,14 @@ struct lldpd_ops bond_ops = { .cleanup = iface_bond_close, }; +static void +make_nonblock(int fd) +{ + int flags; + if ((flags = fcntl(fd, F_GETFL, NULL)) < 0) return; + fcntl(fd, F_SETFL, flags | O_NONBLOCK); +} + static int old_iface_is_bridge(struct lldpd *cfg, const char *name) { @@ -683,6 +691,7 @@ static int iface_eth_send(struct lldpd *cfg, struct lldpd_hardware *hardware, char *buffer, size_t size) { + make_nonblock(hardware->h_sendfd); return write(hardware->h_sendfd, buffer, size); } @@ -888,6 +897,7 @@ iface_bond_send(struct lldpd *cfg, struct lldpd_hardware *hardware, } memset(buffer + ETH_ALEN, 0, ETH_ALEN); } + make_nonblock(hardware->h_sendfd); return write(hardware->h_sendfd, buffer, size); }